Search in sources :

Example 1 with TagReturner

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]);
                    }
                }
            });
        }
    });
}
Also used : TagReturner(com.biglybt.ui.UIFunctions.TagReturner) Category(com.biglybt.core.category.Category) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 2 with TagReturner

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);
}
Also used : TagReturner(com.biglybt.ui.UIFunctions.TagReturner) ArrayList(java.util.ArrayList) Rectangle(org.eclipse.swt.graphics.Rectangle) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) TagButtonsUI(com.biglybt.ui.swt.views.utils.TagButtonsUI) TagButtonTrigger(com.biglybt.ui.swt.views.utils.TagButtonsUI.TagButtonTrigger) FormLayout(org.eclipse.swt.layout.FormLayout) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) Layout(org.eclipse.swt.widgets.Layout) FormLayout(org.eclipse.swt.layout.FormLayout) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData)

Aggregations

TagReturner (com.biglybt.ui.UIFunctions.TagReturner)2 Category (com.biglybt.core.category.Category)1 DownloadManager (com.biglybt.core.download.DownloadManager)1 TagButtonsUI (com.biglybt.ui.swt.views.utils.TagButtonsUI)1 TagButtonTrigger (com.biglybt.ui.swt.views.utils.TagButtonsUI.TagButtonTrigger)1 ArrayList (java.util.ArrayList)1 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)1 Point (org.eclipse.swt.graphics.Point)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 FormLayout (org.eclipse.swt.layout.FormLayout)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Layout (org.eclipse.swt.widgets.Layout)1