List of usage examples for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress
IRunnableWithProgress
From source file:com.googlecode.goclipse.ui.properties.GoProjectBuildOptionsPage.java
License:Open Source License
@Override protected void performApply() { IRunnableWithProgress runnable = new IRunnableWithProgress() { @Override/* w w w . ja v a2s . co m*/ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { // GoPath setting if (selectedProjects != null) { Environment.INSTANCE.setProjectDependency(currentProject, selectedProjects); selectedProjects = null; } // Build options Properties props = Environment.INSTANCE.getProjectProperties(currentProject); int selectIndex = buildOptionCombo.getSelectionIndex(); if (selectIndex == 0) { props.setProperty(GoConstants.CurrentBuildType, BuildConfiguration.RELEASE.name()); props.setProperty(BuildConfiguration.RELEASE.name(), buildOptionTxt.getText()); } else { props.setProperty(GoConstants.CurrentBuildType, BuildConfiguration.DEBUG.name()); props.setProperty(BuildConfiguration.DEBUG.name(), buildOptionTxt.getText()); } } }; GoUIPlugin.fireProjectChange(currentProject, runnable); super.performApply(); }
From source file:com.googlecode.osde.internal.ui.wizards.export.OpenSocialApplicationExportWizard.java
License:Apache License
private void export() { final IProject project = page.getProject(); final String url = page.getUrl(); final String output = page.getOutput(); IRunnableWithProgress op = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { ZipOutputStream out = null; try { ResourceCounter resourceCounter = new ResourceCounter(); project.accept(resourceCounter); int fileCount = resourceCounter.getFileCount(); monitor.beginTask("Exporting application", fileCount); out = new ZipOutputStream(new FileOutputStream(new File(output))); project.accept(new ApplicationExporter(out, project, url, monitor)); monitor.done();//from ww w . j a va2 s . c o m } catch (CoreException e) { throw new InvocationTargetException(e); } catch (IOException e) { throw new InvocationTargetException(e); } finally { IOUtils.closeQuietly(out); } } }; try { getContainer().run(true, true, op); } catch (InterruptedException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { Throwable t = e.getTargetException(); if (t.getCause() instanceof CoreException) { CoreException cause = (CoreException) t.getCause(); StatusAdapter status = new StatusAdapter(StatusUtil.newStatus(cause.getStatus().getSeverity(), "Error occurred when exporting application.", cause)); status.setProperty(IStatusAdapterConstants.TITLE_PROPERTY, "Error occurred when exporting application."); StatusManager.getManager().handle(status, StatusManager.BLOCK); } else { StatusAdapter status = new StatusAdapter( StatusUtil.newStatus(IStatus.WARNING, "Error occurred when exporting application.", t)); status.setProperty(IStatusAdapterConstants.TITLE_PROPERTY, "Error occurred when exporting application."); StatusManager.getManager().handle(status, StatusManager.BLOCK); } } }
From source file:com.googlecode.osde.internal.ui.wizards.newjsprj.NewOpenSocialProjectResourceWizard.java
License:Apache License
private IProject createNewProject() { if (newProject != null) { return newProject; }//from ww w . ja v a2 s.com // final IProject newProjectHandle = mainPage.getProjectHandle(); String projectName = mainPage.getProjectName(); URI location = null; if (!mainPage.useDefaults()) { location = mainPage.getLocationURI(); } IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IProject newProjectHandle = workspace.getRoot().getProject(projectName); final IProjectDescription description = workspace.newProjectDescription(projectName); description.setLocationURI(location); final GadgetXmlData gadgetXmlData = gadgetXmlPage.getInputtedData(); final EnumMap<ViewName, GadgetViewData> gadgetViewData = viewPage.getInputedData(); IRunnableWithProgress op = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException { try { newProjectHandle.create(description, monitor); newProjectHandle.open(monitor); IProjectDescription description = newProjectHandle.getDescription(); if (!description.hasNature(OsdeProjectNature.ID)) { String[] ids = description.getNatureIds(); String[] newIds = new String[ids.length + 1]; System.arraycopy(ids, 0, newIds, 0, ids.length); newIds[ids.length] = OsdeProjectNature.ID; description.setNatureIds(newIds); newProjectHandle.setDescription(description, monitor); } final IFile gadgetXmlFile = (new GadgetXmlFileGenerator(newProjectHandle, gadgetXmlData, gadgetViewData)).generate(monitor); (new JavaScriptFileGenerator(newProjectHandle, gadgetXmlData, gadgetViewData)) .generate(monitor); monitor.beginTask("Opening the Gadget XML file.", 1); getShell().getDisplay().syncExec(new Runnable() { public void run() { IWorkbenchWindow dw = getWorkbench().getActiveWorkbenchWindow(); try { if (dw != null) { IWorkbenchPage page = dw.getActivePage(); if (page != null) { IDE.openEditor(page, gadgetXmlFile, GadgetXmlEditor.ID, true); } } } catch (PartInitException e) { throw new RuntimeException(e); } } }); monitor.worked(1); monitor.done(); } catch (CoreException e) { throw new InvocationTargetException(e); } catch (UnsupportedEncodingException e) { throw new InvocationTargetException(e); } catch (IOException e) { throw new InvocationTargetException(e); } } }; try { getContainer().run(true, true, op); } catch (InterruptedException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { Throwable t = e.getTargetException(); if (t.getCause() instanceof CoreException) { CoreException cause = (CoreException) t.getCause(); StatusAdapter status = new StatusAdapter(StatusUtil.newStatus(cause.getStatus().getSeverity(), "Error occurred when creating project.", cause)); status.setProperty(IStatusAdapterConstants.TITLE_PROPERTY, "Error occurred when creating project."); StatusManager.getManager().handle(status, StatusManager.BLOCK); } else { StatusAdapter status = new StatusAdapter( StatusUtil.newStatus(IStatus.WARNING, "Error occurred when creating project.", t)); status.setProperty(IStatusAdapterConstants.TITLE_PROPERTY, "Error occurred when creating project."); StatusManager.getManager().handle(status, StatusManager.BLOCK); } return null; } newProject = newProjectHandle; return newProject; }
From source file:com.gorillalogic.monkeyconsole.wizard.NewProjectWizard.java
License:Open Source License
/** * Creates a new project resource with the selected name. * <p>/* w w w .ja v a2s . c o m*/ * 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 the pages currently contain valid values. * </p> * <p> * Note that this wizard caches the new project once it has been * successfully created; subsequent invocations of this method will answer * the same project resource without attempting to create it again. * </p> * * @return the created project resource, or <code>null</code> if the project * was not created */ private IProject createNewProject() { if (newProject != null) { return newProject; } // get a project handle final IProject newProjectHandle = mainPage.getProjectHandle(); // get a project descriptor URI location = null; if (!mainPage.useDefaults()) { location = mainPage.getLocationURI(); } IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName()); description.setLocationURI(location); // update the referenced project if provided if (referencePage != null) { IProject[] refProjects = referencePage.getReferencedProjects(); if (refProjects.length > 0) { description.setReferencedProjects(refProjects); } } // create the new project operation IRunnableWithProgress op = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException { CreateProjectOperation op = new CreateProjectOperation(description, ResourceMessages.NewProject_windowTitle); try { PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(op, monitor, WorkspaceUndoUtil.getUIInfoAdapter(getShell())); } catch (ExecutionException e) { throw new InvocationTargetException(e); } } }; // run the new project creation operation try { getContainer().run(true, true, op); } catch (InterruptedException e) { return null; } catch (InvocationTargetException e) { Throwable t = e.getTargetException(); if (t instanceof ExecutionException && t.getCause() instanceof CoreException) { CoreException cause = (CoreException) t.getCause(); StatusAdapter status; if (cause.getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) { status = new StatusAdapter(StatusUtil.newStatus(IStatus.WARNING, NLS .bind(ResourceMessages.NewProject_caseVariantExistsError, newProjectHandle.getName()), cause)); } else { status = new StatusAdapter(StatusUtil.newStatus(cause.getStatus().getSeverity(), ResourceMessages.NewProject_errorMessage, cause)); } status.setProperty(StatusAdapter.TITLE_PROPERTY, ResourceMessages.NewProject_errorMessage); StatusManager.getManager().handle(status, StatusManager.BLOCK); } else { StatusAdapter status = new StatusAdapter( new Status(IStatus.WARNING, IDEWorkbenchPlugin.IDE_WORKBENCH, 0, NLS.bind(ResourceMessages.NewProject_internalError, t.getMessage()), t)); status.setProperty(StatusAdapter.TITLE_PROPERTY, ResourceMessages.NewProject_errorMessage); StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.BLOCK); } return null; } newProject = newProjectHandle; File f = new File(newProject.getLocationURI().getPath() + "/libs/"); try { addNature(newProject); f.mkdir(); //System.out.println(f.getAbsolutePath() + "/MonkeyTalkAPI.js"); BufferedWriter out = new BufferedWriter( new FileWriter(new File(f.getAbsolutePath() + "/MonkeyTalkAPI.js"))); out.write(fileToString("templates/MonkeyTalkAPI.js")); out.close(); newProject.refreshLocal(IResource.DEPTH_INFINITE, null); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return newProject; }
From source file:com.gwtplatform.plugin.wizard.MergeLocalesWizard.java
License:Apache License
@Override public boolean performFinish() { try {/*from w w w . j ava2 s. co m*/ super.getContainer().run(false, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { isDone = finish(monitor); } }); } catch (Exception e) { return false; } return isDone; }
From source file:com.gwtplatform.plugin.wizard.NewActionWizard.java
License:Apache License
@Override public boolean performFinish() { try {/* w w w . j av a 2s.c om*/ super.getContainer().run(false, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { isDone = finish(monitor); } }); } catch (Exception e) { e.printStackTrace(); return false; } return isDone; }
From source file:com.helio.boomer.rap.security.login.AbstractLoginDialog.java
License:Open Source License
public void handle(final Callback[] callbacks) throws IOException { this.callbackArray = callbacks; final Display display = Display.getDefault(); display.syncExec(new Runnable() { public void run() { isCancelled = false;//from www . j a v a2s. c om setBlockOnOpen(false); open(); final Button okButton = getButton(IDialogConstants.OK_ID); okButton.setText("Login"); okButton.addSelectionListener(new SelectionListener() { public void widgetSelected(final SelectionEvent event) { processCallbacks = true; } public void widgetDefaultSelected(final SelectionEvent event) { // nothing to do } }); final Button cancel = getButton(IDialogConstants.CANCEL_ID); cancel.addSelectionListener(new SelectionListener() { public void widgetSelected(final SelectionEvent event) { isCancelled = true; processCallbacks = true; } public void widgetDefaultSelected(final SelectionEvent event) { // nothing to do } }); } }); try { ModalContext.setAllowReadAndDispatch(true); // Works for now. ModalContext.run(new IRunnableWithProgress() { public void run(final IProgressMonitor monitor) { // Wait here until OK or cancel is pressed, then let it rip. The event listener // is responsible for closing the dialog (in the loginSucceeded event). while (!processCallbacks) { try { Thread.sleep(100); } catch (final Exception e) { // do nothing } } processCallbacks = false; // Call the adapter to handle the callbacks if (!isCancelled()) internalHandle(); } }, true, new NullProgressMonitor(), Display.getDefault()); } catch (final Exception e) { final IOException ioe = new IOException(); ioe.initCause(e); throw ioe; } }
From source file:com.horstmann.violet.eclipseplugin.wizards.NewWizard.java
License:Open Source License
/** * Called by eclipse when wizard ends// w ww.j ava 2 s .c om */ public boolean performFinish() { String fname = creationPage.getFileName(); if (!fname.toLowerCase().endsWith(getFileExtension())) { creationPage.setFileName(fname + getFileExtension()); } if (creationPage.getErrorMessage() != null) return false; final IFile file = creationPage.createNewFile(); IRunnableWithProgress op = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException { try { doFinish(file, monitor); } catch (CoreException e) { throw new InvocationTargetException(e); } finally { monitor.done(); } } }; 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.hsveclipse.phototoolkit.application.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();// w ww . ja va 2s . co m 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.htmlhifive.tools.jslint.actions.CheckJavaScriptAction.java
License:Apache License
@Override public void doRun(IAction action, final StatusList statusList) { IProgressService service = PlatformUI.getWorkbench().getProgressService(); try {//from w w w. j a v a 2s . com service.run(true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InterruptedException { Parser parser = JsParserFactory.createParser(getResource()); try { JsParseResult jsParseResult = parser.parse(monitor); statusList.add(new Status(IStatus.INFO, JSLintPlugin.PLUGIN_ID, "?????? : " + jsParseResult.getErrorCount())); } catch (CoreException e) { if (e.getCause() != null) { logger.put(Messages.EM0100, e.getCause()); } statusList.add(e.getStatus()); return; } } }); PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() .showView("org.eclipse.ui.views.ProblemView"); } catch (InvocationTargetException e) { logger.put(Messages.EM0001, e); statusList.add(new Status(IStatus.ERROR, JSLintPlugin.PLUGIN_ID, Messages.EM0100.getText(), e)); } catch (InterruptedException e) { // ignore } catch (PartInitException e) { logger.put(Messages.EM0100, e); statusList.add(e.getStatus()); } }