Skip to content

Commit

Permalink
Add progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
Taneb committed Aug 17, 2015
1 parent 559429a commit 64c0fbc
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,16 @@ private void generateThriftFile(EglFileGeneratingTemplate template, File origin)
public Object execute(final ExecutionEvent event) throws ExecutionException {
Job job = new Job("ecore2thrift"){
protected IStatus run(IProgressMonitor monitor) {
monitor.beginTask("Generating Thrift file from Ecore", 3);

final ISelection selection0 = HandlerUtil.getCurrentSelection(event);
if (selection0 instanceof IStructuredSelection) {
final IStructuredSelection selection = (IStructuredSelection)selection0;
final IFile ecore = (IFile)selection.getFirstElement();
final File ecoreFile = ecore.getLocation().toFile();
// run EVL script
try {
monitor.subTask("Validating");
for (IMarker marker : ecore.findMarkers(EValidator.MARKER, false, IResource.DEPTH_INFINITE)) {
if (marker.getAttribute("secondary-marker-type", "").equalsIgnoreCase("uk.ac.york.mondo.ecore2thift.validation")) {
marker.delete();
Expand Down Expand Up @@ -95,15 +98,27 @@ protected IStatus run(IProgressMonitor monitor) {
Activator.getPlugin().logError("There was some error during validation.", e);
return new Status(Status.ERROR, "ecore2thrift", "There was some error during validation", e);
}
monitor.worked(1);
if (monitor.isCanceled()) {
monitor.done();
return Status.CANCEL_STATUS;
}
final EglFileGeneratingTemplateFactory factory = new EglFileGeneratingTemplateFactory();
try {
monitor.subTask("Loading model");
final IEolExecutableModule eglModule = new EglTemplateFactoryModuleAdapter(factory);
addModelFromFile(eglModule, ecoreFile);
} catch (Exception e) {
Activator.getPlugin().logError("There was an error while loading the model", e);
return new Status(Status.ERROR, "ecore2thrift", "There was an error while loading the model", e);
}
monitor.worked(1);
if (monitor.isCanceled()) {
monitor.done();
return Status.CANCEL_STATUS;
}
try {
monitor.subTask("Processing model");
final URI ecore2thriftURI = GenerateThriftCommand.class.getResource("/epsilon/ecore2thrift.egl").toURI(); // should I bother giving this a name?
final EglFileGeneratingTemplate template = (EglFileGeneratingTemplate)factory.load(ecore2thriftURI);
template.process();
Expand All @@ -114,6 +129,12 @@ protected IStatus run(IProgressMonitor monitor) {
Activator.getPlugin().logError("There was some error while processing the model", e);
return new Status(Status.ERROR, "ecore2thrift", "There was some error while processing the model", e);
}
monitor.worked(1);
if (monitor.isCanceled()) {
monitor.done();
return Status.CANCEL_STATUS;
}
monitor.subTask("Refreshing project");
try {
ecore.getProject().refreshLocal(IProject.DEPTH_INFINITE, null);
} catch (CoreException e) {
Expand All @@ -122,6 +143,8 @@ protected IStatus run(IProgressMonitor monitor) {
Activator.getPlugin().logError("There was an error while refreshing the project", e);
return new Status(Status.ERROR, "ecore2thrift", "There was an error while refreshing the project", e);
}
monitor.done();

}
return Status.OK_STATUS;
}
Expand Down

0 comments on commit 64c0fbc

Please sign in to comment.