Search in sources :

Example 16 with Attribute

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

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

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

the class AttributesProxy method add.

public void add(final String name, final Object value) {
    final Attribute attribute = new Attribute(name, ProxyUtils.transformObject(value, null));
    getAttributeController().addAttribute(getDelegate(), attribute);
}
Also used : Attribute(org.freeplane.features.attribute.Attribute)

Example 19 with Attribute

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

the class ScriptEditor method actionPerformed.

public void actionPerformed(final ActionEvent e) {
    final ModeController modeController = Controller.getCurrentModeController();
    final NodeModel node = modeController.getMapController().getSelectedNode();
    final ArrayList<AttributeHolder> scripts = new ArrayList<AttributeHolder>();
    for (int position = 0; position < NodeAttributeTableModel.getModel(node).getAttributeTableLength(); position++) {
        final Attribute attribute = NodeAttributeTableModel.getModel(node).getAttribute(position);
        if (attribute.getName().startsWith(ScriptingEngine.SCRIPT_PREFIX)) {
            scripts.add(new AttributeHolder(new Attribute(attribute), position));
        }
    }
    final NodeScriptModel nodeScriptModel = new NodeScriptModel(scripts, node);
    final ScriptEditorPanel scriptEditorPanel = new ScriptEditorPanel(nodeScriptModel, true);
    scriptEditorPanel.setVisible(true);
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) Attribute(org.freeplane.features.attribute.Attribute) ArrayList(java.util.ArrayList) ModeController(org.freeplane.features.mode.ModeController)

Example 20 with Attribute

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

the class AddStyleAttributes method pasteAttributes.

/**
 */
private void pasteAttributes(final NodeModel node) {
    Object[] attributes = CopyAttributes.getAttributes();
    if (attributes == null) {
        JOptionPane.showMessageDialog(Controller.getCurrentController().getViewController().getContentPane(), TextUtils.getText("no_copy_attributes_before_paste_attributes"), "", /*=Title*/
        JOptionPane.ERROR_MESSAGE);
        return;
    }
    final MAttributeController controller = MAttributeController.getController();
    for (int i = 0; i < attributes.length; ) {
        final String name = attributes[i++].toString();
        final Object value = attributes[i++];
        controller.addAttribute(node, new Attribute(name, value));
    }
}
Also used : Attribute(org.freeplane.features.attribute.Attribute)

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