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.jasperassistant.designer.viewer.actions.AbstractExportAction.java

License:Open Source License

/**
 * Subclasses can override this method to implement an export method.
 * Default implementation opens a progress monitor dialog and then calls the
 * {@link #exportWithProgress(File, JRExportProgressMonitor)}method.
 * /* w ww.java2s.co m*/
 * @param file
 *            the destination file
 * @throws Throwable
 *             if an error occurs during the export
 * @see #exportWithProgress(File, JRExportProgressMonitor)
 */
protected void export(final File file) throws Throwable {
    ProgressMonitorDialog pm = new ProgressMonitorDialog(Display.getCurrent().getActiveShell());

    try {
        pm.run(true, true, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    int totalPages = getReportViewer().getDocument().getPages().size();
                    monitor.beginTask(Messages.getString("AbstractExportAction.taskLabel"), totalPages); //$NON-NLS-1$
                    exportWithProgress(file, new ProgressMonitorAdapter(monitor, totalPages));
                } catch (Throwable e) {
                    throw new InvocationTargetException(e);
                } finally {
                    monitor.done();
                }
            }
        });
    } catch (InvocationTargetException e) {
        if (pm.getReturnCode() != ProgressMonitorDialog.CANCEL) {
            throw e;
        }
    } catch (InterruptedException e) {
        if (pm.getReturnCode() != ProgressMonitorDialog.CANCEL) {
            throw e;
        }
    } finally {
        if (pm.getReturnCode() == ProgressMonitorDialog.CANCEL) {
            file.delete();
        }
    }
}

From source file:com.javadude.antxr.eclipse.ui.actions.CompileAction.java

License:Open Source License

/**
 * @see IActionDelegate#run(IAction)//from w ww .  ja v  a 2  s  .c  o m
 */
public void run(IAction anAction) {
    Assert.isNotNull(fGrammarFile);
    Shell shell = AntxrUIPlugin.getActiveWorkbenchShell();
    ProgressMonitorDialog pmd = new ProgressMonitorDialog(shell);
    try {
        pmd.run(true, false, new Operation(fGrammarFile)); // cancel button disabled
    } catch (InterruptedException e) {
        AntxrUIPlugin.log(e);
    } catch (InvocationTargetException e) {
        AntxrUIPlugin.log(e);
    }
}

From source file:com.kdmanalytics.toif.report.internal.handlers.MergeTSV.java

License:Open Source License

/**
 * Process the tsv file. this method steps through each line of the TSV
 * file, extracts the details for that finding, and applies it to a matching
 * finding in the repository./*from  w  w  w . j  av a2  s . c  om*/
 * 
 * @param shell2
 * 
 * @param file
 *            the tsvFile that we are parsing
 * @param repo
 *            the event from the handler.
 */
private void processTSVFile(final Shell shell, final File file, final Repository repo) {
    // count the line numbers.
    final int lineNumbers = countLineNumbers(file);

    ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);

    try {
        dialog.run(true, true, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) {
                monitor.beginTask("Importing TSV File...", lineNumbers);

                BufferedReader bufRdr = null;
                try {
                    bufRdr = new BufferedReader(new FileReader(file));

                    String line = null;

                    RepositoryConnection con = null;

                    try {
                        con = repo.getConnection();
                    } catch (RepositoryException e) {
                        e.printStackTrace();
                    }

                    if (con == null) {
                        System.err.println("Could not create the repository connection...");
                        return;
                    }

                    org.openrdf.model.ValueFactory factory = con.getValueFactory();

                    // read each line of text file=
                    while ((line = bufRdr.readLine()) != null) {
                        // split on a tab (tsv file).
                        String[] tokens = line.split("\t");

                        if (tokens.length != 9) {
                            monitor.worked(1);
                            continue;
                        }

                        // get the details
                        String valid = tokens[2];
                        String trust = tokens[3];
                        String resource = tokens[4];
                        String lineNumber = tokens[5];
                        String description = tokens[8];

                        try {
                            String query = "SELECT ?finding ?description WHERE { ?codeLocation <http://toif/path> \""
                                    + resource + "\". ?codeLocation <http://toif/lineNumber> \"" + lineNumber
                                    + "\". ?finding <http://toif/toif:FindingHasCodeLocation> ?codeLocation . ?finding <http://toif/toif:FindingIsDescribedByWeaknessDescription> ?descriptionId . ?descriptionId <http://toif/description> ?description }";

                            TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, query);

                            // query the repository.
                            TupleQueryResult queryResult = tupleQuery.evaluate();

                            while (queryResult.hasNext()) {
                                String[] descriptionTokens = description.split(":");

                                if (descriptionTokens.length < 1) {
                                    continue;
                                }
                                String ident = descriptionTokens[0];

                                BindingSet adaptorSet = queryResult.next();
                                Value finding = adaptorSet.getValue("finding");
                                Value desc = adaptorSet.getValue("description");

                                if (!desc.stringValue().startsWith(ident)) {
                                    continue;
                                }

                                URI findingURI = factory.createURI(finding.stringValue());

                                // set the trust
                                URI trustURI = factory.createURI("http://toif/trust");

                                con.remove(findingURI, trustURI, null);

                                con.add(findingURI, trustURI, factory.createLiteral(trust));

                                // set the validity
                                URI validURI = factory.createURI("http://toif/isWeakness");

                                con.remove(findingURI, validURI, null);

                                con.add(findingURI, validURI, factory.createLiteral(valid));

                            }

                        } catch (RepositoryException e) {
                            e.printStackTrace();
                        } catch (MalformedQueryException e) {
                            e.printStackTrace();
                        } catch (QueryEvaluationException e) {
                            e.printStackTrace();
                        }

                        // update the row for the progress.
                        monitor.worked(1);
                    }

                    // close the file
                    bufRdr.close();
                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } finally {
                    if (bufRdr != null) {
                        try {
                            bufRdr.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }

                monitor.done();
            }

        });
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:com.kdmanalytics.toif.report.internal.handlers.ModelUtil.java

License:Open Source License

/**
 * Create the project model/*from  ww w . j  a v a  2s . co m*/
 * 
 * @param s
 */
public static void buildModel(ISelection s) {
    final ReportView view = (ReportView) openView();
    // final TreeViewer treeViewer = view.getViewer();

    boolean inWorkbench = false;
    IPerspectiveDescriptor[] desc = PlatformUI.getWorkbench().getPerspectiveRegistry().getPerspectives();

    for (IPerspectiveDescriptor iPerspectiveDescriptor : desc) {
        if (iPerspectiveDescriptor.getId().equals("com.kdmanalytics.kdmwb.kdm.ui.KdmPerspective")) {
            inWorkbench = true;
            break;
        }
    }

    if (s instanceof IStructuredSelection) {
        IProject iProject = null;

        for (Object object : ((IStructuredSelection) s).toArray()) {
            if (object instanceof IProject) {
                iProject = (IProject) object;
            }
        }

        if (iProject != null) {

            File file = new File(iProject.getLocation() + "/.toifProject.ser");

            if (file.exists()) {

                try {
                    FileInputStream fileIn = new FileInputStream(file);
                    ObjectInputStream in = new ObjectInputStream(fileIn);
                    IToifProject project = (IToifProject) in.readObject();
                    in.close();
                    fileIn.close();

                    if (project != null) {
                        System.out.println("toif project deserialized");
                        // view.getTableViewer().setInput(project);

                        IFolder repoFolder = ensureKdmRepoFolderExists(iProject);
                        project.setRepository(repoFolder);
                        project.setIProject(repoFolder.getProject());
                        // project.setIProject(iProject.getLocation());

                        view.clearInput();
                        view.updateInput(project);
                        view.refresh();
                        return;
                    }
                } catch (IOException i) {
                    i.printStackTrace();
                    // return;
                } catch (ClassNotFoundException c) {
                    System.out.println("IToifProject class not found");
                    c.printStackTrace();
                    // return;
                } catch (CoreException e) {
                    System.out.println("repo folder could not be found");
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }

        final boolean wbValue = inWorkbench;
        final IFolder folder = getFolderFromSelection((IStructuredSelection) s);
        if (folder != null) {
            ProgressMonitorDialog dialog = new ProgressMonitorDialog(
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
            try {
                IRunnableWithProgress runnable = new IRunnableWithProgress() {

                    @Override
                    public void run(IProgressMonitor monitor)
                            throws InvocationTargetException, InterruptedException {
                        monitor.setTaskName("Populating TOIF View.");
                        final IToifProject project = ProjectFactory.createProjectModel(folder, wbValue,
                                monitor);

                        // have to set the input on the UI thread
                        PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                            @Override
                            public void run() {
                                view.setReportInput(project);
                            }
                        });

                    }
                };

                dialog.run(true, false, runnable);
            } catch (InvocationTargetException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    }
}

From source file:com.laex.cg2d.entityeditor.ui.ImportSpritesComposite.java

License:Open Source License

/**
 * Extract from json./*from   ww w. j  av  a 2 s .c o m*/
 *
 * @param lst the lst
 */
private void extractFromJSON(final List<JsonSprite> lst) {
    spritesheetItems = new ArrayList<EntitySpritesheetItem>();

    clearOutline();
    setSelectedImageToCanvas();

    ProgressMonitorDialog pmd = new ProgressMonitorDialog(getShell());
    try {

        pmd.run(false, false, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {

                int index = 0;

                for (JsonSprite js : lst) {
                    Rectangle r = new Rectangle(js.getX(), js.getY(), js.getWidth(), js.getHeight());

                    EntitySpritesheetItem esi = new EntitySpritesheetItem();
                    esi.setExtractBounds(RectAdapter.gdxRect(r));
                    esi.setFrameIndex(index++);
                    spritesheetItems.add(esi);

                    final RectangleFigure rf = createBlockFigure(r.x, r.y, r.width, r.height);
                    flp.add(rf);

                    final ImageData id = ResourceManager.extractImageFromBounds(selectedImage.getImageData(),
                            RectAdapter.swtRect(rf.getBounds()));
                    extractedImages.add(ResourceManager.getImage(id));
                }

                lblCount.setText("#" + String.valueOf(extractedImages.size()));

                if (delegate != null) {
                    delegate.spriteExtractionComplete(spritesheetImageFile, spritesheetJsonMapperFile,
                            spritesheetItems, extractedImages);
                }
            }

        });

    } catch (InvocationTargetException e1) {
        e1.printStackTrace();
    } catch (InterruptedException e1) {
        e1.printStackTrace();
    }

    figureCanvas.setContents(flp);
}

From source file:com.laex.cg2d.entityeditor.views.EntitiesView.java

License:Open Source License

/**
 * Load all entities with progress./* w ww  .ja v a 2 s.  c om*/
 */
private void loadAllEntitiesWithProgress() {

    if (selectedProject == null) {
        IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
                .getActiveEditor();
        if (activeEditor != null) {
            selectedProject = CGCProject.getInstance().getCurrentProject(activeEditor.getEditorInput());
        } else {
            MessageDialog.openInformation(getSite().getShell(), "Select a resoure",
                    "Select a screen file from the project you want to load the entities or open an entity file.");
            return;
        }
    }

    ProgressMonitorDialog pmd = new ProgressMonitorDialog(getSite().getShell());
    try {
        pmd.run(false, true, new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {

                try {
                    loadEntities(monitor);
                } catch (CoreException e) {
                    Activator.log(e);
                }
            }
        });
    } catch (InvocationTargetException e) {
        Activator.log(e);
    } catch (InterruptedException e) {
        Activator.log(e);
    }
}

From source file:com.laex.cg2d.screeneditor.ScreenEditor.java

License:Open Source License

/**
 * Load screen model.//from  w w  w.ja va2 s . c o  m
 *
 * @param input the input
 * @throws CoreException the core exception
 * @throws IOException Signals that an I/O exception has occurred.
 * @throws InvocationTargetException the invocation target exception
 * @throws InterruptedException the interrupted exception
 */
private void loadScreenModel(final IEditorInput input)
        throws CoreException, IOException, InvocationTargetException, InterruptedException {
    final IFile file = ((IFileEditorInput) input).getFile();

    ProgressMonitorDialog pmd = new ProgressMonitorDialog(getSite().getShell());
    pmd.run(false, false, new IRunnableWithProgress() {
        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {

            try {

                monitor.beginTask("Parse screen model", 1);

                CGScreenModel cgGameModel = CGScreenModel.parseFrom(file.getContents());
                model = ScreenModelAdapter.asGameModel(cgGameModel);
                monitor.worked(1);

                x = cgGameModel.getScreenPrefs().getCardPrefs().getCardNoX();
                y = cgGameModel.getScreenPrefs().getCardPrefs().getCardNoY();
                cardWidthh = cgGameModel.getScreenPrefs().getCardPrefs().getCardWidth();
                cardHeight = cgGameModel.getScreenPrefs().getCardPrefs().getCardHeight();
                cardBgColor = ColorAdapter.swtColor(cgGameModel.getScreenPrefs().getBackgroundColor());

                monitor.done();
            } catch (IOException e) {
                Activator.log(e);
            } catch (CoreException e) {
                Activator.log(e);
            }

        }
    });

    /* Go Ahead and activate the edit parts. */

    setPartName(file.getProject().getName() + "/" + file.getName());
}

From source file:com.maccasoft.composer.Main.java

License:Open Source License

void handlePlayerUpload() {
    File file = new File("Player/Player.binary");
    if (!file.exists()) {
        file = new File("lib/Player.binary");
    }//from   w w  w. j a v  a2  s  .  c  o  m
    if (!file.exists()) {
        file = new File("Player.binary");
    }
    if (!file.exists()) {
        MessageDialog.openError(shell, APP_TITLE, "Player binary file not found!");
        return;
    }

    final File binaryFile = file;

    ProgressMonitorDialog dlg = new ProgressMonitorDialog(shell);
    try {
        dlg.setOpenOnRun(true);
        dlg.run(true, false, new IRunnableWithProgress() {

            @Override
            public void run(final IProgressMonitor monitor)
                    throws InvocationTargetException, InterruptedException {
                PropellerLoader loader = new PropellerLoader(editor.getSerialPort(), true) {

                    SubProgressMonitor subProgressMonitor = new SubProgressMonitor(monitor, 1);

                    @Override
                    protected void bufferUpload(int type, byte[] binaryImage)
                            throws SerialPortException, IOException {
                        StringBuilder sb = new StringBuilder("Loading binary image to ");
                        switch (type) {
                        case DOWNLOAD_EEPROM:
                        case DOWNLOAD_RUN_EEPROM:
                            sb.append("EEPROM via ");
                            // fall through
                        case DOWNLOAD_RUN_BINARY:
                            sb.append("hub memory");
                            break;
                        }
                        monitor.beginTask(sb.toString(), IProgressMonitor.UNKNOWN);
                        super.bufferUpload(type, binaryImage);
                    }

                    @Override
                    protected void notifyProgress(int sent, int total) {
                        subProgressMonitor
                                .subTask(String.format("%d bytes remaining             \r", total - sent));
                    }

                    @Override
                    protected void verifyRam() throws SerialPortException, IOException {
                        subProgressMonitor.subTask("Verifying RAM ... ");
                        super.verifyRam();
                    }

                    @Override
                    protected void eepromWrite() throws SerialPortException, IOException {
                        subProgressMonitor.subTask("Programming EEPROM ... ");
                        super.eepromWrite();
                    }

                    @Override
                    protected void eepromVerify() throws SerialPortException, IOException {
                        subProgressMonitor.subTask("Verifying EEPROM ... ");
                        super.eepromVerify();
                    }
                };

                try {
                    loader.upload(binaryFile, PropellerLoader.DOWNLOAD_RUN_EEPROM);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    } catch (Exception e1) {
        e1.printStackTrace();
    }
}

From source file:com.mansfield.pde.api.tools.internal.ui.preferencepages.TargetBaselinePreferencePage.java

License:Open Source License

private void internalReloadTargetDefinition(final ITargetDefinition target) {
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell()) {
        protected void configureShell(Shell shell) {
            super.configureShell(shell);
            shell.setText(PDEUIMessages.TargetPlatformPreferencePage2_12);
        }//from  w w  w .  java 2 s . c  om
    };
    try {
        dialog.run(true, true, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                if (monitor.isCanceled()) {
                    throw new InterruptedException();
                }
                // Resolve the target
                target.resolve(monitor);
                if (monitor.isCanceled()) {
                    throw new InterruptedException();
                }
            }
        });
    } catch (InvocationTargetException e) {
        PDEPlugin.log(e);
        setErrorMessage(e.getMessage());
    } catch (InterruptedException e) {
        // Do nothing, resolve will happen when user presses ok
    }

    if (target.isResolved()) {
        // Check if the bundle resolution has errors
        IStatus bundleStatus = target.getStatus();
        if (bundleStatus.getSeverity() == IStatus.ERROR) {
            ErrorDialog.openError(getShell(), PDEUIMessages.TargetPlatformPreferencePage2_14,
                    PDEUIMessages.TargetPlatformPreferencePage2_15, bundleStatus, IStatus.ERROR);
        }
    }
    fTableViewer.refresh(true);
}

From source file:com.mentor.nucleus.bp.core.common.ComponentResourceListener.java

License:Open Source License

private static void parseAllInDialog(final NonRootModelElement rootME) {
    if (CorePlugin.getDefault().getParseAllOnResourceChange()) {
        ProgressMonitorDialog monitorDialog = new ProgressMonitorDialog(null);
        try {//from   w  w  w .j  av  a 2 s .c  o m
            monitorDialog.run(false, false, new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor) {
                    Domain_c dom = Domain_c.DomainInstance(rootME.getModelRoot());
                    CorePlugin.parseAll(dom, monitor);
                }
            });
        } catch (InvocationTargetException e) {
            CorePlugin.logError("Could not parse newly loaded component data", e);
        } catch (InterruptedException e) {
            CorePlugin.logError("Could not parse newly loaded component data", e);
        }
    }
}