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:de.quamoco.qm.editor.export.ImportExportActionBase.java
License:Apache License
/** Perform a long-running task on a file. */ private boolean process(final String fileName) { ProgressMonitorDialog dialog = new ProgressMonitorDialog(Display.getDefault().getActiveShell()); try {//from ww w . j av a 2 s . c o m dialog.run(true, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException { doProcess(fileName, monitor); } }); return true; } catch (InvocationTargetException e) { LoggingUtils.error(QmEditorPlugin.getPlugin(), "Error during export", e); MessageDialog.openError(Display.getDefault().getActiveShell(), "Error during export", e.getCause().getMessage()); } catch (InterruptedException e) { LoggingUtils.error(QmEditorPlugin.getPlugin(), "Interruption during export", e); MessageDialog.openError(Display.getDefault().getActiveShell(), "Interruption during export", e.getMessage()); } return false; }
From source file:de.rowlo.diffeclipse.event.ButtonExtractMissingExtensionsHandler.java
License:Open Source License
protected void extractSelectedElements(IStructuredSelection selection) { final Text text = getTargetLocationText(); if (selection != null && text != null) { final String sourceLocation = DiffEclipseUtil.INSTANCE.getExtendedEclipseLocation(); final String targetLocation = text.getText(); final String dropStructure = File.separator + "additionalExtensions" + File.separator + "eclipse"; final List<?> selectedElements = selection.toList(); final int size = count(selectedElements); final ArrayList<Integer> counterResult = new ArrayList<Integer>(1); Shell shell = text.getShell();//ww w . jav a2 s .c o m try { ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(shell); progressMonitorDialog.run(true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { String taskMsg = MessageFormat.format("Extracting Missing Extensions to: {0}", targetLocation + dropStructure); monitor.beginTask(taskMsg, size); totalCounter = 0; processElements(selectedElements, monitor); counterResult.clear(); counterResult.add(totalCounter); monitor.done(); if (monitor.isCanceled()) { throw new InterruptedException("The long extraction was cancelled"); } } private void processElements(List<?> selectedElements, IProgressMonitor monitor) { if (selectedElements == null || monitor == null) { return; } for (Object selectedElement : selectedElements) { if (selectedElement instanceof TreeModel) { TreeModel treeModel = (TreeModel) selectedElement; String filePath = treeModel.getFilePath(); String sourceFilePath = sourceLocation + filePath; String targetFilePath = targetLocation + dropStructure + filePath; if (treeModel.isFile()) { copyFile(sourceFilePath, targetFilePath); } else { createDirectory(targetFilePath); ArrayList<Object> childElements = new ArrayList<Object>(treeModel.children); processElements(childElements, monitor); } totalCounter++; monitor.worked(1); String taskMsg = MessageFormat.format( "Extracting Missing Extensions to: {0} ({1}/{2})", targetLocation + dropStructure, totalCounter, size); monitor.setTaskName(taskMsg); } } } }); } catch (InvocationTargetException e) { MessageDialog.openError(shell, "Error", e.getMessage()); } catch (InterruptedException e) { MessageDialog.openInformation(shell, "Cancelled", e.getMessage()); } int counter = counterResult.size() > 0 ? counterResult.get(0) : 0; String msg = MessageFormat.format("Extracted {1} extensions to: {0}", targetLocation + dropStructure, counter); MessageDialog.openInformation(shell, "Extract Missing Extensions", msg); } }
From source file:de.thischwa.pmcms.gui.dialog.DialogManager.java
License:LGPL
/** * Open the progress dialog and run a {@link IProgressViewer}. *//* ww w.j a v a 2 s . com*/ public static void startProgressDialog(final Shell parentShell, final IProgressViewer progressViewer) { IRunnableWithProgress runnableWithProgress = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { progressViewer.setMonitor(monitor); try { progressViewer.run(); } catch (Exception e) { logger.error("While IProgressViewer was running: " + e.getMessage(), e); throw new ProgressException(e); } } }; ProgressMonitorDialog dialog = new ProgressMonitorDialog(parentShell); try { dialog.run(true, true, runnableWithProgress); } catch (Exception e) { throw new FatalException(e.getCause().getMessage(), e.getCause()); } }
From source file:de.topicmapslab.onotoa.search.handler.AbstractUseFinderHandler.java
License:Open Source License
/** * @param shell/*from ww w .j a va 2 s .c o m*/ * @param tt */ protected void startSearch(Shell shell, TopicType tt) { ProgressMonitorDialog dlg = new ProgressMonitorDialog(shell); try { FindRunnable runnable = new FindRunnable(tt); dlg.run(false, false, runnable); ResultDialog resultDlg = new ResultDialog(shell, tt); resultDlg.setInput(runnable.getResult()); resultDlg.open(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:de.topicmapslab.tmcledit.tmclimport.wizards.ImportWizard.java
License:Open Source License
public boolean performFinish() { ProgressMonitorDialog monitorDlg = new ProgressMonitorDialog(getShell()); monitorDlg.setCancelable(false);/*from w w w .j a v a 2 s. c om*/ try { monitorDlg.run(false, false, new LoaderRunnable()); } catch (Exception e) { Activator.logException(e); MessageDialog.openError(getShell(), "Error while importing schema", "An error occurred:" + e.getMessage() + "[" + e.getClass().getName() + "]"); } return true; }
From source file:de.tub.tfs.muvitor.ui.MuvitorTreeEditor.java
License:Open Source License
/** * This method will create an {@link EMFModelManager} that handles loading * and saving to the file the passed {@link IEditorInput} relies on. If * loading fails (possibly because we created a file with the creation * wizard) we create a new default model and put it to the file resource. * /* w w w . j a v a 2 s . c o m*/ * @see #createDefaultModel() * @see org.eclipse.ui.part.EditorPart#setInput(org.eclipse.ui.IEditorInput) */ @Override protected void setInput(final IEditorInput input) { super.setInput(input); final IFile file = ((IFileEditorInput) input).getFile(); setPartName(file.getName()); setContentDescription(file.getName()); /* * This must be called before trying to load the model, so that the EMF * package has been initialized. */ final List<EObject> defaultModels = createDefaultModels(); for (final EObject defaultModel : defaultModels) { defaultModel.eClass().getEPackage(); } ProgressMonitorDialog dialog = new ProgressMonitorDialog(Display.getCurrent().getActiveShell()); try { dialog.run(false, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { int lines = 0; try { BufferedReader r = new BufferedReader(new FileReader(file.getRawLocation().toFile())); while (r.ready()) { r.readLine(); lines++; } } catch (FileNotFoundException e) { lines = -1; } catch (IOException e) { lines = -1; } modelManager.setMonitor(monitor); monitor.beginTask("loading Ecore Model", lines); Thread t = new Thread() { @Override public void run() { modelRoots = new ArrayList<EObject>( modelManager.load(file.getFullPath(), defaultModels)); super.run(); } }; t.start(); while (t.isAlive()) { if (!Display.getCurrent().readAndDispatch()) Thread.sleep(20); } if (modelRoots == null || modelRoots.isEmpty()) { MuvitorActivator.logError( "The loaded or created model is corrupt and no default model could be created!", null); } // register the root model ID with the editor in the IDUtil IDUtil.registerEditor(MuvitorTreeEditor.this); monitor.done(); } }); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:de.tukl.cs.softech.agilereview.views.reviewexplorer.handler.CleanupHandler.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveMenuSelection(event); Object firstElement = selection.getFirstElement(); if (firstElement instanceof MultipleReviewWrapper) { MultipleReviewWrapper reviewWrapper = ((MultipleReviewWrapper) firstElement); if (!checkReviewOpen(event, reviewWrapper)) { return null; }// ww w. j a va2s. c o m // ask user whether to delete comments and tags or only tags boolean deleteComments = true; MessageBox messageDialog = new MessageBox(HandlerUtil.getActiveShell(event), SWT.ICON_QUESTION | SWT.YES | SWT.NO | SWT.CANCEL); messageDialog.setText("AgileReview Cleanup"); messageDialog.setMessage("Delete comments? Otherwise they will be converted to global comments!"); int result = messageDialog.open(); if (result == SWT.CANCEL) { // cancel selected -> quit method return null; } else if (result == SWT.NO) { deleteComments = false; } // get selected project try { ProgressMonitorDialog pmd = new ProgressMonitorDialog(HandlerUtil.getActiveShell(event)); pmd.open(); pmd.run(true, false, new CleanupProcess(reviewWrapper.getWrappedReview(), deleteComments)); pmd.close(); } catch (InvocationTargetException e) { PluginLogger.logError(this.getClass().toString(), "execute", "InvocationTargetException", e); MessageDialog.openError(HandlerUtil.getActiveShell(event), "Error while performing cleanup", "An Eclipse internal error occured!\nRetry and please report the bug to the AgileReview team when it occurs again.\nCode:1"); } catch (InterruptedException e) { PluginLogger.logError(this.getClass().toString(), "execute", "InterruptedException", e); MessageDialog.openError(HandlerUtil.getActiveShell(event), "Error while performing cleanup", "An Eclipse internal error occured!\nRetry and please report the bug to the AgileReview team when it occurs again.\nCode:2"); } } if (ViewControl.isOpen(CommentTableView.class)) { CommentTableView.getInstance().reparseAllEditors(); } ViewControl.refreshViews(ViewControl.COMMMENT_TABLE_VIEW | ViewControl.REVIEW_EXPLORER, true); return null; }
From source file:de.unistuttgart.ipvs.pmp.editor.ui.editors.internals.ServerProviderDialogWrapper.java
License:Apache License
/** * Updates the {@link RGIS} list from the server, while downloading a {@link ProgressMonitorDialog} is displayed * //from ww w . j a va 2s . c om * @param shell * {@link Shell} to display the {@link ProgressMonitorDialog} */ public void updateServerListWithDialog(final Shell shell) { // Create the dialog ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell); try { // Run the dialog, not cancelable because the timeout is set to 1000 dialog.run(true, false, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { // Start the task monitor.beginTask(I18N.general_rgdownloaddialog_task, 2); ServerProvider server = ServerProvider.getInstance(); try { // Refresh the list server.updateResourceGroupList(); monitor.worked(1); ServerProviderDialogWrapper.this.rgisList = server.getAvailableRessourceGroups(); monitor.done(); } catch (final IOException e) { // Show the error message in an asyncExectuable Display.getDefault().asyncExec(new Thread(new Runnable() { @Override public void run() { IStatus status = new Status(IStatus.ERROR, "PROGRESS_DIALOG", //$NON-NLS-1$ I18N.general_seedetails, e); ErrorDialog.openError(shell, I18N.general_rgdownloaddialog_downloaderror_title, I18N.general_rgdownloaddialog_downloaderror_text, status); } })); } } }); } catch (InvocationTargetException e) { IStatus status = new Status(IStatus.ERROR, "PROGRESS_DIALOG", I18N.general_seedetails, e); //$NON-NLS-1$ ErrorDialog.openError(shell, I18N.general_rgdownloaddialog_downloaderror_title, I18N.general_rgdownloaddialog_downloaderror_text, status); } catch (InterruptedException e) { IStatus status = new Status(IStatus.ERROR, "PROGRESS_DIALOG", I18N.general_seedetails, e); //$NON-NLS-1$ ErrorDialog.openError(shell, I18N.general_rgdownloaddialog_downloaderror_title, I18N.general_rgdownloaddialog_downloaderror_text, status); } }
From source file:de.uni_hildesheim.sse.qmApp.editors.ClassEditor.java
License:Apache License
/** * Create progress Dialog.//from w w w . j a v a 2 s.co m * * @param parent parent composite. * @param artifact The artifacts name. * @param isHardware If true only the master artifact will be downloaded and information from manifest * will be used. */ public static void createProgressDialog(Composite parent, String artifact, boolean isHardware) { try { ProgressMonitorDialog pmd = new ProgressMonitorDialog(parent.getShell()) { @Override protected void setShellStyle(int newShellStyle) { super.setShellStyle(SWT.CLOSE | SWT.INDETERMINATE | SWT.BORDER | SWT.TITLE); setBlockOnOpen(false); } }; ProgressDialogOperation pdo = new ProgressDialogOperation(); pdo.artifact = artifact; pdo.isHardware = isHardware; pmd.run(true, true, pdo); } catch (final InvocationTargetException e) { Throwable exc = e; if (null != e.getCause()) { exc = e.getCause(); } MessageDialog.openError(parent.getShell(), "Error", "Error: " + exc.getMessage()); e.printStackTrace(); } catch (final InterruptedException e) { MessageDialog.openInformation(parent.getShell(), "Cancelled", "Error: "); e.printStackTrace(); } }
From source file:descent.internal.ui.wizards.buildpaths.VariableBlock.java
License:Open Source License
public boolean performOk() { ArrayList removedVariables = new ArrayList(); ArrayList changedVariables = new ArrayList(); removedVariables.addAll(Arrays.asList(JavaCore.getClasspathVariableNames())); // remove all unchanged List changedElements = fVariablesList.getElements(); for (int i = changedElements.size() - 1; i >= 0; i--) { CPVariableElement curr = (CPVariableElement) changedElements.get(i); if (curr.isReserved()) { changedElements.remove(curr); } else {/* ww w . j a v a 2 s. co m*/ IPath path = curr.getPath(); IPath prevPath = JavaCore.getClasspathVariable(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; }