List of usage examples for org.eclipse.jface.dialogs MessageDialog MessageDialog
public MessageDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage, int dialogImageType, int defaultIndex, String... dialogButtonLabels)
From source file:eu.modelwriter.marker.ui.internal.wizards.markallinwswizard.MarkAllInWsWizard.java
License:Open Source License
@Override public boolean performFinish() { final Object[] checkedElements = MarkAllInWsPage.checkboxTreeViewer.getCheckedElements(); final String text = this.textSelection.getText(); final String leader_id = UUID.randomUUID().toString(); boolean success = false; final Image image = MarkerActivator.getDefault().getImageRegistry() .get(MarkerActivator.Images.IMAGE_MODELWRITER_ID); final ProgressMonitorDialog pmd = new ProgressMonitorDialog( Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell()); ProgressMonitorDialog.setDefaultImage(image); pmd.open();//from w ww .ja v a2 s. com final IProgressMonitor pmdmoni = pmd.getProgressMonitor(); try { pmdmoni.beginTask("Marking", checkedElements.length); for (int i = 0; i < checkedElements.length && !pmdmoni.isCanceled(); i++) { try { if (checkedElements[i] instanceof IFile) { final IFile iFile = (IFile) checkedElements[i]; pmdmoni.subTask(iFile.getName()); pmdmoni.worked(1); if (!iFile.getFileExtension().equals("xmi") && !iFile.getFileExtension().equals("ecore") && !iFile.getFileExtension().equals("reqif")) { final String charSet = iFile.getCharset(); final Scanner scanner = new Scanner(iFile.getContents(), charSet); final IDocument document = new Document(scanner.useDelimiter("\\A").next()); scanner.close(); final String fullText = document.get(); boolean hasLeader = false; int index = 0; int offset = 0; final int lenght = this.textSelection.getLength(); final String id = UUID.randomUUID().toString(); if (lenght != 0) { while ((offset = fullText.indexOf(text, index)) != -1) { final TextSelection nextSelection = new TextSelection(document, offset, lenght); if (MarkerFactory.findMarkerByOffset(iFile, offset) == null) { final IMarker mymarker = MarkerFactory.createMarker(iFile, nextSelection); MarkUtilities.setGroupId(mymarker, id); if (!iFile.equals(this.file)) { if (hasLeader == false) { MarkUtilities.setLeaderId(mymarker, leader_id); hasLeader = true; } } else { if (this.textSelection.getOffset() == offset) { MarkUtilities.setLeaderId(mymarker, leader_id); } } this.addToAlloyXML(mymarker); AnnotationFactory.addAnnotation(mymarker, AnnotationFactory.ANNOTATION_MARKING); } index = offset + lenght; } } success = true; } else { final MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(), "Mark All In Workspace", null, iFile.getName() + " doesn't supported for this command.", MessageDialog.INFORMATION, new String[] { "OK" }, 0); dialog.open(); MarkAllInWsPage.checkboxTreeViewer.setChecked(iFile, false); } } } catch (final CoreException e) { e.printStackTrace(); } } } finally { pmdmoni.done(); } pmd.close(); if (success == true) { final MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(), "Mark All In Workspace", null, "Selected project(s) have been marked by selected text", MessageDialog.INFORMATION, new String[] { "OK" }, 0); dialog.open(); return true; } else { return false; } }
From source file:eu.modelwriter.marker.ui.internal.wizards.markerwizard.MarkerWizard.java
License:Open Source License
@Override public boolean performFinish() { AlloyOtherSolutionReasoning.getInstance().finish(); this.candidateToTypeChanging = new ArrayList<IMarker>(); if (MarkerPage.markTreeViewer.getTree().getSelection().length == 1) { if (MarkerPage.markTreeViewer.getTree().getSelection()[0].getText().endsWith("{abs}")) { final MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(), "Trace Type Information", null, "Selected type is not appropriate because it is marked as Abstact", MessageDialog.INFORMATION, new String[] { "OK" }, 0); dialog.open();/*from w w w . j a va 2 s . c om*/ return false; } if (!MarkerPage.markTreeViewer.getTree().getItems()[0] .equals(MarkerPage.markTreeViewer.getTree().getSelection()[0])) { if (this.selection != null) { CreateMarkerWithType.createMarker(this.file, this.selection, MarkerPage.markTreeViewer.getTree().getSelection()[0].getText()); // MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(), // "Marker Type Information", null, "Marker has been created with selected type", // MessageDialog.INFORMATION, new String[] {"OK"}, 0); // dialog.open(); } else { this.findCandidateToTypeChangingMarkers(this.selectedMarker); this.selectedMarker = AnnotationFactory.convertAnnotationType(this.selectedMarker, true, true, AlloyUtilities.getTotalTargetCount(this.selectedMarker)); IMarker marker = null; for (int i = 1; i < this.candidateToTypeChanging.size(); i++) { marker = this.candidateToTypeChanging.get(i); AnnotationFactory.convertAnnotationType(marker, true, MarkUtilities.compare(marker, this.selectedMarker), AlloyUtilities.getTotalTargetCount(marker)); } AlloyUtilities.removeAllRelationsOfMarker(this.selectedMarker); AlloyUtilities.removeRelationOfMarker(this.selectedMarker); if (MarkUtilities.getGroupId(this.selectedMarker) != null) { final List<IMarker> list = MarkerFactory.findMarkersByGroupId( this.selectedMarker.getResource(), MarkUtilities.getGroupId(this.selectedMarker)); for (final IMarker iMarker : list) { AlloyUtilities.removeTypeFromMarker(iMarker); MarkUtilities.setType(iMarker, MarkerPage.markTreeViewer.getTree().getSelection()[0].getText()); if (MarkUtilities.getLeaderId(iMarker) != null) { AlloyUtilities.addTypeToMarker(iMarker); } AlloyUtilities.addMarkerToRepository(this.selectedMarker); } } else { AlloyUtilities.removeTypeFromMarker(this.selectedMarker); MarkUtilities.setType(this.selectedMarker, MarkerPage.markTreeViewer.getTree().getSelection()[0].getText()); AlloyUtilities.addTypeToMarker(this.selectedMarker); AlloyUtilities.addMarkerToRepository(this.selectedMarker); } // MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(), // "Marker Type Information", null, "Selected type added to selected marker", // MessageDialog.INFORMATION, new String[] {"OK"}, 0); // dialog.open(); } return true; } else { final MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(), "Trace Type Information", null, "Please select a valid marker type.", MessageDialog.INFORMATION, new String[] { "OK" }, 0); dialog.open(); return false; } } else { final MessageDialog dialog = new MessageDialog(MarkerActivator.getShell(), "Trace Type Information", null, "Please select one trace type.", MessageDialog.INFORMATION, new String[] { "OK" }, 0); dialog.open(); return false; } }
From source file:eu.numberfour.n4js.product.N4JSApplication.java
License:Open Source License
/** * Return true if the argument directory is ok to use as a workspace and false otherwise. A version check will be * performed, and a confirmation box may be displayed on the argument shell if an older version is detected. * * @return true if the argument URL is ok to use as a workspace and false otherwise. *//*from w ww. ja va 2 s . c o m*/ private boolean checkValidWorkspace(final Shell shell, final URL url) { // a null url is not a valid workspace if (url == null) { return false; } if (WORKSPACE_CHECK_REFERENCE_BUNDLE_VERSION == null) { // no reference bundle installed, no check possible return true; } final Version version = readWorkspaceVersion(url); // if the version could not be read, then there is not any existing // workspace data to trample, e.g., perhaps its a new directory that // is just starting to be used as a workspace if (version == null) { return true; } final Version ide_version = toMajorMinorVersion(WORKSPACE_CHECK_REFERENCE_BUNDLE_VERSION); final Version workspace_version = toMajorMinorVersion(version); final int versionCompareResult = workspace_version.compareTo(ide_version); // equality test is required since any version difference (newer // or older) may result in data being trampled if (versionCompareResult == 0) { return true; } // At this point workspace has been detected to be from a version // other than the current ide version -- find out if the user wants // to use it anyhow. int severity; String title; String message; if (versionCompareResult < 0) { // Workspace < IDE. Update must be possible without issues, // so only inform user about it. severity = INFORMATION; title = IDEApplication_versionTitle_olderWorkspace; message = NLS.bind(IDEApplication_versionMessage_olderWorkspace, url.getFile()); } else { // Workspace > IDE. It must have been opened with a newer IDE version. // Downgrade might be problematic, so warn user about it. severity = WARNING; title = IDEApplication_versionTitle_newerWorkspace; message = NLS.bind(IDEApplication_versionMessage_newerWorkspace, url.getFile()); } final MessageDialog dialog = new MessageDialog(shell, title, null, message, severity, new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0); return dialog.open() == Window.OK; }
From source file:eu.numberfour.n4js.ui.export.AbstractExportToSingleFileWizardPage.java
License:Open Source License
/** * The default implementation of this <code>IOverwriteQuery</code> method asks the user whether the existing * resource at the given path should be overwritten. * * @param pathString/* ww w . j a va 2 s. c om*/ * the path of the archive * @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>, <code>"ALL"</code>, or * <code>"CANCEL"</code> */ @Override public String queryOverwrite(String pathString) { IPath path = Path.fromOSString(pathString); String messageString; // Break the message up if there is a file name and a directory // and there are at least 2 segments. if (path.getFileExtension() == null || path.segmentCount() < 2) { messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_existsQuestion, pathString); } else { messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_overwriteNameAndPathQuestion, path.lastSegment(), path.removeLastSegments(1).toOSString()); } final MessageDialog dialog = new MessageDialog(getContainer().getShell(), IDEWorkbenchMessages.Question, null, messageString, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL, IDialogConstants.CANCEL_LABEL }, 0) { @Override protected int getShellStyle() { return super.getShellStyle() | SWT.SHEET; } }; String[] response = new String[] { YES, ALL, NO, NO_ALL, CANCEL }; // run in syncExec because callback is from an operation, // which is probably not running in the UI thread. getControl().getDisplay().syncExec(new Runnable() { @Override public void run() { dialog.open(); } }); return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()]; }
From source file:eu.numberfour.n4js.ui.export.AbstractExportToSingleFileWizardPage.java
License:Open Source License
/** * Displays a Yes/No question to the user with the specified message and returns the user's response. * * @param message//from w ww. j a v a 2 s .co m * the question to ask * @return <code>true</code> for Yes, and <code>false</code> for No */ private boolean queryYesNoQuestion(String message) { MessageDialog dialog = new MessageDialog(getContainer().getShell(), IDEWorkbenchMessages.Question, (Image) null, message, MessageDialog.NONE, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0) { @Override protected int getShellStyle() { return super.getShellStyle() | SWT.SHEET; } }; return dialog.open() == 0; }
From source file:eu.numberfour.n4js.ui.preferences.N4JSBuilderPreferencePage.java
License:Open Source License
/** * This method has been copied and adapted from org.eclipse.xtext.ui.preferences.OptionsConfigurationBlock. *//* www . ja v a 2 s .c o m*/ @Override protected boolean processChanges(IWorkbenchPreferenceContainer container) { boolean needsBuild = !getPreferenceChanges().isEmpty() | projectSpecificChanged; boolean doBuild = false; if (needsBuild) { int count = getRebuildCount(); if (count > rebuildCount) { needsBuild = false; rebuildCount = count; } } if (needsBuild) { String[] strings = getFullBuildDialogStrings(project == null); if (strings != null) { MessageDialog dialog = new MessageDialog(this.getShell(), strings[0], null, strings[1], MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, 2); int res = dialog.open(); if (res == 0) { doBuild = true; } else if (res != 1) { return false; } } } if (container != null) { if (doBuild) { incrementRebuildCount(); container.registerUpdateJob(getBuildJob(getProject())); } } else { if (doBuild) { getBuildJob(getProject()).schedule(); } } return true; }
From source file:eu.scasefp7.eclipse.servicecomposition.toolbar.FillToolbar.java
/** * <h1>fillToolBar</h1>Add buttons to the toolbar. *///from ww w. j av a 2s. c om public static void fillToolBar(ServiceCompositionView view) { ZoomContributionViewItem toolbarZoomContributionViewItem = new ZoomContributionViewItem(view); IActionBars bars = view.getViewSite().getActionBars(); final Shell shell = view.getSite().getWorkbenchWindow().getShell(); final Display disp = shell.getDisplay(); bars.getMenuManager().add(toolbarZoomContributionViewItem); runWorkflowAction = new Action("Run workflow") { public void run() { try { // clean outputs // cleanOutputs(); RunWorkflow run = new RunWorkflow(view, view.getTreeViewer(), view.getColumnb(), view.getAuthParamsComposite(), view.getRequestHeaderComposite()); run.runWorkflow(); } catch (Exception e) { Activator.log("Error while running the workflow", e); e.printStackTrace(); } } }; runWorkflowAction.setImageDescriptor(getImageDescriptor("icons/run.png")); newWorkflowAction = new Action("Create a new workflow") { public void run() { try { if (view.getSavedWorkflow()) { // clean outputs Utils.cleanOutputs(view.getOutputsComposite(), view.getJungGraph()); CreateWorkflow.createNewWorkflow(view); } else { if (view.jungGraphHasOperations()) { MessageDialog dialog = new MessageDialog(shell, "Workflow is not saved", null, "This workflow is not saved. Would you like to save it before creating a new one?", MessageDialog.QUESTION_WITH_CANCEL, new String[] { "Yes", "No", "Cancel" }, 0); int result = dialog.open(); System.out.println(result); if (result == 0) { IStatus status = checkGraph(view.getJungGraph(), disp); if (status.getMessage().equalsIgnoreCase("OK")) { if (view.getWorkflowFilePath().isEmpty()) { SaveOpen.saveWorkflow(true, view.getWorkflowFilePath(), view); } else { SaveOpen.saveWorkflow(false, view.getWorkflowFilePath(), view); } } // clean outputs Utils.cleanOutputs(view.getOutputsComposite(), view.getJungGraph()); view.clearMatchedInputs(); CreateWorkflow.createNewWorkflow(view); } else if (result == 1) { // clean outputs Utils.cleanOutputs(view.getOutputsComposite(), view.getJungGraph()); view.clearMatchedInputs(); CreateWorkflow.createNewWorkflow(view); } } else { CreateWorkflow.createNewWorkflow(view); } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }; newWorkflowAction.setImageDescriptor(getImageDescriptor("icons/New File.png")); displayCostAction = new Action("Display total cost, trial period, licenses") { public void run() { try { // clean outputs DisplayCost.displayCost(view); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }; displayCostAction.setImageDescriptor(getImageDescriptor("icons/copyrights.png")); generateCodeAction = new Action("Generate RESTful java project of the workflow.") { public void run() { try { IStatus status = checkGraph(view.getJungGraph(), disp); if (status.getMessage().equalsIgnoreCase("OK")) { newProject = new GenerateUpload(view); newProject.generate(); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }; generateCodeAction.setImageDescriptor(getImageDescriptor("icons/java.png")); saveWorkflowAction = new Action("Save the workflow.") { public void run() { try { IStatus status = checkGraph(view.getJungGraph(), disp); if (status.getMessage().equalsIgnoreCase("OK")) { if (view.getWorkflowFilePath().isEmpty()) { SaveOpen.saveWorkflow(true, view.getWorkflowFilePath(), view); } else { SaveOpen.saveWorkflow(false, view.getWorkflowFilePath(), view); } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }; saveWorkflowAction.setImageDescriptor(getImageDescriptor("icons/save.png")); openWorkflowAction = new Action("Open a workflow file.") { public void run() { try { if (view.getSavedWorkflow()) { view.clearMatchedInputs(); SaveOpen.openWorkflow(view); } else { if (view.jungGraphHasOperations()) { MessageDialog dialog = new MessageDialog(shell, "Workflow is not saved", null, "This workflow is not saved. Would you like to save it before creating a new one?", MessageDialog.QUESTION_WITH_CANCEL, new String[] { "Yes", "No", "Cancel" }, 0); int result = dialog.open(); System.out.println(result); if (result == 0) { IStatus status = checkGraph(view.getJungGraph(), disp); if (status.getMessage().equalsIgnoreCase("OK")) { if (view.getWorkflowFilePath().isEmpty()) { SaveOpen.saveWorkflow(true, view.getWorkflowFilePath(), view); } else { SaveOpen.saveWorkflow(false, view.getWorkflowFilePath(), view); } } view.clearMatchedInputs(); SaveOpen.openWorkflow(view); } else if (result == 1) { view.clearMatchedInputs(); SaveOpen.openWorkflow(view); } } else { SaveOpen.openWorkflow(view); } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }; openWorkflowAction.setImageDescriptor(getImageDescriptor("icons/open.png")); reloadWorkflowAction = new Action("Reload storyboard file.") { public void run() { try { ReloadStoryboard.reloadStoryboard(disp, shell, view, view.getStoryboardFile()); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }; reloadWorkflowAction.setImageDescriptor(getImageDescriptor("icons/reload_storyboard.png")); Action uploadOnServerAction = new Action("Upload RESTful web service on server.") { public void run() { try { newProject.install(); } catch (Exception e) { e.printStackTrace(); } } }; uploadOnServerAction.setImageDescriptor(getImageDescriptor("icons/database.png")); IToolBarManager mgr = view.getViewSite().getActionBars().getToolBarManager(); mgr.add(newWorkflowAction); mgr.add(openWorkflowAction); mgr.add(saveWorkflowAction); mgr.add(runWorkflowAction); mgr.add(generateCodeAction); mgr.add(uploadOnServerAction); mgr.add(displayCostAction); mgr.add(reloadWorkflowAction); }
From source file:ext.org.eclipse.jdt.internal.ui.javadocexport.JavadocWizard.java
License:Open Source License
private void setAllJavadocLocations(IJavaProject[] projects, URL newURL) { Shell shell = getShell();//from www . j a v a 2s .com String[] buttonlabels = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL }; for (int j = 0; j < projects.length; j++) { IJavaProject iJavaProject = projects[j]; String message = Messages.format(JavadocExportMessages.JavadocWizard_updatejavadoclocation_message, new String[] { BasicElementLabels.getJavaElementName(iJavaProject.getElementName()), BasicElementLabels.getPathLabel(fDestination, true) }); MessageDialog dialog = new MessageDialog(shell, JavadocExportMessages.JavadocWizard_updatejavadocdialog_label, null, message, MessageDialog.QUESTION, buttonlabels, 1); switch (dialog.open()) { case YES: JavaUI.setProjectJavadocLocation(iJavaProject, newURL); break; case YES_TO_ALL: for (int i = j; i < projects.length; i++) { iJavaProject = projects[i]; JavaUI.setProjectJavadocLocation(iJavaProject, newURL); j++; } break; case NO_TO_ALL: j = projects.length; break; case NO: default: break; } } }
From source file:ext.org.eclipse.jdt.internal.ui.preferences.BuildPathsPropertyPage.java
License:Open Source License
@Override public boolean okToLeave() { if (fBuildPathsBlock != null && fBuildPathsBlock.hasChangesInDialog()) { String title = PreferencesMessages.BuildPathsPropertyPage_unsavedchanges_title; String message = PreferencesMessages.BuildPathsPropertyPage_unsavedchanges_message; String[] buttonLabels = new String[] { PreferencesMessages.BuildPathsPropertyPage_unsavedchanges_button_save, PreferencesMessages.BuildPathsPropertyPage_unsavedchanges_button_discard, PreferencesMessages.BuildPathsPropertyPage_unsavedchanges_button_ignore }; MessageDialog dialog = new MessageDialog(getShell(), title, null, message, MessageDialog.QUESTION, buttonLabels, 0);// w ww . j av a 2s .c om int res = dialog.open(); if (res == 0) { //save fBlockOnApply = true; performOk(); } else if (res == 1) { // discard fBuildPathsBlock.init(JavaCore.create(getProject()), null, null); } else { // keep unsaved } } return super.okToLeave(); }
From source file:ext.org.eclipse.jdt.internal.ui.preferences.OptionsConfigurationBlock.java
License:Open Source License
protected boolean processChanges(IWorkbenchPreferenceContainer container) { IScopeContext currContext = fLookupOrder[0]; List<Key> changedOptions = new ArrayList<Key>(); boolean needsBuild = getChanges(currContext, changedOptions); if (changedOptions.isEmpty()) { return true; }/*w w w . ja va 2s .c o m*/ if (needsBuild) { int count = getRebuildCount(); if (count > fRebuildCount) { needsBuild = false; // build already requested fRebuildCount = count; } } boolean doBuild = false; if (needsBuild) { String[] strings = getFullBuildDialogStrings(fProject == null); if (strings != null) { MessageDialog dialog = new MessageDialog(getShell(), strings[0], null, strings[1], MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, 2); int res = dialog.open(); if (res == 0) { doBuild = true; } else if (res != 1) { return false; // cancel pressed } } } if (container != null) { // no need to apply the changes to the original store: will be done by the page container if (doBuild) { // post build incrementRebuildCount(); container.registerUpdateJob(CoreUtility.getBuildJob(fProject)); } } else { // apply changes right away try { fManager.applyChanges(); } catch (BackingStoreException e) { JavaPlugin.log(e); return false; } if (doBuild) { CoreUtility.getBuildJob(fProject).schedule(); } } return true; }