Search in sources :

Example 6 with AttributeRegistry

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

the class MAttributeController method performReplaceAttributeValue.

@Override
public void performReplaceAttributeValue(final String name, final String oldValue, final String newValue) {
    Controller controller = Controller.getCurrentController();
    final MapModel map = controller.getMap();
    ModeController modeController = controller.getModeController();
    final AttributeRegistry registry = AttributeRegistry.getRegistry(map);
    final IActor actor = new ReplaceAttributeValueActor(registry, name, oldValue, newValue);
    Controller.getCurrentModeController().execute(actor, map);
    final IVisitor replacer = new AttributeChanger(name, oldValue, newValue);
    final Iterator iterator = new Iterator(replacer);
    final NodeModel root = modeController.getMapController().getRootNode();
    iterator.iterate(root);
}
Also used : NodeModel(org.freeplane.features.map.NodeModel) AttributeRegistry(org.freeplane.features.attribute.AttributeRegistry) IActor(org.freeplane.core.undo.IActor) MapModel(org.freeplane.features.map.MapModel) ModeController(org.freeplane.features.mode.ModeController) AttributeController(org.freeplane.features.attribute.AttributeController) Controller(org.freeplane.features.mode.Controller) ModeController(org.freeplane.features.mode.ModeController)

Example 7 with AttributeRegistry

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

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

the class AddAttributeAction method selectedAttributeChanged.

protected void selectedAttributeChanged(final Object selectedAttributeName, final JComboBox values) {
    final MapModel map = Controller.getCurrentController().getMap();
    final AttributeRegistry attributes = AttributeRegistry.getRegistry(map);
    try {
        final AttributeRegistryElement element = attributes.getElement(selectedAttributeName.toString());
        final ComboBoxModel selectedValues = element.getValues();
        values.setModel(new ClonedComboBoxModel(selectedValues));
        try {
            final Object firstValue = selectedValues.getElementAt(0);
            values.setSelectedItem(firstValue);
        } catch (final ArrayIndexOutOfBoundsException ex) {
        }
        values.setEditable(!element.isRestricted());
    } catch (final NoSuchElementException ex) {
        values.setEditable(!selectedAttributeName.toString().equals(""));
    }
}
Also used : AttributeRegistry(org.freeplane.features.attribute.AttributeRegistry) AttributeRegistryElement(org.freeplane.features.attribute.AttributeRegistryElement) MapModel(org.freeplane.features.map.MapModel) ClonedComboBoxModel(org.freeplane.features.attribute.mindmapmode.AssignAttributeDialog.ClonedComboBoxModel) ClonedComboBoxModel(org.freeplane.features.attribute.mindmapmode.AssignAttributeDialog.ClonedComboBoxModel) ComboBoxModel(javax.swing.ComboBoxModel) NoSuchElementException(java.util.NoSuchElementException)

Example 9 with AttributeRegistry

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

the class AssignAttributeDialog method afterMapChange.

public void afterMapChange(final MapModel oldMap, final MapModel newMap) {
    if (oldMap != null) {
        final AttributeRegistry attributes = AttributeRegistry.getRegistry(oldMap);
        if (attributes != null) {
            attributes.removeAttributesListener(this);
        }
    }
    if (newMap == null) {
        setVisible(false);
        return;
    }
    mapSelection = Controller.getCurrentController().getSelection();
    final AttributeRegistry attributes = AttributeRegistry.getRegistry(newMap);
    if (attributes == null) {
        setVisible(false);
        return;
    }
    attributes.addAttributesListener(this);
    attributesChanged();
}
Also used : AttributeRegistry(org.freeplane.features.attribute.AttributeRegistry)

Example 10 with AttributeRegistry

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

the class AssignAttributeDialog method selectedAttributeChanged.

private void selectedAttributeChanged(final Object selectedAttributeName, final JComboBox values) {
    final MapModel map = Controller.getCurrentController().getMap();
    final AttributeRegistry attributes = AttributeRegistry.getRegistry(map);
    try {
        final AttributeRegistryElement element = attributes.getElement(selectedAttributeName.toString());
        final ComboBoxModel selectedValues = element.getValues();
        values.setModel(new ClonedComboBoxModel(selectedValues));
        try {
            final Object firstValue = selectedValues.getElementAt(0);
            values.setSelectedItem(firstValue);
        } catch (final ArrayIndexOutOfBoundsException ex) {
        }
        values.setEditable(!element.isRestricted());
    } catch (final NoSuchElementException ex) {
        values.setEditable(!selectedAttributeName.toString().equals(""));
    }
}
Also used : AttributeRegistry(org.freeplane.features.attribute.AttributeRegistry) AttributeRegistryElement(org.freeplane.features.attribute.AttributeRegistryElement) MapModel(org.freeplane.features.map.MapModel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) ComboBoxModel(javax.swing.ComboBoxModel) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

AttributeRegistry (org.freeplane.features.attribute.AttributeRegistry)19 MapModel (org.freeplane.features.map.MapModel)17 IActor (org.freeplane.core.undo.IActor)13 NodeModel (org.freeplane.features.map.NodeModel)7 NoSuchElementException (java.util.NoSuchElementException)6 AttributeRegistryElement (org.freeplane.features.attribute.AttributeRegistryElement)6 ModeController (org.freeplane.features.mode.ModeController)6 ComboBoxModel (javax.swing.ComboBoxModel)5 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)3 JComboBox (javax.swing.JComboBox)2 AttributeController (org.freeplane.features.attribute.AttributeController)2 ClonedComboBoxModel (org.freeplane.features.attribute.mindmapmode.AssignAttributeDialog.ClonedComboBoxModel)2 Controller (org.freeplane.features.mode.Controller)2 Component (java.awt.Component)1 Dimension (java.awt.Dimension)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 HierarchyEvent (java.awt.event.HierarchyEvent)1 HierarchyListener (java.awt.event.HierarchyListener)1