List of usage examples for org.eclipse.jface.dialogs ProgressMonitorDialog run
@Override public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException
IRunnableWithProgress
using the progress monitor for this progress dialog and blocks until the runnable has been run, regardless of the value of fork
. From source file:org.eclipse.mdht.uml.cda.ui.wizards.NewCDAModelProjectWizard.java
License:Open Source License
@Override public boolean performFinish() { try {/*from w w w. j a v a 2s . co m*/ ProgressMonitorDialog pd = new ProgressMonitorDialog(getShell()); IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); final String modelName = newCDATemplatePage.getModelName().toLowerCase(); modelProject = root .getProject(String.format("%s.%s.model", newCDATemplatePage.getBasePackage(), modelName)); generatedProject = root .getProject(String.format("%s.%s", newCDATemplatePage.getBasePackage(), modelName)); docProject = root .getProject(String.format("%s.%s.doc", newCDATemplatePage.getBasePackage(), modelName)); pd.run(false, false, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Creating Projects", 9); try { modelProject.create(monitor); modelProject.open(monitor); generatedProject.create(monitor); generatedProject.open(monitor); docProject.create(monitor); docProject.open(monitor); // Use pde internal functionality to create plugin IProjectProvider generatedProjectProvider = new IProjectProvider() { public IProject getProject() { return generatedProject; } public String getProjectName() { return generatedProject.getName(); } public IPath getLocationPath() { return generatedProject.getFullPath(); } }; getContainer().run(false, true, new NewProjectCreationOperation(fPluginData, generatedProjectProvider, contentWizard)); IProjectProvider docProjectProvider = new IProjectProvider() { public IProject getProject() { return docProject; } public String getProjectName() { return docProject.getName(); } public IPath getLocationPath() { return docProject.getFullPath(); } }; getContainer().run(false, true, new NewProjectCreationOperation(fPluginData, docProjectProvider, contentWizard)); monitor.worked(1); monitor.setTaskName("Create Manifest for Generated Project"); createGeneratedProjectManifest(generatedProject, newCDATemplatePage.getBasePackage(), modelName); monitor.worked(1); monitor.setTaskName("Create Manifest for Doc Project"); createDocumentProjectManifest(docProject, newCDATemplatePage.getBasePackage(), modelName); monitor.worked(1); monitor.setTaskName("Create css"); createFolder(docProject, "css"); monitor.setTaskName("Create dita"); createFolder(docProject, "dita"); createDocProject(docProject, modelName); createPluginProperties(docProject, modelName); updateBuildProperties(docProject); createDitaProperties(docProject, newCDATemplatePage.getBasePackage(), modelName); monitor.setTaskName("Create UML Model"); createFolder(modelProject, "model"); createUMLModel(modelProject, newCDATemplatePage.getNamespaceURI(), newCDATemplatePage.getBasePackage(), modelName); monitor.worked(1); monitor.setTaskName("Create Model Plugin"); createModelPlugin(modelProject, modelName); monitor.setTaskName("Create Manifest for Model Project"); createModelProjectManifest(modelProject, newCDATemplatePage.getBasePackage(), modelName); monitor.worked(1); monitor.setTaskName("Create Transformation XML"); createTransformation(generatedProject, modelName); monitor.worked(1); monitor.setTaskName("Add Properties"); createPluginProperties(generatedProject, modelName); updateBuildProperties(generatedProject); monitor.setTaskName("Run MDHT Transformation"); org.eclipse.mdht.uml.cda.ui.builder.CDABuilder.runTransformation(generatedProject, monitor); monitor.worked(1); monitor.setTaskName("Create GenModel"); org.eclipse.mdht.uml.cda.ui.builder.CDABuilder.createGenModel(generatedProject, monitor); monitor.worked(1); monitor.setTaskName("Run MDHT Transformation"); org.eclipse.mdht.uml.cda.ui.builder.CDABuilder.runTransformation(generatedProject, monitor); monitor.worked(1); monitor.setTaskName("Generate"); org.eclipse.mdht.uml.cda.ui.builder.CDABuilder.runGenerate(false, generatedProject, monitor); monitor.worked(1); generatedProject.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor); monitor.setTaskName("Toggle Build Nature"); org.eclipse.mdht.uml.cda.ui.builder.ToggleNatureAction.toggleNature(generatedProject); org.eclipse.mdht.uml.cda.ui.builder.ToggleNatureAction.toggleNature(docProject); monitor.worked(1); setupWorkspace(modelProject, modelName); } catch (Exception exception) { monitor.setCanceled(true); Logger.logException(exception); throw new InvocationTargetException(exception); } } }); docProject.refreshLocal(IResource.DEPTH_INFINITE, null); modelProject.refreshLocal(IResource.DEPTH_INFINITE, null); generatedProject.refreshLocal(IResource.DEPTH_INFINITE, null); } catch (InvocationTargetException exception) { Logger.logException(exception); Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, exception.getCause().getLocalizedMessage(), exception.getCause()); ErrorDialog.openError(getShell(), "MDHT CDA Project Wizard Exception", "Unable to create new CDA Project", status); // try { // docProject.delete(true, null); // modelProject.delete(true, null); // generatedProject.delete(true, null); // } catch (CoreException coreException) { // Logger.logException(coreException); // } } catch (InterruptedException interruptedException) { Logger.logException(interruptedException); } catch (CoreException coreException) { Logger.logException(coreException); } return true; }
From source file:org.eclipse.mdht.uml.term.ui.actions.ImportTerminologyAction.java
License:Open Source License
/** * @see IActionDelegate#run(IAction)/*from w ww. j av a2 s .co m*/ */ public void run(IAction action) { ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(shell); ObjectPluginAction opa = (ObjectPluginAction) action; final TreeSelection selection = (TreeSelection) opa.getSelection(); final String ActionTitle = "Import Terminology"; final FileDialog fdlg = new FileDialog(shell, SWT.SINGLE); fdlg.setText("Select Terminology Source File"); fdlg.setFilterNames(FILTER_NAMES); fdlg.setFilterExtensions(FILTER_EXTS); IRunnableWithProgress runnableWithProgress = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { IWorkspaceRoot myWorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); File f = (File) selection.getFirstElement(); String umlPath = myWorkspaceRoot.getLocation().toOSString() + f.getFullPath().toOSString(); try { importTerminlogy(monitor, umlPath, fdlg); } catch (Exception e) { e.printStackTrace(); } try { myWorkspaceRoot.refreshLocal(IResource.DEPTH_INFINITE, null); } catch (CoreException e) { } if (monitor.isCanceled()) { monitor.done(); return; } monitor.done(); } }; try { if (fdlg.open() != null) { progressDialog.run(false, true, runnableWithProgress); UMLModelMetricsDialog dlg = new UMLModelMetricsDialog(shell); dlg.create(); dlg.open(); } } catch (InvocationTargetException invocationTargetException) { MessageDialog.openError(shell, ActionTitle, "Error Processing Export " + invocationTargetException.getMessage()); } catch (InterruptedException interruptedException) { MessageDialog.openError(shell, ActionTitle, "Error Processing Export " + interruptedException.getMessage()); } finally { progressDialog.close(); } }
From source file:org.eclipse.mylyn.monitor.usage.tests.InteractionEventLoggerTest.java
License:Open Source License
private void runWith(final File monitorFile) throws InvocationTargetException, InterruptedException { ProgressMonitorDialog dialog = new ProgressMonitorDialog(Display.getCurrent().getActiveShell()); dialog.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) { monitor.beginTask("Running test job", 1); InteractionEventLogger l = new InteractionEventLogger(null); l.getHistoryFromFile(monitorFile, new SubProgressMonitor(monitor, 1)); monitor.done();/* ww w . j ava2 s .c o m*/ } }); }
From source file:org.eclipse.n4js.ui.utils.EclipseUtils.java
License:Open Source License
/** * Same as {@link #runInModalDialog(OperationCanceledManager, IRunnableWithProgress)}, but allows reacting to * exceptions./*from www.ja v a 2 s . co m*/ * * @param throwableHandler * will be invoked on the runnable's thread in case the runnable throws an exception other than a * {@link OperationCanceledManager#isOperationCanceledException(Throwable) cancellation exception}. May * be <code>null</code> if no handling of exceptions is required. */ public static void runInModalDialog(OperationCanceledManager ocm, IRunnableWithProgress runnable, Consumer<Throwable> throwableHandler) { try { final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); final ProgressMonitorDialog dlg = new ProgressMonitorDialog(shell); dlg.run(true, true, monitor -> { try { runnable.run(monitor); } catch (Throwable th) { // translate cancellation exceptions from Eclipse/Xtext to SWT/JFace world if (ocm.isOperationCanceledException(th)) { throw new InterruptedException(); } if (throwableHandler != null) { throwableHandler.accept(th); } throw th; } }); } catch (InvocationTargetException | InterruptedException e) { // ignore } }
From source file:org.eclipse.ocl.examples.editor.ui.common.ResourceChangeManager.java
License:Open Source License
/** * This is for implementing {@link IEditorPart} and simply saves the model file. *//*from w w w.j a va 2 s . c om*/ public void doSave(IProgressMonitor progressMonitor) { // Save only resources that have actually changed. // Map<Object, Object> saveOptions = new HashMap<Object, Object>(); saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER); // Do the work within an operation because this is a long running activity that modifies the workbench. // WorkspaceModifyOperation operation1 = new SaveOperation1(saveOptions); WorkspaceModifyOperation operation2 = new SaveOperation2(); suspendProblemIndicationUpdate(); try { // This runs the options, and shows progress. // ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(getShell()); progressMonitorDialog.run(true, false, operation1); // Refresh the necessary state. // if (OCLExamplesEditorPlugin.EDITOR_SAVE.isActive()) OCLExamplesEditorPlugin.EDITOR_SAVE.println(getClass(), "Saved all"); try { // This runs the options, and shows progress. // progressMonitorDialog.run(true, false, operation2); // Refresh the necessary state. // if (OCLExamplesEditorPlugin.EDITOR_SAVE.isActive()) OCLExamplesEditorPlugin.EDITOR_SAVE.println(getClass(), "Saved all2"); savingResources.clear(); } catch (Exception exception) { // Something went wrong that shouldn't. // OCLExamplesEditorPlugin.INSTANCE.log(exception); } refreshAfterSave(); } catch (Exception exception) { // Something went wrong that shouldn't. // OCLExamplesEditorPlugin.INSTANCE.log(exception); } finally { resumeProblemIndicationUpdate(); } }
From source file:org.eclipse.oomph.p2.internal.ui.AgentAnalyzerComposite.java
License:Open Source License
private void initAnalyzer() throws InvocationTargetException, InterruptedException { initializingAnalyzer = true;//from w ww.j ava 2s . c om try { ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell()); dialog.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { analyzer = new AgentAnalyzer(agent, true, new Handler() { public void analyzerChanged(final AgentAnalyzer analyzer) { if (analyzer == AgentAnalyzerComposite.this.analyzer) { asyncExec(new Runnable() { public void run() { bundlePoolContentProvider.refresh(); if (!deletingArtifacts) { artifactContentProvider.refresh(); profileContentProvider.refresh(); } getDisplay().asyncExec(new Runnable() { public void run() { Object[] elements = bundlePoolContentProvider.getElements(analyzer); if (elements.length != 0) { bundlePoolViewer .setSelection(new StructuredSelection(elements[0])); } } }); } }); } } public void bundlePoolChanged(final AnalyzedBundlePool bundlePool, final boolean artifacts, final boolean profiles) { asyncExec(new Runnable() { public void run() { bundlePoolViewer.update(bundlePool, null); if (bundlePool == currentBundlePool) { if (!artifacts && !profiles) { updateBundlePoolButtons(); } else { if (artifacts) { artifactContentProvider.refresh(); } if (profiles) { profileContentProvider.refresh(); } } } } }); } public void profileChanged(final AnalyzedProfile profile) { if (deletingArtifacts) { return; } if (profile.getBundlePool() == currentBundlePool) { asyncExec(new Runnable() { public void run() { profileViewer.update(profile, null); } }); } } public void artifactChanged(final AnalyzedArtifact artifact) { if (deletingArtifacts) { return; } if (artifact == null || artifact.getBundlePool() == currentBundlePool) { asyncExec(new Runnable() { public void run() { if (artifact != null && ObjectUtil .equals(artifactContentProvider.getFilter(), SHOW_ALL)) { artifactViewer.update(artifact, null); } else { artifactContentProvider.refresh(); } } }); } } }, monitor); } }); } finally { initializingAnalyzer = false; } }
From source file:org.eclipse.oomph.p2.internal.ui.AgentManagerComposite.java
License:Open Source License
public AgentManagerComposite(Composite parent, int style, final Object selection) { super(parent, style); setBackground(getDisplay().getSystemColor(SWT.COLOR_TRANSPARENT)); setLayout(UIUtil.createGridLayout(2)); final P2ContentProvider contentProvider = new P2ContentProvider(); treeViewer = new TreeViewer(this, SWT.BORDER); treeViewer.setContentProvider(contentProvider); treeViewer.setLabelProvider(new P2LabelProvider()); treeViewer.setSorter(new P2ViewerSorter()); treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { selectedElement = ((IStructuredSelection) treeViewer.getSelection()).getFirstElement(); elementChanged(selectedElement); }// ww w . j a v a 2 s. c o m }); Tree tree = treeViewer.getTree(); tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); tree.addMouseListener(new MouseAdapter() { @Override public void mouseDoubleClick(MouseEvent e) { if (selectedElement instanceof Profile) { showProfileDetails(); } else { treeViewer.setExpandedState(selectedElement, !treeViewer.getExpandedState(selectedElement)); } } }); tree.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.keyCode == SWT.DEL && deleteButton.isEnabled()) { deletePressed(); } } }); GridLayout buttonLayout = new GridLayout(1, false); buttonLayout.marginWidth = 0; buttonLayout.marginHeight = 0; Composite buttonComposite = new Composite(this, SWT.NONE); buttonComposite.setLayout(buttonLayout); buttonComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true)); buttonComposite.setBounds(0, 0, 64, 64); newAgentButton = new Button(buttonComposite, SWT.NONE); newAgentButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); newAgentButton.setText("New Agent..."); newAgentButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String path = openDirectoryDialog("Select the location of the new agent.", PropertiesUtil.getUserHome()); if (path != null) { Agent agent = P2Util.getAgentManager().addAgent(new File(path)); BundlePool bundlePool = agent.addBundlePool(new File(path, BundlePool.DEFAULT_NAME)); refreshFor(bundlePool); } } }); cleanupButton = new Button(buttonComposite, SWT.NONE); cleanupButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); cleanupButton.setText("Cleanup Agent..."); cleanupButton.setEnabled(false); cleanupButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { Agent agent = getAgent(selectedElement); if (agent != null) { cleanup(agent); treeViewer.refresh(); } } }); analyzeButton = new Button(buttonComposite, SWT.NONE); analyzeButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); analyzeButton.setText("Analyze Agent..."); analyzeButton.setEnabled(false); analyzeButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { Agent agent = getAgent(selectedElement); if (agent != null) { analyze(agent); treeViewer.refresh(); } } }); newPoolButton = new Button(buttonComposite, SWT.NONE); newPoolButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); newPoolButton.setText("New Bundle Pool..."); newPoolButton.setEnabled(false); newPoolButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { Agent selectedAgent = (Agent) selectedElement; String path = openDirectoryDialog("Select the location of the new pool.", selectedAgent.getLocation().getAbsolutePath()); if (path != null) { BundlePool bundlePool = selectedAgent.addBundlePool(new File(path)); refreshFor(bundlePool); } } }); deleteButton = new Button(buttonComposite, SWT.NONE); deleteButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); deleteButton.setText("Delete..."); deleteButton.setEnabled(false); deleteButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { deletePressed(); } }); refreshButton = new Button(buttonComposite, SWT.NONE); refreshButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); refreshButton.setText("Refresh"); refreshButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { try { ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell()); dialog.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { P2Util.getAgentManager().refreshAgents(monitor); } }); } catch (InvocationTargetException ex) { P2UIPlugin.INSTANCE.log(ex); } catch (InterruptedException ex) { //$FALL-THROUGH$ } treeViewer.refresh(); } }); new Label(buttonComposite, SWT.NONE); showProfilesButton = new Button(buttonComposite, SWT.CHECK); showProfilesButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); showProfilesButton.setText("Show Profiles"); showProfilesButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { boolean showProfiles = showProfilesButton.getSelection(); PREF_SHOW_PROFILES.set(showProfiles); profileDetailsButton.setVisible(showProfiles); contentProvider.setShowProfiles(showProfiles); treeViewer.refresh(); if (selectedElement instanceof BundlePool) { treeViewer.setExpandedState(selectedElement, true); } profilesShown(showProfiles); } }); profileDetailsButton = new Button(buttonComposite, SWT.NONE); profileDetailsButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); profileDetailsButton.setText("Details..."); profileDetailsButton.setVisible(false); profileDetailsButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { showProfileDetails(); } }); if (PREF_SHOW_PROFILES.get(false)) { showProfilesButton.setSelection(true); profileDetailsButton.setVisible(true); contentProvider.setShowProfiles(true); profilesShown(true); } UIUtil.asyncExec(new Runnable() { public void run() { final AgentManager agentManager = P2Util.getAgentManager(); BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() { public void run() { treeViewer.setInput(agentManager); treeViewer.expandAll(); } }); if (selection == null) { Collection<Agent> agents = agentManager.getAgents(); if (!agents.isEmpty()) { treeViewer.setSelection(new StructuredSelection(agents.iterator().next())); } } else { treeViewer.setSelection(new StructuredSelection(selection)); } } }); }
From source file:org.eclipse.oomph.p2.internal.ui.AgentManagerComposite.java
License:Open Source License
private void cleanup(final Agent agent) { final String title = "Cleanup"; final AgentAnalyzer[] analyzer = { null }; try {//from w ww .ja v a2 s .com ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell()); dialog.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { SubMonitor progress = SubMonitor.convert(monitor, "Analyzing...", 100).detectCancelation(); analyzer[0] = new AgentAnalyzer(agent, false, null, progress.newChild(90)); analyzer[0].awaitAnalyzing(progress.newChild(10)); } }); } catch (Exception ex) { ErrorDialog.open(ex); return; } final Map<AnalyzedProfile, AnalyzedProfile> unusedProfiles = new IdentityHashMap<AnalyzedProfile, AnalyzedProfile>(); final Map<AnalyzedArtifact, AnalyzedArtifact> unusedArtifacts = new IdentityHashMap<AnalyzedArtifact, AnalyzedArtifact>(); for (AnalyzedBundlePool bundlePool : analyzer[0].getBundlePools().values()) { for (AnalyzedProfile profile : bundlePool.getUnusedProfiles()) { unusedProfiles.put(profile, profile); } for (AnalyzedArtifact artifact : bundlePool.getArtifacts()) { if (isUnused(artifact, unusedProfiles)) { unusedArtifacts.put(artifact, artifact); } } } if (unusedProfiles.isEmpty() && unusedArtifacts.isEmpty()) { MessageDialog.openInformation(getShell(), title, "Nothing to clean up."); return; } final boolean showProfiles = showProfilesButton.getSelection(); final int profiles = unusedProfiles.size(); final int artifacts = unusedArtifacts.size(); String message = "Do you want to delete "; if (profiles != 0) { message += profiles + " unused profile" + (profiles == 1 ? "" : "s"); } if (artifacts != 0) { if (profiles != 0) { message += " and "; } message += artifacts + " unused artifact" + (artifacts == 1 ? "" : "s"); } message += "?"; if (artifacts != 0) { message += "\n\n" + "Note: Unused artifacts can always safely be deleted. " + "They will be deleted physically from your disk and logically from your bundle pool."; } if (MessageDialog.openQuestion(getShell(), title, message)) { try { UIUtil.runInProgressDialog(getShell(), new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { SubMonitor progress = SubMonitor.convert(monitor, "Deleting...", profiles + artifacts) .detectCancelation(); if (profiles != 0) { progress.setTaskName("Deleting unused profiles..."); for (AnalyzedProfile profile : unusedProfiles.keySet()) { profile.delete(progress.newChild()); if (showProfiles) { UIUtil.syncExec(new Runnable() { public void run() { treeViewer.refresh(); } }); } } } if (artifacts != 0) { progress.setTaskName("Deleting unused artifacts..."); for (AnalyzedArtifact artifact : unusedArtifacts.keySet()) { artifact.delete(progress.newChild()); } } } }); } catch (InvocationTargetException ex) { ErrorDialog.open(ex); } catch (InterruptedException ex) { // Ignore. } } }
From source file:org.eclipse.oomph.setup.internal.installer.KeepInstallerDialog.java
License:Open Source License
@Override protected void okPressed() { final String launcher = InstallerApplication.getLauncher(); if (launcher != null) { final boolean startMenu = startMenuButton == null ? false : startMenuButton.getSelection(); final boolean desktop = desktopButton == null ? false : desktopButton.getSelection(); ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog((Shell) getShell().getParent()); try {//from ww w . j a v a 2s . c o m progressMonitorDialog.run(true, false, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Copying installer to " + location, IProgressMonitor.UNKNOWN); KeepInstallerUtil.keepInstaller(location, startPermanentInstaller, launcher, startMenu, desktop, false); monitor.done(); } }); } catch (InterruptedException ex) { // Ignore. } catch (Exception ex) { SetupInstallerPlugin.INSTANCE.log(ex); } } super.okPressed(); }
From source file:org.eclipse.oomph.setup.internal.installer.SimpleKeepInstallerPage.java
License:Open Source License
@Override protected void createContent(Composite container) { GridLayout layout = new GridLayout(1, false); layout.marginLeft = 17;//from w ww . j a v a2 s .co m layout.marginRight = 11; layout.marginTop = 39; layout.marginBottom = 30; layout.marginHeight = 0; layout.marginWidth = 0; layout.verticalSpacing = 0; container.setLayout(layout); container.setBackgroundMode(SWT.INHERIT_FORCE); container.setBackground(AbstractSimpleDialog.COLOR_WHITE); Label title = new Label(container, SWT.NONE); title.setText("Keep Installer"); title.setForeground(UIUtil.getEclipseThemeColor()); title.setFont(SimpleInstallerDialog.getFont(3, "bold")); title.setLayoutData(GridDataFactory.swtDefaults().create()); Label description = new Label(container, SWT.WRAP); description.setText(KeepInstallerUtil.KEEP_INSTALLER_DESCRIPTION + "."); description.setForeground(AbstractSimpleDialog.COLOR_LABEL_FOREGROUND); description.setLayoutData(GridDataFactory.swtDefaults().grab(true, false).indent(0, 10).create()); Composite varContainer = new Composite(container, SWT.NONE); GridLayout varContainerLayout = new GridLayout(3, false); varContainerLayout.marginWidth = 0; varContainerLayout.marginHeight = 0; varContainerLayout.verticalSpacing = 3; varContainer.setLayout(varContainerLayout); varContainer.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).indent(0, 48).create()); Label copyToLabel = createLabel(varContainer, "Copy to"); copyToLabel.setLayoutData(GridDataFactory.swtDefaults().hint(144, SWT.DEFAULT).create()); final Text locationText = createTextField(varContainer); locationText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { location = locationText.getText(); String error = validate(); setErrorMessage(error); applyButton.setEnabled(error == null && location.length() != 0); } private String validate() { if (location.length() == 0) { return null; } File folder = new File(location); if (!folder.exists()) { return null; } if (!folder.isDirectory()) { return "Path is not a directory."; } if (!isEmpty(folder)) { return "Directory is not empty."; } return null; } private boolean isEmpty(File folder) { File[] children = folder.listFiles(); return children == null || children.length == 0; } }); FlatButton folderButton = new ImageHoverButton(varContainer, SWT.PUSH, SetupInstallerPlugin.INSTANCE.getSWTImage("simple/folder.png"), SetupInstallerPlugin.INSTANCE.getSWTImage("simple/folder_hover.png")); folderButton.setLayoutData(GridDataFactory.swtDefaults().indent(12, 0).create()); folderButton.setToolTipText("Browse" + StringUtil.HORIZONTAL_ELLIPSIS); folderButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { FileDialog chooser = new FileDialog(dialog.getShell(), SWT.APPLICATION_MODAL | SWT.SAVE); chooser.setText("Keep Installer"); if (!StringUtil.isEmpty(location)) { final File file = new File(location).getAbsoluteFile(); chooser.setFilterPath(file.getParent()); chooser.setFileName(file.getName()); } String dir = chooser.open(); if (dir != null) { locationText.setText(dir); } } }); if (KeepInstallerUtil.getPowerShell() != null) { new Label(varContainer, SWT.NONE); startMenuButton = createCheckbox(varContainer, "create start menu entry"); startMenuButton.setChecked(true); new Label(varContainer, SWT.NONE); desktopButton = createCheckbox(varContainer, "create desktop shortcut"); desktopButton.setChecked(true); } new Label(varContainer, SWT.NONE); applyButton = new FlatButton(varContainer, SWT.PUSH); applyButton.setLayoutData(GridDataFactory.fillDefaults().indent(0, 43).hint(SWT.DEFAULT, 36).create()); applyButton.setText("APPLY"); applyButton.setBackground(SetupInstallerPlugin.getColor(50, 196, 0)); applyButton.setForeground(AbstractSimpleDialog.COLOR_WHITE); applyButton.setFont(SimpleInstallerDialog.getFont(5, "bold")); applyButton.setCornerWidth(10); applyButton.setAlignment(SWT.CENTER); applyButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { final String launcher = InstallerApplication.getLauncher(); if (launcher != null) { final boolean startMenu = startMenuButton == null ? false : startMenuButton.isChecked(); final boolean desktop = desktopButton == null ? false : desktopButton.isChecked(); ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog( (Shell) getShell().getParent()); try { progressMonitorDialog.run(true, false, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Copying installer to " + location, IProgressMonitor.UNKNOWN); KeepInstallerUtil.keepInstaller(location, startPermanentInstaller, launcher, startMenu, desktop, false); UIUtil.getDisplay().asyncExec(new Runnable() { public void run() { dialog.backSelected(); } }); monitor.done(); } }); } catch (InterruptedException ex) { // Ignore. } catch (Exception ex) { SetupInstallerPlugin.INSTANCE.log(ex); } } } }); getShell().getDisplay().asyncExec(new Runnable() { public void run() { File home = new File(PropertiesUtil.getUserHome()); for (int i = 1; i < Integer.MAX_VALUE; i++) { File folder = new File(home, "eclipse-installer" + (i > 1 ? i : "")); if (!folder.exists()) { String path = folder.getAbsolutePath(); locationText.setText(path); locationText.setSelection(path.length()); return; } } } }); }