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:com.siteview.mde.internal.ui.launcher.OpenLogDialog.java
License:Open Source License
private void readFileWithMonitor(final PrintWriter writer) { IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask(MDEUIMessages.OpenLogDialog_message, IProgressMonitor.UNKNOWN); try { readFile(writer);/* www . j a v a 2s.c om*/ } catch (IOException e) { writer.println(MDEUIMessages.OpenLogDialog_cannotDisplay); } } }; ProgressMonitorDialog dialog = new ProgressMonitorDialog(getParentShell()); try { dialog.run(true, true, runnable); } catch (InvocationTargetException e) { } catch (InterruptedException e) { } }
From source file:com.siteview.mde.internal.ui.preferences.TargetPlatformPreferencePage.java
License:Open Source License
private void handleReload() { IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection(); if (!selection.isEmpty()) { isOutOfSynch = false;/* w w w .j a va 2 s . c om*/ ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell()) { protected void configureShell(Shell shell) { super.configureShell(shell); shell.setText(MDEUIMessages.TargetPlatformPreferencePage2_12); } }; try { dialog.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { if (monitor.isCanceled()) { throw new InterruptedException(); } // Resolve the target fActiveTarget.resolve(monitor); if (monitor.isCanceled()) { throw new InterruptedException(); } } }); } catch (InvocationTargetException e) { MDEPlugin.log(e); setErrorMessage(e.getMessage()); } catch (InterruptedException e) { // Do nothing, resolve will happen when user presses ok } if (fActiveTarget.isResolved()) { // Check if the bundle resolution has errors IStatus bundleStatus = fActiveTarget.getBundleStatus(); if (bundleStatus.getSeverity() == IStatus.ERROR) { ErrorDialog.openError(getShell(), MDEUIMessages.TargetPlatformPreferencePage2_14, MDEUIMessages.TargetPlatformPreferencePage2_15, bundleStatus, IStatus.ERROR); } // Compare the target to the existing platform try { if (bundleStatus.getSeverity() != IStatus.ERROR && fActiveTarget.getHandle().equals(fPrevious) && ((TargetDefinition) fPrevious.getTargetDefinition()) .isContentEquivalent(fActiveTarget)) { IStatus compare = getTargetService().compareWithTargetPlatform(fActiveTarget); if (!compare.isOK()) { MessageDialog.openInformation(getShell(), MDEUIMessages.TargetPlatformPreferencePage2_17, MDEUIMessages.TargetPlatformPreferencePage2_18); isOutOfSynch = true; } } } catch (CoreException e) { MDEPlugin.log(e); setErrorMessage(e.getMessage()); } } fTableViewer.refresh(true); } }
From source file:com.smartmonkey.recrep.actions.ScreenshotAction.java
License:Apache License
@Override public void run() { ProgressMonitorDialog dialog = new ProgressMonitorDialog(mViewer.getShell()); try {//from w w w. j a v a 2 s. c o m dialog.run(true, false, new IRunnableWithProgress() { private void showError(final String msg, final Throwable t, IProgressMonitor monitor) { monitor.done(); mViewer.getShell().getDisplay().syncExec(new Runnable() { @Override public void run() { Status s = new Status(IStatus.ERROR, "Screenshot", msg, t); ErrorDialog.openError(mViewer.getShell(), "Error", "Cannot take screenshot", s); } }); } @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { ProcRunner procRunner = null; String serial = System.getenv("ANDROID_SERIAL"); File tmpDir = null; File xmlDumpFile = null; File screenshotFile = null; int retCode = -1; try { tmpDir = File.createTempFile("uiautomatorviewer_", ""); tmpDir.delete(); if (!tmpDir.mkdirs()) throw new IOException("Failed to mkdir"); xmlDumpFile = File.createTempFile("dump_", ".xml", tmpDir); screenshotFile = File.createTempFile("screenshot_", ".png", tmpDir); } catch (IOException e) { e.printStackTrace(); showError("Cannot get temp directory", e, monitor); return; } // boiler plates to do a bunch of adb stuff to take XML // snapshot and screenshot monitor.beginTask("Getting UI status dump from device...", IProgressMonitor.UNKNOWN); monitor.subTask("Detecting device..."); procRunner = ProcUtils.getAdbRunner(serial, "shell", "ls", "/system/bin/uiautomator"); try { retCode = procRunner.run(30000); } catch (IOException e) { e.printStackTrace(); showError("Failed to detect device", e, monitor); return; } if (retCode != 0) { showError("No device or multiple devices connected. " + "Use ANDROID_SERIAL environment variable " + "if you have multiple devices", null, monitor); return; } if (procRunner.getOutputBlob().indexOf("No such file or directory") != -1) { showError("/system/bin/uiautomator not found on device", null, monitor); return; } monitor.subTask("Deleting old UI XML snapshot ..."); procRunner = ProcUtils.getAdbRunner(serial, "shell", "rm", "/sdcard/uidump.xml"); try { retCode = procRunner.run(30000); if (retCode != 0) { throw new IOException("Non-zero return code from \"rm\" xml dump command:\n" + procRunner.getOutputBlob()); } } catch (IOException e) { e.printStackTrace(); showError("Failed to execute \"rm\" xml dump command.", e, monitor); return; } monitor.subTask("Taking UI XML snapshot..."); procRunner = ProcUtils.getAdbRunner(serial, "shell", "/system/bin/uiautomator", "dump", "/sdcard/uidump.xml"); try { retCode = procRunner.run(30000); if (retCode != 0) { throw new IOException( "Non-zero return code from dump command:\n" + procRunner.getOutputBlob()); } } catch (IOException e) { e.printStackTrace(); showError("Failed to execute dump command.", e, monitor); return; } procRunner = ProcUtils.getAdbRunner(serial, "pull", "/sdcard/uidump.xml", xmlDumpFile.getAbsolutePath()); try { retCode = procRunner.run(30000); if (retCode != 0) { throw new IOException( "Non-zero return code from pull command:\n" + procRunner.getOutputBlob()); } } catch (IOException e) { e.printStackTrace(); showError("Failed to pull dump file.", e, monitor); return; } monitor.subTask("Deleting old device screenshot..."); procRunner = ProcUtils.getAdbRunner(serial, "shell", "rm", "/sdcard/screenshot.png"); try { retCode = procRunner.run(30000); if (retCode != 0) { throw new IOException("Non-zero return code from \"rm\" screenshot command:\n" + procRunner.getOutputBlob()); } } catch (IOException e) { e.printStackTrace(); showError("Failed to execute \"rm\" screenshot command.", e, monitor); return; } monitor.subTask("Taking device screenshot..."); procRunner = ProcUtils.getAdbRunner(serial, "shell", "screencap", "-p", "/sdcard/screenshot.png"); try { retCode = procRunner.run(30000); if (retCode != 0) { throw new IOException( "Non-zero return code from screenshot command:\n" + procRunner.getOutputBlob()); } } catch (IOException e) { e.printStackTrace(); showError("Failed to execute screenshot command.", e, monitor); return; } procRunner = ProcUtils.getAdbRunner(serial, "pull", "/sdcard/screenshot.png", screenshotFile.getAbsolutePath()); try { retCode = procRunner.run(30000); if (retCode != 0) { throw new IOException( "Non-zero return code from pull command:\n" + procRunner.getOutputBlob()); } } catch (IOException e) { e.printStackTrace(); showError("Failed to pull dump file.", e, monitor); return; } monitor.subTask("Getting Chimp..."); IChimpDevice device = SMonkeyModel.getModel().getChimp(); if (device == null) { // get the Chimpchat device try { long TIMEOUT = 5000; ChimpChat mChimpChat = ChimpChat.getInstance(); device = mChimpChat.waitForConnection(TIMEOUT, ".*"); if (device == null) { throw new RuntimeException("Chimp Timeout"); } device.wake(); } catch (Exception e) { e.printStackTrace(); showError("Failed to get MonkeyDevice", e, monitor); } } else { monitor.subTask("Already have chimp"); } final File png = screenshotFile, xml = xmlDumpFile; final IChimpDevice finaldevice = device; if (png.length() == 0) { showError("Screenshot file size is 0", null, monitor); return; } else { mViewer.getShell().getDisplay().syncExec(new Runnable() { @Override public void run() { SMonkeyModel.getModel().loadScreenshotAndXmlDump(png, xml); SMonkeyModel.getModel().setChimp(finaldevice); } }); } monitor.done(); } }); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:com.testify.ecfeed.ui.modelif.StaticTestExecutionSupport.java
License:Open Source License
public void proceed() { PrintStream currentOut = System.out; ConsoleManager.displayConsole();/*from w ww . j ava2s.c o m*/ ConsoleManager.redirectSystemOutputToStream(ConsoleManager.getOutputStream()); try { fFailedTests.clear(); ProgressMonitorDialog dialog = new ProgressMonitorDialog(Display.getCurrent().getActiveShell()); dialog.open(); dialog.run(true, true, new ExecuteRunnable()); } catch (InvocationTargetException e) { MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.DIALOG_TEST_EXECUTION_PROBLEM_TITLE, e.getTargetException().getMessage()); } catch (InterruptedException e) { MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.DIALOG_TEST_EXECUTION_PROBLEM_TITLE, e.getMessage()); } if (fFailedTests.size() > 0) { String message = "Following tests were not successfull\n\n"; for (TestCaseNode testCase : fFailedTests) { message += testCase.toString() + "\n"; } MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.DIALOG_TEST_EXECUTION_REPORT_TITLE, message); } displayTestStatusDialog(fTestCases.size()); System.setOut(currentOut); }
From source file:com.verticon.treatment.poi.handlers.EventImportHandler.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { ex = null;/*from ww w. java 2 s.com*/ message = new StringBuffer("Imported: "); IEditorPart editorPart = HandlerUtil.getActiveEditorChecked(event); EditingDomain editingDomain = ((IEditingDomainProvider) editorPart.getAdapter(IEditingDomainProvider.class)) .getEditingDomain(); Resource r = editingDomain.getResourceSet().getResources().get(0); EObject o = r.getContents().get(0); if (!(o instanceof Program)) { MessageDialog.openError(HandlerUtil.getActiveShell(event), "Event Import Failed", "Treatment Document must contain a Program Element"); return false; } Program program = (Program) o; IRunnableWithProgress op = new WorkspaceModifyDelegatingOperation(getRunnable(program, (IStructuredSelection) HandlerUtil.getActiveMenuSelectionChecked(event), editingDomain)); ProgressMonitorDialog dialog = new ProgressMonitorDialog(HandlerUtil.getActiveShell(event)); try { dialog.run(false, true, op); if (ex == null) { MessageDialog.openInformation(HandlerUtil.getActiveShell(event), "Event Data Import", message.toString()); } else { MessageDialog.openError(HandlerUtil.getActiveShell(event), "Event Data Import Failed", ex.getMessage()); } } catch (InvocationTargetException e) { MessageDialog.openError(HandlerUtil.getActiveShell(event), "Event Data Import Failed", e.getMessage()); } catch (InterruptedException e) { // Restore the interrupted status Thread.currentThread().interrupt(); } return null; }
From source file:com.verticon.treatment.poi.handlers.NamingImportHandler.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { IEditorPart editorPart = HandlerUtil.getActiveEditorChecked(event); IRunnableWithProgress op = new WorkspaceModifyDelegatingOperation( getRunnable((IStructuredSelection) HandlerUtil.getActiveMenuSelectionChecked(event), Activator.getDefault(), editorPart)); ProgressMonitorDialog dialog = new ProgressMonitorDialog(HandlerUtil.getActiveShell(event)); try {//from w w w . j a v a2 s .co m dialog.run(false, true, op); if (ex == null) { MessageDialog.openInformation(HandlerUtil.getActiveShell(event), "Name Data Import", message.toString()); } else { MessageDialog.openError(HandlerUtil.getActiveShell(event), "Name Data Import Failed", ex.getMessage()); } } catch (InvocationTargetException e) { MessageDialog.openError(HandlerUtil.getActiveShell(event), "Name Data Import Failed", e.getMessage()); } catch (InterruptedException e) { // Restore the interrupted status Thread.currentThread().interrupt(); } return null; }
From source file:control.ScreenshotAction.java
License:Apache License
@Override public void run() { ProgressMonitorDialog dialog = new ProgressMonitorDialog(mViewer.getShell()); try {// w ww. j ava2s.c o m dialog.run(true, false, new IRunnableWithProgress() { private void showError(final String msg, final Throwable t, IProgressMonitor monitor) { monitor.done(); mViewer.getShell().getDisplay().syncExec(new Runnable() { @Override public void run() { Status s = new Status(IStatus.ERROR, "Screenshot", msg, t); ErrorDialog.openError(mViewer.getShell(), "Error", "Cannot take screenshot", s); } }); } @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { ProcRunner procRunner = null; String serial = System.getenv("ANDROID_SERIAL"); File tmpDir = null; File xmlDumpFile = null; File screenshotFile = null; int retCode = -1; try { tmpDir = File.createTempFile("uiautomatorviewer_", ""); tmpDir.delete(); if (!tmpDir.mkdirs()) throw new IOException("Failed to mkdir"); xmlDumpFile = File.createTempFile("dump_", ".xml", tmpDir); screenshotFile = File.createTempFile("screenshot_", ".png", tmpDir); } catch (IOException e) { e.printStackTrace(); showError("Cannot get temp directory", e, monitor); return; } // boiler plates to do a bunch of adb stuff to take XML snapshot and screenshot monitor.beginTask("Getting UI status dump from device...", IProgressMonitor.UNKNOWN); monitor.subTask("Detecting device..."); procRunner = getAdbRunner(serial, "shell", "ls", "/system/bin/uiautomator"); try { retCode = procRunner.run(30000); } catch (IOException e) { e.printStackTrace(); showError("Failed to detect device", e, monitor); return; } if (retCode != 0) { showError("No device or multiple devices connected. " + "Use ANDROID_SERIAL environment variable " + "if you have multiple devices", null, monitor); return; } if (procRunner.getOutputBlob().indexOf("No such file or directory") != -1) { showError("/system/bin/uiautomator not found on device", null, monitor); return; } monitor.subTask("Deleting old UI XML snapshot ..."); procRunner = getAdbRunner(serial, "shell", "rm", "/sdcard/uidump.xml"); try { retCode = procRunner.run(30000); if (retCode != 0) { throw new IOException("Non-zero return code from \"rm\" xml dump command:\n" + procRunner.getOutputBlob()); } } catch (IOException e) { e.printStackTrace(); showError("Failed to execute \"rm\" xml dump command.", e, monitor); return; } monitor.subTask("Taking UI XML snapshot..."); procRunner = getAdbRunner(serial, "shell", "/system/bin/uiautomator", "dump", "/sdcard/uidump.xml"); try { retCode = procRunner.run(30000); if (retCode != 0) { throw new IOException( "Non-zero return code from dump command:\n" + procRunner.getOutputBlob()); } } catch (IOException e) { e.printStackTrace(); showError("Failed to execute dump command.", e, monitor); return; } procRunner = getAdbRunner(serial, "pull", "/sdcard/uidump.xml", xmlDumpFile.getAbsolutePath()); try { retCode = procRunner.run(30000); if (retCode != 0) { throw new IOException( "Non-zero return code from pull command:\n" + procRunner.getOutputBlob()); } } catch (IOException e) { e.printStackTrace(); showError("Failed to pull dump file.", e, monitor); return; } monitor.subTask("Deleting old device screenshot..."); procRunner = getAdbRunner(serial, "shell", "rm", "/sdcard/screenshot.png"); try { retCode = procRunner.run(30000); if (retCode != 0) { throw new IOException("Non-zero return code from \"rm\" screenshot command:\n" + procRunner.getOutputBlob()); } } catch (IOException e) { e.printStackTrace(); showError("Failed to execute \"rm\" screenshot command.", e, monitor); return; } monitor.subTask("Taking device screenshot..."); procRunner = getAdbRunner(serial, "shell", "screencap", "-p", "/sdcard/screenshot.png"); try { retCode = procRunner.run(30000); if (retCode != 0) { throw new IOException( "Non-zero return code from screenshot command:\n" + procRunner.getOutputBlob()); } } catch (IOException e) { e.printStackTrace(); showError("Failed to execute screenshot command.", e, monitor); return; } procRunner = getAdbRunner(serial, "pull", "/sdcard/screenshot.png", screenshotFile.getAbsolutePath()); try { retCode = procRunner.run(30000); if (retCode != 0) { throw new IOException( "Non-zero return code from pull command:\n" + procRunner.getOutputBlob()); } } catch (IOException e) { e.printStackTrace(); showError("Failed to pull dump file.", e, monitor); return; } final File png = screenshotFile, xml = xmlDumpFile; if (png.length() == 0) { showError("Screenshot file size is 0", null, monitor); return; } else { mViewer.getShell().getDisplay().syncExec(new Runnable() { @Override public void run() { Model.getModel().loadScreenshotAndXmlDump(png, xml); } }); } monitor.done(); } }); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:de.blizzy.backup.check.CheckRun.java
License:Open Source License
public void runCheck() { boolean canceled = false; boolean errors = false; try {/*from w w w . j a va2 s . c o m*/ ProgressMonitorDialog dlg = new ProgressMonitorDialog(parentShell); dlg.run(true, true, this); } catch (InvocationTargetException e) { BackupPlugin.getDefault().logError("error while checking backup integrity", e.getCause()); //$NON-NLS-1$ errors = true; } catch (RuntimeException e) { BackupPlugin.getDefault().logError("error while checking backup integrity", e); //$NON-NLS-1$ errors = true; } catch (InterruptedException e) { canceled = true; } if (!canceled) { if (errors) { MessageDialog.openError(parentShell, Messages.Title_BackupIntegrityCheck, Messages.ErrorsWhileCheckingBackup); } else { if (backupOk) { MessageDialog.openInformation(parentShell, Messages.Title_BackupIntegrityCheck, Messages.BackupIntegrityIntact); } else { MessageDialog.openError(parentShell, Messages.Title_BackupIntegrityCheck, Messages.BackupIntegrityNotIntact); } } } }
From source file:de.blizzy.backup.restore.RestoreDialog.java
License:Open Source License
@Override public int open() { final ProgressMonitorDialog dlg = new ProgressMonitorDialog(getParentShell()); IRunnableWithProgress runnable = new IRunnableWithProgress() { @Override//from w ww .j av a2s .c o m public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask(Messages.Title_OpenBackupDatabase, IProgressMonitor.UNKNOWN); final boolean[] ok = { true }; List<StorageInterceptorDescriptor> descs = BackupPlugin.getDefault().getStorageInterceptors(); for (final StorageInterceptorDescriptor desc : descs) { final IStorageInterceptor interceptor = desc.getStorageInterceptor(); SafeRunner.run(new ISafeRunnable() { @Override public void run() { IDialogSettings settings = Utils .getChildSection(Utils.getSection("storageInterceptors"), desc.getId()); //$NON-NLS-1$ if (!interceptor.initialize(dlg.getShell(), settings)) { ok[0] = false; } } @Override public void handleException(Throwable t) { ok[0] = false; interceptor.showErrorMessage(t, dlg.getShell()); BackupPlugin.getDefault().logError( "error while initializing storage interceptor '" + desc.getName() + "'", t); //$NON-NLS-1$ //$NON-NLS-2$ } }); storageInterceptors.add(interceptor); } if (!ok[0]) { monitor.done(); throw new InterruptedException(); } Cursor<BackupsRecord> cursor = null; try { database.open(storageInterceptors); database.initialize(); cursor = database.factory().selectFrom(Tables.BACKUPS) .where(Tables.BACKUPS.NUM_ENTRIES.isNotNull()).orderBy(Tables.BACKUPS.RUN_TIME.desc()) .fetchLazy(); while (cursor.hasNext()) { BackupsRecord record = cursor.fetchOne(); Backup backup = new Backup(record.getId().intValue(), new Date(record.getRunTime().getTime()), record.getNumEntries().intValue()); backups.add(backup); } } catch (SQLException | IOException e) { boolean handled = false; for (IStorageInterceptor interceptor : storageInterceptors) { if (interceptor.showErrorMessage(e, dlg.getShell())) { handled = true; } } if (handled) { throw new InterruptedException(); } throw new InvocationTargetException(e); } finally { database.closeQuietly(cursor); monitor.done(); } } }; try { dlg.run(true, false, runnable); } catch (InvocationTargetException e) { // TODO BackupPlugin.getDefault().logError("Error while opening backup database", e); //$NON-NLS-1$ } catch (InterruptedException e) { return Window.CANCEL; } return super.open(); }
From source file:de.blizzy.backup.restore.RestoreDialog.java
License:Open Source License
@Override public boolean close() { IRunnableWithProgress runnable = new IRunnableWithProgress() { @Override// ww w . j a va 2 s . co m public void run(IProgressMonitor monitor) { monitor.beginTask(Messages.Title_CloseBackupDatabase, IProgressMonitor.UNKNOWN); try { database.close(); for (final IStorageInterceptor interceptor : storageInterceptors) { SafeRunner.run(new ISafeRunnable() { @Override public void run() { interceptor.destroy(); } @Override public void handleException(Throwable t) { BackupPlugin.getDefault().logError("error while destroying storage interceptor", t); //$NON-NLS-1$ } }); } } finally { monitor.done(); } } }; ProgressMonitorDialog dlg = new ProgressMonitorDialog(getShell()); try { dlg.run(true, false, runnable); } catch (InvocationTargetException e) { // TODO BackupPlugin.getDefault().logError("Error while closing backup database", e); //$NON-NLS-1$ } catch (InterruptedException e) { // not cancelable } System.gc(); return super.close(); }