Search in sources :

Example 26 with DBNNode

use of org.jkiss.dbeaver.model.navigator.DBNNode in project dbeaver by serge-rider.

the class NavigatorHandlerFilterClear method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    DBNNode node = NavigatorUtils.getSelectedNode(selection);
    if (node instanceof DBNDatabaseItem) {
        node = node.getParentNode();
    }
    if (node instanceof DBNDatabaseFolder) {
        final DBNDatabaseFolder folder = (DBNDatabaseFolder) node;
        DBXTreeItem itemsMeta = folder.getItemsMeta();
        if (itemsMeta != null) {
            folder.setNodeFilter(itemsMeta, new DBSObjectFilter());
            NavigatorHandlerRefresh.refreshNavigator(Collections.singleton(folder));
        }
    }
    return null;
}
Also used : DBNDatabaseItem(org.jkiss.dbeaver.model.navigator.DBNDatabaseItem) DBSObjectFilter(org.jkiss.dbeaver.model.struct.DBSObjectFilter) DBXTreeItem(org.jkiss.dbeaver.model.navigator.meta.DBXTreeItem) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ISelection(org.eclipse.jface.viewers.ISelection) DBNDatabaseFolder(org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)

Example 27 with DBNNode

use of org.jkiss.dbeaver.model.navigator.DBNNode in project dbeaver by serge-rider.

the class NavigatorHandlerFilterToggle method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final ISelection selection = HandlerUtil.getCurrentSelection(event);
    DBNNode node = NavigatorUtils.getSelectedNode(selection);
    if (node instanceof DBNDatabaseItem) {
        node = node.getParentNode();
    }
    if (node instanceof DBNDatabaseFolder) {
        final DBNDatabaseFolder folder = (DBNDatabaseFolder) node;
        DBXTreeItem itemsMeta = folder.getItemsMeta();
        if (itemsMeta != null) {
            final DBSObjectFilter nodeFilter = folder.getNodeFilter(itemsMeta, true);
            if (nodeFilter != null) {
                nodeFilter.setEnabled(!nodeFilter.isEnabled());
                NavigatorHandlerRefresh.refreshNavigator(Collections.singleton(folder));
            }
        }
    }
    return null;
}
Also used : DBNDatabaseItem(org.jkiss.dbeaver.model.navigator.DBNDatabaseItem) DBSObjectFilter(org.jkiss.dbeaver.model.struct.DBSObjectFilter) DBXTreeItem(org.jkiss.dbeaver.model.navigator.meta.DBXTreeItem) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ISelection(org.eclipse.jface.viewers.ISelection) DBNDatabaseFolder(org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)

Example 28 with DBNNode

use of org.jkiss.dbeaver.model.navigator.DBNNode in project dbeaver by serge-rider.

the class EntityEditor method createPages.

@Override
protected void createPages() {
    final IDatabaseEditorInput editorInput = getEditorInput();
    if (editorInput instanceof DatabaseLazyEditorInput) {
        try {
            addPage(new ProgressEditorPart(this), editorInput);
            setPageText(0, "Initializing ...");
            setActivePage(0);
        } catch (PartInitException e) {
            log.error(e);
        }
        return;
    } else if (editorInput instanceof ErrorEditorInput) {
        ErrorEditorInput errorInput = (ErrorEditorInput) editorInput;
        try {
            addPage(new ErrorEditorPartEx(errorInput.getError()), errorInput);
            setPageImage(0, UIUtils.getShardImage(ISharedImages.IMG_OBJS_ERROR_TSK));
            setPageText(0, "Error");
            setActivePage(0);
        } catch (PartInitException e) {
            log.error(e);
        }
        return;
    }
    // Command listener
    commandListener = new DBECommandAdapter() {

        @Override
        public void onCommandChange(DBECommand command) {
            DBeaverUI.syncExec(new Runnable() {

                @Override
                public void run() {
                    firePropertyChange(IEditorPart.PROP_DIRTY);
                }
            });
        }
    };
    DBECommandContext commandContext = getCommandContext();
    if (commandContext != null) {
        commandContext.addCommandListener(commandListener);
    }
    // Property listener
    addPropertyListener(new IPropertyListener() {

        @Override
        public void propertyChanged(Object source, int propId) {
            if (propId == IEditorPart.PROP_DIRTY) {
                EntityEditorPropertyTester.firePropertyChange(EntityEditorPropertyTester.PROP_DIRTY);
                EntityEditorPropertyTester.firePropertyChange(EntityEditorPropertyTester.PROP_CAN_UNDO);
                EntityEditorPropertyTester.firePropertyChange(EntityEditorPropertyTester.PROP_CAN_REDO);
            }
        }
    });
    super.createPages();
    DBSObject databaseObject = editorInput.getDatabaseObject();
    EditorDefaults editorDefaults = null;
    if (databaseObject == null) {
        // Weird
        log.debug("Null database object in EntityEditor");
    } else {
        synchronized (defaultPageMap) {
            editorDefaults = defaultPageMap.get(databaseObject.getClass().getName());
        }
        EntityEditorsRegistry editorsRegistry = EntityEditorsRegistry.getInstance();
        // Add object editor page
        EntityEditorDescriptor defaultEditor = editorsRegistry.getMainEntityEditor(databaseObject);
        hasPropertiesEditor = false;
        if (defaultEditor != null) {
            hasPropertiesEditor = addEditorTab(defaultEditor);
        }
        if (hasPropertiesEditor) {
            DBNNode node = editorInput.getNavigatorNode();
            int propEditorIndex = getPageCount() - 1;
            setPageText(propEditorIndex, CoreMessages.editors_entity_properties_text);
            setPageToolTip(propEditorIndex, node.getNodeType() + CoreMessages.editors_entity_properties_tooltip_suffix);
            setPageImage(propEditorIndex, DBeaverIcons.getImage(node.getNodeIconDefault()));
        }
    }
    // Add contributed pages
    addContributions(EntityEditorDescriptor.POSITION_PROPS);
    addContributions(EntityEditorDescriptor.POSITION_START);
    addContributions(EntityEditorDescriptor.POSITION_MIDDLE);
    // Add contributed pages
    addContributions(EntityEditorDescriptor.POSITION_END);
    String defPageId = editorInput.getDefaultPageId();
    String defFolderId = editorInput.getDefaultFolderId();
    if (defPageId == null && editorDefaults != null) {
        defPageId = editorDefaults.pageId;
    }
    if (defPageId != null) {
        IEditorPart defEditorPage = editorMap.get(defPageId);
        if (defEditorPage != null) {
            setActiveEditor(defEditorPage);
        }
    } else {
        setActiveEditor(getEditor(0));
    }
    this.activeEditor = getActiveEditor();
    if (activeEditor instanceof ITabbedFolderContainer) {
        if (defFolderId == null && editorDefaults != null) {
            defFolderId = editorDefaults.folderId;
        }
        if (defFolderId != null) {
            ((ITabbedFolderContainer) activeEditor).switchFolder(defFolderId);
        }
    }
    UIUtils.setHelp(getContainer(), IHelpContextIds.CTX_ENTITY_EDITOR);
}
Also used : DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) EntityEditorDescriptor(org.jkiss.dbeaver.registry.editor.EntityEditorDescriptor) Point(org.eclipse.swt.graphics.Point) EntityEditorsRegistry(org.jkiss.dbeaver.registry.editor.EntityEditorsRegistry) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBECommand(org.jkiss.dbeaver.model.edit.DBECommand) ITabbedFolderContainer(org.jkiss.dbeaver.ui.controls.folders.ITabbedFolderContainer) DBECommandContext(org.jkiss.dbeaver.model.edit.DBECommandContext) DBECommandAdapter(org.jkiss.dbeaver.model.impl.edit.DBECommandAdapter) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject)

Example 29 with DBNNode

use of org.jkiss.dbeaver.model.navigator.DBNNode in project dbeaver by serge-rider.

the class EntityEditor method createPathRow.

private void createPathRow(ToolBar infoGroup, final DBNDatabaseNode databaseNode) {
    final DBNDatabaseNode curNode = getEditorInput().getNavigatorNode();
    final ToolItem item = new ToolItem(infoGroup, databaseNode instanceof DBNDatabaseFolder ? SWT.DROP_DOWN : SWT.PUSH);
    item.setText(databaseNode.getNodeName());
    item.setImage(DBeaverIcons.getImage(databaseNode.getNodeIconDefault()));
    if (databaseNode == curNode) {
        item.setToolTipText(databaseNode.getNodeType());
        item.setEnabled(false);
    } else {
        item.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                if (e.detail == SWT.ARROW) {
                    int itemCount = 0;
                    if (breadcrumbsMenu != null) {
                        breadcrumbsMenu.dispose();
                    }
                    breadcrumbsMenu = new Menu(item.getParent().getShell());
                    try {
                        final DBNNode[] childNodes = NavigatorUtils.getNodeChildrenFiltered(VoidProgressMonitor.INSTANCE, databaseNode, false);
                        if (!ArrayUtils.isEmpty(childNodes)) {
                            for (final DBNNode folderItem : childNodes) {
                                MenuItem childItem = new MenuItem(breadcrumbsMenu, SWT.NONE);
                                childItem.setText(folderItem.getName());
                                //                                childItem.setImage(DBeaverIcons.getImage(folderItem.getNodeIconDefault()));
                                if (folderItem == curNode) {
                                    childItem.setEnabled(false);
                                }
                                childItem.addSelectionListener(new SelectionAdapter() {

                                    @Override
                                    public void widgetSelected(SelectionEvent e) {
                                        NavigatorHandlerObjectOpen.openEntityEditor(folderItem, null, PlatformUI.getWorkbench().getActiveWorkbenchWindow());
                                    }
                                });
                                itemCount++;
                                if (itemCount >= MAX_BREADCRUMBS_MENU_ITEM) {
                                    break;
                                }
                            }
                        }
                    } catch (Throwable e1) {
                        log.error(e1);
                    }
                    Rectangle rect = item.getBounds();
                    Point pt = item.getParent().toDisplay(new Point(rect.x, rect.y));
                    breadcrumbsMenu.setLocation(pt.x, pt.y + rect.height);
                    breadcrumbsMenu.setVisible(true);
                } else {
                    NavigatorHandlerObjectOpen.openEntityEditor(databaseNode, null, PlatformUI.getWorkbench().getActiveWorkbenchWindow());
                }
            }
        });
        item.setToolTipText("Open " + databaseNode.getNodeType() + " Editor");
    }
}
Also used : DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) DBNDatabaseFolder(org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)

Example 30 with DBNNode

use of org.jkiss.dbeaver.model.navigator.DBNNode in project dbeaver by serge-rider.

the class EditForeignKeyPage method createPageContents.

@Override
protected Control createPageContents(Composite parent) {
    final Composite panel = UIUtils.createPlaceholder(parent, 1, 5);
    panel.setLayoutData(new GridData(GridData.FILL_BOTH));
    {
        final Composite tableGroup = UIUtils.createPlaceholder(panel, 2, 5);
        tableGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        UIUtils.createLabelText(tableGroup, CoreMessages.dialog_struct_edit_fk_label_table, ownTable.getFullyQualifiedName(DBPEvaluationContext.UI), SWT.READ_ONLY | SWT.BORDER);
        if (ownerTableNode != null) {
            try {
                createSchemaSelector(tableGroup);
            } catch (Throwable e) {
                log.debug("Can't create schema selector", e);
            }
        }
    }
    {
        DBNNode rootNode = ownerTableNode == null ? DBeaverCore.getInstance().getNavigatorModel().getRoot() : ownerTableNode.getParentNode();
        UIUtils.createControlLabel(panel, CoreMessages.dialog_struct_edit_fk_label_ref_table);
        tableList = new ItemListControl(panel, SWT.SINGLE | SWT.SHEET | SWT.BORDER, null, rootNode, null);
        tableList.loadData();
        final GridData gd = new GridData(GridData.FILL_BOTH);
        gd.widthHint = 500;
        gd.heightHint = 150;
        tableList.setLayoutData(gd);
        tableList.getSelectionProvider().addSelectionChangedListener(new ISelectionChangedListener() {

            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                handleRefTableSelect(event.getSelection());
            }
        });
    }
    final Composite pkGroup = UIUtils.createPlaceholder(panel, 2);
    {
        pkGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        uniqueKeyCombo = UIUtils.createLabelCombo(pkGroup, CoreMessages.dialog_struct_edit_fk_combo_unik, SWT.DROP_DOWN | SWT.READ_ONLY);
        uniqueKeyCombo.setEnabled(false);
        uniqueKeyCombo.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                handleUniqueKeySelect();
            }
        });
    }
    {
        UIUtils.createControlLabel(panel, CoreMessages.dialog_struct_edit_fk_label_columns);
        columnsTable = new Table(panel, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
        columnsTable.setHeaderVisible(true);
        columnsTable.setLinesVisible(true);
        final GridData gd = new GridData(GridData.FILL_BOTH);
        gd.widthHint = 500;
        gd.heightHint = 100;
        columnsTable.setLayoutData(gd);
        UIUtils.createTableColumn(columnsTable, SWT.LEFT, CoreMessages.dialog_struct_edit_fk_column_column);
        UIUtils.createTableColumn(columnsTable, SWT.LEFT, CoreMessages.dialog_struct_edit_fk_column_col_type);
        UIUtils.createTableColumn(columnsTable, SWT.LEFT, CoreMessages.dialog_struct_edit_fk_column_ref_col);
        UIUtils.createTableColumn(columnsTable, SWT.LEFT, CoreMessages.dialog_struct_edit_fk_column_ref_col_type);
        UIUtils.packColumns(columnsTable);
        final TableEditor tableEditor = new TableEditor(columnsTable);
        tableEditor.horizontalAlignment = SWT.CENTER;
        tableEditor.verticalAlignment = SWT.TOP;
        tableEditor.grabHorizontal = true;
        tableEditor.minimumWidth = 50;
        columnsTable.addMouseListener(new ColumnsMouseListener(tableEditor, columnsTable));
    }
    final Composite cascadeGroup = UIUtils.createPlaceholder(panel, 4, 5);
    {
        // Cascades
        cascadeGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        final Combo onDeleteCombo = UIUtils.createLabelCombo(cascadeGroup, CoreMessages.dialog_struct_edit_fk_combo_on_delete, SWT.DROP_DOWN | SWT.READ_ONLY);
        onDeleteCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        final Combo onUpdateCombo = UIUtils.createLabelCombo(cascadeGroup, CoreMessages.dialog_struct_edit_fk_combo_on_update, SWT.DROP_DOWN | SWT.READ_ONLY);
        onUpdateCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        for (DBSForeignKeyModifyRule modifyRule : supportedModifyRules) {
            onDeleteCombo.add(modifyRule.getName());
            onUpdateCombo.add(modifyRule.getName());
        }
        onDeleteCombo.select(0);
        onUpdateCombo.select(0);
        onDeleteRule = onUpdateRule = supportedModifyRules[0];
        onDeleteCombo.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                onDeleteRule = supportedModifyRules[onDeleteCombo.getSelectionIndex()];
            }
        });
        onUpdateCombo.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                onUpdateRule = supportedModifyRules[onUpdateCombo.getSelectionIndex()];
            }
        });
    }
    return panel;
}
Also used : DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) CCombo(org.eclipse.swt.custom.CCombo) CSmartCombo(org.jkiss.dbeaver.ui.controls.CSmartCombo) ItemListControl(org.jkiss.dbeaver.ui.controls.itemlist.ItemListControl) TableEditor(org.eclipse.swt.custom.TableEditor) GridData(org.eclipse.swt.layout.GridData)

Aggregations

DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)40 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)19 DBException (org.jkiss.dbeaver.DBException)13 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)12 ISelection (org.eclipse.jface.viewers.ISelection)9 ArrayList (java.util.ArrayList)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 GridData (org.eclipse.swt.layout.GridData)5 DBNDatabaseFolder (org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)5 DBNResource (org.jkiss.dbeaver.model.navigator.DBNResource)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 IFile (org.eclipse.core.resources.IFile)4 DBNDataSource (org.jkiss.dbeaver.model.navigator.DBNDataSource)4 DBNModel (org.jkiss.dbeaver.model.navigator.DBNModel)4 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 DBNDatabaseItem (org.jkiss.dbeaver.model.navigator.DBNDatabaseItem)3 CSmartCombo (org.jkiss.dbeaver.ui.controls.CSmartCombo)3 IProject (org.eclipse.core.resources.IProject)2