List of usage examples for org.eclipse.jface.dialogs ProgressMonitorDialog setBlockOnOpen
public void setBlockOnOpen(boolean shouldBlock)
open
method should block until the window closes. From source file:org.python.pydev.ui.pythonpathconf.AbstractInterpreterPreferencesPage.java
License:Open Source License
/** * Restores the modules. Is called when the user changed something in the editor and applies the change. * * Gathers all the info and calls the hook that really restores things within a thread, so that the user can * get information on the progress./*from w w w . j a va 2s .c om*/ * * Only the information on the default interpreter is stored. * * @param editorChanged whether the editor was changed (if it wasn't, we'll ask the user what to restore). * @return true if the info was restored and false otherwise. */ protected void restoreInterpreterInfos(boolean editorChanged) { final Set<String> interpreterNamesToRestore = pathEditor.getInterpreterExeOrJarToRestoreAndClear(); final IInterpreterInfo[] exesList = pathEditor.getExesList(); if (!editorChanged && interpreterNamesToRestore.size() == 0) { IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); SelectionDialog listDialog = createChooseIntepreterInfoDialog(workbenchWindow, exesList, "Select interpreters to be restored", true); int open = listDialog.open(); if (open != ListDialog.OK) { return; } Object[] result = listDialog.getResult(); if (result == null || result.length == 0) { return; } for (Object o : result) { interpreterNamesToRestore.add(((IInterpreterInfo) o).getExecutableOrJar()); } } //this is the default interpreter ProgressMonitorDialog monitorDialog = new AsynchronousProgressMonitorDialog(this.getShell()); monitorDialog.setBlockOnOpen(false); try { IRunnableWithProgress operation = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Restoring PYTHONPATH", IProgressMonitor.UNKNOWN); try { pathEditor.pushExpectedSetInfos(); //clear all but the ones that appear getInterpreterManager().setInfos(exesList, interpreterNamesToRestore, monitor); } finally { pathEditor.popExpectedSetInfos(); monitor.done(); } } }; monitorDialog.run(true, true, operation); } catch (Exception e) { Log.log(e); } }
From source file:org.python.pydev.ui.pythonpathconf.InterpreterConfigHelpers.java
License:Open Source License
/** * Attempts to set up a provided interpreter. * * @param interpreterNameAndExecutable Information pertaining to the interpreter to prepare. * @param interpreterManager/* www .ja va2 s .c o m*/ * @param autoSelectFolders If true, folders will be automatically added to the SYSTEM pythonpath. * Otherwise, they must be selected manually with a dialog. * @param displayErrors Set to true to display an error dialog on failure, or false to fail silently. * @param logger * @param shell A mandatory shell in which to display progress and errors. * @return The interpreter config operation, or <code>null</code> if the operation is cancelled. * @throws Exception Will be thrown if an operation fails. */ static ObtainInterpreterInfoOperation tryInterpreter(Tuple<String, String> interpreterNameAndExecutable, IInterpreterManager interpreterManager, boolean autoSelectFolders, boolean displayErrors, PrintWriter logger, Shell shell) throws Exception { String executable = interpreterNameAndExecutable.o2; logger.println("- Ok, file is non-null. Getting info on:" + executable); ProgressMonitorDialog monitorDialog = new AsynchronousProgressMonitorDialog(shell); monitorDialog.setBlockOnOpen(false); ObtainInterpreterInfoOperation operation; while (true) { operation = new ObtainInterpreterInfoOperation(interpreterNameAndExecutable.o2, logger, interpreterManager, autoSelectFolders); monitorDialog.run(true, false, operation); if (operation.e != null) { logger.println("- Some error happened while getting info on the interpreter:"); operation.e.printStackTrace(logger); String errorTitle = "Unable to get info on the interpreter: " + executable; if (operation.e instanceof SimpleJythonRunner.JavaNotConfiguredException) { SimpleJythonRunner.JavaNotConfiguredException javaNotConfiguredException = (SimpleJythonRunner.JavaNotConfiguredException) operation.e; if (displayErrors) { ErrorDialog.openError(shell, errorTitle, javaNotConfiguredException.getMessage(), PydevPlugin.makeStatus(IStatus.ERROR, "Java vm not configured.\n", javaNotConfiguredException)); } throw new Exception(javaNotConfiguredException); } else if (operation.e instanceof JDTNotAvailableException) { JDTNotAvailableException noJdtException = (JDTNotAvailableException) operation.e; if (displayErrors) { ErrorDialog.openError(shell, errorTitle, noJdtException.getMessage(), PydevPlugin.makeStatus(IStatus.ERROR, "JDT not available.\n", noJdtException)); } throw new Exception(noJdtException); } else { if (displayErrors) { //show the user a message (so that it does not fail silently)... String errorMsg = "Unable to get info on the interpreter: " + executable + "\n\n" + "Common reasons include:\n\n" + "- Using an unsupported version\n" + " (Python and Jython require at least version 2.1 and IronPython 2.6).\n" + "\n" + "- Specifying an invalid interpreter\n" + " (usually a link to the actual interpreter on Mac or Linux)" + ""; ErrorDialog.openError(shell, errorTitle, errorMsg, PydevPlugin.makeStatus(IStatus.ERROR, "See error log for details.", operation.e)); } throw new Exception(operation.e); } } else if (operation.result == null) { //Folder selection was canceled, exit return null; } //Ok, we got the result, so, let's check if things are correct (i.e.: do we have threading.py, traceback.py?) HashSet<String> hashSet = new HashSet<String>(); hashSet.add("threading"); hashSet.add("traceback"); String[] validSourceFiles = FileTypesPreferencesPage.getValidSourceFiles(); Set<String> extensions = new HashSet<String>(Arrays.asList(validSourceFiles)); for (String s : operation.result.libs) { File file = new File(s); if (file.isDirectory()) { String[] directoryFiles = file.list(); if (directoryFiles != null) { for (String found : directoryFiles) { List<String> split = StringUtils.split(found, '.'); if (split.size() == 2) { if (extensions.contains(split.get(1))) { hashSet.remove(split.get(0)); } } } } else { logger.append("Warning: unable to get contents of directory: " + file + " (permission not available, it's not a dir or dir does not exist)."); } } else if (file.isFile()) { //Zip file? try { try (ZipFile zipFile = new ZipFile(file)) { for (String extension : validSourceFiles) { if (zipFile.getEntry("threading." + extension) != null) { hashSet.remove("threading"); } if (zipFile.getEntry("traceback." + extension) != null) { hashSet.remove("traceback"); } } } } catch (Exception e) { //ignore (not zip file) } } } if (hashSet.size() > 0) { if (displayErrors) { //The /Lib folder wasn't there (or at least threading.py and traceback.py weren't found) int choice = PyDialogHelpers.openCriticalWithChoices( "Error: Python stdlib source files not found.", "Error: Python stdlib not found or stdlib found without .py files.\n" + "\n" + "It seems that the Python /Lib folder (which contains the standard library) " + "was not found/selected during the install process or the stdlib does not contain " + "the required .py files (i.e.: only has .pyc files).\n" + "\n" + "This folder (which contains files such as threading.py and traceback.py) is " + "required for PyDev to function properly, and it must contain the actual source files, not " + "only .pyc files. if you don't have the .py files in your install, please use an install from " + "python.org or grab the standard library for your install from there.\n" + "\n" + "If this is a virtualenv install, the /Lib folder from the base install needs to be selected " + "(unlike the site-packages which is optional).\n" + "\n" + "What do you want to do?\n\n" + "Note: if you choose to proceed, the /Lib with the standard library .py source files must " + "be added later on, otherwise PyDev may not function properly.", new String[] { "Re-select folders", "Cancel", "Proceed anyways" }); if (choice == 0) { //Keep on with outer while(true) continue; } if (choice == 1) { //Return nothing and exit quietly on a cancel return null; } } else { //Don't allow auto-selection of an interpreter missing these folders logger.println("- Could not find /Lib folder, exiting with error."); throw new Exception(ERMSG_NOLIBS + executable); } } operation.result.setName(interpreterNameAndExecutable.o1); logger.println("- Success getting the info. Result:" + operation.result); return operation; } }
From source file:org.python.pydev.utils.ProgressOperation.java
License:Open Source License
/** * @param shell//w w w . j ava2 s .com * */ public static void startAction(Shell shell, ProgressAction action, boolean cancelable) { ProgressMonitorDialog monitorDialog = new AsynchronousProgressMonitorDialog(shell); monitorDialog.setCancelable(cancelable); monitorDialog.setBlockOnOpen(false); try { IRunnableWithProgress operation = new ProgressOperation(action); monitorDialog.run(false, false, operation); // Perform the action } catch (InvocationTargetException e) { Log.log(e); } catch (InterruptedException e) { Log.log(e); } }
From source file:org.rssowl.ui.internal.dialogs.NewsFiltersListDialog.java
License:Open Source License
private void applyFilter(final List<SearchHit<NewsReference>> news, final ISearchFilter filter) { IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) { List<List<SearchHit<NewsReference>>> chunks = CoreUtils.toChunks(news, FILTER_CHUNK_SIZE); monitor.beginTask(NLS.bind(Messages.NewsFiltersListDialog_WAIT_FILTER_APPLIED, filter.getName()), chunks.size());// w w w .j a va 2 s . c o m if (monitor.isCanceled()) return; int counter = 0; for (List<SearchHit<NewsReference>> chunk : chunks) { if (monitor.isCanceled()) return; monitor.subTask(NLS.bind(Messages.NewsFiltersListDialog_FILTERED_N_OF_M_NEWS, (counter * FILTER_CHUNK_SIZE), news.size())); List<INews> newsItemsToFilter = new ArrayList<INews>(FILTER_CHUNK_SIZE); for (SearchHit<NewsReference> chunkItem : chunk) { INews newsItemToFilter = chunkItem.getResult().resolve(); if (newsItemToFilter != null && newsItemToFilter.isVisible()) newsItemsToFilter.add(newsItemToFilter); else CoreUtils.reportIndexIssue(); } applyFilterOnChunks(newsItemsToFilter, filter); monitor.worked(1); counter++; } monitor.done(); } }; /* Show progress and allow for cancellation */ ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell()); dialog.setBlockOnOpen(false); dialog.setCancelable(true); dialog.setOpenOnRun(true); try { dialog.run(true, true, runnable); } catch (InvocationTargetException e) { Activator.getDefault().logError(e.getMessage(), e); } catch (InterruptedException e) { Activator.getDefault().logError(e.getMessage(), e); } }
From source file:org.schwiebert.cloudio.application.actions.LoadFileAction.java
License:Open Source License
@Override public void run(IAction action) { FileDialog dialog = new FileDialog(getShell(), SWT.OPEN); dialog.setText("Select text file..."); String sourceFile = dialog.open(); if (sourceFile == null) return;/*w w w. j a v a 2s. co m*/ ProgressMonitorDialog pd = new ProgressMonitorDialog(getShell()); try { List<Type> types = TypeCollector.getData(new File(sourceFile), "UTF-8"); pd.setBlockOnOpen(false); pd.open(); pd.getProgressMonitor().beginTask("Generating cloud...", 200); TagCloudViewer viewer = getViewer(); viewer.setInput(types, pd.getProgressMonitor()); long start = System.currentTimeMillis(); viewer.getCloud().layoutCloud(pd.getProgressMonitor(), false); long end = System.currentTimeMillis(); System.out.println("Layouted: " + (end - start)); } catch (IOException e) { e.printStackTrace(); } finally { pd.close(); } }
From source file:org.wso2.developerstudio.eclipse.carbonserver.base.manager.CarbonServerManager.java
License:Open Source License
public static boolean waitForServerToChangeState(IServer server, Shell shell, int changeStateFrom, int changeStateTo, String msg) { ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(shell); CarbonServerStateChange serverStateChange = new CarbonServerStateChange(server, changeStateFrom, changeStateTo, 180000, msg); progressMonitorDialog.setBlockOnOpen(false); try {/* w w w.j a v a 2s. c om*/ progressMonitorDialog.run(true, true, serverStateChange); return progressMonitorDialog.getReturnCode() != ProgressMonitorDialog.CANCEL; } catch (InvocationTargetException e) { log.error(e); } catch (InterruptedException e) { log.error(e); } return false; }
From source file:ummisco.gama.ui.views.SyntaxErrorsView.java
static void build() { final ProgressMonitorDialog dialog = new ProgressMonitorDialog(WorkbenchHelper.getShell()); dialog.setBlockOnOpen(false); dialog.setCancelable(false);/*w ww . j a v a 2s . c o m*/ dialog.setOpenOnRun(true); try { dialog.run(true, false, monitor -> doBuild(monitor)); } catch (InvocationTargetException | InterruptedException e1) { e1.printStackTrace(); } }
From source file:webx.studio.projectcreation.ui.project.ProjectHelper.java
License:Open Source License
public static void changeWebXVersion(final File topDir, final String settingsFile, final String webxVersion) throws Exception { if (topDir == null || topDir.isFile()) return;//w w w . j a v a 2s . c om final File totalPomFile = new File(topDir, "pom.xml"); if (!totalPomFile.exists() || !totalPomFile.isFile()) return; if (StringUtils.isBlank(webxVersion)) return; final Model model = MavenHelper.getModel(totalPomFile); final String origWebXVersion = model.getProperties().getProperty("webx3-version"); if (StringUtils.isBlank(origWebXVersion) || StringUtils.equals(origWebXVersion, webxVersion)) { return; } // Job job = new WorkspaceJob("Change the WebX project version ,from "+origWebXVersion+" to "+webxVersion+", Please wait!") { // // @Override // public IStatus runInWorkspace(IProgressMonitor monitor) // throws CoreException { // // try { // model.getProperties().setProperty("webx3-version", // webxVersion); // FileWriter sw = new FileWriter(totalPomFile); // new MavenXpp3Writer().write(sw, model); // MavenHelper.generateEclipse(topDir.getCanonicalPath(), // settingsFile, ProgressUtil.getMonitorFor(null)); // ResourcesPlugin // .getWorkspace() // .getRoot() // .refreshLocal(IResource.DEPTH_INFINITE, // ProgressUtil.getMonitorFor(null)); // return Status.OK_STATUS; // } catch (Exception e) { // throw new CoreException(new Status(IStatus.ERROR, // ProjectCreationPlugin.PLUGIN_ID, -1, // e.getMessage(), e)); // } // } // // }; // job.schedule(); final ProgressMonitorDialog dialog = new ProgressMonitorDialog( ProjectCreationPlugin.getActiveWorkbenchShell()); dialog.setBlockOnOpen(false); dialog.setCancelable(true); IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) { try { monitor.beginTask("Change the WebX project version ,from " + origWebXVersion + " to " + webxVersion + ", Please wait!", 100); model.getProperties().setProperty("webx3-version", webxVersion); FileWriter sw = new FileWriter(totalPomFile); new MavenXpp3Writer().write(sw, model); monitor.worked(20); MavenHelper.generateEclipse(topDir.getCanonicalPath(), settingsFile, ProgressUtil.getMonitorFor(null)); monitor.worked(80); ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, ProgressUtil.getMonitorFor(null)); monitor.done(); } catch (Exception e) { e.printStackTrace(); } } }; dialog.run(true, true, runnable); }