public class ContentManagerEntityWriter implements ElementWriter<XMLWriter> {
public void write(XMLWriter writer, Context context) {
try {
// Start contentManager
MyDoggyToolWindowManager toolWindowManager = (MyDoggyToolWindowManager) context.get(ToolWindowManager.class);
ContentManager contentManager = context.get(ContentManager.class);
writer.startElement("contentManager");
writer.startElement("sharedWindows");
for (MultiSplitWindow<? extends Dockable> multiSplitWindow : SwingUtil.getContentWindows()) {
storeMultiSplitWindow(writer, multiSplitWindow);
}
writer.endElement("sharedWindows");
// write contents
writer.startElement("contents");
for (Content content : contentManager.getContents()) {
ContentUI contentUI = content.getContentUI();
// Prepare "content" element
AttributesImpl contentAttributes = new AttributesImpl();
contentAttributes.addAttribute(null, "id", null, null, content.getId());
contentAttributes.addAttribute(null, "detached", null, null, String.valueOf(content.isDetached()));
contentAttributes.addAttribute(null, "enabled", null, null, String.valueOf(content.isEnabled()));
contentAttributes.addAttribute(null, "selected", null, null, context.get(InternalPersistenceDelegateFilter.class).saveSelectedContent() ? String.valueOf(content.isSelected()) : "false");
contentAttributes.addAttribute(null, "maximized", null, null, String.valueOf(content.isMaximized()));
contentAttributes.addAttribute(null, "minimized", null, null, String.valueOf(content.isMinimized()));
contentAttributes.addAttribute(null, "flashing", null, null, String.valueOf(content.isFlashing()));
contentAttributes.addAttribute(null, "closeable", null, null, String.valueOf(contentUI.isCloseable()));
contentAttributes.addAttribute(null, "detachable", null, null, String.valueOf(contentUI.isDetachable()));
contentAttributes.addAttribute(null, "minimizable", null, null, String.valueOf(contentUI.isMinimizable()));
contentAttributes.addAttribute(null, "maximizable", null, null, String.valueOf(contentUI.isMaximizable()));
contentAttributes.addAttribute(null, "transparentMode", null, null, String.valueOf(contentUI.isTransparentMode()));
contentAttributes.addAttribute(null, "transparentDelay", null, null, String.valueOf(contentUI.getTransparentDelay()));
contentAttributes.addAttribute(null, "transparentRatio", null, null, String.valueOf(contentUI.getTransparentRatio()));
contentAttributes.addAttribute(null, "addToTaskBarWhenDetached", null, null, String.valueOf(contentUI.isAddToTaskBarWhenDetached()));
contentAttributes.addAttribute(null, "alwaysOnTop", null, null, String.valueOf(contentUI.isAlwaysOnTop()));
writer.startElement("content", contentAttributes);
// Prepare "detachedBounds" sub element if necessary
Rectangle detachedBounds = contentUI.getDetachedBounds();
if (detachedBounds != null) {
AttributesImpl attributes = new AttributesImpl();
attributes.addAttribute(null, "x", null, null, String.valueOf(detachedBounds.x));
attributes.addAttribute(null, "y", null, null, String.valueOf(detachedBounds.y));
attributes.addAttribute(null, "width", null, null, String.valueOf(detachedBounds.width));
attributes.addAttribute(null, "height", null, null, String.valueOf(detachedBounds.height));
writer.dataElement("detachedBounds", attributes);
}
// Prepare "minimizedState" sub element if necessary
if (content.isMinimized()) {
ContentDescriptor contentDescriptor = (ContentDescriptor) toolWindowManager.getDockableDescriptor(content.getId());
AttributesImpl attributes = new AttributesImpl();
attributes.addAttribute(null, "anchor", null, null, contentDescriptor.getAnchor().toString());
attributes.addAttribute(null, "anchorIndex", null, null, String.valueOf(contentDescriptor.getAnchorIndex()));
writer.dataElement("minimizedState", attributes);
}
writer.endElement("content");
}
writer.endElement("contents");
if (!contentManager.isEnabled()) {
MultiSplitDockableContainer dockableContainer = (MultiSplitDockableContainer) ((DockableDropPanel) toolWindowManager.getMainContent()).getComponent();
writer.startElement("layout");
ByteArrayOutputStream os = new ByteArrayOutputStream();
XMLEncoder encoder = new XMLEncoder(os);
encoder.writeObject(dockableContainer.getMultiSplitLayout());