동작하는 프러덕이 db hub일 경우만 화면에 출력되도록 개선.
[Tadpole.git] / com.hangum.tadpole.rdb.core / src / com / hangum / tadpole / rdb / core / editors / main / MainEditor.java
blob084e8c5568b62c97e06869e6aa3c10d3f8bcc911
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;
13 import java.sql.Connection;
14 import java.sql.Statement;
15 import java.util.HashMap;
16 import java.util.Map;
18 import org.apache.commons.lang.StringUtils;
19 import org.apache.log4j.Logger;
20 import org.eclipse.core.runtime.IProgressMonitor;
21 import org.eclipse.core.runtime.IStatus;
22 import org.eclipse.core.runtime.Status;
23 import org.eclipse.jface.dialogs.Dialog;
24 import org.eclipse.jface.dialogs.MessageDialog;
25 import org.eclipse.jface.util.IPropertyChangeListener;
26 import org.eclipse.jface.util.PropertyChangeEvent;
27 import org.eclipse.jface.window.Window;
28 import org.eclipse.swt.SWT;
29 import org.eclipse.swt.SWTException;
30 import org.eclipse.swt.browser.Browser;
31 import org.eclipse.swt.browser.ProgressEvent;
32 import org.eclipse.swt.browser.ProgressListener;
33 import org.eclipse.swt.custom.SashForm;
34 import org.eclipse.swt.events.SelectionAdapter;
35 import org.eclipse.swt.events.SelectionEvent;
36 import org.eclipse.swt.layout.GridData;
37 import org.eclipse.swt.layout.GridLayout;
38 import org.eclipse.swt.widgets.Combo;
39 import org.eclipse.swt.widgets.Composite;
40 import org.eclipse.swt.widgets.ToolBar;
41 import org.eclipse.swt.widgets.ToolItem;
42 import org.eclipse.ui.IEditorInput;
43 import org.eclipse.ui.IEditorSite;
44 import org.eclipse.ui.PartInitException;
45 import org.eclipse.ui.PlatformUI;
47 import com.hangum.tadpole.ace.editor.core.dialogs.help.RDBShortcutHelpDialog;
48 import com.hangum.tadpole.ace.editor.core.texteditor.EditorExtension;
49 import com.hangum.tadpole.ace.editor.core.texteditor.function.EditorFunctionService;
50 import com.hangum.tadpole.ace.editor.core.texteditor.function.IEditorFunction;
51 import com.hangum.tadpole.commons.dialogs.fileupload.SingleFileuploadDialog;
52 import com.hangum.tadpole.commons.exception.dialog.ExceptionDetailsErrorDialog;
53 import com.hangum.tadpole.commons.google.analytics.AnalyticCaller;
54 import com.hangum.tadpole.commons.libs.core.define.PublicTadpoleDefine;
55 import com.hangum.tadpole.commons.libs.core.define.PublicTadpoleDefine.OBJECT_TYPE;
56 import com.hangum.tadpole.commons.libs.core.define.PublicTadpoleDefine.PRODUCT_TYPE;
57 import com.hangum.tadpole.commons.libs.core.define.PublicTadpoleDefine.RESULT_COMP_TYPE;
58 import com.hangum.tadpole.commons.libs.core.message.CommonMessages;
59 import com.hangum.tadpole.commons.util.RequestInfoUtils;
60 import com.hangum.tadpole.commons.util.ShortcutPrefixUtils;
61 import com.hangum.tadpole.engine.define.DBGroupDefine;
62 import com.hangum.tadpole.engine.manager.AbstractTadpoleManager;
63 import com.hangum.tadpole.engine.manager.TadpoleSQLManager;
64 import com.hangum.tadpole.engine.manager.TadpoleSQLTransactionManager;
65 import com.hangum.tadpole.engine.query.dao.system.UserDBDAO;
66 import com.hangum.tadpole.engine.query.dao.system.UserDBResourceDAO;
67 import com.hangum.tadpole.engine.query.sql.DBSystemSchema;
68 import com.hangum.tadpole.engine.query.sql.TadpoleSystem_UserDBResource;
69 import com.hangum.tadpole.engine.sql.dialog.save.ResourceSaveDialog;
70 import com.hangum.tadpole.engine.sql.util.SQLUtil;
71 import com.hangum.tadpole.engine.utils.EditorDefine;
72 import com.hangum.tadpole.engine.utils.RequestQuery;
73 import com.hangum.tadpole.preference.define.GetAdminPreference;
74 import com.hangum.tadpole.preference.define.PreferenceDefine;
75 import com.hangum.tadpole.preference.get.GetPreferenceGeneral;
76 import com.hangum.tadpole.rdb.core.Activator;
77 import com.hangum.tadpole.rdb.core.Messages;
78 import com.hangum.tadpole.rdb.core.dialog.db.DBInformationDialog;
79 import com.hangum.tadpole.rdb.core.dialog.db.UserDBGroupDialog;
80 import com.hangum.tadpole.rdb.core.dialog.export.sqltoapplication.SQLToStringDialog;
81 import com.hangum.tadpole.rdb.core.dialog.restfulapi.MainSQLEditorAPIServiceDialog;
82 import com.hangum.tadpole.rdb.core.editors.main.composite.ResultMainComposite;
83 import com.hangum.tadpole.rdb.core.editors.main.function.MainEditorBrowserFunctionService;
84 import com.hangum.tadpole.rdb.core.editors.main.utils.ExtMakeContentAssistUtil;
85 import com.hangum.tadpole.rdb.core.extensionpoint.definition.IMainEditorExtension;
86 import com.hangum.tadpole.rdb.core.extensionpoint.handler.MainEditorContributionsHandler;
87 import com.hangum.tadpole.rdb.core.util.DialogUtil;
88 import com.hangum.tadpole.rdb.core.util.EditorUtils;
89 import com.hangum.tadpole.rdb.core.util.FindEditorAndWriteQueryUtil;
90 import com.hangum.tadpole.rdb.core.viewers.connections.DBIconsUtils;
91 import com.hangum.tadpole.rdb.core.viewers.object.ExplorerViewer;
92 import com.hangum.tadpole.rdb.core.viewers.object.sub.utils.TadpoleObjectQuery;
93 import com.hangum.tadpole.sql.format.SQLFormater;
94 import com.swtdesigner.ResourceManager;
96 /**
97 * 쿼리 수행 및 검색 창.
99 * @author hangum
102 public class MainEditor extends EditorExtension {
103 /** Editor ID. */
104 public static final String ID = "com.hangum.tadpole.rdb.core.editor.main"; //$NON-NLS-1$
105 /** Logger for this class. */
106 private static final Logger logger = Logger.getLogger(MainEditor.class);
109 * MySQL 그룹은 스키마를 콤보박스
111 protected Combo comboSchema;
113 /** connection URL */
114 private ToolItem tltmConnectURL;
116 /** auto save를 위해 마지막 콘텐츠 를 남겨 놓는다. */
117 private String strLastContent = "";
119 /** toolbar auto commit */
120 private ToolItem tiAutoCommit = null, tiAutoCommitCommit = null, tiAutoCommitRollback = null, tltmTextResultView = null;
121 private PublicTadpoleDefine.RESULT_COMP_TYPE resultViewType = RESULT_COMP_TYPE.Table;
123 /** result tab */
124 protected ResultMainComposite resultMainComposite;
126 /** edior가 초기화 될때 처음 로드 되어야 하는 String. */
127 protected String initDefaultEditorStr = ""; //$NON-NLS-1$
129 /** 현재 editor가 열린 상태. 즉 table, view, index 등의 상태. */
130 protected OBJECT_TYPE dbAction;
132 /** resource 정보. */
133 protected UserDBResourceDAO dBResource;
134 /** 자동 저장 auto save */
135 protected UserDBResourceDAO dBResourceAuto;
137 /** save mode */
138 protected boolean isDirty = false;
140 /** short cut prefix */
141 protected static final String STR_SHORT_CUT_PREFIX = ShortcutPrefixUtils.getCtrlShortcut();
143 protected SashForm sashFormExtension;
144 protected IMainEditorExtension[] compMainExtions;
146 public MainEditor() {
147 super();
150 @Override
151 public void init(IEditorSite site, IEditorInput input) throws PartInitException {
152 MainEditorInput qei = (MainEditorInput)input;
153 try {
154 userDB = (UserDBDAO)qei.getUserDB().clone();
155 } catch(Exception e) {
156 logger.error("set define default userDB", e);
159 initDefaultEditorStr = qei.getDefaultStr();
160 strLastContent = qei.getDefaultStr();
161 dbAction = qei.getDbAction();
163 String strPartName = qei.getName();
164 dBResource = qei.getResourceDAO();
165 if(dBResource != null) {
166 strPartName = dBResource.getName();
167 } else {
168 // 기본 저장된 쿼리가 있는지 가져온다.
169 try {
170 dBResourceAuto = TadpoleSystem_UserDBResource.getDefaultDBResourceData(userDB);
171 if(dBResourceAuto != null) {
172 if(!StringUtils.isEmpty(dBResourceAuto.getDataString())) {
173 if(DBGroupDefine.MYSQL_GROUP == userDB.getDBGroup()) {
174 initDefaultEditorStr = dBResourceAuto.getDataString() + Messages.get().AutoRecoverMsg_mysql + initDefaultEditorStr;
175 } else {
176 initDefaultEditorStr = dBResourceAuto.getDataString() + Messages.get().AutoRecoverMsg + initDefaultEditorStr;
180 } catch(Exception e) {
181 logger.error("Get default resource", e);
184 strLastContent = initDefaultEditorStr;
186 strRoleType = userDB.getRole_id();
187 super.setUserType(strRoleType);
189 // schema 변경
191 setSite(site);
192 setInput(input);
193 setPartName(strPartName);
195 setTitleImage(DBIconsUtils.getEditorImage(getUserDB()));
198 @Override
199 public boolean isDirty() {
200 return isDirty;
203 @Override
204 public boolean isSaveAsAllowed() {
205 if(dBResource == null) return false;
206 else return true;
209 @Override
210 public void createPartControl(Composite parent) {
211 GridLayout gl_parent = new GridLayout(1, false);
212 gl_parent.verticalSpacing = 2;
213 gl_parent.horizontalSpacing = 2;
214 gl_parent.marginHeight = 2;
215 gl_parent.marginWidth = 2;
216 parent.setLayout(gl_parent);
218 // 에디터 확장을 위한 기본 베이스 위젲을 설정합니다.
219 sashFormExtension = new SashForm(parent, SWT.NONE);
220 sashFormExtension.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
222 SashForm sashForm = new SashForm(sashFormExtension, SWT.VERTICAL);
223 sashForm.setSashWidth(4);
224 sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
226 final Composite compositeEditor = new Composite(sashForm, SWT.NONE);
227 GridLayout gl_compositeEditor = new GridLayout(3, false);
228 gl_compositeEditor.verticalSpacing = 0;
229 gl_compositeEditor.horizontalSpacing = 0;
230 gl_compositeEditor.marginHeight = 0;
231 gl_compositeEditor.marginWidth = 0;
232 compositeEditor.setLayout(gl_compositeEditor);
234 ToolBar toolBar = new ToolBar(compositeEditor, SWT.NONE | SWT.FLAT | SWT.RIGHT);
235 tltmConnectURL = new ToolItem(toolBar, SWT.NONE);
236 tltmConnectURL.setToolTipText(Messages.get().DatabaseInformation);
237 tltmConnectURL.setImage(ResourceManager.getPluginImage(Activator.PLUGIN_ID, "resources/icons/editor/connect.png")); //$NON-NLS-1$
238 initConnectionInfo();
240 tltmConnectURL.addSelectionListener(new SelectionAdapter() {
241 @Override
242 public void widgetSelected(SelectionEvent e) {
243 DBInformationDialog dialog = new DBInformationDialog(getSite().getShell(), userDB);
244 dialog.open();
245 setFocus();
249 // 패스워드를 물어야 하면 화면에서 보이지 않도록 수정.
250 if(PublicTadpoleDefine.YES_NO.NO.name().equals(GetAdminPreference.getConnectionAskType())) {
251 final ToolItem tltmSelectDB = new ToolItem(toolBar, SWT.NONE);
252 tltmSelectDB.setToolTipText(Messages.get().SelectOthersDB);
253 tltmSelectDB.setImage(ResourceManager.getPluginImage(Activator.PLUGIN_ID, "resources/icons/editor/arrow_down.png")); //$NON-NLS-1$
254 tltmSelectDB.addSelectionListener(new SelectionAdapter() {
255 @Override
256 public void widgetSelected(SelectionEvent e) {
257 if(!isAutoCommit()) {
258 MessageDialog.openWarning(getSite().getShell(), CommonMessages.get().Warning, Messages.get().PleaseEndedTransaction);
259 } else {
261 UserDBGroupDialog dialog = new UserDBGroupDialog(getSite().getShell(), userDB);
262 if(Dialog.OK == dialog.open()) {
263 UserDBDAO selectedUserDB = dialog.getUserDB();
264 if(selectedUserDB != null) {
265 userDB = selectedUserDB;
267 try {
268 TadpoleObjectQuery.getTableList(userDB);
269 } catch (Exception e1) {
270 logger.error("get table list", e1);
273 initConnectionInfo();
275 comboSchema.removeAll();
276 // if mysql db listup schema list
277 if(userDB.getDBGroup() == DBGroupDefine.MYSQL_GROUP){
278 try {
279 for (Object object : DBSystemSchema.getSchemas(userDB)) {
280 HashMap<String, String> mapData = (HashMap)object;
281 comboSchema.add(mapData.get("SCHEMA"));
284 userDB.setSchema(userDB.getDb());
285 comboSchema.setText(userDB.getDb());
286 } catch (Exception ee) {
287 comboSchema.setItems( new String[]{userDB.getSchema()} );
288 logger.error("get system schemas " + ee.getMessage());
290 } else {
291 comboSchema.add(userDB.getDb());
292 comboSchema.select(0);
294 } // end selected db
295 } // end dialog open
298 setFocus();
301 new ToolItem(toolBar, SWT.SEPARATOR);
304 // mysql group 이면 스키마 목록이 보이도록 합니다.
305 if(getUserDB().getDBGroup() == DBGroupDefine.MYSQL_GROUP | userDB.getDBGroup() == DBGroupDefine.ORACLE_GROUP | userDB.getDBGroup() == DBGroupDefine.POSTGRE_GROUP ) {
306 ToolItem sep = new ToolItem(toolBar, SWT.SEPARATOR);
308 comboSchema = new Combo(toolBar, SWT.READ_ONLY);
309 comboSchema.addSelectionListener(new SelectionAdapter() {
310 @Override
311 public void widgetSelected(SelectionEvent e) {
312 final String strSchema = comboSchema.getText();
313 userDB.setSchema(strSchema);
315 // 기존에 설정되어 있는 테이블 목록등을 삭제한다.
316 userDB.setTableListSeparator(null);
317 userDB.setViewListSeparator(null);
318 userDB.setFunctionLisstSeparator(null);
320 Connection conn = null;
321 try {
322 conn = TadpoleSQLManager.getConnection(userDB);
323 AbstractTadpoleManager.changeSchema(userDB, conn);
324 } catch(Exception e3) {
325 logger.error("** initialize connection", e3);
326 } finally {
327 try { if(conn != null) conn.close(); } catch(Exception ee) {}
330 if(PublicTadpoleDefine.ACTIVE_PRODUCT_TYPE == PRODUCT_TYPE.TadpoleDBHub) {
331 //오브젝트 익스플로어가 같은 스키마 일경우 스키마가 변경되도록.
332 getSite().getShell().getDisplay().asyncExec(new Runnable() {
333 @Override
334 public void run() {
335 try {
336 // 오브젝트 탐색기가 열려 있으면 탐색기의 스키마 이름을 변경해 줍니다.
337 ExplorerViewer ev = (ExplorerViewer)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(ExplorerViewer.ID);
338 ev.changeSchema(userDB, strSchema);
340 } catch (PartInitException e) {
341 logger.error("ExplorerView show", e); //$NON-NLS-1$
346 } // end product type
351 // 스키마리스트가 없는 경우 스키마 리스트를 가지고 넣는다.
353 if(userDB.getSchemas().isEmpty()) {
354 try {
355 for (Object object : DBSystemSchema.getSchemas(userDB)) {
356 HashMap<String, String> mapData = (HashMap)object;
357 comboSchema.add(mapData.get("SCHEMA"));
358 userDB.addSchema(mapData.get("SCHEMA"));
360 if(userDB.getDBGroup() == DBGroupDefine.ORACLE_GROUP) {
361 userDB.setSchema(userDB.getUsers());
362 } else if(userDB.getDBGroup() == DBGroupDefine.MYSQL_GROUP) {
363 userDB.setSchema(userDB.getDb());
365 } catch(Exception e) {
366 logger.error("get schema list " + e.getMessage());
368 } else {
369 for (String schema : userDB.getSchemas()) {
370 comboSchema.add(schema);
373 comboSchema.setVisibleItemCount(comboSchema.getItemCount() > 15 ? 15 : comboSchema.getItemCount());
375 comboSchema.setText(userDB.getSchema());
376 comboSchema.pack();
377 new ToolItem(toolBar, SWT.SEPARATOR);
379 sep.setWidth(comboSchema.getSize().x);
380 sep.setControl(comboSchema);
381 toolBar.pack();
384 // fileupload
385 ToolItem tltmOpen = new ToolItem(toolBar, SWT.NONE);
386 tltmOpen.setToolTipText(Messages.get().MainEditor_35);
387 tltmOpen.setImage(ResourceManager.getPluginImage(Activator.PLUGIN_ID, "resources/icons/editor/file-open.png")); //$NON-NLS-1$
388 tltmOpen.addSelectionListener(new SelectionAdapter() {
389 @Override
390 public void widgetSelected(SelectionEvent e) {
391 SingleFileuploadDialog dialog = new SingleFileuploadDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), Messages.get().MainEditor_36);
392 if(Dialog.OK == dialog.open()) {
393 // if(logger.isDebugEnabled()) logger.debug("============> " + dialog.getStrTxtFile()); //$NON-NLS-1$
394 if(SingleFileuploadDialog.ENUM_OPEN_TYPE.ADD_APPEND.name().equals(dialog.getStrComboOpenType())) {
395 appendText(dialog.getStrFileContent());
396 } else if(SingleFileuploadDialog.ENUM_OPEN_TYPE.NEW_WINDOW.name().equals(dialog.getStrComboOpenType())) {
397 FindEditorAndWriteQueryUtil.run(userDB, "", dialog.getStrFileContent(), true, PublicTadpoleDefine.OBJECT_TYPE.TABLES);
398 } else if(SingleFileuploadDialog.ENUM_OPEN_TYPE.REMOVE_AND_ADD.name().equals(dialog.getStrComboOpenType())) {
399 try {
400 browserEvaluate(EditorFunctionService.RE_NEW_TEXT, dialog.getStrFileContent());
401 } catch(Exception ee) {
402 logger.error("browser re_new_text error");
408 new ToolItem(toolBar, SWT.SEPARATOR);
410 // 결과를 텍스트로 출력할 것인지 여부
411 tltmTextResultView = new ToolItem(toolBar, SWT.CHECK);
412 // tltmTextResultView.setImage(ResourceManager.getPluginImage(Activator.PLUGIN_ID, "resources/icons/editor/textNote.png")); //$NON-NLS-1$
413 tltmTextResultView.setText("Text");
414 tltmTextResultView.addSelectionListener(new SelectionAdapter() {
415 @Override
416 public void widgetSelected(SelectionEvent e) {
417 if(tltmTextResultView.getSelection()) {
418 resultViewType = RESULT_COMP_TYPE.Text;
419 tltmTextResultView.setSelection(true);
420 } else {
421 resultViewType = RESULT_COMP_TYPE.Table;
422 tltmTextResultView.setSelection(false);
426 tltmTextResultView.setToolTipText(Messages.get().TextResultView);
427 tltmTextResultView.setEnabled(PublicTadpoleDefine.YES_NO.YES.name().equals(getUserDB().getIs_resource_download()));
428 new ToolItem(toolBar, SWT.SEPARATOR);
430 ToolItem tltmExecute = new ToolItem(toolBar, SWT.NONE);
431 tltmExecute.setToolTipText(String.format(Messages.get().MainEditor_tltmExecute_toolTipText_1, STR_SHORT_CUT_PREFIX));
432 tltmExecute.setImage(ResourceManager.getPluginImage(Activator.PLUGIN_ID, "resources/icons/editor/play.png")); //$NON-NLS-1$
433 tltmExecute.addSelectionListener(new SelectionAdapter() {
434 @Override
435 public void widgetSelected(SelectionEvent e) {
436 String strQuery = browserEvaluateToStr(EditorFunctionService.GET_SELECTED_TEXT, PublicTadpoleDefine.SQL_DELIMITER);
438 EditorDefine.EXECUTE_TYPE executeType = EditorDefine.EXECUTE_TYPE.NONE;
439 if( Boolean.parseBoolean( browserEvaluateToStr(EditorFunctionService.IS_BLOCK_TEXT) ) ) {
440 executeType = EditorDefine.EXECUTE_TYPE.BLOCK;
443 RequestQuery reqQuery = new RequestQuery(getConnectionid(), userDB, strQuery, dbAction, EditorDefine.QUERY_MODE.QUERY, executeType, isAutoCommit());
444 executeCommand(reqQuery);
447 new ToolItem(toolBar, SWT.SEPARATOR);
449 if(SQLUtil.isSELECTEditor(dbAction)) {
450 ToolItem tltmExecuteAll = new ToolItem(toolBar, SWT.NONE);
451 tltmExecuteAll.setToolTipText(Messages.get().MainEditor_tltmExecuteAll_text);
452 tltmExecuteAll.setImage(ResourceManager.getPluginImage(Activator.PLUGIN_ID, "resources/icons/editor/sql-query-all.png")); //$NON-NLS-1$
453 tltmExecuteAll.addSelectionListener(new SelectionAdapter() {
454 @Override
455 public void widgetSelected(SelectionEvent e) {
456 String strQuery = browserEvaluateToStr(EditorFunctionService.ALL_TEXT);
458 RequestQuery reqQuery = new RequestQuery(getConnectionid(), userDB, strQuery, dbAction, EditorDefine.QUERY_MODE.QUERY, EditorDefine.EXECUTE_TYPE.ALL, isAutoCommit());
459 executeCommand(reqQuery);
462 new ToolItem(toolBar, SWT.SEPARATOR);
465 ToolItem tltmExplainPlanctrl = new ToolItem(toolBar, SWT.NONE);
466 tltmExplainPlanctrl.setImage(ResourceManager.getPluginImage(Activator.PLUGIN_ID, "resources/icons/editor/execute_plan.png")); //$NON-NLS-1$
467 tltmExplainPlanctrl.addSelectionListener(new SelectionAdapter() {
468 @Override
469 public void widgetSelected(SelectionEvent e) {
470 String strQuery = browserEvaluateToStr(EditorFunctionService.GET_SELECTED_TEXT, PublicTadpoleDefine.SQL_DELIMITER); //$NON-NLS-1$
472 RequestQuery reqQuery = new RequestQuery(getConnectionid(), userDB, strQuery, dbAction, EditorDefine.QUERY_MODE.EXPLAIN_PLAN, EditorDefine.EXECUTE_TYPE.NONE, isAutoCommit());
473 executeCommand(reqQuery);
477 tltmExplainPlanctrl.setToolTipText(String.format(Messages.get().MainEditor_3, STR_SHORT_CUT_PREFIX));
478 new ToolItem(toolBar, SWT.SEPARATOR);
479 if(DBGroupDefine.DYNAMODB_GROUP == getUserDB().getDBGroup()) tltmExplainPlanctrl.setEnabled(false);
481 ToolItem tltmSort = new ToolItem(toolBar, SWT.NONE);
482 tltmSort.setImage(ResourceManager.getPluginImage(Activator.PLUGIN_ID, "resources/icons/editor/query_format.png")); //$NON-NLS-1$
483 tltmSort.addSelectionListener(new SelectionAdapter() {
484 @Override
485 public void widgetSelected(SelectionEvent e) {
486 String strQuery = browserEvaluateToStr(EditorFunctionService.ALL_TEXT);
488 try {
489 browserEvaluate(EditorFunctionService.RE_NEW_TEXT, SQLFormater.format(strQuery));
490 } catch(Exception ee) {
491 logger.error("sql format", ee); //$NON-NLS-1$
495 tltmSort.setToolTipText(String.format(Messages.get().MainEditor_4, STR_SHORT_CUT_PREFIX));
496 new ToolItem(toolBar, SWT.SEPARATOR);
498 ToolItem tltmSQLToApplication = new ToolItem(toolBar, SWT.NONE);
499 tltmSQLToApplication.setImage(ResourceManager.getPluginImage(Activator.PLUGIN_ID, "resources/icons/editor/sql_to_applications.png")); //$NON-NLS-1$
500 tltmSQLToApplication.addSelectionListener(new SelectionAdapter() {
501 @Override
502 public void widgetSelected(SelectionEvent e) {
503 String strQuery = browserEvaluateToStr(EditorFunctionService.ALL_TEXT);
505 SQLToStringDialog dialog = new SQLToStringDialog(null, getUserDB(), strQuery);
506 dialog.open();
507 setFocus();
510 tltmSQLToApplication.setToolTipText(Messages.get().MainEditor_40);
511 new ToolItem(toolBar, SWT.SEPARATOR);
513 // ToolItem tltmDownload = new ToolItem(toolBar, SWT.NONE);
514 // tltmDownload.setImage(ResourceManager.getPluginImage(Activator.PLUGIN_ID, "resources/icons/editor/download_query.png")); //$NON-NLS-1$
515 // tltmDownload.addSelectionListener(new SelectionAdapter() {
516 // @Override
517 // public void widgetSelected(SelectionEvent e) {
518 // if(!MessageDialog.openConfirm(null, Messages.get().MainEditor_38, Messages.get().MainEditor_39)) return;
520 // try {
521 // String strQuery = browserEvaluateToStr(EditorFunctionService.ALL_TEXT);
522 // compResult.downloadExtFile(getUserDB().getDisplay_name()+".sql", strQuery); //$NON-NLS-1$
523 // } catch(Exception ee) {
524 // logger.error("Download SQL", ee); //$NON-NLS-1$
525 // }
526 // }
527 // });
528 // tltmDownload.setToolTipText(Messages.get().MainEditor_42);
529 // new ToolItem(toolBar, SWT.SEPARATOR);
531 tiAutoCommit = new ToolItem(toolBar, SWT.CHECK);
532 tiAutoCommit.setSelection(false);
533 tiAutoCommit.setText(Messages.get().MainEditor_41);
534 tiAutoCommit.addSelectionListener(new SelectionAdapter() {
535 @Override
536 public void widgetSelected(SelectionEvent e) {
537 initAutoCommitAction(false, true);
540 if(DBGroupDefine.DYNAMODB_GROUP == getUserDB().getDBGroup()) tiAutoCommit.setEnabled(false);
542 tiAutoCommitCommit = new ToolItem(toolBar, SWT.NONE);
543 tiAutoCommitCommit.setSelection(false);
544 tiAutoCommitCommit.setText(Messages.get().Commit);
545 tiAutoCommitCommit.addSelectionListener(new SelectionAdapter() {
546 @Override
547 public void widgetSelected(SelectionEvent e) {
548 if(logger.isDebugEnabled()) logger.debug("[set commit][user id]" + getUserEMail() + "[user id]" + userDB); //$NON-NLS-1$ //$NON-NLS-2$
550 TadpoleSQLTransactionManager.commit(getConnectionid(), getUserEMail(), userDB);
551 MessageDialog.openInformation(getSite().getShell(), CommonMessages.get().Confirm, Messages.get().ConfirmCommit);
555 tiAutoCommitRollback = new ToolItem(toolBar, SWT.NONE);
556 tiAutoCommitRollback.setSelection(false);
557 tiAutoCommitRollback.setText(Messages.get().Rollback);
558 tiAutoCommitRollback.addSelectionListener(new SelectionAdapter() {
559 @Override
560 public void widgetSelected(SelectionEvent e) {
561 if(logger.isDebugEnabled()) logger.debug("[set rollback][user id]" + getUserEMail() + "[user id]" + userDB); //$NON-NLS-1$ //$NON-NLS-2$
563 TadpoleSQLTransactionManager.rollback(getConnectionid(), getUserEMail(), userDB);
564 MessageDialog.openInformation(getSite().getShell(), CommonMessages.get().Confirm, Messages.get().ConfirmRollback);
567 new ToolItem(toolBar, SWT.SEPARATOR);
569 // api
570 ToolItem tltmAPI = new ToolItem(toolBar, SWT.NONE);
571 tltmAPI.setImage(ResourceManager.getPluginImage(Activator.PLUGIN_ID, "resources/icons/editor/restful_api.png")); //$NON-NLS-1$
572 tltmAPI.addSelectionListener(new SelectionAdapter() {
573 @Override
574 public void widgetSelected(SelectionEvent e) {
575 String strQuery = browserEvaluateToStr(EditorFunctionService.ALL_TEXT);
577 MainSQLEditorAPIServiceDialog dialog = new MainSQLEditorAPIServiceDialog(getSite().getShell(), userDB, strQuery);
578 dialog.open();
580 setFocus();
583 tltmAPI.setToolTipText(Messages.get().MainEditor_51);
584 new ToolItem(toolBar, SWT.SEPARATOR);
586 ToolItem tltmHelp = new ToolItem(toolBar, SWT.NONE);
587 tltmHelp.setImage(ResourceManager.getPluginImage(Activator.PLUGIN_ID, "resources/icons/editor/about.png")); //$NON-NLS-1$
588 tltmHelp.addSelectionListener(new SelectionAdapter() {
589 @Override
590 public void widgetSelected(SelectionEvent e) {
591 RDBShortcutHelpDialog dialog = new RDBShortcutHelpDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.NONE);
592 dialog.open();
594 setFocus();
597 tltmHelp.setToolTipText(String.format(Messages.get().MainEditor_27, STR_SHORT_CUT_PREFIX));
598 ////// tool bar end ///////////////////////////////////////////////////////////////////////////////////
600 ////// orion editor start /////////////////////////////////////////////////////////////////////////////
601 browserQueryEditor = new Browser(compositeEditor, SWT.BORDER);
602 browserQueryEditor.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
603 addBrowserService();
605 resultMainComposite = new ResultMainComposite(sashForm, SWT.BORDER);
606 GridLayout gl_compositeResult = new GridLayout(1, false);
607 gl_compositeResult.verticalSpacing = 0;
608 gl_compositeResult.horizontalSpacing = 0;
609 gl_compositeResult.marginHeight = 0;
610 gl_compositeResult.marginWidth = 0;
611 resultMainComposite.setLayout(gl_compositeResult);
612 resultMainComposite.setMainEditor(this);
614 sashForm.setWeights(new int[] {63, 37});
615 initEditor();
617 // 올챙이 확장에 관한 코드를 넣습니다. ===================================================================
618 MainEditorContributionsHandler editorExtension = new MainEditorContributionsHandler();
619 compMainExtions = editorExtension.evaluateCreateWidgetContribs(userDB);
620 int intSashCnt = 1;
621 for (IMainEditorExtension aMainEditorExtension : compMainExtions) {
623 if(aMainEditorExtension.isEnableExtension()) {
624 intSashCnt++;
625 Composite compExt = new Composite(sashFormExtension, SWT.BORDER);
626 GridLayout gl_compositeExt = new GridLayout(1, false);
627 gl_compositeExt.verticalSpacing = 0;
628 gl_compositeExt.horizontalSpacing = 0;
629 gl_compositeExt.marginHeight = 0;
630 gl_compositeExt.marginWidth = 0;
631 compExt.setLayout(gl_compositeExt);
633 aMainEditorExtension.createPartControl(compExt, this);
637 if(intSashCnt >= 2) {
638 sashFormExtension.setWeights(new int[] {100, 0});
640 // 올챙이 확장에 관한 코드를 넣습니다. ===================================================================
642 // autocommit true 혹은 false값이 바뀌었을때..
643 PlatformUI.getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() {
644 @Override
645 public void propertyChange(PropertyChangeEvent event) {
647 // if (event.getProperty() == PublicTadpoleDefine.AUTOCOMMIT_USE) {
648 // String strAutoCommit_seq = event.getNewValue().toString();
649 // // UserDB.seq || auto commit ture or false
650 // String[] arryVal = StringUtils.split(strAutoCommit_seq, "||"); //$NON-NLS-1$
651 // int seq = Integer.parseInt(arryVal[0]);
652 // boolean boolUseAutocommit = Boolean.parseBoolean(arryVal[1]);
654 // if(!tiAutoCommit.isDisposed()) {
655 // if(seq == userDB.getSeq()) {
656 // tiAutoCommit.setSelection(boolUseAutocommit);
657 // if(!boolUseAutocommit) {
658 // tiAutoCommitCommit.setEnabled(false);
659 // tiAutoCommitRollback.setEnabled(false);
660 // } else {
661 // tiAutoCommitCommit.setEnabled(true);
662 // tiAutoCommitRollback.setEnabled(true);
663 // }
664 // } // end tltmAutoCommit
665 // } // end seq
666 // } else
667 if(event.getProperty() == PreferenceDefine.EDITOR_CHANGE_EVENT) {
668 final String varTheme = PublicTadpoleDefine.getMapTheme().get(GetPreferenceGeneral.getEditorTheme());
669 final String varFontSize = GetPreferenceGeneral.getEditorFontSize();
670 final String varIsWrap = ""+GetPreferenceGeneral.getEditorIsWarp();
671 final String varWarpLimit = GetPreferenceGeneral.getEditorWarpLimitValue();
672 final String varIsShowGutter = ""+GetPreferenceGeneral.getEditorShowGutter();
674 browserEvaluate(IEditorFunction.CHANGE_EDITOR_STYLE,
675 varTheme, varFontSize, varIsWrap, varWarpLimit, varIsShowGutter
678 } //
679 }); // end property change
683 * refresh connection title
685 private void initConnectionInfo() {
686 tltmConnectURL.setText(String.format("%s", userDB.getDisplay_name()));
688 // if selected DB is mysql, reset schema list
691 public Browser getBrowserQueryEditor() {
692 return browserQueryEditor;
696 * browser handler
698 protected void addBrowserService() {
699 browserQueryEditor.setUrl(REAL_DB_URL);
701 // final String strConstList = findDefaultKeyword();
702 // 기존 리소스를 가져왔으면 auto save mode 는 false
703 final String varAutoSave = dBResource != null?"fasle":""+GetPreferenceGeneral.getEditorAutoSave();
705 final String varTheme = PublicTadpoleDefine.getMapTheme().get(GetPreferenceGeneral.getEditorTheme());
706 final String varFontSize = GetPreferenceGeneral.getEditorFontSize();
707 final String varIsWrap = ""+GetPreferenceGeneral.getEditorIsWarp();
708 final String varWarpLimit = GetPreferenceGeneral.getEditorWarpLimitValue();
709 final String varIsShowGutter = ""+GetPreferenceGeneral.getEditorShowGutter();
710 registerBrowserFunctions();
712 browserQueryEditor.addProgressListener(new ProgressListener() {
713 @Override
714 public void completed( ProgressEvent event ) {
715 try {
716 browserEvaluate(IEditorFunction.RDB_INITIALIZE,
717 findEditorExt(), dbAction.toString(), getInitDefaultEditorStr(),
718 varAutoSave, varTheme, varFontSize, varIsWrap, varWarpLimit, varIsShowGutter
719 ); //$NON-NLS-1$
720 } catch(Exception ee) {
721 logger.error("rdb editor initialize ", ee); //$NON-NLS-1$
724 public void changed( ProgressEvent event ) {}
729 * getContentAssist
731 * @param strQuery
732 * @param intPosition
733 * @return
735 public String getContentAssist(String strQuery, int intPosition) {
736 if("".equals(StringUtils.trimToEmpty(strQuery))) return "";
738 if(logger.isDebugEnabled()) {
739 logger.debug("-[start block] -------------------------------------------------------------");
740 logger.debug("\t[strQuery]" + strQuery );
741 logger.debug("\t[intPosition]" + intPosition );
744 String newContentAssist = "";
745 try {
746 ExtMakeContentAssistUtil constAssistUtil = new ExtMakeContentAssistUtil();
747 newContentAssist = constAssistUtil.makeContentAssist(getUserDB(), strQuery, intPosition);
748 } catch(Exception e) {
749 logger.error("Content assist", e);
751 if(logger.isDebugEnabled()) logger.debug("-[end block] -------------------------------------------------------------");
753 return newContentAssist==null?"":newContentAssist;
757 * initialize editor
759 private void initEditor() {
760 if (DBGroupDefine.HIVE_GROUP == userDB.getDBGroup()) {
761 tiAutoCommit.setEnabled(false);
764 if("YES".equals(userDB.getIs_autocommit())) { //$NON-NLS-1$
765 tiAutoCommit.setSelection(false);
766 } else {
767 tiAutoCommit.setSelection(true);
770 // 기존 에디터에서 auto commit button 이 어떻게 설정 되어 있는지 가져옵니다.
771 initAutoCommitAction(true, false);
773 // 과거에 실행했던 쿼리 정보 가져오기.
774 // resultMainComposite.initMainComposite();
776 // 초기 연결 커넥션을 초기화 합니다.
777 if (DBGroupDefine.MYSQL_GROUP == userDB.getDBGroup()) {
778 Connection conn = null;
779 try {
780 conn = TadpoleSQLManager.getConnection(userDB);
781 AbstractTadpoleManager.changeSchema(userDB, conn);
782 } catch(Exception e3) {
783 logger.error("** initialize connection", e3);
784 } finally {
785 try { if(conn != null) conn.close(); } catch(Exception ee) {}
789 // google analytic
790 AnalyticCaller.track(MainEditor.ID, userDB.getDbms_type());
794 * start sql transaction;
796 public void beginTransaction() {
797 getSite().getShell().getDisplay().asyncExec(new Runnable() {
798 public void run() {
799 if(tiAutoCommit.isEnabled()) {
800 tiAutoCommit.setEnabled(true);
801 tiAutoCommit.setSelection(true);
802 tiAutoCommitCommit.setEnabled(true);
803 tiAutoCommitRollback.setEnabled(true);
810 * init auto commit button
812 * @param isFirst
813 * @param isRiseEvent
815 private void initAutoCommitAction(boolean isFirst, boolean isRiseEvent) {
816 if(isAutoCommit()) {
817 tiAutoCommitCommit.setEnabled(false);
818 tiAutoCommitRollback.setEnabled(false);
820 if(!isFirst) {
821 if(TadpoleSQLTransactionManager.isInstance(getConnectionid(), getUserEMail(), userDB)) {
822 if(MessageDialog.openConfirm(null, CommonMessages.get().Confirm, Messages.get().MainEditor_47)) {
823 TadpoleSQLTransactionManager.commit(getConnectionid(), getUserEMail(), userDB);
824 } else {
825 TadpoleSQLTransactionManager.rollback(getConnectionid(), getUserEMail(), userDB);
829 } else {
830 tiAutoCommitCommit.setEnabled(true);
831 tiAutoCommitRollback.setEnabled(true);
834 // if(isRiseEvent) {
835 // // auto commit의 실행버튼을 동일한 db를 열고 있는 에디터에서 공유합니다.
836 // PlatformUI.getPreferenceStore().setValue(PublicTadpoleDefine.AUTOCOMMIT_USE, userDB.getSeq() + "||" + tiAutoCommit.getSelection() + "||" + System.currentTimeMillis()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
837 // }
841 * execute query
843 * @param reqQuery
845 public void executeCommand(final RequestQuery reqQuery) {
846 if(!userDB.is_isUseEnable()) {
847 MessageDialog.openInformation(getSite().getShell(), CommonMessages.get().Information, CommonMessages.get().TermExpiredMsg);
848 return;
851 // 요청쿼리가 없다면 무시합니다.
852 if(StringUtils.isEmpty(reqQuery.getSql())) return;
854 // if(logger.isDebugEnabled()) {
855 // logger.debug("===> [connection id]" + reqQuery.getConnectId());
856 // }
859 // schema test code start
861 final UserDBDAO userDB = getUserDB();
862 // if(logger.isDebugEnabled()) {
863 // logger.debug("======= schema name : " + userDB.getSchema());
864 // }
866 // do not execute query
867 // if(System.currentTimeMillis() > SessionManager.getServiceEnd().getTime()) {
868 // if(ApplicationArgumentUtils.isOnlineServer()) {
869 // if(MessageDialog.openConfirm(null, CommonMessages.get().Information, Messages.get().MainEditorServiceEndGoPay)) {
870 // UserBillEditorInput mei = new UserBillEditorInput();
872 // try {
873 // PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(mei, DefineExternalPlguin.BILL_PLUGIN);
874 // } catch (PartInitException e) {
875 // logger.error("open editor", e); //$NON-NLS-1$
876 // Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); //$NON-NLS-1$
877 // ExceptionDetailsErrorDialog.openError(null,CommonMessages.get().Error, "Bill page open", errStatus); //$NON-NLS-1$
878 // }
879 // }
880 // } else {
881 // MessageDialog.openInformation(null, CommonMessages.get().Information, Messages.get().MainEditorServiceEnd);
882 // }
883 // return;
884 // }
886 String strCheckSQL = SQLUtil.removeCommentAndOthers(userDB, reqQuery.getSql());
887 if(StringUtils.startsWithIgnoreCase(strCheckSQL, "desc ")) {
888 String strObject = StringUtils.removeStartIgnoreCase(strCheckSQL, "desc ");
890 Map<String,String> paramMap = new HashMap<String, String>();
891 if(StringUtils.contains(strObject, ".")) {
892 paramMap.put("OBJECT_OWNER", StringUtils.substringBefore(strObject, "."));
893 paramMap.put("OBJECT_NAME", StringUtils.substringAfter(strObject, "."));
894 }else{
895 paramMap.put("OBJECT_OWNER", userDB.getSchema());
896 paramMap.put("OBJECT_NAME", strObject);
899 DialogUtil.popupObjectInformationDialog(getUserDB(), paramMap);
900 } else if(StringUtils.startsWithIgnoreCase(strCheckSQL, "use ") && getUserDB().getDBGroup() == DBGroupDefine.MYSQL_GROUP) {
901 try {
902 testChangeSchema(strCheckSQL);
903 String strSchema = StringUtils.remove(strCheckSQL, "use ");
904 userDB.setSchema(strSchema);
906 comboSchema.setText(strSchema);
907 } catch(Exception e) {
908 MessageDialog.openError(null, CommonMessages.get().Error, e.getMessage());
909 setFocus();
911 } else {
912 resultMainComposite.executeCommand(reqQuery);
915 // google analytic
916 AnalyticCaller.track(MainEditor.ID, "executeCommand"); //$NON-NLS-1$
920 * schema 변경시 올바른지 검증한다.
921 * @param strCheckSQL
922 * @throws Exception
924 private void testChangeSchema(String strCheckSQL) throws Exception {
925 Connection javaConn = TadpoleSQLManager.getConnection(userDB);
927 Statement statement = null;
928 try {
929 if(userDB.getDBGroup() == DBGroupDefine.MYSQL_GROUP) {
930 if(logger.isDebugEnabled()) logger.debug(String.format("=set define schema %s ", userDB.getSchema()));
932 statement = javaConn.createStatement();
933 statement.executeUpdate(strCheckSQL);
935 } catch(Exception e) {
936 logger.error("change scheman ", e);
937 throw e;
938 } finally {
939 if(statement != null) statement.close();
943 * auto commit
944 * @return
946 public boolean isAutoCommit() {
947 if(tiAutoCommit == null) return true;
948 return !tiAutoCommit.getSelection();
951 @Override
952 public void setFocus() {
953 setOrionTextFocus();
954 EditorUtils.selectConnectionManager(getUserDB());
958 * new resource name
960 * @return
962 private UserDBResourceDAO getResouceName(UserDBResourceDAO initDBResource, String strContentData) {
963 PublicTadpoleDefine.RESOURCE_TYPE resourceType = PublicTadpoleDefine.RESOURCE_TYPE.OBJECT;
964 if(dbAction == PublicTadpoleDefine.OBJECT_TYPE.TABLES |
965 dbAction == PublicTadpoleDefine.OBJECT_TYPE.VIEWS) {
966 resourceType = PublicTadpoleDefine.RESOURCE_TYPE.SQL;
969 ResourceSaveDialog rsDialog = new ResourceSaveDialog(null, initDBResource, userDB, resourceType, strContentData);
970 if(rsDialog.open() == Window.OK) {
971 return rsDialog.getRetResourceDao();
972 } else {
973 return null;
978 * 데이터를 저장합니다.
980 * @param strContentData
981 * @return
983 public boolean calledDoSave(String strContentData) {
984 boolean isSaved = false;
986 try {
987 // 신규 저장일때는 리소스타입, 이름, 코멘를 입력받습니다.
988 if(dBResource == null) {
989 UserDBResourceDAO newDBResource = getResouceName(null, strContentData);
990 if(newDBResource == null) return false;
992 isSaved = saveResourceData(newDBResource, strContentData);
993 // 업데이트 일때.
994 } else {
995 isSaved = updateResourceDate(strContentData);
998 this.strLastContent = strContentData;
1000 // auto save 항목을 지운다.
1001 if(dBResourceAuto != null) {
1002 TadpoleSystem_UserDBResource.updateResourceAuto(dBResourceAuto, "");
1005 } catch(Exception e) {
1006 logger.error(RequestInfoUtils.requestInfo("doSave exception", getUserEMail()), e); //$NON-NLS-1$
1007 } finally {
1008 if(isSaved) {
1009 setDirty(false);
1010 browserEvaluate(IEditorFunction.SAVE_DATA);
1013 browserEvaluate(IEditorFunction.SET_FOCUS);
1016 return isSaved;
1020 * call auto save
1022 * @param strContentData
1023 * @return
1025 public boolean calledDoAutoSave(String strContentData) {
1026 if(logger.isDebugEnabled()) logger.debug("====== called auto save ==========" + strContentData);
1027 // 내용이 공백이거나 이전 내용과 같으면 저장하지 않는다.
1028 if("".equals(StringUtils.trimToEmpty(strContentData))) return true;
1029 if(StringUtils.trimToEmpty(strLastContent).equals(StringUtils.trimToEmpty(strContentData))) return true;
1031 boolean isSaved = false;
1032 try {
1033 isSaved = updateAutoResourceDate(strContentData);
1034 strLastContent = strContentData;
1035 } catch(SWTException e) {
1036 logger.error(RequestInfoUtils.requestInfo("doAutoSave exception", getUserEMail()), e); //$NON-NLS-1$
1037 } finally {
1038 // browserEvaluate(IEditorFunction.SET_FOCUS);
1041 return isSaved;
1044 @Override
1045 public void doSave(IProgressMonitor monitor) {
1046 String strEditorAllText = browserEvaluateToStr(EditorFunctionService.ALL_TEXT);
1047 calledDoSave(strEditorAllText);
1050 @Override
1051 public void doSaveAs() {
1052 boolean isSaved = false;
1054 // 저장을 호출합니다.
1055 try {
1056 String strEditorAllText = browserEvaluateToStr(EditorFunctionService.ALL_TEXT);
1058 // 신규 저장일때는 리소스타입, 이름, 코멘를 입력받습니다.
1059 UserDBResourceDAO newDBResource = getResouceName(dBResource, strEditorAllText);
1060 if(newDBResource == null) return;
1062 isSaved = saveResourceData(newDBResource, strEditorAllText);
1063 } catch(SWTException e) {
1064 logger.error(RequestInfoUtils.requestInfo("doSave exception", getUserEMail()), e); //$NON-NLS-1$
1065 } finally {
1066 if(isSaved) {
1067 setDirty(false);
1068 browserEvaluate(IEditorFunction.SAVE_DATA);
1071 browserEvaluate(IEditorFunction.SET_FOCUS);
1076 * 데이터를 수정합니다.
1078 * @param newContents
1079 * @return
1081 private boolean updateResourceDate(String newContents) {
1082 try {
1083 TadpoleSystem_UserDBResource.updateResource(dBResource, newContents);
1084 return true;
1085 } catch (Exception e) {
1086 logger.error("update file", e); //$NON-NLS-1$
1087 Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); //$NON-NLS-1$
1088 ExceptionDetailsErrorDialog.openError(getSite().getShell(),CommonMessages.get().Error, Messages.get().MainEditor_19, errStatus); //$NON-NLS-1$
1090 return false;
1095 * auto update save
1096 * @param newContents
1097 * @return
1099 private boolean updateAutoResourceDate(String newContents) {
1100 if(dBResource != null) return true;
1102 // table, view만 auto save 된다.
1103 if(dbAction == PublicTadpoleDefine.OBJECT_TYPE.TABLES |
1104 dbAction == PublicTadpoleDefine.OBJECT_TYPE.VIEWS) {
1106 if(logger.isDebugEnabled()) logger.debug("====> called updateAutoResourceDate ");
1107 try {
1108 dBResourceAuto = TadpoleSystem_UserDBResource.updateAutoResourceDate(getUserDB(), dBResourceAuto, dBResource, newContents);
1109 if(dBResource != null) {
1110 setDirty(false);
1112 return true;
1113 } catch (Exception e) {
1114 logger.error("Autosave exception", e);
1115 // igoner error message
1117 return false;
1121 return true;
1125 * save data
1127 * @param newDBResource 저장 하려는 리소스
1128 * @param newContents
1129 * @return
1131 private boolean saveResourceData(UserDBResourceDAO newDBResource, String newContents) {
1133 try {
1134 // db 저장
1135 dBResource = TadpoleSystem_UserDBResource.saveResource(userDB, newDBResource, newContents);
1136 dBResource.setParent(userDB);
1138 // title 수정
1139 setPartName(dBResource.getName());
1141 // tree 갱신
1142 PlatformUI.getPreferenceStore().setValue(PublicTadpoleDefine.SAVE_FILE, String.format("%s:%s", dBResource.getDb_seq(), System.currentTimeMillis())); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1144 } catch (Exception e) {
1145 logger.error("save data", e); //$NON-NLS-1$
1147 Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); //$NON-NLS-1$
1148 ExceptionDetailsErrorDialog.openError(getSite().getShell(),CommonMessages.get().Error, Messages.get().MainEditor_19, errStatus); //$NON-NLS-1$
1150 return false;
1153 return true;
1156 /** save property dirty */
1157 public void setDirty(Boolean newValue) {
1158 if(isDirty != newValue) {
1159 isDirty = newValue;
1160 firePropertyChange(PROP_DIRTY);
1164 @Override
1165 public void dispose() {
1166 super.dispose();
1170 * 에디터의 성격을 정의 합니다.
1172 * @return
1174 public OBJECT_TYPE getDbAction() {
1175 return dbAction;
1179 * get Resource
1181 * @return
1183 public UserDBResourceDAO getdBResource() {
1184 return dBResource;
1187 @Override
1188 protected void registerBrowserFunctions() {
1189 editorService = new MainEditorBrowserFunctionService(userDB, browserQueryEditor, EditorFunctionService.EDITOR_SERVICE_HANDLER, this);
1193 * 에디터 로드할때 사용할 초기 쿼리 입니다.
1194 * @return
1196 public String getInitDefaultEditorStr() {
1197 return initDefaultEditorStr;
1200 public IMainEditorExtension[] getMainEditorExtions() {
1201 return compMainExtions;
1204 public SashForm getSashFormExtension() {
1205 return sashFormExtension;
1209 * 화면에서 보여줄 타입
1210 * @return
1212 public PublicTadpoleDefine.RESULT_COMP_TYPE getResultViewType() {
1213 return resultViewType;