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: 95f8970e0a611b2bcf58971ecf083ccbfd7ecc80 (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
/*******************************************************************************
 * Copyright (c) 2001, 2006 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
 *******************************************************************************/
package org.eclipse.wst.xsd.ui.internal.adt.design.editparts.model;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject;
import org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObjectListener;
import org.eclipse.wst.xsd.ui.internal.adt.facade.IField;
import org.eclipse.wst.xsd.ui.internal.adt.facade.IStructure;
import org.eclipse.wst.xsd.ui.internal.adt.facade.IType;

public class ReferencedTypeColumn extends AbstractModelCollection
{
  List listenerList = new ArrayList();
  InternalListener internalListener = new InternalListener();
  
  // todo... really this this model object should listen
  // to the parent of the IType
  //
  public ReferencedTypeColumn(IADTObject model)
  {
    super(model, "ReferencedTypeColumn"); //$NON-NLS-1$
    model.registerListener(internalListener);
    internalListener.recomputeSubListeners();
  }

  public List getChildren()
  {
    List result = new ArrayList();  
    if (model instanceof IStructure)
    {
      IStructure structure = (IStructure)model;
      for (Iterator i = structure.getFields().iterator(); i.hasNext(); )
      {
        IField field = (IField)i.next();
        IType type = field.getType();
        if (type != null)  // && type.isComplexType())
        {
          if (!result.contains(type))
          {
            if (type instanceof IGraphElement)
            {
              if (((IGraphElement)type).isFocusAllowed())
                result.add(type);
            }
          }  
        }  
      }        
    }  
    else if (model instanceof IField)
    {
      IField field = (IField)model;
      IType type = field.getType();
      if (type != null) //  && type.isComplexType())
      {
        if (type instanceof IGraphElement)
        {
          if (((IGraphElement)type).isFocusAllowed())
            result.add(type);        
        }
      }
    }  
    return result;
  }  
  
  public void registerListener(IADTObjectListener listener)
  {
    listenerList.add(listener);
  }

  public void unregisterListener(IADTObjectListener listener)
  {
    listenerList.remove(listener);
  }   
  
  protected void notifyListeners(Object changedObject, String property)
  {
    List clonedListenerList = new ArrayList();
    clonedListenerList.addAll(listenerList);
    for (Iterator i = clonedListenerList.iterator(); i.hasNext(); )
    {
      IADTObjectListener listener = (IADTObjectListener)i.next();
      listener.propertyChanged(this, null);
    } 
  }   
  
  protected class InternalListener implements IADTObjectListener
  {
    List fields = new ArrayList();

    void recomputeSubListeners()
    {
      if (model instanceof IStructure)
      {  
        // remove old ones
        for (Iterator i = fields.iterator(); i.hasNext();)
        {
          IField field = (IField) i.next();
          field.unregisterListener(this);
        }
        // add new ones
        fields.clear();
        IStructure complexType = (IStructure) model;
        for (Iterator i = complexType.getFields().iterator(); i.hasNext();)
        {
          IField field = (IField) i.next();
          fields.add(field);
          field.registerListener(this);
        }
      }
    }

    public void propertyChanged(Object object, String property)
    {
      if (object == model)
      {
        // we need to update the fields we're listening too
        // since these may have changed
        recomputeSubListeners();
      }
      else if (object instanceof IField)
      {
      }  
      notifyListeners(object, property);
    }
  }
}

Back to the top