提交 5845caea 编写于 作者: S serge-rider

#3507 Grouping panel - configuration dialog


Former-commit-id: 51eeaf5b
上级 d7eddd36
......@@ -150,12 +150,9 @@ public class SQLQueryParameterBindDialog extends StatusDialog {
};
if (!parameters.isEmpty()) {
UIUtils.asyncExec(new Runnable() {
@Override
public void run() {
paramTable.select(0);
tableEditor.showEditor(paramTable.getItem(0), 2);
}
UIUtils.asyncExec(() -> {
paramTable.select(0);
tableEditor.showEditor(paramTable.getItem(0), 2);
});
}
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2018 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;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.*;
import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.model.DBPImage;
import org.jkiss.dbeaver.ui.DBeaverIcons;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.utils.CommonUtils;
import java.util.ArrayList;
import java.util.List;
/**
* Table with editable string rows
*/
public class StringEditorTable {
public static Table createEditableList(Composite parent, String name, List<String> values, DBPImage icon) {
Group group = UIUtils.createControlGroup(parent, name, 2, GridData.FILL_BOTH, 0);
final Table valueTable = new Table(group, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
final GridData gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 300;
gd.heightHint = 100;
valueTable.setLayoutData(gd);
// valueTable.setHeaderVisible(true);
valueTable.setLinesVisible(true);
final TableColumn valueColumn = UIUtils.createTableColumn(valueTable, SWT.LEFT, CoreMessages.dialog_filter_table_column_value);
valueTable.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
valueColumn.setWidth(valueTable.getClientArea().width);
}
});
fillFilterValues(valueTable, values, icon);
final CustomTableEditor tableEditor = new CustomTableEditor(valueTable) {
{
firstTraverseIndex = 0;
lastTraverseIndex = 0;
//editOnEnter = false;
}
@Override
protected Control createEditor(Table table, int index, TableItem item) {
Text editor = new Text(table, SWT.BORDER);
editor.setText(item.getText());
return editor;
}
@Override
protected void saveEditorValue(Control control, int index, TableItem item) {
item.setText(((Text) control).getText().trim());
}
};
Composite buttonsGroup = UIUtils.createPlaceholder(group, 1, 5);
buttonsGroup.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
final Button addButton = new Button(buttonsGroup, SWT.PUSH);
addButton.setText(CoreMessages.dialog_filter_button_add);
addButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
addButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
TableItem newItem = new TableItem(valueTable, SWT.LEFT);
if (icon != null) {
newItem.setImage(DBeaverIcons.getImage(icon));
}
valueTable.setSelection(newItem);
tableEditor.closeEditor();
tableEditor.showEditor(newItem);
}
});
final Button removeButton = new Button(buttonsGroup, SWT.PUSH);
removeButton.setText(CoreMessages.dialog_filter_button_remove);
removeButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
removeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int selectionIndex = valueTable.getSelectionIndex();
if (selectionIndex >= 0) {
tableEditor.closeEditor();
valueTable.remove(selectionIndex);
removeButton.setEnabled(valueTable.getSelectionIndex() >= 0);
}
}
});
removeButton.setEnabled(false);
final Button clearButton = new Button(buttonsGroup, SWT.PUSH);
clearButton.setText(CoreMessages.dialog_filter_button_clear);
clearButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
clearButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
tableEditor.closeEditor();
valueTable.removeAll();
removeButton.setEnabled(false);
}
});
valueTable.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int selectionIndex = valueTable.getSelectionIndex();
removeButton.setEnabled(selectionIndex >= 0);
}
});
return valueTable;
}
public static void fillFilterValues(Table valueTable, List<String> values, DBPImage icon) {
valueTable.removeAll();
if (!CommonUtils.isEmpty(values)) {
for (String value : values) {
TableItem tableItem = new TableItem(valueTable, SWT.LEFT);
tableItem.setText(value);
if (icon != null) {
tableItem.setImage(DBeaverIcons.getImage(icon));
}
}
}
}
public static List<String> collectValues(Table table) {
List<String> values = new ArrayList<>();
for (TableItem item : table.getItems()) {
String value = item.getText().trim();
if (value.isEmpty() || value.equals("%")) { //$NON-NLS-1$
continue;
}
values.add(value);
}
return values;
}
}
/*
* 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.dialogs.IDialogSettings;
import org.eclipse.swt.widgets.*;
import org.jkiss.dbeaver.model.DBIcon;
import org.jkiss.dbeaver.ui.UIIcon;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.controls.StringEditorTable;
import org.jkiss.dbeaver.ui.dialogs.BaseDialog;
import java.util.List;
/**
* Grouping configuration dialog
*/
class GroupingConfigDialog extends BaseDialog
{
private static final String DIALOG_ID = "DBeaver.GroupingConfigDialog";//$NON-NLS-1$
private final GroupingResultsContainer resultsContainer;
private Table columnsTable;
private Table functionsTable;
public GroupingConfigDialog(Shell parentShell, GroupingResultsContainer resultsContainer)
{
super(parentShell, "Grouping configuration", UIIcon.PANEL_AGGREGATE);
this.resultsContainer = resultsContainer;
}
@Override
protected IDialogSettings getDialogBoundsSettings()
{
return UIUtils.getDialogSettings(DIALOG_ID);
}
@Override
protected Composite createDialogArea(Composite parent)
{
Composite composite = super.createDialogArea(parent);
columnsTable = StringEditorTable.createEditableList(composite, "Columns", resultsContainer.getGroupAttributes(), DBIcon.TREE_ATTRIBUTE);
functionsTable = StringEditorTable.createEditableList(composite, "Functions", resultsContainer.getGroupFunctions(), DBIcon.TREE_FUNCTION);
return composite;
}
@Override
protected void okPressed() {
List<String> columns = StringEditorTable.collectValues(columnsTable);
List<String> functions = StringEditorTable.collectValues(functionsTable);
resultsContainer.setGrouping(columns, functions);
super.okPressed();
}
}
......@@ -20,6 +20,7 @@ import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IContributionManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.swt.widgets.Composite;
......@@ -155,7 +156,14 @@ public class GroupingPanel implements IResultSetPanel {
@Override
public void run() {
GroupingConfigDialog dialog = new GroupingConfigDialog(presentation.getControl().getShell(), resultsContainer);
if (dialog.open() == IDialogConstants.OK_ID) {
try {
resultsContainer.rebuildGrouping();
} catch (DBException e) {
DBUserInterface.getInstance().showError("Grouping error", "Can't change grouping settings", e);
}
}
}
}
......
......@@ -180,4 +180,11 @@ public class GroupingResultsContainer implements IResultSetContainer {
groupingViewer.refresh();
}
public void setGrouping(List<String> attributes, List<String> functions) {
groupAttributes.clear();
groupAttributes.addAll(attributes);
groupFunctions.clear();
groupFunctions.addAll(functions);
}
}
......@@ -28,7 +28,7 @@ import org.jkiss.dbeaver.model.app.DBPDataSourceRegistry;
import org.jkiss.dbeaver.model.struct.DBSObjectFilter;
import org.jkiss.dbeaver.ui.IHelpContextIds;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.controls.CustomTableEditor;
import org.jkiss.dbeaver.ui.controls.StringEditorTable;
import org.jkiss.dbeaver.ui.dialogs.HelpEnabledDialog;
import org.jkiss.utils.CommonUtils;
......@@ -99,8 +99,8 @@ public class EditObjectFilterDialog extends HelpEnabledDialog {
blockControl = UIUtils.createPlaceholder(composite, 1);
blockControl.setLayoutData(new GridData(GridData.FILL_BOTH));
includeTable = createEditableList(CoreMessages.dialog_filter_list_include, filter.getInclude());
excludeTable = createEditableList(CoreMessages.dialog_filter_list_exclude, filter.getExclude());
includeTable = StringEditorTable.createEditableList(blockControl, CoreMessages.dialog_filter_list_include, filter.getInclude(), null);
excludeTable = StringEditorTable.createEditableList(blockControl, CoreMessages.dialog_filter_list_exclude, filter.getExclude(), null);
UIUtils.createInfoLabel(blockControl, CoreMessages.dialog_connection_edit_wizard_general_filter_hint_text);
......@@ -155,110 +155,19 @@ public class EditObjectFilterDialog extends HelpEnabledDialog {
}
if (CommonUtils.isEmpty(filterName)) {
// Reset filter
fillFilterValues(includeTable, null);
fillFilterValues(excludeTable, null);
StringEditorTable.fillFilterValues(includeTable, null, null);
StringEditorTable.fillFilterValues(excludeTable, null, null);
} else {
// Find saved filter
DBSObjectFilter savedFilter = dsRegistry.getSavedFilter(filterName);
if (savedFilter != null) {
fillFilterValues(includeTable, savedFilter.getInclude());
fillFilterValues(excludeTable, savedFilter.getExclude());
StringEditorTable.fillFilterValues(includeTable, savedFilter.getInclude(), null);
StringEditorTable.fillFilterValues(excludeTable, savedFilter.getExclude(), null);
}
}
filter.setName(filterName);
}
private Table createEditableList(String name, List<String> values) {
Group group = UIUtils.createControlGroup(blockControl, name, 2, GridData.FILL_BOTH, 0);
final Table valueTable = new Table(group, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
final GridData gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 300;
gd.heightHint = 100;
valueTable.setLayoutData(gd);
// valueTable.setHeaderVisible(true);
valueTable.setLinesVisible(true);
final TableColumn valueColumn = UIUtils.createTableColumn(valueTable, SWT.LEFT, CoreMessages.dialog_filter_table_column_value);
valueColumn.setWidth(300);
fillFilterValues(valueTable, values);
final CustomTableEditor tableEditor = new CustomTableEditor(valueTable) {
@Override
protected Control createEditor(Table table, int index, TableItem item) {
Text editor = new Text(table, SWT.BORDER);
editor.setText(item.getText());
return editor;
}
@Override
protected void saveEditorValue(Control control, int index, TableItem item) {
item.setText(((Text) control).getText());
}
};
Composite buttonsGroup = UIUtils.createPlaceholder(group, 1, 5);
buttonsGroup.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
final Button addButton = new Button(buttonsGroup, SWT.PUSH);
addButton.setText(CoreMessages.dialog_filter_button_add);
addButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
addButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
TableItem newItem = new TableItem(valueTable, SWT.LEFT);
valueTable.setSelection(newItem);
tableEditor.closeEditor();
tableEditor.showEditor(newItem);
}
});
final Button removeButton = new Button(buttonsGroup, SWT.PUSH);
removeButton.setText(CoreMessages.dialog_filter_button_remove);
removeButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
removeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int selectionIndex = valueTable.getSelectionIndex();
if (selectionIndex >= 0) {
tableEditor.closeEditor();
valueTable.remove(selectionIndex);
removeButton.setEnabled(valueTable.getSelectionIndex() >= 0);
}
}
});
removeButton.setEnabled(false);
final Button clearButton = new Button(buttonsGroup, SWT.PUSH);
clearButton.setText(CoreMessages.dialog_filter_button_clear);
clearButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
clearButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
tableEditor.closeEditor();
valueTable.removeAll();
removeButton.setEnabled(false);
}
});
valueTable.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int selectionIndex = valueTable.getSelectionIndex();
removeButton.setEnabled(selectionIndex >= 0);
}
});
return valueTable;
}
private void fillFilterValues(Table valueTable, List<String> values) {
valueTable.removeAll();
if (!CommonUtils.isEmpty(values)) {
for (String value : values) {
new TableItem(valueTable, SWT.LEFT).setText(value);
}
}
}
private void enableFiltersContent() {
if (filter.isEnabled()) {
if (blockEnableState != null) {
......@@ -272,26 +181,14 @@ public class EditObjectFilterDialog extends HelpEnabledDialog {
private void saveConfigurations() {
filter.setEnabled(enableButton.getSelection());
filter.setInclude(collectValues(includeTable));
filter.setExclude(collectValues(excludeTable));
filter.setInclude(StringEditorTable.collectValues(includeTable));
filter.setExclude(StringEditorTable.collectValues(excludeTable));
filter.setName(namesCombo.getText());
if (!CommonUtils.isEmpty(filter.getName())) {
dsRegistry.updateSavedFilter(filter);
}
}
private List<String> collectValues(Table table) {
List<String> values = new ArrayList<>();
for (TableItem item : table.getItems()) {
String value = item.getText().trim();
if (value.isEmpty() || value.equals("%")) { //$NON-NLS-1$
continue;
}
values.add(value);
}
return values;
}
@Override
protected void okPressed() {
saveConfigurations();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册