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:descent.internal.ui.text.java.CompletionProposalComputerRegistry.java
License:Open Source License
/** * Log the status and inform the user about a misbehaving extension. * //from w ww . j av a2 s . c o m * @param descriptor the descriptor of the misbehaving extension * @param status a status object that will be logged */ void informUser(CompletionProposalComputerDescriptor descriptor, IStatus status) { JavaPlugin.log(status); String title = JavaTextMessages.CompletionProposalComputerRegistry_error_dialog_title; CompletionProposalCategory category = descriptor.getCategory(); IContributor culprit = descriptor.getContributor(); Set affectedPlugins = getAffectedContributors(category, culprit); final String avoidHint; final String culpritName = culprit == null ? null : culprit.getName(); if (affectedPlugins.isEmpty()) avoidHint = Messages.format(JavaTextMessages.CompletionProposalComputerRegistry_messageAvoidanceHint, new Object[] { culpritName, category.getDisplayName() }); else avoidHint = Messages.format( JavaTextMessages.CompletionProposalComputerRegistry_messageAvoidanceHintWithWarning, new Object[] { culpritName, category.getDisplayName(), toString(affectedPlugins) }); String message = status.getMessage(); // inlined from MessageDialog.openError MessageDialog dialog = new MessageDialog(JavaPlugin.getActiveWorkbenchShell(), title, null /* default image */, message, MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0) { protected Control createCustomArea(Composite parent) { Link link = new Link(parent, SWT.NONE); link.setText(avoidHint); link.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { PreferencesUtil.createPreferenceDialogOn(getShell(), "descent.ui.preferences.CodeAssistPreferenceAdvanced", null, null).open(); //$NON-NLS-1$ } }); GridData gridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false); gridData.widthHint = this.getMinimumMessageWidth(); link.setLayoutData(gridData); return link; } }; dialog.open(); }
From source file:descent.internal.ui.wizards.buildpaths.BuildPathsBlock.java
License:Open Source License
public static IRemoveOldBinariesQuery getRemoveOldBinariesQuery(final Shell shell) { return new IRemoveOldBinariesQuery() { public boolean doQuery(final IPath oldOutputLocation) throws OperationCanceledException { final int[] res = new int[] { 1 }; Display.getDefault().syncExec(new Runnable() { public void run() { Shell sh = shell != null ? shell : JavaPlugin.getActiveWorkbenchShell(); String title = NewWizardMessages.BuildPathsBlock_RemoveBinariesDialog_title; String message = Messages.format( NewWizardMessages.BuildPathsBlock_RemoveBinariesDialog_description, oldOutputLocation.toString()); MessageDialog dialog = new MessageDialog(sh, title, null, message, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, 0);/* w w w . ja v a2s .c o m*/ res[0] = dialog.open(); } }); if (res[0] == 0) { return true; } else if (res[0] == 1) { return false; } throw new OperationCanceledException(); } }; }
From source file:descent.internal.ui.wizards.buildpaths.newsourcepage.AddFolderToBuildpathAction.java
License:Open Source License
/** * {@inheritDoc}// w ww . jav a 2s . c om */ public void run() { try { final IJavaProject project; Object object = fSelectedElements.get(0); if (object instanceof IJavaProject) { project = (IJavaProject) object; } else if (object instanceof IPackageFragment) { project = ((IPackageFragment) object).getJavaProject(); } else { IFolder folder = (IFolder) object; project = JavaCore.create(folder.getProject()); if (project == null) return; } final Shell shell = fSite.getShell() != null ? fSite.getShell() : JavaPlugin.getActiveWorkbenchShell(); final boolean removeProjectFromClasspath; IPath outputLocation = project.getOutputLocation(); final IPath defaultOutputLocation = outputLocation.makeRelative(); final IPath newDefaultOutputLocation; final boolean removeOldClassFiles; IPath projPath = project.getProject().getFullPath(); if (!(fSelectedElements.size() == 1 && fSelectedElements.get(0) instanceof IJavaProject) && //if only the project should be added, then the query does not need to be executed (outputLocation.equals(projPath) || defaultOutputLocation.segmentCount() == 1)) { final OutputFolderQuery outputFolderQuery = ClasspathModifierQueries.getDefaultFolderQuery(shell, defaultOutputLocation); if (outputFolderQuery.doQuery(true, ClasspathModifier.getValidator(fSelectedElements, project), project)) { newDefaultOutputLocation = outputFolderQuery.getOutputLocation(); removeProjectFromClasspath = outputFolderQuery.removeProjectFromClasspath(); if (BuildPathsBlock.hasClassfiles(project.getProject()) && outputLocation.equals(projPath)) { String title = NewWizardMessages.BuildPathsBlock_RemoveBinariesDialog_title; String message = Messages.format( NewWizardMessages.BuildPathsBlock_RemoveBinariesDialog_description, projPath.toString()); MessageDialog dialog = new MessageDialog(shell, title, null, message, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, 0); int answer = dialog.open(); if (answer == 0) { removeOldClassFiles = true; } else if (answer == 1) { removeOldClassFiles = false; } else { return; } } else { removeOldClassFiles = false; } } else { return; } } else { removeProjectFromClasspath = false; removeOldClassFiles = false; newDefaultOutputLocation = defaultOutputLocation; } try { final IRunnableWithProgress runnable = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { List result = addToClasspath(fSelectedElements, project, newDefaultOutputLocation.makeAbsolute(), removeProjectFromClasspath, removeOldClassFiles, monitor); selectAndReveal(new StructuredSelection(result)); } catch (CoreException e) { throw new InvocationTargetException(e); } } }; PlatformUI.getWorkbench().getProgressService().run(true, false, runnable); } catch (final InvocationTargetException e) { if (e.getCause() instanceof CoreException) { showExceptionDialog((CoreException) e.getCause()); } else { JavaPlugin.log(e); } } catch (final InterruptedException e) { } } catch (CoreException e) { showExceptionDialog(e); } }
From source file:descent.internal.ui.wizards.buildpaths.VariableBlock.java
License:Open Source License
public boolean performOk() { ArrayList removedVariables = new ArrayList(); ArrayList changedVariables = new ArrayList(); removedVariables.addAll(Arrays.asList(JavaCore.getClasspathVariableNames())); // remove all unchanged List changedElements = fVariablesList.getElements(); for (int i = changedElements.size() - 1; i >= 0; i--) { CPVariableElement curr = (CPVariableElement) changedElements.get(i); if (curr.isReserved()) { changedElements.remove(curr); } else {//from w w w.j a va2 s .c o m IPath path = curr.getPath(); IPath prevPath = JavaCore.getClasspathVariable(curr.getName()); if (prevPath != null && prevPath.equals(path)) { changedElements.remove(curr); } else { changedVariables.add(curr.getName()); } } removedVariables.remove(curr.getName()); } int steps = changedElements.size() + removedVariables.size(); if (steps > 0) { boolean needsBuild = false; if (fAskToBuild && doesChangeRequireFullBuild(removedVariables, changedVariables)) { String title = NewWizardMessages.VariableBlock_needsbuild_title; String message = NewWizardMessages.VariableBlock_needsbuild_message; MessageDialog buildDialog = new MessageDialog(getShell(), title, null, message, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, 2); int res = buildDialog.open(); if (res != 0 && res != 1) { return false; } needsBuild = (res == 0); } final VariableBlockRunnable runnable = new VariableBlockRunnable(removedVariables, changedElements); final ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell()); try { dialog.run(true, true, runnable); } catch (InvocationTargetException e) { ExceptionHandler.handle(new InvocationTargetException(new NullPointerException()), getShell(), NewWizardMessages.VariableBlock_variableSettingError_titel, NewWizardMessages.VariableBlock_variableSettingError_message); return false; } catch (InterruptedException e) { return false; } if (needsBuild) { CoreUtility.getBuildJob(null).schedule(); } } return true; }
From source file:distributed.plugin.ui.actions.ProcessActions.java
License:Open Source License
boolean validateSavedGraph(GraphEditor editor) { if (editor.isDirty()) { MessageDialog messageBox;/*from w ww . j av a 2s . co m*/ Shell parent = getWorkbenchPart().getSite().getShell(); String[] btnText = { "No", "Cancel", "Yes" }; messageBox = new MessageDialog(parent, "Save", null, "Graph has been modified. Do you want to save it?", MessageDialog.QUESTION, btnText, 2); messageBox.open(); int ans = messageBox.getReturnCode(); if (ans == 0) return true; else if (ans == 1) return false; else if (ans == 2) { // TODO might need to put progress monitor IProgressMonitor monitor = null; editor.doSave(monitor); return true; } else return false; } else return true; }
From source file:eclipse.spellchecker.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 . j ava 2s . com*/ 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) { if (ResourcesPlugin.getWorkspace().getRoot().getProjects().length == 0) { doBuild = true; // don't bother the user } else { 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) { Activator.log(e); return false; } if (doBuild) { CoreUtility.getBuildJob(fProject).schedule(); } } return true; }
From source file:edu.pitt.dbmi.odie.ui.editors.analysis.ProposalsSection.java
License:Apache License
private void hookMyListeners() { ontologyTree.getViewer().addSelectionChangedListener(new ISelectionChangedListener() { @Override/*from ww w . ja va 2 s . com*/ public void selectionChanged(SelectionChangedEvent event) { if (ontologyTree.getViewer().getSelection().isEmpty()) { remButton.setEnabled(false); // noteButton.setEnabled(false); } else { remButton.setEnabled(true); List<IClass> items = ((StructuredSelection) ontologyTree.getViewer().getSelection()).toList(); if (items.size() == 1) { // bioportalButton.setEnabled(true); IClass cl = items.get(0); // noteButton.setEnabled(!GeneralUtils.isProxyClass(cl)); } else { // noteButton.setEnabled(false); } } } }); addButton.addSelectionListener(new SelectionListener() { @Override public void widgetDefaultSelected(SelectionEvent e) { handleSelection(); } private void handleSelection() { GeneralUtils .addToProposalOntologyWithDialog(((AnalysisEditorInput) editor.getEditorInput()).analysis); ontologyTree.refresh(); } @Override public void widgetSelected(SelectionEvent e) { handleSelection(); } }); remButton.addSelectionListener(new SelectionListener() { @Override public void widgetDefaultSelected(SelectionEvent e) { handleSelection(); } private void handleSelection() { if (ontologyTree.getViewer().getSelection().isEmpty()) return; List<IClass> items = ((StructuredSelection) ontologyTree.getViewer().getSelection()).toList(); String itemNames = ""; if (items.size() > 0) itemNames = "the selected concepts"; else itemNames = "'" + (items.get(0)).getName() + "'"; IOntology ontology = items.get(0).getOntology(); if (MessageDialog.openQuestion(Display.getCurrent().getActiveShell(), "Remove Concept", "Are you sure you want to remove " + itemNames)) { for (IClass item : items) item.delete(); try { ontology.save(); Analysis analysis = ((AnalysisEditorInput) editor.getEditorInput()).getAnalysis(); GeneralUtils.refreshProposalLexicalSet(analysis); ontologyTree.refresh(); } catch (IOntologyException e) { e.printStackTrace(); GeneralUtils.showErrorDialog("Error", e.getMessage()); } } } @Override public void widgetSelected(SelectionEvent e) { handleSelection(); } }); shareButton.addSelectionListener(new SelectionListener() { @Override public void widgetDefaultSelected(SelectionEvent e) { } @Override public void widgetSelected(SelectionEvent e) { final Shell dialog = new Shell(GeneralUtils.getShell(), SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM); dialog.setText("Share"); dialog.setLayout(new GridLayout(3, true)); final Label label = new Label(dialog, SWT.NONE); label.setText("Select the community to contribute to"); GridData gd = new GridData(); gd.horizontalSpan = 3; gd.horizontalAlignment = SWT.LEFT; label.setLayoutData(gd); Button bioportalButton = new Button(dialog, SWT.PUSH); bioportalButton.setText("Bioportal"); gd = new GridData(); gd.horizontalAlignment = SWT.CENTER; bioportalButton.setLayoutData(gd); Button neuroLexButton = new Button(dialog, SWT.PUSH); neuroLexButton.setText("NeuroLex Wiki"); gd = new GridData(); gd.horizontalAlignment = SWT.CENTER; neuroLexButton.setLayoutData(gd); Button buttonCancel = new Button(dialog, SWT.PUSH); buttonCancel.setText("Cancel"); gd = new GridData(); gd.horizontalAlignment = SWT.CENTER; buttonCancel.setLayoutData(gd); dialog.pack(); Aesthetics.centerDialog(dialog); neuroLexButton.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { if (MessageDialog.openQuestion(GeneralUtils.getShell(), "Share on NeuroLex Wiki", "Do you want to create a new wiki page for the concept in the NeuroLex Wiki?")) { List<IClass> items = ((StructuredSelection) ontologyTree.getViewer().getSelection()) .toList(); if (items.size() > 0) { IClass newc = items.get(0); String urlString = ODIEConstants.NEUROLEX_WIKI_CREATE_PAGE_PREFIX + newc.getName(); try { GeneralUtils.openURL(new URL(urlString)); } catch (MalformedURLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } dialog.close(); } } @Override public void widgetDefaultSelected(SelectionEvent e) { // TODO Auto-generated method stub } }); buttonCancel.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { dialog.close(); } @Override public void widgetDefaultSelected(SelectionEvent e) { // TODO Auto-generated method stub } }); bioportalButton.addSelectionListener(new SelectionListener() { @Override public void widgetDefaultSelected(SelectionEvent e) { handleSelection(); dialog.close(); } private void handleSelection() { if (ontologyTree.getViewer().getSelection().isEmpty()) { GeneralUtils.showErrorDialog("No Concept Selected", "Please select a new proposal concept to be suggested in the Bioportal Note"); return; } List<IClass> items = ((StructuredSelection) ontologyTree.getViewer().getSelection()) .toList(); if (items.size() > 0) { IClass newc = items.get(0); String bpURIStr = (String) newc .getPropertyValue(newc.getOntology().getProperty(IProperty.RDFS_IS_DEFINED_BY)); if (bpURIStr != null) { GeneralUtils.showErrorDialog("Concept already in Bioportal", newc.getName() + " is already part of an existing Bioportal " + "ontology. Please select a newly created concept to be submitted as a Bioportal note"); return; } IProperty p = newc.getOntology().getProperty(ODIEConstants.BIOPORTAL_NOTE_ID_PROPERTY); IProperty op = newc.getOntology() .getProperty(ODIEConstants.BIOPORTAL_ONTOLOGY_ID_PROPERTY); if (p != null) { String noteid = (String) newc.getPropertyValue(p); String ontologyid = (String) newc.getPropertyValue(op); if (noteid != null && ontologyid != null) { MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(), "Bioportal note already exists", null, "A bioportal note was previously created for this concept.", MessageDialog.INFORMATION, new String[] { "View in Bioportal", IDialogConstants.OK_LABEL }, 0); int index = dialog.open(); if (index == 0) { String url = BioPortalRepository.DEFAULT_BIOPORTAL_URL + ontologyid + "/?noteid=" + noteid; try { GeneralUtils.openURL(new URL(url)); } catch (MalformedURLException e) { e.printStackTrace(); } } return; } } Analysis analysis = ((AnalysisEditorInput) editor.getEditorInput()).getAnalysis(); MiddleTier mt = Activator.getDefault().getMiddleTier(); BioportalNewProposalNoteWizard wizard = new BioportalNewProposalNoteWizard(analysis, newc); WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), wizard); dialog.open(); } } @Override public void widgetSelected(SelectionEvent e) { handleSelection(); dialog.close(); } }); dialog.open(); } }); exportButton.addSelectionListener(new SelectionListener() { @Override public void widgetDefaultSelected(SelectionEvent e) { handleSelection(); } private void handleSelection() { GeneralUtils.exportOntologyToCSVWithDialog((IOntology) ontologyTree.getViewer().getInput()); } @Override public void widgetSelected(SelectionEvent e) { handleSelection(); } }); }
From source file:edu.toronto.cs.se.modelepedia.petrinet.operator.PetriNetSimulate.java
License:Open Source License
@Override public EList<Model> execute(EList<Model> actualParameters) throws Exception { // simulate//from w ww .jav a 2s .c om PetriNet petrinet = (PetriNet) actualParameters.get(0).getEMFInstanceRoot(); boolean goodResult = !petrinet.getNodes().isEmpty(); // show result Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); int dialogType = (goodResult) ? MessageDialog.INFORMATION : MessageDialog.ERROR; String dialogMessage = (goodResult) ? "Good simulation result" : "Bad simulation result"; MessageDialog dialog = new MessageDialog(shell, "Simulation results", null, dialogMessage, dialogType, new String[] { "Ok" }, 0); dialog.open(); return null; }
From source file:edu.tsinghua.lumaqq.ui.helper.ShellLauncher.java
License:Open Source License
/** * ??/*from w ww . j a v a2s . c o m*/ * * @param url * URL * @param title * ? * @param errorString * ? */ public void openBrowserShell(String url, String title, String errorString) { // ????? String browser = main.getOptionHelper().getBrowser(); try { if (browser.equals("")) { MessageDialog dialog = new MessageDialog(main.getShell(), message_box_common_question_title, null, message_box_browser_not_set, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, 0); switch (dialog.open()) { case 0: main.getShellLauncher().openSystemOptionWindow().setCurrentPage(SystemOptionWindow.OTHER); break; case 1: BrowserShell bs = ShellFactory.createBrowserShell(main); bs.setUrl(url); bs.setTitle(title); bs.open(); break; } } else Runtime.getRuntime().exec(browser.replaceAll("\\[URL\\]", url)); } catch (Throwable t) { MessageDialog.openWarning(main.getShell(), message_box_common_warning_title, errorString); } }
From source file:edu.tsinghua.lumaqq.ui.MainShell.java
License:Open Source License
/** * // w w w . j av a 2 s . c o m * * @param e */ public void onDiskDownload(IStructuredSelection s) { if (s.isEmpty()) return; Object obj = s.getFirstElement(); if (obj instanceof File) { File f = (File) obj; DirectoryDialog dialog = new DirectoryDialog(getShell()); String dir = dialog.open(); if (dir != null) { // ? if (!dir.endsWith(java.io.File.separator)) dir += java.io.File.separatorChar; java.io.File diskfile = new java.io.File(dir + f.name); boolean resume = false; if (diskfile.exists()) { MessageDialog msg = new MessageDialog(getShell(), message_box_common_question_title, null, NLS.bind(message_box_resume_file, diskfile.getAbsolutePath()), MessageDialog.QUESTION, new String[] { button_resume, button_overwrite, button_cancel }, 0); switch (msg.open()) { case 0: resume = true; break; case 1: resume = false; break; default: return; } } // if (f.owner == 0) return; diskJobQueue.addJob(new DownloadFileJob(f, dir, resume)); } } }