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

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

Introduction

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

Prototype

public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException;

Source Link

Document

Runs this operation.

Usage

From source file:org.eclipse.cdt.oprofile.core.Oprofile.java

License:Open Source License

/**
 * Returns a list of all the events collected on the system.
 * @returns a list of all collected events
 *//*from   w  w w  .ja  va  2s  . com*/
public static SessionEvent[] getSessionEvents() {
    SessionEvent[] sessions = new SessionEvent[0];

    ArrayList sessionList = new ArrayList();
    try {
        IRunnableWithProgress opxml = OprofileCorePlugin.getDefault().getOpxmlProvider().sessions(_info,
                sessionList);
        opxml.run(null);
        sessions = new SessionEvent[sessionList.size()];
        sessionList.toArray(sessions);
    } catch (InvocationTargetException e) {
    } catch (InterruptedException e) {
    } catch (OpxmlException e) {
        _showErrorDialog("opxmlProvider", e); //$NON-NLS-1$
    }
    return sessions;
}

From source file:org.eclipse.cdt.oprofile.core.Oprofile.java

License:Open Source License

/**
 * Return a list of all the Samples in the given session.
 * @param session the session for which to get samples
 * @param shell the composite shell to use for the progress dialog
 */// ww  w  .  j av  a  2 s .c  o m
public static void getSamples(final SampleSession session, Shell shell) {
    /* As much as I would like to get all this UI stuff back into the UI code, it really confuses
       things. It would be a real PITA for the UI to check whether we need samples to be read.
       Reading samples should just magically happen (as far as the UI is concerned). */
    final IRunnableWithProgress opxml;
    try {
        opxml = OprofileCorePlugin.getDefault().getOpxmlProvider().samples(session);
    } catch (OpxmlException e) {
        _showErrorDialog("opxmlProvider", e); //$NON-NLS-1$
        return;
    }

    if (shell != null) {
        IRunnableWithProgress runnable = new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                Object[] fmtArgs = null;
                String key = null;
                if (session.isDefaultSession()) {
                    key = "getSamples.caption.default-session"; //$NON-NLS-1$
                    fmtArgs = new Object[0];
                } else {
                    key = "getSamples.caption"; //$NON-NLS-1$
                    fmtArgs = new Object[] { session.getExecutableName() };
                }

                String caption = MessageFormat.format(OprofileProperties.getString(key), fmtArgs);
                monitor.beginTask(caption, session.getSampleCount());
                opxml.run(monitor);
                monitor.done();
            }
        };

        ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
        try {
            dialog.run(true, false, runnable);
        } catch (InterruptedException ie) {
        } catch (InvocationTargetException e) {
        }
    } else {
        // No shell -- just run opxml without a ProgressMonitor
        try {
            opxml.run(null);
        } catch (InvocationTargetException e) {
        } catch (InterruptedException e) {
        }
    }
}

From source file:org.eclipse.cdt.oprofile.core.Oprofile.java

License:Open Source License

/**
 * Collects the debug information for the given sample file.
 * There's a lot of searching going on, and it probably isn't even really needed,
 * since all the samples and debug-info from opxml are ordered. Nonetheless,
 * speed seems very good even with a binary search, so what the heck.
 * //from  w  w w  . j av  a2s . co  m
 * This function will set the debuginfo objects for every Sample in the ProfileImage.
 * @param image the sample file
 */
public static void getDebugInfo(ProfileImage image) {
    Sample[] samples = image.getSamples(null);

    // Sort samples
    Arrays.sort(samples, new Comparator() {
        public int compare(Object o1, Object o2) {
            Sample a = (Sample) o1;
            Sample b = (Sample) o2;
            return a.getAddress().compareTo(b.getAddress());
        }
    });

    // Run opxml and get the list of all the debug info
    ArrayList infoList = new ArrayList();
    try {
        IRunnableWithProgress opxml = OprofileCorePlugin.getDefault().getOpxmlProvider().debugInfo(image,
                infoList);
        opxml.run(null);
    } catch (InvocationTargetException e) {
    } catch (InterruptedException e) {
    } catch (OpxmlException e) {
        _showErrorDialog("opxmlProvider", e); //$NON-NLS-1$
    }

    // Loop through all the debug infos, setting the debug info for each
    // corresponding Sample.
    for (Iterator i = infoList.listIterator(); i.hasNext();) {
        DebugInfo info = (DebugInfo) i.next();
        int index = Arrays.binarySearch(samples, info.address, new Comparator() {
            public int compare(Object o1, Object o2) {
                String addr1 = null;
                String addr2 = null;
                if (o1 instanceof Sample) {
                    addr1 = ((Sample) o1).getAddress();
                    addr2 = (String) o2;
                } else {
                    addr1 = (String) o1;
                    addr2 = ((Sample) o2).getAddress();
                }
                return addr1.compareTo(addr2);
            }
        });

        if (index >= 0) {
            samples[index].setDebugInfo(info);
        }
    }
}

From source file:org.eclipse.cdt.ui.tests.search.BasicSearchTest.java

License:Open Source License

/**
 * Run the specified query, and return the result. When tehis method returns the
 * search page will have been opened./*from www  . j  av a2  s.com*/
 * @param query
 * @return
 */
protected CSearchResult runQuery(CSearchQuery query) {
    final ISearchResult result[] = new ISearchResult[1];
    IQueryListener listener = new IQueryListener() {
        @Override
        public void queryAdded(ISearchQuery query) {
        }

        @Override
        public void queryFinished(ISearchQuery query) {
            result[0] = query.getSearchResult();
        }

        @Override
        public void queryRemoved(ISearchQuery query) {
        }

        @Override
        public void queryStarting(ISearchQuery query) {
        }
    };
    NewSearchUI.addQueryListener(listener);
    NewSearchUI.runQueryInForeground(new IRunnableContext() {
        @Override
        public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
                throws InvocationTargetException, InterruptedException {
            runnable.run(npm());
        }
    }, query);
    assertTrue(result[0] instanceof CSearchResult);
    runEventQueue(500);
    return (CSearchResult) result[0];
}

From source file:org.eclipse.dltk.tcl.ui.tests.wizardapi.NewTCLProjectWizardTest.java

License:Open Source License

public void testBasicCreate() throws Exception {
    IProject project = fWizardPage.getProjectHandle();

    IRunnableWithProgress op = new WorkspaceModifyDelegatingOperation(fWizardPage.getRunnable());
    op.run(null);

    IScriptProject jproj = fWizardPage.getNewScriptProject();

    assertEquals("a", jproj.getProject(), project);

    IBuildpathEntry[] buildpath = jproj.getRawBuildpath();
    assertBasicBuildPath(jproj.getProject(), buildpath);
}

From source file:org.eclipse.dltk.tcl.ui.tests.wizardapi.NewTCLProjectWizardTest.java

License:Open Source License

public void testProjectChange() throws Exception {
    fWizardPage.initBuildPath();//from  w  ww . jav  a 2s  . c  o m
    IProject project = fWizardPage.getProjectHandle();

    IBuildpathEntry[] buildpath = fWizardPage.getRawBuildPath();
    assertBasicBuildPath(project, buildpath);

    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IProject otherProject = root.getProject(OTHER_PROJECT_NAME);

    // change the project before create
    fWizardPage.setProjectHandle(otherProject);

    IRunnableWithProgress op = new WorkspaceModifyDelegatingOperation(fWizardPage.getRunnable());
    op.run(null);

    IScriptProject jproj = fWizardPage.getNewScriptProject();

    assertEquals("a", jproj.getProject(), otherProject);

    IBuildpathEntry[] buildpath1 = fWizardPage.getRawBuildPath();
    assertBasicBuildPath(otherProject, buildpath1);
}

From source file:org.eclipse.dltk.tcl.ui.tests.wizardapi.NewTCLProjectWizardTest.java

License:Open Source License

public void testUserCreate() throws Exception {
    IProject project = fWizardPage.getProjectHandle();

    IBuildpathEntry[] entries = new IBuildpathEntry[] {
            DLTKCore.newSourceEntry(project.getFolder("dsrc1").getFullPath()),
            DLTKCore.newSourceEntry(project.getFolder("dsrc2").getFullPath()) };

    fWizardPage.setDefaultBuildPath(entries, true);

    IRunnableWithProgress op = new WorkspaceModifyDelegatingOperation(fWizardPage.getRunnable());
    op.run(null);

    IScriptProject jproj = fWizardPage.getNewScriptProject();

    assertEquals("a", jproj.getProject(), project);

    IBuildpathEntry[] buildpath = jproj.getRawBuildpath();
    assertUserBuildPath(jproj.getProject(), buildpath);
}

From source file:org.eclipse.dltk.tcl.ui.tests.wizardapi.NewTCLProjectWizardTest.java

License:Open Source License

public void testReadExisting() throws Exception {
    IProject project = fWizardPage.getProjectHandle();

    //IPath folderPath = project.getFolder("dbin").getFullPath();
    IBuildpathEntry[] entries = new IBuildpathEntry[] {
            DLTKCore.newSourceEntry(project.getFolder("dsrc1").getFullPath()),
            DLTKCore.newSourceEntry(project.getFolder("dsrc2").getFullPath()) };

    fWizardPage.setDefaultBuildPath(entries, true);

    IRunnableWithProgress op = new WorkspaceModifyDelegatingOperation(fWizardPage.getRunnable());
    op.run(null);

    IProject proj = fWizardPage.getNewScriptProject().getProject();

    fWizardPage.setDefaultBuildPath(null, false);
    fWizardPage.setProjectHandle(proj);// ww w.jav  a 2  s  .c  om

    // reads from existing
    fWizardPage.initBuildPath();

    IBuildpathEntry[] buildpath1 = fWizardPage.getRawBuildPath();
    assertUserBuildPath(project, buildpath1);
}

From source file:org.eclipse.dltk.tcl.ui.tests.wizardapi.NewTCLProjectWizardTest.java

License:Open Source License

public void testExistingOverwrite() throws Exception {
    IProject project = fWizardPage.getProjectHandle();

    IRunnableWithProgress op = new WorkspaceModifyDelegatingOperation(fWizardPage.getRunnable());
    op.run(null);

    //IPath folderPath = project.getFolder("dbin").getFullPath();
    IBuildpathEntry[] entries = new IBuildpathEntry[] {
            DLTKCore.newSourceEntry(project.getFolder("dsrc1").getFullPath()),
            DLTKCore.newSourceEntry(project.getFolder("dsrc2").getFullPath()) };

    fWizardPage.setDefaultBuildPath(entries, true);

    // should overwrite existing
    IRunnableWithProgress op1 = new WorkspaceModifyDelegatingOperation(fWizardPage.getRunnable());
    op1.run(null);//from  w w w .j  av  a 2 s. c  om

    IScriptProject jproj = fWizardPage.getNewScriptProject();

    IBuildpathEntry[] buildpath1 = jproj.getRawBuildpath();
    assertUserBuildPath(project, buildpath1);
}

From source file:org.eclipse.edt.ide.ui.internal.project.wizard.pages.SourceProjectWizardCapabilityPage.java

License:Open Source License

private void removeProject() {
    if (fCurrProject == null || !fCurrProject.exists()) {
        return;/*from ww w  .j av  a2s.  c o  m*/
    }

    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            final boolean noProgressMonitor = Platform.getLocation().equals(fCurrProjectLocation);
            if (monitor == null || noProgressMonitor) {
                monitor = new NullProgressMonitor();
            }
            monitor.beginTask(NewWizardMessages.NewProjectCreationWizardPageRemoveprojectDesc, 3);

            try {
                fCurrProject.delete(fCanRemoveContent, false, monitor);
            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            } finally {
                monitor.done();
                fCurrProject = null;
                fCanRemoveContent = false;
            }
        }
    };

    try {
        op.run(new NullProgressMonitor());
    } catch (InvocationTargetException e) {
        String message = NewWizardMessages.NewProjectCreationWizardPageOp_error_removeMessage;
        EDTUIPlugin.logErrorMessage(message);
    } catch (InterruptedException e) {
        // cancel pressed
    }
}