Search in sources :

Example 11 with DBPDataSourceContainer

use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by dbeaver.

the class PostgreSqlDebugCore method createConfiguration.

public static ILaunchConfigurationWorkingCopy createConfiguration(DBSObject launchable) throws CoreException {
    boolean isInstance = launchable instanceof PostgreProcedure;
    if (!isInstance) {
        throw DebugCore.abort(PostgreDebugCoreMessages.PostgreSqlDebugCore_e_procedure_required);
    }
    PostgreProcedure procedure = (PostgreProcedure) launchable;
    PostgreDataSource dataSource = procedure.getDataSource();
    DBPDataSourceContainer dataSourceContainer = dataSource.getContainer();
    PostgreDatabase database = procedure.getDatabase();
    PostgreSchema schema = procedure.getContainer();
    String databaseName = database.getName();
    String schemaName = schema.getName();
    String procedureName = procedure.getName();
    Object[] bindings = new Object[] { dataSourceContainer.getName(), databaseName, procedureName, schemaName };
    String name = NLS.bind(PostgreDebugCoreMessages.PostgreSqlDebugCore_launch_configuration_name, bindings);
    // Let's use metadata area for storage
    IContainer container = null;
    ILaunchConfigurationWorkingCopy workingCopy = DebugCore.createConfiguration(container, CONFIGURATION_TYPE, name);
    workingCopy.setAttribute(DebugCore.ATTR_DRIVER_ID, dataSourceContainer.getDriver().getId());
    workingCopy.setAttribute(DebugCore.ATTR_DATASOURCE_ID, dataSourceContainer.getId());
    workingCopy.setAttribute(DebugCore.ATTR_DATABASE_NAME, databaseName);
    workingCopy.setAttribute(DebugCore.ATTR_SCHEMA_NAME, schemaName);
    workingCopy.setAttribute(DebugCore.ATTR_PROCEDURE_OID, String.valueOf(procedure.getObjectId()));
    workingCopy.setAttribute(DebugCore.ATTR_PROCEDURE_NAME, procedureName);
    workingCopy.setAttribute(DebugCore.ATTR_ATTACH_PROCESS, DebugCore.ATTR_ATTACH_PROCESS_DEFAULT);
    workingCopy.setAttribute(DebugCore.ATTR_ATTACH_KIND, DebugCore.ATTR_ATTACH_KIND_DEFAULT);
    workingCopy.setAttribute(DebugCore.ATTR_SCRIPT_EXECUTE, DebugCore.ATTR_SCRIPT_EXECUTE_DEFAULT);
    workingCopy.setAttribute(DebugCore.ATTR_SCRIPT_TEXT, DebugCore.composeScriptText(procedure));
    final DBNModel navigatorModel = DBeaverCore.getInstance().getNavigatorModel();
    DBNDatabaseNode node = navigatorModel.getNodeByObject(procedure);
    workingCopy.setAttribute(DebugCore.ATTR_NODE_PATH, node.getNodeItemPath());
    return workingCopy;
}
Also used : PostgreDataSource(org.jkiss.dbeaver.ext.postgresql.model.PostgreDataSource) PostgreDatabase(org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) DBNModel(org.jkiss.dbeaver.model.navigator.DBNModel) PostgreProcedure(org.jkiss.dbeaver.ext.postgresql.model.PostgreProcedure) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IContainer(org.eclipse.core.resources.IContainer) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) PostgreSchema(org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)

Example 12 with DBPDataSourceContainer

use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by dbeaver.

the class PostgreDebugAdapterFactory method getAdapter.

@SuppressWarnings("unchecked")
@Override
public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
    if (adapterType == DBGController.class) {
        if (adaptableObject instanceof DBPDataSourceContainer) {
            DBPDataSourceContainer sourceContainer = (DBPDataSourceContainer) adaptableObject;
            DBPDriver driver = sourceContainer.getDriver();
            if (driver == null) {
                return null;
            }
            DBPDataSourceProvider dataSourceProvider = driver.getDataSourceProvider();
            if (dataSourceProvider instanceof PostgreDataSourceProvider) {
                PostgreDebugController postgreDebugController = new PostgreDebugController(sourceContainer);
                return (T) postgreDebugController;
            }
        }
    } else if (adapterType == DBGResolver.class) {
        if (adaptableObject instanceof DBPDataSourceContainer) {
            DBPDataSourceContainer sourceContainer = (DBPDataSourceContainer) adaptableObject;
            DBPDataSource dataSource = sourceContainer.getDataSource();
            if (dataSource instanceof PostgreDataSource) {
                PostgreDataSource postgeDataSource = (PostgreDataSource) dataSource;
                return (T) new PostgreResolver(postgeDataSource);
            }
        }
    }
    return null;
}
Also used : PostgreDataSource(org.jkiss.dbeaver.ext.postgresql.model.PostgreDataSource) DBGResolver(org.jkiss.dbeaver.debug.DBGResolver) DBPDriver(org.jkiss.dbeaver.model.connection.DBPDriver) PostgreDataSourceProvider(org.jkiss.dbeaver.ext.postgresql.PostgreDataSourceProvider) PostgreDebugController(org.jkiss.dbeaver.ext.postgresql.debug.internal.impl.PostgreDebugController) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) DBPDataSourceProvider(org.jkiss.dbeaver.model.DBPDataSourceProvider)

Example 13 with DBPDataSourceContainer

use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by dbeaver.

the class Debugger method main.

public static void main(String[] args) throws DBGException {
    // "jdbc:postgresql://localhost/postgres?user=postgres&password=postgres&ssl=false";
    String url = "jdbc:postgresql://192.168.229.133/postgres?user=postgres&password=postgres&ssl=false";
    DBPDataSourceContainer dataSource = null;
    Connection conn;
    DBGBaseController controller;
    try {
        conn = DriverManager.getConnection(url);
    } catch (SQLException e) {
        e.printStackTrace();
        return;
    }
    // TODO: fix connection
    controller = new PostgreDebugController(dataSource);
    Scanner sc = new Scanner(System.in);
    Scanner scArg;
    String command;
    while (true) {
        System.out.print(PROMPT);
        command = sc.next();
        switch(command.toUpperCase()) {
            case COMMAND_HELP:
                System.out.println("W Show sessions");
                System.out.println("N New session");
                System.out.println("D Show debug objects");
                System.out.println("S Stack");
                System.out.println("F Frame");
                System.out.println("V Variables");
                System.out.println("= Set Variables");
                System.out.println("L List breakpoint(s)");
                System.out.println("Q List debug session(s)");
                System.out.println("B Set breakpoint");
                System.out.println("R Remove breakpoint");
                System.out.println("C Continue execution");
                System.out.println("I Step into");
                System.out.println("O Step over");
                System.out.println("X Close session");
                System.out.println("T Abort session");
                System.out.println("E Exit debugger");
                System.out.println("? This help");
                break;
            case COMMAND_CLOSE:
                if (controller.getSessions().size() == 0) {
                    System.out.println("Debug sessions not found");
                    break;
                }
                DBGSession debugSessionC = chooseSession(sc, controller);
                if (debugSessionC == null) {
                    break;
                }
                controller.detach(debugSessionC.getSessionId(), new VoidProgressMonitor());
                System.out.println("Session closed");
                break;
            case COMMAND_STACK:
                if (controller.getSessions().size() == 0) {
                    System.out.println("Debug sessions not found");
                    break;
                }
                DBGSession debugSessionSL = chooseSession(sc, controller);
                if (debugSessionSL == null) {
                    break;
                }
                List<? extends DBGStackFrame> stack = debugSessionSL.getStack();
                if (stack.size() == 0) {
                    System.out.println("No stack defined");
                }
                for (DBGStackFrame s : stack) {
                    System.out.println(s.toString());
                }
                break;
            case COMMAND_FRAME:
                System.out.println("FRAME!!!");
                break;
            case COMMAND_VARIABLES:
                if (controller.getSessions().size() == 0) {
                    System.out.println("Debug sessions not found");
                    break;
                }
                DBGSession debugSessionVL = chooseSession(sc, controller);
                if (debugSessionVL == null) {
                    break;
                }
                List<? extends DBGVariable<?>> vars = debugSessionVL.getVariables();
                if (vars.size() == 0) {
                    System.out.println("No vars defined");
                }
                for (DBGVariable<?> v : vars) {
                    System.out.println(v.toString());
                }
                break;
            case COMMAND_VARIABLE_SET:
                String strVal = "";
                String argcV = sc.nextLine();
                if (argcV.length() > 0) {
                    scArg = new Scanner(argcV);
                    if (scArg.hasNext()) {
                        strVal = scArg.next();
                    }
                    scArg.close();
                }
                if (controller.getSessions().size() == 0) {
                    System.out.println("Debug sessions not found");
                    break;
                }
                DBGSession debugSessionVS = chooseSession(sc, controller);
                if (debugSessionVS == null) {
                    break;
                }
                DBGVariable<?> var = chooseVariable(sc, controller, debugSessionVS);
                if (var == null) {
                    break;
                }
                debugSessionVS.setVariableVal(var, strVal);
                System.out.println(String.format("Variable Set %s", strVal));
                break;
            case COMMAND_BREAKPOINT:
                String strObjId = ANY_ARG;
                String strLineNo = ANY_ARG;
                String argc = sc.nextLine();
                if (argc.length() > 0) {
                    scArg = new Scanner(argc);
                    if (scArg.hasNext()) {
                        strObjId = scArg.next();
                        if (scArg.hasNext()) {
                            argc = scArg.nextLine();
                            if (argc.length() > 0) {
                                strLineNo = argc;
                            }
                        }
                    }
                    scArg.close();
                }
                Integer objId = -1;
                try {
                    objId = Integer.valueOf(strObjId.trim());
                } catch (Exception e) {
                    System.out.println(String.format("Incorrect object ID '%s'", strObjId));
                    break;
                }
                int lineNo = -1;
                if (strLineNo.trim().length() > 0) {
                    try {
                        lineNo = Integer.valueOf(strLineNo.trim());
                    } catch (Exception e) {
                        System.out.println(String.format("Incorrect line number '%s'", strLineNo));
                        break;
                    }
                }
                DBGObjectDescriptor debugObject = null;
                for (DBGObjectDescriptor o : controller.getObjects("_", "_")) {
                    if (objId.equals(o.getID())) {
                        debugObject = o;
                    }
                }
                if (debugObject == null) {
                    System.out.println(String.format("Object ID '%s' no found", strObjId));
                    break;
                }
                if (controller.getSessions().size() == 0) {
                    System.out.println("Debug sessions not found");
                    break;
                }
                DBGSession debugSession = chooseSession(sc, controller);
                if (debugSession == null) {
                    break;
                }
                PostgreDebugBreakpointProperties breakpointProperties = lineNo > 0 ? new PostgreDebugBreakpointProperties(lineNo, true) : new PostgreDebugBreakpointProperties(true);
                Object oid = debugObject.getID();
                PostgreDebugBreakpointDescriptor descriptor = new PostgreDebugBreakpointDescriptor(oid, breakpointProperties);
                debugSession.addBreakpoint(descriptor);
                System.out.println("Breakpoint added");
                System.out.println(breakpointProperties.toString());
                break;
            case COMMAND_BREAKPOINT_LIST:
                if (controller.getSessions().size() == 0) {
                    System.out.println("Debug sessions not found");
                    break;
                }
                DBGSession debugSessionBL = chooseSession(sc, controller);
                if (debugSessionBL == null) {
                    break;
                }
                if (debugSessionBL.getBreakpoints().size() == 0) {
                    System.out.println("No breakpoints defined");
                }
                for (DBGBreakpointDescriptor bpl : debugSessionBL.getBreakpoints()) {
                    System.out.println(bpl.toString());
                }
                break;
            case COMMAND_BREAKPOINT_REMOVE:
                if (controller.getSessions().size() == 0) {
                    System.out.println("Debug sessions not found");
                    break;
                }
                DBGSession debugSessionBR = chooseSession(sc, controller);
                if (debugSessionBR == null) {
                    break;
                }
                if (debugSessionBR.getBreakpoints().size() == 0) {
                    System.out.println("No breakpoints defined");
                }
                DBGBreakpointDescriptor bpr = chooseBreakpoint(sc, controller, debugSessionBR);
                debugSessionBR.removeBreakpoint(bpr);
                System.out.println("Breakpoint removed ...");
                break;
            case COMMAND_CONTINUE:
                if (controller.getSessions().size() == 0) {
                    System.out.println("Debug sessions not found");
                    break;
                }
                DBGSession debugSessionSC = chooseSession(sc, controller);
                if (debugSessionSC == null) {
                    break;
                }
                debugSessionSC.execContinue();
                System.out.println("Continue ...");
                break;
            case COMMAND_INTO:
                if (controller.getSessions().size() == 0) {
                    System.out.println("Debug sessions not found");
                    break;
                }
                DBGSession debugSessionSI = chooseSession(sc, controller);
                if (debugSessionSI == null) {
                    break;
                }
                debugSessionSI.execStepInto();
                System.out.println("Step Into ...");
                break;
            case COMMAND_OVER:
                if (controller.getSessions().size() == 0) {
                    System.out.println("Debug sessions not found");
                    break;
                }
                DBGSession debugSessionSO = chooseSession(sc, controller);
                if (debugSessionSO == null) {
                    break;
                }
                debugSessionSO.execStepOver();
                System.out.println("Step over ...");
                break;
            case COMMAND_SESSIONS:
                for (DBGSessionInfo s : controller.getSessionDescriptors()) {
                    System.out.println(s);
                }
                break;
            case COMMAND_DEBUG_LIST:
                if (controller.getSessions().size() == 0) {
                    System.out.println("no debug sessions");
                    break;
                }
                for (DBGSession s : controller.getSessions()) {
                    System.out.println(s);
                }
                break;
            case COMMAND_NEW:
                try {
                    Connection debugConn = DriverManager.getConnection(url);
                    // TODO: fix connection
                    DBCExecutionContext executionContext = null;
                    DBGSession s = controller.createSession(null, executionContext);
                    System.out.println("created");
                    System.out.println(s);
                } catch (SQLException e) {
                    e.printStackTrace();
                    break;
                }
                break;
            case COMMAND_OBJ:
                String proc = ANY_ARG;
                String owner = ANY_ARG;
                String arg = sc.nextLine();
                if (arg.length() > 0) {
                    scArg = new Scanner(arg);
                    if (scArg.hasNext()) {
                        proc = scArg.next();
                        if (scArg.hasNext()) {
                            arg = scArg.nextLine();
                            if (arg.length() > 0) {
                                owner = arg;
                            }
                        }
                    }
                    scArg.close();
                }
                for (DBGObjectDescriptor o : controller.getObjects(owner.equals(ANY_ARG) ? "_" : owner, proc.equals(ANY_ARG) ? "_" : proc)) {
                    System.out.println(o);
                }
                break;
            case COMMAND_ATTACH:
                if (controller.getSessions().size() == 0) {
                    System.out.println("Debug sessions not found");
                    break;
                }
                DBGSession debugSessionA = chooseSession(sc, controller);
                if (debugSessionA == null) {
                    break;
                }
                System.out.println("Waiting for target session ...");
                break;
            case COMMAND_TERMINATE:
                System.out.println("EXIT.....");
                return;
            default:
                System.out.println(String.format("Unnown command '%s' for command list type ?", command));
                break;
        }
    }
}
Also used : Scanner(java.util.Scanner) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) SQLException(java.sql.SQLException) PostgreDebugBreakpointDescriptor(org.jkiss.dbeaver.ext.postgresql.debug.internal.impl.PostgreDebugBreakpointDescriptor) Connection(java.sql.Connection) PostgreDebugController(org.jkiss.dbeaver.ext.postgresql.debug.internal.impl.PostgreDebugController) DBGBreakpointDescriptor(org.jkiss.dbeaver.debug.DBGBreakpointDescriptor) DBGSession(org.jkiss.dbeaver.debug.DBGSession) DBGException(org.jkiss.dbeaver.debug.DBGException) SQLException(java.sql.SQLException) DBGStackFrame(org.jkiss.dbeaver.debug.DBGStackFrame) PostgreDebugBreakpointProperties(org.jkiss.dbeaver.ext.postgresql.debug.internal.impl.PostgreDebugBreakpointProperties) DBGBaseController(org.jkiss.dbeaver.debug.DBGBaseController) DBGSessionInfo(org.jkiss.dbeaver.debug.DBGSessionInfo) DBGObjectDescriptor(org.jkiss.dbeaver.debug.DBGObjectDescriptor) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 14 with DBPDataSourceContainer

use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by dbeaver.

the class NavigatorViewBase method createNavigatorTree.

private DatabaseNavigatorTree createNavigatorTree(Composite parent, DBNNode rootNode) {
    // Create tree
    final DatabaseNavigatorTree navigatorTree = new DatabaseNavigatorTree(parent, rootNode, getTreeStyle(), false, getNavigatorFilter());
    navigatorTree.getViewer().addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            onSelectionChange((IStructuredSelection) event.getSelection());
        }
    });
    navigatorTree.getViewer().addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            TreeViewer viewer = tree.getViewer();
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            for (Object node : selection.toArray()) {
                // Object node = selection.getFirstElement();
                if ((node instanceof DBNResource && ((DBNResource) node).getResource() instanceof IFolder)) {
                    toggleNode(viewer, node);
                } else if (node instanceof DBNDataSource) {
                    DoubleClickBehavior dsBehaviorDefault = DoubleClickBehavior.valueOf(DBeaverCore.getGlobalPreferenceStore().getString(DBeaverPreferences.NAVIGATOR_CONNECTION_DOUBLE_CLICK));
                    if (dsBehaviorDefault == DoubleClickBehavior.EXPAND) {
                        toggleNode(viewer, node);
                    } else {
                        DBPDataSourceContainer dataSource = ((DBNDataSource) node).getObject();
                        NavigatorViewBase.DoubleClickBehavior doubleClickBehavior = NavigatorViewBase.DoubleClickBehavior.valueOf(DBeaverCore.getGlobalPreferenceStore().getString(DBeaverPreferences.NAVIGATOR_CONNECTION_DOUBLE_CLICK));
                        switch(doubleClickBehavior) {
                            case EDIT:
                                NavigatorHandlerObjectOpen.openEntityEditor((DBNDataSource) node, null, DBeaverUI.getActiveWorkbenchWindow());
                                break;
                            case CONNECT:
                                if (dataSource.isConnected()) {
                                    DataSourceHandler.disconnectDataSource(dataSource, null);
                                } else {
                                    DataSourceHandler.connectToDataSource(null, dataSource, null);
                                }
                                break;
                            case SQL_EDITOR:
                                try {
                                    OpenHandler.openRecentScript(getSite().getWorkbenchWindow(), dataSource, null);
                                } catch (CoreException e) {
                                    DBUserInterface.getInstance().showError("Open SQL editor", "Can't open SQL editor", e);
                                }
                                break;
                        }
                    }
                } else {
                    DoubleClickBehavior dcBehaviorDefault = DoubleClickBehavior.valueOf(DBeaverCore.getGlobalPreferenceStore().getString(DBeaverPreferences.NAVIGATOR_OBJECT_DOUBLE_CLICK));
                    boolean hasChildren = node instanceof DBNNode && ((DBNNode) node).hasChildren(true);
                    if (hasChildren && dcBehaviorDefault == DoubleClickBehavior.EXPAND) {
                        toggleNode(viewer, node);
                    } else {
                        NavigatorUtils.executeNodeAction(DBXTreeNodeHandler.Action.open, node, getSite());
                    }
                }
            }
        }
    });
    // Hook context menu
    NavigatorUtils.addContextMenu(this.getSite(), navigatorTree.getViewer());
    // Add drag and drop support
    NavigatorUtils.addDragAndDropSupport(navigatorTree.getViewer());
    return navigatorTree;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) IFolder(org.eclipse.core.resources.IFolder)

Example 15 with DBPDataSourceContainer

use of org.jkiss.dbeaver.model.DBPDataSourceContainer in project dbeaver by dbeaver.

the class ProjectExplorerView method createColumns.

private void createColumns(final TreeViewer viewer) {
    final Color shadowColor = viewer.getControl().getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);
    final ILabelProvider mainLabelProvider = (ILabelProvider) viewer.getLabelProvider();
    columnController = new ViewerColumnController("projectExplorer", viewer);
    columnController.addColumn("Name", "Resource name", SWT.LEFT, true, true, new TreeColumnViewerLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return mainLabelProvider.getText(element);
        }

        @Override
        public Image getImage(Object element) {
            return mainLabelProvider.getImage(element);
        }
    }));
    columnController.addColumn("DataSource", "Datasource(s) associated with resource", SWT.LEFT, true, false, new TreeColumnViewerLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            DBNNode node = (DBNNode) element;
            if (node instanceof DBNDatabaseNode) {
                return ((DBNDatabaseNode) node).getDataSourceContainer().getName();
            } else if (node instanceof DBNResource) {
                Collection<DBPDataSourceContainer> containers = ((DBNResource) node).getAssociatedDataSources();
                if (!CommonUtils.isEmpty(containers)) {
                    StringBuilder text = new StringBuilder();
                    for (DBPDataSourceContainer container : containers) {
                        if (text.length() > 0) {
                            text.append(", ");
                        }
                        text.append(container.getName());
                    }
                    return text.toString();
                }
            }
            return "";
        }

        @Override
        public Image getImage(Object element) {
            /*
                DBNNode node = (DBNNode) element;
                if (node instanceof DBNDatabaseNode) {
                    return DBeaverIcons.getImage(((DBNDatabaseNode) node).getDataSourceContainer().getDriver().getIcon());
                } else if (node instanceof DBNResource) {
                    Collection<DBPDataSourceContainer> containers = ((DBNResource) node).getAssociatedDataSources();
                    if (containers != null && containers.size() == 1) {
                        return DBeaverIcons.getImage((containers.iterator().next().getDriver().getIcon()));
                    }
                }
*/
            return null;
        }
    }));
    columnController.addColumn("Preview", "Script content preview", SWT.LEFT, false, false, new LazyLabelProvider(shadowColor) {

        @Override
        public String getLazyText(Object element) {
            if (element instanceof DBNNode) {
                return ((DBNNode) element).getNodeDescription();
            } else {
                return null;
            }
        }
    });
    columnController.addColumn("Size", "File size", SWT.LEFT, false, false, new TreeColumnViewerLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            DBNNode node = (DBNNode) element;
            if (node instanceof DBNResource) {
                IResource resource = ((DBNResource) node).getResource();
                if (resource instanceof IFile) {
                    return String.valueOf(resource.getLocation().toFile().length());
                }
            }
            return "";
        }
    }));
    columnController.addColumn("Modified", "Time the file was last modified", SWT.LEFT, false, false, new TreeColumnViewerLabelProvider(new LabelProvider() {

        private SimpleDateFormat sdf = new SimpleDateFormat(DBConstants.DEFAULT_TIMESTAMP_FORMAT);

        @Override
        public String getText(Object element) {
            DBNNode node = (DBNNode) element;
            if (node instanceof DBNResource) {
                IResource resource = ((DBNResource) node).getResource();
                if (resource instanceof IFile || resource instanceof IFolder) {
                    return sdf.format(new Date(resource.getLocation().toFile().lastModified()));
                }
            }
            return "";
        }
    }));
    columnController.addColumn("Type", "Resource type", SWT.LEFT, false, false, new TreeColumnViewerLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            DBNNode node = (DBNNode) element;
            if (node instanceof DBNResource) {
                IResource resource = ((DBNResource) node).getResource();
                ProgramInfo program = ProgramInfo.getProgram(resource);
                if (program != null) {
                    return program.getProgram().getName();
                }
            }
            return "";
        }
    }));
    columnController.createColumns();
}
Also used : ViewerColumnController(org.jkiss.dbeaver.ui.controls.ViewerColumnController) LazyLabelProvider(org.jkiss.dbeaver.ui.LazyLabelProvider) IFile(org.eclipse.core.resources.IFile) Color(org.eclipse.swt.graphics.Color) Date(java.util.Date) ProgramInfo(org.jkiss.dbeaver.ui.ProgramInfo) Collection(java.util.Collection) LazyLabelProvider(org.jkiss.dbeaver.ui.LazyLabelProvider) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) SimpleDateFormat(java.text.SimpleDateFormat) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)148 IFile (org.eclipse.core.resources.IFile)22 ArrayList (java.util.ArrayList)21 DBException (org.jkiss.dbeaver.DBException)19 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)19 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)19 DBPDataSource (org.jkiss.dbeaver.model.DBPDataSource)14 DBNDataSource (org.jkiss.dbeaver.model.navigator.DBNDataSource)14 InvocationTargetException (java.lang.reflect.InvocationTargetException)13 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)13 DBPConnectionConfiguration (org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)12 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)12 IFolder (org.eclipse.core.resources.IFolder)11 IEditorPart (org.eclipse.ui.IEditorPart)11 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)10 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)10 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)9 GridData (org.eclipse.swt.layout.GridData)9 IDataSourceContainerProvider (org.jkiss.dbeaver.model.IDataSourceContainerProvider)9