Hello,
I’m a new user of DockingFrames and I try to write my new program.
I create two SingleCDockable in the left side of my Frame (one on top, one on bottom) and a WorkingArea in the center of my application.In this workingArea my program opens many frames with the functionality of the program (view report, save data, etc…).
I read the common documentation and I understood that the best way to do that is to use MultipleCDockable but i’m not understand which is the function of MultipleCDockableFactory. Is it mandatory its use? Can I create my application without this?
If you are using MultipleCDocables then you have to implement MultipleCDockableFactories, the framework will not allow you to show a dockable without a factory.
In your case you may have something like “ViewReportDockable” (which extends “DefaultMultipleCDockable”), and the user can view several reports at the same time (otherwise there is no point in using a MultipleCDockable). Each ViewReportDockable shows a report (obviously) identified for example by some path (to the report-file).
When the user closes the application the framework stores the location and content of each Dockable such that the user can continue working when he reopens the application (assuming you use the methods CControl.read/write). Your ViewReportDockableFactory will be used to store the file-path of the record that is shown on a ViewReportDockable. The factories might look like the one I’ve attached to this post.
If you don’t need the factory (e.g. because on startup your application never shows reports) you can implement an “empty” factory: its “read” method returns null, and the MultipleCDockableLayout just does not have any fields and empty methods.
public ViewReportDockableLayout create(){
return new ViewReportDockableLayout();
}
public boolean match( ViewReportDockable dockable, ViewReportDockableLayout layout ){
return layout.getReportPath().equals( dockable.getReportPath() );
}
public ViewReportDockable read( ViewReportDockableLayout layout ){
try{
return new ViewReportDockable( layout.getReportPath() );
}
catch( IOException e ){
// can't read the file
return null;
}
}
public ViewReportDockableLayout write( ViewReportDockable dockable ){
ViewReportDockableLayout result = new ViewReportDockableLayout();
result.setReportPath( dockable.getReportPath() );
return result;
}
}
public class ViewReportDockableLayout implements MultipleCDockableLayout{
private String reportPath;
public void setReportPath( String reportPath ){
this.reportPath = reportPath;
}
public String getReportPath(){
return reportPath;
}
public void readStream( DataInputStream in ) throws IOException{
reportPath = in.readUTF();
}
public void readXML( XElement element ){
reportPath = element.getElement( "report" ).getString();
}
public void writeStream( DataOutputStream out ) throws IOException{
out.writeUTF( reportPath );
}
public void writeXML( XElement element ){
element.addElement( "report" ).setString( reportPath );
}
}```
Thanks a lot Beni,
now I understand
But I have another question: if my application don’t load any file from pc but only manage data from database and view java object which Dockable should I use? SingleDockable or MultiDockable?
I’d still use MultipleCDockable, that way the user can show/manage multiple queries at the same time. As I said: noone forces you to have a factory that actually stores something. If you don’t want to store your data/queries/whatever persistently then just use a factory that does not create Dockables.