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

License:Open Source License

public IStatus doAction() {
    try {//  w w w .  jav  a 2  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);
        struc.setXSDSchema(schema);
        // IStructuredSelection selection = (IStructuredSelection) page
        // .getTreeViewer().getSelection();
        // XSDAnnotationsStructure struc = new XSDAnnotationsStructure(
        // (XSDComponent) selection.getFirstElement());
        if (struc.getAnnotation() == null) {
            throw new RuntimeException(Messages.bind(Messages.XSDAnnotationLookupFieldsAction_ExceptionInfo,
                    xSDCom.getClass().getName()));
        }

        dlg = new AnnotationOrderedListsDialog(new ArrayList(struc.getLookupFields().values()),
                new SelectionListener() {

                    public void widgetDefaultSelected(SelectionEvent e) {
                    }

                    public void widgetSelected(SelectionEvent e) {
                        dlg.close();
                    }
                }, page.getSite().getShell(), Messages.XSDAnnotationLookupFieldsAction_SetLookupFields,
                Messages.XSDAnnotationLookupFieldsAction_LookupFields, page,
                AnnotationOrderedListsDialog.AnnotationLookupField_ActionType, null);

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

        struc.setAccessRole(dlg.getXPaths(), false,
                (IStructuredContentProvider) page.getTreeViewer().getContentProvider(), "X_Lookup_Field");//$NON-NLS-1$

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

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

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

License:Open Source License

@Override
public IStatus doAction() {
    try {/*from ww w.  j  a v a  2  s .c o  m*/
        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        XSDSimpleTypeDefinition typedef = (XSDSimpleTypeDefinition) selection.getFirstElement();

        // Cannot change the simple type definition of built in type
        // if (schema.getSchemaForSchemaNamespace().equals(typedef.getTargetNamespace())) return
        // Status.CANCEL_STATUS;

        // build list of custom types and built in types
        ArrayList customTypes = new ArrayList();
        for (Object element : schema.getTypeDefinitions()) {
            XSDTypeDefinition type = (XSDTypeDefinition) element;
            if (type instanceof XSDSimpleTypeDefinition) {
                if (type.getTargetNamespace() != null
                        && !type.getTargetNamespace().equals(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001)
                        || type.getTargetNamespace() == null) {
                    customTypes.add(type.getName());
                }
            }
        }
        List builtInTypes = XSDUtil.getBuiltInTypes();
        // can't change builtin's base type
        if (builtInTypes.contains(typedef.getName())) {
            return Status.CANCEL_STATUS;
        }
        dialog = new SimpleTypeInputDialog(this, page.getSite().getShell(), schema,
                Messages.XSDChangeBaseTypeAction_DialogTitle, customTypes, builtInTypes,
                typedef.getBaseTypeDefinition().getName());

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

        // backup current Base Type
        XSDTypeDefinition current = typedef.getBaseTypeDefinition();

        // set new one
        if (builtIn) {
            typedef.setBaseTypeDefinition(
                    schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), typeName));
        } else {
            // check if simple type definition already exists
            XSDSimpleTypeDefinition std = schema.resolveSimpleTypeDefinition(typeName);
            if (!schema.getTypeDefinitions().contains(std)) {
                std.setBaseTypeDefinition(
                        schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), "string"));//$NON-NLS-1$
                schema.getContents().add(std);
            }
            typedef.setBaseTypeDefinition(std);
        }

        // remove current facets
        typedef.getFacetContents().removeAll(typedef.getFacetContents());

        typedef.updateElement();

        if (builtIn) {
            EList<XSDConstrainingFacet> constrainFacts = typedef.getBaseTypeDefinition().getFacetContents();
            for (XSDConstrainingFacet fact : constrainFacts) {
                if (fact instanceof XSDPatternFacet) {
                    XSDPatternFacet newFact = XSDSchemaBuildingTools.getXSDFactory().createXSDPatternFacet();
                    newFact.setLexicalValue(((XSDPatternFacet) fact).getLexicalValue());
                    typedef.getFacetContents().add(newFact);
                }
            }
            typedef.updateElement();
        }

        // remove current if no more in use
        // if ( (current.getName()!=null) && //anonymous type
        // (!schema.getSchemaForSchemaNamespace().equals(current.getTargetNamespace()))
        // ){
        // List eut =Util.findElementsUsingType(schema, current.getTargetNamespace(), current.getName());
        // if (eut.size()==0)
        // schema.getContents().remove(current);
        // }

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

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

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

License:Open Source License

public void widgetSelected(SelectionEvent e) {
    if (dialog.getReturnCode() == -1) {
        return;//from w w w.  j  a v  a2 s. c  o m
    }
    typeName = dialog.getTypeName();
    builtIn = dialog.isBuiltIn();

    // if built in, check that the type actually exists
    if (builtIn) {
        boolean found = false;
        for (Object element : schema.getSchemaForSchema().getTypeDefinitions()) {
            XSDTypeDefinition type = (XSDTypeDefinition) element;
            if (type instanceof XSDSimpleTypeDefinition) {
                if (type.getName().equals(typeName)) {
                    found = true;
                    break;
                }
            }
        }
        if (!found) {
            MessageDialog.openError(page.getSite().getShell(), Messages._Error,
                    Messages.bind(Messages.XSDChangeBaseTypeAction_ErrorMsg2, typeName));
            return;
        }
    }
    dialog.close();
}

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

License:Open Source License

@Override
public IStatus doAction() {

    try {//from  w ww  .  j a  va2  s.  co m
        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        isConcept = false;
        TreePath tPath = null;
        if (((TreeSelection) selection).getPaths().length > 0) {
            tPath = ((TreeSelection) selection).getPaths()[0];
        }
        // fliu
        // add declNew to support convert action invoked from new concept/new element menu, in this case
        // declNew is the new created one not the selected one in tree vew
        if (declNew != null) {
            decl = declNew;
            checkConcept();
        } else if (selection.getFirstElement() instanceof XSDModelGroup) {
            for (int i = 0; i < tPath.getSegmentCount(); i++) {
                if (tPath.getSegment(i) instanceof XSDElementDeclaration) {
                    decl = (XSDElementDeclaration) tPath.getSegment(i);
                } else if (tPath.getSegment(i) instanceof XSDParticle) {
                    decl = (XSDElementDeclaration) ((XSDParticle) tPath.getSegment(i)).getTerm();
                }
            }
            checkConcept();
        } else if (selection.getFirstElement() instanceof XSDElementDeclaration) {
            decl = (XSDElementDeclaration) selection.getFirstElement();
            // check if concept or "just" element
            checkConcept();

        } else if (selection.getFirstElement() instanceof XSDParticle) {
            // if it's a particle,it should change the element of its
            // content
            decl = (XSDElementDeclaration) ((XSDParticle) selection.getFirstElement()).getContent();
        } else {
            // if(selection.getFirstElement() instanceof XSDParticle )
            if (selection.getFirstElement() != null) {
                // a sub element
                decl = (XSDElementDeclaration) ((XSDParticle) selection.getFirstElement()).getTerm();
            }
        }

        // /save current Type Definition
        // XSDTypeDefinition current = decl.getTypeDefinition();
        List<XSDComplexTypeDefinition> types = Util.getComplexTypes(decl.getSchema());
        if (showDlg) {
            if (decl.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
                boolean confirm = MessageDialog.openConfirm(page.getSite().getShell(), Messages.Warning,
                        Messages.XSDChangeToCXX_ChangeToAnotherTypeWarning);
                if (!confirm) {
                    return Status.CANCEL_STATUS;
                }
            }

            if (tPath != null) {
                for (int i = 0; i < tPath.getSegmentCount(); i++) {
                    if (tPath.getSegment(i) instanceof XSDElementDeclaration) {
                        XSDTypeDefinition type = (((XSDElementDeclaration) tPath.getSegment(i))
                                .getTypeDefinition());
                        if (!type.equals(decl.getTypeDefinition())) {
                            types.remove(type);
                        }
                    }
                    if (tPath.getSegment(i) instanceof XSDParticle) {
                        XSDTypeDefinition type = ((XSDElementDeclaration) (((XSDParticle) tPath.getSegment(i))
                                .getTerm())).getTypeDefinition();
                        if (!type.equals(decl.getTypeDefinition())) {
                            types.remove(type);
                        }
                    }
                }
            }
            dialog = new ComplexTypeInputDialog(this, page.getSite().getShell(), "", schema, //$NON-NLS-1$
                    decl.getTypeDefinition(), types, isXSDModelGroup);

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

        if (!showDlg && !validateType()) {
            return Status.CANCEL_STATUS;
        }

        XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
        boolean anonymous = (typeName == null) || ("".equals(typeName));//$NON-NLS-1$
        boolean alreadyExists = false;

        XSDComplexTypeDefinition complexType = null;
        // the sub element created if needed
        XSDParticle subParticle = null;
        XSDParticle groupParticle = null;
        XSDElementDeclaration subElement = null;

        // check if already exist
        // add by ymli; fix the bug:0012278;
        XSDElementDeclaration parent = null;
        Object pObject = Util.getParent(decl);
        if (pObject instanceof XSDElementDeclaration) {
            parent = (XSDElementDeclaration) pObject;
        }

        if (!anonymous) {
            List<XSDComplexTypeDefinition> list = Util.getComplexTypes(schema);
            if (typeName.lastIndexOf(" : ") != -1) {//$NON-NLS-1$
                typeName = typeName.substring(0, typeName.lastIndexOf(" : "));//$NON-NLS-1$
            }
            for (XSDComplexTypeDefinition td : list) {
                if ((td.getName().equals(typeName))) {
                    alreadyExists = true;
                    complexType = td;
                    break;
                }
            }

        } else {
            XSDComplexTypeDefinition declComplexType = null;
            if (parent != null && decl.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
                declComplexType = (XSDComplexTypeDefinition) decl.getTypeDefinition();
            }
            if (declComplexType != null && declComplexType.getSchema() != null
                    && declComplexType.getName() == null) {
                alreadyExists = true;
            }
            if (decl.getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
                alreadyExists = false;
            }
        }

        if (alreadyExists) {
            XSDParticle partCnt = (XSDParticle) complexType.getContentType();
            partCnt.unsetMaxOccurs();
            partCnt.unsetMinOccurs();
            XSDTypeDefinition superType = null;
            for (XSDTypeDefinition type : types) {
                if (type.getName().equals(superTypeName)) {
                    superType = type;
                    break;
                }
            }

            if (superType != null) {
                XSDModelGroup mdlGrp = (XSDModelGroup) partCnt.getTerm();
                boolean status = updateCompositorType(superType, mdlGrp);
                if (!status) {
                    return Status.CANCEL_STATUS;
                }

                complexType.setDerivationMethod(XSDDerivationMethod.EXTENSION_LITERAL);
                complexType.setBaseTypeDefinition(superType);
            }
            if (isAbstract) {
                complexType.setAbstract(isAbstract);
            } else {
                complexType.unsetAbstract();
            }

            if (parent != null) {
                parent.updateElement();
            }
            if (complexType != null) {
                complexType.updateElement();
            }
        } else {// Create if does not exist

            // add an element declaration
            subElement = factory.createXSDElementDeclaration();
            if (declNew != null) {
                // crate a new entity
                if (declNew.getName() != null) {
                    subElement.setName(declNew.getName() + "Id");//$NON-NLS-1$
                }
            } else {
                // create a complex element
                subElement.setName("subelement");//$NON-NLS-1$
            }
            subElement.setTypeDefinition(
                    schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), "string"));//$NON-NLS-1$

            subParticle = factory.createXSDParticle();
            subParticle.unsetMaxOccurs();
            subParticle.unsetMinOccurs();
            subParticle.setContent(subElement);
            subParticle.updateElement();

            // create group
            XSDModelGroup group = factory.createXSDModelGroup();
            if (isChoice) {
                group.setCompositor(XSDCompositor.CHOICE_LITERAL);
            } else if (isAll) {
                group.setCompositor(XSDCompositor.ALL_LITERAL);
            } else {
                group.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
            }
            group.getContents().add(0, subParticle);
            group.updateElement();

            // create the complex type
            complexType = factory.createXSDComplexTypeDefinition();
            if (!anonymous) {
                XSDTypeDefinition superType = null;
                for (XSDTypeDefinition type : types) {
                    if (type.getName().equals(superTypeName)) {
                        superType = type;
                        break;
                    }
                }
                complexType.setName(typeName);
                if (superType != null) {
                    complexType.setDerivationMethod(XSDDerivationMethod.EXTENSION_LITERAL);
                    complexType.setBaseTypeDefinition(superType);
                    updateCompositorType(superType, group);
                }
                if (isAbstract) {
                    complexType.setAbstract(isAbstract);
                } else {
                    complexType.unsetAbstract();
                }
                schema.getContents().add(complexType);
            }
            complexType.updateElement();

            // add the group
            groupParticle = factory.createXSDParticle();
            groupParticle.unsetMaxOccurs();
            groupParticle.unsetMinOccurs();
            groupParticle.setContent(group);
            groupParticle.updateElement();

            complexType.setContent(groupParticle);
            complexType.updateElement();
        } // end if NOT already exusts

        // set complex type to concept
        if (anonymous) {
            decl.setAnonymousTypeDefinition(complexType);
        } else {
            decl.setTypeDefinition(complexType);
        }

        if (isConcept) {
            buildUniqueKey(factory, decl, complexType, anonymous, alreadyExists);
        } // if isConcept

        decl.updateElement();
        schema.update();
        page.refresh();

        declNew = null;
        page.markDirty();

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

    return Status.OK_STATUS;
}

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

License:Open Source License

private boolean validateType() {
    if (!"".equals(typeName)) {//$NON-NLS-1$
        EList<XSDTypeDefinition> list = schema.getTypeDefinitions();
        for (XSDTypeDefinition td : list) {
            if (td.getName().equals(typeName)) {
                if (td instanceof XSDSimpleTypeDefinition) {
                    MessageDialog.openError(page.getSite().getShell(), Messages._Error,
                            Messages.bind(Messages.XSDChangeToCXX_ErrorMsg2, typeName));
                    return false;
                }/*  w w  w  . java  2  s .c  om*/
            }
        } // for
    }

    return true;
}

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

License:Open Source License

@Override
public IStatus doAction() {
    try {/*from w  ww .  ja  v a2 s . c om*/
        XSDElementDeclaration decl = null;
        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        // fliu
        // add declNew to support convert action invoked from new concept/new element menu, in this case
        // declNew is the new created one not the selected one in tree vew
        if (declNew != null) {
            decl = declNew;
        } else if (selection.getFirstElement() instanceof XSDElementDeclaration) {
            isConcept = true;
            decl = (XSDElementDeclaration) selection.getFirstElement();

        } else {
            isConcept = false;
            if (selection.getFirstElement() != null) {
                decl = (XSDElementDeclaration) ((XSDParticle) selection.getFirstElement()).getTerm();
            }
        }

        // build list of custom types and built in types
        List<String> customTypes = new ArrayList<String>();
        for (XSDTypeDefinition type : schema.getTypeDefinitions()) {
            if (type instanceof XSDSimpleTypeDefinition) {
                if (type.getTargetNamespace() != null
                        && !type.getTargetNamespace().equals(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001)
                        || type.getTargetNamespace() == null) {
                    customTypes.add(type.getName());
                }
            }
        }
        List<String> builtInTypes = XSDUtil.getBuiltInTypes();

        if (showDlg) {
            String name = decl.getTypeDefinition().getName();

            if (decl.getTypeDefinition() instanceof XSDComplexTypeDefinition) {
                name = null;
                boolean confirm = MessageDialog.openConfirm(page.getSite().getShell(), Messages.Warning,
                        Messages.XSDChangeToCXX_ChangeToAnotherTypeWarning);
                if (!confirm) {
                    return Status.CANCEL_STATUS;
                }
            }

            dialog = new SimpleTypeInputDialog(this, page.getSite().getShell(), schema,
                    Messages.XSDChangeToXX_DialogTitle, customTypes, builtInTypes, name);

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

        // if concept
        // remove all unique keys and make new one
        if (isConcept) {
            // remove exisitng unique key(s)
            ArrayList keys = new ArrayList();
            EList list = decl.getIdentityConstraintDefinitions();
            for (Iterator iter = list.iterator(); iter.hasNext();) {
                XSDIdentityConstraintDefinition icd = (XSDIdentityConstraintDefinition) iter.next();
                if (icd.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) {
                    keys.add(icd);
                }
            }
            decl.getIdentityConstraintDefinitions().removeAll(keys);
            // add new unique Key
            XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
            XSDIdentityConstraintDefinition uniqueKey = factory.createXSDIdentityConstraintDefinition();
            uniqueKey.setIdentityConstraintCategory(XSDIdentityConstraintCategory.UNIQUE_LITERAL);
            uniqueKey.setName(decl.getName());
            XSDXPathDefinition selector = factory.createXSDXPathDefinition();
            selector.setVariety(XSDXPathVariety.SELECTOR_LITERAL);
            selector.setValue(".");//$NON-NLS-1$
            uniqueKey.setSelector(selector);
            XSDXPathDefinition field = factory.createXSDXPathDefinition();
            field.setVariety(XSDXPathVariety.FIELD_LITERAL);
            field.setValue(".");//$NON-NLS-1$
            uniqueKey.getFields().add(field);
            decl.getIdentityConstraintDefinitions().add(uniqueKey);
        }

        // Save current type definition
        XSDTypeDefinition current = decl.getTypeDefinition();

        // set new one
        if (builtIn) {
            decl.setTypeDefinition(
                    schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), typeName));
        } else {
            // check if concept already exists
            if (typeName != null && typeName.length() > 0) {
                XSDSimpleTypeDefinition std = null;
                String ns = "";//$NON-NLS-1$
                if (typeName.lastIndexOf(" : ") != -1) {//$NON-NLS-1$
                    ns = typeName.substring(typeName.lastIndexOf(" : ") + 3);//$NON-NLS-1$
                    typeName = typeName.substring(0, typeName.lastIndexOf(" : "));//$NON-NLS-1$
                }
                for (XSDTypeDefinition typeDef : schema.getTypeDefinitions()) {
                    if (typeDef instanceof XSDSimpleTypeDefinition) {
                        if (typeDef.getName().equals(typeName)) {
                            std = (XSDSimpleTypeDefinition) typeDef;
                            break;
                        }
                    }
                }
                if (std == null) {
                    std = schema.resolveSimpleTypeDefinition(typeName);
                    std.setBaseTypeDefinition(
                            schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), "string"));//$NON-NLS-1$

                    if (typeName.equals(EUUIDCustomType.MULTI_LINGUAL.getName())) {
                        XSDPatternFacet f = XSDSchemaBuildingTools.getXSDFactory().createXSDPatternFacet();
                        f.setLexicalValue("(\\[\\w+\\:[^\\[\\]]*\\]){0,}");//$NON-NLS-1$
                        std.getFacetContents().add(f);
                    }

                    schema.getContents().add(std);
                }

                decl.setTypeDefinition(std);
            } else {
                XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
                simpleType = factory.createXSDSimpleTypeDefinition();
                simpleType.setBaseTypeDefinition(
                        schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), "string"));//$NON-NLS-1$
                decl.setAnonymousTypeDefinition(simpleType);
            }
        }
        decl.updateElement();

        // remove current if no more in use
        // if (current != null) {
        // if ( (current.getName()!=null) && //anonymous type
        // (!schema.getSchemaForSchemaNamespace().equals(current.getTargetNamespace()))
        // ){
        // List eut =Util.findElementsUsingType(schema, current.getTargetNamespace(), current.getName());
        // if (eut.size()==0)
        // schema.getContents().remove(current);
        // }
        // }

        declNew = null;
        page.refresh();
        page.markDirty();

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

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

License:Open Source License

private boolean validateType() {
    boolean found = false;
    for (Object element : schema.getSchemaForSchema().getTypeDefinitions()) {
        XSDTypeDefinition type = (XSDTypeDefinition) element;
        if (type instanceof XSDSimpleTypeDefinition) {
            if (type.getName().equals(typeName)) {
                found = true;//from  www .j  a  v  a  2  s  .c  om
                break;
            }
        }
    }
    if (!found) {
        MessageDialog.openError(page.getSite().getShell(), Messages._Error,
                Messages.bind(Messages.XSDChangeToXX_ErrorMsg2, typeName));
        return false;
    }

    return true;
}

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

License:Open Source License

public void run() {
    try {//from ww  w. ja va 2  s  . co m
        WorkbenchClipboard.getWorkbenchClipboard().conceptsReset();
        WorkbenchClipboard.getWorkbenchClipboard().particlesReset();
        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        if (selection.getFirstElement() instanceof XSDElementDeclaration) {
            for (Iterator<XSDElementDeclaration> iter = selection.iterator(); iter.hasNext();) {
                XSDElementDeclaration concept = iter.next();

                if (concept instanceof XSDElementDeclaration)
                    WorkbenchClipboard.getWorkbenchClipboard().add(concept);
            }
        } else if (selection.getFirstElement() instanceof XSDParticle) {
            for (Iterator<XSDParticle> iter = selection.iterator(); iter.hasNext();) {
                XSDParticle particle = iter.next();

                if (particle instanceof XSDParticle)
                    WorkbenchClipboard.getWorkbenchClipboard().add(particle);
            }
        }

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

    }
    // return true;
}

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

License:Open Source License

@Override
protected IStatus doAction() {
    try {/*  w w  w . ja v a  2s .c o m*/
        XSDAttributeUse attriUse = attributeUse;
        XSDAttributeDeclaration attriDec = attributeDeclaration;
        if (attriUse == null || attriDec == null) {
            ISelection selection = page.getTreeViewer().getSelection();
            Object firstElement = ((IStructuredSelection) selection).getFirstElement();
            if (firstElement instanceof XSDAttributeUse) {
                attriUse = (XSDAttributeUse) firstElement;
            } else if (firstElement instanceof XSDAttributeDeclaration) {
                attriDec = (XSDAttributeDeclaration) firstElement;
            }
        }

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

            XSDConcreteComponent container = attriUse.getContainer();
            if (container instanceof XSDComplexTypeDefinition) {
                XSDComplexTypeDefinition cType = (XSDComplexTypeDefinition) container;
                cType.getAttributeUses().remove(attriUse);
                cType.getAttributeContents().remove(attriUse);
                cType.updateElement();
            }
        } else if (attriDec != null) {
            if (attriDec.getContainer() == null) {
                return Status.CANCEL_STATUS;
            }

            XSDConcreteComponent container = attriDec.getContainer();
            if (container instanceof XSDSchema) {
                XSDSchema xsdschema = (XSDSchema) container;
                xsdschema.getContents().remove(attriDec);
            }
        }

        schema.update();

        attributeUse = null;
        attributeDeclaration = 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.XSDDeleteConceptAction.java

License:Open Source License

@Override
public IStatus doAction() {
    try {/*from   ww  w  . j  ava  2 s  .  c  om*/
        // xsdElem is to support the multiple delete action on key press,
        // which each delete action on concept must be explicit passed a xsdElem to
        // delete
        XSDElementDeclaration decl = toDeleteElement;
        if (decl == null) {
            ISelection selection = page.getTreeViewer().getSelection();
            decl = (XSDElementDeclaration) ((IStructuredSelection) selection).getFirstElement();
        }
        deletedEntityName = decl.getName();
        // check if contains fk
        if (checkContainFK(decl.getName())) {
            boolean confirmed = MessageDialog.openConfirm(page.getSite().getShell(),
                    Messages.XSDDeleteConceptAction_ConfirmDel,
                    Messages.bind(Messages.XSDDeleteConceptAction_ConfirmInfo, decl.getName()));
            if (!confirmed) {
                return Status.CANCEL_STATUS;
            }
        }

        // check if refered by
        boolean isReferenced = isCommonReferedBy(decl);
        if (isReferenced) {
            boolean confirmed = MessageDialog.openConfirm(page.getSite().getShell(),
                    Messages.XSDDeleteConceptAction_ConfirmDel,
                    Messages.bind(Messages.XSDDeleteConceptAction_ConfirmReferInfo, decl.getName()));
            if (!confirmed) {
                return Status.CANCEL_STATUS;
            }
        }
        if (schema == null) {
            schema = ((ISchemaContentProvider) page.getTreeViewer().getContentProvider()).getXsdSchema();
        }
        schema.getContents().remove(decl);

        schema.update();
        toDeleteElement = null;
        page.refresh();
        page.markDirtyWithoutCommit();

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