@Override public void run(IAction action) { UserDBDAO userDB = (UserDBDAO) sel.getFirstElement(); if (DBDefine.getDBDefine(userDB) == DBDefine.MYSQL_DEFAULT || DBDefine.getDBDefine(userDB) == DBDefine.MARIADB_DEFAULT || DBDefine.getDBDefine(userDB) == DBDefine.ORACLE_DEFAULT || DBDefine.getDBDefine(userDB) == DBDefine.MSSQL_DEFAULT) { try { SessionListEditorInput sleInput = new SessionListEditorInput(userDB); PlatformUI.getWorkbench() .getActiveWorkbenchWindow() .getActivePage() .openEditor(sleInput, SessionListEditor.ID); } catch (PartInitException e) { logger.error("open session list", e); // $NON-NLS-1$ Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); // $NON-NLS-1$ ExceptionDetailsErrorDialog.openError( null, "Error", Messages.AbstractQueryAction_1, errStatus); // $NON-NLS-1$ } } else { MessageDialog.openWarning(null, "Information", "Not support database."); } }
public void reLoadResource() { try { treeList.clear(); List<String> groupNames = TadpoleSystem_UserDBQuery.getUserGroup(SessionManager.getGroupSeqs()); for (String groupName : groupNames) { ManagerListDTO parent = new ManagerListDTO(groupName); treeList.add(parent); } List<UserDBDAO> userDBS = TadpoleSystem_UserDBQuery.getUserDB(); for (UserDBDAO userDBDAO : userDBS) { addUserDB(userDBDAO, false); } } catch (Exception e) { logger.error("initialize Managerview", e); Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); // $NON-NLS-1$ ExceptionDetailsErrorDialog.openError( getSite().getShell(), "Error", "Can't load database.", errStatus); // $NON-NLS-1$ } treeViewer.refresh(); treeViewer.expandToLevel(2); }
/** * resource load * * @param input */ private void loadDBRsource(IEditorInput input) { TadpoleRDBEditorInput erdInput = (TadpoleRDBEditorInput) input; userDB = erdInput.getUserDBDAO(); isAllTable = erdInput.isAllTable(); // 신규로드 인지 기존 파일 로드 인지 검사합니다. if (null != erdInput.getUserDBERD()) { userDBErd = erdInput.getUserDBERD(); // load resouce try { String xmlString = TadpoleSystem_UserDBResource.getResourceData(userDBErd); // 처음 로드 할때 ResourceSet에 instance가 등록 되어 있어야 합니다. /** <code>TadpolePackage.eNS_URI</code> */ ResourceSet resourceSet = new ResourceSetImpl(); if (resourceSet.getPackageRegistry().get("http://com.hangum.tadpole.rdb.model.ERDInfo") == null) { resourceSet .getPackageRegistry() .put("http://com.hangum.tadpole.rdb.model.ERDInfo", RdbPackage.eINSTANCE.getClass()); } // XMLResourceImpl resource = new XMLResourceImpl(); resource.setEncoding("UTF-8"); resource.load(new InputSource(new StringReader(xmlString)), null); db = (DB) resource.getContents().get(0); } catch (Exception e) { logger.error("Load ERD Resource", e); // $NON-NLS-1$ Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); // $NON-NLS-1$ ExceptionDetailsErrorDialog.openError( getSite().getShell(), "Error", Messages.get().TadpoleEditor_0, errStatus); //$NON-NLS-1$ } setPartName(isAllTable ? "All " + userDBErd.getName() : userDBErd.getName()); setTitleToolTip(userDB.getDisplay_name()); } else { setPartName(isAllTable ? "All " + userDB.getDisplay_name() : userDB.getDisplay_name()); setTitleToolTip(userDB.getDisplay_name()); } // google analytic AnalyticCaller.track(TadpoleRDBEditor.ID, userDB.getDbms_type()); }
/** * 디비의 화면을 오픈합니다. * * @param userDB */ public void run(UserDBDAO userDB) { // mongodb인지 검사하여.. if (userDB.getDBDefine() != DBDefine.MONGODB_DEFAULT) { MainEditorInput mei = new MainEditorInput(userDB); try { PlatformUI.getWorkbench() .getActiveWorkbenchWindow() .getActivePage() .openEditor(mei, MainEditor.ID); } catch (PartInitException e) { logger.error("open editor", e); // $NON-NLS-1$ Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); // $NON-NLS-1$ ExceptionDetailsErrorDialog.openError( null, "Error", Messages.AbstractQueryAction_1, errStatus); // $NON-NLS-1$ } } else if (userDB.getDBDefine() == DBDefine.MONGODB_DEFAULT) { MongoDBInfosInput mongoInput = new MongoDBInfosInput(userDB, MongoDBInfosEditor.PAGES.COLLECTION_SUMMERY); try { PlatformUI.getWorkbench() .getActiveWorkbenchWindow() .getActivePage() .openEditor(mongoInput, MongoDBInfosEditor.ID); } catch (PartInitException e) { logger.error("open editor", e); // $NON-NLS-1$ Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); // $NON-NLS-1$ ExceptionDetailsErrorDialog.openError( null, "Error", Messages.AbstractQueryAction_1, errStatus); // $NON-NLS-1$ } } }
/** * 기존 리소스 호출 * * @param userDB * @param dao */ public void run(UserDBResourceDAO dao) { IEditorReference reference = EditorUtils.findSQLEditor(dao); if (reference == null) { try { MainEditorInput mei = new MainEditorInput(dao); PlatformUI.getWorkbench() .getActiveWorkbenchWindow() .getActivePage() .openEditor(mei, MainEditor.ID); } catch (Exception e) { logger.error("new editor", e); // $NON-NLS-1$ Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); // $NON-NLS-1$ ExceptionDetailsErrorDialog.openError( null, "Error", Messages.MainEditorInput_0, errStatus); // $NON-NLS-1$ } } else { try { MainEditor editor = (MainEditor) reference.getEditor(true); PlatformUI.getWorkbench() .getActiveWorkbenchWindow() .getActivePage() .openEditor(editor.getEditorInput(), MainEditor.ID, false); editor.setFocus(); } catch (Exception e) { logger.error("findEditor", e); // $NON-NLS-1$ Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); // $NON-NLS-1$ ExceptionDetailsErrorDialog.openError( null, "Error", Messages.AbstractQueryAction_1, errStatus); // $NON-NLS-1$ } } }
/** * 트리를 갱신하고 쿼리 창을 엽니다. * * @param dto */ public void selectAndOpenView(UserDBDAO dto) { treeViewer.refresh(); treeViewer.setSelection(new StructuredSelection(dto), true); // mongodb 일경우 열지 않는다. if (DBDefine.getDBDefine(dto) != DBDefine.MONGODB_DEFAULT) { MainEditorInput mei = new MainEditorInput(dto); IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); try { page.openEditor(mei, MainEditor.ID); } catch (PartInitException e) { logger.error("main editor open", e); // $NON-NLS-1$ Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); // $NON-NLS-1$ ExceptionDetailsErrorDialog.openError( getSite().getShell(), "Error", "Can't open resource. ", errStatus); // $NON-NLS-1$ } } }
private void initUI() { try { SqlMapClient sqlClient = TadpoleSQLManager.getInstance(userDB); List listTableInform = sqlClient.queryForList("tableInformation", userDB.getDb()); // $NON-NLS-1$ tvTableInform.setInput(listTableInform); tvTableInform.refresh(); } catch (Exception e) { logger.error("initialize session list", e); // $NON-NLS-1$ Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); // $NON-NLS-1$ ExceptionDetailsErrorDialog.openError( null, "Error", Messages.MainEditor_19, errStatus); // $NON-NLS-1$ } // google analytic AnalyticCaller.track(RDBDBInfosEditor.ID, "TablesComposite"); // $NON-NLS-1$ }
/** * tree에 user resource 항목을 추가합니다. * * @param userDB */ public void addUserResouceData() { try { comboViewer.getCombo().clearSelection(); textTitle.setText(""); textDescription.setText(""); textQuery.setText(""); List<ResourceManagerDAO> listUserDBResources = TadpoleSystem_UserDBResource.userDbResource(userDB); tableViewer.setInput(listUserDBResources); tableViewer.refresh(); } catch (Exception e) { logger.error("user_db_erd list", e); // $NON-NLS-1$ Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); // $NON-NLS-1$ ExceptionDetailsErrorDialog.openError( getSite().getShell(), "Error", "Can't load resource...", errStatus); // $NON-NLS-1$ } }
/** System initialize If the system table does not exist, create a table. */ private void systemInitialize() { try { boolean isInitialize = TadpoleSystemInitializer.initSystem(); if (!isInitialize) { if (logger.isInfoEnabled()) logger.info("Initialize System default setting."); WizardDialog dialog = new WizardDialog(null, new SystemInitializeWizard()); if (Dialog.OK != dialog.open()) { throw new Exception("System initialize fail.\n"); } } } catch (Exception e) { logger.error("System initialize error", e); // $NON-NLS-1$ Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); // $NON-NLS-1$ ExceptionDetailsErrorDialog.openError( null, "Error", com.hangum.tadpole.application.start.Messages.ApplicationWorkbenchWindowAdvisor_2, errStatus); //$NON-NLS-1$ System.exit(0); } }
@Override public void run() { try { CompoundCommand commands = new CompoundCommand(); List models = getViewer().getContents().getChildren(); NodeList graphNodes = new NodeList(); EdgeList graphEdges = new EdgeList(); // nodes for (int i = 0; i < models.size(); i++) { Object obj = models.get(i); if (obj instanceof TableEditPart) { TableEditPart editPart = (TableEditPart) obj; Table model = (Table) editPart.getModel(); EntityNode node = new EntityNode(); node.model = model; node.width = editPart.getFigure().getSize().width; node.height = editPart.getFigure().getSize().height + 40; graphNodes.add(node); } } // edge for (int i = 0; i < models.size(); i++) { Object obj = models.get(i); if (obj instanceof TableEditPart) { TableEditPart tableEditpart = (TableEditPart) obj; List outgoing = tableEditpart.getSourceConnections(); for (int j = 0; j < outgoing.size(); j++) { RelationEditPart conn = (RelationEditPart) outgoing.get(j); EntityNode source = (EntityNode) getNode(graphNodes, (Table) conn.getSource().getModel()); EntityNode target = (EntityNode) getNode(graphNodes, (Table) conn.getTarget().getModel()); if (source != null && target != null) { ConnectionEdge edge = new ConnectionEdge(source, target); Relation relation = (Relation) conn.getModel(); edge.model = relation.getSource(); graphEdges.add(edge); } } } } DirectedGraph graph = new DirectedGraph(); graph.nodes = graphNodes; graph.edges = graphEdges; new DirectedGraphLayout().visit(graph); for (int i = 0; i < graph.nodes.size(); i++) { EntityNode node = (EntityNode) graph.nodes.getNode(i); commands.add(new LayoutCommand(node.model, node.x, node.y)); } getViewer().getEditDomain().getCommandStack().execute(commands); } catch (Exception e) { logger.error(Messages.AutoLayoutAction_2, e); Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); // $NON-NLS-1$ ExceptionDetailsErrorDialog.openError( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error", Messages.AutoLayoutAction_3, errStatus); //$NON-NLS-1$ } }
@Override public void run(IStructuredSelection selection, UserDBDAO userDB, OBJECT_TYPE actionType) { try { PublicTadpoleDefine.QUERY_DML_TYPE queryType = QUERY_DML_TYPE.INSERT; if (queryType == QUERY_DML_TYPE.INSERT) { if (PublicTadpoleDefine.YES_NO .YES .name() .equals(userDB.getDbAccessCtl().getInsert_lock())) { throw new Exception(Messages.get().MainEditor_21); } } queryType = QUERY_DML_TYPE.UPDATE; if (queryType == QUERY_DML_TYPE.UPDATE) { if (PublicTadpoleDefine.YES_NO .YES .name() .equals(userDB.getDbAccessCtl().getUpdate_lock())) { throw new Exception(Messages.get().MainEditor_21); } } queryType = QUERY_DML_TYPE.DELETE; if (queryType == QUERY_DML_TYPE.DELETE) { if (PublicTadpoleDefine.YES_NO .YES .name() .equals(userDB.getDbAccessCtl().getDelete_locl())) { throw new Exception(Messages.get().MainEditor_21); } } } catch (Exception e) { MessageDialog.openError( getWindow().getShell(), Messages.get().ObjectDeleteAction_2, e.getMessage()); return; } try { if (!GrantCheckerUtils.ifExecuteQuery(userDB)) return; } catch (Exception e) { MessageDialog.openError( getWindow().getShell(), Messages.get().ObjectDeleteAction_2, e.getMessage()); return; } TableDAO tableDAO = (TableDAO) selection.getFirstElement(); try { // get the table columns SqlMapClient sqlClient = TadpoleSQLManager.getInstance(userDB); Map<String, String> mapParam = new HashMap<String, String>(); mapParam.put("db", userDB.getDb()); // $NON-NLS-1$ mapParam.put("table", tableDAO.getName()); // $NON-NLS-1$ List showTableColumns = sqlClient.queryForList("tableColumnList", mapParam); // $NON-NLS-1$ // Open the table director editor IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); DBTableEditorInput dbEditorInput = new DBTableEditorInput(tableDAO, userDB, showTableColumns); page.openEditor(dbEditorInput, TableInformationEditor.ID, false); } catch (Exception e) { logger.error("Load the table data", e); // $NON-NLS-1$ Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); // $NON-NLS-1$ ExceptionDetailsErrorDialog.openError( null, "Error", Messages.get().ExplorerViewer_39, errStatus); // $NON-NLS-1$ } }
@Override protected void handleDrop() { String[] arrayDragSourceData = null; try { arrayDragSourceData = StringUtils.splitByWholeSeparator( ((String) getCurrentEvent().data), PublicTadpoleDefine.DELIMITER); int sourceDBSeq = Integer.parseInt(arrayDragSourceData[0]); if (userDB.getSeq() != sourceDBSeq) { MessageDialog.openError( null, "Error", Messages.TableTransferDropTargetListener_1); // $NON-NLS-1$ return; } } catch (Exception e) { logger.error("dragger error", e); // $NON-NLS-1$ MessageDialog.openError( null, "Error", "Draging exception : " + e.getMessage()); // $NON-NLS-1$ return; } String tableName = arrayDragSourceData[1]; String refTableNames = "'" + tableName + "',"; // $NON-NLS-1$ //$NON-NLS-2$ // 이미 editor 상에 테이블 정보를 가져온다. Map<String, Table> mapDBTables = new HashMap<String, Table>(); for (Table table : db.getTables()) { mapDBTables.put(table.getName(), table); refTableNames += "'" + table.getName() + "',"; // $NON-NLS-1$ //$NON-NLS-2$ } refTableNames = StringUtils.chompLast(refTableNames, ","); // $NON-NLS-1$ // 이미 등록되어 있는 것이 아니라면 if (mapDBTables.get(tableName) == null) { // 테이블 모델 생성 Table tableModel = tadpoleFactory.createTable(); tableModel.setName(tableName); tableModel.setDb(db); if (userDB.getDBDefine() == DBDefine.SQLite_DEFAULT) { tableModel.setComment(""); } else { String tableComment = arrayDragSourceData[2]; tableComment = StringUtils.substring("" + tableComment, 0, 10); tableModel.setComment(tableComment); } tableModel.setConstraints(new Rectangle(getDropLocation().x, getDropLocation().y, -1, -1)); try { // 컬럼 모델 생성 for (TableColumnDAO columnDAO : getColumns(tableName)) { Column column = tadpoleFactory.createColumn(); column.setDefault(columnDAO.getDefault()); column.setExtra(columnDAO.getExtra()); column.setField(columnDAO.getField()); column.setNull(columnDAO.getNull()); column.setKey(columnDAO.getKey()); column.setType(columnDAO.getType()); String strComment = columnDAO.getComment(); if (strComment == null) strComment = ""; else strComment = StringUtils.substring("" + strComment, 0, 10); column.setComment(strComment); column.setTable(tableModel); tableModel.getColumns().add(column); } mapDBTables.put(tableName, tableModel); RelationUtil.calRelation( userDB, mapDBTables, db, refTableNames); // RelationUtil.getReferenceTable(userDB, refTableNames)); } catch (Exception e) { logger.error("GEF Table Drag and Drop Exception", e); // $NON-NLS-1$ Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); // $NON-NLS-1$ ExceptionDetailsErrorDialog.openError( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error", Messages.TadpoleModelUtils_2, errStatus); //$NON-NLS-1$ } transferFactory.setTable(tableModel); } else { transferFactory.setTable(mapDBTables.get(tableName)); } super.handleDrop(); }
// /** // * export images // * // * RAP currently, GC drawing is only supported on Canvas, but not on image. // */ // public void exportImage() { // try { // IFigure figure = // ((AbstractGraphicalEditPart)getGraphicalViewer().getRootEditPart()).getFigure(); // File file = new File ("/Users/hangum/Downloads/gefout.png"); // if (file.exists ()) { // if (!MessageDialog.openQuestion(null, "prompted", "The file already exists. Want // to re-cover it?")) { // return; // } // } else { // file.createNewFile (); // } // // if (figure instanceof Viewport) { // ((Viewport)figure).setViewLocation(0, 0); // } // // Dimension size = figure.getPreferredSize (); // Image image = new Image (Display.getDefault (), size.width, size.height); //// Drawable drawable = (Drawable)image; // // GC gc = new GC(getSite().getShell().getDisplay()); // gc.drawImage(image, size.width, size.height); // SWTGraphics graphics = new SWTGraphics(gc); // figure.paint (graphics); // // ImageLoader loader = new ImageLoader (); // loader.data = new ImageData []{image.getImageData ()}; // loader.save("/Users/hangum/Downloads/gefout.png", // SWT.IMAGE_PNG);//FileFormat.FORMATS); // // graphics.dispose(); // gc.dispose(); // image.dispose(); // // } catch (Exception e) { // e.printStackTrace(); // } finally { // } // } @Override public void doSave(IProgressMonitor monitor) { // exportImage(); // 신규 저장이면 if (userDBErd == null) { // file 이름 dialog ResourceSaveDialog rsDialog = new ResourceSaveDialog(null, null, userDB, PublicTadpoleDefine.RESOURCE_TYPE.ERD, ""); if (rsDialog.open() == Window.OK) { try { // erd 정보 디비저장 userDBErd = TadpoleSystem_UserDBResource.saveResource( userDB, rsDialog.getRetResourceDao(), createResourceToString()); userDBErd.setParent(userDB); // command stack 초기화 getCommandStack().markSaveLocation(); // title 수정 setPartName(userDBErd.getName()); // managerView tree refresh // 뒤에 시간을붙인것은 한번 저장한 db_seq는 업데이지 않는 오류를 방지하기위해... // PlatformUI.getPreferenceStore() .setValue( PublicTadpoleDefine.SAVE_FILE, "" + userDBErd.getDb_seq() + ":" + System.currentTimeMillis()); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } catch (Exception e) { logger.error(Messages.get().TadpoleEditor_9, e); Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); // $NON-NLS-1$ ExceptionDetailsErrorDialog.openError( getSite().getShell(), "Error", Messages.get().TadpoleEditor_3, errStatus); //$NON-NLS-1$ } } // 기존 리소스를 가지고 있었으면 } else { try { TadpoleSystem_UserDBResource.updateResource(userDBErd, createResourceToString()); getCommandStack().markSaveLocation(); } catch (Exception e) { logger.error(Messages.get().TadpoleEditor_12, e); Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); // $NON-NLS-1$ ExceptionDetailsErrorDialog.openError( getSite().getShell(), "Error", Messages.get().TadpoleEditor_1, errStatus); //$NON-NLS-1$ } } }
/** * delete message * * @param msgHead * @param e */ protected void exeMessage(String msgHead, Exception e) { Status errStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); // $NON-NLS-1$ ExceptionDetailsErrorDialog.openError( null, "Error", msgHead + Messages.ObjectDeleteAction_25, errStatus); // $NON-NLS-1$ }