List of usage examples for org.eclipse.jface.dialogs ProgressMonitorDialog getShell
@Override
public Shell getShell()
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();//from w w w .j a v a 2s. co 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:net.refractions.udig.ui.ShutdownTaskList.java
License:Open Source License
public void postShutdown(final IWorkbench workbench) { try {//from w w w. j a va2 s . c o m final ProgressMonitorDialog dialog = getDialog(workbench); dialog.run(true, false, new IRunnableWithProgress() { public void run(IProgressMonitor monitor2) throws InvocationTargetException, InterruptedException { OffThreadProgressMonitor monitor = new OffThreadProgressMonitor(monitor2, dialog.getShell().getDisplay()); int totalsteps = 0; for (PostTask task : postShutdownTasks) { try { task.steps = task.task.getProgressMonitorSteps(); totalsteps += task.steps; } catch (Throwable e) { UiPlugin.log("error calling getProgressMonitorSteps() on " + task.task, e); //$NON-NLS-1$ } } monitor.beginTask(Messages.ShutdownTaskList_shutDown, totalsteps); for (PostTask task : postShutdownTasks) { IProgressMonitor subMonitor = new ProgressMonitorTaskNamer(monitor, task.steps); try { task.task.postShutdown(subMonitor, workbench); } catch (Throwable t) { task.task.handlePostShutdownException(t); } finally { subMonitor.done(); } } } }); } catch (InvocationTargetException e) { throw (RuntimeException) new RuntimeException().initCause(e); } catch (InterruptedException e) { throw (RuntimeException) new RuntimeException().initCause(e); } }
From source file:org.eclipse.birt.chart.integration.wtp.ui.internal.actions.ImportChartRuntimeAction.java
License:Open Source License
/** * action to import birt runtime component * // w ww. j a v a2 s .c o m * @param window * @param isClear * @throws Exception */ protected void doImport(IWorkbenchWindow window, boolean isClear) throws Exception { ProgressMonitorDialog monitor = null; try { // web content folder IPath webContentPath = BirtWizardUtil.getWebContentPath(project); // do import birt runtime monitor = new ProgressMonitorDialog(window.getShell()); monitor.open(); // check whether clears the old birt runtime files if (isClear) doClearAction(webContentPath, monitor.getProgressMonitor()); // import birt runtime component BirtWizardUtil.doImports(project, null, webContentPath, monitor.getProgressMonitor(), new ImportOverwriteQuery(monitor.getShell())); // process defined folders BirtWizardUtil.processCheckFolder(properties, project, webContentPath.toFile().getName(), monitor.getProgressMonitor()); // configurate web.xml processConfiguration(monitor.getProgressMonitor(), monitor.getShell()); } finally { // closs dialog if (monitor != null) { monitor.close(); } } }
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 www. j av a 2 s .co 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.jface.snippets.dialogs.Snippet058VistaProgressBars.java
License:Open Source License
private static IRunnableWithProgress createRunnableFor(final ProgressMonitorDialog dialog) { return monitor -> { IProgressMonitorWithBlocking blocking = (IProgressMonitorWithBlocking) monitor; blocking.beginTask("Vista Coolness", 100); for (int i = 0; i < 10; i++) { blocking.setBlocked(new Status(IStatus.WARNING, "Blocked", "This is blocked on Vista")); blocking.worked(5);//from w w w .ja v a2s. co m spin(dialog.getShell().getDisplay()); blocking.clearBlocked(); blocking.worked(5); spin(dialog.getShell().getDisplay()); if (monitor.isCanceled()) return; } blocking.done(); }; }
From source file:org.eclipse.rcptt.ui.report.internal.RcpttReportEditor.java
License:Open Source License
public void openReport(final String id, final String title) { final ProgressMonitorDialog dialog = new ProgressMonitorDialog(getSite().getShell()); try {//w w w. ja v a2 s .c o m final Q7ReportIterator reportList = (Q7ReportIterator) reportListObservable.getValue(); if (reportList == null) return; dialog.run(true, false, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Opening report...", IProgressMonitor.UNKNOWN); Iterator<Report> iterator = reportList.iterator(); while (iterator.hasNext()) { monitor.worked(1); final Report next = iterator.next(); Node root = next.getRoot(); EMap<String, EObject> properties = root.getProperties(); final Q7Info info = (Q7Info) properties.get(IQ7ReportConstants.ROOT); if (info != null) { if (info.getId().equals(id)) { dialog.getShell().getDisplay().asyncExec(new Runnable() { public void run() { openReportPage(id, title, next, info); } }); return; } } } monitor.done(); } }); } catch (Throwable e) { Q7UIReportPlugin.log(e); } }
From source file:org.eclipse.tcf.te.tcf.filesystem.ui.internal.operations.UiExecutor.java
License:Open Source License
public static IStatus execute(final IOperation operation) { final Display display = Display.getCurrent(); Assert.isNotNull(display);// www . j a v a 2 s . c o m final Shell parent = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); final ProgressMonitorDialog dlg = new ProgressMonitorDialog(parent); dlg.setOpenOnRun(false); display.timerExec(500, new Runnable() { @Override public void run() { Shell shell = dlg.getShell(); if (shell != null && !shell.isDisposed()) { Shell activeShell = display.getActiveShell(); if (activeShell == null || activeShell == parent) { dlg.open(); } else { display.timerExec(500, this); } } } }); final AtomicReference<IStatus> ref = new AtomicReference<IStatus>(); try { dlg.run(true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) { ref.set(operation.run(monitor)); } }); } catch (InvocationTargetException e) { ref.set(StatusHelper.getStatus(e.getTargetException())); } catch (InterruptedException e) { return Status.CANCEL_STATUS; } IStatus status = ref.get(); if (!status.isOK() && status.getMessage().length() > 0) { ErrorDialog.openError(parent, operation.getName(), Messages.UiExecutor_errorRunningOperation, status); UIPlugin.getDefault().getLog().log(status); } return status; }
From source file:org.eclipse.team.internal.ccvs.ui.repo.CVSRepositoryPropertiesPage.java
License:Open Source License
private boolean performConnectionInfoChanges() { // Set the caching mode of the location if (!connectionInfoChanged) { location.setAllowCaching(allowCaching); if (!passwordChanged) { ((CVSRepositoryLocation) location).updateCache(); }/* www. j av a 2s. c o m*/ } // Don't do anything else if there wasn't a password or connection change if (!passwordChanged && !connectionInfoChanged) return true; try { // Check if the password was the only thing to change. if (passwordChanged && !connectionInfoChanged) { CVSRepositoryLocation oldLocation = (CVSRepositoryLocation) location; oldLocation.setPassword(getNewPassword()); if (allowCaching) { oldLocation.updateCache(); } passwordChanged = false; return true; } // Otherwise change the connection info and the password // This operation is done inside a workspace operation in case the sharing // info for existing projects is changed if (!(location.getHost().equals(hostText.getText()) && location.getRootDirectory().equals(pathText.getText()))) { // The host or path has changed if (!MessageDialog.openConfirm(getShell(), CVSUIMessages.CVSRepositoryPropertiesPage_0, CVSUIMessages.CVSRepositoryPropertiesPage_1)) { return false; } } final boolean[] result = new boolean[] { false }; final ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog(getShell()); progressMonitorDialog.run(false, false, new WorkspaceModifyOperation(null) { public void execute(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { // Create a new repository location with the new information CVSRepositoryLocation newLocation = CVSRepositoryLocation .fromProperties(createProperties()); newLocation.setEncoding(location.getEncoding()); location.setAllowCaching(allowCaching); try { // For each project shared with the old location, set connection info to the new one List projects = new ArrayList(); IProject[] allProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); for (int i = 0; i < allProjects.length; i++) { RepositoryProvider teamProvider = RepositoryProvider.getProvider(allProjects[i], CVSProviderPlugin.getTypeId()); if (teamProvider != null) { CVSTeamProvider cvsProvider = (CVSTeamProvider) teamProvider; if (cvsProvider.getCVSWorkspaceRoot().getRemoteLocation().equals(location)) { projects.add(allProjects[i]); } } } if (projects.size() > 0) { // To do: warn the user DetailsDialogWithProjects dialog = new DetailsDialogWithProjects( progressMonitorDialog.getShell(), CVSUIMessages.CVSRepositoryPropertiesPage_Confirm_Project_Sharing_Changes_1, CVSUIMessages.CVSRepositoryPropertiesPage_There_are_projects_in_the_workspace_shared_with_this_repository_2, NLS.bind(CVSUIMessages.CVSRepositoryPropertiesPage_sharedProject, new String[] { location.toString() }), (IProject[]) projects.toArray(new IProject[projects.size()]), true, Dialog.DLG_IMG_WARNING); int r = dialog.open(); if (r != Window.OK) { result[0] = false; return; } monitor.beginTask(null, 1000 * projects.size()); try { Iterator it = projects.iterator(); while (it.hasNext()) { IProject project = (IProject) it.next(); RepositoryProvider teamProvider = RepositoryProvider.getProvider(project, CVSProviderPlugin.getTypeId()); CVSTeamProvider cvsProvider = (CVSTeamProvider) teamProvider; cvsProvider.setRemoteRoot(newLocation, Policy.subMonitorFor(monitor, 1000)); } } finally { monitor.done(); } } // Dispose the old repository location CVSUIPlugin.getPlugin().getRepositoryManager().replaceRepositoryLocation(location, newLocation); } finally { // Even if we failed, ensure that the new location appears in the repo view. newLocation = (CVSRepositoryLocation) KnownRepositories.getInstance().addRepository( newLocation, !KnownRepositories.getInstance().isKnownRepository(newLocation.getLocation())); } // Set the location of the page to the new location in case Apply was chosen location = newLocation; connectionInfoChanged = false; passwordChanged = false; } catch (TeamException e) { throw new InvocationTargetException(e); } result[0] = true; } }); return result[0]; } catch (InvocationTargetException e) { handle(e); } catch (InterruptedException e) { } return false; /* we only get here if an exception occurred */ }
From source file:org.eclipse.ui.tests.concurrency.TestBug269121.java
License:Open Source License
public void testBug() throws InterruptedException, InvocationTargetException { Job job = new UIJob("UI job") { @Override//from w w w. jav a 2 s .c o m public IStatus runInUIThread(IProgressMonitor monitor) { return Status.OK_STATUS; }; }; job.setRule(ResourcesPlugin.getWorkspace().getRoot()); final int[] status = new int[] { -1 }; WorkspaceModifyOperation operation = new WorkspaceModifyOperation() { @Override protected void execute(IProgressMonitor monitor) { status[0] = TestBarrier.STATUS_DONE; } }; final ProgressMonitorDialog dialog = new ProgressMonitorDialog(new Shell()); Job statusJob = new Job("Checking for deadlock") { @Override protected IStatus run(IProgressMonitor monitor) { try { TestBarrier.waitForStatus(status, TestBarrier.STATUS_DONE); return Status.OK_STATUS; } catch (AssertionFailedError e) { // syncExecs are processed by // UILockListener.aboutToWait(Thread) without running the // event loop so we can cancel the dialog to stop the test dialog.getShell().getDisplay().syncExec(new Runnable() { @Override public void run() { dialog.getProgressMonitor().setCanceled(true); } }); return Status.CANCEL_STATUS; } } }; job.schedule(); statusJob.schedule(); try { dialog.run(false, true, operation); } catch (InterruptedException e) { // expected if operation was cancelled } statusJob.join(); // run the event loop until the UI job is finished while (job.getResult() == null) { Display.getCurrent().readAndDispatch(); } job.join(); assertTrue("Deadlock occurred", statusJob.getResult().isOK()); }
From source file:org.eclipse.wst.server.ui.internal.RuntimePreferencePage.java
License:Open Source License
/** * Create the preference options.//from w ww .ja v a 2 s .c o m * * @param parent org.eclipse.swt.widgets.Composite * @return org.eclipse.swt.widgets.Control */ protected Control createContents(Composite parent) { initializeDialogUnits(parent); PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, ContextIds.PREF_GENERAL); Composite composite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.horizontalSpacing = convertHorizontalDLUsToPixels(4); layout.verticalSpacing = convertVerticalDLUsToPixels(3); layout.marginWidth = 0; layout.marginHeight = 0; layout.numColumns = 2; composite.setLayout(layout); GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL); composite.setLayoutData(data); Label label = new Label(composite, SWT.WRAP); data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); data.horizontalSpan = 2; label.setLayoutData(data); label.setText(Messages.preferenceRuntimesDescription); label = new Label(composite, SWT.WRAP); data = new GridData(GridData.HORIZONTAL_ALIGN_FILL); data.horizontalSpan = 2; data.verticalIndent = 5; label.setLayoutData(data); label.setText(Messages.preferenceRuntimesTable); runtimeComp = new RuntimeComposite(composite, SWT.NONE, new RuntimeComposite.RuntimeSelectionListener() { public void runtimeSelected(IRuntime runtime) { if (runtime == null) { edit.setEnabled(false); remove.setEnabled(false); pathLabel.setText(""); } else { IStatus status = runtime.validate(new NullProgressMonitor()); if (status != null && status.getSeverity() == IStatus.ERROR) { Color c = pathLabel.getDisplay().getSystemColor(SWT.COLOR_RED); pathLabel.setForeground(c); pathLabel.setText(status.getMessage()); } else if (runtime.getLocation() != null) { pathLabel.setForeground(edit.getForeground()); pathLabel.setText(runtime.getLocation() + ""); } else pathLabel.setText(""); if (runtime.isReadOnly()) { edit.setEnabled(false); remove.setEnabled(false); } else { if (runtime.getRuntimeType() != null) edit.setEnabled(ServerUIPlugin.hasWizardFragment(runtime.getRuntimeType().getId())); else edit.setEnabled(false); remove.setEnabled(true); } } } }); runtimeComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL)); Composite buttonComp = new Composite(composite, SWT.NONE); layout = new GridLayout(); layout.horizontalSpacing = 0; layout.verticalSpacing = convertVerticalDLUsToPixels(3); layout.marginWidth = 0; layout.marginHeight = 0; layout.numColumns = 1; buttonComp.setLayout(layout); data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL); buttonComp.setLayoutData(data); Button add = SWTUtil.createButton(buttonComp, Messages.add); final RuntimeComposite runtimeComp2 = runtimeComp; add.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { if (showWizard(null) == Window.CANCEL) return; runtimeComp2.refresh(); } }); edit = SWTUtil.createButton(buttonComp, Messages.edit); edit.setEnabled(false); edit.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { IRuntime runtime = runtimeComp2.getSelectedRuntime(); if (runtime != null) { IRuntimeWorkingCopy runtimeWorkingCopy = runtime.createWorkingCopy(); if (showWizard(runtimeWorkingCopy) != Window.CANCEL) { try { runtimeComp2.refresh(runtime); } catch (Exception ex) { // ignore } } } } }); remove = SWTUtil.createButton(buttonComp, Messages.remove); remove.setEnabled(false); remove.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { IRuntime runtime = runtimeComp.getSelectedRuntime(); if (removeRuntime(runtime)) runtimeComp2.remove(runtime); } }); Button search = SWTUtil.createButton(buttonComp, Messages.search); data = (GridData) search.getLayoutData(); data.verticalIndent = 9; search.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { try { // select a target directory for the search DirectoryDialog directoryDialog = new DirectoryDialog(getShell()); directoryDialog.setMessage(Messages.dialogRuntimeSearchMessage); directoryDialog.setText(Messages.dialogRuntimeSearchTitle); String pathStr = directoryDialog.open(); if (pathStr == null) return; final IPath path = new Path(pathStr); final ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell()); dialog.setBlockOnOpen(false); dialog.setCancelable(true); dialog.open(); final IProgressMonitor monitor = dialog.getProgressMonitor(); final IRuntimeLocator[] locators = ServerPlugin.getRuntimeLocators(); monitor.beginTask(Messages.dialogRuntimeSearchProgress, 100 * locators.length + 10); final List<IRuntimeWorkingCopy> list = new ArrayList<IRuntimeWorkingCopy>(); final IRuntimeLocator.IRuntimeSearchListener listener = new IRuntimeLocator.IRuntimeSearchListener() { public void runtimeFound(final IRuntimeWorkingCopy runtime) { dialog.getShell().getDisplay().syncExec(new Runnable() { public void run() { monitor.subTask(runtime.getName()); } }); list.add(runtime); } }; IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor2) { int size = locators.length; for (int i = 0; i < size; i++) { if (!monitor2.isCanceled()) try { locators[i].searchForRuntimes(path, listener, monitor2); } catch (CoreException ce) { if (Trace.WARNING) { Trace.trace(Trace.STRING_WARNING, "Error locating runtimes: " + locators[i].getId(), ce); } } } if (Trace.INFO) { Trace.trace(Trace.STRING_INFO, "Done search"); } } }; dialog.run(true, true, runnable); if (Trace.FINER) { Trace.trace(Trace.STRING_FINER, "Found runtimes: " + list.size()); } if (!monitor.isCanceled()) { if (list.isEmpty()) { EclipseUtil.openError(getShell(), Messages.infoNoRuntimesFound); return; } monitor.worked(5); if (Trace.FINER) { Trace.trace(Trace.STRING_FINER, "Removing duplicates"); } List<IRuntime> good = new ArrayList<IRuntime>(); Iterator iterator2 = list.iterator(); while (iterator2.hasNext()) { boolean dup = false; IRuntime wc = (IRuntime) iterator2.next(); IRuntime[] runtimes = ServerCore.getRuntimes(); if (runtimes != null) { int size = runtimes.length; for (int i = 0; i < size; i++) { if (runtimes[i].getLocation() != null && runtimes[i].getLocation().equals(wc.getLocation())) dup = true; } } if (!dup) good.add(wc); } monitor.worked(5); if (Trace.FINER) { Trace.trace(Trace.STRING_FINER, "Adding runtimes: " + good.size()); } Iterator iterator = good.iterator(); while (iterator.hasNext()) { IRuntimeWorkingCopy wc = (IRuntimeWorkingCopy) iterator.next(); wc.save(false, monitor); } monitor.done(); } dialog.close(); } catch (Exception ex) { if (Trace.SEVERE) { Trace.trace(Trace.STRING_SEVERE, "Error finding runtimes", ex); } } runtimeComp2.refresh(); } }); Button columnsButton = SWTUtil.createButton(buttonComp, Messages.actionColumns); data = (GridData) columnsButton.getLayoutData(); final RuntimePreferencePage thisClass = this; columnsButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { ConfigureColumns.forTable(runtimeComp.getTable(), thisClass); } }); pathLabel = new Label(parent, SWT.NONE); pathLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Dialog.applyDialogFont(composite); return composite; }