However, what if you want to open multiple TopComponent at the same time whenever you open a file? There might be different views onto the same file, all provided by different TopComponents. In this case, I've discovered that you need to override the open() method in your OpenSupport class. Then you can open the TopComponents in one of two ways: if you want group behavior you will create a TopComponentGroup and then call open on the group, within the overridden open().
@Override
public void open() {
super.open();
TopComponentGroup group = WindowManager.getDefault().findTopComponentGroup("MyGroup");
if (group != null){
group.open();
}
}
Alternatively, just call open() on each of the TopComponents separately and then call active() on the TopComponent that should be active when the file is opened. Note that in this case the TopComponent must be a CloneableTopComponent, but that doesn't necessarily mean that the TopComponent will be cloneable, since only TopComponents in 'editor' modes are cloneable, never TopComponents in 'view' modes (i.e., there's no 'Clone Document' menu item on TopComponents in 'view' modes). Below, instead of creating a TopComponentGroup, I simply opened another TopComponent from the open() in the OpenSupport class:
And here's the OpenSupport class:
class DemoOpenSupport extends OpenSupport implements OpenCookie, CloseCookie {
TwoTopComponent tc;
String name;
public DemoOpenSupport(Entry primaryEntry) {
super(primaryEntry);
DemoDataObject dobj = (DemoDataObject) primaryEntry.getDataObject();
this.name = dobj.getName():
this.tc = new TwoTopComponent();
}
@Override
protected CloneableTopComponent createCloneableTopComponent() {
OneTopComponent tc = new OneTopComponent();
tc.setDisplayName(name);
return tc;
}
@Override
public void open() {
super.open();
tc.setDisplayName(name);
tc.open();
tc.requestActive();
}
}
How do you create a TopComponentGroup?
How do you register it under a specific name (e.g. "MyGroup", as you suggest)?