Search in sources :

Example 1 with TagButtonTrigger

use of com.biglybt.ui.swt.views.utils.TagButtonsUI.TagButtonTrigger 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)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