use of org.jkiss.dbeaver.ui.editors.object.struct.EditDictionaryPage in project dbeaver by serge-rider.
the class FilterValueEditPopup method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
DBSEntityReferrer descReferrer = ResultSetUtils.getEnumerableConstraint(filter.getAttribute());
Composite group = (Composite) super.createDialogArea(parent);
{
Composite labelComposite = UIUtils.createComposite(group, 2);
labelComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Label controlLabel = UIUtils.createControlLabel(labelComposite, "Choose value(s) to filter by");
controlLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
if (descReferrer instanceof DBSEntityAssociation) {
Link hintLabel = UIUtils.createLink(labelComposite, "(<a>Define Description</a>)", new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
EditDictionaryPage editDictionaryPage = new EditDictionaryPage(((DBSEntityAssociation) descReferrer).getAssociatedEntity());
if (editDictionaryPage.edit(parent.getShell())) {
filter.loadValues(null);
}
}
});
hintLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
} else {
UIUtils.createEmptyLabel(labelComposite, 1, 1);
}
}
Text filterTextbox = filter.addFilterTextbox(group);
filterTextbox.setFocus();
filterTextbox.addTraverseListener(e -> {
Table table = filter.getTableViewer().getTable();
if (e.detail == SWT.TRAVERSE_ARROW_PREVIOUS || e.detail == SWT.TRAVERSE_ARROW_NEXT) {
if (table.getSelectionIndex() < 0 && table.getItemCount() > 0) {
table.setSelection(0);
}
table.setFocus();
} else if (e.detail == SWT.TRAVERSE_RETURN) {
applyFilterValue();
}
});
UIUtils.addEmptyTextHint(filterTextbox, text -> "Type partial value to search");
Composite tableComposite = UIUtils.createComposite(group, 1);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 400;
gd.heightHint = 300;
tableComposite.setLayoutData(gd);
filter.setupTable(tableComposite, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL | (filter.getOperator() == DBCLogicalOperator.IN ? SWT.CHECK : SWT.NONE), true, descReferrer != null, new GridData(GridData.FILL_BOTH));
Table table = filter.getTableViewer().getTable();
TableViewerColumn resultsetColumn = new TableViewerColumn(filter.getTableViewer(), UIUtils.createTableColumn(table, SWT.NONE, "Value"));
resultsetColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return filter.getAttribute().getValueHandler().getValueDisplayString(filter.getAttribute(), ((DBDLabelValuePair) element).getValue(), DBDDisplayFormat.UI);
}
});
TableViewerColumn descColumn;
if (descReferrer != null) {
descColumn = new TableViewerColumn(filter.getTableViewer(), UIUtils.createTableColumn(table, SWT.NONE, "Description"));
descColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return ((DBDLabelValuePair) element).getLabel();
}
});
}
filter.getTableViewer().addSelectionChangedListener(event -> {
value = filter.getFilterValue();
// okPressed();
});
filter.getTableViewer().addDoubleClickListener(event -> applyFilterValue());
filter.setFilterPattern(null);
filter.loadValues(() -> UIUtils.asyncExec(() -> UIUtils.packColumns(table, false)));
filter.createFilterButton(ResultSetMessages.sql_editor_resultset_filter_panel_btn_apply, new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
applyFilterValue();
}
});
closeOnFocusLost(filterTextbox, table);
return tableComposite;
}
use of org.jkiss.dbeaver.ui.editors.object.struct.EditDictionaryPage in project dbeaver by dbeaver.
the class ReferenceValueEditor method createEditorSelector.
public boolean createEditorSelector(final Composite parent) {
if (!(valueController instanceof IAttributeController) || valueController.isReadOnly()) {
return false;
}
refConstraint = getEnumerableConstraint();
if (refConstraint == null) {
return false;
}
if (refConstraint instanceof DBSEntityAssociation) {
final DBSEntityAssociation association = (DBSEntityAssociation) refConstraint;
if (association.getReferencedConstraint() != null) {
final DBSEntity refTable = association.getReferencedConstraint().getParentObject();
Composite labelGroup = UIUtils.createPlaceholder(parent, 2);
labelGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Link dictLabel = UIUtils.createLink(labelGroup, NLS.bind(CoreMessages.dialog_value_view_label_dictionary, refTable.getName()), new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// Open
final IWorkbenchWindow window = valueController.getValueSite().getWorkbenchWindow();
DBeaverUI.runInUI(window, new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
DBNDatabaseNode tableNode = NavigatorUtils.getNodeByObject(monitor, refTable, true);
if (tableNode != null) {
NavigatorHandlerObjectOpen.openEntityEditor(tableNode, DatabaseDataEditor.class.getName(), window);
}
}
});
}
});
dictLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
Link hintLabel = UIUtils.createLink(labelGroup, "(<a>Define Description</a>)", new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
EditDictionaryPage editDictionaryPage = new EditDictionaryPage("Dictionary structure", refTable);
if (editDictionaryPage.edit(parent.getShell())) {
loaderJob.schedule();
}
}
});
hintLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_END));
}
}
editorSelector = new Table(parent, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
editorSelector.setLinesVisible(true);
editorSelector.setHeaderVisible(true);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 150;
// gd.widthHint = 300;
// gd.grabExcessVerticalSpace = true;
// gd.grabExcessHorizontalSpace = true;
editorSelector.setLayoutData(gd);
UIUtils.createTableColumn(editorSelector, SWT.LEFT, CoreMessages.dialog_value_view_column_value);
UIUtils.createTableColumn(editorSelector, SWT.LEFT, CoreMessages.dialog_value_view_column_description);
UIUtils.packColumns(editorSelector);
editorSelector.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
TableItem[] selection = editorSelector.getSelection();
if (selection != null && selection.length > 0) {
Object value = selection[0].getData();
// editorControl.setText(selection[0].getText());
try {
valueEditor.primeEditorValue(value);
} catch (DBException e1) {
log.error(e1);
}
}
}
});
Control control = valueEditor.getControl();
ModifyListener modifyListener = new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
Object curEditorValue;
try {
curEditorValue = valueEditor.extractEditorValue();
} catch (DBException e1) {
log.error(e1);
return;
}
// Try to select current value in the table
final String curTextValue = valueController.getValueHandler().getValueDisplayString(((IAttributeController) valueController).getBinding(), curEditorValue, DBDDisplayFormat.UI);
boolean valueFound = false;
for (TableItem item : editorSelector.getItems()) {
if (item.getText(0).equals(curTextValue)) {
editorSelector.select(editorSelector.indexOf(item));
editorSelector.showItem(item);
valueFound = true;
break;
}
}
if (!valueFound) {
// Read dictionary
if (loaderJob.getState() == Job.RUNNING) {
// Cancel it and create new one
loaderJob.cancel();
loaderJob = new SelectorLoaderJob();
}
loaderJob.setPattern(curEditorValue);
if (loaderJob.getState() != Job.WAITING) {
loaderJob.schedule(100);
}
}
}
};
if (control instanceof Text) {
((Text) control).addModifyListener(modifyListener);
} else if (control instanceof StyledText) {
((StyledText) control).addModifyListener(modifyListener);
}
loaderJob = new SelectorLoaderJob();
final Object curValue = valueController.getValue();
if (curValue instanceof Number) {
loaderJob.setPattern(curValue);
}
loaderJob.schedule(500);
return true;
}
use of org.jkiss.dbeaver.ui.editors.object.struct.EditDictionaryPage in project dbeaver by serge-rider.
the class ReferenceValueEditor method createEditorSelector.
public boolean createEditorSelector(final Composite parent) {
if (!(valueController instanceof IAttributeController) || valueController.isReadOnly()) {
return false;
}
refConstraint = getEnumerableConstraint();
if (refConstraint == null) {
return false;
}
if (refConstraint instanceof DBSEntityAssociation) {
final DBSEntityAssociation association = (DBSEntityAssociation) refConstraint;
if (association.getReferencedConstraint() != null) {
final DBSEntity refTable = association.getReferencedConstraint().getParentObject();
Composite labelGroup = UIUtils.createPlaceholder(parent, 2);
labelGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Link dictLabel = UIUtils.createLink(labelGroup, NLS.bind(ResultSetMessages.dialog_value_view_label_dictionary, refTable.getName()), new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// Open
final IWorkbenchWindow window = valueController.getValueSite().getWorkbenchWindow();
UIUtils.runInUI(window, monitor -> {
DBNDatabaseNode tableNode = DBNUtils.getNodeByObject(monitor, refTable, true);
if (tableNode != null) {
NavigatorHandlerObjectOpen.openEntityEditor(tableNode, DatabaseDataEditor.class.getName(), window);
}
});
}
});
dictLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
Link hintLabel = UIUtils.createLink(labelGroup, "(<a>Define Description</a>)", new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
EditDictionaryPage editDictionaryPage = new EditDictionaryPage(refTable);
if (editDictionaryPage.edit(parent.getShell())) {
reloadSelectorValues(null, true);
}
}
});
hintLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_END));
}
}
editorSelector = new Tree(parent, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
editorSelector.setLinesVisible(true);
editorSelector.setHeaderVisible(true);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 150;
// gd.widthHint = 300;
// gd.grabExcessVerticalSpace = true;
// gd.grabExcessHorizontalSpace = true;
editorSelector.setLayoutData(gd);
TreeColumn valueColumn = UIUtils.createTreeColumn(editorSelector, SWT.LEFT, ResultSetMessages.dialog_value_view_column_value);
valueColumn.setData(Boolean.TRUE);
TreeColumn descColumn = UIUtils.createTreeColumn(editorSelector, SWT.LEFT, ResultSetMessages.dialog_value_view_column_description);
descColumn.setData(Boolean.FALSE);
SortListener sortListener = new SortListener();
valueColumn.addListener(SWT.Selection, sortListener);
descColumn.addListener(SWT.Selection, sortListener);
editorSelector.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
TreeItem[] selection = editorSelector.getSelection();
if (selection != null && selection.length > 0) {
Object value = selection[0].getData();
// editorControl.setText(selection[0].getText());
try {
valueEditor.primeEditorValue(value);
} catch (DBException e1) {
log.error(e1);
}
}
}
});
{
MenuManager menuMgr = new MenuManager();
menuMgr.addMenuListener(manager -> {
manager.add(new CopyAction());
manager.add(new Separator());
});
menuMgr.setRemoveAllWhenShown(true);
this.editorSelector.setMenu(menuMgr.createContextMenu(this.editorSelector));
this.editorSelector.addDisposeListener(e -> menuMgr.dispose());
}
Control control = valueEditor.getControl();
ModifyListener modifyListener = e -> {
Object curEditorValue;
try {
curEditorValue = valueEditor.extractEditorValue();
} catch (DBException e1) {
log.error(e1);
return;
}
// Try to select current value in the table
final String curTextValue = valueController.getValueHandler().getValueDisplayString(((IAttributeController) valueController).getBinding(), curEditorValue, DBDDisplayFormat.EDIT);
boolean valueFound = false;
if (curTextValue != null) {
TreeItem[] items = editorSelector.getItems();
for (int i = 0; i < items.length; i++) {
TreeItem item = items[i];
if (curTextValue.equalsIgnoreCase(item.getText(0)) || curTextValue.equalsIgnoreCase(item.getText(1))) {
editorSelector.select(item);
editorSelector.showItem(item);
// editorSelector.setTopIndex(i);
valueFound = true;
break;
}
}
}
if (!valueFound) {
// Read dictionary
reloadSelectorValues(curEditorValue, false);
}
};
if (control instanceof Text) {
((Text) control).addModifyListener(modifyListener);
} else if (control instanceof StyledText) {
((StyledText) control).addModifyListener(modifyListener);
}
if (refConstraint instanceof DBSEntityAssociation) {
final Text valueFilterText = new Text(parent, SWT.BORDER);
valueFilterText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
valueFilterText.addModifyListener(e -> {
String filterPattern = valueFilterText.getText();
reloadSelectorValues(filterPattern, false);
});
valueFilterText.addPaintListener(e -> {
if (valueFilterText.isEnabled() && valueFilterText.getCharCount() == 0) {
e.gc.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
e.gc.drawText("Type part of dictionary value to search", 2, 0, true);
e.gc.setFont(null);
}
});
}
final Object curValue = valueController.getValue();
reloadSelectorValues(curValue, false);
return true;
}
use of org.jkiss.dbeaver.ui.editors.object.struct.EditDictionaryPage in project dbeaver by serge-rider.
the class EditVirtualEntityDialog method createDictionaryPage.
private void createDictionaryPage(TabFolder tabFolder) {
if (entity != null) {
editDictionaryPage = new EditDictionaryPage(entity);
editDictionaryPage.createControl(tabFolder);
TabItem dictItem = new TabItem(tabFolder, SWT.NONE);
dictItem.setText("Dictionary");
dictItem.setImage(DBeaverIcons.getImage(DBIcon.TREE_PACKAGE));
dictItem.setControl(editDictionaryPage.getControl());
dictItem.setData(InitPage.DICTIONARY);
}
}
use of org.jkiss.dbeaver.ui.editors.object.struct.EditDictionaryPage in project dbeaver by serge-rider.
the class VirtualStructureEditor method createDictionaryPage.
private void createDictionaryPage(TabFolder tabFolder) {
if (entity != null) {
editDictionaryPage = new EditDictionaryPage(entity);
editDictionaryPage.createControl(tabFolder);
TabItem dictItem = new TabItem(tabFolder, SWT.NONE);
dictItem.setText(DataEditorsMessages.virtual_structure_editor_dictionary_page_text);
dictItem.setControl(editDictionaryPage.getControl());
dictItem.setData(EditVirtualEntityDialog.InitPage.DICTIONARY);
}
}
Aggregations