Example usage for org.eclipse.jface.dialogs MessageDialog open

List of usage examples for org.eclipse.jface.dialogs MessageDialog open

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs MessageDialog open.

Prototype

public int open() 

Source Link

Document

Opens this window, creating it first if it has not yet been created.

Usage

From source file:de.uni_koeln.ub.drc.ui.handlers.ExitHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow activeWorkbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
    EditView ev = (EditView) activeWorkbenchWindow.getActivePage().findView(EditView.ID);
    if (ev != null && ev.isDirty()) {
        MessageDialog dialog = new MessageDialog(ev.getSite().getShell(), Messages.get().SavePage, null,
                Messages.get().CurrentPageModified, MessageDialog.CONFIRM,
                new String[] { IDialogConstantsHelper.getYesLabel(), IDialogConstantsHelper.getNoLabel() }, 0);
        dialog.create();/*from   ww w . ja va2  s . c  om*/
        if (dialog.open() == Window.OK) {
            ev.doSave(new NullProgressMonitor());
        }
    }
    // SessionContextSingleton.getInstance().exit();
    return PlatformUI.getWorkbench().close();
}

From source file:de.uni_koeln.ub.drc.ui.views.EditView.java

License:Open Source License

private void attachSelectionListener() {
    ISelectionService selectionService = (ISelectionService) getSite().getService(ISelectionService.class);
    ScrolledCompositeHelper.fixWrapping(sc, editComposite);
    selectionService.addSelectionListener(new ISelectionListener() {
        @Override//from  w ww  .  j av  a2 s .  c o m
        public void selectionChanged(IWorkbenchPart part, ISelection selection) {
            IStructuredSelection structuredSelection = (IStructuredSelection) selection;
            if (structuredSelection.getFirstElement() instanceof Page) {
                @SuppressWarnings("unchecked")
                List<Page> pages = structuredSelection.toList();
                if (pages != null && pages.size() > 0) {
                    Page page = pages.get(0);
                    if (dirtyable) {
                        MessageDialog dialog = new MessageDialog(editComposite.getShell(),
                                Messages.get().SavePage, null, Messages.get().CurrentPageModified,
                                MessageDialog.CONFIRM, new String[] { IDialogConstantsHelper.getYesLabel(),
                                        IDialogConstantsHelper.getNoLabel() },
                                0);
                        dialog.create();
                        if (dialog.open() == Window.OK) {
                            doSave(new NullProgressMonitor());
                        }
                    }
                    editComposite.update(page);
                    sc.setMinHeight(editComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
                    if (page.id().equals(SessionContextSingleton.getInstance().getCurrentUser().latestPage())) {
                        focusLatestWord();
                    }
                }
            }
        }
    });

}

From source file:de.walware.ecommons.debug.ui.UnterminatedLaunchAlerter.java

License:Open Source License

@Override
public boolean preShutdown(final IWorkbench workbench, final boolean forced) {
    final ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
    final List<ILaunchConfigurationType> programTypes = new LinkedList<ILaunchConfigurationType>();
    synchronized (gMutex) {
        for (final String id : fLauchTypeIds) {
            final ILaunchConfigurationType programType = manager.getLaunchConfigurationType(id);
            if (programType != null) {
                programTypes.add(programType);
            }/*from w  w w .j  a  va 2s . c  om*/
        }
    }
    if (programTypes.isEmpty()) {
        return true;
    }

    final Set<ILaunchConfigurationType> stillRunningTypes = new HashSet<ILaunchConfigurationType>();
    int count = 0;
    final ILaunch launches[] = manager.getLaunches();
    for (final ILaunch launch : launches) {
        ILaunchConfigurationType configType;
        ILaunchConfiguration config;
        try {
            config = launch.getLaunchConfiguration();
            if (config == null) {
                continue;
            }
            configType = config.getType();
        } catch (final CoreException e) {
            continue;
        }
        if (programTypes.contains(configType) && !launch.isTerminated()) {
            count++;
            stillRunningTypes.add(configType);
        }
    }
    if (stillRunningTypes.isEmpty()) {
        return true;
    }

    final StringBuilder names = new StringBuilder(stillRunningTypes.size() * 20);
    names.append('\n');
    for (final ILaunchConfigurationType type : stillRunningTypes) {
        names.append("- "); //$NON-NLS-1$
        names.append(type.getName());
        names.append('\n');
    }
    final String message = NLS.bind(Messages.UnterminatedLaunchAlerter_WorkbenchClosing_message,
            new Object[] { count, names });
    if (forced) {
        MessageDialog.openWarning(UIAccess.getDisplay().getActiveShell(),
                Messages.UnterminatedLaunchAlerter_WorkbenchClosing_title, message);
        return true;
    } else {
        final MessageDialog dialog = new MessageDialog(UIAccess.getDisplay().getActiveShell(),
                Messages.UnterminatedLaunchAlerter_WorkbenchClosing_title, null, message, MessageDialog.WARNING,
                new String[] { Messages.UnterminatedLaunchAlerter_WorkbenchClosing_button_Continue,
                        Messages.UnterminatedLaunchAlerter_WorkbenchClosing_button_Cancel, },
                1);
        final int answer = dialog.open();
        if (answer == 1) {
            return false;
        }
        return true;
    }
}

From source file:descent.internal.ui.dialogs.OptionalMessageDialog.java

License:Open Source License

/**
 * Opens the dialog but only if the user hasn't choosen to hide it.
 * Returns <code>NOT_SHOWN</code> if the dialog was not shown.
 *//*from   w  w  w. ja  v  a2 s.co m*/
public static int open(String id, Shell parent, String title, Image titleImage, String message, int dialogType,
        String[] buttonLabels, int defaultButtonIndex) {
    if (!isDialogEnabled(id))
        return OptionalMessageDialog.NOT_SHOWN;

    MessageDialog dialog = new OptionalMessageDialog(id, parent, title, titleImage, message, dialogType,
            buttonLabels, defaultButtonIndex);
    return dialog.open();
}

From source file:descent.internal.ui.preferences.BuildPathsPropertyPage.java

License:Open Source License

public void setVisible(boolean visible) {
    if (fBuildPathsBlock != null) {
        if (!visible) {
            if (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);
                int res = dialog.open();
                if (res == 0) {
                    performOk();/*from   w  w  w .j  a v a2s. c o m*/
                } else if (res == 1) {
                    fBuildPathsBlock.init(JavaCore.create(getProject()), null, null);
                } else {
                    // keep unsaved
                }
            }
        } else {
            if (!fBuildPathsBlock.hasChangesInDialog() && fBuildPathsBlock.hasChangesInClasspathFile()) {
                fBuildPathsBlock.init(JavaCore.create(getProject()), null, null);
            }
        }
    }
    super.setVisible(visible);
}

From source file:descent.internal.ui.preferences.OptionsConfigurationBlock.java

License:Open Source License

protected boolean processChanges(IWorkbenchPreferenceContainer container) {
    IScopeContext currContext = fLookupOrder[0];

    List /* <Key>*/ changedOptions = new ArrayList();
    boolean needsBuild = getChanges(currContext, changedOptions);
    if (changedOptions.isEmpty()) {
        return true;
    }/*from w  w  w.j ava 2s  . c  om*/
    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:descent.internal.ui.text.java.CompletionProposalComputerRegistry.java

License:Open Source License

/**
 * Log the status and inform the user about a misbehaving extension.
 * //from  w  w  w . jav  a 2 s  .c  om
 * @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);/*from  w w w .  j a v a 2 s  .  co 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}/*from  w w w  . java2  s  .c o  m*/
 */
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  va 2  s. c  om*/
            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;
}