private void initData() { try { List<TableColumnDAO> showTableColumns = TadpoleObjectQuery.makeShowTableColumns(userDB, tableDAO); List<ExtendTableColumnDAO> newTableColumns = new ArrayList<ExtendTableColumnDAO>(); ExtendTableColumnDAO newTableDAO = new ExtendTableColumnDAO( "*", "", "", textTableAlias.getText().trim()); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ newTableDAO.setCheck(true); newTableColumns.add(newTableDAO); for (TableColumnDAO tableColumnDAO : showTableColumns) { String strSysName = SQLUtil.makeIdentifierName(userDB, tableColumnDAO.getField()); newTableDAO = new ExtendTableColumnDAO( tableColumnDAO.getField(), tableColumnDAO.getType(), tableColumnDAO.getKey(), textTableAlias.getText().trim()); newTableDAO.setSysName(strSysName); newTableDAO.setComment(tableColumnDAO.getComment()); newTableColumns.add(newTableDAO); } tableViewer.setInput(newTableColumns); tableViewer.refresh(); } catch (Exception e) { e.printStackTrace(); } }
@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(); }