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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
/*******************************************************************************
* Copyright (c) 2004, 2007 Boeing.
* 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:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.framework.ui.data.model.editor.part;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.UnexecutableCommand;
import org.eclipse.gef.editpolicies.GraphicalNodeEditPolicy;
import org.eclipse.gef.editpolicies.LayoutEditPolicy;
import org.eclipse.gef.requests.CreateConnectionRequest;
import org.eclipse.gef.requests.CreateRequest;
import org.eclipse.gef.requests.ReconnectRequest;
import org.eclipse.osee.framework.ui.data.model.editor.command.CreateAttributeCommand;
import org.eclipse.osee.framework.ui.data.model.editor.command.CreateConnectionCommand;
import org.eclipse.osee.framework.ui.data.model.editor.command.CreateRelationCommand;
import org.eclipse.osee.framework.ui.data.model.editor.command.ReconnectConnectionCommand;
import org.eclipse.osee.framework.ui.data.model.editor.figure.ArtifactTypeFigure;
import org.eclipse.osee.framework.ui.data.model.editor.figure.SelectableLabel;
import org.eclipse.osee.framework.ui.data.model.editor.model.ArtifactDataType;
import org.eclipse.osee.framework.ui.data.model.editor.model.AttributeDataType;
import org.eclipse.osee.framework.ui.data.model.editor.model.ConnectionModel;
import org.eclipse.osee.framework.ui.data.model.editor.model.InheritanceLinkModel;
import org.eclipse.osee.framework.ui.data.model.editor.model.RelationDataType;
import org.eclipse.osee.framework.ui.data.model.editor.model.RelationLinkModel;
import org.eclipse.osee.framework.ui.data.model.editor.model.helper.ContainerModel;
import org.eclipse.osee.framework.ui.data.model.editor.model.helper.ContainerModel.ContainerType;
/**
* @author Roberto E. Escobar
*/
public class ArtifactEditPart extends DataTypeEditPart {
@SuppressWarnings("unchecked")
private List children;
public ArtifactEditPart(Object model) {
super((ArtifactDataType) model);
}
@Override
protected void createEditPolicies() {
super.createEditPolicies();
installEditPolicy(EditPolicy.LAYOUT_ROLE, new ArtifactLayoutEditPolicy());
installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new ArtifactGraphicalNodeEditPolicy());
}
@Override
protected IFigure createFigure() {
return new ArtifactTypeFigure(new Label(), new SelectableLabel());
}
@Override
public IFigure getContentPane() {
return ((ArtifactTypeFigure) getFigure()).getContentPane();
}
@Override
protected IFigure getDirectEditFigure() {
return ((ArtifactTypeFigure) getFigure()).getNameFigure();
}
private ArtifactDataType getArtifactDataType() {
return (ArtifactDataType) getDataType();
}
@Override
public boolean canDeleteFromDiagram() {
return true;
}
@Override
@SuppressWarnings("unchecked")
protected List getModelChildren() {
ArtifactDataType model = getArtifactDataType();
if (children == null) {
children = new ArrayList();
children.add(new ContainerModel(model, ContainerType.INHERITED_ATTRIBUTES));
children.add(new ContainerModel(model, ContainerType.LOCAL_ATTRIBUTES));
children.add(new ContainerModel(model, ContainerType.INHERITED_RELATIONS));
children.add(new ContainerModel(model, ContainerType.LOCAL_RELATIONS));
}
// checkInheritance();
return children;
}
// private void checkInheritance() {
// ArtifactDataType model = getArtifactDataType();
//
// for (ArtifactDataType key : toRemove) {
// InheritanceLinkModel link = inheritanceMap.remove(key);
// if (link != null) {
// children.remove(link);
// }
// }
// }
@Override
protected void refreshVisuals() {
super.refreshVisuals();
ArtifactTypeFigure artifactTypeFigure = (ArtifactTypeFigure) getFigure();
artifactTypeFigure.setHeaderIcon(getArtifactDataType().getImage());
((Label) artifactTypeFigure.getNameFigure()).setText(getArtifactDataType().getName());
artifactTypeFigure.getNameFigure().setFont(null);
getFigure().setBackgroundColor(ColorConstants.white);
super.refreshChildren();
}
@Override
protected void handleModelEvent(Object msg) {
refreshVisuals();
}
private final class ArtifactLayoutEditPolicy extends LayoutEditPolicy {
@Override
protected EditPolicy createChildEditPolicy(EditPart child) {
return null;
}
@Override
protected Command getCreateCommand(CreateRequest request) {
if (request.getNewObject() instanceof AttributeDataType) {
return new CreateAttributeCommand((AttributeDataType) request.getNewObject(),
((ArtifactEditPart) getHost()).getArtifactDataType());
} else if (request.getNewObject() instanceof RelationDataType) {
return new CreateRelationCommand(((RelationDataType) request.getNewObject()),
((ArtifactEditPart) getHost()).getArtifactDataType());
}
return UnexecutableCommand.INSTANCE;
}
@Override
protected Command getDeleteDependantCommand(Request request) {
return null;
}
@Override
protected Command getMoveChildrenCommand(Request request) {
return UnexecutableCommand.INSTANCE;
}
}
private final class ArtifactGraphicalNodeEditPolicy extends GraphicalNodeEditPolicy {
@Override
protected Command getConnectionCompleteCommand(CreateConnectionRequest request) {
CreateConnectionCommand cmd = (CreateConnectionCommand) request.getStartCommand();
cmd.setTarget((ArtifactDataType) getHost().getModel());
return cmd;
}
@Override
protected Command getConnectionCreateCommand(CreateConnectionRequest request) {
ConnectionModel connectionModel = (ConnectionModel) request.getNewObject();
if (connectionModel instanceof RelationLinkModel || connectionModel instanceof InheritanceLinkModel) {
ArtifactDataType source = (ArtifactDataType) getHost().getModel();
Command cmd = new CreateConnectionCommand(connectionModel, source);
request.setStartCommand(cmd);
return cmd;
}
return null;
}
@Override
@SuppressWarnings("unchecked")
protected Command getReconnectSourceCommand(ReconnectRequest request) {
ConnectionModel<ArtifactDataType> connectionModel =
(ConnectionModel<ArtifactDataType>) request.getConnectionEditPart().getModel();
if (connectionModel instanceof RelationLinkModel || connectionModel instanceof InheritanceLinkModel) {
ArtifactDataType source = (ArtifactDataType) getHost().getModel();
ReconnectConnectionCommand cmd = new ReconnectConnectionCommand(connectionModel);
cmd.setNewSource(source);
return cmd;
}
return UnexecutableCommand.INSTANCE;
}
@Override
@SuppressWarnings("unchecked")
protected Command getReconnectTargetCommand(ReconnectRequest request) {
ConnectionModel<ArtifactDataType> connectionModel =
(ConnectionModel<ArtifactDataType>) request.getConnectionEditPart().getModel();
if (connectionModel instanceof RelationLinkModel || connectionModel instanceof InheritanceLinkModel) {
ArtifactDataType target = (ArtifactDataType) getHost().getModel();
ReconnectConnectionCommand cmd = new ReconnectConnectionCommand(connectionModel);
cmd.setNewTarget(target);
return cmd;
}
return UnexecutableCommand.INSTANCE;
}
}
}
|