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

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

Introduction

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

Prototype

public static void openError(Shell parent, String title, String message) 

Source Link

Document

Convenience method to open a standard error dialog.

Usage

From source file:com.amalto.workbench.actions.XSDSetFacetMessageAction.java

License:Open Source License

public IStatus doAction() {
    try {/* ww  w  . j  a va2 s. c o  m*/
        IStructuredSelection selection = (TreeSelection) page.getTreeViewer().getSelection();
        XSDComponent xSDCom = null;
        if (selection.getFirstElement() instanceof Element) {
            TreePath tPath = ((TreeSelection) selection).getPaths()[0];
            for (int i = 0; i < tPath.getSegmentCount(); i++) {
                if (tPath.getSegment(i) instanceof XSDAnnotation)
                    xSDCom = (XSDAnnotation) (tPath.getSegment(i));
            }
        } else
            xSDCom = (XSDComponent) selection.getFirstElement();
        XSDAnnotationsStructure struc = new XSDAnnotationsStructure(xSDCom);
        // IStructuredSelection selection = (IStructuredSelection)page.getTreeViewer().getSelection();
        // XSDAnnotationsStructure struc = new XSDAnnotationsStructure((XSDComponent)selection.getFirstElement());
        if (struc.getAnnotation() == null) {
            throw new RuntimeException(Messages.bind(Messages.XSDSetFacetMessageAction_ExceptionInfo,
                    selection.getFirstElement().getClass().getName()));
        }

        dlg = new AnnotationLanguageLabelsDialog(struc.getFactMessage(), new SelectionListener() {

            public void widgetDefaultSelected(SelectionEvent e) {
            }

            public void widgetSelected(SelectionEvent e) {
                dlg.close();
            }
        }, page.getSite().getShell(), Messages.XSDSetFacetMessageAction_DialogTip);

        dlg.setBlockOnOpen(true);
        int ret = dlg.open();
        if (ret == Window.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        LinkedHashMap<String, String> facets = dlg.getDescriptionsMap();
        struc.setFactMessage(facets);

        if (struc.hasChanged()) {
            page.refresh();
            page.getTreeViewer().expandToLevel(selection.getFirstElement(), 2);
            page.markDirty();
        }

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error,
                Messages.bind(Messages.XSDSetFacetMessageAction_ErrorMsg + e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }

    return Status.OK_STATUS;
}

From source file:com.amalto.workbench.compare.ResourceCompareInput.java

License:Open Source License

private void commitToDB() {

    try {/* w  w w .  ja  v a2 s  .  c  om*/
        String toCommitContent = CompareManager.getInstance().getLeftContent();
        toCommitContent = XmlUtil.formatCompact(toCommitContent, "UTF-8");//$NON-NLS-1$
        if (this.compareHeadInfo.isItem()) {
            Util.getMDMService(compareHeadInfo.getXobject())
                    .putItem(new WSPutItem(false, (WSDataClusterPK) compareHeadInfo.getXobject().getWsKey(), ""//$NON-NLS-1$
                            .equals(compareHeadInfo.getDataModelName()) ? null
                                    : new WSDataModelPK(compareHeadInfo.getDataModelName()),
                            toCommitContent));
        } else {
            // TODO add support for Object(s)

        }

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        if (!Util.handleConnectionException((Shell) null, e, null)) {
            MessageDialog.openError(null, Messages._Error,
                    Messages.bind(Messages.ResourceCompareInput_ErrorMsg, e.getLocalizedMessage()));
        }
    }

}

From source file:com.amalto.workbench.detailtabs.sections.CommitBarListenerSection.java

License:Open Source License

protected void handleCommitException(Exception e, String title) {

    MessageDialog.openError(getPart().getSite().getShell(), title, e.getMessage());

}

From source file:com.amalto.workbench.dialogs.AddBrowseItemsWizard.java

License:Open Source License

private boolean saveConfiguration() {
    Iterator<String> browseIterator = browseItemToRoles.keySet().iterator();
    while (browseIterator.hasNext()) {
        String browse = browseIterator.next();
        List<Line> roles = browseItemToRoles.get(browse);
        try {//from w  ww  . j  a v a2s.c  o m
            newBrowseItemView(browse);
            modifyRolesWithAttachedBrowseItem(browse, roles);
        } catch (WebServiceException e) {
            if (!Util.handleConnectionException(page, e, null)) {
                MessageDialog.openError(page.getSite().getShell(), Messages._Error,
                        Messages.bind(Messages.ErrorOccuredSaveView, e.getLocalizedMessage()));
            }
            return false;
        }
    }

    return true;
}

From source file:com.amalto.workbench.dialogs.BusinessElementInputDialog.java

License:Open Source License

@Override
protected void okPressed() {
    elementName = elementNameText.getText().trim();
    refName = refCombo.getText();/*  w  w  w  .  j  a va2s .  co m*/
    if (((elementName == null) || ("".equals(elementName))) && ((refName == null) || "".equals(refName))) {//$NON-NLS-1$//$NON-NLS-2$
        MessageDialog.openError(this.getShell(), Messages._Error,
                Messages.BusinessElementInputDialog_NameCannotbeEmptyIfXX);
        setReturnCode(-1);
        elementNameText.setFocus();
        return;
    }

    if (elementName.replaceAll("\\s", "").length() != elementName.length()) {//$NON-NLS-1$//$NON-NLS-2$
        MessageDialog.openError(this.getShell(), Messages._Error,
                Messages.BusinessElementInputDialog_NameCannotContainEmpty);
        setReturnCode(-1);
        elementNameText.setFocus();
        return;
    }

    if ("".equals(minOccursText.getText()) && "".equals(maxOccursText.getText())) {//$NON-NLS-1$//$NON-NLS-2$
        minOccurs = 1;
        maxOccurs = 1;
        return;
    }
    try {
        minOccurs = Integer.parseInt(minOccursText.getText());
    } catch (Exception e1) {
        MessageDialog.openError(this.getShell(), Messages._Error, Messages.BusinessElementInputDialog_ErrorMsg);
        setReturnCode(-1);
        minOccursText.setFocus();
        return;
    }
    if (minOccurs < 0) {
        MessageDialog.openError(this.getShell(), Messages._Error, Messages.BusinessElementInputDialog_ErrorMsg);
        setReturnCode(-1);
        minOccursText.setFocus();
        return;
    }

    if ("".equals(maxOccursText.getText())) {//$NON-NLS-1$
        maxOccurs = -1;
    } else {
        try {
            maxOccurs = Integer.parseInt(maxOccursText.getText());
        } catch (Exception e2) {
            MessageDialog.openError(this.getShell(), Messages._Error,
                    Messages.BusinessElementInputDialog_ErrorMsg1);
            setReturnCode(-1);
            maxOccursText.setFocus();
            return;
        }
        if ((maxOccurs < minOccurs) || (maxOccurs <= 0)) {
            maxOccurs = -1;
        }
    }

    setReturnCode(OK);
    // no close let Action Handler handle it
}

From source file:com.amalto.workbench.dialogs.ComplexTypeInputDialog.java

License:Open Source License

@Override
protected void okPressed() {
    typeName = conceptPanel.getText();//from   w w  w. j a  va 2  s.c  o  m
    superTypeName = conceptPanel.getSuperName();
    isAbstract = conceptPanel.isAbstract();
    isAll = conceptPanel.isAll();
    isChoice = conceptPanel.isChoice();
    isSequence = conceptPanel.isSequence();

    if (superTypeName.equals(typeName) && (!superTypeName.equals(""))) {//$NON-NLS-1$
        MessageDialog.openError(null, Messages._Error, Messages.typeCannotExtendsItsself);
        setReturnCode(CANCEL);
        return;
    }

    setReturnCode(OK);
    //        super.okPressed();
    // no close let Action Handler handle it
}

From source file:com.amalto.workbench.dialogs.ComplexTypeInputDialogR.java

License:Open Source License

private boolean valid() {
    elementName = elementNameText.getText().trim();
    if (((elementName == null) || ("".equals(elementName)))) {//$NON-NLS-1$
        MessageDialog.openError(this.getShell(), Messages._Error, Messages._BusinessNameCannotEmpty);
        setReturnCode(-1);//w w  w.ja  v a  2  s . co m
        elementNameText.setFocus();
        return false;
    }

    if (elementName.replaceAll("\\s", "").length() != elementName.length()) {//$NON-NLS-1$//$NON-NLS-2$
        MessageDialog.openError(this.getShell(), Messages._Error, Messages._BusinessNameCannotContainEmpty);
        setReturnCode(-1);
        elementNameText.setFocus();
        return false;
    }

    if ("".equals(minOccursText.getText()) && "".equals(maxOccursText.getText())) {//$NON-NLS-1$//$NON-NLS-2$
        minOccurs = 1;
        maxOccurs = 1;
        return false;
    }
    try {
        minOccurs = Integer.parseInt(minOccursText.getText());
    } catch (Exception e1) {
        MessageDialog.openError(this.getShell(), Messages._Error, Messages._MinNoLessThanZero);
        setReturnCode(-1);
        minOccursText.setFocus();
        return false;
    }
    if (minOccurs < 0) {
        MessageDialog.openError(this.getShell(), Messages._Error, Messages._MinNoLessThanZero);
        setReturnCode(-1);
        minOccursText.setFocus();
        return false;
    }

    if ("".equals(maxOccursText.getText())) {//$NON-NLS-1$
        maxOccurs = -1;
    } else {
        try {
            maxOccurs = Integer.parseInt(maxOccursText.getText());
        } catch (Exception e2) {
            MessageDialog.openError(this.getShell(), Messages._Error, Messages._MaxOccBeNum);
            setReturnCode(-1);
            maxOccursText.setFocus();
            return false;
        }
        if ((maxOccurs < minOccurs) || (maxOccurs <= 0)) {
            maxOccurs = -1;
        }
    }

    // check that this element does not already exist
    // get position of the selected particle in the container
    for (Iterator<XSDParticle> iter = group.getContents().iterator(); iter.hasNext();) {
        XSDParticle p = iter.next();
        if (p.getTerm() instanceof XSDElementDeclaration) {
            XSDElementDeclaration thisDecl = (XSDElementDeclaration) p.getTerm();
            if (thisDecl.getName().equals(elementName)) {
                MessageDialog.openError(getShell(), Messages._Error,
                        Messages.bind(Messages._BusinessEle, elementName));
                return false;
            }
        }
    } // for

    String typeName = getTypeName();

    if (!"".equals(typeName)) {//$NON-NLS-1$
        EList<XSDTypeDefinition> list = xsdSchema.getTypeDefinitions();
        for (Iterator<XSDTypeDefinition> iter = list.iterator(); iter.hasNext();) {
            XSDTypeDefinition td = iter.next();
            if (td.getName().equals(typeName)) {
                if (td instanceof XSDSimpleTypeDefinition) {
                    MessageDialog.openError(getShell(), Messages._Error,
                            Messages.bind(Messages._ThisType, typeName));
                    return false;
                }
            }
        }
    }

    return true;
}

From source file:com.amalto.workbench.dialogs.datacontainer.UpdateAutoIncrementDialog.java

License:Open Source License

private VerifyListener getVerifyListener() {
    if (verifyListeneer == null) {
        verifyListeneer = new VerifyListener() {

            public void verifyText(VerifyEvent e) {
                Text text = (Text) e.getSource();
                String msg = null;

                String inputStr = e.text;
                boolean matches = true;
                String digitRegex = "[0-9]*"; //$NON-NLS-1$
                matches = Pattern.matches(digitRegex, inputStr);
                if (!matches) {
                    msg = Messages.UpdateAutoIncrementDialog_inputInvalid;
                } else {
                    if (e.start == 0) {
                        if ((inputStr.startsWith(DEFAULT_VALUE) && inputStr.length() > 1)
                                || (inputStr.equals(DEFAULT_VALUE) && !isFullSelected(e))) {
                            matches = false;
                            msg = Messages.UpdateAutoIncrementDialog_zeroAtBeginning;
                        }//ww  w  . j a va 2 s.  co m
                    } else {
                        if (text.getText().startsWith(DEFAULT_VALUE)) {
                            matches = false;
                            msg = Messages.UpdateAutoIncrementDialog_zeroAtBeginning;
                        }
                    }
                }

                if (!matches) {
                    MessageDialog.openError(getShell(), Messages._Error, msg);
                    e.doit = false;
                    return;
                }

            }

            private boolean isFullSelected(VerifyEvent e) {
                Text text = (Text) e.getSource();
                String textContent = text.getText();
                if (textContent.length() == text.getSelectionCount()) {
                    return true;
                }

                return false;
            }
        };

    }
    return verifyListeneer;
}

From source file:com.amalto.workbench.dialogs.DOMViewDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {

    try {//w  w w.  j  av a 2  s  . c om
        // Should not really be here but well,....
        if (editable) {
            parent.getShell().setText(Messages.DOMViewDialog_EditorViewer);
        } else {
            parent.getShell().setText(Messages.DOMViewDialog_Viewer);
        }

        Composite composite = new Composite(parent, SWT.NULL);
        GridLayout layout = new GridLayout();
        layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
        layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
        layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
        layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
        composite.setLayout(layout);
        composite.setLayoutData(new GridData(GridData.FILL_BOTH));
        applyDialogFont(composite);

        if (desc != null && desc.length() > 0) {
            new Label(composite, SWT.NONE).setText(desc);
        }

        tabFolder = new TabFolder(composite, SWT.TOP | SWT.H_SCROLL | SWT.V_SCROLL);
        tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
        ((GridData) tabFolder.getLayoutData()).heightHint = 600;
        ((GridData) tabFolder.getLayoutData()).widthHint = 600;

        tabFolder.addSelectionListener(new SelectionListener() {

            public void widgetDefaultSelected(SelectionEvent e) {
            }

            public void widgetSelected(SelectionEvent e) {
                if (tabFolder.getSelectionIndex() == 0) {
                    if (node == null) {
                        try {

                            if (sourceViewer == null || sourceViewer.getDocument() == null) {
                                return;
                            }
                            node = Util.parse(sourceViewer.getText());

                        } catch (Exception ex) {

                            log.error(ex.getMessage(), ex);
                            tabFolder.setSelection(1);
                            MessageDialog.openError(DOMViewDialog.this.getShell(),
                                    Messages.DOMViewDialog_XMLInvalid, Messages.bind(
                                            Messages.DOMViewDialog_XMLInvalidInfo, ex.getLocalizedMessage()));
                            return;
                        }
                        domViewer.setInput(node);
                        domViewer.expandAll();
                    }
                } else if (tabFolder.getSelectionIndex() == 1) {
                    try {
                        sourceViewer.setText(Util.nodeToString(node));
                        node = null; // this should be better implemented in a change listener on the text
                    } catch (Exception ex) {
                        MessageDialog.openError(DOMViewDialog.this.getShell(),
                                Messages.DOMViewDialog_ErrorTitle,
                                Messages.bind(Messages.DOMViewDialog_ErrorMsg, ex.getLocalizedMessage()));
                        sourceViewer.setText(""); //$NON-NLS-1$
                    }
                }
            }// widget Selected
        });

        TabItem tiDOM = new TabItem(tabFolder, SWT.NULL);
        tiDOM.setText(Messages.DOMViewDialog_Tree);
        tiDOM.setToolTipText(Messages.DOMViewDialog_DisplayAsDomTree);

        domViewer = new TreeViewer(tabFolder, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
        domViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
        // ((GridData)domViewer.getControl().getLayoutData()).heightHint=300;
        // ((GridData)domViewer.getControl().getLayoutData()).widthHint=300;
        domViewer.setSorter(null);
        domViewer.setLabelProvider(new DOMTreeLabelProvider());
        domViewer.setContentProvider(new DOMTreeContentProvider());
        domViewer.setInput(node);
        domViewer.expandAll();
        domViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

        tiDOM.setControl(domViewer.getControl());

        TabItem tiSource = new TabItem(tabFolder, SWT.NULL);
        tiSource.setText(Messages.DOMViewDialog_TiSourceText);
        tiSource.setToolTipText(Messages.DOMViewDialog_TiSourceTip);

        XMLSourceViewerHelper sourceViewerHelper = XMLSourceViewerHelper.getInstance();
        sourceViewer = new XMLSourceViewer(tabFolder, sourceViewerHelper.createVerticalRuler(),
                sourceViewerHelper.createOverviewRuler(), true, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
        XMLConfiguration sourceViewerConfiguration = new XMLConfiguration(this);
        sourceViewer.configure(sourceViewerConfiguration);
        sourceViewer.initilize();
        sourceViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
        sourceViewer.setText(Util.nodeToString(node));
        sourceViewer.setEditable(this.editable);
        /*
         * sourceViewer.addTextListener( new ITextListener() { public void
         * textChanged(org.eclipse.jface.text.TextEvent event) { if ((event.getText()==null) ||
         * ("".equals(event.getText()))) return; node = null; elementChanged = true; } } );
         */
        tiSource.setControl(sourceViewer.getControl());

        tabFolder.setSelection(firstTab);
        if (firstTab == SOURCE_VIEWER) {
            node = null; // force refresh of tree
        }

        return composite;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(this.getShell(), Messages._Error,
                Messages.bind(Messages.DOMViewDialog_ErrorMsg1, e.getLocalizedMessage()));
        return null;
    }

}

From source file:com.amalto.workbench.dialogs.DOMViewDialog.java

License:Open Source License

@Override
protected void buttonPressed(int buttonId) {
    this.buttonPressed = buttonId;

    if (buttonId == BUTTON_SAVE) {
        // check that Data Model is not nul
        if (dataModelCombo.getSelectionIndex() == -1) {
            MessageDialog.openError(DOMViewDialog.this.getShell(), Messages.DOMViewDialog_ErrorTitle2,
                    Messages.DOMViewDialog_ErrorMsg2);
            return;
        }// w w  w .ja v  a 2 s  . co m
        // if save and on DOM viewer get the XML String
        if (tabFolder.getSelectionIndex() == 0) {
            try {
                sourceViewer.setText(Util.nodeToString(node));
            } catch (Exception ex) {
                tabFolder.setSelection(1);
                MessageDialog.openError(DOMViewDialog.this.getShell(), Messages.DOMViewDialog_ErrorTitle3,
                        Messages.bind(Messages.DOMViewDialog_ErrorMsg3, ex.getLocalizedMessage()));
                return;
            }
        }
    }

    Event e = new Event();
    e.button = buttonId;
    notifyListeners(e);
}