I am using custom composite nodes set up as follows:
<?xml version="1.0" encoding="ISO-8859-1"?>
<SimplePanel>
<Shape Name="Shape" Shape="Rectangle" />
<Border Padding="2">
<StackPanel Orientation="Vertical" GridColumn="1">
<Text Name="Title" Font="Arial-12" TextAlignment="Centre" />
<Image Name="Image" />
<Text Name="NamesList" Font="Arial-10" TextAlignment="Centre" />
</StackPanel>
</Border>
</SimplePanel>
When I create the Node on the Diagram, I can change either of the text components or the image and the changes are immediately reflected on screen. This is true as long as the Diagram remains displayed.
If I close the Diagram (saving it as XML) then reload it, I can make changes and see the changes (via debugging) in the components of the custom composite node. However the changes are NOT reflected on screen or in the data subsequently saved to XML.
If I add a new custom composite node to the Diagram, I can see changes to the new custom composite node, but not to any that existed prior to the Diagram being loaded from XML.
Is there something I need to do to be able to show the changes made to the existing nodes on screen and in new saves to XML??
The code I use to load from XML (and match up to my application classes) is shown below. [Class names have been changed]
diagram = new Diagram();
diagram.setLinkHeadShape( ArrowHeads.Triangle );
diagram.setLinkHeadShapeSize( 10 );
diagram.setAdjustmentHandlesSize( 4 );
diagram.setBackBrush( new SolidBrush( Color.white ) );
diagram.setBackgroundImageAlign( ImageAlign.TopLeft );
diagram.setDynamicLinks( true );
diagram.setMeasureUnit( GraphicsUnit.Point );
diagram.setLinkShape( LinkShape.Bezier );
diagram.setAllowSelfLoops( false );
diagram.addDiagramListener( new DiagramAdapter()
{
@Override
public void nodeClicked( NodeEvent e )
{
onNodeClicked( e );
}
@Override
public void clicked( DiagramEvent e )
{
onClicked( e );
}
@Override
public void linkCreated( LinkEvent linkEvent )
{
onLinkCreated( linkEvent );
}
@Override
public void linkDeleted( LinkEvent linkEvent )
{
onLinkDeleted( linkEvent );
}
@Override
public void linkDoubleClicked( LinkEvent linkEvent )
{
onLinkDoubleClicked( linkEvent );
}
@Override
public void serializeTag( SerializeTagEvent serializeTagEvent )
{
onSerializeTag( serializeTagEvent );
}
@Override
public void deserializeTag( SerializeTagEvent serializeTagEvent )
{
onDeserializeTag( serializeTagEvent );
}
} );
diagramView = new DiagramView( diagram );
if (readOnly)
{
diagramView.setBehavior( Behavior.DoNothing );
}
else
{
diagramView.setBehavior( Behavior.LinkShapes );
}
diagramView.setDiagram( diagram );
diagramView.setInplaceEditFont( new Font( "Microsoft Sans Serif", Font.PLAIN, 12 ) );
diagramView.setModificationStart( ModificationStart.AutoHandles );
diagramView.getPrintOptions().setRenderTarget( RenderTarget.Printer );
// Enable serialization of CustomCompositeNode instances
Diagram.registerItemClass( CustomCompositeNode.class.getClass(), "CustomCompositeNode", 1 );
mainComponent.add( diagramView, BorderLayout.CENTER );
if (diagramHolder != null && diagramHolder.getXml() != null && !diagramHolder.getXml().isEmpty())
{
// load from xml found on diagramHolder
Diagram.registerItemClass( CustomCompositeNode.class, "CustomCompositeNode", 1 );
try
{
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
StringReader reader = new StringReader( diagramHolder.getXml() );
Document doc = builder.parse( new InputSource( reader ) );
diagram.loadFromXml( doc, false );
// match and update MyClasses
if (diagram.getNodes() != null && !diagram.getNodes().isEmpty())
{
for (DiagramNode node : diagram.getNodes())
{
if (node instanceof CustomCompositeNode)
{
CustomCompositeNode ccNode = (CustomCompositeNode) node;
MyClass classOnNode = ccNode.getMyClass();
MyClass match = matchMyClass( classOnNode, ccNode.getClassName(), ccNode.getClassId() );
if (match != null)
{
ccNode.setMyClass( match );
ccNode.updateNamesList(); // sets the text to the correct list of names derived from values in MyClass
}
}
}
}
// remove any previous selection - stops delete button working on 'readonly' diagrams
diagram.getSelection().clear();
diagram.repaint();
}
catch (SAXException se)
{
logger.error( "Failed to initialise diagram from XML", se );
}
catch (ParserConfigurationException pce)
{
logger.error( "Failed to initialise diagram from XML", pce );
}
catch (IOException e)
{
logger.error( "Failed to initialise diagram from XML", e );
}
catch (XmlException e)
{
logger.error( "Failed to initialise diagram from XML", e );
}
}