Search in sources :

Example 1 with DBECommandAdapter

use of org.jkiss.dbeaver.model.impl.edit.DBECommandAdapter in project dbeaver by dbeaver.

the class TabbedFolderPageForm method createControl.

@Override
public void createControl(Composite parent) {
    this.boldFont = UIUtils.makeBoldFont(parent.getFont());
    // ScrolledComposite scrolled = new ScrolledComposite(parent, SWT.V_SCROLL);
    // scrolled.setLayout(new GridLayout(1, false));
    propertiesGroup = new Composite(parent, SWT.NONE);
    // CSSUtils.setCSSClass(propertiesGroup, DBStyles.COLORED_BY_CONNECTION_TYPE);
    curPropertySource = input.getPropertySource();
    DBECommandContext commandContext = input.getCommandContext();
    if (commandContext != null) {
        commandContext.addCommandListener(new DBECommandAdapter() {

            @Override
            public void onCommandChange(DBECommand<?> command) {
                UIUtils.asyncExec(() -> {
                    updateEditButtonsState();
                    if (command instanceof DBECommandProperty) {
                        // We need to exclude current prop from update
                        // Simple value compare on update is not enough because value can be transformed (e.g. uppercased)
                        // and it will differ from the value in edit control
                        Object propId = ((DBECommandProperty<?>) command).getHandler().getId();
                        updateOtherPropertyValues(propId);
                    }
                });
            }

            @Override
            public void onSave() {
                UIUtils.asyncExec(() -> updateEditButtonsState());
            }

            @Override
            public void onReset() {
                UIUtils.asyncExec(() -> {
                    refreshProperties();
                    updateEditButtonsState();
                });
            }
        });
    }
    propertiesGroup.addDisposeListener(e -> dispose());
    refreshProperties();
}
Also used : DBECommandProperty(org.jkiss.dbeaver.model.edit.prop.DBECommandProperty) DBECommandContext(org.jkiss.dbeaver.model.edit.DBECommandContext) DBECommandAdapter(org.jkiss.dbeaver.model.impl.edit.DBECommandAdapter) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject)

Example 2 with DBECommandAdapter

use of org.jkiss.dbeaver.model.impl.edit.DBECommandAdapter in project dbeaver by serge-rider.

the class EntityEditor method createPages.

@Override
protected void createPages() {
    super.createPages();
    final IDatabaseEditorInput editorInput = getEditorInput();
    if (editorInput instanceof DatabaseLazyEditorInput) {
        try {
            addPage(new ProgressEditorPart(this), editorInput);
            setPageText(0, "Initializing ...");
            Image tabImage = DBeaverIcons.getImage(UIIcon.REFRESH);
            setPageImage(0, tabImage);
            setActivePage(0);
            ((CTabFolder) getContainer()).setTabHeight(tabImage.getBounds().height + 2);
        } 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) {
            UIUtils.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);
        }
    });
    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, UINavigatorMessages.editors_entity_properties_text);
            setPageToolTip(propEditorIndex, node.getNodeType() + UINavigatorMessages.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) {
            String folderId = defFolderId;
            UIUtils.asyncExec(() -> {
                ((ITabbedFolderContainer) activeEditor).switchFolder(folderId);
            });
        }
    }
    UIUtils.setHelp(getContainer(), IHelpContextIds.CTX_ENTITY_EDITOR);
}
Also used : CTabFolder(org.eclipse.swt.custom.CTabFolder) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) 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 DBECommandAdapter

use of org.jkiss.dbeaver.model.impl.edit.DBECommandAdapter in project dbeaver by serge-rider.

the class TabbedFolderPageForm method createControl.

@Override
public void createControl(Composite parent) {
    this.boldFont = UIUtils.makeBoldFont(parent.getFont());
    // ScrolledComposite scrolled = new ScrolledComposite(parent, SWT.V_SCROLL);
    // scrolled.setLayout(new GridLayout(1, false));
    propertiesGroup = new Composite(parent, SWT.NONE);
    // CSSUtils.setCSSClass(propertiesGroup, DBStyles.COLORED_BY_CONNECTION_TYPE);
    curPropertySource = input.getPropertySource();
    DBECommandContext commandContext = input.getCommandContext();
    if (commandContext != null) {
        commandContext.addCommandListener(new DBECommandAdapter() {

            @Override
            public void onCommandChange(DBECommand<?> command) {
                UIUtils.asyncExec(() -> {
                    updateEditButtonsState();
                    if (command instanceof DBECommandProperty) {
                        // We need to exclude current prop from update
                        // Simple value compare on update is not enough because value can be transformed (e.g. uppercased)
                        // and it will differ from the value in edit control
                        Object propId = ((DBECommandProperty<?>) command).getHandler().getId();
                        updateOtherPropertyValues(propId);
                    }
                });
            }

            @Override
            public void onSave() {
                UIUtils.asyncExec(() -> updateEditButtonsState());
            }

            @Override
            public void onReset() {
                UIUtils.asyncExec(() -> {
                    refreshProperties();
                    updateEditButtonsState();
                });
            }
        });
    }
    propertiesGroup.addDisposeListener(e -> dispose());
    refreshProperties();
}
Also used : DBECommandProperty(org.jkiss.dbeaver.model.edit.prop.DBECommandProperty) DBECommandContext(org.jkiss.dbeaver.model.edit.DBECommandContext) DBECommandAdapter(org.jkiss.dbeaver.model.impl.edit.DBECommandAdapter) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject)

Example 4 with DBECommandAdapter

use of org.jkiss.dbeaver.model.impl.edit.DBECommandAdapter in project dbeaver by dbeaver.

the class EntityEditor method createPages.

@Override
protected void createPages() {
    super.createPages();
    final IDatabaseEditorInput editorInput = getEditorInput();
    if (editorInput instanceof DatabaseLazyEditorInput) {
        try {
            addPage(new ProgressEditorPart(this), editorInput);
            setPageText(0, "Initializing ...");
            Image tabImage = DBeaverIcons.getImage(UIIcon.REFRESH);
            setPageImage(0, tabImage);
            setActivePage(0);
            ((CTabFolder) getContainer()).setTabHeight(tabImage.getBounds().height + 2);
        } 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) {
            UIUtils.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);
        }
    });
    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, UINavigatorMessages.editors_entity_properties_text);
            setPageToolTip(propEditorIndex, node.getNodeType() + UINavigatorMessages.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) {
            String folderId = defFolderId;
            UIUtils.asyncExec(() -> {
                ((ITabbedFolderContainer) activeEditor).switchFolder(folderId);
            });
        }
    }
    UIUtils.setHelp(getContainer(), IHelpContextIds.CTX_ENTITY_EDITOR);
}
Also used : CTabFolder(org.eclipse.swt.custom.CTabFolder) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ITabbedFolderContainer(org.jkiss.dbeaver.ui.controls.folders.ITabbedFolderContainer) DBECommandContext(org.jkiss.dbeaver.model.edit.DBECommandContext) DBECommandAdapter(org.jkiss.dbeaver.model.impl.edit.DBECommandAdapter)

Aggregations

DBECommandContext (org.jkiss.dbeaver.model.edit.DBECommandContext)4 DBECommandAdapter (org.jkiss.dbeaver.model.impl.edit.DBECommandAdapter)4 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)4 CTabFolder (org.eclipse.swt.custom.CTabFolder)2 Image (org.eclipse.swt.graphics.Image)2 Point (org.eclipse.swt.graphics.Point)2 DBPNamedObject (org.jkiss.dbeaver.model.DBPNamedObject)2 DBECommandProperty (org.jkiss.dbeaver.model.edit.prop.DBECommandProperty)2 ITabbedFolderContainer (org.jkiss.dbeaver.ui.controls.folders.ITabbedFolderContainer)2