Bug 176975 - [DataBinding] IObservables for org.eclipse.ui.forms
Summary: [DataBinding] IObservables for org.eclipse.ui.forms
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 enhancement with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Boris Bokowski CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-03-12 07:27 EDT by Giulio Seregni CLA
Modified: 2019-09-06 16:10 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Giulio Seregni CLA 2007-03-12 07:27:11 EDT
I would like to make a binding between a bean and the label of an hyperlink.

Actually there is no support, in SWTObservables, for Form components like HyperLink.

Using BeanObservable on Hyperlink in this way:

gwBind = dbc.bindValue(BeansObservables.observeValue(LINK, "text"), BeansObservables.observeValue(BEAN, "PROP"), null);

does not work because it can't attach listener to HyperLink.

You should add an observeHyperlinkLabel and  observeHyperlink method in SWTObservables or add bean support in HyperLink class.


Regards

giulio
Comment 1 Peter Centgraf CLA 2007-03-12 12:02:36 EDT
(I'm not a committer, so don't consider this official....)

First, DataBindings has been accepted as part of the JFace project, which has strict limits on the dependencies it is allowed to tie in.  For example, it cannot use packages outside of the Foundation subset of the JRE.  It's my understanding that a dependency on the org.eclipse.ui.forms plugin would tie DataBindings to the whole of RCP, so that it could not be used in a standalone JFace deployment.  So, this request cannot be implemented directly in SWTObservables.  Perhaps it could be added to the Forms plugin, or a new plugin.

Second, I suggest that you implement this yourself and contribute it as a patch.  Creating a new IObservableValue is quite easy -- 100 LOC or less.  Subclass AbstractSWTObservableValue, register the listener in the constructor, and implement getValueType(), doSetValue(), and doGetValue().  Use SpinnerObservableValue (or one of the similar classes) as an example.
Comment 2 Brad Reynolds CLA 2007-03-12 15:19:11 EDT
What is not working for you?  I understand that there isn't a proper API to accomplish this but I'm assuming that all you want to do is to update the Hyperlink text with a value from your model.  If so then you should be able to use the bean support as all you need is setText(...) and getText(...).  

The following test asserts this behavior.  Since the Hyperlink doesn't provide change events for the text attribute I wouldn't think that observing this attribute would provide much benefit above and beyond what BeansObservables provides.  We could add it in the future but I think you should be able to accomplish your goals with what is provided today.

public class HyperlinkTest extends TestCase{
	public void testHyperLink() throws Exception {
		Realm.runWithDefault(SWTObservables.getRealm(Display.getDefault()), new Runnable() {
			public void run() {
				Shell shell = new Shell();
				Hyperlink link = new Hyperlink(shell, SWT.NONE);				
				assertNull(link.getText());

				String text = "text";
				WritableValue value = new WritableValue(text, String.class);
				IObservableValue textObservable = BeansObservables.observeValue(link, "text");
				
				DataBindingContext dbc = new DataBindingContext();
				dbc.bindValue(textObservable, value, null);
				
				assertEquals("text was set when bound", text, link.getText());
				assertEquals("getValue returns the text", text, textObservable.getValue());
			}
		});
	}
}
Comment 3 Giulio Seregni CLA 2007-03-12 17:44:26 EDT
it's, probably, a particular situation.
i'm working on a product having a form editor with an hyperlink binded to a string property. clicking on the link opens a dialog that permit to choose differents values.
Actually the changes on the text property of hyperlink does not reflect on model,  if i don't force a model update.
I hope in the next days to have the time to commit a patch.

giulio
Comment 4 Brad Reynolds CLA 2007-03-12 18:09:30 EDT
(In reply to comment #3)
> it's, probably, a particular situation.
> i'm working on a product having a form editor with an hyperlink binded to a
> string property. clicking on the link opens a dialog that permit to choose
> differents values.
> Actually the changes on the text property of hyperlink does not reflect on
> model,  if i don't force a model update.
> I hope in the next days to have the time to commit a patch.
> 
> giulio
> 

I apologize if I'm just not getting it but what is the issue then?  Do you want API from a FormsObservables perspective?  As Peter pointed out in comment 1 this isn't an SWT or JFace component.  My guess is we'd have to create a new project and I doubt that will occur before 1.0.  A patch is great but I'm curious what this patch would be solving.  Hyperlink doesn't provide change events for the Text property.  So in the end you won't be gaining anything over what BeansObservables provides except for a little more specific API.  If that's what is needed then that's fine.  I just want to make sure that you can get what you need with the API we provide today and if not I'd like to determine why.
Comment 5 Giulio Seregni CLA 2007-03-12 18:29:50 EDT
if hyperlink doesn't provide change events for the Text property, it's useless any patch on databinding.

so sorry and tag this bug as invalid, i'm quite new to eclipse internals ;)
Comment 6 Brad Reynolds CLA 2007-03-12 18:41:44 EDT
(In reply to comment #5)
> if hyperlink doesn't provide change events for the Text property, it's useless
> any patch on databinding.
> 

The only reason at this point would be to ensure that there is a more direct API which I don't think would be a bad thing.  This provides a documented solution and creates more expressive code.  BTW, we do have SWTObservsables.observeSelection(...) which might be beneficial in your use case so that's another candidate for FormsObservables.

> so sorry and tag this bug as invalid, i'm quite new to eclipse internals ;)
> 

No need to apologize.  We appreciate you logging this.  I'm going to leave the request open but update the summary to reflect that this is a more general request for an observable factory for the forms UI project.
Comment 7 Eclipse Webmaster CLA 2007-07-29 09:22:01 EDT
Changing OS from Mac OS to Mac OS X as per bug 185991
Comment 8 Eclipse Webmaster CLA 2019-09-06 16:10:55 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.