Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The property changes for 0.12 caused the properties not save and reload. #237

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions docking-api/src/ModernDocking/Property.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,26 @@
// TODO might have to expose this to the applications
// TODO not sure how we go about converting to the right type without forcing separate calls
public abstract class Property {
private final String name;

public Property(String name) {

this.name = name;
}

public abstract Class<?> getType();

public abstract boolean isNull();

public String getName() {
return name;
}

public static class ByteProperty extends Property {
private final byte value;

public ByteProperty(byte value) {
public ByteProperty(String name, byte value) {
super(name);
this.value = value;
}

Expand All @@ -37,7 +49,8 @@ public byte getValue() {
public static class ShortProperty extends Property {
private final short value;

public ShortProperty(short value) {
public ShortProperty(String name, short value) {
super(name);
this.value = value;
}

Expand All @@ -64,7 +77,8 @@ public short getValue() {
public static class IntProperty extends Property {
private final int value;

public IntProperty(int value) {
public IntProperty(String name, int value) {
super(name);
this.value = value;
}

Expand All @@ -91,7 +105,8 @@ public int getValue() {
public static class LongProperty extends Property {
private final long value;

public LongProperty(long value) {
public LongProperty(String name, long value) {
super(name);
this.value = value;
}

Expand All @@ -118,7 +133,8 @@ public long getValue() {
public static class FloatProperty extends Property {
private final float value;

public FloatProperty(float value) {
public FloatProperty(String name, float value) {
super(name);
this.value = value;
}

Expand All @@ -145,7 +161,8 @@ public float getValue() {
public static class DoubleProperty extends Property {
private final double value;

public DoubleProperty(double value) {
public DoubleProperty(String name, double value) {
super(name);
this.value = value;
}

Expand All @@ -172,7 +189,8 @@ public double getValue() {
public static class CharacterProperty extends Property {
private final char value;

public CharacterProperty(char value) {
public CharacterProperty(String name, char value) {
super(name);
this.value = value;
}

Expand All @@ -199,7 +217,8 @@ public char getValue() {
public static class BooleanProperty extends Property {
private final boolean value;

public BooleanProperty(boolean value) {
public BooleanProperty(String name, boolean value) {
super(name);
this.value = value;
}

Expand All @@ -226,7 +245,8 @@ public boolean getValue() {
public static class StringProperty extends Property {
private final String value;

public StringProperty(String value) {
public StringProperty(String name, String value) {
super(name);
this.value = value;
}

Expand Down
127 changes: 96 additions & 31 deletions docking-api/src/ModernDocking/api/LayoutPersistenceAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,9 @@ private void writeSimpleNodeToFile(XMLStreamWriter writer, DockingSimplePanelNod

if (value != null && !value.isNull()) {
writer.writeStartElement("property");
writer.writeAttribute("name", value.toString());
writer.writeAttribute("type", value.getType().toString());
writer.writeAttribute("name", value.getName());
writer.writeAttribute("type", value.getType().getSimpleName());
writer.writeAttribute("value", value.toString());
writer.writeEndElement();
}
}
Expand Down Expand Up @@ -363,8 +364,9 @@ private void writeTabbedNodeToFile(XMLStreamWriter writer, DockingTabPanelNode n

if (value != null) {
writer.writeStartElement("property");
writer.writeAttribute("name", value.toString());
writer.writeAttribute("type", value.getType().toString());
writer.writeAttribute("name", value.getName());
writer.writeAttribute("type", value.getType().getSimpleName());
writer.writeAttribute("value", value.toString());
writer.writeEndElement();
}
}
Expand Down Expand Up @@ -505,39 +507,60 @@ private Map<String, Property> readProperties(XMLStreamReader reader) throws XMLS

if (next == XMLStreamConstants.START_ELEMENT) {
if (reader.getLocalName().equals("properties")) {
while (!(next == XMLStreamConstants.END_ELEMENT && reader.getLocalName().equals("properties"))) {
readProperty(reader);
next = reader.nextTag();
// old style of properties from before 0.12.0
if (reader.getAttributeCount() != 0) {
DockableProperties.setLoadingLegacyFile(true);

for (int i = 0; i < reader.getAttributeCount(); i++) {
Property prop = DockableProperties.parseProperty(reader.getAttributeLocalName(i), "String", reader.getAttributeValue(i));
properties.put(String.valueOf(reader.getAttributeName(i)), prop);
}
}
else {
DockableProperties.setLoadingLegacyFile(false);

while (reader.hasNext()) {
next = reader.nextTag();

if (next == XMLStreamConstants.START_ELEMENT && reader.getLocalName().equals("property")) {
String property = null;
String type = null;
String value = null;

for (int i = 0; i < reader.getAttributeCount(); i++) {
String attributeLocalName = reader.getAttributeLocalName(i);

switch (attributeLocalName) {
case "name":
property = reader.getAttributeValue(i);
break;
case "type":
type = reader.getAttributeValue(i);
break;
case "value":
value = reader.getAttributeValue(i);
break;
}
}
if (property != null && type != null && value != null) {
Property parsedProperty = DockableProperties.parseProperty(property, type, value);
properties.put(parsedProperty.getName(), parsedProperty);
}
}
else if (next == XMLStreamConstants.END_ELEMENT && reader.getLocalName().equals("properties")) {
break;
}
}
}
break;
// for (int i = 0; i < reader.getAttributeCount(); i++) {
// properties.put(String.valueOf(reader.getAttributeName(i)), readProperty(reader));
// }
}
}
else if (next == XMLStreamConstants.END_ELEMENT && reader.getLocalName().equals("properties")) {
if (next == XMLStreamConstants.END_ELEMENT && reader.getLocalName().equals("properties")) {
break;
}
}
return properties;
}

private Property readProperty(XMLStreamReader reader) throws XMLStreamException {
while (reader.hasNext()) {
int next = reader.nextTag();

if (next == XMLStreamConstants.START_ELEMENT) {
if (reader.getLocalName().equals("property")) {
// reader.getAttributeValue(i)
}
}
else if (next == XMLStreamConstants.END_ELEMENT && reader.getLocalName().equals("property")) {
break;
}
}
return null;
}

private DockingSplitPanelNode readSplitNodeFromFile(XMLStreamReader reader) throws XMLStreamException {
DockingLayoutNode left = null;
DockingLayoutNode right = null;
Expand Down Expand Up @@ -592,15 +615,57 @@ else if (next == XMLStreamConstants.START_ELEMENT && reader.getLocalName().equal
else if (next == XMLStreamConstants.START_ELEMENT && reader.getLocalName().equals("properties")) {
Map<String, Property> properties = new HashMap<>();

for (int i = 0; i < reader.getAttributeCount(); i++) {
// properties.put(String.valueOf(reader.getAttributeName(i)), reader.getAttributeValue(i));
// old style of properties from before 0.12.0
if (reader.getAttributeCount() != 0) {
DockableProperties.setLoadingLegacyFile(true);

for (int i = 0; i < reader.getAttributeCount(); i++) {
Property prop = DockableProperties.parseProperty(reader.getAttributeLocalName(i), "String", reader.getAttributeValue(i));
properties.put(String.valueOf(reader.getAttributeName(i)), prop);
}
}
else {
DockableProperties.setLoadingLegacyFile(false);

while (reader.hasNext()) {
next = reader.nextTag();

if (next == XMLStreamConstants.START_ELEMENT && reader.getLocalName().equals("property")) {
String property = null;
String type = null;
String value = null;

for (int i = 0; i < reader.getAttributeCount(); i++) {
String attributeLocalName = reader.getAttributeLocalName(i);

switch (attributeLocalName) {
case "name":
property = reader.getAttributeValue(i);
break;
case "type":
type = reader.getAttributeValue(i);
break;
case "value":
value = reader.getAttributeValue(i);
break;
}
}
if (property != null && type != null && value != null) {
Property parsedProperty = DockableProperties.parseProperty(property, type, value);
properties.put(parsedProperty.getName(), parsedProperty);
}
}
else if (next == XMLStreamConstants.END_ELEMENT && reader.getLocalName().equals("properties")) {
break;
}
}
}

if (node != null) {
node.setProperties(currentPersistentID, properties);
}
}
else if (next == XMLStreamConstants.END_ELEMENT && reader.getLocalName().equals("tabbed")) {
if (next == XMLStreamConstants.END_ELEMENT && reader.getLocalName().equals("tabbed")) {
break;
}
}
Expand Down
18 changes: 9 additions & 9 deletions docking-api/src/ModernDocking/api/WindowLayoutBuilderAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public WindowLayoutBuilderAPI display(String persistentID) {
public WindowLayoutBuilderAPI setProperty(String persistentID, String property, byte value) {
Map<String, Property> props = properties.getOrDefault(persistentID, new HashMap<>());

props.put(property, new Property.ByteProperty(value));
props.put(property, new Property.ByteProperty(property, value));

properties.put(persistentID, props);

Expand All @@ -125,7 +125,7 @@ public WindowLayoutBuilderAPI setProperty(String persistentID, String property,
public WindowLayoutBuilderAPI setProperty(String persistentID, String property, short value) {
Map<String, Property> props = properties.getOrDefault(persistentID, new HashMap<>());

props.put(property, new Property.ShortProperty(value));
props.put(property, new Property.ShortProperty(property, value));

properties.put(persistentID, props);

Expand All @@ -135,7 +135,7 @@ public WindowLayoutBuilderAPI setProperty(String persistentID, String property,
public WindowLayoutBuilderAPI setProperty(String persistentID, String property, int value) {
Map<String, Property> props = properties.getOrDefault(persistentID, new HashMap<>());

props.put(property, new Property.IntProperty(value));
props.put(property, new Property.IntProperty(property, value));

properties.put(persistentID, props);

Expand All @@ -145,7 +145,7 @@ public WindowLayoutBuilderAPI setProperty(String persistentID, String property,
public WindowLayoutBuilderAPI setProperty(String persistentID, String property, long value) {
Map<String, Property> props = properties.getOrDefault(persistentID, new HashMap<>());

props.put(property, new Property.LongProperty(value));
props.put(property, new Property.LongProperty(property, value));

properties.put(persistentID, props);

Expand All @@ -155,7 +155,7 @@ public WindowLayoutBuilderAPI setProperty(String persistentID, String property,
public WindowLayoutBuilderAPI setProperty(String persistentID, String property, float value) {
Map<String, Property> props = properties.getOrDefault(persistentID, new HashMap<>());

props.put(property, new Property.FloatProperty(value));
props.put(property, new Property.FloatProperty(property, value));

properties.put(persistentID, props);

Expand All @@ -165,7 +165,7 @@ public WindowLayoutBuilderAPI setProperty(String persistentID, String property,
public WindowLayoutBuilderAPI setProperty(String persistentID, String property, double value) {
Map<String, Property> props = properties.getOrDefault(persistentID, new HashMap<>());

props.put(property, new Property.DoubleProperty(value));
props.put(property, new Property.DoubleProperty(property, value));

properties.put(persistentID, props);

Expand All @@ -175,7 +175,7 @@ public WindowLayoutBuilderAPI setProperty(String persistentID, String property,
public WindowLayoutBuilderAPI setProperty(String persistentID, String property, char value) {
Map<String, Property> props = properties.getOrDefault(persistentID, new HashMap<>());

props.put(property, new Property.CharacterProperty(value));
props.put(property, new Property.CharacterProperty(property, value));

properties.put(persistentID, props);

Expand All @@ -185,7 +185,7 @@ public WindowLayoutBuilderAPI setProperty(String persistentID, String property,
public WindowLayoutBuilderAPI setProperty(String persistentID, String property, boolean value) {
Map<String, Property> props = properties.getOrDefault(persistentID, new HashMap<>());

props.put(property, new Property.BooleanProperty(value));
props.put(property, new Property.BooleanProperty(property, value));

properties.put(persistentID, props);

Expand All @@ -195,7 +195,7 @@ public WindowLayoutBuilderAPI setProperty(String persistentID, String property,
public WindowLayoutBuilderAPI setProperty(String persistentID, String property, String value) {
Map<String, Property> props = properties.getOrDefault(persistentID, new HashMap<>());

props.put(property, new Property.StringProperty(value));
props.put(property, new Property.StringProperty(property, value));

properties.put(persistentID, props);

Expand Down
Loading
Loading