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.text.TextCompareEntry;
23 import org.abstracthorizon.aequo.text.TextModel;
24
25
26
27
28
29
30 public class DeleteAction extends TextBaseAction {
31
32
33
34
35 public DeleteAction() {
36 setName("Delete");
37 setMessage("Delete");
38 setDescription("Delete");
39 putValue(Action.MNEMONIC_KEY, KeyEvent.VK_D);
40 putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, ActionEvent.CTRL_MASK));
41 }
42
43
44
45
46
47 public boolean isEnabled() {
48 return (column >= 0) && isSelectionValid();
49 }
50
51
52
53
54
55 public void perform(ActionEvent e) {
56 TextModel model = getTextModel();
57 ListSelectionModel selModel = model.getSelectionModel();
58 int min = selModel.getMinSelectionIndex();
59 int max = selModel.getMaxSelectionIndex();
60 selModel.setValueIsAdjusting(true);
61 try {
62 for (int i = max; i >= min; i--) {
63 TextCompareEntry entry = model.get(i);
64 String d = entry.getData(column);
65 if (d != null) {
66 int j = 0;
67 Object[] data = entry.getData();
68 while ((j < data.length) && ((j == column) || (j != column) && (data[j] == null))) {
69 j++;
70 }
71
72 if (j == data.length) {
73 model.removeImpl(i);
74 } else {
75 entry.setData(column, null);
76 }
77 model.setFileDirty(column);
78 }
79 }
80 model.updateLineNumbers(min, -1);
81 model.notifyUpdate(min, max);
82 } finally {
83 selModel.setValueIsAdjusting(false);
84 }
85 }
86 }