Search in sources :

Example 6 with NodeAttributeTableModel

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

the class HyperLinkCondition method checkNode.

public boolean checkNode(final NodeModel node) {
    final URI nodeLink = NodeLinks.getValidLink(node);
    if (nodeLink != null && checkLink(nodeLink))
        return true;
    final NodeAttributeTableModel attributes = NodeAttributeTableModel.getModel(node);
    if (attributes == null) {
        return false;
    }
    final int rowCount = attributes.getRowCount();
    for (int i = 0; i < rowCount; i++) {
        final Attribute attribute = attributes.getAttribute(i);
        final Object value = attribute.getValue();
        if (value instanceof URI && checkLink((URI) value))
            return true;
    }
    return false;
}
Also used : Attribute(org.freeplane.features.attribute.Attribute) NodeAttributeTableModel(org.freeplane.features.attribute.NodeAttributeTableModel) URI(java.net.URI)

Example 7 with NodeAttributeTableModel

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

the class ScriptingEngine method performScriptOperation.

static void performScriptOperation(final NodeModel node) {
    final NodeAttributeTableModel attributes = NodeAttributeTableModel.getModel(node);
    if (attributes == null) {
        return;
    }
    for (int row = 0; row < attributes.getRowCount(); ++row) {
        final String attrKey = (String) attributes.getName(row);
        final Object value = attributes.getValue(row);
        if (value instanceof String) {
            final String script = (String) value;
            if (attrKey.startsWith(ScriptingEngine.SCRIPT_PREFIX)) {
                executeScript(node, script);
            }
        }
    }
    return;
}
Also used : NodeAttributeTableModel(org.freeplane.features.attribute.NodeAttributeTableModel)

Example 8 with NodeAttributeTableModel

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

the class AttributesProxy method getNames.

public List<String> getNames() {
    final NodeAttributeTableModel attributeTableModel = getNodeAttributeTableModel();
    if (attributeTableModel == null) {
        return Collections.emptyList();
    }
    final ArrayList<String> result = new ArrayList<String>(attributeTableModel.getRowCount());
    for (final Attribute a : attributeTableModel.getAttributes()) {
        result.add(a.getName());
    }
    return result;
}
Also used : Attribute(org.freeplane.features.attribute.Attribute) NodeAttributeTableModel(org.freeplane.features.attribute.NodeAttributeTableModel) ArrayList(java.util.ArrayList)

Example 9 with NodeAttributeTableModel

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

the class AttributesProxy method iterator.

@SuppressWarnings("unchecked")
public Iterator<Map.Entry<String, Object>> iterator() {
    final NodeAttributeTableModel attributeTableModel = getNodeAttributeTableModel();
    if (attributeTableModel == null) {
        return (Iterator<Map.Entry<String, Object>>) (Object) Collections.emptyMap().entrySet().iterator();
    }
    return new Iterator<Map.Entry<String, Object>>() {

        private final Iterator<Attribute> iterator = attributeTableModel.getAttributes().iterator();

        @Override
        public boolean hasNext() {
            return iterator.hasNext();
        }

        @Override
        public Map.Entry<String, Object> next() {
            final Attribute attribute = iterator.next();
            return new Map.Entry<String, Object>() {

                @Override
                public String getKey() {
                    return attribute.getName();
                }

                @Override
                public Object getValue() {
                    return attribute.getValue();
                }

                @Override
                public Object setValue(Object value) {
                    final Object oldValue = attribute.getValue();
                    attribute.setValue(value);
                    return oldValue;
                }
            };
        }

        @Override
        public void remove() {
            iterator.remove();
        }
    };
}
Also used : Attribute(org.freeplane.features.attribute.Attribute) NodeAttributeTableModel(org.freeplane.features.attribute.NodeAttributeTableModel) Iterator(java.util.Iterator) IFormattedObject(org.freeplane.features.format.IFormattedObject) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 10 with NodeAttributeTableModel

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

the class AttributesProxy method removeAll.

public boolean removeAll(final String name) {
    final NodeAttributeTableModel attributeTableModel = getNodeAttributeTableModel();
    if (attributeTableModel == null) {
        return false;
    }
    final ArrayList<Integer> toRemove = new ArrayList<Integer>();
    final Vector<Attribute> attributes = attributeTableModel.getAttributes();
    for (int i = 0; i < attributes.size(); ++i) {
        if (attributes.get(i).getName().equals(name)) {
            toRemove.add(i);
        }
    }
    // do it backwards in order not to invalidate the first indexes
    for (int i = toRemove.size() - 1; i >= 0; --i) {
        getAttributeController().removeAttribute(getDelegate(), toRemove.get(i));
    }
    return !toRemove.isEmpty();
}
Also used : Attribute(org.freeplane.features.attribute.Attribute) NodeAttributeTableModel(org.freeplane.features.attribute.NodeAttributeTableModel) ArrayList(java.util.ArrayList)

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