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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations