Search in sources :

Example 1 with EntityEditorDescriptor

use of org.jkiss.dbeaver.registry.editor.EntityEditorDescriptor in project dbeaver by dbeaver.

the class EntityEditor method addContributions.

private void addContributions(String position) {
    EntityEditorsRegistry editorsRegistry = EntityEditorsRegistry.getInstance();
    final DBSObject databaseObject = getEditorInput().getDatabaseObject();
    DBPObject object;
    if (databaseObject instanceof DBPDataSourceContainer && databaseObject.getDataSource() != null) {
        object = databaseObject.getDataSource();
    } else {
        object = databaseObject;
    }
    List<EntityEditorDescriptor> descriptors = editorsRegistry.getEntityEditors(object, this, position);
    for (EntityEditorDescriptor descriptor : descriptors) {
        if (descriptor.getType() == EntityEditorDescriptor.Type.editor) {
            addEditorTab(descriptor);
        }
    }
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) EntityEditorDescriptor(org.jkiss.dbeaver.registry.editor.EntityEditorDescriptor) EntityEditorsRegistry(org.jkiss.dbeaver.registry.editor.EntityEditorsRegistry)

Example 2 with EntityEditorDescriptor

use of org.jkiss.dbeaver.registry.editor.EntityEditorDescriptor in project dbeaver by dbeaver.

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(() -> firePropertyChange(IEditorPart.PROP_DIRTY));
        }
    };
    DBECommandContext commandContext = getCommandContext();
    if (commandContext != null) {
        commandContext.addCommandListener(commandListener);
    }
    // Property listener
    addPropertyListener((source, 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, this);
        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) EntityEditorsRegistry(org.jkiss.dbeaver.registry.editor.EntityEditorsRegistry) Point(org.eclipse.swt.graphics.Point) 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)

Example 3 with EntityEditorDescriptor

use of org.jkiss.dbeaver.registry.editor.EntityEditorDescriptor in project dbeaver by dbeaver.

the class ObjectPropertiesEditor method makeDatabaseEditorTabs.

private void makeDatabaseEditorTabs(final IDatabaseEditor part, final List<TabbedFolderInfo> tabList) {
    final DBNDatabaseNode node = part.getEditorInput().getNavigatorNode();
    if (node == null) {
        return;
    }
    final DBSObject object = node.getObject();
    if (!node.getMeta().isStandaloneNode()) {
        // Collect tabs from navigator tree model
        DBRRunnableWithProgress tabsCollector = new DBRRunnableWithProgress() {

            @Override
            public void run(DBRProgressMonitor monitor) {
                collectNavigatorTabs(monitor, part, node, tabList);
            }
        };
        try {
            if (node.needsInitialization()) {
                DBeaverUI.runInProgressService(tabsCollector);
            } else {
                tabsCollector.run(new VoidProgressMonitor());
            }
        } catch (InvocationTargetException e) {
            log.error(e.getTargetException());
        } catch (InterruptedException e) {
        // just go further
        }
    }
    // Query for entity editors
    List<EntityEditorDescriptor> editors = EntityEditorsRegistry.getInstance().getEntityEditors(object, this, null);
    if (!CommonUtils.isEmpty(editors)) {
        for (EntityEditorDescriptor descriptor : editors) {
            if (descriptor.getType() == EntityEditorDescriptor.Type.folder) {
                tabList.add(new TabbedFolderInfo(descriptor.getId(), descriptor.getName(), descriptor.getIcon(), descriptor.getDescription(), descriptor.isEmbeddable(), new TabbedFolderPageEditor(this, descriptor)));
            }
        }
    }
}
Also used : DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) EntityEditorDescriptor(org.jkiss.dbeaver.registry.editor.EntityEditorDescriptor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)3 EntityEditorDescriptor (org.jkiss.dbeaver.registry.editor.EntityEditorDescriptor)3 EntityEditorsRegistry (org.jkiss.dbeaver.registry.editor.EntityEditorsRegistry)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Point (org.eclipse.swt.graphics.Point)1 DBECommand (org.jkiss.dbeaver.model.edit.DBECommand)1 DBECommandContext (org.jkiss.dbeaver.model.edit.DBECommandContext)1 DBECommandAdapter (org.jkiss.dbeaver.model.impl.edit.DBECommandAdapter)1 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)1 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)1 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)1 DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)1 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)1 ITabbedFolderContainer (org.jkiss.dbeaver.ui.controls.folders.ITabbedFolderContainer)1