List of usage examples for org.eclipse.jface.dialogs ProgressMonitorDialog ProgressMonitorDialog
public ProgressMonitorDialog(Shell parent)
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) {// w w w .ja va 2 s . co 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(); } } }
From source file:com.ebmwebsourcing.petals.common.extensions.internal.wizards.JavaToWSDLWizardPage.java
License:Open Source License
/** * Open a dialog to select a class.//from www . ja v a 2s .c o m */ private void openClassSelectionDialog() { if (this.javaProject == null) return; Shell shell = this.classText.getShell(); IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { this.javaProject }, IJavaSearchScope.SOURCES | IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.REFERENCED_PROJECTS); String filter = this.classText.getText().trim(); filter = filter.length() == 0 ? "?" : filter; try { SelectionDialog dlg = JavaUI.createTypeDialog(shell, new ProgressMonitorDialog(shell), scope, IJavaElementSearchConstants.CONSIDER_INTERFACES, true, filter); if (dlg.open() == Window.OK) { IType type = (IType) dlg.getResult()[0]; String selection = type.getFullyQualifiedName(); this.classText.setText(selection); this.classText.setSelection(selection.length()); } } catch (JavaModelException e) { PetalsCommonWsdlExtPlugin.log(e, IStatus.ERROR); } }
From source file:com.ebmwebsourcing.petals.common.internal.formeditor.JbiFormEditor.java
License:Open Source License
@Override public void doSave(IProgressMonitor monitor) { // Do the work within an operation because this is a long running // activity that modifies the workbench. WorkspaceModifyOperation operation = new WorkspaceModifyOperation() { @Override/*w ww. j av a2s .c om*/ public void execute(IProgressMonitor monitor) { // Delegate the save part to the personality handler getPersonality().saveModel(JbiFormEditor.this.jbiModel, JbiFormEditor.this.editedFile, JbiFormEditor.this.editDomain); } }; try { new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation); ((BasicCommandStack) getEditingDomain().getCommandStack()).saveIsDone(); firePropertyChange(IEditorPart.PROP_DIRTY); } catch (Exception exception) { PetalsCommonPlugin.log(exception, IStatus.ERROR); } }
From source file:com.ebmwebsourcing.petals.components.drivers.ZipUrlInputDialog.java
License:Open Source License
@Override protected void okPressed() { // Parse the jbi.xml of the URL ProgressMonitorDialog dlg = new ProgressMonitorDialog(getShell()); dlg.setOpenOnRun(true);//from w w w .j av a2 s. c o m try { dlg.run(true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { // To report progression and support cancellation, the parsing is made in another thread final AtomicBoolean isParsed = new AtomicBoolean(false); Thread parsingThread = new Thread() { @Override public void run() { try { URI uri = UriAndUrlHelper.urlToUri(getValue()); ZipUrlInputDialog.this.slProperties = ArtifactArchiveUtils .getSharedLibraryVersion(uri); } catch (InvalidJbiXmlException e) { PetalsComponentsPlugin.log(e, IStatus.ERROR); } finally { isParsed.set(true); } } }; try { monitor.beginTask("", IProgressMonitor.UNKNOWN); parsingThread.start(); while (!isParsed.get()) { Thread.sleep(500); monitor.worked(2); // Cancelled operation? Let the thread finish its job... if (monitor.isCanceled()) { ZipUrlInputDialog.this.cancelled = true; break; } } } finally { monitor.done(); } } }); } catch (InvocationTargetException e) { PetalsComponentsPlugin.log(e, IStatus.ERROR); } catch (InterruptedException e) { // nothing } // Close the dialog super.okPressed(); }
From source file:com.ecfeed.serialization.export.TestCasesExporter.java
License:Open Source License
public void runExportWithProgress(MethodNode method, Collection<TestCaseNode> testCases, OutputStream outputStream, boolean fromGui) { ExportRunnable exportRunnable = new ExportRunnable(method, testCases, outputStream); try {//from www . j a v a 2 s.c o m if (fromGui) { ProgressMonitorDialog progressMonitorDialog = new ProgressMonitorDialog( EclipseHelper.getActiveShell()); progressMonitorDialog.run(true, true, exportRunnable); } else { exportRunnable.run(null); } } catch (InvocationTargetException e) { ExceptionHelper.reportRuntimeException(e.getMessage()); } catch (InterruptedException e) { } }
From source file:com.ecfeed.ui.dialogs.CoverageCalculator.java
License:Open Source License
public boolean calculateCoverage() { // CurrentlyChangedCases are null if deselection left no test cases selected, // hence we can just clear tuple map and set results to 0 if (fCurrentlyChangedCases == null) { for (Map<List<OrderedChoice>, Integer> tupleMap : fTuples) { tupleMap.clear();// w ww .j a v a2 s.c o m } // set results to zero resetResults(); fCurrentlyChangedCases = new ArrayList<>(); return true; } else { ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(Display.getDefault().getActiveShell()); try { CalculatorRunnable runnable = new CalculatorRunnable(); progressDialog.open(); progressDialog.run(true, true, runnable); if (runnable.isCanceled) { return false; } else { fCurrentlyChangedCases.clear(); return true; } } catch (InvocationTargetException e) { MessageDialog.openError(Display.getDefault().getActiveShell(), "Exception", "Invocation: " + e.getCause()); return false; } catch (InterruptedException e) { MessageDialog.openError(Display.getDefault().getActiveShell(), "Exception", "Interrupted: " + e.getMessage()); e.printStackTrace(); return false; } } }
From source file:com.ecfeed.ui.modelif.OnlineTestRunningSupport.java
License:Open Source License
private void runNonParametrizedTest() { try {// ww w . jav a 2s.co m IRunnableWithProgress operation = new NonParametrizedTestRunnable(); new ProgressMonitorDialog(Display.getCurrent().getActiveShell()).run(true, true, operation); MessageDialog.openInformation(null, "Test case executed correctly", "The execution of " + getTargetMethod().toString() + " has been succesful"); } catch (InvocationTargetException | InterruptedException | RuntimeException e) { MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.DIALOG_TEST_EXECUTION_PROBLEM_TITLE, e.getMessage()); } }
From source file:com.ecfeed.ui.modelif.StaticTestExecutionSupport.java
License:Open Source License
public void proceed() { PrintStream currentOut = System.out; ConsoleManager.displayConsole();// www. j a v a2 s . c o m ConsoleManager.redirectSystemOutputToStream(ConsoleManager.getOutputStream()); try { fFailedTests.clear(); ProgressMonitorDialog dialog = new ProgressMonitorDialog(Display.getCurrent().getActiveShell()); dialog.open(); dialog.run(true, true, new ExecuteRunnable()); } catch (InvocationTargetException e) { MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.DIALOG_TEST_EXECUTION_PROBLEM_TITLE, e.getTargetException().getMessage()); } catch (InterruptedException e) { MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.DIALOG_TEST_EXECUTION_PROBLEM_TITLE, e.getMessage()); } if (fFailedTests.size() > 0) { String message = "Following tests were not successfull\n\n"; for (TestCaseNode testCase : fFailedTests) { message += testCase.toString() + "\n"; } MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.DIALOG_TEST_EXECUTION_REPORT_TITLE, message); } displayTestStatusDialog(); System.setOut(currentOut); }
From source file:com.example.app.bootstrapper.Application.java
License:Open Source License
private boolean installNewFeature() throws ProvisionException { /*//ww w . jav a2 s .com * Check to make sure that we are not restarting after an update. If we * are, then there is no need to check for updates again. */ final IPreferenceStore prefStore = Activator.getDefault().getPreferenceStore(); if (prefStore.getBoolean(JUSTUPDATED)) { prefStore.setValue(JUSTUPDATED, false); return false; } final IProvisioningAgent agent = this.getProvisioningAgent(); /* * Create a runnable to execute the update. We'll show a dialog during * the process and then return when the runnable is complete. */ final boolean[] restartRequired = new boolean[] { false }; IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { IStatus installStatus = doInstallOperation(agent, monitor); if (installStatus.getSeverity() != IStatus.ERROR) { prefStore.setValue(JUSTUPDATED, true); restartRequired[0] = true; } else { log(installStatus); } } }; /* * Execute the runnable and wait for it to complete. */ try { new ProgressMonitorDialog(null).run(true, true, runnable); return restartRequired[0]; } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { } return false; }
From source file:com.exploitpack.scanner.ShowDialog.java
License:Open Source License
@Override public Object execute(ExecutionEvent event) throws ExecutionException { ProgressMonitorDialog dialog = new ProgressMonitorDialog(HandlerUtil.getActiveShell(event).getShell()); try {// ww w .j a v a2s .co m dialog.run(true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) { monitor.beginTask("Doing something timeconsuming here", 100); for (int i = 0; i < 10; i++) { if (monitor.isCanceled()) return; monitor.subTask("I'm doing something here " + i); sleep(1000); // worked increates the monitor, the values is added to the existing ones monitor.worked(1); } monitor.done(); } }); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } return null; }