use of com.biglybt.ui.swt.views.PeersGeneralView in project BiglyBT by BiglySoftware.
the class SB_Transfers method setupTag.
public MdiEntry setupTag(final Tag tag) {
MultipleDocumentInterfaceSWT mdi = UIFunctionsManagerSWT.getUIFunctionsSWT().getMDISWT();
if (mdi == null) {
return null;
}
synchronized (tag_setup_lock) {
String id = "Tag." + tag.getTagType().getTagType() + "." + tag.getTagID();
if (mdi.getEntry(id) != null) {
return null;
}
// find where to locate this in the sidebar
TreeMap<Tag, String> name_map = new TreeMap<>(TagUIUtils.getTagComparator());
name_map.put(tag, id);
for (Tag t : tag.getTagType().getTags()) {
if (t.isVisible()) {
String tid = "Tag." + tag.getTagType().getTagType() + "." + t.getTagID();
if (mdi.getEntry(tid) != null) {
name_map.put(t, tid);
}
}
}
String prev_id = null;
for (String this_id : name_map.values()) {
if (this_id == id) {
break;
}
prev_id = this_id;
}
if (prev_id == null && name_map.size() > 1) {
Iterator<String> it = name_map.values().iterator();
it.next();
prev_id = "~" + it.next();
}
boolean auto = tag.getTagType().isTagTypeAuto();
ViewTitleInfo viewTitleInfo = new ViewTitleInfo() {
@Override
public Object getTitleInfoProperty(int pid) {
if (pid == TITLE_TEXT) {
return (tag.getTagName(true));
} else if (pid == TITLE_INDICATOR_TEXT) {
return (String.valueOf(tag.getTaggedCount()));
} else if (pid == TITLE_INDICATOR_COLOR) {
TagType tag_type = tag.getTagType();
int[] def_color = tag_type.getColorDefault();
int[] tag_color = tag.getColor();
if (tag_color != def_color) {
return (tag_color);
}
} else if (pid == TITLE_INDICATOR_TEXT_TOOLTIP) {
return (TagUIUtils.getTagTooltip(tag));
}
return null;
}
};
MdiEntry entry;
boolean closable = auto;
if (tag.getTaggableTypes() == Taggable.TT_DOWNLOAD) {
closable = true;
String name = tag.getTagName(true);
entry = mdi.createEntryFromSkinRef(MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, id, "library", name, viewTitleInfo, tag, closable, prev_id);
} else {
entry = mdi.createEntryFromEventListener(MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, new PeersGeneralView(tag), id, closable, null, prev_id);
entry.setViewTitleInfo(viewTitleInfo);
}
if (closable) {
entry.addListener(new MdiCloseListener() {
@Override
public void mdiEntryClosed(MdiEntry entry, boolean userClosed) {
if (userClosed && entry.getUserData(AUTO_CLOSE_KEY) == null) {
if (COConfigurationManager.getBooleanParameter("Library.TagInSideBar")) {
tag.setVisible(false);
}
}
}
});
}
if (entry != null) {
String image_id = tag.getImageID();
if (image_id != null) {
entry.setImageLeftID(image_id);
} else if (tag.getTagType().getTagType() == TagType.TT_PEER_IPSET) {
entry.setImageLeftID("image.sidebar.tag-red");
} else if (tag.getTagType().isTagTypePersistent()) {
entry.setImageLeftID("image.sidebar.tag-green");
} else {
entry.setImageLeftID("image.sidebar.tag-blue");
}
}
if (entry instanceof SideBarEntrySWT) {
final SideBarEntrySWT entrySWT = (SideBarEntrySWT) entry;
entrySWT.addListener(new MdiSWTMenuHackListener() {
@Override
public void menuWillBeShown(MdiEntry entry, Menu menuTree) {
TagUIUtils.createSideBarMenuItems(menuTree, tag);
}
});
}
if (!auto && entry != null) {
MdiEntryDropListener dl = new MdiEntryDropListener() {
@Override
public boolean mdiEntryDrop(MdiEntry entry, Object payload) {
if (!(payload instanceof String)) {
return false;
}
boolean[] auto = tag.isTagAuto();
if (auto[0] && auto[1]) {
return (false);
}
final String dropped = (String) payload;
new AEThread2("Tagger") {
@Override
public void run() {
dropTorrentOnTag(tag, dropped);
}
}.start();
return true;
}
private void dropTorrentOnTag(Tag tag, String dropped) {
String[] split = Constants.PAT_SPLIT_SLASH_N.split(dropped);
if (split.length <= 1) {
return;
}
String type = split[0];
if (!type.startsWith("DownloadManager") && !type.startsWith("DiskManagerFileInfo")) {
return;
}
GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
List<DownloadManager> listDMs = new ArrayList<>();
boolean doAdd = false;
for (int i = 1; i < split.length; i++) {
String hash = split[i];
// for files
int sep = hash.indexOf(";");
if (sep != -1) {
hash = hash.substring(0, sep);
}
try {
DownloadManager dm = gm.getDownloadManager(new HashWrapper(Base32.decode(hash)));
if (dm != null) {
listDMs.add(dm);
if (!doAdd && !tag.hasTaggable(dm)) {
doAdd = true;
}
}
} catch (Throwable t) {
}
boolean[] auto = tag.isTagAuto();
for (DownloadManager dm : listDMs) {
if (doAdd) {
if (!auto[0]) {
tag.addTaggable(dm);
}
} else {
if (!(auto[0] && auto[1])) {
tag.removeTaggable(dm);
}
}
}
}
}
};
boolean[] tag_auto = tag.isTagAuto();
entry.setUserData(TAG_DATA_KEY, new Object[] { dl, tag_auto });
if (!(tag_auto[0] && tag_auto[1])) {
entry.addListener(dl);
}
}
return entry;
}
}
Aggregations