List of usage examples for org.eclipse.jface.operation IRunnableWithProgress IRunnableWithProgress
IRunnableWithProgress
From source file:com.iw.plugins.spindle.wizards.NewTapComponentWizardPage.java
License:Mozilla Public License
/** * Method getAutoAddRunnable./* w w w . j a v a 2 s .c o m*/ * @return IRunnableWithProgress */ public IRunnableWithProgress getAutoAddRunnable() { final boolean addingNewComponent = getWizard().getClass() == NewTapComponentWizard.class; String extension = "page"; if (addingNewComponent) { extension = "jwc"; } IPackageFragment frag = fPackageDialogField.getPackageFragment(); String componentName = fComponentNameDialog.getTextValue(); String componentTapestryPath = null; if (frag.isDefaultPackage()) { componentTapestryPath = "/" + componentName + "." + extension; } else { componentTapestryPath = ("/" + frag.getElementName() + "/").replace('.', '/') + componentName + "." + extension; } final boolean doAutoAdd = true; final TapestryLibraryModel useSelectedModel = fAutoAddField.getContainerModel(); final String useTapestryPath = componentTapestryPath; final String useComponentName = componentName; final Shell shell = this.getShell(); return new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { if (monitor == null) { monitor = new NullProgressMonitor(); } if (doAutoAdd && useSelectedModel != null) { SpindleMultipageEditor targetEditor = (SpindleMultipageEditor) Utils .getEditorFor(useSelectedModel.getUnderlyingStorage()); if (targetEditor != null) { try { doAddInEditor(targetEditor, monitor); } catch (InterruptedException e) { //do nothing } } else { doAddInWorkspace(monitor); } } } private void doAddInEditor(SpindleMultipageEditor targetEditor, IProgressMonitor monitor) throws InterruptedException { TapestryLibraryModel useModel = (TapestryLibraryModel) targetEditor.getModel(); if (!checkSaveEditor(targetEditor)) { MessageDialog.openInformation(shell, MessageUtil.getString(PAGE_NAME + ".autoAddNotPossible"), //"AutoAdd not possible", MessageUtil.getFormattedString(PAGE_NAME + ".autoAddParseError", useSelectedModel.getUnderlyingStorage().getName()) // "A parse error occured while saving " // + useSelectedModel.getUnderlyingStorage().getName() // + ".\n The component will be created without adding it to the app." ); return; } ILibrarySpecification spec = (ILibrarySpecification) useModel.getSpecification(); if (componentAlreadyExists(spec)) { return; } performAddToModel(spec); useSelectedModel.setOutOfSynch(true); targetEditor.doSave(monitor); targetEditor.showPage(SpindleMultipageEditor.SOURCE_PAGE); } private void doAddInWorkspace(IProgressMonitor monitor) throws InterruptedException { String consumer = "WizardAutoAddToAppInWorkspace"; try { ITapestryProject tproject = TapestryPlugin.getDefault().getTapestryProjectFor(useSelectedModel); TapestryProjectModelManager mgr = tproject.getModelManager(); mgr.connect(useSelectedModel.getUnderlyingStorage(), consumer, true); TapestryLibraryModel useModel = (TapestryLibraryModel) mgr .getEditableModel(useSelectedModel.getUnderlyingStorage(), consumer); IPluginLibrarySpecification spec = (IPluginLibrarySpecification) useModel.getSpecification(); if (componentAlreadyExists(spec)) { return; } performAddToModel(spec); Utils.saveModel(useModel, monitor); //TapestryPlugin.openTapestryEditor(useModel.getUnderlyingStorage()); mgr.disconnect(useModel.getUnderlyingStorage(), consumer); } catch (CoreException e) { throw new InterruptedException("AutoAdd failed"); } } private boolean componentAlreadyExists(ILibrarySpecification spec) { boolean result = false; if (addingNewComponent) { result = spec.getComponentSpecificationPath(useComponentName) != null; } else { result = spec.getPageSpecificationPath(useComponentName) != null; } if (result) { MessageDialog.openInformation(shell, MessageUtil.getString(PAGE_NAME + ".autoAddNotPossible"), MessageUtil.getFormattedString(PAGE_NAME + "autoAddAlreadyExisits", new Object[] { useComponentName, useSelectedModel.getUnderlyingStorage().getName() }) // "The component " // + useComponentName // + " already exists in " // + useSelectedModel.getUnderlyingStorage().getName() // + ".\n The component will be created without adding it to the app." ); } return result; } private void performAddToModel(ILibrarySpecification spec) { if (addingNewComponent) { spec.setComponentSpecificationPath(useComponentName, useTapestryPath); } else { spec.setPageSpecificationPath(useComponentName, useTapestryPath); } } private boolean checkSaveEditor(SpindleMultipageEditor targetEditor) throws InterruptedException { BaseTapestryModel model = null; if (targetEditor != null && targetEditor.isDirty()) { RequiredSaveEditorAction saver = new RequiredSaveEditorAction(targetEditor); if (!saver.save()) { throw new InterruptedException(); } model = (BaseTapestryModel) targetEditor.getModel(); if (!model.isLoaded()) { return false; } } return true; } }; }
From source file:com.iw.plugins.spindle.wizards.project.ApplicationWizardPage.java
License:Mozilla Public License
/** * @see NewElementWizardPage#getRunnable() */// w w w .j av a 2s . co m public IRunnableWithProgress getRunnable(Object obj) { final IJavaProject project = (IJavaProject) obj; return new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { if (monitor == null) { monitor = new NullProgressMonitor(); } createApplicationResource(project, new SubProgressMonitor(monitor, 1)); createServletType(project, new SubProgressMonitor(monitor, 1)); monitor.done(); } catch (CoreException e) { throw new InvocationTargetException(e); } } }; }
From source file:com.iw.plugins.spindle.wizards.project.convert.ConversionWelcomePage.java
License:Mozilla Public License
/** * Method getRunnable./*from ww w . j av a 2s . c o m*/ * @return IRunnableWithProgress */ public IRunnableWithProgress getRunnable(Object object) { final IFile file = (IFile) object; final IJavaProject jproject = (IJavaProject) selection.getFirstElement(); return new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { ITapestryProject tproject = TapestryPlugin.getDefault().addTapestryProjectNatureTo(jproject, null); tproject.setProjectStorage(file); } catch (CoreException e) { ErrorDialog.openError(getShell(), "Conversion Failed", "Could not add Tapestry Project Nature", e.getStatus()); throw new InterruptedException(); } } }; }
From source file:com.iw.plugins.spindle.wizards.project.convert.CreateApplicationWizardPage.java
License:Mozilla Public License
/** * @see NewElementWizardPage#getRunnable() *///from ww w . j a v a2 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(); } createApplicationResource(new SubProgressMonitor(monitor, 1)); createServletType(new SubProgressMonitor(monitor, 1)); monitor.done(); } catch (CoreException e) { throw new InvocationTargetException(e); } } }; }
From source file:com.iw.plugins.spindle.wizards.project.convert.CreateLibraryWizardPage.java
License:Mozilla Public License
/** * @see NewElementWizardPage#getRunnable() *//* www .j a va 2 s. co m*/ public IRunnableWithProgress getRunnable(Object object) { return new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { if (monitor == null) { monitor = new NullProgressMonitor(); } createLibraryResource(new SubProgressMonitor(monitor, 1)); monitor.done(); } catch (CoreException e) { throw new InvocationTargetException(e); } } }; }
From source file:com.iw.plugins.spindle.wizards.project.LibraryWizardPage.java
License:Mozilla Public License
/** * @see NewElementWizardPage#getRunnable() *///from w ww .jav a 2 s .com public IRunnableWithProgress getRunnable(Object object) { final IJavaProject project = (IJavaProject) object; return new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { if (monitor == null) { monitor = new NullProgressMonitor(); } createLibraryResource(project, new SubProgressMonitor(monitor, 1)); monitor.done(); } catch (CoreException e) { throw new InvocationTargetException(e); } } }; }
From source file:com.jasperassistant.designer.viewer.actions.AbstractExportAction.java
License:Open Source License
/** * Subclasses can override this method to implement an export method. * Default implementation opens a progress monitor dialog and then calls the * {@link #exportWithProgress(File, JRExportProgressMonitor)}method. * /* ww w . j a v a 2 s . c o m*/ * @param file * the destination file * @throws Throwable * if an error occurs during the export * @see #exportWithProgress(File, JRExportProgressMonitor) */ protected void export(final File file) throws Throwable { ProgressMonitorDialog pm = new ProgressMonitorDialog(Display.getCurrent().getActiveShell()); try { pm.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { int totalPages = getReportViewer().getDocument().getPages().size(); monitor.beginTask(Messages.getString("AbstractExportAction.taskLabel"), totalPages); //$NON-NLS-1$ exportWithProgress(file, new ProgressMonitorAdapter(monitor, totalPages)); } catch (Throwable e) { throw new InvocationTargetException(e); } finally { monitor.done(); } } }); } catch (InvocationTargetException e) { if (pm.getReturnCode() != ProgressMonitorDialog.CANCEL) { throw e; } } catch (InterruptedException e) { if (pm.getReturnCode() != ProgressMonitorDialog.CANCEL) { throw e; } } finally { if (pm.getReturnCode() == ProgressMonitorDialog.CANCEL) { file.delete(); } } }
From source file:com.jaspersoft.studio.backward.wizard.DownloadJRWizard.java
License:Open Source License
/** * Called when the user press next to go to the second page, launch the thread * to download and unpack (or delete) the selected (or unslected) version. * The next page will be shown automatically when the thread is completed * //from w w w . j av a 2 s.com * @param mainDialog main dialog of the wizard, the reference is used to notify that the thread * is completed, must be not null */ protected void nextPressed(final DownloadJRWizardDialog mainDialog) { run(false, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { HashMap<JRDefinition, Boolean> selection = page0.getSelection(); monitor.beginTask(Messages.DownloadJRWizard_monitorStart, selection.entrySet().size()); for (Entry<JRDefinition, Boolean> def : selection.entrySet()) { if (def.getValue().booleanValue() == false) { JRBackwardManager.INSTANCE.deleteJR(def.getKey()); monitor.worked(1); } else { try { JRBackwardManager.INSTANCE.getJRFolder(def.getKey().getVersion(), monitor); } catch (Exception ex) { String errorMessage = MessageFormat.format(Messages.DownloadJRWizard_errorMessage, new Object[] { def.getKey().getVersion() }); JaspersoftStudioPlugin.getInstance().logError(errorMessage, ex); page1.setError(true); } monitor.worked(1); } if (monitor.isCanceled()) { page1.setAborted(true); break; } } monitor.done(); //The notification of the completed thread must be in the graphic thread since it force the advance of the page UIUtils.getDisplay().syncExec(new Runnable() { @Override public void run() { mainDialog.threadCompleted(); } }); } }); getContainer().updateButtons(); }
From source file:com.jaspersoft.studio.components.customvisualization.creation.wizard.CustomVisualizationComponentWizard.java
License:Open Source License
/** * Create the project inside the workspace and all it's content *///from w ww. j a va 2 s .co m @Override public boolean performFinish() { final String projectName = page0.getProjectName(); final ModuleDefinition selected = page0.getSelectedModule(); final String mName = page0.getModule(); final String oldModule = selected.getModuleName(); try { selected.setModuleName(mName); getContainer().run(true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Creating CVC Component Project", IProgressMonitor.UNKNOWN); try { boolean result = createProject(projectName, monitor); if (result) { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject(projectName); File dest = new File(root.getRawLocation().toFile(), projectName); List<VelocityLibrary> libraries = new ArrayList<VelocityLibrary>(); List<VelocityShimLibrary> shimLibraries = new ArrayList<VelocityShimLibrary>(); try { String outputScriptName = projectName + ".min.js"; // Add the main module and all it's // dependencies addModule(selected, shimLibraries, libraries, dest); for (ModuleDefinition requiredLibrary : selected.getRequiredLibraries()) { addModule(requiredLibrary, shimLibraries, libraries, dest); } String cssFileName = generateCSS(project, monitor, selected); String renderFileName = generateRender(project, monitor, selected); libraries.add(new VelocityLibrary(mName, removeJsExtension(renderFileName))); String buildFile = generateBuildFile(libraries, shimLibraries, mName, outputScriptName); createFile("build.js", project, buildFile, monitor); //$NON-NLS-1$ try { createUIFiles(monitor, project, mName, cssFileName, selected.getLibraryURL()); } catch (IOException e1) { e1.printStackTrace(); } // Eventually create a sample for the // current project createSample(selected, outputScriptName, cssFileName, project, monitor); try { project.refreshLocal(IProject.DEPTH_INFINITE, monitor); project.build(IncrementalProjectBuilder.FULL_BUILD, monitor); project.refreshLocal(IProject.DEPTH_INFINITE, monitor); } catch (CoreException e) { e.printStackTrace(); } } catch (FileNotFoundException ex) { MessageDialog.openError(UIUtils.getShell(), Messages.CustomVisualizationComponentWizard_errorTitle, ex.getMessage()); } } } finally { monitor.done(); selected.setModuleName(oldModule); } } }); } catch (InvocationTargetException e) { UIUtils.showError(e.getCause()); } catch (InterruptedException e) { UIUtils.showError(e); } return true; }
From source file:com.jaspersoft.studio.data.xvia.querydesigner.TrackViaMetadata.java
License:Open Source License
public void loadApp(final TrackViaApp mschema) { if (das != null && ModelUtils.isEmpty(mschema)) { try {/*from w w w.java 2s.com*/ designer.run(true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask(Messages.DBMetadata_5, IProgressMonitor.UNKNOWN); try { monitors.add(monitor); mschema.setDbMetadata(TrackViaMetadata.this); readApp(mschema, monitor, false); } catch (Throwable e) { designer.showError(e); } finally { monitors.remove(monitor); monitor.done(); } } }); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } } }