Search in sources :

Example 21 with NodeAttributeTableModel

use of org.freeplane.features.attribute.NodeAttributeTableModel in project freeplane by freeplane.

the class AttributesProxy method getMap.

public Map<String, Object> getMap() {
    final NodeAttributeTableModel attributeTableModel = getNodeAttributeTableModel();
    if (attributeTableModel == null) {
        return Collections.emptyMap();
    }
    final LinkedHashMap<String, Object> result = new LinkedHashMap<String, Object>(attributeTableModel.getRowCount());
    for (final Attribute a : attributeTableModel.getAttributes()) {
        result.put(a.getName(), a.getValue());
    }
    return result;
}
Also used : Attribute(org.freeplane.features.attribute.Attribute) NodeAttributeTableModel(org.freeplane.features.attribute.NodeAttributeTableModel) IFormattedObject(org.freeplane.features.format.IFormattedObject) LinkedHashMap(java.util.LinkedHashMap)

Example 22 with NodeAttributeTableModel

use of org.freeplane.features.attribute.NodeAttributeTableModel in project freeplane by freeplane.

the class AttributesProxy method getValues.

public List<? extends Convertible> getValues() {
    final NodeAttributeTableModel attributeTableModel = getNodeAttributeTableModel();
    if (attributeTableModel == null) {
        return Collections.emptyList();
    }
    final ArrayList<Convertible> result = new ArrayList<Convertible>(attributeTableModel.getRowCount());
    for (final Attribute a : attributeTableModel.getAttributes()) {
        result.add(ProxyUtils.attributeValueToConvertible(getDelegate(), getScriptContext(), a.getValue()));
    }
    return result;
}
Also used : Attribute(org.freeplane.features.attribute.Attribute) NodeAttributeTableModel(org.freeplane.features.attribute.NodeAttributeTableModel) ArrayList(java.util.ArrayList)

Example 23 with NodeAttributeTableModel

use of org.freeplane.features.attribute.NodeAttributeTableModel in project freeplane by freeplane.

the class AttributesProxy method findValues.

public List<? extends Convertible> findValues(Closure<Boolean> closure) {
    try {
        final NodeAttributeTableModel attributeTableModel = getNodeAttributeTableModel();
        if (attributeTableModel == null) {
            return Collections.emptyList();
        }
        final ArrayList<Convertible> result = new ArrayList<Convertible>(attributeTableModel.getRowCount());
        for (final Attribute a : attributeTableModel.getAttributes()) {
            final Object bool = closure.call(new Object[] { a.getName(), a.getValue() });
            if (result == null) {
                throw new RuntimeException("findValues(): closure returned null instead of boolean/Boolean");
            }
            if ((Boolean) bool)
                result.add(ProxyUtils.attributeValueToConvertible(getDelegate(), getScriptContext(), a.getValue()));
        }
        return result;
    } catch (final MissingMethodException e) {
        throw new RuntimeException("findValues(): closure needs to accept two args and must return boolean/Boolean" + " e.g. findValues{k,v -> k != 'TOTAL'}", e);
    } catch (final ClassCastException e) {
        throw new RuntimeException("findValues(): closure returned " + e.getMessage() + " instead of boolean/Boolean");
    }
}
Also used : MissingMethodException(groovy.lang.MissingMethodException) Attribute(org.freeplane.features.attribute.Attribute) NodeAttributeTableModel(org.freeplane.features.attribute.NodeAttributeTableModel) ArrayList(java.util.ArrayList) IFormattedObject(org.freeplane.features.format.IFormattedObject)

Example 24 with NodeAttributeTableModel

use of org.freeplane.features.attribute.NodeAttributeTableModel in project freeplane by freeplane.

the class AttributesProxy method clear.

public void clear() {
    final NodeAttributeTableModel attributeTableModel = getNodeAttributeTableModel();
    final int size = attributeTableModel.getRowCount();
    for (int i = size - 1; i >= 0; i--) {
        getAttributeController().removeAttribute(getDelegate(), i);
    }
}
Also used : NodeAttributeTableModel(org.freeplane.features.attribute.NodeAttributeTableModel)

Example 25 with NodeAttributeTableModel

use of org.freeplane.features.attribute.NodeAttributeTableModel in project freeplane by freeplane.

the class AddStyleAttributes method setEnabled.

@Override
public void setEnabled() {
    final NodeModel node = Controller.getCurrentModeController().getMapController().getSelectedNode();
    if (node != null) {
        final NodeAttributeTableModel model = NodeAttributeTableModel.getModel(node);
        setEnabled(model != null && model.getAttributeTableLength() > 0);
    } else
        setEnabled(false);
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) NodeAttributeTableModel(org.freeplane.features.attribute.NodeAttributeTableModel)

Aggregations

NodeAttributeTableModel (org.freeplane.features.attribute.NodeAttributeTableModel)25 Attribute (org.freeplane.features.attribute.Attribute)12 ArrayList (java.util.ArrayList)5 IFormattedObject (org.freeplane.features.format.IFormattedObject)5 NodeModel (org.freeplane.features.map.NodeModel)3 LinkedHashMap (java.util.LinkedHashMap)2 MissingMethodException (groovy.lang.MissingMethodException)1 URI (java.net.URI)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1