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();
}
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();
}
Aggregations