Search in sources :

Example 6 with AttributeRegistryElement

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

the class MAttributeController method performInsertRow.

@Override
public void performInsertRow(final NodeAttributeTableModel model, final int row, final String name, Object value) {
    final MapModel map = Controller.getCurrentModeController().getController().getMap();
    final AttributeRegistry attributes = AttributeRegistry.getRegistry(map);
    if (name.equals("")) {
        return;
    }
    try {
        final AttributeRegistryElement element = attributes.getElement(name);
        final int index = element.getValues().getIndexOf(value);
        if (index == -1) {
            if (element.isRestricted()) {
                value = element.getValues().firstElement().toString();
            } else {
                final IActor actor = new RegistryAttributeValueActor(element, value, false);
                Controller.getCurrentModeController().execute(actor, map);
            }
        }
    } catch (final NoSuchElementException ex) {
        final AttributeRegistry registry = AttributeRegistry.getRegistry(map);
        final IActor nameActor = new RegistryAttributeActor(name, false, false, registry, map);
        Controller.getCurrentModeController().execute(nameActor, map);
        final AttributeRegistryElement element = registry.getElement(name);
        final IActor valueActor = new RegistryAttributeValueActor(element, value, false);
        Controller.getCurrentModeController().execute(valueActor, map);
    }
    final Object newValue = value;
    final IActor actor = new InsertAttributeActor(model, row, name, newValue);
    Controller.getCurrentModeController().execute(actor, map);
}
Also used : 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 7 with AttributeRegistryElement

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

the class MAttributeController method performReplaceAtributeName.

@Override
public void performReplaceAtributeName(final String oldName, final String newName) {
    if (oldName.equals("") || newName.equals("") || oldName.equals(newName)) {
        return;
    }
    final MapModel map = Controller.getCurrentModeController().getController().getMap();
    final AttributeRegistry registry = AttributeRegistry.getRegistry(map);
    final int iOld = registry.getElements().indexOf(oldName);
    final AttributeRegistryElement oldElement = registry.getElement(iOld);
    final SortedComboBoxModel values = oldElement.getValues();
    final IActor registryActor = new RegistryAttributeActor(newName, oldElement.isManual(), oldElement.isVisible(), registry, map);
    Controller.getCurrentModeController().execute(registryActor, map);
    final AttributeRegistryElement newElement = registry.getElement(newName);
    for (int i = 0; i < values.getSize(); i++) {
        final IActor registryValueActor = new RegistryAttributeValueActor(newElement, values.getElementAt(i).toString(), false);
        Controller.getCurrentModeController().execute(registryValueActor, map);
    }
    final IVisitor replacer = new AttributeRenamer(oldName, newName);
    final Iterator iterator = new Iterator(replacer);
    ModeController modeController = Controller.getCurrentModeController();
    final NodeModel root = modeController.getMapController().getRootNode();
    iterator.iterate(root);
    final IActor unregistryActor = new UnregistryAttributeActor(oldName, registry, map);
    Controller.getCurrentModeController().execute(unregistryActor, map);
}
Also used : AttributeRegistryElement(org.freeplane.features.attribute.AttributeRegistryElement) MapModel(org.freeplane.features.map.MapModel) ModeController(org.freeplane.features.mode.ModeController) SortedComboBoxModel(org.freeplane.core.util.collection.SortedComboBoxModel) NodeModel(org.freeplane.features.map.NodeModel) AttributeRegistry(org.freeplane.features.attribute.AttributeRegistry) IActor(org.freeplane.core.undo.IActor)

Aggregations

AttributeRegistryElement (org.freeplane.features.attribute.AttributeRegistryElement)7 AttributeRegistry (org.freeplane.features.attribute.AttributeRegistry)6 MapModel (org.freeplane.features.map.MapModel)6 NoSuchElementException (java.util.NoSuchElementException)5 IActor (org.freeplane.core.undo.IActor)4 ComboBoxModel (javax.swing.ComboBoxModel)2 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 SortedComboBoxModel (org.freeplane.core.util.collection.SortedComboBoxModel)1 Attribute (org.freeplane.features.attribute.Attribute)1 ClonedComboBoxModel (org.freeplane.features.attribute.mindmapmode.AssignAttributeDialog.ClonedComboBoxModel)1 NodeModel (org.freeplane.features.map.NodeModel)1 ModeController (org.freeplane.features.mode.ModeController)1