@Override public void selectionChanged(WbSelectionModel list) { WbConnection conn = this.source.getConnection(); if (conn == null || conn.isSessionReadOnly()) { setEnabled(false); } else { List<DbObject> objects = source.getSelectedObjects(); if (CollectionUtil.isEmpty(objects)) { setEnabled(false); return; } int colCount = 0; int selCount = objects.size(); for (DbObject dbo : objects) { if (dbo instanceof ColumnIdentifier) { colCount++; } } if (colCount > 0 && colCount == selCount) { TableIdentifier tbl = source.getObjectTable(); setEnabled(tbl != null); } else { setEnabled(this.available && (colCount == 0 && selCount > 0)); } } }
@Override public void executeAction(ActionEvent e) { List<? extends DbObject> objects = source.getSelectedObjects(); List<DbObject> scriptObjects = new ArrayList<>(objects.size()); List<ColumnIdentifier> cols = new ArrayList<>(); for (DbObject dbo : objects) { if (dbo instanceof TableIdentifier) { TableIdentifier tbl = (TableIdentifier) dbo; if (scriptType.equalsIgnoreCase(ObjectScripter.TYPE_SELECT)) { scriptObjects.add(new DummySelect(tbl)); } else if (scriptType.equalsIgnoreCase(ObjectScripter.TYPE_UPDATE)) { scriptObjects.add(new DummyUpdate(tbl)); } else if (scriptType.equalsIgnoreCase(ObjectScripter.TYPE_INSERT)) { scriptObjects.add(new DummyInsert(tbl)); } } else if (dbo instanceof ColumnIdentifier) { cols.add((ColumnIdentifier) dbo); } } if (cols.size() > 0) { TableIdentifier tbl = source.getObjectTable(); if (tbl != null) { if (scriptType.equalsIgnoreCase(ObjectScripter.TYPE_SELECT)) { scriptObjects.add(new DummySelect(tbl, cols)); } else { scriptObjects.add(new DummyInsert(tbl, cols)); } } } ObjectScripter s = new ObjectScripter(scriptObjects, source.getConnection()); ObjectScripterUI scripterUI = new ObjectScripterUI(s); scripterUI.show(SwingUtilities.getWindowAncestor(source.getComponent())); }
private boolean needAutoCommit(List<DbObject> objects) { DbSettings dbs = source.getConnection().getDbSettings(); for (DbObject dbo : objects) { if (!dbs.canDropInTransaction(dbo.getObjectType())) { return true; } } return false; }
private void checkEnabled() { if (selection.hasSelection()) { List<? extends DbObject> objects = source.getSelectedObjects(); for (DbObject dbo : objects) { if (!(dbo instanceof TableIdentifier)) { setEnabled(false); return; } } setEnabled(true); } else { setEnabled(false); } }
private void dropObjects() { if (!WbSwingUtilities.isConnectionIdle(source.getComponent(), source.getConnection())) return; final List<DbObject> objects = source.getSelectedObjects(); if (objects == null || objects.isEmpty()) return; boolean autoCommitChanged = false; boolean autoCommit = source.getConnection().getAutoCommit(); ObjectDropperUI dropperUI = null; try { // this is essentially here for the DbTree, because the DbTree sets its own connection // to autocommit regardless of the profile to reduce locking when retrieving data. // If the profile was not set to autocommit the dropping of the objects should be done in a // transaction. if (autoCommit && !source.getConnection().getProfile().getAutocommit()) { source.getConnection().changeAutoCommit(false); autoCommitChanged = true; } if (!autoCommit && needAutoCommit(objects)) { source.getConnection().changeAutoCommit(true); autoCommitChanged = true; } ObjectDropper dropperToUse = this.dropper; if (dropperToUse == null) { if (objects.get(0) instanceof ColumnIdentifier) { dropperToUse = new ColumnDropper(); } else { dropperToUse = new GenericObjectDropper(); } } dropperToUse.setObjects(objects); dropperToUse.setConnection(source.getConnection()); dropperToUse.setObjectTable(source.getObjectTable()); dropperUI = new ObjectDropperUI(dropperToUse); JFrame f = (JFrame) SwingUtilities.getWindowAncestor(source.getComponent()); dropperUI.showDialog(f); } finally { if (autoCommitChanged) { source.getConnection().changeAutoCommit(autoCommit); } } if (dropperUI.success() && !dropperUI.dialogWasCancelled()) { EventQueue.invokeLater( new Runnable() { @Override public void run() { if (data != null) { data.reload(); } if (dropListener != null) { dropListener.objectsDropped(objects); } } }); } }