Search in sources :

Example 1 with DBPResourceHandler

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);
}
Also used : DBPResourceHandler(org.jkiss.dbeaver.model.app.DBPResourceHandler)

Example 2 with DBPResourceHandler

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;
}
Also used : DBPResourceHandler(org.jkiss.dbeaver.model.app.DBPResourceHandler)

Example 3 with DBPResourceHandler

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));
}
Also used : DBPResourceHandler(org.jkiss.dbeaver.model.app.DBPResourceHandler)

Example 4 with DBPResourceHandler

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);
}
Also used : DBPResourceHandler(org.jkiss.dbeaver.model.app.DBPResourceHandler)

Example 5 with DBPResourceHandler

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;
}
Also used : VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) DBPResourceHandler(org.jkiss.dbeaver.model.app.DBPResourceHandler)

Aggregations

DBPResourceHandler (org.jkiss.dbeaver.model.app.DBPResourceHandler)12 IResource (org.eclipse.core.resources.IResource)5 IProject (org.eclipse.core.resources.IProject)4 ArrayList (java.util.ArrayList)2 DBPProject (org.jkiss.dbeaver.model.app.DBPProject)2 DBPResourceCreator (org.jkiss.dbeaver.model.app.DBPResourceCreator)2 DBPWorkspace (org.jkiss.dbeaver.model.app.DBPWorkspace)2 ProjectRegistry (org.jkiss.dbeaver.registry.ProjectRegistry)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 java.util (java.util)1 List (java.util.List)1 IContainer (org.eclipse.core.resources.IContainer)1 IFile (org.eclipse.core.resources.IFile)1 IContributionItem (org.eclipse.jface.action.IContributionItem)1 Separator (org.eclipse.jface.action.Separator)1 IDialogConstants (org.eclipse.jface.dialogs.IDialogConstants)1 org.eclipse.jface.viewers (org.eclipse.jface.viewers)1 SWT (org.eclipse.swt.SWT)1 SashForm (org.eclipse.swt.custom.SashForm)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1