Example usage for org.eclipse.jface.operation IRunnableContext IRunnableContext

List of usage examples for org.eclipse.jface.operation IRunnableContext IRunnableContext

Introduction

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

Prototype

IRunnableContext

Source Link

Usage

From source file:cn.dockerfoundry.ide.eclipse.server.ui.internal.wizards.WizardHandleContext.java

License:Open Source License

public IRunnableContext getRunnableContext() {
    return new IRunnableContext() {
        public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
                throws InvocationTargetException, InterruptedException {
            wizardHandle.run(fork, cancelable, runnable);
        }//from www.j  av  a2s .  com
    };
}

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 av  a2 s. c o m

    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/*from w w w  .j  a v a2s  .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.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/*w w  w .java2s. 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:ext.org.eclipse.jdt.internal.ui.text.correction.proposals.FixCorrectionProposal.java

License:Open Source License

public void resolve(MultiFixTarget[] targets, final IProgressMonitor monitor) throws CoreException {
    if (targets.length == 0)
        return;/*from   w  ww  .  ja v a2 s  . c o m*/

    if (fCleanUp == null)
        return;

    String changeName;
    String[] descriptions = fCleanUp.getStepDescriptions();
    if (descriptions.length == 1) {
        changeName = descriptions[0];
    } else {
        changeName = CorrectionMessages.FixCorrectionProposal_MultiFixChange_label;
    }

    final CleanUpRefactoring refactoring = new CleanUpRefactoring(changeName);
    for (int i = 0; i < targets.length; i++) {
        refactoring.addCleanUpTarget(targets[i]);
    }

    refactoring.addCleanUp(fCleanUp);

    IRunnableContext context = new IRunnableContext() {
        public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
                throws InvocationTargetException, InterruptedException {
            runnable.run(monitor == null ? new NullProgressMonitor() : monitor);
        }
    };

    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    RefactoringExecutionHelper helper = new RefactoringExecutionHelper(refactoring, IStatus.INFO,
            RefactoringSaveHelper.SAVE_REFACTORING, shell, context);
    try {
        helper.perform(true, true);
    } catch (InterruptedException e) {
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();
        if (cause instanceof CoreException) {
            throw (CoreException) cause;
        } else {
            throw new CoreException(
                    new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, cause.getLocalizedMessage(), cause));
        }
    }
}

From source file:org.cloudfoundry.ide.eclipse.internal.server.ui.editor.CloudFoundryCredentialsPart.java

License:Open Source License

protected IRunnableContext getRunnableContext() {
    IWizardContainer wizardContainer = getWizardContainer();
    if (wizardContainer != null) {
        return wizardContainer;
    } else if (wizardHandle != null) {
        return new IRunnableContext() {
            public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
                    throws InvocationTargetException, InterruptedException {
                wizardHandle.run(fork, cancelable, runnable);
            }//w  w w.ja v a 2 s. c o m
        };
    } else {
        return PlatformUI.getWorkbench().getProgressService();
    }
}

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.//  w ww  .  j a v  a 2  s. c o m
 * @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.gmf.examples.runtime.diagram.logic.internal.util.LogicEditorUtil.java

License:Open Source License

/**
 * Creates a new diagram file resource in the selected container and with
 * the selected name. Creates any missing resource containers along the
 * path; does nothing if the container resources already exist.
 * <p>//  w  w w  .j a  v  a  2  s .  c om
 * In normal usage, this method is invoked after the user has pressed Finish
 * on the wizard; the enablement of the Finish button implies that all
 * controls on on this page currently contain valid values.
 * </p>
 * <p>
 * Note that this page caches the new file once it has been successfully
 * created; subsequent invocations of this method will answer the same file
 * resource without attempting to create it again.
 * </p>
 * <p>
 * This method should be called within a workspace modify operation since it
 * creates resources.
 * </p>
 *
 * @return the created file resource, or <code>null</code> if the file was
 *         not created
 */
public static final IFile createNewDiagramFile(DiagramFileCreator diagramFileCreator, IPath containerFullPath,
        String fileName, InputStream initialContents, final String kind, Shell shell,
        final IProgressMonitor progressMonitor, final String semanticResourcePath) {

    /** cache of newly-created file */
    final IFile newDiagramFile = diagramFileCreator.createNewFile(containerFullPath, fileName, initialContents,
            shell, new IRunnableContext() {
                public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
                        throws InvocationTargetException, InterruptedException {
                    runnable.run(progressMonitor);
                }
            });

    TransactionalEditingDomain domain = GMFEditingDomainFactory.getInstance().createEditingDomain();
    final ResourceSet resourceSet = domain.getResourceSet();

    AbstractEMFOperation op = new AbstractEMFOperation(domain,
            ExampleDiagramLogicMessages.LogicWizardPage_Title) {

        protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {

            IFile semanticFile = null;
            boolean semanticFileIsNew = false;
            if (semanticResourcePath != null && semanticResourcePath.length() > 0) {
                try {
                    semanticFile = ResourcesPlugin.getWorkspace().getRoot()
                            .getFile(new Path(semanticResourcePath));
                } catch (Exception e) {

                }
                if (!semanticFile.exists()) {
                    semanticFileIsNew = true;
                    try {
                        semanticFile.create(new ByteArrayInputStream(new byte[0]), false, progressMonitor);
                    } catch (CoreException e) {
                        Log.error(LogicDiagramPlugin.getInstance(), IStatus.ERROR, e.getMessage(), e);
                        return null;
                    }
                }
            }

            try {
                newDiagramFile.refreshLocal(IResource.DEPTH_ZERO, null);
                if (semanticFile != null) {
                    semanticFile.refreshLocal(IResource.DEPTH_ZERO, null);
                }
            } catch (CoreException e) {
                Trace.catching(LogicDiagramPlugin.getInstance(), LogicDiagramDebugOptions.EXCEPTIONS_CATCHING,
                        LogicEditorUtil.class, "createNewDiagramFile", //$NON-NLS-1$
                        e);
            }

            Model semanticModel = null;
            if (semanticFileIsNew) {
                // create blank semantic model
                semanticModel = SemanticFactory.eINSTANCE.createModel();
                Resource semanticResource = resourceSet
                        .createResource(URI.createPlatformResourceURI(semanticResourcePath, true));
                semanticResource.getContents().add(semanticModel);
            } else if (semanticFile != null) {
                // load provided semantic model
                semanticModel = (Model) resourceSet
                        .getResource(URI.createPlatformResourceURI(semanticResourcePath, true), true)
                        .getContents().get(0);
            }

            // create blank notation model file
            final String completeFileName = newDiagramFile.getLocation().toOSString();
            Resource notationModel = resourceSet.createResource(URI.createFileURI(completeFileName));

            if (semanticModel == null) {
                semanticModel = SemanticFactory.eINSTANCE.createModel();
                notationModel.getContents().add(semanticModel);
            }

            Diagram view = ViewService.createDiagram(semanticModel, kind,
                    new PreferencesHint(LogicDiagramPlugin.EDITOR_ID));

            if (view != null) {
                notationModel.getContents().add(0, view);
                view.getDiagram().setName(newDiagramFile.getName());
            }

            try {
                notationModel.save(Collections.EMPTY_MAP);
                semanticModel.eResource().save(Collections.EMPTY_MAP);
            } catch (IOException e) {
                Trace.catching(LogicDiagramPlugin.getInstance(), LogicDiagramDebugOptions.EXCEPTIONS_CATCHING,
                        LogicEditorUtil.class, "createNewDiagramFile", e); //$NON-NLS-1$
                Log.error(LogicDiagramPlugin.getInstance(), LogicDiagramStatusCodes.IGNORED_EXCEPTION_WARNING,
                        e.getLocalizedMessage());
            }

            return Status.OK_STATUS;
        }
    };

    try {
        op.execute(new NullProgressMonitor(), null);

    } catch (ExecutionException e) {
        Trace.catching(LogicDiagramPlugin.getInstance(), LogicDiagramDebugOptions.EXCEPTIONS_CATCHING,
                LogicEditorUtil.class, "createNewDiagramFile", e); //$NON-NLS-1$
        Log.error(LogicDiagramPlugin.getInstance(), LogicDiagramStatusCodes.IGNORED_EXCEPTION_WARNING,
                e.getLocalizedMessage());
    }

    return newDiagramFile;
}

From source file:org.eclipse.gmf.runtime.diagram.ui.resources.editor.util.EditorUtil.java

License:Open Source License

/**
 * Creates a new diagram file resource in the selected container and with
 * the selected name. Creates any missing resource containers along the
 * path; does nothing if the container resources already exist. Creates a
 * new editing domain for this diagram./*from  www .  java 2 s . c  o m*/
 * <p>
 * In normal usage, this method is invoked after the user has pressed Finish
 * on the wizard; the enablement of the Finish button implies that all
 * controls on on this page currently contain valid values.
 * </p>
 * <p>
 * Note that this page caches the new file once it has been successfully
 * created; subsequent invocations of this method will answer the same file
 * resource without attempting to create it again.
 * </p>
 * <p>
 * This method should be called within a workspace modify operation since it
 * creates resources.
 * </p>
 * 
 * @param preferencesHint
 *            The preference hint that is to be used to find the appropriate
 *            preference store from which to retrieve diagram preference
 *            values. The preference hint is mapped to a preference store in
 *            the preference registry <@link DiagramPreferencesRegistry>.
 * 
 * @return the created file resource, or <code>null</code> if the file was
 *         not created
 */
public static IFile createNewDiagramFile(DiagramFileCreator diagramFileCreator, IPath containerFullPath,
        String fileName, InputStream initialContents, final String kind, Shell shell,
        final IProgressMonitor progressMonitor, final PreferencesHint preferencesHint) {
    /** cache of newly-created file */
    final IFile newDiagramFile = diagramFileCreator.createNewFile(containerFullPath, fileName, initialContents,
            shell, new IRunnableContext() {

                public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
                        throws InvocationTargetException, InterruptedException {
                    runnable.run(progressMonitor);
                }
            });

    // Fill the contents of the file dynamically
    Resource notationModel = null;

    try {
        newDiagramFile.refreshLocal(IResource.DEPTH_ZERO, null); //RATLC00514368
        InputStream stream = newDiagramFile.getContents();
        String completeFileName = newDiagramFile.getFullPath().toString();

        try {
            // Empty file....
            ResourceSet resourceSet = new ResourceSetImpl();
            notationModel = resourceSet.createResource(URI.createPlatformResourceURI(completeFileName, true));
        } finally {
            stream.close();
        }

    } catch (Exception e) {
        Trace.catching(EditorPlugin.getInstance(), EditorDebugOptions.EXCEPTIONS_CATCHING, EditorUtil.class,
                "createNewDiagramFile", //$NON-NLS-1$
                e);
    }

    if (notationModel != null) {
        View view = ViewService.createDiagram(kind, preferencesHint);

        if (view != null) {
            notationModel.getContents().add(view.getDiagram());
            view.getDiagram().setName(newDiagramFile.getName());
        }
    }
    try {
        notationModel.save(Collections.EMPTY_MAP);
    } catch (IOException e) {
        Trace.catching(EditorPlugin.getInstance(), EditorDebugOptions.EXCEPTIONS_CATCHING, EditorUtil.class,
                "createNewDiagramFile", e); //$NON-NLS-1$
        Log.error(EditorPlugin.getInstance(), EditorStatusCodes.RESOURCE_FAILURE, e.getLocalizedMessage());
    }
    return newDiagramFile;
}

From source file:org.eclipse.m2e.editor.xml.internal.lifecycle.LifecycleMappingDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    Composite container = (Composite) super.createDialogArea(parent);
    Label label = new Label(container, SWT.NONE);
    label.setText("Select location to place ignore");
    pomComposite = new PomHierarchyComposite(container, SWT.BORDER);
    pomComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    pomComposite.addSelectionChangedListener(this);
    pomComposite.computeHeirarchy(facade, new IRunnableContext() {

        public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
                throws InvocationTargetException, InterruptedException {
            runnable.run(new NullProgressMonitor());
        }//from w w w.  j av a2  s .c  o  m
    });
    status = new CLabel(container, SWT.WRAP);
    status.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false));

    pluginProject = locatePlugin();
    return container;
}