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.debug.internal.ui.viewers.model.VirtualCopyToClipboardActionDelegate.java
License:Open Source License
/** * Do the specific action using the current selection. * @param action Action that is running. *//*from www .j a va2 s . c o m*/ public void run(final IAction action) { if (fClientViewer.getSelection().isEmpty()) { writeBufferToClipboard(new StringBuffer("")); return; } final VirtualViewerListener listener = new VirtualViewerListener(); ItemsToCopyVirtualItemValidator validator = new ItemsToCopyVirtualItemValidator(); VirtualTreeModelViewer virtualViewer = initVirtualViewer(fClientViewer, listener, validator); ProgressMonitorDialog dialog = new TimeTriggeredProgressMonitorDialog(fClientViewer.getControl().getShell(), 500); final IProgressMonitor monitor = dialog.getProgressMonitor(); dialog.setCancelable(true); IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(final IProgressMonitor m) throws InvocationTargetException, InterruptedException { synchronized (listener) { listener.fProgressMonitor = m; listener.fProgressMonitor.beginTask(DebugUIPlugin.removeAccelerators(getAction().getText()), listener.fRemainingUpdatesCount); } while ((!listener.fLabelUpdatesComplete || !listener.fViewerUpdatesComplete) && !listener.fProgressMonitor.isCanceled()) { Thread.sleep(1); } synchronized (listener) { listener.fProgressMonitor = null; } } }; try { dialog.run(true, true, runnable); } catch (InvocationTargetException e) { DebugUIPlugin.log(e); return; } catch (InterruptedException e) { return; } if (!monitor.isCanceled()) { copySelectionToClipboard(virtualViewer, validator.fItemsToCopy, listener.fSelectionRootDepth); } virtualViewer.removeLabelUpdateListener(listener); virtualViewer.removeViewerUpdateListener(listener); virtualViewer.dispose(); }
From source file:org.eclipse.dltk.internal.debug.ui.interpreters.AbstractInterpreterLibraryBlock.java
License:Open Source License
protected LibraryLocation[] getLibrariesWithEnvironment(final EnvironmentVariable[] environmentVariables) { final LibraryLocation[][] libs = new LibraryLocation[][] { null }; final IFileHandle installLocation = getHomeDirectory(); if (installLocation == null) { libs[0] = new LibraryLocation[0]; } else {//from w ww .j ava 2 s. c o m ProgressMonitorDialog dialog = new TimeTriggeredProgressMonitorDialog(null, 1000); try { dialog.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { libs[0] = getInterpreterInstallType().getDefaultLibraryLocations(installLocation, environmentVariables, monitor); } }); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } } return libs[0]; }
From source file:org.eclipse.dltk.internal.debug.ui.interpreters.AbstractInterpreterLibraryBlock.java
License:Open Source License
/** * Initializes this control based on the settings in the given Interpreter * install and type.// ww w.j a v a2s. c o m * * @param Interpreter * Interpreter or <code>null</code> if none * @param type * type of Interpreter install */ public void initializeFrom(IInterpreterInstall Interpreter, IInterpreterInstallType type) { fInterpreterInstall = Interpreter; fInterpreterInstallType = type; if (Interpreter != null) { setHomeDirectory(Interpreter.getInstallLocation()); // fLibraryContentProvider.setLibraries(ScriptRuntime // .getLibraryLocations(getInterpreterInstall(), null)); final LibraryLocation[][] libs = new LibraryLocation[][] { null }; ProgressMonitorDialog dialog = new TimeTriggeredProgressMonitorDialog(null, 3000); try { dialog.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { libs[0] = ScriptRuntime.getLibraryLocations(getInterpreterInstall(), monitor); } }); } catch (InvocationTargetException e) { if (DLTKCore.DEBUG) { e.printStackTrace(); } } catch (InterruptedException e) { if (DLTKCore.DEBUG) { e.printStackTrace(); } } fLibraryContentProvider.setLibraries(libs[0]); // Set All possibly libraries here fLibraryContentProvider.initialize(getHomeDirectory(), fDialog.getEnvironmentVariables(), false); } update(); }
From source file:org.eclipse.dltk.internal.debug.ui.interpreters.InterpretersBlock.java
License:Open Source License
/** * Search for installed interpreters in the file system *//*from w ww . j a v a 2 s . co m*/ protected void search() { // choose a root directory for the search // ignore installed locations final Set<IFileHandle> exstingLocations = new HashSet<IFileHandle>(); Iterator<IInterpreterInstall> iter = fInterpreters.iterator(); while (iter.hasNext()) { exstingLocations.add(iter.next().getInstallLocation()); } // search final InterpreterSearcher searcher = new InterpreterSearcher(); final IEnvironment currentEnvironment = getCurrentEnvironment(); IRunnableWithProgress r = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) { try { monitor.beginTask(InterpretersMessages.InstalledInterpretersBlock_11, IProgressMonitor.UNKNOWN); searcher.search(currentEnvironment, getCurrentNature(), exstingLocations, 1, monitor); } finally { monitor.done(); } } }; try { ProgressMonitorDialog progress = new ProgressMonitorDialog(getShell()) { @Override protected void createCancelButton(Composite parent) { super.createCancelButton(parent); cancel.setText(InterpretersMessages.InterpretersBlock_0); } }; progress.run(true, true, r); } catch (InvocationTargetException e) { DLTKDebugUIPlugin.log(e); } catch (InterruptedException e) { return; // cancelled } final int[] widths = { 15, 15 }; if (!searcher.hasResults()) { MessageDialog.openInformation(getShell(), InterpretersMessages.InstalledInterpretersBlock_12, InterpretersMessages.InstalledInterpretersBlock_113); } else { final IFileHandle[] locations = searcher.getFoundFiles(); final IInterpreterInstallType[] types = searcher.getFoundInstallTypes(); boolean added = false; for (int i = 0; i < locations.length; ++i) { final IFileHandle file = locations[i]; final IInterpreterInstallType type = types[i]; if (isDuplicate(file)) { continue; } added = true; IInterpreterInstall interpreter = new InterpreterStandin(type, createUniqueId(type)); final String name = file.getName(); String nameCopy = name; int j = 1; while (isDuplicateName(nameCopy, null)) { nameCopy = name + '(' + (j++) + ')'; } if (widths[0] < nameCopy.length()) { widths[0] = nameCopy.length() + 2; } if (widths[1] < type.getName().length()) { widths[1] = type.getName().length() + 2; } interpreter.setName(nameCopy); interpreter.setInstallLocation(file); interpreterAdded(interpreter); } if (!added) { MessageDialog.openInformation(getShell(), InterpretersMessages.InstalledInterpretersBlock_12, InterpretersMessages.InstalledInterpretersBlock_113); } fTable.getDisplay().asyncExec(new Runnable() { public void run() { PixelConverter conv = new PixelConverter(fTable); for (int i = 0; i < 2; i++) { int nw1 = conv.convertWidthInCharsToPixels(widths[i]); TableColumn cl0 = fTable.getColumn(i); if (cl0.getWidth() < nw1) { cl0.setWidth(nw1); } } fTable.layout(); } }); } }
From source file:org.eclipse.dltk.internal.ui.wizards.buildpath.VariableBlock.java
License:Open Source License
public boolean performOk() { ArrayList removedVariables = new ArrayList(); ArrayList changedVariables = new ArrayList(); removedVariables.addAll(Arrays.asList(DLTKCore.getBuildpathVariableNames())); // remove all unchanged List changedElements = fVariablesList.getElements(); for (int i = changedElements.size() - 1; i >= 0; i--) { BPVariableElement curr = (BPVariableElement) changedElements.get(i); if (curr.isReadOnly()) { changedElements.remove(curr); } else {// w w w . j a v a 2 s . c o m IPath path = curr.getPath(); IPath prevPath = DLTKCore.getBuildpathVariable(curr.getName()); if (prevPath != null && prevPath.equals(path)) { changedElements.remove(curr); } else { changedVariables.add(curr.getName()); } } removedVariables.remove(curr.getName()); } int steps = changedElements.size() + removedVariables.size(); if (steps > 0) { boolean needsBuild = false; if (fAskToBuild && doesChangeRequireFullBuild(removedVariables, changedVariables)) { String title = NewWizardMessages.VariableBlock_needsbuild_title; String message = NewWizardMessages.VariableBlock_needsbuild_message; MessageDialog buildDialog = new MessageDialog(getShell(), title, null, message, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, 2); int res = buildDialog.open(); if (res != 0 && res != 1) { return false; } needsBuild = (res == 0); } final VariableBlockRunnable runnable = new VariableBlockRunnable(removedVariables, changedElements); final ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell()); try { dialog.run(true, true, runnable); } catch (InvocationTargetException e) { ExceptionHandler.handle(new InvocationTargetException(new NullPointerException()), getShell(), NewWizardMessages.VariableBlock_variableSettingError_titel, NewWizardMessages.VariableBlock_variableSettingError_message); return false; } catch (InterruptedException e) { return false; } if (needsBuild) { CoreUtility.getBuildJob(null).schedule(); } } return true; }
From source file:org.eclipse.dltk.mod.internal.debug.ui.interpreters.InterpretersBlock.java
License:Open Source License
/** * Search for installed interpreters in the file system *//*from ww w . j ava2 s. c o m*/ protected void search() { // choose a root directory for the search // ignore installed locations final Set exstingLocations = new HashSet(); Iterator iter = fInterpreters.iterator(); while (iter.hasNext()) { exstingLocations.add(((IInterpreterInstall) iter.next()).getInstallLocation()); } // search final InterpreterSearcher searcher = new InterpreterSearcher(); final IEnvironment currentEnvironment = getCurrentEnvironment(); IRunnableWithProgress r = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) { try { monitor.beginTask(InterpretersMessages.InstalledInterpretersBlock_11, IProgressMonitor.UNKNOWN); searcher.search(currentEnvironment, getCurrentNature(), exstingLocations, 1, monitor); } finally { monitor.done(); } } }; try { ProgressMonitorDialog progress = new TimeTriggeredProgressMonitorDialog(getShell(), 500) { protected void createCancelButton(Composite parent) { super.createCancelButton(parent); cancel.setText(InterpretersMessages.InterpretersBlock_0); } }; progress.run(true, true, r); } catch (InvocationTargetException e) { DLTKDebugUIPlugin.log(e); } catch (InterruptedException e) { return; // cancelled } final int[] widths = { 15, 15 }; if (!searcher.hasResults()) { MessageDialog.openInformation(getShell(), InterpretersMessages.InstalledInterpretersBlock_12, InterpretersMessages.InstalledInterpretersBlock_113); } else { final IFileHandle[] locations = searcher.getFoundFiles(); final IInterpreterInstallType[] types = searcher.getFoundInstallTypes(); boolean added = false; for (int i = 0; i < locations.length; ++i) { final IFileHandle file = locations[i]; final IInterpreterInstallType type = types[i]; if (isDuplicate(file)) { continue; } added = true; IInterpreterInstall interpreter = new InterpreterStandin(type, createUniqueId(type)); final String name = file.getName(); String nameCopy = name; int j = 1; while (isDuplicateName(nameCopy)) { nameCopy = name + '(' + (j++) + ')'; } if (widths[0] < nameCopy.length()) { widths[0] = nameCopy.length() + 2; } if (widths[1] < type.getName().length()) { widths[1] = type.getName().length() + 2; } interpreter.setName(nameCopy); interpreter.setInstallLocation(file); interpreterAdded(interpreter); } if (!added) { MessageDialog.openInformation(getShell(), InterpretersMessages.InstalledInterpretersBlock_12, InterpretersMessages.InstalledInterpretersBlock_113); } fTable.getDisplay().asyncExec(new Runnable() { public void run() { PixelConverter conv = new PixelConverter(fTable); for (int i = 0; i < 2; i++) { int nw1 = conv.convertWidthInCharsToPixels(widths[i]); TableColumn cl0 = fTable.getColumn(i); if (cl0.getWidth() < nw1) { cl0.setWidth(nw1); } } fTable.layout(); } }); } }
From source file:org.eclipse.dltk.tcl.internal.debug.ui.interpreters.TclInterpretersBlock.java
License:Open Source License
private void fetchInterpreterInformation(final IInterpreterInstall install) { ProgressMonitorDialog dialog = new ProgressMonitorDialog(fetchInterpreterInformation.getShell()); try {/*from w w w .j ava 2 s.c om*/ dialog.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { IContentCache cache = ModelManager.getModelManager().getCoreCache(); monitor.beginTask("Fetching interpreter information", 100); List<TclPackageInfo> list = null; try { TclPackagesManager.markInterprterAsNotFetched(install); list = TclPackagesManager.getPackageInfos(install); } catch (Exception e) { // Try one more time list = TclPackagesManager.getPackageInfos(install); } monitor.worked(20); SubProgressMonitor smon0 = new SubProgressMonitor(monitor, 40); int s = 0; int lsize = list.size(); smon0.beginTask("Fetch package information", lsize / 50); while (s < lsize) { int part = 50; if (lsize - s < part) { part = lsize - s; } if (smon0.isCanceled()) { break; } smon0.subTask("Processing packages info (" + (lsize - s) + " left)"); Set<String> pkgs = new HashSet(); for (int i = s; i < s + part; i++) { pkgs.add(list.get(i).getName()); } try { List<TclPackageInfo> infos = TclPackagesManager.getPackageInfos(install, pkgs, true); } catch (Exception e) { if (DLTKCore.DEBUG) { e.printStackTrace(); } } s += part; smon0.worked(1); } smon0.done(); SubProgressMonitor smon = new SubProgressMonitor(monitor, 40); IEnvironment env = install.getEnvironment(); smon.beginTask("Processing packages", lsize); int index = 1; for (TclPackageInfo tclPackageInfo : list) { smon.subTask("Processing package:" + tclPackageInfo.getName() + " (" + (lsize - index) + " left)"); index++; if (smon.isCanceled()) { break; } boolean processed = false; try { TclPackageInfo info = TclPackagesManager.getPackageInfo(install, tclPackageInfo.getName(), true); if (info != null) { List<String> sources = info.getSources(); Set<IPath> parents = new HashSet<IPath>(); for (String source : sources) { IPath path = new Path(source); IPath parent = path.removeLastSegments(1); parents.add(parent); } for (IPath path : parents) { IFileHandle file = env.getFile(path); if (file.exists()) { ArchiveContentCacheProvider.processFolderIndexes(file, cache, smon); processed = true; } } } } catch (Exception e) { if (DLTKCore.DEBUG) { e.printStackTrace(); } } if (!processed) { smon.worked(1); } } smon.done(); monitor.done(); } }); } catch (Exception e1) { if (DLTKCore.DEBUG) { e1.printStackTrace(); } } }
From source file:org.eclipse.dltk.tcl.internal.ui.documentation.ManPagesLocationsDialog.java
License:Open Source License
protected void doAdd() { final DirectoryDialog dialog = new DirectoryDialog(getShell()); dialog.setMessage(ManPagesMessages.ManPagesLocationsDialog_6); final String result = dialog.open(); if (result != null) { final File file = new File(result); if (file.isDirectory()) { ProgressMonitorDialog dialog2 = new TimeTriggeredProgressMonitorDialog(null, 500); try { dialog2.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) { monitor.beginTask(ManPagesMessages.ManPagesLocationsDialog_7, 1); final ManPageFinder finder = new ManPageFinder(); finder.find(documentation, file); monitor.done();/*www. jav a 2s . c om*/ } }); } catch (InvocationTargetException e) { TclUI.error(e); } catch (InterruptedException e) { // ignore } pathViewer.refresh(); updateStatus(); } } }
From source file:org.eclipse.e4.demo.contacts.handlers.SaveHandler.java
License:Open Source License
@Execute public void execute(IEclipseContext context, @Optional IStylingEngine engine, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell, final EPartService partService) throws InvocationTargetException, InterruptedException { final MPart details = partService.findPart("DetailsView"); final IEclipseContext pmContext = context.createChild(); ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell); dialog.open();//from ww w. j av a 2s . c o m ThemeUtil.applyDialogStyles(engine, dialog.getShell()); dialog.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { pmContext.set(IProgressMonitor.class.getName(), monitor); Object clientObject = details.getObject(); ContextInjectionFactory.invoke(clientObject, Persist.class, pmContext, null); } }); if (pmContext != null) pmContext.dispose(); }
From source file:org.eclipse.e4.tools.emf.ui.internal.common.resourcelocator.TargetPlatformContributionCollector.java
License:Open Source License
/** * Ensures the cache is loaded. By default it is loaded on first access, and * kept static until forced to reloaded. * * @param force/*from w w w . j a v a 2 s . c o m*/ * true to force reload the cache */ private void reloadCache(boolean force) { if (cacheEntry.isEmpty() || force) { cacheEntry.clear(); cacheBundleId.clear(); cachePackage.clear(); cacheLocation.clear(); outputDirectories.clear(); Display.getDefault().syncExec(new Runnable() { @Override public void run() { ProgressMonitorDialog dlg = new ProgressMonitorDialog(Display.getDefault().getActiveShell()) { @Override protected Control createContents(Composite parent) { // TODO odd this is not a bean. Composite ret = (Composite) super.createContents(parent); Label label = new Label(ret, SWT.NONE); label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 2, 1)); label.setText(Messages.TargetPlatformContributionCollector_pleaseWait); return ret; } }; try { dlg.run(true, true, new IRunnableWithProgress() { @Override public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { // load workspace projects IProject[] projects = PDECore.getWorkspace().getRoot().getProjects(); IPluginModelBase[] models = TargetPlatformHelper.getPDEState().getTargetModels(); int total = projects.length + models.length; monitor.beginTask( Messages.TargetPlatformContributionCollector_updatingTargetPlatformCache + cacheName + ")", //$NON-NLS-1$ total); for (final IProject pj : projects) { if (monitor.isCanceled()) { break; } String rootDirectory = pj.getLocation().toOSString(); monitor.subTask(rootDirectory); monitor.worked(1); TargetPlatformContributionCollector.this.visit(monitor, FilteredContributionDialog.getBundle(rootDirectory), rootDirectory, new File(rootDirectory)); } // load target platform bundles for (IPluginModelBase pluginModelBase : models) { monitor.subTask(pluginModelBase.getPluginBase().getId()); monitor.worked(1); if (monitor.isCanceled()) { break; } IPluginBase pluginBase = pluginModelBase.getPluginBase(); if (pluginBase == null) { // bundle = getBundle(new File()) continue; } URL url; try { String installLocation = pluginModelBase.getInstallLocation(); if (installLocation.endsWith(".jar")) { //$NON-NLS-1$ url = new URL("file://" + installLocation); //$NON-NLS-1$ ZipInputStream zis = new ZipInputStream(url.openStream()); while (true) { ZipEntry entry = zis.getNextEntry(); if (entry == null) { break; } else { String name2 = entry.getName(); if (shouldIgnore(name2)) { continue; } Matcher m = patternFile.matcher(name2); if (m.matches()) { Entry e = new Entry(); e.installLocation = installLocation; cacheLocation.add(installLocation); e.name = m.group(2); e.path = m.group(1); if (e.path != null) { e.pakage = e.path.replace("/", "."); //$NON-NLS-1$ //$NON-NLS-2$ if (e.pakage.startsWith(".")) { //$NON-NLS-1$ e.pakage = e.pakage.substring(1); } if (e.pakage.endsWith(".")) { //$NON-NLS-1$ e.pakage = e.pakage.substring(0, e.pakage.length() - 1); } } else { e.pakage = ""; //$NON-NLS-1$ } cachePackage.add(e.pakage); e.bundleSymName = pluginBase.getId(); if (e.path == null) { e.path = ""; //$NON-NLS-1$ } cacheEntry.add(e); cacheBundleId.add(pluginBase.getId()); // // System.out.println(group // + " -> " // + // m.group(2)); } } } } else { // not a jar file String bundle = getBundle(new File(installLocation)); if (bundle != null) { visit(monitor, bundle, installLocation, new File(installLocation)); } } } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } monitor.done(); } }); } catch (InvocationTargetException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (InterruptedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); } }