use of org.jkiss.dbeaver.model.struct.DBSWrapper in project dbeaver by serge-rider.
the class BrowseObjectDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
getShell().setText(title);
Composite group = (Composite) super.createDialogArea(parent);
GridData gd = new GridData(GridData.FILL_BOTH);
group.setLayoutData(gd);
navigatorTree = new DatabaseNavigatorTree(group, rootNode, (singleSelection ? SWT.SINGLE : SWT.MULTI) | SWT.BORDER);
gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 500;
gd.heightHint = 500;
navigatorTree.setLayoutData(gd);
navigatorTree.getViewer().addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof TreeLoadNode || element instanceof DBNLocalFolder) {
return true;
}
if (element instanceof DBNNode) {
if (element instanceof DBNDatabaseFolder) {
DBNDatabaseFolder folder = (DBNDatabaseFolder) element;
Class<? extends DBSObject> folderItemsClass = folder.getChildrenClass();
return folderItemsClass != null && matchesType(folderItemsClass, false);
}
if (element instanceof DBNProject || element instanceof DBNProjectDatabases || element instanceof DBNDataSource || (element instanceof DBSWrapper && matchesType(((DBSWrapper) element).getObject().getClass(), false))) {
return true;
}
}
return false;
}
});
if (selectedNode != null) {
navigatorTree.getViewer().setSelection(new StructuredSelection(selectedNode));
selectedObjects.add(selectedNode);
}
navigatorTree.getViewer().addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
selectedObjects.clear();
IStructuredSelection selection = (IStructuredSelection) navigatorTree.getViewer().getSelection();
for (Iterator iter = selection.iterator(); iter.hasNext(); ) {
DBNNode node = (DBNNode) iter.next();
if (node instanceof DBSWrapper) {
DBSObject object = DBUtils.getAdapter(DBSObject.class, ((DBSWrapper) node).getObject());
if (object != null && matchesType(object.getClass(), true)) {
selectedObjects.add(node);
}
}
}
getButton(IDialogConstants.OK_ID).setEnabled(!selectedObjects.isEmpty());
}
});
return group;
}
use of org.jkiss.dbeaver.model.struct.DBSWrapper in project dbeaver by serge-rider.
the class NavigatorHandlerObjectGoto method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
DBCExecutionContext context = null;
DBSObject container = null;
IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
if (activePart instanceof DBPContextProvider) {
context = ((DBPContextProvider) activePart).getExecutionContext();
} else if (activePart instanceof INavigatorModelView) {
final ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof DBSWrapper) {
DBSObject object = ((DBSWrapper) element).getObject();
if (object != null) {
container = object;
while (container instanceof DBSFolder) {
container = container.getParentObject();
}
DBPDataSource dataSource = object.getDataSource();
if (dataSource != null) {
context = dataSource.getDefaultContext(true);
}
}
}
}
}
if (context == null) {
DBUserInterface.getInstance().showError("Go to object", "No active datasource");
return null;
}
IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
GotoObjectDialog dialog = new GotoObjectDialog(HandlerUtil.getActiveShell(event), context, container);
dialog.open();
Object[] objectsToOpen = dialog.getResult();
if (!ArrayUtils.isEmpty(objectsToOpen)) {
Collection<DBNDatabaseNode> nodes = NavigatorHandlerObjectBase.getNodesByObjects(Arrays.asList(objectsToOpen));
for (DBNDatabaseNode node : nodes) {
NavigatorUtils.openNavigatorNode(node, workbenchWindow);
}
}
return null;
}
use of org.jkiss.dbeaver.model.struct.DBSWrapper 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;
}
use of org.jkiss.dbeaver.model.struct.DBSWrapper in project dbeaver by serge-rider.
the class NavigatorAdapterFactory method getAdapter.
@Override
public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
if (adapterType == DBPDataSourceContainer.class) {
if (adaptableObject instanceof DBNDataSource) {
return adapterType.cast(((DBNDataSource) adaptableObject).getDataSourceContainer());
}
DBSObject object = DBUtils.getFromObject(adaptableObject);
if (object == null) {
return null;
}
if (object instanceof DBPDataSourceContainer) {
return adapterType.cast(object);
}
DBPDataSource dataSource = object.getDataSource();
return dataSource == null ? null : adapterType.cast(dataSource.getContainer());
} else if (DBPObject.class.isAssignableFrom(adapterType)) {
DBPObject object = null;
if (adaptableObject instanceof DBSWrapper) {
object = ((DBSWrapper) adaptableObject).getObject();
} else if (adaptableObject instanceof DBPObject) {
object = (DBPObject) adaptableObject;
}
if (object != null && adapterType.isAssignableFrom(object.getClass())) {
return adapterType.cast(object);
}
} else if (IResource.class.isAssignableFrom(adapterType)) {
if (adaptableObject instanceof DBNResource) {
return ((DBNResource) adaptableObject).getAdapter(adapterType);
}
} else if (adapterType == IPropertySource.class) {
DBPObject dbObject = null;
if (adaptableObject instanceof DBSWrapper) {
dbObject = ((DBSWrapper) adaptableObject).getObject();
} else if (adaptableObject instanceof DBPObject) {
dbObject = (DBPObject) adaptableObject;
}
if (dbObject instanceof IPropertySource) {
return adapterType.cast(dbObject);
}
if (dbObject instanceof DBPPropertySource) {
return adapterType.cast(new PropertySourceDelegate((DBPPropertySource) dbObject));
}
if (dbObject instanceof IAdaptable) {
Object adapter = ((IAdaptable) dbObject).getAdapter(IPropertySource.class);
if (adapter != null) {
return adapterType.cast(adapter);
}
adapter = ((IAdaptable) dbObject).getAdapter(DBPPropertySource.class);
if (adapter != null) {
return adapterType.cast(new PropertySourceDelegate((DBPPropertySource) adapter));
}
}
if (dbObject != null) {
PropertyCollector props = new PropertyCollector(adaptableObject, dbObject, true);
props.collectProperties();
if (props.isEmpty() && adaptableObject instanceof DBSObject) {
// Add default properties
DBSObject meta = (DBSObject) adaptableObject;
//$NON-NLS-1$
props.addProperty(null, DBConstants.PROP_ID_NAME, CoreMessages.model_navigator_Name, meta.getName());
//$NON-NLS-1$
props.addProperty(null, "desc", CoreMessages.model_navigator_Description, meta.getDescription());
}
return adapterType.cast(new PropertySourceDelegate(props));
}
} else if (adapterType == IWorkbenchAdapter.class) {
// Workbench adapter
if (adaptableObject instanceof DBNNode) {
final DBNNode node = (DBNNode) adaptableObject;
WorkbenchAdapter workbenchAdapter = new WorkbenchAdapter() {
@Override
public ImageDescriptor getImageDescriptor(Object object) {
return DBeaverIcons.getImageDescriptor(node.getNodeIconDefault());
}
@Override
public String getLabel(Object o) {
return node.getNodeName();
}
@Override
public Object getParent(Object o) {
return node.getParentNode();
}
};
return adapterType.cast(workbenchAdapter);
} else {
return null;
}
}
return null;
}
use of org.jkiss.dbeaver.model.struct.DBSWrapper in project dbeaver by serge-rider.
the class NavigatorUtils method isDefaultElement.
public static boolean isDefaultElement(Object element) {
if (element instanceof DBSWrapper) {
DBSObject object = ((DBSWrapper) element).getObject();
DBSObjectSelector activeContainer = DBUtils.getParentAdapter(DBSObjectSelector.class, object);
if (activeContainer != null) {
return activeContainer.getDefaultObject() == object;
}
} else if (element instanceof DBNProject) {
if (((DBNProject) element).getProject() == DBeaverCore.getInstance().getProjectRegistry().getActiveProject()) {
return true;
}
}
return false;
}
Aggregations