Search in sources :

Example 31 with XSDBaseAdapter

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

the class AddXSDAttributeGroupDefinitionAction method run.

public void run() {
    Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
    if (selection instanceof XSDBaseAdapter) {
        selection = ((XSDBaseAdapter) selection).getTarget();
    }
    AddXSDAttributeGroupDefinitionCommand command = null;
    if (selection instanceof XSDComplexTypeDefinition) {
        command = new AddXSDAttributeGroupDefinitionCommand(Messages._UI_ACTION_ADD_ATTRIBUTE_GROUP_REF, (XSDComplexTypeDefinition) selection);
        getCommandStack().execute(command);
    } else if (selection instanceof XSDSchema) {
        command = new AddXSDAttributeGroupDefinitionCommand(Messages._UI_ACTION_ADD_ATTRIBUTE_GROUP_DEFINITION, (XSDSchema) selection);
        getCommandStack().execute(command);
    }
    if (command != null) {
        addedComponent = command.getAddedComponent();
        Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent);
        selectAddedComponent(adapter);
    }
}
Also used : AddXSDAttributeGroupDefinitionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDAttributeGroupDefinitionCommand) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) Adapter(org.eclipse.emf.common.notify.Adapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 32 with XSDBaseAdapter

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

the class XSDTabbedPropertySheetPage method selectionChanged.

/* (non-Javadoc)
   * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
   */
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
    Object selected = ((IStructuredSelection) selection).getFirstElement();
    if (selected instanceof XSDBaseAdapter) {
        XSDBaseAdapter adapter = (XSDBaseAdapter) selected;
        if (oldSelection != null) {
            oldSelection.unregisterListener(this);
            if (oldSelection instanceof XSDElementDeclarationAdapter) {
                XSDElementDeclaration elem = (XSDElementDeclaration) ((XSDElementDeclarationAdapter) oldSelection).getTarget();
                if (elem.getContainer() != null) {
                    Adapter adap = XSDAdapterFactory.getInstance().adapt(elem.getContainer());
                    if (adap instanceof XSDParticleAdapter) {
                        XSDParticleAdapter particleAdapter = (XSDParticleAdapter) adap;
                        particleAdapter.unregisterListener(this);
                    }
                }
                if (elem.isElementDeclarationReference()) {
                    XSDElementDeclarationAdapter resolvedElementAdapter = (XSDElementDeclarationAdapter) XSDAdapterFactory.getInstance().adapt(elem.getResolvedElementDeclaration());
                    resolvedElementAdapter.unregisterListener(this);
                }
            }
        }
        if (adapter instanceof XSDElementDeclarationAdapter) {
            XSDElementDeclaration elem = (XSDElementDeclaration) ((XSDElementDeclarationAdapter) adapter).getTarget();
            Adapter adap = XSDAdapterFactory.getInstance().adapt(elem.getContainer());
            if (adap instanceof XSDParticleAdapter) {
                XSDParticleAdapter particleAdapter = (XSDParticleAdapter) adap;
                particleAdapter.registerListener(this);
            }
            if (elem.isElementDeclarationReference()) {
                XSDElementDeclarationAdapter resolvedElementAdapter = (XSDElementDeclarationAdapter) XSDAdapterFactory.getInstance().adapt(elem.getResolvedElementDeclaration());
                resolvedElementAdapter.registerListener(this);
            }
        } else if (adapter instanceof XSDAttributeUseAdapter) {
            XSDAttributeUseAdapter attributeUse = (XSDAttributeUseAdapter) adapter;
            XSDAttributeUse xsdAttrUse = (XSDAttributeUse) attributeUse.getTarget();
            adapter = (XSDBaseAdapter) XSDAdapterFactory.getInstance().adapt(xsdAttrUse.getAttributeDeclaration());
        }
        adapter.registerListener(this);
        oldSelection = adapter;
        Object model = adapter.getTarget();
        if (xsdModelAdapter != null && xsdModelAdapter.getModelReconcileAdapter() != null) {
            xsdModelAdapter.getModelReconcileAdapter().removeListener(internalNodeAdapter);
        }
        Element element = ((XSDConcreteComponent) adapter.getTarget()).getElement();
        if (element != null) {
            xsdModelAdapter = XSDModelAdapter.lookupOrCreateModelAdapter(element.getOwnerDocument());
        }
        if (xsdModelAdapter != null && xsdModelAdapter.getModelReconcileAdapter() != null) {
            xsdModelAdapter.getModelReconcileAdapter().addListener(internalNodeAdapter);
        }
        if (model instanceof XSDConcreteComponent) {
            selection = new StructuredSelection(model);
        }
        super.selectionChanged(part, selection);
        return;
    }
    super.selectionChanged(part, selection);
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Element(org.w3c.dom.Element) XSDParticleAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDParticleAdapter) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) XSDParticleAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDParticleAdapter) Adapter(org.eclipse.emf.common.notify.Adapter) XSDModelAdapter(org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter) XSDElementDeclarationAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter) INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) XSDAttributeUseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeUseAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDElementDeclarationAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter) XSDAttributeUseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeUseAdapter)

Example 33 with XSDBaseAdapter

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

the class RefactorEnablementTester method test.

public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return false;
    }
    IWorkbenchPage activePage = window.getActivePage();
    if (activePage == null) {
        return false;
    }
    IEditorPart editor = activePage.getActiveEditor();
    if (editor == null) {
        return false;
    }
    XSDSchema schema = (XSDSchema) editor.getAdapter(XSDSchema.class);
    if (receiver instanceof IStructuredSelection) {
        IStructuredSelection fStructuredSelection = (IStructuredSelection) receiver;
        receiver = fStructuredSelection.getFirstElement();
        if (receiver instanceof XSDBaseAdapter) {
            receiver = ((XSDBaseAdapter) receiver).getTarget();
        }
        if (receiver instanceof XSDConcreteComponent) {
            return canEnable((XSDConcreteComponent) receiver, schema);
        } else if (receiver instanceof Node) {
            Node node = (Node) receiver;
            if (schema != null) {
                XSDConcreteComponent concreteComponent = schema.getCorrespondingComponent(node);
                return canEnable(concreteComponent, schema);
            }
        }
        return true;
    }
    return false;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) Node(org.w3c.dom.Node) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) IEditorPart(org.eclipse.ui.IEditorPart) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDSchema(org.eclipse.xsd.XSDSchema)

Aggregations

XSDBaseAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter)33 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)23 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)16 Adapter (org.eclipse.emf.common.notify.Adapter)14 XSDSchema (org.eclipse.xsd.XSDSchema)10 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)9 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)8 IEditorPart (org.eclipse.ui.IEditorPart)6 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)5 Iterator (java.util.Iterator)4 XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)4 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)4 List (java.util.List)3 Point (org.eclipse.draw2d.geometry.Point)3 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)3 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)3 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)3 ArrayList (java.util.ArrayList)2 Image (org.eclipse.swt.graphics.Image)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2