📄 edittableconstraintspanel.java
字号:
} /** * Returns the table displaying the constraint data. * * @return the table displaying the data */ public JTable getTable() { return table; } public void addTableFocusListener(FocusListener listener) { table.addFocusListener(listener); } /** * Clears all the SQL text. */ public void reset() { sqlBuffer.setLength(0); tempSqlText.clear(); } /** * Removes the SQL with the specified reference key * from the temp buffer. * * @param key - the reference key to the SQL text */ protected void removeFromBuffer(String key) { tempSqlText.remove(key); } /** * Adds the specified value SQL text with the specified key * to the temp SQL buffer. * * @param key - the key to reference the SQL text value * @param value - the SQL text */ protected void addToBuffer(String key, String value) { tempSqlText.put(key, value); } /** * Generates the SQL statements based on the stored value changes. */ protected void generateSQL() { sqlBuffer.setLength(0); for (Enumeration i = tempSqlText.elements(); i.hasMoreElements();) { sqlBuffer.append((String)i.nextElement()); } } /** * Stores the original unmodified key values. */ public void setOriginalData() { GUIUtils.startWorker(new Runnable() { //SwingUtilities.invokeLater(new Runnable() { public void run() { Vector fKeys = model.getKeys(); int v_size = fKeys.size(); fKeys_orig = new ColumnConstraint[v_size]; for (int i = 0; i < v_size; i++) { fKeys_orig[i] = new ColumnConstraint(); fKeys_orig[i].setValues((ColumnConstraint)fKeys.elementAt(i)); } } }); } /** * Marks the currently selected column (table row) * to be deleted/dropped from this table. */ public void markDeleteRow() { int row = getSelectedRow(); if (row == -1) { return; } table.editingStopped(null); if (table.isEditing()) { table.removeEditor(); } ColumnConstraint cc = getConstraintAt(row); // if its already a new row - just remove it if (cc.isNewConstraint()) { //int newEditingRow = (row == tableVector.size() - 1) ? row - 1 : row; //setEditingRow(newEditingRow); model.deleteConstraint(row); tempSqlText.remove(ADD_CONSTRAINT + row); // add the dummy row if (model.getRowCount() == 0) { model.insertRowAfter(true); } // regenerate the SQL generateSQL(); return; } // create the drop statement sqlBuffer.setLength(0); sqlBuffer.append(ALTER_TABLE); /* String schema = cc.getRefSchema(); if (!MiscUtilities.isNull(schema)) { sqlBuffer.append(schema.toUpperCase()).append(DOT); } */ sqlBuffer.append(cc.getTable()); sqlBuffer.append(DROP_CONSTRAINT); sqlBuffer.append(cc.getName()); sqlBuffer.append(NEW_LINE); tempSqlText.put(DROP_CONSTRAINT + row, sqlBuffer.toString()); // mark the column to be dumped cc.setMarkedDeleted(true); // regenerate the SQL generateSQL(); // fire the event model.fireTableRowsUpdated(row, row); } public void insertRowAfter() { model.insertRowAfter(true); } public void deleteSelectedRow(QuerySender qs) { table.editingStopped(null); if (table.isEditing()) { table.removeEditor(); } int row = table.getSelectedRow(); ColumnConstraint cc = getConstraintAt(row); if (!cc.isNewConstraint()) { deleteSelectedRow(row, qs); return; } int newEditingRow = row == model.getRowCount() - 1 ? row - 1 : row; table.setEditingRow(newEditingRow); model.deleteRow(row); tempSqlText.remove(ADD_CONSTRAINT + row); model.fireTableRowsDeleted(row, row); generateSQL(); creator.setSQLText(sqlBuffer.toString(), TableModifier.CONSTRAINT_VALUES); if (model.getKeys().size() == 0) { model.insertRowAfter(true); } } public void deleteSelectedRow(int row, QuerySender qs) { if (row == -1) { return; } ColumnConstraint cc = getConstraintAt(row); int yesNo = GUIUtilities.displayConfirmDialog( "Are you sure you want to remove\nthe constraint " + cc.getName() + "?"); if (yesNo == JOptionPane.NO_OPTION) return; else { try { SqlStatementResult result = qs.updateRecords( ALTER_TABLE + creator.getTableName() + DROP_CONSTRAINT + cc.getName()); if (result.getUpdateCount() >= 0) { int newEditingRow = (row == model.getRowCount() - 1 ? row - 1 : row); table.setEditingRow(newEditingRow); model.deleteRow(row); model.fireTableRowsDeleted(row, row); } else { SQLException e = result.getSqlException(); if (e != null) { StringBuffer sb = new StringBuffer(); sb.append("An error occurred applying the specified changes."). append("\n\nThe system returned:\n"). append(MiscUtils.formatSQLError(e)); GUIUtilities.displayExceptionErrorDialog(sb.toString(), e); } else { GUIUtilities.displayErrorMessage(result.getErrorMessage()); } } } catch (Exception e) { e.printStackTrace(); StringBuffer sb = new StringBuffer(); sb.append("An error occurred applying the specified changes."). append("\n\nThe system returned:\n"). append(e.getMessage()); GUIUtilities.displayExceptionErrorDialog(sb.toString(), e); } } } public String getSQLText() { return sqlBuffer.toString(); } public void columnValuesChanged() { columnValuesChanged(-1, -1, null); } private class MouseHandler extends MouseAdapter { public MouseHandler() {} public void mouseClicked(MouseEvent e) { int mouseX = e.getX(); int mouseY = e.getY(); int col = table.columnAtPoint(new Point(mouseX, mouseY)); // if we haven't clicked on column 0 - bail if (col != 0) { return; } int row = table.rowAtPoint(new Point(mouseX, mouseY)); Object object = model.getValueAt(row, col); if (object == null) { return; } ColumnConstraint cc = (ColumnConstraint)object; // if this constraint is marked to be dropped, unmark it if (cc.isMarkedDeleted()) { cc.setMarkedDeleted(false); tempSqlText.remove(DROP_CONSTRAINT + row); model.fireTableRowsUpdated(row, row); generateSQL(); creator.setSQLText(); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -