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