List of usage examples for org.eclipse.jface.dialogs ProgressMonitorDialog ProgressMonitorDialog
public ProgressMonitorDialog(Shell parent)
From source file:com.motorolamobility.studio.android.certmanager.ui.wizards.RemoveExternalPackageSignatureWizard.java
License:Apache License
/** * Finishes this wizard removing packages signatures *//*from w w w .ja v a 2 s. c om*/ @Override public boolean performFinish() { final List<String> defectivePackages = new ArrayList<String>(); IRunnableWithProgress finishAction = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { List<String> selectedFiles = RemoveExternalPackageSignatureWizard.this.page.getSelectedPackages(); monitor.beginTask(CertificateManagerNLS.UNSIGN_EXTERNAL_PKG_WIZARD_WINDOW_TITLE, selectedFiles.size()); for (String selected : selectedFiles) { File file = new File(selected); monitor.setTaskName( CertificateManagerNLS.UNSIGN_EXTERNAL_PKG_WIZARD_OPERATION + " " + file.getName()); if ((file != null) && file.exists() && file.isFile() && file.canWrite()) { OutputStream fileToWrite = null; JarFile jar = null; PackageFile pack = null; try { // Open package and remove signature jar = new JarFile(file); pack = new PackageFile(jar); try { pack.removeMetaEntryFiles(); } catch (IOException e) { StudioLogger.error(RemoveExternalPackageSignatureWizard.class.toString(), "Impossible to delete temporary files"); throw e; } // Write the new package file fileToWrite = new FileOutputStream(file); pack.write(fileToWrite); PackageFile.zipAlign(file); } catch (IOException e) { defectivePackages.add(selected); StudioLogger.error(RemoveExternalPackageSignatureWizard.class.toString(), "Impossible write to package: " + selected + " " + e.getMessage()); } catch (SecurityException e) { defectivePackages.add(selected); StudioLogger.error(RemoveExternalPackageSignatureWizard.class.toString(), "Impossible write to package: " + selected + " " + e.getMessage()); } finally { System.gc(); // Force garbage collector to avoid // errors when deleting temp files try { if (jar != null) { jar.close(); } if (pack != null) { pack.removeTemporaryEntryFiles(); } if (fileToWrite != null) { fileToWrite.close(); } } catch (IOException e) { // Silent exception. Only log the deletion // exception. StudioLogger.error(CertificateManagerActivator.PLUGIN_ID, "Deleting temporary files"); } } } else { defectivePackages.add(selected); } monitor.worked(1); } monitor.done(); } }; try { PlatformUI.getWorkbench().getProgressService().runInUI(new ProgressMonitorDialog(getShell()), finishAction, null); } catch (InvocationTargetException e1) { StudioLogger.error(RemoveExternalPackageSignatureWizard.class.toString(), "Error running finish actions"); } catch (InterruptedException e1) { StudioLogger.error(RemoveExternalPackageSignatureWizard.class.toString(), "Error running finish actions"); } if (ResourcesPlugin.getWorkspace().getRoot().getLocation().isPrefixOf(this.page.getSourcePath())) { org.eclipse.ui.actions.WorkspaceModifyOperation op = new org.eclipse.ui.actions.WorkspaceModifyOperation() { @Override protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { for (IContainer container : ResourcesPlugin.getWorkspace().getRoot().findContainersForLocation( RemoveExternalPackageSignatureWizard.this.page.getSourcePath())) { container.refreshLocal(IResource.DEPTH_INFINITE, monitor); } } }; try { PlatformUI.getWorkbench().getProgressService().run(false, false, op); } catch (InvocationTargetException e) { StudioLogger.error(RemoveExternalPackageSignatureWizard.class.toString(), "Error refreshing workspace"); } catch (InterruptedException e) { StudioLogger.error(RemoveExternalPackageSignatureWizard.class.toString(), "Error refreshing workspace"); } } if (!defectivePackages.isEmpty()) { MultiStatus errors = new MultiStatus(CertificateManagerActivator.PLUGIN_ID, IStatus.ERROR, CertificateManagerNLS.UNSIGN_EXTERNAL_PKG_WIZARD_ERROR_REASON, null); for (String defect : defectivePackages) { errors.add(new Status(IStatus.ERROR, CertificateManagerActivator.PLUGIN_ID, defect)); } ErrorDialog errorBox = new ErrorDialog(getShell(), CertificateManagerNLS.UNSIGN_EXTERNAL_PKG_WIZARD_WINDOW_TITLE, CertificateManagerNLS.UNSIGN_EXTERNAL_PKG_WIZARD_ERROR, errors, IStatus.ERROR); errorBox.open(); } return true; }
From source file:com.motorolamobility.studio.android.certmanager.ui.wizards.SignExternalPackageWizard.java
License:Apache License
/** * Finishes this wizard, signing the selected packages *//*from w w w . j a va 2 s .c o m*/ @Override public boolean performFinish() { final List<String> defectivePackages = new ArrayList<String>(); IRunnableWithProgress finishAction = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { List<String> selectedFiles = SignExternalPackageWizard.this.page.getSelectedPackages(); monitor.beginTask(CertificateManagerNLS.SIGN_EXTERNAL_PKG_WIZARD_WINDOW_TITLE, selectedFiles.size() * 2); for (String selected : selectedFiles) { File file = new File(selected); monitor.setTaskName( CertificateManagerNLS.SIGN_EXTERNAL_PKG_WIZARD_OPERATION + " " + file.getName()); if ((file != null) && file.exists() && file.isFile() && file.canWrite()) { OutputStream fileToWrite = null; PackageFile pack = null; JarFile jar = null; try { // Update monitor monitor.worked(1); monitor.setTaskName(CertificateManagerNLS.SIGN_EXTERNAL_PKG_WIZARD_OPERATION + " " + file.getName()); String keyStorePassword = SignExternalPackageWizard.this.page.getKeystorePassword(); if (SignExternalPackageWizard.this.page.getSavePasswordSelection()) { SignExternalPackageWizard.this.page.getPasswordProvider() .saveKeyStorePassword(keyStorePassword); } String keyEntryPassword = SignExternalPackageWizard.this.page.getKeyEntryPassword(); boolean keepTrying; if (keyEntryPassword != null) { keepTrying = true; } else { keepTrying = false; throw new Exception(); } while (keepTrying) { try { // Open package and remove signature jar = new JarFile(file); pack = new PackageFile(jar); pack.removeMetaEntryFiles(); // Sign the new package PackageFileSigner.signPackage(pack, SignExternalPackageWizard.this.page.getSelectedKeyEntry(), keyEntryPassword, PackageFileSigner.MOTODEV_STUDIO); keepTrying = false; } catch (UnrecoverableKeyException sE) { keyEntryPassword = SignExternalPackageWizard.this.page.getPasswordProvider() .getPassword(SignExternalPackageWizard.this.page.getSelectedKeyEntry() .getAlias(), true, false); if (keyEntryPassword == null) { keepTrying = false; } else { keepTrying = true; } } } // Write the new package file fileToWrite = new FileOutputStream(file); pack.write(fileToWrite); PackageFile.zipAlign(file); } catch (IOException e) { defectivePackages.add(selected); StudioLogger.error(SignExternalPackageWizard.class.toString(), "Impossible write to package: " + selected + " " + e.getMessage()); } catch (SignException e) { defectivePackages.add(selected); StudioLogger.error(SignExternalPackageWizard.class.toString(), "Impossible sign the package: " + selected + " " + e.getMessage()); } catch (SecurityException e) { defectivePackages.add(selected); StudioLogger.error(SignExternalPackageWizard.class.toString(), "Impossible sign the package: " + selected + " " + e.getMessage()); } catch (Exception e) { defectivePackages.add(selected); StudioLogger.error(SignExternalPackageWizard.class.toString(), "Impossible sign the package: " + selected + " " + e.getMessage()); } finally { System.gc(); // Force garbage collector to avoid // errors when deleting temp files try { if (pack != null) { pack.removeTemporaryEntryFiles(); } if (fileToWrite != null) { fileToWrite.close(); } if (jar != null) { jar.close(); } } catch (IOException e) { // Silent exception. Only log the deletion // exception. StudioLogger.error(CertificateManagerActivator.PLUGIN_ID, "Deleting temporary files"); } } } else { defectivePackages.add(selected); } monitor.worked(1); } monitor.done(); } }; try { PlatformUI.getWorkbench().getProgressService().runInUI(new ProgressMonitorDialog(getShell()), finishAction, null); } catch (InvocationTargetException e1) { StudioLogger.error(SignExternalPackageWizard.class.toString(), "Error running finish actions"); } catch (InterruptedException e1) { StudioLogger.error(SignExternalPackageWizard.class.toString(), "Error running finish actions"); } if (ResourcesPlugin.getWorkspace().getRoot().getLocation().isPrefixOf(this.page.getSourcePath())) { WorkspaceModifyOperation op = new WorkspaceModifyOperation() { @Override protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { for (IContainer container : ResourcesPlugin.getWorkspace().getRoot() .findContainersForLocation(SignExternalPackageWizard.this.page.getSourcePath())) { container.refreshLocal(IResource.DEPTH_INFINITE, monitor); } } }; try { PlatformUI.getWorkbench().getProgressService().run(false, false, op); } catch (InvocationTargetException e) { StudioLogger.error(SignExternalPackageWizard.class.toString(), "Error refreshing workspace"); } catch (InterruptedException e) { StudioLogger.error(SignExternalPackageWizard.class.toString(), "Error refreshing workspace"); } } if (!defectivePackages.isEmpty()) { MultiStatus errors = new MultiStatus(CertificateManagerActivator.PLUGIN_ID, IStatus.ERROR, CertificateManagerNLS.UNSIGN_EXTERNAL_PKG_WIZARD_ERROR_REASON, null); for (String defect : defectivePackages) { errors.add(new Status(IStatus.ERROR, CertificateManagerActivator.PLUGIN_ID, defect)); } ErrorDialog errorBox = new ErrorDialog(getShell(), CertificateManagerNLS.SIGN_EXTERNAL_PKG_WIZARD_WINDOW_TITLE, CertificateManagerNLS.SIGN_EXTERNAL_PKG_WIZARD_ERROR, errors, IStatus.ERROR); errorBox.open(); } return true; }
From source file:com.muratools.eclipse.wizard.newInstall.NewInstallWizard.java
License:Apache License
private void downloadMura() { ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell()); try {//from w w w . j av a 2 s . com dialog.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { //monitor.beginTask("Downloading Mura...", 100); try { URL url = new URL("http://www.getmura.com/currentversion/?source=muratools"); int contentLength = url.openConnection().getContentLength(); monitor.beginTask("Downloading Mura...", contentLength); InputStream reader = url.openStream(); FileOutputStream writer = new FileOutputStream(zipLocation); byte[] buffer = new byte[44640]; int bytesRead = 0; int tp = 0; while ((bytesRead = reader.read(buffer)) > 0) { writer.write(buffer, 0, bytesRead); buffer = new byte[44640]; tp++; System.err.println(tp + " / " + Integer.toString((int) Math.ceil((double) contentLength / (double) 44640)) + "[" + bytesRead + "]"); monitor.worked(bytesRead); } writer.close(); reader.close(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } monitor.done(); } }); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:com.muratools.eclipse.wizard.newInstall.NewInstallWizard.java
License:Apache License
private void deployMuraZip() { ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell()); try {//from w w w. ja va2 s .com dialog.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { //monitor.beginTask("Unzipping Mura...", IProgressMonitor.UNKNOWN); try { String tempDir = System.getProperty("java.io.tmpdir") + "/latest-mura-" + Long.toString(new Date().getTime()); // make the tempDir new File(tempDir).mkdir(); Enumeration entries; ZipFile zipFile; zipFile = new ZipFile(zipLocation); entries = zipFile.entries(); monitor.beginTask("Unzipping Mura...", zipFile.size() * 2); // unzip the zip file to the temp directory while (entries.hasMoreElements()) { ZipEntry entry = (ZipEntry) entries.nextElement(); String fullEntryPath = tempDir + "/" + entry.getName(); if (entry.isDirectory()) { (new File(fullEntryPath)).mkdir(); continue; } copyInputStream(zipFile.getInputStream(entry), new BufferedOutputStream(new FileOutputStream(fullEntryPath))); monitor.worked(1); } zipFile.close(); // copy the files to the target directory String sourceDir = tempDir; File testDir = new File(tempDir + "/www"); if (testDir.exists() && testDir.isDirectory()) { sourceDir += "/www"; } copyDirectory(new File(sourceDir), new File(getTargetDirectory()), monitor); } catch (IOException e) { e.printStackTrace(); } monitor.done(); } }); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:com.netxforge.editing.base.impl.EMFEditingService.java
License:Open Source License
public void doSave(IProgressMonitor monitor) { IRunnableWithProgress operation = doGetSaveOperation(monitor); if (operation == null) return;/*w ww.j a va 2s . co m*/ try { // This runs the options, and shows progress. new ProgressMonitorDialog(Display.getDefault().getActiveShell()).run(true, false, operation); // Refresh the necessary state. ((BasicCommandStack) getEditingDomain().getCommandStack()).saveIsDone(); } catch (Exception exception) { exception.printStackTrace(); // Hide here will be caught higher up. } }
From source file:com.netxforge.netxstudio.delta16042013.generics.presentation.GenericsEditor.java
License:Open Source License
/** * This is for implementing {@link IEditorPart} and simply saves the model file. * <!-- begin-user-doc -->//from www . j av a 2s .com * <!-- end-user-doc --> * @generated NOT */ @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. // IRunnableWithProgress operation = new IRunnableWithProgress() { // This is the method that gets invoked when the operation runs. // public void run(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. // NetxstudioEditorPlugin.INSTANCE.log(exception); } updateProblemIndication = true; updateProblemIndication(); }
From source file:com.netxforge.netxstudio.generics.presentation.GenericsEditor.java
License:Open Source License
/** * This is for implementing {@link IEditorPart} and simply saves the model file. * <!-- begin-user-doc -->/*from www . ja v a 2 s .c om*/ * <!-- 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. // NetxstudioEditorPlugin.INSTANCE.log(exception); } updateProblemIndication = true; updateProblemIndication(); }
From source file:com.netxforge.netxstudio.models.export.ui.AbstractExportTempleWizard.java
License:Open Source License
public boolean doPerformFinish(final XpandTemplate currentTemplate) { // The export template should be set by the super... // Set template variables. (Generalize this). final IPath exportPath = xpandExportFilePage.getFilePath(); Map<String, Variable> map = new HashMap<String, Variable>(); map.put(XpandCallerService.FILE_NAME, new Variable(XpandCallerService.FILE_NAME, exportPath.lastSegment())); currentTemplate.setGlobalVarsMap(map); IPath containerPath = xpandExportFilePage.getContainerFullPath(); final IContainer container = ResourcesPlugin.getWorkspace().getRoot().getFolder(containerPath); // Implement the export. IRunnableWithProgress op = new WorkspaceModifyOperation(null) { protected void execute(IProgressMonitor monitor) throws CoreException, InterruptedException { monitor.beginTask(Messages.XPandExportWizard_0 + currentTemplate.getTemplateDescription(), 100); currentTemplate.xpand(container); monitor.worked(50);//w w w . j av a 2 s. c o m container.refreshLocal(IResource.DEPTH_ONE, null); monitor.setTaskName(Messages.XPandExportWizard_1 + container.getName()); monitor.done(); } }; try { Shell activeShell = this.getContainer().getShell(); new ProgressMonitorDialog(activeShell).run(false, true, op); } catch (InterruptedException e) { return false; } catch (InvocationTargetException e) { if (e.getTargetException() instanceof CoreException) { ErrorDialog.openError(getContainer().getShell(), Messages.XPandExportWizard_2, null, ((CoreException) e.getTargetException()).getStatus()); } return false; } return true; }
From source file:com.netxforge.netxstudio.models.export.ui.AbstractModelExportWizard.java
License:Open Source License
@Override public boolean performFinish() { // Set template variables from the template extension and the export path. final IPath exportPath = xpandExportFilePage.getFilePath(); Map<String, Variable> map = new HashMap<String, Variable>(); map.put(XpandCallerService.FILE_NAME, new Variable(XpandCallerService.FILE_NAME, exportPath.lastSegment())); final XpandTemplate currentTemplate = this.getTargetTemplate(); currentTemplate.setGlobalVarsMap(map); IPath containerPath = xpandExportFilePage.getContainerFullPath(); final IContainer container = ResourcesPlugin.getWorkspace().getRoot().getFolder(containerPath); // Implement the export. IRunnableWithProgress op = new WorkspaceModifyOperation(null) { protected void execute(IProgressMonitor monitor) throws CoreException, InterruptedException { monitor.beginTask(Messages.XPandExportWizard_0 + currentTemplate.getTemplateDescription(), 100); currentTemplate.xpand(container); monitor.worked(50);//from w w w. j a v a 2s . c om container.refreshLocal(IResource.DEPTH_ONE, null); monitor.setTaskName(Messages.XPandExportWizard_1 + container.getName()); monitor.done(); } }; try { Shell activeShell = this.getContainer().getShell(); new ProgressMonitorDialog(activeShell).run(false, true, op); } catch (InterruptedException e) { return false; } catch (InvocationTargetException e) { if (e.getTargetException() instanceof CoreException) { ErrorDialog.openError(getContainer().getShell(), Messages.XPandExportWizard_2, null, ((CoreException) e.getTargetException()).getStatus()); } return false; } return true; }
From source file:com.netxforge.netxstudio.screens.editing.CDOEditingService.java
License:Open Source License
@Override public void doSave(IProgressMonitor monitor) { // save could be triggered from CDOView view = dawnEditorSupport.getView(); if (view instanceof CDOTransaction) { if (view.isDirty()) { StudioUtils.cdoDumpDirtyObject((CDOTransaction) view); }//from w w w .ja va 2 s .com if (((CDOTransaction) view).hasConflict()) { MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(), "Conflict", null, "There is a conflict with another user. Would you like to rollback your current transaction?", MessageDialog.QUESTION, new String[] { "yes", "no", "Cancel" }, 1); switch (dialog.open()) { case 0: // yes ((IDawnEditor) this).getDawnEditorSupport().rollback(); break; case 1: // no break; default: // cancel break; } } else { // this.doSaveHistory(monitor); IRunnableWithProgress operation = doGetSaveOperation(monitor); if (operation == null) return; try { // This runs the options, and shows progress. new ProgressMonitorDialog(Display.getDefault().getActiveShell()).run(true, false, operation); // Refresh the necessary state. ((BasicCommandStack) getEditingDomain().getCommandStack()).saveIsDone(); } catch (Exception exception) { } } } }