Search in sources :

Example 71 with StyledText

use of org.eclipse.swt.custom.StyledText in project cubrid-manager by CUBRID.

the class LongTextCellPopupDialog method createDialogArea.

/**
	 * Create dialog area
	 * 
	 * @param parent Composite
	 * @return Control
	 */
protected Control createDialogArea(Composite parent) {
    Composite parentComp = (Composite) super.createDialogArea(parent);
    Composite composite = new Composite(parentComp, SWT.NONE);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayout layout = new GridLayout();
    layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
    layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
    layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
    composite.setLayout(layout);
    Composite btnComposite = new Composite(composite, SWT.NONE);
    RowLayout rowLayout = new RowLayout();
    rowLayout.spacing = 5;
    btnComposite.setLayout(rowLayout);
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalAlignment = GridData.BEGINNING;
    gridData.horizontalSpan = 2;
    btnComposite.setLayoutData(gridData);
    setNullBtn = new Button(btnComposite, SWT.CHECK);
    {
        setNullBtn.setText(Messages.btnSetNull);
        setNullBtn.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent event) {
                changeBtnStatus();
            }
        });
    }
    importBtn = new Button(btnComposite, SWT.PUSH);
    importBtn.setText(Messages.btnImport);
    importBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            File file = FileDialogUtils.getImportedFile(getShell(), new String[] { "*.txt", "*.sql", "*.csv" });
            if (null != file && file.getName().length() > 0) {
                final String charsetName = fileCharsetCombo.getText();
                try {
                    "".getBytes(charsetName);
                } catch (UnsupportedEncodingException e) {
                    CommonUITool.openErrorBox(Messages.errCharset);
                    return;
                }
                try {
                    String textValue = FileUtil.readData(file.getPath(), charsetName);
                    columnValueText.setText(textValue);
                    currValue = textValue;
                } catch (IOException ex) {
                    CommonUITool.openErrorBox(ex.getMessage());
                }
            }
        }
    });
    exportBtn = new Button(btnComposite, SWT.PUSH);
    exportBtn.setText(Messages.btnExport);
    exportBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (columnValueText.getText().length() == 0) {
                CommonUITool.openWarningBox(Messages.noDataExport);
                return;
            }
            String charsetName = fileCharsetCombo.getText();
            try {
                "".getBytes(charsetName);
            } catch (UnsupportedEncodingException e) {
                CommonUITool.openErrorBox(Messages.errCharset);
                return;
            }
            File file = FileDialogUtils.getDataExportedFile(getShell(), new String[] { "*.*" }, new String[] { "*.*" }, null);
            if (null != file && file.getName().length() > 0) {
                exportData(file.getPath());
            }
        }
    });
    fileCharsetCombo = new Combo(btnComposite, SWT.NONE);
    {
        fileCharsetCombo.setItems(QueryOptions.getAllCharset(null));
        String charset = StringUtil.getDefaultCharset();
        fileCharsetCombo.setText(charset);
    }
    columnValueText = new StyledText(composite, SWT.WRAP | SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    if (value.hasLoadAll()) {
        CommonUITool.registerContextMenu(columnValueText, isEditable);
    }
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 280;
    gd.widthHint = 500;
    columnValueText.setLayoutData(gd);
    initValue();
    return composite;
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Combo(org.eclipse.swt.widgets.Combo) IOException(java.io.IOException) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) File(java.io.File)

Example 72 with StyledText

use of org.eclipse.swt.custom.StyledText in project dbeaver by serge-rider.

the class TextViewDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite dialogGroup = (Composite) super.createDialogArea(parent);
    ReferenceValueEditor referenceValueEditor = new ReferenceValueEditor(getValueController(), this);
    boolean isForeignKey = referenceValueEditor.isReferenceValue();
    Label label = new Label(dialogGroup, SWT.NONE);
    label.setText(CoreMessages.dialog_data_label_value);
    boolean readOnly = getValueController().isReadOnly();
    boolean useHex = !isForeignKey;
    final DBSTypedObject valueType = getValueController().getValueType();
    long maxSize = valueType.getMaxLength();
    if (useHex) {
        editorContainer = new CTabFolder(dialogGroup, SWT.FLAT | SWT.TOP);
        editorContainer.setLayoutData(new GridData(GridData.FILL_BOTH));
        lengthLabel = new Label(editorContainer, SWT.RIGHT);
        lengthLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        editorContainer.setTopRight(lengthLabel, SWT.FILL);
    }
    int selectedType = 0;
    if (getDialogSettings().get(VALUE_TYPE_SELECTOR) != null) {
        selectedType = getDialogSettings().getInt(VALUE_TYPE_SELECTOR);
    }
    {
        int style = SWT.NONE;
        if (readOnly) {
            style |= SWT.READ_ONLY;
        }
        if (useHex) {
            style |= SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.WRAP;
        } else {
            // Use border only for plain text editor, otherwise tab folder's border will be used
            style |= SWT.BORDER;
        }
        textEdit = new StyledText(useHex ? editorContainer : dialogGroup, style);
        textEdit.setMargins(3, 3, 3, 3);
        if (maxSize > 0 && valueType.getDataKind() == DBPDataKind.STRING) {
            textEdit.setTextLimit((int) maxSize);
        }
        if (readOnly) {
        //textEdit.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
        }
        GridData gd = new GridData(isForeignKey ? GridData.FILL_HORIZONTAL : GridData.FILL_BOTH);
        gd.widthHint = 300;
        if (!isForeignKey) {
            gd.heightHint = 200;
            gd.grabExcessVerticalSpace = true;
        }
        textEdit.setLayoutData(gd);
        textEdit.setFocus();
        textEdit.setEditable(!readOnly);
        textEdit.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                dirty = true;
                updateValueLength();
            }
        });
        UIUtils.fillDefaultStyledTextContextMenu(textEdit);
        if (useHex) {
            CTabItem item = new CTabItem(editorContainer, SWT.NO_FOCUS);
            item.setText("Text");
            item.setImage(DBeaverIcons.getImage(DBIcon.TYPE_TEXT));
            item.setControl(textEdit);
        }
    }
    Point minSize = null;
    if (useHex) {
        hexEditControl = new HexEditControl(editorContainer, readOnly ? SWT.READ_ONLY : SWT.NONE, 6, 8);
        GridData gd = new GridData(GridData.FILL_BOTH);
        gd.heightHint = 200;
        gd.minimumWidth = hexEditControl.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
        hexEditControl.setLayoutData(gd);
        minSize = hexEditControl.computeSize(SWT.DEFAULT, SWT.DEFAULT);
        minSize.x += 50;
        minSize.y += 50;
        CTabItem item = new CTabItem(editorContainer, SWT.NO_FOCUS);
        item.setText("Hex");
        item.setImage(DBeaverIcons.getImage(DBIcon.TYPE_BINARY));
        item.setControl(hexEditControl);
        if (selectedType >= editorContainer.getItemCount()) {
            selectedType = 0;
        }
        editorContainer.setSelection(selectedType);
        editorContainer.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent event) {
                getDialogSettings().put(VALUE_TYPE_SELECTOR, editorContainer.getSelectionIndex());
            }
        });
        hexEditControl.addListener(SWT.Modify, new Listener() {

            @Override
            public void handleEvent(Event event) {
                dirty = true;
            }
        });
        updateValueLength();
    }
    primeEditorValue(getValueController().getValue());
    if (isForeignKey) {
        referenceValueEditor.createEditorSelector(dialogGroup);
    }
    if (minSize != null) {
        // Set default size as minimum
        getShell().setMinimumSize(minSize);
    }
    return dialogGroup;
}
Also used : CTabFolder(org.eclipse.swt.custom.CTabFolder) StyledText(org.eclipse.swt.custom.StyledText) ModifyListener(org.eclipse.swt.events.ModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Point(org.eclipse.swt.graphics.Point) ReferenceValueEditor(org.jkiss.dbeaver.ui.data.editors.ReferenceValueEditor) CTabItem(org.eclipse.swt.custom.CTabItem) Point(org.eclipse.swt.graphics.Point) HexEditControl(org.jkiss.dbeaver.ui.editors.binary.HexEditControl) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 73 with StyledText

use of org.eclipse.swt.custom.StyledText in project dbeaver by serge-rider.

the class XMLPanelEditor method createControl.

@Override
public StyledText createControl(IValueController valueController) {
    this.valueController = valueController;
    this.subSite = new SubEditorSite(valueController.getValueSite());
    editor = new XMLEditor();
    try {
        editor.init(subSite, StringEditorInput.EMPTY_INPUT);
    } catch (PartInitException e) {
        valueController.showMessage(e.getMessage(), DBPMessageType.ERROR);
        return new StyledText(valueController.getEditPlaceholder(), SWT.NONE);
    }
    editor.createPartControl(valueController.getEditPlaceholder());
    ContentPanelEditor.setEditorSettings(editor.getEditorControl());
    return editor.getEditorControl();
}
Also used : SubEditorSite(org.jkiss.dbeaver.ui.editors.SubEditorSite) StyledText(org.eclipse.swt.custom.StyledText) PartInitException(org.eclipse.ui.PartInitException) XMLEditor(org.jkiss.dbeaver.ui.editors.xml.XMLEditor)

Example 74 with StyledText

use of org.eclipse.swt.custom.StyledText in project cubrid-manager by CUBRID.

the class TextEditorFindReplaceMediator method focusGained.

/**
	 * When text editor focus gained, update the find dialog's buttons.
	 *
	 * @param event FocusEnent
	 */
public void focusGained(FocusEvent event) {
    if (event.widget instanceof StyledText) {
        StyledText text = (StyledText) event.widget;
        setCurrentTextEditor((TextViewer) text.getData(SQL_EDITOR_FLAG));
        if (null == dialog) {
            return;
        }
        dialog.updateButtons();
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText)

Example 75 with StyledText

use of org.eclipse.swt.custom.StyledText in project eclipse.platform.text by eclipse.

the class EncodingChangeTests method testAInvalidEncoding.

@Test
public void testAInvalidEncoding() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
    try {
        fFile.setCharset("nonexistent", null);
    } catch (CoreException e2) {
        fail();
    }
    try {
        fEditor = IDE.openEditor(page, fFile);
        if (fEditor instanceof TextEditor) {
            TextEditor editor = (TextEditor) fEditor;
            Accessor accessor = new Accessor(editor, StatusTextEditor.class);
            while (editor.getSite().getShell().getDisplay().readAndDispatch()) {
            }
            ITextFileBuffer fileBuffer = FileBuffers.getTextFileBufferManager().getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
            DefaultEncodingSupport encodingSupport = (DefaultEncodingSupport) editor.getAdapter(IEncodingSupport.class);
            String expected = encodingSupport.getStatusMessage(fileBuffer.getStatus());
            Composite composite = (Composite) accessor.get("fStatusControl");
            ScrolledComposite scrolledComposite = (ScrolledComposite) composite.getChildren()[0];
            StyledText statusText = (StyledText) ((Composite) scrolledComposite.getContent()).getChildren()[5];
            String actual = statusText.getText();
            assertEquals(expected, actual);
        } else
            fail();
    } catch (PartInitException e) {
        fail();
    }
}
Also used : DefaultEncodingSupport(org.eclipse.ui.editors.text.DefaultEncodingSupport) StyledText(org.eclipse.swt.custom.StyledText) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) IEncodingSupport(org.eclipse.ui.editors.text.IEncodingSupport) Accessor(org.eclipse.text.tests.Accessor) IWorkbench(org.eclipse.ui.IWorkbench) StatusTextEditor(org.eclipse.ui.texteditor.StatusTextEditor) TextEditor(org.eclipse.ui.editors.text.TextEditor) CoreException(org.eclipse.core.runtime.CoreException) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) PartInitException(org.eclipse.ui.PartInitException) Test(org.junit.Test)

Aggregations

StyledText (org.eclipse.swt.custom.StyledText)329 Point (org.eclipse.swt.graphics.Point)102 GridData (org.eclipse.swt.layout.GridData)68 Composite (org.eclipse.swt.widgets.Composite)63 GridLayout (org.eclipse.swt.layout.GridLayout)62 Control (org.eclipse.swt.widgets.Control)46 SelectionEvent (org.eclipse.swt.events.SelectionEvent)32 Label (org.eclipse.swt.widgets.Label)32 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)30 Display (org.eclipse.swt.widgets.Display)30 Shell (org.eclipse.swt.widgets.Shell)30 Rectangle (org.eclipse.swt.graphics.Rectangle)27 Color (org.eclipse.swt.graphics.Color)25 FillLayout (org.eclipse.swt.layout.FillLayout)25 Button (org.eclipse.swt.widgets.Button)23 Text (org.eclipse.swt.widgets.Text)21 StyleRange (org.eclipse.swt.custom.StyleRange)20 Font (org.eclipse.swt.graphics.Font)20 Event (org.eclipse.swt.widgets.Event)20 Test (org.junit.Test)20