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 CopyToAction extends TextBaseAction {
31
32 public CopyToAction() {
33 setDirectionalAction(true);
34 setName("{0} Copy To {1}");
35 setMessage("Copy To");
36 setDescription("Copy To");
37 putValue(Action.MNEMONIC_KEY, KeyEvent.VK_C);
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));
56 } else {
57 putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, ActionEvent.CTRL_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, source);
78
79 model.setFileDirty(destColumn);
80 }
81 }
82 model.notifyUpdate(min, max);
83 } finally {
84 selModel.setValueIsAdjusting(false);
85 }
86 }
87 }
88