Search in sources :

Example 86 with XSDConcreteComponent

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

the class RenameEnablementTester method canEnable.

protected boolean canEnable(XSDConcreteComponent selectedObject, XSDSchema schema) {
    if (selectedObject == null) {
        return false;
    }
    XSDNamedComponent selectedComponent = null;
    boolean enable = false;
    XSDSchema selectedComponentSchema = null;
    selectedComponentSchema = selectedObject.getSchema();
    if (selectedComponentSchema != null && selectedComponentSchema == schema) {
        enable = true;
    }
    if (enable && selectedObject instanceof XSDNamedComponent) {
        selectedComponent = (XSDNamedComponent) selectedObject;
        if (selectedComponent instanceof XSDElementDeclaration) {
            XSDElementDeclaration element = (XSDElementDeclaration) selectedComponent;
            if (element.isElementDeclarationReference()) {
                return false;
            }
            if (!element.isGlobal()) {
                return false;
            }
        }
        if (selectedComponent instanceof XSDTypeDefinition) {
            XSDTypeDefinition type = (XSDTypeDefinition) selectedComponent;
            XSDConcreteComponent parent = type.getContainer();
            if (parent instanceof XSDElementDeclaration) {
                XSDElementDeclaration element = (XSDElementDeclaration) parent;
                if (element.getAnonymousTypeDefinition().equals(type)) {
                    return false;
                }
            } else if (parent instanceof XSDAttributeDeclaration) {
                XSDAttributeDeclaration element = (XSDAttributeDeclaration) parent;
                if (element.getAnonymousTypeDefinition().equals(type)) {
                    return false;
                }
            }
        }
        return true;
    }
    return false;
}
Also used : XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDSchema(org.eclipse.xsd.XSDSchema) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 87 with XSDConcreteComponent

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

the class XSDGetXPathAction method doAction.

@Override
public IStatus doAction() {
    try {
        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        XSDParticle particle = (XSDParticle) selection.getFirstElement();
        XSDTerm term = particle.getTerm();
        if (!(term instanceof XSDElementDeclaration))
            return Status.CANCEL_STATUS;
        Clipboard clipboard = Util.getClipboard();
        // $NON-NLS-1$
        String path = "";
        TreeItem item = page.getTreeViewer().getTree().getSelection()[0];
        do {
            XSDConcreteComponent component = (XSDConcreteComponent) item.getData();
            if (component instanceof XSDParticle) {
                if (((XSDParticle) component).getTerm() instanceof XSDElementDeclaration)
                    // $NON-NLS-1$
                    path = "/" + ((XSDElementDeclaration) ((XSDParticle) component).getTerm()).getName() + path;
            } else if (component instanceof XSDElementDeclaration) {
                path = ((XSDElementDeclaration) component).getName() + path;
            }
            // System.out.println("          "+path+ "             $$"+component.toString()+"$$");
            item = item.getParentItem();
        } while (item != null);
        xpath = path;
        clipboard.setContents(new Object[] { path }, new Transfer[] { TextTransfer.getInstance() });
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDGetXPathAction_ErrorMsg, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) TreeItem(org.eclipse.swt.widgets.TreeItem) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDTerm(org.eclipse.xsd.XSDTerm) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Clipboard(org.eclipse.swt.dnd.Clipboard) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 88 with XSDConcreteComponent

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

the class XSDDeleteAttributeAction method doAction.

@Override
protected IStatus doAction() {
    try {
        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;
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDSchema(org.eclipse.xsd.XSDSchema)

Aggregations

XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)88 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)30 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)25 XSDSchema (org.eclipse.xsd.XSDSchema)23 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)18 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)18 XSDBaseAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter)17 Adapter (org.eclipse.emf.common.notify.Adapter)15 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)15 XSDParticle (org.eclipse.xsd.XSDParticle)13 Iterator (java.util.Iterator)12 ArrayList (java.util.ArrayList)11 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)11 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)11 XSDModelGroupDefinition (org.eclipse.xsd.XSDModelGroupDefinition)11 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)11 List (java.util.List)10 Element (org.w3c.dom.Element)10 IADTObject (org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject)9 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)9