Search in sources :

Example 16 with DBEObjectMaker

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);
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBException(org.jkiss.dbeaver.DBException) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) DBEObjectMaker(org.jkiss.dbeaver.model.edit.DBEObjectMaker)

Example 17 with DBEObjectMaker

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);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBEObjectMaker(org.jkiss.dbeaver.model.edit.DBEObjectMaker) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject)

Example 18 with DBEObjectMaker

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;
    }
}
Also used : DBSWrapper(org.jkiss.dbeaver.model.struct.DBSWrapper) IContributionItem(org.eclipse.jface.action.IContributionItem) DBEObjectMaker(org.jkiss.dbeaver.model.edit.DBEObjectMaker)

Aggregations

DBEObjectMaker (org.jkiss.dbeaver.model.edit.DBEObjectMaker)18 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)16 DBException (org.jkiss.dbeaver.DBException)12 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)5 DBPObject (org.jkiss.dbeaver.model.DBPObject)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 DBPRefreshableObject (org.jkiss.dbeaver.model.DBPRefreshableObject)4 DBSWrapper (org.jkiss.dbeaver.model.struct.DBSWrapper)4 DBPScriptObject (org.jkiss.dbeaver.model.DBPScriptObject)3 HashMap (java.util.HashMap)2 IContributionItem (org.eclipse.jface.action.IContributionItem)2 Display (org.eclipse.swt.widgets.Display)2 DBPNamedObject (org.jkiss.dbeaver.model.DBPNamedObject)2 DBPOrderedObject (org.jkiss.dbeaver.model.DBPOrderedObject)2 DBECommand (org.jkiss.dbeaver.model.edit.DBECommand)2 DBECommandContext (org.jkiss.dbeaver.model.edit.DBECommandContext)2 DBEObjectRenamer (org.jkiss.dbeaver.model.edit.DBEObjectRenamer)2 DBEObjectReorderer (org.jkiss.dbeaver.model.edit.DBEObjectReorderer)2 DBEPersistAction (org.jkiss.dbeaver.model.edit.DBEPersistAction)2 DBNContainer (org.jkiss.dbeaver.model.navigator.DBNContainer)2