Home » Modeling » EMF » Hide specific elements in tree editor
| | | | |
Re: Hide specific elements in tree editor [message #426906 is a reply to message #426905] |
Sat, 24 January 2009 12:56 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Matthias,
Comments below.
Matthias wrote:
> Hi,
>
> BUT!
>
> If I try this:
>
> @Override
> public Collection<?> getChildren(Object object) {
> // TODO Auto-generated method stub
>
> EObject eo = (EObject) object;
> Collection<?> collectionVar = (Collection<?>)
> eo.eGet(containments...);
>
> collectionVar.clear();
It's obviously better to make a copy of the collection rather than
modifying the model itself.
>
> return collectionVar;
> }
>
>
> It works and the editor doesn't show the children, but if I do
> something in the editor and save after this, the model WITHOUT the not
> shown childs will be saved to the file. And this is a big problem.
Are you just trying not to show any children for certain features (i.e.,
filtering out entire features, which you can do on the properties for
the GenFeature) or are you trying to filter the children down to a
subset of some specific feature's larger set of children?
>
> Maybe you have a workaround?
Don't change the model if you don't want it to change...
>
> Thanks a lot
>
> Matthias
>
>
> Ed Merks wrote:
>
>> Matthias,
>
>> Comments below.
>
>> Matthias wrote:
>>> Hi,
>>>
>>> thank you for your fast reply.
>>>
>>> This is what I was thinking about...
>>>
>>> You mean this function:
>>>
>>> @Override
>>> public Collection<?> getChildren(Object object) {
>>> // TODO Auto-generated method stub
>>>
>>> return super.getChildren(object);
>>> }
>>>
>>>
>>> But how I can hide elements, when I remove childs from this object
>>> the childs will also removed from the file.
>> It sounds like you've just assumed this but not confirmed it. The
>> item providers are purely for viewing and have no impact on the model
>> itself.
>>>
>>> object is the parent object of the children. When I go thru all his
>>> children, how can I temp delete one or two?
>> Simply return a collection that doesn't contain them.
>>>
>>>
>>> Thank you a lot
>>>
>>>
>>>
>>>
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| | | | | |
Re: Hide specific elements in tree editor [message #426971 is a reply to message #426911] |
Tue, 27 January 2009 14:09 |
Matthias Messages: 19 Registered: July 2009 |
Junior Member |
|
|
Hi Ed,
I'm too stupid at the moment.
My problem at the moment is where I have to implement this?
Is it in MyElementItemProvider.java or somewhere in the Editor.java.
The problem is I need a object of the viewer and I only can get it
somewhere in the editor part and not edit part. Is this correct?
Or how I get the StructuredViewer of the actual object?
Thank's a lot.
Matthias
Ed Merks wrote:
> Matthias,
> StructuredViewer has this method and then you'd implement a ViewerFilter
> to pass in
> public void setFilters(ViewerFilter[] filters)
> Matthias wrote:
>> Hi,
>>
>> this sounds good, how can I set such a filter?
>>
>> Can I say to the filter-> elemet with attribute C don't show?
>>
>> Thanks
>> Matthias
>>
>> Tom Schindl wrote:
>>
>>> Why not setting a ViewerFilter on the TreeViewer?
>>
>>> Tom
>>
>>> Ed Merks schrieb:
>>>> Matthias,
>>>>
>>>> Comments below.
>>>>
>>>>
>>>> Matthias wrote:
>>>>> Hi,
>>>>>
>>>>> yes my example looks like I try to hide ALL of them, but this was just
>>>>> a try.
>>>>>
>>>>> I want to hide only ab subset of them, so it is not possible to do it
>>>>> in the genmodel. Thats easy.
>>>>>
>>>>>
>>>>> But how to distinguish the elements between document and view. Thats
>>>>> the main problem.
>>>> The collection returned by getChildren should be the ones you want in
>>>> the view.
>>>>>
>>>>>
>>>>> At the moment I stay at an end point and I don't know how to solve the
>>>>> problem.
>>>> I'm not sure how else to explain it. Return the children you want in
>>>> the view. Don't modify the model's collections because that modifies
>>>> the state of the model. Make a copy of the list and modify that. Or
>>>> make a new list and add only the ones you want in the view.
>>>>>
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Matthias
>>>>>
>>
|
|
|
Re: Hide specific elements in tree editor [message #426982 is a reply to message #426971] |
Tue, 27 January 2009 16:36 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Matthias,
Comments below.
Matthias wrote:
> Hi Ed,
>
> I'm too stupid at the moment.
Your stupidity is beyond my control. :-P
>
> My problem at the moment is where I have to implement this?
You have to set it on the viewer and the view is created in the editor,
so yes, look for the Viewer creation in the editor.
>
> Is it in MyElementItemProvider.java or somewhere in the Editor.java.
>
> The problem is I need a object of the viewer and I only can get it
> somewhere in the editor part and not edit part. Is this correct?
>
> Or how I get the StructuredViewer of the actual object?
Yes, in the editor.
>
>
> Thank's a lot.
>
> Matthias
>
> Ed Merks wrote:
>
>> Matthias,
>
>> StructuredViewer has this method and then you'd implement a
>> ViewerFilter to pass in
>
>> public void setFilters(ViewerFilter[] filters)
>
>
>> Matthias wrote:
>>> Hi,
>>>
>>> this sounds good, how can I set such a filter?
>>>
>>> Can I say to the filter-> elemet with attribute C don't show?
>>>
>>> Thanks
>>> Matthias
>>>
>>> Tom Schindl wrote:
>>>
>>>> Why not setting a ViewerFilter on the TreeViewer?
>>>
>>>> Tom
>>>
>>>> Ed Merks schrieb:
>>>>> Matthias,
>>>>>
>>>>> Comments below.
>>>>>
>>>>>
>>>>> Matthias wrote:
>>>>>> Hi,
>>>>>>
>>>>>> yes my example looks like I try to hide ALL of them, but this was
>>>>>> just
>>>>>> a try.
>>>>>>
>>>>>> I want to hide only ab subset of them, so it is not possible to
>>>>>> do it
>>>>>> in the genmodel. Thats easy.
>>>>>>
>>>>>>
>>>>>> But how to distinguish the elements between document and view. Thats
>>>>>> the main problem.
>>>>> The collection returned by getChildren should be the ones you want in
>>>>> the view.
>>>>>>
>>>>>>
>>>>>> At the moment I stay at an end point and I don't know how to
>>>>>> solve the
>>>>>> problem.
>>>>> I'm not sure how else to explain it. Return the children you want in
>>>>> the view. Don't modify the model's collections because that modifies
>>>>> the state of the model. Make a copy of the list and modify that. Or
>>>>> make a new list and add only the ones you want in the view.
>>>>>>
>>>>>>
>>>>>> Thanks,
>>>>>>
>>>>>> Matthias
>>>>>>
>>>
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Hide specific elements in tree editor [message #427013 is a reply to message #426982] |
Wed, 28 January 2009 09:05 |
Matthias Messages: 19 Registered: July 2009 |
Junior Member |
|
|
Ok,
now I implemented following code in ...Editor.java
ViewerFilter newFilter = new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement,
Object element) {
EObject eo = (EObject) element;
if((element.getClass().toString()).contains("TypeOfElement")) {
return true;
} else {
return false;
}
}
@Override
public boolean isFilterProperty(Object element, String property) {
EObject eo = (EObject) element;
if((element.getClass().toString()).contains("TypeOfElement")) {
return true;
}
if (property.equals("status"))
return true;
else
return super.isFilterProperty(element, property);
}
};
// Create a page for the parent tree view.
//
{
ViewerPane viewerPane =
new ViewerPane(getSite().getPage(), MSCEditor.this) {
@Override
public Viewer createViewer(Composite composite) {
Tree tree = new Tree(composite, SWT.MULTI);
TreeViewer newTreeViewer = new TreeViewer(tree);
return newTreeViewer;
}
@Override
public void requestActivation() {
super.requestActivation();
setCurrentViewerPane(this);
}
};
viewerPane.createControl(getContainer());
parentViewer = (TreeViewer)viewerPane.getViewer();
parentViewer.setAutoExpandLevel(30);
parentViewer.setContentProvider(new
ReverseAdapterFactoryContentProvider(adapterFactory));
parentViewer.setLabelProvider(new
AdapterFactoryLabelProvider(adapterFactory));
parentViewer.addFilter(newFilter);
createContextMenuFor(parentViewer);
int pageIndex = addPage(viewerPane.getControl());
setPageText(pageIndex, getString("_UI_ParentPage_label"));
}
I added the Filter before the tree is setted with:
ViewerFilter newFilter = new ViewerFilter()
I have added the filter with:
parentViewer.addFilter(newFilter);
I have tried to create the select() and isFilterProperty() with my needs,
but when this functions will be called, or must I call them?
This point is still confusing to me.
Thanks a lot
Matthias
But
Ed Merks wrote:
> Matthias,
> Comments below.
> Matthias wrote:
>> Hi Ed,
>>
>> I'm too stupid at the moment.
> Your stupidity is beyond my control. :-P
>>
>> My problem at the moment is where I have to implement this?
> You have to set it on the viewer and the view is created in the editor,
> so yes, look for the Viewer creation in the editor.
>>
>> Is it in MyElementItemProvider.java or somewhere in the Editor.java.
>>
>> The problem is I need a object of the viewer and I only can get it
>> somewhere in the editor part and not edit part. Is this correct?
>>
>> Or how I get the StructuredViewer of the actual object?
> Yes, in the editor.
>>
>>
>> Thank's a lot.
>>
>> Matthias
>>
>> Ed Merks wrote:
>>
>>> Matthias,
>>
>>> StructuredViewer has this method and then you'd implement a
>>> ViewerFilter to pass in
>>
>>> public void setFilters(ViewerFilter[] filters)
>>
>>
>>> Matthias wrote:
>>>> Hi,
>>>>
>>>> this sounds good, how can I set such a filter?
>>>>
>>>> Can I say to the filter-> elemet with attribute C don't show?
>>>>
>>>> Thanks
>>>> Matthias
>>>>
>>>> Tom Schindl wrote:
>>>>
>>>>> Why not setting a ViewerFilter on the TreeViewer?
>>>>
>>>>> Tom
>>>>
>>>>> Ed Merks schrieb:
>>>>>> Matthias,
>>>>>>
>>>>>> Comments below.
>>>>>>
>>>>>>
>>>>>> Matthias wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> yes my example looks like I try to hide ALL of them, but this was
>>>>>>> just
>>>>>>> a try.
>>>>>>>
>>>>>>> I want to hide only ab subset of them, so it is not possible to
>>>>>>> do it
>>>>>>> in the genmodel. Thats easy.
>>>>>>>
>>>>>>>
>>>>>>> But how to distinguish the elements between document and view. Thats
>>>>>>> the main problem.
>>>>>> The collection returned by getChildren should be the ones you want in
>>>>>> the view.
>>>>>>>
>>>>>>>
>>>>>>> At the moment I stay at an end point and I don't know how to
>>>>>>> solve the
>>>>>>> problem.
>>>>>> I'm not sure how else to explain it. Return the children you want in
>>>>>> the view. Don't modify the model's collections because that modifies
>>>>>> the state of the model. Make a copy of the list and modify that. Or
>>>>>> make a new list and add only the ones you want in the view.
>>>>>>>
>>>>>>>
>>>>>>> Thanks,
>>>>>>>
>>>>>>> Matthias
>>>>>>>
>>>>
>>
>>
|
|
|
Re: Hide specific elements in tree editor [message #427018 is a reply to message #427013] |
Wed, 28 January 2009 11:49 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Matthias,
It sounds like you're ignoring your best friend, the debugger: set a
breakpoint in your select method and see when/if it's called. This
would reveal that of course the framework calls it.
Matthias wrote:
> Ok,
>
> now I implemented following code in ...Editor.java
>
> ViewerFilter newFilter = new ViewerFilter() {
> @Override
> public boolean select(Viewer viewer, Object
> parentElement,
> Object element) {
> EObject eo = (EObject)
> element;
>
>
> if((element.getClass().toString()).contains("TypeOfElement")) {
> return true;
> } else {
> return false;
> }
> }
> @Override
> public boolean isFilterProperty(Object element,
> String property) {
> EObject eo = (EObject)
> element;
>
>
> if((element.getClass().toString()).contains("TypeOfElement")) {
> return true;
> }
> if (property.equals("status"))
> return true;
> else
> return super.isFilterProperty(element,
> property);
> }
> };
>
> // Create a page for the parent tree view.
> //
> {
> ViewerPane viewerPane =
> new ViewerPane(getSite().getPage(), MSCEditor.this) {
> @Override
> public Viewer createViewer(Composite composite) {
> Tree tree = new Tree(composite, SWT.MULTI);
> TreeViewer newTreeViewer = new
> TreeViewer(tree);
> return newTreeViewer;
> }
> @Override
> public void requestActivation() {
> super.requestActivation();
> setCurrentViewerPane(this);
> }
> };
> viewerPane.createControl(getContainer());
>
> parentViewer = (TreeViewer)viewerPane.getViewer();
> parentViewer.setAutoExpandLevel(30);
> parentViewer.setContentProvider(new
> ReverseAdapterFactoryContentProvider(adapterFactory));
> parentViewer.setLabelProvider(new
> AdapterFactoryLabelProvider(adapterFactory));
>
> parentViewer.addFilter(newFilter);
>
> createContextMenuFor(parentViewer);
> int pageIndex = addPage(viewerPane.getControl());
> setPageText(pageIndex,
> getString("_UI_ParentPage_label"));
> }
>
>
>
> I added the Filter before the tree is setted with:
>
> ViewerFilter newFilter = new ViewerFilter()
>
> I have added the filter with:
>
> parentViewer.addFilter(newFilter);
>
>
> I have tried to create the select() and isFilterProperty() with my
> needs, but when this functions will be called, or must I call them?
>
> This point is still confusing to me.
>
> Thanks a lot
>
> Matthias
>
>
> But
> Ed Merks wrote:
>
>> Matthias,
>
>> Comments below.
>
>
>> Matthias wrote:
>>> Hi Ed,
>>>
>>> I'm too stupid at the moment.
>> Your stupidity is beyond my control. :-P
>>>
>>> My problem at the moment is where I have to implement this?
>> You have to set it on the viewer and the view is created in the
>> editor, so yes, look for the Viewer creation in the editor.
>>>
>>> Is it in MyElementItemProvider.java or somewhere in the Editor.java.
>>>
>>> The problem is I need a object of the viewer and I only can get it
>>> somewhere in the editor part and not edit part. Is this correct?
>>>
>>> Or how I get the StructuredViewer of the actual object?
>> Yes, in the editor.
>>>
>>>
>>> Thank's a lot.
>>>
>>> Matthias
>>>
>>> Ed Merks wrote:
>>>
>>>> Matthias,
>>>
>>>> StructuredViewer has this method and then you'd implement a
>>>> ViewerFilter to pass in
>>>
>>>> public void setFilters(ViewerFilter[] filters)
>>>
>>>
>>>> Matthias wrote:
>>>>> Hi,
>>>>>
>>>>> this sounds good, how can I set such a filter?
>>>>>
>>>>> Can I say to the filter-> elemet with attribute C don't show?
>>>>>
>>>>> Thanks
>>>>> Matthias
>>>>>
>>>>> Tom Schindl wrote:
>>>>>
>>>>>> Why not setting a ViewerFilter on the TreeViewer?
>>>>>
>>>>>> Tom
>>>>>
>>>>>> Ed Merks schrieb:
>>>>>>> Matthias,
>>>>>>>
>>>>>>> Comments below.
>>>>>>>
>>>>>>>
>>>>>>> Matthias wrote:
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> yes my example looks like I try to hide ALL of them, but this
>>>>>>>> was just
>>>>>>>> a try.
>>>>>>>>
>>>>>>>> I want to hide only ab subset of them, so it is not possible to
>>>>>>>> do it
>>>>>>>> in the genmodel. Thats easy.
>>>>>>>>
>>>>>>>>
>>>>>>>> But how to distinguish the elements between document and view.
>>>>>>>> Thats
>>>>>>>> the main problem.
>>>>>>> The collection returned by getChildren should be the ones you
>>>>>>> want in
>>>>>>> the view.
>>>>>>>>
>>>>>>>>
>>>>>>>> At the moment I stay at an end point and I don't know how to
>>>>>>>> solve the
>>>>>>>> problem.
>>>>>>> I'm not sure how else to explain it. Return the children you
>>>>>>> want in
>>>>>>> the view. Don't modify the model's collections because that
>>>>>>> modifies
>>>>>>> the state of the model. Make a copy of the list and modify
>>>>>>> that. Or
>>>>>>> make a new list and add only the ones you want in the view.
>>>>>>>>
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>>
>>>>>>>> Matthias
>>>>>>>>
>>>>>
>>>
>>>
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Hide specific elements in tree editor [message #427032 is a reply to message #427018] |
Wed, 28 January 2009 19:52 |
Matthias Messages: 19 Registered: July 2009 |
Junior Member |
|
|
Hi Ed,
thank you very much. Your right, the debugger knows everything!!
It works.
Thanks a lot.
Matthias
Ed Merks wrote:
> Matthias,
> It sounds like you're ignoring your best friend, the debugger: set a
> breakpoint in your select method and see when/if it's called. This
> would reveal that of course the framework calls it.
> Matthias wrote:
>> Ok,
>>
>> now I implemented following code in ...Editor.java
>>
>> ViewerFilter newFilter = new ViewerFilter() {
>> @Override
>> public boolean select(Viewer viewer, Object
>> parentElement,
>> Object element) {
>> EObject eo = (EObject)
>> element;
>>
>>
>> if((element.getClass().toString()).contains("TypeOfElement")) {
>> return true;
>> } else {
>> return false;
>> }
>> }
>> @Override
>> public boolean isFilterProperty(Object element,
>> String property) {
>> EObject eo = (EObject)
>> element;
>>
>>
>> if((element.getClass().toString()).contains("TypeOfElement")) {
>> return true;
>> }
>> if (property.equals("status"))
>> return true;
>> else
>> return super.isFilterProperty(element,
>> property);
>> }
>> };
>>
>> // Create a page for the parent tree view.
>> //
>> {
>> ViewerPane viewerPane =
>> new ViewerPane(getSite().getPage(), MSCEditor.this) {
>> @Override
>> public Viewer createViewer(Composite composite) {
>> Tree tree = new Tree(composite, SWT.MULTI);
>> TreeViewer newTreeViewer = new
>> TreeViewer(tree);
>> return newTreeViewer;
>> }
>> @Override
>> public void requestActivation() {
>> super.requestActivation();
>> setCurrentViewerPane(this);
>> }
>> };
>> viewerPane.createControl(getContainer());
>>
>> parentViewer = (TreeViewer)viewerPane.getViewer();
>> parentViewer.setAutoExpandLevel(30);
>> parentViewer.setContentProvider(new
>> ReverseAdapterFactoryContentProvider(adapterFactory));
>> parentViewer.setLabelProvider(new
>> AdapterFactoryLabelProvider(adapterFactory));
>>
>> parentViewer.addFilter(newFilter);
>>
>> createContextMenuFor(parentViewer);
>> int pageIndex = addPage(viewerPane.getControl());
>> setPageText(pageIndex,
>> getString("_UI_ParentPage_label"));
>> }
>>
>>
>>
>> I added the Filter before the tree is setted with:
>>
>> ViewerFilter newFilter = new ViewerFilter()
>>
>> I have added the filter with:
>>
>> parentViewer.addFilter(newFilter);
>>
>>
>> I have tried to create the select() and isFilterProperty() with my
>> needs, but when this functions will be called, or must I call them?
>>
>> This point is still confusing to me.
>>
>> Thanks a lot
>>
>> Matthias
>>
>>
>> But
>> Ed Merks wrote:
>>
>>> Matthias,
>>
>>> Comments below.
>>
>>
>>> Matthias wrote:
>>>> Hi Ed,
>>>>
>>>> I'm too stupid at the moment.
>>> Your stupidity is beyond my control. :-P
>>>>
>>>> My problem at the moment is where I have to implement this?
>>> You have to set it on the viewer and the view is created in the
>>> editor, so yes, look for the Viewer creation in the editor.
>>>>
>>>> Is it in MyElementItemProvider.java or somewhere in the Editor.java.
>>>>
>>>> The problem is I need a object of the viewer and I only can get it
>>>> somewhere in the editor part and not edit part. Is this correct?
>>>>
>>>> Or how I get the StructuredViewer of the actual object?
>>> Yes, in the editor.
>>>>
>>>>
>>>> Thank's a lot.
>>>>
>>>> Matthias
>>>>
>>>> Ed Merks wrote:
>>>>
>>>>> Matthias,
>>>>
>>>>> StructuredViewer has this method and then you'd implement a
>>>>> ViewerFilter to pass in
>>>>
>>>>> public void setFilters(ViewerFilter[] filters)
>>>>
>>>>
>>>>> Matthias wrote:
>>>>>> Hi,
>>>>>>
>>>>>> this sounds good, how can I set such a filter?
>>>>>>
>>>>>> Can I say to the filter-> elemet with attribute C don't show?
>>>>>>
>>>>>> Thanks
>>>>>> Matthias
>>>>>>
>>>>>> Tom Schindl wrote:
>>>>>>
>>>>>>> Why not setting a ViewerFilter on the TreeViewer?
>>>>>>
>>>>>>> Tom
>>>>>>
>>>>>>> Ed Merks schrieb:
>>>>>>>> Matthias,
>>>>>>>>
>>>>>>>> Comments below.
>>>>>>>>
>>>>>>>>
>>>>>>>> Matthias wrote:
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> yes my example looks like I try to hide ALL of them, but this
>>>>>>>>> was just
>>>>>>>>> a try.
>>>>>>>>>
>>>>>>>>> I want to hide only ab subset of them, so it is not possible to
>>>>>>>>> do it
>>>>>>>>> in the genmodel. Thats easy.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> But how to distinguish the elements between document and view.
>>>>>>>>> Thats
>>>>>>>>> the main problem.
>>>>>>>> The collection returned by getChildren should be the ones you
>>>>>>>> want in
>>>>>>>> the view.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> At the moment I stay at an end point and I don't know how to
>>>>>>>>> solve the
>>>>>>>>> problem.
>>>>>>>> I'm not sure how else to explain it. Return the children you
>>>>>>>> want in
>>>>>>>> the view. Don't modify the model's collections because that
>>>>>>>> modifies
>>>>>>>> the state of the model. Make a copy of the list and modify
>>>>>>>> that. Or
>>>>>>>> make a new list and add only the ones you want in the view.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Thanks,
>>>>>>>>>
>>>>>>>>> Matthias
>>>>>>>>>
>>>>>>
>>>>
>>>>
>>
>>
|
|
| |
Goto Forum:
Current Time: Thu Sep 26 13:53:03 GMT 2024
Powered by FUDForum. Page generated in 0.04152 seconds
|