提交 ec424c3f 编写于 作者: S Serge Rider

#5384 Virtual entity edit dialog improvements

上级 045927b1
...@@ -33,12 +33,11 @@ public class DBVEntityForeignKey implements DBSEntityConstraint, DBSEntityReferr ...@@ -33,12 +33,11 @@ public class DBVEntityForeignKey implements DBSEntityConstraint, DBSEntityReferr
@NotNull @NotNull
private final DBVEntity entity; private final DBVEntity entity;
private final DBSEntityConstraint refEntityConstraint; private DBSEntityConstraint refEntityConstraint;
private final List<DBVEntityForeignKeyColumn> attributes = new ArrayList<>(); private final List<DBVEntityForeignKeyColumn> attributes = new ArrayList<>();
public DBVEntityForeignKey(DBVEntity entity, DBSEntityConstraint refEntityConstraint) throws DBException { public DBVEntityForeignKey(@NotNull DBVEntity entity) {
this.entity = entity; this.entity = entity;
this.refEntityConstraint = refEntityConstraint;
/* /*
if (refEntityConstraint instanceof DBSEntityReferrer) { if (refEntityConstraint instanceof DBSEntityReferrer) {
for (DBSEntityAttributeRef attrRef : ((DBSEntityReferrer) refEntityConstraint).getAttributeReferences(monitor)) { for (DBSEntityAttributeRef attrRef : ((DBSEntityReferrer) refEntityConstraint).getAttributeReferences(monitor)) {
...@@ -58,6 +57,10 @@ public class DBVEntityForeignKey implements DBSEntityConstraint, DBSEntityReferr ...@@ -58,6 +57,10 @@ public class DBVEntityForeignKey implements DBSEntityConstraint, DBSEntityReferr
return refEntityConstraint; return refEntityConstraint;
} }
public void setReferencedConstraint(DBSEntityConstraint refEntityConstraint) {
this.refEntityConstraint = refEntityConstraint;
}
@Override @Override
public DBSEntity getAssociatedEntity() { public DBSEntity getAssociatedEntity() {
return refEntityConstraint.getParentObject(); return refEntityConstraint.getParentObject();
......
...@@ -16,6 +16,10 @@ ...@@ -16,6 +16,10 @@
*/ */
package org.jkiss.dbeaver.ui.editors.object.struct; package org.jkiss.dbeaver.ui.editors.object.struct;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.osgi.util.NLS; import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionAdapter;
...@@ -27,19 +31,20 @@ import org.jkiss.dbeaver.DBException; ...@@ -27,19 +31,20 @@ import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBPEvaluationContext; import org.jkiss.dbeaver.model.DBPEvaluationContext;
import org.jkiss.dbeaver.model.DBUtils; import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.navigator.DBNDatabaseNode; import org.jkiss.dbeaver.model.navigator.DBNDatabaseNode;
import org.jkiss.dbeaver.model.runtime.AbstractJob;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor; import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress;
import org.jkiss.dbeaver.model.struct.DBSEntity; import org.jkiss.dbeaver.model.struct.DBSEntity;
import org.jkiss.dbeaver.model.struct.DBSEntityAttribute; import org.jkiss.dbeaver.model.struct.DBSEntityAttribute;
import org.jkiss.dbeaver.runtime.DBWorkbench; import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.dbeaver.ui.DBeaverIcons; import org.jkiss.dbeaver.ui.DBeaverIcons;
import org.jkiss.dbeaver.ui.UITask;
import org.jkiss.dbeaver.ui.UIUtils; import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.controls.CustomTableEditor; import org.jkiss.dbeaver.ui.controls.CustomTableEditor;
import org.jkiss.dbeaver.ui.controls.TableColumnSortListener; import org.jkiss.dbeaver.ui.controls.TableColumnSortListener;
import org.jkiss.dbeaver.ui.editors.internal.EditorsMessages; import org.jkiss.dbeaver.ui.editors.internal.EditorsMessages;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.utils.CommonUtils; import org.jkiss.utils.CommonUtils;
import java.lang.reflect.InvocationTargetException;
import java.util.*; import java.util.*;
import java.util.List; import java.util.List;
...@@ -237,54 +242,51 @@ public abstract class AttributesSelectorPage extends BaseObjectEditPage { ...@@ -237,54 +242,51 @@ public abstract class AttributesSelectorPage extends BaseObjectEditPage {
//item.setText(index, control.getText()); //item.setText(index, control.getText());
} }
protected void fillAttributes(final DBSEntity entity) private void fillAttributes(final DBSEntity entity)
{ {
// Collect attributes final List<DBSEntityAttribute> attrList = new ArrayList<>();
final List<DBSEntityAttribute> attributes = new ArrayList<>(); AbstractJob loadJob = new AbstractJob("Load entity attributes") {
try { @Override
UIUtils.runInProgressService(new DBRRunnableWithProgress() { protected IStatus run(DBRProgressMonitor monitor) {
@Override try {
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException for (DBSEntityAttribute attr : CommonUtils.safeCollection(entity.getAttributes(monitor))) {
{ if (!DBUtils.isHiddenObject(attr)) {
try { attrList.add(attr);
for (DBSEntityAttribute attr : CommonUtils.safeCollection(entity.getAttributes(monitor))) {
if (!DBUtils.isHiddenObject(attr)) {
attributes.add(attr);
}
} }
} catch (DBException e) {
throw new InvocationTargetException(e);
} }
} catch (DBException e) {
return GeneralUtils.makeErrorStatus("Error loading attributes", e);
} }
}); return Status.OK_STATUS;
} catch (InvocationTargetException e) { }
DBWorkbench.getPlatformUI().showError( };
EditorsMessages.dialog_struct_columns_select_error_load_columns_title, loadJob.addJobChangeListener(new JobChangeAdapter() {
EditorsMessages.dialog_struct_columns_select_error_load_columns_message, @Override
e.getTargetException()); public void done(IJobChangeEvent event) {
} catch (InterruptedException e) { UIUtils.syncExec(() -> {
// do nothing for (DBSEntityAttribute attribute : attrList) {
} TableItem columnItem = new TableItem(columnsTable, SWT.NONE);
for (DBSEntityAttribute attribute : attributes) {
TableItem columnItem = new TableItem(columnsTable, SWT.NONE);
AttributeInfo col = new AttributeInfo(attribute); AttributeInfo col = new AttributeInfo(attribute);
this.attributes.add(col); attributes.add(col);
DBNDatabaseNode attributeNode = DBWorkbench.getPlatform().getNavigatorModel().findNode(attribute); DBNDatabaseNode attributeNode = DBWorkbench.getPlatform().getNavigatorModel().findNode(attribute);
if (attributeNode != null) { if (attributeNode != null) {
columnItem.setImage(0, DBeaverIcons.getImage(attributeNode.getNodeIcon())); columnItem.setImage(0, DBeaverIcons.getImage(attributeNode.getNodeIcon()));
} }
fillAttributeColumns(attribute, col, columnItem); fillAttributeColumns(attribute, col, columnItem);
columnItem.setData(col); columnItem.setData(col);
if (isColumnSelected(attribute)) { if (isColumnSelected(attribute)) {
columnItem.setChecked(true); columnItem.setChecked(true);
handleItemSelect(columnItem, false); handleItemSelect(columnItem, false);
}
}
UIUtils.packColumns(columnsTable);
updateToggleButton();
});
} }
} });
UIUtils.packColumns(columnsTable); loadJob.schedule();
updateToggleButton();
} }
private Composite createTableNameInput(Composite panel) { private Composite createTableNameInput(Composite panel) {
......
...@@ -83,7 +83,7 @@ public class EditForeignKeyPage extends BaseObjectEditPage { ...@@ -83,7 +83,7 @@ public class EditForeignKeyPage extends BaseObjectEditPage {
} }
private DBSForeignKeyModifyRule[] supportedModifyRules; private DBSForeignKeyModifyRule[] supportedModifyRules;
private DBSTableForeignKey foreignKey; private DBSEntityAssociation foreignKey;
private DBSTable curRefTable; private DBSTable curRefTable;
private List<DBSEntityConstraint> curConstraints; private List<DBSEntityConstraint> curConstraints;
private DBNDatabaseNode ownerTableNode; private DBNDatabaseNode ownerTableNode;
...@@ -102,7 +102,7 @@ public class EditForeignKeyPage extends BaseObjectEditPage { ...@@ -102,7 +102,7 @@ public class EditForeignKeyPage extends BaseObjectEditPage {
public EditForeignKeyPage( public EditForeignKeyPage(
String title, String title,
DBSTableForeignKey foreignKey, DBSEntityAssociation foreignKey,
DBSForeignKeyModifyRule[] supportedModifyRules) DBSForeignKeyModifyRule[] supportedModifyRules)
{ {
super(title); super(title);
...@@ -124,7 +124,7 @@ public class EditForeignKeyPage extends BaseObjectEditPage { ...@@ -124,7 +124,7 @@ public class EditForeignKeyPage extends BaseObjectEditPage {
{ {
final Composite tableGroup = UIUtils.createPlaceholder(panel, 2, 5); final Composite tableGroup = UIUtils.createPlaceholder(panel, 2, 5);
tableGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); tableGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
UIUtils.createLabelText(tableGroup, EditorsMessages.dialog_struct_edit_fk_label_table, foreignKey.getParentObject().getFullyQualifiedName(DBPEvaluationContext.UI), SWT.READ_ONLY | SWT.BORDER); UIUtils.createLabelText(tableGroup, EditorsMessages.dialog_struct_edit_fk_label_table, DBUtils.getObjectFullName(foreignKey, DBPEvaluationContext.UI), SWT.READ_ONLY | SWT.BORDER);
if (ownerTableNode != null) { if (ownerTableNode != null) {
try { try {
...@@ -459,7 +459,7 @@ public class EditForeignKeyPage extends BaseObjectEditPage { ...@@ -459,7 +459,7 @@ public class EditForeignKeyPage extends BaseObjectEditPage {
UIUtils.packColumns(columnsTable, true); UIUtils.packColumns(columnsTable, true);
} }
private static List<DBSEntityAttribute> getValidAttributes(DBSTable table) throws DBException { private static List<DBSEntityAttribute> getValidAttributes(DBSEntity table) throws DBException {
List<DBSEntityAttribute> result = new ArrayList<>(); List<DBSEntityAttribute> result = new ArrayList<>();
for (DBSEntityAttribute attr : table.getAttributes(new VoidProgressMonitor())) { for (DBSEntityAttribute attr : table.getAttributes(new VoidProgressMonitor())) {
if (!DBUtils.isHiddenObject(attr) && !DBUtils.isPseudoAttribute(attr)) { if (!DBUtils.isHiddenObject(attr) && !DBUtils.isPseudoAttribute(attr)) {
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
package org.jkiss.dbeaver.ui.controls.resultset; package org.jkiss.dbeaver.ui.controls.resultset;
import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionEvent;
...@@ -33,7 +34,9 @@ import org.jkiss.dbeaver.model.data.DBDAttributeTransformerDescriptor; ...@@ -33,7 +34,9 @@ import org.jkiss.dbeaver.model.data.DBDAttributeTransformerDescriptor;
import org.jkiss.dbeaver.model.data.DBDRowIdentifier; import org.jkiss.dbeaver.model.data.DBDRowIdentifier;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor; import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSEntity; import org.jkiss.dbeaver.model.struct.DBSEntity;
import org.jkiss.dbeaver.model.struct.DBSEntityAssociation;
import org.jkiss.dbeaver.model.struct.DBSEntityAttribute; import org.jkiss.dbeaver.model.struct.DBSEntityAttribute;
import org.jkiss.dbeaver.model.struct.rdb.DBSForeignKeyModifyRule;
import org.jkiss.dbeaver.model.virtual.*; import org.jkiss.dbeaver.model.virtual.*;
import org.jkiss.dbeaver.runtime.DBWorkbench; import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.dbeaver.ui.DBeaverIcons; import org.jkiss.dbeaver.ui.DBeaverIcons;
...@@ -41,6 +44,7 @@ import org.jkiss.dbeaver.ui.UIUtils; ...@@ -41,6 +44,7 @@ import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.dialogs.BaseDialog; import org.jkiss.dbeaver.ui.dialogs.BaseDialog;
import org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage; import org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage;
import org.jkiss.dbeaver.ui.editors.object.struct.EditDictionaryPage; import org.jkiss.dbeaver.ui.editors.object.struct.EditDictionaryPage;
import org.jkiss.dbeaver.ui.editors.object.struct.EditForeignKeyPage;
import org.jkiss.utils.CommonUtils; import org.jkiss.utils.CommonUtils;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -50,6 +54,8 @@ class EditVirtualEntityDialog extends BaseDialog { ...@@ -50,6 +54,8 @@ class EditVirtualEntityDialog extends BaseDialog {
private static final Log log = Log.getLog(EditVirtualEntityDialog.class); private static final Log log = Log.getLog(EditVirtualEntityDialog.class);
private static final String DIALOG_ID = "DBeaver.EditVirtualEntityDialog";//$NON-NLS-1$
public static final int ID_CREATE_UNIQUE_KEY = 1000; public static final int ID_CREATE_UNIQUE_KEY = 1000;
public static final int ID_REMOVE_UNIQUE_KEY = 1001; public static final int ID_REMOVE_UNIQUE_KEY = 1001;
public static final int ID_CREATE_FOREIGN_KEY = 2000; public static final int ID_CREATE_FOREIGN_KEY = 2000;
...@@ -63,6 +69,14 @@ class EditVirtualEntityDialog extends BaseDialog { ...@@ -63,6 +69,14 @@ class EditVirtualEntityDialog extends BaseDialog {
private EditDictionaryPage editDictionaryPage; private EditDictionaryPage editDictionaryPage;
private EditConstraintPage editUniqueKeyPage; private EditConstraintPage editUniqueKeyPage;
private DBVEntityConstraint uniqueConstraint; private DBVEntityConstraint uniqueConstraint;
private InitPage initPage = InitPage.ATTRIBUTES;
public enum InitPage {
ATTRIBUTES,
UNIQUE_KEY,
FOREIGN_KEYS,
DICTIONARY,
}
public EditVirtualEntityDialog(ResultSetViewer viewer, @Nullable DBSEntity entity, @NotNull DBVEntity vEntity) { public EditVirtualEntityDialog(ResultSetViewer viewer, @Nullable DBSEntity entity, @NotNull DBVEntity vEntity) {
super(viewer.getControl().getShell(), "Edit logical structure / presentation", null); super(viewer.getControl().getShell(), "Edit logical structure / presentation", null);
...@@ -71,6 +85,20 @@ class EditVirtualEntityDialog extends BaseDialog { ...@@ -71,6 +85,20 @@ class EditVirtualEntityDialog extends BaseDialog {
this.vEntity = vEntity; this.vEntity = vEntity;
} }
@Override
protected IDialogSettings getDialogBoundsSettings()
{
return UIUtils.getDialogSettings(DIALOG_ID);
}
public InitPage getInitPage() {
return initPage;
}
public void setInitPage(InitPage initPage) {
this.initPage = initPage;
}
@Override @Override
protected Composite createDialogArea(Composite parent) protected Composite createDialogArea(Composite parent)
{ {
...@@ -84,7 +112,12 @@ class EditVirtualEntityDialog extends BaseDialog { ...@@ -84,7 +112,12 @@ class EditVirtualEntityDialog extends BaseDialog {
createForeignKeysPage(tabFolder); createForeignKeysPage(tabFolder);
createDictionaryPage(tabFolder); createDictionaryPage(tabFolder);
tabFolder.setSelection(0); for (TabItem item : tabFolder.getItems()) {
if (item.getData() == initPage) {
tabFolder.setSelection(item);
break;
}
}
UIUtils.createInfoLabel(composite, "Entity logical structure is defined on client-side.\nYou can define virtual unique/foreign keys even if physical database\n" + UIUtils.createInfoLabel(composite, "Entity logical structure is defined on client-side.\nYou can define virtual unique/foreign keys even if physical database\n" +
"doesn't have or doesn't support them. Also you can define how to view column values."); "doesn't have or doesn't support them. Also you can define how to view column values.");
...@@ -99,6 +132,7 @@ class EditVirtualEntityDialog extends BaseDialog { ...@@ -99,6 +132,7 @@ class EditVirtualEntityDialog extends BaseDialog {
TabItem dictItem = new TabItem(tabFolder, SWT.NONE); TabItem dictItem = new TabItem(tabFolder, SWT.NONE);
dictItem.setText("Dictionary"); dictItem.setText("Dictionary");
dictItem.setControl(editDictionaryPage.getControl()); dictItem.setControl(editDictionaryPage.getControl());
dictItem.setData(InitPage.DICTIONARY);
} }
} }
...@@ -109,6 +143,7 @@ class EditVirtualEntityDialog extends BaseDialog { ...@@ -109,6 +143,7 @@ class EditVirtualEntityDialog extends BaseDialog {
} }
TabItem ukItem = new TabItem(tabFolder, SWT.NONE); TabItem ukItem = new TabItem(tabFolder, SWT.NONE);
ukItem.setText("Virtual Unique Key"); ukItem.setText("Virtual Unique Key");
ukItem.setData(InitPage.UNIQUE_KEY);
uniqueConstraint = (DBVEntityConstraint) virtualEntityIdentifier.getUniqueKey(); uniqueConstraint = (DBVEntityConstraint) virtualEntityIdentifier.getUniqueKey();
...@@ -122,6 +157,7 @@ class EditVirtualEntityDialog extends BaseDialog { ...@@ -122,6 +157,7 @@ class EditVirtualEntityDialog extends BaseDialog {
private void createForeignKeysPage(TabFolder tabFolder) { private void createForeignKeysPage(TabFolder tabFolder) {
TabItem fkItem = new TabItem(tabFolder, SWT.NONE); TabItem fkItem = new TabItem(tabFolder, SWT.NONE);
fkItem.setText("Virtual Foreign Keys"); fkItem.setText("Virtual Foreign Keys");
fkItem.setData(InitPage.FOREIGN_KEYS);
Composite panel = new Composite(tabFolder, 1); Composite panel = new Composite(tabFolder, 1);
panel.setLayout(new GridLayout(1, false)); panel.setLayout(new GridLayout(1, false));
...@@ -140,7 +176,14 @@ class EditVirtualEntityDialog extends BaseDialog { ...@@ -140,7 +176,14 @@ class EditVirtualEntityDialog extends BaseDialog {
btnAdd.addSelectionListener(new SelectionAdapter() { btnAdd.addSelectionListener(new SelectionAdapter() {
@Override @Override
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
UIUtils.showMessageBox(getShell(), "Not implemented", "Not Implemented Yet", SWT.ICON_ERROR);
DBSEntityAssociation virtualFK = new DBVEntityForeignKey(vEntity);
EditForeignKeyPage editDialog = new EditForeignKeyPage(
"Define virtual foreign keys", virtualFK, new DBSForeignKeyModifyRule[] { DBSForeignKeyModifyRule.NO_ACTION });
if (!editDialog.edit()) {
return;
}
// Save
} }
}); });
Button btnRemove = createButton(buttonsPanel, ID_REMOVE_FOREIGN_KEY, "Remove", false); Button btnRemove = createButton(buttonsPanel, ID_REMOVE_FOREIGN_KEY, "Remove", false);
...@@ -158,6 +201,7 @@ class EditVirtualEntityDialog extends BaseDialog { ...@@ -158,6 +201,7 @@ class EditVirtualEntityDialog extends BaseDialog {
private void createColumnsPage(TabFolder tabFolder) { private void createColumnsPage(TabFolder tabFolder) {
TabItem colItem = new TabItem(tabFolder, SWT.NONE); TabItem colItem = new TabItem(tabFolder, SWT.NONE);
colItem.setText("Columns view"); colItem.setText("Columns view");
colItem.setData(InitPage.ATTRIBUTES);
Composite panel = new Composite(tabFolder, 1); Composite panel = new Composite(tabFolder, 1);
panel.setLayout(new GridLayout(1, false)); panel.setLayout(new GridLayout(1, false));
......
...@@ -103,8 +103,6 @@ import org.jkiss.dbeaver.ui.dialogs.ConfirmationDialog; ...@@ -103,8 +103,6 @@ import org.jkiss.dbeaver.ui.dialogs.ConfirmationDialog;
import org.jkiss.dbeaver.ui.editors.data.internal.DataEditorsMessages; import org.jkiss.dbeaver.ui.editors.data.internal.DataEditorsMessages;
import org.jkiss.dbeaver.ui.editors.data.preferences.PrefPageDataFormat; import org.jkiss.dbeaver.ui.editors.data.preferences.PrefPageDataFormat;
import org.jkiss.dbeaver.ui.editors.data.preferences.PrefPageResultSetMain; import org.jkiss.dbeaver.ui.editors.data.preferences.PrefPageResultSetMain;
import org.jkiss.dbeaver.ui.editors.object.struct.EditConstraintPage;
import org.jkiss.dbeaver.ui.editors.object.struct.EditDictionaryPage;
import org.jkiss.dbeaver.ui.navigator.NavigatorCommands; import org.jkiss.dbeaver.ui.navigator.NavigatorCommands;
import org.jkiss.dbeaver.utils.GeneralUtils; import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.dbeaver.utils.PrefUtils; import org.jkiss.dbeaver.utils.PrefUtils;
...@@ -114,8 +112,8 @@ import org.jkiss.utils.CommonUtils; ...@@ -114,8 +112,8 @@ import org.jkiss.utils.CommonUtils;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.List;
import java.util.*; import java.util.*;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
/** /**
...@@ -3643,6 +3641,12 @@ public class ResultSetViewer extends Viewer ...@@ -3643,6 +3641,12 @@ public class ResultSetViewer extends Viewer
} }
} }
private DBVEntity getVirtualEntity(DBSEntity entity) {
return entity != null ?
DBVUtils.getVirtualEntity(entity, true) :
DBVUtils.getVirtualEntity(getDataContainer(), true);
}
private void checkEntityIdentifiers(ResultSetPersister persister) throws DBException private void checkEntityIdentifiers(ResultSetPersister persister) throws DBException
{ {
...@@ -3707,33 +3711,11 @@ public class ResultSetViewer extends Viewer ...@@ -3707,33 +3711,11 @@ public class ResultSetViewer extends Viewer
} }
} }
boolean editEntityIdentifier(DBRProgressMonitor monitor) throws DBException boolean editEntityIdentifier(DBRProgressMonitor monitor) {
{ EditVirtualEntityDialog dialog = new EditVirtualEntityDialog(
DBDRowIdentifier virtualEntityIdentifier = getVirtualEntityIdentifier(); ResultSetViewer.this, model.getSingleSource(), getVirtualEntity(model.getSingleSource()));
if (virtualEntityIdentifier == null) { dialog.setInitPage(EditVirtualEntityDialog.InitPage.UNIQUE_KEY);
log.warn("No virtual identifier"); return dialog.open() != IDialogConstants.OK_ID;
return false;
}
DBVEntityConstraint constraint = (DBVEntityConstraint) virtualEntityIdentifier.getUniqueKey();
EditConstraintPage page = new EditConstraintPage(
"Define virtual unique identifier",
constraint);
if (!page.edit()) {
return false;
}
Collection<DBSEntityAttribute> uniqueAttrs = page.getSelectedAttributes();
constraint.setAttributes(uniqueAttrs);
virtualEntityIdentifier = getVirtualEntityIdentifier();
if (virtualEntityIdentifier == null) {
log.warn("No virtual identifier defined");
return false;
}
virtualEntityIdentifier.reloadAttributes(monitor, model.getAttributes());
persistConfig();
return true;
} }
private void clearEntityIdentifier(DBRProgressMonitor monitor) throws DBException private void clearEntityIdentifier(DBRProgressMonitor monitor) throws DBException
...@@ -4431,30 +4413,28 @@ public class ResultSetViewer extends Viewer ...@@ -4431,30 +4413,28 @@ public class ResultSetViewer extends Viewer
return; return;
} }
DBSEntity entity = model.isSingleSource() ? model.getSingleSource() : null; DBSEntity entity = model.isSingleSource() ? model.getSingleSource() : null;
DBVEntity vEntity = entity != null ? DBVEntity vEntity = getVirtualEntity(entity);
DBVUtils.getVirtualEntity(entity, true) :
DBVUtils.getVirtualEntity(dataContainer, true);
EditVirtualEntityDialog dialog = new EditVirtualEntityDialog(ResultSetViewer.this, entity, vEntity); EditVirtualEntityDialog dialog = new EditVirtualEntityDialog(ResultSetViewer.this, entity, vEntity);
dialog.setInitPage(EditVirtualEntityDialog.InitPage.ATTRIBUTES);
dialog.open(); dialog.open();
} }
} }
private class DictionaryEditAction extends Action { private class DictionaryEditAction extends Action {
DictionaryEditAction() DictionaryEditAction() {
{
super("Define dictionary"); super("Define dictionary");
} }
@Override @Override
public void run() public void run() {
{ EditVirtualEntityDialog dialog = new EditVirtualEntityDialog(
EditDictionaryPage page = new EditDictionaryPage(model.getSingleSource()); ResultSetViewer.this, model.getSingleSource(), getVirtualEntity(model.getSingleSource()));
page.edit(); dialog.setInitPage(EditVirtualEntityDialog.InitPage.DICTIONARY);
dialog.open();
} }
@Override @Override
public boolean isEnabled() public boolean isEnabled() {
{
final DBSEntity singleSource = model.getSingleSource(); final DBSEntity singleSource = model.getSingleSource();
return singleSource != null; return singleSource != null;
} }
......
...@@ -93,12 +93,8 @@ class ValidateUniqueKeyUsageDialog extends MessageDialogWithToggle { ...@@ -93,12 +93,8 @@ class ValidateUniqueKeyUsageDialog extends MessageDialogWithToggle {
private void editCustomKey() private void editCustomKey()
{ {
// Edit custom key // Edit custom key
try { if (viewer.editEntityIdentifier(new VoidProgressMonitor())) {
if (viewer.editEntityIdentifier(new VoidProgressMonitor())) { super.buttonPressed(IDialogConstants.OK_ID);
super.buttonPressed(IDialogConstants.OK_ID);
}
} catch (DBException e) {
DBWorkbench.getPlatformUI().showError("Virtual key edit", "Error editing virtual key", e);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册