From d37b3795298ee97ceacd8f2a99f5cf8c6695702c Mon Sep 17 00:00:00 2001 From: Serge Rider Date: Thu, 1 Jul 2021 17:12:38 +0300 Subject: [PATCH] #11533 Extra panels layout (menu and toolbar) --- .../OSGI-INF/l10n/bundle.properties | 3 + .../plugin.xml | 34 ++++- .../dbeaver/ui/editors/sql/SQLEditor.java | 135 ++++++++++++++---- .../sql/SQLEditorOutputConsoleViewer.java | 4 + .../editors/sql/SQLPreferenceConstants.java | 4 + .../SQLEditorHandlerToggleExtraPanels.java | 52 +++++++ 6 files changed, 205 insertions(+), 27 deletions(-) create mode 100644 plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/handlers/SQLEditorHandlerToggleExtraPanels.java diff --git a/plugins/org.jkiss.dbeaver.ui.editors.sql/OSGI-INF/l10n/bundle.properties b/plugins/org.jkiss.dbeaver.ui.editors.sql/OSGI-INF/l10n/bundle.properties index c8dde07173..2e69ffc2d9 100644 --- a/plugins/org.jkiss.dbeaver.ui.editors.sql/OSGI-INF/l10n/bundle.properties +++ b/plugins/org.jkiss.dbeaver.ui.editors.sql/OSGI-INF/l10n/bundle.properties @@ -95,6 +95,8 @@ command.org.jkiss.dbeaver.ui.editors.sql.show.log.name=Show execution log command.org.jkiss.dbeaver.ui.editors.sql.show.log.description=Show SQL execution log command.org.jkiss.dbeaver.ui.editors.sql.show.variables.name=Show SQL variables command.org.jkiss.dbeaver.ui.editors.sql.show.variables.description=Show active SQL variables +command.org.jkiss.dbeaver.ui.editors.sql.toggle.extraPanel.name=Show panels in result tabs +command.org.jkiss.dbeaver.ui.editors.sql.toggle.extraPanel.description=Show panels in result tabs instead of SQL editor pane command.org.jkiss.dbeaver.ui.editors.sql.toggle.result.panel.name=Toggle results panel command.org.jkiss.dbeaver.ui.editors.sql.toggle.result.panel.description=Show/hide results panel @@ -143,6 +145,7 @@ menu.sqleditor=&SQL Editor menu.org.jkiss.dbeaver.ui.editors.sql.SQLEditor.execute.label = Execute menu.org.jkiss.dbeaver.ui.editors.sql.SQLEditor.file.label = File menu.org.jkiss.dbeaver.ui.editors.sql.SQLEditor.layout.label = Layout +menu.org.jkiss.dbeaver.ui.editors.sql.SQLEditor.extraPanels.label = Panels themeElementCategory.org.jkiss.dbeaver.ui.presentation.sql.label = SQL Editor themeElementCategory.org.jkiss.dbeaver.ui.presentation.sql.description = SQL Editor diff --git a/plugins/org.jkiss.dbeaver.ui.editors.sql/plugin.xml b/plugins/org.jkiss.dbeaver.ui.editors.sql/plugin.xml index b098cde065..875736ff59 100644 --- a/plugins/org.jkiss.dbeaver.ui.editors.sql/plugin.xml +++ b/plugins/org.jkiss.dbeaver.ui.editors.sql/plugin.xml @@ -234,9 +234,12 @@ + + + @@ -462,6 +465,10 @@ + + + + @@ -837,11 +844,23 @@ + - - - + + + + + + + + + + + + + + @@ -896,6 +915,15 @@ + + + + + + + + + diff --git a/plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/SQLEditor.java b/plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/SQLEditor.java index 64916d5ead..0ceadfbdb1 100644 --- a/plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/SQLEditor.java +++ b/plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/SQLEditor.java @@ -43,6 +43,7 @@ import org.eclipse.swt.widgets.*; import org.eclipse.ui.*; import org.eclipse.ui.actions.CompoundContributionItem; import org.eclipse.ui.ide.FileStoreEditorInput; +import org.eclipse.ui.menus.CommandContributionItem; import org.eclipse.ui.texteditor.DefaultRangeIndicator; import org.eclipse.ui.texteditor.ITextEditorActionConstants; import org.eclipse.ui.texteditor.rulers.IColumnSupport; @@ -1084,10 +1085,7 @@ public class SQLEditor extends SQLEditorBase implements }); // Extra views - //planView = new ExplainPlanViewer(this, resultTabs); - logViewer = new SQLLogPanel(sqlExtraPanelFolder, this); - variablesViewer = new SQLVariablesPanel(sqlExtraPanelFolder, this); - outputViewer = new SQLEditorOutputConsoleViewer(getSite(), sqlExtraPanelFolder, SWT.NONE); + createExtraViewControls(); // Create results tab createQueryProcessor(true, true); @@ -1272,24 +1270,110 @@ public class SQLEditor extends SQLEditorBase implements ///////////////////////////////////////////////////////////// // Panels + public void toggleExtraPanelsLayout() { + CTabItem outTab = getExtraViewTab(outputViewer.getControl()); + CTabItem logTab = getExtraViewTab(logViewer); + CTabItem varTab = getExtraViewTab(variablesViewer); + if (outTab != null) outTab.dispose(); + if (logTab != null) logTab.dispose(); + if (varTab != null) varTab.dispose(); + + IPreferenceStore preferenceStore = getPreferenceStore(); + String epLocation = getExtraPanelsLocation(); + if (SQLPreferenceConstants.LOCATION_RESULTS.equals(epLocation)) { + epLocation = SQLPreferenceConstants.LOCATION_RIGHT; + } else { + epLocation = SQLPreferenceConstants.LOCATION_RESULTS; + } + preferenceStore.setValue(SQLPreferenceConstants.EXTRA_PANEL_LOCATION, epLocation); + + createExtraViewControls(); + + if (outTab != null) showOutputPanel(); + if (logTab != null) showExecutionLogPanel(); + if (varTab != null) showVariablesPanel(); + } + + public String getExtraPanelsLocation() { + return getPreferenceStore().getString(SQLPreferenceConstants.EXTRA_PANEL_LOCATION); + } + + private void createExtraViewControls() { + if (logViewer != null) { + logViewer.dispose(); + logViewer = null; + } + if (variablesViewer != null) { + variablesViewer.dispose(); + variablesViewer = null; + } + if (outputViewer != null) { + outputViewer.dispose(); + outputViewer = null; + } + if (sqlExtraPanelFolder != null) { + for (CTabItem ti : sqlExtraPanelFolder.getItems()) { + ti.dispose(); + } + } + + //planView = new ExplainPlanViewer(this, resultTabs); + CTabFolder folder = getFolderForExtraPanels(); + + logViewer = new SQLLogPanel(folder, this); + variablesViewer = new SQLVariablesPanel(folder, this); + outputViewer = new SQLEditorOutputConsoleViewer(getSite(), folder, SWT.NONE); + + if (getFolderForExtraPanels() != sqlExtraPanelFolder) { + sqlExtraPanelSash.setMaximizedControl(sqlExtraPanelSash.getChildren()[0]); + } + } + + private CTabFolder getFolderForExtraPanels() { + CTabFolder folder = this.sqlExtraPanelFolder; + String epLocation = getExtraPanelsLocation(); + if (SQLPreferenceConstants.LOCATION_RESULTS.equals(epLocation)) { + folder = resultTabs; + } + return folder; + } + + private CTabItem getExtraViewTab(Control control) { + CTabFolder tabFolder = this.getFolderForExtraPanels(); + for (CTabItem item : tabFolder.getItems()) { + if (item.getData() == control) { + return item; + } + } + return null; + } + private void showExtraView(final String commandId, String name, String toolTip, Image image, Control view, IActionContributor actionContributor) { VerticalButton viewItem = getViewToolItem(commandId); if (viewItem == null) { log.warn("Tool item for command " + commandId + " not found"); return; } - for (CTabItem item : sqlExtraPanelFolder.getItems()) { - if (item.getData() == view) { - // Close tab if it is already open - viewItem.setChecked(false); - viewItem.redraw(); - item.dispose(); - return; - } + CTabFolder tabFolder = this.getFolderForExtraPanels(); + CTabItem curItem = getExtraViewTab(view); + if (curItem != null) { + // Close tab if it is already open + viewItem.setChecked(false); + viewItem.redraw(); + curItem.dispose(); + return; } - if (sqlExtraPanelSash.getMaximizedControl() != null) { - sqlExtraPanelSash.setMaximizedControl(null); + boolean isTabsToTheRight = tabFolder == sqlExtraPanelFolder; + + if (isTabsToTheRight) { + if (sqlExtraPanelSash.getMaximizedControl() != null) { + sqlExtraPanelSash.setMaximizedControl(null); + } + } else { + sqlExtraPanelSash.setMaximizedControl(sqlExtraPanelSash.getChildren()[0]); + // Show results + showResultsPanel(); } if (view == outputViewer.getControl()) { @@ -1299,7 +1383,7 @@ public class SQLEditor extends SQLEditorBase implements // Create new tab viewItem.setChecked(true); - CTabItem item = new CTabItem(sqlExtraPanelFolder, SWT.CLOSE); + CTabItem item = new CTabItem(tabFolder, SWT.CLOSE); item.setControl(view); item.setText(name); item.setToolTipText(toolTip); @@ -1312,14 +1396,16 @@ public class SQLEditor extends SQLEditorBase implements viewItem.setChecked(false); viewItem.redraw(); } - if (sqlExtraPanelFolder.getItemCount() == 0) { + if (tabFolder.getItemCount() == 0) { sqlExtraPanelSash.setMaximizedControl(sqlExtraPanelSash.getChildren()[0]); } }); - sqlExtraPanelFolder.setSelection(item); + tabFolder.setSelection(item); viewItem.redraw(); - updateExtraViewToolbar(actionContributor); + if (isTabsToTheRight) { + updateExtraViewToolbar(actionContributor); + } } private void updateExtraViewToolbar(IActionContributor actionContributor) { @@ -1328,6 +1414,11 @@ public class SQLEditor extends SQLEditorBase implements if (actionContributor != null) { actionContributor.contributeActions(sqlExtraPanelToolbar); } + sqlExtraPanelToolbar.add(ActionUtils.makeCommandContribution( + getSite(), + "org.jkiss.dbeaver.ui.editors.sql.toggle.extraPanels", + CommandContributionItem.STYLE_CHECK, + UIIcon.ARROW_DOWN)); sqlExtraPanelToolbar.update(true); } @@ -1362,9 +1453,7 @@ public class SQLEditor extends SQLEditorBase implements SQLEditorMessages.editors_sql_output_tip, IMG_OUTPUT, outputViewer.getControl(), - manager -> { - manager.add(new OutputAutoShowToggleAction()); - }); + manager -> manager.add(new OutputAutoShowToggleAction())); } public void showExecutionLogPanel() { @@ -1385,9 +1474,7 @@ public class SQLEditor extends SQLEditorBase implements IMG_VARIABLES, variablesViewer, null); - UIUtils.asyncExec(() -> { - variablesViewer.refreshVariables(); - }); + UIUtils.asyncExec(() -> variablesViewer.refreshVariables()); } public T getExtraPresentationPanel(Class panelClass) { diff --git a/plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/SQLEditorOutputConsoleViewer.java b/plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/SQLEditorOutputConsoleViewer.java index 271c012c26..96fd2e1255 100644 --- a/plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/SQLEditorOutputConsoleViewer.java +++ b/plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/SQLEditorOutputConsoleViewer.java @@ -82,6 +82,10 @@ public class SQLEditorOutputConsoleViewer extends TextConsoleViewer { writer = new PrintWriter(out, true); } + public void dispose() { + this.getControl().dispose(); + } + public boolean isDisposed() { return this.getControl().isDisposed(); } diff --git a/plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/SQLPreferenceConstants.java b/plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/SQLPreferenceConstants.java index e3564ee6c1..bbddadbabc 100644 --- a/plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/SQLPreferenceConstants.java +++ b/plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/SQLPreferenceConstants.java @@ -116,6 +116,7 @@ public class SQLPreferenceConstants public final static String RESULT_SET_ORIENTATION = "SQLEditor.resultSet.orientation"; public static final String RESULTS_PANEL_RATIO = "SQLEditor.resultSet.ratio"; public static final String EXTRA_PANEL_RATIO = "SQLEditor.extraPanels.ratio"; + public static final String EXTRA_PANEL_LOCATION = "SQLEditor.extraPanels.location"; public static final String OUTPUT_PANEL_AUTO_SHOW = "SQLEditor.outputPanel.autoShow"; public static final String SCRIPT_BIND_EMBEDDED_READ = "SQLEditor.script.bind.embedded.read"; //$NON-NLS-1$ @@ -144,5 +145,8 @@ public class SQLPreferenceConstants public static final String DEFAULT_SQL_EDITOR_OPEN_COMMAND = "SQLEditor.defaultOpenCommand"; + public static final String LOCATION_RIGHT = "right"; + public static final String LOCATION_BOTTOM = "bottom"; + public static final String LOCATION_RESULTS = "results"; } diff --git a/plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/handlers/SQLEditorHandlerToggleExtraPanels.java b/plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/handlers/SQLEditorHandlerToggleExtraPanels.java new file mode 100644 index 0000000000..e749d5bd17 --- /dev/null +++ b/plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/handlers/SQLEditorHandlerToggleExtraPanels.java @@ -0,0 +1,52 @@ +/* + * DBeaver - Universal Database Manager + * Copyright (C) 2010-2021 DBeaver Corp and others + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jkiss.dbeaver.ui.editors.sql.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.commands.IElementUpdater; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.menus.UIElement; +import org.jkiss.dbeaver.ui.editors.sql.SQLEditor; +import org.jkiss.dbeaver.ui.editors.sql.SQLPreferenceConstants; +import org.jkiss.dbeaver.utils.RuntimeUtils; + +import java.util.Map; + +public class SQLEditorHandlerToggleExtraPanels extends AbstractHandler implements IElementUpdater { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + SQLEditor editor = RuntimeUtils.getObjectAdapter(HandlerUtil.getActiveEditor(event), SQLEditor.class); + if (editor != null) { + editor.toggleExtraPanelsLayout(); + } + return null; + } + + @Override + public void updateElement(UIElement element, Map parameters) { + IWorkbenchWindow workbenchWindow = element.getServiceLocator().getService(IWorkbenchWindow.class); + IEditorPart activeEditor = workbenchWindow.getActivePage().getActiveEditor(); + if (activeEditor instanceof SQLEditor) { + element.setChecked(SQLPreferenceConstants.LOCATION_RESULTS.equals(((SQLEditor) activeEditor).getExtraPanelsLocation())); + } + } +} \ No newline at end of file -- GitLab