1
2
3
4
5
6
7
8
9
10
11
12 package sk.uniba.euromath.editor.xmlEditor.actions;
13
14 import java.util.ArrayList;
15 import java.util.List;
16 import org.eclipse.ui.IWorkbenchPart;
17 import org.w3c.dom.Attr;
18 import org.w3c.dom.Element;
19 import sk.baka.ikslibs.levelmapper.NodeListID;
20 import sk.uniba.euromath.editor.textEditor.ICaretProvider;
21 import sk.uniba.euromath.editor.xmlEditor.actions.lang.Messages;
22
23 /***
24 * Selects parent of selected element or element with cursor.
25 *
26 * @author TV Created on 22.7.2004
27 *
28 */
29 public class SelectParentAction extends NodeManipulateAction {
30
31 /***
32 * Default id of action.
33 */
34 public static final String id = SelectParentAction.class.toString();
35
36 /***
37 * Calculated id of parent of selected node or node with caret.
38 */
39 private String parentId = null;
40
41 /***
42 * Constructor.
43 */
44 public SelectParentAction() {
45 this(null);
46 }
47
48 /***
49 * Constructor.
50 *
51 * @param part
52 */
53 public SelectParentAction(IWorkbenchPart part) {
54 super(part);
55 setId(id);
56 setText(Messages.getString("SelectParentAction.Text"));
57 }
58
59 @Override
60 protected void clear() {
61 super.clear();
62 setParentId(null);
63 }
64
65 /***
66 * Computes parentID of selected element, if is selected.
67 */
68 @Override
69 protected void processSelection() {
70 super.processSelection();
71 if ((getNode() == null) || (getNode() instanceof Attr)
72 || (getNode().getParentNode() == null))
73 return;
74
75 }
76
77 @Override
78 protected boolean calculateEnabled() {
79 return (getXMLAccess() != null) && (getParentId() != null);
80 }
81
82 /***
83 * Returns id of parent of selected element, or id of element containing
84 * caret or null;
85 *
86 * @return id of parent of node with focus
87 */
88 public String getParentId() {
89 if (this.parentId != null)
90 return this.parentId;
91
92 if (getNodeID() == null)
93 return null;
94 NodeListID nodes = getXMLAccess().getIdManager().getNodeNull(
95 getNodeID());
96 if ((nodes != null) && (nodes.item(0).getParentNode() != null))
97 return getIdManager().getIDNull(
98 nodes.item(0).getParentNode());
99
100 return null;
101 }
102
103 /***
104 * Getter for caret provider.
105 *
106 * @return caret provider from associated workbench part
107 */
108 protected ICaretProvider getCaretProvider() {
109 return (ICaretProvider) (getWorkbenchPart()
110 .getAdapter(ICaretProvider.class));
111 }
112
113 /***
114 * Returns ID of node containig caret
115 *
116 * @return id of node with caret
117 */
118 protected String getNodeID() {
119 if (getCaretProvider() == null)
120 return null;
121 return getCaretProvider().getNodeIDWithCaret();
122 }
123
124 /***
125 * Selects paretn of selected node or parent of node with caret.
126 */
127 @Override
128 public void run() {
129 List<String> ids = new ArrayList<String>();
130 ids.add(getParentId());
131
132 }
133
134 /***
135 * @param parentId
136 * The parentId to set.
137 */
138 protected void setParentId(String parentId) {
139 this.parentId = parentId;
140 }
141 }