Search in sources :

Example 1 with HierarchicalPersistent

use of com.ramussoft.core.attribute.simple.HierarchicalPersistent in project ramus by Vitaliy-Yakovchuk.

the class QualifierView method moveElements.

private void moveElements(Row row, long parentElementId, long prevParentId, Qualifier dest) {
    long qualifierId = StandardAttributesPlugin.getQualifierId(engine, row.getElement());
    framework.propertyChanged("CloseQualifier", qualifierId);
    Attribute hAttribute = StandardAttributesPlugin.getHierarchicalAttribute(engine);
    List<Element> elements = engine.getElements(qualifierId);
    for (Element element : elements) {
        engine.setElementQualifier(element.getId(), dest.getId());
        element.setQualifierId(dest.getId());
        HierarchicalPersistent hp = (HierarchicalPersistent) engine.getAttribute(element, hAttribute);
        if ((hp != null) && (hp.getParentElementId() == -1l)) {
            hp.setParentElementId(row.getElementId());
            engine.setAttribute(element, hAttribute, hp);
        }
    }
    long prevId = -1l;
    for (Row row2 : toArray(row.getChildren())) {
        moveElements(row2, row.getElementId(), prevId, dest);
        prevId = row2.getId();
    }
    String name = row.getName();
    engine.setElementQualifier(row.getElementId(), dest.getId());
    HierarchicalPersistent hp = new HierarchicalPersistent();
    hp.setPreviousElementId(prevParentId);
    hp.setParentElementId(parentElementId);
    engine.setAttribute(row.getElement(), hAttribute, hp);
    Attribute nameAttribute = engine.getAttribute(dest.getAttributeForName());
    if (nameAttribute != null)
        engine.setAttribute(row.getElement(), nameAttribute, name);
}
Also used : Attribute(com.ramussoft.common.Attribute) HierarchicalPersistent(com.ramussoft.core.attribute.simple.HierarchicalPersistent) Element(com.ramussoft.common.Element) Row(com.ramussoft.database.common.Row) RootRow(com.ramussoft.database.common.RowSet.RootRow)

Example 2 with HierarchicalPersistent

use of com.ramussoft.core.attribute.simple.HierarchicalPersistent in project ramus by Vitaliy-Yakovchuk.

the class NFunction method sortChilds.

private synchronized void sortChilds() {
    final NFunction[] os = children.toArray(new NFunction[children.size()]);
    if (os.length < 1)
        return;
    Arrays.sort(os, new Comparator<NFunction>() {

        public int compare(final NFunction o1, final NFunction o2) {
            return ((NFunction) o1).getFId() - ((NFunction) o2).getFId();
        }
    });
    HierarchicalPersistent hp = os[0].getHierarchicalPersistent();
    if (hp.getPreviousElementId() != -1l) {
        hp.setPreviousElementId(-1l);
        os[0].setHierarchicalPersistent(hp);
    }
    for (int i = 1; i < os.length; i++) {
        hp = os[i].getHierarchicalPersistent();
        if (hp.getPreviousElementId() != os[i - 1].getElementId()) {
            hp.setPreviousElementId(os[i - 1].getElementId());
            os[i].setHierarchicalPersistent(hp);
        }
    }
}
Also used : HierarchicalPersistent(com.ramussoft.core.attribute.simple.HierarchicalPersistent)

Example 3 with HierarchicalPersistent

use of com.ramussoft.core.attribute.simple.HierarchicalPersistent in project ramus by Vitaliy-Yakovchuk.

the class IDEF0Plugin method installFunctionAttributes.

public static void installFunctionAttributes(Qualifier qualifier, Engine engine) {
    if (isFunction(qualifier))
        throw new RuntimeException("Qualifier is allready function.");
    IDEF0Plugin plugin = (IDEF0Plugin) engine.getPluginProperty(IDEF0, PLUGIN);
    for (Attribute a : plugin.functionAttributes) {
        qualifier.getSystemAttributes().add(a);
    }
    engine.updateQualifier(qualifier);
    Element e = engine.createElement(plugin.baseFunctions.getId());
    engine.setAttribute(e, plugin.baseFunctionQualifierId, qualifier.getId());
    engine.setAttribute(e, (Attribute) engine.getPluginProperty("Core", HierarchicalPlugin.HIERARHICAL_ATTRIBUTE), new HierarchicalPersistent());
}
Also used : Attribute(com.ramussoft.common.Attribute) HierarchicalPersistent(com.ramussoft.core.attribute.simple.HierarchicalPersistent) Element(com.ramussoft.common.Element)

Example 4 with HierarchicalPersistent

use of com.ramussoft.core.attribute.simple.HierarchicalPersistent in project ramus by Vitaliy-Yakovchuk.

the class Row method setParent.

public void setParent(Row parent) {
    HierarchicalPersistent hp = getHierarchicalPersistent();
    if (hp == null)
        hp = new HierarchicalPersistent();
    hp.setParentElementId(parent.getElementId());
    hp.setPreviousElementId(-1l);
    if (parent.getChildCount() > 0) {
        hp.setPreviousElementId(parent.getChildAt(parent.getChildCount() - 1).getElementId());
    }
    parent.children.add(this);
    this.setHierarchicalPersistent(hp);
}
Also used : HierarchicalPersistent(com.ramussoft.core.attribute.simple.HierarchicalPersistent)

Example 5 with HierarchicalPersistent

use of com.ramussoft.core.attribute.simple.HierarchicalPersistent in project ramus by Vitaliy-Yakovchuk.

the class RowSet method attributeChanged.

protected void attributeChanged(AttributeEvent event) {
    synchronized (STATIC_LOCK) {
        if (currentThread == Thread.currentThread())
            return;
    }
    if (event.getAttribute().equals(getHAttribute())) {
        HierarchicalPersistent old = (HierarchicalPersistent) event.getOldValue();
        HierarchicalPersistent p = (HierarchicalPersistent) event.getNewValue();
        Element e = event.getElement();
        Row row = findRow(e.getId());
        if (row != null) {
            if (old != null) {
                Row parent = row.getParent();
                if (parent != null) {
                    int index = parent.getChildren().indexOf(row);
                    parent.getChildren().remove(row);
                    removedFromChildren(parent, row, index);
                }
            }
            if (p == null)
                return;
            Row parent = findRow(p.getParentElementId());
            if (parent == null)
                parent = root;
            List<Row> children = parent.getChildren();
            children.remove(row);
            row.setNativeParent(parent);
            int index = 0;
            int size = children.size();
            for (int i = 0; i < size; i++) {
                Row row2 = children.get(i);
                if (row2.getElementId() == p.getPreviousElementId()) {
                    index = i + 1;
                    break;
                }
            }
            if (!filter(row.getElement())) {
                children.add(index, row);
                added(parent, row, index);
            }
        } else {
            System.err.println("Warning! Unregister with current rowset row where changed. Element id: " + e.getId() + ", Name: " + e.getName());
            return;
        }
    }
    for (int i = 0; i < attributesWithH.length; i++) {
        if (attributesWithH[i].equals(event.getAttribute())) {
            Row row = findRow(event.getElement().getId());
            if (row == null)
                return;
            row.updateObject(i, event.getNewValue());
            attributeChanged(row, event.getAttribute(), event.getNewValue(), event.getOldValue(), event.isJournaled());
        }
    }
    if (event.getAttribute().getId() == qualifier.getAttributeForName()) {
        Row row = findRow(event.getElement().getId());
        row.updateElement();
    }
}
Also used : HierarchicalPersistent(com.ramussoft.core.attribute.simple.HierarchicalPersistent) Element(com.ramussoft.common.Element)

Aggregations

HierarchicalPersistent (com.ramussoft.core.attribute.simple.HierarchicalPersistent)17 Element (com.ramussoft.common.Element)11 Attribute (com.ramussoft.common.Attribute)9 Qualifier (com.ramussoft.common.Qualifier)4 AttributeType (com.ramussoft.common.AttributeType)3 Row (com.ramussoft.database.common.Row)2 ArrayList (java.util.ArrayList)2 ProjectOptions (com.dsoft.pb.idef.elements.ProjectOptions)1 Engine (com.ramussoft.common.Engine)1 IEngine (com.ramussoft.common.IEngine)1 AttributeAdapter (com.ramussoft.common.event.AttributeAdapter)1 AttributeEvent (com.ramussoft.common.event.AttributeEvent)1 ElementAdapter (com.ramussoft.common.event.ElementAdapter)1 ElementAttributeListener (com.ramussoft.common.event.ElementAttributeListener)1 ElementEvent (com.ramussoft.common.event.ElementEvent)1 QualifierAdapter (com.ramussoft.common.event.QualifierAdapter)1 QualifierEvent (com.ramussoft.common.event.QualifierEvent)1 StreamAdapter (com.ramussoft.common.event.StreamAdapter)1 StreamEvent (com.ramussoft.common.event.StreamEvent)1 Journaled (com.ramussoft.common.journal.Journaled)1