use of org.eclipse.nebula.widgets.opal.textassist.TextAssistContentProvider 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 org.eclipse.nebula.widgets.opal.textassist.TextAssistContentProvider 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 org.eclipse.nebula.widgets.opal.textassist.TextAssistContentProvider 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;
}
Aggregations