Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 00359159085ca55e2d4e8c09983572f5fae984e0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*******************************************************************************
 * Copyright (c) 2001, 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     Eugene Ostroukhov, eugene@genuitec.com - [203291] XSD Editor Source State
 *                                              not updated in Outline/Graph
 *******************************************************************************/
package org.eclipse.wst.xsd.ui.internal.editor;

import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
import org.eclipse.wst.xsd.ui.internal.adapters.XSDAdapterFactory;
import org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeUseAdapter;
import org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter;
import org.eclipse.wst.xsd.ui.internal.adapters.XSDElementDeclarationAdapter;
import org.eclipse.wst.xsd.ui.internal.adapters.XSDParticleAdapter;
import org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObjectListener;
import org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter;
import org.eclipse.xsd.XSDAttributeUse;
import org.eclipse.xsd.XSDConcreteComponent;
import org.eclipse.xsd.XSDElementDeclaration;
import org.w3c.dom.Element;

public class XSDTabbedPropertySheetPage extends TabbedPropertySheetPage implements IADTObjectListener
{
  XSDBaseAdapter oldSelection;
  XSDModelAdapter xsdModelAdapter;
  public XSDTabbedPropertySheetPage(ITabbedPropertySheetPageContributor tabbedPropertySheetPageContributor)
  {
    super(tabbedPropertySheetPageContributor);
  }
  
  /* (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 = ((StructuredSelection)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);
  }
  
  public void propertyChanged(Object object, String property)
  {
    if (getCurrentTab() != null)
    {
      refresh();
    }
  }
  
  public void dispose()
  {
    if (xsdModelAdapter != null && xsdModelAdapter.getModelReconcileAdapter() != null)
    {
      xsdModelAdapter.getModelReconcileAdapter().removeListener(internalNodeAdapter);
      xsdModelAdapter = null;
    }
    super.dispose();
  }

  protected INodeAdapter internalNodeAdapter = new InternalNodeAdapter();
  class InternalNodeAdapter implements INodeAdapter
  {
    public boolean isAdapterForType(Object type)
    {
      return false;
    }

    public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos)
    {
      refresh();
    }
  }
}

Back to the top