Search in sources :

Example 1 with MultiPageEditorSite

use of org.eclipse.ui.part.MultiPageEditorSite in project dbeaver by serge-rider.

the class TabbedFolderPageNode method createControl.

@Override
public void createControl(Composite parent) {
    itemControl = new ItemListControl(parent, SWT.SHEET, mainEditor.getSite(), node, metaNode);
    //itemControl.getLayout().marginHeight = 0;
    //itemControl.getLayout().marginWidth = 0;
    ProgressPageControl progressControl = null;
    if (mainEditor instanceof IProgressControlProvider) {
        progressControl = ((IProgressControlProvider) mainEditor).getProgressControl();
    }
    if (progressControl != null) {
        itemControl.substituteProgressPanel(progressControl);
    } else {
        itemControl.createProgressPanel();
    }
    parent.layout();
    // Activate items control on focus
    itemControl.getItemsViewer().getControl().addFocusListener(new FocusListener() {

        @Override
        public void focusGained(FocusEvent e) {
            // Update selection provider and selection
            final ISelectionProvider selectionProvider = itemControl.getSelectionProvider();
            if (mainEditor.getSite().getSelectionProvider() != selectionProvider) {
                mainEditor.getSite().setSelectionProvider(selectionProvider);
                selectionProvider.setSelection(selectionProvider.getSelection());
            }
            itemControl.activate(true);
            // We need it to update search actions and other contributions provided by node editor
            if (mainEditor.getSite() instanceof MultiPageEditorSite) {
                MultiPageEditorPart multiPageEditor = ((MultiPageEditorSite) mainEditor.getSite()).getMultiPageEditor();
                if (multiPageEditor.getSelectedPage() != mainEditor) {
                    multiPageEditor.setActiveEditor(mainEditor);
                }
            }
        }

        @Override
        public void focusLost(FocusEvent e) {
            itemControl.activate(false);
        }
    });
}
Also used : ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ProgressPageControl(org.jkiss.dbeaver.ui.controls.ProgressPageControl) MultiPageEditorPart(org.eclipse.ui.part.MultiPageEditorPart) ItemListControl(org.jkiss.dbeaver.ui.controls.itemlist.ItemListControl) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent) MultiPageEditorSite(org.eclipse.ui.part.MultiPageEditorSite)

Example 2 with MultiPageEditorSite

use of org.eclipse.ui.part.MultiPageEditorSite in project dbeaver by serge-rider.

the class ItemListControl method fillCustomActions.

@Override
protected void fillCustomActions(IContributionManager contributionManager) {
    super.fillCustomActions(contributionManager);
    final DBNNode rootNode = getRootNode();
    if (rootNode instanceof DBNDatabaseFolder && ((DBNDatabaseFolder) rootNode).getItemsMeta() != null) {
        contributionManager.add(new Action("Filter", DBeaverIcons.getImageDescriptor(UIIcon.FILTER)) {

            @Override
            public void run() {
                NavigatorHandlerFilterConfig.configureFilters(getShell(), rootNode);
            }
        });
    }
    IWorkbenchSite workbenchSite = getWorkbenchSite();
    if (workbenchSite != null) {
        contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.FILE_REFRESH));
    }
    if (rootNode instanceof DBNDatabaseNode) {
        contributionManager.add(new Separator());
        contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, CoreCommands.CMD_OBJECT_OPEN));
        contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, CoreCommands.CMD_OBJECT_CREATE));
        contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, CoreCommands.CMD_OBJECT_DELETE));
    }
    if (rootNode instanceof DBNDatabaseNode && rootNode.isPersisted()) {
        boolean hasReorder = false;
        List<Class<?>> childrenTypes = ((DBNDatabaseNode) rootNode).getChildrenTypes(null);
        for (Class<?> chilType : childrenTypes) {
            if (EntityEditorsRegistry.getInstance().getObjectManager(chilType, DBEObjectReorderer.class) != null) {
                hasReorder = true;
                break;
            }
        }
        if (hasReorder) {
            contributionManager.add(new Separator());
            contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, CoreCommands.CMD_OBJECT_MOVE_UP));
            contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, CoreCommands.CMD_OBJECT_MOVE_DOWN));
        }
    }
    if (workbenchSite instanceof MultiPageEditorSite) {
        final MultiPageEditorPart editor = ((MultiPageEditorSite) workbenchSite).getMultiPageEditor();
        if (editor instanceof EntityEditor) {
            contributionManager.add(new Separator());
            contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.FILE_SAVE, null, UIIcon.SAVE, null, true));
            contributionManager.add(ActionUtils.makeCommandContribution(workbenchSite, IWorkbenchCommandConstants.FILE_REVERT, null, UIIcon.RESET, null, true));
        }
    }
}
Also used : IWorkbenchSite(org.eclipse.ui.IWorkbenchSite) Action(org.eclipse.jface.action.Action) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) MultiPageEditorPart(org.eclipse.ui.part.MultiPageEditorPart) DBNDatabaseFolder(org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder) DBEObjectReorderer(org.jkiss.dbeaver.model.edit.DBEObjectReorderer) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) MultiPageEditorSite(org.eclipse.ui.part.MultiPageEditorSite) Separator(org.eclipse.jface.action.Separator)

Example 3 with MultiPageEditorSite

use of org.eclipse.ui.part.MultiPageEditorSite in project dbeaver by serge-rider.

the class TabbedFolderPageEditor method createControl.

@Override
public void createControl(Composite parent) {
    editor = editorDescriptor.createEditor();
    final IWorkbenchPartSite ownerSite = this.mainEditor.getSite();
    if (ownerSite instanceof MultiPageEditorSite) {
        final MultiPageEditorPart ownerMultiPageEditor = ((MultiPageEditorSite) ownerSite).getMultiPageEditor();
        nestedEditorSite = new TabbedFolderPageEditorSite(ownerMultiPageEditor, editor);
        // We need it to tell owner editor about dirty state change
        if (ownerMultiPageEditor instanceof IPropertyChangeReflector) {
            editor.addPropertyListener(new IPropertyListener() {

                @Override
                public void propertyChanged(Object source, int propId) {
                    ((IPropertyChangeReflector) ownerMultiPageEditor).handlePropertyChange(propId);
                }
            });
        }
    } else {
        nestedEditorSite = new SubEditorSite(mainEditor.getEditorSite());
    }
    try {
        editor.init(nestedEditorSite, editorDescriptor.getNestedEditorInput(mainEditor.getEditorInput()));
    } catch (PartInitException e) {
        UIUtils.showErrorDialog(parent.getShell(), "Create SQL viewer", null, e);
    }
    editor.createPartControl(parent);
    if (editor instanceof ISingleControlEditor) {
        // Use focus to active selection provider and contributed actions
        Control editorControl = ((ISingleControlEditor) editor).getEditorControl();
        assert editorControl != null;
        editorControl.addFocusListener(new FocusListener() {

            @Override
            public void focusGained(FocusEvent e) {
                ISelectionProvider selectionProvider = editor.getSite().getSelectionProvider();
                mainEditor.getSite().setSelectionProvider(selectionProvider);
                if (actionContributor != null) {
                    actionContributor.setActiveEditor(editor);
                }
                activateNestedSite(true);
            }

            @Override
            public void focusLost(FocusEvent e) {
                activateNestedSite(false);
                if (actionContributor != null) {
                    actionContributor.setActiveEditor(null);
                }
            }
        });
    }
    parent.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            if (editor != null) {
                editor.dispose();
                editor = null;
            }
        }
    });
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) MultiPageEditorPart(org.eclipse.ui.part.MultiPageEditorPart) DisposeEvent(org.eclipse.swt.events.DisposeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) SubEditorSite(org.jkiss.dbeaver.ui.editors.SubEditorSite) Control(org.eclipse.swt.widgets.Control) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) MultiPageEditorSite(org.eclipse.ui.part.MultiPageEditorSite) FocusListener(org.eclipse.swt.events.FocusListener)

Example 4 with MultiPageEditorSite

use of org.eclipse.ui.part.MultiPageEditorSite in project dbeaver by serge-rider.

the class SQLEditorNested method refreshPart.

@Override
public void refreshPart(Object source, boolean force) {
    // Check if we are in saving process
    // If so then no refresh needed (source text was updated during save)
    IEditorSite editorSite = getEditorSite();
    if (editorSite instanceof MultiPageEditorSite && ((MultiPageEditorSite) editorSite).getMultiPageEditor() instanceof EntityEditor && ((EntityEditor) ((MultiPageEditorSite) editorSite).getMultiPageEditor()).isSaveInProgress()) {
        return;
    }
    final IDocumentProvider documentProvider = getDocumentProvider();
    if (documentProvider instanceof SQLEditorNested.ObjectDocumentProvider) {
        ((SQLEditorNested.ObjectDocumentProvider) documentProvider).sourceText = null;
    }
    if (force) {
        try {
            super.init(editorSite, getEditorInput());
        //setFocus();
        } catch (PartInitException e) {
            log.error(e);
        }
    }
}
Also used : IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor) PartInitException(org.eclipse.ui.PartInitException) MultiPageEditorSite(org.eclipse.ui.part.MultiPageEditorSite) IEditorSite(org.eclipse.ui.IEditorSite)

Aggregations

MultiPageEditorSite (org.eclipse.ui.part.MultiPageEditorSite)4 MultiPageEditorPart (org.eclipse.ui.part.MultiPageEditorPart)3 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)2 FocusEvent (org.eclipse.swt.events.FocusEvent)2 FocusListener (org.eclipse.swt.events.FocusListener)2 EntityEditor (org.jkiss.dbeaver.ui.editors.entity.EntityEditor)2 Action (org.eclipse.jface.action.Action)1 Separator (org.eclipse.jface.action.Separator)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 DisposeListener (org.eclipse.swt.events.DisposeListener)1 Control (org.eclipse.swt.widgets.Control)1 IEditorSite (org.eclipse.ui.IEditorSite)1 IWorkbenchSite (org.eclipse.ui.IWorkbenchSite)1 PartInitException (org.eclipse.ui.PartInitException)1 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)1 DBEObjectReorderer (org.jkiss.dbeaver.model.edit.DBEObjectReorderer)1 DBNDatabaseFolder (org.jkiss.dbeaver.model.navigator.DBNDatabaseFolder)1 DBNDatabaseNode (org.jkiss.dbeaver.model.navigator.DBNDatabaseNode)1 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)1 ProgressPageControl (org.jkiss.dbeaver.ui.controls.ProgressPageControl)1