use of org.jkiss.dbeaver.model.edit.DBEObjectReorderer in project dbeaver by serge-rider.
the class ObjectPropertyTester method test.
@SuppressWarnings("unchecked")
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (!(receiver instanceof DBNNode)) {
return false;
}
Display display = Display.getCurrent();
if (display == null) {
return false;
}
DBNNode node = (DBNNode) receiver;
switch(property) {
case PROP_CAN_OPEN:
return node.isPersisted();
case PROP_CAN_CREATE:
case PROP_CAN_PASTE:
{
if (node instanceof DBNResource) {
return property.equals(PROP_CAN_PASTE);
}
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 (node instanceof DBSWrapper && isReadOnly(((DBSWrapper) node).getObject())) {
return false;
}
if (objectType == null) {
return false;
}
DBEObjectMaker objectMaker = getObjectManager(objectType, DBEObjectMaker.class);
if (objectMaker == null) {
return false;
}
if (!objectMaker.canCreateObject(container.getValueObject())) {
return false;
}
/*
if (property.equals(PROP_CAN_CREATE)) {
return true;
}
// Check objects in clipboard
Collection<DBNNode> cbNodes = TreeNodeTransfer.getFromClipboard();
if (cbNodes == null) {
return false;
}
for (DBNNode nodeObject : cbNodes) {
if (nodeObject.isManagable() && nodeObject instanceof DBSWrapper) {
DBSObject pasteObject = ((DBSWrapper)nodeObject).getObject();
if (pasteObject == null || objectType != pasteObject.getClass()) {
return false;
}
} else {
return false;
}
}
*/
return true;
}
case PROP_CAN_DELETE:
{
if (node instanceof DBNDataSource || node instanceof DBNLocalFolder) {
return true;
}
if (node instanceof DBSWrapper) {
DBSObject object = ((DBSWrapper) node).getObject();
if (object == null || isReadOnly(object) || !(node.getParentNode() instanceof DBNContainer)) {
return false;
}
DBEObjectMaker objectMaker = getObjectManager(object.getClass(), DBEObjectMaker.class);
return objectMaker != null && objectMaker.canDeleteObject(object);
} else if (node instanceof DBNResource) {
if ((((DBNResource) node).getFeatures() & DBPResourceHandler.FEATURE_DELETE) != 0) {
return true;
}
}
break;
}
case PROP_CAN_RENAME:
{
if (node.supportsRename()) {
return true;
}
if (node instanceof DBNDatabaseNode) {
DBSObject object = ((DBNDatabaseNode) node).getObject();
return object != null && !isReadOnly(object) && object.isPersisted() && node.getParentNode() instanceof DBNContainer && getObjectManager(object.getClass(), DBEObjectRenamer.class) != null;
}
break;
}
case PROP_CAN_MOVE_UP:
case PROP_CAN_MOVE_DOWN:
{
if (node instanceof DBNDatabaseNode) {
DBSObject object = ((DBNDatabaseNode) node).getObject();
if (object instanceof DBPOrderedObject) {
DBEObjectReorderer objectReorderer = getObjectManager(object.getClass(), DBEObjectReorderer.class);
if (objectReorderer != null) {
final int position = ((DBPOrderedObject) object).getOrdinalPosition();
if (property.equals(PROP_CAN_MOVE_UP)) {
return position > objectReorderer.getMinimumOrdinalPosition(object);
}
return position < objectReorderer.getMaximumOrdinalPosition(object);
}
}
}
break;
}
case PROP_CAN_FILTER:
{
if (node instanceof DBNDatabaseItem) {
node = node.getParentNode();
}
if (node instanceof DBNDatabaseFolder && ((DBNDatabaseFolder) node).getItemsMeta() != null) {
return true;
}
break;
}
case PROP_CAN_FILTER_OBJECT:
{
if (node.getParentNode() instanceof DBNDatabaseFolder && ((DBNDatabaseFolder) node.getParentNode()).getItemsMeta() != null) {
return true;
}
break;
}
case PROP_HAS_FILTER:
{
if (node instanceof DBNDatabaseItem) {
node = node.getParentNode();
}
if (node instanceof DBNDatabaseFolder && ((DBNDatabaseFolder) node).getItemsMeta() != null) {
DBSObjectFilter filter = ((DBNDatabaseFolder) node).getNodeFilter(((DBNDatabaseFolder) node).getItemsMeta(), true);
if ("defined".equals(expectedValue)) {
return filter != null && !filter.isEmpty();
} else {
return filter != null && !filter.isNotApplicable();
}
}
break;
}
}
return false;
}
Aggregations