Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Accessing/updating UI elements in other Parts + best practices?
Accessing/updating UI elements in other Parts + best practices? [message #1070249] Wed, 17 July 2013 14:43 Go to next message
Murray Rush is currently offline 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 Go to previous messageGo to next message
Joseph Carroll is currently offline Joseph Carroll
Messages: 174
Registered: May 2012
Location: Milwaukee, WI
Senior Member

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 #1070564 is a reply to message #1070274] Thu, 18 July 2013 08:14 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph Keimel
Messages: 371
Registered: December 2010
Location: Germany
Senior Member
Hi Murray

You could send an event when the user presses "Update" in the master part. The slave part can listen for these events to update its fields. Have a look at this tutorial on how to use IEventBroker:
http://www.vogella.com/articles/Eclipse4EventSystem/article.html

Hope that helps.

Christoph

[Updated on: Thu, 18 July 2013 08:15]

Report message to a moderator

Re: Accessing/updating UI elements in other Parts + best practices? [message #1071317 is a reply to message #1070249] Fri, 19 July 2013 20:17 Go to previous messageGo to next message
Murray Rush is currently offline Murray Rush
Messages: 6
Registered: July 2013
Junior Member
Thanks for the replies. Yes databinding is probably more what I am looking for (so I don't have to go through updating the table values manually then, it also allows me to add in validation easier).

Unfortunately I can't seem to find it for my imports though. E4 Databinding is installed and my product file has org.eclipse.core.databinding as one of the plugins. Not sure why Eclipse isn't finding it...
Re: Accessing/updating UI elements in other Parts + best practices? [message #1071509 is a reply to message #1071317] Sat, 20 July 2013 09:40 Go to previous messageGo to next message
Sopot Cela is currently offline Sopot Cela
Messages: 597
Registered: December 2010
Senior Member

You have to have the jface databinding plugin in the manifest.
Re: Accessing/updating UI elements in other Parts + best practices? [message #1072459 is a reply to message #1071509] Mon, 22 July 2013 20:19 Go to previous messageGo to next message
Murray Rush is currently offline Murray Rush
Messages: 6
Registered: July 2013
Junior Member
Thanks, I have implemented databinding to populate my table so far, but I am still not sure how databinding will help me communicate the changes to the object between the 2 Parts. My TableViewer is populated from a List of simple objects (object only has a few fields consisting of booleans, ints, Strings). Using the void setSelection(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) service, I get my currently selected object and populate the second Parts fields based on this object. How can the changes to this object possibly be reflected in the TableViewer?
Re: Accessing/updating UI elements in other Parts + best practices? [message #1073192 is a reply to message #1072459] Wed, 24 July 2013 09:41 Go to previous messageGo to next message
Cedric Moonen is currently offline Cedric Moonen
Messages: 274
Registered: August 2009
Senior Member
Quote:
How can the changes to this object possibly be reflected in the TableViewer?


Did you use an ObservableMapLabelProvider for your table viewer ? Check this tutorial:
http://www.vogella.com/articles/EclipseDataBinding/article.html#tutorial_observablemaplabelprovider

Your model objects (elements which are populated in the list and edited), are they EMF objects or POJOs ?
Re: Accessing/updating UI elements in other Parts + best practices? [message #1073416 is a reply to message #1073192] Wed, 24 July 2013 18:26 Go to previous messageGo to next message
Murray Rush is currently offline Murray Rush
Messages: 6
Registered: July 2013
Junior Member
They are POJOs. I don't understand how
    ILabelProvider labelProvider = new ObservableMapLabelProvider(labelMaps) {
      public String getText(Object element) {
        return firstNames.get(element) + " " + lastNames.get(element);
      }
    };

    viewer.setLabelProvider(labelProvider);

could be translated into label providers for each column since they are looking for CellLabelProviders.
Re: Accessing/updating UI elements in other Parts + best practices? [message #1073606 is a reply to message #1073416] Thu, 25 July 2013 06:56 Go to previous messageGo to next message
Cedric Moonen is currently offline Cedric Moonen
Messages: 274
Registered: August 2009
Senior Member
I guess (never worked with that before) you have to use an ObservableMapCellLabelProvider instead (http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fjface%2Fdatabinding%2Fviewers%2FObservableMapCellLabelProvider.html). You can override the update method if needed.
Re: Accessing/updating UI elements in other Parts + best practices? [message #1073928 is a reply to message #1073606] Thu, 25 July 2013 19:22 Go to previous messageGo to next message
Murray Rush is currently offline 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 Go to previous messageGo to next message
Cedric Moonen is currently offline 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.
Re: Accessing/updating UI elements in other Parts + best practices? [message #1074332 is a reply to message #1074122] Fri, 26 July 2013 14:17 Go to previous message
Murray Rush is currently offline Murray Rush
Messages: 6
Registered: July 2013
Junior Member
I am not sure where else I could instantiate my model, since I am using the eclipse application model, there is no place for it to live really unless I am mistaken? This is a fairly simple app (3-5 Parts total) so they are not closeable. I was also going to implement the Dirtyable features to allow for saving anyways.

It does work, ONLY if the changes to the object are made within
void setSelection(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) MyOwnObject object) {
		// Populate text boxes based on selection
	}


If I make a shallow copy to be used in public void widgetSelected(SelectionEvent e) and do the changes in there, it does update in the tableviewer, but then when you select another row or alter the UI, the change disappears.
Previous Topic:Eclipse e4 CSS Export
Next Topic:accessing resources from other plugin in Application.e4xmi
Goto Forum:
  


Current Time: Thu Oct 23 17:27:34 GMT 2014

Powered by FUDForum. Page generated in 0.04105 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software