Reading XML layout from file

Could you please provide some example how to use readXML from CControl?
I’m trying that:

  final JPanel sample = new JPanel();
  sample.add( new JButton( "no elo" ) );
  sample.setVisible( true );

  final CControl control = new CControl( frame );
  control.readXML( new File( "layout.xml" ) );
  final DefaultSingleCDockable dockable =
        new DefaultSingleCDockable( "sampleId", sample );
  control.addDockable( dockable );
  dockable.setVisible( true );

and the result is the IllegalStateException: unable to find valid target, no history available.

The layout.xml file was generated by writeXML when the location for this element was set by CLocation creating.

What am I missing?

You should try to first build/register your Dockables and CContentAreas, and read the file afterwards.

That way the identifiers written into the file can be matched to existing objects.

(There are some ways to read, process and even modify a file without creating any Dockables, it involves the “Perspectives-API” but is a complex solution for a problem that can be fixed easier).

It’s the same if I move control.readXML( new File( "layout.xml" ) ); on the bottom of given example.

What do you mean by build/register dockables and control areas? Haven’t I made it?

Could you please provide the simplest example, so I can work with it further? Or just take a look at mine and write what’s wrong with it.
From what I understand, I build and register them, but I guess I’m missing one or magic methods :wink:

Currently at work, can’t write any examples at the moment :wink:

Did you call „CControl.getContentArea“ anywhere before „readXml“? Because that call would create and register the missing „area“ that can lead to this kind of error.

1 Like

Yeah, me too :wink:

I played with it a little bit and it seems that getContentArea can be called after XML reading, while what was cause of my error was calling setVisible on dockable before reading XML.

Maybe silly mistake, but I expected something just like this :slight_smile:

Anyway, thanks a lot for you great help (and for the whole framework ;)).