1
2
3
4
5
6
7
8
9
10
11
12 package sk.uniba.euromath.editor.xmlEditor;
13
14 import org.eclipse.core.runtime.IStatus;
15 import org.eclipse.gef.EditPart;
16 import org.eclipse.gef.EditPartFactory;
17
18 import sk.uniba.euromath.EuroMath;
19 import sk.uniba.euromath.editor.figures.IEMFigure;
20 import sk.uniba.euromath.editor.xmlEditor.editParts.XMLEditPart;
21 import sk.uniba.euromath.editor.xmlEditor.lang.Messages;
22
23 /***
24 * @author Tomáš Studva 31.7.2005
25 */
26 public class XMLEditPartFactory implements EditPartFactory {
27
28 /***
29 * Holds which ids have been visualized and by which XMLEditPart.
30 */
31 private final IdVisualInfo visualInfo;
32
33 /***
34 * Constructor.
35 */
36 public XMLEditPartFactory() {
37 super();
38 this.visualInfo = new IdVisualInfo();
39 }
40
41 /***
42 * Updates IdVisualInfo to valid state.
43 *
44 * @param figure
45 * associated with editpart
46 * @param editPart
47 * new created editpart, yet not affected IdVisualInfo
48 */
49 protected void updateVisualInfo(IEMFigure figure, IXMLEditPart editPart) {
50
51 if (figure.getID() != null) {
52 String id = figure.getID();
53 getVisualInfo().add(id, editPart);
54 }
55 }
56
57 /***
58 * Creates EditPart for model of type IEMFigure. In other model types
59 * returns null. Be very careful when overriding. Updates VisualInfo.
60 *
61 * @param context
62 * is parent editPart
63 * @param model
64 * figure for which editPart should be created
65 */
66 public EditPart createEditPart(EditPart context, Object model) {
67
68
69 if (model instanceof IEMFigure) {
70 IXMLEditPart result = new XMLEditPart(
71 (IEMFigure) model, true);
72 updateVisualInfo((IEMFigure) model, result);
73 return result;
74 }
75 EuroMath.log(IStatus.WARNING, IStatus.WARNING, Messages
76 .getString("XMLEditPartFactory.0"), null);
77 return null;
78 }
79
80 /***
81 * Returns IdVisualInfo object. Holds which ids have been visualized and
82 * by which XMLEditPart
83 *
84 * @return IdVisualInfo
85 */
86 public IdVisualInfo getVisualInfo() {
87 return this.visualInfo;
88 }
89 }