Unterschiede
Hier werden die Unterschiede zwischen der gewählten und der aktuellen Version gezeigt.
| eclipse-rcp:binding 2008/11/18 08:37 | eclipse-rcp:binding 2020/09/25 09:41 aktuell | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| - | [[eclipse-rcp|Eclipse-RCP]] | + | [[eclipse-rcp|Java - Eclipse-RCP]] |
| ====== Eclipse - Binding (ab Eclipse 3.3) ====== | ====== Eclipse - Binding (ab Eclipse 3.3) ====== | ||
| Zeile 10: | Zeile 9: | ||
| * Geburtsdatum\\ | * Geburtsdatum\\ | ||
| bestehen.\\ | bestehen.\\ | ||
| + | \\ | ||
| + | <html> | ||
| + | <script type="text/javascript"><!-- | ||
| + | google_ad_client="pub-9681858985507948"; | ||
| + | google_ad_width = 468; | ||
| + | google_ad_height = 60; | ||
| + | google_ad_format = "468x60_as"; | ||
| + | google_ad_type = "text"; | ||
| + | google_ad_channel = ""; | ||
| + | google_color_border = "cccccc"; | ||
| + | google_color_bg = "FFFFFF"; | ||
| + | google_color_link = "1d2d8c"; | ||
| + | google_color_text = "000000"; | ||
| + | google_color_url = "1d2d8c"; | ||
| + | //--> | ||
| + | </script> | ||
| + | <script type="text/javascript" | ||
| + | src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> | ||
| + | </script> | ||
| + | </html> | ||
| + | \\ | ||
| ===== Binding-Methode ===== | ===== Binding-Methode ===== | ||
| Die Binding-Methode kann beispielsweise in der MyFormPart-Klasse implementiert werden.\\ | Die Binding-Methode kann beispielsweise in der MyFormPart-Klasse implementiert werden.\\ | ||
| Zeile 18: | Zeile 37: | ||
| m_bindingContext = new DataBindingContext(); | m_bindingContext = new DataBindingContext(); | ||
| - | Binding binding; | + | // Das Textfeld "m_lastnameTxt" für den Nachnamen an das Model-Attribut "m_lastname" binden: |
| - | + | m_bindingContext.bindValue(SWTObservables.observeText(m_lastnameTxt, | |
| - | binding = m_bindingContext.bindValue(SWTObservables.observeText(m_lastnameTxt, | + | SWT.Modify), BeansObservables.observeValue(model, MyModel.PROP_LASTNAME), null, null); |
| - | SWT.Modify), BeansObservables.observeValue(model, MyModel.PROP_LASTNAME), null, null); | + | |
| - | binding = m_bindingContext.bindValue(SWTObservables.observeText(m_firstnameTxt, | + | // Das Textfeld "m_firstnameTxt" für den Nachnamen an das Model-Attribut "m_firstname" binden: |
| - | SWT.Modify), BeansObservables.observeValue(model, MyModel.PROP_FIRSTNAME), null, null); | + | m_bindingContext.bindValue(SWTObservables.observeText(m_firstnameTxt, |
| + | SWT.Modify), BeansObservables.observeValue(model, MyModel.PROP_FIRSTNAME), null, null); | ||
| + | |||
| + | // Das Textfeld "m_birthdateTxt" für den Nachnamen an das Model-Attribut "m_birthday" binden: | ||
| + | m_bindingContext.bindValue(SWTObservables.observeText(m_birthdateTxt, | ||
| + | SWT.Modify), BeansObservables.observeValue(model, MyModel.PROP_BIRTHDAY), | ||
| + | m_targetToModelStrategy, m_modelToTargetStrategy); | ||
| + | // UpdateStrategy initialisieren (Konverter und Validatoren festlegen): | ||
| initUpdateStrategy(); | initUpdateStrategy(); | ||
| - | binding = m_bindingContext.bindValue(SWTObservables.observeText(m_birthdateTxt, | ||
| - | SWT.Modify), BeansObservables.observeValue(model, MyModel.PROP_BIRTHDAY), | ||
| - | m_targetToModelStrategy, m_modelToTargetStrategy); | ||
| } | } | ||
| </code> | </code> | ||
| Zeile 72: | Zeile 94: | ||
| String str = (String) fromObject; | String str = (String) fromObject; | ||
| SimpleDateFormat sd = new SimpleDateFormat("dd.MM.yyyy"); | SimpleDateFormat sd = new SimpleDateFormat("dd.MM.yyyy"); | ||
| - | Date date; | + | Date date = null; |
| try { | try { | ||
| Date newDate = sd.parse(dateString); | Date newDate = sd.parse(dateString); | ||
| Zeile 124: | Zeile 146: | ||
| m_modelToTargetUpdateStrategy1 = new UpdateValueStrategy(); | m_modelToTargetUpdateStrategy1 = new UpdateValueStrategy(); | ||
| + | // oder bei spezieller Policy (Default: UpdateValueStrategy.POLICYUPDATE) | ||
| + | // m_modelToTargetUpdateStrategy1 = new UpdateValueStrategy(UpdateValueStrategy.NEVER); | ||
| m_modelToTargetUpdateStrategy1.setConverter(date2StrConverter); | m_modelToTargetUpdateStrategy1.setConverter(date2StrConverter); | ||
| m_targetToModelUpdateStrategy = new UpdateValueStrategy(); | m_targetToModelUpdateStrategy = new UpdateValueStrategy(); | ||
| Zeile 208: | Zeile 232: | ||
| } | } | ||
| } | } | ||
| + | </code> | ||
| + | \\ | ||
| + | \\ | ||
| + | \\ | ||
| + | ===== Button-Enablement an Validationstatus binden ===== | ||
| + | <code java> | ||
| + | public void bindButtonEnablementToValidationStatus(final Button button) { | ||
| + | |||
| + | final IObservableValue buttonEnable = SWTObservables.observeEnabled(button); | ||
| + | final IObservableValue validationStatus = | ||
| + | new AggregateValidationStatus(myBindingContext.getValidationRealm(), myBindingContext.getBindings(), AggregateValidationStatus.MAX_SEVERITY); | ||
| + | myBindingContext.bindValue(buttonEnable, | ||
| + | validationStatus, | ||
| + | new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), | ||
| + | new UpdateValueStrategy().setConverter(new Converter(IStatus.class, Boolean.TYPE) { | ||
| + | @Override | ||
| + | public Object convert(final Object fromObject) { | ||
| + | return new Boolean(((IStatus) fromObject).isOK()); | ||
| + | } | ||
| + | })); | ||
| + | } | ||
| </code> | </code> | ||
| \\ | \\ | ||