use of org.jkiss.dbeaver.ui.controls.TreeContentProvider in project dbeaver by serge-rider.
the class FilterSettingsDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
getShell().setText(CoreMessages.controls_resultset_filter_title);
getShell().setImage(DBeaverIcons.getImage(UIIcon.FILTER));
Composite composite = (Composite) super.createDialogArea(parent);
TabFolder tabFolder = new TabFolder(composite, SWT.NONE);
tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
TreeColumn criteriaColumn;
{
Composite columnsGroup = UIUtils.createPlaceholder(tabFolder, 1);
columnsViewer = new CheckboxTreeViewer(columnsGroup, SWT.SINGLE | SWT.FULL_SELECTION | SWT.CHECK);
columnsViewer.setContentProvider(new TreeContentProvider() {
@Override
public Object[] getChildren(Object parentElement) {
final java.util.List<DBDAttributeBinding> nestedBindings = ((DBDAttributeBinding) parentElement).getNestedBindings();
if (nestedBindings == null || nestedBindings.isEmpty()) {
return null;
}
final DBDAttributeBinding[] res = nestedBindings.toArray(new DBDAttributeBinding[nestedBindings.size()]);
Arrays.sort(res, activeSorter);
return res;
}
@Override
public boolean hasChildren(Object element) {
final java.util.List<DBDAttributeBinding> nestedBindings = ((DBDAttributeBinding) element).getNestedBindings();
return nestedBindings != null && !nestedBindings.isEmpty();
}
});
columnsViewer.setLabelProvider(new ColumnLabelProvider());
columnsViewer.setCheckStateProvider(new CheckStateProvider());
final Tree columnsTree = columnsViewer.getTree();
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 300;
//gd.heightHint = 300;
columnsTree.setLayoutData(gd);
columnsTree.setHeaderVisible(true);
columnsTree.setLinesVisible(true);
UIUtils.createTreeColumn(columnsTree, SWT.LEFT, CoreMessages.controls_resultset_filter_column_name);
UIUtils.createTreeColumn(columnsTree, SWT.LEFT, "#");
UIUtils.createTreeColumn(columnsTree, SWT.LEFT, CoreMessages.controls_resultset_filter_column_order);
criteriaColumn = UIUtils.createTreeColumn(columnsTree, SWT.LEFT, CoreMessages.controls_resultset_filter_column_criteria);
new CustomTreeEditor(columnsTree) {
{
firstTraverseIndex = 3;
lastTraverseIndex = 3;
}
@Override
protected Control createEditor(Tree table, int index, TreeItem item) {
if (index == 2) {
toggleColumnOrder(item);
return null;
} else if (index == 3 && resultSetViewer.supportsDataFilter()) {
Text text = new Text(columnsTree, SWT.BORDER);
text.setText(item.getText(index));
text.selectAll();
return text;
}
return null;
}
@Override
protected void saveEditorValue(Control control, int index, TreeItem item) {
Text text = (Text) control;
String criteria = text.getText().trim();
DBDAttributeConstraint constraint = getBindingConstraint((DBDAttributeBinding) item.getData());
if (CommonUtils.isEmpty(criteria)) {
constraint.setCriteria(null);
} else {
constraint.setCriteria(criteria);
}
item.setText(3, criteria);
}
private void toggleColumnOrder(TreeItem item) {
DBDAttributeConstraint constraint = getBindingConstraint((DBDAttributeBinding) item.getData());
if (constraint.getOrderPosition() == 0) {
// Add new ordered column
constraint.setOrderPosition(dataFilter.getMaxOrderingPosition() + 1);
constraint.setOrderDescending(false);
} else if (!constraint.isOrderDescending()) {
constraint.setOrderDescending(true);
} else {
// Remove ordered column
/*
for (DBDAttributeConstraint con2 : dataFilter.getConstraints()) {
if (con2.getOrderPosition() > constraint.getOrderPosition()) {
con2.setOrderPosition(con2.getOrderPosition() - 1);
}
}
*/
constraint.setOrderPosition(0);
constraint.setOrderDescending(false);
}
columnsViewer.refresh();
}
};
columnsViewer.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
DBDAttributeConstraint constraint = getBindingConstraint((DBDAttributeBinding) event.getElement());
constraint.setVisible(event.getChecked());
}
});
{
ToolBar toolbar = new ToolBar(columnsGroup, SWT.HORIZONTAL | SWT.RIGHT);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.verticalIndent = 3;
toolbar.setLayoutData(gd);
toolbar.setLayout(new FillLayout());
moveTopButton = createToolItem(toolbar, "Move to top", UIIcon.ARROW_TOP, new Runnable() {
@Override
public void run() {
int selectionIndex = getSelectionIndex(columnsViewer.getTree());
moveColumn(selectionIndex, 0);
}
});
moveTopButton.setEnabled(false);
moveUpButton = createToolItem(toolbar, "Move up", UIIcon.ARROW_UP, new Runnable() {
@Override
public void run() {
int selectionIndex = getSelectionIndex(columnsViewer.getTree());
moveColumn(selectionIndex, selectionIndex - 1);
}
});
moveUpButton.setEnabled(false);
moveDownButton = createToolItem(toolbar, "Move down", UIIcon.ARROW_DOWN, new Runnable() {
@Override
public void run() {
int selectionIndex = getSelectionIndex(columnsViewer.getTree());
moveColumn(selectionIndex, selectionIndex + 1);
}
});
moveDownButton.setEnabled(false);
moveBottomButton = createToolItem(toolbar, "Move to bottom", UIIcon.ARROW_BOTTOM, new Runnable() {
@Override
public void run() {
int selectionIndex = getSelectionIndex(columnsViewer.getTree());
moveColumn(selectionIndex, getItemsCount() - 1);
}
});
moveBottomButton.setEnabled(false);
UIUtils.createToolBarSeparator(toolbar, SWT.VERTICAL);
createToolItem(toolbar, "Sort", UIIcon.SORT, new Runnable() {
@Override
public void run() {
Collections.sort(attributes, ALPHA_SORTER);
for (int i = 0; i < attributes.size(); i++) {
final DBDAttributeConstraint constraint = getBindingConstraint(attributes.get(i));
constraint.setVisualPosition(i);
}
columnsViewer.refresh();
}
});
UIUtils.createToolBarSeparator(toolbar, SWT.VERTICAL);
ToolItem showAllButton = createToolItem(toolbar, "Show All", null, new Runnable() {
@Override
public void run() {
for (DBDAttributeConstraint constraint : constraints) {
constraint.setVisible(true);
}
columnsViewer.refresh();
}
});
showAllButton.setImage(UIUtils.getShardImage(ISharedImages.IMG_ETOOL_DEF_PERSPECTIVE));
ToolItem showNoneButton = createToolItem(toolbar, "Show None", null, new Runnable() {
@Override
public void run() {
for (DBDAttributeConstraint constraint : constraints) {
constraint.setVisible(false);
}
columnsViewer.refresh();
}
});
showNoneButton.setImage(UIUtils.getShardImage(ISharedImages.IMG_ELCL_REMOVEALL));
createToolItem(toolbar, "Reset", UIIcon.REFRESH, new Runnable() {
@Override
public void run() {
dataFilter.reset();
constraints = new ArrayList<>(dataFilter.getConstraints());
refreshData();
//columnsViewer.refresh();
//$NON-NLS-1$
orderText.setText("");
//$NON-NLS-1$
whereText.setText("");
}
});
columnsViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
int selectionIndex = getSelectionIndex(columnsViewer.getTree());
moveTopButton.setEnabled(selectionIndex > 0);
moveUpButton.setEnabled(selectionIndex > 0);
moveDownButton.setEnabled(selectionIndex >= 0 && selectionIndex < getItemsCount() - 1);
moveBottomButton.setEnabled(selectionIndex >= 0 && selectionIndex < getItemsCount() - 1);
}
});
}
TabItem libsTab = new TabItem(tabFolder, SWT.NONE);
libsTab.setText(CoreMessages.controls_resultset_filter_group_columns);
libsTab.setToolTipText("Set criteria and order for individual column(s)");
libsTab.setControl(columnsGroup);
}
createCustomFilters(tabFolder);
// Fill columns
columnsViewer.setInput(attributes);
refreshData();
// Pack UI
UIUtils.packColumns(columnsViewer.getTree());
if (criteriaColumn.getWidth() < 200) {
criteriaColumn.setWidth(200);
}
if (!resultSetViewer.supportsDataFilter()) {
Label warnLabel = new Label(composite, SWT.NONE);
warnLabel.setText(CoreMessages.controls_resultset_filter_warning_custom_order_disabled);
warnLabel.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_RED));
}
return parent;
}
use of org.jkiss.dbeaver.ui.controls.TreeContentProvider 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 = NavigatorUtils.getNodeChildrenFiltered(VoidProgressMonitor.INSTANCE, (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.TreeContentProvider in project dbeaver by serge-rider.
the class DatabaseConsumerPageMapping method createMappingsTree.
private void createMappingsTree(Composite composite) {
// Mapping table
mappingViewer = new TreeViewer(composite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
mappingViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
mappingViewer.getTree().setLinesVisible(true);
mappingViewer.getTree().setHeaderVisible(true);
TreeViewerColumn columnSource = new TreeViewerColumn(mappingViewer, SWT.LEFT);
columnSource.setLabelProvider(new MappingLabelProvider() {
@Override
public void update(ViewerCell cell) {
DatabaseMappingObject mapping = (DatabaseMappingObject) cell.getElement();
cell.setText(DBUtils.getObjectFullName(mapping.getSource(), DBPEvaluationContext.UI));
if (mapping.getIcon() != null) {
cell.setImage(DBeaverIcons.getImage(mapping.getIcon()));
}
super.update(cell);
}
});
columnSource.getColumn().setText("Source");
TreeViewerColumn columnTarget = new TreeViewerColumn(mappingViewer, SWT.LEFT);
columnTarget.setLabelProvider(new MappingLabelProvider() {
@Override
public void update(ViewerCell cell) {
DatabaseMappingObject mapping = (DatabaseMappingObject) cell.getElement();
cell.setText(mapping.getTargetName());
if (mapping.getMappingType() == DatabaseMappingType.unspecified) {
cell.setBackground(DBeaverUI.getSharedTextColors().getColor(SharedTextColors.COLOR_WARNING));
} else {
cell.setBackground(null);
}
super.update(cell);
}
});
columnTarget.getColumn().setText("Target");
columnTarget.setEditingSupport(new EditingSupport(mappingViewer) {
@Override
protected CellEditor getCellEditor(Object element) {
try {
return createTargetEditor(element);
} catch (DBException e) {
setErrorMessage(e.getMessage());
return null;
}
}
@Override
protected boolean canEdit(Object element) {
return true;
}
@Override
protected Object getValue(Object element) {
DatabaseMappingObject mapping = (DatabaseMappingObject) element;
if (mapping.getMappingType() == DatabaseMappingType.unspecified) {
return mapping.getSource().getName();
}
if (mapping instanceof DatabaseMappingContainer) {
if (mapping.getMappingType() == DatabaseMappingType.existing) {
return ((DatabaseMappingContainer) mapping).getTarget();
}
return mapping.getTargetName();
} else {
if (mapping.getMappingType() == DatabaseMappingType.existing) {
return ((DatabaseMappingAttribute) mapping).getTarget();
}
return mapping.getTargetName();
}
}
@Override
protected void setValue(final Object element, Object value) {
try {
final DatabaseConsumerSettings settings = getWizard().getPageSettings(DatabaseConsumerPageMapping.this, DatabaseConsumerSettings.class);
String name = CommonUtils.toString(value);
DBPDataSource dataSource = settings.getTargetDataSource((DatabaseMappingObject) element);
if (!name.equals(DatabaseMappingAttribute.TARGET_NAME_SKIP) && !name.equals(TARGET_NAME_BROWSE) && dataSource != null) {
name = DBObjectNameCaseTransformer.transformName(dataSource, name);
}
setMappingTarget((DatabaseMappingObject) element, name);
//mappingViewer.setSelection(mappingViewer.getSelection());
mappingViewer.update(element, null);
updatePageCompletion();
} catch (DBException e) {
UIUtils.showDatabaseError(getShell(), "Mapping error", "Error setting target table", e);
}
}
});
//TreeViewerEditor.create(mappingViewer, new TreeViewerFocusCellManager(), ColumnViewerEditor.TABBING_CYCLE_IN_ROW);
TreeViewerColumn columnMapping = new TreeViewerColumn(mappingViewer, SWT.LEFT);
columnMapping.setLabelProvider(new MappingLabelProvider() {
@Override
public void update(ViewerCell cell) {
DatabaseMappingObject mapping = (DatabaseMappingObject) cell.getElement();
cell.setText(mapping.getMappingType().name());
super.update(cell);
}
});
columnMapping.getColumn().setText("Mapping");
columnMapping.setEditingSupport(new EditingSupport(mappingViewer) {
@Override
protected CellEditor getCellEditor(Object element) {
List<String> mappingTypes = new ArrayList<>();
mappingTypes.add(DatabaseMappingType.skip.name());
DatabaseMappingObject mapping = (DatabaseMappingObject) element;
if (mapping instanceof DatabaseMappingAttribute) {
mappingTypes.add(((DatabaseMappingAttribute) mapping).getParent().getMappingType().name());
} else {
mappingTypes.add(mapping.getMappingType().name());
}
return new CustomComboBoxCellEditor(mappingViewer.getTree(), mappingTypes.toArray(new String[mappingTypes.size()]), SWT.DROP_DOWN | SWT.READ_ONLY);
}
@Override
protected boolean canEdit(Object element) {
return true;
}
@Override
protected Object getValue(Object element) {
DatabaseMappingObject mapping = (DatabaseMappingObject) element;
return mapping.getMappingType().name();
}
@Override
protected void setValue(Object element, Object value) {
try {
DatabaseMappingObject mapping = (DatabaseMappingObject) element;
DatabaseMappingType mappingType = DatabaseMappingType.valueOf(value.toString());
if (mapping instanceof DatabaseMappingAttribute) {
((DatabaseMappingAttribute) mapping).setMappingType(mappingType);
} else {
((DatabaseMappingContainer) mapping).refreshMappingType(getWizard().getContainer(), mappingType);
}
mappingViewer.refresh();
setErrorMessage(null);
} catch (DBException e) {
setErrorMessage(e.getMessage());
}
}
});
mappingViewer.setContentProvider(new TreeContentProvider() {
@Override
public boolean hasChildren(Object element) {
return element instanceof DatabaseMappingContainer;
}
@Override
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof DatabaseMappingContainer) {
return ((DatabaseMappingContainer) parentElement).getAttributeMappings(getContainer()).toArray();
}
return null;
}
});
}
Aggregations