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

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

Introduction

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

Prototype

int QUESTION

To view the source code for org.eclipse.jface.dialogs MessageDialog QUESTION.

Click Source Link

Document

Constant for the question image, or a simple dialog with the question image and Yes/No buttons (value 3).

Usage

From source file:com.ultimatetech.cim.views.CIMInstanceView.java

License:Open Source License

private void makeActions() {
    setInstanceAct = new Action() {
        public void run() {
            //get client
            CIMClient client = null;//from  www  . ja  va  2s . c  o m
            try {
                client = CIMConnect.connectUsingPreferences();
                try {
                    client.setInstance(cimInstance.getObjectPath(), cimInstance, false,
                            (String[]) changedProps.toArray(new String[] {}));
                    showMessage("Set instance successfull");
                    setInstanceAct.setEnabled(false);
                } catch (CIMException e) {
                    e.printStackTrace();
                    ErrorDialog ed = new ErrorDialog(
                            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                            "Set Instance Error", "Set Instance failed:" + e.getMessage(),
                            new Status(Status.ERROR, "CIMPlugin", e.getXmlCode(e.getID()), e.getMessage(), e),
                            IStatus.ERROR);
                    ed.open();
                }
            } finally {
                if (client != null) {
                    try {
                        client.close();
                    } catch (CIMException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }

        }
    };
    setInstanceAct.setText("Set instance");
    setInstanceAct.setToolTipText("Set instance");
    setInstanceAct.setImageDescriptor(CIMPlugin.getImageDescriptor("icons/save.gif"));
    setInstanceAct.setDisabledImageDescriptor(CIMPlugin.getImageDescriptor("icons/save_disabled.gif"));
    setInstanceAct.setEnabled(false);
    deleteInstance = new Action() {
        public void run() {
            CIMClient client = CIMConnect.connectUsingPreferences();
            try {
                MessageDialog areYouSure = new MessageDialog(
                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Delete Instance?",
                        MessageDialog.getImage(MessageDialog.DLG_IMG_QUESTION), "Delete this instance?",
                        MessageDialog.QUESTION, new String[] { "OK", "Cancel" }, 0);
                areYouSure.open();
                if (areYouSure.getReturnCode() == MessageDialog.OK) {
                    client.deleteInstance(cimInstance.getObjectPath());
                    clearView();
                    CIMExplorerView cev = (CIMExplorerView) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
                            .getActivePage().showView("com.ultimatetech.cim.views.CIMExplorerView");
                    cev.refreshAllTreeNodes();
                }
            } catch (CIMException e) {
                ErrorDialog ed = new ErrorDialog(
                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                        "Delete Instance Error", "Delete instance failed:" + e.getMessage(),
                        new Status(Status.ERROR, "CIMPlugin", e.getXmlCode(e.getID()), e.getMessage(), e),
                        IStatus.ERROR);
                ed.open();
            } catch (Exception e) {
                ErrorDialog ed = new ErrorDialog(
                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                        "Delete Instance Error", "Delete instance failed:" + e.getMessage(),
                        new Status(Status.ERROR, "CIMPlugin", 100, e.getMessage(), e), IStatus.ERROR);
                ed.open();
            } finally {
                if (client != null) {
                    try {
                        client.close();
                    } catch (CIMException e) {
                        e.printStackTrace();
                    }
                }
            }
            //showMessage("Delete instance not yet implemented");
        }
    };
    deleteInstance.setText("Delete instance");
    deleteInstance.setToolTipText("Delete instance");
    deleteInstance.setImageDescriptor(
            PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJS_ERROR_TSK));

    /*doubleClickAction = new Action() {
       public void run() {
    ISelection selection = viewer.getSelection();
    Object obj = ((IStructuredSelection)selection).getFirstElement();
    showMessage("Double-click detected on "+obj.toString());
       }
    };*/

    refreshAction = new Action() {
        public void run() {
            CIMClient client = CIMConnect.connectUsingPreferences();
            try {
                cimInstance = client.getInstance(cimInstance.getObjectPath(), false, true, true, null);
                showMessage("Instance reloaded");
            } catch (CIMException e) {
                e.printStackTrace();
                ErrorDialog ed = new ErrorDialog(
                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                        "Reload Instance Error", "Reload Instance failed:" + e.getMessage(),
                        new Status(Status.ERROR, "CIMPlugin", e.getXmlCode(e.getID()), e.getMessage(), e),
                        IStatus.ERROR);
                ed.open();
            } finally {
                if (client != null) {
                    try {
                        client.close();
                    } catch (CIMException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }

            setInstanceAct.setEnabled(false);
        }
    };
    refreshAction.setText("Reload instance");
    refreshAction.setToolTipText("Reload instance");
    refreshAction.setImageDescriptor(
            PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_REDO));
}

From source file:com.vectrace.MercurialEclipse.menu.RebaseHandler.java

License:Open Source License

public static void openWizard(HgRoot hgRoot, Shell shell) throws CoreException {
    if (HgRebaseClient.isRebasing(hgRoot)) {
        MessageDialog dialog = new MessageDialog(null, Messages.getString("RebaseHandler.inProgress"), null,
                Messages.getString("RebaseHandler.inProgressAbortOrContinue"), MessageDialog.QUESTION,
                new String[] { Messages.getString("RebaseHandler.cancel"),
                        Messages.getString("RebaseHandler.abort"),
                        Messages.getString("RebaseHandler.continue") },
                2);//  w  ww  .j a  v  a  2  s  .  co  m

        switch (dialog.open()) {
        case 1:
            // Shouldn't fail
            HgRebaseClient.abortRebase(hgRoot);
            break;
        case 2:
            ContinueRebaseHandler handler = new ContinueRebaseHandler();
            handler.setShell(shell);
            handler.run(hgRoot);
            break;
        }
    } else {
        RebaseWizard wizard = new RebaseWizard(hgRoot);
        WizardDialog wizardDialog = new WizardDialog(shell, wizard);
        wizardDialog.open();
    }
}

From source file:com.vectrace.MercurialEclipse.menu.ShelveHandler.java

License:Open Source License

@Override
protected void run(final HgRoot hgRoot) {
    new SafeWorkspaceJob(Messages.getString("ShelveHandler.Shelving")) { //$NON-NLS-1$

        @Override/* w  ww  . j av a 2  s .  com*/
        protected IStatus runSafe(IProgressMonitor monitor) {
            final ShelveOperation op = new ShelveOperation((IWorkbenchPart) null, hgRoot, false);
            try {
                op.run(monitor);
                return super.runSafe(monitor);
            } catch (InvocationTargetException e) {
                if (op.getShelveFileConflict() != null) {
                    getShell().getDisplay().asyncExec(new Runnable() {
                        public void run() {
                            MessageDialog dialog = new MessageDialog(getShell(),
                                    "Shelve file exists. Delete shelved changes?", null,
                                    "Shelve file exists. You must unshelve before shelving anew. "
                                            + "Would you like to delete shelved changes instead?",
                                    MessageDialog.QUESTION, new String[] { "Delete shelved changes", "Retain" },
                                    1) {
                                {
                                    setShellStyle(getShellStyle() | SWT.SHEET);
                                }
                            };

                            if (dialog.open() == 0) {
                                op.getShelveFileConflict().delete();
                                ShelveHandler.this.run(hgRoot);
                            }
                        }
                    });
                    return Status.OK_STATUS;
                }
                return new Status(IStatus.WARNING, MercurialEclipsePlugin.ID, 0, e.getLocalizedMessage(), e);

            } catch (InterruptedException e) {
                return new Status(IStatus.INFO, MercurialEclipsePlugin.ID, 0, e.getLocalizedMessage(), e);
            }
        }
    }.schedule();

}

From source file:com.vectrace.MercurialEclipse.menu.TransplantHandler.java

License:Open Source License

@Override
protected void run(final HgRoot hgRoot) throws CoreException {
    if (HgStatusClient.isDirty(hgRoot)) {
        MessageDialog dialog = new MessageDialog(null, Messages.getString("TransplantHandler.dirtyTitle"), null,
                Messages.getString("TransplantHandler.dirtyMessage"), MessageDialog.QUESTION,
                new String[] { Messages.getString("TransplantHandler.cancel"),
                        Messages.getString("TransplantHandler.continue") },
                0);// w  w w. j a  v a 2  s  .c  o  m

        if (dialog.open() == 1) {
            TransplantOperation op = TransplantOperation
                    .createContinueOperation(MercurialEclipsePlugin.getActiveWindow(), hgRoot);

            try {
                op.run();
            } catch (InvocationTargetException e) {
                MercurialEclipsePlugin.showError(e.getTargetException());
            } catch (InterruptedException e) {
                MercurialEclipsePlugin.logError(e);
            }
        }
    } else {
        TransplantWizard transplantWizard = new TransplantWizard(hgRoot);
        WizardDialog transplantWizardDialog = new WizardDialog(getShell(), transplantWizard);
        transplantWizardDialog.open();
    }
}

From source file:com.vectrace.MercurialEclipse.wizards.ProjectsImportPage.java

License:Open Source License

/**
 * The <code>WizardDataTransfer</code> implementation of this
 * <code>IOverwriteQuery</code> method asks the user whether the existing
 * resource at the given path should be overwritten.
 *
 * @param pathString// ww w .  ja  v a  2s.c  om
 * @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>,
 *    <code>"ALL"</code>, or <code>"CANCEL"</code>
 */
public String queryOverwrite(String pathString) {

    Path path = new Path(pathString);

    String messageString;
    // Break the message up if there is a file name and a directory
    // and there are at least 2 segments.
    if (path.getFileExtension() == null || path.segmentCount() < 2) {
        messageString = "'" + pathString + "' already exists.  Would you like to overwrite it?";
    } else {
        messageString = "Overwrite '" + path.lastSegment() + "' in folder '"
                + path.removeLastSegments(1).toOSString() + "'?";
    }

    final MessageDialog dialog = new MessageDialog(getContainer().getShell(), "Question", null, messageString,
            MessageDialog.QUESTION,
            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.YES_TO_ALL_LABEL,
                    IDialogConstants.NO_LABEL, IDialogConstants.NO_TO_ALL_LABEL,
                    IDialogConstants.CANCEL_LABEL },
            0) {
        @Override
        protected int getShellStyle() {
            // TODO add  "| SWT.SHEET" flag as soon as we drop Eclipse 3.4 support
            return super.getShellStyle()/* | SWT.SHEET*/;
        }
    };
    String[] response = new String[] { YES, ALL, NO, NO_ALL, CANCEL };
    // run in syncExec because callback is from an operation,
    // which is probably not running in the UI thread.
    getControl().getDisplay().syncExec(new Runnable() {
        public void run() {
            dialog.open();
        }
    });
    return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()];
}

From source file:com.xse.eclipseui.dialog.MessageDialogHelper.java

License:Open Source License

/**
 * Convenience method to open a simple Yes/No question dialog.
 *
 * @param title/*from w  ww.  ja  va2  s .co m*/
 *            the dialog's title, or <code>null</code> if none
 * @param message
 *            the message
 * @return <code>true</code> if the user presses the Yes button, <code>false</code> otherwise
 */
public static boolean openQuestion(final String title, final String message) {
    final ValueContainer<Boolean> result = new ValueContainer<>(Boolean.FALSE);
    Display.getDefault().syncExec(new Runnable() {
        @Override
        public void run() {
            result.setValue(Boolean.valueOf(MessageDialog.open(MessageDialog.QUESTION,
                    Display.getDefault().getActiveShell(), title, message, SWT.NONE)));
        }
    });

    return result.getValue().booleanValue();
}

From source file:cu.uci.abos.core.util.MessageDialogUtil.java

License:Open Source License

public static void openQuestion(Shell parent, String title, String message, DialogCallback callback) {
    open(MessageDialog.QUESTION, parent, title, message, callback);
}

From source file:cu.uci.abos.core.util.MessageDialogUtil.java

License:Open Source License

private static String[] getButtonLabels(int kind) {
    String[] dialogButtonLabels;//from   w  ww .  j  av a  2s . co  m
    switch (kind) {
    case MessageDialog.ERROR:
    case MessageDialog.INFORMATION:
    case MessageDialog.WARNING: {
        dialogButtonLabels = new String[] { AbosMessages.get().BUTTON_CLOSE };
        break;
    }
    case MessageDialog.CONFIRM: {
        dialogButtonLabels = new String[] { AbosMessages.get().BUTTON_ACCEPT,
                AbosMessages.get().BUTTON_CANCEL };
        break;
    }
    case MessageDialog.QUESTION: {
        dialogButtonLabels = new String[] { AbosMessages.get().BUTTON_ACCEPT,
                AbosMessages.get().BUTTON_CANCEL };
        break;
    }
    case MessageDialog.QUESTION_WITH_CANCEL: {
        dialogButtonLabels = new String[] { AbosMessages.get().BUTTON_ACCEPT, AbosMessages.get().BUTTON_CANCEL,
                AbosMessages.get().BUTTON_CLOSE };
        break;
    }
    default: {
        throw new IllegalArgumentException("Illegal value for kind in MessageDialog.open()");
    }
    }
    return dialogButtonLabels;
}

From source file:de.anbos.eclipse.easyshell.plugin.preferences.CommandPage.java

License:Open Source License

@Override
protected void performDefaults() {
    // get the selected commands and referenced menus as lists
    CommandDataList commands = new CommandDataList(CommandDataStore.instance().getDataList());
    List<MenuData> menus = new ArrayList<MenuData>();
    for (CommandData command : commands) {
        if (command.getPresetType() == PresetType.presetUser) {
            List<MenuData> menusForOne = MenuDataStore.instance().getRefencedBy(command.getId());
            menus.addAll(menusForOne);/*from  ww w  .j  a v  a2  s . c  o  m*/
        }
    }
    String title = Activator.getResourceString("easyshell.command.page.dialog.defaults.title");
    String question = Activator.getResourceString("easyshell.command.page.dialog.defaults.question");
    int dialogImageType = MessageDialog.QUESTION;
    if (menus.size() >= 0) {
        dialogImageType = MessageDialog.WARNING;
        String menuNames = "";
        for (MenuData menu : menus) {
            menuNames += menu.getNameExpanded() + "\n";
        }
        question = MessageFormat.format(
                Activator.getResourceString("easyshell.command.page.dialog.defaults.menu.question"), menuNames);
    }
    MessageDialog dialog = new MessageDialog(null, title, null, question, dialogImageType,
            new String[] { "Yes", "No" }, 1); // no is the default
    int result = dialog.open();
    if (result == 0) {
        if (menus.size() >= 0) {
            for (MenuData menu : menus) {
                MenuDataStore.instance().delete(menu);
            }
            //MenuDataStore.instance().save();
        }
        CommandDataStore.instance().loadDefaults();
        tableViewer.refresh();
    }
}

From source file:de.anbos.eclipse.easyshell.plugin.preferences.CommandPage.java

License:Open Source License

private void removeDialog() {
    // get the selected commands and referenced menus as lists
    List<CommandData> commands = new ArrayList<CommandData>();
    List<MenuData> menus = new ArrayList<MenuData>();
    IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
    Iterator<?> elements = selection.iterator();
    while (elements.hasNext()) {
        CommandData data = (CommandData) elements.next();
        commands.add(data);//w ww.  j  ava 2  s .c  o  m
        List<MenuData> menusForOne = MenuDataStore.instance().getRefencedBy(data.getId());
        menus.addAll(menusForOne);
    }
    // ask user
    String commandNames = "";
    PresetType type = PresetType.presetUnknown;
    for (CommandData command : commands) {
        if (type == PresetType.presetUnknown) {
            type = command.getPresetType();
        }
        commandNames += command.getCommandAsComboName() + "\n";
    }
    String title = null;
    String question = null;
    if (type == PresetType.presetPluginAndUser) {
        title = Activator.getResourceString("easyshell.command.page.dialog.remove.user.title");
        question = MessageFormat.format(
                Activator.getResourceString("easyshell.command.page.dialog.remove.user.question"),
                commandNames);
    } else {
        title = Activator.getResourceString("easyshell.command.page.dialog.remove.title");
        question = MessageFormat.format(
                Activator.getResourceString("easyshell.command.page.dialog.remove.question"), commandNames);
    }
    int dialogImageType = MessageDialog.QUESTION;
    if (menus.size() > 0) {
        dialogImageType = MessageDialog.WARNING;
        String menuNames = "";
        for (MenuData menu : menus) {
            menuNames += menu.getNameExpanded() + "\n";
        }
        if (type == PresetType.presetPluginAndUser) {
            title = Activator.getResourceString("easyshell.command.page.dialog.remove.menu.user.title");
            question = MessageFormat.format(
                    Activator.getResourceString("easyshell.command.page.dialog.remove.menu.user.question"),
                    commandNames, menuNames);
        } else {
            title = Activator.getResourceString("easyshell.command.page.dialog.remove.menu.title");
            question = MessageFormat.format(
                    Activator.getResourceString("easyshell.command.page.dialog.remove.menu.question"),
                    commandNames, menuNames);
        }
    }
    MessageDialog dialog = new MessageDialog(null, title, null, question, dialogImageType,
            new String[] { "Yes", "No" }, 1); // no is the default
    int result = dialog.open();
    if (result == 0) {
        if (menus.size() >= 0 && type == PresetType.presetUser) {
            for (MenuData menu : menus) {
                MenuDataStore.instance().delete(menu);
            }
            //MenuDataStore.instance().save();
        }
        for (CommandData command : commands) {
            if (command.getPresetType() == PresetType.presetUser) {
                CommandDataStore.instance().delete(command);
            } else if (command.getPresetType() == PresetType.presetPluginAndUser) {
                command.removeUserData();
                CommandDataStore.instance().replace(command);
            }
        }
        tableViewer.refresh();
    }
}