Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a0eec279d9e164b9c9fcce33c032794112f683cf (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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
 * Copyright (c) 2011-2013 Eike Stepper (Berlin, Germany) 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:
 *     Martin Fluegge - initial API and implementation
 * 
 */
package org.eclipse.emf.cdo.dawn.examples.acore.graphiti.diagram;

import org.eclipse.emf.cdo.dawn.examples.acore.AClass;
import org.eclipse.emf.cdo.dawn.examples.acore.AInterface;
import org.eclipse.emf.cdo.dawn.examples.acore.graphiti.features.AcoreAddAClassFeature;
import org.eclipse.emf.cdo.dawn.examples.acore.graphiti.features.AcoreAddAInterfaceFeature;
import org.eclipse.emf.cdo.dawn.examples.acore.graphiti.features.AcoreAddAggregationFeature;
import org.eclipse.emf.cdo.dawn.examples.acore.graphiti.features.AcoreAddAssociationFeature;
import org.eclipse.emf.cdo.dawn.examples.acore.graphiti.features.AcoreAddCompositionFeature;
import org.eclipse.emf.cdo.dawn.examples.acore.graphiti.features.AcoreAddImplementationFeature;
import org.eclipse.emf.cdo.dawn.examples.acore.graphiti.features.AcoreAddSubClassesFeature;
import org.eclipse.emf.cdo.dawn.examples.acore.graphiti.features.AcoreCopyAClassFeature;
import org.eclipse.emf.cdo.dawn.examples.acore.graphiti.features.AcoreCreateAClassFeature;
import org.eclipse.emf.cdo.dawn.examples.acore.graphiti.features.AcoreCreateAInterfaceFeature;
import org.eclipse.emf.cdo.dawn.examples.acore.graphiti.features.AcoreCreateAggregationFeature;
import org.eclipse.emf.cdo.dawn.examples.acore.graphiti.features.AcoreCreateAssociationFeature;
import org.eclipse.emf.cdo.dawn.examples.acore.graphiti.features.AcoreCreateCompositionsFeature;
import org.eclipse.emf.cdo.dawn.examples.acore.graphiti.features.AcoreCreateImplementationFeature;
import org.eclipse.emf.cdo.dawn.examples.acore.graphiti.features.AcoreCreateSubclassFeature;
import org.eclipse.emf.cdo.dawn.examples.acore.graphiti.features.AcoreDirectEditAClassFeature;
import org.eclipse.emf.cdo.dawn.examples.acore.graphiti.features.AcorePasteAClassFeature;
import org.eclipse.emf.cdo.dawn.examples.acore.graphiti.features.AcoreReconnectionFeature;
import org.eclipse.emf.cdo.dawn.examples.acore.graphiti.features.AcoreRenameAClassFeature;
import org.eclipse.emf.cdo.dawn.examples.acore.graphiti.features.AcoreUpdateAClassFeature;
import org.eclipse.emf.cdo.dawn.examples.acore.graphiti.util.AcoreGraphitiContextUtil;
import org.eclipse.emf.cdo.dawn.examples.acore.graphiti.util.AcoreGraphitiContextUtil.ConnectionType;

import org.eclipse.graphiti.dt.IDiagramTypeProvider;
import org.eclipse.graphiti.features.IAddFeature;
import org.eclipse.graphiti.features.ICopyFeature;
import org.eclipse.graphiti.features.ICreateConnectionFeature;
import org.eclipse.graphiti.features.ICreateFeature;
import org.eclipse.graphiti.features.IDirectEditingFeature;
import org.eclipse.graphiti.features.IFeature;
import org.eclipse.graphiti.features.IPasteFeature;
import org.eclipse.graphiti.features.IReconnectionFeature;
import org.eclipse.graphiti.features.IUpdateFeature;
import org.eclipse.graphiti.features.context.IAddConnectionContext;
import org.eclipse.graphiti.features.context.IAddContext;
import org.eclipse.graphiti.features.context.ICopyContext;
import org.eclipse.graphiti.features.context.ICustomContext;
import org.eclipse.graphiti.features.context.IDirectEditingContext;
import org.eclipse.graphiti.features.context.IPasteContext;
import org.eclipse.graphiti.features.context.IPictogramElementContext;
import org.eclipse.graphiti.features.context.IReconnectionContext;
import org.eclipse.graphiti.features.context.IUpdateContext;
import org.eclipse.graphiti.features.custom.ICustomFeature;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.ui.features.DefaultFeatureProvider;

/**
 * @author Martin Fluegge
 */
public class AcoreFeatureProvider extends DefaultFeatureProvider
{
  public AcoreFeatureProvider(IDiagramTypeProvider dtp)
  {
    super(dtp);
  }

  @Override
  public ICreateFeature[] getCreateFeatures()
  {
    return new ICreateFeature[] { new AcoreCreateAClassFeature(this), new AcoreCreateAInterfaceFeature(this) };
  }

  @Override
  public ICreateConnectionFeature[] getCreateConnectionFeatures()
  {
    return new ICreateConnectionFeature[] { new AcoreCreateSubclassFeature(this),
        new AcoreCreateImplementationFeature(this), new AcoreCreateAssociationFeature(this),
        new AcoreCreateAggregationFeature(this), new AcoreCreateCompositionsFeature(this) };
  }

  @Override
  public IAddFeature getAddFeature(IAddContext context)
  {
    if (context instanceof IAddConnectionContext)
    {
      ConnectionType connectionType = (ConnectionType)context.getProperty(AcoreGraphitiContextUtil.CONNECTTION_TYPE);
      switch (connectionType)
      {
      case SUBCLASSES:
      {
        return new AcoreAddSubClassesFeature(this);
      }
      case IMPLEMENTATIONS:
      {
        return new AcoreAddImplementationFeature(this);
      }
      case AGGREGATIONS:
      {
        return new AcoreAddAggregationFeature(this);
      }
      case ASSOCIATIONS:
      {
        return new AcoreAddAssociationFeature(this);
      }
      case COMPOSITIONS:
      {
        return new AcoreAddCompositionFeature(this);
      }
      default:
        break;
      }
    }
    else
    {
      if (context.getNewObject() instanceof AClass)
      {
        return new AcoreAddAClassFeature(this);
      }
      else if (context.getNewObject() instanceof AInterface)
      {
        return new AcoreAddAInterfaceFeature(this);
      }
    }

    return super.getAddFeature(context);
  }

  @Override
  public IUpdateFeature getUpdateFeature(IUpdateContext context)
  {
    PictogramElement pictogramElement = context.getPictogramElement();
    if (pictogramElement instanceof ContainerShape)
    {
      Object bo = getBusinessObjectForPictogramElement(pictogramElement);
      if (bo instanceof AClass)
      {
        return new AcoreUpdateAClassFeature(this);
      }
    }
    return super.getUpdateFeature(context);
  }

  @Override
  public IFeature[] getDragAndDropFeatures(IPictogramElementContext context)
  {
    // simply return all create connection features
    return getCreateConnectionFeatures();
  }

  @Override
  public IReconnectionFeature getReconnectionFeature(IReconnectionContext context)
  {
    return new AcoreReconnectionFeature(this);
  }

  @Override
  public IDirectEditingFeature getDirectEditingFeature(IDirectEditingContext context)
  {
    PictogramElement pe = context.getPictogramElement();
    Object bo = getBusinessObjectForPictogramElement(pe);
    if (bo instanceof AClass)
    {
      return new AcoreDirectEditAClassFeature(this);
    }
    return super.getDirectEditingFeature(context);
  }

  @Override
  public ICopyFeature getCopyFeature(ICopyContext context)
  {
    return new AcoreCopyAClassFeature(this);
  }

  @Override
  public IPasteFeature getPasteFeature(IPasteContext context)
  {
    return new AcorePasteAClassFeature(this);
  }

  @Override
  public ICustomFeature[] getCustomFeatures(ICustomContext context)
  {
    return new ICustomFeature[] { new AcoreRenameAClassFeature(this) };
  }
}

Back to the top