Search in sources :

Example 11 with DBPResourceHandler

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

the class DBNResource method refreshResourceState.

public void refreshResourceState(Object source) {
    DBPResourceHandler newHandler = getModel().getPlatform().getWorkspace().getResourceHandler(resource);
    if (newHandler != handler) {
        handler = newHandler;
    }
    if (handler != null) {
        handler.updateNavigatorNode(this, resource);
    } else {
        log.error("Can't find handler for resource " + resource.getFullPath());
    }
    getModel().fireNodeEvent(new DBNEvent(source, DBNEvent.Action.UPDATE, this));
}
Also used : DBPResourceHandler(org.jkiss.dbeaver.model.app.DBPResourceHandler)

Example 12 with DBPResourceHandler

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

the class NavigatorHandlerObjectCreateNew method fillCreateMenuItems.

// If site is null then we need only item count. BAD CODE.
public static List<IContributionItem> fillCreateMenuItems(@Nullable IWorkbenchPartSite site, DBNNode node) {
    List<IContributionItem> createActions = new ArrayList<>();
    if (node instanceof DBNLocalFolder || node instanceof DBNProjectDatabases) {
        IContributionItem item = makeCreateContributionItem(site, DBPDataSourceContainer.class.getName(), ModelMessages.model_navigator_Connection, UIIcon.SQL_NEW_CONNECTION, false);
        createActions.add(item);
    }
    if (node instanceof DBNDatabaseNode) {
        addDatabaseNodeCreateItems(site, createActions, (DBNDatabaseNode) node);
    }
    if (node instanceof DBNLocalFolder || node instanceof DBNProjectDatabases || node instanceof DBNDataSource) {
        createActions.add(makeCommandContributionItem(site, NavigatorCommands.CMD_CREATE_LOCAL_FOLDER));
    } else if (node instanceof DBNResource) {
        final DBPWorkspace workspace = DBWorkbench.getPlatform().getWorkspace();
        IResource resource = ((DBNResource) node).getResource();
        if (resource instanceof IProject) {
            createActions.add(makeCommandContributionItem(site, NavigatorCommands.CMD_CREATE_PROJECT));
        }
        DBPResourceHandler handler = workspace.getResourceHandler(resource);
        if (handler instanceof DBPResourceCreator && (handler.getFeatures(resource) & DBPResourceCreator.FEATURE_CREATE_FILE) != 0) {
            createActions.add(makeCommandContributionItem(site, NavigatorCommands.CMD_CREATE_RESOURCE_FILE));
        }
        if (handler != null && (handler.getFeatures(resource) & DBPResourceHandler.FEATURE_CREATE_FOLDER) != 0) {
            createActions.add(makeCommandContributionItem(site, NavigatorCommands.CMD_CREATE_RESOURCE_FOLDER));
        }
        if (resource instanceof IContainer) {
            createActions.add(makeCommandContributionItem(site, NavigatorCommands.CMD_CREATE_FILE_LINK));
            createActions.add(makeCommandContributionItem(site, NavigatorCommands.CMD_CREATE_FOLDER_LINK));
        }
    }
    if (site != null) {
        if (!createActions.isEmpty() && !(createActions.get(createActions.size() - 1) instanceof Separator)) {
            createActions.add(new Separator());
        }
        createActions.add(ActionUtils.makeCommandContribution(site, IWorkbenchCommandConstants.FILE_NEW, "Other ...", null));
    }
    return createActions;
}
Also used : DBPWorkspace(org.jkiss.dbeaver.model.app.DBPWorkspace) IContributionItem(org.eclipse.jface.action.IContributionItem) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) DBPResourceCreator(org.jkiss.dbeaver.model.app.DBPResourceCreator) IContainer(org.eclipse.core.resources.IContainer) DBPResourceHandler(org.jkiss.dbeaver.model.app.DBPResourceHandler) IResource(org.eclipse.core.resources.IResource) Separator(org.eclipse.jface.action.Separator)

Example 13 with DBPResourceHandler

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

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;
    DBPWorkspace workspace = DBWorkbench.getPlatform().getWorkspace();
    DBPResourceHandler handler = workspace.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_FILE:
            return handler instanceof DBPResourceCreator && (handler.getFeatures(resource) & DBPResourceCreator.FEATURE_CREATE_FILE) != 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:
            {
                DBPProject activeProject = workspace.getActiveProject();
                return resource instanceof IProject && (activeProject == null || resource != activeProject.getEclipseProject());
            }
        case PROP_TYPE:
            final DBPResourceHandler resourceHandler = DBWorkbench.getPlatform().getWorkspace().getResourceHandler(resource);
            return resourceHandler != null && expectedValue.equals(resourceHandler.getTypeName(resource));
    }
    return false;
}
Also used : DBPWorkspace(org.jkiss.dbeaver.model.app.DBPWorkspace) DBPResourceCreator(org.jkiss.dbeaver.model.app.DBPResourceCreator) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) DBPResourceHandler(org.jkiss.dbeaver.model.app.DBPResourceHandler) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Example 14 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;
    DBPWorkspace workspace = DBWorkbench.getPlatform().getWorkspace();
    DBPResourceHandler handler = workspace.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_FILE:
            return handler instanceof DBPResourceCreator && (handler.getFeatures(resource) & DBPResourceCreator.FEATURE_CREATE_FILE) != 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:
            {
                DBPProject activeProject = workspace.getActiveProject();
                return resource instanceof IProject && (activeProject == null || resource != activeProject.getEclipseProject());
            }
        case PROP_TYPE:
            final DBPResourceHandler resourceHandler = DBWorkbench.getPlatform().getWorkspace().getResourceHandler(resource);
            return resourceHandler != null && expectedValue.equals(resourceHandler.getTypeName(resource));
    }
    return false;
}
Also used : DBPWorkspace(org.jkiss.dbeaver.model.app.DBPWorkspace) DBPResourceCreator(org.jkiss.dbeaver.model.app.DBPResourceCreator) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) DBPResourceHandler(org.jkiss.dbeaver.model.app.DBPResourceHandler) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Example 15 with DBPResourceHandler

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

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