01: package org.drools.eclipse.editors.rete.part;
02:
03: import org.drools.eclipse.DroolsEclipsePlugin;
04: import org.drools.eclipse.editors.rete.model.Connection;
05: import org.drools.eclipse.editors.rete.model.ReteGraph;
06: import org.drools.reteoo.BaseVertex;
07: import org.eclipse.gef.EditPart;
08: import org.eclipse.gef.EditPartFactory;
09:
10: /**
11: * Factory mapping model elements to edit parts
12: */
13: public class VertexEditPartFactory implements EditPartFactory {
14:
15: /*
16: * (non-Javadoc)
17: * @see org.eclipse.gef.EditPartFactory#createEditPart(org.eclipse.gef.EditPart, java.lang.Object)
18: */
19: public EditPart createEditPart(EditPart context, Object modelElement) {
20: // get EditPart for model element
21: EditPart part = getPartForElement(modelElement);
22: // store model element in EditPart
23: part.setModel(modelElement);
24: return part;
25: }
26:
27: /**
28: * Maps object to EditPart.
29: *
30: * @throws RuntimeException if no match was found
31: */
32: private EditPart getPartForElement(Object modelElement) {
33: if (modelElement instanceof ReteGraph) {
34: return new DiagramEditPart();
35: }
36: if (modelElement instanceof BaseVertex) {
37: return new VertexEditPart();
38: }
39: if (modelElement instanceof Connection) {
40: return new ConnectionEditPart();
41: }
42: DroolsEclipsePlugin.log(new Exception(
43: "Can't create part for model element: "
44: + ((modelElement != null) ? modelElement
45: .getClass().getName() : "null")));
46: return null;
47:
48: }
49:
50: }
|