Skip to main content
summaryrefslogtreecommitdiffstats
blob: d2677d4a121d2b6f33b1b6c7a0d7deb374562dba (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
/*******************************************************************************
 * Copyright (c) 2001, 2010 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;

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

import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.Panel;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.model.IGraphElement;
import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.model.RootHolder;
import org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject;
import org.eclipse.wst.xsd.ui.internal.adt.facade.IComplexType;
import org.eclipse.wst.xsd.ui.internal.adt.facade.IField;
import org.eclipse.wst.xsd.ui.internal.adt.facade.IModel;
import org.eclipse.wst.xsd.ui.internal.adt.facade.IStructure;
import org.eclipse.wst.xsd.ui.internal.adt.facade.IType;

public class RootContentEditPart extends BaseEditPart
{
  List collections = null;
  Figure contentPane;
  
  protected IFigure createFigure()
  {    
    Panel panel = new Panel();    
    panel.setBorder(new MarginBorder(60));
   
    ToolbarLayout panelLayout = new ToolbarLayout(false);
    panelLayout.setStretchMinorAxis(true);
    panel.setLayoutManager(panelLayout);
    
    contentPane = new Figure();
    panel.add(contentPane);
    
    ToolbarLayout tb = new ToolbarLayout(false);
    tb.setMinorAlignment(ToolbarLayout.ALIGN_CENTER);
    tb.setStretchMinorAxis(true);
    tb.setSpacing(40);
    contentPane.setLayoutManager(tb);
    
    return panel;
  }
  
  public IFigure getContentPane()
  {
    return contentPane;
  }
  
  
  public IComplexType getSelectedComplexType()
  {
    IComplexType result = null;
    IModel model = (IModel)getModel();
    List types = model.getTypes();
    if (types.size() > 0)
    {
      if (types.get(0) instanceof IComplexType) 
        result = (IComplexType)types.get(0);
    }  
    return result;
  }

  protected void createEditPolicies()
  {
    // TODO Auto-generated method stub
  }
  
  protected List getModelChildren()
  { 
    collections = new ArrayList();
    if (getModel() != null)
    {
      Object obj = getModel();
      IADTObject focusObject = null;
      if (obj instanceof IStructure)
      {
        if (obj instanceof IGraphElement)
        {
          if (((IGraphElement)obj).isFocusAllowed())
            focusObject = (IStructure)obj;          
        }
      }
      else if (obj instanceof IField)
      {
        focusObject = (IField)obj;
      }  
      else if (obj instanceof IModel)
      {
        focusObject = (IModel)obj;
        collections.add(focusObject);
        return collections;
      }
      else if (obj instanceof IType)
      {
        if (obj instanceof IGraphElement)
        {
          if (((IGraphElement)obj).isFocusAllowed())
          {
            focusObject = (IType)obj;
          }
        }
      }
      else if (obj instanceof IGraphElement)
      {
        if (((IGraphElement)obj).isFocusAllowed())
        {
          focusObject = (IADTObject)obj;
          collections.add(focusObject);
          return collections;
        }
      }
      if (focusObject != null)
      {
        RootHolder holder = new RootHolder(focusObject);
        collections.add(holder);
        return collections;
      }
    }
    return collections;
  }
    
  
  /**
   * @deprecated Don't call this method.  Use DesignViewGraphicalViewer.setInput() instead.
   */
  public void setInput(Object component)
  {
    setModel(component);
    refresh();
  }
  
  /**
   * @deprecated Don't call this method.  Use DesignViewGraphicalViewer.getInput() instead.
   */
  public Object getInput()
  {
    return getModel();
  }
  
  // https://bugs.eclipse.org/bugs/show_bug.cgi?id=252589
  public void activate()
  {
    super.activate();
    Object model = getModel();
    // The schema adapter doesn't have to notify the RootContentEditPart of it changes
    if (model instanceof IADTObject)
    {
      IADTObject object = (IADTObject)model;
      object.unregisterListener(this);
    }
  }

}

Back to the top