How to use properties from a child in EMF - eclipse

I have a sample EMF hierarchy like this -
Parent : Shape
Child 1 : Circle
Child 2 : Square
Child 3 : Rect
Now I want to generate my properties view in Eclipse in such a way that . I have a drop down with ShapeType and based on the shape type I want to show the properties of the child element.
Essentially I want to display/edit the child properties based on the 'type' selection in the parent.
Any thoughts how I can achieve this?

You cannot solve this issue easily, as in that case the dropdown needs to change the EMF type of an object, that results in Java class changes. To have such thing working, you have to create a new EObject instance, copy all relevant attributes, and remove the old object (and possibly update the selection).
So, alltogether, I believe, what you want is not possible with basic EMF tooling, however, if you provide a custom model manipulation commands, it should be possible.
Other things, you can try (if possible in your domain):
Move all your data to properties of the parent object, add EValidators to prevent inconsistent states from appearing, and update the default EMF Edit commands to filter out unnecessary editors. Ugly, but may work.
Create custom forms/editors, that manage the object removal/addition during the manually coded editing process.

Related

TYPO3 9.5 Sorting of child-elements from parent

I have a problem finding a simple and easy solution to sort child-elements in it's parent. I don't want to have them sorted by the sorting-property of the child but some other value (in this example sort_value).
The parent has the property child_elements, and the child has a property sort_value.
I've already tried adding the following statement to the defaultOrderings of the ParentRepository:
'child_elements.sort_value' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
I've also tried with childElements.sort_value and childElements.sortValue but that didn't work in either way.
I've found some solutions like sorting the children in the template using vhs-viewhelper or with injecting the childRepository into the ParentModel which then calls the findAll-function on the child in the getter-function of the parent (which is really dirty)...
Is there a mistake I'm not aware of in the defaultOrderings-statement? Or is there simply not such a simple way to do it?
The childRepository already has it's defaultOrderings set to the sortValue. The functions used for getting the parent is findAll or findByUid so no custom repository function.
What I want is to get the parent-object with it's sorted children by the children's field sort_value.
Thanks for your help.

MVVM practices: expose viewmodel class inside a control

I've edited the question to make what I want to obtain clearer.
Here's the original question:
I'm working on a class that inherits from Control which will be used in my View and includes some Dependency Properties.
One of these DPs is an IEnumerable(Of RfidTag) and will be bound to an ObservableCollection(Of RfidTag) inside the VM.
The class RfidTag is defined as public class in the same file where the VM's class resides.
The questions are:
1. is it a good practice to expose a VM-related class to a Control class?
2. is the VM source file a good place for the RfidTag class?
UPDATE 1
In my application logic (I think I could say in my Model) there is an event published throught an Eventaggregator. The event's payload is a List of ModelRfidTag (that is the model class).
My VM subscribes to this event and I made the RfidTag class to wrap my Model class and provides some additional properties related only to the VM.
When the event handler inside the VM is executed, it makes an ObservableCollection(Of RfidTag) bindable from the view.
Then in the View I've a bounch of my control instances like that
<c:RfidTagPresenter
TagPosition="1"
Collection="{Binding RfidTagList, Mode=OneWay}" />
Then in my RfidTagPresenter (the class that inherits from Control) I've a DP of type RfidTag (called RfidTagResult) that returns the object in the OC which has the Position property (property available inside the RfidTag class) equal to the value set by the TagPosition DP.
In this way, the ControlTemplate of the RfidTagPresenter can bind its elements to the desired object.
This is the simplification of what I want to make. In the actual application there are some other DPs on which the RfidTagResult selection is performed
UPDATE 2
After a bit of research, seem that I can solve one problem with an indexed property that return (in the get method) the object from the collection I want to bind.
However a problem still exist: My control need to have a DP of type of RfidTag so that the relative ControlTemplate can bind to the property declared in the RfidTag class.
So: Is it possible (read: a good practice) to have a DP of a type that is a VM related class?
In other words: Can a custom control know about the class type used by the VM?
I will try to go all over your question (if I miss something let me know) but first you should explain the purpose of binding a Collection in a control as a DP.
is it a good practice to expose a VM-related class to a Control class?
RfidTag, I suppose, is a Model. What you are really doing here is binding a Model in your control which go against the MVVM pattern. You should think about the next question... Do you really need all your RfidTag to be shown in the View ? If you need to show a name, an ID... you could just create an IEnumerable<string> as DP (which is correct) and then in your VM instead of an ObservableCollection<RfidTag> you would have an ObservableCollection<string>.
Some simple theory. In MVVM, VM adapts the Model to the View. So your VM should have everything that will be shown in your View.
is the VM source file a good place for the RfidTag class?
RfidTag is a Model so there's no better place for it :)

Eclipse 4 RCP - how to change what is showed in specific area?

I have splitted my application into two main areas.
Part(A)
PartStashContainer(B)
The content of A should be set based on what user wants.
So basically i can have 1..N classes which could be used in Class URI of Part in application model.
I don't know if i should replace the whole Part(A) with new dynamically created Part(C) which has content i want, or i should somehow to modify the existing Part (call setContributionURI, or setObject methods on Part object?).
It does make more sense to me to modify the existing Part, because it is defined in Application model and therefore already describing the location where the content should be.
Possible solutions:
Modify the Part object so it "reload" its content based on new setup (But how? Can setContributionURI or setObject methods help?)
Remove the old Part and add dynamically on same place in Application model the new Part (using EModelService and EPartService).
other solution??
If you want to reuse the Part then do something like:
MPart part = find or inject your part
MyClass myClass = (MyClass)part.getObject();
... call a method of MyClass to change the contents
MyClass is the class you specify for the object in the application model. You should add a method to that to let you change the contents.
Don't try to call setObject, this is really only for use by Eclipse. I don't think setContributionURI would do anything after the part is created (but I am not sure).
If you want to use different classes for the different data then you really should use different Parts.

How to get Properties from an EObject, similiar to the Properties View

i have an EObject and want to get all the Properties from it. I tryed to get all Structural Features:
myEObject.eClass().getEAllStructuralFeatures()
but i get too many Properties i do not want like the object ID.
With
myEObject.eClass().getEStructuralFeatures()
there are missing some that are displayed in the Properties View.
So how can i get the same List of Properties from an EObject like the Properties View does?
Thx for your help
Just use the first option and filter out the ones you don't want (like object id) from being displayed. It's probably the easiest way.
If it must absolutely be the same as the list that is displayed in the properties view, the safest bet is to find the code used to populate the properties view and reuse it.

Eclipse: Connecting a TextEditor to the Properties View

I am currently implementing an Eclipse-Plugin which is using the standard properties view, connected to a Navigator. It also features a textual editor, which is able to connect regions within its' document to certain objects that can supply properties to the PropertiesView (i.e. the same objects, that are displayed in the Navigator).
However, the Tuturials I found only dealt with Views that used a pre-implemented Viewer, which already supported passing on the selected element to the Properties View.
The TextEditor does not do that (I am using jface and a subclass of the AbstractTextEditor class), because it's SelectionProvider returns informations about the offset and the length of the selection only.
How do I have to modify the SelectionProvider of my TextEditor, such that it provides information usable to the Properties View?
Thank you in advance
Okay, I have managed to find the solution myself.
First of all, I had to implement the getAdapter() method in my subclass of TextEditor such that it returns an Adapter for IPropertySourceProvider, that can deal with the type of elements that are selected in my AbstractTextEditor.
Then, I implemented an ISelection that extended TextSelection, in order to not interfere with any selection-specific mechanism supplied by the AbstractTextEditor, and implements the interface IStructuredSelection, because the Properties View works with this interface of ISelection only.
An IStructuredSelection features basic methods of an array, however, in my case it is only possible to ever select only a single element, so implementation of these methods were trivial.
The last step was to get my ISelection to the right place. Overwriting the getSelection()-method of the ISelectionProvider of the AbstractTextEditor did not suffice, because obviously, the methods of firing SelectionChangedEvents does not use this method.
Thus, instead of using a standard SourceViewer, I used my own implementation in which I basically overrid the methods fireSelectionChanged(int offset, int length) and firePostSelectionChanged(int offset, int lenght), such that they use events containing my ISelection.
The rest is implementing the handling of my Objects in the Adapter for IPropertySourceProvider in a way that it returns an IPropertySource for the given Object, as it is shown in various tutorials.