Search in sources :

Example 1 with IStylingEngine

use of org.eclipse.e4.ui.services.IStylingEngine 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 IStylingEngine

use of org.eclipse.e4.ui.services.IStylingEngine in project aero.minova.rcp by minova-afis.

the class BooleanField method create.

public static Control create(Composite composite, MField field, int row, int column, Locale locale, MPerspective perspective) {
    String labelText = field.getLabel() == null ? "" : field.getLabel();
    Button button = ButtonFactory.newButton(SWT.CHECK).text(field.getLabel()).create(composite);
    // ValueAccessor in den Context injecten, damit IStylingEngine über @Inject verfügbar ist (in AbstractValueAccessor)
    IEclipseContext context = perspective.getContext();
    BooleanValueAccessor valueAccessor = new BooleanValueAccessor(field, button);
    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 = TEXT_WIDTH;
    button.setLayoutData(fd);
    button.setData(CssData.CSSDATA_KEY, new CssData(CssType.TEXT_FIELD, column + 1, row, 1, 1, false));
    button.setData(CSSSWTConstants.CSS_CLASS_NAME_KEY, "Description");
    button.setData(TRANSLATE_PROPERTY, labelText);
    button.setData(TRANSLATE_LOCALE, locale);
    button.setData(Constants.CONTROL_FIELD, field);
    button.setData(Constants.CONTROL_DATATYPE, DataType.BOOLEAN);
    button.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            field.setValue(new Value(button.getSelection()), true);
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            field.setValue(new Value(button.getSelection()), true);
        }
    });
    return button;
}
Also used : FormData(org.eclipse.swt.layout.FormData) Button(org.eclipse.swt.widgets.Button) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Value(aero.minova.rcp.model.Value) BooleanValueAccessor(aero.minova.rcp.rcp.accessor.BooleanValueAccessor) FormAttachment(org.eclipse.swt.layout.FormAttachment) CssData(aero.minova.rcp.css.CssData) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 3 with IStylingEngine

use of org.eclipse.e4.ui.services.IStylingEngine 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 4 with IStylingEngine

use of org.eclipse.e4.ui.services.IStylingEngine in project eclipse.platform.ui by eclipse-platform.

the class PerspectiveRenderer method createWidget.

@Override
public Widget createWidget(MUIElement element, Object parent) {
    if (!(element instanceof MPerspective) || !(parent instanceof Composite))
        return null;
    Composite perspArea = new Composite((Composite) parent, SWT.NONE);
    perspArea.setLayout(new FillLayout());
    IStylingEngine stylingEngine = getContext(element).get(IStylingEngine.class);
    // $NON-NLS-1$
    stylingEngine.setClassname(perspArea, "perspectiveLayout");
    return perspArea;
}
Also used : MPerspective(org.eclipse.e4.ui.model.application.ui.advanced.MPerspective) Composite(org.eclipse.swt.widgets.Composite) IStylingEngine(org.eclipse.e4.ui.services.IStylingEngine) FillLayout(org.eclipse.swt.layout.FillLayout)

Example 5 with IStylingEngine

use of org.eclipse.e4.ui.services.IStylingEngine in project eclipse.platform.ui by eclipse-platform.

the class PerspectiveStackRenderer method createWidget.

@Override
public Object createWidget(MUIElement element, Object parent) {
    if (!(element instanceof MPerspectiveStack) || !(parent instanceof Composite))
        return null;
    Composite perspStack = new Composite((Composite) parent, SWT.NONE);
    IStylingEngine stylingEngine = getContext(element).get(IStylingEngine.class);
    // $NON-NLS-1$
    stylingEngine.setClassname(perspStack, "perspectiveLayout");
    perspStack.setLayout(new StackLayout());
    return perspStack;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) StackLayout(org.eclipse.swt.custom.StackLayout) IStylingEngine(org.eclipse.e4.ui.services.IStylingEngine) MPerspectiveStack(org.eclipse.e4.ui.model.application.ui.advanced.MPerspectiveStack)

Aggregations

IStylingEngine (org.eclipse.e4.ui.services.IStylingEngine)14 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)11 CssData (aero.minova.rcp.css.CssData)6 FormAttachment (org.eclipse.swt.layout.FormAttachment)6 FormData (org.eclipse.swt.layout.FormData)6 Test (org.junit.Test)6 Value (aero.minova.rcp.model.Value)5 FocusAdapter (org.eclipse.swt.events.FocusAdapter)5 FocusEvent (org.eclipse.swt.events.FocusEvent)5 Label (org.eclipse.swt.widgets.Label)5 Composite (org.eclipse.swt.widgets.Composite)4 Shell (org.eclipse.swt.widgets.Shell)4 ApplicationPreferences (aero.minova.rcp.preferences.ApplicationPreferences)3 Instant (java.time.Instant)3 LocalDateTime (java.time.LocalDateTime)3 ArrayList (java.util.ArrayList)3 MUIElement (org.eclipse.e4.ui.model.application.ui.MUIElement)3 EObject (org.eclipse.emf.ecore.EObject)3 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)3 ColorRegistry (org.eclipse.jface.resource.ColorRegistry)3