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

Table editor - proposals

上级 a096cbbb
......@@ -16,6 +16,9 @@
*/
package org.jkiss.dbeaver.ui.controls;
import org.eclipse.jface.fieldassist.ContentProposalAdapter;
import org.eclipse.jface.fieldassist.IContentProposalProvider;
import org.eclipse.jface.fieldassist.TextContentAdapter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
......@@ -23,6 +26,8 @@ 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.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.model.DBPImage;
import org.jkiss.dbeaver.ui.DBeaverIcons;
......@@ -37,7 +42,15 @@ import java.util.List;
*/
public class StringEditorTable {
public static Table createEditableList(Composite parent, String name, List<String> values, DBPImage icon) {
private static Button removeButton;
public static Table createEditableList(
@NotNull Composite parent,
@NotNull String name,
@Nullable List<String> values,
@Nullable DBPImage icon,
@Nullable IContentProposalProvider proposalProvider)
{
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);
......@@ -69,6 +82,14 @@ public class StringEditorTable {
protected Control createEditor(Table table, int index, TableItem item) {
Text editor = new Text(table, SWT.BORDER);
editor.setText(item.getText());
if (proposalProvider != null) {
setProposalAdapter(UIUtils.installContentProposal(
editor,
new TextContentAdapter(),
proposalProvider,
true,
false));
}
return editor;
}
@Override
......@@ -92,10 +113,11 @@ public class StringEditorTable {
valueTable.setSelection(newItem);
tableEditor.closeEditor();
tableEditor.showEditor(newItem);
removeButton.setEnabled(true);
}
});
final Button removeButton = new Button(buttonsGroup, SWT.PUSH);
removeButton = new Button(buttonsGroup, SWT.PUSH);
removeButton.setText(CoreMessages.dialog_filter_button_remove);
removeButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
removeButton.addSelectionListener(new SelectionAdapter() {
......
......@@ -17,13 +17,18 @@
package org.jkiss.dbeaver.ui.controls.resultset.panel.grouping;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.fieldassist.IContentProposalProvider;
import org.eclipse.jface.fieldassist.SimpleContentProposalProvider;
import org.eclipse.swt.widgets.*;
import org.jkiss.dbeaver.model.DBIcon;
import org.jkiss.dbeaver.model.data.DBDAttributeBinding;
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.ArrayList;
import java.util.Collections;
import java.util.List;
/**
......@@ -54,8 +59,16 @@ class GroupingConfigDialog extends BaseDialog
{
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);
List<String> proposals = new ArrayList<>();
for (DBDAttributeBinding attr : resultsContainer.getOwnerPresentation().getController().getModel().getAttributes()) {
proposals.add(attr.getName());
}
IContentProposalProvider proposalProvider = new SimpleContentProposalProvider(proposals.toArray(new String[0]));
columnsTable = StringEditorTable.createEditableList(composite, "Columns", resultsContainer.getGroupAttributes(), DBIcon.TREE_ATTRIBUTE, proposalProvider);
Collections.addAll(proposals,"COUNT", "AVG", "MAX", "MIN", "SUM");
proposalProvider = new SimpleContentProposalProvider(proposals.toArray(new String[0]));
functionsTable = StringEditorTable.createEditableList(composite, "Functions", resultsContainer.getGroupFunctions(), DBIcon.TREE_FUNCTION, proposalProvider);
return composite;
}
......
......@@ -35,6 +35,10 @@ import java.util.List;
public class GroupingResultsContainer implements IResultSetContainer {
public static final String FUNCTION_COUNT = "COUNT";
public static final String DEFAULT_FUNCTION = FUNCTION_COUNT + "(*)";
private final IResultSetPresentation presentation;
private GroupingDataContainer dataContainer;
private ResultSetViewer groupingViewer;
......@@ -52,7 +56,11 @@ public class GroupingResultsContainer implements IResultSetContainer {
private void initDefaultSettings() {
this.groupAttributes.clear();
this.groupFunctions.clear();
addGroupingFunctions(Collections.singletonList("COUNT(*)"));
addGroupingFunctions(Collections.singletonList(DEFAULT_FUNCTION));
}
public IResultSetPresentation getOwnerPresentation() {
return presentation;
}
public List<String> getGroupAttributes() {
......
......@@ -99,8 +99,8 @@ public class EditObjectFilterDialog extends HelpEnabledDialog {
blockControl = UIUtils.createPlaceholder(composite, 1);
blockControl.setLayoutData(new GridData(GridData.FILL_BOTH));
includeTable = StringEditorTable.createEditableList(blockControl, CoreMessages.dialog_filter_list_include, filter.getInclude(), null);
excludeTable = StringEditorTable.createEditableList(blockControl, CoreMessages.dialog_filter_list_exclude, filter.getExclude(), null);
includeTable = StringEditorTable.createEditableList(blockControl, CoreMessages.dialog_filter_list_include, filter.getInclude(), null, null);
excludeTable = StringEditorTable.createEditableList(blockControl, CoreMessages.dialog_filter_list_exclude, filter.getExclude(), null, null);
UIUtils.createInfoLabel(blockControl, CoreMessages.dialog_connection_edit_wizard_general_filter_hint_text);
......
......@@ -1585,7 +1585,7 @@ public class UIUtils {
installContentProposal(control, contentAdapter, provider, false, true);
}
public static void installContentProposal(Control control, IControlContentAdapter contentAdapter, IContentProposalProvider provider, boolean autoActivation, boolean insertAfter) {
public static ContentProposalAdapter installContentProposal(Control control, IControlContentAdapter contentAdapter, IContentProposalProvider provider, boolean autoActivation, boolean insertAfter) {
try {
KeyStroke keyStroke = autoActivation ? null : KeyStroke.getInstance("Ctrl+Space");
final ContentProposalAdapter proposalAdapter = new ContentProposalAdapter(
......@@ -1596,8 +1596,10 @@ public class UIUtils {
autoActivation ? ".abcdefghijklmnopqrstuvwxyz_$(".toCharArray() : ".(".toCharArray());
proposalAdapter.setProposalAcceptanceStyle(insertAfter ? ContentProposalAdapter.PROPOSAL_INSERT : ContentProposalAdapter.PROPOSAL_REPLACE);
proposalAdapter.setPopupSize(new Point(300, 200));
return proposalAdapter;
} catch (ParseException e) {
log.error("Error installing filters content assistant");
return null;
}
}
......
......@@ -16,6 +16,7 @@
*/
package org.jkiss.dbeaver.ui.controls;
import org.eclipse.jface.fieldassist.ContentProposalAdapter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.events.*;
......@@ -32,23 +33,34 @@ public abstract class CustomTableEditor implements MouseListener, TraverseListen
private final Table table;
private final TableEditor tableEditor;
private ContentProposalAdapter proposalAdapter;
private int columnIndex;
protected int firstTraverseIndex = -1, lastTraverseIndex = -1;
protected boolean editOnEnter = true;
public CustomTableEditor(Table table) {
this(table, null);
}
public CustomTableEditor(Table table, ContentProposalAdapter proposalAdapter) {
this.table = table;
this.proposalAdapter = proposalAdapter;
tableEditor = new TableEditor(table);
tableEditor.horizontalAlignment = SWT.CENTER;
tableEditor.verticalAlignment = SWT.TOP;
tableEditor.grabHorizontal = true;
//tableEditor.grabVertical = true;
tableEditor.minimumWidth = 50;
table.addMouseListener(this);
table.addTraverseListener(this);
}
public void setProposalAdapter(ContentProposalAdapter proposalAdapter) {
this.proposalAdapter = proposalAdapter;
}
@Override
public void mouseDoubleClick(MouseEvent e) {
......@@ -68,12 +80,7 @@ public abstract class CustomTableEditor implements MouseListener, TraverseListen
final TableItem item = table.getItem(new Point(e.x, e.y));
if (item != null) {
columnIndex = UIUtils.getColumnAtPos(item, e.x, e.y);
UIUtils.asyncExec(new Runnable() {
@Override
public void run() {
showEditor(item);
}
});
UIUtils.asyncExec(() -> showEditor(item));
}
}
......@@ -94,13 +101,19 @@ public abstract class CustomTableEditor implements MouseListener, TraverseListen
@Override
public void focusLost(FocusEvent e) {
saveEditorValue(editor, columnIndex, tableEditor.getItem());
closeEditor();
if (!isProposalPopupActive()) {
closeEditor();
}
}
});
editor.addTraverseListener(this);
tableEditor.setEditor(editor, item, columnIndex);
}
private boolean isProposalPopupActive() {
return proposalAdapter != null && proposalAdapter.isProposalPopupOpen();
}
public void closeEditor() {
Control oldEditor = this.tableEditor.getEditor();
if (oldEditor != null) oldEditor.dispose();
......@@ -116,7 +129,9 @@ public abstract class CustomTableEditor implements MouseListener, TraverseListen
if (e.detail == SWT.TRAVERSE_RETURN) {
if (editor != null) {
saveEditorValue(editor, columnIndex, tableEditor.getItem());
closeEditor();
if (!isProposalPopupActive()) {
this.closeEditor();
}
} else if (editOnEnter) {
TableItem[] selection = table.getSelection();
if (selection != null && selection.length >= 1) {
......@@ -131,7 +146,9 @@ public abstract class CustomTableEditor implements MouseListener, TraverseListen
TableItem item = tableEditor.getItem();
if (item != null) {
saveEditorValue(editor, columnIndex, item);
closeEditor();
if (!isProposalPopupActive()) {
this.closeEditor();
}
int lastColumn = lastTraverseIndex > 0 ? lastTraverseIndex : table.getColumnCount() - 1;
if (columnIndex < lastColumn) {
......@@ -153,7 +170,9 @@ public abstract class CustomTableEditor implements MouseListener, TraverseListen
e.detail = SWT.TRAVERSE_NONE;
}
} else if (e.detail == SWT.TRAVERSE_ESCAPE && editor != null) {
closeEditor();
if (!isProposalPopupActive()) {
this.closeEditor();
}
e.doit = false;
e.detail = SWT.TRAVERSE_NONE;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册