use of org.jkiss.dbeaver.model.edit.DBEObjectMaker in project dbeaver by dbeaver.
the class NavigatorObjectsDeleter method of.
static NavigatorObjectsDeleter of(final List<Object> selection, final IWorkbenchWindow window) {
DBPDataSource dataSource = null;
boolean hasNodesFromDifferentDataSources = false;
boolean showCascade = false;
boolean showViewScript = false;
boolean showKeepContents = false;
for (Object obj : selection) {
if (obj instanceof DBNProject) {
showKeepContents = true;
continue;
}
if (!(obj instanceof DBNDatabaseNode)) {
continue;
}
final DBNDatabaseNode node = (DBNDatabaseNode) obj;
final DBPDataSource currentDatasource = node.getDataSource();
if (dataSource == null) {
dataSource = currentDatasource;
} else if (!dataSource.equals(currentDatasource)) {
hasNodesFromDifferentDataSources = true;
}
if (!(node.getParentNode() instanceof DBNContainer)) {
continue;
}
final DBSObject object = node.getObject();
if (object == null) {
continue;
}
final DBEObjectMaker objectMaker = DBWorkbench.getPlatform().getEditorsRegistry().getObjectManager(object.getClass(), DBEObjectMaker.class);
if (objectMaker == null) {
continue;
}
showCascade |= (objectMaker.getMakerOptions(object.getDataSource()) & DBEObjectMaker.FEATURE_DELETE_CASCADE) != 0;
final NavigatorHandlerObjectBase.CommandTarget commandTarget;
try {
commandTarget = NavigatorHandlerObjectBase.getCommandTarget(window, node.getParentNode(), object.getClass(), false);
} catch (DBException e) {
continue;
}
if (object.isPersisted() && commandTarget.getEditor() == null && commandTarget.getContext() != null) {
showViewScript = true;
}
}
return new NavigatorObjectsDeleter(selection, window, hasNodesFromDifferentDataSources, showCascade, showViewScript, showKeepContents);
}
use of org.jkiss.dbeaver.model.edit.DBEObjectMaker in project dbeaver by dbeaver.
the class NavigatorObjectsDeleter method deleteDatabaseNode.
private void deleteDatabaseNode(final DBNDatabaseNode node) {
try {
if (!(node.getParentNode() instanceof DBNContainer)) {
throw new DBException("Node '" + node + "' doesn't have a container");
}
final DBSObject object = node.getObject();
if (object == null) {
throw new DBException("Can't delete node with null object");
}
final DBEObjectMaker objectMaker = DBWorkbench.getPlatform().getEditorsRegistry().getObjectManager(object.getClass(), DBEObjectMaker.class);
if (objectMaker == null) {
// $NON-NLS-2$
throw new DBException("Object maker not found for type '" + object.getClass().getName() + "'");
}
final boolean supportsCascade = (objectMaker.getMakerOptions(object.getDataSource()) & DBEObjectMaker.FEATURE_DELETE_CASCADE) != 0;
final NavigatorHandlerObjectBase.CommandTarget commandTarget = NavigatorHandlerObjectBase.getCommandTarget(window, node.getParentNode(), object.getClass(), false);
if (!object.isPersisted() || commandTarget.getEditor() != null) {
// There should be command context somewhere
if (deleteNewObject(node)) {
return;
}
// No direct editor host found for this object -
// try to find corresponding command context
// and execute command within it
}
Map<String, Object> deleteOptions = Collections.emptyMap();
if (deleteCascade && supportsCascade) {
deleteOptions = OPTIONS_CASCADE;
}
objectMaker.deleteObject(commandTarget.getContext(), node.getObject(), deleteOptions);
if (commandTarget.getEditor() == null && commandTarget.getContext() != null) {
// Persist object deletion - only if there is no host editor and we have a command context
final NavigatorHandlerObjectBase.ObjectSaver deleter = new NavigatorHandlerObjectBase.ObjectSaver(commandTarget.getContext(), deleteOptions);
tasksToExecute.add(deleter);
}
} catch (Throwable e) {
DBWorkbench.getPlatformUI().showError(UINavigatorMessages.actions_navigator_error_dialog_delete_object_title, NLS.bind(UINavigatorMessages.actions_navigator_error_dialog_delete_object_message, node.getNodeName()), e);
}
}
use of org.jkiss.dbeaver.model.edit.DBEObjectMaker in project dbeaver by dbeaver.
the class ObjectPropertyTester method canCreateObject.
public static boolean canCreateObject(DBNNode node, Boolean onlySingle) {
if (node instanceof DBNDatabaseNode) {
if (((DBNDatabaseNode) node).isVirtual()) {
// Can't create virtual objects
return false;
}
if (!(node instanceof DBNDataSource) && isMetadataChangeDisabled(((DBNDatabaseNode) node))) {
return false;
}
}
if (onlySingle == null) {
// Just try to find first create handler
if (node instanceof DBNDataSource) {
// We always can create datasource
return true;
}
Class objectType;
if (!(node instanceof DBNContainer)) {
if (node.getParentNode() instanceof DBNContainer) {
node = node.getParentNode();
}
}
DBNContainer container;
if (node instanceof DBNContainer) {
// Try to detect child type
objectType = ((DBNContainer) node).getChildrenClass();
container = (DBNContainer) node;
} else {
return false;
}
if (DBNUtils.isReadOnly(node)) {
return false;
}
if (node instanceof DBSWrapper && DBUtils.isReadOnly(((DBSWrapper) node).getObject())) {
return false;
}
if (objectType == null) {
return false;
}
DBEObjectMaker objectMaker = getObjectManager(objectType, DBEObjectMaker.class);
if (objectMaker == null) {
return false;
}
return objectMaker.canCreateObject(container.getValueObject());
}
if (DBNUtils.isReadOnly(node)) {
return false;
}
// Check whether only single object type can be created or multiple ones
List<IContributionItem> createItems = NavigatorHandlerObjectCreateNew.fillCreateMenuItems(null, node);
if (onlySingle) {
return createItems.size() == 1;
} else {
return createItems.size() > 1;
}
}
Aggregations