Search in sources :

Example 1 with DBPResourceCreator

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

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 2 with DBPResourceCreator

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

the class NavigatorHandlerCreateFile method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection structSelection = (IStructuredSelection) selection;
        Object element = structSelection.getFirstElement();
        if (!(element instanceof DBNResource)) {
            return null;
        }
        DBPWorkspace workspace = DBWorkbench.getPlatform().getWorkspace();
        IResource resource = ((DBNResource) element).getResource();
        DBPResourceCreator handler = (DBPResourceCreator) workspace.getResourceHandler(resource);
        if (resource instanceof IFolder) {
            try {
                handler.createResource((IFolder) resource);
            } catch (Exception e) {
                DBWorkbench.getPlatformUI().showError("Can't create file", "Error during " + handler.getTypeName(resource) + " creation", e);
            }
        }
    }
    return null;
}
Also used : DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) DBPWorkspace(org.jkiss.dbeaver.model.app.DBPWorkspace) DBPResourceCreator(org.jkiss.dbeaver.model.app.DBPResourceCreator) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IResource(org.eclipse.core.resources.IResource) ExecutionException(org.eclipse.core.commands.ExecutionException) IFolder(org.eclipse.core.resources.IFolder)

Example 3 with DBPResourceCreator

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

the class NavigatorHandlerCreateFile method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection structSelection = (IStructuredSelection) selection;
        Object element = structSelection.getFirstElement();
        if (!(element instanceof DBNResource)) {
            return null;
        }
        DBPWorkspace workspace = DBWorkbench.getPlatform().getWorkspace();
        IResource resource = ((DBNResource) element).getResource();
        DBPResourceCreator handler = (DBPResourceCreator) workspace.getResourceHandler(resource);
        if (resource instanceof IFolder) {
            try {
                handler.createResource((IFolder) resource);
            } catch (Exception e) {
                DBWorkbench.getPlatformUI().showError("Can't create file", "Error during " + handler.getTypeName(resource) + " creation", e);
            }
        }
    }
    return null;
}
Also used : DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) DBPWorkspace(org.jkiss.dbeaver.model.app.DBPWorkspace) DBPResourceCreator(org.jkiss.dbeaver.model.app.DBPResourceCreator) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IResource(org.eclipse.core.resources.IResource) ExecutionException(org.eclipse.core.commands.ExecutionException) IFolder(org.eclipse.core.resources.IFolder)

Example 4 with DBPResourceCreator

use of org.jkiss.dbeaver.model.app.DBPResourceCreator 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 5 with DBPResourceCreator

use of org.jkiss.dbeaver.model.app.DBPResourceCreator 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)

Aggregations

IResource (org.eclipse.core.resources.IResource)6 DBPResourceCreator (org.jkiss.dbeaver.model.app.DBPResourceCreator)6 DBPWorkspace (org.jkiss.dbeaver.model.app.DBPWorkspace)6 IProject (org.eclipse.core.resources.IProject)4 DBPResourceHandler (org.jkiss.dbeaver.model.app.DBPResourceHandler)4 ArrayList (java.util.ArrayList)2 ExecutionException (org.eclipse.core.commands.ExecutionException)2 IContainer (org.eclipse.core.resources.IContainer)2 IFolder (org.eclipse.core.resources.IFolder)2 IContributionItem (org.eclipse.jface.action.IContributionItem)2 Separator (org.eclipse.jface.action.Separator)2 ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 DBPProject (org.jkiss.dbeaver.model.app.DBPProject)2 DBNResource (org.jkiss.dbeaver.model.navigator.DBNResource)2