1
2
3
4
5
6
7
8
9
10
11
12 package sk.uniba.euromath.editor.textEditor.actions;
13
14 import org.eclipse.swt.dnd.TextTransfer;
15 import org.eclipse.swt.dnd.Transfer;
16 import org.w3c.dom.DOMException;
17 import sk.baka.ikslibs.levelmapper.NodeListID;
18 import sk.baka.xml.gene.ExportException;
19 import sk.uniba.euromath.document.DocumentModifier;
20 import sk.uniba.euromath.editor.IEditor;
21 import sk.uniba.euromath.editor.textEditor.TextPieceInfoImpl;
22 import sk.uniba.euromath.editor.textEditor.actions.lang.Messages;
23
24 /***
25 * Standart cut action.
26 *
27 * @author Tomáš Studva 8.7.2005
28 */
29 public class CutAction extends CopyAction {
30
31 /***
32 * Id of action.
33 */
34 @SuppressWarnings("hiding")
35 public static final String id = CutAction.class.toString();
36
37 /***
38 * Constructor.
39 */
40 public CutAction() {
41 super();
42 setId(id);
43 setText(Messages.getString("CutAction.Text"));
44 }
45
46 @Override
47 protected boolean calculateEnabled() {
48 return super.calculateEnabled();
49 }
50
51 @Override
52 public void run() {
53
54
55 if (!getTextIds().isEmpty()) {
56 String text = new String();
57 IEditor editor = (IEditor) getWorkbenchPart().getAdapter(
58 IEditor.class);
59 if (editor != null)
60 throw new IllegalStateException();
61 editor.sortIds(getTextIds());
62 DocumentModifier dm = getXMLAccess().getModifier();
63 dm.startModify();
64
65 for (String fullID : getTextIds()) {
66
67 String nodeID = TextPieceInfoImpl.getNodeID(fullID);
68 int offset = TextPieceInfoImpl.getOffset(fullID);
69 int length = TextPieceInfoImpl.getLength(fullID);
70
71 try {
72 NodeListID nodeList = getIdManager().getNode(nodeID);
73 text = text
74 + nodeList.getTextValue().substring(offset,
75 offset + length);
76 if (nodeList.isDeletable(offset, offset + length)) {
77 dm.delete(nodeList, offset, offset + length);
78 }
79
80 } catch (DOMException e) {
81 handleDOMException(e);
82 }
83 }
84
85 try {
86 dm.endModify();
87 } catch (ExportException e) {
88 handleExportException(e);
89 }
90 TextTransfer textTransfer = TextTransfer.getInstance();
91 Transfer[] transfer = new Transfer[] { textTransfer };
92 String[] textA = new String[] { text };
93 getClipboard().setContents(textA, transfer);
94 }
95
96 }
97
98 }