Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Get all occurrencies of Object-Typ for Combo
Get all occurrencies of Object-Typ for Combo [message #780253] Tue, 17 January 2012 13:28 Go to next message
Markus Jo is currently offline Markus JoFriend
Messages: 83
Registered: January 2012
Member
Hi,
me again.

I think this must be i little bit simpler.

Lets say I have many markets in my EMF Model below he root object in a list "markets". Every Market has a list called "products" in which you can find its products (type Product).

Now I have a combo box that I created like this:



// Listing Device
Label listingDeviceLabel = toolkit.createLabel(composite, "Maschine:", SWT.NONE);
listingDeviceLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));

this.listingDeviceCombo = new Combo(composite, SWT.READ_ONLY);
listingDeviceCombo.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));

toolkit.adapt(listingDeviceCombo);
toolkit.paintBordersFor(listingDeviceCombo);

listingDeviceComboViewer = new ComboViewer(listingDeviceCombo);

ObservableListContentProvider observableListContentProvider = new ObservableListContentProvider();
listingDeviceComboViewer.setContentProvider(observableListContentProvider);

IObservableMap observableMap = EMFProperties.value(MetamodelPackage.Literals.LISTING_DEVICE__NAME).observeDetail(observableListContentProvider.getKnownElements());
listingDeviceComboViewer.setLabelProvider(new ObservableMapLabelProvider(observableMap));

FeaturePath parallelTrainNumberFeature = FeaturePath.fromList(
MetamodelPackage.Literals.COACH_GROUP__CLIENT_ORGANIZATION,
MetamodelPackage.Literals.CLIENT_ORGANIZATION__LISTING_DEVICES,
MetamodelPackage.Literals.LISTING_DEVICES__LISTING_DEVICE);

IEMFListProperty p = EMFProperties.list(parallelTrainNumberFeature);
CoachGroup coachGroup = (CoachGroup) ((Listing) getCurrentSelection()).eContainer().eContainer();
listingDeviceComboViewer.setInput(p.observe(coachGroup));

// bind
IViewerObservableValue listingDeviceViewerObsevable = ViewersObservables.observeSingleSelection(listingDeviceComboViewer);
IObservableValue listingDeviceModelObsevable = EMFEditProperties.value(editingDomain, MetamodelPackage.Literals.LISTING__DEVICE).observeDetail(masterTreeViewerObservable);
bindingContext.bindValue(listingDeviceViewerObsevable, listingDeviceModelObsevable);


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

ClientOrganization = Market
ListingDevice = Product

QUESTION: How can I display ALL Products (ListingDevices) of ALL Markets (ClientOrganization) in my ComboBoy using the EMF mechnism ?

Thank you
Markus
Re: Get all occurrencies of Object-Typ for Combo [message #780306 is a reply to message #780253] Tue, 17 January 2012 15:12 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
Hi Markus,

I haven't looked at your code, but I post here the way I deal with combo's which should present
enums and it works nicely. My UI screens, are always chopped in two parts, 1) build the widgets, 2) inject the data

1) first build a combo


		cmbLevelViewer = new ComboViewer(composite_1, widgetStyle);
		Combo cmbToleranceLevel = cmbLevelViewer.getCombo();
		cmbToleranceLevel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1,
				1));
		toolkit.paintBordersFor(cmbToleranceLevel);


2) do the binding stuff, with an injected object.


cmbLevelViewer.setContentProvider(new ArrayContentProvider());
		cmbLevelViewer.setLabelProvider(new LabelProvider());
		cmbLevelViewer.setInput(LevelKind.VALUES);

		IEMFValueProperty toleranceLevelProperty = EMFEditProperties
				.value(editingService.getEditingDomain(), LibraryPackage.Literals.TOLERANCE__LEVEL);
		IValueProperty selectionProperty = ViewerProperties.singleSelection();
		
		context.bindValue(selectionProperty.observe(cmbLevelViewer),
				toleranceLevelProperty.observe(tolerance), null, null);


does this help?
Re: Get all occurrencies of Object-Typ for Combo [message #780312 is a reply to message #780253] Tue, 17 January 2012 15:29 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
ok, I did look at the code now, you didn't mention what happens with this code. Does it work?
As you build a feature path, you will get only the entries, in the last part of the path, so this will be items from this correct?

MetamodelPackage.Literals.LISTING_DEVICES__LISTING_DEVICE

When combining items from multiple features, I use a Computed list.
see some sample code here:


ComputedList computedResourceList = new ComputedList() {
			@SuppressWarnings("unchecked")
			@Override
			protected List<Object> calculate() {
				List<Object> result = Lists.newArrayList();
				Object value = anySelectionObservable.getValue();
                                // here: put items from value, in the "result" list. 
                                // in your case from both these features,            //MetamodelPackage.Literals.CLIENT_ORGANIZATION__LISTING_DEVICES,
// MetamodelPackage.Literals.LISTING_DEVICES__LISTING_DEVICE 
				return result;
			}
		};


the computed list is then set as an input to the ComboViewer.
Does this help you?

Cheers Christophe

[Updated on: Tue, 17 January 2012 15:30]

Report message to a moderator

Re: Get all occurrencies of Object-Typ for Combo [message #780471 is a reply to message #780312] Wed, 18 January 2012 07:55 Go to previous messageGo to next message
Markus Jo is currently offline Markus JoFriend
Messages: 83
Registered: January 2012
Member
Hi Christophe,
yes your assumption ("As you build a feature path, you will get only the entries, in the last part of the path, so this will be items from this correct?") is correct.

Your advice helps...but I am not sure if I get this "Object value = anySelectionObservable.getValue();" right. SelectionObservable ?

I have done it like this....and it works....nearly complete....

ComputedList computedResourceList = new ComputedList() {
			@SuppressWarnings("unchecked")
			@Override
			protected List<Object> calculate() {
				List<Object> result = new ArrayList<Object>();

				EList<ClientOrganization> mandants = EpaModelAccess.getRootObject().getMandants().getMandant();
				for (ClientOrganization mandant : mandants) {
					result.addAll(mandant.getListingDevices().getListingDevice());
				}
				return result;
			}
		};


listingDeviceComboViewer.setInput(computedResourceList);


Now I have all ListingDevices of all ClientOrganiztations.....BUT if I add a new Listing Device to one of the ClientOrganizations in the EMF model it won´t be shown in the ComboBox until I reopen the editor.
The solution is the SelectionObservable you spoke from ? How do I get these observables ?
Re: Get all occurrencies of Object-Typ for Combo [message #780543 is a reply to message #780471] Wed, 18 January 2012 14:42 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
Hello Markus,

The way you coded it, it's kind of hard reference not based on a selection from another widget or other observable.

this:

"Object value = anySelectionObservable.getValue();" right. SelectionObservable ?


means, that you would get the value from i.e. a tree viewer observable or any observable which would be the base for building up your computed list.
I believe you need to observe you "ClientOrganizations" and use this in the computed list.

rgds Christophe







Re: Get all occurrencies of Object-Typ for Combo [message #781063 is a reply to message #780543] Fri, 20 January 2012 10:11 Go to previous messageGo to next message
Markus Jo is currently offline Markus JoFriend
Messages: 83
Registered: January 2012
Member
Hmm .... maybe I should describe the case again.....source for the dropdown-box is the emf model (all Listing-Devices of all ClientOrganizations). I want to achieve that the entries in the dropdownbox get refreshed if somebody adds/removes/changes a listing device in any of the ClientOrganizations.

I tried this.....

ComputedList computedResourceList = new ComputedList() {
			@SuppressWarnings("unchecked")
			@Override
			protected List<Object> calculate() {
				List<Object> result = new ArrayList<Object>();
//				Object value = anySelectionObservable.getValue();


				IEMFEditValueProperty[] values = EMFEditProperties.values(getEditingDomain(), ClientorganizationPackage.Literals.CLIENT_ORGANIZATIONS__MANDANT);

				for (IEMFEditValueProperty valueProperty : values) {
					IObservableValue valueObsevable =  valueProperty.observe(EpaModelAccess.getRootObject().getMandants());


					IEMFEditValueProperty[] values2 = EMFEditProperties.values(getEditingDomain(), ListingdevicePackage.Literals.LISTING_DEVICES__LISTING_DEVICE);

					for (IEMFEditValueProperty valueProperty2 : values2) {
						IObservableValue valueObsevable2 =  valueProperty.observe(valueObsevable);
						result.add(valueObsevable2);
					}



					result.add(valueObsevable);
				}



....it compiles...thats cool...but I get the following exception: java.lang.ClassCastException: org.eclipse.emf.databinding.edit.internal.EMFEditObservableValueDecorator cannot be cast to org.eclipse.emf.ecore.EObject

So he wants an EObject....but if I just give him an EObject (the ListingDevice), where is the observation-logic. Then he does not know anything about the overlaying clientorganization, does he ? And how does he know that he has to recompute the list wenn somebody changes something in the emf model ?
Re: Get all occurrencies of Object-Typ for Combo [message #781074 is a reply to message #781063] Fri, 20 January 2012 11:49 Go to previous messageGo to next message
Markus Jo is currently offline Markus JoFriend
Messages: 83
Registered: January 2012
Member
Wait a moment before you answer....maybe I got it
Re: Get all occurrencies of Object-Typ for Combo [message #781077 is a reply to message #781074] Fri, 20 January 2012 12:13 Go to previous message
Markus Jo is currently offline Markus JoFriend
Messages: 83
Registered: January 2012
Member
OK, I am the champ.....I got it. Because of the List-in-List construct I had to loop for the features a then trigger "-iterator()" on every ObservableList (the inner ones) in order to "register" it as dependency of the computed list.

I could do something more beautyful....please comment:

Here is the code:

final IObservableList clientOrganizationsObsevable = 
EMFObservables.observeList(EpaModelAccess.getRootObject().getMandants(), ClientorganizationPackage.Literals.CLIENT_ORGANIZATIONS__MANDANT);

final List<IObservableList> observableLists = new ArrayList<IObservableList>();
		for(ClientOrganization clientOrganization : EpaModelAccess.getRootObject().getMandants().getMandant()){
			final IObservableList listingDevicesObsevable = EMFObservables.observeList(clientOrganization.getListingDevices(), ListingdevicePackage.Literals.LISTING_DEVICES__LISTING_DEVICE);
			observableLists.add(listingDevicesObsevable);
		}


ComputedList computedResourceList = new ComputedList() {

			@SuppressWarnings("unchecked")
			@Override
			protected List<Object> calculate() {
				List<Object> result = new ArrayList<Object>();

				for (Object object : clientOrganizationsObsevable) {
					ClientOrganization clientOrganization = (ClientOrganization) object;
					if(clientOrganization.getListingDevices() != null && clientOrganization.getListingDevices().getListingDevice() != null){
						result.addAll(((ClientOrganization) object).getListingDevices().getListingDevice());
					}
				}

				for(IObservableList observableList : observableLists){
					observableList.iterator();
				}
				return result;
			}
		};
		listingDeviceComboViewer.setInput(computedResourceList);

[Updated on: Fri, 20 January 2012 12:14]

Report message to a moderator

Previous Topic:[TENEO] UML2 experience
Next Topic:[CDO] Importing a UML model
Goto Forum:
  


Current Time: Thu Apr 25 16:53:18 GMT 2024

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

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

Back to the top