Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Hackstedt2015-04-24 19:39:13 +0000
committerLars Vogel2015-04-29 14:05:14 +0000
commitcc1e6ec907f376624b14947359f1776fd1252d16 (patch)
tree4d79c0cce888bac30c976f6838b8a1ce76fa918f
parent6bb16a09494dcd73645d37b3c1aca05330bde044 (diff)
downloadeclipse.platform.ui-cc1e6ec907f376624b14947359f1776fd1252d16.tar.gz
eclipse.platform.ui-cc1e6ec907f376624b14947359f1776fd1252d16.tar.xz
eclipse.platform.ui-cc1e6ec907f376624b14947359f1776fd1252d16.zip
Bug 465449 - [Demo] Fix deprecated databinding factories inI20150429-1030
org.eclipse.e4.demo.contacts Change-Id: Ieafeb7e9fc97afdbc44ef50f16210a82aba7bf4b Change-Id: Ieafeb7e9fc97afdbc44ef50f16210a82aba7bf4b Signed-off-by: Stephan Hackstedt <stephan.hackstedt@googlemail.com>
-rw-r--r--examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/databinding/AggregateNameObservableValue.java17
-rw-r--r--examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/views/DetailComposite.java37
-rw-r--r--examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/views/ListView.java14
3 files changed, 37 insertions, 31 deletions
diff --git a/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/databinding/AggregateNameObservableValue.java b/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/databinding/AggregateNameObservableValue.java
index fb2a8c995e2..b0fb169aeb2 100644
--- a/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/databinding/AggregateNameObservableValue.java
+++ b/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/databinding/AggregateNameObservableValue.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Siemens AG and others.
+ * Copyright (c) 2009, 2015 Siemens AG and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,11 +8,12 @@
*
* Contributors:
* Kai Tödter - initial implementation
+ * Stephan Hackstedt <stephan.hackstedt@googlemail.com> - Bug 465449
******************************************************************************/
package org.eclipse.e4.demo.contacts.databinding;
-import org.eclipse.core.databinding.beans.PojoObservables;
+import org.eclipse.core.databinding.beans.PojoProperties;
import org.eclipse.core.databinding.observable.Diffs;
import org.eclipse.core.databinding.observable.value.AbstractObservableValue;
import org.eclipse.core.databinding.observable.value.IObservableValue;
@@ -29,9 +30,10 @@ public class AggregateNameObservableValue extends AbstractObservableValue {
public AggregateNameObservableValue(WritableValue value) {
String[] properties = new String[] { "firstName", "middleName",
- "lastName" };
+ "lastName" };
observableValues = new IObservableValue[properties.length];
listener = new IValueChangeListener() {
+ @Override
public void handleValueChange(ValueChangeEvent event) {
if (!isUpdating) {
fireValueChange(Diffs.createValueDiff(currentStringValue,
@@ -41,8 +43,8 @@ public class AggregateNameObservableValue extends AbstractObservableValue {
};
int i = 0;
for (String property : properties) {
- observableValues[i] = PojoObservables.observeDetailValue(value,
- property, String.class);
+ observableValues[i] = PojoProperties.value((Class<?>) value.getValueType(), property, String.class)
+ .observeDetail(value);
observableValues[i++].addValueChangeListener(listener);
}
}
@@ -92,14 +94,15 @@ public class AggregateNameObservableValue extends AbstractObservableValue {
fireValueChange(Diffs.createValueDiff(oldValue, value));
}
+ @Override
public Object getValueType() {
return String.class;
}
@Override
public synchronized void dispose() {
- for (int i = 0; i < observableValues.length; i++) {
- observableValues[i].removeValueChangeListener(listener);
+ for (IObservableValue observableValue : observableValues) {
+ observableValue.removeValueChangeListener(listener);
}
super.dispose();
}
diff --git a/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/views/DetailComposite.java b/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/views/DetailComposite.java
index d11e8fa3bcd..4d819f2757f 100644
--- a/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/views/DetailComposite.java
+++ b/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/views/DetailComposite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2012 Siemens AG and others.
+ * Copyright (c) 2009, 2015 Siemens AG and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,6 +8,7 @@
*
* Contributors:
* Kai Tödter - initial implementation
+ * Stephan Hackstedt <stephan.hackstedt@googlemail.com> - Bug 465449
******************************************************************************/
package org.eclipse.e4.demo.contacts.views;
@@ -16,7 +17,7 @@ import java.net.URL;
import javax.inject.Inject;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.UpdateValueStrategy;
-import org.eclipse.core.databinding.beans.PojoObservables;
+import org.eclipse.core.databinding.beans.PojoProperties;
import org.eclipse.core.databinding.observable.value.ComputedValue;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.observable.value.WritableValue;
@@ -28,7 +29,7 @@ import org.eclipse.e4.demo.contacts.databinding.AggregateNameObservableValue;
import org.eclipse.e4.demo.contacts.model.Contact;
import org.eclipse.e4.ui.css.swt.dom.WidgetElement;
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
-import org.eclipse.jface.databinding.swt.SWTObservables;
+import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
@@ -71,9 +72,8 @@ public class DetailComposite extends Composite {
dbc = new DataBindingContext();
- URL url = FileLocator.find(Platform
- .getBundle("org.eclipse.e4.demo.contacts"), new Path(
- "images/dummy.png"), null);
+ URL url = FileLocator.find(Platform.getBundle("org.eclipse.e4.demo.contacts"), new Path("images/dummy.png"),
+ null);
ImageDescriptor imageDescriptor = ImageDescriptor.createFromURL(url);
if (imageDescriptor != null) {
dummyPortrait = imageDescriptor.getImageData();
@@ -120,8 +120,8 @@ public class DetailComposite extends Composite {
createVerticalSpace(composite);
// Bind the image
- final IObservableValue imageObservableValue = PojoObservables
- .observeDetailValue(contactValue, "image", ImageData.class);
+ final IObservableValue imageObservableValue = PojoProperties
+ .value((Class<?>) contactValue.getValue(), "image", ImageData.class).observeDetail(contactValue);
this.scaledImage = new ComputedValue() {
private Image currentImage;
@@ -155,10 +155,11 @@ public class DetailComposite extends Composite {
};
- dbc.bindValue(SWTObservables.observeImage(imageLabel), scaledImage,
+ dbc.bindValue(WidgetProperties.image().observe(imageLabel), scaledImage,
new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), null);
addDisposeListener(new DisposeListener() {
+ @Override
public void widgetDisposed(DisposeEvent e) {
scaledImage.dispose();
}
@@ -172,8 +173,7 @@ public class DetailComposite extends Composite {
}
public boolean checkEmptyString(Object testString) {
- if (testString == null || !(testString instanceof String)
- || ((String) testString).trim().length() == 0) {
+ if (testString == null || !(testString instanceof String) || ((String) testString).trim().length() == 0) {
return false;
}
return true;
@@ -209,14 +209,12 @@ public class DetailComposite extends Composite {
private static Composite createComposite(final Composite parent) {
final Composite composite = new Composite(parent, SWT.NONE);
- composite
- .setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
composite.setLayout(new GridLayout(3, false));
return composite;
}
- private Text createText(final Composite parent, final String labelText,
- final String property) {
+ private Text createText(final Composite parent, final String labelText, final String property) {
final Label label = new Label(parent, SWT.NONE);
label.setText(labelText + " "); // the extra space is due to a bug in
// font formatting when using css
@@ -245,16 +243,17 @@ public class DetailComposite extends Composite {
if (property != null) {
if (property.equals("name")) {
- dbc.bindValue(SWTObservables.observeText(text, SWT.Modify),
+ dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(text),
new AggregateNameObservableValue(contactValue));
} else {
- dbc.bindValue(SWTObservables.observeText(text, SWT.Modify),
- PojoObservables.observeDetailValue(contactValue,
- property, String.class));
+ dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(text),
+ PojoProperties.value((Class<?>) contactValue.getValueType(), property, String.class)
+ .observeDetail(contactValue));
}
}
text.addModifyListener(new ModifyListener() {
+ @Override
public void modifyText(ModifyEvent e) {
if (commitChanges) {
setDirty(true);
diff --git a/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/views/ListView.java b/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/views/ListView.java
index 954cceb8668..258a32426f0 100644
--- a/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/views/ListView.java
+++ b/examples/org.eclipse.e4.demo.contacts/src/org/eclipse/e4/demo/contacts/views/ListView.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2014 Siemens AG and others.
+ * Copyright (c) 2009, 2015 Siemens AG and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -9,12 +9,13 @@
* Contributors:
* Kai Tödter - initial implementation
* Lars Vogel <Lars.Vogel@gmail.com> - Bug 427896
+ * Stephan Hackstedt <stephan.hackstedt@googlemail.com> - Bug 465449
******************************************************************************/
package org.eclipse.e4.demo.contacts.views;
import javax.inject.Inject;
-import org.eclipse.core.databinding.beans.BeansObservables;
+import org.eclipse.core.databinding.beans.BeanProperties;
import org.eclipse.core.databinding.observable.map.IObservableMap;
import org.eclipse.e4.demo.contacts.model.Contact;
import org.eclipse.e4.demo.contacts.model.ContactsRepositoryFactory;
@@ -105,9 +106,12 @@ public class ListView {
contactsViewer.setContentProvider(contentProvider);
- IObservableMap[] attributes = BeansObservables.observeMaps(
- contentProvider.getKnownElements(), Contact.class,
- new String[] { "firstName", "lastName" });
+ IObservableMap firstName = BeanProperties.value(Contact.class, "firstName")
+ .observeDetail(contentProvider.getKnownElements());
+ IObservableMap lastName = BeanProperties.value(Contact.class, "lastName")
+ .observeDetail(contentProvider.getKnownElements());
+ IObservableMap[] attributes = { firstName, lastName };
+
contactsViewer.setLabelProvider(new ObservableMapLabelProvider(
attributes));

Back to the top