List of usage examples for org.eclipse.jface.dialogs ProgressMonitorDialog ProgressMonitorDialog
public ProgressMonitorDialog(Shell parent)
From source file:com.contrastsecurity.ide.eclipse.ui.internal.preferences.ContrastPreferencesPage.java
License:Open Source License
private void testConnection(Composite composite) { final String url = teamServerText.getText(); URL u;/*from w w w . j a v a 2s . co m*/ try { u = new URL(url); } catch (MalformedURLException e1) { MessageDialog.openError(getShell(), "Exception", "Invalid URL."); testConnectionLabel.setText("Connection failed!"); return; } if (!u.getProtocol().startsWith("http")) { MessageDialog.openError(getShell(), "Exception", "Invalid protocol."); testConnectionLabel.setText("Connection failed!"); return; } IRunnableWithProgress op = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) { Display.getDefault().syncExec(new Runnable() { @Override public void run() { ContrastSDK sdk = new ContrastSDK(usernameText.getText(), serviceKeyText.getText(), apiKeyText.getText(), url); try { Organization organization = Util.getDefaultOrganization(sdk); if (organization == null || organization.getOrgUuid() == null) { testConnectionLabel .setText("Connection is correct, but no default organizations found."); } else { testConnectionLabel.setText("Connection confirmed!"); } } catch (IOException e1) { showErrorMessage(e1, getShell(), "Connection error", "Could not connect to Contrast. Please verify that the URL is correct and try again."); } catch (UnauthorizedException e1) { showErrorMessage(e1, getShell(), "Access denied", "Verify your credentials and make sure you have access to the selected organization."); } catch (Exception e1) { showErrorMessage(e1, getShell(), "Unknown error", "Unknown exception. Please inform an admin about this."); } finally { composite.layout(true, true); composite.redraw(); } } }); } }; IWorkbench wb = PlatformUI.getWorkbench(); IWorkbenchWindow win = wb.getActiveWorkbenchWindow(); Shell shell = win != null ? win.getShell() : null; try { new ProgressMonitorDialog(shell).run(true, true, op); } catch (InvocationTargetException | InterruptedException e1) { ContrastUIActivator.log(e1); } }
From source file:com.contrastsecurity.ide.eclipse.ui.internal.preferences.ContrastPreferencesPage.java
License:Open Source License
private void retrieveOrganizationName(Composite composite) { final String url = teamServerText.getText(); URL u;/*from w w w . j av a2s. c o m*/ try { u = new URL(url); } catch (MalformedURLException e1) { MessageDialog.openError(getShell(), "Exception", "Invalid URL."); testConnectionLabel.setText("Connection failed!"); return; } if (!u.getProtocol().startsWith("http")) { MessageDialog.openError(getShell(), "Exception", "Invalid protocol."); testConnectionLabel.setText("Connection failed!"); return; } IRunnableWithProgress op = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) { Display.getDefault().syncExec(new Runnable() { @Override public void run() { ExtendedContrastSDK sdk = ContrastCoreActivator.getContrastSDK(usernameText.getText(), apiKeyText.getText(), serviceKeyText.getText(), url); try { Organizations organizations = sdk.getProfileOrganizations(); if (organizations.getOrganizations() != null && !organizations.getOrganizations().isEmpty()) { for (Organization organization : organizations.getOrganizations()) { if (organization.getOrgUuid().equals(organizationUuidText.getText())) { // Check if organization is already saved if (ContrastCoreActivator .getOrganizationConfiguration(organization.getName()) == null) { ContrastCoreActivator.saveNewOrganization(organization.getName(), teamServerText.getText(), usernameText.getText(), serviceKeyText.getText(), apiKeyText.getText(), organizationUuidText.getText()); teamServerText.setText(""); usernameText.setText(""); serviceKeyText.setText(""); apiKeyText.setText(""); organizationUuidText.setText(""); String[] organizationsArray = (String[]) tableViewer.getInput(); String[] newOrganizationsArray = Arrays.copyOf(organizationsArray, organizationsArray.length + 1); newOrganizationsArray[newOrganizationsArray.length - 1] = organization .getName(); tableViewer.setInput(newOrganizationsArray); if (newOrganizationsArray.length == 1) { tableViewer.getTable().setSelection(0); } } else { testConnectionLabel.setText("Organization already exists"); } break; } } } } catch (IOException e1) { showErrorMessage(e1, getShell(), "Connection error", "Could not connect to Contrast. Please verify that the URL is correct and try again."); } catch (UnauthorizedException e1) { showErrorMessage(e1, getShell(), "Access denied", "Verify your credentials and make sure you have access to the selected organization."); } catch (Exception e1) { showErrorMessage(e1, getShell(), "Unknown error", "Unknown exception. Please inform an admin about this."); } finally { composite.layout(true, true); composite.redraw(); } } }); } }; IWorkbench wb = PlatformUI.getWorkbench(); IWorkbenchWindow win = wb.getActiveWorkbenchWindow(); Shell shell = win != null ? win.getShell() : null; try { new ProgressMonitorDialog(shell).run(true, true, op); } catch (InvocationTargetException | InterruptedException e1) { ContrastUIActivator.log(e1); } }
From source file:com.crispico.flower.mp.model.eclipse_editor.Editor.java
License:Open Source License
/** * This is for implementing {@link IEditorPart} and simply saves the model file. * <!-- begin-user-doc -->//from w w w . j av a2 s. c o m * <!-- end-user-doc --> * */ @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. // EclipseEditorPlugin.INSTANCE.log(exception); } updateProblemIndication = true; updateProblemIndication(); }
From source file:com.drgarbage.ast.ASTPanel.java
License:Apache License
/** * Creates content for the tree viewer./*from ww w . j a v a 2 s . c o m*/ * @param compilationUnit the compilation unit object (may be <code>null</code>). * @param classFile the class file object (may be <code>null</code>). * * @throws InvocationTargetException * @throws InterruptedException */ private void createContent(final ICompilationUnit compilationUnit, final IClassFile classFile) throws InvocationTargetException, InterruptedException { clearContent(); ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell()); dialog.run(true, true, new IRunnableWithProgress() { public void run(final IProgressMonitor monitor) throws InvocationTargetException { parser.setKind(ASTParser.K_COMPILATION_UNIT); if (monitor.isCanceled()) return; if (compilationUnit != null) { parser.setSource(compilationUnit); if (monitor.isCanceled()) return; } else { parser.setSource(classFile); if (monitor.isCanceled()) return; } final CompilationUnit node = (CompilationUnit) parser.createAST(monitor); if (monitor.isCanceled()) return; getDisplay().syncExec(new Runnable() { public void run() { TreeModel t = new TreeModel(); ASTVisitorImpl visitor = new ASTVisitorImpl(t, monitor); node.accept(visitor); treeViewer.setInput(t); } }); } }); }
From source file:com.drgarbage.bytecode.jdi.dialogs.JDIExportFromJvmDialog.java
License:Apache License
/** * Creates dialog specific controls. /*from w w w. jav a2 s . c om*/ */ protected void createControls() { /* hint text */ hintLabel = new Label(shell, SWT.NONE); hintLabel.setText(BytecodeVisualizerMessages.JDI_Export_Dialog_hint_text); /* Filtered list */ PatternFilter pf = new PatternFilter(); pf.setPattern(""); FilteredCheckboxList ft = new FilteredCheckboxList(shell, SWT.BORDER | SWT.MULTI, pf); ft.setLayoutData(new GridData(GridData.FILL_BOTH)); /* initialize the viewer before filling the list */ viewer = (CheckboxTreeViewer) ft.getViewer(); viewer.setContentProvider(new TreeContentProvider()); viewer.setLabelProvider(new LabelProvider()); /* create message label */ Composite c = new Composite(hintLabel.getParent(), SWT.NONE); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 2; c.setLayout(gridLayout); messageIcon = new Label(c, SWT.NONE); messageLabel = new Label(c, SWT.NONE); /* fill the viewer */ fillList(ft); Composite selectComposite = new Composite(shell, SWT.NONE); selectComposite.setLayout(new GridLayout(2, false)); selectComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); selectAll = new Button(selectComposite, SWT.PUSH); selectAll.setText(BytecodeVisualizerMessages.JDI_Export_Dialog_Select_All); selectAll.addListener(SWT.Selection, new Listener() { /* (non-Javadoc) * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event) */ @SuppressWarnings("deprecation") public void handleEvent(Event event) { viewer.setAllChecked(true); } }); deselectAll = new Button(selectComposite, SWT.PUSH); deselectAll.setText(BytecodeVisualizerMessages.JDI_Export_Dialog_Deselect_All); deselectAll.addListener(SWT.Selection, new Listener() { /* (non-Javadoc) * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event) */ @SuppressWarnings("deprecation") public void handleEvent(Event event) { viewer.setAllChecked(false); } }); /* buttons */ Composite dirPromptComposite = new Composite(shell, SWT.BORDER); dirPromptComposite.setLayout(new GridLayout(2, false)); dirPromptComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); final Text pathText = new Text(dirPromptComposite, SWT.SINGLE | SWT.BORDER); GridData gd = new GridData(); gd.widthHint = folderPromptWidth; pathText.setLayoutData(gd); pathText.setEditable(false); pathText.setText(BytecodeVisualizerMessages.JDI_Export_Dialog_Define_Class_Folder); chooseDirBtn = new Button(dirPromptComposite, SWT.PUSH); chooseDirBtn.setText(BytecodeVisualizerMessages.JDI_Export_Dialog_browse_btn_label); chooseDirBtn.setToolTipText(BytecodeVisualizerMessages.JDI_Export_Dialog_tooltip_browse_folder); chooseDirBtn.addListener(SWT.Selection, new Listener() { /* (non-Javadoc) * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event) */ public void handleEvent(Event event) { Object o = DebugUITools.getDebugContext(); if (o instanceof JDIDebugElement) { JDIDebugElement jdiDebugElement = (JDIDebugElement) o; ILaunchConfiguration config = jdiDebugElement.getLaunch().getLaunchConfiguration(); IJavaProject javaProject = null; try { javaProject = JavaRuntime.getJavaProject(config); } catch (CoreException e) { BytecodeVisualizerPlugin.getDefault().getLog() .log(BytecodeVisualizerPlugin.createErrorStatus(e.getMessage(), e)); } ProjectBuildPathDialog selectFolderDlg = new ProjectBuildPathDialog(shell, javaProject); selectFolderDlg.open(); IFolder f = selectFolderDlg.getSelectedFolder(); if (f != null) { exportFolder = f; pathText.setText(exportFolder.getFullPath().toOSString()); } } } }); Composite footerBtnComposite = new Composite(shell, SWT.RIGHT_TO_LEFT); footerBtnComposite.setLayout(new GridLayout(2, false)); copyToPathBtn = new Button(footerBtnComposite, SWT.NONE); copyToPathBtn.setText(BytecodeVisualizerMessages.JDI_Export_Dialog_copy_to_btn_text); copyToPathBtn.setEnabled(false); copyToPathBtn.addSelectionListener(new SelectionListener() { /* (non-Javadoc) * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) */ public void widgetSelected(SelectionEvent e) { final Object[] selection = viewer.getCheckedElements(); ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell); try { dialog.run(false, true, new IRunnableWithProgress() { public void run(final IProgressMonitor monitor) throws InvocationTargetException { monitor.beginTask(BytecodeVisualizerMessages.JDI_Export_Dialog_Export_Selected_Classes, selection.length + 1); for (Object o : selection) { String className = o.toString(); String[] nameArray = className.split(Pattern.quote(".")); IPath path = exportFolder.getFullPath(); try { for (int i = 0; i < nameArray.length - 1; i++) { path = path.append(nameArray[i]); createFolder(path, null); } path = path.append(nameArray[nameArray.length - 1]).addFileExtension("class"); monitor.subTask(className); byte[] content = getClassFileContent(className); createFile(path, content, null); monitor.worked(1); } catch (CoreException e1) { BytecodeVisualizerPlugin.getDefault().getLog() .log(BytecodeVisualizerPlugin.createErrorStatus(e1.getMessage(), e1)); } } monitor.subTask("Saving Sourcelookup ..."); JDIDebugElement jdiDebugElement = null; Object o1 = DebugUITools.getDebugContext(); if (o1 instanceof JDIDebugElement) { jdiDebugElement = (JDIDebugElement) o1; /* add to source lookup */ ISourceLocator sourceLocator = jdiDebugElement.getLaunch().getSourceLocator(); if (sourceLocator instanceof ISourceLookupDirector) { boolean folderExists = false; /* get source lookup entries */ ISourceLookupDirector sourceLookupDirector = (ISourceLookupDirector) sourceLocator; ISourceContainer[] sourceContainers = sourceLookupDirector .getSourceContainers(); List<ISourceContainer> listContainers = new ArrayList<ISourceContainer>( sourceContainers.length); for (ISourceContainer isc : sourceContainers) { /* check if source exists already in the source lookup */ if (isc instanceof FolderSourceContainer) { FolderSourceContainer fsc = (FolderSourceContainer) isc; IContainer ic = fsc.getContainer(); if (ic instanceof IFolder) { IFolder iFolder = (IFolder) ic; if (iFolder.equals(exportFolder)) { folderExists = true; break; } } } listContainers.add(isc); } if (!folderExists) { /* add the new source to the source lookup */ ISourceContainer exportFolderContainer = new FolderSourceContainer( exportFolder, false); listContainers.add(exportFolderContainer); sourceLookupDirector.setSourceContainers(listContainers .toArray(new ISourceContainer[listContainers.size()])); /* save the source lookup configuration */ try { ILaunchConfigurationWorkingCopy workingCopy = sourceLookupDirector .getLaunchConfiguration().getWorkingCopy(); workingCopy.setAttribute( ILaunchConfiguration.ATTR_SOURCE_LOCATOR_MEMENTO, sourceLookupDirector.getMemento()); workingCopy.setAttribute(ILaunchConfiguration.ATTR_SOURCE_LOCATOR_ID, sourceLookupDirector.getId()); workingCopy.doSave(); } catch (CoreException e1) { BytecodeVisualizerPlugin.getDefault().getLog() .log(BytecodeVisualizerPlugin.createErrorStatus(e1.getMessage(), e1)); } } } /* display source */ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow() .getActivePage(); SourceLookupManager.getDefault().displaySource(jdiDebugElement, page, true); monitor.worked(1); } monitor.done(); } }); } catch (InvocationTargetException e1) { BytecodeVisualizerPlugin.log(e1); } catch (InterruptedException e2) { BytecodeVisualizerPlugin.log(e2); } shell.close(); } /* (non-Javadoc) * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent) */ public void widgetDefaultSelected(SelectionEvent e) { } }); closeBtn = new Button(footerBtnComposite, SWT.NONE); closeBtn.setText(BytecodeVisualizerMessages.JDI_Export_Dialog_close_text); closeBtn.addSelectionListener(new SelectionListener() { /* (non-Javadoc) * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) */ public void widgetSelected(SelectionEvent e) { shell.close(); } /* (non-Javadoc) * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent) */ public void widgetDefaultSelected(SelectionEvent e) { } }); /* enable copy button if the export has been set */ pathText.addModifyListener(new ModifyListener() { /* (non-Javadoc) * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent) */ public void modifyText(ModifyEvent e) { /* Default text: <Define a folder to class export> */ if (!pathText.getText().startsWith("<")) { copyToPathBtn.setEnabled(true); } } }); }
From source file:com.drgarbage.bytecodevisualizer.compare.OpenClassFileAction.java
License:Apache License
/** * Opens a dialog with a list of classes from the current workspace. * The selected class is returned as a java element. * @return the java element or <code>null</null> * @see IJavaElement/* w ww.j a va 2s. co m*/ */ private IJavaElement selectJavaElement() { Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); FilteredItemsSelectionDialog dialog = new OpenTypeSelectionDialog(shell, false, new ProgressMonitorDialog(shell), SearchEngine.createWorkspaceScope(), IJavaSearchConstants.TYPE); dialog.setTitle(ClassFileMergeViewer.CLASS_FILE_MERGEVIEWER_TITLE); dialog.setMessage(BytecodeVisualizerMessages.Message_file_to_compare); int resultCode = dialog.open(); if (resultCode != IDialogConstants.OK_ID) { return null; } Object[] result = dialog.getResult(); if (result != null) { if (result.length != 0) { IJavaElement je = (IJavaElement) result[0]; return je; } } return null; }
From source file:com.drgarbage.controlflowgraphfactory.actions.ActionUtils.java
License:Apache License
/** * Save Diagram in file and open Editor. * @param path//from w w w . j a v a 2s .c om * @param parent * @param page * @param controlFlowGraphDiagram */ public static void saveDiagramInFileAndOpenEditor(IPath path, final Shell parent, final IWorkbenchPage page, final ControlFlowGraphDiagram controlFlowGraphDiagram, final boolean openGraphInEditor) { /* check file extension, if not equals to graph set again*/ if (!path.getFileExtension().endsWith(FileExtensions.GRAPH)) { path = path.addFileExtension(FileExtensions.GRAPH); } final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); ProgressMonitorDialog monitor = new ProgressMonitorDialog(parent); try { monitor.run(false, /* don't fork */ false, /* not cancelable */ new WorkspaceModifyOperation() { /* run this operation */ public void execute(final IProgressMonitor monitor) { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(out); oos.writeObject(controlFlowGraphDiagram); oos.close(); /* delete if exists */ if (file.exists()) { file.delete(false, monitor); } file.create(new ByteArrayInputStream(out.toByteArray()), /* contents */ true, /* keep saving, even if IFile is out of sync with the Workspace */ monitor); /* progress monitor */ } catch (StackOverflowError e) { //Messages.error(StackOverflowError.class.getName() + PreferencesMessages.ExceptionAdditionalMessage); ControlFlowFactoryPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, ControlFlowFactoryPlugin.PLUGIN_ID, StackOverflowError.class.getName(), e)); return; } catch (CoreException ce) { Messages.error( CoreException.class.getName() + CoreMessages.ExceptionAdditionalMessage); ControlFlowFactoryPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, ControlFlowFactoryPlugin.PLUGIN_ID, CoreException.class.getName(), ce)); return; } catch (IOException ioe) { Messages.error( IOException.class.getName() + CoreMessages.ExceptionAdditionalMessage); ControlFlowFactoryPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, ControlFlowFactoryPlugin.PLUGIN_ID, IOException.class.getName(), ioe)); return; } } }); } catch (InterruptedException ie) { Messages.error(InterruptedException.class.getName() + CoreMessages.ExceptionAdditionalMessage); ControlFlowFactoryPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, ControlFlowFactoryPlugin.PLUGIN_ID, InterruptedException.class.getName(), ie)); return; } catch (InvocationTargetException ite) { Messages.error(InvocationTargetException.class.getName() + CoreMessages.ExceptionAdditionalMessage); ControlFlowFactoryPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, ControlFlowFactoryPlugin.PLUGIN_ID, InvocationTargetException.class.getName(), ite)); return; } finally { monitor.close(); } /* open newly created file in the editor */ if (openGraphInEditor) { if (file != null && page != null) { try { /* close editor if already open for this file */ IEditorPart part = page.findEditor(new FileEditorInput(file)); if (part != null) page.closeEditor(part, false); IDE.openEditor(page, file, true); } catch (PartInitException e) { Messages.error(PartInitException.class.getName() + CoreMessages.ExceptionAdditionalMessage); ControlFlowFactoryPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, ControlFlowFactoryPlugin.PLUGIN_ID, PartInitException.class.getName(), e)); return; } } } else { showInPackageExplorer(file, false); } }
From source file:com.drgarbage.controlflowgraphfactory.actions.ActionUtils.java
License:Apache License
/** * Save a text content in a file and open an Editor. * @param path//from www .ja v a 2 s .com * @param parent * @param page * @param content */ public static void saveContentInFileAndOpenEditor(IPath path, final Shell parent, final IWorkbenchPage page, final String content, final boolean openEditor) { final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); ProgressMonitorDialog monitor = new ProgressMonitorDialog(parent); try { monitor.run(false, /* don't fork */ false, /* not cancelable */ new WorkspaceModifyOperation() { /* run this operation */ public void execute(final IProgressMonitor monitor) { try { /* delete if exists */ if (file.exists()) { file.delete(false, monitor); } file.create(new ByteArrayInputStream(content.getBytes()), /* contents */ true, /* keep saving, even if IFile is out of sync with the Workspace */ monitor); /* progress monitor */ } catch (StackOverflowError e) { //Messages.error(StackOverflowError.class.getName() + PreferencesMessages.ExceptionAdditionalMessage); ControlFlowFactoryPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, ControlFlowFactoryPlugin.PLUGIN_ID, StackOverflowError.class.getName(), e)); return; } catch (CoreException ce) { Messages.error( CoreException.class.getName() + CoreMessages.ExceptionAdditionalMessage); ControlFlowFactoryPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, ControlFlowFactoryPlugin.PLUGIN_ID, CoreException.class.getName(), ce)); return; } } }); } catch (InterruptedException ie) { Messages.error(InterruptedException.class.getName() + CoreMessages.ExceptionAdditionalMessage); ControlFlowFactoryPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, ControlFlowFactoryPlugin.PLUGIN_ID, InterruptedException.class.getName(), ie)); return; } catch (InvocationTargetException ite) { Messages.error(InvocationTargetException.class.getName() + CoreMessages.ExceptionAdditionalMessage); ControlFlowFactoryPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, ControlFlowFactoryPlugin.PLUGIN_ID, InvocationTargetException.class.getName(), ite)); return; } finally { monitor.close(); } /* open newly created file in the editor */ if (openEditor) { if (file != null && page != null) { try { /* close editor if already open for this file */ IEditorPart part = page.findEditor(new FileEditorInput(file)); if (part != null) page.closeEditor(part, false); IDE.openEditor(page, file, true); } catch (PartInitException e) { Messages.error(PartInitException.class.getName() + CoreMessages.ExceptionAdditionalMessage); ControlFlowFactoryPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, ControlFlowFactoryPlugin.PLUGIN_ID, PartInitException.class.getName(), e)); return; } } } else { showInPackageExplorer(file, false); } }
From source file:com.drgarbage.controlflowgraphfactory.editors.ControlFlowGraphEditor.java
License:Apache 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. j a va 2 s. c o 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) { Messages.error(CoreException.class.getName() + CoreMessages.ExceptionAdditionalMessage); ControlFlowFactoryPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, ControlFlowFactoryPlugin.PLUGIN_ID, CoreException.class.getName(), ce)); } catch (IOException ioe) { Messages.error( IOException.class.getName() + CoreMessages.ExceptionAdditionalMessage); ControlFlowFactoryPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, ControlFlowFactoryPlugin.PLUGIN_ID, IOException.class.getName(), ioe)); } } }); /* 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.drgarbage.visualgraphic.model.ControlFlowGraphDiagramFactory.java
License:Apache License
/** * Generates graphs for the given type.// w w w . j av a2s.c om * * @param shell * @param folder * @param type * @param graphType * @param createMonitor * @return Result: OK, YES_TO_ALL, NO_TO_ALL, ERROR, CANCELED * @throws CoreException * @throws InvocationTargetException * @throws InterruptedException * @throws IOException */ public static Result builAndSavedControlFlowDiagrams(final Shell shell, final IFolder folder, final IType type, final IGraphSpecification spec, boolean createMonitor) throws CoreException, InvocationTargetException, InterruptedException, IOException { final InputStream in = getInputStream(type); if (in == null) { String msg = MessageFormat.format(ControlFlowFactoryMessages.ClassFileInputNotCreated, new Object[] { type.getElementName() }); ControlFlowFactoryPlugin.getDefault().getLog() .log(new Status(IStatus.ERROR, ControlFlowFactoryPlugin.PLUGIN_ID, msg)); return Result.ERROR; } Result res = null; if (createMonitor) { ProgressMonitorDialog monitor = new ProgressMonitorDialog(shell); monitor.run(false, true, new WorkspaceModifyOperation() { /* * (non-Javadoc) * * @see * org.eclipse.ui.actions.WorkspaceModifyOperation#execute(org * .eclipse.core.runtime.IProgressMonitor) */ @Override protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { final int ticks = type.getMethods().length; monitor.beginTask(ControlFlowFactoryMessages.ProgressDialogCreateGraphs, ticks); try { generateControlFlowGraphs(monitor, folder, getElementName(type), in, spec); } catch (IOException e) { ControlFlowFactoryPlugin.getDefault().getLog().log( new Status(IStatus.ERROR, ControlFlowFactoryPlugin.PLUGIN_ID, e.getMessage(), e)); if (!spec.isSupressMessages()) { Messages.error(e.getMessage() + CoreMessages.ExceptionAdditionalMessage); } return; } catch (ControlFlowGraphException e) { ControlFlowFactoryPlugin.getDefault().getLog().log( new Status(IStatus.ERROR, ControlFlowFactoryPlugin.PLUGIN_ID, e.getMessage(), e)); if (!spec.isSupressMessages()) { Messages.error(e.getMessage() + CoreMessages.ExceptionAdditionalMessage); } return; } finally { monitor.done(); } } }); } else { try { res = generateControlFlowGraphs(null, folder, getElementName(type), in, spec); } catch (ControlFlowGraphException e) { ControlFlowFactoryPlugin.getDefault().getLog() .log(new Status(IStatus.ERROR, ControlFlowFactoryPlugin.PLUGIN_ID, e.getMessage(), e)); if (!spec.isSupressMessages()) { Messages.error(e.getMessage() + CoreMessages.ExceptionAdditionalMessage); } return Result.ERROR; } } return res; }