Accessing/updating UI elements in other Parts + best practices? [message #1070249] |
Wed, 17 July 2013 14:43 |
Murray Rush Messages: 6 Registered: July 2013 |
Junior Member |
|
|
Fairly simple question here: I have an application where one Part is a TableViewer and another Part which contains form fields (spinners, combo boxes, text fields, etc.). The form Part updates based on the current selection in the TableViewer Part, implemented using @Optional @Named(IServiceConstants.ACTIVE_SELECTION).
What I want is for an Update button in the form Part to reflect the changes in my TableViewer, but I am not quite sure of how to manipulate the TableViewer part via the form Part.
What is the E4 best practice to accomplish manipulation of other parts? I have looked around quite a bit already but I am running into a lot of E3 stuff that doesn't really help me. Also, if anyone has any pointers/tutorials on how to maintain/separate my TableViewers data separate from the actual Part code, that would be appreciated.
Thanks!
[Updated on: Wed, 17 July 2013 15:35] Report message to a moderator
|
|
|
Re: Accessing/updating UI elements in other Parts + best practices? [message #1070274 is a reply to message #1070249] |
Wed, 17 July 2013 15:56 |
|
To summarize: You have a list of items in one part, and item details in another part. And you want the table to reflect changes you make in the details part. (Correct?)
The best way to accomplish this is through databinding. This way the object you receive in the details part is a shared model object and all changes are propagated to the table. For more info, check out the JFace forum.
JD
|
|
|
|
|
|
|
|
|
|
Re: Accessing/updating UI elements in other Parts + best practices? [message #1073928 is a reply to message #1073606] |
Thu, 25 July 2013 19:22 |
Murray Rush Messages: 6 Registered: July 2013 |
Junior Member |
|
|
Ok so I have got that working, but it doesn't solve that I have two Parts that so far, are unable to communicate. Hopefully I am not missing something terribly obvious. How can the databinding be adapted to work across Parts? Where my model is living right now is probably bad, but I don't know the best practices.
public class TableViewerPart {
private List<MyOwnObject> objects;
//Table Viewer is populated with these objects...
//Databinding objects
}
public class FormEditorPart {
@Inject
void setSelection(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) MyOwnObject object) {
// Populate text boxes based on selection
}
// Update button pressed - update the object
}
[Updated on: Thu, 25 July 2013 19:25] Report message to a moderator
|
|
|
Re: Accessing/updating UI elements in other Parts + best practices? [message #1074122 is a reply to message #1073928] |
Fri, 26 July 2013 06:50 |
Cedric Moonen Messages: 274 Registered: August 2009 |
Senior Member |
|
|
Quote:Ok so I have got that working, but it doesn't solve that I have two Parts that so far, are unable to communicate.
You have to think at it differently: you should avoid having two parts "communicating" together, this is in general not a so good practice. However, the views are displaying some data (which should be always accessible, so not stored in your views). Databinding will take care of updating your views when the model changes.
So, in this case you don't need to communicate between views anymore.
In your particular example, are you sure that the list of objects has to be stored within your view ? It means that the lifetime of those objects is the same as the lifetime of the view, e.g. if you close the view, you don't have your objects anymore. Is that what you really want ? If you reopen your view, your list will be recreated (so the user has lost all its changes).
Anyway, your code should technically work (if databinding is implemented properly), since your second view receive the selected object and modifies it (unless you are making a copy of it). So, it this element is modified, databinding in the first view should be notified when this object changes and update the table viewer accordingly.
|
|
|
|
Powered by
FUDForum. Page generated in 0.04067 seconds