use of com.biglybt.ui.UIFunctions.TagReturner in project BiglyBT by BiglySoftware.
the class TorrentUtil method addCategorySubMenu.
protected static void addCategorySubMenu(final DownloadManager[] dms, Menu menuCategory) {
MenuItem[] items = menuCategory.getItems();
int i;
for (i = 0; i < items.length; i++) {
items[i].dispose();
}
Category[] categories = CategoryManager.getCategories();
Arrays.sort(categories);
// Ensure that there is at least one user category available.
boolean allow_category_selection = categories.length > 0;
if (allow_category_selection) {
boolean user_category_found = false;
for (i = 0; i < categories.length; i++) {
if (categories[i].getType() == Category.TYPE_USER) {
user_category_found = true;
break;
}
}
// It may be the categories array just contains "uncategorised".
allow_category_selection = user_category_found;
}
if (allow_category_selection) {
final Category catUncat = CategoryManager.getCategory(Category.TYPE_UNCATEGORIZED);
if (catUncat != null) {
final MenuItem itemCategory = new MenuItem(menuCategory, SWT.PUSH);
Messages.setLanguageText(itemCategory, catUncat.getName());
itemCategory.addListener(SWT.Selection, new ListenerDMTask(dms) {
@Override
public void run(DownloadManager dm) {
dm.getDownloadState().setCategory(catUncat);
}
});
new MenuItem(menuCategory, SWT.SEPARATOR);
}
for (i = 0; i < categories.length; i++) {
final Category category = categories[i];
if (category.getType() == Category.TYPE_USER) {
final MenuItem itemCategory = new MenuItem(menuCategory, SWT.PUSH);
itemCategory.setText(category.getName());
itemCategory.addListener(SWT.Selection, new ListenerDMTask(dms) {
@Override
public void run(DownloadManager dm) {
dm.getDownloadState().setCategory(category);
}
});
}
}
new MenuItem(menuCategory, SWT.SEPARATOR);
}
final MenuItem itemAddCategory = new MenuItem(menuCategory, SWT.PUSH);
Messages.setLanguageText(itemAddCategory, "MyTorrentsView.menu.setCategory.add");
itemAddCategory.addListener(SWT.Selection, new ListenerDMTask(dms) {
@Override
public void run(DownloadManager[] dms) {
CategoryUIUtils.showCreateCategoryDialog(new TagReturner() {
@Override
public void returnedTags(Tag[] tags) {
if (tags.length == 1 && tags[0] instanceof Category) {
assignToCategory(dms, (Category) tags[0]);
}
}
});
}
});
}
use of com.biglybt.ui.UIFunctions.TagReturner in project BiglyBT by BiglySoftware.
the class TaggingView method initialize.
private void initialize() {
if (cMainComposite == null || cMainComposite.isDisposed()) {
if (parent == null || parent.isDisposed()) {
return;
}
sc = new ScrolledComposite(parent, SWT.V_SCROLL);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.getVerticalBar().setIncrement(16);
Layout parentLayout = parent.getLayout();
if (parentLayout instanceof GridLayout) {
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
sc.setLayoutData(gd);
} else if (parentLayout instanceof FormLayout) {
sc.setLayoutData(Utils.getFilledFormData());
}
cMainComposite = new Composite(sc, SWT.NONE);
sc.setContent(cMainComposite);
} else {
Utils.disposeComposite(cMainComposite, false);
}
cMainComposite.setLayout(new GridLayout(1, false));
TagManager tm = TagManagerFactory.getTagManager();
int[] tagTypesWanted = { TagType.TT_DOWNLOAD_MANUAL // TagType.TT_DOWNLOAD_CATEGORY
};
tagButtonsUI = new TagButtonsUI();
List<Tag> listAllTags = new ArrayList<>();
for (int tagType : tagTypesWanted) {
TagType tt = tm.getTagType(tagType);
List<Tag> tags = tt.getTags();
listAllTags.addAll(tags);
}
tagButtonsUI.buildTagGroup(listAllTags, cMainComposite, new TagButtonTrigger() {
@Override
public void tagButtonTriggered(Tag tag, boolean doTag) {
for (Taggable taggable : taggables) {
if (doTag) {
tag.addTaggable(taggable);
} else {
tag.removeTaggable(taggable);
}
swt_updateFields();
}
}
});
Button buttonAdd = new Button(cMainComposite, SWT.PUSH);
buttonAdd.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, false, false));
Messages.setLanguageText(buttonAdd, "label.add.tag");
buttonAdd.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
TagUIUtils.createManualTag(new TagReturner() {
@Override
public void returnedTags(Tag[] tags) {
if (taggables == null) {
return;
}
for (Tag tag : tags) {
for (Taggable taggable : taggables) {
tag.addTaggable(taggable);
}
}
}
});
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
sc.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
Rectangle r = sc.getClientArea();
Point size = cMainComposite.computeSize(r.width, SWT.DEFAULT);
sc.setMinSize(size);
}
});
swt_updateFields();
Rectangle r = sc.getClientArea();
Point size = cMainComposite.computeSize(r.width, SWT.DEFAULT);
sc.setMinSize(size);
}
Aggregations