1
2
3
4
5
6
7
8
9
10
11
12
13 package org.abstracthorizon.aequo.text.action;
14
15 import java.awt.event.ActionEvent;
16 import java.awt.event.KeyEvent;
17
18 import javax.swing.Action;
19 import javax.swing.KeyStroke;
20 import javax.swing.ListSelectionModel;
21
22 import org.abstracthorizon.aequo.CompareEntry;
23 import org.abstracthorizon.aequo.text.TextModel;
24
25
26
27
28
29
30 public class MoveToAction extends TextBaseAction {
31
32 public MoveToAction() {
33 setDirectionalAction(true);
34 setName("{0} Move To {1}");
35 setMessage("Move To");
36 setDescription("Move To");
37 putValue(Action.MNEMONIC_KEY, KeyEvent.VK_M);
38 }
39
40
41
42
43
44 public boolean isEnabled() {
45 return (column >= 0) && isSelectionValid();
46 }
47
48
49
50
51
52 public void setColumn(int column) {
53 super.setColumn(column);
54 if (column == 0) {
55 putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK));
56 } else {
57 putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK));
58 }
59 }
60
61
62
63
64
65 public void perform(ActionEvent e) {
66 TextModel model = getTextModel();
67 ListSelectionModel selModel = model.getSelectionModel();
68 int min = selModel.getMinSelectionIndex();
69 int max = selModel.getMaxSelectionIndex();
70 selModel.setValueIsAdjusting(true);
71 try {
72 for (int i = max; i >= min; i--) {
73 CompareEntry<String> entry = model.get(i);
74 String source = entry.getData(column);
75 String dest = entry.getData(destColumn);
76 if ((source != dest) && ((source == null) || !source.equals(dest))) {
77 entry.setData(destColumn, entry.getData(column));
78
79 model.setFileDirty(destColumn);
80 }
81 if (source != null) {
82 entry.setData(column, null);
83 model.setFileDirty(column);
84 }
85 }
86 model.notifyUpdate(min, max);
87 } finally {
88 selModel.setValueIsAdjusting(false);
89 }
90 }
91 }