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.XSDDeleteConceptWrapAction.java

License:Open Source License

@Override
public IStatus doAction() {

    List<IStatus> results = new ArrayList<IStatus>();
    try {/*from  w  w  w.  ja va  2  s.  c om*/
        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        if (delObjs.isEmpty()) {
            return Status.CANCEL_STATUS;
        } else {
            boolean sameType = checkInSameClassType(delObjs.toArray(), delObjs.get(0).getClass());
            String deleteLabel = Messages.DelLabel1;
            String elemDesc = ((Action) clsAction.get(delObjs.get(0).getClass())).getText();
            int backPos = elemDesc.indexOf(" "); //$NON-NLS-1$

            if (delObjs.size() > 1) {
                deleteLabel += elemDesc.substring(0, backPos) + Messages.DelLabel2 + delObjs.size()
                        + Messages.DelLabel2A
                        + (!sameType ? Messages.DelLabel2B : elemDesc.substring(backPos + 1));
                if (deleteLabel.endsWith("y")) {//$NON-NLS-1$
                    deleteLabel = deleteLabel.substring(0, deleteLabel.length() - 1) + Messages.DelLabel3;
                } else {
                    deleteLabel = deleteLabel + Messages.XSDDeleteXX_DelLabel4;
                }
            } else {
                deleteLabel += elemDesc.substring(0, backPos) + Messages.XSDDeleteXX_DelLabel5
                        + (!sameType ? Messages.XSDDeleteXX_DelLabel5A : elemDesc.substring(backPos + 1));
            }

            if (!MessageDialog.openConfirm(page.getSite().getShell(), Messages.XSDDeleteXX_DialogTitle,
                    deleteLabel)) {
                return Status.CANCEL_STATUS;
            }
        }

        for (Iterator iterator = delObjs.iterator(); iterator.hasNext();) {
            Object toDel = iterator.next();
            UndoAction delExecute = null;
            boolean isElem = true;
            if (toDel instanceof XSDElementDeclaration) {
                XSDElementDeclaration decl = (XSDElementDeclaration) toDel;

                EList l = decl.getIdentityConstraintDefinitions();
                for (Iterator iter = l.iterator(); iter.hasNext();) {
                    XSDIdentityConstraintDefinition icd = (XSDIdentityConstraintDefinition) iter.next();
                    if (icd.getIdentityConstraintCategory()
                            .equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) {
                        isElem = false;
                        break;
                    }
                }
            }
            if (toDel instanceof XSDXPathDefinition) {
                XSDXPathDefinition xpath = (XSDXPathDefinition) toDel;
                if (!xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL)) {
                    continue;
                }
            }

            delExecute = clsAction.get(toDel.getClass());
            if (isElem && toDel instanceof XSDElementDeclaration) {
                delExecute = clsAction.get(null);
            }

            if (delExecute instanceof XSDDeleteConceptAction && toDel instanceof XSDElementDeclaration) {
                ((XSDDeleteConceptAction) delExecute).setXSDTODel((XSDElementDeclaration) toDel);
            } else if (delExecute instanceof XSDDeleteElementAction && toDel instanceof XSDElementDeclaration) {
                ((XSDDeleteElementAction) delExecute).setXSDTODel((XSDElementDeclaration) toDel);
            } else if (delExecute instanceof XSDDeleteParticleAction && toDel instanceof XSDParticle) {
                ((XSDDeleteParticleAction) delExecute).setXSDTODel((XSDParticle) toDel);
            } else if (delExecute instanceof XSDDeleteXPathAction && toDel instanceof XSDXPathDefinition) {
                ((XSDDeleteXPathAction) delExecute).setXSDTODel((XSDXPathDefinition) toDel);
            } else if (delExecute instanceof XSDDeleteIdentityConstraintAction
                    && toDel instanceof XSDIdentityConstraintDefinition) {
                ((XSDDeleteIdentityConstraintAction) delExecute)
                        .setXSDTODel((XSDIdentityConstraintDefinition) toDel);
            } else if (delExecute instanceof XSDDeleteTypeDefinition
                    && toDel instanceof XSDComplexTypeDefinition) {
                ((XSDDeleteTypeDefinition) delExecute).setXSDTODel((XSDComplexTypeDefinition) toDel);
            } else if (delExecute instanceof XSDDeleteTypeDefinition
                    && toDel instanceof XSDSimpleTypeDefinition) {
                ((XSDDeleteTypeDefinition) delExecute).setXSDTODel((XSDSimpleTypeDefinition) toDel);
            } else if (delExecute instanceof XSDDeleteAttributeAction && toDel instanceof XSDAttributeUse) {
                ((XSDDeleteAttributeAction) delExecute).setXSDAttributeUse((XSDAttributeUse) toDel);
            } else if (delExecute instanceof XSDDeleteAttributeAction
                    && toDel instanceof XSDAttributeDeclaration) {
                ((XSDDeleteAttributeAction) delExecute).setXSDAttribute((XSDAttributeDeclaration) toDel);
            } else {
                return Status.CANCEL_STATUS;
            }

            results.add(delExecute.execute());
        }

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error,
                Messages.bind(Messages.XSDDeleteXX_ErrorMsg, e.getLocalizedMessage()));

        return (results.indexOf(Status.OK_STATUS) >= 0 ? Status.OK_STATUS : Status.CANCEL_STATUS);
    }

    return (results.indexOf(Status.OK_STATUS) >= 0 ? Status.OK_STATUS : Status.CANCEL_STATUS);
}

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

License:Open Source License

public IStatus doAction() {
    try {//ww  w  .  j av a2 s  . c  o  m

        // xsdElem is to support the multiple delete action on key press,
        // which each delete action on element must be explicit passed a xsdElem to
        // delete
        XSDElementDeclaration decl = xsdElem;
        if (decl == null) {
            ISelection selection = page.getTreeViewer().getSelection();
            decl = (XSDElementDeclaration) ((IStructuredSelection) selection).getFirstElement();
        }

        ArrayList<Object> objList = new ArrayList<Object>();
        IStructuredContentProvider provider = (IStructuredContentProvider) page.getTreeViewer()
                .getContentProvider();
        Object[] all = Util.getAllObject(page.getSite(), objList, provider);
        Util.deleteReference(decl, all);

        // remove declaration
        schema.getContents().remove(decl);

        schema.update();

        xsdElem = null;
        page.refresh();
        page.markDirtyWithoutCommit();

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

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

License:Open Source License

public IStatus doAction() {
    try {//from w  w w .  ja  v a  2  s.co  m

        // xsdIdenty is to support the multiple delete action on key press,
        // which each delete action on identity must be explicit passed a xsd key to
        // delete
        XSDIdentityConstraintDefinition constraint = xsdIdenty;
        XSDElementDeclaration decl = null;
        if (constraint != null) {
            decl = (XSDElementDeclaration) constraint.getContainer();
            if (decl == null)
                return Status.CANCEL_STATUS;
        }

        if (decl == null) {
            IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
            constraint = (XSDIdentityConstraintDefinition) selection.getFirstElement();
            decl = (XSDElementDeclaration) constraint.getContainer();
        }
        /*
         * REMOVE so that simple elements can be made if (
         * (constraint.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) &&
         * (decl.getContainer().equals(decl.getSchema())) ) { MessageDialog.openError(
         * this.page.getSite().getShell(), "Error", "Entities must have an unique key" ); return; }
         */

        decl.getIdentityConstraintDefinitions().remove(constraint);
        decl.updateElement();
        xsdIdenty = null;
        page.refresh();
        page.markDirty();

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

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

License:Open Source License

public IStatus doAction() {
    try {/*from  ww  w .j  a v a2s. c o  m*/

        // xsdPartle is to support the multiple delete action on key press,
        // which each delete action on particle must be explicit passed a xsd particle to
        // delete
        XSDParticle particle = (XSDParticle) xsdPartle;
        if (particle == null) {
            ISelection selection = page.getTreeViewer().getSelection();
            particle = (XSDParticle) ((IStructuredSelection) selection).getFirstElement();
        }
        XSDTerm term = particle.getTerm();

        XSDElementDeclaration decl = null;
        if (term instanceof XSDElementDeclaration) {
            decl = (XSDElementDeclaration) particle.getTerm();
        }

        if (particle.getContainer() == null) {
            return Status.CANCEL_STATUS;
        }

        XSDIdentityConstraintDefinition identify = null;
        XSDXPathDefinition keyPath = null;
        List<Object> keyInfo = Util.getKeyInfo(decl);
        if (keyInfo != null && keyInfo.size() > 0) {
            identify = (XSDIdentityConstraintDefinition) keyInfo.get(0);
            keyPath = (XSDXPathDefinition) keyInfo.get(1);
            identify.getFields().remove(keyPath);
            if (identify.getFields().size() == 0) {
                XSDElementDeclaration top = (XSDElementDeclaration) Util.getParent(decl);
                top.getIdentityConstraintDefinitions().remove(identify);
            }
        }
        if (!(particle.getContainer() instanceof XSDModelGroup))
            throw new XtentisException(Messages.bind(Messages.XSDDeleteParticleAction_ExceptionInfo,
                    particle.getContainer().getClass().getName()));

        XSDModelGroup group = (XSDModelGroup) particle.getContainer();
        group.getContents().remove(particle);

        // if (term instanceof XSDElementDeclaration) {
        // //remove type definition is no more used and type is not built in
        // XSDTypeDefinition typeDef = decl.getTypeDefinition();
        // if ( (typeDef.getName()!=null) && //anonymous type
        // (!typeDef.getSchema().getSchemaForSchemaNamespace().equals(typeDef.getTargetNamespace()))
        // ){
        // if (Util.findElementsUsingType(group.getSchema(),typeDef.getTargetNamespace(),
        // typeDef.getName()).size()==0)
        // group.getSchema().getContents().remove(typeDef);
        // }
        // }

        group.updateElement();
        xsdPartle = null;
        page.refresh();
        page.markDirty();

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

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

License:Open Source License

public IStatus doAction() {
    try {/*from  ww w . j  a  v  a 2s . c  om*/

        // xsdPath is to support the multiple delete action on key press,
        // which each delete action on xpath must be explicit passed a xsd path to
        // delete
        XSDXPathDefinition xpath = xsdPath;
        if (xpath == null) {
            ISelection selection = page.getTreeViewer().getSelection();
            xpath = (XSDXPathDefinition) ((IStructuredSelection) selection).getFirstElement();
        }
        XSDIdentityConstraintDefinition icd = (XSDIdentityConstraintDefinition) xpath.getContainer();
        if (icd == null)
            return Status.CANCEL_STATUS;

        if (xpath.getVariety().equals(XSDXPathVariety.SELECTOR_LITERAL)) {
            MessageDialog.openError(page.getSite().getShell(), Messages._Error,
                    Messages.XSDDeleteXPathAction_SelectorCannotDel);
            return Status.CANCEL_STATUS;
        }

        if (icd.getFields().size() == 1) {
            MessageDialog.openError(page.getSite().getShell(), Messages._Error,
                    Messages.XSDDeleteXPathAction_KeyMustContainOne);
            return Status.CANCEL_STATUS;
        }

        icd.getFields().remove(xpath);
        icd.updateElement();
        xsdPath = null;
        page.refresh();
        page.markDirty();

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error,
                Messages.bind(Messages.XSDDeleteXPathAction_ErrorRemoveAField, e.getLocalizedMessage()));

        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}

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

License:Open Source License

@Override
public IStatus doAction() {
    try {/*from w ww. j  a va  2 s  .c  o  m*/
        ISelection selection = page.getTreeViewer().getSelection();
        IStructuredContentProvider provider = (IStructuredContentProvider) page.getSchemaContentProvider();
        XSDComplexTypeDefinition decl = (XSDComplexTypeDefinition) ((IStructuredSelection) selection)
                .getFirstElement();

        String oldName = decl.getName();
        InputDialog id = new InputDialog(page.getSite().getShell(),
                Messages.XSDEditComplexTypeAction_EditComplexType,
                Messages.XSDEditComplexTypeAction_EnterNameForEntity, oldName, new IInputValidator() {

                    public String isValid(String newText) {
                        if ((newText == null) || "".equals(newText)) //$NON-NLS-1$
                            return Messages.XSDEditComplexTypeAction_ComplexTypeCannotBeEmpty;

                        if (Pattern.compile("^\\s+\\w+\\s*").matcher(newText).matches()//$NON-NLS-1$
                                || newText.trim().replaceAll("\\s", "").length() != newText.trim().length())//$NON-NLS-1$//$NON-NLS-2$
                            return Messages.XSDEditComplexTypeAction_NameCannotContainEmpty;
                        if (!XSDUtil.isValidatedXSDName(newText)) {
                            return Messages.InvalidName_Message;
                        }
                        EList list = schema.getTypeDefinitions();
                        for (Iterator iter = list.iterator(); iter.hasNext();) {
                            Object d = iter.next();
                            if (d instanceof XSDComplexTypeDefinition) {
                                XSDComplexTypeDefinition type = (XSDComplexTypeDefinition) d;
                                if (type.getName().equals(newText.trim()))
                                    return Messages.XSDEditComplexTypeAction_ComplexAlreadyExists;
                            }
                        }
                        return null;
                    };
                });

        id.setBlockOnOpen(true);
        int ret = id.open();
        if (ret == Dialog.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        decl.setName(id.getValue().trim());

        Util.updateReferenceToXSDTypeDefinition(page.getSite(), decl, provider);
        page.refresh();
        page.markDirty();

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

    return Status.OK_STATUS;
}

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

License:Open Source License

@Override
public IStatus doAction() {
    try {//from  w w  w.  ja  v a2  s.  c  o  m
        ISelection selection = page.getTreeViewer().getSelection();
        XSDElementDeclaration decl = (XSDElementDeclaration) ((IStructuredSelection) selection)
                .getFirstElement();
        ArrayList<Object> objList = new ArrayList<Object>();
        IStructuredContentProvider provider = (IStructuredContentProvider) page.getTreeViewer()
                .getContentProvider();
        String oldName = decl.getName();

        InputDialog id = new InputDialog(page.getSite().getShell(), Messages.XSDEditConceptAction_Text,
                Messages.XSDEditConceptAction_DialogTip, oldName, new IInputValidator() {

                    public String isValid(String newText) {
                        if ((newText == null) || "".equals(newText)) {
                            return Messages.XSDEditConceptAction_NameCannotBeEmpty;
                        }

                        if (Pattern.compile("^\\s+\\w+\\s*").matcher(newText).matches()//$NON-NLS-1$
                                || newText.trim().replaceAll("\\s", "").length() != newText.trim().length()) {
                            return Messages.XSDEditConceptAction_NameCannotContainEmpty;
                        }
                        if (!XSDUtil.isValidatedXSDName(newText)) {
                            return Messages.InvalidName_Message;
                        }
                        EList list = schema.getElementDeclarations();
                        for (Iterator iter = list.iterator(); iter.hasNext();) {
                            XSDElementDeclaration d = (XSDElementDeclaration) iter.next();
                            if (d.getName().equalsIgnoreCase(newText.trim())) {
                                return Messages.XSDEditConceptAction_EntityAlreadyExist;
                            }
                        }
                        return null;
                    };
                });

        id.setBlockOnOpen(true);
        int ret = id.open();
        if (ret == Dialog.CANCEL) {
            return Status.CANCEL_STATUS;
        }

        Object[] objs = Util.getAllObject(page.getSite(), objList, provider);
        Object[] allForeignKeyRelatedInfos = Util.getAllForeignKeyRelatedInfos(page.getSite(),
                new ArrayList<Object>(), provider, new HashSet<Object>());

        String newName = id.getValue().trim();
        decl.setName(newName);
        decl.updateElement();
        Util.updateReference(decl, objs, allForeignKeyRelatedInfos, oldName, newName);

        EntitySyncProcessor.syncNameForAnnotation(decl, oldName, newName);

        if (mapinfoExAdapter != null) {
            mapinfoExAdapter.renameEntityMapinfo(oldName, newName);
        }
        if (elementExAdapter != null) {
            elementExAdapter.renameEntityName(decl.getSchema(), oldName, newName);
        }
        // change unique key with new name of concept
        EList list = decl.getIdentityConstraintDefinitions();
        XSDIdentityConstraintDefinition toUpdate = null;
        for (Iterator iter = list.iterator(); iter.hasNext();) {
            XSDIdentityConstraintDefinition icd = (XSDIdentityConstraintDefinition) iter.next();
            if (icd.getName().equals(oldName)) {
                toUpdate = icd;
                break;
            }
        }
        if (toUpdate != null) {
            toUpdate.setName(newName);
            toUpdate.updateElement();
        }

        page.refresh();
        page.markDirty();
        // page.refreshPage();

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

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

License:Open Source License

@Override
public IStatus doAction() {
    try {//from   w w  w  .  ja v a 2  s  .  com
        ISelection selection = page.getTreeViewer().getSelection();
        XSDElementDeclaration decl = (XSDElementDeclaration) ((IStructuredSelection) selection)
                .getFirstElement();
        ArrayList<Object> objList = new ArrayList<Object>();
        IStructuredContentProvider provider = (IStructuredContentProvider) page.getTreeViewer()
                .getContentProvider();
        String oldName = decl.getName();

        InputDialog id = new InputDialog(page.getSite().getShell(), Messages.XSDEditElementAction_EditElement,
                Messages.XSDEditElementAction_EnterNameForElement, oldName,
                new EditXSDEleDecNameValidator(schema)
        // new IInputValidator() {
        // public String isValid(String newText) {
        // if ((newText==null) || "".equals(newText)) return "The Entity Name cannot be empty";
        // EList list = schema.getElementDeclarations();
        // for (Iterator iter = list.iterator(); iter.hasNext(); ) {
        // XSDElementDeclaration d = (XSDElementDeclaration) iter.next();
        // if (d.getName().equals(newText)) return "This Entity already exists";
        // }
        // return null;
        // };
        // }
        );

        id.setBlockOnOpen(true);
        int ret = id.open();
        if (ret == Window.CANCEL) {
            return Status.CANCEL_STATUS;
        }

        Object[] objs = Util.getAllObject(page.getSite(), objList, provider);
        Object[] allForeignKeyRelatedInfos = Util.getAllForeignKeyRelatedInfos(page.getSite(),
                new ArrayList<Object>(), provider, new HashSet<Object>());

        decl.setName(id.getValue());
        decl.updateElement();
        Util.updateReference(decl, objs, allForeignKeyRelatedInfos, oldName, id.getValue());
        // change unique key with new name of concept
        EList list = decl.getIdentityConstraintDefinitions();
        XSDIdentityConstraintDefinition toUpdate = null;
        for (Iterator iter = list.iterator(); iter.hasNext();) {
            XSDIdentityConstraintDefinition icd = (XSDIdentityConstraintDefinition) iter.next();
            if (icd.getName().equals(oldName)) {
                toUpdate = icd;
                break;
            }
        }
        if (toUpdate != null) {
            toUpdate.setName(id.getValue());
            toUpdate.updateElement();
        }

        page.refresh();
        page.markDirty();

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

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

License:Open Source License

@Override
public IStatus doAction() {
    try {// w  w  w .  j av  a  2 s.  c  o m

        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();

        XSDComponent xSDCom = null;
        if (selection.getFirstElement() instanceof XSDSimpleTypeDefinition) {
            std = (XSDSimpleTypeDefinition) selection.getFirstElement();
        } else {
            TreePath tPath = ((TreeSelection) selection).getPaths()[0];
            for (int i = 0; i < tPath.getSegmentCount(); i++) {
                if (tPath.getSegment(i) instanceof XSDSimpleTypeDefinition) {
                    std = (XSDSimpleTypeDefinition) (tPath.getSegment(i));
                }
            }
        }
        // std = (XSDSimpleTypeDefinition)((IStructuredSelection)selection).getFirstElement();
        /**
         * totalDigits, fractionDigits, maxInclusive, maxExclusive, minInclusive, minExclusive
         */
        if (facetName.equals("pattern")) {//$NON-NLS-1$
            editPattern();
        } else if (facetName.equals("enumeration")) {//$NON-NLS-1$
            editEnumeration();
        } else if (facetName.equals("length")) {//$NON-NLS-1$
            editLength();
        } else if (facetName.equals("minLength")) {//$NON-NLS-1$
            editMinLength();
        } else if (facetName.equals("maxLength")) {//$NON-NLS-1$
            editMaxLength();
        } else if (facetName.equals("totalDigits")) {//$NON-NLS-1$
            editTotalDigits();
        } else if (facetName.equals("fractionDigits")) {//$NON-NLS-1$
            editFractionDigits();
        } else if (facetName.equals("maxInclusive")) {//$NON-NLS-1$
            editMaxInclusive();
        } else if (facetName.equals("maxExclusive")) {//$NON-NLS-1$
            editMaxExclusive();
        } else if (facetName.equals("minInclusive")) {//$NON-NLS-1$
            editMinInclusive();
        } else if (facetName.equals("minExclusive")) {//$NON-NLS-1$
            editMinExclusive();
        } else if (facetName.equals("whiteSpace")) {//$NON-NLS-1$
            editWhiteSpace();
        }

        else {
            MessageDialog.openError(page.getSite().getShell(), Messages._Error,
                    Messages.bind(Messages.XSDEditFacetAction_ErrorMsg1, facetName));
            return Status.CANCEL_STATUS;
        }

        std.updateElement();

        page.getTreeViewer().refresh(true);
        page.markDirty();
        page.refresh();

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

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

License:Open Source License

public IStatus doAction() {
    try {/*from   w  w w. java 2 s. com*/

        ISelection selection = page.getTreeViewer().getSelection();
        constraint = (XSDIdentityConstraintDefinition) ((IStructuredSelection) selection).getFirstElement();
        String oldName = constraint.getName();

        InputDialog id = new InputDialog(page.getSite().getShell(), Messages.XSDEditIdentityXX_EditKey,
                Messages.XSDEditIdentityXX_EnterANameForKey, oldName,
                new EditXSDIdentityConstraintNameValidator(constraint)
        // new IInputValidator() {
        // public String isValid(String newText) {
        // if ((newText==null) || "".equals(newText)) return "The Entity Name cannot be empty";
        // XSDSchema schema = XSDEditIdentityConstraintAction.this.constraint.getSchema();
        // EList list = schema.getIdentityConstraintDefinitions();
        // for (Iterator iter = list.iterator(); iter.hasNext(); ) {
        // XSDIdentityConstraintDefinition icd = (XSDIdentityConstraintDefinition) iter.next();
        // if (icd.getName().equals(newText)) return "This Key already exists";
        // }
        // return null;
        // };
        // }
        );

        id.setBlockOnOpen(true);
        int ret = id.open();
        if (ret == Dialog.CANCEL) {
            return Status.CANCEL_STATUS;
        }

        if (XSDIdentityConstraintCategory.UNIQUE_LITERAL.equals(constraint.getIdentityConstraintCategory())
                && !((XSDElementDeclaration) constraint.getContainer()).getName().equals(id.getValue())) {

            MessageDialog.openWarning(page.getSite().getShell(), Messages.Warning,
                    Messages.XSDEditIdentityXX_WarningMsg);
            return Status.CANCEL_STATUS;
        }

        constraint.setName(id.getValue());
        constraint.updateElement();

        page.refresh();
        page.markDirty();

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