Search in sources :

Example 96 with StyledText

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;
}
Also used : DBException(org.jkiss.dbeaver.DBException) ModifyListener(org.eclipse.swt.events.ModifyListener) EditDictionaryPage(org.jkiss.dbeaver.ui.editors.object.struct.EditDictionaryPage) IAttributeController(org.jkiss.dbeaver.ui.data.IAttributeController) ModifyEvent(org.eclipse.swt.events.ModifyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DatabaseDataEditor(org.jkiss.dbeaver.ui.editors.data.DatabaseDataEditor) StyledText(org.eclipse.swt.custom.StyledText) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) StyledText(org.eclipse.swt.custom.StyledText) GridData(org.eclipse.swt.layout.GridData) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Example 97 with StyledText

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;
}
Also used : StyledText(org.eclipse.swt.custom.StyledText)

Example 98 with StyledText

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);
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) Composite(org.eclipse.swt.widgets.Composite) FillLayout(org.eclipse.swt.layout.FillLayout)

Example 99 with StyledText

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;
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) StyledText(org.eclipse.swt.custom.StyledText)

Example 100 with StyledText

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;
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) Nullable(org.jkiss.code.Nullable)

Aggregations

StyledText (org.eclipse.swt.custom.StyledText)157 GridData (org.eclipse.swt.layout.GridData)52 Composite (org.eclipse.swt.widgets.Composite)50 GridLayout (org.eclipse.swt.layout.GridLayout)41 Point (org.eclipse.swt.graphics.Point)37 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)22 SelectionEvent (org.eclipse.swt.events.SelectionEvent)22 Control (org.eclipse.swt.widgets.Control)22 Label (org.eclipse.swt.widgets.Label)17 FillLayout (org.eclipse.swt.layout.FillLayout)13 CTabItem (org.eclipse.swt.custom.CTabItem)12 SashForm (org.eclipse.swt.custom.SashForm)12 Button (org.eclipse.swt.widgets.Button)12 ModifyEvent (org.eclipse.swt.events.ModifyEvent)10 ModifyListener (org.eclipse.swt.events.ModifyListener)10 TextTransfer (org.eclipse.swt.dnd.TextTransfer)8 Listener (org.eclipse.swt.widgets.Listener)8 UnnotifiableColorStyledText (org.talend.commons.ui.swt.colorstyledtext.UnnotifiableColorStyledText)8 Clipboard (org.eclipse.swt.dnd.Clipboard)7 DisposeEvent (org.eclipse.swt.events.DisposeEvent)7