use of com.biglybt.core.tag.Tag in project BiglyBT by BiglySoftware.
the class ColumnTagType method refresh.
@Override
public void refresh(TableCell cell) {
Tag tag = (Tag) cell.getDataSource();
TagType sortVal = null;
if (tag != null) {
sortVal = tag.getTagType();
}
if (!cell.setSortValue(sortVal == null ? 0 : sortVal.getTagType()) && cell.isValid()) {
return;
}
if (!cell.isShown()) {
return;
}
cell.setText(sortVal == null ? "" : sortVal.getTagTypeName(true));
}
use of com.biglybt.core.tag.Tag in project BiglyBT by BiglySoftware.
the class ColumnTagUpTotal method refresh.
@Override
public void refresh(TableCell cell) {
Tag tag = (Tag) cell.getDataSource();
if (tag instanceof TagFeatureRateLimit) {
TagFeatureRateLimit rl = (TagFeatureRateLimit) tag;
if (rl.supportsTagRates()) {
long[] up = rl.getTagUploadTotal();
if (up != null) {
long tot = 0;
for (long l : up) {
tot += l;
}
if (!cell.setSortValue(tot) && cell.isValid()) {
return;
}
if (!cell.isShown()) {
return;
}
cell.setText(DisplayFormatters.formatByteCountToKiBEtc(tot));
}
}
}
}
use of com.biglybt.core.tag.Tag in project BiglyBT by BiglySoftware.
the class DeviceManagerUI method addTagSubMenu.
private static void addTagSubMenu(MenuManager menu_manager, MenuItem menu, final DeviceMediaRenderer device) {
menu.removeAllChildItems();
TagManager tm = TagManagerFactory.getTagManager();
List<Tag> tags = tm.getTagType(TagType.TT_DOWNLOAD_MANUAL).getTags();
tags = TagUIUtils.sortTags(tags);
long tag_id = device.getAutoShareToTagID();
Tag assigned_tag = tm.lookupTagByUID(tag_id);
MenuItem m = menu_manager.addMenuItem(menu, "label.no.tag");
m.setStyle(MenuItem.STYLE_RADIO);
m.setData(Boolean.valueOf(assigned_tag == null));
m.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
device.setAutoShareToTagID(-1);
}
});
m = menu_manager.addMenuItem(menu, "sep1");
m.setStyle(MenuItem.STYLE_SEPARATOR);
List<String> menu_names = new ArrayList<>();
Map<String, Tag> menu_name_map = new IdentityHashMap<>();
for (Tag t : tags) {
if (!t.isTagAuto()[0]) {
String name = t.getTagName(true);
menu_names.add(name);
menu_name_map.put(name, t);
}
}
List<Object> menu_structure = MenuBuildUtils.splitLongMenuListIntoHierarchy(menu_names, TagUIUtils.MAX_TOP_LEVEL_TAGS_IN_MENU);
for (Object obj : menu_structure) {
List<Tag> bucket_tags = new ArrayList<>();
MenuItem parent_menu;
if (obj instanceof String) {
parent_menu = menu;
bucket_tags.add(menu_name_map.get((String) obj));
} else {
Object[] entry = (Object[]) obj;
List<String> tag_names = (List<String>) entry[1];
boolean has_selected = false;
for (String name : tag_names) {
Tag tag = menu_name_map.get(name);
bucket_tags.add(tag);
if (assigned_tag == tag) {
has_selected = true;
}
}
parent_menu = menu_manager.addMenuItem(menu, "!" + (String) entry[0] + (has_selected ? " (*)" : "") + "!");
parent_menu.setStyle(MenuItem.STYLE_MENU);
}
for (final Tag tag : bucket_tags) {
m = menu_manager.addMenuItem(parent_menu, tag.getTagName(false));
m.setStyle(MenuItem.STYLE_RADIO);
m.setData(Boolean.valueOf(assigned_tag == tag));
m.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
device.setAutoShareToTagID(tag.getTagUID());
}
});
}
}
m = menu_manager.addMenuItem(menu, "sep2");
m.setStyle(MenuItem.STYLE_SEPARATOR);
m = menu_manager.addMenuItem(menu, "label.add.tag");
m.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
TagUIUtils.createManualTag(new UIFunctions.TagReturner() {
@Override
public void returnedTags(Tag[] tags) {
if (tags != null) {
for (Tag new_tag : tags) {
device.setAutoShareToTagID(new_tag.getTagUID());
}
}
}
});
}
});
}
use of com.biglybt.core.tag.Tag in project BiglyBT by BiglySoftware.
the class SBC_DevicesView method addTagsSubMenu.
private void addTagsSubMenu(Menu menu_tags, final TranscodeFile[] files) {
MenuItem[] items = menu_tags.getItems();
for (int i = 0; i < items.length; i++) {
items[i].dispose();
}
TagManager tm = TagManagerFactory.getTagManager();
List<Tag> all_tags = tm.getTagType(TagType.TT_DOWNLOAD_MANUAL).getTags();
all_tags = TagUIUtils.sortTags(all_tags);
if (all_tags.size() > 0) {
Set<String> shared_tags = null;
boolean some_tags_assigned = false;
for (TranscodeFile file : files) {
Set<String> file_tags = new HashSet<>();
file_tags.addAll(Arrays.asList(file.getTags(true)));
if (file_tags.size() > 0) {
some_tags_assigned = true;
}
if (shared_tags == null) {
shared_tags = file_tags;
} else {
if (shared_tags.size() != file_tags.size()) {
shared_tags.clear();
break;
} else {
if (!shared_tags.equals(file_tags)) {
shared_tags.clear();
break;
}
}
}
}
if (some_tags_assigned) {
final MenuItem mi_no_tag = new MenuItem(menu_tags, SWT.PUSH);
mi_no_tag.setText(MessageText.getString("label.no.tag"));
mi_no_tag.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
for (TranscodeFile file : files) {
file.setTags(new String[0]);
}
}
});
new MenuItem(menu_tags, SWT.SEPARATOR);
}
List<String> menu_names = new ArrayList<>();
Map<String, Tag> menu_name_map = new IdentityHashMap<>();
for (Tag t : all_tags) {
if (!t.isTagAuto()[0]) {
String name = t.getTagName(true);
menu_names.add(name);
menu_name_map.put(name, t);
}
}
List<Object> menu_structure = MenuBuildUtils.splitLongMenuListIntoHierarchy(menu_names, TagUIUtils.MAX_TOP_LEVEL_TAGS_IN_MENU);
for (Object obj : menu_structure) {
List<Tag> bucket_tags = new ArrayList<>();
Menu parent_menu;
if (obj instanceof String) {
parent_menu = menu_tags;
bucket_tags.add(menu_name_map.get((String) obj));
} else {
Object[] entry = (Object[]) obj;
List<String> tag_names = (List<String>) entry[1];
boolean sub_all_selected = true;
boolean sub_some_selected = false;
for (String name : tag_names) {
Tag sub_tag = menu_name_map.get(name);
if (shared_tags != null && shared_tags.contains(name)) {
sub_some_selected = true;
} else {
sub_all_selected = false;
}
bucket_tags.add(sub_tag);
}
String mod;
if (sub_all_selected) {
mod = " (*)";
} else if (sub_some_selected) {
mod = " (+)";
} else {
mod = "";
}
Menu menu_bucket = new Menu(menu_tags.getShell(), SWT.DROP_DOWN);
MenuItem bucket_item = new MenuItem(menu_tags, SWT.CASCADE);
bucket_item.setText((String) entry[0] + mod);
bucket_item.setMenu(menu_bucket);
parent_menu = menu_bucket;
}
for (final Tag t : bucket_tags) {
final MenuItem t_i = new MenuItem(parent_menu, SWT.CHECK);
String tag_name = t.getTagName(true);
t_i.setText(tag_name);
boolean selected = shared_tags != null && shared_tags.contains(tag_name);
t_i.setSelection(selected);
t_i.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
boolean selected = t_i.getSelection();
String tag_uid = String.valueOf(t.getTagUID());
for (TranscodeFile file : files) {
Set<String> uids = new TreeSet<>();
uids.addAll(Arrays.asList(file.getTags(false)));
boolean update = false;
if (selected) {
if (!uids.contains(tag_uid)) {
uids.add(tag_uid);
update = true;
}
} else {
if (uids.contains(tag_uid)) {
uids.remove(tag_uid);
update = true;
}
}
if (update) {
file.setTags(uids.toArray(new String[uids.size()]));
}
}
}
});
}
}
}
new MenuItem(menu_tags, SWT.SEPARATOR);
MenuItem item_create = new MenuItem(menu_tags, SWT.PUSH);
Messages.setLanguageText(item_create, "label.add.tag");
item_create.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
TagUIUtilsV3.showCreateTagDialog(new UIFunctions.TagReturner() {
@Override
public void returnedTags(Tag[] tags) {
if (tags != null) {
for (Tag new_tag : tags) {
if (new_tag != null) {
String[] tagUIDs = new String[] { String.valueOf(new_tag.getTagUID()) };
for (TranscodeFile file : files) {
file.setTags(tagUIDs);
}
COConfigurationManager.setParameter("Library.TagInSideBar", true);
}
}
}
}
});
}
});
}
use of com.biglybt.core.tag.Tag in project BiglyBT by BiglySoftware.
the class TagAddedToDateItem method refresh.
@Override
public void refresh(TableCell cell, long timestamp) {
DownloadManager dm = (DownloadManager) cell.getDataSource();
TableView<?> tv = cell.getTableRow().getView();
TableViewCreator tvc = tv == null ? null : cell.getTableRow().getView().getTableViewCreator();
if (dm != null && tvc instanceof MyTorrentsView) {
MyTorrentsView mtv = (MyTorrentsView) tvc;
Tag[] tags = mtv.getCurrentTags();
if (tags != null && tags.length == 1) {
long time = tags[0].getTaggableAddedTime(dm);
super.refresh(cell, time);
return;
}
}
super.refresh(cell, -1);
}
Aggregations