List of usage examples for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress
IRunnableWithProgress
From source file:com.iw.plugins.spindle.core.builder.TapestryArtifactManager.java
License:Mozilla Public License
public Object getLastBuildState(final IProject project, final boolean buildIfRequired, IRunnableContext context) {//from w w w . j a va 2 s . c o m if (project == null) return null; if (!TapestryCore.hasTapestryNature(project)) return null; Object state = getProjectState(project); if (state == null && (buildIfRequired && canBuild(project))) { IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { fNonJobBuildLock.acquire(); Object state = getProjectState(project); if (state == null && (buildIfRequired && canBuild(project))) { project.build(IncrementalProjectBuilder.FULL_BUILD, TapestryCore.BUILDER_ID, new HashMap(), monitor); } } catch (CoreException e) { TapestryCore.log(e); } finally { fNonJobBuildLock.release(); } } }; try { context.run(false, false, runnable); } catch (Exception e) { TapestryCore.log(e); } state = getProjectState(project); } return state; }
From source file:com.iw.plugins.spindle.editorlib.RenamedLibraryAction.java
License:Mozilla Public License
/** * Method getRunnable.//w ww. ja v a2 s .c o m * @param toChange * @return IRunnableWithProgress */ private IRunnableWithProgress getRunnable(Object[] toChange, Map changeData, String oldLibraryName, String newLibraryName) { final Object[] useDirty = toChange; final Map useMap = changeData; final TapestryProjectModelManager useManager = mgr; final String useOld = oldLibraryName; final String useNew = newLibraryName; return new IRunnableWithProgress() { /** * @see org.eclipse.jface.operation.IRunnableWithProgress#run(IProgressMonitor) */ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { for (int i = 0; i < useDirty.length; i++) { IStorage storage = (IStorage) useDirty[i]; IEditorPart editor = Utils.getEditorFor(storage); if (editor != null) { if (editor.isDirty()) { editor.doSave(monitor); } SpindleMultipageEditor spindleEditor = (SpindleMultipageEditor) editor; TapestryComponentModel editorModel = (TapestryComponentModel) spindleEditor.getModel(); try { performChangeInModel(editorModel, useMap, useOld, useNew, monitor); } catch (RuntimeException e) { e.printStackTrace(); } editorModel.setOutOfSynch(true); // spindleEditor.showPage(spindleEditor.SOURCE_PAGE); spindleEditor.fireSaveNeeded(); } else { final TapestryComponentModel workspaceModel = (TapestryComponentModel) mgr .getEditableModel(storage, this); mgr.connect(storage, this); performChangeInModel(workspaceModel, useMap, useOld, useNew, monitor); try { (new WorkspaceModifyOperation() { public void execute(final IProgressMonitor monitor) throws CoreException { Utils.saveModel(workspaceModel, monitor); } }).execute(monitor); } catch (CoreException e) { } mgr.disconnect(workspaceModel, this); } } } }; }
From source file:com.iw.plugins.spindle.model.manager.TapestryProjectModelManager.java
License:Mozilla Public License
protected void initializeProjectTapestryModels() { if (initialized) { return;/* w ww . j ava 2 s . c om*/ } allModels = new ArrayList(); models = new HashMap(); if (project.isOpen()) { Shell shell = TapestryPlugin.getDefault().getActiveWorkbenchShell(); if (shell != null && shell.getVisible()) { IWorkbenchWindow window = TapestryPlugin.getDefault().getActiveWorkbenchWindow(); try { window.run(false, false, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { populateAllModels(project, TapestryLookup.ACCEPT_ANY, monitor); } }); } catch (InvocationTargetException e) { } catch (InterruptedException e) { } } else { populateAllModels(project, TapestryLookup.ACCEPT_ANY, new NullProgressMonitor()); } } IWorkspace workspace = TapestryPlugin.getDefault().getWorkspace(); workspace.addResourceChangeListener(this, IResourceChangeEvent.PRE_CLOSE | IResourceChangeEvent.PRE_DELETE | IResourceChangeEvent.PRE_AUTO_BUILD); initialized = true; }
From source file:com.iw.plugins.spindle.project.actions.MigrationModelManager.java
License:Mozilla Public License
/** * @see com.iw.plugins.spindle.model.manager.TapestryProjectModelManager#initializeProjectTapestryModels() *//*from w w w . j a v a2s . com*/ protected void initializeProjectTapestryModels() { if (initialized) { return; } initialized = true; allModels = new ArrayList(); models = new HashMap(); Shell shell = TapestryPlugin.getDefault().getActiveWorkbenchShell(); ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell); try { dialog.run(false, false, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { populateAllModels(project, TapestryLookup.ACCEPT_TAPESTRY_PROJECTS_ONLY | TapestryLookup.WRITEABLE, monitor); try { int acceptFlags = TapestryLookup.ACCEPT_LIBRARIES | TapestryLookup.FULL_TAPESTRY_PATH; IJavaProject jproject = TapestryPlugin.getDefault().getJavaProjectFor(project); TapestryLookup lookup = new TapestryLookup(); lookup.configure(jproject); IStorage storage = lookup.findDefaultLibrary(); if (storage != null) { TapestryLibraryModel framework = new TapestryLibraryModel(storage); framework.load(); setDefaultLibrary(framework); } } catch (CoreException e) { ErrorDialog.openError(TapestryPlugin.getDefault().getActiveWorkbenchShell(), "Migration Error", "could not find the Tapestry Project", e.getStatus()); } } }); } catch (InvocationTargetException e) { } catch (InterruptedException e) { } finally { } }
From source file:com.iw.plugins.spindle.refactor.components.RefactorComponentAliasWizard.java
License:Mozilla Public License
/** * Method setup./*from w w w . j a v a 2 s. co m*/ */ private void setup() { try { TapestryPlugin.getDefault().getActiveWorkbenchWindow().run(false, false, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { findAffectedComponents(); canShow = doAnyRequiredSaves(); } catch (CoreException e) { } } }); } catch (InvocationTargetException e) { } catch (InterruptedException e) { } }
From source file:com.iw.plugins.spindle.refactor.components.RefactorComponentAliasWizard.java
License:Mozilla Public License
/** * Method getFinishRunnable./* w w w. j a v a2s . c om*/ */ private IRunnableWithProgress getFinishRunnable() { return new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { TapestryProjectModelManager manager; try { manager = project.getModelManager(); } catch (CoreException e) { ErrorDialog.openError(getContainer().getShell(), "Spindle Error", "refactoring failed. could not obtain a model manager from the project", e.getStatus()); return; } monitor.beginTask("refactoring...", affectedComponents.size()); List affected = getFinalAffectedComponents(); for (Iterator iter = affected.iterator(); iter.hasNext();) { AffectedComponentHolder holder = (AffectedComponentHolder) iter.next(); IStorage storage = holder.model.getUnderlyingStorage(); IEditorPart editor = Utils.getEditorFor(storage); boolean pulledFromWorkspace = false; TapestryComponentModel model; try { if (editor == null) { model = (TapestryComponentModel) manager.getEditableModel(storage, this); pulledFromWorkspace = true; } else { model = holder.model; } if (model.isLoaded()) { PluginComponentSpecification componentSpec = (PluginComponentSpecification) model .getComponentSpecification(); String[] affectedIds = holder.getIds(); for (int i = 0; i < affectedIds.length; i++) { PluginContainedComponent contained = (PluginContainedComponent) componentSpec .getComponent(affectedIds[i]); if (contained != null && oldName.equals(contained.getType())) { contained.setType(newName); // we do this so that the editor's dity flag is in sync with the models dirty flag componentSpec.setComponent(affectedIds[i], contained); } } } monitor.worked(1); if (pulledFromWorkspace) { Utils.saveModel(model, monitor); } else { editor.doSave(monitor); if (editor instanceof SpindleMultipageEditor) { ((SpindleMultipageEditor) editor).showPage(SpindleMultipageEditor.SOURCE_PAGE); } } } finally { if (pulledFromWorkspace) { manager.disconnect(storage, this); } } } } }; }
From source file:com.iw.plugins.spindle.ui.properties.ProjectPropertyPage.java
License:Mozilla Public License
public boolean performOk() { Shell shell = UIPlugin.getDefault().getActiveWorkbenchShell(); if (shell == null) { try {/*from www. ja v a2 s . c o m*/ doOk(new NullProgressMonitor()); } catch (CoreException e) { UIPlugin.log(e); } } else { try { new ProgressMonitorDialog(shell).run(false, false, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { doOk(monitor); } catch (CoreException e) { UIPlugin.log(e); } } }); } catch (InvocationTargetException e) { UIPlugin.log(e); } catch (InterruptedException e) { UIPlugin.log(e); } } return true; }
From source file:com.iw.plugins.spindle.ui.widgets.TypeChooserWidget.java
License:Mozilla Public License
public void configure(final IJavaProject project, final IRunnableContext context) { try {// w w w. j av a 2s. co m final boolean baseIsInterface = fHierarchyRoot.isInterface(); fSearchResults = new ArrayList(); IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { IJavaSearchScope scope = null; try { // we want to rip out the JRE entry as there's no chance of finding a tapestry class there. ArrayList roots = new ArrayList(); IClasspathEntry[] classpath = project.getRawClasspath(); for (int i = 0; i < classpath.length; i++) { if (classpath[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IPath cpPath = classpath[i].getPath(); if (JavaRuntime.JRE_CONTAINER.equals(cpPath.segment(0))) continue; } roots.add(project.findPackageFragmentRoots(classpath[i])); } scope = SearchEngine.createJavaSearchScope( (IJavaElement[]) roots.toArray(new IJavaElement[roots.size()]), true); } catch (JavaModelException e1) { scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, true); } ISearchPattern pattern = SearchEngine.createSearchPattern("*", IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, true); SearchEngine engine = new SearchEngine(); IJavaSearchResultCollector collector = new IJavaSearchResultCollector() { public void aboutToStart() { } public void accept(IResource resource, int start, int end, IJavaElement enclosingElement, int accuracy) throws CoreException { if (accuracy != EXACT_MATCH) return; if (enclosingElement.getElementType() != IJavaElement.TYPE) return; IType type = (IType) enclosingElement; System.out.println(type.getFullyQualifiedName()); if (baseIsInterface) { if (!CoreUtils.implementsInterface(type, fHierarchyRoot.getElementName())) return; } else { if (!CoreUtils.extendsType(type, fHierarchyRoot)) return; } System.out.println(type.getFullyQualifiedName()); fSearchResults.add(type); } public void done() { } public IProgressMonitor getProgressMonitor() { return monitor; } }; try { engine.search(ResourcesPlugin.getWorkspace(), pattern, scope, collector); } catch (JavaModelException e) { UIPlugin.log(e); } } }; context.run(false, true, runnable); } catch (InvocationTargetException e) { UIPlugin.log(e); } catch (InterruptedException e) { //do nothing; } catch (JavaModelException e) { UIPlugin.log(e); } }
From source file:com.iw.plugins.spindle.ui.wizards.NewTapComponentWizardClassPage.java
License:Mozilla Public License
/** * @see NewElementWizardPage#getRunnable() *//*w w w.j a v a 2 s . c o m*/ public IRunnableWithProgress getRunnable(Object object) { return new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { if (monitor == null) { monitor = new NullProgressMonitor(); } createSpecClassResource(new SubProgressMonitor(monitor, 1)); monitor.done(); } catch (CoreException e) { throw new InvocationTargetException(e); } } }; }
From source file:com.iw.plugins.spindle.ui.wizards.NewTapComponentWizardPage.java
License:Mozilla Public License
/** * create the specification and the template (if required) *///from w ww. jav a 2s. co m 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(); } createSpecificationResource(monitor, useClass); if (fGenerateHTML.getSelection()) { TapestryTemplateFactory factory = new TapestryTemplateFactory(); Template template = fTapestryTemplateSelector.getSelectedTemplate(); fTemplateFile = factory.createTapestryTemplate(getTemplateFile(), template, new SubProgressMonitor(monitor, 1)); } monitor.done(); } catch (CoreException e) { throw new InvocationTargetException(e); } } }; }