Search in sources :

Example 1 with TextAssist

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]);
}
Also used : Control(org.eclipse.swt.widgets.Control) LookupComposite(aero.minova.rcp.widgets.LookupComposite) ArrayList(java.util.ArrayList) TextAssist(org.eclipse.nebula.widgets.opal.textassist.TextAssist) Text(org.eclipse.swt.widgets.Text) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) MField(aero.minova.rcp.model.form.MField)

Example 2 with TextAssist

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));
        }
    }
}
Also used : Locale(java.util.Locale) LocalTime(java.time.LocalTime) Instant(java.time.Instant) TextAssist(org.eclipse.nebula.widgets.opal.textassist.TextAssist) Preferences(org.osgi.service.prefs.Preferences) ApplicationPreferences(aero.minova.rcp.preferences.ApplicationPreferences) DateTimeFormatter(java.time.format.DateTimeFormatter)

Example 3 with TextAssist

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;
}
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 4 with TextAssist

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;
}
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 5 with TextAssist

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));
        }
    }
}
Also used : Locale(java.util.Locale) Instant(java.time.Instant) TextAssist(org.eclipse.nebula.widgets.opal.textassist.TextAssist) Preferences(org.osgi.service.prefs.Preferences) ApplicationPreferences(aero.minova.rcp.preferences.ApplicationPreferences) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter)

Aggregations

TextAssist (org.eclipse.nebula.widgets.opal.textassist.TextAssist)8 ApplicationPreferences (aero.minova.rcp.preferences.ApplicationPreferences)7 Preferences (org.osgi.service.prefs.Preferences)7 Instant (java.time.Instant)6 LocalDateTime (java.time.LocalDateTime)4 ArrayList (java.util.ArrayList)4 CssData (aero.minova.rcp.css.CssData)3 Value (aero.minova.rcp.model.Value)3 DateTimeFormatter (java.time.format.DateTimeFormatter)3 Locale (java.util.Locale)3 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)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 MField (aero.minova.rcp.model.form.MField)2 LookupComposite (aero.minova.rcp.widgets.LookupComposite)2 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)2