Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 10 Replies) AttachToNode and detaching during modifying event (Read 8069 times)
koosala
Full Member
***
Offline


Java Happens

Posts: 136
Joined: May 13th, 2007
AttachToNode and detaching during modifying event
Nov 2nd, 2007 at 6:15am
Print Post  
Hi,

I have this requirement where two boxes must be attached to another bigger box when on the flowchart. When the bigger box is moved around the two boxes must move also.

This works alright for me.

I also need to detach the boxes if the bigger box is resized. So, I handle the ItemModifying event to detach the two boxes.

The boxes get detached alright,

But I get two problems with this:

1. If there is an arrow connecting the two smaller boxes, the arrow also moves with the bigger box.

2. The two boxes become unselectable after the resize. They can never be selected again.

I have attached the code here:

[code]

private void testContainment() {
Box three = new Box(flowChart);
three.setBounds(5, 5, 60, 60);

Box one = new Box(flowChart);
one.setBounds(10, 10, 15, 15);

Box two = new Box(flowChart);
two.setBounds(40, 10, 15, 15);

flowChart.addFlowChartListener(new FlowChartAdapter() {
@Override
public void itemModifying(ValidationEvent e) {
if (e.getItem() instanceof Box && e.getSelectionHandle() != 8) {

ItemList attachedItems = new ItemList();

for (Item item : ((Box) e.getItem()).getSubordinateGroup()
.getAttachedItems()) {
attachedItems.add(item);
}

for (Item item : attachedItems) {
((Box) item).detach();
}

if (((Box) e.getItem()).getSubordinateGroup() != null) {
((Box) e.getItem()).getSubordinateGroup()
.getAttachedItems().clear();
}
}
}
});

flowChart.add(three);
flowChart.add(one);
flowChart.add(two);

one.attachTo(three, AttachToNode.TopCenter);
two.attachTo(three, AttachToNode.TopCenter);
}
[/code]

Or if there is any other way I can fulfil my requirement?

Thanks,
Praveen
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: AttachToNode and detaching during modifying ev
Reply #1 - Nov 2nd, 2007 at 7:20am
Print Post  
Hi,

You will need to modify the source code again.

1. Add this to the FlowChart class:

public InteractionState getInteraction()
{
     return interaction;
}

2. Make the cancelModify method of Box public.

3. Add the following line after calling detach():

((Box) item).cancelModify(item.getFlowChart().getInteraction());

Stoyan
  
Back to top
 
IP Logged
 
koosala
Full Member
***
Offline


Java Happens

Posts: 136
Joined: May 13th, 2007
Re: AttachToNode and detaching during modifying ev
Reply #2 - Nov 2nd, 2007 at 9:27am
Print Post  
Hi Stoyan,

Thanks, this solves the problem 2, and the boxes are now selectable.

But the problem 1 is still present - the arrow connecting the two smaller box is still moving with the larger box.

Thanks,
Praveen
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: AttachToNode and detaching during modifying ev
Reply #3 - Nov 2nd, 2007 at 9:36am
Print Post  
Hi,

It did not move in my test, but maybe you can also call the arrow's cancelModify method to prevent that anyway.

Stoyan
  
Back to top
 
IP Logged
 
koosala
Full Member
***
Offline


Java Happens

Posts: 136
Joined: May 13th, 2007
Re: AttachToNode and detaching during modifying ev
Reply #4 - Nov 5th, 2007 at 1:03am
Print Post  
Hi Stoyan,

I have the following code now:

[code]
private void testContainment() {
Box three = new Box(flowChart);
three.setBounds(5, 5, 60, 60);

Box one = new Box(flowChart);
one.setBounds(10, 10, 15, 15);

Box two = new Box(flowChart);
two.setBounds(40, 10, 15, 15);

flowChart.addFlowChartListener(new FlowChartAdapter() {
@Override
public void itemModifying(ValidationEvent e) {
if (e.getItem() instanceof Box && e.getSelectionHandle() != 8) {

ItemList attachedItems = new ItemList();

for (Item item : ((Box) e.getItem()).getSubordinateGroup()
.getAttachedItems()) {
attachedItems.add(item);
}

for (Item item : attachedItems) {
((Box) item).detach();
((Box) item).cancelModify(item.getFlowChart().getInteraction());

for (Arrow arrow : ((Box) item).getOutgoingArrows()) {
arrow.cancelModify(item.getFlowChart().getInteraction());
}

for (Arrow arrow : ((Box) item).getIncomingArrows()) {
arrow.cancelModify(item.getFlowChart().getInteraction());
}
}
}
}
});

flowChart.add(three);
flowChart.add(one);
flowChart.add(two);

one.attachTo(three, AttachToNode.TopCenter);
two.attachTo(three, AttachToNode.TopCenter);
}
[/code]

But inspite of this, the arrow connecting the inner two boxes continues to move.

Maybe I have older version of the source code then? If so, can you send me the current version, so I can check against that?

Thanks,
Praveen
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: AttachToNode and detaching during modifying ev
Reply #5 - Nov 5th, 2007 at 10:17am
Print Post  
Hi Praveen,

I have sent you a PM containing the latest code.

Stoyan
  
Back to top
 
IP Logged
 
koosala
Full Member
***
Offline


Java Happens

Posts: 136
Joined: May 13th, 2007
Re: AttachToNode and detaching during modifying ev
Reply #6 - Nov 21st, 2007 at 3:06pm
Print Post  
Hi Stoyan,

I am sorry I have come back quite late after testing with the new source you gave me. Some other work held me up.

I still have the same problem. I have attached the code now where the arrow is also created during the initialization.

[code]
package research;

import javax.swing.JApplet;

import com.mindfusion.jdiagram.Arrow;
import com.mindfusion.jdiagram.AttachToNode;
import com.mindfusion.jdiagram.Box;
import com.mindfusion.jdiagram.FlowChart;
import com.mindfusion.jdiagram.FlowChartAdapter;
import com.mindfusion.jdiagram.Item;
import com.mindfusion.jdiagram.ItemList;
import com.mindfusion.jdiagram.ValidationEvent;

public class Goop extends JApplet {
private static final long serialVersionUID = 1L;

private FlowChart flowChart;

@Override
public void init() {
super.init();

flowChart = new FlowChart();
this.getContentPane().add(flowChart);

testContainment();
}

private void testContainment() {
Box three = new Box(flowChart);
three.setBounds(5, 5, 60, 60);

Box one = new Box(flowChart);
one.setBounds(10, 10, 15, 15);

Box two = new Box(flowChart);
two.setBounds(40, 10, 15, 15);

flowChart.addFlowChartListener(new FlowChartAdapter() {
@Override
public void itemModifying(ValidationEvent e) {
if (e.getItem() instanceof Box && e.getSelectionHandle() != 8) {

ItemList attachedItems = new ItemList();

for (Item item : ((Box) e.getItem()).getSubordinateGroup()
.getAttachedItems()) {
attachedItems.add(item);
}

for (Item item : attachedItems) {
((Box) item).detach();
((Box) item).cancelModify(item.getFlowChart().getInteraction());
}
}
}
});

flowChart.add(three);
flowChart.add(one);
flowChart.add(two);

Arrow arrow = new Arrow(flowChart, one, two);
flowChart.add(arrow);
one.attachTo(three, AttachToNode.TopCenter);
two.attachTo(three, AttachToNode.TopCenter);
}
}

[/code]

I hope you get the same error I do, so at least I know I am not doing something wrong somewhere.

Thanks,
Praveen
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: AttachToNode and detaching during modifying ev
Reply #7 - Nov 23rd, 2007 at 10:52am
Print Post  
Hi,

We could not reproduce the problem. Here is our test project:
https://mindfusion.org/_temp/TestApplet.zip

What should we do when the test page opens to see the problem?

Stoyan
  
Back to top
 
IP Logged
 
koosala
Full Member
***
Offline


Java Happens

Posts: 136
Joined: May 13th, 2007
Re: AttachToNode and detaching during modifying ev
Reply #8 - Nov 26th, 2007 at 4:42am
Print Post  
Hi Stoyan,

To get the problem I am talking about:


1. Select the bigger outer rectangle.
2. Drag the left border of this rectangle to the right.
You will now notice that the bigger rectangle is on the top.
3. Move the rectangle away. You will see that the arrow has moved to the right.

I have tried this out with the sample you have sent me now.

Thanks,
Praveen
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: AttachToNode and detaching during modifying ev
Reply #9 - Nov 26th, 2007 at 8:00am
Print Post  
Hi,

We have tried this only with the right and bottom resize handles. I can see the problem now with the left one.

The arrow moves because the Group keeps a list of Arrow objects that should be modified too when the whole group is moved. So apart from calling cancelModify, try to remove the affected arrows from the group's "arrowsToMove" list.

For the next release we will add code that removes the affected arrows when the detach() method is called.

Stoyan
  
Back to top
 
IP Logged
 
koosala
Full Member
***
Offline


Java Happens

Posts: 136
Joined: May 13th, 2007
Re: AttachToNode and detaching during modifying ev
Reply #10 - Jan 28th, 2008 at 2:09am
Print Post  
Hi,

Can you give me an approximate time I can see this change, or does 1.0.2 release have this fix already?

Thanks,
Praveen
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: AttachToNode and detaching during modifying ev
Reply #11 - Jan 28th, 2008 at 6:40am
Print Post  
Hi,

Since this is related only to your custom interaction code, our developers think it will be better to implement that there as well. Replace the loop that detaches boxes and removes them from the interaction list with the following:

Code
Select All
Group g = e.getItem().getSubordinateGroup();
for (Item item : attachedItems)
{
	Box box = (Box)item;

	for (Arrow a : box.getIncomingArrows())
		if (g.getArrowsToMove().contains(a))
			g.getArrowsToMove().remove(a);

	for (Arrow a : box.getOutgoingArrows())
		if (g.getArrowsToMove().contains(a))
			g.getArrowsToMove().remove(a);

	((Box) item).detach();
	((Box) item).cancelModify(item.getFlowChart().getInteraction());
}
fc.recreateCacheImage();
 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
koosala
Full Member
***
Offline


Java Happens

Posts: 136
Joined: May 13th, 2007
Re: AttachToNode and detaching during modifying ev
Reply #12 - Jan 31st, 2008 at 2:43am
Print Post  
Hi Stoyan,

That works very well.  Thanks.

I had to make

[code]
ItemList getAttachedItems()
[/code]

of Group public to get this done. Will your next release have this method as public?

Thanks,
Praveen
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: AttachToNode and detaching during modifying ev
Reply #13 - Jan 31st, 2008 at 6:24am
Print Post  
Hi Praveen,

Yes, it is going to be a public method.

Stoyan
  
Back to top
 
IP Logged
 
koosala
Full Member
***
Offline


Java Happens

Posts: 136
Joined: May 13th, 2007
Re: AttachToNode and detaching during modifying ev
Reply #14 - Apr 12th, 2008 at 4:27pm
Print Post  
Hi,

I am getting some other problems with this implementation. I have extended the example as shown below:

[code]
package research;

import java.awt.Color;

import javax.swing.JApplet;

import com.mindfusion.jdiagram.Arrow;
import com.mindfusion.jdiagram.AttachToNode;
import com.mindfusion.jdiagram.Box;
import com.mindfusion.jdiagram.FlowChart;
import com.mindfusion.jdiagram.FlowChartAdapter;
import com.mindfusion.jdiagram.Group;
import com.mindfusion.jdiagram.Item;
import com.mindfusion.jdiagram.ItemList;
import com.mindfusion.jdiagram.ShadowsStyle;
import com.mindfusion.jdiagram.SolidBrush;
import com.mindfusion.jdiagram.ValidationEvent;

public class Goop extends JApplet {
private static final long serialVersionUID = 1L;

private FlowChart flowChart;

@Override
public void init() {
super.init();

flowChart = new FlowChart();
flowChart.setSelectionOnTop(false);
flowChart.setBackBrush(new SolidBrush(Color.WHITE));
flowChart.setShadowsStyle(ShadowsStyle.None);
this.getContentPane().add(flowChart);

testContainment();
}

Box four, five;

private void testContainment() {
Box three = new Box(flowChart);
three.setBounds(5, 5, 90, 60);

Box one = new Box(flowChart);
one.setBounds(10, 10, 15, 15);

Box two = new Box(flowChart);
two.setBounds(40, 10, 15, 15);

four = new Box(flowChart);
four.setBounds(60, 10, 15, 15);

five = new Box(flowChart);
five.setBounds(160, 110, 15, 15);

flowChart.addFlowChartListener(new FlowChartAdapter() {
@Override
public void itemModifying(ValidationEvent e) {
if (e.getItem() instanceof Box && e.getSelectionHandle() != 8) {

ItemList attachedItems = new ItemList();

if (e.getItem().getSubordinateGroup() == null) {
return;
}

for (Item item : ((Box) e.getItem()).getSubordinateGroup()
.getAttachedItems()) {
attachedItems.add(item);
}

Group g = e.getItem().getSubordinateGroup();
for (Item item : attachedItems)
{
Box box = (Box)item;

if (box == four) {
continue;
}

for (Arrow a : box.getIncomingArrows())
if (g.getArrowsToMove().contains(a))
g.getArrowsToMove().remove(a);

for (Arrow a : box.getOutgoingArrows())
if (g.getArrowsToMove().contains(a))
g.getArrowsToMove().remove(a);

((Box) item).detach();
((Box) item).cancelModify(item.getFlowChart().getInteraction());
}
flowChart.recreateCacheImage();
}
}
});

flowChart.add(three);
flowChart.add(one);
flowChart.add(two);
flowChart.add(four);

flowChart.add(five);

Arrow arrow = new Arrow(flowChart, one, two);
flowChart.add(arrow);
one.attachTo(three, AttachToNode.TopCenter);
two.attachTo(three, AttachToNode.TopCenter);
four.attachTo(three, AttachToNode.TopCenter);
}
}

[/code]

Resize the biggest box (the one which contains the the three boxes).

The box to the bottom right disappears.

If I remove

[code]
flowChart.recreateCacheImage();
[/code]

the symbol stops disappearing.

Is that line really required, or can I lose it?
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint