use of org.jkiss.dbeaver.ui.controls.ListContentProvider in project dbeaver by serge-rider.
the class NodeListControl method createContentProvider.
private static IContentProvider createContentProvider(DBNNode node, DBXTreeNode metaNode) {
if (node instanceof DBNDatabaseNode) {
final DBNDatabaseNode dbNode = (DBNDatabaseNode) node;
if (metaNode == null) {
metaNode = dbNode.getMeta();
}
final List<DBXTreeNode> inlineMetas = collectInlineMetas(dbNode, metaNode);
if (!inlineMetas.isEmpty()) {
return new TreeContentProvider() {
@Override
public boolean hasChildren(Object parentElement) {
return parentElement instanceof DBNDatabaseNode && ((DBNDatabaseNode) parentElement).hasChildren(false);
}
@Override
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof DBNDatabaseNode) {
try {
// Read children with void progress monitor because inline children SHOULD be already cached
DBNNode[] children = DBNUtils.getNodeChildrenFiltered(new VoidProgressMonitor(), (DBNDatabaseNode) parentElement, false);
if (ArrayUtils.isEmpty(children)) {
return null;
} else {
return children;
}
} catch (DBException e) {
log.error(e);
}
}
return null;
}
};
}
}
return new ListContentProvider();
}
use of org.jkiss.dbeaver.ui.controls.ListContentProvider in project dbeaver by serge-rider.
the class PostgreCreateExtensionDialog method createDialogArea.
@Override
protected Composite createDialogArea(Composite parent) {
final Composite composite = super.createDialogArea(parent);
final Composite group = new Composite(composite, SWT.NONE);
group.setLayout(new GridLayout(2, false));
GridData gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 600;
gd.heightHint = 200;
gd.verticalIndent = 0;
gd.horizontalIndent = 0;
group.setLayoutData(gd);
// $NON-NLS-2$
final Text databaseText = UIUtils.createLabelText(group, PostgreMessages.dialog_create_extension_database, newextension.getDatabase().getName(), SWT.BORDER | SWT.READ_ONLY);
final Combo schemaCombo = UIUtils.createLabelCombo(group, PostgreMessages.dialog_create_extension_schema, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
final Label lblExtension = UIUtils.createLabel(group, PostgreMessages.dialog_create_extension_name);
extTable = new TableViewer(group, SWT.BORDER | SWT.UNDERLINE_SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION);
{
final Table table = extTable.getTable();
table.setLayoutData(new GridData(GridData.FILL_BOTH));
table.setLinesVisible(true);
table.setHeaderVisible(true);
table.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
UIUtils.packColumns(table);
UIUtils.maxTableColumnsWidth(table);
table.removeControlListener(this);
}
});
}
ViewerColumnController columnController = new ViewerColumnController("AvailabelExtensionDialog", extTable);
columnController.addColumn(PostgreMessages.dialog_create_extension_column_name, null, SWT.NONE, true, true, new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
cell.setText(((PostgreAvailableExtension) cell.getElement()).getName());
}
});
columnController.addColumn(PostgreMessages.dialog_create_extension_column_version, null, SWT.NONE, true, true, new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
cell.setText(((PostgreAvailableExtension) cell.getElement()).getVersion());
}
});
columnController.addColumn(PostgreMessages.dialog_create_extension_column_description, null, SWT.NONE, true, true, new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
cell.setText(((PostgreAvailableExtension) cell.getElement()).getDescription());
}
});
columnController.createColumns();
extTable.addSelectionChangedListener(event -> {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
if (!selection.isEmpty()) {
// installed.get(extensionCombo.getSelectionIndex());
extension = (PostgreAvailableExtension) selection.getFirstElement();
checkEnabled();
}
});
extTable.setContentProvider(new ListContentProvider());
schemaCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
schema = allSchemas.get(schemaCombo.getSelectionIndex());
checkEnabled();
}
});
new AbstractJob("Load schemas") {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
allSchemas = new ArrayList<>(newextension.getDatabase().getSchemas(monitor));
UIUtils.syncExec(() -> {
for (PostgreSchema schema : allSchemas) {
schemaCombo.add(schema.getName());
}
schema = DBUtils.findObject(allSchemas, PostgreConstants.PUBLIC_SCHEMA_NAME);
if (schema != null) {
schemaCombo.setText(schema.getName());
}
});
} catch (DBException e) {
return GeneralUtils.makeExceptionStatus(e);
}
return Status.OK_STATUS;
}
}.schedule();
new AbstractJob("Load available extensions") {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
final List<PostgreAvailableExtension> installed = new ArrayList<>(newextension.getDatabase().getAvailableExtensions(monitor));
UIUtils.syncExec(() -> {
extTable.setInput(installed);
});
} catch (DBException e) {
return GeneralUtils.makeExceptionStatus(e);
}
return Status.OK_STATUS;
}
}.schedule();
return composite;
}
use of org.jkiss.dbeaver.ui.controls.ListContentProvider in project dbeaver by serge-rider.
the class DashboardAddDialog method createDialogArea.
@Override
protected Composite createDialogArea(Composite parent) {
Composite dialogArea = super.createDialogArea(parent);
// AdvancedListViewer listViewer = new AdvancedListViewer(dialogArea, SWT.NONE);
// listViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
TableViewer dashboardTable = new TableViewer(dialogArea, SWT.BORDER | SWT.FULL_SELECTION);
dashboardTable.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
Table table = dashboardTable.getTable();
GridData gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 400;
gd.heightHint = 200;
table.setLayoutData(gd);
table.setHeaderVisible(true);
UIUtils.createTableColumn(table, SWT.LEFT, UIDashboardMessages.dialog_add_dashboard_column_name);
UIUtils.createTableColumn(table, SWT.LEFT, UIDashboardMessages.dialog_add_dashboard_column_description);
dashboardTable.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
DashboardDescriptor dashboardDescriptor = (DashboardDescriptor) cell.getElement();
if (cell.getColumnIndex() == 0) {
cell.setText(dashboardDescriptor.getName());
} else {
cell.setText(CommonUtils.notEmpty(dashboardDescriptor.getDescription()));
}
}
});
dashboardTable.addDoubleClickListener(event -> {
if (!dashboardTable.getSelection().isEmpty()) {
okPressed();
}
});
dashboardTable.addSelectionChangedListener(event -> {
ISelection selection = dashboardTable.getSelection();
getButton(IDialogConstants.OK_ID).setEnabled(!selection.isEmpty());
if (selection instanceof IStructuredSelection) {
selectedDashboard = (DashboardDescriptor) ((IStructuredSelection) selection).getFirstElement();
}
getButton(IDialogConstants.OK_ID).setEnabled(selectedDashboard != null);
});
table.addPaintListener(e -> {
if (table.getItemCount() == 0) {
final String dbmsName = viewConfiguration.getDataSourceContainer().getDriver().getName();
final String msg = NLS.bind(UIDashboardMessages.dialog_add_dashboard_message_no_more_dashboards_for, dbmsName);
UIUtils.drawMessageOverControl(table, e, msg, 0);
}
});
dashboardTable.setContentProvider(new ListContentProvider());
java.util.List<DashboardDescriptor> dashboards = new ArrayList<>(DashboardRegistry.getInstance().getDashboards(viewConfiguration.getDataSourceContainer(), false));
dashboards.removeIf(descriptor -> viewConfiguration.getDashboardConfig(descriptor.getId()) != null);
dashboardTable.setInput(dashboards);
UIUtils.asyncExec(() -> UIUtils.packColumns(table, true));
return dialogArea;
}
use of org.jkiss.dbeaver.ui.controls.ListContentProvider in project dbeaver by dbeaver.
the class SQLScriptTaskPageSettings method createControl.
@Override
public void createControl(Composite parent) {
initializeDialogUnits(parent);
Composite composite = UIUtils.createComposite(parent, 1);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
SQLScriptExecuteSettings dtSettings = getWizard().getSettings();
SashForm mainGroup = new SashForm(composite, SWT.NONE);
mainGroup.setSashWidth(5);
mainGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
DBNProject projectNode = DBWorkbench.getPlatform().getNavigatorModel().getRoot().getProjectNode(sqlWizard.getProject());
{
Composite filesGroup = UIUtils.createControlGroup(mainGroup, DTMessages.sql_script_task_page_settings_group_files, 2, GridData.FILL_BOTH, 0);
scriptsViewer = new TableViewer(filesGroup, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
scriptsViewer.setContentProvider(new ListContentProvider());
scriptsViewer.getTable().setHeaderVisible(true);
scriptsViewer.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return ((DBNResource) element).getResource().getProjectRelativePath().toString();
}
@Override
public Image getImage(Object element) {
return DBeaverIcons.getImage(((DBNResource) element).getNodeIconDefault());
}
});
scriptsViewer.addDoubleClickListener(event -> {
StructuredSelection selection = (StructuredSelection) event.getSelection();
IResource resource = ((DBNResource) selection.getFirstElement()).getResource();
if (resource != null) {
DBPResourceHandler handler = DBWorkbench.getPlatform().getWorkspace().getResourceHandler(resource);
if (handler != null) {
try {
handler.openResource(resource);
} catch (Exception e) {
log.error("Failed to open resource " + resource, e);
}
}
}
});
// GridData gd = new GridData(GridData.FILL_BOTH);
// gd.heightHint = 300;
// gd.widthHint = 400;
// scriptsViewer.getTable().setLayoutData(gd);
SQLScriptTaskScriptSelectorDialog.createScriptColumns(scriptsViewer);
final Table scriptTable = scriptsViewer.getTable();
scriptTable.setLayoutData(new GridData(GridData.FILL_BOTH));
ToolBar buttonsToolbar = new ToolBar(filesGroup, SWT.VERTICAL);
buttonsToolbar.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_add_script, UIIcon.ROW_ADD, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
SQLScriptTaskScriptSelectorDialog dialog = new SQLScriptTaskScriptSelectorDialog(getShell(), projectNode);
if (dialog.open() == IDialogConstants.OK_ID) {
for (DBNResource script : dialog.getSelectedScripts()) {
if (!selectedScripts.contains(script)) {
selectedScripts.add(script);
}
}
refreshScripts();
}
}
});
ToolItem deleteItem = UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_remove_script, UIIcon.ROW_DELETE, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ISelection selection = scriptsViewer.getSelection();
if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
for (Object element : ((IStructuredSelection) selection).toArray()) {
if (element instanceof DBNResource) {
selectedScripts.remove(element);
}
}
refreshScripts();
}
}
});
UIUtils.createToolBarSeparator(buttonsToolbar, SWT.HORIZONTAL);
ToolItem moveUpItem = UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_move_script_up, UIIcon.ARROW_UP, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int selectionIndex = scriptTable.getSelectionIndex();
if (selectionIndex > 0) {
DBNResource prevScript = selectedScripts.get(selectionIndex - 1);
selectedScripts.set(selectionIndex - 1, selectedScripts.get(selectionIndex));
selectedScripts.set(selectionIndex, prevScript);
refreshScripts();
}
}
});
ToolItem moveDownItem = UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_move_script_down, UIIcon.ARROW_DOWN, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int selectionIndex = scriptTable.getSelectionIndex();
if (selectionIndex < scriptTable.getItemCount() - 1) {
DBNResource nextScript = selectedScripts.get(selectionIndex + 1);
selectedScripts.set(selectionIndex + 1, selectedScripts.get(selectionIndex));
selectedScripts.set(selectionIndex, nextScript);
refreshScripts();
}
}
});
scriptsViewer.addSelectionChangedListener(event -> {
int selectionIndex = scriptTable.getSelectionIndex();
deleteItem.setEnabled(selectionIndex >= 0);
moveUpItem.setEnabled(selectionIndex > 0);
moveDownItem.setEnabled(selectionIndex < scriptTable.getItemCount() - 1);
});
deleteItem.setEnabled(false);
}
{
Composite connectionsGroup = UIUtils.createControlGroup(mainGroup, DTMessages.sql_script_task_page_settings_group_connections, 2, GridData.FILL_BOTH, 0);
dataSourceViewer = new TableViewer(connectionsGroup, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
dataSourceViewer.setContentProvider(new ListContentProvider());
// dataSourceViewer.getTable().setHeaderVisible(true);
dataSourceViewer.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return ((DBNDataSource) element).getNodeName();
}
@Override
public Image getImage(Object element) {
return DBeaverIcons.getImage(((DBNDataSource) element).getNodeIcon());
}
});
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 300;
gd.widthHint = 400;
dataSourceViewer.getTable().setLayoutData(gd);
final Table dsTable = dataSourceViewer.getTable();
dsTable.setLayoutData(new GridData(GridData.FILL_BOTH));
ToolBar buttonsToolbar = new ToolBar(connectionsGroup, SWT.VERTICAL);
buttonsToolbar.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_add_data_source, UIIcon.ROW_ADD, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
SQLScriptTaskDataSourceSelectorDialog dialog = new SQLScriptTaskDataSourceSelectorDialog(getShell(), projectNode);
if (dialog.open() == IDialogConstants.OK_ID) {
for (DBNDataSource ds : dialog.getSelectedDataSources()) {
if (!selectedDataSources.contains(ds)) {
selectedDataSources.add(ds);
}
}
refreshDataSources();
updatePageCompletion();
}
}
});
ToolItem deleteItem = UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_remove_data_source, UIIcon.ROW_DELETE, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ISelection selection = dataSourceViewer.getSelection();
if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
for (Object element : ((IStructuredSelection) selection).toArray()) {
if (element instanceof DBNDataSource) {
selectedDataSources.remove(element);
}
}
refreshDataSources();
updatePageCompletion();
}
}
});
UIUtils.createToolBarSeparator(buttonsToolbar, SWT.HORIZONTAL);
ToolItem moveUpItem = UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_move_data_source_up, UIIcon.ARROW_UP, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int selectionIndex = dsTable.getSelectionIndex();
if (selectionIndex > 0) {
DBNDataSource prevScript = selectedDataSources.get(selectionIndex - 1);
selectedDataSources.set(selectionIndex - 1, selectedDataSources.get(selectionIndex));
selectedDataSources.set(selectionIndex, prevScript);
refreshDataSources();
}
}
});
ToolItem moveDownItem = UIUtils.createToolItem(buttonsToolbar, DTUIMessages.sql_script_task_page_settings_tool_item_text_move_data_source_down, UIIcon.ARROW_DOWN, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int selectionIndex = dsTable.getSelectionIndex();
if (selectionIndex < dsTable.getItemCount() - 1) {
DBNDataSource nextScript = selectedDataSources.get(selectionIndex + 1);
selectedDataSources.set(selectionIndex + 1, selectedDataSources.get(selectionIndex));
selectedDataSources.set(selectionIndex, nextScript);
refreshScripts();
}
}
});
dataSourceViewer.addSelectionChangedListener(event -> {
int selectionIndex = dsTable.getSelectionIndex();
deleteItem.setEnabled(selectionIndex >= 0);
moveUpItem.setEnabled(selectionIndex > 0);
moveDownItem.setEnabled(selectionIndex < dsTable.getItemCount() - 1);
});
deleteItem.setEnabled(false);
}
{
Composite settingsGroup = UIUtils.createControlGroup(composite, DTMessages.sql_script_task_page_settings_group_script, 3, GridData.HORIZONTAL_ALIGN_BEGINNING, 0);
ignoreErrorsCheck = UIUtils.createCheckbox(settingsGroup, DTMessages.sql_script_task_page_settings_option_ignore_errors, "", dtSettings.isIgnoreErrors(), 1);
dumpQueryCheck = UIUtils.createCheckbox(settingsGroup, DTMessages.sql_script_task_page_settings_option_dump_results, "", dtSettings.isDumpQueryResultsToLog(), 1);
dumpQueryCheck.setEnabled(false);
autoCommitCheck = UIUtils.createCheckbox(settingsGroup, DTMessages.sql_script_task_page_settings_option_auto_commit, "", dtSettings.isAutoCommit(), 1);
}
getWizard().createTaskSaveButtons(composite, true, 1);
loadSettings();
setControl(composite);
}
use of org.jkiss.dbeaver.ui.controls.ListContentProvider in project dbeaver by dbeaver.
the class ColumnsMappingDialog method createDialogArea.
@Override
protected Composite createDialogArea(Composite parent) {
DBPDataSource targetDataSource = settings.getTargetDataSource(mapping);
boldFont = UIUtils.makeBoldFont(parent.getFont());
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(2, false));
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
DBPDataSource sourceDataSource = mapping.getSource().getDataSource();
UIUtils.createLabelText(composite, DTUIMessages.columns_mapping_dialog_composite_label_text_source_container, sourceDataSource == null ? "" : sourceDataSource.getContainer().getName(), SWT.BORDER | SWT.READ_ONLY);
Text sourceEntity = UIUtils.createLabelText(composite, DTUIMessages.columns_mapping_dialog_composite_label_text_source_entity, DBUtils.getObjectFullName(mapping.getSource(), DBPEvaluationContext.UI), SWT.BORDER | SWT.READ_ONLY | SWT.MULTI | SWT.V_SCROLL);
((GridData) sourceEntity.getLayoutData()).widthHint = 600;
((GridData) sourceEntity.getLayoutData()).heightHint = UIUtils.getFontHeight(sourceEntity) * 3;
UIUtils.createLabelText(composite, DTUIMessages.columns_mapping_dialog_composite_label_text_target_container, (targetDataSource == null ? "?" : targetDataSource.getContainer().getName()), SWT.BORDER | SWT.READ_ONLY);
Text targetEntity = UIUtils.createLabelText(composite, DTUIMessages.columns_mapping_dialog_composite_label_text_target_entity, mapping.getTargetName(), SWT.BORDER | SWT.READ_ONLY);
((GridData) targetEntity.getLayoutData()).widthHint = 600;
((GridData) targetEntity.getLayoutData()).heightHint = UIUtils.getFontHeight(sourceEntity) * 3;
mappingViewer = new TableViewer(composite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 600;
gd.heightHint = 300;
gd.horizontalSpan = 2;
mappingViewer.getTable().setLayoutData(gd);
mappingViewer.getTable().setLinesVisible(true);
mappingViewer.getTable().setHeaderVisible(true);
mappingViewer.setContentProvider(new ListContentProvider());
mappingViewer.getTable().addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.character == SWT.DEL) {
for (TableItem item : mappingViewer.getTable().getSelection()) {
DatabaseMappingAttribute attribute = (DatabaseMappingAttribute) item.getData();
attribute.setMappingType(DatabaseMappingType.skip);
}
mappingViewer.refresh();
} else if (e.character == SWT.SPACE) {
for (TableItem item : mappingViewer.getTable().getSelection()) {
DatabaseMappingAttribute attribute = (DatabaseMappingAttribute) item.getData();
attribute.setMappingType(DatabaseMappingType.existing);
try {
attribute.updateMappingType(new VoidProgressMonitor());
} catch (DBException e1) {
DBWorkbench.getPlatformUI().showError("Bad mapping", "Invalid column mapping", e1);
}
}
mappingViewer.refresh();
}
}
});
{
TableViewerColumn columnSource = new TableViewerColumn(mappingViewer, SWT.LEFT);
columnSource.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
DatabaseMappingAttribute attrMapping = (DatabaseMappingAttribute) cell.getElement();
cell.setText(DBUtils.getObjectFullName(attrMapping.getSource(), DBPEvaluationContext.UI));
if (attrMapping.getIcon() != null) {
cell.setImage(DBeaverIcons.getImage(attrMapping.getIcon()));
}
}
});
columnSource.getColumn().setText(DTUIMessages.columns_mapping_dialog_column_source_text);
columnSource.getColumn().setWidth(170);
}
{
TableViewerColumn columnSourceType = new TableViewerColumn(mappingViewer, SWT.LEFT);
columnSourceType.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
cell.setText(((DatabaseMappingAttribute) cell.getElement()).getSourceType());
}
});
columnSourceType.getColumn().setText(DTUIMessages.columns_mapping_dialog_column_source_type_text);
columnSourceType.getColumn().setWidth(100);
}
{
TableViewerColumn columnTarget = new TableViewerColumn(mappingViewer, SWT.LEFT);
columnTarget.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
DatabaseMappingAttribute mapping = (DatabaseMappingAttribute) cell.getElement();
cell.setText(mapping.getTargetName());
if (mapping.getMappingType() == DatabaseMappingType.unspecified) {
cell.setBackground(UIUtils.getSharedTextColors().getColor(SharedTextColors.COLOR_WARNING));
} else {
cell.setBackground(null);
}
cell.setFont(boldFont);
}
});
columnTarget.getColumn().setText(DTUIMessages.columns_mapping_dialog_column_target_text);
columnTarget.getColumn().setWidth(170);
columnTarget.setEditingSupport(new EditingSupport(mappingViewer) {
@Override
protected CellEditor getCellEditor(Object element) {
try {
java.util.List<String> items = new ArrayList<>();
DatabaseMappingAttribute mapping = (DatabaseMappingAttribute) element;
if (mapping.getParent().getMappingType() == DatabaseMappingType.existing && mapping.getParent().getTarget() instanceof DBSEntity) {
DBSEntity parentEntity = (DBSEntity) mapping.getParent().getTarget();
for (DBSEntityAttribute attr : CommonUtils.safeCollection(parentEntity.getAttributes(new VoidProgressMonitor()))) {
items.add(attr.getName());
}
}
items.add(DatabaseMappingAttribute.TARGET_NAME_SKIP);
return new CustomComboBoxCellEditor(mappingViewer, mappingViewer.getTable(), items.toArray(new String[0]), SWT.DROP_DOWN);
} catch (DBException e) {
DBWorkbench.getPlatformUI().showError("Bad value", "Wrong target column", e);
return null;
}
}
@Override
protected boolean canEdit(Object element) {
return true;
}
@Override
protected Object getValue(Object element) {
return ((DatabaseMappingAttribute) element).getTargetName();
}
@Override
protected void setValue(Object element, Object value) {
try {
String name = CommonUtils.toString(value);
DatabaseMappingAttribute attrMapping = (DatabaseMappingAttribute) element;
if (DatabaseMappingAttribute.TARGET_NAME_SKIP.equals(name)) {
attrMapping.setMappingType(DatabaseMappingType.skip);
} else {
if (attrMapping.getParent().getMappingType() == DatabaseMappingType.existing && attrMapping.getParent().getTarget() instanceof DBSEntity) {
DBSEntity parentEntity = (DBSEntity) attrMapping.getParent().getTarget();
for (DBSEntityAttribute attr : CommonUtils.safeCollection(parentEntity.getAttributes(new VoidProgressMonitor()))) {
if (name.equalsIgnoreCase(attr.getName())) {
attrMapping.setTarget(attr);
attrMapping.setMappingType(DatabaseMappingType.existing);
attrMapping.setTargetName(name);
return;
}
}
}
attrMapping.setMappingType(DatabaseMappingType.create);
attrMapping.setTargetName(name);
}
} catch (DBException e) {
DBWorkbench.getPlatformUI().showError("Bad value", "Wrong target", e);
} finally {
mappingViewer.refresh();
}
}
});
}
{
TableViewerColumn columnTargetType = new TableViewerColumn(mappingViewer, SWT.LEFT);
columnTargetType.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
DatabaseMappingAttribute attrMapping = (DatabaseMappingAttribute) cell.getElement();
DBPDataSource dataSource = settings.getTargetDataSource(attrMapping);
cell.setText(attrMapping.getTargetType(dataSource, true));
cell.setFont(boldFont);
}
});
columnTargetType.getColumn().setText(DTUIMessages.columns_mapping_dialog_column_target_type_text);
columnTargetType.getColumn().setWidth(100);
columnTargetType.setEditingSupport(new EditingSupport(mappingViewer) {
@Override
protected CellEditor getCellEditor(Object element) {
DatabaseMappingAttribute attrMapping = (DatabaseMappingAttribute) element;
Set<String> types = new TreeSet<>();
DBPDataSource dataSource = settings.getTargetDataSource(attrMapping);
if (dataSource instanceof DBPDataTypeProvider) {
for (DBSDataType type : ((DBPDataTypeProvider) dataSource).getLocalDataTypes()) {
types.add(type.getName());
}
}
types.add(attrMapping.getTargetType(dataSource, true));
return new CustomComboBoxCellEditor(mappingViewer, mappingViewer.getTable(), types.toArray(new String[0]), SWT.BORDER);
}
@Override
protected boolean canEdit(Object element) {
return true;
}
@Override
protected Object getValue(Object element) {
DatabaseMappingAttribute attrMapping = (DatabaseMappingAttribute) element;
return attrMapping.getTargetType(settings.getTargetDataSource(attrMapping), true);
}
@Override
protected void setValue(Object element, Object value) {
DatabaseMappingAttribute attrMapping = (DatabaseMappingAttribute) element;
attrMapping.setTargetType(CommonUtils.toString(value));
mappingViewer.refresh(element);
}
});
}
{
TableViewerColumn columnType = new TableViewerColumn(mappingViewer, SWT.LEFT);
columnType.setLabelProvider(new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
DatabaseMappingAttribute mapping = (DatabaseMappingAttribute) cell.getElement();
String text = "";
switch(mapping.getMappingType()) {
case unspecified:
text = "?";
break;
case existing:
text = DTUIMessages.columns_mapping_dialog_cell_text_existing;
break;
case create:
text = DTUIMessages.columns_mapping_dialog_cell_text_new;
break;
case skip:
text = DTUIMessages.columns_mapping_dialog_cell_text_skip;
break;
}
cell.setText(text);
}
});
columnType.getColumn().setText(DTUIMessages.columns_mapping_dialog_column_type_text_mapping);
columnType.getColumn().setWidth(60);
}
mappingViewer.setInput(attributeMappings);
return parent;
}
Aggregations