Search in sources :

Example 6 with IFindReplaceTarget

use of org.eclipse.jface.text.IFindReplaceTarget in project dbeaver by serge-rider.

the class ResultSetViewer method setActivePresentation.

private void setActivePresentation(@NotNull IResultSetPresentation presentation) {
    boolean focusInPresentation = UIUtils.isParent(presentationPanel, viewerPanel.getDisplay().getFocusControl());
    // Dispose previous presentation and panels
    if (activePresentation != null) {
        activePresentation.dispose();
    }
    UIUtils.disposeChildControls(presentationPanel);
    if (panelFolder != null) {
        CTabItem curItem = panelFolder.getSelection();
        for (CTabItem panelItem : panelFolder.getItems()) {
            if (panelItem != curItem) {
                panelItem.dispose();
            }
        }
        if (curItem != null) {
            curItem.dispose();
        }
    }
    // Set new presentation
    activePresentation = presentation;
    availablePanels.clear();
    activePanels.clear();
    IResultSetContext context = new ResultSetContextImpl(this, null);
    if (activePresentationDescriptor != null) {
        availablePanels.addAll(ResultSetPresentationRegistry.getInstance().getSupportedPanels(context, getDataSource(), activePresentationDescriptor.getId(), activePresentationDescriptor.getPresentationType()));
    } else if (activePresentation instanceof StatisticsPresentation) {
        // Stats presentation
        availablePanels.addAll(ResultSetPresentationRegistry.getInstance().getSupportedPanels(context, getDataSource(), null, IResultSetPresentation.PresentationType.COLUMNS));
    }
    activePresentation.createPresentation(this, presentationPanel);
    // Clear panels toolbar
    if (panelSwitchFolder != null) {
        UIUtils.disposeChildControls(panelSwitchFolder);
    }
    // Activate panels
    if (supportsPanels()) {
        boolean panelsVisible = false;
        boolean verticalLayout = false;
        int[] panelWeights = new int[] { 700, 300 };
        if (activePresentationDescriptor != null) {
            PresentationSettings settings = getPresentationSettings();
            panelsVisible = settings.panelsVisible;
            verticalLayout = settings.verticalLayout;
            if (settings.panelRatio > 0) {
                panelWeights = new int[] { 1000 - settings.panelRatio, settings.panelRatio };
            }
            activateDefaultPanels(settings);
        }
        viewerSash.setOrientation(verticalLayout ? SWT.VERTICAL : SWT.HORIZONTAL);
        viewerSash.setWeights(panelWeights);
        showPanels(panelsVisible, false, false);
        if (!availablePanels.isEmpty()) {
            VerticalButton panelsButton = new VerticalButton(panelSwitchFolder, SWT.RIGHT | SWT.CHECK);
            {
                panelsButton.setText(ResultSetMessages.controls_resultset_config_panels);
                panelsButton.setImage(DBeaverIcons.getImage(UIIcon.PANEL_CUSTOMIZE));
                panelsButton.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        showPanels(!isPanelsVisible(), true, true);
                        panelsButton.setChecked(isPanelsVisible());
                        updatePanelsButtons();
                    }
                });
                String toolTip = ActionUtils.findCommandDescription(ResultSetHandlerMain.CMD_TOGGLE_PANELS, getSite(), false);
                if (!CommonUtils.isEmpty(toolTip)) {
                    panelsButton.setToolTipText(toolTip);
                }
                panelsButton.setChecked(panelsVisible);
            }
            // Add all panels
            for (final ResultSetPanelDescriptor panel : availablePanels) {
                VerticalButton panelButton = new VerticalButton(panelSwitchFolder, SWT.RIGHT | SWT.CHECK);
                GridData gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
                gd.verticalIndent = 2;
                gd.horizontalIndent = 1;
                panelButton.setLayoutData(gd);
                panelButton.setData(panel);
                panelButton.setImage(DBeaverIcons.getImage(panel.getIcon()));
                panelButton.setToolTipText(panel.getLabel());
                String toolTip = ActionUtils.findCommandDescription(ResultSetHandlerTogglePanel.CMD_TOGGLE_PANEL, getSite(), true, ResultSetHandlerTogglePanel.PARAM_PANEL_ID, panel.getId());
                if (!CommonUtils.isEmpty(toolTip)) {
                    panelButton.setToolTipText(panel.getLabel() + " (" + toolTip + ")");
                }
                panelButton.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        boolean isPanelVisible = isPanelsVisible() && isPanelVisible(panel.getId());
                        if (isPanelVisible) {
                            closePanel(panel.getId());
                        } else {
                            activatePanel(panel.getId(), true, true);
                        }
                        panelButton.setChecked(!isPanelVisible);
                        panelsButton.setChecked(isPanelsVisible());
                        if (panelSwitchFolder != null) {
                            panelSwitchFolder.redraw();
                        }
                    }
                });
                panelButton.setChecked(panelsVisible && isPanelVisible(panel.getId()));
            }
            UIUtils.createEmptyLabel(panelSwitchFolder, 1, 1).setLayoutData(new GridData(GridData.FILL_VERTICAL));
            VerticalButton.create(panelSwitchFolder, SWT.RIGHT | SWT.CHECK, getSite(), ResultSetHandlerMain.CMD_TOGGLE_LAYOUT, false);
        }
    } else {
        if (viewerSash != null) {
            viewerSash.setMaximizedControl(viewerSash.getChildren()[0]);
        }
    }
    mainPanel.layout(true, true);
    if (recordModeButton != null) {
        recordModeButton.setVisible(activePresentationDescriptor != null && activePresentationDescriptor.supportsRecordMode());
    }
    // Update dynamic find/replace target
    {
        IFindReplaceTarget nested = null;
        if (presentation instanceof IAdaptable) {
            nested = ((IAdaptable) presentation).getAdapter(IFindReplaceTarget.class);
        }
        findReplaceTarget.setTarget(nested);
    }
    if (!toolbarList.isEmpty()) {
        for (ToolBarManager tb : toolbarList) {
            tb.update(true);
        }
    }
    // Listen presentation selection change
    if (presentation instanceof ISelectionProvider) {
        ((ISelectionProvider) presentation).addSelectionChangedListener(this::fireResultSetSelectionChange);
    }
    // Use async exec to avoid focus switch after user UI interaction (e.g. combo)
    if (focusInPresentation) {
        UIUtils.asyncExec(() -> {
            Control control = activePresentation.getControl();
            if (control != null && !control.isDisposed()) {
                control.setFocus();
            }
        });
    }
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) VerticalButton(org.jkiss.dbeaver.ui.controls.VerticalButton) ResultSetPanelDescriptor(org.jkiss.dbeaver.ui.controls.resultset.panel.ResultSetPanelDescriptor) AutoRefreshControl(org.jkiss.dbeaver.ui.controls.autorefresh.AutoRefreshControl) StatisticsPresentation(org.jkiss.dbeaver.ui.controls.resultset.view.StatisticsPresentation) IFindReplaceTarget(org.eclipse.jface.text.IFindReplaceTarget)

Example 7 with IFindReplaceTarget

use of org.eclipse.jface.text.IFindReplaceTarget in project eclipse.platform.text by eclipse.

the class AbstractTextEditor method getAdapter.

@SuppressWarnings("unchecked")
@Override
public <T> T getAdapter(Class<T> required) {
    if (IEditorStatusLine.class.equals(required)) {
        if (fEditorStatusLine == null) {
            IStatusLineManager statusLineManager = getStatusLineManager();
            ISelectionProvider selectionProvider = getSelectionProvider();
            if (statusLineManager != null && selectionProvider != null)
                fEditorStatusLine = new EditorStatusLine(statusLineManager, selectionProvider);
        }
        return (T) fEditorStatusLine;
    }
    if (IVerticalRulerInfo.class.equals(required)) {
        if (fVerticalRuler != null)
            return (T) fVerticalRuler;
    }
    if (IMarkRegionTarget.class.equals(required)) {
        if (fMarkRegionTarget == null) {
            IStatusLineManager manager = getStatusLineManager();
            if (manager != null)
                fMarkRegionTarget = (fSourceViewer == null ? null : new MarkRegionTarget(fSourceViewer, manager));
        }
        return (T) fMarkRegionTarget;
    }
    if (IDeleteLineTarget.class.equals(required)) {
        if (fDeleteLineTarget == null) {
            fDeleteLineTarget = new TextViewerDeleteLineTarget(fSourceViewer);
        }
        return (T) fDeleteLineTarget;
    }
    if (IncrementalFindTarget.class.equals(required)) {
        if (fIncrementalFindTarget == null) {
            IStatusLineManager manager = getStatusLineManager();
            if (manager != null)
                fIncrementalFindTarget = (fSourceViewer == null ? null : new IncrementalFindTarget(fSourceViewer, manager));
        }
        return (T) fIncrementalFindTarget;
    }
    if (IFindReplaceTarget.class.equals(required)) {
        if (fFindReplaceTarget == null) {
            IFindReplaceTarget target = (fSourceViewer == null ? null : fSourceViewer.getFindReplaceTarget());
            if (target != null) {
                fFindReplaceTarget = new FindReplaceTarget(this, target);
                if (fFindScopeHighlightColor != null)
                    fFindReplaceTarget.setScopeHighlightColor(fFindScopeHighlightColor);
            }
        }
        return (T) fFindReplaceTarget;
    }
    if (ITextOperationTarget.class.equals(required))
        return (fSourceViewer == null ? null : (T) fSourceViewer.getTextOperationTarget());
    if (IRewriteTarget.class.equals(required)) {
        if (fSourceViewer instanceof ITextViewerExtension) {
            ITextViewerExtension extension = (ITextViewerExtension) fSourceViewer;
            return (T) extension.getRewriteTarget();
        }
        return null;
    }
    if (Control.class.equals(required))
        return fSourceViewer != null ? (T) fSourceViewer.getTextWidget() : null;
    if (IColumnSupport.class.equals(required)) {
        if (fColumnSupport == null)
            fColumnSupport = createColumnSupport();
        return (T) fColumnSupport;
    }
    return super.getAdapter(required);
}
Also used : ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) SWT(org.eclipse.swt.SWT) ST(org.eclipse.swt.custom.ST) IStatusLineManager(org.eclipse.jface.action.IStatusLineManager) IFindReplaceTarget(org.eclipse.jface.text.IFindReplaceTarget) IFindReplaceTarget(org.eclipse.jface.text.IFindReplaceTarget) IMarkRegionTarget(org.eclipse.jface.text.IMarkRegionTarget)

Example 8 with IFindReplaceTarget

use of org.eclipse.jface.text.IFindReplaceTarget in project dbeaver by serge-rider.

the class StyledTextUtils method fillDefaultStyledTextContextMenu.

public static void fillDefaultStyledTextContextMenu(IContributionManager menu, final StyledText text) {
    final Point selectionRange = text.getSelectionRange();
    menu.add(new StyledTextAction(IWorkbenchCommandConstants.EDIT_COPY, selectionRange.y > 0, text, ST.COPY));
    menu.add(new StyledTextAction(IWorkbenchCommandConstants.EDIT_PASTE, text.getEditable(), text, ST.PASTE));
    menu.add(new StyledTextAction(IWorkbenchCommandConstants.EDIT_CUT, selectionRange.y > 0, text, ST.CUT));
    menu.add(new StyledTextAction(IWorkbenchCommandConstants.EDIT_SELECT_ALL, true, text, ST.SELECT_ALL));
    menu.add(new StyledTextActionEx(ITextEditorActionDefinitionIds.WORD_WRAP, Action.AS_CHECK_BOX) {

        @Override
        public boolean isChecked() {
            return text.getWordWrap();
        }

        @Override
        public void run() {
            text.setWordWrap(!text.getWordWrap());
        }
    });
    IFindReplaceTarget stFindReplaceTarget = new StyledTextFindReplaceTarget(text);
    menu.add(TextEditorUtils.createFindReplaceAction(text.getShell(), stFindReplaceTarget));
    menu.add(new GroupMarker("styled_text_additions"));
}
Also used : GroupMarker(org.eclipse.jface.action.GroupMarker) Point(org.eclipse.swt.graphics.Point) IFindReplaceTarget(org.eclipse.jface.text.IFindReplaceTarget)

Example 9 with IFindReplaceTarget

use of org.eclipse.jface.text.IFindReplaceTarget in project dbeaver by dbeaver.

the class ResultSetViewer method setActivePresentation.

private void setActivePresentation(@NotNull IResultSetPresentation presentation) {
    boolean focusInPresentation = UIUtils.isParent(presentationPanel, viewerPanel.getDisplay().getFocusControl());
    // Dispose previous presentation and panels
    if (activePresentation != null) {
        activePresentation.dispose();
    }
    UIUtils.disposeChildControls(presentationPanel);
    if (panelFolder != null) {
        CTabItem curItem = panelFolder.getSelection();
        for (CTabItem panelItem : panelFolder.getItems()) {
            if (panelItem != curItem) {
                panelItem.dispose();
            }
        }
        if (curItem != null) {
            curItem.dispose();
        }
    }
    // Set new presentation
    activePresentation = presentation;
    availablePanels.clear();
    activePanels.clear();
    IResultSetContext context = new ResultSetContextImpl(this, null);
    if (activePresentationDescriptor != null) {
        availablePanels.addAll(ResultSetPresentationRegistry.getInstance().getSupportedPanels(context, getDataSource(), activePresentationDescriptor.getId(), activePresentationDescriptor.getPresentationType()));
    } else if (activePresentation instanceof StatisticsPresentation) {
        // Stats presentation
        availablePanels.addAll(ResultSetPresentationRegistry.getInstance().getSupportedPanels(context, getDataSource(), null, IResultSetPresentation.PresentationType.COLUMNS));
    }
    activePresentation.createPresentation(this, presentationPanel);
    // Clear panels toolbar
    if (panelSwitchFolder != null) {
        UIUtils.disposeChildControls(panelSwitchFolder);
    }
    // Activate panels
    if (supportsPanels()) {
        boolean panelsVisible = false;
        boolean verticalLayout = false;
        int[] panelWeights = new int[] { 700, 300 };
        if (activePresentationDescriptor != null) {
            PresentationSettings settings = getPresentationSettings();
            panelsVisible = settings.panelsVisible;
            verticalLayout = settings.verticalLayout;
            if (settings.panelRatio > 0) {
                panelWeights = new int[] { 1000 - settings.panelRatio, settings.panelRatio };
            }
            activateDefaultPanels(settings);
        }
        viewerSash.setOrientation(verticalLayout ? SWT.VERTICAL : SWT.HORIZONTAL);
        viewerSash.setWeights(panelWeights);
        showPanels(panelsVisible, false, false);
        if (!availablePanels.isEmpty()) {
            VerticalButton panelsButton = new VerticalButton(panelSwitchFolder, SWT.RIGHT | SWT.CHECK);
            {
                panelsButton.setText(ResultSetMessages.controls_resultset_config_panels);
                panelsButton.setImage(DBeaverIcons.getImage(UIIcon.PANEL_CUSTOMIZE));
                panelsButton.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        showPanels(!isPanelsVisible(), true, true);
                        panelsButton.setChecked(isPanelsVisible());
                        updatePanelsButtons();
                    }
                });
                String toolTip = ActionUtils.findCommandDescription(ResultSetHandlerMain.CMD_TOGGLE_PANELS, getSite(), false);
                if (!CommonUtils.isEmpty(toolTip)) {
                    panelsButton.setToolTipText(toolTip);
                }
                panelsButton.setChecked(panelsVisible);
            }
            // Add all panels
            for (final ResultSetPanelDescriptor panel : availablePanels) {
                VerticalButton panelButton = new VerticalButton(panelSwitchFolder, SWT.RIGHT | SWT.CHECK);
                GridData gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
                gd.verticalIndent = 2;
                gd.horizontalIndent = 1;
                panelButton.setLayoutData(gd);
                panelButton.setData(panel);
                panelButton.setImage(DBeaverIcons.getImage(panel.getIcon()));
                panelButton.setToolTipText(panel.getLabel());
                String toolTip = ActionUtils.findCommandDescription(ResultSetHandlerTogglePanel.CMD_TOGGLE_PANEL, getSite(), true, ResultSetHandlerTogglePanel.PARAM_PANEL_ID, panel.getId());
                if (!CommonUtils.isEmpty(toolTip)) {
                    panelButton.setToolTipText(panel.getLabel() + " (" + toolTip + ")");
                }
                panelButton.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        boolean isPanelVisible = isPanelsVisible() && isPanelVisible(panel.getId());
                        if (isPanelVisible) {
                            closePanel(panel.getId());
                        } else {
                            activatePanel(panel.getId(), true, true);
                        }
                        panelButton.setChecked(!isPanelVisible);
                        panelsButton.setChecked(isPanelsVisible());
                        if (panelSwitchFolder != null) {
                            panelSwitchFolder.redraw();
                        }
                    }
                });
                panelButton.setChecked(panelsVisible && isPanelVisible(panel.getId()));
            }
            UIUtils.createEmptyLabel(panelSwitchFolder, 1, 1).setLayoutData(new GridData(GridData.FILL_VERTICAL));
            VerticalButton.create(panelSwitchFolder, SWT.RIGHT | SWT.CHECK, getSite(), ResultSetHandlerMain.CMD_TOGGLE_LAYOUT, false);
        }
    } else {
        if (viewerSash != null) {
            viewerSash.setMaximizedControl(viewerSash.getChildren()[0]);
        }
    }
    mainPanel.layout(true, true);
    if (recordModeButton != null) {
        recordModeButton.setVisible(activePresentationDescriptor != null && activePresentationDescriptor.supportsRecordMode());
    }
    // Update dynamic find/replace target
    {
        IFindReplaceTarget nested = null;
        if (presentation instanceof IAdaptable) {
            nested = ((IAdaptable) presentation).getAdapter(IFindReplaceTarget.class);
        }
        findReplaceTarget.setTarget(nested);
    }
    if (!toolbarList.isEmpty()) {
        for (ToolBarManager tb : toolbarList) {
            tb.update(true);
        }
    }
    // Listen presentation selection change
    if (presentation instanceof ISelectionProvider) {
        ((ISelectionProvider) presentation).addSelectionChangedListener(this::fireResultSetSelectionChange);
    }
    // Use async exec to avoid focus switch after user UI interaction (e.g. combo)
    if (focusInPresentation) {
        UIUtils.asyncExec(() -> {
            Control control = activePresentation.getControl();
            if (control != null && !control.isDisposed()) {
                control.setFocus();
            }
        });
    }
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) VerticalButton(org.jkiss.dbeaver.ui.controls.VerticalButton) ResultSetPanelDescriptor(org.jkiss.dbeaver.ui.controls.resultset.panel.ResultSetPanelDescriptor) AutoRefreshControl(org.jkiss.dbeaver.ui.controls.autorefresh.AutoRefreshControl) StatisticsPresentation(org.jkiss.dbeaver.ui.controls.resultset.view.StatisticsPresentation) IFindReplaceTarget(org.eclipse.jface.text.IFindReplaceTarget)

Example 10 with IFindReplaceTarget

use of org.eclipse.jface.text.IFindReplaceTarget in project dbeaver by dbeaver.

the class StyledTextUtils method fillDefaultStyledTextContextMenu.

public static void fillDefaultStyledTextContextMenu(IContributionManager menu, final StyledText text) {
    final Point selectionRange = text.getSelectionRange();
    menu.add(new StyledTextAction(IWorkbenchCommandConstants.EDIT_COPY, selectionRange.y > 0, text, ST.COPY));
    menu.add(new StyledTextAction(IWorkbenchCommandConstants.EDIT_PASTE, text.getEditable(), text, ST.PASTE));
    menu.add(new StyledTextAction(IWorkbenchCommandConstants.EDIT_CUT, selectionRange.y > 0, text, ST.CUT));
    menu.add(new StyledTextAction(IWorkbenchCommandConstants.EDIT_SELECT_ALL, true, text, ST.SELECT_ALL));
    menu.add(new StyledTextActionEx(ITextEditorActionDefinitionIds.WORD_WRAP, Action.AS_CHECK_BOX) {

        @Override
        public boolean isChecked() {
            return text.getWordWrap();
        }

        @Override
        public void run() {
            text.setWordWrap(!text.getWordWrap());
        }
    });
    IFindReplaceTarget stFindReplaceTarget = new StyledTextFindReplaceTarget(text);
    menu.add(TextEditorUtils.createFindReplaceAction(text.getShell(), stFindReplaceTarget));
    menu.add(new GroupMarker("styled_text_additions"));
}
Also used : GroupMarker(org.eclipse.jface.action.GroupMarker) Point(org.eclipse.swt.graphics.Point) IFindReplaceTarget(org.eclipse.jface.text.IFindReplaceTarget)

Aggregations

IFindReplaceTarget (org.eclipse.jface.text.IFindReplaceTarget)10 IAdaptable (org.eclipse.core.runtime.IAdaptable)2 GroupMarker (org.eclipse.jface.action.GroupMarker)2 IFindReplaceTargetExtension (org.eclipse.jface.text.IFindReplaceTargetExtension)2 Point (org.eclipse.swt.graphics.Point)2 VerticalButton (org.jkiss.dbeaver.ui.controls.VerticalButton)2 AutoRefreshControl (org.jkiss.dbeaver.ui.controls.autorefresh.AutoRefreshControl)2 ResultSetPanelDescriptor (org.jkiss.dbeaver.ui.controls.resultset.panel.ResultSetPanelDescriptor)2 StatisticsPresentation (org.jkiss.dbeaver.ui.controls.resultset.view.StatisticsPresentation)2 IStatusLineManager (org.eclipse.jface.action.IStatusLineManager)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 IMarkRegionTarget (org.eclipse.jface.text.IMarkRegionTarget)1 ITextViewer (org.eclipse.jface.text.ITextViewer)1 ITextViewerExtension (org.eclipse.jface.text.ITextViewerExtension)1 TextViewer (org.eclipse.jface.text.TextViewer)1 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)1 SWT (org.eclipse.swt.SWT)1 ST (org.eclipse.swt.custom.ST)1 StyledText (org.eclipse.swt.custom.StyledText)1 Color (org.eclipse.swt.graphics.Color)1