Example usage for org.eclipse.jface.dialogs ProgressMonitorDialog open

List of usage examples for org.eclipse.jface.dialogs ProgressMonitorDialog open

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs ProgressMonitorDialog open.

Prototype

@Override
    public int open() 

Source Link

Usage

From source file:org.lejos.tools.eclipse.plugin.util.AbstractJavaTestProject.java

License:Open Source License

public void buildProject() throws CoreException {
    if (!hasBeenBuild()) {
        Shell shell = new Shell();
        ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
        dialog.open();
        IProgressMonitor monitor = dialog.getProgressMonitor();
        try {/*from   w w w  .j a  v a 2  s .c  o m*/
            monitor.beginTask("Building project", 100);
            this.project.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
        } finally {
            monitor.done();
        }
        dialog.close();
    }
}

From source file:org.openhealthtools.mdht.uml.hl7.ui.actions.ImportMIFAction.java

License:Open Source License

/**
 * @see IActionDelegate#run(IAction)// w  w w .  j  av  a 2  s. co m
 */
public void run(IAction action) {
    ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(activePart.getSite().getShell());
    progressDialog.open();

    try {
        Model umlModel = UMLFactory.eINSTANCE.createModel();
        umlModel.setName("MIF_Import");

        // Must create UML model resource before importing
        // so that MIF datatypes can be added to same resource set.
        List<ModelElement> mifElements = getModelElements();
        if (mifElements.isEmpty()) {
            return;
        }

        Resource mifResource = (mifElements.get(0)).eResource();
        URI umlURI = mifResource.getURI().trimFileExtension();
        umlURI = umlURI.appendFileExtension(getUMLFileExtension());

        /*
         * Special case for rim.coremif
         * Create a model named "RIM", import content directly into top-level Model.
         */
        if (mifElements.size() == 1 && "rim.coremif".equals(mifResource.getURI().lastSegment())) {

            umlModel.setName("RIM");
            umlURI.trimSegments(1);
            umlURI = umlURI.appendSegment("RIM");
            umlURI = umlURI.appendFileExtension(getUMLFileExtension());
        }

        // save to current IProject
        IProject project = getCurrentProject();
        IFile umlFile = null;
        if (project != null) {
            umlFile = project.getFile(umlURI.lastSegment());
            umlURI = URI.createPlatformResourceURI(umlFile.getFullPath().toString(), false);
        }

        Resource umlResource = mifResource.getResourceSet().createResource(umlURI);
        umlResource.getContents().add(umlModel);

        MIFImporter importer = new MIFImporter();
        importer.setUMLModel(umlModel);

        /*
         * Special case for rim.coremif
         * Create a model named "RIM", import content directly into top-level Model.
         */
        if (mifElements.size() == 1 && "rim.coremif".equals(mifResource.getURI().lastSegment())
                && mifElements.get(0) instanceof StaticModelBase) {

            ((XMLResource) umlResource).setID(umlModel, "RIM-model");
            importer.processMIF(mifElements.get(0));
        } else {
            for (ModelElement element : mifElements) {
                importer.processMIF(element);
            }
        }

        umlResource.save(new HashMap<Object, Object>());
        // unload the model
        umlModel.eResource().unload();
        resourceSet = null;

        // refresh the Eclipse workspace to show this new file
        IFile[] files = null;
        if (umlFile != null) {
            files = new IFile[1];
            files[0] = umlFile;
            project.refreshLocal(1, null);
        } else {
            files = ResourcesPlugin.getWorkspace().getRoot()
                    .findFilesForLocation(new Path(umlURI.toFileString()));
        }
        if (files.length == 1) {
            // files[0].getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
            files[0].getParent().refreshLocal(IResource.DEPTH_ONE, null);

            String editorID = "org.eclipse.uml2.uml.editor.presentation.UMLEditorID";
            Bundle rsmBundle = Platform.getBundle("com.ibm.xtools.modeler.ui");
            if (rsmBundle != null && "emx".equals(files[0].getFullPath().getFileExtension())) {
                editorID = "com.ibm.xtools.modeler.ui.editors.internal.ModelEditor";
            } else if (activePart instanceof CommonNavigator) {
                // without this, the model file is in wrong sort position in navigator
                CommonViewer viewer = ((CommonNavigator) activePart).getCommonViewer();
                viewer.refresh();
                ((CommonNavigator) activePart).selectReveal(new StructuredSelection(files[0]));
            }
            // else if (activePart instanceof ISetSelectionTarget) {
            // ((ISetSelectionTarget)activePart).selectReveal(new StructuredSelection(files[0]));
            // }

            IEditorInput editorInput = new FileEditorInput(files[0]);
            try {
                IWorkbenchPage activePage = activePart.getSite().getPage();
                activePage.openEditor(editorInput, editorID);
            } catch (PartInitException e) {
            }

            // display these last so that the error console will display after Rational console
            ConsoleUtil.logToConsole(importer.getDiagnostics());

        }
    } catch (Exception e) {
        e.printStackTrace();
        ConsoleUtil.showConsole(ConsoleUtil.DEFAULT_CONSOLE_NAME);
        ConsoleUtil.printError(ConsoleUtil.DEFAULT_CONSOLE_NAME, e.toString());
    } finally {
        progressDialog.close();
    }
}

From source file:org.pentaho.di.core.market.Market.java

License:Apache License

/**
 * Installs the passed MarketEntry into the folder built by buildPluginsFolderPath(marketEntry).
 * /*from w  ww  . j a  v  a  2 s  .  c om*/
 * A warning dialog box is displayed if the plugin folder already exists. If the user chooses to install then the
 * plugin folder is deleted and then recreated.
 * 
 * @param marketEntry
 * @throws KettleException
 */
public static void install(final MarketEntry marketEntry, ProgressMonitorDialog monitorDialog)
        throws KettleException {
    String parentFolderName = buildPluginsFolderPath(marketEntry);

    // Until plugin dependencies are implemented, check that the pentaho-big-data-plugin directory exists
    // before installing anything of type HadoopShim
    if (marketEntry.getType().equals(MarketEntryType.HadoopShim)) {

        File bdPluginFolder = new File(parentFolderName).getParentFile();
        if (bdPluginFolder == null || !bdPluginFolder.exists()) {
            throw new KettleException(BaseMessages.getString(PKG,
                    "Marketplaces.Dialog.PluginNotInstalled.message", "Pentaho Big Data Plugin")
                    + ". You must install the Pentaho Big Data plugin before you can install a Hadoop Shim");
        }
    }

    File pluginFolder = new File(parentFolderName + File.separator + marketEntry.getId());
    LogChannel.GENERAL.logBasic("Installing plugin in folder: " + pluginFolder.getAbsolutePath());
    if (pluginFolder.exists()) {
        monitorDialog.close();
        MessageBox mb = new MessageBox(Spoon.getInstance().getShell(), SWT.NO | SWT.YES | SWT.ICON_WARNING);
        mb.setMessage(BaseMessages.getString(PKG, "Marketplace.Dialog.PromptOverwritePlugin.Message",
                pluginFolder.getAbsolutePath()));
        mb.setText(BaseMessages.getString(PKG, "Marketplace.Dialog.PromptOverwritePlugin.Title"));
        int answer = SWT.NO;
        answer = mb.open();
        if (answer == SWT.YES) {
            monitorDialog.open();
            ClassLoader cl = PluginRegistry.getInstance().getClassLoader(getPluginObject(marketEntry.getId()));
            if (cl instanceof KettleURLClassLoader) {
                ((KettleURLClassLoader) cl).closeClassLoader();
            }
            deleteDirectory(pluginFolder);
            unzipMarketEntry(parentFolderName, marketEntry.getPackageUrl());
            if (Market.discoverInstalledVersion(marketEntry).equalsIgnoreCase("unknown")) {
                createVersionXML(marketEntry);
            }
            refreshSpoon(monitorDialog);
        }
    } else {
        unzipMarketEntry(parentFolderName, marketEntry.getPackageUrl());
        if (Market.discoverInstalledVersion(marketEntry).equalsIgnoreCase("unknown")) {
            createVersionXML(marketEntry);
        }
        refreshSpoon(monitorDialog);
    }
}

From source file:org.salever.swtjface.demo.processbar.ProgressBars.java

License:Open Source License

/**
 * Open a progress monitor dialog and switch the blocking.
 * /*from  w ww .  ja v  a 2s .  co m*/
 * @param args
 */
public static void main(String[] args) {

    final Display display = new Display();
    Shell shell = new Shell(display);

    final ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);

    try {
        dialog.run(true, false, new IRunnableWithProgress() {
            /*
             * (non-Javadoc)
             * 
             * @see
             * org.eclipse.jface.operation.IRunnableWithProgress#run(org
             * .eclipse.core.runtime.IProgressMonitor)
             */
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {

                IProgressMonitorWithBlocking blocking = (IProgressMonitorWithBlocking) monitor;

                blocking.beginTask("Job......", IProgressMonitor.UNKNOWN);

                work();

                blocking.done();
                display.syncExec(new Runnable() {
                    @Override
                    public void run() {
                        MessageDialog.openInformation(display.getActiveShell(), "OK", "Job    OK.");

                    }

                });

            }
        });
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        System.out.println(e.getMessage());
        MessageDialog.openError(null, "Error", "Job failed.");
        e.printStackTrace();
    }

    if (dialog.open() == Window.OK) {
        System.out.println("OK");
    } else {
        System.out.println("Cancel");
    }

    display.dispose();
}

From source file:org.schwiebert.cloudio.application.actions.LoadFileAction.java

License:Open Source License

@Override
public void run(IAction action) {
    FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);

    dialog.setText("Select text file...");
    String sourceFile = dialog.open();
    if (sourceFile == null)
        return;/*from w ww  . j  av  a  2 s . c om*/
    ProgressMonitorDialog pd = new ProgressMonitorDialog(getShell());
    try {
        List<Type> types = TypeCollector.getData(new File(sourceFile), "UTF-8");
        pd.setBlockOnOpen(false);
        pd.open();
        pd.getProgressMonitor().beginTask("Generating cloud...", 200);
        TagCloudViewer viewer = getViewer();
        viewer.setInput(types, pd.getProgressMonitor());
        long start = System.currentTimeMillis();
        viewer.getCloud().layoutCloud(pd.getProgressMonitor(), false);
        long end = System.currentTimeMillis();
        System.out.println("Layouted: " + (end - start));
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        pd.close();
    }
}

From source file:org.talend.commons.ui.swt.dialogs.ProgressDialog.java

License:Open Source License

public void executeProcess(boolean useAsync) throws InvocationTargetException, InterruptedException {
    Display display2 = null;//from  w w  w.j a  va  2s  . c om
    if (parentShell != null) {
        display2 = parentShell.getDisplay();
    }
    final Display display = display2;
    final InvocationTargetException[] iteHolder = new InvocationTargetException[1];
    try {
        final IRunnableWithProgress op = new IRunnableWithProgress() {

            public void run(final IProgressMonitor monitor)
                    throws InvocationTargetException, InterruptedException {
                final InvocationTargetException[] iteHolder1 = new InvocationTargetException[1];
                try {
                    ProgressDialog.this.run(monitor);
                } catch (InvocationTargetException e) {
                    // Pass it outside the workspace runnable
                    iteHolder1[0] = e;
                } catch (InterruptedException e) {
                    // Re-throw as OperationCanceledException, which will be
                    // caught and re-thrown as InterruptedException below.
                    throw new OperationCanceledException(e.getMessage());
                }
                // CoreException and OperationCanceledException are propagated

                // Re-throw the InvocationTargetException, if any occurred
                if (iteHolder1[0] != null) {
                    throw iteHolder1[0];
                }
            }
        };

        if (useAsync) {
            display.asyncExec(new Runnable() {

                public void run() {
                    final ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(parentShell);
                    if (timeBeforeShowDialog > 0) {
                        progressMonitorDialog.setOpenOnRun(false);
                        // for bug 16801
                        AsynchronousThreading asynchronousThreading = new AsynchronousThreading(
                                timeBeforeShowDialog, true, display, new Runnable() {

                                    public void run() {
                                        progressMonitorDialog.open();
                                    }
                                });
                        asynchronousThreading.start();
                    }

                    try {
                        progressMonitorDialog.run(false, true, op);
                    } catch (InvocationTargetException e) {
                        // Pass it outside the workspace runnable
                        iteHolder[0] = e;
                    } catch (InterruptedException e) {
                        // Re-throw as OperationCanceledException, which will be
                        // caught and re-thrown as InterruptedException below.
                        throw new OperationCanceledException(e.getMessage());
                    }
                }
            });
        } else {
            display.syncExec(new Runnable() {

                public void run() {
                    final ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(parentShell);
                    if (timeBeforeShowDialog > 0) {
                        progressMonitorDialog.setOpenOnRun(false);
                        // for bug 16801
                        AsynchronousThreading asynchronousThreading = new AsynchronousThreading(
                                timeBeforeShowDialog, true, display, new Runnable() {

                                    public void run() {
                                        progressMonitorDialog.open();
                                    }
                                });
                        asynchronousThreading.start();
                    }

                    try {
                        progressMonitorDialog.run(false, true, op);
                    } catch (InvocationTargetException e) {
                        // Pass it outside the workspace runnable
                        iteHolder[0] = e;
                    } catch (InterruptedException e) {
                        // Re-throw as OperationCanceledException, which will be
                        // caught and re-thrown as InterruptedException below.
                        throw new OperationCanceledException(e.getMessage());
                    }
                }
            });
        }

    } catch (OperationCanceledException e) {
        throw new InterruptedException(e.getMessage());
    }
    // Re-throw the InvocationTargetException, if any occurred
    if (iteHolder[0] != null) {
        throw iteHolder[0];
    }
}

From source file:org.talend.designer.runtime.visualization.internal.actions.OpenDeclarationAction.java

License:Open Source License

/**
 * Searches the source for the given class name with progress monitor.
 * //from  ww  w . j  av a 2 s.  c om
 * @return The source
 * @throws InterruptedException if operation is canceled
 */
private IType searchSource() throws InterruptedException {
    final ProgressMonitorDialog dialog = new ProgressMonitorDialog(
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
    dialog.setOpenOnRun(false);

    // search source corresponding to the class name
    final IType[] source = new IType[1];
    IRunnableWithProgress op = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            if (!searchEngineInitialized) {
                monitor.subTask(Messages.searchingSoruceMsg);
                searchEngineInitialized = true;
            }

            // open progress monitor dialog when it takes long time
            new Timer().schedule(new TimerTask() {

                @Override
                public void run() {
                    Display.getDefault().syncExec(new Runnable() {

                        @Override
                        public void run() {
                            dialog.open();
                        }
                    });
                }
            }, 400);

            if (className == null) {
                return;
            }

            try {
                source[0] = doSearchSource(className);
            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            }
            if (monitor.isCanceled()) {
                throw new InterruptedException();
            }
        }
    };

    try {
        dialog.run(true, true, op);
    } catch (InvocationTargetException e) {
        Activator.log(IStatus.ERROR, NLS.bind(Messages.searchClassFailedMsg, className), e);
    }

    return source[0];
}

From source file:org.testeditor.ui.handlers.SaveHandler.java

License:Open Source License

/**
 * execute the save operation.// w w  w . ja  v a 2 s.  c  o  m
 * 
 * @param context
 *            Eclipse Context
 * @param shell
 *            active Shell
 * @param partService
 *            used to refresh the ui.
 * @throws InvocationTargetException
 *             on error
 * @throws InterruptedException
 *             of the Progress Monitor
 */
@Execute
public void execute(IEclipseContext context, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
        EPartService partService) throws InvocationTargetException, InterruptedException {
    final IEclipseContext pmContext = context.createChild();
    final MPart activeDirtyPart = getActiveDirtyPart(partService);
    if (activeDirtyPart != null) {

        final Object clientObject = activeDirtyPart.getObject();

        ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
        dialog.open();
        dialog.run(true, true, new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {

                pmContext.set(IProgressMonitor.class.getName(), monitor);

                ContextInjectionFactory.invoke(clientObject, Persist.class, pmContext, null);

            }

        });
        if (activeDirtyPart.getObject() instanceof ITestStructureEditor) {
            TestProject testProject = ((ITestStructureEditor) activeDirtyPart.getObject()).getTestStructure()
                    .getRootElement();
            if (testProject.getTestProjectConfig().isTeamSharedProject()) {

                TeamShareStatus shareState = new TeamShareStatus(eventBroker);
                shareState.setSVNStatusForProject(testProject);

            }
        }
        refreshNodeIcon(partService);

    }

    pmContext.dispose();

}

From source file:org.testeditor.ui.uiscanner.ui.handler.ScanHandler.java

License:Open Source License

/**
 * // ww w  .  ja va  2  s. c  o  m
 * @param shell
 *            Shell
 * @param webScanner
 *            WebScanner
 * @param filters
 *            ArrayList<String>
 * @param xPath
 *            String
 * @param webElements
 *            ArrayList<UiScannerWebElement>
 * @throws InvocationTargetException
 *             InvocationTargetException
 * @throws InterruptedException
 *             InterruptedException
 */
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell, final WebScanner webScanner,
        final ArrayList<String> filters, final String xPath, final ArrayList<UiScannerWebElement> webElements)
        throws InvocationTargetException, InterruptedException {

    ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
    dialog.open();
    dialog.run(true, true, new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            monitor.beginTask(translate.translate("%PROGRESS_SCAN_WEBSITE"), filters.size());
            for (UiScannerWebElement elem : webScanner.scanWebsite(filters, xPath, monitor)) {
                webElements.add(elem);
            }
        }
    });
}

From source file:org.webcat.eclipse.submitter.ui.SubmitterUIPlugin.java

License:Open Source License

/**
 * Initializes the submission engine and invokes the submission wizard.
 * /*from   w  w  w  . jav  a  2s  . co  m*/
 * @param shell the shell that will be the parent to the wizard
 * @param project the Eclipse project to be submitted
 */
public void spawnSubmissionUI(Shell shell, IProject project) {
    URL url;
    Submitter engine = new Submitter();

    try {
        url = new URL(SubmitterCore.getDefault().getOption(SubmitterCore.DEFINITIONS_URL));

        ProgressMonitorDialog dlg = new ProgressMonitorDialog(shell);

        RunnableContextLongRunningTaskManager taskManager = new RunnableContextLongRunningTaskManager(dlg);
        engine.setLongRunningTaskManager(taskManager);

        engine.readSubmissionTargets(url);

        engine.setLongRunningTaskManager(null);
    } catch (MalformedURLException e) {
        MessageDialog.openWarning(null, Messages.PLUGINUI_NO_DEF_URL_TITLE,
                Messages.PLUGINUI_NO_DEF_URL_DESCRIPTION);
        return;
    } catch (Throwable e) {
        SubmissionParserErrorDialog dlg = new SubmissionParserErrorDialog(shell, e);
        dlg.open();

        return;
    }

    SubmitterWizard wizard = new SubmitterWizard();
    wizard.init(engine, project);

    // Instantiates the wizard container with the wizard and opens it
    WizardDialog dialog = new WizardDialog(shell, wizard);
    dialog.open();
}