use of org.jkiss.dbeaver.model.app.DBPResourceHandler in project dbeaver by serge-rider.
the class ProjectRegistry method getResourceDefaultRoot.
public IFolder getResourceDefaultRoot(IProject project, Class<? extends DBPResourceHandler> handlerType, boolean forceCreate) {
if (project == null) {
return null;
}
for (ResourceHandlerDescriptor rhd : handlerDescriptors) {
DBPResourceHandler handler = rhd.getHandler();
if (handler != null && handler.getClass() == handlerType) {
final IFolder realFolder = project.getFolder(rhd.getDefaultRoot());
if (!realFolder.exists() && forceCreate) {
try {
realFolder.create(true, true, new NullProgressMonitor());
} catch (CoreException e) {
log.error("Can't create '" + rhd.getName() + "' root folder '" + realFolder.getName() + "'", e);
return realFolder;
}
}
final IFolder linkFolder = project.getFolder(rhd.getFolderLinkName());
if (!linkFolder.exists()) {
/*
try {
linkFolder.createLink(realFolder.getRawLocation(), IResource.HIDDEN, null);
} catch (CoreException e) {
log.error("Can't create '" + rhd.getName() + "' root folder link", e);
return realFolder;
}
*/
}
return realFolder;
}
}
return project.getFolder(DefaultResourceHandlerImpl.DEFAULT_ROOT);
}
use of org.jkiss.dbeaver.model.app.DBPResourceHandler in project dbeaver by serge-rider.
the class ProjectRegistry method getResourceHandler.
@Override
public DBPResourceHandler getResourceHandler(IResource resource) {
if (resource == null || resource.isHidden() || resource.isPhantom()) {
// Skip not accessible hidden and phantom resources
return null;
}
if (resource.getParent() instanceof IProject && resource.getName().startsWith(DataSourceRegistry.CONFIG_FILE_PREFIX)) {
// TODO: remove in some older version
return null;
}
// Check resource is synced
if (resource instanceof IFile && !resource.isSynchronized(IResource.DEPTH_ZERO)) {
ContentUtils.syncFile(VoidProgressMonitor.INSTANCE, resource);
}
// Find handler
DBPResourceHandler handler = null;
for (ResourceHandlerDescriptor rhd : handlerDescriptors) {
if (rhd.canHandle(resource)) {
handler = rhd.getHandler();
break;
}
}
if (handler == null && resource instanceof IFolder) {
IPath relativePath = resource.getFullPath().makeRelativeTo(resource.getProject().getFullPath());
while (relativePath.segmentCount() > 0) {
ResourceHandlerDescriptor handlerDescriptor = rootMapping.get(relativePath.toString());
if (handlerDescriptor != null) {
handler = handlerDescriptor.getHandler();
}
relativePath = relativePath.removeLastSegments(1);
}
}
if (handler == null) {
handler = DefaultResourceHandlerImpl.INSTANCE;
}
return handler;
}
use of org.jkiss.dbeaver.model.app.DBPResourceHandler in project dbeaver by dbeaver.
the class DBNResource method refreshResourceState.
public void refreshResourceState(Object source) {
DBPResourceHandler newHandler = getModel().getPlatform().getProjectManager().getResourceHandler(resource);
if (newHandler != handler) {
handler = newHandler;
}
handler.updateNavigatorNode(this, resource);
getModel().fireNodeEvent(new DBNEvent(source, DBNEvent.Action.UPDATE, this));
}
use of org.jkiss.dbeaver.model.app.DBPResourceHandler in project dbeaver by dbeaver.
the class ProjectRegistry method getResourceDefaultRoot.
@Override
public IFolder getResourceDefaultRoot(IProject project, Class<? extends DBPResourceHandler> handlerType, boolean forceCreate) {
if (project == null) {
return null;
}
for (ResourceHandlerDescriptor rhd : handlerDescriptors) {
DBPResourceHandler handler = rhd.getHandler();
if (handler != null && handler.getClass() == handlerType) {
String defaultRoot = rhd.getDefaultRoot(project);
if (defaultRoot == null) {
// No root
return null;
}
final IFolder realFolder = project.getFolder(defaultRoot);
if (forceCreate && !realFolder.exists()) {
try {
realFolder.create(true, true, new NullProgressMonitor());
} catch (CoreException e) {
log.error("Can't create '" + rhd.getName() + "' root folder '" + realFolder.getName() + "'", e);
return realFolder;
}
}
return realFolder;
}
}
return project.getFolder(DefaultResourceHandlerImpl.DEFAULT_ROOT);
}
use of org.jkiss.dbeaver.model.app.DBPResourceHandler in project dbeaver by dbeaver.
the class ProjectRegistry method getResourceHandler.
@Override
public DBPResourceHandler getResourceHandler(IResource resource) {
if (resource == null || resource.isHidden() || resource.isPhantom()) {
// Skip not accessible hidden and phantom resources
return null;
}
if (resource.getParent() instanceof IProject && resource.getName().startsWith(DataSourceRegistry.CONFIG_FILE_PREFIX)) {
// TODO: remove in some older version
return null;
}
// Check resource is synced
if (resource instanceof IFile && !resource.isSynchronized(IResource.DEPTH_ZERO)) {
ContentUtils.syncFile(new VoidProgressMonitor(), resource);
}
// Find handler
DBPResourceHandler handler = null;
for (ResourceHandlerDescriptor rhd : handlerDescriptors) {
if (rhd.canHandle(resource)) {
handler = rhd.getHandler();
break;
}
}
if (handler == null && resource instanceof IFolder) {
final IProject project = resource.getProject();
IPath relativePath = resource.getFullPath().makeRelativeTo(project.getFullPath());
while (relativePath.segmentCount() > 0) {
String folderPath = relativePath.toString();
ResourceHandlerDescriptor handlerDescriptor = getHandlerDescriptorByRootPath(project, folderPath);
if (handlerDescriptor != null) {
handler = handlerDescriptor.getHandler();
}
relativePath = relativePath.removeLastSegments(1);
}
}
if (handler == null) {
handler = DefaultResourceHandlerImpl.INSTANCE;
}
return handler;
}
Aggregations