use of org.jkiss.dbeaver.ui.controls.ListContentProvider in project dbeaver by dbeaver.
the class DataTransferPagePipes method createInputsTable.
private void createInputsTable(Composite composite) {
Composite panel = UIUtils.createComposite(composite, 1);
// UIUtils.createControlLabel(panel, DTUIMessages.data_transfer_wizard_final_group_objects);
inputsTable = new TableViewer(panel, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
inputsTable.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
inputsTable.getTable().setLinesVisible(true);
inputsTable.getTable().setHeaderVisible(true);
inputsTable.setContentProvider(new ListContentProvider());
UIUtils.createTableContextMenu(inputsTable.getTable(), null);
DBNModel nModel = DBWorkbench.getPlatform().getNavigatorModel();
CellLabelProvider labelProvider = new CellLabelProvider() {
@Override
public void update(ViewerCell cell) {
DBSObject element = (DBSObject) cell.getElement();
if (cell.getColumnIndex() == 0) {
DBNDatabaseNode objectNode = nModel.getNodeByObject(element);
DBPImage icon = objectNode != null ? objectNode.getNodeIconDefault() : DBValueFormatting.getObjectImage(element);
cell.setImage(DBeaverIcons.getImage(icon));
cell.setText(DBUtils.getObjectFullName(element, DBPEvaluationContext.UI));
} else if (element.getDescription() != null) {
cell.setText(element.getDescription());
}
}
};
{
TableViewerColumn columnName = new TableViewerColumn(inputsTable, SWT.LEFT);
columnName.setLabelProvider(labelProvider);
columnName.getColumn().setText(DTMessages.data_transfer_wizard_init_column_exported);
TableViewerColumn columnDesc = new TableViewerColumn(inputsTable, SWT.LEFT);
columnDesc.setLabelProvider(labelProvider);
columnDesc.getColumn().setText(DTMessages.data_transfer_wizard_init_column_description);
}
}
use of org.jkiss.dbeaver.ui.controls.ListContentProvider in project dbeaver by dbeaver.
the class SQLToolTaskWizardPageStatus method createControl.
@Override
public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.BORDER);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
composite.setLayout(new FillLayout());
SashForm partDivider = new SashForm(composite, SWT.VERTICAL);
partDivider.setSashWidth(5);
statusTable = new ObjectListControl<SQLToolStatistics>(partDivider, SWT.SHEET, new ListContentProvider()) {
@NotNull
@Override
protected String getListConfigId(List<Class<?>> classList) {
return "SQLToolStatus." + getWizard().getTaskType().getId();
}
@Override
protected DBPImage getObjectImage(SQLToolStatistics item) {
return DBValueFormatting.getObjectImage(item.getObject());
}
@Override
protected LoadingJob<Collection<SQLToolStatistics>> createLoadService() {
return LoadingJob.createService(new DummyLoadService(), new ObjectsLoadVisualizer());
}
};
console = new MessageConsole(TasksSQLUIMessages.sql_tool_task_wizard_page_status_message_console_name_tool_log, null);
LogConsoleViewer consoleViewer = new LogConsoleViewer(partDivider);
console.setWaterMarks(1024 * 1024 * 3, 1024 * 1024 * 4);
try {
writer = new PrintStream(console.newMessageStream(), true, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
writer = new PrintStream(console.newMessageStream(), true);
}
setControl(composite);
}
use of org.jkiss.dbeaver.ui.controls.ListContentProvider in project dbeaver by dbeaver.
the class ObjectACLEditor method createPartControl.
public void createPartControl(Composite parent) {
this.pageControl = new PageControl(parent);
SashForm composite = UIUtils.createPartDivider(getSite().getPart(), this.pageControl, SWT.HORIZONTAL);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
roleOrObjectTable = new DatabaseNavigatorTree(composite, DBWorkbench.getPlatform().getNavigatorModel().getRoot(), SWT.MULTI | SWT.FULL_SELECTION, false, isRoleEditor() ? new DatabaseObjectFilter() : null);
roleOrObjectTable.setLayoutData(new GridData(GridData.FILL_BOTH));
final TreeViewer treeViewer = roleOrObjectTable.getViewer();
treeViewer.setLabelProvider(new DatabaseNavigatorLabelProvider(treeViewer) {
@Override
public Font getFont(Object element) {
if (element instanceof DBNDatabaseNode) {
DBSObject object = ((DBNDatabaseNode) element).getObject();
if (object instanceof DBSSchema) {
String schemaPrefix = DBUtils.getQuotedIdentifier(object) + ".";
for (String tableName : privilegeMap.keySet()) {
if (tableName.startsWith(schemaPrefix)) {
return boldFont;
}
}
} else if (getObjectPermissions(object) != null) {
return boldFont;
}
}
return null;
}
});
treeViewer.addSelectionChangedListener(event -> handleSelectionChange());
treeViewer.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof DBNNode && !(element instanceof DBNDatabaseNode)) {
return false;
}
if (element instanceof DBNDatabaseFolder) {
try {
String elementTypeName = ((DBNDatabaseFolder) element).getMeta().getType();
if (elementTypeName == null) {
return false;
}
Class<?> childType = Class.forName(elementTypeName);
return DBAPrivilegeOwner.class.isAssignableFrom(childType);
} catch (ClassNotFoundException e) {
return false;
}
}
return true;
}
});
{
permEditPanel = new Composite(composite, SWT.NONE);
permEditPanel.setLayout(new GridLayout(1, true));
permissionTable = new ObjectListControl<DBAPrivilege>(permEditPanel, SWT.FULL_SELECTION | SWT.CHECK, new ListContentProvider()) {
@Override
protected String getListConfigId(List<Class<?>> classList) {
return ObjectACLEditor.this.getClass().getName();
}
@Override
protected LoadingJob<Collection<DBAPrivilege>> createLoadService() {
return null;
}
};
permissionTable.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
/*
UIUtils.createTableColumn(permissionTable, SWT.LEFT, "Permission");
UIUtils.createTableColumn(permissionTable, SWT.CENTER, "With GRANT");
UIUtils.createTableColumn(permissionTable, SWT.CENTER, "With Hierarchy");
permissionTable.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (e.detail == SWT.CHECK) {
updateCurrentPrivileges(((TableItem) e.item).getChecked(), (DBAPrivilegeType) e.item.getData());
}
}
});
if (!isRoleEditor()) {
for (PRIVILEGE_TYPE pt : getACLManager().getPrivilegeTypes()) {
if (!pt.isValid() || !pt.supportsType(getDatabaseObject().getClass())) {
continue;
}
TableItem privItem = new TableItem(permissionTable, SWT.LEFT);
privItem.setText(0, pt.getName());
privItem.setData(pt);
}
}
*/
Composite buttonPanel = new Composite(permEditPanel, SWT.NONE);
buttonPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
buttonPanel.setLayout(new RowLayout());
UIUtils.createPushButton(buttonPanel, "Grant All", null, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
/*
boolean hadNonChecked = false;
for (TableItem item : permissionTable.getItems()) {
if (!item.getChecked()) hadNonChecked = true;
item.setChecked(true);
}
if (hadNonChecked) updateCurrentPrivileges(true, null);
*/
}
});
UIUtils.createPushButton(buttonPanel, "Revoke All", null, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
/*
boolean hadChecked = false;
for (TableItem item : permissionTable.getItems()) {
if (item.getChecked()) hadChecked = true;
item.setChecked(false);
}
if (hadChecked) {
updateCurrentPrivileges(false, null);
}
*/
}
});
objectDescriptionText = new Text(permEditPanel, SWT.READ_ONLY | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
objectDescriptionText.setLayoutData(new GridData(GridData.FILL_BOTH));
}
pageControl.createOrSubstituteProgressPanel(getSite());
updateObjectPermissions(null);
}
use of org.jkiss.dbeaver.ui.controls.ListContentProvider in project dbeaver by dbeaver.
the class GenericFilterValueEdit method setupTable.
void setupTable(Composite composite, int style, boolean visibleLines, boolean visibleHeader, Object layoutData) {
tableViewer = new TableViewer(composite, style);
Table table = this.tableViewer.getTable();
table.setLinesVisible(false);
table.setHeaderVisible(visibleHeader);
table.setLayoutData(layoutData);
this.tableViewer.setContentProvider(new ListContentProvider());
isCheckedTable = (style & SWT.CHECK) == SWT.CHECK;
if (isCheckedTable) {
buttonsPanel = UIUtils.createComposite(composite, 2);
buttonsPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
toggleButton = UIUtils.createDialogButton(buttonsPanel, "&Select All", new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
TableItem[] items = tableViewer.getTable().getItems();
if (Boolean.FALSE.equals(toggleButton.getData())) {
// Clear all checked
for (TableItem item : items) {
item.setChecked(false);
}
toggleButton.setData(false);
savedValues.clear();
} else {
for (TableItem item : items) {
item.setChecked(true);
savedValues.add((((DBDLabelValuePair) item.getData())).getValue());
}
toggleButton.setData(true);
}
updateToggleButton(toggleButton);
}
});
toggleButton.setData(true);
GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
gd.widthHint = 120;
toggleButton.setLayoutData(gd);
UIUtils.createEmptyLabel(buttonsPanel, 1, 1).setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
tableViewer.getTable().addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (e.detail == SWT.CHECK) {
DBDLabelValuePair value = (DBDLabelValuePair) e.item.getData();
if (((TableItem) e.item).getChecked()) {
savedValues.add(value.getValue());
} else {
savedValues.remove(value.getValue());
}
updateToggleButton(toggleButton);
}
}
});
}
}
use of org.jkiss.dbeaver.ui.controls.ListContentProvider in project dbeaver by dbeaver.
the class ColumnsMappingDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
DBPDataSource targetDataSource = settings.getTargetDataSource(mapping);
getShell().setText("Map columns of " + mapping.getTargetName());
boldFont = UIUtils.makeBoldFont(parent.getFont());
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(1, false));
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
new Label(composite, SWT.NONE).setText("Source entity: " + DBUtils.getObjectFullName(mapping.getSource(), DBPEvaluationContext.UI) + " [" + mapping.getSource().getDataSource().getContainer().getName() + "]");
new Label(composite, SWT.NONE).setText("Target entity: " + mapping.getTargetName() + " [" + (targetDataSource == null ? "?" : targetDataSource.getContainer().getName()) + "]");
mappingViewer = new TableViewer(composite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 600;
gd.heightHint = 300;
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);
}
updateStatus(Status.OK_STATUS);
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) {
updateStatus(GeneralUtils.makeExceptionStatus(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("Source Column");
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("Source Type");
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.mappingType == DatabaseMappingType.unspecified) {
cell.setBackground(DBeaverUI.getSharedTextColors().getColor(SharedTextColors.COLOR_WARNING));
} else {
cell.setBackground(null);
}
cell.setFont(boldFont);
}
});
columnTarget.getColumn().setText("Target Column");
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);
CustomComboBoxCellEditor editor = new CustomComboBoxCellEditor(mappingViewer, mappingViewer.getTable(), items.toArray(new String[items.size()]), SWT.DROP_DOWN);
updateStatus(Status.OK_STATUS);
return editor;
} catch (DBException e) {
updateStatus(GeneralUtils.makeExceptionStatus(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);
return;
}
}
}
attrMapping.setMappingType(DatabaseMappingType.create);
attrMapping.setTargetName(name);
}
updateStatus(Status.OK_STATUS);
} catch (DBException e) {
updateStatus(GeneralUtils.makeExceptionStatus(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));
cell.setFont(boldFont);
}
});
columnTargetType.getColumn().setText("Target Type");
columnTargetType.getColumn().setWidth(100);
columnTargetType.setEditingSupport(new EditingSupport(mappingViewer) {
@Override
protected CellEditor getCellEditor(Object element) {
DatabaseMappingAttribute attrMapping = (DatabaseMappingAttribute) element;
Set<String> types = new LinkedHashSet<>();
DBPDataSource dataSource = settings.getTargetDataSource(attrMapping);
if (dataSource instanceof DBPDataTypeProvider) {
for (DBSDataType type : ((DBPDataTypeProvider) dataSource).getLocalDataTypes()) {
types.add(type.getName());
}
}
types.add(attrMapping.getTargetType(dataSource));
return new CustomComboBoxCellEditor(mappingViewer, mappingViewer.getTable(), types.toArray(new String[types.size()]), 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));
}
@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 = "existing";
break;
case create:
text = "new";
break;
case skip:
text = "skip";
break;
}
cell.setText(text);
}
});
columnType.getColumn().setText("Mapping");
columnType.getColumn().setWidth(60);
}
mappingViewer.setInput(attributeMappings);
return parent;
}
Aggregations