Search in sources :

Example 71 with DBPProject

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

the class PrefPageProjectResourceSettings method performOk.

@Override
public boolean performOk() {
    java.util.List<IResource> refreshedResources = new ArrayList<>();
    // Save roots
    DBPProject projectMeta = getProjectMeta();
    if (projectMeta != null) {
        for (TableItem item : resourceTable.getItems()) {
            DBPResourceHandlerDescriptor descriptor = (DBPResourceHandlerDescriptor) item.getData();
            String rootPath = item.getText(1);
            if (!CommonUtils.equalObjects(descriptor.getDefaultRoot(projectMeta), rootPath)) {
                IResource oldResource = project.findMember(descriptor.getDefaultRoot(projectMeta));
                if (oldResource != null) {
                    refreshedResources.add(oldResource);
                }
                IResource newResource = project.findMember(rootPath);
                if (newResource != null) {
                    refreshedResources.add(newResource);
                }
                descriptor.setDefaultRoot(projectMeta, rootPath);
            }
        }
        if (!refreshedResources.isEmpty()) {
            for (IResource resource : refreshedResources) {
                DBNUtils.refreshNavigatorResource(resource, this);
            }
        }
    }
    return super.performOk();
}
Also used : DBPResourceHandlerDescriptor(org.jkiss.dbeaver.model.app.DBPResourceHandlerDescriptor) ArrayList(java.util.ArrayList) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) IResource(org.eclipse.core.resources.IResource)

Example 72 with DBPProject

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

the class QueryLogViewer method openSelectionInEditor.

private void openSelectionInEditor() {
    DBPDataSourceContainer dsContainer = null;
    StringBuilder sql = new StringBuilder();
    TableItem[] items = logTable.getSelection();
    for (TableItem item : items) {
        QMMetaEvent event = (QMMetaEvent) item.getData();
        QMMObject object = event.getObject();
        if (object instanceof QMMStatementExecuteInfo) {
            QMMStatementExecuteInfo stmtExec = (QMMStatementExecuteInfo) object;
            if (dsContainer == null) {
                QMMSessionInfo session = stmtExec.getStatement().getSession();
                DBPProject project = session.getProject();
                String containerId = session.getContainerId();
                if (project != null) {
                    dsContainer = project.getDataSourceRegistry().getDataSource(containerId);
                } else {
                    dsContainer = DBUtils.findDataSource(containerId);
                }
            }
            String queryString = stmtExec.getQueryString();
            if (!CommonUtils.isEmptyTrimmed(queryString)) {
                if (sql.length() > 0) {
                    // $NON-NLS-1$
                    sql.append("\n");
                }
                queryString = queryString.trim();
                sql.append(queryString);
                if (!queryString.endsWith(SQLConstants.DEFAULT_STATEMENT_DELIMITER)) {
                    // $NON-NLS-1$
                    sql.append(SQLConstants.DEFAULT_STATEMENT_DELIMITER).append("\n");
                }
            }
        }
    }
    if (sql.length() > 0) {
        SQLEditorHandlerOpenEditor.openSQLConsole(UIUtils.getActiveWorkbenchWindow(), new SQLNavigatorContext(dsContainer), // $NON-NLS-1$
        "QueryManager", sql.toString());
    }
}
Also used : DBPProject(org.jkiss.dbeaver.model.app.DBPProject) SQLNavigatorContext(org.jkiss.dbeaver.ui.editors.sql.handlers.SQLNavigatorContext) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 73 with DBPProject

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

the class DatabaseBrowserView method getNodeFromSecondaryId.

public static DBNNode getNodeFromSecondaryId(String id) throws DBException {
    int divPos = id.indexOf('|');
    if (divPos == -1) {
        throw new DBException("Bad secondary ID: " + id);
    }
    String projectName = id.substring(0, divPos);
    String nodePath = id.substring(divPos + 1).replace("~", ":");
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
    if (project == null) {
        throw new DBException("Project '" + projectName + "' not found");
    }
    final DBNModel navigatorModel = DBWorkbench.getPlatform().getNavigatorModel();
    DBNNode node = null;
    DBPProject projectMeta = DBWorkbench.getPlatform().getWorkspace().getProject(project);
    if (projectMeta != null) {
        navigatorModel.ensureProjectLoaded(projectMeta);
        node = navigatorModel.getNodeByPath(new VoidProgressMonitor(), projectMeta, nodePath);
    }
    if (node == null) {
        log.error("Node " + nodePath + " not found for browse view");
        node = new DBNEmptyNode();
    }
    return node;
}
Also used : DBException(org.jkiss.dbeaver.DBException) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) DBNEmptyNode(org.jkiss.dbeaver.model.navigator.DBNEmptyNode) IProject(org.eclipse.core.resources.IProject) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel)

Example 74 with DBPProject

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

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

the class NavigatorActiveProjectContributor method createMenu.

private void createMenu(final Menu menu) {
    final DBPProject activeProject = DBWorkbench.getPlatform().getWorkspace().getActiveProject();
    for (final DBPProject project : DBWorkbench.getPlatform().getWorkspace().getProjects()) {
        MenuItem txnItem = new MenuItem(menu, SWT.RADIO);
        txnItem.setText(project.getName());
        txnItem.setSelection(project == activeProject);
        txnItem.setData(project);
        txnItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                NavigatorHandlerProjectSetActive.setActiveProject(project);
            }
        });
    }
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBPProject(org.jkiss.dbeaver.model.app.DBPProject) MenuItem(org.eclipse.swt.widgets.MenuItem)

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