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: 26426048abbd5bb55ae4007d4cddb38d2d6c0512 (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
/*******************************************************************************
 * 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
 *******************************************************************************/
package org.eclipse.wst.xsd.ui.internal.adt.design.editparts;

import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartFactory;
import org.eclipse.jface.util.Assert;
import org.eclipse.wst.xsd.ui.internal.adt.design.ADTFloatingToolbar.ADTFloatingToolbarModel;
import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.model.AbstractModelCollection;
import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.model.Compartment;
import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.model.FocusTypeColumn;
import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.model.RootHolder;
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;

public class ADTEditPartFactory implements EditPartFactory
{
  public EditPart createEditPart(EditPart context, Object model)
  {
    EditPart child = doCreateEditPart(context, model);
    checkChild(child, model);
    return child;
  }
  
  protected EditPart doCreateEditPart(EditPart context, Object model)
  {
    EditPart child = null;
    if (model instanceof Compartment)
    {
      child = new CompartmentEditPart();
    }
    else if (model instanceof RootHolder)
    {
      child = new RootHolderEditPart();
    }
    else if (model instanceof ADTFloatingToolbarModel)
    {
      child = new ADTFloatingToolbarEditPart(((ADTFloatingToolbarModel)model).getModel());
    }
    else if (model instanceof AbstractModelCollection)
    {
      child = new ColumnEditPart();
      if (model instanceof FocusTypeColumn)
      {
        ColumnEditPart columnEditPart = (ColumnEditPart)child;
        columnEditPart.setSpacing(60);
        columnEditPart.setMinorAlignment(ToolbarLayout.ALIGN_CENTER);
      }  
    }
    else if (model instanceof IComplexType)
    {
      child = new ComplexTypeEditPart();
    }
    else if (model instanceof IStructure)
    {
      child = new StructureEditPart();
    }  
    else if (model instanceof IField)
    {
      if (context instanceof CompartmentEditPart)
      {  
        child = new FieldEditPart();
      }
      else
      {
        child = new TopLevelFieldEditPart();
      }  
    }
    else if (model instanceof IModel)
    {
      child = new RootContentEditPart();
    }
    return child;   
  }

  /**
   * Subclasses can override and not check for null
   * 
   * @param child
   * @param model
   */
  protected void checkChild(EditPart child, Object model)
  {
    if (child == null)
    {
      // Thread.dumpStack();
    }
    Assert.isNotNull(child);
    child.setModel(model);
  }
}

Back to the top