Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ebb4f422444d692000d98c3f3ea63e2696140d20 (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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*******************************************************************************
 * 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.adapters;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.graphics.Image;
import org.eclipse.wst.xsd.ui.internal.adt.actions.BaseSelectionAction;
import org.eclipse.wst.xsd.ui.internal.adt.actions.ShowPropertiesViewAction;
import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.model.IActionProvider;
import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.model.IModelProxy;
import org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObjectListener;
import org.eclipse.wst.xsd.ui.internal.adt.facade.IModel;
import org.eclipse.wst.xsd.ui.internal.adt.outline.ITreeElement;
import org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDAttributeDeclarationAction;
import org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDAttributeGroupDefinitionAction;
import org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDComplexTypeDefinitionAction;
import org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDElementAction;
import org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDSchemaDirectiveAction;
import org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDModelGroupDefinitionAction;
import org.eclipse.wst.xsd.ui.internal.common.actions.AddXSDSimpleTypeDefinitionAction;
import org.eclipse.xsd.XSDSchema;

public class CategoryAdapter extends XSDBaseAdapter implements IModelProxy, IActionProvider, IADTObjectListener
{
  protected String text;
  protected Image image;
  protected Object parent;
  protected int groupType;
  Collection children, allChildren;  // children from current schema, children from current schema and includes
  XSDSchema xsdSchema;

  public CategoryAdapter(String label, Image image, Collection children, XSDSchema xsdSchema, int groupType)
  {
    this.text = label;
    this.image = image;
    this.parent = xsdSchema;
    this.xsdSchema = xsdSchema;
    this.target = xsdSchema;
    this.children = children;
    this.groupType = groupType;
  }

  public final static int ATTRIBUTES = 1;
  public final static int ELEMENTS = 2;
  public final static int TYPES = 3;
  public final static int GROUPS = 5;
  public final static int DIRECTIVES = 6;
  public final static int NOTATIONS = 7;
  public final static int ATTRIBUTE_GROUPS = 8;
  public final static int IDENTITY_CONSTRAINTS = 9;
  public final static int ANNOTATIONS = 10;

  public XSDSchema getXSDSchema()
  {
    return xsdSchema;
  }

  public int getGroupType()
  {
    return groupType;
  }

  public Image getImage()
  {
    return image;
  }

  public String getText()
  {
    return text;
  }

  public ITreeElement[] getChildren()
  {
    return (ITreeElement[]) children.toArray(new ITreeElement[0]);
  }
  
  public ITreeElement[] getAllChildren()
  {
    return (ITreeElement[]) allChildren.toArray(new ITreeElement[0]);
  }

  public void setChildren(Collection list)
  {
    children = list;
  }

  public void setAllChildren(Collection list)
  {
    allChildren = list;
  }

  public Object getParent(Object element)
  {
    return xsdSchema;
  }

  public boolean hasChildren(Object element)
  {
    return true;
  }

  public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
  {

  }

  public String[] getActions(Object object)
  {    
    Collection actionIDs = new ArrayList();
    
    switch (groupType)
    {
      case TYPES : {
        actionIDs.add(AddXSDComplexTypeDefinitionAction.ID);
        actionIDs.add(AddXSDSimpleTypeDefinitionAction.ID);
        break;
      }
      case ELEMENTS : {
        actionIDs.add(AddXSDElementAction.ID);
        break;
      }
      case GROUPS : {
        actionIDs.add(AddXSDModelGroupDefinitionAction.MODELGROUPDEFINITION_ID);
        break;
      }
      case ATTRIBUTES : {
        actionIDs.add(AddXSDAttributeDeclarationAction.ID);
        actionIDs.add(AddXSDAttributeGroupDefinitionAction.ID);
        break;
      }
      case ATTRIBUTE_GROUPS : {
        actionIDs.add(AddXSDAttributeGroupDefinitionAction.ID);
        break;
      }
      case DIRECTIVES : {
        actionIDs.add(AddXSDSchemaDirectiveAction.INCLUDE_ID);
        actionIDs.add(AddXSDSchemaDirectiveAction.IMPORT_ID);
        actionIDs.add(AddXSDSchemaDirectiveAction.REDEFINE_ID);
        break;
      }
    }
    actionIDs.add(BaseSelectionAction.SEPARATOR_ID);
    actionIDs.add(ShowPropertiesViewAction.ID);
    return (String [])actionIDs.toArray(new String[0]);
  }
  
  public void propertyChanged(Object object, String property)
  {
    if (getText().equals(property))
      notifyListeners(this, property);
  }

  public List getTypes()
  {
    return null;
  }

  public IModel getModel()
  {
    return (IModel)XSDAdapterFactory.getInstance().adapt(xsdSchema);
  }
}

Back to the top