use of org.jkiss.dbeaver.ui.data.IAttributeController 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(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 = DBeaverCore.getInstance().getNavigatorModel().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.data.IAttributeController in project dbeaver by serge-rider.
the class ContentEditorInput method prepareContent.
private void prepareContent(DBRProgressMonitor monitor) throws DBException {
DBDContent content = getContent();
DBDContentStorage storage = content.getContents(monitor);
if (contentDetached) {
release(monitor);
contentDetached = false;
}
if (storage instanceof DBDContentStorageLocal) {
// User content's storage directly
contentFile = ((DBDContentStorageLocal) storage).getDataFile();
contentDetached = true;
} else {
// Copy content to local file
try {
// Create file
if (contentFile == null) {
String valueId;
if (valueController instanceof IAttributeController) {
valueId = ((IAttributeController) valueController).getColumnId();
} else {
valueId = valueController.getValueName();
}
contentFile = ContentUtils.createTempContentFile(monitor, DBeaverCore.getInstance(), valueId);
}
// Write value to file
copyContentToFile(content, monitor);
} catch (IOException e) {
// Delete temp file
if (contentFile != null && contentFile.exists()) {
if (!contentFile.delete()) {
log.warn("Can't delete temporary content file '" + contentFile.getAbsolutePath() + "'");
}
}
throw new DBException("Can't delete content file", e);
}
}
// Mark file as readonly
if (valueController.isReadOnly()) {
markReadOnly(true);
}
}
Aggregations