Search in sources :

Example 1 with Attribute

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

the class MAttributeController method performSetValueAt.

@Override
public void performSetValueAt(final NodeAttributeTableModel model, final Object o, final int row, final int col) {
    final Attribute attribute = model.getAttribute(row);
    final MapModel map = model.getNode().getMap();
    final AttributeRegistry registry = AttributeRegistry.getRegistry(map);
    switch(col) {
        case 0:
            {
                final String name = o.toString().trim();
                final String oldName = attribute.getName();
                if (oldName.equals(name)) {
                    return;
                }
                final IActor nameActor = new SetAttributeNameActor(model, name, oldName, row);
                Controller.getCurrentModeController().execute(nameActor, map);
                try {
                    final AttributeRegistryElement element = registry.getElement(name);
                    final String value = model.getValueAt(row, 1).toString();
                    final int index = element.getValues().getIndexOf(value);
                    if (index == -1) {
                        final IActor valueActor = new SetAttributeValueActor(model, row, element.getValues().firstElement());
                        Controller.getCurrentModeController().execute(valueActor, map);
                    }
                } catch (final NoSuchElementException ex) {
                    final IActor registryActor = new RegistryAttributeActor(name, false, false, registry, map);
                    Controller.getCurrentModeController().execute(registryActor, map);
                }
                break;
            }
        case 1:
            {
                if (attribute.getValue().equals(o)) {
                    return;
                }
                final IActor actor = new SetAttributeValueActor(model, row, o);
                Controller.getCurrentModeController().execute(actor, map);
                final String name = model.getValueAt(row, 0).toString();
                final AttributeRegistryElement element = registry.getElement(name);
                final int index = element.getValues().getIndexOf(o);
                if (index == -1) {
                    final IActor registryActor = new RegistryAttributeValueActor(element, o, false);
                    Controller.getCurrentModeController().execute(registryActor, map);
                }
                break;
            }
    }
}
Also used : Attribute(org.freeplane.features.attribute.Attribute) AttributeRegistry(org.freeplane.features.attribute.AttributeRegistry) AttributeRegistryElement(org.freeplane.features.attribute.AttributeRegistryElement) IActor(org.freeplane.core.undo.IActor) MapModel(org.freeplane.features.map.MapModel) NoSuchElementException(java.util.NoSuchElementException)

Example 2 with Attribute

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

the class MAttributeController method editAttribute.

public int editAttribute(final NodeModel pNode, final String pName, final String pNewValue) {
    createAttributeTableModel(pNode);
    final Attribute newAttribute = new Attribute(pName, pNewValue);
    final NodeAttributeTableModel attributes = NodeAttributeTableModel.getModel(pNode);
    for (int i = 0; i < attributes.getRowCount(); i++) {
        if (pName.equals(attributes.getAttribute(i).getName())) {
            if (pNewValue != null) {
                setAttribute(pNode, i, newAttribute);
            } else {
                removeAttribute(pNode, i);
            }
            return i;
        }
    }
    if (pNewValue == null) {
        return -1;
    }
    return addAttribute(pNode, newAttribute);
}
Also used : Attribute(org.freeplane.features.attribute.Attribute) NodeAttributeTableModel(org.freeplane.features.attribute.NodeAttributeTableModel)

Example 3 with Attribute

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

the class MAttributeController method performRemoveRow.

@Override
public Attribute performRemoveRow(final NodeAttributeTableModel model, final int row) {
    final Vector<Attribute> attributes = model.getAttributes();
    final Object o = attributes.elementAt(row);
    final IActor actor = new RemoveAttributeActor(model, row);
    Controller.getCurrentModeController().execute(actor, model.getNode().getMap());
    return (Attribute) o;
}
Also used : Attribute(org.freeplane.features.attribute.Attribute) IActor(org.freeplane.core.undo.IActor)

Example 4 with Attribute

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

the class AddStyleAttributes method copyAttributes.

/**
 */
private void copyAttributes(final NodeModel node) {
    final NodeAttributeTableModel model = NodeAttributeTableModel.getModel(node);
    if (model == null) {
        attributes = null;
        return;
    }
    final int attributeTableLength = model.getAttributeTableLength();
    attributes = new Object[attributeTableLength * 2];
    for (int i = 0; i < attributeTableLength; i++) {
        final Attribute attribute = model.getAttribute(i);
        attributes[2 * i] = attribute.getName();
        attributes[2 * i + 1] = attribute.getValue();
    }
}
Also used : Attribute(org.freeplane.features.attribute.Attribute) NodeAttributeTableModel(org.freeplane.features.attribute.NodeAttributeTableModel)

Example 5 with Attribute

use of org.freeplane.features.attribute.Attribute 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)

Aggregations

Attribute (org.freeplane.features.attribute.Attribute)20 NodeAttributeTableModel (org.freeplane.features.attribute.NodeAttributeTableModel)12 ArrayList (java.util.ArrayList)6 IFormattedObject (org.freeplane.features.format.IFormattedObject)4 LinkedHashMap (java.util.LinkedHashMap)2 IActor (org.freeplane.core.undo.IActor)2 MissingMethodException (groovy.lang.MissingMethodException)1 URI (java.net.URI)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1 AttributeRegistry (org.freeplane.features.attribute.AttributeRegistry)1 AttributeRegistryElement (org.freeplane.features.attribute.AttributeRegistryElement)1 MapModel (org.freeplane.features.map.MapModel)1 NodeModel (org.freeplane.features.map.NodeModel)1 ModeController (org.freeplane.features.mode.ModeController)1