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

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

Introduction

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

Prototype

@Override
public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
        throws InvocationTargetException, InterruptedException 

Source Link

Document

This implementation of IRunnableContext#run(boolean, boolean, IRunnableWithProgress) runs the given IRunnableWithProgress using the progress monitor for this progress dialog and blocks until the runnable has been run, regardless of the value of fork.

Usage

From source file:com.astra.ses.spell.gui.model.commands.helpers.CommandHelper.java

License:Open Source License

public static void executeInProgress(IRunnableWithProgress job, boolean cancellable, boolean fork) {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(window.getShell());
    try {//  w  ww. j  av  a2  s  .c  o m
        dialog.setCancelable(cancellable);
        dialog.run(fork, cancellable, job);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:com.bdaum.zoom.db.internal.DbManager.java

License:Open Source License

public void checkDbSanity(final boolean force) {
    // MessageDialog.openInformation(null, "", systemInfo.freespaceSize()
    // + ", " + systemInfo.totalSize() + "; "
    // + systemInfo.freespaceEntryCount());
    if (!emergency)
        try {//from  w  w  w.  ja  v  a  2  s. c o m
            if (force || needsDefragmentation()) {
                Meta meta1 = getMeta(false);
                boolean hasBackups = meta1 == null
                        || meta1.getBackupLocation() != null && !meta1.getBackupLocation().isEmpty();
                if (force || hasBackups
                        || factory.getErrorHandler().question(Messages.DbManager_Catalog_maintenance,
                                Messages.DbManager_The_cat_seems_to_be_fragmented, this)) {
                    SystemInfo systemInfo = getSystemInfo();
                    long totalSize = systemInfo.totalSize();
                    long freespaceSize = systemInfo.freespaceSize();
                    long occupiedspaceSize = totalSize - freespaceSize;
                    final long reserve = isReadOnly() ? occupiedspaceSize / 100 : occupiedspaceSize / 20;
                    final long defragSpaceSize = occupiedspaceSize + reserve;
                    long requiredSpace = defragSpaceSize + (force ? 0 : totalSize);
                    long availableSpace = file.getUsableSpace();
                    if (availableSpace < requiredSpace) {
                        factory.getErrorHandler().showError(Messages.DbManager_Catalog_maintenance, NLS.bind(
                                Messages.DbManager_not_enough_disc_space, requiredSpace, availableSpace), this);
                        return;
                    }
                    final String backupPath = fileName + ".defrag"; //$NON-NLS-1$
                    File backup = new File(backupPath);
                    ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
                    try {
                        dialog.run(true, false, new IRunnableWithProgress() {

                            public void run(IProgressMonitor monitor)
                                    throws InvocationTargetException, InterruptedException {
                                try {
                                    monitor.beginTask(NLS.bind(Messages.DbManager_Defragmenting_, fileName),
                                            IProgressMonitor.UNKNOWN);
                                    if (!force) {
                                        monitor.subTask(Messages.DbManager_backing_up_cat);
                                        performBackup(0L, -1L, true);
                                    }

                                    db.close();
                                    db = null;
                                    monitor.subTask(Messages.DbManager_defragmenting_cat);

                                    DefragmentConfig config = new DefragmentConfig(fileName, backupPath);
                                    boolean fileNeedsUpgrade = config.fileNeedsUpgrade();
                                    EmbeddedConfiguration ef = createDatabaseConfiguration(fileNeedsUpgrade,
                                            fileName, defragSpaceSize);
                                    try {
                                        defragment(fileName, backupPath, ef);
                                        ef = createDatabaseConfiguration(false, fileName, -1L);
                                        db = Db4oEmbedded.openFile(ef, fileName);
                                        SystemInfo systemInfo = getSystemInfo();
                                        long newFreespaceSize = systemInfo.freespaceSize();
                                        long newTotalSize = systemInfo.totalSize();
                                        db.close();
                                        db = null;
                                        if (newFreespaceSize > 3 * reserve) {
                                            monitor.subTask(Messages.DbManager_defrag_cat_2);
                                            long newOccupiedspaceSize = newTotalSize - newFreespaceSize;
                                            long newReserve = isReadOnly() ? newOccupiedspaceSize / 100
                                                    : newOccupiedspaceSize / 20;
                                            long newDefragSpaceSize = newOccupiedspaceSize + newReserve;
                                            ef = createDatabaseConfiguration(fileNeedsUpgrade, fileName,
                                                    newDefragSpaceSize);
                                            defragment(fileName, backupPath, ef);
                                        }
                                    } catch (Exception e) {
                                        File target = new File(fileName);
                                        target.delete();
                                        new File(backupPath).renameTo(target);
                                        throw new InvocationTargetException(e);
                                    }
                                    if (fileNeedsUpgrade) {
                                        monitor.subTask(Messages.DbManager_updating_database_version);
                                        db = Db4oEmbedded.openFile(ef, fileName);
                                        db.close();
                                        db = null;
                                        DbActivator.getDefault()
                                                .logInfo(NLS.bind(
                                                        Messages.DbManager_database_converted_to_version_n,
                                                        Db4o.version()));
                                    }
                                } finally {
                                    if (db == null)
                                        db = createDatabase(fileName, false);
                                }
                            }
                        });
                    } catch (InvocationTargetException e1) {
                        factory.getErrorHandler().showError(Messages.DbManager_Defrag_error,
                                NLS.bind(Messages.DbManager_Defrag_failed, e1.getCause()), this);
                        DbActivator.getDefault().logError(Messages.DbManager_Defrag_error, e1);
                        return;
                    } catch (InterruptedException e1) {
                        // should never happen
                    } finally {
                        if (!file.exists()) {
                            if (backup.exists())
                                backup.renameTo(file);
                            DbActivator.getDefault().logError(Messages.DbManager_defragmentation_failed, null);
                            return;
                        }
                    }
                    backup.delete();
                    DbActivator.getDefault().logInfo(Messages.DbManager_defragmentation_successfiul);
                }
            }
        } catch (Throwable e) {
            DbActivator.getDefault().logError(Messages.DbManager_error_checking_sanity, e);
        }
}

From source file:com.bdaum.zoom.db.internal.DbManager.java

License:Open Source License

public void pruneEmptySystemCollections() {
    if (!readOnly && hasDirtyCollection()) {
        IRunnableWithProgress runnable = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                pruneEmptySystemCollections(monitor, false);
            }//from  www . j  a v  a 2s  .  com
        };
        try {
            IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
            if (workbenchWindow != null) {
                ProgressMonitorDialog dialog = new ProgressMonitorDialog(workbenchWindow.getShell());
                dialog.create();
                dialog.getShell().setText(Constants.APPLICATION_NAME);
                dialog.run(false, true, runnable);
            } else
                runnable.run(new NullProgressMonitor());
        } catch (InvocationTargetException e) {
            // ignore
        } catch (InterruptedException e) {
            // ignore
        }
    }
}

From source file:com.binge.workforce.app.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();/*  w  w w.j av a2  s .  c o m*/
    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:com.centurylink.mdw.plugin.actions.ProjectUpdateAction.java

License:Apache License

/**
 * @see IActionDelegate#run(IAction)/*from   w  w  w  .j a  v a2 s.  c o m*/
 */
public void run(final IAction action) {
    IProject project = null;
    WorkflowProject workflowProject = null;
    try {
        if (selection instanceof IStructuredSelection
                && ((IStructuredSelection) selection).getFirstElement() instanceof IProject) {
            project = (IProject) ((IStructuredSelection) selection).getFirstElement();
            workflowProject = WorkflowProjectManager.getInstance().getWorkflowProject(project);
        }
        if (workflowProject == null) {
            MessageDialog.openError(shell, "MDW Update", "Selection must be a Workflow project.");
            return;
        }

        final ProjectUpdater updater = new ProjectUpdater(workflowProject, MdwPlugin.getSettings());

        if (action.getId().equals("mdw.workflow.updateFrameworkJars")) {
            updater.updateFrameworkJars(null);
            ExtensionModulesUpdater modulesUpdater = new ExtensionModulesUpdater(workflowProject);
            modulesUpdater.doUpdate(shell);
        } else if (action.getId().equals("mdw.workflow.associateFrameworkSourceCode")) {
            ProgressMonitorDialog pmDialog = new MdwProgressMonitorDialog(shell);
            final WorkflowProject wfProject = workflowProject;
            pmDialog.run(true, false, new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    monitor.beginTask("Setting Java source attachment locations", 100);
                    monitor.worked(20);
                    ProjectConfigurator configurator = new ProjectConfigurator(wfProject,
                            MdwPlugin.getSettings());
                    try {
                        configurator.createFrameworkSourceCodeAssociations(shell, monitor);
                    } catch (CoreException ex) {
                        PluginMessages.log(ex);
                    }
                }
            });
        }
    } catch (Exception ex) {
        PluginMessages.log(ex);
    }
}

From source file:com.centurylink.mdw.plugin.actions.WebUpdateAction.java

License:Apache License

/**
 * @see IActionDelegate#run(IAction)//w  w  w  .  j av a 2s.c o m
 */
public void run(final IAction action) {
    IProject webProject = null;
    WorkflowProject workflowProject = null;
    try {
        if (selection instanceof IStructuredSelection
                && ((IStructuredSelection) selection).getFirstElement() instanceof IProject) {
            webProject = (IProject) ((IStructuredSelection) selection).getFirstElement();
            workflowProject = WorkflowProjectManager.getInstance().getWorkflowProject(webProject);
        }
        if (workflowProject == null) {
            MessageDialog.openError(shell, "MDW Update",
                    "Selection must be a Workflow Web project.\n(Try refreshing Process Explorer view.)");
            return;
        }

        ProjectUpdater updater = new ProjectUpdater(workflowProject, MdwPlugin.getSettings());

        if (action.getId().equals("mdw.workflow.updateFrameworkWebJars")) {
            updater.updateWebProjectJars(null);
        } else if (action.getId().equals("mdw.workflow.associateWebAppSourceCode")) {
            ProgressMonitorDialog pmDialog = new MdwProgressMonitorDialog(shell);
            final WorkflowProject wfProject = workflowProject;
            pmDialog.run(true, false, new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    monitor.beginTask("Setting Java source attachment locations", 100);
                    monitor.worked(20);
                    ProjectConfigurator configurator = new ProjectConfigurator(wfProject,
                            MdwPlugin.getSettings());
                    try {
                        configurator.createWebProjectSourceCodeAssociations(shell, monitor);
                    } catch (CoreException ex) {
                        PluginMessages.log(ex);
                    }
                }
            });
        }
    } catch (Exception ex) {
        PluginMessages.log(ex);
    }
}

From source file:com.centurylink.mdw.plugin.actions.WorkflowElementActionHandler.java

License:Apache License

public void remoteImportVcs(final WorkflowProject workflowProject) {
    VcsRepository repo = workflowProject.getMdwVcsRepository();
    String msg = "Pull latest assets into " + workflowProject.getName() + " from Git branch: "
            + repo.getBranch() + "?";
    boolean proceed = MessageDialog.openConfirm(getShell(), "Import from VCS", msg);
    if (proceed) {
        ProgressMonitorDialog pmDialog = new MdwProgressMonitorDialog(getShell());
        try {/*www. j  a v a 2s  .c om*/
            pmDialog.run(true, false, new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    monitor.beginTask("Importing remote project from Git...", IProgressMonitor.UNKNOWN);
                    monitor.worked(20);
                    try {
                        workflowProject.getDesignerProxy().remoteImportVcs();
                    } catch (Exception ex) {
                        PluginMessages.log(ex);
                        throw new InvocationTargetException(ex);
                    }
                }
            });
        } catch (Exception ex) {
            PluginMessages.uiError(getShell(), ex, "Import From VCS", workflowProject);
        }
    }
}

From source file:com.centurylink.mdw.plugin.actions.WorkflowElementActionHandler.java

License:Apache License

public void syncOpenEditors(final WorkflowProject project) {
    final WorkflowProjectManager projectMgr = WorkflowProjectManager.getInstance();
    final List<ProcessEditor> processEditors = getOpenProcessEditors(project);
    final List<IEditorPart> assetEditors = getOpenAssetEditors(project);

    if (!processEditors.isEmpty() || !assetEditors.isEmpty()) {
        // sync open editors
        IRunnableWithProgress loader = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Loading " + project.getLabel(), 100);
                monitor.worked(25);//from  w  ww  . j  av  a 2  s.  c om

                // sync process editors
                for (ProcessEditor ed : processEditors) {
                    WorkflowProcess pv = ed.getProcess();
                    pv.setProject(projectMgr.getWorkflowProject(pv.getProject().getName()));
                    if (pv.getPackage() != null && !pv.getPackage().isDefaultPackage()) {
                        WorkflowPackage pkg = pv.getProject().getPackage(pv.getPackage().getName());
                        WorkflowProcess oldPv = pkg.getProcess(pv.getName());
                        if (oldPv != null)
                            pkg.removeProcess(oldPv);
                        pkg.addProcess(pv);
                        pv.setPackage(pkg);
                    }
                }
                monitor.worked(50);
                // sync asset editors
                Map<IFile, AssetWorkbenchListener> assetListeners = WorkflowAssetFactory
                        .getWorkbenchListeners();
                for (IEditorPart assetEd : assetEditors) {
                    FileEditorInput fileInput = (FileEditorInput) assetEd.getEditorInput();
                    AssetWorkbenchListener wbListener = assetListeners.get(fileInput.getFile());
                    if (wbListener != null) {
                        WorkflowAsset asset = wbListener.getAsset();
                        WorkflowProject wfProj = projectMgr.getWorkflowProject(asset.getProject().getName());
                        WorkflowAsset oldAsset = wfProj.getAsset(asset.getName(), asset.getLanguage(),
                                asset.getVersion());
                        if (asset.getPackage() != null && !asset.getPackage().isDefaultPackage()) {
                            WorkflowPackage pkg = wfProj.getPackage(asset.getPackage().getName());
                            if (pkg != null) {
                                pkg.removeAsset(oldAsset);
                                pkg.addAsset(asset);
                                asset.setPackage(pkg);
                            } else {
                                asset.setPackage(wfProj.getDefaultPackage());
                            }
                        } else {
                            asset.setPackage(wfProj.getDefaultPackage());
                        }

                        asset.addElementChangeListener(wfProj);

                        if (oldAsset != null)
                            WorkflowAssetFactory.deRegisterAsset(oldAsset);
                        WorkflowAssetFactory.registerAsset(asset);
                        assetEd.addPropertyListener(asset.new AssetEditorPropertyListener(assetEd));
                        WorkflowAssetFactory.registerWorkbenchListener(fileInput.getFile(), wbListener);
                    }
                }
                monitor.worked(25);
                monitor.done();
            }
        };

        ProgressMonitorDialog progMonDlg = new MdwProgressMonitorDialog(Display.getCurrent().getActiveShell());
        try {
            progMonDlg.run(true, false, loader);
        } catch (Exception ex) {
            PluginMessages.uiError(ex, "Sync Open Editors", project);
        }

    }
}

From source file:com.centurylink.mdw.plugin.designer.model.Template.java

License:Apache License

public void runWith(final String inputPath, final String outputLocation, final String velocityPropFile,
        final String velocityToolboxFile) {
    try {/*from  w w  w. j  av a 2s .  co m*/
        VelocityEngine engine = new VelocityEngine();
        Properties vProps = new Properties();
        if (velocityPropFile != null && velocityPropFile.length() > 0)
            vProps.load(new FileInputStream(velocityPropFile));
        String loadPath = vProps.getProperty("file.resource.loader.path");
        String tempFolder = getTempFolder().getLocation().toString();
        if (loadPath == null)
            loadPath = tempFolder;
        else
            loadPath += "," + tempFolder;
        vProps.setProperty("file.resource.loader.path", loadPath);
        engine.init(vProps);

        final VelocityContext velocityContext = getVelocityContext(velocityToolboxFile);

        final org.apache.velocity.Template velocityTemplate = engine.getTemplate(getTempFileName());

        final java.io.File input = new java.io.File(inputPath);
        if (input.isDirectory()) {
            ProgressMonitorDialog pmDialog = new MdwProgressMonitorDialog(
                    MdwPlugin.getActiveWorkbenchWindow().getShell());
            pmDialog.run(true, false, new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    java.io.File[] inputFiles = input.listFiles();
                    monitor.beginTask("Creating output files", inputFiles.length);
                    for (java.io.File inputFile : inputFiles) {
                        if (!inputFile.isDirectory()) {
                            String outputFile = outputLocation + "/" + getOutputFileName(inputFile.getName());
                            monitor.subTask(inputFile.getName());
                            InputStream inputStream = null;
                            try {
                                inputStream = new FileInputStream(inputFile);
                                processInput(inputStream, outputLocation, outputFile, velocityContext,
                                        velocityTemplate);
                            } catch (Exception ex) {
                                throw new InvocationTargetException(ex,
                                        "Problem applying input:\n'" + inputFile.getName() + "'");
                            } finally {
                                if (inputStream != null) {
                                    try {
                                        inputStream.close();
                                    } catch (Exception ex) {
                                    }
                                }

                            }
                        }
                        monitor.worked(1);
                    }
                }
            });

        } else {
            int sepIdx = inputPath.lastIndexOf(System.getProperty("file.separator"));
            String inputFileName = sepIdx == -1 ? inputPath : inputPath.substring(sepIdx + 1);
            String outputFile = outputLocation + "/" + getOutputFileName(inputFileName);
            processInput(new FileInputStream(inputPath), outputLocation, outputFile, velocityContext,
                    velocityTemplate);

            final IWorkbenchPage page = MdwPlugin.getActivePage();
            if (page != null) {
                IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(outputFile));
                IDE.openEditorOnFileStore(page, fileStore);
            }
        }
    } catch (InvocationTargetException ex) {
        PluginMessages.log(ex);
        String message = ex.getMessage() + ":\n\nCause:\n---------\n" + PluginMessages.getRootCause(ex);
        PluginMessages.uiError(message, "Run Template", getProject());
    } catch (Exception ex) {
        PluginMessages.uiError(ex, "Run Template", getProject());
    }
}

From source file:com.centurylink.mdw.plugin.designer.ToolboxWrapper.java

License:Apache License

/**
 * Reloads from the database./*w ww  .  j  av  a2s  .co  m*/
 */
public void refresh() {
    try {
        IRunnableWithProgress loader = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                ProgressMonitor progressMonitor = new SwtProgressMonitor(monitor);
                progressMonitor.start("Loading Activity Implementors for " + getProject().getLabel());
                progressMonitor.progress(25);
                getProject().reloadActivityImplementors();
                progressMonitor.done();
            }
        };
        ProgressMonitorDialog progMonDlg = new MdwProgressMonitorDialog(Display.getCurrent().getActiveShell());
        progMonDlg.run(true, false, loader);
    } catch (Exception ex) {
        PluginMessages.uiError(ex, "Refresh Implementors", getProject());
    }
    update();
    clearDirty();
}