Search in sources :

Example 1 with TextAssistContentProvider

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;
}
Also used : LocalDateTime(java.time.LocalDateTime) DateTimeValueAccessor(aero.minova.rcp.rcp.accessor.DateTimeValueAccessor) FormData(org.eclipse.swt.layout.FormData) FocusAdapter(org.eclipse.swt.events.FocusAdapter) Instant(java.time.Instant) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) FocusEvent(org.eclipse.swt.events.FocusEvent) TextAssistContentProvider(org.eclipse.nebula.widgets.opal.textassist.TextAssistContentProvider) Value(aero.minova.rcp.model.Value) TextAssist(org.eclipse.nebula.widgets.opal.textassist.TextAssist) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Preferences(org.osgi.service.prefs.Preferences) ApplicationPreferences(aero.minova.rcp.preferences.ApplicationPreferences) FormAttachment(org.eclipse.swt.layout.FormAttachment) CssData(aero.minova.rcp.css.CssData)

Example 2 with TextAssistContentProvider

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;
}
Also used : LocalDateTime(java.time.LocalDateTime) FormData(org.eclipse.swt.layout.FormData) FocusAdapter(org.eclipse.swt.events.FocusAdapter) Instant(java.time.Instant) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) FocusEvent(org.eclipse.swt.events.FocusEvent) ShortDateValueAccessor(aero.minova.rcp.rcp.accessor.ShortDateValueAccessor) TextAssistContentProvider(org.eclipse.nebula.widgets.opal.textassist.TextAssistContentProvider) Value(aero.minova.rcp.model.Value) TextAssist(org.eclipse.nebula.widgets.opal.textassist.TextAssist) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Preferences(org.osgi.service.prefs.Preferences) ApplicationPreferences(aero.minova.rcp.preferences.ApplicationPreferences) FormAttachment(org.eclipse.swt.layout.FormAttachment) CssData(aero.minova.rcp.css.CssData)

Example 3 with TextAssistContentProvider

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;
}
Also used : LocalDateTime(java.time.LocalDateTime) FormData(org.eclipse.swt.layout.FormData) FocusAdapter(org.eclipse.swt.events.FocusAdapter) ShortTimeValueAccessor(aero.minova.rcp.rcp.accessor.ShortTimeValueAccessor) Instant(java.time.Instant) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) FocusEvent(org.eclipse.swt.events.FocusEvent) TextAssistContentProvider(org.eclipse.nebula.widgets.opal.textassist.TextAssistContentProvider) Value(aero.minova.rcp.model.Value) TextAssist(org.eclipse.nebula.widgets.opal.textassist.TextAssist) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Preferences(org.osgi.service.prefs.Preferences) ApplicationPreferences(aero.minova.rcp.preferences.ApplicationPreferences) FormAttachment(org.eclipse.swt.layout.FormAttachment) CssData(aero.minova.rcp.css.CssData)

Aggregations

CssData (aero.minova.rcp.css.CssData)3 Value (aero.minova.rcp.model.Value)3 ApplicationPreferences (aero.minova.rcp.preferences.ApplicationPreferences)3 Instant (java.time.Instant)3 LocalDateTime (java.time.LocalDateTime)3 ArrayList (java.util.ArrayList)3 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)3 TextAssist (org.eclipse.nebula.widgets.opal.textassist.TextAssist)3 TextAssistContentProvider (org.eclipse.nebula.widgets.opal.textassist.TextAssistContentProvider)3 FocusAdapter (org.eclipse.swt.events.FocusAdapter)3 FocusEvent (org.eclipse.swt.events.FocusEvent)3 FormAttachment (org.eclipse.swt.layout.FormAttachment)3 FormData (org.eclipse.swt.layout.FormData)3 Label (org.eclipse.swt.widgets.Label)3 Preferences (org.osgi.service.prefs.Preferences)3 DateTimeValueAccessor (aero.minova.rcp.rcp.accessor.DateTimeValueAccessor)1 ShortDateValueAccessor (aero.minova.rcp.rcp.accessor.ShortDateValueAccessor)1 ShortTimeValueAccessor (aero.minova.rcp.rcp.accessor.ShortTimeValueAccessor)1