use of org.jkiss.dbeaver.model.navigator.DBNContainer in project dbeaver by dbeaver.
the class ModelPropertyTester method test.
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (!(receiver instanceof DBSObject)) {
return false;
}
Display display = Display.getCurrent();
if (display == null) {
return false;
}
switch(property) {
case PROP_CHILD_OF_TYPE:
{
{
DBSObject object = (DBSObject) receiver;
if (object instanceof DBSObjectContainer) {
if (expectedValue instanceof String) {
try {
Class<?> expectedChildClass = Class.forName((String) expectedValue);
Class<? extends DBSObject> childType = ((DBSObjectContainer) object).getPrimaryChildType(null);
return expectedChildClass.isAssignableFrom(childType);
} catch (Exception e) {
return false;
}
}
}
}
return false;
}
case PROP_IS_TABLE_CONTAINER:
{
DBSObject object = DBUtils.getPublicObject((DBSObject) receiver);
if (object instanceof DBNContainer) {
Object valueObject = ((DBNContainer) object).getValueObject();
if (valueObject instanceof DBSObject) {
object = (DBSObject) valueObject;
}
}
if (object instanceof DBSSchema) {
return true;
}
if (object instanceof DBSObjectContainer) {
try {
Class<? extends DBSObject> primaryChildType = ((DBSObjectContainer) object).getPrimaryChildType(null);
if (DBSDataContainer.class.isAssignableFrom(primaryChildType)) {
return true;
}
} catch (DBException e) {
log.debug(e);
}
}
return false;
}
}
return false;
}
use of org.jkiss.dbeaver.model.navigator.DBNContainer in project dbeaver by dbeaver.
the class NavigatorHandlerObjectMove method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final ISelection selection = HandlerUtil.getCurrentSelection(event);
DBNNode node = NavigatorUtils.getSelectedNode(selection);
if (node == null || !(node.getParentNode() instanceof DBNContainer)) {
return null;
}
DBSObject object = ((DBNDatabaseNode) node).getObject();
if (!(object instanceof DBPOrderedObject)) {
return null;
}
@SuppressWarnings("unchecked") DBEObjectReorderer<DBSObject> objectReorderer = DBWorkbench.getPlatform().getEditorsRegistry().getObjectManager(object.getClass(), DBEObjectReorderer.class);
if (objectReorderer == null) {
return null;
}
DBPOrderedObject orderedObject = (DBPOrderedObject) object;
try {
// Sibling objects - they are involved in reordering process
List<DBSObject> siblingObjects = new ArrayList<>();
for (DBNNode siblingNode : node.getParentNode().getChildren(new VoidProgressMonitor())) {
if (siblingNode instanceof DBNDatabaseNode) {
DBSObject siblingObject = ((DBNDatabaseNode) siblingNode).getObject();
if (siblingObject.getClass() != object.getClass()) {
log.warn("Sibling object class " + siblingObject.getClass() + " differs from moving object class " + object.getClass().getName());
} else {
siblingObjects.add(siblingObject);
}
} else {
log.warn("Wrong sibling node type: " + siblingNode);
}
}
CommandTarget commandTarget = getCommandTarget(HandlerUtil.getActiveWorkbenchWindow(event), node.getParentNode(), object.getClass(), false);
String actionId = event.getCommand().getId();
switch(actionId) {
case NavigatorCommands.CMD_OBJECT_MOVE_UP:
objectReorderer.setObjectOrdinalPosition(commandTarget.getContext(), object, siblingObjects, orderedObject.getOrdinalPosition() - 1);
break;
case NavigatorCommands.CMD_OBJECT_MOVE_DOWN:
objectReorderer.setObjectOrdinalPosition(commandTarget.getContext(), object, siblingObjects, orderedObject.getOrdinalPosition() + 1);
break;
}
if (object.isPersisted() && commandTarget.getEditor() == null) {
Map<String, Object> options = DBPScriptObject.EMPTY_OPTIONS;
if (!showScript(HandlerUtil.getActiveWorkbenchWindow(event), commandTarget.getContext(), options, "Reorder script")) {
commandTarget.getContext().resetChanges(true);
return false;
} else {
ObjectSaver orderer = new ObjectSaver(commandTarget.getContext(), options);
TasksJob.runTask("Change object '" + object.getName() + "' position", orderer);
}
}
} catch (DBException e) {
DBWorkbench.getPlatformUI().showError("Object move", "Error during object reposition", e);
}
return null;
}
Aggregations