use of aero.minova.rcp.css.CssData in project aero.minova.rcp by minova-afis.
the class DateTimeField 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 dateUtil = (String) InstancePreferenceAccessor.getValue(preferences, ApplicationPreferences.DATE_UTIL, DisplayType.DATE_UTIL, "", locale);
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 date = DateTimeUtil.getDateTime(Instant.now(), entry, locale);
if (date == null && !entry.isEmpty()) {
result.add(translationService.translate("@msg.ErrorConverting", null));
} else {
result.add(DateTimeUtil.getDateTimeString(date, locale, dateUtil, timeUtil));
field.setValue(new Value(date), true);
}
return result;
}
};
TextAssist text = new TextAssist(composite, SWT.BORDER, contentProvider);
LocalDateTime of = LocalDateTime.of(LocalDate.of(2020, 12, 12), LocalTime.of(22, 55));
text.setMessage(DateTimeUtil.getDateTimeString(of.toInstant(ZoneOffset.UTC), locale, dateUtil, 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();
DateTimeValueAccessor valueAccessor = new DateTimeValueAccessor(field, text);
ContextInjectionFactory.inject(valueAccessor, context);
field.setValueAccessor(valueAccessor);
FormData fd = new FormData();
fd.top = new FormAttachment(composite, MARGIN_TOP + row * COLUMN_HEIGHT);
fd.left = new FormAttachment(column == 0 ? 25 : 75);
fd.right = new FormAttachment(column == 0 ? 50 : 100, column == 0 ? -ICssStyler.CSS_SECTION_SPACING : -MARGIN_BORDER);
text.setLayoutData(fd);
text.setData(CssData.CSSDATA_KEY, new CssData(CssType.DATE_TIME_FIELD, column + 1, row, field.getNumberColumnsSpanned(), field.getNumberRowsSpanned(), false));
FieldLabel.layout(label, text, row, column, field.getNumberRowsSpanned());
return text;
}
use of aero.minova.rcp.css.CssData in project aero.minova.rcp by minova-afis.
the class BooleanField method create.
public static Control create(Composite composite, MField field, int row, int column, Locale locale, MPerspective perspective) {
String labelText = field.getLabel() == null ? "" : field.getLabel();
Button button = ButtonFactory.newButton(SWT.CHECK).text(field.getLabel()).create(composite);
// ValueAccessor in den Context injecten, damit IStylingEngine über @Inject verfügbar ist (in AbstractValueAccessor)
IEclipseContext context = perspective.getContext();
BooleanValueAccessor valueAccessor = new BooleanValueAccessor(field, button);
ContextInjectionFactory.inject(valueAccessor, context);
field.setValueAccessor(valueAccessor);
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;
button.setLayoutData(fd);
button.setData(CssData.CSSDATA_KEY, new CssData(CssType.TEXT_FIELD, column + 1, row, 1, 1, false));
button.setData(CSSSWTConstants.CSS_CLASS_NAME_KEY, "Description");
button.setData(TRANSLATE_PROPERTY, labelText);
button.setData(TRANSLATE_LOCALE, locale);
button.setData(Constants.CONTROL_FIELD, field);
button.setData(Constants.CONTROL_DATATYPE, DataType.BOOLEAN);
button.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
field.setValue(new Value(button.getSelection()), true);
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
field.setValue(new Value(button.getSelection()), true);
}
});
return button;
}
use of aero.minova.rcp.css.CssData in project aero.minova.rcp by minova-afis.
the class FieldLabel method layout.
public static void layout(Label label, Control field, int row, int column, int numberRowsSpanned) {
FormData fd = new FormData();
fd.right = new FormAttachment(field, MARGIN_LEFT * -1, SWT.LEFT);
fd.left = new FormAttachment((column == 0) ? 0 : 50);
fd.top = new FormAttachment(field, 0, (numberRowsSpanned > 1) ? SWT.TOP : SWT.CENTER);
label.setLayoutData(fd);
CssData cssData = new CssData(CssType.LABEL, column, row, 1, numberRowsSpanned, false);
label.setData(CssData.CSSDATA_KEY, cssData);
}
use of aero.minova.rcp.css.CssData in project aero.minova.rcp by minova-afis.
the class ShortDateField 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 dateUtil = (String) InstancePreferenceAccessor.getValue(preferences, ApplicationPreferences.DATE_UTIL, DisplayType.DATE_UTIL, "", locale);
Label label = FieldLabel.create(composite, field);
TextAssistContentProvider contentProvider = new TextAssistContentProvider() {
@Override
public List<String> getContent(String entry) {
Preferences preferences = InstanceScope.INSTANCE.getNode(ApplicationPreferences.PREFERENCES_NODE);
String dateUtil = (String) InstancePreferenceAccessor.getValue(preferences, ApplicationPreferences.DATE_UTIL, DisplayType.DATE_UTIL, "", locale);
ArrayList<String> result = new ArrayList<>();
Instant date = DateUtil.getDate(entry, locale, dateUtil);
if (date == null) {
result.add(translationService.translate("@msg.ErrorConverting", null));
} else {
result.add(DateUtil.getDateString(date, locale, dateUtil));
field.setValue(new Value(date), true);
}
return result;
}
};
TextAssist text = new TextAssist(composite, SWT.BORDER, contentProvider);
LocalDateTime time = LocalDateTime.of(LocalDate.of(2000, 01, 01), LocalTime.of(11, 59));
text.setMessage(DateUtil.getDateString(time.toInstant(ZoneOffset.UTC), locale, dateUtil));
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();
ShortDateValueAccessor valueAccessor = new ShortDateValueAccessor(field, text);
ContextInjectionFactory.inject(valueAccessor, context);
field.setValueAccessor(valueAccessor);
FormData fd = new FormData();
fd.top = new FormAttachment(composite, MARGIN_TOP + row * COLUMN_HEIGHT);
fd.left = new FormAttachment((column == 0) ? 25 : 75);
fd.width = SHORT_DATE_WIDTH;
text.setLayoutData(fd);
text.setData(CssData.CSSDATA_KEY, new CssData(CssType.DATE_FIELD, column + 1, row, field.getNumberColumnsSpanned(), field.getNumberRowsSpanned(), false));
FieldLabel.layout(label, text, row, column, field.getNumberRowsSpanned());
return text;
}
use of aero.minova.rcp.css.CssData in project aero.minova.rcp by minova-afis.
the class LookupField method create.
public static Control create(Composite composite, MField field, int row, int column, Locale locale, MPerspective perspective) {
Label label = FieldLabel.create(composite, field);
IEclipseContext context = perspective.getContext();
LookupComposite lookupControl = new LookupComposite(composite, SWT.BORDER | SWT.LEFT);
lookupControl.setMessage("...");
lookupControl.setLabel(label);
// In Context injected, damit TranslationService genutzt werden kann
ContextInjectionFactory.inject(lookupControl, context);
LookupContentProvider contentProvider = new LookupContentProvider(field.getLookupTable());
contentProvider.setLookup(lookupControl);
lookupControl.setContentProvider(contentProvider);
// In Context injected, damit TranslationService genutzt werden kann
ContextInjectionFactory.inject(contentProvider, context);
Label descriptionLabel = LabelFactory.newLabel(SWT.LEFT).create(composite);
FormData lookupFormData = new FormData();
FormData labelFormData = new FormData();
FormData descriptionLabelFormData = new FormData();
LookupValueAccessor lookupValueAccessor = new LookupValueAccessor(field, lookupControl);
ContextInjectionFactory.inject(lookupValueAccessor, context);
field.setValueAccessor(lookupValueAccessor);
lookupControl.setData(Constants.CONTROL_FIELD, field);
lookupFormData.top = new FormAttachment(composite, FieldUtil.MARGIN_TOP + row * FieldUtil.COLUMN_HEIGHT);
lookupFormData.left = new FormAttachment((column == 0) ? 25 : 75);
lookupFormData.width = FieldUtil.TEXT_WIDTH;
// Lookup-Felder sollen immer genau eine Zeile hoch sein
CssData cssData = new CssData(CssType.TEXT_FIELD, column, row, field.getNumberColumnsSpanned(), 1, field.isFillToRight() || field.isFillHorizontal());
lookupControl.setData(CssData.CSSDATA_KEY, cssData);
labelFormData.top = new FormAttachment(lookupControl, 0, SWT.CENTER);
labelFormData.right = new FormAttachment(lookupControl, FieldUtil.MARGIN_LEFT * -1, SWT.LEFT);
labelFormData.width = FieldUtil.COLUMN_WIDTH;
descriptionLabelFormData.top = new FormAttachment(lookupControl, 0, SWT.CENTER);
descriptionLabelFormData.left = new FormAttachment(lookupControl, 0, SWT.RIGHT);
if (field.getNumberColumnsSpanned() == 4) {
descriptionLabelFormData.width = FieldUtil.MARGIN_LEFT * 2 + FieldUtil.COLUMN_WIDTH * 2;
} else {
descriptionLabelFormData.width = 0;
}
if (field.getNumberRowsSpanned() > 1) {
// ZB für Contact Lookups
descriptionLabelFormData.height = field.getNumberRowsSpanned() * FieldUtil.COLUMN_HEIGHT;
descriptionLabelFormData.top = new FormAttachment(lookupControl, 0, SWT.TOP);
}
label.setData(AERO_MINOVA_RCP_LOOKUP, lookupControl);
FieldLabel.layout(label, lookupControl, row, column, field.getNumberRowsSpanned());
lookupControl.setLayoutData(lookupFormData);
lookupControl.setDescription(descriptionLabel);
descriptionLabel.setLayoutData(descriptionLabelFormData);
descriptionLabel.setData(CSSSWTConstants.CSS_CLASS_NAME_KEY, "DescriptionLabel");
lookupControl.addTraverseListener(e -> {
Text text = ((Text) e.getSource());
LookupComposite t = (LookupComposite) text.getParent();
switch(e.detail) {
case SWT.TRAVERSE_TAB_PREVIOUS:
case SWT.TRAVERSE_TAB_NEXT:
case SWT.TRAVERSE_RETURN:
t.fillSelectedValue();
e.doit = true;
break;
}
});
return lookupControl;
}
Aggregations