Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Hiding and unhiding elements / editparts
Hiding and unhiding elements / editparts [message #683431] Mon, 13 June 2011 17:48 Go to next message
Ivar Refsdal is currently offline Ivar RefsdalFriend
Messages: 24
Registered: May 2011
Junior Member
Hi,

I'm trying to hide (and unhide) some elements using the notation view in
GMF.
Hiding works fine. This is done through a parent element.

However, how can one go about to unhide these elements (through the same
parent element)?
I'm using the following code:

> public void hideSelfAndChildren(GraphicalEditPart part, TransactionalEditingDomain ted, CompoundCommand cc) {
> View v = ((GraphicalEditPart) part).getNotationView();
> Boolean newVal = v.isVisible() ? Boolean.FALSE : Boolean.TRUE;
> SetCommand cmd = new SetCommand(ted, v, NotationPackage.Literals.VIEW__VISIBLE, newVal);
> cc.append(cmd);
> System.err.println("changing visibility of " + part);
> for (GraphicalEditPart child : getChildren(part)) {
> hideSelfAndChildren(child, ted, cc);
> }
> }
>
> private List<GraphicalEditPart> getChildren(GraphicalEditPart part) {
> List<GraphicalEditPart> children = new LinkedList<GraphicalEditPart>();
>
> for (Object childConnection : part.getSourceConnections()) {
> System.err.println("found outgoing connection...");
> if (childConnection instanceof AbstractConnectionEditPart) {
> AbstractConnectionEditPart child = (AbstractConnectionEditPart)childConnection;
> EditPart target = child.getTarget();
> if (target instanceof GraphicalEditPart) {
> children.add((GraphicalEditPart) target);
> }
> }
> }
> return children;
> }
> public void run(IAction action) {
>
> if (selection==null) return;
> if (selection instanceof IStructuredSelection) {
>
> if (((IStructuredSelection) selection).getFirstElement() instanceof GraphicalEditPart) {
> GraphicalEditPart part = (GraphicalEditPart) ((IStructuredSelection) selection).getFirstElement();
> TransactionalEditingDomain ted = part.getEditingDomain();
> CompoundCommand cc = new CompoundCommand();
> System.err.println("");
>
> int cnt = 0;
> for (GraphicalEditPart child : getChildren(part)) {
> System.err.println("doing child " + child);
> hideSelfAndChildren(child, ted, cc);
> cnt++;
> }
> if (cnt==0) {
> System.err.println("trying to restore part.. ");
> part.refresh();
> // todo: how to unhide?
> } else {
> System.err.println("executing compoundcommand");
> ted.getCommandStack().execute(cc);
> }
>
> }
> }
> }


When trying to unhide elements, child.getTarget() simply returns null.
How does one restore that editPart? Any clues?

Thanks and all the best,
Ivar Refsdal
Re: Hiding and unhiding elements / editparts [message #683852 is a reply to message #683431] Tue, 14 June 2011 14:04 Go to previous message
Ivar Refsdal is currently offline Ivar RefsdalFriend
Messages: 24
Registered: May 2011
Junior Member
Hi all,

I found a solution for this.
To retrieve the hidden views one can do something like this:

> private List<View> invisibleViews(GraphicalEditPart part) {
> List<View> result = new LinkedList<View>();
> ResourceSet resSet = part.getEditingDomain().getResourceSet();
> for (Resource res : resSet.getResources()) {
> if (res instanceof GMFResource) {
> Iterator<EObject> it = res.getAllContents();
> while (it.hasNext()) {
> EObject obj = it.next();
> if (obj instanceof View) {
> View v = (View) obj;
> if (v.isVisible()==false) {
> result.add(v);
> }
> }
> }
> }
> }
> return result;
> }


Then the View will have a .getElement() which returns your domain
object. So, one can use something like this (this is the easy part..):

> List<EObject> children = semanticChildren(part, new LinkedList<EObject>());
> System.err.println("and the children are " + children);
> for (View view : invisibleViews(part)) {
> if (children.contains(view.getElement())) {
> SetCommand cmd = new SetCommand(ted, view, NotationPackage.Literals.VIEW__VISIBLE, Boolean.TRUE);
> cc.append(cmd);
> }
> }
> System.err.println("executing compoundcommand");
> ted.getCommandStack().execute(cc);
>
> System.err.println("trying to restore part.. ");
> part.refresh();
semanticChildren of course needs to return the semantic children (i.e.
domain objects) of the part that was clicked.

The hiddenness of the objects are persisted across sessions and so on. I
did not discover any problems with this, but then again of course there
may be..

Is this the "right" way to do it, or is there a better way? Comments
would be appreciated.

Thanks and all the best,
Ivar


Ivar Refsdal wrote, on 06/13/2011 07:48 PM:
> Hi,
>
> I'm trying to hide (and unhide) some elements using the notation view in
> GMF.
> Hiding works fine. This is done through a parent element.
>
> However, how can one go about to unhide these elements (through the same
> parent element)?
> I'm using the following code:
>
>> public void hideSelfAndChildren(GraphicalEditPart part,
>> TransactionalEditingDomain ted, CompoundCommand cc) {
>> View v = ((GraphicalEditPart) part).getNotationView();
>> Boolean newVal = v.isVisible() ? Boolean.FALSE : Boolean.TRUE;
>> SetCommand cmd = new SetCommand(ted, v,
>> NotationPackage.Literals.VIEW__VISIBLE, newVal);
>> cc.append(cmd);
>> System.err.println("changing visibility of " + part);
>> for (GraphicalEditPart child : getChildren(part)) {
>> hideSelfAndChildren(child, ted, cc);
>> }
>> }
>>
>> private List<GraphicalEditPart> getChildren(GraphicalEditPart part) {
>> List<GraphicalEditPart> children = new LinkedList<GraphicalEditPart>();
>>
>> for (Object childConnection : part.getSourceConnections()) {
>> System.err.println("found outgoing connection...");
>> if (childConnection instanceof AbstractConnectionEditPart) {
>> AbstractConnectionEditPart child =
>> (AbstractConnectionEditPart)childConnection;
>> EditPart target = child.getTarget();
>> if (target instanceof GraphicalEditPart) {
>> children.add((GraphicalEditPart) target);
>> }
>> }
>> }
>> return children;
>> }
>> public void run(IAction action) {
>>
>> if (selection==null) return;
>> if (selection instanceof IStructuredSelection) {
>>
>> if (((IStructuredSelection) selection).getFirstElement() instanceof
>> GraphicalEditPart) {
>> GraphicalEditPart part = (GraphicalEditPart) ((IStructuredSelection)
>> selection).getFirstElement();
>> TransactionalEditingDomain ted = part.getEditingDomain();
>> CompoundCommand cc = new CompoundCommand();
>> System.err.println("");
>>
>> int cnt = 0;
>> for (GraphicalEditPart child : getChildren(part)) {
>> System.err.println("doing child " + child);
>> hideSelfAndChildren(child, ted, cc);
>> cnt++;
>> }
>> if (cnt==0) {
>> System.err.println("trying to restore part.. ");
>> part.refresh();
>> // todo: how to unhide?
>> } else {
>> System.err.println("executing compoundcommand");
>> ted.getCommandStack().execute(cc);
>> }
>>
>> }
>> }
>> }
>
>
> When trying to unhide elements, child.getTarget() simply returns null.
> How does one restore that editPart? Any clues?
>
> Thanks and all the best,
> Ivar Refsdal
Re: Hiding and unhiding elements / editparts [message #683853 is a reply to message #683431] Tue, 14 June 2011 14:04 Go to previous message
Ivar Refsdal is currently offline Ivar RefsdalFriend
Messages: 24
Registered: May 2011
Junior Member
Hi all,

I found a solution for this.
To retrieve the hidden views one can do something like this:

> private List<View> invisibleViews(GraphicalEditPart part) {
> List<View> result = new LinkedList<View>();
> ResourceSet resSet = part.getEditingDomain().getResourceSet();
> for (Resource res : resSet.getResources()) {
> if (res instanceof GMFResource) {
> Iterator<EObject> it = res.getAllContents();
> while (it.hasNext()) {
> EObject obj = it.next();
> if (obj instanceof View) {
> View v = (View) obj;
> if (v.isVisible()==false) {
> result.add(v);
> }
> }
> }
> }
> }
> return result;
> }


Then the View will have a .getElement() which returns your domain
object. So, one can use something like this (this is the easy part..):

> List<EObject> children = semanticChildren(part, new LinkedList<EObject>());
> System.err.println("and the children are " + children);
> for (View view : invisibleViews(part)) {
> if (children.contains(view.getElement())) {
> SetCommand cmd = new SetCommand(ted, view, NotationPackage.Literals.VIEW__VISIBLE, Boolean.TRUE);
> cc.append(cmd);
> }
> }
> System.err.println("executing compoundcommand");
> ted.getCommandStack().execute(cc);
>
> System.err.println("trying to restore part.. ");
> part.refresh();
semanticChildren of course needs to return the semantic children (i.e.
domain objects) of the part that was clicked.

The hiddenness of the objects are persisted across sessions and so on. I
did not discover any problems with this, but then again of course there
may be..

Is this the "right" way to do it, or is there a better way? Comments
would be appreciated.

Thanks and all the best,
Ivar


Ivar Refsdal wrote, on 06/13/2011 07:48 PM:
> Hi,
>
> I'm trying to hide (and unhide) some elements using the notation view in
> GMF.
> Hiding works fine. This is done through a parent element.
>
> However, how can one go about to unhide these elements (through the same
> parent element)?
> I'm using the following code:
>
>> public void hideSelfAndChildren(GraphicalEditPart part,
>> TransactionalEditingDomain ted, CompoundCommand cc) {
>> View v = ((GraphicalEditPart) part).getNotationView();
>> Boolean newVal = v.isVisible() ? Boolean.FALSE : Boolean.TRUE;
>> SetCommand cmd = new SetCommand(ted, v,
>> NotationPackage.Literals.VIEW__VISIBLE, newVal);
>> cc.append(cmd);
>> System.err.println("changing visibility of " + part);
>> for (GraphicalEditPart child : getChildren(part)) {
>> hideSelfAndChildren(child, ted, cc);
>> }
>> }
>>
>> private List<GraphicalEditPart> getChildren(GraphicalEditPart part) {
>> List<GraphicalEditPart> children = new LinkedList<GraphicalEditPart>();
>>
>> for (Object childConnection : part.getSourceConnections()) {
>> System.err.println("found outgoing connection...");
>> if (childConnection instanceof AbstractConnectionEditPart) {
>> AbstractConnectionEditPart child =
>> (AbstractConnectionEditPart)childConnection;
>> EditPart target = child.getTarget();
>> if (target instanceof GraphicalEditPart) {
>> children.add((GraphicalEditPart) target);
>> }
>> }
>> }
>> return children;
>> }
>> public void run(IAction action) {
>>
>> if (selection==null) return;
>> if (selection instanceof IStructuredSelection) {
>>
>> if (((IStructuredSelection) selection).getFirstElement() instanceof
>> GraphicalEditPart) {
>> GraphicalEditPart part = (GraphicalEditPart) ((IStructuredSelection)
>> selection).getFirstElement();
>> TransactionalEditingDomain ted = part.getEditingDomain();
>> CompoundCommand cc = new CompoundCommand();
>> System.err.println("");
>>
>> int cnt = 0;
>> for (GraphicalEditPart child : getChildren(part)) {
>> System.err.println("doing child " + child);
>> hideSelfAndChildren(child, ted, cc);
>> cnt++;
>> }
>> if (cnt==0) {
>> System.err.println("trying to restore part.. ");
>> part.refresh();
>> // todo: how to unhide?
>> } else {
>> System.err.println("executing compoundcommand");
>> ted.getCommandStack().execute(cc);
>> }
>>
>> }
>> }
>> }
>
>
> When trying to unhide elements, child.getTarget() simply returns null.
> How does one restore that editPart? Any clues?
>
> Thanks and all the best,
> Ivar Refsdal
Previous Topic:why save failed
Next Topic:Customize command "Initialize XXX model diagram" => Don't arrange everything horizontal
Goto Forum:
  


Current Time: Thu Dec 05 13:00:27 GMT 2024

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

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

Back to the top