Search in sources :

Example 81 with DBPProject

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

the class GITAbstractHandler method getRepositories.

protected Repository[] getRepositories(ExecutionEvent event) {
    IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    if (activePart instanceof IEditorPart) {
        IFile editorFile = EditorUtils.getFileFromInput(((IEditorPart) activePart).getEditorInput());
        if (editorFile != null) {
            Repository repository = SelectionUtils.getRepository(new StructuredSelection(editorFile));
            if (repository != null) {
                return new Repository[] { repository };
            }
        }
    }
    {
        INavigatorModelView navigatorModelView = GeneralUtils.adapt(activePart, INavigatorModelView.class);
        if (navigatorModelView != null) {
            DBNNode rootNode = navigatorModelView.getRootNode();
            if (rootNode != null) {
                DBPProject ownerProject = rootNode.getOwnerProject();
                if (ownerProject != null) {
                    return getRepositories(new StructuredSelection(ownerProject.getEclipseProject()));
                }
            }
        }
    }
    IStructuredSelection selection = HandlerUtil.getCurrentStructuredSelection(event);
    return getRepositories(selection);
}
Also used : Repository(org.eclipse.jgit.lib.Repository) IFile(org.eclipse.core.resources.IFile) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) INavigatorModelView(org.jkiss.dbeaver.ui.navigator.INavigatorModelView) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) IEditorPart(org.eclipse.ui.IEditorPart) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 82 with DBPProject

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

the class RecentTasksMenuContributor method fillContributionItems.

@Override
protected void fillContributionItems(final List<IContributionItem> menuItems) {
    DBPProject project = NavigatorUtils.getSelectedProject();
    if (project == null) {
        return;
    }
    DBTTask[] tasks = project.getTaskManager().getAllTasks();
    Arrays.sort(tasks, (o1, o2) -> {
        DBTTaskRun lr1 = o1.getLastRun();
        DBTTaskRun lr2 = o1.getLastRun();
        if (lr1 == lr2)
            return o1.getCreateTime().compareTo(o2.getCreateTime());
        else if (lr1 == null)
            return -1;
        else if (lr2 == null)
            return 1;
        else
            return lr1.getStartTime().compareTo(lr2.getStartTime());
    });
    for (int i = 0; i < tasks.length && i <= MAX_ITEMS; i++) {
        DBTTask task = tasks[i];
        DBPImage taskIcon = task.getType().getIcon();
        if (taskIcon == null)
            taskIcon = DBIcon.TREE_TASK;
        menuItems.add(ActionUtils.makeActionContribution(new Action(task.getName(), DBeaverIcons.getImageDescriptor(taskIcon)) {

            @Override
            public void run() {
                TaskHandlerRun.runTask(task);
            }
        }, false));
    }
}
Also used : DBTTaskRun(org.jkiss.dbeaver.model.task.DBTTaskRun) Action(org.eclipse.jface.action.Action) DBTTask(org.jkiss.dbeaver.model.task.DBTTask) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) DBPImage(org.jkiss.dbeaver.model.DBPImage)

Example 83 with DBPProject

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

the class DatabaseTasksTree method refreshTasks.

private void refreshTasks() {
    allTasks.clear();
    for (DBPProject project : DBWorkbench.getPlatform().getWorkspace().getProjects()) {
        DBTTaskManager taskManager = project.getTaskManager();
        DBTTask[] tasks = taskManager.getAllTasks();
        if (tasks.length == 0) {
            continue;
        }
        Collections.addAll(allTasks, tasks);
    }
    allTasks.sort(Comparator.comparing(DBTTask::getName));
}
Also used : DBPProject(org.jkiss.dbeaver.model.app.DBPProject)

Example 84 with DBPProject

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

Example 85 with DBPProject

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

the class EditorUtils method getInputContextDefaults.

/**
 * String[2] = { defaultCatalogName, defaultSchema }
 */
public static String[] getInputContextDefaults(DBPDataSourceContainer dataSource, IEditorInput editorInput) {
    String defaultDatasource = null;
    String defaultCatalogName = null;
    String defaultSchema = null;
    if (editorInput instanceof INonPersistentEditorInput) {
        defaultDatasource = (String) ((INonPersistentEditorInput) editorInput).getProperty(PROP_CONTEXT_DEFAULT_DATASOURCE);
        defaultCatalogName = (String) ((INonPersistentEditorInput) editorInput).getProperty(PROP_CONTEXT_DEFAULT_CATALOG);
        defaultSchema = (String) ((INonPersistentEditorInput) editorInput).getProperty(PROP_CONTEXT_DEFAULT_SCHEMA);
    } else {
        IFile file = getFileFromInput(editorInput);
        if (file != null) {
            DBPProject projectMeta = DBWorkbench.getPlatform().getWorkspace().getProject(file.getProject());
            if (projectMeta != null) {
                defaultDatasource = (String) projectMeta.getResourceProperty(file, PROP_CONTEXT_DEFAULT_DATASOURCE);
                defaultCatalogName = (String) projectMeta.getResourceProperty(file, PROP_CONTEXT_DEFAULT_CATALOG);
                defaultSchema = (String) projectMeta.getResourceProperty(file, PROP_CONTEXT_DEFAULT_SCHEMA);
            }
        } else {
            File localFile = getLocalFileFromInput(editorInput);
            if (localFile != null) {
                final DBPExternalFileManager efManager = DBWorkbench.getPlatform().getExternalFileManager();
                defaultDatasource = (String) efManager.getFileProperty(localFile, PROP_CONTEXT_DEFAULT_DATASOURCE);
                defaultCatalogName = (String) efManager.getFileProperty(localFile, PROP_CONTEXT_DEFAULT_CATALOG);
                defaultSchema = (String) efManager.getFileProperty(localFile, PROP_CONTEXT_DEFAULT_SCHEMA);
            }
        }
    }
    if (!CommonUtils.isEmpty(defaultDatasource) && !defaultDatasource.equals(dataSource.getId())) {
        // Wrong datasource
        return new String[] { null, null };
    }
    return new String[] { defaultCatalogName, defaultSchema };
}
Also used : IFile(org.eclipse.core.resources.IFile) DBPExternalFileManager(org.jkiss.dbeaver.model.DBPExternalFileManager) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Aggregations

DBPProject (org.jkiss.dbeaver.model.app.DBPProject)90 IFile (org.eclipse.core.resources.IFile)20 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)18 DBException (org.jkiss.dbeaver.DBException)14 DBPDataSourceRegistry (org.jkiss.dbeaver.model.app.DBPDataSourceRegistry)14 IFolder (org.eclipse.core.resources.IFolder)8 DBPWorkspace (org.jkiss.dbeaver.model.app.DBPWorkspace)8 IResource (org.eclipse.core.resources.IResource)6 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)6 SelectionEvent (org.eclipse.swt.events.SelectionEvent)6 IEditorPart (org.eclipse.ui.IEditorPart)6 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)6 GridData (org.eclipse.swt.layout.GridData)5 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 ArrayList (java.util.ArrayList)4 CoreException (org.eclipse.core.runtime.CoreException)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 DBPImage (org.jkiss.dbeaver.model.DBPImage)4 Document (org.w3c.dom.Document)4