use of org.jkiss.dbeaver.ui.controls.ObjectContainerSelectorPanel in project dbeaver by serge-rider.
the class DatabaseConsumerPageMapping method createControl.
@Override
public void createControl(Composite parent) {
initializeDialogUnits(parent);
final DatabaseConsumerSettings settings = getDatabaseConsumerSettings();
Composite composite = UIUtils.createComposite(parent, 1);
{
// Target container
// Use first source object as cur selection (it's better than nothing)
containerPanel = new ObjectContainerSelectorPanel(composite, getWizard().getProject(), "container.data-transfer.database-consumer", DTMessages.data_transfer_db_consumer_target_container, DTMessages.data_transfer_db_consumer_choose_container) {
@Nullable
@Override
protected DBNNode getSelectedNode() {
DBNNode selectedNode = settings.getContainerNode();
if (selectedNode == null && !settings.getDataMappings().isEmpty()) {
// Use first source object as cur selection (it's better than nothing)
DBSDataContainer firstSource = settings.getDataMappings().keySet().iterator().next();
selectedNode = DBWorkbench.getPlatform().getNavigatorModel().getNodeByObject(firstSource);
while (selectedNode != null) {
if (selectedNode instanceof DBSWrapper && ((DBSWrapper) selectedNode).getObject() instanceof DBSObjectContainer) {
break;
} else {
selectedNode = selectedNode.getParentNode();
}
}
}
return selectedNode;
}
@Override
protected void setSelectedNode(DBNDatabaseNode node) {
settings.setContainerNode(node);
setContainerInfo(node);
// Reset mappings
for (DatabaseMappingContainer mappingContainer : settings.getDataMappings().values()) {
if (mappingContainer.getMappingType() != DatabaseMappingType.unspecified) {
try {
mappingContainer.refreshMappingType(getWizard().getRunnableContext(), DatabaseMappingType.unspecified);
} catch (DBException e1) {
log.error(e1);
}
}
}
mappingViewer.refresh();
updatePageCompletion();
setMessage(null);
}
};
}
Composite mappingsGroup = UIUtils.createComposite(composite, 2);
mappingsGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
createMappingsTree(mappingsGroup);
{
// Control buttons
Composite buttonsPanel = UIUtils.createComposite(mappingsGroup, 1);
buttonsPanel.setLayoutData(new GridData(GridData.FILL_VERTICAL));
autoAssignButton = UIUtils.createDialogButton(buttonsPanel, DTMessages.data_transfer_db_consumer_auto_assign, UIIcon.ASTERISK, DTMessages.data_transfer_db_consumer_auto_assign_description, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
autoAssignMappings();
}
});
UIUtils.createLabelSeparator(buttonsPanel, SWT.HORIZONTAL);
final Button mapTableButton = UIUtils.createDialogButton(buttonsPanel, DTMessages.data_transfer_db_consumer_existing_table, DBIcon.TREE_TABLE, DTMessages.data_transfer_db_consumer_existing_table_description, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
mapExistingTable((DatabaseMappingContainer) getSelectedMapping());
}
});
mapTableButton.setEnabled(false);
final Button createNewButton = UIUtils.createDialogButton(buttonsPanel, DTMessages.data_transfer_db_consumer_new_table, DBIcon.TREE_VIEW, DTMessages.data_transfer_db_consumer_new_table_description, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
mapNewTable((DatabaseMappingContainer) getSelectedMapping());
}
});
createNewButton.setEnabled(false);
final Button columnsButton = UIUtils.createDialogButton(buttonsPanel, DTMessages.data_transfer_db_consumer_column_mappings, DBIcon.TREE_COLUMNS, DTMessages.data_transfer_db_consumer_column_mappings_description, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DatabaseMappingObject selectedMapping = getSelectedMapping();
mapColumns(selectedMapping instanceof DatabaseMappingContainer ? (DatabaseMappingContainer) selectedMapping : ((DatabaseMappingAttribute) selectedMapping).getParent());
}
});
columnsButton.setEnabled(false);
UIUtils.createLabelSeparator(buttonsPanel, SWT.HORIZONTAL);
final Button ddlButton = UIUtils.createDialogButton(buttonsPanel, DTMessages.data_transfer_wizard_page_ddl_name, UIIcon.SQL_TEXT, DTMessages.data_transfer_wizard_page_ddl_description, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DatabaseMappingObject selectedMapping = getSelectedMapping();
showDDL(selectedMapping instanceof DatabaseMappingContainer ? (DatabaseMappingContainer) selectedMapping : ((DatabaseMappingAttribute) selectedMapping).getParent());
}
});
ddlButton.setEnabled(false);
final Button previewButton = UIUtils.createDialogButton(buttonsPanel, DTMessages.data_transfer_wizard_page_preview_name, UIIcon.SQL_PREVIEW, DTMessages.data_transfer_wizard_page_preview_description, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DBPDataSourceContainer dataSourceContainer = getDatabaseConsumerSettings().getContainerNode().getDataSourceContainer();
if (!dataSourceContainer.hasModifyPermission(DBPDataSourcePermission.PERMISSION_EDIT_METADATA)) {
UIUtils.showMessageBox(getShell(), DTMessages.data_transfer_wizard_restricted_title, NLS.bind(DTMessages.data_transfer_wizard_restricted_description, dataSourceContainer.getName()), SWT.ICON_WARNING);
return;
}
DatabaseMappingObject selectedMapping = getSelectedMapping();
showPreview(selectedMapping instanceof DatabaseMappingContainer ? (DatabaseMappingContainer) selectedMapping : ((DatabaseMappingAttribute) selectedMapping).getParent());
}
});
previewButton.setEnabled(false);
mappingViewer.getTree().addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
try {
boolean updated = false;
Object element = null;
if (e.character == SWT.CR) {
// Object element = mappingViewer.getStructuredSelection().getFirstElement();
// mappingViewer.editElement(element, 1);
} else if (e.character == SWT.DEL) {
for (TreeItem item : mappingViewer.getTree().getSelection()) {
element = item.getData();
if (element instanceof DatabaseMappingAttribute) {
DatabaseMappingAttribute attribute = (DatabaseMappingAttribute) element;
attribute.setMappingType(DatabaseMappingType.skip);
} else if (element instanceof DatabaseMappingContainer) {
DatabaseMappingContainer container = (DatabaseMappingContainer) element;
container.refreshMappingType(getWizard().getRunnableContext(), DatabaseMappingType.skip);
}
selectNextColumn(item);
}
updated = true;
} else if (e.character == SWT.SPACE) {
for (TreeItem item : mappingViewer.getTree().getSelection()) {
element = item.getData();
if (element instanceof DatabaseMappingAttribute) {
DatabaseMappingAttribute attribute = (DatabaseMappingAttribute) item.getData();
attribute.setMappingType(DatabaseMappingType.existing);
attribute.updateMappingType(new VoidProgressMonitor());
} else if (element instanceof DatabaseMappingContainer) {
DatabaseMappingContainer container = (DatabaseMappingContainer) element;
setMappingTarget(container, container.getTargetName());
}
selectNextColumn(item);
}
updated = true;
}
if (updated) {
updateMappingsAndButtons();
updatePageCompletion();
if (element instanceof DatabaseMappingContainer) {
// Select next container
@SuppressWarnings("unchecked") List<DatabaseMappingContainer> model = (List<DatabaseMappingContainer>) mappingViewer.getInput();
int curIndex = model.indexOf(element);
if (curIndex < model.size() - 1) {
mappingViewer.setSelection(new StructuredSelection(model.get(curIndex + 1)), true);
}
}
}
} catch (DBException e1) {
DBWorkbench.getPlatformUI().showError(DTUIMessages.database_consumer_page_mapping_title_error_mapping_table, DTUIMessages.database_consumer_page_mapping_message_error_mapping_target_table, e1);
}
}
});
mappingViewer.addSelectionChangedListener(event -> {
DatabaseMappingObject mapping = getSelectedMapping();
mapTableButton.setEnabled(mapping instanceof DatabaseMappingContainer);
createNewButton.setEnabled(mapping instanceof DatabaseMappingContainer && settings.getContainerNode() != null);
final boolean hasMappings = settings.getContainerNode() != null && ((mapping instanceof DatabaseMappingContainer && mapping.getMappingType() != DatabaseMappingType.unspecified) || (mapping instanceof DatabaseMappingAttribute && ((DatabaseMappingAttribute) mapping).getParent().getMappingType() != DatabaseMappingType.unspecified));
columnsButton.setEnabled(hasMappings);
ddlButton.setEnabled(hasMappings);
previewButton.setEnabled(hasMappings);
});
mappingViewer.addDoubleClickListener(event -> {
DatabaseMappingObject selectedMapping = getSelectedMapping();
if (selectedMapping != null) {
if (selectedMapping instanceof DatabaseMappingContainer) {
/*
if (selectedMapping.getMappingType() == DatabaseMappingType.unspecified) {
mapExistingTable((DatabaseMappingContainer) selectedMapping);
} else {
mapColumns((DatabaseMappingContainer) selectedMapping);
}
*/
}
}
});
}
{
Composite hintPanel = new Composite(composite, SWT.NONE);
hintPanel.setLayout(new GridLayout(3, false));
hintPanel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
new Label(hintPanel, SWT.NONE).setText(DTUIMessages.database_consumer_page_mapping_label_hint);
}
setControl(composite);
}
use of org.jkiss.dbeaver.ui.controls.ObjectContainerSelectorPanel in project dbeaver by serge-rider.
the class EditForeignKeyPage method createContainerSelector.
private void createContainerSelector(Composite tableGroup) throws DBException {
ObjectContainerSelectorPanel containerPanel = new ObjectContainerSelectorPanel(tableGroup, foreignKey.getDataSource().getContainer().getRegistry().getProject(), CONTAINER_LOGICAL_FK, "Reference table container", "Select reference table catalog/schema") {
@Nullable
@Override
protected DBNNode getSelectedNode() {
if (ownerContainerNode != null) {
return ownerContainerNode;
}
DBSObject containerObject;
if (ownerTableNode != null) {
DBNNode containerNode = ownerTableNode.getParentNode();
while (containerNode instanceof DBNDatabaseFolder) {
containerNode = containerNode.getParentNode();
}
if (containerNode instanceof DBNDatabaseNode) {
containerObject = ((DBNDatabaseNode) containerNode).getObject();
} else {
containerObject = null;
}
} else {
containerObject = foreignKey.getParentObject();
}
if (containerObject != null && containerObject.getParentObject() instanceof DBSObjectContainer) {
containerObject = containerObject.getParentObject();
}
if (containerObject instanceof DBVContainer) {
try {
containerObject = ((DBVContainer) containerObject).getRealContainer(new VoidProgressMonitor());
} catch (DBException e) {
log.error("Error getting real object container", e);
}
}
return ownerContainerNode = DBWorkbench.getPlatform().getNavigatorModel().getNodeByObject(containerObject);
}
@Override
protected void setSelectedNode(DBNDatabaseNode node) {
ownerContainerNode = node;
if (ownerContainerNode == null) {
setContainerInfo(null);
} else {
setContainerInfo(node);
loadTableList(ownerContainerNode);
}
}
};
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
containerPanel.setLayoutData(gd);
if (ownerTableNode != null) {
DBNNode containerNode = ownerTableNode.getParentNode();
while (containerNode instanceof DBNDatabaseFolder) {
containerNode = containerNode.getParentNode();
}
if (containerNode instanceof DBNDatabaseNode) {
containerPanel.setContainerInfo((DBNDatabaseNode) containerNode);
}
}
}
use of org.jkiss.dbeaver.ui.controls.ObjectContainerSelectorPanel in project dbeaver by dbeaver.
the class DatabaseConsumerPageMapping method createControl.
@Override
public void createControl(Composite parent) {
initializeDialogUnits(parent);
final DatabaseConsumerSettings settings = getDatabaseConsumerSettings();
Composite composite = UIUtils.createComposite(parent, 1);
{
// Target container
// Use first source object as cur selection (it's better than nothing)
containerPanel = new ObjectContainerSelectorPanel(composite, getWizard().getProject(), "container.data-transfer.database-consumer", DTMessages.data_transfer_db_consumer_target_container, DTMessages.data_transfer_db_consumer_choose_container) {
@Nullable
@Override
protected DBNNode getSelectedNode() {
DBNNode selectedNode = settings.getContainerNode();
if (selectedNode == null && !settings.getDataMappings().isEmpty()) {
// Use first source object as cur selection (it's better than nothing)
DBSDataContainer firstSource = settings.getDataMappings().keySet().iterator().next();
selectedNode = DBWorkbench.getPlatform().getNavigatorModel().getNodeByObject(firstSource);
while (selectedNode != null) {
if (selectedNode instanceof DBSWrapper && ((DBSWrapper) selectedNode).getObject() instanceof DBSObjectContainer) {
break;
} else {
selectedNode = selectedNode.getParentNode();
}
}
}
return selectedNode;
}
@Override
protected void setSelectedNode(DBNDatabaseNode node) {
settings.setContainerNode(node);
setContainerInfo(node);
// Reset mappings
for (DatabaseMappingContainer mappingContainer : settings.getDataMappings().values()) {
if (mappingContainer.getMappingType() != DatabaseMappingType.unspecified) {
try {
mappingContainer.refreshMappingType(getWizard().getRunnableContext(), DatabaseMappingType.unspecified);
} catch (DBException e1) {
log.error(e1);
}
}
}
mappingViewer.refresh();
updatePageCompletion();
setMessage(null);
}
};
}
Composite mappingsGroup = UIUtils.createComposite(composite, 2);
mappingsGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
createMappingsTree(mappingsGroup);
{
// Control buttons
Composite buttonsPanel = UIUtils.createComposite(mappingsGroup, 1);
buttonsPanel.setLayoutData(new GridData(GridData.FILL_VERTICAL));
autoAssignButton = UIUtils.createDialogButton(buttonsPanel, DTMessages.data_transfer_db_consumer_auto_assign, UIIcon.ASTERISK, DTMessages.data_transfer_db_consumer_auto_assign_description, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
autoAssignMappings();
}
});
UIUtils.createLabelSeparator(buttonsPanel, SWT.HORIZONTAL);
final Button mapTableButton = UIUtils.createDialogButton(buttonsPanel, DTMessages.data_transfer_db_consumer_existing_table, DBIcon.TREE_TABLE, DTMessages.data_transfer_db_consumer_existing_table_description, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
mapExistingTable((DatabaseMappingContainer) getSelectedMapping());
}
});
mapTableButton.setEnabled(false);
final Button createNewButton = UIUtils.createDialogButton(buttonsPanel, DTMessages.data_transfer_db_consumer_new_table, DBIcon.TREE_VIEW, DTMessages.data_transfer_db_consumer_new_table_description, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
mapNewTable((DatabaseMappingContainer) getSelectedMapping());
}
});
createNewButton.setEnabled(false);
final Button columnsButton = UIUtils.createDialogButton(buttonsPanel, DTMessages.data_transfer_db_consumer_column_mappings, DBIcon.TREE_COLUMNS, DTMessages.data_transfer_db_consumer_column_mappings_description, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DatabaseMappingObject selectedMapping = getSelectedMapping();
mapColumns(selectedMapping instanceof DatabaseMappingContainer ? (DatabaseMappingContainer) selectedMapping : ((DatabaseMappingAttribute) selectedMapping).getParent());
}
});
columnsButton.setEnabled(false);
UIUtils.createLabelSeparator(buttonsPanel, SWT.HORIZONTAL);
final Button ddlButton = UIUtils.createDialogButton(buttonsPanel, DTMessages.data_transfer_wizard_page_ddl_name, UIIcon.SQL_TEXT, DTMessages.data_transfer_wizard_page_ddl_description, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DatabaseMappingObject selectedMapping = getSelectedMapping();
showDDL(selectedMapping instanceof DatabaseMappingContainer ? (DatabaseMappingContainer) selectedMapping : ((DatabaseMappingAttribute) selectedMapping).getParent());
}
});
ddlButton.setEnabled(false);
final Button previewButton = UIUtils.createDialogButton(buttonsPanel, DTMessages.data_transfer_wizard_page_preview_name, UIIcon.SQL_PREVIEW, DTMessages.data_transfer_wizard_page_preview_description, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DBPDataSourceContainer dataSourceContainer = getDatabaseConsumerSettings().getContainerNode().getDataSourceContainer();
if (!dataSourceContainer.hasModifyPermission(DBPDataSourcePermission.PERMISSION_EDIT_METADATA)) {
UIUtils.showMessageBox(getShell(), DTMessages.data_transfer_wizard_restricted_title, NLS.bind(DTMessages.data_transfer_wizard_restricted_description, dataSourceContainer.getName()), SWT.ICON_WARNING);
return;
}
DatabaseMappingObject selectedMapping = getSelectedMapping();
showPreview(selectedMapping instanceof DatabaseMappingContainer ? (DatabaseMappingContainer) selectedMapping : ((DatabaseMappingAttribute) selectedMapping).getParent());
}
});
previewButton.setEnabled(false);
mappingViewer.getTree().addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
try {
boolean updated = false;
Object element = null;
if (e.character == SWT.CR) {
// Object element = mappingViewer.getStructuredSelection().getFirstElement();
// mappingViewer.editElement(element, 1);
} else if (e.character == SWT.DEL) {
for (TreeItem item : mappingViewer.getTree().getSelection()) {
element = item.getData();
if (element instanceof DatabaseMappingAttribute) {
DatabaseMappingAttribute attribute = (DatabaseMappingAttribute) element;
attribute.setMappingType(DatabaseMappingType.skip);
} else if (element instanceof DatabaseMappingContainer) {
DatabaseMappingContainer container = (DatabaseMappingContainer) element;
container.refreshMappingType(getWizard().getRunnableContext(), DatabaseMappingType.skip);
}
selectNextColumn(item);
}
updated = true;
} else if (e.character == SWT.SPACE) {
for (TreeItem item : mappingViewer.getTree().getSelection()) {
element = item.getData();
if (element instanceof DatabaseMappingAttribute) {
DatabaseMappingAttribute attribute = (DatabaseMappingAttribute) item.getData();
attribute.setMappingType(DatabaseMappingType.existing);
attribute.updateMappingType(new VoidProgressMonitor());
} else if (element instanceof DatabaseMappingContainer) {
DatabaseMappingContainer container = (DatabaseMappingContainer) element;
setMappingTarget(container, container.getTargetName());
}
selectNextColumn(item);
}
updated = true;
}
if (updated) {
updateMappingsAndButtons();
updatePageCompletion();
if (element instanceof DatabaseMappingContainer) {
// Select next container
@SuppressWarnings("unchecked") List<DatabaseMappingContainer> model = (List<DatabaseMappingContainer>) mappingViewer.getInput();
int curIndex = model.indexOf(element);
if (curIndex < model.size() - 1) {
mappingViewer.setSelection(new StructuredSelection(model.get(curIndex + 1)), true);
}
}
}
} catch (DBException e1) {
DBWorkbench.getPlatformUI().showError(DTUIMessages.database_consumer_page_mapping_title_error_mapping_table, DTUIMessages.database_consumer_page_mapping_message_error_mapping_target_table, e1);
}
}
});
mappingViewer.addSelectionChangedListener(event -> {
DatabaseMappingObject mapping = getSelectedMapping();
mapTableButton.setEnabled(mapping instanceof DatabaseMappingContainer);
createNewButton.setEnabled(mapping instanceof DatabaseMappingContainer && settings.getContainerNode() != null);
final boolean hasMappings = settings.getContainerNode() != null && ((mapping instanceof DatabaseMappingContainer && mapping.getMappingType() != DatabaseMappingType.unspecified) || (mapping instanceof DatabaseMappingAttribute && ((DatabaseMappingAttribute) mapping).getParent().getMappingType() != DatabaseMappingType.unspecified));
columnsButton.setEnabled(hasMappings);
ddlButton.setEnabled(hasMappings);
previewButton.setEnabled(hasMappings);
});
mappingViewer.addDoubleClickListener(event -> {
DatabaseMappingObject selectedMapping = getSelectedMapping();
if (selectedMapping != null) {
if (selectedMapping instanceof DatabaseMappingContainer) {
/*
if (selectedMapping.getMappingType() == DatabaseMappingType.unspecified) {
mapExistingTable((DatabaseMappingContainer) selectedMapping);
} else {
mapColumns((DatabaseMappingContainer) selectedMapping);
}
*/
}
}
});
}
{
Composite hintPanel = new Composite(composite, SWT.NONE);
hintPanel.setLayout(new GridLayout(3, false));
hintPanel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
new Label(hintPanel, SWT.NONE).setText(DTUIMessages.database_consumer_page_mapping_label_hint);
}
setControl(composite);
}
use of org.jkiss.dbeaver.ui.controls.ObjectContainerSelectorPanel in project dbeaver by dbeaver.
the class EditForeignKeyPage method createContainerSelector.
private void createContainerSelector(Composite tableGroup) throws DBException {
ObjectContainerSelectorPanel containerPanel = new ObjectContainerSelectorPanel(tableGroup, foreignKey.getDataSource().getContainer().getRegistry().getProject(), CONTAINER_LOGICAL_FK, "Reference table container", "Select reference table catalog/schema") {
@Nullable
@Override
protected DBNNode getSelectedNode() {
if (ownerContainerNode != null) {
return ownerContainerNode;
}
DBSObject containerObject;
if (ownerTableNode != null) {
DBNNode containerNode = ownerTableNode.getParentNode();
while (containerNode instanceof DBNDatabaseFolder) {
containerNode = containerNode.getParentNode();
}
if (containerNode instanceof DBNDatabaseNode) {
containerObject = ((DBNDatabaseNode) containerNode).getObject();
} else {
containerObject = null;
}
} else {
containerObject = foreignKey.getParentObject();
}
if (containerObject != null && containerObject.getParentObject() instanceof DBSObjectContainer) {
containerObject = containerObject.getParentObject();
}
if (containerObject instanceof DBVContainer) {
try {
containerObject = ((DBVContainer) containerObject).getRealContainer(new VoidProgressMonitor());
} catch (DBException e) {
log.error("Error getting real object container", e);
}
}
return ownerContainerNode = DBWorkbench.getPlatform().getNavigatorModel().getNodeByObject(containerObject);
}
@Override
protected void setSelectedNode(DBNDatabaseNode node) {
ownerContainerNode = node;
if (ownerContainerNode == null) {
setContainerInfo(null);
} else {
setContainerInfo(node);
loadTableList(ownerContainerNode);
}
}
};
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
containerPanel.setLayoutData(gd);
if (ownerTableNode != null) {
DBNNode containerNode = ownerTableNode.getParentNode();
while (containerNode instanceof DBNDatabaseFolder) {
containerNode = containerNode.getParentNode();
}
if (containerNode instanceof DBNDatabaseNode) {
containerPanel.setContainerInfo((DBNDatabaseNode) containerNode);
}
}
}
Aggregations