1
2
3
4
5
6
7
8
9
10
11
12 package sk.uniba.euromath.editor.xmlEditor.actions;
13
14 import org.eclipse.ui.IWorkbenchPart;
15 import org.w3c.dom.Node;
16
17 import sk.baka.ikslibs.interval.DOMInterval;
18 import sk.baka.ikslibs.interval.DOMIntervalSet;
19 import sk.baka.ikslibs.ptr.DomPointer;
20 import sk.baka.ikslibs.ptr.DomPointerFactory;
21 import sk.uniba.euromath.editor.textEditor.CaretManager;
22 import sk.uniba.euromath.editor.xmlEditor.actions.lang.Messages;
23
24 /***
25 * Selects parent of selected element or element with caret.
26 *
27 * @author TV Created on 22.7.2004
28 *
29 */
30 public class SelectParentAction extends NodeManipulateAction {
31
32 /***
33 * Default id of action.
34 */
35 public static final String id = SelectParentAction.class.toString();
36
37 public Node nodeToSelect;
38
39 /***
40 * Constructor.
41 *
42 * @param part
43 */
44 public SelectParentAction(IWorkbenchPart part) {
45 super(part, NodeAcquireType.Single, true);
46 setId(id);
47 setText(Messages.getString("SelectParentAction.Text"));
48 }
49
50 /***
51 * Is enabled if is selected one node or caret is active.
52 */
53 @Override
54 protected boolean calculateEnabled() {
55 if (!super.calculateEnabled())
56 return false;
57 if (getNode().getParentNode() != null) {
58
59 this.nodeToSelect = getNode().getParentNode();
60 return true;
61 }
62
63 if ((getCaretManager() != null)
64 && (getCaretManager()
65 .getActiveTextPieceKeeper() != null)) {
66 String nodeId = getCaretManager()
67 .getActiveTextPieceKeeper()
68 .getTextPieceInfo().getNodeID();
69 this.nodeToSelect = getXMLAccess().getIDManager()
70 .getNodeNull(nodeId).item(0)
71 .getParentNode();
72 }
73 return this.nodeToSelect != null;
74 }
75
76 /***
77 * Getter for caret manager.
78 *
79 * @return caret manager from associated workbench part
80 */
81 protected CaretManager getCaretManager() {
82 return (CaretManager) (getWorkbenchPart()
83 .getAdapter(CaretManager.class));
84 }
85
86 /***
87 * Selects parent of selected node or parent of node with caret.
88 */
89 @Override
90 public void run() {
91 DomPointer startPointer = DomPointerFactory
92 .create(this.nodeToSelect);
93 getSelectionProvider()
94 .setSelection(
95 new DOMIntervalSet(
96 new DOMInterval(
97 startPointer,
98 startPointer
99 .getNextSibling())));
100 return;
101
102 }
103 }