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:ext.org.eclipse.jdt.internal.ui.refactoring.reorg.DeleteAction.java
License:Open Source License
/** * Removes or hides the selected working sets. * //from w w w . j a v a 2 s . c om * @param selection the selected working sets * @since 3.5 */ private void deleteWorkingSets(IStructuredSelection selection) { MessageDialog dialog; if (selection.size() == 1) { IWorkingSet workingSet = (IWorkingSet) selection.getFirstElement(); final String workingSetID = workingSet.getId(); dialog = new MessageDialog(getShell(), ReorgMessages.DeleteWorkingSet_single, null, MessageFormat.format(ReorgMessages.DeleteWorkingSet_removeorhideworkingset_single, new Object[] { workingSet.getLabel() }), MessageDialog.QUESTION, new String[] { ReorgMessages.DeleteWorkingSet_Hide, ReorgMessages.DeleteWorkingSet_Remove, IDialogConstants.CANCEL_LABEL }, 0) { /* * @see org.eclipse.jface.dialogs.MessageDialog#createButton(org.eclipse.swt.widgets.Composite, int, java.lang.String, boolean) * @since 3.5 */ @Override protected Button createButton(Composite parent, int id, String label, boolean defaultButton) { Button button = super.createButton(parent, id, label, defaultButton); if (id == REMOVE_BUTTON && IWorkingSetIDs.OTHERS.equals(workingSetID)) button.setEnabled(false); return button; } }; } else { dialog = new MessageDialog(getShell(), ReorgMessages.DeleteWorkingSet_multiple, null, MessageFormat.format(ReorgMessages.DeleteWorkingSet_removeorhideworkingset_multiple, new Object[] { new Integer(selection.size()) }), MessageDialog.QUESTION, new String[] { ReorgMessages.DeleteWorkingSet_Hide, ReorgMessages.DeleteWorkingSet_Remove, IDialogConstants.CANCEL_LABEL }, 0); } int dialogResponse = dialog.open(); if (dialogResponse == REMOVE_BUTTON) { Iterator<?> iter = selection.iterator(); IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager(); while (iter.hasNext()) { IWorkingSet workingSet = (IWorkingSet) iter.next(); if (!(IWorkingSetIDs.OTHERS.equals(workingSet.getId()))) manager.removeWorkingSet(workingSet); } } else if (dialogResponse == HIDE_BUTTON) { IWorkbenchPage page = JavaPlugin.getActivePage(); if (page != null) { IWorkbenchPart activePart = page.getActivePart(); if (activePart instanceof PackageExplorerPart) { PackageExplorerPart packagePart = (PackageExplorerPart) activePart; WorkingSetModel model = packagePart.getWorkingSetModel(); List<IWorkingSet> activeWorkingSets = new ArrayList<IWorkingSet>( Arrays.asList(model.getActiveWorkingSets())); activeWorkingSets.removeAll(SelectionUtil.toList(selection)); model.setActiveWorkingSets( activeWorkingSets.toArray(new IWorkingSet[activeWorkingSets.size()])); } } } }
From source file:ext.org.eclipse.jdt.internal.ui.text.java.CompletionProposalComputerRegistry.java
License:Open Source License
/** * Log the status and inform the user about a misbehaving extension. * * @param descriptor the descriptor of the misbehaving extension * @param status a status object that will be logged */// ww w . jav a 2 s.co m 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<String> 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) { @Override protected Control createCustomArea(Composite parent) { Link link = new Link(parent, SWT.NONE); link.setText(avoidHint); link.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { PreferencesUtil .createPreferenceDialogOn(getShell(), "org.eclipse.jdt.ui.preferences.CodeAssistPreferenceAdvanced", null, null) //$NON-NLS-1$ .open(); } }); GridData gridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false); gridData.widthHint = this.getMinimumMessageWidth(); link.setLayoutData(gridData); return link; } }; dialog.open(); }
From source file:ext.org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.AddFolderToBuildpathAction.java
License:Open Source License
/** * {@inheritDoc}/*from ww w . j a va2 s . c o m*/ */ @Override public void run() { try { final IJavaProject project; Object object = getSelectedElements().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 = getShell(); final boolean removeProjectFromClasspath; IPath outputLocation = project.getOutputLocation(); final IPath defaultOutputLocation = outputLocation.makeRelative(); final IPath newDefaultOutputLocation; final boolean removeOldClassFiles; IPath projPath = project.getProject().getFullPath(); if (!(getSelectedElements().size() == 1 && getSelectedElements().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(getSelectedElements(), 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, BasicElementLabels.getPathLabel(projPath, false)); 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<IJavaElement> result = addToClasspath(getSelectedElements(), project, newDefaultOutputLocation.makeAbsolute(), removeProjectFromClasspath, removeOldClassFiles, monitor); selectAndReveal(new StructuredSelection(result)); } catch (CoreException e) { throw new InvocationTargetException(e); } } }; fContext.run(false, false, runnable); } catch (final InvocationTargetException e) { if (e.getCause() instanceof CoreException) { showExceptionDialog((CoreException) e.getCause(), NewWizardMessages.AddSourceFolderToBuildpathAction_ErrorTitle); } else { JavaPlugin.log(e); } } catch (final InterruptedException e) { } } catch (CoreException e) { showExceptionDialog(e, NewWizardMessages.AddSourceFolderToBuildpathAction_ErrorTitle); } }
From source file:ext.org.eclipse.jdt.internal.ui.wizards.buildpaths.VariableBlock.java
License:Open Source License
public boolean performOk() { ArrayList<String> removedVariables = new ArrayList<String>(); ArrayList<String> changedVariables = new ArrayList<String>(); removedVariables.addAll(Arrays.asList(JavaCore.getClasspathVariableNames())); // remove all unchanged List<CPVariableElement> changedElements = fVariablesList.getElements(); for (int i = changedElements.size() - 1; i >= 0; i--) { CPVariableElement curr = changedElements.get(i); if (curr.isReadOnly()) { changedElements.remove(curr); } else {//from ww w . j a va 2s. co 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 { PlatformUI.getWorkbench().getProgressService().runInUI(dialog, runnable, ResourcesPlugin.getWorkspace().getRoot()); } 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:fable.framework.toolbox.FableUtils.java
License:Open Source License
/** * Displays an question MessageDialog.//from w ww . j a va2 s .co m * * @param message * The question to ask. * @return 0 if the user presses OK button, 1 for Cancel, 2 for No. */ public static int questionMsg(final String message) { String[] buttons = { "OK", "Cancel", "No" }; MessageDialog dialog = new MessageDialog(null, "Question", null, message, MessageDialog.QUESTION, buttons, 0); return dialog.open(); }
From source file:fr.gouv.mindef.safran.database.ui.actions.AbstractScaffoldHandler.java
License:Open Source License
public Object execute(ExecutionEvent event) throws ExecutionException { ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection(); shell = HandlerUtil.getActiveShell(event); if (selection instanceof StructuredSelection) { StructuredSelection structuredSelection = (StructuredSelection) selection; if (structuredSelection.size() == 2) { ScaffoldInfo existingScaffoldInfo = getExistingScaffoldModel(structuredSelection); if (existingScaffoldInfo != null) { MessageDialog dlg = new MessageDialog(shell, "Existing scaffold model found", null, "A scaffold model already exists for these objects in file " + existingScaffoldInfo.eResource().getURI().toPlatformString(true) + "\n\nWhat do you want to do ?", MessageDialog.QUESTION_WITH_CANCEL, new String[] { "Use existing scaffold", "Create a new scaffold", "Cancel" }, 0); int btn = dlg.open(); if (btn == CANCEL) { return null; } else if (btn == CREATE_NEW_SCAFFOLD) { executeScaffoldingWizard(structuredSelection); } else if (btn == USE_EXISTING_SCAFFOLD) { executeFromScaffoldModel(existingScaffoldInfo); }/*from w ww . j av a 2 s . co m*/ } else { executeScaffoldingWizard(structuredSelection); } } else if (structuredSelection.size() == 1) { executeFromScaffoldModel(structuredSelection); } } return null; }
From source file:fr.inria.atlanmod.collaboro.ui.wizards.NewLocalCollaboroProjectWizard.java
License:Open Source License
@Override public boolean performFinish() { final String projectName = newProjectPage.getProjectName(); WorkspaceModifyOperation operation = new WorkspaceModifyOperation() { @Override// www . ja v a 2 s .c o m protected void execute(IProgressMonitor progressMonitor) { progressMonitor.beginTask("Creating Collaboro Project", 10); progressMonitor.subTask("Registering packages"); ResourceSet rset = new ResourceSetImpl(); rset.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Controller.HISTORY_EXTENSION, new EcoreResourceFactoryImpl()); rset.getPackageRegistry().put(HistoryPackage.eNS_URI, HistoryPackage.eINSTANCE); rset.getPackageRegistry().put(NotationPackage.eNS_URI, NotationPackage.eINSTANCE); rset.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Controller.MODEL_EXTENSION, new EcoreResourceFactoryImpl()); rset.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Controller.NOTATION_EXTENSION, new EcoreResourceFactoryImpl()); rset.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Controller.ECORE_EXTENSION, new EcoreResourceFactoryImpl()); progressMonitor.worked(1); progressMonitor.subTask("Creating the project"); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject(projectName); try { project.create(progressMonitor); project.open(progressMonitor); } catch (Exception e) { e.printStackTrace(); MessageDialog dialog = new MessageDialog(getShell(), "Error", null, "Error when creating the project in the workspace", MessageDialog.ERROR, new String[] { "OK" }, 0); dialog.open(); progressMonitor.done(); return; } IFolder modelsFolder = project.getFolder("models"); try { modelsFolder.create(true, true, progressMonitor); } catch (Exception e) { e.printStackTrace(); MessageDialog dialog = new MessageDialog(getShell(), "Error", null, "Error when creating the folder 'models' in the project", MessageDialog.ERROR, new String[] { "OK" }, 0); dialog.open(); progressMonitor.done(); return; } IFolder examplesFolder = project.getFolder("examples"); try { examplesFolder.create(true, true, progressMonitor); } catch (Exception e) { e.printStackTrace(); MessageDialog dialog = new MessageDialog(getShell(), "Error", null, "Error when creating the folder 'examples' in the project", MessageDialog.ERROR, new String[] { "OK" }, 0); dialog.open(); progressMonitor.done(); return; } progressMonitor.worked(1); progressMonitor.subTask("Creating initial Collaboro model"); History historyModel = createInitialHistoryModel(); List<User> users = newUsersPage.getUsers(); if (users != null) historyModel.getUsers().addAll(users); URI collaboroFile = URI.createPlatformResourceURI( modelsFolder.getFullPath().toString() + File.separator + projectName + ".history", true); Resource collaboroRes = rset.createResource(collaboroFile); collaboroRes.getContents().add(historyModel); try { collaboroRes.save(null); } catch (Exception exception) { exception.printStackTrace(); MessageDialog dialog = new MessageDialog(getShell(), "Error", null, "Error when creating initial Collaboro model", MessageDialog.ERROR, new String[] { "OK" }, 0); dialog.open(); progressMonitor.done(); return; } progressMonitor.worked(1); progressMonitor.subTask("Creating initial Ecore model"); EPackage ePackage = createInitiaEcorePackage(projectName); URI ePackageFile = URI.createPlatformResourceURI( modelsFolder.getFullPath().toString() + File.separator + projectName + ".ecore", true); Resource ePackageRes = rset.createResource(ePackageFile); ePackageRes.getContents().add(ePackage); try { ePackageRes.save(null); } catch (Exception exception) { exception.printStackTrace(); MessageDialog dialog = new MessageDialog(getShell(), "Error", null, "Error when creating initial Ecore model", MessageDialog.ERROR, new String[] { "OK" }, 0); dialog.open(); progressMonitor.done(); return; } progressMonitor.worked(1); progressMonitor.subTask("Creating initial Notation model"); Definition notation = createInitiaNotationModel(); URI notationFile = URI.createPlatformResourceURI( modelsFolder.getFullPath().toString() + File.separator + projectName + ".notation", true); Resource notationRes = rset.createResource(notationFile); notationRes.getContents().add(notation); try { notationRes.save(null); } catch (Exception exception) { exception.printStackTrace(); MessageDialog dialog = new MessageDialog(getShell(), "Error", null, "Error when creating initial Notation model", MessageDialog.ERROR, new String[] { "OK" }, 0); dialog.open(); progressMonitor.done(); return; } progressMonitor.worked(6); progressMonitor.done(); } }; try { getContainer().run(false, false, operation); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } return true; }
From source file:fr.inria.linuxtools.internal.tmf.ui.project.wizards.tracepkg.importexport.ImportTracePackageWizardPage.java
License:Open Source License
private int promptForOverwrite(String traceName) { final MessageDialog dialog = new MessageDialog(getContainer().getShell(), null, null, MessageFormat.format(Messages.ImportTracePackageWizardPage_AlreadyExists, traceName), MessageDialog.QUESTION, new String[] { IDialogConstants.NO_TO_ALL_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.YES_LABEL, }, 3) {//from w w w .j a v a 2s .c om @Override protected int getShellStyle() { return super.getShellStyle() | SWT.SHEET; } }; return dialog.open(); }
From source file:fr.inria.soctrace.tools.ocelotl.ui.views.OcelotlView.java
License:Open Source License
/** * Set the cache strategy depending on the selected policy TODO Take the * operator into account/*from w w w.j av a 2s .c o m*/ */ public void setCachePolicy() { if (hasChanged != HasChanged.ALL) return; switch (ocelotlParameters.getOcelotlSettings().getCachePolicy()) { case CACHEPOLICY_FAST: ocelotlParameters.getDataCache().setBuildingStrategy(DatacacheStrategy.DATACACHE_PROPORTIONAL); break; case CACHEPOLICY_SLOW: ocelotlParameters.getDataCache().setBuildingStrategy(DatacacheStrategy.DATACACHE_DATABASE); break; case CACHEPOLICY_ASK: String[] dialogButtonLabels = { "Precise", "Fast", "Automatic" }; MessageDialog choosePolicy = new MessageDialog(getSite().getShell(), "Choose a cache policy", null, "Please choose one of the following methods for cache rebuilding:", MessageDialog.NONE, dialogButtonLabels, 0); int choice = choosePolicy.open(); if (choice == 0) { ocelotlParameters.getDataCache().setBuildingStrategy(DatacacheStrategy.DATACACHE_DATABASE); break; } else if (choice == 1) { ocelotlParameters.getDataCache().setBuildingStrategy(DatacacheStrategy.DATACACHE_PROPORTIONAL); break; } case CACHEPOLICY_AUTO: // TODO implement auto (decision taken when computing ratio) ocelotlParameters.getDataCache().setBuildingStrategy(DatacacheStrategy.DATACACHE_PROPORTIONAL); break; default: break; } }
From source file:gda.rcp.views.NudgePositionerComposite.java
License:Open Source License
private void move(double position) throws DeviceException { boolean batonHeld = JythonServerFacade.getInstance().isBatonHeld(); if (!batonHeld) { MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(), "Baton not held", null, "You do not hold the baton, please take the baton using the baton manager.", MessageDialog.ERROR, new String[] { "Ok" }, 0); dialog.open();/*from w w w. ja v a2s . co m*/ } else if (!limitsSet || (position >= lowerLimit && position <= upperLimit) && moveEnabled) NudgePositionerComposite.this.scannable.asynchronousMoveTo(position); }