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

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

Introduction

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

Prototype

public MessageDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage,
        int dialogImageType, int defaultIndex, String... dialogButtonLabels) 

Source Link

Document

Create a message dialog.

Usage

From source file:de.tub.tfs.henshin.editor.ui.dialog.resources.ResourcesDialog.java

License:Open Source License

@Override
protected void okPressed() {
    IPath path = resourceGroup.getResourceFullPath();
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);

    if (file.exists() && type == SWT.SAVE) {
        String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                IDialogConstants.CANCEL_LABEL };
        MessageDialog confirm = new MessageDialog(getShell(), "Overwrite Question", null,
                "The file" + file.getName() + " already exists. Do you want to replace the existing file?",
                MessageDialog.QUESTION, buttons, 0);

        int result = confirm.open();

        switch (result) {
        case 0://  ww w.j a  va 2  s  .c om
            break;
        case 1:
            return;
        default:
            cancelPressed();
            break;
        }
    }

    this.result = file.getRawLocation().toFile();
    super.okPressed();
}

From source file:de.tub.tfs.muvitor.actions.DNPTBAction.java

License:Open Source License

@Override
public void run() {
    // MessageBox dialog = new MessageBox(new Shell(), SWT.ICON_WARNING);
    // dialog.setText("You pushed the button!");
    // dialog.setMessage("Please don't push the button again!");

    final MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(),
            "You pushed the button!", null, "Please don't push the button again!", MessageDialog.WARNING,
            new String[] { "I promise..." }, 0);
    dialog.open();/*ww w  .j ava 2 s .  c o  m*/
}

From source file:de.uniluebeck.itm.spyglass.gui.configuration.PluginPreferenceDialog.java

License:Open Source License

/**
 * Displays an information dialog which reminds the user that there are still unsaved changes at
 * a preference page. In respect to the type of the preference page, the user will be offered
 * the opportunity to store the changes before leaving the page.
 * // w  w  w .j  av  a2s .c  o m
 * @returns <ul>
 *          <li>0 if there were no unsaved changes or there were unsaved changes and the user
 *          decided to save them</li>
 *          <li>1 if there were unsaved changes and the user decided to discard them</li>
 *          <li>2 if there were unsaved changes and the user decided to cancel page change</li>
 *          </ul>
 */
private int askToSaveChanges() {

    if (hasUnsavedChanges()) {

        final AbstractDatabindingPreferencePage selectedPrefPage = (AbstractDatabindingPreferencePage) preferenceDialog
                .getSelectedPage();

        if ((selectedPrefPage != null) && (selectedPrefPage instanceof AbstractDatabindingPreferencePage)) {

            final String message = "The currently opened preference page contains unsaved changes. Do you want to save now?";
            final MessageDialog dialog = new MessageDialog(preferenceDialog.getShell(), "Unsaved changes", null,
                    message, SWT.ICON_QUESTION, new String[] { "Save", "Discard", "Cancel" }, 0);
            final int answer = dialog.open();

            if (answer == 0) {
                // save the changes
                selectedPrefPage.performApply();
            } else if (answer == 1) {
                // discard the changes
                selectedPrefPage.loadFromModel();
            }

            return answer;

        } else {
            // there are unsaved changes
            return 2;
        }

    }

    // there are no unsaved changes
    return 0;
}

From source file:de.uni_jena.iaa.linktype.atomic.model.pepper.exportwizard.PepperExportWizard.java

License:Apache License

@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
    initialize();/* ww w .j  a  va2  s .  co  m*/
    if (1 == selection.size()) {
        Object element = selection.getFirstElement();
        if (element instanceof IProject) {
            selectedProject = (IProject) element;
        } else {
            new MessageDialog(this.getShell(), "Error", null, "Selection is not a project!",
                    MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0).open();
        }
    } else {
        new MessageDialog(this.getShell(), "Error", null,
                "To run the Pepper Export Wizard select exactly one project!", MessageDialog.ERROR,
                new String[] { IDialogConstants.OK_LABEL }, 0).open();
    }
}

From source file:de.uni_jena.iaa.linktype.atomic.model.pepper.wizard.AbstractPepperWizard.java

License:Apache License

public List<P> getPepperModules() {
    if (pepperModuleList == null) {
        List<P> modules = null;
        if (pepperConverter != null) {
            PepperModuleResolver pepperModuleResolver = pepperConverter.getPepperModuleResolver();
            if (pepperModuleResolver != null) {
                modules = resolvePepperModules(pepperModuleResolver);
                if (modules != null) {
                    Collections.sort(modules, new Comparator<P>() {
                        @Override
                        public int compare(P o1, P o2) {
                            return o1.getName().compareTo(o2.getName());
                        }//from  w w  w  .j  a v a  2  s .  co  m
                    });
                } else {
                    new MessageDialog(this.getShell(), "Error", null, "Did not found any Pepper module!",
                            MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0).open();
                }
            } else {
                new MessageDialog(this.getShell(), "Error", null, "Did not found Pepper module resolver!",
                        MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0).open();
            }
        }

        pepperModuleList = modules != null ? modules : Collections.<P>emptyList();
    }

    return pepperModuleList;
}

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   w  w w .  j a  v  a2  s.c o  m
        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/*  w ww .j a va 2  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.  java 2 s .  com
        }
    }
    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.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();//  w  ww. jav a 2 s . c  om
                } 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  av  a2 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;
}