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 associated with editpart
45       * @param editPart new created editpart, yet not affected IdVisualInfo
46       */
47      protected void updateVisualInfo(IEMFigure figure, XMLEditPart editPart) {
48          // add id to visualized ids
49          if (figure.getID() != null) {
50              String id = figure.getID();
51              // TODO Studva this is not right, remove, and also update
52              // OutlineItem...
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          // BTW parent doesn't need to be set, it is done in another place
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); //$NON-NLS-1$
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  }