List of usage examples for org.eclipse.jface.dialogs MessageDialog open
public int open()
From source file:eu.scasefp7.eclipse.servicecomposition.toolbar.FillToolbar.java
/** * <h1>fillToolBar</h1>Add buttons to the toolbar. *//*from w w w.j a va 2 s . 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.dialogs.OptionalMessageDialog.java
License:Open Source License
/** * Opens the dialog but only if the user hasn't chosen to hide it. * * @return the index of the pressed button or {@link SWT#DEFAULT} if the dialog got dismissed * without pressing a button (e.g. via Esc) or {{@link #NOT_SHOWN} if the dialog was not * shown//from w w w. j a va 2s. c o m */ public static int open(String id, Shell parent, String title, Image titleImage, String message, int dialogType, String[] buttonLabels, int defaultButtonIndex, String checkboxText) { if (!isDialogEnabled(id)) return OptionalMessageDialog.NOT_SHOWN; MessageDialog dialog = new OptionalMessageDialog(id, parent, title, titleImage, message, dialogType, buttonLabels, defaultButtonIndex, checkboxText); return dialog.open(); }
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 w ww.j a v a2 s . co m*/ 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);//from ww w .j a v a 2 s . c o m 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; }/*from w ww . ja v a 2 s .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; }
From source file:ext.org.eclipse.jdt.internal.ui.refactoring.reorg.DeleteAction.java
License:Open Source License
/** * Removes or hides the selected working sets. * /* w ww . j av a 2 s .c o m*/ * @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 *//*from w ww .j av a2 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 w w w . j av a 2 s.c om */ @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 {//w w w . ja v a 2s .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 { 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 v a2s . c o 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(); }