Search in sources :

Example 11 with XSDComponent

use of org.eclipse.xsd.XSDComponent in project tmdm-studio-se by Talend.

the class XSDSetFacetMessageAction method doAction.

public IStatus doAction() {
    try {
        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);
        // XSDAnnotationsStructure struc = new XSDAnnotationsStructure((XSDComponent)selection.getFirstElement());
        if (struc.getAnnotation() == null) {
            throw new RuntimeException(Messages.bind(Messages.XSDSetFacetMessageAction_ExceptionInfo, selection.getFirstElement().getClass().getName()));
        }
        dlg = new AnnotationLanguageLabelsDialog(struc.getFactMessage(), new SelectionListener() {

            public void widgetDefaultSelected(SelectionEvent e) {
            }

            public void widgetSelected(SelectionEvent e) {
                dlg.close();
            }
        }, page.getSite().getShell(), Messages.XSDSetFacetMessageAction_DialogTip);
        dlg.setBlockOnOpen(true);
        int ret = dlg.open();
        if (ret == Window.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        LinkedHashMap<String, String> facets = dlg.getDescriptionsMap();
        struc.setFactMessage(facets);
        if (struc.hasChanged()) {
            page.refresh();
            page.getTreeViewer().expandToLevel(selection.getFirstElement(), 2);
            page.markDirty();
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDSetFacetMessageAction_ErrorMsg + e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) Element(org.w3c.dom.Element) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComponent(org.eclipse.xsd.XSDComponent) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) AnnotationLanguageLabelsDialog(com.amalto.workbench.dialogs.AnnotationLanguageLabelsDialog) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 12 with XSDComponent

use of org.eclipse.xsd.XSDComponent in project tmdm-studio-se by Talend.

the class DataModelMainPage method getStructureByActiveItem.

public XSDAnnotationsStructure getStructureByActiveItem() {
    XSDComponent xSDCom = null;
    XSDAnnotationsStructure struc = null;
    IStructuredSelection selection = (TreeSelection) getTreeViewer().getSelection();
    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();
    }
    if (xSDCom != null) {
        struc = new XSDAnnotationsStructure(xSDCom);
    }
    return struc;
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) TreeSelection(org.eclipse.jface.viewers.TreeSelection) Element(org.w3c.dom.Element) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDComponent(org.eclipse.xsd.XSDComponent)

Example 13 with XSDComponent

use of org.eclipse.xsd.XSDComponent in project tmdm-studio-se by Talend.

the class DataModelMainPage method addLabelForTheItem.

private void addLabelForTheItem(TreeItem[] items, boolean isAdd) {
    XSDComponent xSDCom = null;
    for (TreeItem item : items) {
        XSDAnnotationsStructure struc = null;
        String labelValue = null;
        if (item.getData() instanceof XSDElementDeclaration) {
            xSDCom = (XSDElementDeclaration) item.getData();
            struc = new XSDAnnotationsStructure(xSDCom);
            labelValue = ((XSDElementDeclaration) xSDCom).getName();
            setLabel(struc, labelValue, isAdd);
            setLabelForElement((XSDElementDeclaration) xSDCom, isAdd);
        }
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDComponent(org.eclipse.xsd.XSDComponent)

Example 14 with XSDComponent

use of org.eclipse.xsd.XSDComponent in project tmdm-studio-se by Talend.

the class XSDAnnotationsStructure method setAccessRole.

/**
 **************************************************************************
 * WRITE ACCESS
 *
 * @throws XtentisException
 ***************************************************************************
 */
public boolean setAccessRole(Collection<String> roles, boolean recursive, IStructuredContentProvider provider, String access) throws Exception {
    XSDSchema xsd = schema != null ? schema : declaration.getSchema();
    String xsdString = Util.nodeToString(xsd.getDocument().getDocumentElement());
    if (recursive) {
        ArrayList<Object> objList = new ArrayList<Object>();
        XSDComponent component = declaration;
        if (declaration == null) {
            component = this.componet;
        }
        Object[] objs = Util.getAllObject(component, objList, provider);
        while (objs.length > 0) {
            Object[] objCpys = objs;
            for (Object obj : objCpys) {
                if (obj instanceof XSDElementDeclaration || obj instanceof XSDParticle) {
                    boolean isImported = false;
                    if (obj instanceof XSDParticle) {
                        XSDParticle particle = (XSDParticle) obj;
                        if (particle.getTerm() instanceof XSDElementDeclaration) {
                            XSDElementDeclaration decl = (XSDElementDeclaration) particle.getTerm();
                            if (Util.IsAImporedElement(decl, xsdString)) {
                                XSDTypeDefinition typeDef = decl.getTypeDefinition();
                                if (Util.IsAImporedElement(typeDef, xsdString)) {
                                    isImported = true;
                                }
                            }
                        }
                    } else if (obj instanceof XSDElementDeclaration) {
                        XSDElementDeclaration decl = (XSDElementDeclaration) obj;
                        if (Util.IsAImporedElement(decl, xsdString)) {
                            isImported = true;
                        }
                    }
                    if (!isImported) {
                        XSDAnnotationsStructure annotion = new XSDAnnotationsStructure((XSDComponent) obj);
                        // see 7993, if UUID/AUTO_INCREMENT ,should not add write access
                        if (obj instanceof XSDParticle) {
                            XSDParticle o = (XSDParticle) obj;
                            // String name=Util.getFirstTextNode(o.getElement(), "@name");
                            // $NON-NLS-1$
                            String type = Util.getFirstTextNode(o.getElement(), "@type");
                            if (EUUIDCustomType.AUTO_INCREMENT.equals(type) || EUUIDCustomType.UUID.equals(type)) {
                                objList.remove(obj);
                                objs = objList.toArray();
                                continue;
                            }
                        }
                        // X_Write
                        annotion.removeAppInfos(access);
                        for (Iterator<String> iter = roles.iterator(); iter.hasNext(); ) {
                            String role = iter.next();
                            annotion.addAppInfo(access, role);
                        }
                    }
                }
                objList.remove(obj);
                objs = objList.toArray();
            }
        }
        return setAccessRole(roles, access);
    } else {
        if (Util.IsAImporedElement(declaration, xsdString)) {
            return false;
        }
        return setAccessRole(roles, access);
    }
}
Also used : ArrayList(java.util.ArrayList) XSDComponent(org.eclipse.xsd.XSDComponent) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 15 with XSDComponent

use of org.eclipse.xsd.XSDComponent in project webtools.sourceediting by eclipse.

the class UpdateAttributeReferenceAndManagerDirectivesCommand method execute.

public void execute() {
    try {
        beginRecording(concreteComponent.getElement());
        XSDComponent componentDef = computeComponent();
        if (componentDef != null) {
            UpdateAttributeReferenceCommand command = new UpdateAttributeReferenceCommand(org.eclipse.wst.xsd.ui.internal.editor.Messages._UI_ACTION_UPDATE_ATTRIBUTE_REFERENCE, (XSDAttributeDeclaration) concreteComponent, (XSDAttributeDeclaration) componentDef);
            command.execute();
            XSDDirectivesManager.removeUnusedXSDImports(concreteComponent.getSchema());
        }
    } catch (Exception e) {
    } finally {
        endRecording();
    }
}
Also used : XSDComponent(org.eclipse.xsd.XSDComponent)

Aggregations

XSDComponent (org.eclipse.xsd.XSDComponent)21 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)14 TreePath (org.eclipse.jface.viewers.TreePath)14 XSDAnnotationsStructure (com.amalto.workbench.utils.XSDAnnotationsStructure)13 TreeSelection (org.eclipse.jface.viewers.TreeSelection)13 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)13 Element (org.w3c.dom.Element)13 ArrayList (java.util.ArrayList)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 SelectionListener (org.eclipse.swt.events.SelectionListener)5 AnnotationLanguageLabelsDialog (com.amalto.workbench.dialogs.AnnotationLanguageLabelsDialog)4 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)4 AnnotationOrderedListsDialog (com.amalto.workbench.dialogs.AnnotationOrderedListsDialog)3 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)3 Iterator (java.util.Iterator)2 XSDParticle (org.eclipse.xsd.XSDParticle)2 XSDSchema (org.eclipse.xsd.XSDSchema)2 DataModelMainPage (com.amalto.workbench.editors.DataModelMainPage)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 IInputValidator (org.eclipse.jface.dialogs.IInputValidator)1