use of aero.minova.rcp.css.CssData in project aero.minova.rcp by minova-afis.
the class ShortTimeField method create.
public static Control create(Composite composite, MField field, int row, int column, Locale locale, String timezone, MPerspective perspective, TranslationService translationService) {
Preferences preferences = InstanceScope.INSTANCE.getNode(ApplicationPreferences.PREFERENCES_NODE);
String timeUtil = (String) InstancePreferenceAccessor.getValue(preferences, ApplicationPreferences.TIME_UTIL, DisplayType.TIME_UTIL, "", locale);
Label label = FieldLabel.create(composite, field);
TextAssistContentProvider contentProvider = new TextAssistContentProvider() {
@Override
public List<String> getContent(String entry) {
ArrayList<String> result = new ArrayList<>();
Instant time = TimeUtil.getTime(entry, timeUtil, locale);
if (time == null && !entry.isEmpty()) {
result.add(translationService.translate("@msg.ErrorConverting", null));
} else {
result.add(TimeUtil.getTimeString(time, locale, timeUtil));
field.setValue(new Value(time), true);
}
return result;
}
};
TextAssist text = new TextAssist(composite, SWT.BORDER, contentProvider);
LocalDateTime date = LocalDateTime.of(LocalDate.of(2000, 01, 01), LocalTime.of(11, 59));
text.setMessage(TimeUtil.getTimeString(date.toInstant(ZoneOffset.UTC), locale, timeUtil));
text.setNumberOfLines(1);
text.setData(TRANSLATE_LOCALE, locale);
text.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
text.selectAll();
}
@Override
public void focusLost(FocusEvent e) {
if (text.getText().isBlank()) {
field.setValue(null, true);
}
}
});
text.setData(Constants.CONTROL_FIELD, field);
// ValueAccessor in den Context injecten, damit IStylingEngine über @Inject verfügbar ist (in AbstractValueAccessor)
IEclipseContext context = perspective.getContext();
ShortTimeValueAccessor valueAccessor = new ShortTimeValueAccessor(field, text);
ContextInjectionFactory.inject(valueAccessor, context);
field.setValueAccessor(valueAccessor);
FieldLabel.layout(label, text, row, column, field.getNumberRowsSpanned());
FormData fd = new FormData();
fd.top = new FormAttachment(composite, MARGIN_TOP + row * COLUMN_HEIGHT);
fd.left = new FormAttachment((column == 0) ? 25 : 75);
fd.width = TEXT_WIDTH;
text.setLayoutData(fd);
text.setData(CssData.CSSDATA_KEY, new CssData(CssType.TIME_FIELD, column + 1, row, 1, 1, false));
return text;
}
use of aero.minova.rcp.css.CssData in project aero.minova.rcp by minova-afis.
the class NumberField method create.
public static Control create(Composite composite, MNumberField field, int row, int column, Locale locale, MPerspective perspective) {
String unitText = field.getUnitText() == null ? "" : field.getUnitText();
Label label = FieldLabel.create(composite, field);
Text text = TextFactory.newText(SWT.BORDER | SWT.RIGHT).text("").create(composite);
NumberValueAccessor numberValueAccessor = new NumberValueAccessor(field, text);
text.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
text.selectAll();
}
});
text.addVerifyListener(numberValueAccessor);
// ValueAccessor in den Context injecten, damit IStylingEngine über @Inject verfügbar ist (in AbstractValueAccessor)
IEclipseContext context = perspective.getContext();
ContextInjectionFactory.inject(numberValueAccessor, context);
field.setValueAccessor(numberValueAccessor);
Label unit = LabelFactory.newLabel(SWT.LEFT).text(unitText).create(composite);
FormData textFormData = new FormData();
FormData unitFormData = new FormData();
FieldLabel.layout(label, text, row, column, field.getNumberRowsSpanned());
textFormData.top = new FormAttachment(composite, MARGIN_TOP + row * COLUMN_HEIGHT);
textFormData.left = new FormAttachment((column == 0) ? 25 : 75);
textFormData.width = NUMBER_WIDTH;
unitFormData.top = new FormAttachment(text, 0, SWT.CENTER);
unitFormData.left = new FormAttachment(text, 0, SWT.RIGHT);
unitFormData.right = new FormAttachment((column == 0) ? 50 : 100);
Integer decimals = field.getDecimals();
decimals = decimals == null ? 0 : decimals;
Double maximum = field.getMaximumValue();
maximum = maximum == null ? Double.MAX_VALUE : maximum;
Double minimum = field.getMinimumValue();
minimum = minimum == null ? Double.MIN_VALUE : maximum;
text.setData(TRANSLATE_LOCALE, locale);
text.setData(FIELD_DECIMALS, decimals);
text.setData(FIELD_MAX_VALUE, maximum);
text.setData(FIELD_MIN_VALUE, minimum);
text.setData(Constants.CONTROL_FIELD, field);
text.setLayoutData(textFormData);
NumberFieldUtil.setMessage(text);
text.setData(CssData.CSSDATA_KEY, new CssData(CssType.NUMBER_FIELD, column + 1, row, field.getNumberColumnsSpanned(), field.getNumberRowsSpanned(), field.isFillToRight() || field.isFillHorizontal()));
unit.setData(TRANSLATE_PROPERTY, unitText);
unit.setData(CSSSWTConstants.CSS_CLASS_NAME_KEY, "DescriptionLabel");
unit.setLayoutData(unitFormData);
return text;
}
use of aero.minova.rcp.css.CssData in project aero.minova.rcp by minova-afis.
the class TextField method create.
public static Control create(Composite composite, MField field, int row, int column, MPerspective perspective) {
Label label = FieldLabel.create(composite, field);
int style = SWT.BORDER;
if (field.getNumberRowsSpanned() > 1) {
// Maskenentwickler hat mehrzeilige Eingabe definiert
style |= SWT.WRAP;
}
Text text = TextFactory.newText(style).text("").create(composite);
text.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
text.selectAll();
}
});
// Wenn der Anwender den Wert ändert, muss es weitergegeben werden
text.addModifyListener(e -> {
if (text.isFocusControl()) {
String newValue = text.getText();
if (newValue.length() < 1) {
field.setValue(null, true);
} else {
field.setValue(new Value(newValue), true);
}
}
});
text.addTraverseListener(e -> {
if (e.detail == SWT.TRAVERSE_TAB_NEXT && e.stateMask == 0) {
e.doit = true;
} else if (e.detail == SWT.TRAVERSE_TAB_NEXT && e.stateMask == 262144) {
e.doit = false;
text.setText(text.getText() + "\t");
text.setSelection(text.getText().length());
} else if (e.detail == SWT.TRAVERSE_TAB_NEXT && e.stateMask == 65536) {
e.doit = true;
}
});
text.setData(Constants.CONTROL_FIELD, field);
CssData cssData = new CssData(CssType.TEXT_FIELD, column + 1, row, field.getNumberColumnsSpanned(), field.getNumberRowsSpanned(), field.isFillToRight() || field.isFillHorizontal());
text.setData(CssData.CSSDATA_KEY, cssData);
// ValueAccessor in den Context injecten, damit IStylingEngine über @Inject verfügbar ist (in AbstractValueAccessor)
IEclipseContext context = perspective.getContext();
TextValueAccessor valueAccessor = new TextValueAccessor(field, text);
ContextInjectionFactory.inject(valueAccessor, context);
field.setValueAccessor(valueAccessor);
FieldLabel.layout(label, text, row, column, field.getNumberRowsSpanned());
FormData fd = new FormData();
fd.top = new FormAttachment(composite, MARGIN_TOP + row * COLUMN_HEIGHT);
if (field.isFillHorizontal() && field.getLabel() == null) {
fd.left = new FormAttachment((column == 0) ? 0 : 50);
} else {
fd.left = new FormAttachment((column == 0) ? 25 : 75);
}
if ((field.getNumberColumnsSpanned() > 2 && field.isFillToRight()) || field.isFillHorizontal() || column >= 2) {
fd.right = new FormAttachment(100, -MARGIN_BORDER);
} else {
fd.right = new FormAttachment(50, -ICssStyler.CSS_SECTION_SPACING);
}
text.setLayoutData(fd);
return text;
}
Aggregations