use of org.eclipse.nebula.widgets.opal.textassist.TextAssist in project aero.minova.rcp by minova-afis.
the class TabUtil method getTabListForSectionComposite.
/**
* Gibt einen Array mit den Controls für die TabListe des Composites der Section zurück.
*
* @param mSection
* der Section
* @param composite
* der Section
* @return Array mit Controls
*/
public static Control[] getTabListForSectionComposite(MSection mSection, Composite composite) {
List<Control> tabList = new ArrayList<>();
Control[] compositeChilds = composite.getChildren();
for (Control control : compositeChilds) {
if (control instanceof LookupComposite || control instanceof TextAssist || control instanceof Text) {
MField field = (MField) control.getData(Constants.CONTROL_FIELD);
if (!field.isReadOnly()) {
tabList.add(control);
}
} else if (control instanceof NatTable) {
tabList.add(control);
}
}
return tabList.toArray(new Control[0]);
}
use of org.eclipse.nebula.widgets.opal.textassist.TextAssist in project aero.minova.rcp by minova-afis.
the class ShortTimeValueAccessor method updateControlFromValue.
@Override
protected void updateControlFromValue(Control control, Value value) {
Locale locale = (Locale) control.getData(TRANSLATE_LOCALE);
Preferences preferences = InstanceScope.INSTANCE.getNode(ApplicationPreferences.PREFERENCES_NODE);
String timeUtil = (String) InstancePreferenceAccessor.getValue(preferences, ApplicationPreferences.TIME_UTIL, DisplayType.TIME_UTIL, "", locale);
if (value == null) {
((TextAssist) control).setText("");
} else {
Instant time = value.getInstantValue();
LocalTime localTime = LocalTime.ofInstant(time, ZoneId.of("UTC"));
DateTimeFormatter dtf = DateTimeFormatter.ofPattern(timeUtil, locale);
if (timeUtil.equals("")) {
((TextAssist) control).setText(localTime.format(DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT).withLocale(locale)));
} else {
((TextAssist) control).setText(localTime.format(dtf));
}
}
}
use of org.eclipse.nebula.widgets.opal.textassist.TextAssist 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.TextAssist 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.TextAssist in project aero.minova.rcp by minova-afis.
the class ShortDateValueAccessor method updateControlFromValue.
@Override
protected void updateControlFromValue(Control control, Value value) {
Locale locale = (Locale) control.getData(TRANSLATE_LOCALE);
Preferences preferences = InstanceScope.INSTANCE.getNode(ApplicationPreferences.PREFERENCES_NODE);
String dateUtil = (String) InstancePreferenceAccessor.getValue(preferences, ApplicationPreferences.DATE_UTIL, DisplayType.DATE_UTIL, "", locale);
if (value == null) {
((TextAssist) control).setText("");
} else {
Instant date = value.getInstantValue();
LocalDate localDate = LocalDate.ofInstant(date, ZoneId.of("UTC"));
DateTimeFormatter dtf = DateTimeFormatter.ofPattern(dateUtil, locale);
if (dateUtil.equals("")) {
// Bei der Formatierung geschehen fehler, wir erhalten das Milienium zurück
((TextAssist) control).setText(localDate.format(DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM).withLocale(locale)));
} else {
// Bei der Formatierung geschehen fehler, wir erhalten das Milienium zurück
((TextAssist) control).setText(localDate.format(dtf));
}
}
}
Aggregations