List of usage examples for org.eclipse.jface.dialogs ProgressMonitorDialog ProgressMonitorDialog
public ProgressMonitorDialog(Shell parent)
From source file:eu.geclipse.ui.problems.CheckSystemTimeSolution.java
License:Open Source License
public void solve() { final TimeChecker tr = new TimeChecker(); boolean timeOK = false; boolean timeCheckValid = true; // Get the shell first IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); Shell shell = null;/*from www. ja v a 2s .co m*/ if (window != null) { shell = window.getShell(); } IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { tr.checkSysTime(monitor); } catch (ProblemException pe) { throw new InvocationTargetException(pe); } } }; // Run the dialog try { new ProgressMonitorDialog(shell).run(true, true, runnable); } catch (InterruptedException ie) { // The user interrupted the operation timeCheckValid = false; } catch (InvocationTargetException ite) { // The system time check failed, inform the user Throwable cause = ite.getCause(); if (cause instanceof ProblemException) { String title = Messages.getString("CheckSystemTimeSolution.failed_dialog_title"); //$NON-NLS-1$ String msg = Messages.getString("CheckSystemTimeSolution.failed_check_system_time"); //$NON-NLS-1$ ProblemDialog.openProblem(shell, title, msg, cause); timeCheckValid = false; } } // Don't display any more dialogs, we cannot help further... if (!timeCheckValid) { return; } // The servers have been queried timeOK = tr.getTimeCheckStatus(); String title = Messages.getString("CheckSystemTimeSolution.dialog_title"); //$NON-NLS-1$ Shell parent = shell; // Construct the message string String message; if (timeOK) { message = Messages.getString("CheckSystemTimeSolution.system_clock_ok"); //$NON-NLS-1$ message = String.format(message, Integer.valueOf(tr.getTolerance())); } else { message = Messages.getString("CheckSystemTimeSolution.system_clock_not_ok"); //$NON-NLS-1$ message = String.format(message, Long.valueOf(tr.getOffset())); } message += ":\n\t" + tr.getSystemDate() + "\n\n"; //$NON-NLS-1$ //$NON-NLS-2$ message += Messages.getString("CheckSystemTimeSolution.queried_servers_report"); //$NON-NLS-1$ message += ":\n\t" + tr.getReferenceDate(); //$NON-NLS-1$ // Show the appropriate dialog if (timeOK) { MessageDialog.openInformation(parent, title, message); } else { MessageDialog.openError(parent, title, message); } }
From source file:eu.hydrologis.jgrass.formeditor.FormEditor.java
License:Open Source License
public void doSaveAs() { // Show a SaveAs dialog Shell shell = getSite().getWorkbenchWindow().getShell(); SaveAsDialog dialog = new SaveAsDialog(shell); // dialog.setOriginalFile(((IFileEditorInput) getEditorInput()).getFile()); dialog.open();/*from w ww . j a v a 2s . c o m*/ IPath path = dialog.getResult(); if (path != null) { // try to save the editor's contents under a different file name final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); try { new ProgressMonitorDialog(shell).run(false, // don't fork false, // not cancelable new WorkspaceModifyOperation() { // run this operation public void execute(final IProgressMonitor monitor) { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); createOutputStream(out); file.create(new ByteArrayInputStream(out.toByteArray()), // contents true, // keep saving, even if IFile is out of sync with // the Workspace monitor); // progress monitor } catch (CoreException ce) { ce.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } } }); // set input to the new file setInput(new FileEditorInput(file)); getCommandStack().markSaveLocation(); } catch (InterruptedException ie) { // should not happen, since the monitor dialog is not cancelable ie.printStackTrace(); } catch (InvocationTargetException ite) { ite.printStackTrace(); } } }
From source file:eu.modelwriter.marker.ui.internal.wizards.markallinwswizard.MarkAllInWsWizard.java
License:Open Source License
@Override public boolean performFinish() { final Object[] checkedElements = MarkAllInWsPage.checkboxTreeViewer.getCheckedElements(); final String text = this.textSelection.getText(); final String leader_id = UUID.randomUUID().toString(); boolean success = false; final Image image = MarkerActivator.getDefault().getImageRegistry() .get(MarkerActivator.Images.IMAGE_MODELWRITER_ID); final ProgressMonitorDialog pmd = new ProgressMonitorDialog( Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell()); ProgressMonitorDialog.setDefaultImage(image); pmd.open();// w w w . j a v a 2 s .c o m final IProgressMonitor pmdmoni = pmd.getProgressMonitor(); try { pmdmoni.beginTask("Marking", checkedElements.length); for (int i = 0; i < checkedElements.length && !pmdmoni.isCanceled(); i++) { try { if (checkedElements[i] instanceof IFile) { final IFile iFile = (IFile) checkedElements[i]; pmdmoni.subTask(iFile.getName()); pmdmoni.worked(1); if (!iFile.getFileExtension().equals("xmi") && !iFile.getFileExtension().equals("ecore") && !iFile.getFileExtension().equals("reqif")) { final String charSet = iFile.getCharset(); final Scanner scanner = new Scanner(iFile.getContents(), charSet); final IDocument document = new Document(scanner.useDelimiter("\\A").next()); scanner.close(); final String fullText = document.get(); boolean hasLeader = false; int index = 0; int offset = 0; final int lenght = this.textSelection.getLength(); final String id = UUID.randomUUID().toString(); if (lenght != 0) { while ((offset = fullText.indexOf(text, index)) != -1) { final TextSelection nextSelection = new TextSelection(document, offset, lenght); if (MarkerFactory.findMarkerByOffset(iFile, offset) == null) { final IMarker mymarker = MarkerFactory.createMarker(iFile, nextSelection); MarkUtilities.setGroupId(mymarker, id); if (!iFile.equals(this.file)) { if (hasLeader == false) { MarkUtilities.setLeaderId(mymarker, leader_id); hasLeader = true; } } else { if (this.textSelection.getOffset() == offset) { MarkUtilities.setLeaderId(mymarker, leader_id); } } this.addToAlloyXML(mymarker); AnnotationFactory.addAnnotation(mymarker, AnnotationFactory.ANNOTATION_MARKING); } index = offset + lenght; } } success = true; } else { final MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(), "Mark All In Workspace", null, iFile.getName() + " doesn't supported for this command.", MessageDialog.INFORMATION, new String[] { "OK" }, 0); dialog.open(); MarkAllInWsPage.checkboxTreeViewer.setChecked(iFile, false); } } } catch (final CoreException e) { e.printStackTrace(); } } } finally { pmdmoni.done(); } pmd.close(); if (success == true) { final MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(), "Mark All In Workspace", null, "Selected project(s) have been marked by selected text", MessageDialog.INFORMATION, new String[] { "OK" }, 0); dialog.open(); return true; } else { return false; } }
From source file:eu.numberfour.n4js.ui.compare.ProjectCompareTree.java
License:Open Source License
/** * Creates a new default comparison of all API / implementation projects in the default workspace (i.e. the one * accessed via {@link IN4JSCore}) and shows this comparison in the widget. *//* w w w. j a v a 2 s. co m*/ public void setComparison() { final ProgressMonitorDialog dlg = new ProgressMonitorDialog(getTree().getShell()); try { dlg.run(false, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { setComparison(monitor); } }); } catch (InvocationTargetException | InterruptedException e) { // ignore } }
From source file:eu.numberfour.n4js.ui.dialog.ModuleSpecifierSelectionDialog.java
License:Open Source License
@Override protected void createPressed() { InputDialog dialog = new InputDialog(getShell(), CREATE_A_NEW_FOLDER_TITLE, CREATE_A_NEW_FOLDER_MESSAGE, "", new ModuleFolderValidator()); dialog.open();// w ww. j a v a 2 s . c o m Object selection = treeViewer.getStructuredSelection().getFirstElement(); // Infer parent folder from selection IContainer parent; if (selection instanceof IFile) { parent = ((IFile) selection).getParent(); } else if (selection instanceof IContainer) { parent = (IContainer) selection; } else { // Use the source folder as default parent = this.sourceFolder; } String dialogValue = dialog.getValue(); if (OSInfo.isWindows()) { dialogValue = convertToUnixPath(dialogValue); } IPath folderPath = new Path(dialogValue); IContainer createdFolder = null; if (Window.OK == dialog.getReturnCode()) { ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(getShell()); progressMonitorDialog.open(); IProgressMonitor progressMonitor = progressMonitorDialog.getProgressMonitor(); createdFolder = createFolderPath(folderPath, parent, null); progressMonitor.done(); progressMonitorDialog.close(); if (null != createdFolder) { treeViewer.setSelection(new StructuredSelection(createdFolder)); } } }
From source file:eu.numberfour.n4js.ui.dialog.ModuleSpecifierSelectionDialog.java
License:Open Source License
/** * Processes the initial string selection. * * For existing resources it just sets the initial selection to the specified file system resource. * * In the case that the initial module specifier points to a non-existing location, a dialog is displayed which * allows the user to automatically create not yet existing folders. * * @param initialModuleSpecifier/* www. ja va 2 s . com*/ * The module specifier * @return A {@link IWorkbenchAdapter} adaptable object or null on failure */ private Object processInitialSelection(String initialModuleSpecifier) { IPath sourceFolderPath = sourceFolder.getFullPath(); IPath initialModulePath = new Path(initialModuleSpecifier); // Use the root element source folder for an empty initial selection if (initialModuleSpecifier.isEmpty()) { return this.sourceFolder; } // Use the root element source folder for invalid module specifiers if (!WorkspaceWizardValidatorUtils.isValidFolderPath(initialModulePath)) { return this.sourceFolder; } // The project relative path of a module specifier IPath fullPath = sourceFolderPath.append(new Path(initialModuleSpecifier)); // If the module specifier refers to an existing n4js resource if (!fullPath.hasTrailingSeparator()) { IFile n4jsModuleFile = workspaceRoot .getFile(fullPath.addFileExtension(N4JSGlobals.N4JS_FILE_EXTENSION)); IFile n4jsdModuleFile = workspaceRoot .getFile(fullPath.addFileExtension(N4JSGlobals.N4JSD_FILE_EXTENSION)); // Just use it as initial selection if (n4jsModuleFile.exists()) { return n4jsModuleFile; } if (n4jsdModuleFile.exists()) { return n4jsdModuleFile; } } //// Otherwise use the existing part of the path as initial selection: // If the module specifier specifies the module name, extract it and remove its segment. if (isModuleFileSpecifier(initialModulePath)) { initialModuleName = initialModulePath.lastSegment(); initialModulePath = initialModulePath.removeLastSegments(1); } IResource selection = this.sourceFolder; // Accumulate path segments to search for the longest existing path IPath accumulatedPath = sourceFolderPath; // Collect the paths of all non-existing segments // These are relative to the last existing segment of the path List<IPath> nonExistingSegmentPaths = new ArrayList<>(); for (Iterator<String> segmentIterator = Arrays.asList(initialModulePath.segments()) .iterator(); segmentIterator.hasNext(); /**/) { accumulatedPath = accumulatedPath.append(segmentIterator.next()); // Results in null if non-existing IResource nextSegmentResource = workspaceRoot.findMember(accumulatedPath); // If the current segment is an existing file and not the last specifier segment // show a file overlap error message if (null != nextSegmentResource && !(nextSegmentResource instanceof IContainer) && segmentIterator.hasNext()) { MessageDialog.open(MessageDialog.ERROR, getShell(), SPECIFIER_OVERLAPS_WITH_FILE_TITLE, String .format(SPECIFIER_OVERLAPS_WITH_FILE_MESSAGE, initialModuleSpecifier, accumulatedPath), SWT.NONE); return selection; } // If the segment exist go ahead with the next one if (null != nextSegmentResource && nextSegmentResource.exists()) { selection = nextSegmentResource; } else { // If not add it to the list of non existing segments. nonExistingSegmentPaths.add(accumulatedPath.makeRelativeTo(selection.getFullPath())); } } // If any non-existing folders need to be created if (nonExistingSegmentPaths.size() > 0) { // Ask the user if he wants to create the missing folders boolean create = MessageDialog.open(MessageDialog.QUESTION, getShell(), NON_EXISTING_MODULE_LOCATION_TITLE, NON_EXISTING_MODULE_LOCATION_MESSAGE, SWT.NONE); // Create the missing folders if (create) { ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(getShell()); progressMonitorDialog.open(); IProgressMonitor progressMonitor = progressMonitorDialog.getProgressMonitor(); IPath deepestPath = nonExistingSegmentPaths.get(nonExistingSegmentPaths.size() - 1); selection = createFolderPath(deepestPath, (IContainer) selection, progressMonitor); progressMonitor.done(); progressMonitorDialog.close(); } } return selection; }
From source file:eu.numberfour.n4js.ui.organize.imports.N4JSOrganizeImportsHandler.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { Collection<?> callingMenus = HandlerUtil.getActiveMenus(event); // "#TextEditorContext" is the defined plugin.xml boolean fromTextContext = (callingMenus != null && callingMenus.contains("#TextEditorContext")); boolean fromShortCut = (callingMenus == null || callingMenus.isEmpty()); XtextEditor editor = EditorUtils.getActiveXtextEditor(event); boolean haveActiveEditor = editor != null; ISelection selection = HandlerUtil.getCurrentSelection(event); boolean nonEmptyStructuredSelection = (selection != null && selection instanceof IStructuredSelection && !selection.isEmpty()); if (haveActiveEditor && (fromTextContext || fromShortCut)) { organizeEditor(editor);//from w ww . j a v a 2s . c o m } else if (nonEmptyStructuredSelection) { // probably called on a tree-selection in the package-manager or whatever view shows the project-structure: // organize files and folders: // for each selection entry collect files: Multimap<IProject, IFile> projectFiles = collectFiles((IStructuredSelection) selection); HashSet<IFile> filesInSet = new HashSet<>(projectFiles.values()); List<IFile> filesAsList = new ArrayList<>(filesInSet); if (filesAsList.isEmpty()) { return null; } // Query unsaved IWorkbench wbench = PlatformUI.getWorkbench(); IWorkbenchWindow activeWorkbenchWindow = wbench.getActiveWorkbenchWindow(); boolean allSaved = wbench.saveAll(activeWorkbenchWindow, activeWorkbenchWindow, null, true); if (!allSaved) { return null; } Shell shell = HandlerUtil.getActiveShell(event); IRunnableWithProgress op = new IRunnableWithProgress() { @Override public void run(IProgressMonitor mon) throws InvocationTargetException, InterruptedException { int totalWork = filesAsList.size(); mon.beginTask("Organize imports.", totalWork); for (int i = 0; !mon.isCanceled() && i < filesAsList.size(); i++) { IFile currentFile = filesAsList.get(i); mon.setTaskName("Organize imports." + " - File (" + (i + 1) + " of " + totalWork + ")"); try { mon.subTask(currentFile.getName()); doOrganizeImports(currentFile, new SubProgressMonitor(mon, 1)); } catch (CoreException | RuntimeException e) { String msg = "Exception in file " + currentFile.getFullPath().toString() + "."; LOGGER.error(msg, e); if (errorDialogWithStackTrace(msg + " Hit OK to continue.", e)) { // - logged anyway } else { throw new InvocationTargetException(e); } } } if (mon.isCanceled()) { throw new InterruptedException(); } } }; try { new ProgressMonitorDialog(shell).run(true, true, op); } catch (InvocationTargetException e) { throw new ExecutionException("Error during organizing imports", e); } catch (InterruptedException e) { // user cancelled, ok } } return null; }
From source file:eu.numberfour.n4js.ui.preferences.ExternalLibraryPreferencePage.java
License:Open Source License
@Override protected void performApply() { try {//w w w. j a v a 2 s . c o m new ProgressMonitorDialog(getShell()).run(true, false, monitor -> { final IStatus status = store.save(monitor); if (!status.isOK()) { setMessage(status.getMessage(), ERROR); } else { updateInput(viewer, store.getLocations()); } }); } catch (final InvocationTargetException | InterruptedException exc) { throw new RuntimeException("Error while building external libraries.", exc); } }
From source file:ext.org.eclipse.jdt.internal.corext.refactoring.RefactoringExecutionStarter.java
License:Open Source License
public static void startCleanupRefactoring(ICompilationUnit[] cus, ICleanUp[] cleanUps, boolean useOptionsFromProfile, Shell shell, boolean showWizard, String actionName) throws InvocationTargetException { final CleanUpRefactoring refactoring = new CleanUpRefactoring(actionName); for (int i = 0; i < cus.length; i++) { refactoring.addCompilationUnit(cus[i]); }//from w w w. j a va 2s . c o m if (!showWizard) { refactoring.setUseOptionsFromProfile(useOptionsFromProfile); for (int i = 0; i < cleanUps.length; i++) { refactoring.addCleanUp(cleanUps[i]); } IRunnableContext context; if (refactoring.getCleanUpTargetsSize() > 1) { context = new ProgressMonitorDialog(shell); } else { context = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); } RefactoringExecutionHelper helper = new RefactoringExecutionHelper(refactoring, IStatus.INFO, RefactoringSaveHelper.SAVE_REFACTORING, shell, context); try { helper.perform(true, true, true); } catch (InterruptedException e) { } } else { CleanUpRefactoringWizard refactoringWizard = new CleanUpRefactoringWizard(refactoring, RefactoringWizard.WIZARD_BASED_USER_INTERFACE); RefactoringStarter starter = new RefactoringStarter(); starter.activate(refactoringWizard, shell, actionName, RefactoringSaveHelper.SAVE_REFACTORING); } }
From source file:ext.org.eclipse.jdt.internal.corext.refactoring.RefactoringExecutionStarter.java
License:Open Source License
public static void startCutRefactoring(final Object[] elements, final Shell shell) throws InterruptedException, InvocationTargetException { JavaDeleteProcessor processor = new JavaDeleteProcessor(elements); processor.setSuggestGetterSetterDeletion(false); processor.setQueries(new ReorgQueries(shell)); Refactoring refactoring = new DeleteRefactoring(processor); int stopSeverity = RefactoringCore.getConditionCheckingFailedSeverity(); new RefactoringExecutionHelper(refactoring, stopSeverity, RefactoringSaveHelper.SAVE_NOTHING, shell, new ProgressMonitorDialog(shell)).perform(false, false); }