영문으로 보여질때 크기가 올바르지 않는 오류 수정.
[Tadpole.git] / com.hangum.tadpole.rdb.core / src / com / hangum / tadpole / rdb / core / editors / main / parameter / ParameterDialog.java
blob83e13d5396e19d7665d2a5ac438715ad066e2a15
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
7 *
8 * Contributors:
9 * hangum - initial API and implementation
10 ******************************************************************************/
11 package com.hangum.tadpole.rdb.core.editors.main.parameter;
13 import java.util.ArrayList;
14 import java.util.HashMap;
15 import java.util.List;
16 import java.util.Map;
18 import org.apache.commons.lang.StringUtils;
19 import org.apache.log4j.Logger;
20 import org.eclipse.jface.dialogs.Dialog;
21 import org.eclipse.jface.dialogs.IDialogConstants;
22 import org.eclipse.jface.layout.TableColumnLayout;
23 import org.eclipse.jface.viewers.ArrayContentProvider;
24 import org.eclipse.jface.viewers.ColumnPixelData;
25 import org.eclipse.jface.viewers.TableViewer;
26 import org.eclipse.jface.viewers.TableViewerColumn;
27 import org.eclipse.swt.SWT;
28 import org.eclipse.swt.events.SelectionAdapter;
29 import org.eclipse.swt.events.SelectionEvent;
30 import org.eclipse.swt.graphics.Point;
31 import org.eclipse.swt.layout.GridData;
32 import org.eclipse.swt.layout.GridLayout;
33 import org.eclipse.swt.widgets.Composite;
34 import org.eclipse.swt.widgets.Control;
35 import org.eclipse.swt.widgets.Shell;
36 import org.eclipse.swt.widgets.Table;
37 import org.eclipse.swt.widgets.TableColumn;
38 import org.eclipse.swt.widgets.ToolBar;
39 import org.eclipse.swt.widgets.ToolItem;
41 import com.hangum.tadpole.commons.google.analytics.AnalyticCaller;
42 import com.hangum.tadpole.commons.libs.core.define.PublicTadpoleDefine;
43 import com.hangum.tadpole.commons.libs.core.define.PublicTadpoleDefine.PARAMETER_TYPE;
44 import com.hangum.tadpole.commons.libs.core.message.CommonMessages;
45 import com.hangum.tadpole.engine.query.dao.system.UserDBDAO;
46 import com.hangum.tadpole.engine.sql.util.ParameterUtils;
47 import com.hangum.tadpole.engine.sql.util.RDBTypeToJavaTypeUtils;
48 import com.hangum.tadpole.engine.utils.RequestQuery;
49 import com.hangum.tadpole.mongodb.core.dialogs.msg.TadpoleSQLDialog;
50 import com.hangum.tadpole.rdb.core.Messages;
51 import com.hangum.tadpole.rdb.core.editors.main.composite.ResultSetComposite;
53 /**
55 * @author nilriri
57 public class ParameterDialog extends Dialog {
58 private static final Logger logger = Logger.getLogger(ParameterDialog.class);
59 /** 쿼리 실행 후 닫기 버튼 정의 */
60 private int EXECUTE_AND_CLOSE = IDialogConstants.CLIENT_ID + 1;
62 private ResultSetComposite resultSetComposite;
63 private PARAMETER_TYPE parameterType;
64 private RequestQuery reqQuery;
65 private String strSQL;
66 private UserDBDAO userDB;
67 private Map<Integer, String> mapIndex;
68 private List<Map<Integer, Object>> parameters;
70 /**
71 * Create the dialog.
73 * @param parentShell
74 * @param parameterType
75 * @param reqQuery
76 * @wbp.parser.constructor
78 public ParameterDialog(Shell parentShell, ResultSetComposite resultSetComposite, PARAMETER_TYPE parameterType, final RequestQuery reqQuery, final UserDBDAO userDB, final String strSQL, int paramCount) {
79 super(parentShell);
80 setBlockOnOpen(false);
81 setShellStyle(SWT.MAX | SWT.RESIZE | SWT.TITLE);
83 this.resultSetComposite = resultSetComposite;
84 this.parameterType = parameterType;
85 this.reqQuery = reqQuery;
86 this.userDB = userDB;
88 this.strSQL = strSQL;
89 this.makeParamCount(paramCount);
92 public ParameterDialog(Shell parentShell, ResultSetComposite resultSetComposite, PARAMETER_TYPE parameterType, final RequestQuery reqQuery, final UserDBDAO userDB, final String strSQL, final Map<Integer, String> mapIndex) {
93 super(parentShell);
94 setBlockOnOpen(false);
95 setShellStyle(SWT.MAX | SWT.RESIZE | SWT.TITLE);
97 this.resultSetComposite = resultSetComposite;
98 this.parameterType = parameterType;
99 this.reqQuery = reqQuery;
100 this.userDB = userDB;
102 this.strSQL = strSQL;
103 this.mapIndex = mapIndex;
104 this.makeParamCount(mapIndex);
107 @Override
108 protected void configureShell(Shell newShell) {
109 super.configureShell(newShell);
110 newShell.setText(Messages.get().ParameterDialog_0);
114 * Create contents of the dialog.
116 * @param parent
118 @Override
119 protected Control createDialogArea(Composite parent) {
120 Composite container = (Composite) super.createDialogArea(parent);
121 GridLayout gridLayout = (GridLayout) container.getLayout();
122 gridLayout.horizontalSpacing = 2;
123 gridLayout.marginWidth = 5;
124 gridLayout.verticalSpacing = 2;
125 gridLayout.horizontalSpacing = 2;
126 gridLayout.marginWidth = 5;
127 gridLayout.marginHeight = 2;
128 gridLayout.marginWidth = 2;
129 container.setLayout(new GridLayout(1, false));
131 Composite compositeHead = new Composite(container, SWT.NONE);
132 compositeHead.setLayout(new GridLayout(1, false));
134 ToolBar toolBar = new ToolBar(compositeHead, SWT.FLAT | SWT.RIGHT);
136 ToolItem toolItem = new ToolItem(toolBar, SWT.NONE);
137 toolItem.addSelectionListener(new SelectionAdapter() {
138 @Override
139 public void widgetSelected(SelectionEvent e) {
140 TadpoleSQLDialog dialog = new TadpoleSQLDialog(getShell(), Messages.get().ViewQuery, strSQL);
141 dialog.open();
144 toolItem.setText(Messages.get().ViewQuery);
146 Composite compositeBody = new Composite(container, SWT.NONE);
147 compositeBody.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
148 TableColumnLayout tcl_compositeBody = new TableColumnLayout();
149 compositeBody.setLayout(tcl_compositeBody);
151 TableViewer tableViewer = new TableViewer(compositeBody, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
152 Table table = tableViewer.getTable();
153 table.setHeaderVisible(true);
154 table.setLinesVisible(true);
156 createTableColumn(tableViewer, tcl_compositeBody);
158 tableViewer.setContentProvider(ArrayContentProvider.getInstance());
159 tableViewer.setLabelProvider(new ParamLabelProvider());
160 tableViewer.setInput(parameters);
162 // google analytic
163 AnalyticCaller.track(this.getClass().getName());
165 tableViewer.getTable().setFocus();
167 return container;
170 @Override
171 protected void buttonPressed(int buttonId) {
172 if(buttonId == EXECUTE_AND_CLOSE) {
173 executeQuery();
174 return;
176 super.buttonPressed(buttonId);
180 @Override
181 protected void okPressed() {
182 executeQuery();
184 super.okPressed();
188 * 쿼리 실행
190 private void executeQuery() {
191 reqQuery.setSqlStatementType(PublicTadpoleDefine.SQL_STATEMENT_TYPE.PREPARED_STATEMENT);
192 reqQuery.setSql(strSQL);
194 ParameterObject paramObj = getParameterObject();
195 String repSQL = ParameterUtils.fillParameters(reqQuery.getSql(), paramObj.getParameter());
197 reqQuery.setSqlAddParameter(repSQL);
199 if(PARAMETER_TYPE.JAVA_BASIC == parameterType) {
200 reqQuery.setStatementParameter(getParameterObject().getParameter());
201 } else if(PARAMETER_TYPE.ORACLE == parameterType ||
202 PARAMETER_TYPE.MYBATIS_SHARP == parameterType ||
203 PARAMETER_TYPE.MYBATIS_DOLLAR == parameterType
205 reqQuery.setStatementParameter(getOracleParameterObject(mapIndex).getParameter());
208 resultSetComposite._executeQuery(reqQuery);
212 * create table column
214 * @param tableViewer
215 * @param tcl_composite
217 private void createTableColumn(TableViewer tableViewer, TableColumnLayout tcl_composite) {
218 // Not support Eclipse RAP.
219 // This class table course. course is keyboard controls
220 // final TableCursor cursor = new TableCursor(table, SWT.NONE);
222 TableViewerColumn tvcSeq = new TableViewerColumn(tableViewer, SWT.NONE);
223 TableColumn tcSeq = tvcSeq.getColumn();
224 tcl_composite.setColumnData(tcSeq, new ColumnPixelData(30, true, true));
225 tcSeq.setText(Messages.get().ParameterDialog_1);
227 TableViewerColumn tvcName = new TableViewerColumn(tableViewer, SWT.NONE);
228 TableColumn tcName = tvcName.getColumn();
229 tcl_composite.setColumnData(tcName, new ColumnPixelData(150, true, true));
230 tcName.setText(Messages.get().ParameterDialog_2);
232 TableViewerColumn tvcType = new TableViewerColumn(tableViewer, SWT.NONE);
233 TableColumn tcType = tvcType.getColumn();
234 tcl_composite.setColumnData(tcType, new ColumnPixelData(80, true, true));
235 tcType.setText(Messages.get().DataType);
236 tvcType.setEditingSupport(new ParameterEditingSupport(tableViewer, 2, this.userDB, parameters));
238 TableViewerColumn tvcValue = new TableViewerColumn(tableViewer, SWT.NONE);
239 TableColumn tcValue = tvcValue.getColumn();
240 tcl_composite.setColumnData(tcValue, new ColumnPixelData(150, true, true));
241 tcValue.setText(Messages.get().ParameterDialog_4);
242 tvcValue.setEditingSupport(new ParameterEditingSupport(tableViewer, 3, this.userDB, parameters));
246 * Create contents of the button bar.
248 * @param parent
250 @Override
251 protected void createButtonsForButtonBar(Composite parent) {
252 createButton(parent, EXECUTE_AND_CLOSE, Messages.get().ExecuteQuery, true);
253 createButton(parent, IDialogConstants.OK_ID, Messages.get().ExecuteQueryAndClose, false);
254 createButton(parent, IDialogConstants.CANCEL_ID, CommonMessages.get().Close, false);
258 * Return the initial size of the dialog.
260 @Override
261 protected Point getInitialSize() {
262 // 영문에 맞추어 사이즈를 키웠다.
263 return new Point(580, 400);
267 * Return java style parameter
269 * @return
271 private ParameterObject getParameterObject() {
272 ParameterObject param = new ParameterObject();
274 for (Map<Integer, Object> paramE : parameters) {
275 switch (RDBTypeToJavaTypeUtils.getJavaType((String) paramE.get(2))) {
276 case java.sql.Types.INTEGER:
277 param.setObject(Integer.valueOf(paramE.get(3).toString()));
278 break;
279 default:
280 param.setObject(paramE.get(3));
281 break;
284 return param;
288 * Returns oracle styled parameter object
290 * @param mapIndex
291 * @return
293 private ParameterObject getOracleParameterObject(Map<Integer, String> mapIndex) {
294 ParameterObject param = new ParameterObject();
296 for(Integer intKey : mapIndex.keySet()) {
297 String strParamName = mapIndex.get(intKey);
299 for (Map<Integer, Object> mapParam : parameters) {
300 String strTmpParamName = ""+mapParam.get(1); //$NON-NLS-1$
302 if(StringUtils.equals(strParamName, strTmpParamName)) {
303 switch (RDBTypeToJavaTypeUtils.getJavaType((String) mapParam.get(2))) {
304 case java.sql.Types.INTEGER:
305 param.setObject(Integer.valueOf(mapParam.get(3).toString()));
306 break;
307 default:
308 param.setObject(mapParam.get(3));
309 break;
312 // 파라미터 이름이 동일할 경우 하나만 설정되도록 수정.
313 break;
319 return param;
324 * java type
326 * @param paramCount
328 private void makeParamCount(int paramCount) {
329 parameters = new ArrayList<Map<Integer, Object>>();
330 for (int i = 0; i < paramCount; i++) {
331 Map<Integer, Object> map = new HashMap<Integer, Object>();
332 map.put(0, (i + 1));
333 map.put(1, "Param" + (i + 1)); //$NON-NLS-1$
334 map.put(2, RDBTypeToJavaTypeUtils.supportParameterTypes(userDB)[0]);
335 map.put(3, ""); //$NON-NLS-1$
337 parameters.add(map);
342 * oracel type
344 * @param mapIndex
346 private void makeParamCount(Map<Integer, String> mapIndex) {
348 parameters = new ArrayList<Map<Integer, Object>>();
349 // int i = 0;
350 // for (String strKey : mapIndex.keySet()) {
351 for(int i=0; i<mapIndex.size(); i++) {
352 String strKey = mapIndex.get(i+1);
353 Map<Integer, Object> map = new HashMap<Integer, Object>();
354 map.put(0, (i+ + 1));
355 map.put(1, strKey);
356 map.put(2, RDBTypeToJavaTypeUtils.supportParameterTypes(userDB)[0]);
357 map.put(3, ""); //$NON-NLS-1$
359 parameters.add(map);
365 * table dao
367 * @return
369 private List<Map<Integer, Object>> getParameters() {
370 return parameters;