Search in sources :

Example 1 with ITabbedFolderContainer

use of org.jkiss.dbeaver.ui.controls.folders.ITabbedFolderContainer in project dbeaver by serge-rider.

the class NavigatorHandlerObjectOpen method openEntityEditor.

public static IEditorPart openEntityEditor(@NotNull DBNNode selectedNode, @Nullable String defaultPageId, @Nullable Map<String, Object> attributes, IWorkbenchWindow workbenchWindow) {
    if (selectedNode instanceof DBNDataSource) {
        final DataSourceDescriptor dataSourceContainer = (DataSourceDescriptor) ((DBNDataSource) selectedNode).getDataSourceContainer();
        openConnectionEditor(workbenchWindow, dataSourceContainer);
        return null;
    }
    if (!selectedNode.isPersisted()) {
        log.debug("Node '" + selectedNode.getNodeName() + "' s not persisted. Open not possible.");
        return null;
    }
    try {
        String defaultFolderId = null;
        if (selectedNode instanceof DBNDatabaseFolder && !(selectedNode.getParentNode() instanceof DBNDatabaseFolder) && selectedNode.getParentNode() instanceof DBNDatabaseNode) {
            defaultFolderId = selectedNode.getNodeType();
            selectedNode = selectedNode.getParentNode();
        }
        DatabaseEditorInputFactory.setLookupEditor(true);
        try {
            for (IEditorReference ref : workbenchWindow.getActivePage().getEditorReferences()) {
                IEditorInput editorInput;
                try {
                    editorInput = ref.getEditorInput();
                } catch (Throwable e) {
                    continue;
                }
                if (editorInput instanceof INavigatorEditorInput) {
                    boolean matches;
                    if (editorInput instanceof DatabaseLazyEditorInput) {
                        matches = selectedNode.getNodeItemPath().equals(((DatabaseLazyEditorInput) editorInput).getNodePath());
                    } else {
                        matches = ((INavigatorEditorInput) editorInput).getNavigatorNode() == selectedNode;
                    }
                    if (matches) {
                        final IEditorPart editor = ref.getEditor(true);
                        if (editor instanceof ITabbedFolderContainer && defaultFolderId != null) {
                            // Activate default folder
                            ((ITabbedFolderContainer) editor).switchFolder(defaultFolderId);
                        }
                        workbenchWindow.getActivePage().activate(editor);
                        return editor;
                    }
                }
            }
        } finally {
            DatabaseEditorInputFactory.setLookupEditor(false);
        }
        if (selectedNode instanceof DBNDatabaseObject) {
            DBNDatabaseObject objectNode = (DBNDatabaseObject) selectedNode;
            ObjectEditorInput objectInput = new ObjectEditorInput(objectNode);
            setInputAttributes(objectInput, defaultPageId, defaultFolderId, attributes);
            return workbenchWindow.getActivePage().openEditor(objectInput, objectNode.getMeta().getEditorId());
        } else if (selectedNode instanceof DBNDatabaseNode) {
            DBNDatabaseNode dnNode = (DBNDatabaseNode) selectedNode;
            if (dnNode.getObject() != null) {
                EntityEditorInput editorInput = new EntityEditorInput(dnNode);
                if (DBeaverCore.getGlobalPreferenceStore().getBoolean(DBeaverPreferences.NAVIGATOR_REFRESH_EDITORS_ON_OPEN)) {
                    if (dnNode.getObject() instanceof DBSObjectContainer) {
                    // do not auto-refresh object containers (too expensive)
                    } else {
                        refreshDatabaseNode(dnNode);
                    }
                }
                setInputAttributes(editorInput, defaultPageId, defaultFolderId, attributes);
                return workbenchWindow.getActivePage().openEditor(editorInput, EntityEditor.class.getName());
            } else {
                UIUtils.showErrorDialog(workbenchWindow.getShell(), "No object", "Node do not has associated database object");
                return null;
            }
        } else {
            NodeEditorInput folderInput = new NodeEditorInput(selectedNode);
            return workbenchWindow.getActivePage().openEditor(folderInput, FolderEditor.class.getName());
        }
    } catch (Exception ex) {
        UIUtils.showErrorDialog(workbenchWindow.getShell(), CoreMessages.actions_navigator_error_dialog_open_entity_title, "Can't open entity '" + selectedNode.getNodeName() + "'", ex);
        return null;
    }
}
Also used : EntityEditorInput(org.jkiss.dbeaver.ui.editors.entity.EntityEditorInput) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException) ITabbedFolderContainer(org.jkiss.dbeaver.ui.controls.folders.ITabbedFolderContainer) ObjectEditorInput(org.jkiss.dbeaver.ui.editors.object.ObjectEditorInput) NodeEditorInput(org.jkiss.dbeaver.ui.editors.entity.NodeEditorInput) DBSObjectContainer(org.jkiss.dbeaver.model.struct.DBSObjectContainer) DataSourceDescriptor(org.jkiss.dbeaver.registry.DataSourceDescriptor)

Example 2 with ITabbedFolderContainer

use of org.jkiss.dbeaver.ui.controls.folders.ITabbedFolderContainer in project dbeaver by serge-rider.

the class EntityEditor method addEditorTab.

private boolean addEditorTab(EntityEditorDescriptor descriptor) {
    try {
        IEditorPart editor = descriptor.createEditor();
        if (editor == null) {
            return false;
        }
        IEditorInput nestedInput = descriptor.getNestedEditorInput(getEditorInput());
        final Class<? extends IEditorActionBarContributor> contributorClass = descriptor.getContributorClass();
        if (contributorClass != null) {
            addActionsContributor(editor, contributorClass);
        }
        int index = addPage(editor, nestedInput);
        setPageText(index, descriptor.getName());
        if (descriptor.getIcon() != null) {
            setPageImage(index, DBeaverIcons.getImage(descriptor.getIcon()));
        }
        if (!CommonUtils.isEmpty(descriptor.getDescription())) {
            setPageToolTip(index, descriptor.getDescription());
        }
        editorMap.put(descriptor.getId(), editor);
        if (editor instanceof ITabbedFolderContainer) {
            ((ITabbedFolderContainer) editor).addFolderListener(folderListener);
        }
        return true;
    } catch (Exception ex) {
        //$NON-NLS-1$
        log.error("Error adding nested editor", ex);
        return false;
    }
}
Also used : ITabbedFolderContainer(org.jkiss.dbeaver.ui.controls.folders.ITabbedFolderContainer) Point(org.eclipse.swt.graphics.Point) DBCException(org.jkiss.dbeaver.model.exec.DBCException) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBException(org.jkiss.dbeaver.DBException)

Example 3 with ITabbedFolderContainer

use of org.jkiss.dbeaver.ui.controls.folders.ITabbedFolderContainer 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)

Aggregations

ITabbedFolderContainer (org.jkiss.dbeaver.ui.controls.folders.ITabbedFolderContainer)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Point (org.eclipse.swt.graphics.Point)2 DBException (org.jkiss.dbeaver.DBException)2 ExecutionException (org.eclipse.core.commands.ExecutionException)1 DBECommand (org.jkiss.dbeaver.model.edit.DBECommand)1 DBECommandContext (org.jkiss.dbeaver.model.edit.DBECommandContext)1 DBCException (org.jkiss.dbeaver.model.exec.DBCException)1 DBECommandAdapter (org.jkiss.dbeaver.model.impl.edit.DBECommandAdapter)1 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)1 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)1 DBSObjectContainer (org.jkiss.dbeaver.model.struct.DBSObjectContainer)1 DataSourceDescriptor (org.jkiss.dbeaver.registry.DataSourceDescriptor)1 EntityEditorDescriptor (org.jkiss.dbeaver.registry.editor.EntityEditorDescriptor)1 EntityEditorsRegistry (org.jkiss.dbeaver.registry.editor.EntityEditorsRegistry)1 EntityEditorInput (org.jkiss.dbeaver.ui.editors.entity.EntityEditorInput)1 NodeEditorInput (org.jkiss.dbeaver.ui.editors.entity.NodeEditorInput)1 ObjectEditorInput (org.jkiss.dbeaver.ui.editors.object.ObjectEditorInput)1