Search in sources :

Example 41 with MdiEntry

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);
        }
    }
}
Also used : MdiEntry(com.biglybt.ui.mdi.MdiEntry)

Aggregations

MdiEntry (com.biglybt.ui.mdi.MdiEntry)41 MultipleDocumentInterface (com.biglybt.ui.mdi.MultipleDocumentInterface)13 BaseMdiEntry (com.biglybt.ui.swt.mdi.BaseMdiEntry)11 MenuItem (com.biglybt.pif.ui.menus.MenuItem)4 ViewTitleInfo (com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo)4 MdiCloseListener (com.biglybt.ui.mdi.MdiCloseListener)4 MultipleDocumentInterfaceSWT (com.biglybt.ui.swt.mdi.MultipleDocumentInterfaceSWT)4 UISWTViewEvent (com.biglybt.ui.swt.pif.UISWTViewEvent)4 UISWTViewEventListener (com.biglybt.ui.swt.pif.UISWTViewEventListener)4 ParameterListener (com.biglybt.core.config.ParameterListener)3 DownloadManager (com.biglybt.core.download.DownloadManager)3 PluginInterface (com.biglybt.pif.PluginInterface)3 UIPluginViewToolBarListener (com.biglybt.pif.ui.UIPluginViewToolBarListener)3 UIFunctions (com.biglybt.ui.UIFunctions)3 DownloadManagerPeerListener (com.biglybt.core.download.DownloadManagerPeerListener)2 PEPeer (com.biglybt.core.peer.PEPeer)2 PEPeerStats (com.biglybt.core.peer.PEPeerStats)2 UIManager (com.biglybt.pif.ui.UIManager)2 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)2 MenuManager (com.biglybt.pif.ui.menus.MenuManager)2