提交 0726393b 编写于 作者: S Serge Rider

Index create dialog: support ASC/DESC index column modifiers

上级 36338e8d
......@@ -36,6 +36,7 @@ import org.jkiss.dbeaver.model.struct.DBSEntity;
import org.jkiss.dbeaver.model.struct.DBSEntityAttribute;
import org.jkiss.dbeaver.ui.DBeaverIcons;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.controls.CustomTableEditor;
import org.jkiss.utils.CommonUtils;
import java.lang.reflect.InvocationTargetException;
......@@ -52,19 +53,34 @@ public abstract class AttributesSelectorPage extends BaseObjectEditPage {
protected DBSEntity entity;
protected Table columnsTable;
protected List<AttributeInfo> attributes = new ArrayList<>();
protected Button toggleButton;
protected Group columnsGroup;
private static class AttributeInfo {
protected static class AttributeInfo {
DBSEntityAttribute attribute;
int position;
Map<String, Object> properties = new HashMap<>();
public AttributeInfo(DBSEntityAttribute attribute)
{
this.attribute = attribute;
this.position = -1;
}
public Object getProperty(String name) {
return properties.get(name);
}
public void setProperty(String name, Object value) {
properties.put(name, value);
}
@Override
public String toString() {
return attribute.getName();
}
}
public AttributesSelectorPage(
......@@ -75,6 +91,16 @@ public abstract class AttributesSelectorPage extends BaseObjectEditPage {
this.entity = entity;
}
public Map<String, Object> getAttributeProperties(DBSEntityAttribute attr) {
for (AttributeInfo attrInfo : attributes) {
if (attrInfo.attribute == attr) {
return attrInfo.properties;
}
}
return Collections.emptyMap();
}
@Override
protected Composite createPageContents(Composite parent) {
final Composite panel = UIUtils.createPlaceholder(parent, 1);
......@@ -111,14 +137,18 @@ public abstract class AttributesSelectorPage extends BaseObjectEditPage {
}
});
TableColumn colName = UIUtils.createTableColumn(columnsTable, SWT.NONE, CoreMessages.dialog_struct_columns_select_column);
colName.addListener(SWT.Selection, new SortListener(0));
TableColumn colPosition = UIUtils.createTableColumn(columnsTable, SWT.CENTER, "#"); //$NON-NLS-1$
colPosition.addListener(SWT.Selection, new SortListener(1));
createAttributeColumns(columnsTable);
TableColumn colType = UIUtils.createTableColumn(columnsTable, SWT.RIGHT, "Type"); //$NON-NLS-1$
colType.addListener(SWT.Selection, new SortListener(2));
final CustomTableEditor tableEditor = new CustomTableEditor(columnsTable) {
@Override
protected Control createEditor(Table table, final int index, final TableItem item) {
return createCellEditor(table, index, item, (AttributeInfo)item.getData());
}
@Override
protected void saveEditorValue(Control control, int index, TableItem item) {
saveCellValue(control, index, item, (AttributeInfo)item.getData());
}
};
toggleButton = new Button(columnsGroup, SWT.PUSH);
toggleButton.setText("Select All");
......@@ -151,6 +181,37 @@ public abstract class AttributesSelectorPage extends BaseObjectEditPage {
});
}
protected void createAttributeColumns(Table columnsTable) {
TableColumn colName = UIUtils.createTableColumn(columnsTable, SWT.NONE, CoreMessages.dialog_struct_columns_select_column);
colName.addListener(SWT.Selection, new SortListener(0));
TableColumn colPosition = UIUtils.createTableColumn(columnsTable, SWT.CENTER, "#"); //$NON-NLS-1$
colPosition.addListener(SWT.Selection, new SortListener(1));
TableColumn colType = UIUtils.createTableColumn(columnsTable, SWT.RIGHT, "Type"); //$NON-NLS-1$
colType.addListener(SWT.Selection, new SortListener(2));
}
protected void fillAttributeColumns(DBSEntityAttribute attribute, AttributeInfo attributeInfo, TableItem columnItem) {
columnItem.setText(0, attribute.getName());
columnItem.setText(1, String.valueOf(attribute.getOrdinalPosition()));
columnItem.setText(2, attribute.getFullTypeName());
}
protected Control createCellEditor(Table table, int index, TableItem item, AttributeInfo data) {
/*
final Text text = new Text(table, SWT.BORDER);
text.setText(item.getText(index));
text.selectAll();
return text;
*/
return null;
}
protected void saveCellValue(Control control, int index, TableItem item, AttributeInfo data) {
//item.setText(index, control.getText());
}
protected void fillAttributes(final DBSEntity entity)
{
// Collect attributes
......@@ -191,9 +252,7 @@ public abstract class AttributesSelectorPage extends BaseObjectEditPage {
if (attributeNode != null) {
columnItem.setImage(0, DBeaverIcons.getImage(attributeNode.getNodeIcon()));
}
columnItem.setText(0, attribute.getName());
columnItem.setText(1, String.valueOf(attribute.getOrdinalPosition()));
columnItem.setText(2, attribute.getFullTypeName());
fillAttributeColumns(attribute, col, columnItem);
columnItem.setData(col);
if (isColumnSelected(attribute)) {
columnItem.setChecked(true);
......
......@@ -19,13 +19,13 @@ package org.jkiss.dbeaver.ui.editors.object.struct;
import org.eclipse.core.runtime.Assert;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.*;
import org.jkiss.dbeaver.core.CoreMessages;
import org.jkiss.dbeaver.model.struct.DBSEntityAttribute;
import org.jkiss.dbeaver.model.struct.rdb.DBSIndexType;
import org.jkiss.dbeaver.model.struct.rdb.DBSTable;
import org.jkiss.dbeaver.ui.UIUtils;
......@@ -42,6 +42,8 @@ import java.util.List;
*/
public class EditIndexPage extends AttributesSelectorPage {
public static final String PROP_DESC = "desc";
private List<DBSIndexType> indexTypes;
private DBSIndexType selectedIndexType;
private boolean unique;
......@@ -96,4 +98,48 @@ public class EditIndexPage extends AttributesSelectorPage {
public boolean isUnique() {
return unique;
}
@Override
protected void createAttributeColumns(Table columnsTable) {
super.createAttributeColumns(columnsTable);
TableColumn colDesc = UIUtils.createTableColumn(columnsTable, SWT.NONE, "Order");
colDesc.setToolTipText("Ascending/descending");
}
@Override
protected void fillAttributeColumns(DBSEntityAttribute attribute, AttributeInfo attributeInfo, TableItem columnItem) {
super.fillAttributeColumns(attribute, attributeInfo, columnItem);
boolean isDesc = Boolean.TRUE.equals(attributeInfo.getProperty(PROP_DESC));
columnItem.setText(3, isDesc ? "DESC" : "ASC");
}
protected Control createCellEditor(Table table, int index, TableItem item, AttributeInfo attributeInfo) {
if (index == 3) {
boolean isDesc = Boolean.TRUE.equals(attributeInfo.getProperty(PROP_DESC));
CCombo combo = new CCombo(table, SWT.DROP_DOWN | SWT.READ_ONLY);
combo.add("ASC");
combo.add("DESC");
combo.select(isDesc ? 1 : 0);
return combo;
}
/*
final Text text = new Text(table, SWT.BORDER);
text.setText(item.getText(index));
text.selectAll();
return text;
*/
return null;
}
protected void saveCellValue(Control control, int index, TableItem item, AttributeInfo attributeInfo) {
if (index == 3) {
CCombo combo = (CCombo) control;
boolean isDesc = combo.getSelectionIndex() == 1;
item.setText(index, isDesc ? "DESC" : "ASC");
attributeInfo.setProperty(PROP_DESC, isDesc);
}
}
}
......@@ -32,6 +32,7 @@ import org.jkiss.dbeaver.ui.editors.object.struct.EditIndexPage;
import org.jkiss.utils.CommonUtils;
import java.util.Collections;
import java.util.Map;
/**
* MySQL index manager
......@@ -72,6 +73,7 @@ public class MySQLIndexManager extends SQLIndexManager<MySQLTableIndex, MySQLTab
idxName.append(CommonUtils.escapeIdentifier(parent.getName()));
int colIndex = 1;
for (DBSEntityAttribute tableColumn : editPage.getSelectedAttributes()) {
final Map<String, Object> attrProps = editPage.getAttributeProperties(tableColumn);
if (colIndex == 1) {
idxName.append("_").append(CommonUtils.escapeIdentifier(tableColumn.getName())); //$NON-NLS-1$
}
......@@ -80,7 +82,7 @@ public class MySQLIndexManager extends SQLIndexManager<MySQLTableIndex, MySQLTab
index,
(MySQLTableColumn) tableColumn,
colIndex++,
true,
!Boolean.TRUE.equals(attrProps.get(EditIndexPage.PROP_DESC)),
false,
null));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册