1
2
3
4
5
6
7 package org.asyrinx.joey.gui.swing.listview;
8
9 import java.awt.event.ActionEvent;
10 import java.awt.event.KeyEvent;
11
12 import javax.swing.JPopupMenu;
13 import javax.swing.KeyStroke;
14
15 import org.asyrinx.joey.gui.swing.EntityListViewTable;
16
17 /***
18 * @author akima
19 */
20 public class DefaultEntityListViewTableActionKit
21 implements EntityListViewTableActionKit {
22
23 /***
24 *
25 */
26 public DefaultEntityListViewTableActionKit() {
27 super();
28 }
29
30
31
32
33 public EntityListViewTableAction[] getActions(EntityListViewTable listViewTable) {
34 return DEFAULT_ACTIONS;
35 }
36
37
38
39
40 public void preparePopupMenu(
41 EntityListViewTable listViewTable,
42 JPopupMenu popupMenu) {
43 final EntityListViewTableAction[] actions = getActions(listViewTable);
44 for (int i = 0; i < actions.length; i++) {
45 final EntityListViewTableAction action = actions[i];
46 if (action.isOnPopupMenu()) {
47 popupMenu.add(new ListViewMenuItem(listViewTable, action));
48
49 }
50 }
51
52 }
53
54 public static final EntityListViewTableAction SELECT = new Select();
55 public static final EntityListViewTableAction SHOW_DETAIL =
56 new ShowDetail();
57 public static final EntityListViewTableAction INSERT = new Insert();
58 public static final EntityListViewTableAction DELETE = new Delete();
59 public static final EntityListViewTableAction REFRESH = new Refresh();
60
61 private static final EntityListViewTableAction[] DEFAULT_ACTIONS =
62 new EntityListViewTableAction[] {
63 SELECT,
64 SHOW_DETAIL,
65 INSERT,
66 DELETE,
67 REFRESH };
68
69 public static class Select extends AbstractEntityListViewTableAction {
70 public String getName() {
71 return "選択";
72 }
73
74 public KeyStroke getAccelerator() {
75 return KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
76 }
77
78 public void actionPerformed(ActionEvent e) {
79 final EntityListViewTable listViewTable = getListViewComponent(e);
80 if (listViewTable.getInvoker() != null) {
81 listViewTable.notifySelectionToInvoker();
82 listViewTable.closeWinfow();
83 } else {
84 listViewTable.showDetail();
85 }
86 }
87
88
89
90 public boolean isEnabled(EntityListViewTable table) {
91 return table.getTable().getSelectedRow() > -1;
92 }
93
94 }
95
96 public static class ShowDetail extends AbstractEntityListViewTableAction {
97 public String getName() {
98 return "詳細表示";
99 }
100
101 public KeyStroke getAccelerator() {
102 return null;
103 }
104
105 public void actionPerformed(ActionEvent e) {
106 final EntityListViewTable listViewTable = getListViewComponent(e);
107 listViewTable.showDetail();
108 }
109
110
111
112 public boolean isEnabled(EntityListViewTable table) {
113 return table.getTable().getSelectedRow() > -1;
114 }
115 }
116
117 public static class Insert extends AbstractEntityListViewTableAction {
118 public String getName() {
119 return "新規追加";
120 }
121 public KeyStroke getAccelerator() {
122 return KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, 0);
123 }
124
125 public void actionPerformed(ActionEvent e) {
126 final EntityListViewTable listViewTable = getListViewComponent(e);
127 listViewTable.insertNewRow();
128 }
129 }
130
131 public static class Delete extends AbstractEntityListViewTableAction {
132 public String getName() {
133 return "削除";
134 }
135 public KeyStroke getAccelerator() {
136 return KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0);
137 }
138
139 public void actionPerformed(ActionEvent e) {
140 final EntityListViewTable listViewTable = getListViewComponent(e);
141 listViewTable.deleteSelections();
142 }
143
144
145
146 public boolean isEnabled(EntityListViewTable table) {
147 return table.getTable().getSelectedRow() > -1;
148 }
149 }
150
151 public static class Refresh extends AbstractEntityListViewTableAction {
152 public String getName() {
153 return "最新の情報に更新";
154 }
155 public KeyStroke getAccelerator() {
156 return KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0);
157 }
158
159 public void actionPerformed(ActionEvent e) {
160 final EntityListViewTable listViewTable = getListViewComponent(e);
161 listViewTable.refresh();
162 }
163
164
165
166 public boolean isEnabled(EntityListViewTable table) {
167 return table.getService() != null;
168 }
169 }
170
171 }