Search in sources :

Example 1 with Mode

use of com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType.Mode in project convertigo by convertigo.

the class NgxSmartSourceTypeCellEditor method setValidator.

@Override
public void setValidator(ICellEditorValidator validator) {
    super.setValidator(new ICellEditorValidator() {

        @Override
        public String isValid(Object value) {
            String error = null;
            String txt = null;
            Mode mode = null;
            if (value instanceof MobileSmartSourceType) {
                MobileSmartSourceType m = (MobileSmartSourceType) value;
                mode = m.getMode();
                txt = m.getValue();
                if (!Mode.PLAIN.equals(m.getMode())) {
                    String s = m.getValue();
                    if (s.isEmpty()) {
                        error = "cannot be empty";
                    }
                }
            } else if (value instanceof String && msst != null) {
                mode = msst.getMode();
                txt = (String) value;
            }
            if (txt != null) {
                if (!Mode.PLAIN.equals(mode) && txt.isEmpty()) {
                    error = "value cannot be empty with mode " + mode.label();
                } else if (validator != null) {
                    error = validator.isValid(txt);
                }
            }
            return error;
        }
    });
}
Also used : ICellEditorValidator(org.eclipse.jface.viewers.ICellEditorValidator) MobileSmartSourceType(com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType) Mode(com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType.Mode) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Example 2 with Mode

use of com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType.Mode in project convertigo by convertigo.

the class NgxSmartSourceTypeCellEditor method doSetValue.

@Override
protected void doSetValue(Object value) {
    this.msst = ((MobileSmartSourceType) value).clone();
    Mode mode = this.msst.getMode();
    comboBox.setText(this.msst.getValue());
    for (Button button : buttons) {
        if (button.getData(DataKeys.SMART_TYPE.name()) == mode) {
            button.notifyListeners(SWT.Selection, null);
            break;
        }
    }
}
Also used : Button(org.eclipse.swt.widgets.Button) Mode(com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType.Mode)

Example 3 with Mode

use of com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType.Mode in project convertigo by convertigo.

the class NgxSmartSourceTypeCellEditor method createControl.

@Override
protected Control createControl(Composite parent) {
    final boolean itemsReadOnly = getStyle() == SWT.READ_ONLY;
    final Composite control = new Composite(parent, SWT.NONE) {

        @Override
        public boolean isFocusControl() {
            return true;
        }
    };
    Font font = parent.getFont();
    Color bg = parent.getBackground();
    control.setFont(font);
    control.setForeground(control.getDisplay().getSystemColor(SWT.COLOR_BLACK));
    control.setBackground(bg);
    GridLayout gl = new GridLayout(99, false);
    gl.horizontalSpacing = gl.marginHeight = gl.marginWidth = gl.verticalSpacing = 0;
    control.setLayout(gl);
    comboBox = new CCombo(control, SWT.NONE);
    comboBox.setFont(control.getFont());
    comboBox.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    populateComboBoxItems();
    comboBox.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            keyReleaseOccured(e);
        }
    });
    comboBox.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetDefaultSelected(SelectionEvent event) {
            applyEditorValueAndDeactivate();
        }

        @Override
        public void widgetSelected(SelectionEvent event) {
            selection = comboBox.getSelectionIndex();
        }
    });
    comboBox.addTraverseListener(new TraverseListener() {

        @Override
        public void keyTraversed(TraverseEvent e) {
            if (e.detail == SWT.TRAVERSE_ESCAPE || e.detail == SWT.TRAVERSE_RETURN) {
                e.doit = false;
            }
        }
    });
    comboBox.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            if (!isCorrect(comboBox.getText())) {
                setValueValid(false);
                setErrorMessage(MessageFormat.format(getErrorMessage(), new Object[] { comboBox.getText() }));
            } else {
                setValueValid(true);
                setErrorMessage(null);
            }
        }
    });
    comboBox.addVerifyListener(new VerifyListener() {

        @Override
        public void verifyText(VerifyEvent e) {
            String oldS = comboBox.getText();
            String newS = oldS.substring(0, e.start) + e.text + oldS.substring(e.end);
            boolean oldValidState = isValueValid();
            if (!isCorrect(newS)) {
                setValueValid(false);
                setErrorMessage(MessageFormat.format(getErrorMessage(), new Object[] { newS }));
                valueChanged(oldValidState, false);
            } else {
                setValueValid(true);
                setErrorMessage(null);
                valueChanged(oldValidState, true);
            }
        }
    });
    comboBox.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(FocusEvent e) {
        // NgxSmartSourceTypeCellEditor.this.focusLost();
        }
    });
    FontData fontDefaultData = font.getFontData()[0];
    fontDefaultData.setStyle(SWT.BOLD);
    fontDefaultData.setHeight(Math.round(fontDefaultData.getHeight() * 0.7f));
    final Font fontTitle = new Font(parent.getDisplay(), fontDefaultData);
    dotButton = new Button(control, SWT.NONE);
    dotButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
    dotButton.setFont(fontTitle);
    dotButton.setText("…");
    dotButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            openDialog();
        }
    });
    buttons = new ArrayList<Button>(3);
    SelectionListener selectionListener = new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            for (Button button : buttons) {
                button.setSelection(false);
            }
            Button button = (Button) e.widget;
            button.setSelection(true);
            comboBox.getDisplay().asyncExec(() -> {
                comboBox.setForeground(button.getDisplay().getSystemColor(SWT.COLOR_BLACK));
                comboBox.setBackground((Color) button.getData(DataKeys.TEXT_COLOR.name()));
            });
            Mode mode = (Mode) button.getData(DataKeys.SMART_TYPE.name());
            msst.setMode(mode);
            if (Mode.PLAIN.equals(mode)) {
                populateComboBoxItems();
            } else {
                comboBox.removeAll();
                comboBox.add("");
                selection = -1;
            }
            comboBox.setText(msst.getValue());
            comboBox.setEditable(!(Mode.PLAIN.equals(mode) && itemsReadOnly) || Mode.SCRIPT.equals(mode));
            comboBox.setEnabled(!Mode.SOURCE.equals(mode));
            dotButton.setEnabled(!(Mode.PLAIN.equals(mode) && itemsReadOnly));
            dialogCompositeClass = GenericUtils.cast(button.getData(DataKeys.EDITOR_CLASS.name()));
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    };
    Button button = null;
    button = new Button(control, SWT.TOGGLE | SWT.FLAT);
    button.setForeground(ColorEnum.DARK_YELLOW.get());
    button.setData(DataKeys.TEXT_COLOR.name(), ColorEnum.LIGHT_YELLOW.get());
    button.setData(DataKeys.SMART_TYPE.name(), Mode.PLAIN);
    button.setData(DataKeys.EDITOR_CLASS.name(), TextEditorComposite.class);
    buttons.add(button);
    button = new Button(control, SWT.TOGGLE | SWT.FLAT);
    button.setForeground(ColorEnum.DARK_BLUE.get());
    button.setData(DataKeys.TEXT_COLOR.name(), ColorEnum.JAVASCRIPTABLE.get());
    button.setData(DataKeys.SMART_TYPE.name(), Mode.SCRIPT);
    button.setData(DataKeys.EDITOR_CLASS.name(), TextEditorComposite.class);
    buttons.add(button);
    button = new Button(control, SWT.TOGGLE | SWT.FLAT);
    button.setForeground(ColorEnum.DARK_GREEN.get());
    button.setData(DataKeys.TEXT_COLOR.name(), ColorEnum.LIGHT_GREEN.get());
    button.setData(DataKeys.SMART_TYPE.name(), Mode.SOURCE);
    button.setData(DataKeys.EDITOR_CLASS.name(), NgxSmartSourceEditorComposite.class);
    buttons.add(button);
    for (Button bt : buttons) {
        Mode mode = (Mode) bt.getData(DataKeys.SMART_TYPE.name());
        bt.setText(mode.label());
        bt.setToolTipText(mode.tooltip());
        bt.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
        bt.setFont(fontTitle);
        bt.addSelectionListener(selectionListener);
        bt.addMouseListener(new MouseListener() {

            public void mouseUp(MouseEvent e) {
            }

            public void mouseDown(MouseEvent e) {
            }

            public void mouseDoubleClick(MouseEvent e) {
                openDialog();
            }
        });
    }
    return control;
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) TraverseEvent(org.eclipse.swt.events.TraverseEvent) ModifyListener(org.eclipse.swt.events.ModifyListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) FocusEvent(org.eclipse.swt.events.FocusEvent) Font(org.eclipse.swt.graphics.Font) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) MouseListener(org.eclipse.swt.events.MouseListener) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) VerifyEvent(org.eclipse.swt.events.VerifyEvent) VerifyListener(org.eclipse.swt.events.VerifyListener) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) TraverseListener(org.eclipse.swt.events.TraverseListener) Color(org.eclipse.swt.graphics.Color) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FontData(org.eclipse.swt.graphics.FontData) Mode(com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType.Mode) CCombo(org.eclipse.swt.custom.CCombo) GridData(org.eclipse.swt.layout.GridData) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

Mode (com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType.Mode)3 Button (org.eclipse.swt.widgets.Button)2 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)1 MobileSmartSourceType (com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType)1 ICellEditorValidator (org.eclipse.jface.viewers.ICellEditorValidator)1 CCombo (org.eclipse.swt.custom.CCombo)1 FocusAdapter (org.eclipse.swt.events.FocusAdapter)1 FocusEvent (org.eclipse.swt.events.FocusEvent)1 KeyAdapter (org.eclipse.swt.events.KeyAdapter)1 KeyEvent (org.eclipse.swt.events.KeyEvent)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1 MouseListener (org.eclipse.swt.events.MouseListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 TraverseEvent (org.eclipse.swt.events.TraverseEvent)1 TraverseListener (org.eclipse.swt.events.TraverseListener)1 VerifyEvent (org.eclipse.swt.events.VerifyEvent)1