List of usage examples for org.eclipse.jface.dialogs ProgressMonitorDialog ProgressMonitorDialog
public ProgressMonitorDialog(Shell parent)
From source file:com.windowtester.examples.gef.uml.editor.ClassDiagramEditor.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();/* www. ja v a 2 s . co 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:com.windowtester.internal.customer.cat.shapes.ShapesEditor.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 av a 2 s . com*/ 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:com.windowtester.swt.codegen.dialogs.SubclassSelectionDialog.java
License:Open Source License
public String getSelection() { //TODO: improve exception handling String result = ""; try {//ww w.j a v a 2s . c om IType[] subtypes = SearchScopeHelper.forSubclasses(type).inProject(getJavaProject()); SelectionDialog dialog = null; Object[] types; IJavaSearchScope scope; IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); scope = getSearchScope(); dialog = JavaUI.createTypeDialog(window.getShell(), new ProgressMonitorDialog(window.getShell()), scope, IJavaElementSearchConstants.CONSIDER_CLASSES, false, /*type.getFullyQualifiedName()*/ "", FilteredTypeSelectionExtension.forTypes(subtypes)); dialog.setTitle("Superclass Selection"); dialog.setMessage("Choose a type:"); if (dialog.open() == IDialogConstants.CANCEL_ID) { return null; } types = dialog.getResult(); if (types != null && types.length > 0) { result = ((IType) types[0]).getFullyQualifiedName(); } } catch (JavaModelException e) { LogHandler.log(e); } catch (Exception e) { LogHandler.log(e); } return result; }
From source file:com.xored.fanide.internal.ui.preferences.FanBuildPathPropertyPage.java
License:Open Source License
@Override public boolean performOk() { if (fBuildPathsBlock != null) { getSettings().put(INDEX, fBuildPathsBlock.getPageIndex()); if (fBuildPathsBlock.hasChangesInDialog()) { final boolean doBuild = FanBuildUtils.doBuildDialog(getProject(), getShell()); IWorkspaceRunnable runnable = new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException, OperationCanceledException { fBuildPathsBlock.configureScriptProject(monitor); if (doBuild) { FanBuildUtils.processChanges(getProject(), monitor); }/* w w w.j a va 2 s.c om*/ } }; WorkbenchRunnableAdapter op = new WorkbenchRunnableAdapter(runnable); if (true/* fBlockOnApply */) { try { new ProgressMonitorDialog(getShell()).run(true, true, op); } catch (InvocationTargetException e) { ExceptionHandler.handle(e, getShell(), PreferencesMessages.BuildPathsPropertyPage_error_title, PreferencesMessages.BuildPathsPropertyPage_error_message); return false; } catch (InterruptedException e) { return false; } } else { op.runAsUserJob(PreferencesMessages.BuildPathsPropertyPage_job_title, null); } } } return true; }
From source file:control.ScreenshotAction.java
License:Apache License
@Override public void run() { ProgressMonitorDialog dialog = new ProgressMonitorDialog(mViewer.getShell()); try {/*from w w w .java2s .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:crosswalk.presentation.CrosswalkEditor.java
License:Apache License
/** * This is for implementing {@link IEditorPart} and simply saves the model file. * <!-- begin-user-doc -->// w ww .j a va2s . c o m * <!-- end-user-doc --> * @generated */ @Override public void doSave(IProgressMonitor progressMonitor) { // Save only resources that have actually changed. // final Map<Object, Object> saveOptions = new HashMap<Object, Object>(); saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER); // Do the work within an operation because this is a long running activity that modifies the workbench. // WorkspaceModifyOperation operation = new WorkspaceModifyOperation() { // This is the method that gets invoked when the operation runs. // @Override public void execute(IProgressMonitor monitor) { // Save the resources to the file system. // boolean first = true; for (Resource resource : editingDomain.getResourceSet().getResources()) { if ((first || !resource.getContents().isEmpty() || isPersisted(resource)) && !editingDomain.isReadOnly(resource)) { try { long timeStamp = resource.getTimeStamp(); resource.save(saveOptions); if (resource.getTimeStamp() != timeStamp) { savedResources.add(resource); } } catch (Exception exception) { resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception)); } first = false; } } } }; updateProblemIndication = false; try { // This runs the options, and shows progress. // new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation); // Refresh the necessary state. // ((BasicCommandStack) editingDomain.getCommandStack()).saveIsDone(); firePropertyChange(IEditorPart.PROP_DIRTY); } catch (Exception exception) { // Something went wrong that shouldn't. // CrosswalkEditorPlugin.INSTANCE.log(exception); } updateProblemIndication = true; updateProblemIndication(); }
From source file:de.berlios.svgcompost.editor.SVGEditor.java
License:Apache License
public void doSaveAs() { Shell shell = getSite().getWorkbenchWindow().getShell(); SaveAsDialog dialog = new SaveAsDialog(shell); dialog.setOriginalFile(((IFileEditorInput) getEditorInput()).getFile()); dialog.open();// w w w .j a va2 s .c o m IPath path = dialog.getResult(); if (path != null) { final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); try { new ProgressMonitorDialog(shell).run(false, false, new WorkspaceModifyOperation() { public void execute(final IProgressMonitor monitor) { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); createOutputStream(out); file.create(new ByteArrayInputStream(out.toByteArray()), true, monitor); } catch (CoreException ce) { ce.printStackTrace(); } } }); setInput(new FileEditorInput(file)); getCommandStack().markSaveLocation(); } catch (InterruptedException e) { e.printStackTrace(); } catch (InvocationTargetException 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 {// w w w . j ava2 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 ww w .j av a 2 s . com*/ 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/*from ww w . ja va2s . c o 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(); }