Search in sources :

Example 6 with CssData

use of aero.minova.rcp.css.CssData 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 7 with CssData

use of aero.minova.rcp.css.CssData in project aero.minova.rcp by minova-afis.

the class NumberField method create.

public static Control create(Composite composite, MNumberField field, int row, int column, Locale locale, MPerspective perspective) {
    String unitText = field.getUnitText() == null ? "" : field.getUnitText();
    Label label = FieldLabel.create(composite, field);
    Text text = TextFactory.newText(SWT.BORDER | SWT.RIGHT).text("").create(composite);
    NumberValueAccessor numberValueAccessor = new NumberValueAccessor(field, text);
    text.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent e) {
            text.selectAll();
        }
    });
    text.addVerifyListener(numberValueAccessor);
    // ValueAccessor in den Context injecten, damit IStylingEngine über @Inject verfügbar ist (in AbstractValueAccessor)
    IEclipseContext context = perspective.getContext();
    ContextInjectionFactory.inject(numberValueAccessor, context);
    field.setValueAccessor(numberValueAccessor);
    Label unit = LabelFactory.newLabel(SWT.LEFT).text(unitText).create(composite);
    FormData textFormData = new FormData();
    FormData unitFormData = new FormData();
    FieldLabel.layout(label, text, row, column, field.getNumberRowsSpanned());
    textFormData.top = new FormAttachment(composite, MARGIN_TOP + row * COLUMN_HEIGHT);
    textFormData.left = new FormAttachment((column == 0) ? 25 : 75);
    textFormData.width = NUMBER_WIDTH;
    unitFormData.top = new FormAttachment(text, 0, SWT.CENTER);
    unitFormData.left = new FormAttachment(text, 0, SWT.RIGHT);
    unitFormData.right = new FormAttachment((column == 0) ? 50 : 100);
    Integer decimals = field.getDecimals();
    decimals = decimals == null ? 0 : decimals;
    Double maximum = field.getMaximumValue();
    maximum = maximum == null ? Double.MAX_VALUE : maximum;
    Double minimum = field.getMinimumValue();
    minimum = minimum == null ? Double.MIN_VALUE : maximum;
    text.setData(TRANSLATE_LOCALE, locale);
    text.setData(FIELD_DECIMALS, decimals);
    text.setData(FIELD_MAX_VALUE, maximum);
    text.setData(FIELD_MIN_VALUE, minimum);
    text.setData(Constants.CONTROL_FIELD, field);
    text.setLayoutData(textFormData);
    NumberFieldUtil.setMessage(text);
    text.setData(CssData.CSSDATA_KEY, new CssData(CssType.NUMBER_FIELD, column + 1, row, field.getNumberColumnsSpanned(), field.getNumberRowsSpanned(), field.isFillToRight() || field.isFillHorizontal()));
    unit.setData(TRANSLATE_PROPERTY, unitText);
    unit.setData(CSSSWTConstants.CSS_CLASS_NAME_KEY, "DescriptionLabel");
    unit.setLayoutData(unitFormData);
    return text;
}
Also used : FormData(org.eclipse.swt.layout.FormData) FocusAdapter(org.eclipse.swt.events.FocusAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) FocusEvent(org.eclipse.swt.events.FocusEvent) NumberValueAccessor(aero.minova.rcp.rcp.accessor.NumberValueAccessor) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) FormAttachment(org.eclipse.swt.layout.FormAttachment) CssData(aero.minova.rcp.css.CssData)

Example 8 with CssData

use of aero.minova.rcp.css.CssData in project aero.minova.rcp by minova-afis.

the class TextField method create.

public static Control create(Composite composite, MField field, int row, int column, MPerspective perspective) {
    Label label = FieldLabel.create(composite, field);
    int style = SWT.BORDER;
    if (field.getNumberRowsSpanned() > 1) {
        // Maskenentwickler hat mehrzeilige Eingabe definiert
        style |= SWT.WRAP;
    }
    Text text = TextFactory.newText(style).text("").create(composite);
    text.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent e) {
            text.selectAll();
        }
    });
    // Wenn der Anwender den Wert ändert, muss es weitergegeben werden
    text.addModifyListener(e -> {
        if (text.isFocusControl()) {
            String newValue = text.getText();
            if (newValue.length() < 1) {
                field.setValue(null, true);
            } else {
                field.setValue(new Value(newValue), true);
            }
        }
    });
    text.addTraverseListener(e -> {
        if (e.detail == SWT.TRAVERSE_TAB_NEXT && e.stateMask == 0) {
            e.doit = true;
        } else if (e.detail == SWT.TRAVERSE_TAB_NEXT && e.stateMask == 262144) {
            e.doit = false;
            text.setText(text.getText() + "\t");
            text.setSelection(text.getText().length());
        } else if (e.detail == SWT.TRAVERSE_TAB_NEXT && e.stateMask == 65536) {
            e.doit = true;
        }
    });
    text.setData(Constants.CONTROL_FIELD, field);
    CssData cssData = new CssData(CssType.TEXT_FIELD, column + 1, row, field.getNumberColumnsSpanned(), field.getNumberRowsSpanned(), field.isFillToRight() || field.isFillHorizontal());
    text.setData(CssData.CSSDATA_KEY, cssData);
    // ValueAccessor in den Context injecten, damit IStylingEngine über @Inject verfügbar ist (in AbstractValueAccessor)
    IEclipseContext context = perspective.getContext();
    TextValueAccessor valueAccessor = new TextValueAccessor(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);
    if (field.isFillHorizontal() && field.getLabel() == null) {
        fd.left = new FormAttachment((column == 0) ? 0 : 50);
    } else {
        fd.left = new FormAttachment((column == 0) ? 25 : 75);
    }
    if ((field.getNumberColumnsSpanned() > 2 && field.isFillToRight()) || field.isFillHorizontal() || column >= 2) {
        fd.right = new FormAttachment(100, -MARGIN_BORDER);
    } else {
        fd.right = new FormAttachment(50, -ICssStyler.CSS_SECTION_SPACING);
    }
    text.setLayoutData(fd);
    return text;
}
Also used : FormData(org.eclipse.swt.layout.FormData) FocusAdapter(org.eclipse.swt.events.FocusAdapter) TextValueAccessor(aero.minova.rcp.rcp.accessor.TextValueAccessor) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) FocusEvent(org.eclipse.swt.events.FocusEvent) Value(aero.minova.rcp.model.Value) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) CssData(aero.minova.rcp.css.CssData) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Aggregations

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