Search in sources :

Example 16 with HierarchicalPersistent

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

the class RowSet method deleteRow.

public void deleteRow(Row row) {
    boolean start = isUserTransactionStarted();
    if (!start)
        startUserTransaction();
    int index = row.getParent().getIndex(row);
    index++;
    if (index < row.getParent().getChildCount()) {
        Row row2 = row.getParent().getChildAt(index);
        HierarchicalPersistent p = row2.getHierarchicalPersistent();
        HierarchicalPersistent persistent = row.getHierarchicalPersistent();
        if (persistent != null) {
            if (p == null)
                p = new HierarchicalPersistent();
            p.setPreviousElementId(persistent.getPreviousElementId());
            row2.setAttribute(getHAttribute(), p);
        }
    }
    engine.deleteElement(row.getElementId());
    if (!start)
        commitUserTransaction();
}
Also used : HierarchicalPersistent(com.ramussoft.core.attribute.simple.HierarchicalPersistent)

Example 17 with HierarchicalPersistent

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

the class RowSet method init.

private void init() {
    rowHash.clear();
    ArrayList<Attribute> attributeList = new ArrayList<Attribute>();
    hAttribute = (Attribute) engine.getPluginProperty("Core", HierarchicalPlugin.HIERARHICAL_ATTRIBUTE);
    attributeList.add(hAttribute);
    for (Attribute attribute : attributes) {
        attributeList.add(attribute);
    }
    Row root = null;
    attributesWithH = attributeList.toArray(new Attribute[attributeList.size()]);
    for (int i = 0; i < attributesWithH.length; i++) attributeIndexes.put(attributesWithH[i].getId(), i);
    this.root = rowCreater.createRow(null, this, attributesWithH, new Object[attributesWithH.length]);
    this.rootList = this.root.getChildren();
    List<Integer> removed = new ArrayList<Integer>();
    for (int i = attributeList.size() - 1; i >= 0; i--) {
        AttributeType attributeType = attributeList.get(i).getAttributeType();
        if (!attributeType.isLight()) {
            attributeList.remove(i);
            removed.add(i);
        }
    }
    int[] rems = new int[removed.size()];
    for (int i = 0; i < rems.length; i++) {
        rems[i] = removed.get(i);
    }
    Hashtable<Element, Object[]> hash = engine.getElements(qualifier, attributeList);
    for (Entry<Element, Object[]> e : hash.entrySet()) {
        Element element = e.getKey();
        Object[] objects = e.getValue();
        Object[] objects2;
        if (rems.length == 0) {
            objects2 = objects;
        } else {
            objects2 = new Object[objects.length + rems.length];
            int k = 0;
            for (int i = objects.length - 1; i >= 0; i--) {
                while ((rems.length > k) && (i == rems[k] - rems.length + k)) {
                    k++;
                }
                objects2[i - k + rems.length] = objects[i];
            }
        }
        Row row = rowCreater.createRow(element, this, attributesWithH, objects2);
        rowHash.put(element.getId(), row);
        HierarchicalPersistent p = (HierarchicalPersistent) e.getValue()[0];
        if ((p != null) && (p.getParentElementId() == -1l) && (p.getPreviousElementId() == -1l)) {
            root = row;
        }
    }
    for (Entry<Long, Row> e : rowHash.entrySet()) {
        Row row = e.getValue();
        HierarchicalPersistent p = row.getHierarchicalPersistent();
        if (p == null) {
            p = new HierarchicalPersistent();
            p.setParentElementId(-1);
            p.setPreviousElementId((root == null) ? -1l : root.getElementId());
            boolean start = isUserTransactionStarted();
            if (!start)
                startUserTransaction();
            row.setAttribute(attributeList.get(0), p);
            if (!start)
                commitUserTransaction();
            row.setNativeHierarchicalPersistent(p);
            if (root == null) {
                root = row;
            }
        }
        Row parent = findRow(p.getParentElementId());
        if (parent == null) {
            parent = this.root;
        } else if (parent.getElementId() == row.getElementId())
            parent = this.root;
        addRow(parent.getChildren(), row);
        row.setNativeParent(parent);
    }
    resort(rootList);
    for (Entry<Long, Row> e : rowHash.entrySet()) {
        Row row = e.getValue();
        resort(row.getChildren());
    }
    filter(rootList);
    if (!readOnly) {
        engine.addElementAttributeListener(qualifier, listener);
        engine.addElementListener(qualifier, elementListener);
        engine.addQualifierListener(qualifierListener);
    }
    postInit();
}
Also used : Attribute(com.ramussoft.common.Attribute) Element(com.ramussoft.common.Element) ArrayList(java.util.ArrayList) HierarchicalPersistent(com.ramussoft.core.attribute.simple.HierarchicalPersistent) AttributeType(com.ramussoft.common.AttributeType)

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