use of com.ramussoft.core.attribute.simple.HierarchicalPersistent in project ramus by Vitaliy-Yakovchuk.
the class StandardAttributesPlugin method getParentElement.
public static Element getParentElement(Engine engine, long elementId) {
Attribute h = getHierarchicalAttribute(engine);
Element element = engine.getElement(elementId);
if (element == null)
return null;
HierarchicalPersistent hp = (HierarchicalPersistent) engine.getAttribute(element, h);
if (hp != null)
return engine.getElement(hp.getParentElementId());
return null;
}
use of com.ramussoft.core.attribute.simple.HierarchicalPersistent in project ramus by Vitaliy-Yakovchuk.
the class RowMover method copyUp.
private Setter copyUp(Row next) {
if (next.getHierarchicalPersistent() == null)
return null;
Row parent = next.getParent();
int index = parent.getIndex(next);
if (index + 1 < parent.getChildCount()) {
Row nn = parent.getChildAt(index + 1);
if (inGroup(nn))
return null;
long prev = -1l;
for (int i = index - 1; i >= 0; i--) {
Row childAt = parent.getChildAt(i);
if (!inGroup(childAt)) {
prev = childAt.getElementId();
break;
}
}
HierarchicalPersistent hp = nn.getHierarchicalPersistent();
if (hp == null)
hp = new HierarchicalPersistent();
hp.setPreviousElementId(prev);
Setter setter = new Setter();
setter.hp = hp;
setter.row = nn;
return setter;
}
return null;
}
use of com.ramussoft.core.attribute.simple.HierarchicalPersistent in project ramus by Vitaliy-Yakovchuk.
the class RowMover method insert.
public void insert(final int position) {
try {
rowSet.startUserTransaction();
Row parent = null;
int pos;
if (position == 0) {
parent = base;
pos = -1;
} else {
if (position < group.length - 1 && group[position - 1].equals(group[position].getParent())) {
parent = group[position - 1];
pos = -1;
} else {
parent = group[position - 1].getParent();
pos = getIndex(parent, group[position - 1]);
}
}
if (!isOk(parent))
return;
remChilds();
int len = 0;
for (int i : selected) if (i >= 0)
len++;
int[] is = new int[len];
len = 0;
for (int i : selected) if (i >= 0) {
is[len] = i;
len++;
}
selected = is;
if (selected.length == 0)
return;
for (int i : selected) {
Row next = group[i];
Setter s = copyUp(next);
if (s != null)
s.set();
}
Row first = group[selected[0]];
Row next = null;
int p = pos + 1;
while (p < parent.getChildCount()) {
if (!inGroup(parent.getChildAt(p))) {
next = parent.getChildAt(p);
break;
}
p++;
}
HierarchicalPersistent old = first.getHierarchicalPersistent();
HierarchicalPersistent hp = new HierarchicalPersistent(old);
if ((parent.getChildCount() > 0) && (pos >= 0)) {
Row prev = parent.getChildAt(pos);
hp.setPreviousElementId(prev.getElementId());
} else
hp.setPreviousElementId(-1l);
hp.setParentElementId(parent.getElementId());
// if (!old.equals(hp))
first.setHierarchicalPersistent(hp);
Row last = group[selected[selected.length - 1]];
if (next != null) {
old = next.getHierarchicalPersistent();
hp = new HierarchicalPersistent(old);
hp.setPreviousElementId(last.getElementId());
// if (!old.equals(hp))
next.setHierarchicalPersistent(hp);
}
for (int i = 1; i < selected.length; i++) {
Row s = group[selected[i]];
Row f = group[selected[i - 1]];
old = s.getHierarchicalPersistent();
hp = new HierarchicalPersistent(old);
hp.setPreviousElementId(f.getElementId());
hp.setParentElementId(parent.getElementId());
// if (!old.equals(hp))
s.setHierarchicalPersistent(hp);
}
// for (Setter s : setters)
// s.set();
} finally {
rowSet.commitUserTransaction();
}
}
use of com.ramussoft.core.attribute.simple.HierarchicalPersistent in project ramus by Vitaliy-Yakovchuk.
the class Row method sortByName.
public void sortByName() {
Row[] rows = children.toArray(new Row[children.size()]);
Arrays.sort(rows, new Comparator<Row>() {
@Override
public int compare(Row o1, Row o2) {
return StringCollator.compare(o1.getName(), o2.getName());
}
});
Row prev = null;
for (Row row : rows) {
HierarchicalPersistent hp = new HierarchicalPersistent(row.getHierarchicalPersistent());
if (prev == null)
hp.setPreviousElementId(-1l);
else
hp.setPreviousElementId(prev.getElementId());
if (!row.getHierarchicalPersistent().equals(hp))
row.setHierarchicalPersistent(hp);
prev = row;
}
for (Row row : rows) if (row.getChildCount() > 0)
row.sortByName();
}
use of com.ramussoft.core.attribute.simple.HierarchicalPersistent in project ramus by Vitaliy-Yakovchuk.
the class RowSet method setRowQualifier.
public void setRowQualifier(Row row, Qualifier qualifier) {
RowSet rs = new RowSet(engine, qualifier, new Attribute[] {});
List<Row> rows = rs.getAllRows();
engine.setElementQualifier(row.getElementId(), qualifier.getId());
HierarchicalPersistent hp = new HierarchicalPersistent();
hp.setParentElementId(-1l);
hp.setPreviousElementId(-1l);
if (rows.size() > 0) {
hp.setPreviousElementId(rows.get(rows.size() - 1).getElementId());
}
rs.close();
Element element = row.getElement();
element.setQualifierId(qualifier.getId());
engine.setAttribute(element, getHAttribute(), hp);
}
Aggregations