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 associated with editpart
45 * @param editPart new created editpart, yet not affected IdVisualInfo
46 */
47 protected void updateVisualInfo(IEMFigure figure, XMLEditPart editPart) {
48
49 if (figure.getID() != null) {
50 String id = figure.getID();
51
52
53 if (id.indexOf(':') >= 0)
54 id = id.substring(0, id.indexOf(':'));
55 getVisualInfo().add(id, editPart);
56 }
57 }
58
59 /***
60 * Creates EditPart for model of type IEMFigure. In other model types
61 * returns null. Be very careful when overriding. Updates VisualInfo.
62 *
63 * @param context
64 * is parent editPart
65 * @param model
66 * figure for which editPart should be created
67 */
68 public EditPart createEditPart(EditPart context, Object model) {
69
70 if (model instanceof IEMFigure) {
71 XMLEditPart result = new XMLEditPart((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 by
82 * which XMLEditPart
83 *
84 * @return IdVisualInfo
85 */
86 public IdVisualInfo getVisualInfo() {
87 return this.visualInfo;
88 }
89 }