Search in sources :

Example 6 with XSDElementDeclarationAdapter

use of org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter 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)

Aggregations

XSDElementDeclarationAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter)6 XSDBaseFieldEditPart (org.eclipse.wst.xsd.ui.internal.design.editparts.XSDBaseFieldEditPart)3 List (java.util.List)2 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 XSDAttributeDeclarationAdapter (org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeDeclarationAdapter)2 BaseDragAndDropCommand (org.eclipse.wst.xsd.ui.internal.commands.BaseDragAndDropCommand)2 XSDAttributeDragAndDropCommand (org.eclipse.wst.xsd.ui.internal.commands.XSDAttributeDragAndDropCommand)2 XSDElementDragAndDropCommand (org.eclipse.wst.xsd.ui.internal.commands.XSDElementDragAndDropCommand)2 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)2 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)2 ArrayList (java.util.ArrayList)1 Point (org.eclipse.draw2d.geometry.Point)1 Adapter (org.eclipse.emf.common.notify.Adapter)1 EditPart (org.eclipse.gef.EditPart)1 ChangeBoundsRequest (org.eclipse.gef.requests.ChangeBoundsRequest)1 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 IEditorPart (org.eclipse.ui.IEditorPart)1 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)1