Search in sources :

Example 16 with DBPResourceHandler

use of org.jkiss.dbeaver.model.app.DBPResourceHandler in project dbeaver by dbeaver.

the class ResourcePropertyTester method test.

@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
    if (!(receiver instanceof IResource)) {
        return false;
    }
    IResource resource = (IResource) receiver;
    final ProjectRegistry projectRegistry = DBeaverCore.getInstance().getProjectRegistry();
    DBPResourceHandler handler = projectRegistry.getResourceHandler(resource);
    if (handler == null) {
        return false;
    }
    switch(property) {
        case PROP_CAN_OPEN:
            return (handler.getFeatures(resource) & DBPResourceHandler.FEATURE_OPEN) != 0;
        case PROP_CAN_DELETE:
            return (handler.getFeatures(resource) & DBPResourceHandler.FEATURE_DELETE) != 0;
        case PROP_CAN_CREATE_FOLDER:
            return (handler.getFeatures(resource) & DBPResourceHandler.FEATURE_CREATE_FOLDER) != 0;
        case PROP_CAN_CREATE_LINK:
            return (handler.getFeatures(resource) & DBPResourceHandler.FEATURE_CREATE_FOLDER) != 0 && !resource.isLinked(IResource.CHECK_ANCESTORS);
        case PROP_CAN_SET_ACTIVE:
            return resource instanceof IProject && resource != projectRegistry.getActiveProject();
        case PROP_TYPE:
            final DBPResourceHandler resourceHandler = DBeaverCore.getInstance().getProjectRegistry().getResourceHandler(resource);
            return resourceHandler != null && expectedValue.equals(resourceHandler.getTypeName(resource));
    }
    return false;
}
Also used : ProjectRegistry(org.jkiss.dbeaver.registry.ProjectRegistry) DBPResourceHandler(org.jkiss.dbeaver.model.app.DBPResourceHandler) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Aggregations

DBPResourceHandler (org.jkiss.dbeaver.model.app.DBPResourceHandler)16 IResource (org.eclipse.core.resources.IResource)8 IProject (org.eclipse.core.resources.IProject)6 ArrayList (java.util.ArrayList)4 DBPProject (org.jkiss.dbeaver.model.app.DBPProject)4 DBPResourceCreator (org.jkiss.dbeaver.model.app.DBPResourceCreator)4 DBPWorkspace (org.jkiss.dbeaver.model.app.DBPWorkspace)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 java.util (java.util)2 List (java.util.List)2 IContainer (org.eclipse.core.resources.IContainer)2 IFile (org.eclipse.core.resources.IFile)2 IContributionItem (org.eclipse.jface.action.IContributionItem)2 Separator (org.eclipse.jface.action.Separator)2 IDialogConstants (org.eclipse.jface.dialogs.IDialogConstants)2 org.eclipse.jface.viewers (org.eclipse.jface.viewers)2 SWT (org.eclipse.swt.SWT)2 SashForm (org.eclipse.swt.custom.SashForm)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2