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:com.microsoft.azuretools.webapp.ui.AppServiceCreateDialog.java

License:Open Source License

@Override
protected void okPressed() {
    if (validated()) {
        String errTitle = "Create App Service Error";
        try {/* ww w  . j  a va2  s .  c  om*/
            ProgressDialog.get(this.getShell(), "Create App Service Progress").run(true, true,
                    new IRunnableWithProgress() {
                        @Override
                        public void run(IProgressMonitor monitor) {
                            monitor.beginTask("Creating App Service....", IProgressMonitor.UNKNOWN);
                            if (monitor.isCanceled()) {
                                AzureModel.getInstance().setResourceGroupToWebAppMap(null);
                                Display.getDefault().asyncExec(new Runnable() {
                                    @Override
                                    public void run() {
                                        AppServiceCreateDialog.super.cancelPressed();
                                    }
                                });
                            }

                            try {
                                webApp = WebAppUtils.createAppService(new UpdateProgressIndicator(monitor),
                                        model);
                                Display.getDefault().asyncExec(new Runnable() {
                                    @Override
                                    public void run() {
                                        AppServiceCreateDialog.super.okPressed();
                                    };
                                });
                            } catch (Exception ex) {
                                ex.printStackTrace();
                                LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
                                        "run@ProgressDialog@okPressed@AppServiceCreateDialog", ex));
                                Display.getDefault().asyncExec(new Runnable() {
                                    @Override
                                    public void run() {
                                        ErrorWindow.go(getShell(), ex.getMessage(), errTitle);
                                        ;
                                    }
                                });

                            }
                        }
                    });
        } catch (InvocationTargetException | InterruptedException ex) {
            ex.printStackTrace();
            LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "okPressed@AppServiceCreateDialog", ex));
            ErrorWindow.go(getShell(), ex.getMessage(), errTitle);
            ;
        }
    }
}

From source file:com.minres.scviewer.ui.TxEditorPart.java

License:Open Source License

protected void loadDatabases() throws IOException, InvocationTargetException, InterruptedException {
    IWorkbench wb = PlatformUI.getWorkbench();
    IProgressService ps = wb.getProgressService();
    IEditorInput input = getEditorInput();
    File file = null;//from   w  ww  .  j  ava2 s  .  c om
    boolean loadSecondary = false;
    boolean dontAskForSecondary = false;
    ArrayList<File> filesToLoad = new ArrayList<File>();
    if (input instanceof TxEditorInput) {
        TxEditorInput txInput = (TxEditorInput) input;
        file = txInput.getFile().getLocation().toFile();
        loadSecondary = txInput.isSecondaryLoaded() == null || txInput.isSecondaryLoaded();
        dontAskForSecondary = txInput.isSecondaryLoaded() != null;
    } else if (input instanceof FileStoreEditorInput) {
        file = new File(((FileStoreEditorInput) input).getURI().getPath());
    }
    if (file.exists()) {
        filesToLoad.add(file);
        if (loadSecondary) {
            String ext = getFileExtension(file.getName());
            if ("vcd".equals(ext.toLowerCase())) {
                if (dontAskForSecondary
                        || askIfToLoad(new File(renameFileExtension(file.getCanonicalPath(), "txdb")))) {
                    filesToLoad.add(new File(renameFileExtension(file.getCanonicalPath(), "txdb")));
                    if (input instanceof TxEditorInput)
                        ((TxEditorInput) input).setSecondaryLoaded(true);
                } else if (dontAskForSecondary
                        || askIfToLoad(new File(renameFileExtension(file.getCanonicalPath(), "txlog")))) {
                    filesToLoad.add(new File(renameFileExtension(file.getCanonicalPath(), "txlog")));
                    if (input instanceof TxEditorInput)
                        ((TxEditorInput) input).setSecondaryLoaded(true);
                }
            } else if ("txdb".equals(ext.toLowerCase()) || "txlog".equals(ext.toLowerCase())) {
                if (dontAskForSecondary
                        || askIfToLoad(new File(renameFileExtension(file.getCanonicalPath(), "vcd")))) {
                    filesToLoad.add(new File(renameFileExtension(file.getCanonicalPath(), "vcd")));
                    if (input instanceof TxEditorInput)
                        ((TxEditorInput) input).setSecondaryLoaded(true);
                }
            }
        }

    }
    final File[] files = filesToLoad.toArray(new File[filesToLoad.size()]);
    ps.run(true, false, new IRunnableWithProgress() {
        //ps.busyCursorWhile(new IRunnableWithProgress() {
        public void run(IProgressMonitor pm) throws InvocationTargetException {
            pm.beginTask("Loading database " + files[0].getName(), files.length);
            try {
                database.load(files[0]);
                database.addPropertyChangeListener(txDisplay);
                pm.worked(1);
                if (pm.isCanceled())
                    return;
                if (files.length == 2) {
                    database.load(files[1]);
                    pm.worked(1);
                }
                myParent.getDisplay().syncExec(new Runnable() {
                    @Override
                    public void run() {
                        updateTxDisplay();
                    }
                });
            } catch (Exception e) {
                database = null;
                throw new InvocationTargetException(e);
            }
            pm.done();
        }
    });
}

From source file:com.mmkarton.mx7.reportgenerator.wizards.BIRTDataSetWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    final String query = sqlpage.getQueryText();
    final String fileName = reportFileName;
    final String dataSetName = datasetpage.getDataSetNameText();

    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            try {
                doFinish(fileName, dataSetName, query, monitor);
            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            } finally {
                monitor.done();// ww w .  jav  a 2 s . c o  m
            }
        }
    };
    try {
        getContainer().run(true, false, op);
    } catch (InterruptedException e) {
        return false;
    } catch (InvocationTargetException e) {
        Throwable realException = e.getTargetException();
        MessageDialog.openError(getShell(), "Error", realException.getMessage());
        return false;
    }
    return true;
}

From source file:com.mmkarton.mx7.reportgenerator.wizards.BIRTReportWizard.java

License:Open Source License

public boolean performFinish() {
    final String containerName = page.getContainerName(); //Report Directory
    final String fileName = page.getFileName(); //New-Report Filename
    final String templatefile = page.getReportTemplateText(); //Report Template Filename
    final String query = sqlpage.getQueryText(); //SQL-Query Text

    final String reportTitle = page.getReportTitleText();
    final String reportDescription = page.getReportDescriptionText();
    final String reportAuthor = page.getReportAuthorText();

    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            try {
                doFinish(containerName, fileName, templatefile, query, reportTitle, reportDescription,
                        reportAuthor, monitor);
            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            } finally {
                monitor.done();/*  w  w  w  . j ava  2 s.  c  o m*/
            }
        }
    };
    try {
        getContainer().run(true, false, op);
    } catch (InterruptedException e) {
        return false;
    } catch (InvocationTargetException e) {
        Throwable realException = e.getTargetException();
        MessageDialog.openError(getShell(), "Error", realException.getMessage());
        return false;
    }
    return true;
}

From source file:com.mmyumu.magictome.handlers.OpenHandler.java

License:Open Source License

@Execute
public void execute(IEclipseContext context, @Named(IServiceConstants.ACTIVE_SHELL) final Shell shell)
        throws InvocationTargetException, InterruptedException {
    FileDialog dialog = new FileDialog(shell);
    dialog.setFilterExtensions(new String[] { "*.xml" });
    dialog.setFilterNames(new String[] { "MTG Database XML File" });
    dialog.setText("Open MTG Database");
    final String filePath = dialog.open();

    if (filePath != null) {
        ProgressMonitorDialog monitorDialog = new ProgressMonitorDialog(shell);
        monitorDialog.run(true, true, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) {
                monitor.beginTask("Importing card database", 100);
                try {
                    JAXBContext jc = JAXBContext.newInstance(MtgCarddatabase.class);
                    Unmarshaller unmarshaller = jc.createUnmarshaller();

                    unmarshaller.setProperty("com.sun.xml.internal.bind.ObjectFactory", new ObjectFactoryEx());
                    monitor.worked(30);/* ww w  . j a  va 2 s  . c  o  m*/
                    final MtgCarddatabase mtgCarddatabase = (MtgCarddatabase) unmarshaller
                            .unmarshal(new File(filePath));
                    monitor.worked(80);
                    shell.getDisplay().syncExec(new Runnable() {
                        public void run() {
                            // Add sets to Model
                            List<IModelCheckElement> sets = new ArrayList<>();
                            for (Set set : mtgCarddatabase.getSets().getSet()) {
                                SetEx setEx = (SetEx) set;
                                sets.add(setEx);
                            }
                            MtgDatabaseModel mtgModel = ModelProvider.getModel(AppParams.ID,
                                    MtgDatabaseModel.class);
                            SetsModel setsModel = mtgModel.getSetsModel();
                            setsModel.addElements(sets);

                            // Add cards to Model
                            List<IModelElement> cards = new ArrayList<>();
                            for (Card card : mtgCarddatabase.getCards().getCard()) {
                                CardEx cardEx = (CardEx) card;
                                cards.add(cardEx);
                            }
                            CardsModel cardsModel = mtgModel.getCardsModel();
                            cardsModel.addElements(cards);

                            AppLifecycle.save();
                        }
                    });

                    // Add cards to the set
                    // for (Card card :
                    // mtgCarddatabase.getCards().getCard()) {
                    // CardEx cardEx = (CardEx) card;
                    // ((SetExFull) cardEx.getSet()).addCard(cardEx);
                    // }
                    monitor.worked(100);
                } catch (JAXBException e) {
                    logger.error(e, "Error while parsing XML file");
                }
                monitor.done();
            }
        });
    }

}

From source file:com.mmyumu.magictome.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 w  w  w .  j  a  v a  2  s. c  om*/
    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);
            }
        }
    });

    pmContext.dispose();
}

From source file:com.mobilesorcery.sdk.core.MoSyncBuilder.java

License:Open Source License

public static IRunnableWithProgress createBuildJob(final IProject project, final IBuildSession buildSession,
        final List<IBuildVariant> variantsToBuild) {
    return new IRunnableWithProgress() {

        @Override/*from ww w.j  a v  a2 s  .c  o m*/
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            monitor.beginTask(MessageFormat.format("Building {0} variants", variantsToBuild.size()),
                    variantsToBuild.size());

            for (IBuildVariant variantToBuild : variantsToBuild) {
                SubProgressMonitor jobMonitor = new SubProgressMonitor(monitor, 1);
                if (!monitor.isCanceled()) {
                    IRunnableWithProgress buildJob = createBuildJob(project, buildSession, variantToBuild);
                    buildJob.run(jobMonitor);
                }
            }
        }
    };
}

From source file:com.mobilesorcery.sdk.core.MoSyncBuilder.java

License:Open Source License

public static IRunnableWithProgress createBuildJob(final IProject project, final IBuildSession session,
        final IBuildVariant variant) {
    return new IRunnableWithProgress() {
        @Override//w  w w. j  av  a 2 s  .c  om
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                IBuildResult buildResult = new MoSyncBuilder().build(project, session, variant, null, monitor);
                if (!buildResult.success()) {
                    throw new InvocationTargetException(buildResult.createException());
                }
            } catch (CoreException e) {
                throw new InvocationTargetException(e, variant.getProfile() + ": " + e.getMessage()); //$NON-NLS-1$
            } finally {
                monitor.done();
            }
        }
    };
}

From source file:com.mobilesorcery.sdk.importproject.MoSyncWizardProjectsImportPage.java

License:Open Source License

/**
 * Update the list of projects based on path. Method declared public only
 * for test suite./* ww  w  .ja  va2  s. c  o m*/
 *
 * @param path
 */
public void updateProjectsList(final String path) {
    // on an empty path empty selectedProjects
    if (path == null || path.length() == 0) {
        setMessage(DataTransferMessages.WizardProjectsImportPage_ImportProjectsDescription);
        selectedProjects = new ProjectRecord[0];
        projectsList.refresh(true);
        projectsList.setCheckedElements(selectedProjects);
        setPageComplete(projectsList.getCheckedElements().length > 0);
        lastPath = path;
        return;
    }

    final File directory = new File(path);
    long modified = directory.lastModified();
    // Mattias Bybro @ MOSYNC - 111017
    // BRUTAL FIX -- WHY DO WE NEED TO REFRESH IF COPY STATE CHANGED? LET'S NOT A
    // AND INSTEAD SQUASH THIS BUG AT LEAST UNTIL 3.0
    if (path.equals(lastPath) && lastModified == modified/* && lastCopyFiles == copyFiles*/) {
        // since the file/folder was not modified and the path did not
        // change, no refreshing is required
        return;
    }

    lastPath = path;
    lastModified = modified;
    lastCopyFiles = copyFiles;

    // We can't access the radio button from the inner class so get the
    // status beforehand
    final boolean dirSelected = this.projectFromDirectoryRadio.getSelection();
    try {
        getContainer().run(true, true, new IRunnableWithProgress() {

            /*
             * (non-Javadoc)
             *
             * @see
             * org.eclipse.jface.operation.IRunnableWithProgress#run(org
             * .eclipse.core.runtime.IProgressMonitor)
             */
            @Override
            public void run(IProgressMonitor monitor) {

                monitor.beginTask(DataTransferMessages.WizardProjectsImportPage_SearchingMessage, 100);
                selectedProjects = new ProjectRecord[0];
                Collection files = new ArrayList();
                monitor.worked(10);
                if (!dirSelected && ArchiveFileManipulations.isTarFile(path)) {
                    TarFile sourceTarFile = getSpecifiedTarSourceFile(path);
                    if (sourceTarFile == null) {
                        return;
                    }

                    structureProvider = new TarLeveledStructureProvider(sourceTarFile);
                    Object child = structureProvider.getRoot();

                    if (!collectProjectFilesFromProvider(files, child, 0, monitor)) {
                        return;
                    }
                    Iterator filesIterator = files.iterator();
                    selectedProjects = new ProjectRecord[files.size()];
                    int index = 0;
                    monitor.worked(50);
                    monitor.subTask(DataTransferMessages.WizardProjectsImportPage_ProcessingMessage);
                    while (filesIterator.hasNext()) {
                        selectedProjects[index++] = (ProjectRecord) filesIterator.next();
                    }
                } else if (!dirSelected && ArchiveFileManipulations.isZipFile(path)) {
                    ZipFile sourceFile = getSpecifiedZipSourceFile(path);
                    if (sourceFile == null) {
                        return;
                    }
                    structureProvider = new ZipLeveledStructureProvider(sourceFile);
                    Object child = structureProvider.getRoot();

                    if (!collectProjectFilesFromProvider(files, child, 0, monitor)) {
                        return;
                    }
                    Iterator filesIterator = files.iterator();
                    selectedProjects = new ProjectRecord[files.size()];
                    int index = 0;
                    monitor.worked(50);
                    monitor.subTask(DataTransferMessages.WizardProjectsImportPage_ProcessingMessage);
                    while (filesIterator.hasNext()) {
                        selectedProjects[index++] = (ProjectRecord) filesIterator.next();
                    }
                }

                else if (dirSelected && directory.isDirectory()) {

                    if (!collectProjectFilesFromDirectory(files, directory, null, monitor)) {
                        return;
                    }
                    Iterator filesIterator = files.iterator();
                    selectedProjects = new ProjectRecord[files.size()];
                    int index = 0;
                    monitor.worked(50);
                    monitor.subTask(DataTransferMessages.WizardProjectsImportPage_ProcessingMessage);
                    while (filesIterator.hasNext()) {
                        File file = (File) filesIterator.next();
                        selectedProjects[index] = new ProjectRecord(file);
                        index++;
                    }
                } else {
                    monitor.worked(60);
                }
                monitor.done();
            }

        });
    } catch (InvocationTargetException e) {
        IDEWorkbenchPlugin.log(e.getMessage(), e);
    } catch (InterruptedException e) {
        // Nothing to do if the user interrupts.
    }

    projectsList.refresh(true);
    ProjectRecord[] projects = getProjectRecords();
    boolean displayWarning = false;
    for (int i = 0; i < projects.length; i++) {
        if (projects[i].hasConflicts) {
            displayWarning = true;
            projectsList.setGrayed(projects[i], true);
        } else {
            projectsList.setChecked(projects[i], true);
        }
    }

    if (displayWarning) {
        setMessage(DataTransferMessages.WizardProjectsImportPage_projectsInWorkspace, WARNING);
    } else {
        setMessage(DataTransferMessages.WizardProjectsImportPage_ImportProjectsDescription);
    }
    setPageComplete(projectsList.getCheckedElements().length > 0);
    if (selectedProjects.length == 0) {
        setMessage(DataTransferMessages.WizardProjectsImportPage_noProjectsToImport, WARNING);
    }
}

From source file:com.mobilesorcery.sdk.wizards.internal.NewMoSyncProjectWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    boolean completed = false;

    final ProjectTemplate template = templatePage.getProjectTemplate();

    IRunnableWithProgress createProject = new IRunnableWithProgress() {
        @Override/* ww w .j  av  a  2s  .  c  o  m*/
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                createProject(monitor, template);
            } catch (CoreException e) {
                e.printStackTrace();
                throw new InvocationTargetException(e);
            }
        }
    };

    try {
        getContainer().run(false, true, new WorkspaceModifyDelegatingOperation(createProject));
        completed = true;
    } catch (Exception e) {
        e.printStackTrace();
        // completed is false
    }

    return completed;
}