Skip to content

Commit

Permalink
Add the automatic refresh after generation
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Prouvost <olivier.prouvost@opcoach.com>
  • Loading branch information
opcoach committed Feb 22, 2015
1 parent e3e40a9 commit 2612a65
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Expand Up @@ -8,8 +8,11 @@
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
Expand Down Expand Up @@ -63,11 +66,20 @@ public Object execute(ExecutionEvent event) throws ExecutionException
fw.write(gen.generateAntFileContent(modelName).toString());
fw.flush();
fw.close();

// Add a refresh
IProject proj = ResourcesPlugin.getWorkspace().getRoot().getProject(extractProjectName(gm));
proj.refreshLocal(IResource.DEPTH_ONE, null);

} catch (IOException e)
{
MessageDialog.openWarning(parentShell, "Ant file could not be generated",
"It was not possible to generate the file : " + ANT_FILENAME
+ "\n\n The reason is : \n\n" + e.getMessage());
} catch (CoreException e)
{
MessageDialog.openWarning(parentShell, "Could not refresh the workspace",
"It was not possible refresh the workspace. You should do it by hand");
}
}

Expand All @@ -86,7 +98,7 @@ private File getAntFile(GenModel gm)
return f;
}

private String extractProjectName(GenModel gm)
static String extractProjectName(GenModel gm)
{
String genModelUri = gm.eResource().getURI().toString();
String nameStartingWithProjectName = genModelUri.replace("platform:/resource/", "");
Expand Down
Expand Up @@ -9,6 +9,10 @@
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
Expand Down Expand Up @@ -102,6 +106,15 @@ public Object execute(ExecutionEvent event) throws ExecutionException

}
}

// Refresh the workspace.
IProject proj = ResourcesPlugin.getWorkspace().getRoot().getProject(GenerateAntFileHandler.extractProjectName(gm));
try
{
proj.refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (CoreException e)
{
}

// Display a sum up dialog
if (filesInError.length() == 0)
Expand Down

0 comments on commit 2612a65

Please sign in to comment.