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

License:Open Source License

public IStatus doAction() {
    try {/*from  ww w .j a v  a2s  .  co  m*/
        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        selParticle = (XSDParticle) selection.getFirstElement();

        if (!(selParticle.getContainer() instanceof XSDModelGroup))
            return Status.CANCEL_STATUS;
        ;

        XSDModelGroup group = (XSDModelGroup) selParticle.getContainer();
        // get position of the selected particle in the container
        int index = 0;
        int i = 0;
        for (Iterator<XSDParticle> iter = group.getContents().iterator(); iter.hasNext();) {
            XSDParticle p = (XSDParticle) iter.next();
            if (p.equals(selParticle)) {
                index = i;
                break;
            }
            i++;
        }

        EList<XSDElementDeclaration> eDecls = schema.getElementDeclarations();
        List<String> elementDeclarations = new ArrayList<String>();
        for (Iterator<XSDElementDeclaration> iter = eDecls.iterator(); iter.hasNext();) {
            XSDElementDeclaration d = (XSDElementDeclaration) iter.next();
            if (d.getTargetNamespace() != null && d.getTargetNamespace().equals(IConstants.DEFAULT_NAME_SPACE))
                continue;
            elementDeclarations
                    .add(d.getQName() + (d.getTargetNamespace() != null ? " : " + d.getTargetNamespace() : ""));//$NON-NLS-1$//$NON-NLS-2$
        }
        elementDeclarations.add("");//$NON-NLS-1$

        dialog = new BusinessElementInputDialog(this, page.getSite().getShell(),
                Messages._AddANewBusinessElement, null, null, elementDeclarations, 0, 1, true, false);
        dialog.setBlockOnOpen(true);
        int ret = dialog.open();
        if (ret == Dialog.CANCEL) {
            return Status.CANCEL_STATUS;
        }

        XSDElementDeclaration elem = (XSDElementDeclaration) selParticle.getContent();
        if (Util.changeElementTypeToSequence(elem, maxOccurs) == Status.CANCEL_STATUS) {
            return Status.CANCEL_STATUS;
        }

        XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();

        XSDElementDeclaration decl = factory.createXSDElementDeclaration();
        decl.setName(this.elementName);
        if (!refName.equals("")) {//$NON-NLS-1$
            XSDElementDeclaration ref = Util.findReference(refName, schema);
            if (ref != null) {
                decl.setResolvedElementDeclaration(ref);
            }
        } else {
            decl.setTypeDefinition(
                    schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), simpleTypeName));
        }

        XSDParticle particle = factory.createXSDParticle();
        particle.setContent(decl);
        particle.setMinOccurs(this.minOccurs);
        if (maxOccurs > -1) {
            particle.setMaxOccurs(this.maxOccurs);
        } else {
            particle.setMaxOccurs(this.maxOccurs);
            group.getContents().add(group.getContents().size(), particle);
            group.updateElement();
            if (particle.getElement().getAttributeNode("maxOccurs") != null)//$NON-NLS-1$
                particle.getElement().getAttributeNode("maxOccurs").setNodeValue("unbounded");//$NON-NLS-1$//$NON-NLS-2$
            else {
                particle.getElement().setAttribute("maxOccurs", "unbounded");//$NON-NLS-1$//$NON-NLS-2$
            }
        }
        if (maxOccurs > -1) {
            group.getContents().add(group.getContents().size(), particle);
            group.updateElement();
        }

        // fix 0010248. add annotion from parent

        if (dialog.isInherit()) {
            XSDTerm totm = particle.getTerm();
            XSDElementDeclaration concept = null;
            if (Util.getParent(selParticle) instanceof XSDElementDeclaration)
                concept = (XSDElementDeclaration) Util.getParent(selParticle);
            else if (Util.getParent(selParticle) instanceof XSDComplexTypeDefinition) {
                if (selParticle instanceof XSDParticle)
                    concept = (XSDElementDeclaration) ((XSDParticle) selParticle).getContent();
                else if (selParticle instanceof XSDElementDeclaration)
                    concept = (XSDElementDeclaration) selParticle;
            }
            XSDAnnotation fromannotation = null;
            if (concept != null)
                fromannotation = concept.getAnnotation();
            if (fromannotation != null) {
                XSDAnnotationsStructure struc = new XSDAnnotationsStructure(totm);
                if (((XSDElementDeclaration) totm).getType() != null)
                    addAnnotion(struc, fromannotation);
            }

        }

        page.refresh();
        page.getTreeViewer().setSelection(new StructuredSelection(particle), true);
        page.markDirty();

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

        return Status.CANCEL_STATUS;
    }

    return Status.OK_STATUS;
}

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

License:Open Source License

public Map<String, List<String>> cloneXSDAnnotation(XSDAnnotation oldAnn) {
    Map<String, List<String>> infor = new HashMap<String, List<String>>();
    try {/*from www  .j  a v  a2s  .c om*/
        if (oldAnn != null) {
            for (int i = 0; i < oldAnn.getApplicationInformation().size(); i++) {
                Element oldElem = oldAnn.getApplicationInformation().get(i);
                String type = oldElem.getAttributes().getNamedItem("source").getNodeValue();//$NON-NLS-1$
                // X_Write,X_Hide,X_Workflow
                if (type.equals("X_Write") || type.equals("X_Hide") || type.equals("X_Workflow")) {//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
                    if (!infor.containsKey(type)) {
                        List<String> typeList = new ArrayList<String>();
                        typeList.add(oldElem.getFirstChild().getNodeValue());
                        infor.put(type, typeList);
                    } else {
                        (infor.get(type)).add(oldElem.getFirstChild().getNodeValue());
                    }
                }
            }
        }

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

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

License:Open Source License

public void widgetSelected(SelectionEvent e) {
    if (dialog.getReturnCode() == -1)
        return; // there was a validation error
    elementName = dialog.getElementName();
    refName = dialog.getRefName();// w w w .ja  va  2  s . c  om
    minOccurs = dialog.getMinOccurs();
    maxOccurs = dialog.getMaxOccurs();

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

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

License:Open Source License

@Override
public IStatus doAction() {
    try {//w ww . j a  v a  2 s  .  com
        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        if (selection.getFirstElement() instanceof XSDComplexTypeDefinition) {
            ctd = (XSDComplexTypeDefinition) selection.getFirstElement();
            if (!(ctd.getContent() instanceof XSDParticle)) {
                return Status.CANCEL_STATUS;
            }
            if (!(((XSDParticle) ctd.getContent()).getTerm() instanceof XSDModelGroup)) {
                return Status.CANCEL_STATUS;
            }
            ;
            group = (XSDModelGroup) ((XSDParticle) ctd.getContent()).getTerm();
        } else if (selection.getFirstElement() instanceof XSDParticle) {
            group = (XSDModelGroup) ((XSDParticle) selection.getFirstElement()).getTerm();
        } else if (selection.getFirstElement() instanceof XSDModelGroup) {
            group = (XSDModelGroup) selection.getFirstElement();
        } else {
            log.info(Messages.bind(Messages._UnkownSection, selection.getFirstElement().getClass().getName(),
                    selection.getFirstElement().toString()));
            return Status.CANCEL_STATUS;
        }

        EList<XSDElementDeclaration> eDecls = schema.getElementDeclarations();
        List<String> elementDeclarations = new LinkedList<String>();
        for (XSDElementDeclaration xsdElementDeclaration : eDecls) {
            XSDElementDeclaration d = xsdElementDeclaration;
            if (d.getTargetNamespace() != null
                    && d.getTargetNamespace().equals(IConstants.DEFAULT_NAME_SPACE)) {
                continue;
            }
            elementDeclarations
                    .add(d.getQName() + (d.getTargetNamespace() != null ? " : " + d.getTargetNamespace() : ""));//$NON-NLS-1$//$NON-NLS-2$
        }
        elementDeclarations.add("");//$NON-NLS-1$

        dialog = new BusinessElementInputDialog(this, page.getSite().getShell(),
                Messages._AddANewBusinessElement, "", "", elementDeclarations, 0, 1, true, false);//$NON-NLS-1$//$NON-NLS-2$;
        dialog.setBlockOnOpen(true);
        int ret = dialog.open();
        if (ret == Dialog.CANCEL) {
            return Status.CANCEL_STATUS;
        }

        XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();

        XSDElementDeclaration decl = factory.createXSDElementDeclaration();
        decl.setName(this.elementName);
        // decl.setTypeDefinition(schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(),
        // simpleTypeName));
        if (!refName.equals("")) {//$NON-NLS-1$
            XSDElementDeclaration ref = Util.findReference(refName, schema);
            if (ref != null) {
                decl.setResolvedElementDeclaration(ref);
            }
        } else {
            decl.setTypeDefinition(
                    schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), simpleTypeName));
        }

        XSDParticle particle = factory.createXSDParticle();
        particle.setContent(decl);
        particle.setMinOccurs(this.minOccurs);
        particle.setMaxOccurs(this.maxOccurs);

        group.getContents().add(group.getContents().size(), particle);
        group.updateElement();

        if (Util.changeElementTypeToSequence(decl, maxOccurs) == Status.CANCEL_STATUS) {
            return Status.CANCEL_STATUS;
        }
        // fix 0010248. add annotion from parent

        if (dialog.isInherit()) {
            XSDTerm totm = particle.getTerm();
            XSDElementDeclaration concept = null;
            Object obj = Util.getParent(particle);
            if (obj instanceof XSDElementDeclaration) {
                concept = (XSDElementDeclaration) obj;
            } else {
                concept = (XSDElementDeclaration) particle.getContent();
            }
            XSDAnnotation fromannotation = null;
            if (concept != null) {
                fromannotation = concept.getAnnotation();
            }
            if (fromannotation != null) {
                XSDAnnotationsStructure struc = new XSDAnnotationsStructure(totm);
                if (((XSDElementDeclaration) totm).getType() != null) {
                    addAnnotion(struc, fromannotation);
                }
            }

        }

        page.refresh();
        page.getTreeViewer().setSelection(new StructuredSelection(particle), true);
        page.markDirty();

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

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

License:Open Source License

public void widgetSelected(SelectionEvent e) {
    if (dialog.getReturnCode() == -1) {
        return; // there was a validation error
    }/*from  w w  w. j a  va2 s. c om*/
    elementName = dialog.getElementName();
    refName = dialog.getRefName();
    minOccurs = dialog.getMinOccurs();
    maxOccurs = dialog.getMaxOccurs();

    // check that this element does not already exist
    // get position of the selected particle in the container
    for (XSDParticle xsdParticle : group.getContents()) {
        XSDParticle p = xsdParticle;
        if (p.getTerm() instanceof XSDElementDeclaration) {
            XSDElementDeclaration thisDecl = (XSDElementDeclaration) p.getTerm();
            if (thisDecl.getName().equals(elementName)) {
                MessageDialog.openError(page.getSite().getShell(), Messages._Error,
                        Messages.bind(Messages._TheBusinessElement, elementName));
                return;
            }
        }
    } // for

    dialog.close();
}

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

License:Open Source License

public void widgetSelected(SelectionEvent e) {
    if (dialog.getReturnCode() == -1) {
        return;/*from  ww  w . ja  v  a  2 s.c  om*/
    }
    typeName = dialog.getTypeName();
    if (typeName.trim().length() == 0) {
        return;
    }
    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.XSDNewSimpleTypeDefinition_ErrorMsg, typeName));
            return;
        }
    }
    dialog.close();
}

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

License:Open Source License

private boolean validateType() {
    if (!"".equals(typeName)) { //$NON-NLS-1$
        EList list = schema.getTypeDefinitions();
        for (Iterator iter = list.iterator(); iter.hasNext();) {
            XSDTypeDefinition td = (XSDTypeDefinition) iter.next();
            if (td.getName().equals(typeName)) {
                if (td instanceof XSDSimpleTypeDefinition) {
                    MessageDialog.openError(page.getSite().getShell(), Messages._Error,
                            Messages.bind(Messages.XSDNewSimpleTypeDefinition_ErrorMsg1, typeName));
                    return false;
                }//from  w w  w .  j  av a  2  s .  c  o  m
            }
        } // for
    } else {
        MessageDialog.openError(page.getSite().getShell(), Messages._Error,
                Messages.XSDNewSimpleTypeDefinition_ErrorMsg2);
        return false;
    }

    return true;
}

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

License:Open Source License

@Override
public IStatus doAction() {
    try {//from  w  ww .j  a va2 s. c o m
        int index = 0;
        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        if (selection.getFirstElement() instanceof XSDIdentityConstraintDefinition) {
            icd = (XSDIdentityConstraintDefinition) selection.getFirstElement();
        } else if (selection.getFirstElement() instanceof XSDXPathDefinition) {
            XSDXPathDefinition xpath = (XSDXPathDefinition) selection.getFirstElement();
            icd = (XSDIdentityConstraintDefinition) xpath.getContainer();
            if (xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL))
                index = icd.getFields().indexOf(xpath) + 1;
            else
                index = 0;
        } else {
            MessageDialog.openError(this.page.getSite().getShell(), Messages._Error,
                    Messages.XSDNewXPathAction_Huhhh + selection.getFirstElement().getClass().getName());
            return Status.CANCEL_STATUS;
        }

        // InputDialog id = new InputDialog(
        // page.getSite().getShell(),
        // "New XPath",
        // "Enter a new XPath to the field",
        // null,
        // new IInputValidator() {
        // public String isValid(String newText) {
        // if ((newText==null) || "".equals(newText)) return "The XPath cannot be empty";
        // return null;
        // };
        // }
        // );

        List<String> childNames = Util.getChildElementNames("", (XSDElementDeclaration) icd.getContainer()); //$NON-NLS-1$
        // filter the non top level fields
        List<String> topChilds = new ArrayList<String>();
        for (String child : childNames) {
            if (child.indexOf('/') == -1) {
                topChilds.add(child);
            }
        }
        // forbid to add already exists field
        EList<XSDXPathDefinition> fields = icd.getFields();
        for (XSDXPathDefinition fd : fields) {
            if (topChilds.contains(fd.getValue()))
                topChilds.remove(fd.getValue());
        }

        SelectFieldDialog id = new SelectFieldDialog(page.getSite().getShell(),
                Messages.XSDNewXPathAction_SelectOnField, topChilds, null);
        id.create();
        id.setBlockOnOpen(true);
        int ret = id.open();
        if (ret == Dialog.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        String field = id.getField();
        if (field.length() == 0)
            return Status.CANCEL_STATUS;

        XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();

        XSDXPathDefinition xpath = factory.createXSDXPathDefinition();
        xpath.setValue(field);
        xpath.setVariety(XSDXPathVariety.FIELD_LITERAL);

        icd.getFields().add(index, xpath);
        icd.updateElement();

        updateElementForAddedfield(icd, field);

        page.refresh();
        page.getTreeViewer().setSelection(new StructuredSelection(xpath), true);
        page.markDirty();

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

    return Status.OK_STATUS;
}

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

License:Open Source License

@Override
public IStatus doAction() {

    try {//from   w w w .j av a  2  s .  c o m

        conceptList = WorkbenchClipboard.getWorkbenchClipboard().getConcepts();

        XSDFactory factory = XSDFactory.eINSTANCE;
        if (!conceptList.isEmpty()) {
            // List<String> concepts = new ArrayList<String>();
            int index = 0;
            for (Iterator<XSDElementDeclaration> it = conceptList.iterator(); it.hasNext();) {

                if (conceptList.get(index).getSchema() != null) {
                    // concepts = Util.getConcepts(conceptList.get(index).getSchema());
                    typeList = Util.getTypeDefinition(conceptList.get(index).getSchema());
                }
                index++;
                Object concept = it.next();

                if (concept instanceof XSDElementDeclaration) {
                    // edit by ymli,fix the bug:0011523. let the element(simple or complex) can be pasted
                    // if (concepts.contains(((XSDElementDeclaration) concept).getName())) {
                    XSDElementDeclaration copy_concept = (XSDElementDeclaration) concept;

                    XSDElementDeclaration new_copy_concept = factory.createXSDElementDeclaration();

                    new_copy_concept = (XSDElementDeclaration) copy_concept.cloneConcreteComponent(true, false);
                    InputDialog id = new InputDialog(page.getSite().getShell(),
                            Messages.XSDPasteConceptAction_CopyElement,
                            Messages.XSDPasteConceptAction_DialogTip,
                            Messages.bind(Messages.XSDPasteConceptAction_CopyOf, copy_concept.getName()),
                            new IInputValidator() {

                                public String isValid(String newText) {
                                    if ((newText == null) || "".equals(newText)) {
                                        return Messages.XSDPasteConceptAction_NameCannNotbeEmpty;
                                    }
                                    EList<XSDElementDeclaration> list = schema.getElementDeclarations();
                                    for (XSDElementDeclaration d : list) {
                                        if (d.getName().equalsIgnoreCase(newText)) {
                                            return Messages.XSDPasteConceptAction_EntityAlreadyExists;
                                        }
                                    }
                                    return null;
                                };
                            });

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

                    new_copy_concept.setName(id.getValue());
                    for (int i = 0; i < new_copy_concept.getIdentityConstraintDefinitions().size(); i++) {
                        String name = new_copy_concept.getIdentityConstraintDefinitions().get(i).getName()
                                .replaceAll(copy_concept.getName(), new_copy_concept.getName());
                        new_copy_concept.getIdentityConstraintDefinitions().get(i).setName(name);
                    }

                    ///modified by xie to fix the bug 22077

                    if (new_copy_concept.getAnonymousTypeDefinition() == null) {

                        XSDComplexTypeDefinition copyType = (XSDComplexTypeDefinition) copy_concept
                                .getTypeDefinition().cloneConcreteComponent(true, false);
                        String originalName = copyType.getName();
                        String typeName = "Copy_of_" + originalName; //$NON-NLS-1$
                        copyType.setName(typeName);
                        schema.getContents().add(copyType);
                        new_copy_concept.setTypeDefinition(copyType);

                    }

                    new_copy_concept.updateElement();
                    schema.getContents().add(new_copy_concept);
                    addAnnotationForXSDElementDeclaration(copy_concept, new_copy_concept);

                }
            }
            Map<String, XSDTypeDefinition> typeDef = Util.getTypeDefinition(schema);
            for (XSDTypeDefinition type : copyTypeSet) {
                if (typeDef.containsKey(type.getName())) {
                    continue;
                }
                XSDTypeDefinition typedefinitionClone = null;
                if (type instanceof XSDComplexTypeDefinition) {
                    typedefinitionClone = factory.createXSDComplexTypeDefinition();
                    typedefinitionClone = (XSDComplexTypeDefinition) type.cloneConcreteComponent(true, false);
                    schema.getContents().add(typedefinitionClone);
                    addAnnotationForComplexType((XSDComplexTypeDefinition) type,
                            (XSDComplexTypeDefinition) typedefinitionClone);
                } else if (type instanceof XSDSimpleTypeDefinition) {
                    schema.getContents()
                            .add((XSDSimpleTypeDefinition) type.cloneConcreteComponent(true, false));
                }
            }
            schema.getElement();
            // WSDataModel wsObject = (WSDataModel)
            // (page.getXObject().getWsObject());
            // wsObject.getXsdSchema();//.setXsdSchema(Util.nodeToString(
            // schema.getDocument()));

            /*
             * String schema1 = ((XSDTreeContentProvider) page.getViewer()
             * .getContentProvider()).getXSDSchemaAsString(); wsObject.setXsdSchema(schema1); XMLEditor
             * xmleditor=((XObjectEditor)page.getEditor()).getXmlEditor(); xmleditor.refresh(page.getXObject());
             */

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

            getOperationHistory();
            WorkbenchClipboard.getWorkbenchClipboard().conceptsReset();
            typeList.clear();

            return Status.OK_STATUS;
        } else if (WorkbenchClipboard.getWorkbenchClipboard().getParticles().size() > 0) {
            copyElements();
            WorkbenchClipboard.getWorkbenchClipboard().particlesReset();
            page.markDirty();
            page.refresh();
            // page.refreshData();

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

    }
    return Status.OK_STATUS;
}

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

License:Open Source License

public Map<String, List<String>> cloneXSDAnnotation(XSDAnnotation oldAnn) {
    XSDAnnotation xsdannotation = XSDFactory.eINSTANCE.createXSDAnnotation();
    Map<String, List<String>> infor = new HashMap<String, List<String>>();
    try {//from   ww w  .  ja  v a2s  . c  om
        /*
         * Element oldAnnElem =oldAnn.getElement(); Element newAnnElem = (Element)oldAnnElem.cloneNode(true);
         * xsdannotation.setElement(newAnnElem);
         */

        /*
         * List<Element> listAppInfo = new ArrayList<Element>(); List<Element> listUserInfo = new
         * ArrayList<Element>(); List<Attr> listAttri = new ArrayList<Attr>();
         */
        if (oldAnn != null) {
            for (int i = 0; i < oldAnn.getApplicationInformation().size(); i++) {
                Element oldElem = oldAnn.getApplicationInformation().get(i);
                // System.out.println(oldElem.getAttributes().getNamedItem(
                // "source").getNodeValue());
                String type = oldElem.getAttributes().getNamedItem(Messages.XSDPasteConceptAction_Source)
                        .getNodeValue();
                /*
                 * Element newElem = (Element) oldElem.cloneNode(true);
                 * listAppInfo.add(oldAnn.getApplicationInformation().get(i));
                 */
                if (!infor.containsKey(type)) {
                    List<String> typeList = new ArrayList<String>();
                    typeList.add(oldElem.getFirstChild().getNodeValue());
                    infor.put(type, typeList);
                } else {
                    infor.get(type).add(oldElem.getFirstChild().getNodeValue());
                }
            }
            /*
             * xsdannotation.getApplicationInformation().addAll(listAppInfo);
             *
             * for (int i = 0; i < oldAnn.getUserInformation().size(); i++) { Element oldElemUserInfo =
             * oldAnn.getUserInformation() .get(i); Element newElemUserInfo = (Element) oldElemUserInfo
             * .cloneNode(true); listUserInfo.add(newElemUserInfo);
             *
             * } xsdannotation.getUserInformation().addAll(listUserInfo);
             *
             * for (int i = 0; i < oldAnn.getAttributes().size(); i++) { Attr oldAttri =
             * oldAnn.getAttributes().get(i); Attr newAtri = (Attr) oldAttri.cloneNode(true);
             * listAttri.add(newAtri); } xsdannotation.getAttributes().addAll(listAttri);
             */
        }

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