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.centurylink.mdw.plugin.server.WebLogicServerConfigurator.java
License:Apache License
public void doDeploy(Shell shell) { setShell(shell);//from w w w.ja v a2 s . c om deployOnly = true; try { ProgressMonitorDialog pmDialog = new MdwProgressMonitorDialog(shell); pmDialog.run(true, true, this); } catch (InvocationTargetException ex) { PluginMessages.uiError(shell, ex, "Server Deploy", getServerSettings().getProject()); } catch (InterruptedException ex) { PluginMessages.log(ex); MessageDialog.openWarning(shell, "Server Deploy", "Deployment cancelled"); } }
From source file:com.cloudbees.eclipse.run.ui.popup.actions.StartAction.java
License:Open Source License
/** * @see IActionDelegate#run(IAction)//from w w w.ja v a 2s. c o m */ @Override public void run(IAction action) { if (action instanceof ObjectPluginAction) { final ISelection selection = ((ObjectPluginAction) action).getSelection(); if (selection instanceof StructuredSelection) { try { ProgressMonitorDialog monitor = new ProgressMonitorDialog( Display.getCurrent().getActiveShell()); monitor.run(false, false, new IRunnableWithProgressImplementation(selection)); CloudBeesUIPlugin.getDefault().fireApplicationInfoChanged(); } catch (Exception e) { CBRunUiActivator.logError(e); } } } }
From source file:com.cloudbees.eclipse.run.ui.popup.actions.StopAction.java
License:Open Source License
/** * @see IActionDelegate#run(IAction)/* ww w . ja va 2 s .c om*/ */ @Override public void run(IAction action) { if (action instanceof ObjectPluginAction) { final ISelection selection = ((ObjectPluginAction) action).getSelection(); if (selection instanceof StructuredSelection) { ProgressMonitorDialog monitor = new ProgressMonitorDialog(Display.getCurrent().getActiveShell()); try { monitor.run(false, false, new IRunnableWithProgressImplementation(selection)); CloudBeesUIPlugin.getDefault().fireApplicationInfoChanged(); } catch (Exception e) { CBRunUiActivator.logError(e); } } } }
From source file:com.cloudbees.eclipse.ui.internal.preferences.GeneralPreferencePage.java
License:Open Source License
private void createCompositeLogin() { Group group = new Group(getFieldEditorParent(), SWT.SHADOW_ETCHED_IN); group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); GridLayout gl = new GridLayout(1, false); gl.marginLeft = 5;/* w w w . j ava2 s . co m*/ gl.marginRight = 5; gl.marginTop = 5; gl.marginBottom = 5; gl.horizontalSpacing = 5; group.setLayout(gl); Composite groupInnerComp = new Composite(group, SWT.NONE); groupInnerComp.setLayout(new GridLayout(2, false)); groupInnerComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); group.setText(Messages.pref_group_login); final StringFieldEditor fieldEmail = new StringFieldEditor(PreferenceConstants.P_EMAIL, Messages.pref_email, 30, groupInnerComp); fieldEmail.getTextControl(groupInnerComp).setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); addField(fieldEmail); final StringFieldEditor fieldPassword = new StringFieldEditor(PreferenceConstants.P_PASSWORD, Messages.pref_password, 30, groupInnerComp) { @Override protected void doLoad() { try { if (getTextControl() != null) { String value = CloudBeesUIPlugin.getDefault().readP(); getTextControl().setText(value); this.oldValue = value; } } catch (StorageException e) { // Ignore StorageException, very likely just // "No password provided." } } @Override protected void doStore() { try { CloudBeesUIPlugin.getDefault().storeP(getTextControl().getText()); } catch (Exception e) { CloudBeesUIPlugin.showError( "Saving password failed!\nPossible cause: Eclipse security master password is not set.", e); } } @Override protected void doFillIntoGrid(Composite parent, int numColumns) { super.doFillIntoGrid(parent, numColumns); getTextControl().setEchoChar('*'); } }; fieldPassword.getTextControl(groupInnerComp).setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); addField(fieldPassword); Composite signupAndValidateRow = new Composite(groupInnerComp, SWT.NONE); GridData signupRowData = new GridData(GridData.FILL_HORIZONTAL); signupRowData.horizontalSpan = 2; signupAndValidateRow.setLayoutData(signupRowData); GridLayout gl2 = new GridLayout(2, false); gl2.marginWidth = 0; gl2.marginHeight = 0; gl2.marginTop = 5; signupAndValidateRow.setLayout(gl2); createSignUpLink(signupAndValidateRow); Button b = new Button(signupAndValidateRow, SWT.PUSH); GridData validateButtonLayoutData = new GridData(GridData.HORIZONTAL_ALIGN_END); validateButtonLayoutData.widthHint = 75; b.setLayoutData(validateButtonLayoutData); b.setText(Messages.pref_validate_login); b.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { final String email = fieldEmail.getStringValue(); final String password = fieldPassword.getStringValue(); ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell()); try { dialog.run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) { try { monitor.beginTask("Validating CloudBees account...", 100); //TODO i18n monitor.subTask("Connecting...");//TODO i18n monitor.worked(10); GrandCentralService gcs = new GrandCentralService(); gcs.setAuthInfo(email, password); monitor.worked(20); monitor.subTask("Validating...");//TODO i18n final boolean loginValid = gcs.validateUser(monitor); monitor.worked(50); PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { public void run() { if (loginValid) { MessageDialog.openInformation( CloudBeesUIPlugin.getDefault().getWorkbench().getDisplay() .getActiveShell(), "Validation result", "Validation successful!");//TODO i18n } else { MessageDialog.openError( CloudBeesUIPlugin.getDefault().getWorkbench().getDisplay() .getActiveShell(), "Validation result", "Validation was not successful!\nWrong email or password?");//TODO i18n } } }); monitor.worked(20); } catch (CloudBeesException e1) { throw new RuntimeException(e1); } finally { monitor.done(); } } }); } catch (InvocationTargetException e1) { Throwable t1 = e1.getTargetException().getCause() != null ? e1.getTargetException().getCause() : e1.getTargetException(); Throwable t2 = t1.getCause() != null ? t1.getCause() : null; CloudBeesUIPlugin.showError("Failed to validate your account.", t1.getMessage(), t2); } catch (InterruptedException e1) { CloudBeesUIPlugin.showError("Failed to validate your account.", e1); } } }); }
From source file:com.drgarbage.ast.ASTPanel.java
License:Apache License
/** * Creates content for the tree viewer./* w ww .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. // www.j a v 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.controlflowgraphfactory.actions.ActionUtils.java
License:Apache License
/** * Save Diagram in file and open Editor. * @param path// ww w . ja v a 2 s . c o m * @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 w w w . j av a2 s . co m*/ * @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.visualgraphic.model.ControlFlowGraphDiagramFactory.java
License:Apache License
/** * Generates graphs for the given type./*from ww w. j a v a 2 s . c o m*/ * * @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; }
From source file:com.dubture.twig.ui.actions.TwigToggleLineCommentHandler.java
License:Open Source License
@Override protected void processAction(final ITextEditor textEditor, final IStructuredDocument document, ITextSelection textSelection) {//from w w w . j a va2 s .c o m IStructuredModel model = null; DocumentRewriteSession session = null; boolean changed = false; try { // get text selection lines info int selectionStartLine = textSelection.getStartLine(); int selectionEndLine = textSelection.getEndLine(); int selectionEndLineOffset = document.getLineOffset(selectionEndLine); int selectionEndOffset = textSelection.getOffset() + textSelection.getLength(); // adjust selection end line if ((selectionEndLine > selectionStartLine) && (selectionEndLineOffset == selectionEndOffset)) { selectionEndLine--; selectionEndLineOffset = document.getLineInformation(selectionEndLine).getOffset(); } int selectionStartLineOffset = document.getLineOffset(selectionStartLine); ITypedRegion[] lineTypedRegions = document.computePartitioning(selectionStartLineOffset, selectionEndLineOffset - selectionStartLineOffset); if (lineTypedRegions != null && lineTypedRegions.length >= 1 && (lineTypedRegions[0].getType().equals("org.eclipse.wst.html.HTML_DEFAULT") || lineTypedRegions[0].getType().equals("com.dubture.twig.TWIG_DEFAULT"))) { // save the selection position since it will be changing Position selectionPosition = null; selectionPosition = new Position(textSelection.getOffset(), textSelection.getLength()); document.addPosition(selectionPosition); model = StructuredModelManager.getModelManager().getModelForEdit(document); if (model != null) { // makes it so one undo will undo all the edits to the // document model.beginRecording(this, SSEUIMessages.ToggleComment_label, SSEUIMessages.ToggleComment_description); // keeps listeners from doing anything until updates are all // done model.aboutToChangeModel(); if (document instanceof IDocumentExtension4) { session = ((IDocumentExtension4) document) .startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED); } changed = true; // get the display for the editor if we can Display display = null; if (textEditor instanceof StructuredTextEditor) { StructuredTextViewer viewer = ((StructuredTextEditor) textEditor).getTextViewer(); if (viewer != null) { display = viewer.getControl().getDisplay(); } } // create the toggling operation IRunnableWithProgress toggleCommentsRunnable = new ToggleLinesRunnable( model.getContentTypeIdentifier(), document, selectionStartLine, selectionEndLine, display); // if toggling lots of lines then use progress monitor else // just // run the operation if ((selectionEndLine - selectionStartLine) > TOGGLE_LINES_MAX_NO_BUSY_INDICATOR && display != null) { ProgressMonitorDialog dialog = new ProgressMonitorDialog(display.getActiveShell()); dialog.run(false, true, toggleCommentsRunnable); } else { toggleCommentsRunnable.run(new NullProgressMonitor()); } } } else { org.eclipse.core.expressions.EvaluationContext evaluationContext = new org.eclipse.core.expressions.EvaluationContext( null, "") { @Override public Object getVariable(String name) { if (ISources.ACTIVE_EDITOR_NAME.equals(name)) { return textEditor; } return null; } }; org.eclipse.core.commands.ExecutionEvent executionEvent = new org.eclipse.core.commands.ExecutionEvent( null, Collections.EMPTY_MAP, new Event(), evaluationContext); toggleLineCommentHandler.execute(executionEvent); } } catch (InvocationTargetException e) { Logger.logException("Problem running toggle comment progess dialog.", e); //$NON-NLS-1$ } catch (InterruptedException e) { Logger.logException("Problem running toggle comment progess dialog.", e); //$NON-NLS-1$ } catch (BadLocationException e) { Logger.logException("The given selection " + textSelection + " must be invalid", e); //$NON-NLS-1$ //$NON-NLS-2$ } catch (ExecutionException e) { } finally { // clean everything up if (session != null && document instanceof IDocumentExtension4) { ((IDocumentExtension4) document).stopRewriteSession(session); } if (model != null) { model.endRecording(this); if (changed) { model.changedModel(); } model.releaseFromEdit(); } } }