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;
}
});
}
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;
}
}
}
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;
}
Aggregations