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

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

Introduction

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

Prototype

public static boolean openConfirm(Shell parent, String title, String message) 

Source Link

Document

Convenience method to open a simple confirm (OK/Cancel) dialog.

Usage

From source file:com.ibm.etools.mft.conversion.esb.editor.parameter.ConversionEditor.java

License:Open Source License

protected boolean showFlashWarning() {
    final List<Object> result = new ArrayList<Object>();
    Display.getDefault().syncExec(new Runnable() {

        @Override//from  w w w.  j a  va 2 s  . com
        public void run() {
            if (MessageDialog.openConfirm(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                    WESBConversionMessages.ConversionEditor_warningTitle,
                    WESBConversionMessages.warningFlashingScreen)) {
                result.add(Boolean.TRUE);
            }
        }
    });
    return result.size() > 0;
}

From source file:com.ibm.etools.mft.conversion.esb.editor.parameter.ConversionEditor.java

License:Open Source License

protected boolean showWarningIfNecessary() {
    final StringBuffer msg = new StringBuffer();
    HashMap<String, WESBProject> projectsToConvert = new HashMap<String, WESBProject>();
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    for (WESBProject p : getModel().getSourceProjects()) {
        if (p.isToConvert()) {
            IProject prj = ConversionUtils.getProject(p.getTargetName());
            if (prj.isAccessible()) {
                if (msg.length() > 0) {
                    msg.append("\n"); //$NON-NLS-1$
                }/*  w w w.  j a  va 2 s .co m*/
                String IIBprojectName = prj.getName();
                msg.append(IIBprojectName);
                IProject jcnProject = root.getProject(IIBprojectName + JCN_SUFFIX);
                // Can't tell if the WESB project will create a JCN so just
                // check whether a JCN project already exists
                if (jcnProject.exists()) {
                    msg.append("\n");
                    msg.append(IIBprojectName + JCN_SUFFIX);
                }
                // Check whether the WESB project will create a Java project
                if (p.getJavas() != null) {
                    IProject javaProject = root.getProject(IIBprojectName + WESBJAVA_SUFFIX);
                    if (javaProject.exists()) {
                        msg.append("\n");
                        msg.append(IIBprojectName + WESBJAVA_SUFFIX);
                    }
                }
            }
            projectsToConvert.put(p.getName(), p);
        }
    }

    if (msg.length() > 0) {
        msg.insert(0, WESBConversionMessages.ConversionEditor_projectsAlreadyExist);
    }

    if (msg.length() > 0) {
        final List<Object> result = new ArrayList<Object>();
        Display.getDefault().syncExec(new Runnable() {

            @Override
            public void run() {
                if (MessageDialog.openConfirm(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                        WESBConversionMessages.ConversionEditor_warningTitle, msg.toString())) {
                    result.add(Boolean.TRUE);
                }
            }
        });
        return result.size() > 0;
    }
    return true;
}

From source file:com.ibm.xsp.extlib.designer.tooling.panels.AbstractTreeNodePanel.java

License:Open Source License

/**
 * /*from   w  w w  . j a va 2s. co m*/
 */
private void removeSelected() {

    // save the current table selection
    Tree tree = _linkViewer.getTree();
    TreeItem[] selectedItems = tree.getSelection();
    int selectedIndex = -1;
    if (null != selectedItems && selectedItems.length > 0) {
        TreeItem[] items = tree.getItems();
        if (null != items && items.length > 0) {
            for (int i = 0; i < items.length; i++) {
                if (selectedItems[0].equals(items[i])) {
                    selectedIndex = i;
                    break;
                }
            }
            if (selectedIndex == items.length - 1)
                selectedIndex--;
        }
    } else {
        //play the prompt sound!
        Display.getDefault().beep();
        return;
    }

    // the DN for the complextComposite will be the current selection
    DataNode dnSelected = DCUtils.findDataNode(_complexComposite, true);
    ILoader loader = dnSelected.getLoader();
    Element selected = (Element) dnSelected.getCurrentObject();

    if (null == selected) {
        ExtLibToolingLogger.EXT_LIB_TOOLING_LOGGER
                .warn("\"Delete\" links menu item pressed with no selected element"); //$NON-NLS-1$
        return;
    }

    boolean doIt = true;

    // need to check if we want to warn that they are deleting a container with child elements 

    NodeList childrenNodes = selected.getChildNodes();

    if (null != childrenNodes && childrenNodes.getLength() > 0) {
        // does it have any non-text children?
        boolean hasChildElement = false;
        for (int i = 0; i < childrenNodes.getLength() && !hasChildElement; i++) {
            Node node = childrenNodes.item(i);
            hasChildElement = (node.getNodeType() == Node.ELEMENT_NODE);
        }

        // GGRD8UAP4U check if this -really- has children, or just child element nodes (like an empty <this.children>)
        if (hasChildElement) {
            ITreeContentProvider cp = (ITreeContentProvider) _linkViewer.getContentProvider();
            Object[] childrenFromProvider = cp.getChildren(selected);
            if (childrenFromProvider == null || childrenFromProvider.length == 0) {
                hasChildElement = false;
            }
        }

        if (hasChildElement) {

            // can this have children? if so, get the member that contains the children
            IMember childrenMember = findTreeNodeMember(selected, loader, null);

            // if selected has child DOM Nodes and could have child tree nodes 
            // (has a member of type iTreeNode), warn...
            if (childrenMember != null) {
                doIt = MessageDialog.openConfirm(getShell(), "Application Layout", // $NLX-AbstractTreeNodePanel.ApplicationLayout-1$
                        "This Node has children. Are you sure you want to remove it, and all of its children?"); // $NLX-AbstractTreeNodePanel.ThisNodehaschildrenAreyousureyouw-1$
            }
        }
    }

    Node parent = selected.getParentNode();
    if (doIt && null != parent) {
        String memberName = parent.getLocalName();
        try {
            if (memberName.startsWith(IExtLibTagNames.TAG_THIS_PREFIX)) {
                memberName = memberName.substring(IExtLibTagNames.TAG_THIS_PREFIX.length());
            }

            Node grandparentNode = selected.getParentNode().getParentNode();
            IMember containerMember = findTreeNodeMember(grandparentNode, loader, memberName);
            if (containerMember instanceof ICollection) {
                IObjectCollection c = loader.getObjectCollection(grandparentNode,
                        (ICollection) containerMember);
                if (null != c) {
                    IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
                            .getActivePart();
                    IAction undo = null;
                    IAction redo = null;
                    CommandStack stack = null;
                    IActionBars bars = null;
                    if (part instanceof IViewPart) {
                        bars = ((IViewPart) part).getViewSite().getActionBars();
                        if (bars != null) {
                            undo = bars.getGlobalActionHandler(ActionFactory.UNDO.getId());
                            redo = bars.getGlobalActionHandler(ActionFactory.REDO.getId());

                            if (redo == null) {
                                stack = XPagesEditorUtils.getCommandStack(null);
                                redo = new RedoAction(stack);
                            }
                            if (undo == null) {
                                if (stack == null) {
                                    stack = XPagesEditorUtils.getCommandStack(null);
                                }
                                undo = new UndoAction(stack, redo);
                                if (redo instanceof RedoAction) {
                                    ((RedoAction) redo).setUndoAction((UndoAction) undo);
                                }
                            }
                            bars.setGlobalActionHandler(ActionFactory.UNDO.getId(), undo);
                            bars.setGlobalActionHandler(ActionFactory.REDO.getId(), redo);
                        }
                    }
                    for (int i = 0; i < c.size(); i++) {
                        // remove the member of the collection that is selected
                        if (c.get(i).equals(selected)) {
                            Node n = (Node) c.get(i);
                            removeAndUpdateUndoActions(n, undo, redo, stack, bars);
                            break;
                        }
                    }

                    // GGRD8UAP4U get the children again.... if 0, remove the "this.children"
                    IObjectCollection cpost = loader.getObjectCollection(grandparentNode,
                            (ICollection) containerMember);
                    if (null != cpost && cpost.size() == 0 && parent != null) {
                        if (containerMember.getName().endsWith("children")) { //$NON-NLS-1$
                            removeAndUpdateUndoActions(parent, undo, redo, stack, bars);
                        }
                    }
                }
            }
            // try to select the previous (or next) one
            if (selectedIndex >= 0) {
                TreeItem[] items = tree.getItems();
                if (selectedIndex < items.length)
                    tree.select(items[selectedIndex]);
            } else {
                _complexComposite.updatePanel(null, null);
            }
        } catch (NodeException e) {
            if (ExtLibToolingLogger.EXT_LIB_TOOLING_LOGGER.isErrorEnabled()) {
                ExtLibToolingLogger.EXT_LIB_TOOLING_LOGGER.error(e, "Failed to get children for Data Node ",
                        memberName); // $NLE-AbstractTreeNodePanel.FailedtogetchildrenforDataNode-1$
            }
        }
    }
}

From source file:com.ibm.xsp.extlib.designer.tooling.panels.redirect.RedirectRulesPanel.java

License:Open Source License

/**
 * /*ww w  .jav  a  2s. c  om*/
 */
private void removeSelected() {

    // save the current table selection
    Tree tree = ruleViewer.getTree();
    TreeItem[] selectedItems = tree.getSelection();
    int selectedIndex = -1;
    if (null != selectedItems && selectedItems.length > 0) {
        TreeItem[] items = tree.getItems();
        if (null != items && items.length > 0) {
            for (int i = 0; i < items.length; i++) {
                if (selectedItems[0].equals(items[i])) {
                    selectedIndex = i;
                    break;
                }
            }
            if (selectedIndex == items.length - 1)
                selectedIndex--;
        }
    } else {
        //play the prompt sound!
        Display.getDefault().beep();
        return;
    }

    // the DN for the complextComposite will be the current selection
    DataNode dnSelected = DCUtils.findDataNode(cmplxComposite, true);
    ILoader loader = dnSelected.getLoader();
    Element selected = (Element) dnSelected.getCurrentObject();

    if (null == selected) {
        ExtLibToolingLogger.EXT_LIB_TOOLING_LOGGER
                .warn("\"Delete\" links menu item pressed with no selected element"); //$NON-NLS-1$
        return;
    }

    boolean doIt = true;

    // need to check if we want to warn that they are deleting a container with child elements 

    NodeList childrenNodes = selected.getChildNodes();

    if (null != childrenNodes && childrenNodes.getLength() > 0) {
        // does it have any non-text children?
        boolean hasChildElement = false;
        for (int i = 0; i < childrenNodes.getLength() && !hasChildElement; i++) {
            Node node = childrenNodes.item(i);
            hasChildElement = (node.getNodeType() == Node.ELEMENT_NODE);
        }

        // GGRD8UAP4U check if this -really- has children, or just child element nodes (like an empty <this.children>)
        if (hasChildElement) {
            ITreeContentProvider cp = (ITreeContentProvider) ruleViewer.getContentProvider();
            Object[] childrenFromProvider = cp.getChildren(selected);
            if (childrenFromProvider == null || childrenFromProvider.length == 0) {
                hasChildElement = false;
            }
        }

        if (hasChildElement) {

            // can this have children? if so, get the member that contains the children
            IMember childrenMember = findRulesNodeMember(selected, loader, null);

            // if selected has child DOM Nodes and could have child tree nodes 
            // (has a member of type iTreeNode), warn...
            if (childrenMember != null) {
                doIt = MessageDialog.openConfirm(getShell(), "Application Layout", // $NLX-AbstractTreeNodePanel.ApplicationLayout-1$
                        "This Node has children. Are you sure you want to remove it, and all of its children?"); // $NLX-AbstractTreeNodePanel.ThisNodehaschildrenAreyousureyouw-1$
            }
        }
    }

    Node parent = selected.getParentNode();
    if (doIt && null != parent) {
        String memberName = parent.getLocalName();
        try {
            if (memberName.startsWith(IExtLibTagNames.TAG_THIS_PREFIX)) {
                memberName = memberName.substring(IExtLibTagNames.TAG_THIS_PREFIX.length());
            }

            Node grandparentNode = selected.getParentNode().getParentNode();
            IMember containerMember = findRulesNodeMember(grandparentNode, loader, memberName);
            if (containerMember instanceof ICollection) {
                IObjectCollection c = loader.getObjectCollection(grandparentNode,
                        (ICollection) containerMember);
                if (null != c) {
                    IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
                            .getActivePart();
                    IAction undo = null;
                    IAction redo = null;
                    CommandStack stack = null;
                    IActionBars bars = null;
                    if (part instanceof IViewPart) {
                        bars = ((IViewPart) part).getViewSite().getActionBars();
                        if (bars != null) {
                            undo = bars.getGlobalActionHandler(ActionFactory.UNDO.getId());
                            redo = bars.getGlobalActionHandler(ActionFactory.REDO.getId());

                            if (redo == null) {
                                stack = XPagesEditorUtils.getCommandStack(null);
                                redo = new RedoAction(stack);
                            }
                            if (undo == null) {
                                if (stack == null) {
                                    stack = XPagesEditorUtils.getCommandStack(null);
                                }
                                undo = new UndoAction(stack, redo);
                                if (redo instanceof RedoAction) {
                                    ((RedoAction) redo).setUndoAction((UndoAction) undo);
                                }
                            }
                            bars.setGlobalActionHandler(ActionFactory.UNDO.getId(), undo);
                            bars.setGlobalActionHandler(ActionFactory.REDO.getId(), redo);
                        }
                    }
                    for (int i = 0; i < c.size(); i++) {
                        // remove the member of the collection that is selected
                        if (c.get(i).equals(selected)) {
                            Node n = (Node) c.get(i);
                            removeAndUpdateUndoActions(n, undo, redo, stack, bars);
                            break;
                        }
                    }

                    // GGRD8UAP4U get the children again.... if 0, remove the "this.children"
                    IObjectCollection cpost = loader.getObjectCollection(grandparentNode,
                            (ICollection) containerMember);
                    if (null != cpost && cpost.size() == 0) {
                        if (containerMember.getName().endsWith("children")) { //$NON-NLS-1$
                            removeAndUpdateUndoActions(parent, undo, redo, stack, bars);
                        }
                    }
                }
            }
            // try to select the previous (or next) one
            if (selectedIndex >= 0) {
                TreeItem[] items = tree.getItems();
                if (selectedIndex < items.length) {
                    ruleViewer.refresh();
                    tree.select(items[selectedIndex]);
                }
            } else {
                ruleViewer.refresh();
                cmplxComposite.updatePanel(null, null);
            }
        } catch (NodeException e) {
            if (ExtLibToolingLogger.EXT_LIB_TOOLING_LOGGER.isErrorEnabled()) {
                ExtLibToolingLogger.EXT_LIB_TOOLING_LOGGER.error(e, "Failed to get children for Data Node ",
                        memberName); // $NLE-AbstractTreeNodePanel.FailedtogetchildrenforDataNode-1$
            }
        }
    }
}

From source file:com.intel.audioviz.example.handlers.QuitHandler.java

License:Open Source License

@Execute
public void execute(final IWorkbench workbench, final Shell shell) {
    if (MessageDialog.openConfirm(shell, "Confirmation", "Do you want to exit?")) {
        workbench.close();/*  www  . j ava2s.c  om*/
    }
}

From source file:com.itsolut.mantis.ui.action.MantisDeleteAttachmentAction.java

License:Open Source License

public void run(IAction action) {

    String message = "";

    for (ITaskAttachment attachment : attachments)
        message += " - " + attachment.getFileName() + " \n";

    boolean confirm = MessageDialog.openConfirm(null, "Attachment deletion",
            "Please confirm that the following attachments will be deleted:\n\n" + message);
    if (!confirm)
        return;//  w w w.j  a  v a  2  s  .c  o  m

    TaskEditor taskEditor = null;
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IWorkbenchPage page = window.getActivePage();
    IEditorPart activeEditor = page.getActiveEditor();
    if (activeEditor instanceof TaskEditor)
        taskEditor = (TaskEditor) activeEditor;

    final DeleteAttachmentJob job = new DeleteAttachmentJob(attachments, taskEditor);
    job.setUser(true);
    job.schedule();
}

From source file:com.jalios.jcmstools.handlers.SyncAllHandler.java

License:LGPL

/**
 * the command has been executed, so extract extract the needed information
 * from the application context.//  w  w  w  .j a  va 2s . c o  m
 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    preview = isPreview(event.getCommand());

    if (!preview) {
        boolean isSyncAllConfirmed = MessageDialog.openConfirm(window.getShell(), "Sync All",
                "Are you sure to sync all JCMS Plugin Project ?");
        if (!isSyncAllConfirmed) {
            return null;
        }
    }

    for (IProject pluginProject : EJPTUtil.getPluginProjects()) {
        SyncContext context;
        try {
            context = initSyncContext(pluginProject);
            context.setPreview(preview);
        } catch (InitSyncContextException e) {
            logger.info(e.getMessage());
            break;
        }

        Job sync = new SyncJob("Check sync for : " + pluginProject, context);
        sync.schedule();

    }
    return null;
}

From source file:com.legstar.eclipse.plugin.cixsmap.dialogs.LegacyMappingComposite.java

License:Open Source License

/**
 * Delete button was clicked, confirm and remove operation.
 *///w ww.j a  v  a  2  s  .c  om
private void handleDelete() {
    /* Check that at least one operation is selected */
    if (mOperationsTable.getSelectionIndices().length == 0) {
        MessageDialog.openError(null, Messages.operation_mapping_error_dialog_title,
                Messages.no_operations_selected_msg);
        return;
    }
    if (MessageDialog.openConfirm(null, Messages.operation_mapping_error_dialog_title,
            Messages.confirm_operation_delete_msg)) {
        /* Remove this operation from the service */
        for (int i = 0; i < mOperationsTable.getSelectionIndices().length; i++) {
            mMappingModel.getCixsOperations().remove(mOperationsTable.getSelectionIndices()[i]);
        }
        mOperationsTable.remove(mOperationsTable.getSelectionIndices());
        postProcessChange();
    }
}

From source file:com.legstar.eclipse.plugin.cixsmap.dialogs.StructuresTableComposite.java

License:Open Source License

/**
 * Delete button was clicked, confirm and remove structure.
 *///from   w ww. j a  va2  s  . c  o  m
private void handleDelete() {
    /* Check that at least one structure is selected */
    if (mStructuresTable.getSelectionIndices().length == 0) {
        MessageDialog.openError(null, Messages.structure_mapping_error_dialog_title,
                Messages.no_structure_selected_msg);
        return;
    }
    if (MessageDialog.openConfirm(null, Messages.structure_mapping_error_dialog_title,
            Messages.confirm_structure_delete_msg)) {
        /* Remove this structure from the structures */
        for (int i = 0; i < mStructuresTable.getSelectionIndices().length; i++) {
            mStructures.remove(mStructuresTable.getSelectionIndices()[i]);
        }
        mStructuresTable.remove(mStructuresTable.getSelectionIndices());
        enableButtons();
    }
}

From source file:com.liferay.ide.project.ui.migration.MigrateProjectHandler.java

License:Open Source License

private boolean showMessageDialog(IProject project) {
    final Display display = Display.getDefault();
    final Shell shell = display.getActiveShell();

    return MessageDialog.openConfirm(shell, "Migrate Liferay Plugin",
            "This project already contains migration problem markers.  All existing markers will be deleted.  "
                    + "Do you want to continue to run migration tool?");
}