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.actions;
13  
14  import org.eclipse.ui.IWorkbenchPart;
15  
16  import sk.baka.ikslibs.interval.DOMInterval;
17  import sk.baka.ikslibs.interval.DOMIntervalSet;
18  import sk.baka.ikslibs.levelmapper.NodeListID;
19  import sk.uniba.euromath.editor.xmlEditor.actions.lang.Messages;
20  
21  /***
22   * Selects node(or part, depends on id) specified by id in constructor.
23   * 
24   * @author Tomáš Studva 9.7.2005
25   */
26  public class SelectAction extends XMLAccessModifyAction {
27  
28          /***
29           * Default id of action.
30           */
31          public static final String id = SelectAction.class.toString();
32  
33          /***
34           * Id of (part of) node to select.
35           */
36          private final String nodeId;
37  
38          /***
39           * Constructor.
40           * 
41           * @param id
42           *                of node to select
43           * @param part
44           */
45          public SelectAction(String id, IWorkbenchPart part) {
46                  super(part);
47                  this.nodeId = id;
48                  setId(SelectAction.id);
49                  setText(Messages.getString("SelectAction.Text")); //$NON-NLS-1$
50          }
51  
52          /***
53           * Selects node with id = nodeId in selection provider.
54           */
55          @Override
56          public void run() {
57                  NodeListID node = getXMLAccess().getIDManager().getNode(
58                                  this.nodeId);
59                  getSelectionProvider().setSelection(
60                                  new DOMIntervalSet(new DOMInterval(node
61                                                  .getStart(), node.getEnd())));
62          }
63  
64          @Override
65          protected boolean calculateEnabled() {
66                  if (!super.calculateEnabled())
67                          return false;
68                  NodeListID node = getXMLAccess().getIDManager().getNodeNull(
69                                  this.nodeId);
70                  return node != null;
71          }
72  
73  }