• R/O
  • SSH

JdbcAcsess2: Commit

全てを再実装したJdbcAcsessです。


Commit MetaInfo

Revisionfb10a3a267951a29dd7798fd653bc3b11f41f32a (tree)
Time2012-03-04 19:04:33
Authorshimakazuro
Commitershimakazuro

Log Message

mousewheelでfont変更

Change Summary

Incremental Difference

diff -r e366c0f78aa8 -r fb10a3a26795 src/jdbcacsess2/main/FontZoom.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdbcacsess2/main/FontZoom.java Sun Mar 04 19:04:33 2012 +0900
@@ -0,0 +1,91 @@
1+/*
2+ * Copyright 2012 Kazuhiro Shimada
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+package jdbcacsess2.main;
18+
19+import java.awt.Component;
20+import java.awt.Font;
21+import java.awt.event.KeyEvent;
22+import java.awt.event.KeyListener;
23+import java.awt.event.MouseWheelEvent;
24+import java.awt.event.MouseWheelListener;
25+
26+/**
27+ * @author sima
28+ *
29+ */
30+public class FontZoom {
31+
32+ static public void setMouseWheel(Component component) {
33+ component.addKeyListener(new MouseWheelControl());
34+ }
35+
36+ static private class MouseWheelControl implements KeyListener {
37+
38+ private boolean press = false;
39+
40+ @Override
41+ public void keyPressed(KeyEvent e) {
42+ if (press) {
43+ return;
44+ }
45+
46+ if (e.getKeyCode() == KeyEvent.VK_CONTROL) {
47+ e.getComponent().addMouseWheelListener(mouseWheelListener);
48+ press = true;
49+ }
50+ }
51+
52+ @Override
53+ public void keyReleased(KeyEvent e) {
54+ if (e.getKeyCode() == KeyEvent.VK_CONTROL) {
55+ e.getComponent().removeMouseWheelListener(mouseWheelListener);
56+ press = false;
57+ }
58+ }
59+
60+ @Override
61+ public void keyTyped(KeyEvent e) {
62+ // 押す&離すで発生するイベントなので使用しない
63+ }
64+
65+ private final MouseWheelListener mouseWheelListener = new MouseWheelListener() {
66+
67+ /*
68+ * (非 Javadoc)
69+ *
70+ * @see
71+ * java.awt.event.MouseWheelListener#mouseWheelMoved(java.awt.event.
72+ * MouseWheelEvent)
73+ */
74+ @Override
75+ public void mouseWheelMoved(MouseWheelEvent e) {
76+ if (!e.isControlDown()) {
77+ return;
78+ }
79+ Component c = e.getComponent();
80+
81+ Font font = c.getFont();
82+ float size = font.getSize() + e.getWheelRotation();
83+ if (4 < size && size < 30) {
84+ c.setFont(font.deriveFont(size));
85+ }
86+ e.consume();
87+ }
88+ };
89+ }
90+
91+}
diff -r e366c0f78aa8 -r fb10a3a26795 src/jdbcacsess2/main/FontZoomByMouseWheel.java
--- a/src/jdbcacsess2/main/FontZoomByMouseWheel.java Sun Mar 04 12:45:48 2012 +0900
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,91 +0,0 @@
1-/*
2- * Copyright 2012 Kazuhiro Shimada
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- */
16-
17-package jdbcacsess2.main;
18-
19-import java.awt.Component;
20-import java.awt.Font;
21-import java.awt.event.KeyEvent;
22-import java.awt.event.KeyListener;
23-import java.awt.event.MouseWheelEvent;
24-import java.awt.event.MouseWheelListener;
25-
26-/**
27- * @author sima
28- *
29- */
30-public class FontZoomByMouseWheel {
31-
32- private final Component component;
33- private boolean press = false;
34-
35- public FontZoomByMouseWheel(Component c) {
36- this.component = c;
37- component.addKeyListener(new KeyListener() {
38-
39- @Override
40- public void keyPressed(KeyEvent e) {
41- if (press) {
42- return;
43- }
44- if (e.getKeyCode() == KeyEvent.VK_CONTROL) {
45- component.addMouseWheelListener(mouseWheelListener);
46- press = true;
47- }
48- }
49-
50- @Override
51- public void keyReleased(KeyEvent e) {
52- if (e.getKeyCode() == KeyEvent.VK_CONTROL) {
53- component.removeMouseWheelListener(mouseWheelListener);
54- press = false;
55- }
56- }
57-
58- @Override
59- public void keyTyped(KeyEvent e) {
60- // 押す&離すで発生するイベントなので使用しない
61- }
62-
63- });
64-
65- }
66-
67- private final MouseWheelListener mouseWheelListener = new MouseWheelListener() {
68-
69- /*
70- * (非 Javadoc)
71- *
72- * @see
73- * java.awt.event.MouseWheelListener#mouseWheelMoved(java.awt.event.
74- * MouseWheelEvent)
75- */
76- @Override
77- public void mouseWheelMoved(MouseWheelEvent e) {
78- if (!e.isControlDown()) {
79- return;
80- }
81-
82- Font font = component.getFont();
83- float size = font.getSize() + e.getWheelRotation();
84- if (4 < size && size < 30) {
85- component.setFont(font.deriveFont(size));
86- }
87- e.consume();
88- }
89- };
90-
91-}
diff -r e366c0f78aa8 -r fb10a3a26795 src/jdbcacsess2/main/JPanelHIstory.java
--- a/src/jdbcacsess2/main/JPanelHIstory.java Sun Mar 04 12:45:48 2012 +0900
+++ b/src/jdbcacsess2/main/JPanelHIstory.java Sun Mar 04 19:04:33 2012 +0900
@@ -24,34 +24,34 @@
2424 import javax.swing.ListSelectionModel;
2525
2626 public class JPanelHIstory extends JPanel {
27- private static final long serialVersionUID = -3133659235665481170L;
28-
29- private final JTable table;
30-
31- /**
32- * Create the panel.
33- */
34- public JPanelHIstory() {
35- setLayout(new BorderLayout(0, 0));
36-
37- JScrollPane scrollPane = new JScrollPane();
38- add(scrollPane, BorderLayout.CENTER);
39-
40- table = new JTable();
27+ private static final long serialVersionUID = -3133659235665481170L;
4128
42- table.setAutoCreateRowSorter(true);
43- table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
44- table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
45- table.setCellSelectionEnabled(true);
46- scrollPane.setViewportView(table);
47- new FontZoomByMouseWheel(table);
29+ private final JTable table;
4830
49- JToolBar toolBar = new JToolBar();
50- add(toolBar, BorderLayout.NORTH);
31+ /**
32+ * Create the panel.
33+ */
34+ public JPanelHIstory() {
35+ setLayout(new BorderLayout(0, 0));
5136
52- }
37+ JScrollPane scrollPane = new JScrollPane();
38+ add(scrollPane, BorderLayout.CENTER);
5339
54- public JTable getTable() {
55- return table;
56- }
40+ table = new JTable();
41+
42+ table.setAutoCreateRowSorter(true);
43+ table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
44+ table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
45+ table.setCellSelectionEnabled(true);
46+ scrollPane.setViewportView(table);
47+ FontZoom.setMouseWheel(table);
48+
49+ JToolBar toolBar = new JToolBar();
50+ add(toolBar, BorderLayout.NORTH);
51+
52+ }
53+
54+ public JTable getTable() {
55+ return table;
56+ }
5757 }
diff -r e366c0f78aa8 -r fb10a3a26795 src/jdbcacsess2/main/JPanelSession.java
--- a/src/jdbcacsess2/main/JPanelSession.java Sun Mar 04 12:45:48 2012 +0900
+++ b/src/jdbcacsess2/main/JPanelSession.java Sun Mar 04 19:04:33 2012 +0900
@@ -257,7 +257,7 @@
257257 jxTreeTableDBObjects.setOpaque(true);
258258 jxTreeTableDBObjects.setHighlighters(HighlighterFactory.createSimpleStriping());
259259 jxTreeTableDBObjects.setComponentPopupMenu(getJPopupMenu());
260-
260+ FontZoom.setMouseWheel(jxTreeTableDBObjects);
261261 }
262262 return jxTreeTableDBObjects;
263263 }
diff -r e366c0f78aa8 -r fb10a3a26795 src/jdbcacsess2/main/JPanelSql.java
--- a/src/jdbcacsess2/main/JPanelSql.java Sun Mar 04 12:45:48 2012 +0900
+++ b/src/jdbcacsess2/main/JPanelSql.java Sun Mar 04 19:04:33 2012 +0900
@@ -59,804 +59,804 @@
5959 public class JPanelSql extends JPanel implements SqlExecutedListener, DataBaseConnectionListener,
6060 DataBaseTransactionListener {
6161
62- // -------------------------------------------------------------------------
63- // -------------------------------------------------------------------------
64- // -------------------------------------------------------------------------
65-
66- final static private int TABBEDPANEL_INDEX_DATA = 0;
67- final static private int TABBEDPANEL_INDEX_LOG = 1;
68- final static private int TABBEDPANEL_INDEX_RS = 2;
69-
70- private DataBaseConnection dataBaseConnection; // @jve:decl-index=0:
71-
72- /*
73- * (非 Javadoc)
74- *
75- * @see
76- * jdbcacsess2.sqlService.DataBaseConnectionListener#dataBaseConnectionOpened
77- * (jdbcacsess2.sqlService.DataBaseConnection)
78- */
79- @Override
80- public void dataBaseConnectionOpened(DataBaseConnection dataBaseConnection) {
81- this.dataBaseConnection = dataBaseConnection;
82-
83- SwingUtilities.invokeLater(new Runnable() {
84- @Override
85- public void run() {
86- writeGuiLog("connection opened");
87-
88- // dbコネクションの autocommit を、画面設定から取得して設定する。
89- boolean flg = getJCheckBoxAutoCommit().isSelected();
90- try {
91- getDataBaseConnection().setAutoCommit(flg);
92-
93- getJToggleButtonExecution().setEnabled(true);
94- getJButtonContinue().setEnabled(false);
95- getJCheckBoxAutoCommit().setEnabled(true);
96- getJToggleButtonConnection().setSelected(true);
97- } catch (Exception e) {
98- ShowDialog.errorMessage(e);
99- }
100- }
101- });
102-
103- }
104-
105- /*
106- * (非 Javadoc)
107- *
108- * @see
109- * jdbcacsess2.sqlService.DataBaseConnectionListener#dataBaseConnectionClosing
110- * ()
111- */
112- @Override
113- public void dataBaseConnectionClosing(DataBaseConnection dataBaseConnection) {
114- SwingUtilities.invokeLater(new Runnable() {
115- @Override
116- public void run() {
117- getJToggleButtonExecution().setEnabled(false);
118- getJButtonContinue().setEnabled(false);
119- getJCheckBoxAutoCommit().setEnabled(false);
120- getJButtonCommit().setEnabled(false);
121- getJButtonRollback().setEnabled(false);
122- getJToggleButtonConnection().setSelected(false);
123- }
124- });
125- }
126-
127- /*
128- * (非 Javadoc)
129- *
130- * @see
131- * jdbcacsess2.sqlService.DataBaseConnectionListener#dataBaseConnectionClosed
132- * ()
133- */
134- @Override
135- public void dataBaseConnectionClosed(DataBaseConnection dataBaseConnection) {
136- SwingUtilities.invokeLater(new Runnable() {
137- @Override
138- public void run() {
139- writeGuiLog("connection closed");
140- }
141- });
142- }
143-
144- /**
145- * @return dataBaseConnection
146- */
147- DataBaseConnection getDataBaseConnection() {
148- return dataBaseConnection;
149- }
150-
151- /*
152- * (非 Javadoc)
153- *
154- * @see
155- * jdbcacsess2.sqlService.DataBaseTransactionListener#autoCommitChange(boolean
156- * )
157- */
158- @Override
159- public void autoCommitChange(DataBaseConnection dataBaseConnection, final boolean autoCommit) {
160- SwingUtilities.invokeLater(new Runnable() {
161- @Override
162- public void run() {
163- writeGuiLog("autocommit[" + autoCommit + "]");
164- }
165- });
166- }
167-
168- /*
169- * (非 Javadoc)
170- *
171- * @see jdbcacsess2.sqlService.DataBaseTransactionListener#commitEnd()
172- */
173- @Override
174- public void commitEnd(DataBaseConnection dataBaseConnection) {
175- SwingUtilities.invokeLater(new Runnable() {
176- @Override
177- public void run() {
178- getJTabbedPaneResult().setSelectedIndex(TABBEDPANEL_INDEX_LOG);
179- writeGuiLog("commit end");
180- }
181- });
182- }
183-
184- /*
185- * (非 Javadoc)
186- *
187- * @see jdbcacsess2.sqlService.DataBaseTransactionListener#rollbackEnd()
188- */
189- @Override
190- public void rollbackEnd(DataBaseConnection dataBaseConnection) {
191- SwingUtilities.invokeLater(new Runnable() {
192- @Override
193- public void run() {
194- getJTabbedPaneResult().setSelectedIndex(TABBEDPANEL_INDEX_LOG);
195- writeGuiLog("rollback end");
196- }
197- });
198- }
199-
200- /**
201- * SQLパネルログへ出力
202- *
203- * @param message
204- * 出力文字列
205- */
206- private void writeGuiLog(String message) {
207- int i;
208- for (i = message.length(); 0 < i; i--) {
209- String s = message.substring(i - 1, i);
210- if (!s.equals("\n")) {
211- break;
212- }
213- }
214-
215- getJTextAreaLog().append(message.substring(0, i));
216- getJTextAreaLog().append("\n");
217- getJTextAreaLog().setCaretPosition(getJTextAreaLog().getText().length());
218- }
219-
220- //
221- /**
222- * 文字列を挿入します。改行文字が含まれている場合、インデントされます。
223- *
224- * @param str
225- * 挿入したい文字列
226- */
227- public void insertStringPreviousCaret(String str) {
228- if (str.equals("")) {
229- return;
230- }
231- rSyntaxTextAreaSql.replaceRange(addIndent(str),
232- rSyntaxTextAreaSql.getSelectionStart(),
233- rSyntaxTextAreaSql.getSelectionEnd());
234-
235- rSyntaxTextAreaSql.requestFocus();
236- }
237-
238- /**
239- * 改行文字があったら、現在行の左端からの位置をインデント文字数として、空白インデント処理する
240- *
241- * @param editot
242- * 挿入文字列
243- * @return インデント挿入後の文字列
244- */
245- private String addIndent(String editor) {
246-
247- // 先頭からのキャレット位置 - 現在行の先頭キャレット位置 で、現在行内でのキャレットオフセットを取得
248- int x = rSyntaxTextAreaSql.getCaretPosition() - rSyntaxTextAreaSql.getLineStartOffsetOfCurrentLine();
249-
250- // indent用に左空白文字列を作成する
251- StringBuilder indent = new StringBuilder();
252- for (int i = 0; i < x; i++) {
253- indent.append(' ');
254- }
255-
256- // indent後の文字列を作成
257- StringBuilder buf = new StringBuilder();
258- for (int i = 0; i < editor.length(); i++) {
259- char c = editor.charAt(i);
260- buf.append(c);
261- if (c == '\n') {
262- // 改行の後にはインデントを挿入する
263- buf.append(indent);
264- }
265- }
266- return buf.toString();
267- }
268-
269- /**
270- * 実行結果を受け取り、ボタンの制御を行う。
271- */
272- private SqlExecuteTask sqlExecuteTask; // @jve:decl-index=0:
273-
274- public void taskWakuUp() {
275- sqlExecuteTask.taskWakeUp();
276- }
277-
278- public void taskCancel() {
279- sqlExecuteTask.taskCancel();
280- }
281-
282- /**
283- *
284- */
285- private TableColumnFit resultsTableColumnFit;
286- /**
287- * 実行を開始したSQL情報
288- */
289- private SqlExecuteSentence sqlExecuteSentenceLast; // @jve:decl-index=0:
290- /**
291- * 例外発生時に処理を継続するか
292- */
293- private boolean exceptionContinue;
294- /*
295- * (非 Javadoc)
296- *
297- * @see
298- * jdbcacsess2.sqlService.SqlExecutedListener#taskAccept(jdbcacsess2.sqlService
299- * .SqlExecuteTask)
300- */
301- @Override
302- public void taskAccept(SqlExecuteTask sqlExecuteTask) {
303- this.sqlExecuteTask = sqlExecuteTask;
304- exceptionContinue = false;
305-
306- SwingUtilities.invokeLater(new Runnable() {
307- public void run() {
308- getJToggleButtonExecution().setEnabled(false);
309- getJToggleButtonExecution().setSelected(true);
310- getJButtonContinue().setEnabled(false);
311- getJToggleButtonConnection().setEnabled(false);
312- }
313- });
314- }
315-
316- /*
317- * (非 Javadoc)
318- *
319- * @see
320- * jdbcacsess2.sqlService.SqlExecutedListener#executBegin(jdbcacsess2.sqlService
321- * .SqlExecuteSentencies.SqlExecuteSentence)
322- */
323- @Override
324- public void executBegin(final SqlExecuteSentence sqlExecuteSentence) {
325- sqlExecuteSentenceLast = sqlExecuteSentence;
326-
327- SwingUtilities.invokeLater(new Runnable() {
328- public void run() {
329-
330- if (sqlExecuteSentence.getSqlCommand().toUpperCase().equals("SELECT")) {
331- // カラム自動調整を有効にする
332- resultsTableColumnFit.setEnableAutoFit(true);
333-
334- getJTabbedPaneResult().setSelectedIndex(TABBEDPANEL_INDEX_DATA);
335- } else {
336- getJTabbedPaneResult().setSelectedIndex(TABBEDPANEL_INDEX_LOG);
337- }
338-
339- writeGuiLog("\nstart sql\n"
340- + sqlExecuteSentence.getSqlSentence());
341- }
342- });
343- }
344-
345- /*
346- * (非 Javadoc)
347- *
348- * @see jdbcacsess2.sqlService.SqlExecutedListener#executNormalFinish(int)
349- */
350- @Override
351- public void executNormalFinish(final int rowCnt) {
352- // sqlExecuteSentenceLast は、SwingUtilities.invokeLaterの外から
353- // どんどん更新されるので、画面出力に必要な情報はEDTキューイング前に作成しておく
354- final String counrMessage = countmsg();
355-
356- SwingUtilities.invokeLater(new Runnable() {
357- public void run() {
358- getJToggleButtonExecution().setEnabled(true);
359- writeGuiLog("normal end sql" + counrMessage + " "
360- + Integer.toString(rowCnt) + " row " + sqlExecuteTask.getExecutionTime()
361- + "ms");
362- }
363- });
364- }
365-
366- /*
367- * (非 Javadoc)
368- *
369- * @see
370- * jdbcacsess2.sqlService.SqlExecutedListener#executeException(java.lang
371- * .Throwable)
372- */
373- @Override
374- public void executeException(final Throwable t) {
375- // sqlExecuteSentenceLast は、SwingUtilities.invokeLaterの外から
376- // どんどん更新されるので、画面出力に必要な情報はEDTキューイング前に作成しておく
377- final String counrMessage = countmsg();
378-
379- SwingUtilities.invokeLater(new Runnable() {
380- public void run() {
381- getJToggleButtonExecution().setEnabled(true);
382- writeGuiLog("abnormal end " + counrMessage + "\n "
383- + t.getLocalizedMessage());
384- }
385- });
386- ShowDialog.errorMessage(t);
387-
388- int zan = sqlExecuteTask.getCnt() - sqlExecuteSentenceLast.getSentenceCount();
389- if (!exceptionContinue && zan > 0) {
390- try {
391- SwingUtilities.invokeAndWait(new Runnable() {
392- @Override
393- public void run() {
394- Object[] options = { "はい、後続のSQL実行を中断", "いいえ、以降の全エラーを無視" };
395- int n = JOptionPane.showOptionDialog(null,
396- "残りのSQL実行は中断しますか?",
397- "まだ実行予定のSQLが残ってます",
398- JOptionPane.YES_NO_OPTION,
399- JOptionPane.QUESTION_MESSAGE,
400- null,
401- options,
402- options[0]);
403- if (n == JOptionPane.NO_OPTION) {
404- exceptionContinue = true;
405- } else {
406- taskCancel();
407- }
408- }
409- });
410- } catch (InvocationTargetException e) {
411- ShowDialog.errorMessage(e);
412- e.printStackTrace();
413- } catch (InterruptedException e) {
414- Thread.currentThread().interrupt();
415- }
416- }
417- }
418-
419- private String countmsg() {
420- return "[" + sqlExecuteSentenceLast.getSentenceCount() + "/" + sqlExecuteTask.getCnt() + "]";
421- }
422-
423- /*
424- * (非 Javadoc)
425- *
426- * @see
427- * jdbcacsess2.sqlService.SqlExecutedListener#resultHeader(java.util.List)
428- */
429- @Override
430- public void resultHeader(final List<ColumnAttributeResult> header) {
431- final PropertyResultSetTableModel dataModel = new PropertyResultSetTableModel(header);
432- SwingUtilities.invokeLater(new Runnable() {
433- @Override
434- public void run() {
435- getJTableResultSet().setModel(dataModel);
436- }
437- });
438- }
439-
440- /*
441- * (非 Javadoc)
442- *
443- * @see jdbcacsess2.sqlService.SqlExecutedListener#resultDetail(int,
444- * java.util.List)
445- */
446- @Override
447- public void resultDetail(int seq, List<Object> detail) {
448- }
62+ // -------------------------------------------------------------------------
63+ // -------------------------------------------------------------------------
64+ // -------------------------------------------------------------------------
44965
450- /*
451- * (非 Javadoc)
452- *
453- * @see jdbcacsess2.sqlService.SqlExecutedListener#statusContinue(int)
454- */
455- @Override
456- public void statusContinue(final int seqNo) {
457- SwingUtilities.invokeLater(new Runnable() {
458- public void run() {
459- getJToggleButtonExecution().setEnabled(true);
460- getJButtonContinue().setEnabled(true);
461- getJToggleButtonConnection().setEnabled(false);
462-
463- writeGuiLog("data cotinue now " + Integer.toString(seqNo) + " row");
464- }
465- });
466- }
467-
468- /*
469- * (非 Javadoc)
470- *
471- * @see jdbcacsess2.sqlService.SqlExecutedListener#executeAllEnd()
472- */
473- @Override
474- public void executeAllEnd() {
475- SwingUtilities.invokeLater(new Runnable() {
476- public void run() {
477- getJToggleButtonExecution().setEnabled(true);
478- getJToggleButtonExecution().setSelected(false);
479- getJButtonContinue().setEnabled(false);
480- getJToggleButtonConnection().setEnabled(true);
481- }
482- });
483- }
484-
485- // -------------------------------------------------------------------------
486- // -------------------------------------------------------------------------
487- // -------------------------------------------------------------------------
488-
489- private static final long serialVersionUID = 1L;
490- private JSplitPane jSplitPaneTable = null;
491- private RTextScrollPane rTextScrollPaneSql = null;
492- private RSyntaxTextArea rSyntaxTextAreaSql = null;
493- private JTabbedPane jTabbedPaneResult = null;
494- private JScrollPane jScrollPane = null;
495- private JTable jTable = null;
496- private JScrollPane jScrollPaneLog = null;
497- private JTextArea jTextAreaLog = null;
498- private JToolBar jJToolBarBar = null;
499- private JButton jButtonContinue = null;
500- private JCheckBox jCheckBoxAutoCommit = null;
501- private JButton jButtonCommit = null;
502- private JButton jButtonRollback = null;
503-
504- private JToggleButton jToggleButtonExecution = null;
505- private JToggleButton jToggleButtonConnection = null;
506- private JScrollPane jScrollPane1 = null;
507- private JTable jTableResultSet = null;
508- private JComboBox<SentenceSeparator> jComboBoxSentenceSeparator = null;
509-
510- /**
511- * This is the default constructor
512- */
513- public JPanelSql() {
514- super();
515- initialize();
516- }
517-
518- /**
519- * This method initializes this
520- *
521- * @return void
522- */
523- private void initialize() {
524- this.setLayout(new BorderLayout());
525- this.add(getJSplitPaneTable(), java.awt.BorderLayout.CENTER);
526- this.add(getJJToolBarBar(), java.awt.BorderLayout.NORTH);
527- }
528-
529- /**
530- * This method initializes jSplitPaneTable
531- *
532- * @return javax.swing.JSplitPane
533- */
534- JSplitPane getJSplitPaneTable() {
535- if (jSplitPaneTable == null) {
536- jSplitPaneTable = new JSplitPane();
537- jSplitPaneTable.setOrientation(JSplitPane.VERTICAL_SPLIT);
538- jSplitPaneTable.setDividerLocation(200);
539- jSplitPaneTable.setDividerSize(10);
540- jSplitPaneTable.setOneTouchExpandable(true);
541- jSplitPaneTable.setTopComponent(getRTextScrollPaneSql());
542- jSplitPaneTable.setBottomComponent(getJTabbedPaneResult());
543- }
544- return jSplitPaneTable;
545- }
546-
547- /**
548- * This method initializes jScrollPane1
549- *
550- * @return javax.swing.JScrollPane
551- */
552- private RTextScrollPane getRTextScrollPaneSql() {
553- if (rTextScrollPaneSql == null) {
554- rTextScrollPaneSql = new RTextScrollPane();
555- rTextScrollPaneSql.setViewportView(getRSyntaxTextAreaSql());
556- }
557- return rTextScrollPaneSql;
558- }
559-
560- /**
561- * This method initializes jEditorPaneSql
562- *
563- * @return javax.swing.JEditorPane
564- */
565- RSyntaxTextArea getRSyntaxTextAreaSql() {
566- if (rSyntaxTextAreaSql == null) {
567- rSyntaxTextAreaSql = new RSyntaxTextArea();
568- rSyntaxTextAreaSql.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_SQL);
569- rSyntaxTextAreaSql.setAntiAliasingEnabled(true);
570- new FontZoomByMouseWheel(rSyntaxTextAreaSql);
571- }
572- return rSyntaxTextAreaSql;
573- }
574-
575- /**
576- * This method initializes jTabbedPaneResult
577- *
578- * @return javax.swing.JTabbedPane
579- */
580- JTabbedPane getJTabbedPaneResult() {
581- if (jTabbedPaneResult == null) {
582- jTabbedPaneResult = new JTabbedPane();
583- jTabbedPaneResult.setTabPlacement(SwingConstants.LEFT);
584- jTabbedPaneResult.add(getJScrollPane(), "data", TABBEDPANEL_INDEX_DATA);
585- jTabbedPaneResult.add(getJScrollPaneLog(), "log", TABBEDPANEL_INDEX_LOG);
586- jTabbedPaneResult.add(getJScrollPane1(), "RS", TABBEDPANEL_INDEX_RS);
587- }
588- return jTabbedPaneResult;
589- }
590-
591- /**
592- * This method initializes jScrollPane
593- *
594- * @return javax.swing.JScrollPane
595- */
596- private JScrollPane getJScrollPane() {
597- if (jScrollPane == null) {
598- jScrollPane = new JScrollPane();
599- jScrollPane.setViewportView(getJTable());
600- }
601- return jScrollPane;
602- }
603-
604- /**
605- * This method initializes jTable
606- *
607- * @return javax.swing.JTable
608- */
609- JTable getJTable() {
610- if (jTable == null) {
611- jTable = new JTable();
612- jTable.setIntercellSpacing(new Dimension(3, 2));
613- jTable.setAutoCreateRowSorter(true);
614- jTable.setCellSelectionEnabled(true);
615- jTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
616- Font font = jTable.getFont();
617- jTable.setFont(new Font(Font.MONOSPACED, font.getStyle(), font.getSize()));
618-
619- new FontZoomByMouseWheel(jTable);
620- resultsTableColumnFit = new TableColumnFit(jTable);
621- jTable.setModel(new ResultsTableModel());
622- }
623- return jTable;
624- }
625-
626- /**
627- * This method initializes jJToolBarBar
628- *
629- * @return javax.swing.JToolBar
630- */
631- private JToolBar getJJToolBarBar() {
632- if (jJToolBarBar == null) {
633- jJToolBarBar = new JToolBar();
634- jJToolBarBar.add(getJToggleButtonExecution());
635- jJToolBarBar.add(getJButtonContinue());
636- jJToolBarBar.add(getJCheckBoxAutoCommit());
637- jJToolBarBar.add(getJButtonCommit());
638- jJToolBarBar.add(getJButtonRollback());
639- jJToolBarBar.add(getJToggleButtonConnection());
640- jJToolBarBar.add(getJComboBoxSentenceSeparator());
641- }
642- return jJToolBarBar;
643- }
66+ final static private int TABBEDPANEL_INDEX_DATA = 0;
67+ final static private int TABBEDPANEL_INDEX_LOG = 1;
68+ final static private int TABBEDPANEL_INDEX_RS = 2;
64469
645- /**
646- * This method initializes jToggleButtonExecution
647- *
648- * @return javax.swing.JButton
649- */
650- JToggleButton getJToggleButtonExecution() {
651- if (jToggleButtonExecution == null) {
652- jToggleButtonExecution = new JToggleButton(IconImage.EXECUTE.getValue(), false);
653- jToggleButtonExecution.setText("Execute");
654- jToggleButtonExecution.setEnabled(false);
655- jToggleButtonExecution.addChangeListener(new ChangeListener() {
656- // pressedicon selectedicon では、うまく制御できないので、自前で制御する
657- @Override
658- public void stateChanged(ChangeEvent e) {
659- JToggleButton b = (JToggleButton) e.getSource();
660- if (b.isSelected()) {
661- b.setIcon(IconImage.STOP.getValue());
662- } else {
663- b.setIcon(IconImage.EXECUTE.getValue());
664- }
665- }
666- });
667- }
668- return jToggleButtonExecution;
669- }
670-
671- /**
672- * This method initializes jButtonContinue
673- *
674- * @return javax.swing.JButton
675- */
676- JButton getJButtonContinue() {
677- if (jButtonContinue == null) {
678- jButtonContinue = new JButton(IconImage.GO_DOWN.getValue());
679- jButtonContinue.setEnabled(false);
680- jButtonContinue.setText("Continue");
681- }
682- return jButtonContinue;
683- }
684-
685- /**
686- * This method initializes jCheckBoxAutoCommit
687- *
688- * @return javax.swing.JCheckBox
689- */
690- JCheckBox getJCheckBoxAutoCommit() {
691- if (jCheckBoxAutoCommit == null) {
692- jCheckBoxAutoCommit = new JCheckBox();
693- jCheckBoxAutoCommit.setText("AutoCommit");
694- jCheckBoxAutoCommit.setEnabled(false);
695- jCheckBoxAutoCommit.addItemListener(new ItemListener() {
696- @Override
697- public void itemStateChanged(ItemEvent e) {
698- boolean flg = jCheckBoxAutoCommit.isSelected();
699- getJButtonCommit().setEnabled(!flg);
700- getJButtonRollback().setEnabled(!flg);
701- Jdbcacsess2.logger.fine("autocomit:" + flg);
702-
703- if (getDataBaseConnection() == null) {
704- return;
705- }
706- try {
707- getDataBaseConnection().setAutoCommit(flg);
708- } catch (Exception ex) {
709- ShowDialog.errorMessage(ex);
710- }
711- }
712- });
713- jCheckBoxAutoCommit.setSelected(true);
714- }
715- return jCheckBoxAutoCommit;
716- }
717-
718- /**
719- * This method initializes jButtonCommit
720- *
721- * @return javax.swing.JButton
722- */
723- JButton getJButtonCommit() {
724- if (jButtonCommit == null) {
725- jButtonCommit = new JButton(IconImage.COMMIT.getValue());
726- jButtonCommit.setText("Commit");
727- jButtonCommit.setEnabled(false);
728- }
729- return jButtonCommit;
730- }
731-
732- /**
733- * This method initializes jButtonRollback
734- *
735- * @return javax.swing.JButton
736- */
737- JButton getJButtonRollback() {
738- if (jButtonRollback == null) {
739- jButtonRollback = new JButton(IconImage.ROLLBACK.getValue());
740- jButtonRollback.setText("Rollback");
741- jButtonRollback.setEnabled(false);
742- }
743- return jButtonRollback;
744- }
70+ private DataBaseConnection dataBaseConnection; // @jve:decl-index=0:
74571
746- /**
747- * This method initializes jScrollPaneLog
748- *
749- * @return javax.swing.JScrollPane
750- */
751- private JScrollPane getJScrollPaneLog() {
752- if (jScrollPaneLog == null) {
753- jScrollPaneLog = new JScrollPane();
754- jScrollPaneLog.setViewportView(getJTextAreaLog());
755- }
756- return jScrollPaneLog;
757- }
758-
759- /**
760- * This method initializes jTextAreaLog
761- *
762- * @return javax.swing.JTextArea
763- */
764- JTextArea getJTextAreaLog() {
765- if (jTextAreaLog == null) {
766- jTextAreaLog = new JTextArea();
767- jTextAreaLog.setEditable(false);
768- jTextAreaLog.setLineWrap(false);
769- jTextAreaLog.setOpaque(false);
770- }
771- return jTextAreaLog;
772- }
773-
774- /**
775- * This method initializes jToggleButtonConnection
776- *
777- * @return javax.swing.JToggleButton
778- */
779- JToggleButton getJToggleButtonConnection() {
780- if (jToggleButtonConnection == null) {
781- jToggleButtonConnection = new JToggleButton(IconImage.DISCONNECT.getValue());
782- jToggleButtonConnection.setText("session");
783- jToggleButtonConnection.addChangeListener(new ChangeListener() {
784- // pressedicon selectedicon では、うまく制御できないので、自前で制御する
785- @Override
786- public void stateChanged(ChangeEvent e) {
787- JToggleButton b = (JToggleButton) e.getSource();
788- if (b.isSelected()) {
789- b.setIcon(IconImage.CONNECT.getValue());
790- } else {
791- b.setIcon(IconImage.DISCONNECT.getValue());
792- }
793- }
794- });
795- }
796- return jToggleButtonConnection;
797- }
72+ /*
73+ * (非 Javadoc)
74+ *
75+ * @see
76+ * jdbcacsess2.sqlService.DataBaseConnectionListener#dataBaseConnectionOpened
77+ * (jdbcacsess2.sqlService.DataBaseConnection)
78+ */
79+ @Override
80+ public void dataBaseConnectionOpened(DataBaseConnection dataBaseConnection) {
81+ this.dataBaseConnection = dataBaseConnection;
79882
799- /**
800- * This method initializes jScrollPane1
801- *
802- * @return javax.swing.JScrollPane
803- */
804- private JScrollPane getJScrollPane1() {
805- if (jScrollPane1 == null) {
806- jScrollPane1 = new JScrollPane();
807- jScrollPane1.setViewportView(getJTableResultSet());
808- }
809- return jScrollPane1;
810- }
811-
812- /**
813- * This method initializes jTableResultSet
814- *
815- * @return javax.swing.JTable
816- */
817- private JTable getJTableResultSet() {
818- if (jTableResultSet == null) {
819- jTableResultSet = new JmyTable();
820- }
821- return jTableResultSet;
822- }
83+ SwingUtilities.invokeLater(new Runnable() {
84+ @Override
85+ public void run() {
86+ writeGuiLog("connection opened");
82387
824- /**
825- * This method initializes jComboBoxSentenceSeparator
826- *
827- * @return javax.swing.JComboBox
828- */
829- JComboBox<SentenceSeparator> getJComboBoxSentenceSeparator() {
830- if (jComboBoxSentenceSeparator == null) {
831- jComboBoxSentenceSeparator = new JComboBox<SentenceSeparator>();
832- jComboBoxSentenceSeparator.setEditable(true);
833- jComboBoxSentenceSeparator.addItem(new SentenceSeparator(";", ";\\s*\\n?"));
834- jComboBoxSentenceSeparator.addItem(new SentenceSeparator("/", "\\n+\\s*/\\s*\\n?"));
835- jComboBoxSentenceSeparator.addItem(new SentenceSeparator("//", "\\n+?\\s*//\\s*\\n?"));
836- jComboBoxSentenceSeparator.addItem(new SentenceSeparator("GO", "\\n+\\s*[Gg][Oo]\\s*\\n?"));
837- }
838- return jComboBoxSentenceSeparator;
839- }
88+ // dbコネクションの autocommit を、画面設定から取得して設定する。
89+ boolean flg = getJCheckBoxAutoCommit().isSelected();
90+ try {
91+ getDataBaseConnection().setAutoCommit(flg);
84092
841- public static class SentenceSeparator {
842- private final String guiVal;
843- private final String regVal;
844-
845- SentenceSeparator(String guiVal, String regVal) {
846- this.guiVal = guiVal;
847- this.regVal = regVal;
848- }
93+ getJToggleButtonExecution().setEnabled(true);
94+ getJButtonContinue().setEnabled(false);
95+ getJCheckBoxAutoCommit().setEnabled(true);
96+ getJToggleButtonConnection().setSelected(true);
97+ } catch (Exception e) {
98+ ShowDialog.errorMessage(e);
99+ }
100+ }
101+ });
849102
850- @Override
851- public String toString() {
852- return guiVal;
853- }
103+ }
854104
855- /**
856- * @return regVal
857- */
858- public String getRegVal() {
859- return regVal;
860- }
861- }
105+ /*
106+ * (非 Javadoc)
107+ *
108+ * @see
109+ * jdbcacsess2.sqlService.DataBaseConnectionListener#dataBaseConnectionClosing
110+ * ()
111+ */
112+ @Override
113+ public void dataBaseConnectionClosing(DataBaseConnection dataBaseConnection) {
114+ SwingUtilities.invokeLater(new Runnable() {
115+ @Override
116+ public void run() {
117+ getJToggleButtonExecution().setEnabled(false);
118+ getJButtonContinue().setEnabled(false);
119+ getJCheckBoxAutoCommit().setEnabled(false);
120+ getJButtonCommit().setEnabled(false);
121+ getJButtonRollback().setEnabled(false);
122+ getJToggleButtonConnection().setSelected(false);
123+ }
124+ });
125+ }
126+
127+ /*
128+ * (非 Javadoc)
129+ *
130+ * @see
131+ * jdbcacsess2.sqlService.DataBaseConnectionListener#dataBaseConnectionClosed
132+ * ()
133+ */
134+ @Override
135+ public void dataBaseConnectionClosed(DataBaseConnection dataBaseConnection) {
136+ SwingUtilities.invokeLater(new Runnable() {
137+ @Override
138+ public void run() {
139+ writeGuiLog("connection closed");
140+ }
141+ });
142+ }
143+
144+ /**
145+ * @return dataBaseConnection
146+ */
147+ DataBaseConnection getDataBaseConnection() {
148+ return dataBaseConnection;
149+ }
150+
151+ /*
152+ * (非 Javadoc)
153+ *
154+ * @see
155+ * jdbcacsess2.sqlService.DataBaseTransactionListener#autoCommitChange(boolean
156+ * )
157+ */
158+ @Override
159+ public void autoCommitChange(DataBaseConnection dataBaseConnection, final boolean autoCommit) {
160+ SwingUtilities.invokeLater(new Runnable() {
161+ @Override
162+ public void run() {
163+ writeGuiLog("autocommit[" + autoCommit + "]");
164+ }
165+ });
166+ }
167+
168+ /*
169+ * (非 Javadoc)
170+ *
171+ * @see jdbcacsess2.sqlService.DataBaseTransactionListener#commitEnd()
172+ */
173+ @Override
174+ public void commitEnd(DataBaseConnection dataBaseConnection) {
175+ SwingUtilities.invokeLater(new Runnable() {
176+ @Override
177+ public void run() {
178+ getJTabbedPaneResult().setSelectedIndex(TABBEDPANEL_INDEX_LOG);
179+ writeGuiLog("commit end");
180+ }
181+ });
182+ }
183+
184+ /*
185+ * (非 Javadoc)
186+ *
187+ * @see jdbcacsess2.sqlService.DataBaseTransactionListener#rollbackEnd()
188+ */
189+ @Override
190+ public void rollbackEnd(DataBaseConnection dataBaseConnection) {
191+ SwingUtilities.invokeLater(new Runnable() {
192+ @Override
193+ public void run() {
194+ getJTabbedPaneResult().setSelectedIndex(TABBEDPANEL_INDEX_LOG);
195+ writeGuiLog("rollback end");
196+ }
197+ });
198+ }
199+
200+ /**
201+ * SQLパネルログへ出力
202+ *
203+ * @param message
204+ * 出力文字列
205+ */
206+ private void writeGuiLog(String message) {
207+ int i;
208+ for (i = message.length(); 0 < i; i--) {
209+ String s = message.substring(i - 1, i);
210+ if (!s.equals("\n")) {
211+ break;
212+ }
213+ }
214+
215+ getJTextAreaLog().append(message.substring(0, i));
216+ getJTextAreaLog().append("\n");
217+ getJTextAreaLog().setCaretPosition(getJTextAreaLog().getText().length());
218+ }
219+
220+ //
221+ /**
222+ * 文字列を挿入します。改行文字が含まれている場合、インデントされます。
223+ *
224+ * @param str
225+ * 挿入したい文字列
226+ */
227+ public void insertStringPreviousCaret(String str) {
228+ if (str.equals("")) {
229+ return;
230+ }
231+ rSyntaxTextAreaSql.replaceRange(addIndent(str),
232+ rSyntaxTextAreaSql.getSelectionStart(),
233+ rSyntaxTextAreaSql.getSelectionEnd());
234+
235+ rSyntaxTextAreaSql.requestFocus();
236+ }
237+
238+ /**
239+ * 改行文字があったら、現在行の左端からの位置をインデント文字数として、空白インデント処理する
240+ *
241+ * @param editot
242+ * 挿入文字列
243+ * @return インデント挿入後の文字列
244+ */
245+ private String addIndent(String editor) {
246+
247+ // 先頭からのキャレット位置 - 現在行の先頭キャレット位置 で、現在行内でのキャレットオフセットを取得
248+ int x = rSyntaxTextAreaSql.getCaretPosition() - rSyntaxTextAreaSql.getLineStartOffsetOfCurrentLine();
249+
250+ // indent用に左空白文字列を作成する
251+ StringBuilder indent = new StringBuilder();
252+ for (int i = 0; i < x; i++) {
253+ indent.append(' ');
254+ }
255+
256+ // indent後の文字列を作成
257+ StringBuilder buf = new StringBuilder();
258+ for (int i = 0; i < editor.length(); i++) {
259+ char c = editor.charAt(i);
260+ buf.append(c);
261+ if (c == '\n') {
262+ // 改行の後にはインデントを挿入する
263+ buf.append(indent);
264+ }
265+ }
266+ return buf.toString();
267+ }
268+
269+ /**
270+ * 実行結果を受け取り、ボタンの制御を行う。
271+ */
272+ private SqlExecuteTask sqlExecuteTask; // @jve:decl-index=0:
273+
274+ public void taskWakuUp() {
275+ sqlExecuteTask.taskWakeUp();
276+ }
277+
278+ public void taskCancel() {
279+ sqlExecuteTask.taskCancel();
280+ }
281+
282+ /**
283+ *
284+ */
285+ private TableColumnFit resultsTableColumnFit;
286+ /**
287+ * 実行を開始したSQL情報
288+ */
289+ private SqlExecuteSentence sqlExecuteSentenceLast; // @jve:decl-index=0:
290+ /**
291+ * 例外発生時に処理を継続するか
292+ */
293+ private boolean exceptionContinue;
294+ /*
295+ * (非 Javadoc)
296+ *
297+ * @see
298+ * jdbcacsess2.sqlService.SqlExecutedListener#taskAccept(jdbcacsess2.sqlService
299+ * .SqlExecuteTask)
300+ */
301+ @Override
302+ public void taskAccept(SqlExecuteTask sqlExecuteTask) {
303+ this.sqlExecuteTask = sqlExecuteTask;
304+ exceptionContinue = false;
305+
306+ SwingUtilities.invokeLater(new Runnable() {
307+ public void run() {
308+ getJToggleButtonExecution().setEnabled(false);
309+ getJToggleButtonExecution().setSelected(true);
310+ getJButtonContinue().setEnabled(false);
311+ getJToggleButtonConnection().setEnabled(false);
312+ }
313+ });
314+ }
315+
316+ /*
317+ * (非 Javadoc)
318+ *
319+ * @see
320+ * jdbcacsess2.sqlService.SqlExecutedListener#executBegin(jdbcacsess2.sqlService
321+ * .SqlExecuteSentencies.SqlExecuteSentence)
322+ */
323+ @Override
324+ public void executBegin(final SqlExecuteSentence sqlExecuteSentence) {
325+ sqlExecuteSentenceLast = sqlExecuteSentence;
326+
327+ SwingUtilities.invokeLater(new Runnable() {
328+ public void run() {
329+
330+ if (sqlExecuteSentence.getSqlCommand().toUpperCase().equals("SELECT")) {
331+ // カラム自動調整を有効にする
332+ resultsTableColumnFit.setEnableAutoFit(true);
333+
334+ getJTabbedPaneResult().setSelectedIndex(TABBEDPANEL_INDEX_DATA);
335+ } else {
336+ getJTabbedPaneResult().setSelectedIndex(TABBEDPANEL_INDEX_LOG);
337+ }
338+
339+ writeGuiLog("\nstart sql\n"
340+ + sqlExecuteSentence.getSqlSentence());
341+ }
342+ });
343+ }
344+
345+ /*
346+ * (非 Javadoc)
347+ *
348+ * @see jdbcacsess2.sqlService.SqlExecutedListener#executNormalFinish(int)
349+ */
350+ @Override
351+ public void executNormalFinish(final int rowCnt) {
352+ // sqlExecuteSentenceLast は、SwingUtilities.invokeLaterの外から
353+ // どんどん更新されるので、画面出力に必要な情報はEDTキューイング前に作成しておく
354+ final String counrMessage = countmsg();
355+
356+ SwingUtilities.invokeLater(new Runnable() {
357+ public void run() {
358+ getJToggleButtonExecution().setEnabled(true);
359+ writeGuiLog("normal end sql" + counrMessage + " "
360+ + Integer.toString(rowCnt) + " row " + sqlExecuteTask.getExecutionTime()
361+ + "ms");
362+ }
363+ });
364+ }
365+
366+ /*
367+ * (非 Javadoc)
368+ *
369+ * @see
370+ * jdbcacsess2.sqlService.SqlExecutedListener#executeException(java.lang
371+ * .Throwable)
372+ */
373+ @Override
374+ public void executeException(final Throwable t) {
375+ // sqlExecuteSentenceLast は、SwingUtilities.invokeLaterの外から
376+ // どんどん更新されるので、画面出力に必要な情報はEDTキューイング前に作成しておく
377+ final String counrMessage = countmsg();
378+
379+ SwingUtilities.invokeLater(new Runnable() {
380+ public void run() {
381+ getJToggleButtonExecution().setEnabled(true);
382+ writeGuiLog("abnormal end " + counrMessage + "\n "
383+ + t.getLocalizedMessage());
384+ }
385+ });
386+ ShowDialog.errorMessage(t);
387+
388+ int zan = sqlExecuteTask.getCnt() - sqlExecuteSentenceLast.getSentenceCount();
389+ if (!exceptionContinue && zan > 0) {
390+ try {
391+ SwingUtilities.invokeAndWait(new Runnable() {
392+ @Override
393+ public void run() {
394+ Object[] options = { "はい、後続のSQL実行を中断", "いいえ、以降の全エラーを無視" };
395+ int n = JOptionPane.showOptionDialog(null,
396+ "残りのSQL実行は中断しますか?",
397+ "まだ実行予定のSQLが残ってます",
398+ JOptionPane.YES_NO_OPTION,
399+ JOptionPane.QUESTION_MESSAGE,
400+ null,
401+ options,
402+ options[0]);
403+ if (n == JOptionPane.NO_OPTION) {
404+ exceptionContinue = true;
405+ } else {
406+ taskCancel();
407+ }
408+ }
409+ });
410+ } catch (InvocationTargetException e) {
411+ ShowDialog.errorMessage(e);
412+ e.printStackTrace();
413+ } catch (InterruptedException e) {
414+ Thread.currentThread().interrupt();
415+ }
416+ }
417+ }
418+
419+ private String countmsg() {
420+ return "[" + sqlExecuteSentenceLast.getSentenceCount() + "/" + sqlExecuteTask.getCnt() + "]";
421+ }
422+
423+ /*
424+ * (非 Javadoc)
425+ *
426+ * @see
427+ * jdbcacsess2.sqlService.SqlExecutedListener#resultHeader(java.util.List)
428+ */
429+ @Override
430+ public void resultHeader(final List<ColumnAttributeResult> header) {
431+ final PropertyResultSetTableModel dataModel = new PropertyResultSetTableModel(header);
432+ SwingUtilities.invokeLater(new Runnable() {
433+ @Override
434+ public void run() {
435+ getJTableResultSet().setModel(dataModel);
436+ }
437+ });
438+ }
439+
440+ /*
441+ * (非 Javadoc)
442+ *
443+ * @see jdbcacsess2.sqlService.SqlExecutedListener#resultDetail(int,
444+ * java.util.List)
445+ */
446+ @Override
447+ public void resultDetail(int seq, List<Object> detail) {
448+ }
449+
450+ /*
451+ * (非 Javadoc)
452+ *
453+ * @see jdbcacsess2.sqlService.SqlExecutedListener#statusContinue(int)
454+ */
455+ @Override
456+ public void statusContinue(final int seqNo) {
457+ SwingUtilities.invokeLater(new Runnable() {
458+ public void run() {
459+ getJToggleButtonExecution().setEnabled(true);
460+ getJButtonContinue().setEnabled(true);
461+ getJToggleButtonConnection().setEnabled(false);
462+
463+ writeGuiLog("data cotinue now " + Integer.toString(seqNo) + " row");
464+ }
465+ });
466+ }
467+
468+ /*
469+ * (非 Javadoc)
470+ *
471+ * @see jdbcacsess2.sqlService.SqlExecutedListener#executeAllEnd()
472+ */
473+ @Override
474+ public void executeAllEnd() {
475+ SwingUtilities.invokeLater(new Runnable() {
476+ public void run() {
477+ getJToggleButtonExecution().setEnabled(true);
478+ getJToggleButtonExecution().setSelected(false);
479+ getJButtonContinue().setEnabled(false);
480+ getJToggleButtonConnection().setEnabled(true);
481+ }
482+ });
483+ }
484+
485+ // -------------------------------------------------------------------------
486+ // -------------------------------------------------------------------------
487+ // -------------------------------------------------------------------------
488+
489+ private static final long serialVersionUID = 1L;
490+ private JSplitPane jSplitPaneTable = null;
491+ private RTextScrollPane rTextScrollPaneSql = null;
492+ private RSyntaxTextArea rSyntaxTextAreaSql = null;
493+ private JTabbedPane jTabbedPaneResult = null;
494+ private JScrollPane jScrollPane = null;
495+ private JTable jTable = null;
496+ private JScrollPane jScrollPaneLog = null;
497+ private JTextArea jTextAreaLog = null;
498+ private JToolBar jJToolBarBar = null;
499+ private JButton jButtonContinue = null;
500+ private JCheckBox jCheckBoxAutoCommit = null;
501+ private JButton jButtonCommit = null;
502+ private JButton jButtonRollback = null;
503+
504+ private JToggleButton jToggleButtonExecution = null;
505+ private JToggleButton jToggleButtonConnection = null;
506+ private JScrollPane jScrollPane1 = null;
507+ private JTable jTableResultSet = null;
508+ private JComboBox<SentenceSeparator> jComboBoxSentenceSeparator = null;
509+
510+ /**
511+ * This is the default constructor
512+ */
513+ public JPanelSql() {
514+ super();
515+ initialize();
516+ }
517+
518+ /**
519+ * This method initializes this
520+ *
521+ * @return void
522+ */
523+ private void initialize() {
524+ this.setLayout(new BorderLayout());
525+ this.add(getJSplitPaneTable(), java.awt.BorderLayout.CENTER);
526+ this.add(getJJToolBarBar(), java.awt.BorderLayout.NORTH);
527+ }
528+
529+ /**
530+ * This method initializes jSplitPaneTable
531+ *
532+ * @return javax.swing.JSplitPane
533+ */
534+ JSplitPane getJSplitPaneTable() {
535+ if (jSplitPaneTable == null) {
536+ jSplitPaneTable = new JSplitPane();
537+ jSplitPaneTable.setOrientation(JSplitPane.VERTICAL_SPLIT);
538+ jSplitPaneTable.setDividerLocation(200);
539+ jSplitPaneTable.setDividerSize(10);
540+ jSplitPaneTable.setOneTouchExpandable(true);
541+ jSplitPaneTable.setTopComponent(getRTextScrollPaneSql());
542+ jSplitPaneTable.setBottomComponent(getJTabbedPaneResult());
543+ }
544+ return jSplitPaneTable;
545+ }
546+
547+ /**
548+ * This method initializes jScrollPane1
549+ *
550+ * @return javax.swing.JScrollPane
551+ */
552+ private RTextScrollPane getRTextScrollPaneSql() {
553+ if (rTextScrollPaneSql == null) {
554+ rTextScrollPaneSql = new RTextScrollPane();
555+ rTextScrollPaneSql.setViewportView(getRSyntaxTextAreaSql());
556+ }
557+ return rTextScrollPaneSql;
558+ }
559+
560+ /**
561+ * This method initializes jEditorPaneSql
562+ *
563+ * @return javax.swing.JEditorPane
564+ */
565+ RSyntaxTextArea getRSyntaxTextAreaSql() {
566+ if (rSyntaxTextAreaSql == null) {
567+ rSyntaxTextAreaSql = new RSyntaxTextArea();
568+ rSyntaxTextAreaSql.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_SQL);
569+ rSyntaxTextAreaSql.setAntiAliasingEnabled(true);
570+ FontZoom.setMouseWheel(rSyntaxTextAreaSql);
571+ }
572+ return rSyntaxTextAreaSql;
573+ }
574+
575+ /**
576+ * This method initializes jTabbedPaneResult
577+ *
578+ * @return javax.swing.JTabbedPane
579+ */
580+ JTabbedPane getJTabbedPaneResult() {
581+ if (jTabbedPaneResult == null) {
582+ jTabbedPaneResult = new JTabbedPane();
583+ jTabbedPaneResult.setTabPlacement(SwingConstants.LEFT);
584+ jTabbedPaneResult.add(getJScrollPane(), "data", TABBEDPANEL_INDEX_DATA);
585+ jTabbedPaneResult.add(getJScrollPaneLog(), "log", TABBEDPANEL_INDEX_LOG);
586+ jTabbedPaneResult.add(getJScrollPane1(), "RS", TABBEDPANEL_INDEX_RS);
587+ }
588+ return jTabbedPaneResult;
589+ }
590+
591+ /**
592+ * This method initializes jScrollPane
593+ *
594+ * @return javax.swing.JScrollPane
595+ */
596+ private JScrollPane getJScrollPane() {
597+ if (jScrollPane == null) {
598+ jScrollPane = new JScrollPane();
599+ jScrollPane.setViewportView(getJTable());
600+ }
601+ return jScrollPane;
602+ }
603+
604+ /**
605+ * This method initializes jTable
606+ *
607+ * @return javax.swing.JTable
608+ */
609+ JTable getJTable() {
610+ if (jTable == null) {
611+ jTable = new JTable();
612+ jTable.setIntercellSpacing(new Dimension(3, 2));
613+ jTable.setAutoCreateRowSorter(true);
614+ jTable.setCellSelectionEnabled(true);
615+ jTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
616+ Font font = jTable.getFont();
617+ jTable.setFont(new Font(Font.MONOSPACED, font.getStyle(), font.getSize()));
618+
619+ FontZoom.setMouseWheel(jTable);
620+ resultsTableColumnFit = new TableColumnFit(jTable);
621+ jTable.setModel(new ResultsTableModel());
622+ }
623+ return jTable;
624+ }
625+
626+ /**
627+ * This method initializes jJToolBarBar
628+ *
629+ * @return javax.swing.JToolBar
630+ */
631+ private JToolBar getJJToolBarBar() {
632+ if (jJToolBarBar == null) {
633+ jJToolBarBar = new JToolBar();
634+ jJToolBarBar.add(getJToggleButtonExecution());
635+ jJToolBarBar.add(getJButtonContinue());
636+ jJToolBarBar.add(getJCheckBoxAutoCommit());
637+ jJToolBarBar.add(getJButtonCommit());
638+ jJToolBarBar.add(getJButtonRollback());
639+ jJToolBarBar.add(getJToggleButtonConnection());
640+ jJToolBarBar.add(getJComboBoxSentenceSeparator());
641+ }
642+ return jJToolBarBar;
643+ }
644+
645+ /**
646+ * This method initializes jToggleButtonExecution
647+ *
648+ * @return javax.swing.JButton
649+ */
650+ JToggleButton getJToggleButtonExecution() {
651+ if (jToggleButtonExecution == null) {
652+ jToggleButtonExecution = new JToggleButton(IconImage.EXECUTE.getValue(), false);
653+ jToggleButtonExecution.setText("Execute");
654+ jToggleButtonExecution.setEnabled(false);
655+ jToggleButtonExecution.addChangeListener(new ChangeListener() {
656+ // pressedicon selectedicon では、うまく制御できないので、自前で制御する
657+ @Override
658+ public void stateChanged(ChangeEvent e) {
659+ JToggleButton b = (JToggleButton) e.getSource();
660+ if (b.isSelected()) {
661+ b.setIcon(IconImage.STOP.getValue());
662+ } else {
663+ b.setIcon(IconImage.EXECUTE.getValue());
664+ }
665+ }
666+ });
667+ }
668+ return jToggleButtonExecution;
669+ }
670+
671+ /**
672+ * This method initializes jButtonContinue
673+ *
674+ * @return javax.swing.JButton
675+ */
676+ JButton getJButtonContinue() {
677+ if (jButtonContinue == null) {
678+ jButtonContinue = new JButton(IconImage.GO_DOWN.getValue());
679+ jButtonContinue.setEnabled(false);
680+ jButtonContinue.setText("Continue");
681+ }
682+ return jButtonContinue;
683+ }
684+
685+ /**
686+ * This method initializes jCheckBoxAutoCommit
687+ *
688+ * @return javax.swing.JCheckBox
689+ */
690+ JCheckBox getJCheckBoxAutoCommit() {
691+ if (jCheckBoxAutoCommit == null) {
692+ jCheckBoxAutoCommit = new JCheckBox();
693+ jCheckBoxAutoCommit.setText("AutoCommit");
694+ jCheckBoxAutoCommit.setEnabled(false);
695+ jCheckBoxAutoCommit.addItemListener(new ItemListener() {
696+ @Override
697+ public void itemStateChanged(ItemEvent e) {
698+ boolean flg = jCheckBoxAutoCommit.isSelected();
699+ getJButtonCommit().setEnabled(!flg);
700+ getJButtonRollback().setEnabled(!flg);
701+ Jdbcacsess2.logger.fine("autocomit:" + flg);
702+
703+ if (getDataBaseConnection() == null) {
704+ return;
705+ }
706+ try {
707+ getDataBaseConnection().setAutoCommit(flg);
708+ } catch (Exception ex) {
709+ ShowDialog.errorMessage(ex);
710+ }
711+ }
712+ });
713+ jCheckBoxAutoCommit.setSelected(true);
714+ }
715+ return jCheckBoxAutoCommit;
716+ }
717+
718+ /**
719+ * This method initializes jButtonCommit
720+ *
721+ * @return javax.swing.JButton
722+ */
723+ JButton getJButtonCommit() {
724+ if (jButtonCommit == null) {
725+ jButtonCommit = new JButton(IconImage.COMMIT.getValue());
726+ jButtonCommit.setText("Commit");
727+ jButtonCommit.setEnabled(false);
728+ }
729+ return jButtonCommit;
730+ }
731+
732+ /**
733+ * This method initializes jButtonRollback
734+ *
735+ * @return javax.swing.JButton
736+ */
737+ JButton getJButtonRollback() {
738+ if (jButtonRollback == null) {
739+ jButtonRollback = new JButton(IconImage.ROLLBACK.getValue());
740+ jButtonRollback.setText("Rollback");
741+ jButtonRollback.setEnabled(false);
742+ }
743+ return jButtonRollback;
744+ }
745+
746+ /**
747+ * This method initializes jScrollPaneLog
748+ *
749+ * @return javax.swing.JScrollPane
750+ */
751+ private JScrollPane getJScrollPaneLog() {
752+ if (jScrollPaneLog == null) {
753+ jScrollPaneLog = new JScrollPane();
754+ jScrollPaneLog.setViewportView(getJTextAreaLog());
755+ }
756+ return jScrollPaneLog;
757+ }
758+
759+ /**
760+ * This method initializes jTextAreaLog
761+ *
762+ * @return javax.swing.JTextArea
763+ */
764+ JTextArea getJTextAreaLog() {
765+ if (jTextAreaLog == null) {
766+ jTextAreaLog = new JTextArea();
767+ jTextAreaLog.setEditable(false);
768+ jTextAreaLog.setLineWrap(false);
769+ jTextAreaLog.setOpaque(false);
770+ }
771+ return jTextAreaLog;
772+ }
773+
774+ /**
775+ * This method initializes jToggleButtonConnection
776+ *
777+ * @return javax.swing.JToggleButton
778+ */
779+ JToggleButton getJToggleButtonConnection() {
780+ if (jToggleButtonConnection == null) {
781+ jToggleButtonConnection = new JToggleButton(IconImage.DISCONNECT.getValue());
782+ jToggleButtonConnection.setText("session");
783+ jToggleButtonConnection.addChangeListener(new ChangeListener() {
784+ // pressedicon selectedicon では、うまく制御できないので、自前で制御する
785+ @Override
786+ public void stateChanged(ChangeEvent e) {
787+ JToggleButton b = (JToggleButton) e.getSource();
788+ if (b.isSelected()) {
789+ b.setIcon(IconImage.CONNECT.getValue());
790+ } else {
791+ b.setIcon(IconImage.DISCONNECT.getValue());
792+ }
793+ }
794+ });
795+ }
796+ return jToggleButtonConnection;
797+ }
798+
799+ /**
800+ * This method initializes jScrollPane1
801+ *
802+ * @return javax.swing.JScrollPane
803+ */
804+ private JScrollPane getJScrollPane1() {
805+ if (jScrollPane1 == null) {
806+ jScrollPane1 = new JScrollPane();
807+ jScrollPane1.setViewportView(getJTableResultSet());
808+ }
809+ return jScrollPane1;
810+ }
811+
812+ /**
813+ * This method initializes jTableResultSet
814+ *
815+ * @return javax.swing.JTable
816+ */
817+ private JTable getJTableResultSet() {
818+ if (jTableResultSet == null) {
819+ jTableResultSet = new JmyTable();
820+ }
821+ return jTableResultSet;
822+ }
823+
824+ /**
825+ * This method initializes jComboBoxSentenceSeparator
826+ *
827+ * @return javax.swing.JComboBox
828+ */
829+ JComboBox<SentenceSeparator> getJComboBoxSentenceSeparator() {
830+ if (jComboBoxSentenceSeparator == null) {
831+ jComboBoxSentenceSeparator = new JComboBox<SentenceSeparator>();
832+ jComboBoxSentenceSeparator.setEditable(true);
833+ jComboBoxSentenceSeparator.addItem(new SentenceSeparator(";", ";\\s*\\n?"));
834+ jComboBoxSentenceSeparator.addItem(new SentenceSeparator("/", "\\n+\\s*/\\s*\\n?"));
835+ jComboBoxSentenceSeparator.addItem(new SentenceSeparator("//", "\\n+?\\s*//\\s*\\n?"));
836+ jComboBoxSentenceSeparator.addItem(new SentenceSeparator("GO", "\\n+\\s*[Gg][Oo]\\s*\\n?"));
837+ }
838+ return jComboBoxSentenceSeparator;
839+ }
840+
841+ public static class SentenceSeparator {
842+ private final String guiVal;
843+ private final String regVal;
844+
845+ SentenceSeparator(String guiVal, String regVal) {
846+ this.guiVal = guiVal;
847+ this.regVal = regVal;
848+ }
849+
850+ @Override
851+ public String toString() {
852+ return guiVal;
853+ }
854+
855+ /**
856+ * @return regVal
857+ */
858+ public String getRegVal() {
859+ return regVal;
860+ }
861+ }
862862 }
diff -r e366c0f78aa8 -r fb10a3a26795 src/jdbcacsess2/main/JmyTable.java
--- a/src/jdbcacsess2/main/JmyTable.java Sun Mar 04 12:45:48 2012 +0900
+++ b/src/jdbcacsess2/main/JmyTable.java Sun Mar 04 19:04:33 2012 +0900
@@ -38,186 +38,186 @@
3838 */
3939 public class JmyTable extends JXTable {
4040
41- private static final long serialVersionUID = -7507194043135028576L;
42-
43- public JmyTable() {
44- super();
45- initialize();
46- }
47-
48- /**
49- * @param dm
50- */
51- public JmyTable(TableModel dm) {
52- super(dm);
53- initialize();
54- }
55-
56- /**
57- * @param dm
58- * @param cm
59- */
60- public JmyTable(TableModel dm, TableColumnModel cm) {
61- super(dm, cm);
62- initialize();
63- }
64-
65- /**
66- * @param numRows
67- * @param numColumns
68- */
69- public JmyTable(int numRows, int numColumns) {
70- super(numRows, numColumns);
71- initialize();
72- }
73-
74- /**
75- * @param rowData
76- * @param columnNames
77- */
78- public JmyTable(Vector<?> rowData, Vector<?> columnNames) {
79- super(rowData, columnNames);
80- initialize();
81- }
82-
83- /**
84- * @param rowData
85- * @param columnNames
86- */
87- public JmyTable(Object[][] rowData, Object[] columnNames) {
88- super(rowData, columnNames);
89- initialize();
90- }
91-
92- /**
93- * @param dm
94- * @param cm
95- * @param sm
96- */
97- public JmyTable(TableModel dm, TableColumnModel cm, ListSelectionModel sm) {
98- super(dm, cm, sm);
99- initialize();
100- }
101-
102- private void initialize() {
103- setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
104- setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
105- setShowVerticalLines(false);
106- setShowHorizontalLines(false);
107- setHighlighters(HighlighterFactory.createSimpleStriping());
108- // setCellSelectionEnabled(true);
109- setRowSelectionAllowed(true);
110- setAutoCreateRowSorter(true);
111- setEditable(false);
112- new FontZoomByMouseWheel(this);
113- }
114-
115- @Override
116- public void setModel(TableModel tableModel) {
117- super.setModel(tableModel);
118- new TableColumnFit(this).setEnableAutoFit(true);
119- TableRowFilterSupport.forTable(this).searchable(true).apply();
120- tableModel.addTableModelListener(tableModelListener);
121- setSortsOnUpdates(true);
122- }
41+ private static final long serialVersionUID = -7507194043135028576L;
12342
124- /**
125- * @return
126- */
127- public int getSelectedModelRow() {
128- int row = getSelectedRow();
129- if (row < 0) {
130- return -1;
131- }
132- return convertRowIndexToModel(row);
133- }
134-
135- /**
136- * @return
137- */
138- public int getSelectedModelColumn() {
139- int column = getSelectedColumn();
140- if (column < 0) {
141- return -1;
142- }
143- return convertColumnIndexToModel(column);
144- }
145-
146- /**
147- * @return
148- */
149- public ArrayList<Integer> getSelectedModelRows() {
150- int[] rows = getSelectedRows();
151- ArrayList<Integer> list = new ArrayList<Integer>(rows.length);
152- for (int i = 0; i < rows.length; i++) {
153- list.add(convertRowIndexToModel(rows[i]));
154- }
155- return list;
156- }
157-
158- /**
159- * @return
160- */
161- public ArrayList<Integer> getSelectedModelColumns() {
162- int[] columns = getSelectedColumns();
163- ArrayList<Integer> list = new ArrayList<Integer>(columns.length);
164- for (int i = 0; i < columns.length; i++) {
165- list.add(convertColumnIndexToModel(columns[i]));
166- }
167- return list;
168- }
43+ public JmyTable() {
44+ super();
45+ initialize();
46+ }
16947
170- /**
171- * 追加変更削除が行われた行を選択する。
172- */
173- transient private final TableModelListener tableModelListener = new TableModelListener() {
174- @Override
175- public void tableChanged(TableModelEvent event) {
176-
177- switch (event.getType()) {
178- case TableModelEvent.UPDATE:
179- int updateRow = convertRowIndexToView(event.getFirstRow());
180- changeSelection(updateRow, updateRow, false, false);
181- break;
48+ /**
49+ * @param dm
50+ */
51+ public JmyTable(TableModel dm) {
52+ super(dm);
53+ initialize();
54+ }
18255
183- case TableModelEvent.INSERT:
184- final int insertRow = event.getFirstRow();
185- // モデルの変更後に、追加行のGUI表示が行われる為、ここで追加イベントを拾ってもまだ画面表示は行われていない。
186- // なので、EDTにキューイング?して、画面書き換え後に選択させる。
187- SwingUtilities.invokeLater(new Runnable() {
188- @Override
189- public void run() {
190- // 行追加後のview状態で、view座標に変換。反映前だと変換テーブルがみつからないらしい
191- int row = convertRowIndexToView(insertRow);
192- changeSelection(row, row, false, false);
193- }
194- });
195- break;
196-
197- case TableModelEvent.DELETE:
198- if (getModel().getRowCount() == 0) {
199- break;
200- }
56+ /**
57+ * @param dm
58+ * @param cm
59+ */
60+ public JmyTable(TableModel dm, TableColumnModel cm) {
61+ super(dm, cm);
62+ initialize();
63+ }
20164
202- // 行削除前のview状態で、view座標に変換。反映後だと変換テーブルが見つからないらしい
203- final int deletedViewRow = convertRowIndexToView(event.getFirstRow());
204- SwingUtilities.invokeLater(new Runnable() {
65+ /**
66+ * @param numRows
67+ * @param numColumns
68+ */
69+ public JmyTable(int numRows, int numColumns) {
70+ super(numRows, numColumns);
71+ initialize();
72+ }
20573
206- @Override
207- public void run() {
208- int row = deletedViewRow;
209- if (getRowSorter().getViewRowCount() <= row) {
210- row = getRowSorter().getViewRowCount() - 1;
211- }
212- changeSelection(row, row, false, false);
213- }
214- });
215- break;
74+ /**
75+ * @param rowData
76+ * @param columnNames
77+ */
78+ public JmyTable(Vector<?> rowData, Vector<?> columnNames) {
79+ super(rowData, columnNames);
80+ initialize();
81+ }
21682
217- default:
218- break;
219- }
220- }
221- };
83+ /**
84+ * @param rowData
85+ * @param columnNames
86+ */
87+ public JmyTable(Object[][] rowData, Object[] columnNames) {
88+ super(rowData, columnNames);
89+ initialize();
90+ }
91+
92+ /**
93+ * @param dm
94+ * @param cm
95+ * @param sm
96+ */
97+ public JmyTable(TableModel dm, TableColumnModel cm, ListSelectionModel sm) {
98+ super(dm, cm, sm);
99+ initialize();
100+ }
101+
102+ private void initialize() {
103+ setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
104+ setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
105+ setShowVerticalLines(false);
106+ setShowHorizontalLines(false);
107+ setHighlighters(HighlighterFactory.createSimpleStriping());
108+ // setCellSelectionEnabled(true);
109+ setRowSelectionAllowed(true);
110+ setAutoCreateRowSorter(true);
111+ setEditable(false);
112+ FontZoom.setMouseWheel(this);
113+ }
114+
115+ @Override
116+ public void setModel(TableModel tableModel) {
117+ super.setModel(tableModel);
118+ new TableColumnFit(this).setEnableAutoFit(true);
119+ TableRowFilterSupport.forTable(this).searchable(true).apply();
120+ tableModel.addTableModelListener(tableModelListener);
121+ setSortsOnUpdates(true);
122+ }
123+
124+ /**
125+ * @return
126+ */
127+ public int getSelectedModelRow() {
128+ int row = getSelectedRow();
129+ if (row < 0) {
130+ return -1;
131+ }
132+ return convertRowIndexToModel(row);
133+ }
134+
135+ /**
136+ * @return
137+ */
138+ public int getSelectedModelColumn() {
139+ int column = getSelectedColumn();
140+ if (column < 0) {
141+ return -1;
142+ }
143+ return convertColumnIndexToModel(column);
144+ }
145+
146+ /**
147+ * @return
148+ */
149+ public ArrayList<Integer> getSelectedModelRows() {
150+ int[] rows = getSelectedRows();
151+ ArrayList<Integer> list = new ArrayList<Integer>(rows.length);
152+ for (int i = 0; i < rows.length; i++) {
153+ list.add(convertRowIndexToModel(rows[i]));
154+ }
155+ return list;
156+ }
157+
158+ /**
159+ * @return
160+ */
161+ public ArrayList<Integer> getSelectedModelColumns() {
162+ int[] columns = getSelectedColumns();
163+ ArrayList<Integer> list = new ArrayList<Integer>(columns.length);
164+ for (int i = 0; i < columns.length; i++) {
165+ list.add(convertColumnIndexToModel(columns[i]));
166+ }
167+ return list;
168+ }
169+
170+ /**
171+ * 追加変更削除が行われた行を選択する。
172+ */
173+ transient private final TableModelListener tableModelListener = new TableModelListener() {
174+ @Override
175+ public void tableChanged(TableModelEvent event) {
176+
177+ switch (event.getType()) {
178+ case TableModelEvent.UPDATE:
179+ int updateRow = convertRowIndexToView(event.getFirstRow());
180+ changeSelection(updateRow, updateRow, false, false);
181+ break;
182+
183+ case TableModelEvent.INSERT:
184+ final int insertRow = event.getFirstRow();
185+ // モデルの変更後に、追加行のGUI表示が行われる為、ここで追加イベントを拾ってもまだ画面表示は行われていない。
186+ // なので、EDTにキューイング?して、画面書き換え後に選択させる。
187+ SwingUtilities.invokeLater(new Runnable() {
188+ @Override
189+ public void run() {
190+ // 行追加後のview状態で、view座標に変換。反映前だと変換テーブルがみつからないらしい
191+ int row = convertRowIndexToView(insertRow);
192+ changeSelection(row, row, false, false);
193+ }
194+ });
195+ break;
196+
197+ case TableModelEvent.DELETE:
198+ if (getModel().getRowCount() == 0) {
199+ break;
200+ }
201+
202+ // 行削除前のview状態で、view座標に変換。反映後だと変換テーブルが見つからないらしい
203+ final int deletedViewRow = convertRowIndexToView(event.getFirstRow());
204+ SwingUtilities.invokeLater(new Runnable() {
205+
206+ @Override
207+ public void run() {
208+ int row = deletedViewRow;
209+ if (getRowSorter().getViewRowCount() <= row) {
210+ row = getRowSorter().getViewRowCount() - 1;
211+ }
212+ changeSelection(row, row, false, false);
213+ }
214+ });
215+ break;
216+
217+ default:
218+ break;
219+ }
220+ }
221+ };
222222
223223 }
Show on old repository browser