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

Debug panel UI - function parameters redesign

上级 a1ea5818
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
package org.jkiss.dbeaver.ext.postgresql.debug.ui.internal; package org.jkiss.dbeaver.ext.postgresql.debug.ui.internal;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionAdapter;
...@@ -26,10 +25,7 @@ import org.eclipse.swt.events.SelectionEvent; ...@@ -26,10 +25,7 @@ import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.*;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Text;
import org.jkiss.dbeaver.DBException; import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.core.DBeaverCore; import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.debug.ui.DBGConfigurationPanel; import org.jkiss.dbeaver.debug.ui.DBGConfigurationPanel;
...@@ -44,11 +40,11 @@ import org.jkiss.dbeaver.model.navigator.DBNNode; ...@@ -44,11 +40,11 @@ import org.jkiss.dbeaver.model.navigator.DBNNode;
import org.jkiss.dbeaver.model.struct.DBSInstance; import org.jkiss.dbeaver.model.struct.DBSInstance;
import org.jkiss.dbeaver.model.struct.DBSObjectContainer; import org.jkiss.dbeaver.model.struct.DBSObjectContainer;
import org.jkiss.dbeaver.model.struct.rdb.DBSProcedureParameter; import org.jkiss.dbeaver.model.struct.rdb.DBSProcedureParameter;
import org.jkiss.dbeaver.runtime.sql.ProcedureParameterBindDialog;
import org.jkiss.dbeaver.ui.DBeaverIcons; import org.jkiss.dbeaver.ui.DBeaverIcons;
import org.jkiss.dbeaver.ui.UIUtils; import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.controls.CSmartCombo; import org.jkiss.dbeaver.ui.controls.CSmartCombo;
import org.jkiss.dbeaver.ui.controls.CSmartSelector; import org.jkiss.dbeaver.ui.controls.CSmartSelector;
import org.jkiss.dbeaver.ui.controls.CustomTableEditor;
import org.jkiss.dbeaver.ui.dialogs.BrowseObjectDialog; import org.jkiss.dbeaver.ui.dialogs.BrowseObjectDialog;
import org.jkiss.utils.CommonUtils; import org.jkiss.utils.CommonUtils;
...@@ -65,10 +61,10 @@ public class PostgreDebugPanelFunction implements DBGConfigurationPanel { ...@@ -65,10 +61,10 @@ public class PostgreDebugPanelFunction implements DBGConfigurationPanel {
private Button kindGlobal; private Button kindGlobal;
private CSmartCombo<PostgreProcedure> functionCombo; private CSmartCombo<PostgreProcedure> functionCombo;
private Text processIdText; private Text processIdText;
private Button configParametersButton;
private PostgreProcedure selectedFunction; private PostgreProcedure selectedFunction;
private Map<DBSProcedureParameter, Object> parameterValues = new HashMap<>(); private Map<DBSProcedureParameter, Object> parameterValues = new HashMap<>();
private Table parametersTable;
@Override @Override
public void createPanel(Composite parent, DBGConfigurationPanelContainer container) { public void createPanel(Composite parent, DBGConfigurationPanelContainer container) {
...@@ -81,7 +77,7 @@ public class PostgreDebugPanelFunction implements DBGConfigurationPanel { ...@@ -81,7 +77,7 @@ public class PostgreDebugPanelFunction implements DBGConfigurationPanel {
@Override @Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
processIdText.setEnabled(kindGlobal.getSelection()); processIdText.setEnabled(kindGlobal.getSelection());
configParametersButton.setEnabled(kindLocal.getSelection()); parametersTable.setEnabled(kindLocal.getSelection());
container.updateDialogState(); container.updateDialogState();
} }
}; };
...@@ -93,77 +89,112 @@ public class PostgreDebugPanelFunction implements DBGConfigurationPanel { ...@@ -93,77 +89,112 @@ public class PostgreDebugPanelFunction implements DBGConfigurationPanel {
kindGlobal.setText("Global"); kindGlobal.setText("Global");
kindGlobal.addSelectionListener(listener); kindGlobal.addSelectionListener(listener);
} }
{ createFunctionGroup(parent);
Group functionGroup = UIUtils.createControlGroup(parent, "Function", 2, GridData.VERTICAL_ALIGN_BEGINNING, SWT.DEFAULT); createParametersGroup(parent);
UIUtils.createControlLabel(functionGroup, "Function"); }
functionCombo = new CSmartSelector<PostgreProcedure>(functionGroup, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY, new LabelProvider() {
@Override
public Image getImage(Object element) {
return DBeaverIcons.getImage(DBIcon.TREE_PROCEDURE);
}
@Override private void createFunctionGroup(Composite parent) {
public String getText(Object element) { Group functionGroup = UIUtils.createControlGroup(parent, "Function", 2, GridData.VERTICAL_ALIGN_BEGINNING, SWT.DEFAULT);
if (element == null) { UIUtils.createControlLabel(functionGroup, "Function");
return "N/A"; functionCombo = new CSmartSelector<PostgreProcedure>(functionGroup, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY, new LabelProvider() {
} @Override
return ((PostgreProcedure)element).getFullQualifiedSignature(); public Image getImage(Object element) {
return DBeaverIcons.getImage(DBIcon.TREE_PROCEDURE);
}
@Override
public String getText(Object element) {
if (element == null) {
return "N/A";
} }
}) { return ((PostgreProcedure)element).getFullQualifiedSignature();
@Override }
protected void dropDown(boolean drop) { }) {
if (drop) { @Override
DBNModel navigatorModel = DBeaverCore.getInstance().getNavigatorModel(); protected void dropDown(boolean drop) {
DBNDatabaseNode dsNode = navigatorModel.getNodeByObject(container.getDataSource()); if (drop) {
if (dsNode != null) { DBNModel navigatorModel = DBeaverCore.getInstance().getNavigatorModel();
DBNNode curNode = selectedFunction == null ? null : navigatorModel.getNodeByObject(selectedFunction); DBNDatabaseNode dsNode = navigatorModel.getNodeByObject(container.getDataSource());
DBNNode node = BrowseObjectDialog.selectObject( if (dsNode != null) {
parent.getShell(), DBNNode curNode = selectedFunction == null ? null : navigatorModel.getNodeByObject(selectedFunction);
"Select function to debug", DBNNode node = BrowseObjectDialog.selectObject(
dsNode, parent.getShell(),
curNode, "Select function to debug",
new Class[]{DBSInstance.class, DBSObjectContainer.class, PostgreProcedure.class}, dsNode,
new Class[]{PostgreProcedure.class}); curNode,
if (node instanceof DBNDatabaseNode && ((DBNDatabaseNode) node).getObject() instanceof PostgreProcedure) { new Class[]{DBSInstance.class, DBSObjectContainer.class, PostgreProcedure.class},
functionCombo.removeAll(); new Class[]{PostgreProcedure.class});
selectedFunction = (PostgreProcedure) ((DBNDatabaseNode) node).getObject(); if (node instanceof DBNDatabaseNode && ((DBNDatabaseNode) node).getObject() instanceof PostgreProcedure) {
functionCombo.addItem(selectedFunction); functionCombo.removeAll();
functionCombo.select(selectedFunction); selectedFunction = (PostgreProcedure) ((DBNDatabaseNode) node).getObject();
container.updateDialogState(); functionCombo.addItem(selectedFunction);
} functionCombo.select(selectedFunction);
configParametersButton.setEnabled(selectedFunction != null); updateParametersTable();
container.updateDialogState();
} }
parametersTable.setEnabled(selectedFunction != null);
} }
} }
};
functionCombo.addItem(null);
GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
gd.widthHint = UIUtils.getFontHeight(functionCombo) * 40 + 10;
functionCombo.setLayoutData(gd);
configParametersButton = UIUtils.createPushButton(functionGroup, "Configure Parameters...", null, new SelectionAdapter() { }
@Override };
public void widgetSelected(SelectionEvent e) { functionCombo.addItem(null);
if (selectedFunction == null) { GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
return; gd.widthHint = UIUtils.getFontHeight(functionCombo) * 40 + 10;
} functionCombo.setLayoutData(gd);
ProcedureParameterBindDialog dialog = new ProcedureParameterBindDialog(parent.getShell(), selectedFunction, parameterValues);
if (dialog.open() == IDialogConstants.OK_ID) { processIdText = UIUtils.createLabelText(functionGroup, "Process ID", "", SWT.BORDER, new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
parameterValues.clear(); gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
parameterValues.putAll(dialog.getValues()); gd.widthHint = UIUtils.getFontHeight(processIdText) * 10 + 10;
} processIdText.setLayoutData(gd);
}
private void createParametersGroup(Composite parent) {
Group composite = UIUtils.createControlGroup(parent, "Function parameters", 2, GridData.VERTICAL_ALIGN_BEGINNING, SWT.DEFAULT);
parametersTable = new Table(composite, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
final GridData gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 400;
gd.heightHint = 200;
parametersTable.setLayoutData(gd);
parametersTable.setHeaderVisible(true);
parametersTable.setLinesVisible(true);
final TableColumn nameColumn = UIUtils.createTableColumn(parametersTable, SWT.LEFT, "Name");
nameColumn.setWidth(100);
final TableColumn valueColumn = UIUtils.createTableColumn(parametersTable, SWT.LEFT, "Value");
valueColumn.setWidth(200);
final TableColumn typeColumn = UIUtils.createTableColumn(parametersTable, SWT.LEFT, "Type");
typeColumn.setWidth(60);
final TableColumn kindColumn = UIUtils.createTableColumn(parametersTable, SWT.LEFT, "Kind");
kindColumn.setWidth(40);
new CustomTableEditor(parametersTable) {
{
firstTraverseIndex = 1;
lastTraverseIndex = 1;
editOnEnter = false;
}
@Override
protected Control createEditor(Table table, int index, TableItem item) {
if (index != 1) {
return null;
} }
}); DBSProcedureParameter param = (DBSProcedureParameter) item.getData();
gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); Text editor = new Text(table, SWT.BORDER);
gd.horizontalSpan = 2; editor.setText(CommonUtils.toString(parameterValues.get(param), ""));
configParametersButton.setLayoutData(gd); editor.selectAll();
return editor;
}
@Override
protected void saveEditorValue(Control control, int index, TableItem item) {
DBSProcedureParameter param = (DBSProcedureParameter) item.getData();
String newValue = ((Text) control).getText();
item.setText(1, newValue);
processIdText = UIUtils.createLabelText(functionGroup, "Process ID", "", SWT.BORDER, new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING)); parameterValues.put(param, newValue);
gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); }
gd.widthHint = UIUtils.getFontHeight(processIdText) * 10 + 10; };
processIdText.setLayoutData(gd);
}
} }
@Override @Override
...@@ -174,7 +205,7 @@ public class PostgreDebugPanelFunction implements DBGConfigurationPanel { ...@@ -174,7 +205,7 @@ public class PostgreDebugPanelFunction implements DBGConfigurationPanel {
} else { } else {
kindLocal.setSelection(true); kindLocal.setSelection(true);
} }
configParametersButton.setEnabled(kindLocal.getSelection()); parametersTable.setEnabled(kindLocal.getSelection());
processIdText.setEnabled(kindGlobal.getSelection()); processIdText.setEnabled(kindGlobal.getSelection());
Object processId = configuration.get(PostgreDebugConstants.ATTR_ATTACH_PROCESS); Object processId = configuration.get(PostgreDebugConstants.ATTR_ATTACH_PROCESS);
...@@ -225,8 +256,10 @@ public class PostgreDebugPanelFunction implements DBGConfigurationPanel { ...@@ -225,8 +256,10 @@ public class PostgreDebugPanelFunction implements DBGConfigurationPanel {
} }
} }
} }
updateParametersTable();
} }
configParametersButton.setEnabled(selectedFunction != null); parametersTable.setEnabled(selectedFunction != null);
if (selectedFunction != null) { if (selectedFunction != null) {
functionCombo.addItem(selectedFunction); functionCombo.addItem(selectedFunction);
functionCombo.select(selectedFunction); functionCombo.select(selectedFunction);
...@@ -237,6 +270,22 @@ public class PostgreDebugPanelFunction implements DBGConfigurationPanel { ...@@ -237,6 +270,22 @@ public class PostgreDebugPanelFunction implements DBGConfigurationPanel {
} }
} }
private void updateParametersTable() {
parametersTable.removeAll();
for (DBSProcedureParameter param : selectedFunction.getParameters(null)) {
TableItem item = new TableItem(parametersTable, SWT.NONE);
item.setData(param);
item.setImage(DBeaverIcons.getImage(DBIcon.TREE_ATTRIBUTE));
item.setText(0, param.getName());
Object value = parameterValues.get(param);
item.setText(1, CommonUtils.toString(value, ""));
item.setText(2, param.getParameterType().getFullTypeName());
item.setText(3, param.getParameterKind().getTitle());
}
parametersTable.select(0);
}
@Override @Override
public void saveConfiguration(DBPDataSourceContainer dataSource, Map<String, Object> configuration) { public void saveConfiguration(DBPDataSourceContainer dataSource, Map<String, Object> configuration) {
configuration.put(PostgreDebugConstants.ATTR_ATTACH_KIND, configuration.put(PostgreDebugConstants.ATTR_ATTACH_KIND,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册