use of com.biglybt.ui.mdi.MdiEntry in project BiglyBT by BiglySoftware.
the class SideBar method _setupNewEntry.
private void _setupNewEntry(SideBarEntrySWT entry, String id, boolean expandParent, boolean closeable) {
if (tree.isDisposed()) {
return;
}
String view_id = entry.getViewID();
SideBarEntrySWT existing = getEntry(view_id);
if (existing != entry) {
return;
}
MdiEntry currentEntry = entry;
String currentID = id;
while (true) {
if (MainMDISetup.hiddenTopLevelIDs.contains(currentID)) {
return;
}
if (currentEntry == null) {
break;
}
currentID = currentEntry.getParentID();
if (currentID == null) {
break;
}
currentEntry = getEntry(currentID);
}
String parentID = entry.getParentID();
MdiEntry parent = getEntry(parentID);
TreeItem parentTreeItem = null;
if (parent instanceof SideBarEntrySWT) {
SideBarEntrySWT parentSWT = (SideBarEntrySWT) parent;
parentTreeItem = parentSWT.getTreeItem();
if (expandParent) {
parentTreeItem.setExpanded(true);
}
}
int index = -1;
String preferredAfterID = entry.getPreferredAfterID();
if (preferredAfterID != null) {
if (preferredAfterID.length() == 0) {
index = 0;
} else {
boolean hack_it = preferredAfterID.startsWith("~");
if (hack_it) {
// hack - this means preferred BEFORE ID...
preferredAfterID = preferredAfterID.substring(1);
}
MdiEntry entryAbove = getEntry(preferredAfterID);
if (entryAbove != null) {
index = indexOf(entryAbove);
if (hack_it) {
} else {
if (index >= 0) {
index++;
}
}
// System.out.println("ENTRY " + id + " is going to go below " + entryAbove.getId() + " at " + index);
}
}
}
if (index == -1 && parent == null) {
index = 0;
String[] order = getPreferredOrder();
for (int i = 0; i < order.length; i++) {
String orderID = order[i];
if (orderID.equals(id)) {
break;
}
MdiEntry entry2 = getEntry(orderID);
if (entry2 != null) {
int i2 = indexOf(entry2);
if (i2 >= 0) {
index = i2 + 1;
}
}
}
}
if (GAP_BETWEEN_LEVEL_1 > 0 && parentTreeItem == null && tree.getItemCount() > 0 && index != 0) {
for (int i = 0; i < GAP_BETWEEN_LEVEL_1; i++) {
createTreeItem(null, null, index);
if (index >= 0) {
index++;
}
}
}
TreeItem treeItem = createTreeItem(entry, parentTreeItem, index);
if (treeItem != null) {
triggerEntryLoadedListeners(entry);
}
if (GAP_BETWEEN_LEVEL_1 > 0 && parentTreeItem == null && tree.getItemCount() > 1 && index == 0) {
for (int i = 0; i < GAP_BETWEEN_LEVEL_1; i++) {
createTreeItem(null, null, ++index);
}
}
}
Aggregations