Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Hide specific elements in tree editor
Hide specific elements in tree editor [message #426896] Fri, 23 January 2009 20:36 Go to next message
Matthias is currently offline MatthiasFriend
Messages: 19
Registered: July 2009
Junior Member
Hi,

I have created a tree editor with emf. I want to hide specific elements in
the tree editor.

But not all!!

example:

-parent element
-element 1
-element 2 <-how to hide this?
-element 3


Is it possible to decide maybe with the name of the element or elements
with the same name only one time shown or hidden?


Thank you for your help!

Matthias
Re: Hide specific elements in tree editor [message #426900 is a reply to message #426896] Sat, 24 January 2009 02:44 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Matthias,

Comments below.


Matthias wrote:
> Hi,
>
> I have created a tree editor with emf. I want to hide specific
> elements in the tree editor.
>
> But not all!!
> example:
>
> -parent element
> -element 1
> -element 2 <-how to hide this?
> -element 3
>
>
> Is it possible to decide maybe with the name of the element or
> elements with the same name only one time shown or hidden?
It's certainly not trivial. In the end, it's AbcItemProvider's
getChildren/getElements that determines what's shown, so you can
certainly alter what's returned by those. But things like drag and drop
and other things based on child position will need specialization as well...
>
>
> Thank you for your help!
>
> Matthias
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Hide specific elements in tree editor [message #426901 is a reply to message #426900] Sat, 24 January 2009 08:30 Go to previous messageGo to next message
Matthias is currently offline MatthiasFriend
Messages: 19
Registered: July 2009
Junior Member
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.

object is the parent object of the children. When I go thru all his
children, how can I temp delete one or two?


Thank you a lot
Re: Hide specific elements in tree editor [message #426904 is a reply to message #426901] Sat, 24 January 2009 11:33 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
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 #426905 is a reply to message #426904] Sat, 24 January 2009 12:13 Go to previous messageGo to next message
Matthias is currently offline MatthiasFriend
Messages: 19
Registered: July 2009
Junior Member
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();

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.

Maybe you have a workaround?

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
>>
>>
>>
>>
Re: Hide specific elements in tree editor [message #426906 is a reply to message #426905] Sat, 24 January 2009 12:56 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
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 #426907 is a reply to message #426906] Sat, 24 January 2009 13:08 Go to previous messageGo to next message
Matthias is currently offline MatthiasFriend
Messages: 19
Registered: July 2009
Junior Member
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.


At the moment I stay at an end point and I don't know how to solve the
problem.


Thanks,

Matthias
Re: Hide specific elements in tree editor [message #426908 is a reply to message #426907] Sat, 24 January 2009 14:09 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
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 #426909 is a reply to message #426908] Sat, 24 January 2009 14:27 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
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
>>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: Hide specific elements in tree editor [message #426910 is a reply to message #426909] Sat, 24 January 2009 18:39 Go to previous messageGo to next message
Matthias is currently offline MatthiasFriend
Messages: 19
Registered: July 2009
Junior Member
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 #426911 is a reply to message #426910] Sat, 24 January 2009 20:45 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
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 #426971 is a reply to message #426911] Tue, 27 January 2009 14:09 Go to previous messageGo to next message
Matthias is currently offline MatthiasFriend
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 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
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 Go to previous messageGo to next message
Matthias is currently offline MatthiasFriend
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 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
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 Go to previous messageGo to next message
Matthias is currently offline MatthiasFriend
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
>>>>>>>>>
>>>>>>
>>>>
>>>>
>>
>>
Re: Hide specific elements in tree editor [message #1815060 is a reply to message #426896] Wed, 25 September 2019 05:42 Go to previous message
vikash singh is currently offline vikash singhFriend
Messages: 6
Registered: September 2019
Junior Member
//add a filter in tree viewer

treeViewer.addFilter(new ViewerFilter() {

@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {

if (element instanceof MyObj) {
Myobj srmObj = (Myobj ) element;
if(srmObj .equals("element2")
return false;
else
return true;
}


});
Previous Topic:Hook to prevent command execution
Next Topic:I create an xml element by right click to EMF editor. Default values appear but not get saved to xml
Goto Forum:
  


Current Time: Tue Apr 16 23:02:30 GMT 2024

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

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

Back to the top