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:bndtools.editor.components.ComponentNameProposalProvider.java

License:Open Source License

@Override
protected List<IContentProposal> doGenerateProposals(String contents, int position) {
    final String prefix = contents.substring(0, position);
    IJavaProject javaProject = searchContext.getJavaProject();
    final List<IContentProposal> result = new ArrayList<IContentProposal>(100);

    // Resource matches
    IProject project = javaProject.getProject();
    try {//from   www  . j  a v  a 2 s .  c  o m
        project.accept(new IResourceProxyVisitor() {
            public boolean visit(IResourceProxy proxy) throws CoreException {
                if (proxy.getType() == IResource.FILE) {
                    if (proxy.getName().toLowerCase().startsWith(prefix)
                            && proxy.getName().toLowerCase().endsWith(XML_SUFFIX)) {
                        result.add(new ResourceProposal(proxy.requestResource()));
                    }
                    return false;
                }
                // Recurse into everything else
                return true;
            }
        }, 0);
    } catch (CoreException e) {
        Plugin.log(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error searching for resources.", e));
    }

    // Class matches
    final IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject });
    final TypeNameRequestor requestor = new TypeNameRequestor() {
        @Override
        public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName,
                char[][] enclosingTypeNames, String path) {
            if (!Flags.isAbstract(modifiers) && (Flags.isPublic(modifiers) || Flags.isProtected(modifiers))) {
                result.add(new JavaContentProposal(new String(packageName), new String(simpleTypeName), false));
            }
        };
    };
    final IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                new SearchEngine().searchAllTypeNames(null, 0, prefix.toCharArray(),
                        SearchPattern.R_PREFIX_MATCH, IJavaSearchConstants.CLASS, scope, requestor,
                        IJavaSearchConstants.CANCEL_IF_NOT_READY_TO_SEARCH, monitor);
            } catch (JavaModelException e) {
                throw new InvocationTargetException(e);
            }
        }
    };
    IRunnableContext runContext = searchContext.getRunContext();
    try {
        if (runContext != null) {
            runContext.run(false, false, runnable);
        } else {
            runnable.run(new NullProgressMonitor());
        }
    } catch (InvocationTargetException e) {
        Plugin.log(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error searching for classes.",
                e.getTargetException()));
    } catch (InterruptedException e) {
        // Reset the interruption status and continue
        Thread.currentThread().interrupt();
    }
    return result;
}

From source file:bndtools.editor.components.MethodProposalProvider.java

License:Open Source License

@Override
public List<IContentProposal> doGenerateProposals(String contents, int position) {
    final String prefix = contents.substring(0, position);
    final List<IContentProposal> result = new ArrayList<IContentProposal>();

    try {//  w  w w .  ja  v  a 2 s.  c o m
        IRunnableWithProgress runnable = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException {
                SubMonitor progress = SubMonitor.convert(monitor, 10);

                try {
                    IJavaProject project = searchContext.getJavaProject();
                    String targetTypeName = searchContext.getTargetTypeName();
                    IType targetType = project.findType(targetTypeName, progress.newChild(1));

                    if (targetType == null)
                        return;

                    ITypeHierarchy hierarchy = targetType.newSupertypeHierarchy(progress.newChild(5));
                    IType[] classes = hierarchy.getAllClasses();
                    progress.setWorkRemaining(classes.length);
                    for (IType clazz : classes) {
                        IMethod[] methods = clazz.getMethods();
                        for (IMethod method : methods) {
                            if (method.getElementName().toLowerCase().startsWith(prefix)) {
                                // String[] parameterTypes = method.getParameterTypes();
                                // TODO check parameter type
                                result.add(new MethodContentProposal(method));
                            }
                        }
                        progress.worked(1);
                    }
                } catch (JavaModelException e) {
                    throw new InvocationTargetException(e);
                }
            }
        };
        IRunnableContext runContext = searchContext.getRunContext();
        if (runContext != null) {
            runContext.run(false, false, runnable);
        } else {
            runnable.run(new NullProgressMonitor());
        }
        return result;
    } catch (InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return Collections.emptyList();
}

From source file:bndtools.editor.components.SvcInterfaceProposalProvider.java

License:Open Source License

@Override
protected List<IContentProposal> doGenerateProposals(String contents, int position) {
    final String prefix = contents.substring(0, position);
    final IJavaSearchScope scope = SearchEngine
            .createJavaSearchScope(new IJavaElement[] { searchContext.getJavaProject() });
    final ArrayList<IContentProposal> result = new ArrayList<IContentProposal>(100);
    final TypeNameRequestor typeNameRequestor = new TypeNameRequestor() {
        @Override//from   w  w  w  . j  a  va2 s.co  m
        public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName,
                char[][] enclosingTypeNames, String path) {
            boolean isInterface = Flags.isInterface(modifiers);
            result.add(
                    new JavaContentProposal(new String(packageName), new String(simpleTypeName), isInterface));
        }
    };
    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                new SearchEngine().searchAllTypeNames(null, 0, prefix.toCharArray(),
                        SearchPattern.R_PREFIX_MATCH, IJavaSearchConstants.CLASS_AND_INTERFACE, scope,
                        typeNameRequestor, IJavaSearchConstants.CANCEL_IF_NOT_READY_TO_SEARCH, monitor);
            } catch (JavaModelException e) {
                throw new InvocationTargetException(e);
            }
        }
    };

    try {
        if (searchContext.getRunContext() == null) {
            runnable.run(new NullProgressMonitor());
        } else {
            searchContext.getRunContext().run(false, false, runnable);
        }
    } catch (InvocationTargetException e) {
        Plugin.log(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error searching for Java types.",
                e.getTargetException()));
        return Collections.emptyList();
    } catch (InterruptedException e) {
        // Reset interrupted status and return empty
        Thread.currentThread().interrupt();
        return Collections.emptyList();
    }
    return result;
}

From source file:bndtools.editor.pkgpatterns.PkgPatternsProposalProvider.java

License:Open Source License

@Override
protected Collection<? extends IContentProposal> doGenerateProposals(String contents, int position) {
    String prefix = contents.substring(0, position);

    final int replaceFromPos;
    if (prefix.startsWith("!")) { //$NON-NLS-1$
        prefix = prefix.substring(1);//from  w ww  .j av  a2s  . com
        replaceFromPos = 1;
    } else {
        replaceFromPos = 0;
    }

    Comparator<PkgPatternProposal> comparator = new Comparator<PkgPatternProposal>() {
        @Override
        public int compare(PkgPatternProposal o1, PkgPatternProposal o2) {
            int result = o1.getPackageFragment().getElementName()
                    .compareTo(o2.getPackageFragment().getElementName());
            if (result == 0) {
                result = Boolean.valueOf(o1.isWildcard()).compareTo(Boolean.valueOf(o2.isWildcard()));
            }
            return result;
        }
    };
    final TreeSet<PkgPatternProposal> result = new TreeSet<PkgPatternProposal>(comparator);

    final IJavaSearchScope scope = SearchEngine
            .createJavaSearchScope(new IJavaElement[] { searchContext.getJavaProject() });
    final SearchPattern pattern = SearchPattern.createPattern("*" + prefix + "*", IJavaSearchConstants.PACKAGE,
            IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH);
    final SearchRequestor requestor = new SearchRequestor() {
        @Override
        public void acceptSearchMatch(SearchMatch match) throws CoreException {
            IPackageFragment pkg = (IPackageFragment) match.getElement();
            // Reject the default package and any package starting with
            // "java." since these cannot be imported
            if (pkg.isDefaultPackage() || pkg.getElementName().startsWith("java."))
                return;

            result.add(new PkgPatternProposal(pkg, false, replaceFromPos));
            result.add(new PkgPatternProposal(pkg, true, replaceFromPos));
        }
    };
    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                new SearchEngine().search(pattern,
                        new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope,
                        requestor, monitor);
            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            }
        }
    };

    try {
        IRunnableContext runContext = searchContext.getRunContext();
        if (runContext != null) {
            runContext.run(false, false, runnable);
        } else {
            runnable.run(new NullProgressMonitor());
        }
        return result;
    } catch (InvocationTargetException e) {
        logger.logError("Error searching for packages.", e);
        return Collections.emptyList();
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        return Collections.emptyList();
    }
}

From source file:ca.uvic.chisel.javasketch.SketchPlugin.java

License:Open Source License

/**
 * Sets the active sketch to the given sketch. May be null.
 * @param sketch the new active sketch. May be null.
 *///from  w  w w  . jav a 2  s .  c o m
public synchronized void setActiveSketch(final IProgramSketch sketch) {
    IProgramSketch activeSketch = doi.getActiveSketch();
    if (doi.getActiveSketch() != null) {
        if (activeSketch.getTraceData() != null) {
            activeSketch.getTraceData().removeListener(staticJavaModelListener);
        }
    }
    try {
        IRunnableWithProgress runnable = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                doi.setActiveSketch(sketch, monitor);
                if (sketch != null) {
                    sketch.getTraceData().addListener(staticJavaModelListener);
                }
                SketchUI.INSTANCE.refreshJavaUI();

            }
        };
        if (Display.getCurrent() != null) {
            getWorkbench().getProgressService().busyCursorWhile(runnable);
        } else {
            runnable.run(new NullProgressMonitor());
        }

    } catch (InterruptedException e) {
    } catch (Exception e) {
        log(e);
        doi.setActiveSketch(null, new NullProgressMonitor());
        SketchUI.INSTANCE.refreshJavaUI();
    }
}

From source file:com.android.ide.eclipse.adt.internal.editors.layout.refactoring.AdtProjectTest.java

License:Open Source License

protected IProject createProject(String name) {
    IAndroidTarget target = null;/*from   w ww.  j a  v a  2s.com*/

    IAndroidTarget[] targets = getSdk().getTargets();
    for (IAndroidTarget t : targets) {
        if (!t.isPlatform()) {
            continue;
        }
        if (t.getVersion().getApiLevel() >= TARGET_API_LEVEL) {
            target = t;
            break;
        }
    }
    assertNotNull(target);

    IRunnableContext context = new IRunnableContext() {
        @Override
        public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
                throws InvocationTargetException, InterruptedException {
            runnable.run(new NullProgressMonitor());
        }
    };
    NewProjectWizardState state = new NewProjectWizardState(Mode.ANY);
    state.projectName = name;
    state.target = target;
    state.packageName = TEST_PROJECT_PACKAGE;
    state.activityName = name;
    state.applicationName = name;
    state.createActivity = false;
    state.useDefaultLocation = true;
    if (getMinSdk() != -1) {
        state.minSdk = Integer.toString(getMinSdk());
    }

    NewProjectCreator creator = new NewProjectCreator(state, context);
    creator.createAndroidProjects();
    return validateProjectExists(name);
}

From source file:com.android.ide.eclipse.adt.internal.wizards.exportgradle.ExportGradleTest.java

License:Open Source License

protected IProject createJavaProject(String name) {
    IRunnableContext context = new IRunnableContext() {
        @Override// www.ja  v  a2 s.  c  o m
        public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
                throws InvocationTargetException, InterruptedException {
            runnable.run(new NullProgressMonitor());
        }
    };
    NewProjectWizardState state = new NewProjectWizardState(Mode.ANY);
    state.projectName = name;
    state.packageName = TEST_PROJECT_PACKAGE;
    state.activityName = name;
    state.applicationName = name;
    state.createActivity = false;
    state.useDefaultLocation = true;
    if (getMinSdk() != -1) {
        state.minSdk = Integer.toString(getMinSdk());
    }

    NewProjectCreator creator = new NewProjectCreator(state, context);
    creator.createJavaProjects();
    return validateProjectExists(name);
}

From source file:com.android.ide.eclipse.adt.wizards.newproject.StubProjectWizard.java

License:Open Source License

/**
 * Overrides parent to return dummy wizard container
 *//*from  w  w  w  .j  av a 2  s . c o  m*/
@Override
public IWizardContainer getContainer() {
    return new IWizardContainer() {

        public IWizardPage getCurrentPage() {
            return null;
        }

        public Shell getShell() {
            return null;
        }

        public void showPage(IWizardPage page) {
            // pass
        }

        public void updateButtons() {
            // pass
        }

        public void updateMessage() {
            // pass
        }

        public void updateTitleBar() {
            // pass
        }

        public void updateWindowTitle() {
            // pass
        }

        /**
         * Executes runnable on current thread
         */
        public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
                throws InvocationTargetException, InterruptedException {
            runnable.run(new NullProgressMonitor());
        }

    };
}

From source file:com.android.ide.eclipse.tests.functests.sampleProjects.SampleProjectTest.java

License:Open Source License

/**
 * Tests the sample project with the given name
 *
 * @param target - SDK target of project
 * @param name - name of sample project to test
 * @param path - absolute file system path
 * @throws CoreException/*from   w w w .  j  ava  2  s  .c om*/
 */
private void doTestSampleProject(String name, String path, IAndroidTarget target) throws CoreException {
    IProject iproject = null;
    try {
        sLogger.log(Level.INFO, String.format("Testing sample %s for target %s", name, target.getName()));

        prepareProject(path, target);

        IRunnableContext context = new IRunnableContext() {
            @Override
            public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
                    throws InvocationTargetException, InterruptedException {
                runnable.run(new NullProgressMonitor());
            }
        };
        NewProjectWizardState state = new NewProjectWizardState(Mode.SAMPLE);
        state.projectName = name;
        state.target = target;
        state.packageName = "com.android.samples";
        state.activityName = name;
        state.applicationName = name;
        state.chosenSample = new File(path);
        state.useDefaultLocation = false;
        state.createActivity = false;

        NewProjectCreator creator = new NewProjectCreator(state, context);
        creator.createAndroidProjects();
        iproject = validateProjectExists(name);
        validateNoProblems(iproject);
    } catch (CoreException e) {
        sLogger.log(Level.SEVERE,
                String.format("Unexpected exception when creating sample project %s " + "for target %s", name,
                        target.getName()));
        throw e;
    } finally {
        if (iproject != null) {
            iproject.delete(false, true, new NullProgressMonitor());
        }
    }
}

From source file:com.bdaum.zoom.core.internal.CoreActivator.java

License:Open Source License

public void deleteTrashCan() {
    if (dbManager.hasTrash()) {
        IRunnableWithProgress runnable = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                List<Trash> set = dbManager.obtainTrashToDelete(true);
                monitor.beginTask(Messages.CoreActivator_Cleaning_up, set.size() + 1);
                for (Trash t : set) {
                    t.deleteFiles();//from   w w w  . jav  a2  s  . co  m
                    monitor.worked(1);
                }
                dbManager.closeTrash();
                monitor.done();
            }
        };
        try {
            IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
            if (workbenchWindow != null)
                new ProgressMonitorDialog(workbenchWindow.getShell()).run(false, true, runnable);
            else
                runnable.run(new NullProgressMonitor());
        } catch (InvocationTargetException e) {
            // ignore
        } catch (InterruptedException e) {
            // ignore
        }
    }
}