Search in sources :

Example 1 with HexEditControl

use of org.jkiss.dbeaver.ui.editors.binary.HexEditControl 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 2 with HexEditControl

use of org.jkiss.dbeaver.ui.editors.binary.HexEditControl in project dbeaver by dbeaver.

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 3 with HexEditControl

use of org.jkiss.dbeaver.ui.editors.binary.HexEditControl in project dbeaver by dbeaver.

the class BinaryPanelEditor method createControl.

@Override
public HexEditControl createControl(IValueController valueController) {
    HexEditControl hControl = new HexEditControl(valueController.getEditPlaceholder(), SWT.BORDER);
    DBPPreferenceListener preferencesChangeListener = new DBPPreferenceListener() {

        @Override
        public void preferenceChange(PreferenceChangeEvent event) {
            if (HexPreferencesPage.PROP_DEF_WIDTH.equals(event.getProperty())) {
                String defValue = (String) event.getNewValue();
                hControl.setDefWidth(Integer.valueOf(defValue));
            }
        }
    };
    DBPPreferenceStore store = DBeaverCore.getGlobalPreferenceStore();
    store.addPropertyChangeListener(preferencesChangeListener);
    return hControl;
}
Also used : PreferenceChangeEvent(org.jkiss.dbeaver.model.preferences.DBPPreferenceListener.PreferenceChangeEvent) DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore) HexEditControl(org.jkiss.dbeaver.ui.editors.binary.HexEditControl) DBPPreferenceListener(org.jkiss.dbeaver.model.preferences.DBPPreferenceListener)

Example 4 with HexEditControl

use of org.jkiss.dbeaver.ui.editors.binary.HexEditControl in project dbeaver by serge-rider.

the class BinaryPanelEditor method createControl.

@Override
public HexEditControl createControl(IValueController valueController) {
    HexEditControl hControl = new HexEditControl(valueController.getEditPlaceholder(), SWT.BORDER);
    DBPPreferenceListener preferencesChangeListener = new DBPPreferenceListener() {

        @Override
        public void preferenceChange(PreferenceChangeEvent event) {
            if (HexPreferencesPage.PROP_DEF_WIDTH.equals(event.getProperty())) {
                String defValue = (String) event.getNewValue();
                hControl.setDefWidth(Integer.valueOf(defValue));
            }
        }
    };
    DBPPreferenceStore store = DBWorkbench.getPlatform().getPreferenceStore();
    store.addPropertyChangeListener(preferencesChangeListener);
    return hControl;
}
Also used : DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore) HexEditControl(org.jkiss.dbeaver.ui.editors.binary.HexEditControl) DBPPreferenceListener(org.jkiss.dbeaver.model.preferences.DBPPreferenceListener)

Aggregations

HexEditControl (org.jkiss.dbeaver.ui.editors.binary.HexEditControl)4 CTabFolder (org.eclipse.swt.custom.CTabFolder)2 CTabItem (org.eclipse.swt.custom.CTabItem)2 StyledText (org.eclipse.swt.custom.StyledText)2 ModifyEvent (org.eclipse.swt.events.ModifyEvent)2 ModifyListener (org.eclipse.swt.events.ModifyListener)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Point (org.eclipse.swt.graphics.Point)2 GridData (org.eclipse.swt.layout.GridData)2 DBPPreferenceListener (org.jkiss.dbeaver.model.preferences.DBPPreferenceListener)2 DBPPreferenceStore (org.jkiss.dbeaver.model.preferences.DBPPreferenceStore)2 DBSTypedObject (org.jkiss.dbeaver.model.struct.DBSTypedObject)2 ReferenceValueEditor (org.jkiss.dbeaver.ui.data.editors.ReferenceValueEditor)2 PreferenceChangeEvent (org.jkiss.dbeaver.model.preferences.DBPPreferenceListener.PreferenceChangeEvent)1