Proxy.AttributesROpublic static interface Proxy.Attributes extends Proxy.AttributesRO
node.attributes - read-write.
Notes on attribute setters:
node['creationDate'] = format(new Date(), 'MM/yyyy')
Examples:
// == text
node["attribute name"] = "a value"
assert node["attribute name"].text == "a value"
assert node.attributes.getFirst("attribute name") == "a value" // the same
// == numbers and others
// converts numbers and other stuff with toString()
node["a number"] = 1.2
assert node["a number"].text == "1.2"
assert node["a number"].num == 1.2d
* // == dates
def date = new Date()
node["a date"] = date
assert node["a date"].object.getClass().simpleName == "FormattedDate"
assert node["a date"].date == format(date)
// == enforce formats on attribute values
node["another date"] = format(date, 'yyyy|MM|dd')
assert node["another date"].date == format(date, 'yyyy|MM|dd')
// change the date while keeping the silly format
def index = node.attributes.findAttribute("another date")
node.attributes.set(index, new Date(0L))
// == URIs
def uri = new URI("http://www.freeplane.org")
node["uri"] = uri
assert node["uri"].object.getClass().simpleName == "URI"
assert node["uri"].object == uri
// == remove an attribute
node["removed attribute"] = "to be removed"
assert node["removed attribute"] == "to be removed"
node["removed attribute"] = null
assert node.attributes.findFirst("removed attribute") == -1
| Modifier and Type | Method | Description |
|---|---|---|
void |
add(String name,
Object value) |
adds an attribute no matter if an attribute with the given name already exists.
|
void |
add(String name,
Object value,
String format) |
adds an attribute with formatting pattern no matter if an attribute with the given name already exists.
|
void |
clear() |
removes all attributes.
|
Iterator<Map.Entry<String,Object>> |
iterator() |
allows application of Groovy collection methods like each(), collect(), ...
|
void |
optimizeWidths() |
optimize widths of attribute view columns according to contents.
|
void |
remove(int index) |
removes the attribute at the given index.
|
boolean |
remove(String name) |
Deprecated.
before 1.1 - use
remove(int) or removeAll(String) instead. |
boolean |
removeAll(String name) |
removes all attributes with this name.
|
void |
set(int index,
Object value) |
sets the value of the attribute at an index.
|
void |
set(int index,
String name,
Object value) |
sets name and value of the attribute at the given index.
|
void |
set(int index,
String name,
Object value,
String format) |
sets name, value and format pattern of the attribute at the given index.
|
void |
set(String name,
Object value) |
adds an attribute if there is no attribute with the given name or changes
the value of the first attribute with the given name.
|
void |
setFormat(int index,
String format) |
sets format pattern to the attribute at the given index.
|
containsKey, findAttribute, findFirst, findValues, get, get, getAll, getAttributeNames, getFirst, getKey, getMap, getNames, getValues, isEmpty, sizevoid set(int index,
Object value)
IndexOutOfBoundsException - if index is out of range, i. e. index < 0 || index >= size().void set(int index,
String name,
Object value)
IndexOutOfBoundsException - if index is out of range, i. e. index < 0 || index >= size().void set(int index,
String name,
Object value,
String format)
IndexOutOfBoundsException - if index is out of range, i. e. index < 0 || index >= size().void setFormat(int index,
String format)
IndexOutOfBoundsException - if index is out of range, i. e. index < 0 || index >= size().@Deprecated boolean remove(String name)
remove(int) or removeAll(String) instead.boolean removeAll(String name)
void remove(int index)
IndexOutOfBoundsException - if index is out of range, i. e. index < 0 || index >= size().void set(String name, Object value)
void add(String name, Object value)
void add(String name, Object value, String format)
void clear()
Iterator<Map.Entry<String,Object>> iterator()
def keyList = node.attributes.collect { it.key }
def values = node.attributes.collect { it.value }
node.attributes.each {
if (it.key =~ /.*day/)
it.value += ' days'
}
void optimizeWidths()