Search in sources :

Example 1 with XSDSimpleTypeDefinitionAdapter

use of org.eclipse.wst.xsd.ui.internal.adapters.XSDSimpleTypeDefinitionAdapter in project webtools.sourceediting by eclipse.

the class XSDSimpleTypeEditPart method performRequest.

public void performRequest(Request request) {
    if (request.getType() == RequestConstants.REQ_OPEN) {
        Object model = getModel();
        if (request instanceof LocationRequest) {
            LocationRequest locationRequest = (LocationRequest) request;
            Point p = locationRequest.getLocation();
            if (getStructureFigure().hitTestHeader(p)) {
                // 
                if (model instanceof XSDSimpleTypeDefinitionAdapter) {
                    XSDSimpleTypeDefinitionAdapter adapter = (XSDSimpleTypeDefinitionAdapter) model;
                    XSDSimpleTypeDefinition st = (XSDSimpleTypeDefinition) adapter.getTarget();
                    IWorkbench workbench = PlatformUI.getWorkbench();
                    IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
                    IEditorPart editorPart = workbenchWindow.getActivePage().getActiveEditor();
                    Object schema = editorPart.getAdapter(XSDSchema.class);
                    ActionRegistry registry = getEditorActionRegistry(editorPart);
                    if (registry != null) {
                        if (schema == st.getSchema()) {
                            IAction action = registry.getAction(SetInputToGraphView.ID);
                            action.run();
                        } else {
                            IAction action = registry.getAction(OpenInNewEditor.ID);
                            action.run();
                        }
                    }
                }
            }
        }
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) XSDSimpleTypeDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDSimpleTypeDefinitionAdapter) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) LocationRequest(org.eclipse.gef.requests.LocationRequest) IAction(org.eclipse.jface.action.IAction) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) Point(org.eclipse.draw2d.geometry.Point) IEditorPart(org.eclipse.ui.IEditorPart) ActionRegistry(org.eclipse.gef.ui.actions.ActionRegistry)

Example 2 with XSDSimpleTypeDefinitionAdapter

use of org.eclipse.wst.xsd.ui.internal.adapters.XSDSimpleTypeDefinitionAdapter in project webtools.sourceediting by eclipse.

the class XSDSimpleTypeEditPart method createConnectionFigure.

public TypeReferenceConnection createConnectionFigure() {
    TypeReferenceConnection connectionFigure = null;
    XSDSimpleTypeDefinitionAdapter adapter = (XSDSimpleTypeDefinitionAdapter) getModel();
    IType superType = adapter.getSuperType();
    if (superType != null) {
        AbstractGraphicalEditPart referenceTypePart = (AbstractGraphicalEditPart) getTargetEditPart(superType);
        if (referenceTypePart != null) {
            connectionFigure = new TypeReferenceConnection(true);
            // draw a line out from the top
            connectionFigure.setSourceAnchor(new CenteredConnectionAnchor(getFigure(), CenteredConnectionAnchor.TOP, 1));
            // TODO (cs) need to draw the target anchor to look like a UML inheritance relationship
            // adding a label to the connection would help to
            connectionFigure.setTargetAnchor(new CenteredConnectionAnchor(referenceTypePart.getFigure(), CenteredConnectionAnchor.BOTTOM, 0, 0));
            connectionFigure.setConnectionRouter(new ManhattanConnectionRouter());
            ((CenteredConnectionAnchor) connectionFigure.getSourceAnchor()).setOther((CenteredConnectionAnchor) connectionFigure.getTargetAnchor());
            connectionFigure.setHighlight(false);
        }
    }
    return connectionFigure;
}
Also used : XSDSimpleTypeDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDSimpleTypeDefinitionAdapter) CenteredConnectionAnchor(org.eclipse.wst.xsd.ui.internal.adt.design.editparts.CenteredConnectionAnchor) AbstractGraphicalEditPart(org.eclipse.gef.editparts.AbstractGraphicalEditPart) ManhattanConnectionRouter(org.eclipse.draw2d.ManhattanConnectionRouter) TypeReferenceConnection(org.eclipse.wst.xsd.ui.internal.adt.design.editparts.TypeReferenceConnection) IType(org.eclipse.wst.xsd.ui.internal.adt.facade.IType)

Example 3 with XSDSimpleTypeDefinitionAdapter

use of org.eclipse.wst.xsd.ui.internal.adapters.XSDSimpleTypeDefinitionAdapter in project webtools.sourceediting by eclipse.

the class AddRedefinedComponentCommand method execute.

public void execute() {
    Element element = redefine.getElement();
    try {
        beginRecording(element);
        doExecute();
        Object adapter = redefinableComponent.eAdapters().get(0);
        if (adapter instanceof XSDComplexTypeDefinitionAdapter) {
            ((XSDComplexTypeDefinitionAdapter) adapter).updateDeletedMap(redefinableComponent.getName());
        } else if (adapter instanceof XSDSimpleTypeDefinitionAdapter) {
            ((XSDSimpleTypeDefinitionAdapter) adapter).updateDeletedMap(redefinableComponent.getName());
        } else if (adapter instanceof XSDAttributeGroupDefinitionAdapter) {
            ((XSDAttributeGroupDefinitionAdapter) adapter).updateDeletedMap(redefinableComponent.getName());
        } else if (adapter instanceof XSDModelGroupDefinitionAdapter) {
            ((XSDModelGroupDefinitionAdapter) adapter).updateDeletedMap(redefinableComponent.getName());
        }
        redefine.getContents().add(addedXSDConcreteComponent);
        formatChild(addedXSDConcreteComponent.getElement());
    } finally {
        endRecording();
    }
}
Also used : XSDComplexTypeDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDComplexTypeDefinitionAdapter) XSDSimpleTypeDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDSimpleTypeDefinitionAdapter) XSDModelGroupDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDModelGroupDefinitionAdapter) Element(org.w3c.dom.Element) XSDAttributeGroupDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeGroupDefinitionAdapter)

Example 4 with XSDSimpleTypeDefinitionAdapter

use of org.eclipse.wst.xsd.ui.internal.adapters.XSDSimpleTypeDefinitionAdapter in project webtools.sourceediting by eclipse.

the class XSDSimpleTypeEditPart method refreshVisuals.

protected void refreshVisuals() {
    XSDSimpleTypeDefinitionAdapter adapter = (XSDSimpleTypeDefinitionAdapter) getModel();
    String name = adapter.getDisplayName();
    HeadingFigure headingFigure = figure.getHeadingFigure();
    headingFigure.setIsReadOnly(adapter.isReadOnly());
    Label label = headingFigure.getLabel();
    label.setText(name);
    label.setIcon(XSDCommonUIUtils.getUpdatedImage(adapter.getXSDTypeDefinition(), adapter.getImage(), adapter.isReadOnly()));
}
Also used : XSDSimpleTypeDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDSimpleTypeDefinitionAdapter) Label(org.eclipse.draw2d.Label) HeadingFigure(org.eclipse.wst.xsd.ui.internal.adt.typeviz.design.figures.HeadingFigure)

Example 5 with XSDSimpleTypeDefinitionAdapter

use of org.eclipse.wst.xsd.ui.internal.adapters.XSDSimpleTypeDefinitionAdapter in project webtools.sourceediting by eclipse.

the class DeleteCommand method execute.

public void execute() {
    XSDVisitor visitor = new XSDVisitor() {

        public void visitElementDeclaration(org.eclipse.xsd.XSDElementDeclaration element) {
            if (element.getTypeDefinition() == target) {
                // $NON-NLS-1$
                XSDSimpleTypeDefinition type = target.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition("string");
                element.setTypeDefinition(type);
            }
            super.visitElementDeclaration(element);
        }
    };
    XSDConcreteComponent parent = target.getContainer();
    XSDSchema schema = target.getSchema();
    try {
        beginRecording(parent.getElement());
        boolean doCleanup = false;
        if (target instanceof XSDModelGroup || target instanceof XSDElementDeclaration || target instanceof XSDModelGroupDefinition) {
            doCleanup = true;
            if (parent instanceof XSDParticle) {
                if (parent.getContainer() instanceof XSDModelGroup) {
                    XSDModelGroup modelGroup = (XSDModelGroup) ((XSDParticle) parent).getContainer();
                    modelGroup.getContents().remove(parent);
                } else if (parent.getContainer() instanceof XSDComplexTypeDefinition) {
                    XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) parent.getContainer();
                    complexType.setContent(null);
                }
            } else if (parent instanceof XSDSchema) {
                visitor.visitSchema(target.getSchema());
                ((XSDSchema) parent).getContents().remove(target);
            } else if (parent instanceof XSDRedefine) {
                Object adapter = target.eAdapters().get(0);
                if (adapter instanceof XSDModelGroupDefinitionAdapter) {
                    ((XSDModelGroupDefinitionAdapter) adapter).setReadOnly(true);
                    ((XSDModelGroupDefinitionAdapter) adapter).setChangeReadOnlyField(true);
                }
                ((XSDRedefine) parent).getContents().remove(target);
            }
        } else if (target instanceof XSDAttributeDeclaration) {
            doCleanup = true;
            if (parent instanceof XSDAttributeUse) {
                EObject obj = parent.eContainer();
                XSDComplexTypeDefinition complexType = null;
                while (obj != null) {
                    if (obj instanceof XSDComplexTypeDefinition) {
                        complexType = (XSDComplexTypeDefinition) obj;
                        break;
                    }
                    obj = obj.eContainer();
                }
                if (complexType != null) {
                    complexType.getAttributeContents().remove(parent);
                }
                if (parent.getContainer() instanceof XSDAttributeGroupDefinition) {
                    XSDAttributeGroupDefinition attrGroup = (XSDAttributeGroupDefinition) parent.getContainer();
                    attrGroup.getContents().remove(parent);
                }
            } else if (parent instanceof XSDSchema) {
                visitor.visitSchema(target.getSchema());
                ((XSDSchema) parent).getContents().remove(target);
            }
        } else if (target instanceof XSDAttributeGroupDefinition && parent instanceof XSDComplexTypeDefinition) {
            doCleanup = true;
            ((XSDComplexTypeDefinition) parent).getAttributeContents().remove(target);
        } else if (target instanceof XSDEnumerationFacet) {
            XSDEnumerationFacet enumerationFacet = (XSDEnumerationFacet) target;
            enumerationFacet.getSimpleTypeDefinition().getFacetContents().remove(enumerationFacet);
        } else if (target instanceof XSDWildcard) {
            if (parent instanceof XSDParticle) {
                if (parent.getContainer() instanceof XSDModelGroup) {
                    XSDModelGroup modelGroup = (XSDModelGroup) ((XSDParticle) parent).getContainer();
                    modelGroup.getContents().remove(parent);
                }
            } else if (parent instanceof XSDComplexTypeDefinition) {
                ((XSDComplexTypeDefinition) parent).setAttributeWildcardContent(null);
            } else if (parent instanceof XSDAttributeGroupDefinition) {
                ((XSDAttributeGroupDefinition) parent).setAttributeWildcardContent(null);
            }
        } else if (target instanceof XSDTypeDefinition && parent instanceof XSDElementDeclaration) {
            doCleanup = true;
            ((XSDElementDeclaration) parent).setTypeDefinition(target.resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "string"));
        } else {
            if (parent instanceof XSDSchema) {
                doCleanup = true;
                visitor.visitSchema(target.getSchema());
                ((XSDSchema) parent).getContents().remove(target);
            } else if (parent instanceof XSDRedefine) {
                doCleanup = false;
                EList contents = ((XSDRedefine) parent).getContents();
                Object adapter = target.eAdapters().get(0);
                if (adapter instanceof XSDComplexTypeDefinitionAdapter) {
                    ((XSDComplexTypeDefinitionAdapter) adapter).setReadOnly(true);
                    ((XSDComplexTypeDefinitionAdapter) adapter).setChangeReadOnlyField(true);
                } else if (adapter instanceof XSDSimpleTypeDefinitionAdapter) {
                    ((XSDSimpleTypeDefinitionAdapter) adapter).setReadOnly(true);
                    ((XSDSimpleTypeDefinitionAdapter) adapter).setChangeReadOnlyField(true);
                } else if (adapter instanceof XSDAttributeGroupDefinitionAdapter) {
                    ((XSDAttributeGroupDefinitionAdapter) adapter).setReadOnly(true);
                    ((XSDAttributeGroupDefinitionAdapter) adapter).setChangeReadOnlyField(true);
                }
                contents.remove(target);
            }
        }
        if (doCleanup)
            XSDDirectivesManager.removeUnusedXSDImports(schema);
    } finally {
        endRecording();
    }
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDRedefine(org.eclipse.xsd.XSDRedefine) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDVisitor(org.eclipse.wst.xsd.ui.internal.adapters.XSDVisitor) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDSimpleTypeDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDSimpleTypeDefinitionAdapter) XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet) EObject(org.eclipse.emf.ecore.EObject) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema) XSDComplexTypeDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDComplexTypeDefinitionAdapter) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDAttributeGroupDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeGroupDefinitionAdapter) XSDWildcard(org.eclipse.xsd.XSDWildcard) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) EList(org.eclipse.emf.common.util.EList) XSDModelGroupDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDModelGroupDefinitionAdapter) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) EObject(org.eclipse.emf.ecore.EObject) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Aggregations

XSDSimpleTypeDefinitionAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDSimpleTypeDefinitionAdapter)5 XSDAttributeGroupDefinitionAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeGroupDefinitionAdapter)2 XSDComplexTypeDefinitionAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDComplexTypeDefinitionAdapter)2 XSDModelGroupDefinitionAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDModelGroupDefinitionAdapter)2 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)2 Label (org.eclipse.draw2d.Label)1 ManhattanConnectionRouter (org.eclipse.draw2d.ManhattanConnectionRouter)1 Point (org.eclipse.draw2d.geometry.Point)1 EList (org.eclipse.emf.common.util.EList)1 EObject (org.eclipse.emf.ecore.EObject)1 AbstractGraphicalEditPart (org.eclipse.gef.editparts.AbstractGraphicalEditPart)1 LocationRequest (org.eclipse.gef.requests.LocationRequest)1 ActionRegistry (org.eclipse.gef.ui.actions.ActionRegistry)1 IAction (org.eclipse.jface.action.IAction)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IWorkbench (org.eclipse.ui.IWorkbench)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 XSDVisitor (org.eclipse.wst.xsd.ui.internal.adapters.XSDVisitor)1 CenteredConnectionAnchor (org.eclipse.wst.xsd.ui.internal.adt.design.editparts.CenteredConnectionAnchor)1 TypeReferenceConnection (org.eclipse.wst.xsd.ui.internal.adt.design.editparts.TypeReferenceConnection)1