Search in sources :

Example 6 with TextAssist

use of org.eclipse.nebula.widgets.opal.textassist.TextAssist in project aero.minova.rcp by minova-afis.

the class TraverseEnterHandler method getNextRequired.

/**
 * Diese Methode ermittelt das nächste leere Pflichtfeld nach folgendem Muster: <br>
 * <br>
 * 1. Prüfen, ob LookupEnterSelectsNextRequired gesetzt ist und ein Lookup mit offenen Popup selektiert ist:<br>
 * <br>
 * LookupEnterSelectsNextRequired ist nicht gesetzt: <br>
 * Bei einem Lookup mit offenen Popup wird der ausgewählte Wert festgesetzt und das Lookup bleibt selektiert. <br>
 * <br>
 * LookupEnterSelectsNextRequired ist gesetzt:<br>
 * Bei einem Lookup mit offenen Popup wird der ausgewählte Wert festgesetzt und das nächste leere Pflichtfeld selektiert. <br>
 * <br>
 * 2. Prüfen, ob EnterSelectsFirstRequired gesetzt ist und kein Lookup mit offenem Popup selektiert ist: <br>
 * <br>
 * EnterSelectsFirstRequired ist gesetzt: <br>
 * Begonnen mit der ersten Section, wird das erste leere Pflichtfeld ermittelt und selektiert. <br>
 * <br>
 * EnterSelectsFirstRequired ist nicht gesetzt und es ist kein Lookup mit offenem Popup selektiert: <br>
 * - Beginnend mit der Section, in der das aktuell selektierte Control sich befindet, wird das nächste leere Pflichtfeld ermittelt. Dabei werden nur die
 * Controls nach dem aktuell selektiertem geprüft.<br>
 * - Wenn kein Pflichtfeld gefunden wurde, werden die Sections, die nach der Section des selektierten Controls kommen, durchsucht.<br>
 * - Falls am Ende des Parts angekommen und immer noch kein Pflichtfeld selektiert wurde, wird mit den Sections vor dem des selektierten Control weiter
 * gemacht. Beginnend mit der ersten section <br>
 * - Bei der Section des aktuell selektierten Controls angekommen ohne ein Pflichtfeld selktiert zu haben, werden nun die Controls in der Section und vor
 * dem selktierten Control durchsucht. <br>
 * <br>
 * Wenn kein Pflichtfeld gefunden wird, bleibt das aktuelle Pflichtfeld selektiert.
 *
 * @param control
 *            fokussiertes Control
 * @param mDetail
 * @param popupOpen
 */
private void getNextRequired(Control control, MDetail mDetail, boolean popupOpen) {
    Preferences preferences = InstanceScope.INSTANCE.getNode(ApplicationPreferences.PREFERENCES_NODE);
    boolean lookupEnterSelectsNextRequired = (boolean) InstancePreferenceAccessor.getValue(preferences, ApplicationPreferences.LOOKUP_ENTER_SELECTS_NEXT_REQUIRED, DisplayType.CHECK, true, locale);
    boolean enterSelectsFirstRequired = (boolean) InstancePreferenceAccessor.getValue(preferences, ApplicationPreferences.ENTER_SELECTS_FIRST_REQUIRED, DisplayType.CHECK, true, locale);
    Control focussedControl = null;
    if (control.getParent() instanceof TextAssist || control.getParent() instanceof LookupComposite) {
        focussedControl = control.getParent();
    } else {
        focussedControl = control;
    }
    // Wir holen uns das MField des selektierten Felds.
    Control fc = null;
    Composite comp = null;
    Section fcSection = null;
    if (focussedControl instanceof NatTable) {
        fcSection = (Section) focussedControl.getData(Constants.GRID_DATA_SECTION);
        ((NatTable) focussedControl).commitAndCloseActiveCellEditor();
    } else {
        fcSection = ((SectionAccessor) ((MField) control.getData(Constants.CONTROL_FIELD)).getmSection().getSectionAccessor()).getSection();
    }
    if (focussedControl instanceof LookupComposite) {
        LookupComposite lookup = (LookupComposite) focussedControl;
        // Wir holen uns den Status des Popup des Lookup
        popupOpen = lookup.popupIsOpen();
    }
    for (Control children : fcSection.getChildren()) {
        if (children instanceof Composite && !(children instanceof ToolBar) && !(children instanceof ImageHyperlink)) {
            comp = (Composite) children;
            break;
        }
    }
    // Wir prüfen ob die Preference LookupEnterSelectsNextRequired nicht gesetzt ist und das Lookup offen ist.
    if (!lookupEnterSelectsNextRequired && popupOpen) {
        focussedControl.setFocus();
        if (focussedControl instanceof LookupComposite) {
            LookupComposite lookup = (LookupComposite) focussedControl;
            lookup.closePopup();
            MField field = (MField) focussedControl.getData(Constants.CONTROL_FIELD);
            setLookupValue(field, lookup);
        }
        return;
    }
    if (!enterSelectsFirstRequired || popupOpen) {
        boolean cellSelected = false;
        if (focussedControl instanceof NatTable) {
            cellSelected = getNextRequiredNatTableCell(focussedControl, true);
        }
        LookupComposite lookup = null;
        if (focussedControl instanceof LookupComposite) {
            MField selectedField = (MField) focussedControl.getData(Constants.CONTROL_FIELD);
            lookup = (LookupComposite) focussedControl;
            if (popupOpen) {
                setLookupValue(selectedField, lookup);
            } else {
                selectedField.setValue(selectedField.getValue(), false);
            }
        }
        if (!cellSelected && focussedControl instanceof NatTable) {
            NatTable natTable = (NatTable) focussedControl;
            ((SelectionLayer) natTable.getData(Constants.GRID_DATA_SELECTIONLAYER)).clear();
        }
        if (!cellSelected) {
            Control[] tabListArrayFromFocussedControlSection = comp.getTabList();
            List<Control> tabListFromFocussedControlSection = arrayToList(tabListArrayFromFocussedControlSection);
            List<Section> sectionList = ((DetailAccessor) mDetail.getDetailAccessor()).getSectionList();
            // [0,1,2,3,4,5,6,7,8,9] --> sublist(0,5) = [0,1,2,3,4]
            int indexFocussedControl = tabListFromFocussedControlSection.indexOf(focussedControl);
            fc = getNextRequiredControl(tabListFromFocussedControlSection.subList(indexFocussedControl + 1, tabListFromFocussedControlSection.size()));
            if (fc != null) {
                return;
            }
            int indexFocussedControlSection = sectionList.indexOf(fcSection);
            fc = getNextRequiredControlOtherSection(focussedControl, sectionList.subList(indexFocussedControlSection + 1, sectionList.size()));
            if (fc != null) {
                return;
            }
            fc = getNextRequiredControlOtherSection(focussedControl, sectionList.subList(0, indexFocussedControlSection + 1));
            if (fc != null) {
                return;
            }
            fc = getNextRequiredControl(tabListFromFocussedControlSection.subList(0, indexFocussedControl + 1));
            if (fc == null) {
                if (focussedControl instanceof LookupComposite) {
                    lookup = (LookupComposite) focussedControl;
                    lookup.closePopup();
                }
                return;
            }
        }
    } else {
        LookupComposite lookup = null;
        if (focussedControl instanceof LookupComposite) {
            MField selectedField = (MField) focussedControl.getData(Constants.CONTROL_FIELD);
            lookup = (LookupComposite) focussedControl;
            if (popupOpen) {
                setLookupValue(selectedField, lookup);
            } else {
                selectedField.setValue(selectedField.getValue(), false);
            }
        }
        for (MSection mSection : mDetail.getMSectionList()) {
            Composite compo = null;
            Section section = ((SectionAccessor) mSection.getSectionAccessor()).getSection();
            for (Control children : section.getChildren()) {
                if (children instanceof Composite && !(children instanceof ToolBar || children instanceof Twistie || children instanceof ImageHyperlink)) {
                    compo = (Composite) children;
                    break;
                }
            }
            List<Control> tabList = arrayToList(compo.getTabList());
            fc = getNextRequiredControl(tabList);
            if (fc != null) {
                if (focussedControl instanceof LookupComposite) {
                    lookup = (LookupComposite) focussedControl;
                    lookup.closePopup();
                }
                return;
            } else {
                continue;
            }
        }
    }
}
Also used : Composite(org.eclipse.swt.widgets.Composite) LookupComposite(aero.minova.rcp.widgets.LookupComposite) ImageHyperlink(org.eclipse.ui.forms.widgets.ImageHyperlink) LookupComposite(aero.minova.rcp.widgets.LookupComposite) SectionAccessor(aero.minova.rcp.rcp.accessor.SectionAccessor) MSection(aero.minova.rcp.model.form.MSection) Section(org.eclipse.ui.forms.widgets.Section) Control(org.eclipse.swt.widgets.Control) DetailAccessor(aero.minova.rcp.rcp.accessor.DetailAccessor) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) TextAssist(org.eclipse.nebula.widgets.opal.textassist.TextAssist) ToolBar(org.eclipse.swt.widgets.ToolBar) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) MSection(aero.minova.rcp.model.form.MSection) Twistie(org.eclipse.ui.forms.widgets.Twistie) Preferences(org.osgi.service.prefs.Preferences) ApplicationPreferences(aero.minova.rcp.preferences.ApplicationPreferences) MField(aero.minova.rcp.model.form.MField)

Example 7 with TextAssist

use of org.eclipse.nebula.widgets.opal.textassist.TextAssist 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)

Example 8 with TextAssist

use of org.eclipse.nebula.widgets.opal.textassist.TextAssist in project aero.minova.rcp by minova-afis.

the class DateTimeValueAccessor 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);
    String timeUtil = (String) InstancePreferenceAccessor.getValue(preferences, ApplicationPreferences.TIME_UTIL, DisplayType.TIME_UTIL, "", locale);
    if (value == null) {
        ((TextAssist) control).setText("");
    } else {
        Instant date = value.getInstantValue();
        LocalDateTime localDateTime = LocalDateTime.ofInstant(date, ZoneId.of("UTC"));
        String pattern = dateUtil + " " + timeUtil;
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern(pattern);
        if (dateUtil.isBlank() && timeUtil.isBlank()) {
            // Bei der Formatierung geschehen fehler, wir erhalten das Milienium zurück
            ((TextAssist) control).setText(localDateTime.format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm").withLocale(locale)));
        } else if (timeUtil.isBlank()) {
            ((TextAssist) control).setText(localDateTime.format(DateTimeFormatter.ofPattern(pattern + "HH:mm").withLocale(locale)));
        } else if (dateUtil.isBlank()) {
            ((TextAssist) control).setText(localDateTime.format(DateTimeFormatter.ofPattern("dd.MM.yyyy" + pattern).withLocale(locale)));
        } else {
            ((TextAssist) control).setText(localDateTime.format(dtf));
        }
    }
}
Also used : Locale(java.util.Locale) LocalDateTime(java.time.LocalDateTime) 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)

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