diff options
author | Stéphane Bégaudeau | 2016-04-28 09:07:18 +0000 |
---|---|---|
committer | Stephane Begaudeau | 2016-04-28 12:41:21 +0000 |
commit | 911636d149de4092e7e7427a0ea212c35d442209 (patch) | |
tree | d3970a4472cc1a9f8d7a8c8769d0febd766025af /plugins | |
parent | cfa8ad8119848e323c57c0af33339960bd957267 (diff) | |
download | org.eclipse.eef-911636d149de4092e7e7427a0ea212c35d442209.tar.gz org.eclipse.eef-911636d149de4092e7e7427a0ea212c35d442209.tar.xz org.eclipse.eef-911636d149de4092e7e7427a0ea212c35d442209.zip |
Add support for any object as the value of the text
Previously users of a Text widget had to call explicitely toString on
their result otherwise nothing would happen and an error would be
logged. This new algorithm will call toString() automatically
Change-Id: I1dde6dc12544b35721cca3bf72c1283b9c041162
Signed-off-by: Stéphane Bégaudeau <stephane.begaudeau@obeo.fr>
Diffstat (limited to 'plugins')
3 files changed, 11 insertions, 11 deletions
diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/controllers/IEEFTextController.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/controllers/IEEFTextController.java index a6a50ca49..7ac11909e 100644 --- a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/controllers/IEEFTextController.java +++ b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/api/controllers/IEEFTextController.java @@ -27,12 +27,13 @@ public interface IEEFTextController extends IEEFWidgetController { void updateValue(String text); /** - * Register a consumer which will be called with the new value of the text when it will change. + * Register a consumer which will be called with the new value of the text when it will change. The consumer will + * have the responsibility to transform the given object into text * * @param consumer * The consumer of the new value of the text */ - void onNewValue(IConsumer<String> consumer); + void onNewValue(IConsumer<Object> consumer); /** * Remove the consumer of the new value of the text. diff --git a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFTextController.java b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFTextController.java index 9f9268fe7..b636462fb 100644 --- a/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFTextController.java +++ b/plugins/org.eclipse.eef.core/src/org/eclipse/eef/core/internal/controllers/EEFTextController.java @@ -49,7 +49,7 @@ public class EEFTextController extends AbstractEEFWidgetController implements IE /** * The consumer of a new value of the text. */ - private IConsumer<String> newValueConsumer; + private IConsumer<Object> newValueConsumer; /** * Executor service used to run the update of the text field. @@ -119,7 +119,7 @@ public class EEFTextController extends AbstractEEFWidgetController implements IE String valueExpression = this.description.getValueExpression(); EAttribute eAttribute = EefPackage.Literals.EEF_TEXT_DESCRIPTION__VALUE_EXPRESSION; - this.newEval().call(eAttribute, valueExpression, String.class, EEFTextController.this.newValueConsumer); + this.newEval().call(eAttribute, valueExpression, Object.class, EEFTextController.this.newValueConsumer); } /** @@ -128,7 +128,7 @@ public class EEFTextController extends AbstractEEFWidgetController implements IE * @see org.eclipse.eef.core.api.controllers.IEEFTextController#onNewValue(org.eclipse.eef.core.api.controllers.IConsumer) */ @Override - public void onNewValue(IConsumer<String> consumer) { + public void onNewValue(IConsumer<Object> consumer) { this.newValueConsumer = consumer; } diff --git a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFTextLifecycleManager.java b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFTextLifecycleManager.java index 4c6be81ac..de1a6d9e6 100644 --- a/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFTextLifecycleManager.java +++ b/plugins/org.eclipse.eef.ide.ui/src/org/eclipse/eef/ide/ui/internal/widgets/EEFTextLifecycleManager.java @@ -10,8 +10,6 @@ *******************************************************************************/ package org.eclipse.eef.ide.ui.internal.widgets; -import com.google.common.base.Objects; - import java.util.ArrayList; import java.util.List; @@ -21,6 +19,7 @@ import org.eclipse.eef.EEFTextDescription; import org.eclipse.eef.EEFTextStyle; import org.eclipse.eef.EEFWidgetDescription; import org.eclipse.eef.EEFWidgetStyle; +import org.eclipse.eef.common.api.utils.Util; import org.eclipse.eef.common.ui.api.EEFWidgetFactory; import org.eclipse.eef.common.ui.api.IEEFFormContainer; import org.eclipse.eef.core.api.EditingContextAdapter; @@ -204,12 +203,12 @@ public class EEFTextLifecycleManager extends AbstractEEFWidgetLifecycleManager { }; this.text.addModifyListener(this.modifyListener); - this.controller.onNewValue(new IConsumer<String>() { + this.controller.onNewValue(new IConsumer<Object>() { @Override - public void apply(String value) { + public void apply(Object value) { if (!text.isDisposed()) { - if (!(text.getText() != null && text.getText().equals(value))) { - text.setText(Objects.firstNonNull(value, "")); //$NON-NLS-1$ + if (value != null && !(text.getText() != null && text.getText().equals(value.toString()))) { + text.setText(Util.firstNonBlank(value.toString(), "")); //$NON-NLS-1$ } // Set style setStyle(); |