Editor Nullable

This commit is contained in:
Olof Larsson 2016-01-14 22:36:25 +01:00
parent 8034bf44c6
commit c37feb469e
6 changed files with 32 additions and 6 deletions

View File

@ -249,4 +249,10 @@ public class CommandEditAbstract<O, V> extends MassiveCommand
msg("%s<silver> for %s<silver>: %s", descProperty, descObject, descValue); msg("%s<silver> for %s<silver>: %s", descProperty, descObject, descValue);
} }
public void requireNullable() throws MassiveException
{
if (this.getProperty().isNullable()) return;
throw new MassiveException().addMsg("<h>%s<b> can not be null.", this.getPropertyName());
}
} }

View File

@ -15,8 +15,12 @@ public class CommandEditCollection<O, V extends Collection<?>> extends CommandEd
// Children // Children
this.addChild(new CommandEditShow<O, V>(settings, property)); this.addChild(new CommandEditShow<O, V>(settings, property));
if (property.isNullable())
{
this.addChild(new CommandEditCreate<O, V>(settings, property)); this.addChild(new CommandEditCreate<O, V>(settings, property));
this.addChild(new CommandEditDelete<O, V>(settings, property)); this.addChild(new CommandEditDelete<O, V>(settings, property));
}
this.addChild(new CommandEditCollectionAdd<O, V>(settings, property)); this.addChild(new CommandEditCollectionAdd<O, V>(settings, property));
this.addChild(new CommandEditCollectionInsert<O, V>(settings, property)); this.addChild(new CommandEditCollectionInsert<O, V>(settings, property));

View File

@ -17,8 +17,13 @@ public class CommandEditItemStacks<O> extends CommandEditAbstract<O, List<ItemSt
// Children // Children
this.addChild(new CommandEditShow<O, List<ItemStack>>(settings, property)); this.addChild(new CommandEditShow<O, List<ItemStack>>(settings, property));
if (property.isNullable())
{
this.addChild(new CommandEditCreate<O, List<ItemStack>>(settings, property)); this.addChild(new CommandEditCreate<O, List<ItemStack>>(settings, property));
this.addChild(new CommandEditDelete<O, List<ItemStack>>(settings, property)); this.addChild(new CommandEditDelete<O, List<ItemStack>>(settings, property));
}
this.addChild(new CommandEditItemStacksOpen<O>(settings, property)); this.addChild(new CommandEditItemStacksOpen<O>(settings, property));
} }

View File

@ -15,8 +15,12 @@ public class CommandEditMap<O, V extends Map<?, ?>> extends CommandEditAbstract<
// Children // Children
this.addChild(new CommandEditShow<O, V>(settings, property)); this.addChild(new CommandEditShow<O, V>(settings, property));
if (property.isNullable())
{
this.addChild(new CommandEditCreate<O, V>(settings, property)); this.addChild(new CommandEditCreate<O, V>(settings, property));
this.addChild(new CommandEditDelete<O, V>(settings, property)); this.addChild(new CommandEditDelete<O, V>(settings, property));
}
this.addChild(new CommandEditMapPut<O, V>(settings, property)); this.addChild(new CommandEditMapPut<O, V>(settings, property));
this.addChild(new CommandEditMapRemove<O, V>(settings, property)); this.addChild(new CommandEditMapRemove<O, V>(settings, property));

View File

@ -39,6 +39,9 @@ public class CommandEditSimple<O, V> extends CommandEditAbstract<O, V>
// Arguments // Arguments
V after = this.readArg(); V after = this.readArg();
// Validate
if (after == null) this.requireNullable();
// Apply // Apply
this.attemptSet(after); this.attemptSet(after);
} }

View File

@ -43,6 +43,10 @@ public abstract class Property<O, V> implements Named
public boolean isEditable() { return this.editable; } public boolean isEditable() { return this.editable; }
public void setEditable(boolean editable) { this.editable = editable; } public void setEditable(boolean editable) { this.editable = editable; }
protected boolean nullable = true;
public boolean isNullable() { return this.nullable; }
public void setNullable(boolean nullable) { this.nullable = nullable; }
// -------------------------------------------- // // -------------------------------------------- //
// NAME // NAME
// -------------------------------------------- // // -------------------------------------------- //