1 /*******************************************************************************
2 * Copyright (c) 2013 hangum.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the GNU Lesser Public License v2.1
5 * which accompanies this distribution, and is available at
6 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
9 * hangum - initial API and implementation
10 ******************************************************************************/
11 package com
.hangum
.tadpole
.preference
.ui
;
13 import org
.apache
.commons
.lang
.math
.NumberUtils
;
14 import org
.apache
.log4j
.Logger
;
15 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
16 import org
.eclipse
.swt
.SWT
;
17 import org
.eclipse
.swt
.events
.ModifyEvent
;
18 import org
.eclipse
.swt
.events
.ModifyListener
;
19 import org
.eclipse
.swt
.events
.SelectionAdapter
;
20 import org
.eclipse
.swt
.events
.SelectionEvent
;
21 import org
.eclipse
.swt
.graphics
.FontData
;
22 import org
.eclipse
.swt
.layout
.GridData
;
23 import org
.eclipse
.swt
.layout
.GridLayout
;
24 import org
.eclipse
.swt
.widgets
.Button
;
25 import org
.eclipse
.swt
.widgets
.Combo
;
26 import org
.eclipse
.swt
.widgets
.Composite
;
27 import org
.eclipse
.swt
.widgets
.Control
;
28 import org
.eclipse
.swt
.widgets
.FontDialog
;
29 import org
.eclipse
.swt
.widgets
.Label
;
30 import org
.eclipse
.swt
.widgets
.Text
;
31 import org
.eclipse
.ui
.IWorkbench
;
32 import org
.eclipse
.ui
.IWorkbenchPreferencePage
;
34 import com
.hangum
.tadpole
.commons
.google
.analytics
.AnalyticCaller
;
35 import com
.hangum
.tadpole
.commons
.libs
.core
.define
.PublicTadpoleDefine
;
36 import com
.hangum
.tadpole
.commons
.libs
.core
.define
.TadpoleProperties
;
37 import com
.hangum
.tadpole
.commons
.libs
.core
.message
.CommonMessages
;
38 import com
.hangum
.tadpole
.engine
.query
.sql
.TadpoleSystem_UserInfoData
;
39 import com
.hangum
.tadpole
.preference
.Messages
;
40 import com
.hangum
.tadpole
.preference
.define
.PreferenceDefine
;
41 import com
.hangum
.tadpole
.preference
.get
.GetPreferenceGeneral
;
42 import com
.hangum
.tadpole
.preference
.internal
.TadpoleSimpleMessageDialog
;
43 import com
.hangum
.tadpole
.session
.manager
.SessionManager
;
51 public class RDBPreferencePage
extends TadpoleDefaulPreferencePage
implements IWorkbenchPreferencePage
{
52 private static final Logger logger
= Logger
.getLogger(RDBPreferencePage
.class);
54 private Combo comboRDBNumberComma
;
55 private Text textSelectLimit
;
56 private Text textResultPage
;
57 private Text textNull
;
58 private Label lblUserFont
;
60 private Text textQueryTimeout
;
61 private Text textCommitCount
;
62 private Text textShowInTheColumn
;
64 private Combo comboResultHeadClick
;
66 private Text textOraclePlan
;
68 public RDBPreferencePage() {
72 public void init(IWorkbench workbench
) {
76 protected Control
createContents(Composite parent
) {
78 Composite container
= new Composite(parent
, SWT
.NULL
);
79 container
.setLayout(new GridLayout(2, false));
81 Label lblBasic
= new Label(container
, SWT
.NONE
);
82 lblBasic
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
83 lblBasic
.setText(Messages
.get().General
);
85 Label labelBasic
= new Label(container
, SWT
.SEPARATOR
| SWT
.HORIZONTAL
);
86 labelBasic
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
88 Label lblNumberColumnAdd
= new Label(container
, SWT
.NONE
);
89 lblNumberColumnAdd
.setText(Messages
.get().RDBPreferencePage_lblNumberColumnAdd_text
);
91 comboRDBNumberComma
= new Combo(container
, SWT
.READ_ONLY
);
92 comboRDBNumberComma
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
93 comboRDBNumberComma
.add(PublicTadpoleDefine
.YES_NO
.YES
.name());
94 comboRDBNumberComma
.add(PublicTadpoleDefine
.YES_NO
.NO
.name());
95 comboRDBNumberComma
.select(0);
97 Label lblNewLabel
= new Label(container
, SWT
.NONE
);
98 lblNewLabel
.setText(Messages
.get().MaxNumOfRowsBySelect
);
100 textSelectLimit
= new Text(container
, SWT
.BORDER
);
101 textSelectLimit
.addModifyListener(new ModifyListener() {
102 public void modifyText(ModifyEvent event
) {
106 textSelectLimit
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
108 Label lblNewLabel_1
= new Label(container
, SWT
.NONE
);
109 lblNewLabel_1
.setText(Messages
.get().RowsPerPage
);
111 textResultPage
= new Text(container
, SWT
.BORDER
);
112 textResultPage
.addModifyListener(new ModifyListener() {
113 public void modifyText(ModifyEvent event
) {
117 textResultPage
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
119 Label lblNull
= new Label(container
, SWT
.NONE
);
120 lblNull
.setText(Messages
.get().ShowNullCharacters
);
122 textNull
= new Text(container
, SWT
.BORDER
);
123 textNull
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
125 Label lblResultViewFont
= new Label(container
, SWT
.NONE
);
126 lblResultViewFont
.setText(Messages
.get().FontForResultPages
);
128 Composite compositeFont
= new Composite(container
, SWT
.NONE
);
129 compositeFont
.setLayout(new GridLayout(2, false));
130 compositeFont
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
132 lblUserFont
= new Label(compositeFont
, SWT
.NONE
);
133 lblUserFont
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
134 lblUserFont
.setText("");
136 Button btnNewButton
= new Button(compositeFont
, SWT
.NONE
);
137 btnNewButton
.addSelectionListener(new SelectionAdapter() {
139 public void widgetSelected(SelectionEvent e
) {
143 btnNewButton
.setText(Messages
.get().Font
);
145 Label lblQueryTimeout
= new Label(container
, SWT
.NONE
);
146 lblQueryTimeout
.setText(Messages
.get().QueryTimeout
);
148 textQueryTimeout
= new Text(container
, SWT
.BORDER
);
149 textQueryTimeout
.addModifyListener(new ModifyListener() {
150 public void modifyText(ModifyEvent event
) {
154 textQueryTimeout
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
156 Label lblCommitCount
= new Label(container
, SWT
.NONE
);
157 lblCommitCount
.setText(Messages
.get().BatchSize
);
159 textCommitCount
= new Text(container
, SWT
.BORDER
);
160 textCommitCount
.setText(Integer
.toString(TadpoleProperties
.ROWS_PER_PAGE_DEF
));
161 textCommitCount
.addModifyListener(new ModifyListener() {
162 public void modifyText(ModifyEvent event
) {
166 textCommitCount
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
168 Label lblCharacterShownIn
= new Label(container
, SWT
.NONE
);
169 lblCharacterShownIn
.setText(Messages
.get().MaximumNumberOfCharactersPerColumn
);
171 textShowInTheColumn
= new Text(container
, SWT
.BORDER
);
172 textShowInTheColumn
.setText(Messages
.get().RDBPreferencePage_text_text_1
);
173 textShowInTheColumn
.addModifyListener(new ModifyListener() {
174 public void modifyText(ModifyEvent event
) {
178 textShowInTheColumn
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
180 Label labelClickResultHead
= new Label(container
, SWT
.NONE
);
181 labelClickResultHead
.setText(Messages
.get().WhenClickingOnColumnName
);
183 comboResultHeadClick
= new Combo(container
, SWT
.READ_ONLY
);
184 comboResultHeadClick
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
185 comboResultHeadClick
.add(Messages
.get().SortData
);
186 comboResultHeadClick
.add(Messages
.get().CopyColumnNameToEditor
);
187 comboResultHeadClick
.select(1);
189 Label lblOracleBar
= new Label(container
, SWT
.NONE
);
190 lblOracleBar
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
191 lblOracleBar
.setText("Oracle");
193 Label lblOracle
= new Label(container
, SWT
.SEPARATOR
| SWT
.HORIZONTAL
);
194 lblOracle
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
196 Label lblNewLabel_2
= new Label(container
, SWT
.NONE
);
197 lblNewLabel_2
.setText(Messages
.get().OraclePlanTable
);
199 Composite compositeOraclePlan
= new Composite(container
, SWT
.NONE
);
200 compositeOraclePlan
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
201 compositeOraclePlan
.setLayout(new GridLayout(2, false));
203 textOraclePlan
= new Text(compositeOraclePlan
, SWT
.BORDER
);
204 textOraclePlan
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
206 Button btnCreatePlanTable
= new Button(compositeOraclePlan
, SWT
.NONE
);
207 btnCreatePlanTable
.addSelectionListener(new SelectionAdapter() {
209 public void widgetSelected(SelectionEvent e
) {
210 TadpoleSimpleMessageDialog planDialog
= new TadpoleSimpleMessageDialog(getShell(), Messages
.get().PleaseCreateOraclePlanTable
, String
.format(ORACLE_PLAN_TABLE
, textOraclePlan
.getText()));
214 btnCreatePlanTable
.setText(Messages
.get().CreatePlanTable
);
215 textOraclePlan
.addModifyListener(new ModifyListener() {
216 public void modifyText(ModifyEvent event
) {
224 AnalyticCaller
.track(this.getClass().getName());
232 private void setFontData() {
233 FontDialog fd
= new FontDialog(getShell(), SWT
.NONE
);
234 FontData fdFont
= fd
.open();
236 lblUserFont
.setText(fdFont
.getName()+"|"+fdFont
.getHeight()+"|"+fdFont
.getStyle());
241 public boolean isValid() {
242 String txtSelectLimit
= textSelectLimit
.getText();
243 String txtResultPage
= textResultPage
.getText();
244 String txtQueryTimtout
= textQueryTimeout
.getText();
245 String txtOraclePlan
= textOraclePlan
.getText();
246 String txtCommitCount
= textCommitCount
.getText();
247 String txtShownInTheColumn
= textShowInTheColumn
.getText();
249 if(!NumberUtils
.isNumber(txtSelectLimit
)) {
250 textSelectLimit
.setFocus();
252 setErrorMessage(String
.format(CommonMessages
.get().EnterNumbersOnlyWithItem
, Messages
.get().MaxNumOfRowsBySelect
));
254 } else if(!((NumberUtils
.toInt(txtSelectLimit
) >= TadpoleProperties
.NUMBER_OF_ROWS_BY_SELECT_MIN
)
255 && (NumberUtils
.toInt(txtSelectLimit
) <= TadpoleProperties
.NUMBER_OF_ROWS_BY_SELECT_MAX
))) {
256 textSelectLimit
.setFocus();
259 setErrorMessage(String
.format(CommonMessages
.get().InvalidRange_GEAndLEWithItem
,
260 Messages
.get().MaxNumOfRowsBySelect
,
261 TadpoleProperties
.NUMBER_OF_ROWS_BY_SELECT_MIN
,
262 TadpoleProperties
.NUMBER_OF_ROWS_BY_SELECT_MAX
));
264 } else if(!NumberUtils
.isNumber(txtResultPage
)) {
265 textResultPage
.setFocus();
267 setErrorMessage(String
.format(CommonMessages
.get().EnterNumbersOnlyWithItem
, Messages
.get().RowsPerPage
));
269 } else if(!((NumberUtils
.toInt(txtResultPage
) >= TadpoleProperties
.ROWS_PER_PAGE_MIN
)
270 && (NumberUtils
.toInt(txtResultPage
) <= TadpoleProperties
.ROWS_PER_PAGE_MAX
))) {
271 textResultPage
.setFocus();
274 setErrorMessage(String
.format(CommonMessages
.get().InvalidRange_GEAndLEWithItem
,
275 Messages
.get().RowsPerPage
,
276 TadpoleProperties
.ROWS_PER_PAGE_MIN
,
277 TadpoleProperties
.ROWS_PER_PAGE_MAX
));
279 } else if(!NumberUtils
.isNumber(txtQueryTimtout
)) {
280 textQueryTimeout
.setFocus();
283 setErrorMessage(Messages
.get().QueryTimeout
+ CommonMessages
.get().EnterNumbersOnlyWithItem
);
285 } else if(!((NumberUtils
.toInt(txtQueryTimtout
) >= TadpoleProperties
.QUERY_TIMEOUT_MIN
)
286 && (NumberUtils
.toInt(txtQueryTimtout
) <= TadpoleProperties
.QUERY_TIMEOUT_MAX
))) {
287 textQueryTimeout
.setFocus();
290 setErrorMessage(String
.format(CommonMessages
.get().InvalidRange_GEAndLEWithItem
,
291 Messages
.get().QueryTimeout
,
292 TadpoleProperties
.QUERY_TIMEOUT_MIN
,
293 TadpoleProperties
.QUERY_TIMEOUT_MAX
));
295 } else if(!NumberUtils
.isNumber(txtCommitCount
)) {
296 textCommitCount
.setFocus();
299 setErrorMessage(String
.format(CommonMessages
.get().EnterNumbersOnlyWithItem
, Messages
.get().BatchSize
));
301 } else if(!((NumberUtils
.toInt(txtCommitCount
) >= TadpoleProperties
.BATCH_SIZE_MIN
)
302 && (NumberUtils
.toInt(txtCommitCount
) <= TadpoleProperties
.BATCH_SIZE_MAX
))) {
303 textCommitCount
.setFocus();
306 setErrorMessage(String
.format(CommonMessages
.get().InvalidRange_GEAndLEWithItem
,
307 Messages
.get().BatchSize
,
308 TadpoleProperties
.BATCH_SIZE_MIN
,
309 TadpoleProperties
.BATCH_SIZE_MAX
));
311 } else if(!NumberUtils
.isNumber(txtShownInTheColumn
)) {
312 textShowInTheColumn
.setFocus();
315 setErrorMessage(String
.format(CommonMessages
.get().EnterNumbersOnlyWithItem
, Messages
.get().BatchSize
));
317 // } else if(!((NumberUtils.toInt(txtShownInTheColumn) >= TadpoleProperties.NUMBER_OF_CHARACTERS_PER_COLUMN_MIN)
318 // && (NumberUtils.toInt(txtShownInTheColumn) <= TadpoleProperties.NUMBER_OF_CHARACTERS_PER_COLUMN_MAX))) {
319 // textShowInTheColumn.setFocus();
322 // setErrorMessage(String.format(WarningMessages.get().InvalidRange_GEAndLEWithItem,
323 // Messages.get().MaximumNumberOfCharactersPerColumn,
324 // TadpoleProperties.NUMBER_OF_CHARACTERS_PER_COLUMN_MIN,
325 // TadpoleProperties.NUMBER_OF_CHARACTERS_PER_COLUMN_MAX));
327 } else if("".equals(txtOraclePlan
)) { //$NON-NLS-1$
330 setErrorMessage(Messages
.get().RDBPreferencePage_3
);
334 setErrorMessage(null);
341 public boolean performOk() {
342 if(PublicTadpoleDefine
.YES_NO
.NO
.name().equals(SessionManager
.getIsModifyPerference())) {
343 MessageDialog
.openWarning(null, CommonMessages
.get().Warning
, CommonMessages
.get().CantModifyPreferenc
);
346 if(!isValid()) return false;
348 String txtSelectLimit
= textSelectLimit
.getText();
349 String txtResultPage
= textResultPage
.getText();
350 String txtNull
= textNull
.getText();
351 String txtQueryTimtout
= textQueryTimeout
.getText();
352 String txtOraclePlan
= textOraclePlan
.getText();
353 String txtRDBNumberColumnIsComman
= comboRDBNumberComma
.getText();
354 String txtFontInfo
= lblUserFont
.getText();
355 String txtCommitCount
= textCommitCount
.getText();
356 String txtShownInTheColumn
= textShowInTheColumn
.getText();
358 String txtResultHeadClick
= PreferenceDefine
.RDB_RESULT_SET_HEAD_CLICK_SORTDATA_VALUE
;
359 if(comboResultHeadClick
.getSelectionIndex() == 1) {
360 txtResultHeadClick
= PreferenceDefine
.RDB_RESULT_SET_HEAD_CLICK_COPYCOLUMNNAME_VALUE
;
365 TadpoleSystem_UserInfoData
.updateRDBUserInfoData(
366 txtSelectLimit
, txtResultPage
, txtQueryTimtout
, txtOraclePlan
, txtRDBNumberColumnIsComman
, txtFontInfo
, txtCommitCount
, txtShownInTheColumn
, txtResultHeadClick
, txtNull
);
368 // session 데이터를 수정한다.
369 SessionManager
.setUserInfo(PreferenceDefine
.SELECT_LIMIT_COUNT
, txtSelectLimit
);
370 SessionManager
.setUserInfo(PreferenceDefine
.SELECT_RESULT_PAGE_PREFERENCE
, txtResultPage
);
371 SessionManager
.setUserInfo(PreferenceDefine
.RDB_RESULT_NULL
, txtNull
);
372 SessionManager
.setUserInfo(PreferenceDefine
.SELECT_QUERY_TIMEOUT
, txtQueryTimtout
);
374 SessionManager
.setUserInfo(PreferenceDefine
.ORACLE_PLAN_TABLE
, txtOraclePlan
);
375 SessionManager
.setUserInfo(PreferenceDefine
.RDB_RESULT_NUMBER_IS_COMMA
, txtRDBNumberColumnIsComman
);
376 SessionManager
.setUserInfo(PreferenceDefine
.RDB_RESULT_FONT
, txtFontInfo
);
377 SessionManager
.setUserInfo(PreferenceDefine
.RDB_COMMIT_COUNT
, txtCommitCount
);
378 SessionManager
.setUserInfo(PreferenceDefine
.RDB_CHARACTER_SHOW_IN_THE_COLUMN
, txtShownInTheColumn
);
379 SessionManager
.setUserInfo(PreferenceDefine
.RDB_RESULT_SET_HEAD_CLICK
, txtResultHeadClick
);
381 } catch(Exception e
) {
382 logger
.error("RDBPreference saveing", e
);
384 MessageDialog
.openError(getShell(), CommonMessages
.get().Confirm
, Messages
.get().RDBPreferencePage_5
+ e
.getMessage()); //$NON-NLS-1$
388 return super.performOk();
392 public boolean performCancel() {
395 return super.performCancel();
399 protected void performApply() {
401 super.performApply();
405 protected void performDefaults() {
408 super.performDefaults();
414 private void initDefaultValue() {
415 textSelectLimit
.setText( "" + GetPreferenceGeneral
.getSelectLimitCount() ); //$NON-NLS-1$
416 textNull
.setText(GetPreferenceGeneral
.getResultNull());
417 textResultPage
.setText( "" + GetPreferenceGeneral
.getPageCount() ); //$NON-NLS-1$
418 textQueryTimeout
.setText( "" + GetPreferenceGeneral
.getQueryTimeOut() );
420 textOraclePlan
.setText( GetPreferenceGeneral
.getPlanTableName() );
421 comboRDBNumberComma
.setText(GetPreferenceGeneral
.getRDBNumberISComma());
423 textCommitCount
.setText(GetPreferenceGeneral
.getRDBCommitCount());
425 String strFontInfo
= GetPreferenceGeneral
.getRDBResultFont();
426 lblUserFont
.setText(strFontInfo
);
428 textShowInTheColumn
.setText(""+GetPreferenceGeneral
.getRDBShowInTheColumn());
430 if(PreferenceDefine
.RDB_RESULT_SET_HEAD_CLICK_SORTDATA_VALUE
.equals(GetPreferenceGeneral
.getRDBResultHeadClick())) {
431 comboResultHeadClick
.select(0);
433 comboResultHeadClick
.select(1);
437 /** ORACLE PLAN TABLE */
438 private static final String ORACLE_PLAN_TABLE
=
439 " CREATE TABLE %s ( \r\n" +
440 " STATEMENT_ID VARCHAR2(30), \r\n" +
441 " plan_id NUMBER, \r\n" +
442 " TIMESTAMP DATE, \r\n" +
443 " remarks VARCHAR2(4000), \r\n" +
444 " operation VARCHAR2(30), \r\n" +
445 " options VARCHAR2(255), \r\n" +
446 " object_node VARCHAR2(128), \r\n" +
447 " object_owner VARCHAR2(30), \r\n" +
448 " object_name VARCHAR2(30), \r\n" +
449 " object_alias VARCHAR2(65), \r\n" +
450 " object_instance NUMERIC, \r\n" +
451 " object_type VARCHAR2(30), \r\n" +
452 " optimizer VARCHAR2(255), \r\n" +
453 " search_columns NUMBER, \r\n" +
454 " ID NUMERIC, \r\n" +
455 " parent_id NUMERIC, \r\n" +
456 " DEPTH NUMERIC, \r\n" +
457 " POSITION NUMERIC, \r\n" +
458 " COST NUMERIC, \r\n" +
459 " CARDINALITY NUMERIC, \r\n" +
460 " BYTES NUMERIC, \r\n" +
461 " other_tag VARCHAR2(255), \r\n" +
462 " partition_start VARCHAR2(255), \r\n" +
463 " partition_stop VARCHAR2(255), \r\n" +
464 " partition_id NUMERIC, \r\n" +
465 " other LONG, \r\n" +
466 " distribution VARCHAR2(30), \r\n" +
467 " cpu_cost NUMERIC, \r\n" +
468 " io_cost NUMERIC, \r\n" +
469 " temp_space NUMERIC, \r\n" +
470 " access_predicates VARCHAR2(4000), \r\n" +
471 " filter_predicates VARCHAR2(4000), \r\n" +
472 " projection VARCHAR2(4000), \r\n" +
473 " TIME NUMERIC, \r\n" +
474 " qblock_name VARCHAR2(30) \r\n" +