Example usage for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress

List of usage examples for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress

Introduction

In this page you can find the example usage for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress.

Prototype

IRunnableWithProgress

Source Link

Usage

From source file:SaveHandler.java

License:Open Source License

    @Execute
   public void execute(
         IEclipseContext context,// ww  w .  j  a v a2s  .  c  om
         @Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
         @Named(IServiceConstants.ACTIVE_PART) final MContribution contribution)
         throws InvocationTargetException, InterruptedException {
      final IEclipseContext pmContext = context.createChild();

      ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
      dialog.open();
      dialog.run(true, true, new IRunnableWithProgress() {
         public void run(IProgressMonitor monitor)
               throws InvocationTargetException, InterruptedException {
            pmContext.set(IProgressMonitor.class.getName(), monitor);
            if (contribution != null) {
               Object clientObject = contribution.getObject();
//               ContextInjectionFactory.invoke(clientObject, Persist.class, //$NON-NLS-1$
//                     pmContext, null);
            }
         }
      });

      if (pmContext instanceof IDisposable) {
         ((IDisposable) pmContext).dispose();
      }
   }

From source file:BMVirtualFindAction.java

License:Open Source License

public void run() {
    final VirtualViewerListener listener = new VirtualViewerListener();
    VirtualTreeModelViewer virtualViewer = initVirtualViewer(fClientViewer, listener);

    ProgressMonitorDialog dialog = new TimeTriggeredProgressMonitorDialog(fClientViewer.getControl().getShell(),
            500);/* w  w w . ja  va 2  s .  c  om*/
    final IProgressMonitor monitor = dialog.getProgressMonitor();
    dialog.setCancelable(true);

    try {
        dialog.run(true, true, new IRunnableWithProgress() {
            public void run(final IProgressMonitor m) throws InvocationTargetException, InterruptedException {
                synchronized (listener) {
                    listener.fProgressMonitor = m;
                    listener.fProgressMonitor.beginTask(DebugUIPlugin.removeAccelerators(getText()),
                            listener.fRemainingUpdatesCount);
                }

                while ((!listener.fLabelUpdatesComplete || !listener.fViewerUpdatesComplete)
                        && !listener.fProgressMonitor.isCanceled()) {
                    Thread.sleep(1);
                }
                synchronized (listener) {
                    listener.fProgressMonitor = null;
                }
            }
        });
    } catch (InvocationTargetException e) {
        DebugUIPlugin.log(e);
        return;
    } catch (InterruptedException e) {
        return;
    }

    VirtualItem root = virtualViewer.getTree();
    if (!monitor.isCanceled()) {
        List<VirtualItem> list = new ArrayList<VirtualItem>();
        collectAllChildren(root, list);
        FindLabelProvider labelProvider = new FindLabelProvider(virtualViewer, list);
        VirtualItem result = performFind(list, labelProvider);
        if (result != null) {
            setSelectionToClient(virtualViewer, labelProvider, result);
        }
    }

    virtualViewer.removeLabelUpdateListener(listener);
    virtualViewer.removeViewerUpdateListener(listener);
    virtualViewer.dispose();
}

From source file:$.AcceleoGenerateUMLtoJavaAction.java

License:Open Source License

/**{@inheritDoc}
     *//  w  ww  . jav  a 2  s  . c  o m
     * @see org.eclipse.ui.actions.ActionDelegate#run(org.eclipse.jface.action.IAction)
     * @generated
     */
    public void run(IAction action) {
        if (files != null) {
            IRunnableWithProgress operation = new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor) {
                    try {
                        Iterator<IFile> filesIt = files.iterator();
                        while (filesIt.hasNext()) {
                            IFile model = (IFile) filesIt.next();
                            URI modelURI = URI.createPlatformResourceURI(model.getFullPath().toString(), true);
                            try {
                                IContainer target = model.getProject().getFolder("src-gen");
                                GenerateAll generator = new GenerateAll(modelURI, target.getLocation().toFile(),
                                        getArguments());
                                generator.doGenerate(monitor);
                            } catch (IOException e) {
                                IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
                                Activator.getDefault().getLog().log(status);
                            } finally {
                                model.getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);
                            }
                        }
                    } catch (CoreException e) {
                        IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
                        Activator.getDefault().getLog().log(status);
                    }
                }
            };
            try {
                PlatformUI.getWorkbench().getProgressService().run(true, true, operation);
            } catch (InvocationTargetException e) {
                IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
                Activator.getDefault().getLog().log(status);
            } catch (InterruptedException e) {
                IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e);
                Activator.getDefault().getLog().log(status);
            }
        }
    }

From source file:$group_id$.core.handlers.SaveHandler.java

License:Open Source License

@Execute
public void execute(IEclipseContext context, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
        @Named(IServiceConstants.ACTIVE_PART) final MContribution contribution)
        throws InvocationTargetException, InterruptedException {
    final IEclipseContext pmContext = context.createChild();

    ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
    dialog.open();//from www  . j  a  v  a  2 s.  c om
    dialog.run(true, true, new IRunnableWithProgress() {
        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            pmContext.set(IProgressMonitor.class.getName(), monitor);
            if (contribution != null) {
                //               Object clientObject = contribution.getObject();
                //               ContextInjectionFactory.invoke(clientObject, Persist.class, //\$NON-NLS-1\$
                //                     pmContext, null);
            }
        }
    });

    pmContext.dispose();
}

From source file:ac.soton.eventb.atomicitydecomposition.generator.actions.GenerateAction.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

    IEditorPart editor = HandlerUtil.getActiveEditorChecked(event);
    if (editor instanceof RoseEditor) {
        final RoseEditor roseEditor = (RoseEditor) editor;
        IStructuredSelection selection = (IStructuredSelection) roseEditor.getSelection();
        if (selection.getFirstElement() instanceof EventBElement) {
            final EventBElement eventBElement = (EventBElement) selection.getFirstElement();

            ResourceSet resourceSet = eventBElement.eResource().getResourceSet();

            if (editor.isDirty())
                editor.doSave(new NullProgressMonitor());

            // first validate, then transform
            //   if (ValidateAction.validate(diagramDocumentEditor)){

            for (AbstractExtension abs : eventBElement.getExtensions()) {
                TransactionalEditingDomain editingDomain = TransactionalEditingDomain.Factory.INSTANCE
                        .createEditingDomain();

                AbstractExtension absExt;
                if (abs.eIsProxy()) {
                    absExt = (AbstractExtension) resourceSet.getEObject(EcoreUtil.getURI(abs), false);
                } else
                    absExt = abs;//from   w w  w .  j  a  va2s .c  o m

                if (absExt instanceof FlowDiagram) {
                    //If there is no extension, set as being the name
                    if (absExt.getExtensionId() == null || absExt.getExtensionId().equals("")) {
                        absExt.setExtensionId(((FlowDiagram) absExt).getName());
                    }

                    final GenerateCommand generateCommand = new GenerateCommand(editingDomain, absExt);
                    if (generateCommand.canExecute()) {
                        // run with progress
                        ProgressMonitorDialog dialog = new ProgressMonitorDialog(
                                roseEditor.getSite().getShell());
                        try {
                            dialog.run(true, true, new IRunnableWithProgress() {
                                public void run(IProgressMonitor monitor) {
                                    monitor.beginTask(Messages.GENERATOR_MSG_05, IProgressMonitor.UNKNOWN);
                                    try {
                                        generateCommand.execute(monitor, roseEditor);
                                    } catch (ExecutionException e) {
                                        Activator.logError(Messages.GENERATOR_MSG_06, e);
                                    }
                                    monitor.done();
                                }
                            });
                        } catch (InvocationTargetException e) {
                            Activator.logError(Messages.GENERATOR_MSG_07, e);
                            return null;
                        } catch (InterruptedException e) {
                            Activator.logError(Messages.GENERATOR_MSG_08, e);
                            return null;
                        }
                        // error feedback
                        if (false == generateCommand.getCommandResult().getStatus().isOK())
                            MessageDialog.openError(editor.getSite().getShell(), Messages.GENERATOR_MSG_09,
                                    Messages.GENERATOR_MSG_10);
                    }
                }
            }
        }
    }
    return null;
}

From source file:ac.soton.eventb.classdiagrams.diagram.part.ValidateAction.java

License:Open Source License

/**
 * @generated/* w  ww . j  a v a2  s  .  c  om*/
 */
public void run() {
    IWorkbenchPart workbenchPart = page.getActivePart();
    if (workbenchPart instanceof IDiagramWorkbenchPart) {
        final IDiagramWorkbenchPart part = (IDiagramWorkbenchPart) workbenchPart;
        try {
            new WorkspaceModifyDelegatingOperation(new IRunnableWithProgress() {

                public void run(IProgressMonitor monitor)
                        throws InterruptedException, InvocationTargetException {
                    runValidation(part.getDiagramEditPart(), part.getDiagram());
                }
            }).run(new NullProgressMonitor());
        } catch (Exception e) {
            ClassdiagramsDiagramEditorPlugin.getInstance().logError("Validation action failed", e); //$NON-NLS-1$
        }
    }
}

From source file:ac.soton.eventb.emf.diagrams.generator.actions.GenerateAction.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

    IEditorPart editor = HandlerUtil.getActiveEditorChecked(event);
    if (editor instanceof DiagramDocumentEditor) {
        final DiagramDocumentEditor diagramDocumentEditor = (DiagramDocumentEditor) editor;

        if (diagramDocumentEditor.getDiagram().getElement() instanceof EventBElement) {
            final EventBElement eventBElement = (EventBElement) diagramDocumentEditor.getDiagram().getElement();

            // save before transformation
            if (editor.isDirty())
                editor.doSave(new NullProgressMonitor());

            // first validate, then transform
            if (ValidateAction.validate(diagramDocumentEditor)) {

                final GenerateCommand generateCommand = new GenerateCommand(
                        diagramDocumentEditor.getDiagramEditPart().getEditingDomain(), eventBElement);
                if (generateCommand.canExecute()) {
                    // run with progress
                    ProgressMonitorDialog dialog = new ProgressMonitorDialog(
                            diagramDocumentEditor.getSite().getShell());
                    try {
                        dialog.run(true, true, new IRunnableWithProgress() {
                            public void run(IProgressMonitor monitor) {
                                monitor.beginTask(Messages.GENERATOR_MSG_05, IProgressMonitor.UNKNOWN);
                                try {
                                    generateCommand.execute(monitor, diagramDocumentEditor);
                                } catch (ExecutionException e) {
                                    Activator.logError(Messages.GENERATOR_MSG_06, e);
                                }//from w ww.  j a  v  a2 s.  c o  m
                                monitor.done();
                            }
                        });
                    } catch (InvocationTargetException e) {
                        Activator.logError(Messages.GENERATOR_MSG_07, e);
                        return null;
                    } catch (InterruptedException e) {
                        Activator.logError(Messages.GENERATOR_MSG_08, e);
                        return null;
                    }

                    // error feedback
                    if (false == generateCommand.getCommandResult().getStatus().isOK())
                        MessageDialog.openError(editor.getSite().getShell(), Messages.GENERATOR_MSG_09,
                                Messages.GENERATOR_MSG_10);
                }
            }
        }
    }
    return null;
}

From source file:ac.soton.eventb.statemachines.diagram.part.ValidateAction.java

License:Open Source License

/**
 * @generated//from  ww  w .  java2  s .c  om
 */
public void run() {
    IWorkbenchPart workbenchPart = page.getActivePart();
    if (workbenchPart instanceof IDiagramWorkbenchPart) {
        final IDiagramWorkbenchPart part = (IDiagramWorkbenchPart) workbenchPart;
        try {
            new WorkspaceModifyDelegatingOperation(new IRunnableWithProgress() {

                public void run(IProgressMonitor monitor)
                        throws InterruptedException, InvocationTargetException {
                    runValidation(part.getDiagramEditPart(), part.getDiagram());
                }
            }).run(new NullProgressMonitor());
        } catch (Exception e) {
            StatemachinesDiagramEditorPlugin.getInstance().logError("Validation action failed", e); //$NON-NLS-1$
        }
    }
}

From source file:ac.soton.eventb.statemachines.transformation.TranslateAction.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

    IEditorPart editor = HandlerUtil.getActiveEditorChecked(event);
    if (editor instanceof DiagramDocumentEditor) {
        final DiagramDocumentEditor diagramDocumentEditor = (DiagramDocumentEditor) editor;

        if (diagramDocumentEditor.getDiagram().getElement() instanceof Statemachine) {
            final Statemachine statemachine = (Statemachine) diagramDocumentEditor.getDiagram().getElement();

            // save before transformation
            if (editor.isDirty())
                editor.doSave(new NullProgressMonitor());

            // first validate, then transform
            if (ValidateAction.validate(diagramDocumentEditor)) {

                final StatemachineTransformationCommand generateCommand = new StatemachineTransformationCommand(
                        diagramDocumentEditor.getDiagramEditPart().getEditingDomain(), statemachine);

                if (generateCommand.canExecute()) {
                    // run with progress
                    ProgressMonitorDialog dialog = new ProgressMonitorDialog(
                            diagramDocumentEditor.getSite().getShell());
                    try {
                        dialog.run(true, true, new IRunnableWithProgress() {
                            public void run(IProgressMonitor monitor) {
                                monitor.beginTask("Translating to Event-B ...", IProgressMonitor.UNKNOWN);
                                try {
                                    generateCommand.execute(monitor, diagramDocumentEditor);
                                } catch (ExecutionException e) {
                                    Activator.logError("Statemachine transformation failed", e);
                                }//from   w w  w  . j av  a 2 s .co  m
                                monitor.done();
                            }
                        });
                    } catch (InvocationTargetException e) {
                        TransformationPlugin.getDefault().logError("Transformation failed", e);
                        return null;
                    } catch (InterruptedException e) {
                        TransformationPlugin.getDefault().logError("Transformation interrupted", e);
                        return null;
                    }

                    // error feedback
                    if (false == generateCommand.getCommandResult().getStatus().isOK())
                        MessageDialog.openError(editor.getSite().getShell(), "Translation Information",
                                "Translation encountered problems.\n\nSee log for details.");
                }
            }
        }
    }
    return null;
}

From source file:ac.soton.fmusim.components.diagram.part.ValidateAction.java

License:Open Source License

/**
 * @generated/* w ww  .  j  a  va  2  s .c om*/
 */
public void run() {
    IWorkbenchPart workbenchPart = page.getActivePart();
    if (workbenchPart instanceof IDiagramWorkbenchPart) {
        final IDiagramWorkbenchPart part = (IDiagramWorkbenchPart) workbenchPart;
        try {
            new WorkspaceModifyDelegatingOperation(new IRunnableWithProgress() {

                public void run(IProgressMonitor monitor)
                        throws InterruptedException, InvocationTargetException {
                    runValidation(part.getDiagramEditPart(), part.getDiagram());
                }
            }).run(new NullProgressMonitor());
        } catch (Exception e) {
            ComponentsDiagramEditorPlugin.getInstance().logError("Validation action failed", e); //$NON-NLS-1$
        }
    }
}