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:eu.udig.tools.internal.ui.util.DialogUtil.java
License:LGPL
public static void runsyncInDisplayThread(final String dialogTitle, final boolean showRunInBackground, final IRunnableWithProgress process, final boolean confirmCancelRequests) { Runnable object = new Runnable() { @Override//from w ww .ja v a2s.co m public void run() { Shell shell = Display.getDefault().getActiveShell(); ProgressMonitorDialog dialog = DialogUtil.openProgressMonitorDialog(shell, dialogTitle, showRunInBackground, confirmCancelRequests); try { dialog.run(true, true, new IRunnableWithProgress() { @Override public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { PlatformGISMediator.syncInDisplayThread(new Runnable() { @Override public void run() { try { process.run(monitor); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } catch (Exception e) { // TODO feedback to user is required e.printStackTrace(); } } }); } catch (Exception e) { // TODO feedback to user is required e.printStackTrace(); } } }; // if (runASync) // Display.getDefault().asyncExec(object); // TODO should be tested with this method // PlatformGISMediator.asyncInDisplayThread(object, false); // else PlatformGISMediator.syncInDisplayThread(object); }
From source file:ext.org.eclipse.jdt.internal.ui.refactoring.ChangeExceptionHandler.java
License:Open Source License
private void performUndo(final Change undo) { IWorkspaceRunnable runnable = new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { monitor.beginTask("", 11); //$NON-NLS-1$ try { undo.initializeValidationData( new NotCancelableProgressMonitor(new SubProgressMonitor(monitor, 1))); if (undo.isValid(new SubProgressMonitor(monitor, 1)).hasFatalError()) { monitor.done();//from ww w .j a va 2 s.co m return; } undo.perform(new SubProgressMonitor(monitor, 9)); } finally { undo.dispose(); } } }; WorkbenchRunnableAdapter adapter = new WorkbenchRunnableAdapter(runnable, ResourcesPlugin.getWorkspace().getRoot()); ProgressMonitorDialog dialog = new ProgressMonitorDialog(fParent); try { dialog.run(false, false, adapter); } catch (InvocationTargetException e) { ExceptionHandler.handle(e, fParent, RefactoringMessages.ChangeExceptionHandler_undo_dialog_title, RefactoringMessages.ChangeExceptionHandler_undo_dialog_message + fName); } catch (InterruptedException e) { // can't happen } }
From source file:fr.obeo.dsl.arduino.utils.ArduinoServices.java
License:Open Source License
public void upload(final Sketch sketch) { if (preferences.getArduinoSdk() == null || preferences.getArduinoSdk().length() == 0) { askUser();/* www . jav a2 s . c o m*/ return; } final ProgressMonitorDialog dialog = new ProgressMonitorDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); try { dialog.run(true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) { monitor.beginTask("Upload sketch to arduino platform...", 100); monitor.subTask("Generate code"); File genFolder = generateCode(sketch); monitor.worked(33); monitor.subTask("Compile code"); String arduinoSdk = preferences.getArduinoSdk(); String serialPort = preferences.getArduinoSerialPort(); String boardTag = sketch.getHardware().getPlatforms().get(0).getName(); String workingDirectory = genFolder.toString(); ArduinoBuilder builder = new ArduinoBuilder(arduinoSdk, boardTag, workingDirectory, serialPort); List<String> libraries = getLibraries(sketch); final IStatus compileStatus = builder.compile("Sketch", libraries); if (compileStatus.getSeverity() != IStatus.OK) { Display.getDefault().syncExec(new Runnable() { public void run() { MessageDialog.openError(dialog.getShell(), "Compilation Fail", "Compilation fail : " + compileStatus.getMessage()); } }); return; } monitor.worked(33); monitor.subTask("Upload code"); final IStatus uploadStatus = builder.upload(); if (uploadStatus.getSeverity() != IStatus.OK) { Display.getDefault().syncExec(new Runnable() { public void run() { MessageDialog.openError(dialog.getShell(), "Upload Fail", "Upload fail : " + uploadStatus.getMessage()); } }); } monitor.done(); } }); } catch (InvocationTargetException e) { ArduinoUiActivator.log(Status.ERROR, "Upload failed", e); } catch (InterruptedException e) { ArduinoUiActivator.log(Status.ERROR, "Upload failed", e); } }
From source file:goko.handlers.SaveHandler.java
License:Open Source License
@Execute public void execute(IEclipseContext context, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell, @Named(IServiceConstants.ACTIVE_PART) final MContribution contribution) throws InvocationTargetException, InterruptedException { final IEclipseContext pmContext = context.createChild(); ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell); dialog.open();// w ww. java 2s. c o m dialog.run(true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { pmContext.set(IProgressMonitor.class.getName(), monitor); if (contribution != null) { // Object clientObject = contribution.getObject(); // ContextInjectionFactory.invoke(clientObject, Persist.class, //$NON-NLS-1$ // pmContext, null); } } }); pmContext.dispose(); }
From source file:gov.nasa.ensemble.common.ui.WidgetUtils.java
License:Open Source License
/** * If not in the display thread, just run the runnable. * Otherwise, spawn a thread for the runnable and popup * a progress dialog box./*from w w w. j a va2 s . c o m*/ * * @param runnable * @return true if the runnable completed normally */ public static <T extends Exception, O extends Object> O avoidDisplayThread(GenericRunnable<T, O> runnable) throws T, OperationCanceledException { if (!WidgetUtils.inDisplayThread() || !WidgetUtils.isThereAWindow() || CommonPlugin.isJunitRunning()) { return runnable.run(); } IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); Shell shell = window.getShell(); ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell); OtherThreadRunnable<T, O> otherThreadRunnable = new OtherThreadRunnable<T, O>(runnable); try { dialog.run(true, true, otherThreadRunnable); } catch (InvocationTargetException e) { @SuppressWarnings("unchecked") T exception = (T) e.getCause(); throw exception; } catch (InterruptedException e) { throw new OperationCanceledException(); } return otherThreadRunnable.result; }
From source file:gov.redhawk.ide.codegen.ui.internal.command.GenerateCodeHandler.java
License:Open Source License
private void upgrade(Shell parent, final SoftPkg spd, final WaveDevSettings implSettings) throws CoreException { ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(parent); try {/*from www . j a va 2s. c om*/ progressDialog.run(true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { IComponentProjectUpgrader service = RedhawkCodegenUiActivator.getDefault() .getComponentProjectUpgraderService(); if (service != null) { service.upgrade(monitor, spd, implSettings); } else { throw new CoreException(new Status(Status.ERROR, RedhawkCodegenUiActivator.PLUGIN_ID, "Failed to find project upgrade service.", null)); } } catch (CoreException e) { throw new InvocationTargetException(e); } } }); } catch (InvocationTargetException e1) { if (e1.getCause() instanceof CoreException) { CoreException core = (CoreException) e1.getCause(); throw core; } else if (e1.getCause() instanceof OperationCanceledException) { throw new OperationCanceledException(); } else { Status status = new Status(Status.ERROR, RedhawkCodegenUiActivator.PLUGIN_ID, "Failed to update code generator.", e1.getCause()); throw new CoreException(status); } } catch (InterruptedException e1) { throw new OperationCanceledException(); } }
From source file:gov.redhawk.ide.codegen.ui.internal.command.GenerateCodeHandler.java
License:Open Source License
/** * Tries to save the resources which are in the same project as the editorFile provided. The user is prompted to * save// w w w .j ava 2 s . co m * if any related unsaved resources are present. * @param event Handler event * @param editorFile File who's project we are using to find related editor pages. * @return True if everything saved correctly. False otherwise. * @throws CoreException */ private boolean relatedResourcesSaved(final Shell shell, final IProject parentProject) throws CoreException { final Set<ISaveablePart> dirtyPartsSet = getRelatedDirtyParts(parentProject); // If there were unsaved parts in this project. if (!dirtyPartsSet.isEmpty()) { // Prompt the user that they MUST save before generation if (MessageDialog.openQuestion(shell, "File Changed", "Resources in the project '" + parentProject.getName() + "' have unsaved changes. Changes must be saved prior to code generation.\n\nDo you want to save these changes now?")) { ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell); try { dialog.run(false, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) { monitor.beginTask("Saving Resources ...", dirtyPartsSet.size()); // Go through and save each of the parts that were previously identified. for (ISaveablePart dirtyPart : dirtyPartsSet) { dirtyPart.doSave(monitor); monitor.worked(1); if (monitor.isCanceled()) { break; } } monitor.done(); } }); } catch (InvocationTargetException e) { throw new CoreException(new Status(Status.ERROR, RedhawkUiActivator.PLUGIN_ID, "Error while attempting to save editors", e.getCause())); } catch (InterruptedException e) { return false; // The user canceled this save dialog. } if (dialog.getProgressMonitor().isCanceled()) { return false; // The user has canceled another dialog which was passed our monitor. } return true; // User saved all unsaved parts with no errors, generate code. } // User canceled the save dialog do not generate return false; } // Resources don't need to be saved return true; }
From source file:gov.redhawk.ide.debug.internal.ui.diagram.LocalScaEditor.java
License:Open Source License
@SuppressWarnings("restriction") @Override/*from w w w . ja va 2 s.c o m*/ protected void setInput(IEditorInput input) { if (input instanceof ScaFileStoreEditorInput) { ScaFileStoreEditorInput scaInput = (ScaFileStoreEditorInput) input; if (scaInput.getScaObject() instanceof LocalScaWaveform) { this.waveform = (LocalScaWaveform) scaInput.getScaObject(); } else { throw new IllegalStateException( "Sandbox Editor opened on invalid sca input " + scaInput.getScaObject()); } } else if (input instanceof URIEditorInput) { URIEditorInput uriInput = (URIEditorInput) input; if (uriInput.getURI().equals(ScaDebugInstance.getLocalSandboxWaveformURI())) { final LocalSca localSca = ScaDebugPlugin.getInstance().getLocalSca(); if (!ScaDebugInstance.INSTANCE.isInit()) { ProgressMonitorDialog dialog = new ProgressMonitorDialog(Display.getCurrent().getActiveShell()); try { dialog.run(true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Starting Chalkboard...", IProgressMonitor.UNKNOWN); try { ScaDebugInstance.INSTANCE.init(monitor); } catch (CoreException e) { throw new InvocationTargetException(e); } monitor.done(); } }); } catch (InvocationTargetException e1) { StatusManager.getManager().handle( new Status(Status.ERROR, ScaDebugPlugin.ID, "Failed to initialize sandbox.", e1), StatusManager.SHOW | StatusManager.LOG); } catch (InterruptedException e1) { // PASS } } this.waveform = localSca.getSandboxWaveform(); if (waveform == null) { ProgressMonitorDialog dialog = new ProgressMonitorDialog(Display.getCurrent().getActiveShell()); try { dialog.run(true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Starting Sandbox...", IProgressMonitor.UNKNOWN); try { ScaDebugPlugin.getInstance().getLocalSca(monitor); } catch (CoreException e) { throw new InvocationTargetException(e); } } }); } catch (InvocationTargetException e) { throw new IllegalStateException("Failed to setup sandbox", e); } catch (InterruptedException e) { throw new IllegalStateException("Sandbox setup canceled, can not load editor."); } this.waveform = localSca.getSandboxWaveform(); if (waveform == null) { throw new IllegalStateException("Failed to setup sandbox, null waveform.", null); } } } } else { throw new IllegalStateException("Sandbox Editor opened on invalid input " + input); } if (ScaDebugPlugin.getInstance().getLocalSca().getSandboxWaveform() == waveform || this.waveform == null) { isLocalSca = true; } super.setInput(input); }
From source file:gov.redhawk.ide.debug.internal.ui.diagram.LocalScaEditor.java
License:Open Source License
private void initModelMap() { if (waveform == null) { throw new IllegalStateException("Can not initialize the Model Map with null local waveform"); }/*w ww. java 2 s. c o m*/ if (sad == null) { throw new IllegalStateException("Can not initialize the Model Map with null sad"); } if (!waveform.isSetComponents()) { if (Display.getCurrent() != null) { ProgressMonitorDialog dialog = new ProgressMonitorDialog(Display.getCurrent().getActiveShell()); try { dialog.run(true, true, new IRunnableWithProgress() { @Override public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { CorbaUtils.invoke(new Callable<Object>() { @Override public Object call() throws Exception { waveform.refresh(monitor, RefreshDepth.FULL); return null; } }, monitor); } catch (CoreException e) { throw new InvocationTargetException(e); } } }); } catch (InvocationTargetException e) { // PASS } catch (InterruptedException e) { // PASS } } else { try { waveform.refresh(null, RefreshDepth.FULL); } catch (InterruptedException e) { // PASS } } } final ModelMap modelMap = new ModelMap(this, sad, waveform); if (isLocalSca) { // Use the SCA Model are source to build the SAD when we are in the chalkboard since the SAD file isn't // modified getEditingDomain().getCommandStack().execute(new SadModelInitializerCommand(modelMap, sad, waveform)); } else { // Use the existing SAD file as a template when initializing the modeling map getEditingDomain().getCommandStack().execute(new ModelMapInitializerCommand(modelMap, sad, waveform)); } getEditingDomain().getCommandStack().flush(); this.sadlistener = new SadModelAdapter(modelMap); this.scaListener = new ScaModelAdapter(modelMap) { @Override public void notifyChanged(Notification notification) { super.notifyChanged(notification); if (notification.getNotifier() == waveform) { if (waveform.isDisposed() && !isDisposed()) { getEditorSite().getPage().getWorkbenchWindow().getWorkbench().getDisplay() .asyncExec(new Runnable() { @Override public void run() { if (!isDisposed()) { getEditorSite().getPage().closeEditor(LocalScaEditor.this, false); } } }); } } } }; ScaModelCommand.execute(this.waveform, new ScaModelCommand() { @Override public void execute() { scaListener.addAdapter(waveform); } }); sad.eAdapters().add(this.sadlistener); if (LocalScaEditor.DEBUG.enabled) { try { sad.eResource().save(null); } catch (final IOException e) { LocalScaEditor.DEBUG.catching("Failed to save local diagram.", e); } } }
From source file:gov.redhawk.ide.internal.ui.templates.handlers.NewControlPanelProject.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { ProgressMonitorDialog dialog = new ProgressMonitorDialog(HandlerUtil.getActiveShell(event)); final IEditorPart editor = HandlerUtil.getActiveEditor(event); EObject eObj = null;/*from w w w . j a v a2 s . co m*/ String name = null; if (editor != null) { if (editor instanceof SCAFormEditor) { SCAFormEditor scaEditor = (SCAFormEditor) editor; Resource resource = scaEditor.getMainResource(); if (resource instanceof SpdResourceImpl) { SoftPkg spd = SoftPkg.Util.getSoftPkg(resource); name = spd.getName(); eObj = spd; } else if (resource instanceof SadResourceImpl) { SoftwareAssembly sad = SoftwareAssembly.Util.getSoftwareAssembly(resource); name = sad.getName(); eObj = sad; } else if (resource instanceof DcdResourceImpl) { DeviceConfiguration dcd = DeviceConfiguration.Util.getDeviceConfiguration(resource); name = dcd.getName(); eObj = dcd; } } } if (eObj == null) { return null; } IProject spdProject = ModelUtil.getProject(eObj); String baseName = null; if (spdProject != null) { baseName = spdProject.getName(); } else { if (name != null) { baseName = ScaTemplateSection.makeNameSafe(name); } } String tmpProjectName = baseName + ".ui"; IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(tmpProjectName); if (project.exists()) { InputDialog inputDialog = new InputDialog(HandlerUtil.getActiveShell(event), "Name Conflict", "Enter a name for the project:", baseName + "2.ui", new IInputValidator() { @Override public String isValid(String newText) { if (newText.trim().isEmpty()) { return "Must enter a value."; } else if (ResourcesPlugin.getWorkspace().getRoot().getProject(newText).exists()) { return "Project '" + newText + "' already exists."; } return null; } }); if (inputDialog.open() == Window.OK) { tmpProjectName = inputDialog.getValue(); } else { return null; } } final String projectName = tmpProjectName; final String pluginName = name; ResourceControlPanelWizard contentWizard = new ResourceControlPanelWizard(); contentWizard.setResource(eObj); ResourceControlPanelTemplateSection resourceTemplate = contentWizard .getResourceControlPanelTemplateSection(); String packageName = ScaTemplateSection.makeNameSafe(projectName).toLowerCase(Locale.ENGLISH); PluginFieldData fPluginData = new PluginFieldData(); updateData(fPluginData, pluginName, projectName, packageName); IProjectProvider fProjectProvider = new IProjectProvider() { @Override public String getProjectName() { return projectName; } @Override public IProject getProject() { return ResourcesPlugin.getWorkspace().getRoot().getProject(getProjectName()); } @Override public IPath getLocationPath() { // return null for in workspace return null; } }; try { dialog.run(false, true, new NewProjectCreationOperation(fPluginData, fProjectProvider, contentWizard)); final IFile file = project.getFile(new Path("src/" + packageName.replace(".", "/") + "/" + resourceTemplate.getCompositeClassName() + ".java")); final IWorkbenchWindow ww = HandlerUtil.getActiveWorkbenchWindow(event); final IWorkbenchPage page = ww.getActivePage(); IWorkbenchPart focusPart = page.getActivePart(); if (focusPart instanceof ISetSelectionTarget) { ISelection selection = new StructuredSelection(file); ((ISetSelectionTarget) focusPart).selectReveal(selection); } try { try { file.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); } catch (CoreException e) { StatusManager.getManager().handle(e, TemplatesActivator.getPluginId()); } IDE.openEditor(page, file, true); } catch (PartInitException e) { StatusManager.getManager().handle(new Status(IStatus.ERROR, TemplatesActivator.getPluginId(), "Failed to open Control Panel Project editor", e)); } } catch (InvocationTargetException e) { StatusManager.getManager().handle(new Status(IStatus.ERROR, TemplatesActivator.getPluginId(), "Failed to generate Control Panel Project.", e.getCause())); } catch (InterruptedException e) { // PASS } return null; }