• R/O
  • SSH
  • HTTPS

dbviewer: コミット


コミットメタ情報

リビジョン239 (tree)
日時2010-09-17 12:25:23
作者zigen

ログメッセージ

for SQL with Binding Data

変更サマリ

差分

--- DBViewer/branches/2.0.0/src/zigen/plugin/db/ui/views/BindData.java (revision 238)
+++ DBViewer/branches/2.0.0/src/zigen/plugin/db/ui/views/BindData.java (nonexistent)
@@ -1,147 +0,0 @@
1-package zigen.plugin.db.ui.views;
2-
3-import java.util.Iterator;
4-import java.util.List;
5-
6-import zigen.plugin.db.core.IDBConfig;
7-import zigen.plugin.db.parser.util.ASTUtil2;
8-import zigen.plugin.db.ui.contentassist.ContentAssistUtil;
9-import zigen.plugin.db.ui.contentassist.ContentInfo;
10-import zigen.plugin.db.ui.contentassist.SQLProposalCreator2;
11-import zigen.plugin.db.ui.contentassist.processor.Messages;
12-import zigen.plugin.db.ui.internal.Column;
13-import zigen.sql.parser.INode;
14-import zigen.sql.parser.ast.ASTBind;
15-import zigen.sql.parser.ast.ASTColumn;
16-import zigen.sql.parser.ast.ASTFrom;
17-import zigen.sql.parser.ast.ASTOperator;
18-import zigen.sql.parser.ast.ASTParentheses;
19-import zigen.sql.parser.ast.ASTSelect;
20-import zigen.sql.parser.ast.ASTSelectStatement;
21-import zigen.sql.parser.ast.ASTTable;
22-
23-public class BindData{
24-
25- public ASTBind ast;
26-
27- public String name;
28-
29- public boolean isCharacter = false;
30-
31- public String value;
32-
33- ContentInfo ci = null;
34-
35- Column column;
36-
37-
38- public BindData(IDBConfig config, ASTBind ast, boolean isCharacter){
39- this.ast = ast;
40- this.name = ast.getName();
41- this.isCharacter = isCharacter;
42- this.value = "";
43-
44- ci = new ContentInfo(config);
45- setup();
46- }
47-
48-
49- void setup(){
50- ASTSelectStatement st = findParentASTSelectStatement(ast);
51- if(st != null){
52- ASTFrom fromList = findASTFrom(st);
53- if(fromList.getChildrenSize() == 1){
54- Column[] cols = getColumns(fromList.getChild(0));
55- if(cols != null){
56- for (int i = 0; i < cols.length; i++) {
57- Column _col = cols[i];
58- if(_col.getColumn().getColumnName().equalsIgnoreCase(getASTColumn().getColumnName())){
59- column = _col;
60- if(column.getTypeName().toUpperCase().indexOf("CHAR") >= 0){
61- this.isCharacter = true;
62- }else{
63- this.isCharacter = false;
64- }
65- break;
66-
67- }
68- }
69- }
70-
71- }
72- }
73-
74- }
75- public Column getTargetColumn(){
76- return column;
77- }
78-
79-
80- private ASTColumn getASTColumn(){
81- INode parent = ast.getParent();
82- if(parent != null){
83- List list = ast.getParent().getChildren();
84- if(parent instanceof ASTOperator){
85- // COL = ? や COL <> ? などの場合のみ対応
86- int offset = ast.getOffset(); // バインド変数のオフセット
87- for (Iterator iterator = list.iterator(); iterator.hasNext();) {
88- INode node = (INode) iterator.next();
89- if(node.getOffset() != offset){
90- if(node instanceof ASTColumn){
91- return (ASTColumn)node;
92-
93- }
94- }
95- }
96- }
97- }
98- return null;
99- }
100-
101-
102- private ASTSelectStatement findParentASTSelectStatement(INode node) {
103- return (ASTSelectStatement) ASTUtil2.findParent(node, "ASTSelectStatement");
104- }
105-
106- private ASTFrom findASTFrom(ASTSelectStatement node) {
107- return (ASTFrom) node.getChild("ASTFrom");
108- }
109-
110-
111-
112- protected Column[] getColumns(INode target) {
113- if (target != null) {
114- if (target instanceof ASTTable) {
115- return getColumnsForASTTable((ASTTable) target);
116-
117- } else if (target instanceof ASTSelectStatement) {
118-// createColumn((ASTSelectStatement) target);
119-
120- } else if (target instanceof ASTParentheses) {
121-// ASTSelectStatement select = (ASTSelectStatement) ASTUtil2.findFirstChild(target, "ASTSelectStatement"); //$NON-NLS-1$
122-// if (select != null) {
123-// createColumnProposal(select);
124-// } else {
125-// throw new IllegalStateException(Messages.getString("DefaultProcessor.13")); //$NON-NLS-1$
126-// }
127- }
128- }
129- return null;
130-
131- }
132-
133- private Column[] getColumnsForASTTable(ASTTable target) {
134- if (target != null) {
135- if (ci.isConnected()) {
136- String schemaName = ((ASTTable) target).getSchemaName();
137- if(schemaName == null) schemaName = ci.getCurrentSchema();
138- String tableName = ((ASTTable) target).getTableName();
139- Column[] cols = ci.getColumns(schemaName, tableName);
140- return cols;
141- }
142- }
143- return null;
144- }
145-
146-
147-}
\ No newline at end of file
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- DBViewer/branches/2.0.0/src/zigen/plugin/db/ui/views/BindingData.java (nonexistent)
+++ DBViewer/branches/2.0.0/src/zigen/plugin/db/ui/views/BindingData.java (revision 239)
@@ -0,0 +1,172 @@
1+package zigen.plugin.db.ui.views;
2+
3+import java.util.Iterator;
4+import java.util.List;
5+
6+import zigen.plugin.db.core.IDBConfig;
7+import zigen.plugin.db.parser.util.ASTUtil2;
8+import zigen.plugin.db.ui.contentassist.ContentAssistUtil;
9+import zigen.plugin.db.ui.contentassist.ContentInfo;
10+import zigen.plugin.db.ui.contentassist.SQLProposalCreator2;
11+import zigen.plugin.db.ui.contentassist.processor.Messages;
12+import zigen.plugin.db.ui.internal.Column;
13+import zigen.sql.parser.INode;
14+import zigen.sql.parser.ISqlParser;
15+import zigen.sql.parser.ast.ASTBind;
16+import zigen.sql.parser.ast.ASTColumn;
17+import zigen.sql.parser.ast.ASTFrom;
18+import zigen.sql.parser.ast.ASTOperator;
19+import zigen.sql.parser.ast.ASTParentheses;
20+import zigen.sql.parser.ast.ASTSelect;
21+import zigen.sql.parser.ast.ASTSelectStatement;
22+import zigen.sql.parser.ast.ASTTable;
23+
24+public class BindingData {
25+
26+ public ASTBind ast;
27+
28+ public String name;
29+
30+ public boolean isCharacter = false;
31+
32+ public String value;
33+
34+ ContentInfo ci = null;
35+
36+ Column column;
37+
38+ private int scope;
39+
40+ public BindingData(IDBConfig config, ASTBind ast, int scope) {
41+ this.ast = ast;
42+ this.name = ast.getName();
43+ this.value = "";
44+ this.scope = scope;
45+ ci = new ContentInfo(config);
46+ setup();
47+ }
48+
49+ private void setup() {
50+ ASTSelectStatement st = findParentASTSelectStatement(ast);
51+ if (st != null) {
52+ ASTFrom fromList = findASTFrom(st);
53+ if (fromList.getChildrenSize() == 0) {
54+
55+ }
56+ if (fromList.getChildrenSize() == 1) {
57+ // 単一テーブルの場合
58+ Column[] cols = getColumns(fromList.getChild(0));
59+ if (cols != null) {
60+ for (int i = 0; i < cols.length; i++) {
61+ Column _col = cols[i];
62+ if (_col.getColumn().getColumnName().equalsIgnoreCase(getASTColumn().getColumnName())) {
63+ column = _col;
64+ if (column.getTypeName().toUpperCase().indexOf("CHAR") >= 0) {
65+ this.isCharacter = true;
66+ } else {
67+ this.isCharacter = false;
68+ }
69+ break;
70+
71+ }
72+ }
73+ }
74+
75+ } else {
76+
77+ }
78+ }
79+
80+ }
81+
82+
83+ private ASTColumn getASTColumn() {
84+ switch (scope) {
85+ case ISqlParser.SCOPE_WHERE:
86+ INode parent = ast.getParent();
87+ if (parent == null) {
88+ return null;
89+ }
90+
91+ if(parent instanceof ASTParentheses){
92+ // for ASTParentheses
93+ ASTParentheses p = (ASTParentheses)parent;
94+ return getASTColumnForParent(p.getParent());
95+
96+ }else{
97+ // for parent is ASTOperator, etc
98+ return getASTColumnForParent(ast.getParent());
99+
100+ }
101+
102+ default:
103+ break;
104+ }
105+
106+ return null;
107+
108+ }
109+
110+ private ASTColumn getASTColumnForParent(INode parent){
111+ if(parent == null) return null;
112+
113+ List list = parent.getChildren();
114+ for (Iterator iterator = list.iterator(); iterator.hasNext();) {
115+ INode node = (INode) iterator.next();
116+ if (node instanceof ASTColumn) {
117+ return (ASTColumn) node;
118+ }
119+ }
120+ return null;
121+ }
122+
123+
124+ public Column getTargetColumn() {
125+ return column;
126+ }
127+
128+ private ASTSelectStatement findParentASTSelectStatement(INode node) {
129+ return (ASTSelectStatement) ASTUtil2.findParent(node,
130+ "ASTSelectStatement");
131+ }
132+
133+ private ASTFrom findASTFrom(ASTSelectStatement node) {
134+ return (ASTFrom) node.getChild("ASTFrom");
135+ }
136+
137+ protected Column[] getColumns(INode target) {
138+ if (target != null) {
139+ if (target instanceof ASTTable) {
140+ return getColumnsForASTTable((ASTTable) target);
141+
142+ } else if (target instanceof ASTSelectStatement) {
143+ // createColumn((ASTSelectStatement) target);
144+
145+ } else if (target instanceof ASTParentheses) {
146+ // ASTSelectStatement select = (ASTSelectStatement) ASTUtil2.findFirstChild(target, "ASTSelectStatement"); //$NON-NLS-1$
147+ // if (select != null) {
148+ // createColumnProposal(select);
149+ // } else {
150+ // throw new IllegalStateException(Messages.getString("DefaultProcessor.13")); //$NON-NLS-1$
151+ // }
152+ }
153+ }
154+ return null;
155+
156+ }
157+
158+ private Column[] getColumnsForASTTable(ASTTable target) {
159+ if (target != null) {
160+ if (ci.isConnected()) {
161+ String schemaName = ((ASTTable) target).getSchemaName();
162+ if (schemaName == null)
163+ schemaName = ci.getCurrentSchema();
164+ String tableName = ((ASTTable) target).getTableName();
165+ Column[] cols = ci.getColumns(schemaName, tableName);
166+ return cols;
167+ }
168+ }
169+ return null;
170+ }
171+
172+}
\ No newline at end of file
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
--- DBViewer/branches/2.0.0/src/zigen/plugin/db/ui/views/BindingParamArea.java (revision 238)
+++ DBViewer/branches/2.0.0/src/zigen/plugin/db/ui/views/BindingParamArea.java (revision 239)
@@ -22,11 +22,19 @@
2222 import org.eclipse.swt.widgets.Item;
2323 import org.eclipse.swt.widgets.Table;
2424 import org.eclipse.swt.widgets.TableColumn;
25+import org.eclipse.ui.IActionBars;
2526
2627 import zigen.plugin.db.DbPlugin;
2728 import zigen.plugin.db.IStatusChangeListener;
2829 import zigen.plugin.db.ImageCacher;
2930 import zigen.plugin.db.core.IDBConfig;
31+import zigen.plugin.db.core.TableElement;
32+import zigen.plugin.db.ui.editors.CellModifier;
33+import zigen.plugin.db.ui.editors.event.TableKeyAdapter;
34+import zigen.plugin.db.ui.editors.event.TableKeyEventHandler;
35+import zigen.plugin.db.ui.editors.internal.CellEditorType;
36+import zigen.plugin.db.ui.editors.internal.ColumnFilterInfo;
37+import zigen.plugin.db.ui.editors.internal.FileCellEditor;
3038 import zigen.sql.parser.INode;
3139 import zigen.sql.parser.ast.ASTBind;
3240 import zigen.sql.parser.ast.ASTRoot;
@@ -47,10 +55,25 @@
4755
4856 IDBConfig config;
4957
50- public void createPartControl(IDBConfig config, INode nodel) {
58+ BindingTableKeyEventHandler handler = null;
59+
60+ public void setVisibled(boolean b){
61+ if(b){
62+
63+ if(columnTableViewer != null || handler != null){
64+ columnTableViewer.getTable().setFocus();
65+ handler.selectRow(0);
66+ handler.editTableElement(0, 2);
67+ }
68+
69+ }
70+
71+ }
72+
73+ public void createPartControl(IDBConfig config, INode node, int scope) {
5174 this.config = config;
5275
53- createBindingDataList(nodel);
76+ createBindingDataList(node, scope);
5477
5578 if(columnTableViewer == null){
5679 columnTableViewer = new TableViewer(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
@@ -63,6 +86,12 @@
6386
6487 setHeaderColumn(table, headers);
6588
89+ handler = new BindingTableKeyEventHandler(columnTableViewer);
90+ setCellModify(columnTableViewer, handler);
91+ columnTableViewer.setLabelProvider(new ColumnSelectLabelProvider());
92+ columnTableViewer.setContentProvider(new ColumnSelectContentProvider());
93+
94+ /*
6695 columnTableViewer.setColumnProperties(new String[] {"dummy", "name", "value", "check", "memo"});
6796
6897 CheckboxCellEditor checkEditor = new CheckboxCellEditor(table);
@@ -83,25 +112,88 @@
83112 DbPlugin.fireStatusChangeListener(e, IStatusChangeListener.EVT_FOCUS_LOST_BIND_AREA);
84113 }
85114 }
86- );
115+ );*/
87116
88117 }
89118
90119 if(bindDataList.size() > 0){
91- columnTableViewer.setInput(bindDataList.toArray(new BindData[0]));
120+ columnTableViewer.setInput(bindDataList.toArray(new BindingData[0]));
92121 parent.setWeights(defaultWeight);
93122 columnsPack(table);
123+ setVisibled(true);
94124 }else{
95125 columnTableViewer.setInput(null);
96126 parent.setWeights(new int[] {1000, 0});
127+ setVisibled(false);
97128 }
98129
99130 }
131+ private void setCellModify(TableViewer viewer, BindingTableKeyEventHandler handler) {
132+
133+ //final IActionBars bars = getEditorSite().getActionBars();
134+
135+ String[] properties = new String[4];
136+ CellEditor[] cellEditors = new CellEditor[4];
137+ BindingTableKeyAdapter keyAdapter = new BindingTableKeyAdapter(handler);
138+ for (int i = 0; i < cellEditors.length; i++) {
139+ properties[i] = String.valueOf(i);
140+ if (i > 0) {
141+ CellEditor cellEditor = null;
142+
143+ if(i == 3){
144+ cellEditor = new CheckboxCellEditor(table, i);
145+ }else{
146+ cellEditor = new TextCellEditor(table, i);
147+ cellEditor.getControl().addKeyListener(keyAdapter);
148+ cellEditor.getControl().addTraverseListener(keyAdapter);
149+ cellEditor.getControl().addFocusListener(new FocusAdapter() {
150+ public void focusGained(FocusEvent e) {
151+ //setInfomationText(EDIT_MODE_ON);
152+ //isEditing = true;
153+ //bars.clearGlobalActionHandlers();
154+ //bars.updateActionBars();
155+ DbPlugin.fireStatusChangeListener(e, IStatusChangeListener.EVT_FOCUS_GAIN_BIND_AREA);
156+ }
157+
158+ public void focusLost(FocusEvent e) {
159+ //setInfomationText(EDIT_MODE_OFF);
160+ //isEditing = false;
161+ DbPlugin.fireStatusChangeListener(e, IStatusChangeListener.EVT_FOCUS_LOST_BIND_AREA);
162+ }
163+ });
164+
165+ }
166+
167+ // cellEditor.getControl().addFocusListener(new
168+ // CellFocusAdapter(element));
169+
170+ cellEditors[i] = cellEditor;
171+
172+ }
173+ }
174+
175+ viewer.setColumnProperties(properties);
176+ viewer.setCellModifier(new ColumnSelectCellModifier());
177+ viewer.setCellEditors(cellEditors);
178+ }
100179
101-
102- public void createPartControl(IDBConfig config, String sql) {
103- INode node = parseSql(sql);
104- createPartControl(config, node);
180+ public void createPartControl(IDBConfig config, String sql) {
181+ INode node = new ASTRoot();
182+ zigen.sql.parser.SqlParser parser = null;
183+ try {
184+ parser = new zigen.sql.parser.SqlParser(sql, DbPlugin.getSqlFormatRult());
185+ parser.parse(node);
186+ // for debug
187+ //parser.dump(node);
188+
189+ createPartControl(config, node, parser.getScope());
190+
191+ } catch (Exception e) {
192+ DbPlugin.log(e);
193+ } finally {
194+ if (parser != null)
195+ parser = null;
196+ }
105197 }
106198
107199 private void columnsPack(Table table) {
@@ -158,26 +250,26 @@
158250 }
159251 }
160252
161- private INode parseSql(String sql) {
162- INode node = new ASTRoot();
163- zigen.sql.parser.ISqlParser parser = null;
164- try {
165- parser = new zigen.sql.parser.SqlParser(sql, DbPlugin.getSqlFormatRult());
166- parser.parse(node);
167- // for debug
168- //parser.dump(node);
169- } catch (Exception e) {
170- DbPlugin.log(e);
171- } finally {
172- if (parser != null)
173- parser = null;
174- }
175- return node;
176- }
253+// private INode parseSql(String sql) {
254+// INode node = new ASTRoot();
255+// zigen.sql.parser.ISqlParser parser = null;
256+// try {
257+// parser = new zigen.sql.parser.SqlParser(sql, DbPlugin.getSqlFormatRult());
258+// parser.parse(node);
259+// // for debug
260+// //parser.dump(node);
261+// } catch (Exception e) {
262+// DbPlugin.log(e);
263+// } finally {
264+// if (parser != null)
265+// parser = null;
266+// }
267+// return node;
268+// }
177269
178270
179271
180- private void createBindingDataList(INode node){
272+ private void createBindingDataList(INode node, int scope){
181273
182274 List wk = new ArrayList();
183275
@@ -187,29 +279,30 @@
187279 if(list != null){
188280 for (Iterator iterator = list.iterator(); iterator.hasNext();) {
189281 ASTBind ast = (ASTBind) iterator.next();
190- wk.add(new BindData(config, ast, false));
282+ wk.add(new BindingData(config, ast, scope));
191283 }
192284 }
193285
194286 int index = 0;
195287 for (Iterator iterator = wk.iterator(); iterator.hasNext();) {
196- BindData newData = (BindData) iterator.next();
288+ BindingData newData = (BindingData) iterator.next();
197289
198290
199291 if("?".equals(newData.name)){
200292 int index2 = 0;
201293 for (Iterator iterator2 = bindDataList.iterator(); iterator2.hasNext();) {
202- BindData oldData = (BindData) iterator2.next();
294+ BindingData oldData = (BindingData) iterator2.next();
203295 if("?".equals(oldData.name) && index == index2){
204296 newData.value = oldData.value;
205- newData.isCharacter = oldData.isCharacter;
297+ //newData.isCharacter = oldData.isCharacter;
206298 }
299+
207300 index2++;
208301 }
209302
210303 }else{
211304 for (Iterator iterator2 = bindDataList.iterator(); iterator2.hasNext();) {
212- BindData oldData = (BindData) iterator2.next();
305+ BindingData oldData = (BindingData) iterator2.next();
213306 if(newData.name.equals(oldData.name)){
214307 newData.value = oldData.value;
215308 newData.isCharacter = oldData.isCharacter;
@@ -241,7 +334,7 @@
241334
242335 public String getColumnText(Object element, int columnIndex) {
243336 String result = ""; //$NON-NLS-1$
244- BindData data = (BindData) element;
337+ BindingData data = (BindingData) element;
245338 switch (columnIndex) {
246339 case 0:
247340 break;
@@ -254,11 +347,12 @@
254347 break;
255348 case 3:
256349 result = "";
350+ //result = String.valueOf(data.isCharacter);
257351 break;
258352
259353 case 4:
260354 if(data.getTargetColumn() != null){
261- result = data.getTargetColumn().getColumnLabel(true);
355+ result = data.getTargetColumn().getColumnLabel(false);
262356 }else{
263357 return "";
264358 }
@@ -272,7 +366,7 @@
272366 }
273367
274368 public Image getColumnImage(Object element, int columnIndex) {
275- BindData data = (BindData) element;
369+ BindingData data = (BindingData) element;
276370 if (columnIndex == 3) {
277371 return getImage(data.isCharacter);
278372 }
@@ -289,8 +383,8 @@
289383 private List contents = null;
290384
291385 public Object[] getElements(Object inputElement) {
292- if (inputElement instanceof BindData[]) {
293- return (BindData[]) inputElement;
386+ if (inputElement instanceof BindingData[]) {
387+ return (BindingData[]) inputElement;
294388 }
295389 return null;
296390 }
@@ -310,34 +404,49 @@
310404 public ColumnSelectCellModifier() {}
311405
312406 public boolean canModify(Object element, String property) {
313- return true;
407+ try {
408+ int index = Integer.parseInt(property);
409+ switch (index) {
410+ //case 1: // << for test
411+ case 2:
412+ case 3:
413+ return true;
414+ default:
415+ return false;
416+ }
417+
418+ } catch (Exception e) {
419+ e.printStackTrace();
420+ return false;
421+ }
314422 }
315423
316424 public Object getValue(Object element, String property) {
317- BindData data = (BindData) element;
318- /*
319- if (property == "check") { //$NON-NLS-1$
320- return new Boolean(item.isChecked());
321- } else if (property == "sort") { //$NON-NLS-1$
322- return new Boolean(item.isChecked());
323- } else {
324- return item.getColumnName();
325- }*/
326- if(property == "name"){
327- return data.ast.getName();
425+ BindingData data = (BindingData) element;
426+
427+ try {
428+ int index = Integer.parseInt(property);
429+ switch (index) {
430+ case 1:
431+ return data.ast.getName();
432+ case 2:
433+ return data.value;
434+ case 3:
435+ return new Boolean(data.isCharacter);
436+ //return String.valueOf(data.isCharacter);
437+
438+ case 4:
439+ return data.getTargetColumn();
440+
441+ default:
442+ return null;
443+ }
328444
329- }else if(property == "check"){
330- return new Boolean(data.isCharacter);
331-
332- }else if(property == "value"){
333- return data.value;
334-
335- }else if(property == "memo"){
336- return data.getTargetColumn();
337-
338- }else{
445+ } catch (Exception e) {
446+ e.printStackTrace();
339447 return null;
340- }
448+ }
449+
341450 }
342451
343452 public void modify(Object element, String property, Object value) {
@@ -344,19 +453,31 @@
344453 if (element instanceof Item) {
345454 element = ((Item) element).getData();
346455 }
347- BindData data = (BindData) element;
456+ BindingData data = (BindingData) element;
348457
349- if(property == "value"){
350- data.value = ((String)value).toString();
351- columnTableViewer.update(element, new String[] {"value"}); //$NON-NLS-1$
458+ try {
459+ int index = Integer.parseInt(property);
460+ switch (index) {
461+
462+ case 2:
463+ data.value = ((String)value).toString();
464+ columnTableViewer.update(element, new String[] {"2"}); //$NON-NLS-1$
465+ break;
466+
467+ case 3:
468+ data.isCharacter = ((Boolean) value).booleanValue();
469+ //data.isCharacter = Boolean.parseBoolean((String)value);
470+ columnTableViewer.update(element, new String[] {"3"}); //$NON-NLS-1$
471+ break;
472+ default:
473+ return;
474+ }
352475
353- }else if(property == "check"){
354- data.isCharacter = ((Boolean) value).booleanValue();
355- columnTableViewer.update(element, new String[] {"check"}); //$NON-NLS-1$
356-
476+ } catch (Exception e) {
477+ e.printStackTrace();
478+ return;
357479 }
358-
359-
480+
360481 }
361482 }
362483 }
--- DBViewer/branches/2.0.0/src/zigen/plugin/db/ui/views/BindingTableKeyEventHandler.java (nonexistent)
+++ DBViewer/branches/2.0.0/src/zigen/plugin/db/ui/views/BindingTableKeyEventHandler.java (revision 239)
@@ -0,0 +1,203 @@
1+/*
2+ * Copyright (c) 2007 - 2009 ZIGEN
3+ * Eclipse Public License - v 1.0
4+ * http://www.eclipse.org/legal/epl-v10.html
5+ */
6+package zigen.plugin.db.ui.views;
7+
8+import org.eclipse.jface.viewers.CellEditor;
9+import org.eclipse.jface.viewers.ICellModifier;
10+import org.eclipse.jface.viewers.TableViewer;
11+import org.eclipse.swt.widgets.Table;
12+
13+import zigen.plugin.db.DbPlugin;
14+import zigen.plugin.db.core.IDBConfig;
15+import zigen.plugin.db.core.TableElement;
16+import zigen.plugin.db.core.rule.AbstractValidatorFactory;
17+import zigen.plugin.db.core.rule.IValidatorFactory;
18+import zigen.plugin.db.ui.editors.TextCellEditor;
19+
20+public class BindingTableKeyEventHandler {
21+ protected TableViewer viewer;
22+ protected Table table;
23+
24+ public BindingTableKeyEventHandler(TableViewer viewer) {
25+ this.viewer = viewer;
26+ this.table = viewer.getTable();
27+ }
28+
29+ public int getSelectedRow() {
30+ return table.getSelectionIndex();
31+ }
32+
33+ public void selectRow(int index) {
34+ table.select(index);
35+ }
36+
37+ public int getSelectedCellEditorIndex() {
38+ int defaultIndex = 0;
39+ CellEditor[] editors = viewer.getCellEditors();
40+ if (editors == null)
41+ return -1;
42+ for (int i = 0; i < editors.length; i++) {
43+ if (editors[i] != null && editors[i].isActivated()) {
44+ return i;
45+ }
46+ }
47+ return defaultIndex;
48+ }
49+
50+ public int getEditableNextColumn(int cuurentCol) {
51+ ICellModifier modifier = viewer.getCellModifier();
52+ int nextCol = (cuurentCol < table.getColumnCount() - 1) ? cuurentCol + 1 : 1;
53+ if (modifier.canModify(null, String.valueOf(nextCol))) {
54+ return nextCol;
55+ } else {
56+ return getEditableNextColumn(nextCol);
57+ }
58+ }
59+
60+ public int getEditablePrevColumn(int CurrentCol) {
61+ ICellModifier modifier = viewer.getCellModifier();
62+ int nextCol = (CurrentCol == 1) ? table.getColumnCount() - 1 : CurrentCol - 1;
63+ if (modifier.canModify(null, String.valueOf(nextCol))) {
64+ return nextCol;
65+ } else {
66+ return getEditablePrevColumn(nextCol);
67+ }
68+ }
69+
70+ public void editTableElement(int rowIndex, int columnIndex) {
71+ Object element = viewer.getElementAt(rowIndex);
72+ if (element != null) {
73+ if (columnIndex == 1) {
74+ table.showColumn(table.getColumn(0));
75+ } else {
76+ table.showColumn(table.getColumn(columnIndex));
77+ }
78+ viewer.editElement(element, columnIndex);
79+
80+ }
81+ }
82+
83+ public void updateColumn(TableElement element, int col, Object newValue) {
84+ element.updateItems(col - 1, newValue);
85+ viewer.update(element, null);
86+ columnsPack();
87+
88+ }
89+
90+
91+ public void setMessage(String msg) {
92+ DbPlugin.getDefault().showWarningMessage(msg);
93+ }
94+
95+ private void columnsPack() {
96+ }
97+
98+
99+//
100+// public boolean validate(int row, int col) {
101+// //TableElement element = (TableElement) viewer.getElementAt(row);
102+// Object newValue = null;
103+// CellEditor editor = viewer.getCellEditors()[col];
104+// if (editor == null)
105+// throw new IllegalStateException("CellEditor is not set."); //$NON-NLS-1$
106+// int columnIndex = -1;
107+// if (editor instanceof TextCellEditor) {
108+// TextCellEditor tce = (TextCellEditor) editor;
109+// newValue = tce.getInputValue();
110+// columnIndex = tce.getColumnIndex();
111+//
112+// }
113+// Object oldValue = element.getItems()[col - 1];
114+// if (!oldValue.equals(newValue)) {
115+// String msg = editor.getErrorMessage();
116+// if (msg == null) {
117+// updateColumn(element, col, newValue);
118+// return true;
119+//
120+// } else {
121+// viewer.cancelEditing();
122+// updateColumn(element, col, newValue);
123+// setMessage(msg); //$NON-NLS-1$
124+// editTableElement(row, col);
125+// return false;
126+// }
127+//
128+// }
129+// return true;
130+//
131+// }
132+
133+// public boolean validateAll() {
134+// // log.debug("validateAll");
135+// try {
136+// int row = getSelectedRow();
137+// if (row == -1) {
138+// ;// CTRL+C
139+// } else {
140+// TableElement element = (TableElement) viewer.getElementAt(row);
141+// IDBConfig config = element.getTable().getDbConfig();
142+// IValidatorFactory factory = AbstractValidatorFactory.getFactory(config);
143+// zigen.plugin.db.core.TableColumn[] columns = element.getColumns();
144+// String msg = null;
145+// for (int col = 0; col < columns.length; col++) {
146+// Object[] items = element.getItems();
147+// msg = factory.validate(columns[col], items[col]);
148+// if (msg != null) {
149+// viewer.cancelEditing();
150+// setMessage(msg);
151+// editTableElement(row, col + 1);
152+// return false;
153+// }
154+// }
155+// }
156+//
157+// } catch (Exception e) {
158+// e.printStackTrace();
159+// DbPlugin.getDefault().showErrorDialog(e);
160+// }
161+// return true;
162+// }
163+
164+
165+ /*
166+ public boolean hasSameRecord(TableElement element) throws Exception {
167+ Connection con = TransactionForTableEditor.getInstance(config).getConnection();
168+ TableElement registedElem = TableElementSearcher.findElement(con, element, true);
169+ return registedElem != null ? true : false;
170+ }*/
171+
172+ /*
173+ public void createNewRecord() {
174+
175+ String nullSymbol = DbPlugin.getDefault().getPreferenceStore().getString(PreferencePage.P_NULL_SYMBOL);
176+
177+ TableElement elem = getHeaderTableElement();
178+ ITable tbl = elem.getTable();
179+ int count = table.getItems().length;
180+
181+ Object[] items = new Object[elem.getColumns().length];
182+ for (int i = 0; i < items.length; i++) {
183+ zigen.plugin.db.core.TableColumn column = elem.getColumns()[i];
184+ items[i] = InsertRecordAction.getDefaultValue(column);
185+ }
186+
187+ TableElement newElement = new TableNewElement(tbl, count + 1, elem.getColumns(), items, elem.getUniqueColumns());
188+
189+ TableViewerManager.insert(viewer, newElement);
190+
191+ editTableElement(count, 1);
192+
193+ }
194+
195+ public void removeRecord(TableElement element) {
196+ TableViewerManager.remove(viewer, element);
197+ }*/
198+
199+ public void dispose() {
200+ }
201+
202+
203+}
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
--- DBViewer/branches/2.0.0/src/zigen/plugin/db/ui/views/BindingTableKeyAdapter.java (nonexistent)
+++ DBViewer/branches/2.0.0/src/zigen/plugin/db/ui/views/BindingTableKeyAdapter.java (revision 239)
@@ -0,0 +1,214 @@
1+/*
2+ * Copyright (c) 2007 - 2009 ZIGEN
3+ * Eclipse Public License - v 1.0
4+ * http://www.eclipse.org/legal/epl-v10.html
5+ */
6+package zigen.plugin.db.ui.views;
7+
8+import org.eclipse.swt.SWT;
9+import org.eclipse.swt.events.KeyEvent;
10+import org.eclipse.swt.events.KeyListener;
11+import org.eclipse.swt.events.TraverseEvent;
12+import org.eclipse.swt.events.TraverseListener;
13+import org.eclipse.swt.widgets.Button;
14+import org.eclipse.swt.widgets.Table;
15+import org.eclipse.swt.widgets.Text;
16+
17+import zigen.plugin.db.DbPlugin;
18+import zigen.plugin.db.core.TableElement;
19+
20+public class BindingTableKeyAdapter implements KeyListener, TraverseListener {
21+
22+ private BindingTableKeyEventHandler handler;
23+
24+ int columnCount;
25+ Table table;
26+
27+ public BindingTableKeyAdapter(BindingTableKeyEventHandler handler) {
28+ this.handler = handler;
29+ this.table = handler.table;
30+ this.columnCount = handler.table.getColumnCount();
31+ }
32+
33+ public void keyTraversed(TraverseEvent e) {
34+ int row = handler.getSelectedRow();
35+ int col = handler.getSelectedCellEditorIndex();
36+
37+ if (e.character == SWT.TAB) {
38+ if ((e.stateMask & SWT.SHIFT) != 0) {
39+ int prevCol = handler.getEditablePrevColumn(col);
40+ handler.editTableElement(row, prevCol);
41+
42+ } else {
43+ int nextCol = handler.getEditableNextColumn(col);
44+ handler.editTableElement(row, nextCol);
45+ }
46+ e.doit = false;
47+ }
48+ }
49+
50+ private void enterEvent(KeyEvent e) throws Exception {
51+ int row = handler.getSelectedRow();
52+ int col = handler.getSelectedCellEditorIndex();
53+ //handler.selectRow(row);
54+ if(handler.table.getItemCount()-1 == row){
55+ handler.editTableElement(row, 0); // 行選択状態にする
56+ }else{
57+ handler.editTableElement(row + 1, col);
58+ }
59+ e.doit = false;
60+ }
61+
62+ private void arrowEvent(KeyEvent e, Text text) throws Exception {
63+ int row = handler.getSelectedRow();
64+ int col = handler.getSelectedCellEditorIndex();
65+ int prevCol = handler.getEditablePrevColumn(col);
66+ int nextCol = handler.getEditableNextColumn(col);
67+ int maxRow = handler.table.getItemCount();
68+ int maxCol = handler.table.getColumnCount();
69+ int caretPostion = text.getCaretPosition();
70+ int carCount = text.getCharCount();
71+ int selectionCount = text.getSelectionCount();
72+ //TableElement element = (TableElement) handler.viewer.getElementAt(row);
73+ switch (e.keyCode) {
74+ case SWT.ARROW_UP:
75+ // if (row > 0) {
76+ if (row >= 0) {
77+ handler.editTableElement(row - 1, col);
78+ e.doit = false;
79+ }
80+ break;
81+ case SWT.ARROW_DOWN:
82+ if (row < maxRow - 1) {
83+ handler.editTableElement(row + 1, col);
84+ e.doit = false;
85+ }
86+ break;
87+ case SWT.ARROW_LEFT:
88+ if (col == 1) {
89+ if (selectionCount == carCount) {
90+ e.doit = false;
91+
92+ } else {
93+ e.doit = true;
94+ }
95+ } else if (col > 1) {
96+ if ((selectionCount == 0 && caretPostion == 0) || selectionCount == carCount) {
97+ handler.editTableElement(row, prevCol);
98+ e.doit = false;
99+ }
100+ } else {
101+ e.doit = false;
102+ }
103+ break;
104+ case SWT.ARROW_RIGHT:
105+ if (col == maxCol - 1) {
106+ if (selectionCount == carCount) {
107+ e.doit = false;
108+
109+ } else {
110+ e.doit = true;
111+ }
112+ } else if (col < maxCol - 1) {
113+ if (selectionCount == carCount || caretPostion == carCount) {
114+ handler.editTableElement(row, nextCol);
115+ e.doit = false;
116+ }
117+ } else {
118+ e.doit = false;
119+ }
120+ break;
121+ default:
122+ break;
123+ }
124+
125+ }
126+
127+ public void keyReleased(KeyEvent e) {
128+ ;
129+ }
130+
131+ public void keyPressed(KeyEvent e) {
132+ Text text = null;
133+ try {
134+ if (e.widget instanceof Text) {
135+ text = (Text) e.widget;
136+
137+ // ENTER
138+ if (e.character == SWT.CR) {
139+ System.out.println("Enter!");
140+ enterEvent(e);
141+
142+ // F2
143+ } else if (e.keyCode == SWT.F2) {
144+ text.clearSelection();
145+
146+ } else if (e.keyCode == SWT.ARROW_UP || e.keyCode == SWT.ARROW_DOWN || e.keyCode == SWT.ARROW_LEFT || e.keyCode == SWT.ARROW_RIGHT) {
147+ arrowEvent(e, text);
148+ }
149+
150+ // CTRL+V
151+ if (e.stateMask == SWT.CTRL && e.keyCode == 118) {
152+ e.doit = false;
153+ }
154+
155+// } else if (e.widget instanceof Button) {
156+// if (e.keyCode == SWT.ARROW_UP || e.keyCode == SWT.ARROW_DOWN || e.keyCode == SWT.ARROW_LEFT || e.keyCode == SWT.ARROW_RIGHT) {
157+// arrowEvent(e);
158+// }
159+
160+
161+ }
162+ } catch (Exception e1) {
163+ DbPlugin.getDefault().showErrorDialog(e1);
164+ }
165+ }
166+
167+// private void arrowEvent(KeyEvent e) throws Exception {
168+// int row = handler.getSelectedRow();
169+// int col = handler.getSelectedCellEditorIndex();
170+// int prevCol = handler.getEditablePrevColumn(col);
171+// int nextCol = handler.getEditableNextColumn(col);
172+// int maxRow = handler.table.getItemCount();
173+// int maxCol = handler.table.getColumnCount();
174+// //TableElement element = (TableElement) handler.viewer.getElementAt(row);
175+// switch (e.keyCode) {
176+// case SWT.ARROW_UP:
177+// // if (row > 0) {
178+// if (row >= 0) {
179+// handler.editTableElement(row - 1, col);
180+// e.doit = false;
181+// }
182+// break;
183+// case SWT.ARROW_DOWN:
184+// if (row < maxRow - 1) {
185+// handler.editTableElement(row + 1, col);
186+// e.doit = false;
187+// }
188+// break;
189+// case SWT.ARROW_LEFT:
190+// if (col == 1) {
191+// e.doit = true;
192+// } else if (col > 1) {
193+// handler.editTableElement(row, prevCol);
194+// e.doit = false;
195+// } else {
196+// e.doit = false;
197+// }
198+// break;
199+// case SWT.ARROW_RIGHT:
200+// if (col == maxCol - 1) {
201+// e.doit = true;
202+// } else if (col < maxCol - 1) {
203+// handler.editTableElement(row, nextCol);
204+// e.doit = false;
205+// } else {
206+// e.doit = false;
207+// }
208+// break;
209+// default:
210+// break;
211+// }
212+//
213+// }
214+}
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
旧リポジトリブラウザで表示