View Javadoc

1   /*
2    * Copyright 1999-2006 Faculty of Mathematics, Physics and Informatics, Comenius
3    * University, Bratislava. This file is protected by the Mozilla Public License
4    * version 1.1 (the License); you may not use this file except in compliance
5    * with the License. You may obtain a copy of the License at
6    * http://euromath2.sourceforge.net/license.html Unless required by applicable
7    * law or agreed to in writing, software distributed under the License is
8    * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9    * KIND, either express or implied. See the License for the specific language
10   * governing permissions and limitations under the License.
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                  // add id to visualized ids
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                  // BTW parent doesn't need to be set, it is done in another
68                  // place
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); //$NON-NLS-1$
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  }