提交 2834944a 编写于 作者: S serge-rider

#3507 Grouping panel. Panels API refactoring


Former-commit-id: 1e30644f
上级 8e1ae56b
......@@ -627,9 +627,14 @@ handler.socks_proxy.label = SOCKS Proxy
presentation.spreadsheet.label = Grid
presentation.plaintext.label = Text
panel.value-view.label = Value viewer
panel.column-aggregate.label = Aggregate columns
panel.value-view.label = Value
panel.value-view.description = Results cell value viewer
panel.column-aggregate.label = Aggregate
panel.column-aggregate.description = Results aggregate functions (SUM, MAX, AVG, etc)
panel.results-metadata.label = Metadata
panel.results-metadata.description = ResultSet metadata description
panel.results-grouping.label = Grouping
panel.results-grouping.description = Results grouping (GROUP BY)
search.result.view.page.metadata.result.name = Database Metadata Search Result
......
......@@ -120,8 +120,8 @@
properties="active,hasData,hasMoreData,canCopy,canPaste,canCut,canMove,editable,changed,canToggle,canSwitchPresentation,canNavigateLink,canNavigateHistory,supportsCount"
type="org.eclipse.ui.IWorkbenchPart"/>
<propertyTester
class="org.jkiss.dbeaver.ui.controls.resultset.panel.ValueViewPropertyTester"
id="org.jkiss.dbeaver.ui.controls.resultset.panel.ValueViewPropertyTester"
class="org.jkiss.dbeaver.ui.controls.resultset.panel.valueviewer.ValueViewPropertyTester"
id="org.jkiss.dbeaver.ui.controls.resultset.panel.valueviewer.ValueViewPropertyTester"
namespace="org.jkiss.dbeaver.core.resultset.panel.valueView"
properties="active"
type="org.eclipse.ui.IWorkbenchPart"/>
......@@ -1555,7 +1555,7 @@
</enabledWhen>
</handler>
<handler commandId="org.jkiss.dbeaver.core.resultset.cell.save" class="org.jkiss.dbeaver.ui.controls.resultset.panel.ValueViewCommandHandler">
<handler commandId="org.jkiss.dbeaver.core.resultset.cell.save" class="org.jkiss.dbeaver.ui.controls.resultset.panel.valueviewer.ValueViewCommandHandler">
<activeWhen>
<with variable="activePart">
<test property="org.jkiss.dbeaver.core.resultset.panel.valueView.active"/>
......@@ -3708,28 +3708,36 @@
<panel
id="value-view"
label="%panel.value-view.label"
description="%resultset.panel.valueview.description"
description="%panel.value-view.description"
icon="platform:/plugin/org.jkiss.dbeaver.ui/icons/sql/panel_value.png"
default="true"
class="org.jkiss.dbeaver.ui.controls.resultset.panel.ViewValuePanel">
class="org.jkiss.dbeaver.ui.controls.resultset.panel.valueviewer.ValueViewerPanel">
<supports type="columns"/>
</panel>
<panel
id="column-aggregate"
label="%panel.column-aggregate.label"
description="%resultset.panel.columnsaggregate.description"
description="%panel.column-aggregate.description"
icon="platform:/plugin/org.jkiss.dbeaver.ui/icons/sql/panel_aggregate.png"
default="false"
class="org.jkiss.dbeaver.ui.controls.resultset.panel.AggregateColumnsPanel">
class="org.jkiss.dbeaver.ui.controls.resultset.panel.aggregate.AggregateColumnsPanel">
<supports type="columns"/>
</panel>
<panel
id="results-metadata"
label="%panel.results-metadata.label"
description="%resultset.panel.metadata.description"
description="%panel.results-metadata.description"
icon="platform:/plugin/org.jkiss.dbeaver.ui/icons/sql/panel_metadata.png"
default="false"
class="org.jkiss.dbeaver.ui.controls.resultset.panel.MetaDataPanel">
class="org.jkiss.dbeaver.ui.controls.resultset.panel.metadata.MetaDataPanel">
</panel>
<panel
id="results-grouping"
label="%panel.results-grouping.label"
description="%panel.results-grouping.description"
icon="platform:/plugin/org.jkiss.dbeaver.ui/icons/sql/panel_grouping.png"
default="false"
class="org.jkiss.dbeaver.ui.controls.resultset.panel.grouping.GroupingPanel">
</panel>
</extension>
......
......@@ -28,12 +28,6 @@ import org.jkiss.dbeaver.model.DBPImage;
*/
public interface IResultSetPanel {
String getPanelTitle();
DBPImage getPanelImage();
String getPanelDescription();
Control createContents(IResultSetPresentation presentation, Composite parent);
void activatePanel();
......
......@@ -24,7 +24,6 @@ import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.exec.DBCResultSet;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
......@@ -58,12 +57,7 @@ public class ResultSetPresentationRegistry {
presentations.add(descriptor);
}
}
Collections.sort(presentations, new Comparator<ResultSetPresentationDescriptor>() {
@Override
public int compare(ResultSetPresentationDescriptor o1, ResultSetPresentationDescriptor o2) {
return o1.getOrder() - o2.getOrder();
}
});
presentations.sort(Comparator.comparingInt(ResultSetPresentationDescriptor::getOrder));
// Load panel descriptors
IConfigurationElement[] panelElements = registry.getConfigurationElementsFor(ResultSetPanelDescriptor.EXTENSION_ID);
......@@ -117,12 +111,7 @@ public class ResultSetPresentationRegistry {
result.add(panel);
}
}
Collections.sort(result, new Comparator<ResultSetPanelDescriptor>() {
@Override
public int compare(ResultSetPanelDescriptor o1, ResultSetPanelDescriptor o2) {
return o1.getLabel().compareTo(o2.getLabel());
}
});
result.sort(Comparator.comparing(ResultSetPanelDescriptor::getLabel));
return result;
}
......
......@@ -741,9 +741,9 @@ public class ResultSetViewer extends Viewer
boolean firstPanel = panelFolder.getItemCount() == 0;
CTabItem panelTab = new CTabItem(panelFolder, SWT.CLOSE);
panelTab.setData(id);
panelTab.setText(panel.getPanelTitle());
panelTab.setText(panelDescriptor.getLabel());
panelTab.setImage(DBeaverIcons.getImage(panelDescriptor.getIcon()));
panelTab.setToolTipText(panel.getPanelDescription());
panelTab.setToolTipText(panelDescriptor.getDescription());
panelTab.setControl(panelControl);
if (setActive || firstPanel) {
......@@ -861,6 +861,11 @@ public class ResultSetViewer extends Viewer
for (final ResultSetPanelDescriptor panel : availablePanels) {
Action panelAction = new Action(panel.getLabel(), Action.AS_CHECK_BOX) {
{
setToolTipText(panel.getDescription());
// Icons turns menu into mess - checkboxes are much better
//setImageDescriptor(DBeaverIcons.getImageDescriptor(panel.getIcon()));
}
@Override
public boolean isChecked() {
return activePanels.containsKey(panel.getId());
......@@ -879,7 +884,6 @@ public class ResultSetViewer extends Viewer
}
}
};
//panelAction.setImageDescriptor(DBeaverIcons.getImageDescriptor(panel.getIcon()));
items.add(new ActionContributionItem(panelAction));
}
return items;
......
......@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ui.controls.resultset.panel;
package org.jkiss.dbeaver.ui.controls.resultset.panel.aggregate;
import org.eclipse.jface.action.*;
import org.eclipse.jface.dialogs.IDialogSettings;
......@@ -72,21 +72,6 @@ public class AggregateColumnsPanel implements IResultSetPanel {
public AggregateColumnsPanel() {
}
@Override
public String getPanelTitle() {
return "Aggregate";
}
@Override
public DBPImage getPanelImage() {
return UIIcon.PANEL_AGGREGATE;
}
@Override
public String getPanelDescription() {
return "Aggregate columns";
}
@Override
public Control createContents(final IResultSetPresentation presentation, Composite parent) {
this.presentation = presentation;
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org)
*
* 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.controls.resultset.panel.grouping;
import org.eclipse.jface.action.*;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.swt.widgets.*;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.controls.resultset.*;
/**
* RSV grouping panel
*/
public class GroupingPanel implements IResultSetPanel {
private static final Log log = Log.getLog(GroupingPanel.class);
public static final String PANEL_ID = "results-grouping";
public static final String SETTINGS_SECTION_GROUPING = "panel-" + PANEL_ID;
private IResultSetPresentation presentation;
private IDialogSettings panelSettings;
public GroupingPanel() {
}
@Override
public Control createContents(final IResultSetPresentation presentation, Composite parent) {
this.presentation = presentation;
this.panelSettings = ResultSetUtils.getViewerSettings(SETTINGS_SECTION_GROUPING);
Composite composite = UIUtils.createPlaceholder(parent, 1);
loadSettings();
if (this.presentation instanceof ISelectionProvider) {
((ISelectionProvider) this.presentation).addSelectionChangedListener(event -> {
if (presentation.getController().getVisiblePanel() == GroupingPanel.this) {
refresh(false);
}
});
}
/*
MenuManager menuMgr = new MenuManager();
menuMgr.addMenuListener(manager -> {
manager.add(new CopyAction());
manager.add(new CopyAllAction());
manager.add(new Separator());
fillToolBar(manager);
});
menuMgr.setRemoveAllWhenShown(true);
this.aggregateTable.setMenu(menuMgr.createContextMenu(this.aggregateTable));
*/
return composite;
}
private void loadSettings() {
/*
IDialogSettings functionsSection = panelSettings.getSection("functions");
if (functionsSection != null) {
final Map<AggregateFunctionDescriptor, Integer> funcIndexes = new HashMap<>();
for (IDialogSettings funcSection : functionsSection.getSections()) {
String funcId = funcSection.getName();
if (!funcSection.getBoolean("enabled")) {
continue;
}
AggregateFunctionDescriptor func = FunctionsRegistry.getInstance().getFunction(funcId);
if (func == null) {
log.debug("Function '" + funcId + "' not found");
} else {
funcIndexes.put(func, funcSection.getInt("index"));
enabledFunctions.add(func);
}
}
enabledFunctions.sort(Comparator.comparingInt(funcIndexes::get));
}
if (enabledFunctions.isEmpty()) {
loadDefaultFunctions();
}
*/
}
private void saveSettings() {
IDialogSettings functionsSection = UIUtils.getSettingsSection(panelSettings, "functions");
/*
for (AggregateFunctionDescriptor func : FunctionsRegistry.getInstance().getFunctions()) {
IDialogSettings funcSection = UIUtils.getSettingsSection(functionsSection, func.getId());
boolean enabled = enabledFunctions.contains(func);
funcSection.put("enabled", enabled);
if (enabled) {
funcSection.put("index", enabledFunctions.indexOf(func));
} else {
funcSection.put("index", -1);
}
}
*/
}
@Override
public void activatePanel() {
refresh(false);
}
@Override
public void deactivatePanel() {
}
@Override
public void refresh(boolean force) {
/*
aggregateTable.setRedraw(false);
try {
aggregateTable.removeAll();
if (this.presentation instanceof ISelectionProvider) {
ISelection selection = ((ISelectionProvider) presentation).getSelection();
if (selection instanceof IResultSetSelection) {
aggregateSelection((IResultSetSelection)selection);
}
}
UIUtils.packColumns(aggregateTable, true, null);
} finally {
aggregateTable.setRedraw(true);
}
*/
saveSettings();
}
@Override
public void contributeActions(ToolBarManager manager) {
fillToolBar(manager);
}
private void fillToolBar(IContributionManager contributionManager)
{
/*
contributionManager.add(new AddFunctionAction());
contributionManager.add(new RemoveFunctionAction());
contributionManager.add(new ResetFunctionsAction());
contributionManager.add(new Separator());
contributionManager.add(new GroupByColumnsAction());
*/
}
}
......@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ui.controls.resultset.panel;
package org.jkiss.dbeaver.ui.controls.resultset.panel.metadata;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IContributionManager;
......@@ -35,7 +35,6 @@ import org.jkiss.dbeaver.model.exec.DBCExecutionContext;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.load.DatabaseLoadService;
import org.jkiss.dbeaver.ui.LoadingJob;
import org.jkiss.dbeaver.ui.UIIcon;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.controls.TreeContentProvider;
import org.jkiss.dbeaver.ui.controls.itemlist.DatabaseObjectListControl;
......@@ -64,21 +63,6 @@ public class MetaDataPanel implements IResultSetPanel {
public MetaDataPanel() {
}
@Override
public String getPanelTitle() {
return "MetaData";
}
@Override
public DBPImage getPanelImage() {
return UIIcon.PANEL_METADATA;
}
@Override
public String getPanelDescription() {
return "Resultset metadata";
}
@Override
public Control createContents(final IResultSetPresentation presentation, Composite parent) {
this.presentation = presentation;
......
......@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ui.controls.resultset.panel;
package org.jkiss.dbeaver.ui.controls.resultset.panel.valueviewer;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
......@@ -43,12 +43,12 @@ public class ValueViewCommandHandler extends AbstractHandler {
}
String actionId = event.getCommand().getId();
IResultSetPanel visiblePanel = rsv.getVisiblePanel();
if (visiblePanel instanceof ViewValuePanel) {
if (visiblePanel instanceof ValueViewerPanel) {
switch (actionId) {
case ITextEditorActionDefinitionIds.SMART_ENTER:
case CoreCommands.CMD_EXECUTE_STATEMENT:
case CMD_SAVE_VALUE:
((ViewValuePanel) visiblePanel).saveValue();
((ValueViewerPanel) visiblePanel).saveValue();
break;
}
}
......
......@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ui.controls.resultset.panel;
package org.jkiss.dbeaver.ui.controls.resultset.panel.valueviewer;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.ui.IWorkbenchPart;
......@@ -40,7 +40,7 @@ public class ValueViewPropertyTester extends PropertyTester
private boolean checkResultSetProperty(ResultSetViewer rsv, String property, Object expectedValue)
{
IResultSetPanel visiblePanel = rsv.getVisiblePanel();
if (visiblePanel instanceof ViewValuePanel) {
if (visiblePanel instanceof ValueViewerPanel) {
switch (property) {
case PROP_ACTIVE:
return true;
......
......@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ui.controls.resultset.panel;
package org.jkiss.dbeaver.ui.controls.resultset.panel.valueviewer;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.action.Action;
......@@ -37,7 +37,6 @@ import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.DBeaverPreferences;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.model.DBPImage;
import org.jkiss.dbeaver.model.data.DBDAttributeBinding;
import org.jkiss.dbeaver.model.data.DBDValue;
import org.jkiss.dbeaver.runtime.ui.DBUserInterface;
......@@ -56,9 +55,9 @@ import org.jkiss.utils.CommonUtils;
/**
* RSV value view panel
*/
public class ViewValuePanel implements IResultSetPanel, IAdaptable {
public class ValueViewerPanel implements IResultSetPanel, IAdaptable {
private static final Log log = Log.getLog(ViewValuePanel.class);
private static final Log log = Log.getLog(ValueViewerPanel.class);
public static final String PANEL_ID = "value-view";
public static final String SETTINGS_SECTION = "panel-" + PANEL_ID;
......@@ -79,22 +78,7 @@ public class ViewValuePanel implements IResultSetPanel, IAdaptable {
return ResultSetUtils.getViewerSettings(SETTINGS_SECTION);
}
public ViewValuePanel() {
}
@Override
public String getPanelTitle() {
return "Value";
}
@Override
public DBPImage getPanelImage() {
return UIIcon.PANEL_VALUE;
}
@Override
public String getPanelDescription() {
return "Value view/edit";
public ValueViewerPanel() {
}
@Override
......@@ -107,7 +91,7 @@ public class ViewValuePanel implements IResultSetPanel, IAdaptable {
if (viewPlaceholder.getChildren().length == 0) {
String hidePanelCmd = ActionUtils.findCommandDescription(
ResultSetCommandHandler.CMD_TOGGLE_PANELS,
ViewValuePanel.this.presentation.getController().getSite(),
ValueViewerPanel.this.presentation.getController().getSite(),
true);
UIUtils.drawMessageOverControl(viewPlaceholder, e, "Select a cell to view/edit value", 0);
......@@ -130,7 +114,7 @@ public class ViewValuePanel implements IResultSetPanel, IAdaptable {
if (this.presentation instanceof ISelectionProvider) {
final ISelectionProvider selectionProvider = (ISelectionProvider) this.presentation;
final ISelectionChangedListener selectionListener = event -> {
if (ViewValuePanel.this.presentation.getController().getVisiblePanel() == ViewValuePanel.this) {
if (ValueViewerPanel.this.presentation.getController().getVisiblePanel() == ValueViewerPanel.this) {
refreshValue(false);
}
};
......
......@@ -87,7 +87,7 @@ import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.controls.PropertyPageStandard;
import org.jkiss.dbeaver.ui.controls.lightgrid.*;
import org.jkiss.dbeaver.ui.controls.resultset.*;
import org.jkiss.dbeaver.ui.controls.resultset.panel.ViewValuePanel;
import org.jkiss.dbeaver.ui.controls.resultset.panel.valueviewer.ValueViewerPanel;
import org.jkiss.dbeaver.ui.data.IMultiController;
import org.jkiss.dbeaver.ui.data.IValueController;
import org.jkiss.dbeaver.ui.data.IValueEditor;
......@@ -914,7 +914,7 @@ public class SpreadsheetPresentation extends AbstractPresentation implements IRe
if (ArrayUtils.contains(supportedEditTypes, IValueController.EditType.PANEL)) {
// Inline editor isn't supported but panel viewer is
// Enable panel
controller.activatePanel(ViewValuePanel.PANEL_ID, true, true);
controller.activatePanel(ValueViewerPanel.PANEL_ID, true, true);
return null;
}
}
......
......@@ -25,7 +25,7 @@ import org.eclipse.swt.custom.StyledText;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.exec.DBCException;
import org.jkiss.dbeaver.ui.controls.resultset.panel.ViewValuePanel;
import org.jkiss.dbeaver.ui.controls.resultset.panel.valueviewer.ValueViewerPanel;
import org.jkiss.dbeaver.ui.data.IStreamValueEditor;
import org.jkiss.dbeaver.ui.data.IValueController;
import org.jkiss.dbeaver.ui.editors.text.BaseTextEditor;
......@@ -58,7 +58,7 @@ public abstract class AbstractTextPanelEditor implements IStreamValueEditor<Styl
boolean newWW = !editorControl.getWordWrap();
setChecked(newWW);
editorControl.setWordWrap(newWW);
ViewValuePanel.getPanelSettings().put(PREF_TEXT_EDITOR_WORD_WRAP, newWW);
ValueViewerPanel.getPanelSettings().put(PREF_TEXT_EDITOR_WORD_WRAP, newWW);
}
};
wwAction.setChecked(editorControl.getWordWrap());
......@@ -70,13 +70,13 @@ public abstract class AbstractTextPanelEditor implements IStreamValueEditor<Styl
final Action afAction = new Action("Auto Format", Action.AS_CHECK_BOX) {
@Override
public void run() {
boolean newAF = !ViewValuePanel.getPanelSettings().getBoolean(PREF_TEXT_EDITOR_AUTO_FORMAT);
boolean newAF = !ValueViewerPanel.getPanelSettings().getBoolean(PREF_TEXT_EDITOR_AUTO_FORMAT);
setChecked(newAF);
ViewValuePanel.getPanelSettings().put(PREF_TEXT_EDITOR_AUTO_FORMAT, newAF);
ValueViewerPanel.getPanelSettings().put(PREF_TEXT_EDITOR_AUTO_FORMAT, newAF);
applyEditorStyle();
}
};
afAction.setChecked(ViewValuePanel.getPanelSettings().getBoolean(PREF_TEXT_EDITOR_AUTO_FORMAT));
afAction.setChecked(ValueViewerPanel.getPanelSettings().getBoolean(PREF_TEXT_EDITOR_AUTO_FORMAT));
manager.add(afAction);
}
}
......@@ -86,7 +86,7 @@ public abstract class AbstractTextPanelEditor implements IStreamValueEditor<Styl
}
protected void initEditorSettings(StyledText control) {
boolean wwEnabled = ViewValuePanel.getPanelSettings().getBoolean(PREF_TEXT_EDITOR_WORD_WRAP);
boolean wwEnabled = ValueViewerPanel.getPanelSettings().getBoolean(PREF_TEXT_EDITOR_WORD_WRAP);
if (wwEnabled != control.getWordWrap()) {
control.setWordWrap(wwEnabled);
}
......@@ -94,7 +94,7 @@ public abstract class AbstractTextPanelEditor implements IStreamValueEditor<Styl
protected void applyEditorStyle() {
BaseTextEditor textEditor = getTextEditor();
if (textEditor != null && ViewValuePanel.getPanelSettings().getBoolean(PREF_TEXT_EDITOR_AUTO_FORMAT)) {
if (textEditor != null && ValueViewerPanel.getPanelSettings().getBoolean(PREF_TEXT_EDITOR_AUTO_FORMAT)) {
try {
textEditor.getViewer().doOperation(ISourceViewer.FORMAT);
} catch (Exception e) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册