use of org.eclipse.swt.custom.StyledText 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.eclipse.swt.custom.StyledText in project dbeaver by serge-rider.
the class TextPanelEditor method createControl.
@Override
public StyledText createControl(IValueController valueController) {
StyledText text = new StyledText(valueController.getEditPlaceholder(), SWT.MULTI | SWT.V_SCROLL);
text.setEditable(!valueController.isReadOnly());
text.setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT));
ContentPanelEditor.setEditorSettings(text);
return text;
}
use of org.eclipse.swt.custom.StyledText in project dbeaver by serge-rider.
the class ShellProcessView method createPartControl.
@Override
public void createPartControl(Composite parent) {
Composite group = UIUtils.createPlaceholder(parent, 1);
group.setLayout(new FillLayout());
processLogText = new StyledText(group, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.READ_ONLY);
UIUtils.setHelp(group, IHelpContextIds.CTX_QUERY_MANAGER);
}
use of org.eclipse.swt.custom.StyledText in project dbeaver by serge-rider.
the class WidgetCommandDirector method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
String commandID = event.getCommand().getId();
Object control = HandlerUtil.getVariable(event, ISources.ACTIVE_FOCUS_CONTROL_NAME);
if (control instanceof Text) {
Text text = (Text) control;
if (ITextEditorActionDefinitionIds.LINE_START.equals(commandID) || ITextEditorActionDefinitionIds.TEXT_START.equals(commandID)) {
text.setSelection(0);
} else if (ITextEditorActionDefinitionIds.LINE_END.equals(commandID) || ITextEditorActionDefinitionIds.TEXT_END.equals(commandID)) {
text.setSelection(text.getCharCount());
}
} else if (control instanceof StyledText) {
Integer widgetCommand = BaseTextEditor.getActionMap().get(commandID);
StyledText text = (StyledText) control;
if (widgetCommand != null) {
text.invokeAction(widgetCommand);
}
}
return null;
}
use of org.eclipse.swt.custom.StyledText in project dbeaver by serge-rider.
the class ToolsContextMenuHandler method getLocationFromControl.
@Nullable
private Point getLocationFromControl(Shell activeShell, Control focusControl) {
Point location = null;
final Display display = activeShell.getDisplay();
if (focusControl instanceof Table) {
final Table table = (Table) focusControl;
final int selectionIndex = table.getSelectionIndex();
if (selectionIndex < 0) {
location = display.map(focusControl, null, table.getLocation());
} else {
Rectangle absBounds = display.map(focusControl, null, table.getItem(selectionIndex).getBounds());
location = new Point(absBounds.x, absBounds.y + table.getItemHeight());
}
} else if (focusControl instanceof Tree) {
final Tree tree = (Tree) focusControl;
final TreeItem[] selection = tree.getSelection();
if (ArrayUtils.isEmpty(selection)) {
location = display.map(focusControl, null, tree.getLocation());
} else {
Rectangle absBounds = display.map(focusControl, null, selection[0].getBounds());
location = new Point(absBounds.x, absBounds.y + tree.getItemHeight());
}
} else if (focusControl instanceof StyledText) {
final StyledText styledText = (StyledText) focusControl;
final int caretOffset = styledText.getCaretOffset();
location = styledText.getLocationAtOffset(caretOffset);
location = display.map(styledText, null, location);
location.y += styledText.getLineHeight();
}
return location;
}
Aggregations