List of usage examples for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress
IRunnableWithProgress
From source file:com.iw.plugins.spindle.ui.wizards.NewTapComponentWizardPage.java
License:Mozilla Public License
public IRunnableWithProgress getAutoAddRunnable() throws IOException, CoreException { if (!fShowingAdvanced) return null; final INamespace namespace = fNamespaceDialogField.getSelectedNamespace(); if (namespace == null) return null; final boolean addingNewComponent = getWizard().getClass() == NewTapComponentWizard.class; final String name = fComponentNameDialogField.getTextValue(); ITapestryProject tproject = fTapestryProjectDialogField.getTapestryProject(); final IFolder webInf = tproject.getWebContextFolder().getFolder("WEB-INF"); return new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { if (monitor == null) monitor = new NullProgressMonitor(); String specificationPath; IDocument document;/*from ww w . ja v a 2s. c o m*/ IEditorPart editor = null; PluginLibrarySpecification library; IFile file = null; library = (PluginLibrarySpecification) namespace.getSpecification(); IResourceWorkspaceLocation location = (IResourceWorkspaceLocation) namespace .getSpecificationLocation(); file = (IFile) location.getStorage(); editor = UIUtils.getEditorFor(location); if (namespace.isApplicationNamespace() && !((CoreNamespace) namespace).isOnClassPath()) { IFolder applicationSpecFolder = (IFolder) file.getParent(); // first eliminate folders where no changes to .application are // needed. // not needed if web-inf. IFolder chosenFolder = fApplicationLocationField.getSpecLocation(); if (chosenFolder.equals(webInf)) return; // not needed if same folder as .application if (applicationSpecFolder.equals(chosenFolder)) return; // not needed if same folder as WEB-INF/servletname TODO confirm String appName = ((PluginApplicationSpecification) library).getName(); if (webInf.getFolder(appName).equals(chosenFolder)) return; IPath webInfPath = webInf.getFullPath(); IPath applicationFileFolderPath = applicationSpecFolder.getFullPath(); IPath usePath = chosenFolder.getFullPath(); // now that we have eliminated all the ones that need no mods... // two options, a relative path if the chosen location is a subFolder // of the .applciation file if (applicationFileFolderPath.isPrefixOf(usePath)) { usePath = usePath.removeFirstSegments(applicationFileFolderPath.segmentCount()) .makeRelative(); } else { // or otherwise an absolute path including WEB-INF usePath = usePath.removeFirstSegments(webInfPath.segmentCount() - 1).makeAbsolute(); } specificationPath = usePath.toString() + "/" + name + (addingNewComponent ? ".jwc" : ".page"); } else { IPackageFragment fragment = fLibraryPackageField.getPackageFragment(); specificationPath = ("/" + fragment.getElementName().replace('.', '/')) + "/" + name + (addingNewComponent ? ".jwc" : ".page"); } if (editor != null && editor.isDirty()) { RequiredSaveEditorAction saver = new RequiredSaveEditorAction(editor); if (!saver.save("Save files", "It is strongly recommended you save all here.")) throw new InterruptedException("ack!"); try { file.getProject().build(TapestryBuilder.INCREMENTAL_BUILD, monitor); } catch (CoreException e1) { UIPlugin.log(e1); throw new InvocationTargetException(e1); } Map specMap = TapestryArtifactManager.getTapestryArtifactManager().getSpecMap(file.getProject(), false); library = specMap == null ? null : (PluginLibrarySpecification) specMap.get(file); } if (editor != null && editor instanceof AbstractTextEditor) { AbstractTextEditor textEditor = (AbstractTextEditor) editor; document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()); } else { // we turf the editor if its not null 'cuz we can't get a document // from it. try { editor = null; document = new Document(); document.set(Files.readFileToString(file.getContents(), null)); } catch (IOException e1) { throw new InvocationTargetException(e1); } catch (CoreException e1) { throw new InvocationTargetException(e1); } } LibraryEdits helper = addingNewComponent ? new LibraryEdits(library, document) : new ApplicationEdits((PluginApplicationSpecification) library, document); try { if (addingNewComponent) { helper.addComponentDeclaration(name, specificationPath); } else { helper.addPageDeclaration(name, specificationPath); } helper.apply(); } catch (MalformedTreeException e) { UIPlugin.log(e); throw new InvocationTargetException(e); } catch (BadLocationException e) { UIPlugin.log(e); throw new InvocationTargetException(e); } catch (TapestryException e) { UIPlugin.log(e); throw new InvocationTargetException(e); } if (editor != null) { editor.doSave(monitor); } else { ByteArrayInputStream b = new ByteArrayInputStream(document.get().getBytes()); try { file.setContents(b, true, true, monitor); } catch (CoreException e1) { UIPlugin.log(e1); throw new InvocationTargetException(e1); } } } }; }
From source file:com.iw.plugins.spindle.ui.wizards.project.BaseNewTapestryProjectJavaPage.java
License:Mozilla Public License
public void changeToNewProject() { IProject newProjectHandle = fMainPage.getProjectHandle(); IPath newProjectLocation = fMainPage.getLocationPath(); if (fMainPage.useDefaults()) { fCanRemoveContent = !newProjectLocation.append(fMainPage.getProjectName()).toFile().exists(); } else {/*from w ww . j av a2s. c o m*/ fCanRemoveContent = !newProjectLocation.toFile().exists(); } final boolean initialize = !(newProjectHandle.equals(fCurrProject) && newProjectLocation.equals(fCurrProjectLocation)); IRunnableWithProgress op = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { updateProject(initialize, monitor); } catch (CoreException e) { throw new InvocationTargetException(e); } } }; try { IRunnableContext context = (IRunnableContext) getContainer(); if (context == null) { if (getWizard() == null) { UIPlugin.log("creating : wizard is null: bug [ 843021 ] Is this what 3 Beta is supposed to do"); } else { UIPlugin.log( "creating : container not set in wizard: bug [ 843021 ] Is this what 3 Beta is supposed to do"); } context = (IRunnableContext) UIPlugin.getDefault().getActivePage(); } context.run(false, true, op); } catch (InvocationTargetException e) { String title = NewWizardMessages .getString("NewProjectCreationWizardPage.EarlyCreationOperation.error.title"); //$NON-NLS-1$ String message = NewWizardMessages .getString("NewProjectCreationWizardPage.EarlyCreationOperation.error.desc"); //$NON-NLS-1$ ExceptionHandler.handle(e, getShell(), title, message); } catch (InterruptedException e) { // cancel pressed } }
From source file:com.iw.plugins.spindle.ui.wizards.project.BaseNewTapestryProjectJavaPage.java
License:Mozilla Public License
public void removeProject() { if (fCurrProject == null || !fCurrProject.exists()) { return;/*from w w w . jav a 2 s. c om*/ } IRunnableWithProgress op = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { boolean noProgressMonitor = Platform.getLocation().equals(fCurrProjectLocation); if (monitor == null || noProgressMonitor) { monitor = new NullProgressMonitor(); } monitor.beginTask(NewWizardMessages.getString("NewProjectCreationWizardPage.removeproject.desc"), //$NON-NLS-1$ 3); try { fCurrProject.delete(fCanRemoveContent, false, monitor); } catch (CoreException e) { throw new InvocationTargetException(e); } finally { monitor.done(); fCurrProject = null; fCanRemoveContent = false; } } }; try { IRunnableContext context = (IRunnableContext) getContainer(); if (context == null) { if (getWizard() == null) { UIPlugin.log("removing : wizard is null: bug [ 843021 ] Is this what 3 Beta is supposed to do"); } else { UIPlugin.log( "removing : container not set in wizard: bug [ 843021 ] Is this what 3 Beta is supposed to do"); } context = (IRunnableContext) UIPlugin.getDefault().getActivePage(); } context.run(false, true, op); } catch (InvocationTargetException e) { String title = NewWizardMessages.getString("NewProjectCreationWizardPage.op_error.title"); //$NON-NLS-1$ String message = NewWizardMessages.getString("NewProjectCreationWizardPage.op_error_remove.message"); //$NON-NLS-1$ ExceptionHandler.handle(e, getShell(), title, message); } catch (InterruptedException e) { // cancel pressed } }
From source file:com.iw.plugins.spindle.ui.wizards.project.BaseTemplateSelectionPage.java
License:Mozilla Public License
public IRunnableWithProgress getRunnable(Object object) { if (fUseWorkspaceDefaultTemplates.getSelection()) { fListener.stop();/* www . j a v a 2 s . co m*/ fLibraryTemplateSelector.loadDefault(); fComponentTemplateSelector.loadDefault(); fPageTemplateSelector.loadDefault(); fTapestryTemplateSelector.loadDefault(); } IProject project = null; if (object instanceof IProject) { project = (IProject) object; } else if (object instanceof IJavaProject) { project = ((IJavaProject) object).getProject(); } if (project != null) { final IProject useProject = project; final ProjectPreferenceStore dirtyStore = fProjectPreferences; return new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { IFile dataFile = useProject.getFile(UIPlugin.SPINDLEUI_PREFS_FILE); String fullname; if (dataFile.exists()) { fullname = dataFile.getLocation().toOSString(); } else { fullname = useProject.getLocation().toOSString() + File.separator + UIPlugin.SPINDLEUI_PREFS_FILE; } dirtyStore.setFilename(fullname); dirtyStore.save(); } catch (Exception e) { UIPlugin.log(e); throw new InvocationTargetException(e); } } }; } return null; }
From source file:com.iw.plugins.spindle.ui.wizards.project.NewTapestryProjectWizard.java
License:Mozilla Public License
/** * @see Wizard#performFinish()/* w w w .j a v a 2 s. c o m*/ */ public boolean performFinish() { if (finishPage(fJavaPage.getRunnable())) { IJavaProject jproject = fJavaPage.getJavaProject(); fInstallData.setProject(jproject.getProject()); fInstallData.setApplicationFactory(new ApplicationFactory()); fInstallData.setPageFactory(new PageFactory()); fInstallData.setTemplateFactory(new TapestryTemplateFactory()); fInstallData.setTemplateSource(fTemplatePage); IRunnableWithProgress operation = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { ArrayList created = new ArrayList(); IStatus status = new SpindleStatus(); monitor.beginTask("", 100); TapestryProjectInstaller installer = new TapestryProjectInstaller(fInstallData); status = installer.configureTapestryProject(created, new SubProgressMonitor(monitor, 50)); if (!status.isOK()) { ErrorDialog.openError(null, "Tapestry Install Problems", "Unable to create all Tapestry files.", status); return; } status = installer.addTapestryNature(new SubProgressMonitor(monitor, 50)); if (!status.isOK()) { ErrorDialog.openError(null, "Tapestry Install Problems", "Unable to install the Tapestry nature.", status); return; } for (Iterator iter = created.iterator(); iter.hasNext();) { IResource element = (IResource) iter.next(); selectAndReveal(element); } } }; finishPage(operation); finishPage(fTemplatePage.getRunnable(fInstallData.getProject())); } return true; }
From source file:com.iw.plugins.spindle.ui.wizards.source.MoveImplicitToSpecWizard.java
License:Mozilla Public License
private IRunnableWithProgress getRunnable() { return new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { doFinish(monitor);//w w w.j ava 2s .c om } }; }
From source file:com.iw.plugins.spindle.ui.wizards.TypeChooseWizardPage.java
License:Mozilla Public License
public IRunnableWithProgress getRunnable(Object object) { return new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { if (monitor == null) { monitor = new NullProgressMonitor(); }//from w w w. j a v a 2 s .c o m if (fChooseClass.getCheckBoxValue()) { fFinalSpecClass = fChooseSpecClassDialogField.getType(); } else { createType(new SubProgressMonitor(monitor, 1)); fFinalSpecClass = getCreatedType(); } monitor.done(); } catch (CoreException e) { throw new InvocationTargetException(e); } } }; }
From source file:com.iw.plugins.spindle.util.PublicStaticFieldSearchEngine.java
License:Mozilla Public License
/** * Searches for all types with public static fields in the given scope. * Valid styles are IJavaElementSearchConstants.CONSIDER_BINARIES and * IJavaElementSearchConstants.CONSIDER_EXTERNAL_JARS */// w ww . ja va 2s .c om public IType[] searchPublicStaticMethods(IRunnableContext context, final IJavaSearchScope scope, final int style) throws InvocationTargetException, InterruptedException { int allFlags = IJavaElementSearchConstants.CONSIDER_EXTERNAL_JARS | IJavaElementSearchConstants.CONSIDER_BINARIES; Assert.isTrue((style | allFlags) == allFlags); final IType[][] res = new IType[1][]; IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor pm) throws InvocationTargetException { try { long start = new Date().getTime(); res[0] = searchPublicStaticMethods(pm, scope, style); } catch (JavaModelException e) { throw new InvocationTargetException(e); } } }; context.run(true, true, runnable); return res[0]; }
From source file:com.iw.plugins.spindle.wizards.migrate.MigrationWizard.java
License:Mozilla Public License
/** * @see org.eclipse.jface.wizard.IWizard#performFinish() */// w w w.j av a 2s . c o m public boolean performFinish() { List undefinedComponents = collectUndefined(); Map migratorMap = context.getMigrationMap(); MigrationWorkUnit libraryWorker = (MigrationWorkUnit) migratorMap .get(context.getContextModel().getUnderlyingStorage()); final ArrayList migrators = orderedMigrators(migratorMap, libraryWorker); IPluginLibrarySpecification librarySpec = (IPluginLibrarySpecification) context.getContextModel() .getSpecification(); List convertToNewPages = new ArrayList(); if (getContainer().getCurrentPage() == definePage) { convertToNewPages = definePage.getNewPages(); } undefinedComponents.removeAll(convertToNewPages); createMigratorsForUndefined(undefinedComponents, migratorMap, migrators, librarySpec, convertToNewPages); migrators.add(0, libraryWorker); return doFinish(new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { TapestryProject.migrating = true; monitor.beginTask("Performing Migration", migrators.size() * 2); for (Iterator iter = migrators.iterator(); iter.hasNext();) { MigrationWorkUnit worker = (MigrationWorkUnit) iter.next(); try { worker.migrate(); monitor.worked(1); } catch (CoreException e) { TapestryProject.migrating = false; throw new InvocationTargetException(e); } } for (Iterator iter = migrators.iterator(); iter.hasNext();) { MigrationWorkUnit worker = (MigrationWorkUnit) iter.next(); try { worker.commitMigration(monitor); monitor.worked(1); } catch (CoreException e) { TapestryProject.migrating = false; throw new InvocationTargetException(e); } } } finally { TapestryProject.migrating = false; } } }); }
From source file:com.iw.plugins.spindle.wizards.NewTapComponentWizardPage.java
License:Mozilla Public License
/** * @see NewElementWizardPage#getRunnable() *//*from ww w . j av a 2 s .com*/ public IRunnableWithProgress getRunnable(Object specClass) { final IType useClass = (IType) specClass; return new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { if (monitor == null) { monitor = new NullProgressMonitor(); } createComponentResource(new SubProgressMonitor(monitor, 1), useClass); if (fGenerateHTML.getCheckBoxValue()) { createHTMLResource(new SubProgressMonitor(monitor, 1)); } monitor.done(); } catch (CoreException e) { throw new InvocationTargetException(e); } } }; }