Example usage for org.eclipse.jface.dialogs InputDialog setErrorMessage

List of usage examples for org.eclipse.jface.dialogs InputDialog setErrorMessage

Introduction

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

Prototype

public void setErrorMessage(String errorMessage) 

Source Link

Document

Sets or clears the error message.

Usage

From source file:org.objectstyle.wolips.ui.actions.FindUnusedWOCodeAction.java

License:Open Source License

public void run(IAction action) {
    IWorkbench workbench = PlatformUI.getWorkbench();
    shell = workbench.getActiveWorkbenchWindow().getShell();

    if (selection instanceof IStructuredSelection) {
        for (Iterator it = ((IStructuredSelection) selection).iterator(); it.hasNext();) {
            Object element = it.next();
            IProject project = null;/*w ww. j  ava  2s.  c o  m*/
            if (element instanceof IProject) {
                project = (IProject) element;
            } else if (element instanceof IAdaptable) {
                project = (IProject) ((IAdaptable) element).getAdapter(IProject.class);
            }

            if (project != null) {
                if (MessageDialog.openConfirm(shell, "Confirm action",
                        "Processing project: " + project.getName() + "\n\n"
                                + "Please save changes before and check that no compiler errors exist.")) {
                    try {
                        IJavaProject javaProject = JavaCore.create(project);

                        MethodSearch methodSearcher = new MethodSearch(javaProject);
                        IRunnableWithProgress op = methodSearcher;
                        ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(shell);
                        progressDialog.run(true, true, op);

                        // output format?
                        MessageDialog formatDialog = new MessageDialog(shell, "Output Format", null,
                                "What kind of output do you want?", 0,
                                new String[] { "cancel", "Comments", "Text File", }, 1);
                        formatDialog.open();
                        if (formatDialog.getReturnCode() == 2) {
                            // text file
                            InputDialog inputDialog = new InputDialog(shell, "Output text file",
                                    "Where do you want to save the file?", "file path including name", null);
                            inputDialog.open();
                            if (inputDialog.getReturnCode() == Window.OK) {
                                String path = inputDialog.getValue();
                                while (path == null || path.length() == 0) {
                                    inputDialog.open();
                                    inputDialog.setErrorMessage("Wrong Input");
                                    path = inputDialog.getValue();
                                }
                                methodSearcher.writePossiblyUnusedMethodsToFile(new File(path));
                            }
                        } else if (formatDialog.getReturnCode() == 1) {
                            // comments
                            if (!methodSearcher.setComments()) {
                                throw new InterruptedException();
                            }
                        }
                    } catch (InvocationTargetException e) {
                        StackTraceElement[] stackTraces = e.getStackTrace();
                        String stackTraceString = "";
                        for (int i = 0; i < stackTraces.length; i++) {
                            stackTraceString += stackTraces[i].toString() + "\n";
                        }
                        MessageDialog.openError(shell, "Error", "Error searching for unused WO code:\n\n"
                                + e.toString() + "\n\n" + e.getCause().toString());
                    } catch (InterruptedException e) {
                        MessageDialog.openWarning(shell, "Process Canceled",
                                "Search for unsused WO code canceled");
                    }
                }
            }
        }
    }
}

From source file:org.talend.designer.hl7.action.CreateHL7ElementAction.java

License:Open Source License

/**
 * Create the child node of the input node
 *
 * @param node/*from w ww  .  j a  v  a  2 s.  c om*/
 */
private boolean createChildNode(final HL7TreeNode node) {
    if (node.getColumn() != null) {
        if (!MessageDialog.openConfirm(xmlViewer.getControl().getShell(), "Warning",
                "Do you want to disconnect the existing linker and then add an sub element for the selected element"
                        + node.getLabel() + "\"?")) {
            return false;
        }
        node.setColumn(null);
    }
    String label = "";
    final String nodeLabel = node.getLabel() + "-";
    while (!StringUtil.validateLabelForXML(label)) {
        // add validator
        IInputValidator validator = new IInputValidator() {

            @Override
            public String isValid(String newText) {
                if (newText != null) {
                    String text = newText.trim();
                    for (HL7TreeNode children : node.getChildren()) {
                        if (text.equals(children.getLabel())) {
                            return "The name already existed."; //$NON-NLS-1$
                        }
                    }
                }
                return null;
            }
        };
        InputDialog dialog = new InputDialog(null, "Input element's label",
                "Input the new element's valid label", nodeLabel, validator) {

            /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.jface.dialogs.Dialog#okPressed()
             */
            @Override
            protected void okPressed() {
                super.okPressed();
            }

        };
        dialog.setErrorMessage("name is error");
        int status = dialog.open();
        if (status == InputDialog.OK) {
            label = dialog.getValue().trim();
        }
        if (status == InputDialog.CANCEL) {
            return false;
        }
    }
    HL7TreeNode child = new Element(label);
    // if the root not have CurSchema
    if (node.getRow() == null || node.getRow().equals("")) {
        if (hl7ui != null && hl7ui.gethl7Manager() instanceof HL7OutputManager) {
            if (label.length() == 3) {
                child.setRow(label);
                IMetadataTable table = null;
                for (IMetadataTable curTable : hl7ui.gethl7Manager().getHl7Component().getMetadataList()) {
                    if (label.equals(curTable.getLabel())) {
                        table = curTable;
                        break;
                    }
                }
                if (table == null) {
                    table = new MetadataTable();
                    table.setLabel(label);
                    table.setTableName(label);
                    hl7ui.gethl7Manager().getHl7Component().getMetadataList().add(table);
                }
                List<Map<String, String>> maps = (List<Map<String, String>>) hl7ui.gethl7Manager()
                        .getHl7Component().getElementParameter("SCHEMAS").getValue(); //$NON-NLS-1$
                boolean found = false;
                for (Map<String, String> map : maps) {
                    if (map.get("SCHEMA").equals(table.getTableName())) {
                        found = true;
                    }
                }
                if (!found) {
                    Map<String, String> hl7Schema = new HashMap<String, String>();
                    maps.add(hl7Schema);
                    hl7Schema.put("SCHEMA", table.getTableName());
                }
            }
        } else if (label.length() == 3) {
            child.setRow(label);
        }
    } else {
        child.setRow(node.getRow());
    }

    node.addChild(child);
    this.xmlViewer.refresh();
    return true;
}