Search in sources :

Example 1 with TagUIUtilsV3

use of com.biglybt.ui.swt.utils.TagUIUtilsV3 in project BiglyBT by BiglySoftware.

the class BuddyPluginViewInstance method addBuddyTable.

private Comparator<BuddyPluginBuddy> addBuddyTable(Composite child1, boolean is_public) {
    Table buddy_table = new Table(child1, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION | SWT.VIRTUAL);
    List<BuddyPluginBuddy> buddies;
    if (is_public) {
        public_buddy_table = buddy_table;
        buddies = public_buddies;
    } else {
        anon_buddy_table = buddy_table;
        buddies = anon_buddies;
    }
    final String[] headers = { "azbuddy.ui.table.name", "azbuddy.ui.table.online", "azbuddy.ui.table.lastseen", "azbuddy.ui.table.last_ygm", "azbuddy.ui.table.last_msg", "azbuddy.ui.table.loc_cat", "azbuddy.ui.table.rem_cat", "azbuddy.ui.table.read_cat", "azbuddy.ui.table.con", "azbuddy.ui.table.track", "azbuddy.ui.table.msg_in", "azbuddy.ui.table.msg_out", "azbuddy.ui.table.msg_queued", "label.bytesIn", "label.bytesOut", "azbuddy.ui.table.ss" };
    int[] sizes = { 250, 100, 100, 100, 200, 100, 100, 100, 75, 75, 75, 75, 75, 75, 75, 40 };
    int[] aligns = { SWT.LEFT, SWT.CENTER, SWT.CENTER, SWT.CENTER, SWT.CENTER, SWT.LEFT, SWT.LEFT, SWT.LEFT, SWT.LEFT, SWT.CENTER, SWT.CENTER, SWT.CENTER, SWT.CENTER, SWT.CENTER, SWT.CENTER, SWT.CENTER };
    for (int i = 0; i < headers.length; i++) {
        TableColumn tc = new TableColumn(buddy_table, aligns[i]);
        tc.setWidth(sizes[i]);
        Messages.setLanguageText(tc, headers[i]);
    }
    buddy_table.setHeaderVisible(true);
    TableColumn[] columns = buddy_table.getColumns();
    columns[0].setData(new Integer(FilterComparator.FIELD_NAME));
    columns[1].setData(new Integer(FilterComparator.FIELD_ONLINE));
    columns[2].setData(new Integer(FilterComparator.FIELD_LAST_SEEN));
    columns[3].setData(new Integer(FilterComparator.FIELD_YGM));
    columns[4].setData(new Integer(FilterComparator.FIELD_LAST_MSG));
    columns[5].setData(new Integer(FilterComparator.FIELD_LOC_CAT));
    columns[6].setData(new Integer(FilterComparator.FIELD_REM_CAT));
    columns[7].setData(new Integer(FilterComparator.FIELD_READ_CAT));
    columns[8].setData(new Integer(FilterComparator.FIELD_CON));
    columns[9].setData(new Integer(FilterComparator.FIELD_TRACK));
    columns[10].setData(new Integer(FilterComparator.FIELD_MSG_IN));
    columns[11].setData(new Integer(FilterComparator.FIELD_MSG_OUT));
    columns[12].setData(new Integer(FilterComparator.FIELD_QUEUED));
    columns[13].setData(new Integer(FilterComparator.FIELD_BYTES_IN));
    columns[14].setData(new Integer(FilterComparator.FIELD_BYTES_OUT));
    columns[15].setData(new Integer(FilterComparator.FIELD_SS));
    final FilterComparator comparator = new FilterComparator();
    Listener sort_listener = new Listener() {

        @Override
        public void handleEvent(Event e) {
            TableColumn tc = (TableColumn) e.widget;
            int field = ((Integer) tc.getData()).intValue();
            comparator.setField(field);
            Collections.sort(buddies, comparator);
            updateTable(is_public);
        }
    };
    for (int i = 0; i < columns.length; i++) {
        columns[i].addListener(SWT.Selection, sort_listener);
    }
    GridData gridData = new GridData(GridData.FILL_BOTH);
    gridData.heightHint = buddy_table.getHeaderHeight() * 3;
    buddy_table.setLayoutData(gridData);
    buddy_table.addListener(SWT.SetData, new Listener() {

        @Override
        public void handleEvent(Event event) {
            TableItem item = (TableItem) event.item;
            int index = buddy_table.indexOf(item);
            if (index < 0 || index >= buddies.size()) {
                return;
            }
            BuddyPluginBuddy buddy = (BuddyPluginBuddy) buddies.get(index);
            item.setText(0, buddy.getName());
            int os;
            if (buddy.isOnline(false)) {
                os = buddy.getOnlineStatus();
            } else {
                os = BuddyPlugin.STATUS_APPEAR_OFFLINE;
            }
            if (os == BuddyPlugin.STATUS_APPEAR_OFFLINE) {
                item.setText(1, "");
            } else {
                item.setText(1, plugin.getOnlineStatus(os));
            }
            long lo = buddy.getLastTimeOnline();
            item.setText(2, lo == 0 ? "" : new SimpleDateFormat().format(new Date(lo)));
            long last_ygm = buddy.getLastMessagePending();
            item.setText(3, last_ygm == 0 ? "" : new SimpleDateFormat().format(new Date(last_ygm)));
            String lm = buddy.getLastMessageReceived();
            item.setText(4, lm == null ? "" : lm);
            String loc_cat = buddy.getLocalAuthorisedRSSTagsOrCategoriesAsString();
            if (loc_cat == null) {
                loc_cat = "";
            }
            item.setText(5, "" + loc_cat);
            String rem_cat = buddy.getRemoteAuthorisedRSSTagsOrCategoriesAsString();
            if (rem_cat == null) {
                rem_cat = "";
            }
            item.setText(6, "" + rem_cat);
            String read_cat = buddy.getLocalReadTagsOrCategoriesAsString();
            if (read_cat == null) {
                read_cat = "";
            }
            item.setText(7, "" + read_cat);
            item.setText(8, "" + buddy.getConnectionsString());
            item.setText(9, "" + tracker.getTrackingStatus(buddy));
            String in_frag = buddy.getMessageInFragmentDetails();
            item.setText(10, "" + buddy.getMessageInCount() + (in_frag.length() == 0 ? "" : ("+" + in_frag)));
            item.setText(11, "" + buddy.getMessageOutCount());
            item.setText(12, "" + buddy.getMessageHandler().getMessageCount());
            item.setText(13, "" + DisplayFormatters.formatByteCountToKiBEtc(buddy.getBytesInCount()));
            item.setText(14, "" + DisplayFormatters.formatByteCountToKiBEtc(buddy.getBytesOutCount()));
            item.setText(15, "" + buddy.getSubsystem() + " v" + buddy.getVersion());
            item.setData(buddy);
        }
    });
    final Listener tt_label_listener = new Listener() {

        @Override
        public void handleEvent(Event event) {
            Label label = (Label) event.widget;
            Shell shell = label.getShell();
            switch(event.type) {
                case SWT.MouseDown:
                    Event e = new Event();
                    e.item = (TableItem) label.getData("_TABLEITEM");
                    buddy_table.setSelection(new TableItem[] { (TableItem) e.item });
                    buddy_table.notifyListeners(SWT.Selection, e);
                // fall through
                case SWT.MouseExit:
                    shell.dispose();
                    break;
            }
        }
    };
    Listener tt_table_listener = new Listener() {

        private Shell tip = null;

        private Label label = null;

        @Override
        public void handleEvent(Event event) {
            switch(event.type) {
                case SWT.Dispose:
                case SWT.KeyDown:
                case SWT.MouseMove:
                    {
                        if (tip == null)
                            break;
                        tip.dispose();
                        tip = null;
                        label = null;
                        break;
                    }
                case SWT.MouseHover:
                    {
                        Point mouse_position = new Point(event.x, event.y);
                        TableItem item = buddy_table.getItem(mouse_position);
                        if (item != null) {
                            if (tip != null && !tip.isDisposed()) {
                                tip.dispose();
                                tip = null;
                            }
                            int index = buddy_table.indexOf(item);
                            if (index < 0 || index >= buddies.size()) {
                                return;
                            }
                            BuddyPluginBuddy buddy = (BuddyPluginBuddy) buddies.get(index);
                            int item_index = 0;
                            for (int i = 0; i < headers.length; i++) {
                                Rectangle bounds = item.getBounds(i);
                                if (bounds.contains(mouse_position)) {
                                    item_index = i;
                                    break;
                                }
                            }
                            if (item_index != 0) {
                                return;
                            }
                            tip = new Shell(buddy_table.getShell(), SWT.ON_TOP | SWT.TOOL);
                            tip.setLayout(new FillLayout());
                            label = new Label(tip, SWT.NONE);
                            label.setForeground(buddy_table.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
                            label.setBackground(buddy_table.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
                            label.setData("_TABLEITEM", item);
                            label.setText(getToolTip(buddy));
                            label.addListener(SWT.MouseExit, tt_label_listener);
                            label.addListener(SWT.MouseDown, tt_label_listener);
                            Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT);
                            Rectangle rect = item.getBounds(item_index);
                            Point pt = buddy_table.toDisplay(rect.x, rect.y);
                            tip.setBounds(pt.x, pt.y, size.x, size.y);
                            tip.setVisible(true);
                        }
                    }
            }
        }

        protected String getToolTip(BuddyPluginBuddy buddy) {
            List<InetSocketAddress> addresses = buddy.getAdjustedIPs();
            InetSocketAddress ip = buddy.getIP();
            InetSocketAddress adj = buddy.getAdjustedIP();
            InetSocketAddress latest_v4 = buddy.getLatestIP(true);
            InetSocketAddress latest_v6 = buddy.getLatestIP(false);
            Set<InetSocketAddress> all_ips = new HashSet<>();
            all_ips.addAll(addresses);
            all_ips.add(ip);
            all_ips.add(adj);
            all_ips.add(latest_v4);
            all_ips.add(latest_v6);
            all_ips.remove(null);
            String str = "";
            if (all_ips.isEmpty()) {
                str = "<none>";
            } else {
                Set<String> done = new HashSet<>();
                for (InetSocketAddress a : all_ips) {
                    String host = AddressUtils.getHostAddress(a);
                    if (!done.contains(host)) {
                        done.add(host);
                        str += (str.isEmpty() ? "" : ", ") + host;
                    }
                }
            }
            return ("ip=" + str + ",tcp=" + buddy.getTCPPort() + ",udp=" + buddy.getUDPPort());
        }
    };
    buddy_table.addListener(SWT.Dispose, tt_table_listener);
    buddy_table.addListener(SWT.KeyDown, tt_table_listener);
    buddy_table.addListener(SWT.MouseMove, tt_table_listener);
    buddy_table.addListener(SWT.MouseHover, tt_table_listener);
    buddy_table.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent event) {
            if (event.stateMask == SWT.MOD1) {
                int key = event.character;
                if (key <= 26 && key > 0) {
                    key += 'a' - 1;
                }
                if (key == 'a') {
                    buddy_table.selectAll();
                    event.doit = false;
                }
            } else if (event.stateMask == 0 && event.keyCode == SWT.DEL) {
                TableItem[] selection = buddy_table.getSelection();
                String str = "";
                for (int i = 0; i < selection.length; i++) {
                    BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
                    str += (str.isEmpty() ? "" : ", ") + buddy.getName();
                }
                MessageBoxShell mb = new MessageBoxShell(MessageText.getString("message.confirm.delete.title"), MessageText.getString("message.confirm.delete.text", new String[] { str }), new String[] { MessageText.getString("Button.yes"), MessageText.getString("Button.no") }, 1);
                mb.open(new UserPrompterResultListener() {

                    @Override
                    public void prompterClosed(int result) {
                        if (result == 0) {
                            for (int i = 0; i < selection.length; i++) {
                                BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
                                buddy.remove();
                            }
                            buddy_table.setSelection(new int[0]);
                        }
                    }
                });
                event.doit = false;
            }
        }
    });
    final Menu menu = new Menu(buddy_table);
    // send message
    final MenuItem send_msg_item = new MenuItem(menu, SWT.PUSH);
    send_msg_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.send"));
    send_msg_item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            final TableItem[] selection = buddy_table.getSelection();
            UIInputReceiver prompter = ui_instance.getInputReceiver();
            prompter.setLocalisedTitle(lu.getLocalisedMessageText("azbuddy.ui.menu.send"));
            prompter.setLocalisedMessage(lu.getLocalisedMessageText("azbuddy.ui.menu.send_msg"));
            try {
                prompter.prompt(new UIInputReceiverListener() {

                    @Override
                    public void UIInputReceiverClosed(UIInputReceiver prompter) {
                        String text = prompter.getSubmittedInput();
                        if (text != null) {
                            for (int i = 0; i < selection.length; i++) {
                                BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
                                buddy.getPluginNetwork().getAZ2Handler().sendAZ2Message(buddy, text);
                            }
                        }
                    }
                });
            } catch (Throwable e) {
            }
        }
    });
    // chat
    final MenuItem chat_item = new MenuItem(menu, SWT.PUSH);
    chat_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.chat"));
    chat_item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            TableItem[] selection = buddy_table.getSelection();
            BuddyPluginBuddy[] buddies = new BuddyPluginBuddy[selection.length];
            for (int i = 0; i < selection.length; i++) {
                BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
                buddies[i] = buddy;
            }
            plugin.createChat(buddies);
        }
    });
    // ping
    final MenuItem ping_item = new MenuItem(menu, SWT.PUSH);
    ping_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.ping"));
    ping_item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            TableItem[] selection = buddy_table.getSelection();
            for (int i = 0; i < selection.length; i++) {
                BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
                try {
                    buddy.ping();
                } catch (Throwable e) {
                    print("Ping failed", e);
                }
            }
        }
    });
    // cats
    Menu cat_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
    MenuItem cat_item = new MenuItem(menu, SWT.CASCADE);
    Messages.setLanguageText(cat_item, "azbuddy.ui.menu.cat");
    cat_item.setMenu(cat_menu);
    // cats - share
    final MenuItem cat_share_item = new MenuItem(cat_menu, SWT.PUSH);
    cat_share_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.cat.share"));
    cat_share_item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            TableItem[] selection = buddy_table.getSelection();
            List<BuddyPluginBuddy> buddies = new ArrayList<>();
            Set<String> enabled_tags = new HashSet<>();
            for (int i = 0; i < selection.length; i++) {
                BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
                buddies.add(buddy);
                Set<String> et = buddy.getLocalAuthorisedRSSTagsOrCategories();
                if (et == null) {
                    enabled_tags.clear();
                    break;
                } else {
                    if (i == 0) {
                        enabled_tags.addAll(et);
                    } else {
                        enabled_tags.retainAll(et);
                        if (enabled_tags.isEmpty()) {
                            break;
                        }
                    }
                }
            }
            TagManager tm = TagManagerFactory.getTagManager();
            List<Tag> all_tags = tm.getTagType(TagType.TT_DOWNLOAD_CATEGORY).getTags();
            all_tags.addAll(tm.getTagType(TagType.TT_DOWNLOAD_MANUAL).getTags());
            Map<String, Tag> tag_map = new HashMap<>();
            for (Tag t : all_tags) {
                tag_map.put(t.getTagName(true), t);
            }
            List<Tag> selected_tags = new ArrayList<>();
            for (String s : enabled_tags) {
                Tag t = tag_map.get(s);
                if (t != null) {
                    selected_tags.add(t);
                }
            }
            TagUIUtilsV3.showTagSelectionDialog(all_tags, selected_tags, false, (tags) -> {
                Set<String> tag_names = new HashSet<>();
                for (Tag t : tags) {
                    tag_names.add(t.getTagName(true));
                }
                for (BuddyPluginBuddy buddy : buddies) {
                    buddy.setLocalAuthorisedRSSTagsOrCategories(tag_names);
                }
            });
        }
    });
    // cats - subscribe
    final Menu cat_subs_menu = new Menu(cat_menu.getShell(), SWT.DROP_DOWN);
    final MenuItem cat_subs_item = new MenuItem(cat_menu, SWT.CASCADE);
    Messages.setLanguageText(cat_subs_item, "azbuddy.ui.menu.cat_subs");
    cat_subs_item.setMenu(cat_subs_menu);
    cat_subs_menu.addMenuListener(new MenuListener() {

        @Override
        public void menuShown(MenuEvent arg0) {
            MenuItem[] items = cat_subs_menu.getItems();
            for (int i = 0; i < items.length; i++) {
                items[i].dispose();
            }
            final TableItem[] selection = buddy_table.getSelection();
            List<BuddyPluginBuddy> buddies = new ArrayList<>();
            Set<String> avail_cats = new TreeSet<>();
            for (int i = 0; i < selection.length; i++) {
                BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
                buddies.add(buddy);
                Set<String> cats = buddy.getRemoteAuthorisedRSSTagsOrCategories();
                if (cats != null) {
                    avail_cats.addAll(cats);
                }
            }
            for (final String cat : avail_cats) {
                final MenuItem subs_item = new MenuItem(cat_subs_menu, SWT.CHECK);
                subs_item.setText(cat);
                boolean all_subs = true;
                boolean some_subs = false;
                for (BuddyPluginBuddy buddy : buddies) {
                    if (buddy.isSubscribedToCategory(cat)) {
                        some_subs = true;
                    } else {
                        all_subs = false;
                    }
                }
                subs_item.setSelection(all_subs);
                subs_item.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent event) {
                        for (int i = 0; i < selection.length; i++) {
                            BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
                            if (buddy.isRemoteRSSTagOrCategoryAuthorised(cat)) {
                                try {
                                    buddy.subscribeToCategory(cat);
                                } catch (Throwable e) {
                                    print("Failed", e);
                                }
                            }
                        }
                    }
                });
            }
        }

        @Override
        public void menuHidden(MenuEvent arg0) {
        }
    });
    // set local name
    MenuItem set_name_item = new MenuItem(menu, SWT.PUSH);
    set_name_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.setname"));
    set_name_item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            final TableItem[] selection = buddy_table.getSelection();
            UIInputReceiver prompter = ui_instance.getInputReceiver();
            prompter.setLocalisedTitle(lu.getLocalisedMessageText("azbuddy.ui.menu.setname"));
            prompter.setLocalisedMessage(lu.getLocalisedMessageText("azbuddy.ui.menu.setname_msg"));
            try {
                prompter.prompt(new UIInputReceiverListener() {

                    @Override
                    public void UIInputReceiverClosed(UIInputReceiver prompter) {
                        String text = prompter.getSubmittedInput();
                        if (text != null) {
                            text = text.trim();
                            for (int i = 0; i < selection.length; i++) {
                                BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
                                buddy.setMyName(text);
                            }
                        }
                    }
                });
            } catch (Throwable e) {
            }
        }
    });
    MenuItem ygm_item;
    if (Constants.isCVSVersion()) {
        // ygm
        ygm_item = new MenuItem(menu, SWT.PUSH);
        ygm_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.ygm"));
        ygm_item.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent event) {
                TableItem[] selection = buddy_table.getSelection();
                for (int i = 0; i < selection.length; i++) {
                    BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
                    try {
                        buddy.setMessagePending();
                    } catch (Throwable e) {
                        print("YGM failed", e);
                    }
                }
            }
        });
    } else {
        ygm_item = null;
    }
    new MenuItem(menu, SWT.SEPARATOR);
    // get public key
    final MenuItem get_pk_item = new MenuItem(menu, SWT.PUSH);
    get_pk_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.copypk"));
    get_pk_item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            TableItem[] selection = buddy_table.getSelection();
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < selection.length; i++) {
                BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
                sb.append(buddy.getPublicKey()).append("\r\n");
            }
            if (sb.length() > 0) {
                writeToClipboard(sb.toString());
            }
        }
    });
    // encrypt
    final MenuItem encrypt_item = new MenuItem(menu, SWT.PUSH);
    encrypt_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.enc"));
    encrypt_item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            TableItem[] selection = buddy_table.getSelection();
            String str = readFromClipboard();
            if (str != null) {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < selection.length; i++) {
                    BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
                    try {
                        byte[] contents = str.getBytes("UTF-8");
                        BuddyPlugin.CryptoResult result = buddy.encrypt(contents);
                        sb.append("key: ");
                        sb.append(plugin.getPublicKey(is_public));
                        sb.append("\r\n");
                        sb.append("hash: ");
                        sb.append(Base32.encode(result.getChallenge()));
                        sb.append("\r\n");
                        sb.append("payload: ");
                        sb.append(Base32.encode(result.getPayload()));
                        sb.append("\r\n\r\n");
                    } catch (Throwable e) {
                        print("YGM failed", e);
                    }
                }
                writeToClipboard(sb.toString());
            }
        }
    });
    // decrypt
    final MenuItem decrypt_item = new MenuItem(menu, SWT.PUSH);
    decrypt_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.dec"));
    decrypt_item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            String str = readFromClipboard();
            if (str != null) {
                String[] bits = str.split("\n");
                StringBuilder sb = new StringBuilder();
                BuddyPluginBuddy buddy = null;
                byte[] hash = null;
                for (int i = 0; i < bits.length; i++) {
                    String bit = bits[i].trim();
                    if (bit.length() > 0) {
                        int pos = bit.indexOf(':');
                        if (pos == -1) {
                            continue;
                        }
                        String lhs = bit.substring(0, pos).trim();
                        String rhs = bit.substring(pos + 1).trim();
                        if (lhs.equals("key")) {
                            buddy = plugin.getBuddyFromPublicKey(rhs);
                        } else if (lhs.equals("hash")) {
                            hash = Base32.decode(rhs);
                        } else if (lhs.equals("payload")) {
                            byte[] payload = Base32.decode(rhs);
                            if (buddy != null) {
                                try {
                                    BuddyPlugin.CryptoResult result = buddy.decrypt(payload);
                                    byte[] sha1 = new SHA1Simple().calculateHash(result.getChallenge());
                                    sb.append("key: ");
                                    sb.append(buddy.getPublicKey());
                                    sb.append("\r\n");
                                    sb.append("hash_ok: ").append(Arrays.equals(hash, sha1));
                                    sb.append("\r\n");
                                    sb.append("payload: ");
                                    sb.append(new String(result.getPayload(), "UTF-8"));
                                    sb.append("\r\n\r\n");
                                } catch (Throwable e) {
                                    print("decrypt failed", e);
                                }
                            }
                        }
                    }
                }
                if (sb.length() > 0) {
                    writeToClipboard(sb.toString());
                }
            }
        }
    });
    // sign
    final MenuItem sign_item = new MenuItem(menu, SWT.PUSH);
    sign_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.sign"));
    sign_item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            String str = readFromClipboard();
            if (str != null) {
                StringBuilder sb = new StringBuilder();
                try {
                    sb.append("key: ");
                    sb.append(plugin.getPublicKey(is_public));
                    sb.append("\r\n");
                    byte[] payload = str.getBytes("UTF-8");
                    sb.append("data: ");
                    sb.append(Base32.encode(payload));
                    sb.append("\r\n");
                    byte[] sig = plugin.sign(is_public, payload);
                    sb.append("sig: ");
                    sb.append(Base32.encode(sig));
                    sb.append("\r\n");
                } catch (Throwable e) {
                    print("sign failed", e);
                }
                if (sb.length() > 0) {
                    writeToClipboard(sb.toString());
                }
            }
        }
    });
    // verify
    final MenuItem verify_item = new MenuItem(menu, SWT.PUSH);
    verify_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.verify"));
    verify_item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            String str = readFromClipboard();
            if (str != null) {
                String[] bits = str.split("\n");
                StringBuilder sb = new StringBuilder();
                String pk = null;
                byte[] data = null;
                for (int i = 0; i < bits.length; i++) {
                    String bit = bits[i].trim();
                    if (bit.length() > 0) {
                        int pos = bit.indexOf(':');
                        if (pos == -1) {
                            continue;
                        }
                        String lhs = bit.substring(0, pos).trim();
                        String rhs = bit.substring(pos + 1).trim();
                        if (lhs.equals("key")) {
                            pk = rhs;
                        } else if (lhs.equals("data")) {
                            data = Base32.decode(rhs);
                        } else if (lhs.equals("sig")) {
                            byte[] sig = Base32.decode(rhs);
                            if (pk != null && data != null) {
                                try {
                                    sb.append("key: ");
                                    sb.append(pk);
                                    sb.append("\r\n");
                                    boolean ok = plugin.verify(is_public, pk, data, sig);
                                    sb.append("sig_ok: ").append(ok);
                                    sb.append("\r\n");
                                    sb.append("data: ");
                                    sb.append(new String(data, "UTF-8"));
                                    sb.append("\r\n\r\n");
                                } catch (Throwable e) {
                                    print("decrypt failed", e);
                                }
                            }
                        }
                    }
                }
                if (sb.length() > 0) {
                    writeToClipboard(sb.toString());
                }
            }
        }
    });
    new MenuItem(menu, SWT.SEPARATOR);
    // disconnect message
    final MenuItem disconnect_msg_item;
    if (Constants.isCVSVersion()) {
        disconnect_msg_item = new MenuItem(menu, SWT.PUSH);
        disconnect_msg_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.disconnect"));
        disconnect_msg_item.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent event) {
                TableItem[] selection = buddy_table.getSelection();
                for (int i = 0; i < selection.length; i++) {
                    BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
                    buddy.disconnect();
                }
            }
        });
    } else {
        disconnect_msg_item = null;
    }
    final MenuItem remove_item = new MenuItem(menu, SWT.PUSH);
    remove_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.remove"));
    Utils.setMenuItemImage(remove_item, "delete");
    remove_item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            TableItem[] selection = buddy_table.getSelection();
            for (int i = 0; i < selection.length; i++) {
                BuddyPluginBuddy buddy = (BuddyPluginBuddy) selection[i].getData();
                buddy.remove();
            }
        }
    });
    // done with menus
    buddy_table.setMenu(menu);
    menu.addMenuListener(new MenuListener() {

        @Override
        public void menuShown(MenuEvent arg0) {
            boolean available = plugin.isAvailable();
            TableItem[] selection = buddy_table.getSelection();
            remove_item.setEnabled(selection.length > 0);
            get_pk_item.setEnabled(available && selection.length > 0);
            if (disconnect_msg_item != null) {
                disconnect_msg_item.setEnabled(selection.length > 0);
            }
            send_msg_item.setEnabled(available && selection.length > 0);
            chat_item.setEnabled(available && selection.length > 0);
            ping_item.setEnabled(available && selection.length > 0);
            if (ygm_item != null) {
                ygm_item.setEnabled(available && selection.length > 0);
            }
            encrypt_item.setEnabled(selection.length > 0);
            decrypt_item.setEnabled(true);
            sign_item.setEnabled(true);
            verify_item.setEnabled(true);
            cat_item.setEnabled(selection.length > 0);
            set_name_item.setEnabled(selection.length == 1);
        }

        @Override
        public void menuHidden(MenuEvent arg0) {
        }
    });
    return (comparator);
}
Also used : Messages(com.biglybt.ui.swt.Messages) COConfigurationManager(com.biglybt.core.config.COConfigurationManager) TagManagerFactory(com.biglybt.core.tag.TagManagerFactory) Colors(com.biglybt.ui.swt.mainwindow.Colors) UIFunctionsManager(com.biglybt.ui.UIFunctionsManager) Point(org.eclipse.swt.graphics.Point) Clipboard(org.eclipse.swt.dnd.Clipboard) Utils(com.biglybt.ui.swt.Utils) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) org.eclipse.swt.custom(org.eclipse.swt.custom) IntSwtParameter(com.biglybt.ui.swt.config.IntSwtParameter) LocaleUtilities(com.biglybt.pif.utils.LocaleUtilities) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) org.eclipse.swt.layout(org.eclipse.swt.layout) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader) MessageText(com.biglybt.core.internat.MessageText) InetSocketAddress(java.net.InetSocketAddress) Transfer(org.eclipse.swt.dnd.Transfer) com.biglybt.plugin.net.buddy(com.biglybt.plugin.net.buddy) List(java.util.List) CryptoManagerKeyListener(com.biglybt.core.security.CryptoManagerKeyListener) SWT(org.eclipse.swt.SWT) TagUIUtilsV3(com.biglybt.ui.swt.utils.TagUIUtilsV3) UIFunctions(com.biglybt.ui.UIFunctions) UIManagerEvent(com.biglybt.pif.ui.UIManagerEvent) java.util(java.util) Tag(com.biglybt.core.tag.Tag) TagManager(com.biglybt.core.tag.TagManager) I2PHelpers(com.biglybt.plugin.I2PHelpers) CryptoManagerFactory(com.biglybt.core.security.CryptoManagerFactory) SimpleDateFormat(java.text.SimpleDateFormat) Image(org.eclipse.swt.graphics.Image) Rectangle(org.eclipse.swt.graphics.Rectangle) CryptoManager(com.biglybt.core.security.CryptoManager) BuddyPluginTracker(com.biglybt.plugin.net.buddy.tracker.BuddyPluginTracker) CryptoHandler(com.biglybt.core.security.CryptoHandler) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) PluginInterface(com.biglybt.pif.PluginInterface) TextTransfer(org.eclipse.swt.dnd.TextTransfer) UIInstance(com.biglybt.pif.ui.UIInstance) org.eclipse.swt.events(org.eclipse.swt.events) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) org.eclipse.swt.widgets(org.eclipse.swt.widgets) LinkLabel(com.biglybt.ui.swt.components.LinkLabel) com.biglybt.core.util(com.biglybt.core.util) Color(org.eclipse.swt.graphics.Color) TagType(com.biglybt.core.tag.TagType) ClipboardCopy(com.biglybt.ui.swt.mainwindow.ClipboardCopy) PluginConfig(com.biglybt.pif.PluginConfig) InetSocketAddress(java.net.InetSocketAddress) LinkLabel(com.biglybt.ui.swt.components.LinkLabel) Rectangle(org.eclipse.swt.graphics.Rectangle) List(java.util.List) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) CryptoManagerKeyListener(com.biglybt.core.security.CryptoManagerKeyListener) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) TagManager(com.biglybt.core.tag.TagManager) UIManagerEvent(com.biglybt.pif.ui.UIManagerEvent) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) Tag(com.biglybt.core.tag.Tag) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with TagUIUtilsV3

use of com.biglybt.ui.swt.utils.TagUIUtilsV3 in project BiglyBT by BiglySoftware.

the class TagUIUtils method createSideBarMenuItems.

public static void createSideBarMenuItems(final Menu menu, final Tag tag) {
    if (tag instanceof Category) {
        CategoryUIUtils.createMenuItems(menu, (Category) tag);
        return;
    }
    int userMode = COConfigurationManager.getIntParameter("User Mode");
    final TagType tag_type = tag.getTagType();
    boolean needs_separator_next = false;
    int countBefore = menu.getItemCount();
    if (tag_type.hasTagTypeFeature(TagFeature.TF_RATE_LIMIT)) {
        createTF_RateLimitMenuItems(menu, tag, tag_type, userMode);
    }
    if (tag_type.hasTagTypeFeature(TagFeature.TF_RUN_STATE)) {
        createTF_RunState(menu, tag);
    }
    if (tag_type.hasTagTypeFeature(TagFeature.TF_FILE_LOCATION)) {
        createTF_FileLocationMenuItems(menu, tag);
    }
    if (tag_type.hasTagTypeFeature(TagFeature.TF_EXEC_ON_ASSIGN)) {
        final TagFeatureExecOnAssign tf_eoa = (TagFeatureExecOnAssign) tag;
        int supported_actions = tf_eoa.getSupportedActions();
        if (supported_actions != TagFeatureExecOnAssign.ACTION_NONE) {
            final Menu eoa_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
            MenuItem eoa_item = new MenuItem(menu, SWT.CASCADE);
            Messages.setLanguageText(eoa_item, "label.exec.on.assign");
            eoa_item.setMenu(eoa_menu);
            boolean is_peer_set = tag.getTagType().getTagType() == TagType.TT_PEER_IPSET;
            int[] action_ids = { TagFeatureExecOnAssign.ACTION_APPLY_OPTIONS_TEMPLATE, TagFeatureExecOnAssign.ACTION_DESTROY, TagFeatureExecOnAssign.ACTION_START, TagFeatureExecOnAssign.ACTION_FORCE_START, TagFeatureExecOnAssign.ACTION_NOT_FORCE_START, TagFeatureExecOnAssign.ACTION_STOP, TagFeatureExecOnAssign.ACTION_QUEUE, TagFeatureExecOnAssign.ACTION_PAUSE, TagFeatureExecOnAssign.ACTION_RESUME, TagFeatureExecOnAssign.ACTION_SCRIPT, TagFeatureExecOnAssign.ACTION_POST_MAGNET_URI, TagFeatureExecOnAssign.ACTION_MOVE_INIT_SAVE_LOC, TagFeatureExecOnAssign.ACTION_ASSIGN_TAGS, TagFeatureExecOnAssign.ACTION_REMOVE_TAGS, TagFeatureExecOnAssign.ACTION_HOST, TagFeatureExecOnAssign.ACTION_PUBLISH };
            String[] action_keys = { "label.apply.options.template", is_peer_set ? "azbuddy.ui.menu.disconnect" : "v3.MainWindow.button.delete", "v3.MainWindow.button.start", "v3.MainWindow.button.forcestart", "v3.MainWindow.button.notforcestart", "v3.MainWindow.button.stop", "ConfigView.section.queue", "v3.MainWindow.button.pause", "v3.MainWindow.button.resume", "label.script", "label.post.magnet.to.chat", "label.init.save.loc.move", "label.assign.tags", "label.remove.tags", "menu.host.on.tracker", "menu.publish.on.tracker" };
            for (int i = 0; i < action_ids.length; i++) {
                final int action_id = action_ids[i];
                if (tf_eoa.supportsAction(action_id)) {
                    if (action_id == TagFeatureExecOnAssign.ACTION_APPLY_OPTIONS_TEMPLATE) {
                        final MenuItem opts_item = new MenuItem(eoa_menu, SWT.CHECK);
                        opts_item.setText(MessageText.getString(action_keys[i]) + "...");
                        opts_item.setSelection(tf_eoa.getOptionsTemplateHandler().isActive());
                        opts_item.addListener(SWT.Selection, new Listener() {

                            @Override
                            public void handleEvent(Event event) {
                                UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
                                if (uiFunctions != null) {
                                    uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_OPTIONS, tf_eoa.getOptionsTemplateHandler());
                                }
                            }
                        });
                        new MenuItem(eoa_menu, SWT.SEPARATOR);
                    } else if (action_id == TagFeatureExecOnAssign.ACTION_SCRIPT) {
                        new MenuItem(eoa_menu, SWT.SEPARATOR);
                        final MenuItem action_item = new MenuItem(eoa_menu, SWT.PUSH);
                        String script = tf_eoa.getActionScript();
                        if (script.length() > 23) {
                            script = script.substring(0, 20) + "...";
                        }
                        String msg = MessageText.getString(action_keys[i]);
                        if (script.length() > 0) {
                            msg += ": " + script;
                        }
                        msg += "...";
                        action_item.setText(msg);
                        action_item.addListener(SWT.Selection, new Listener() {

                            @Override
                            public void handleEvent(Event event) {
                                String msg = MessageText.getString("UpdateScript.message");
                                SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("UpdateScript.title", "!" + msg + "!");
                                entryWindow.setPreenteredText(tf_eoa.getActionScript(), false);
                                entryWindow.selectPreenteredText(true);
                                entryWindow.prompt(new UIInputReceiverListener() {

                                    @Override
                                    public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
                                        if (entryWindow.hasSubmittedInput()) {
                                            String text = entryWindow.getSubmittedInput().trim();
                                            tf_eoa.setActionScript(text);
                                        }
                                    }
                                });
                            }
                        });
                    } else if (action_id == TagFeatureExecOnAssign.ACTION_POST_MAGNET_URI) {
                        String chat_str = tf_eoa.getPostMessageChannel();
                        MenuBuildUtils.addChatSelectionMenu(eoa_menu, "label.post.magnet.to.chat", chat_str, new MenuBuildUtils.ChatSelectionListener() {

                            @Override
                            public void chatSelected(Object target, String chat) {
                                tf_eoa.setPostMessageChannel(chat);
                            }

                            @Override
                            public void chatAvailable(Object target, ChatInstance chat) {
                            }
                        });
                    } else if (action_id == TagFeatureExecOnAssign.ACTION_ASSIGN_TAGS || action_id == TagFeatureExecOnAssign.ACTION_REMOVE_TAGS) {
                        boolean is_assign = action_id == TagFeatureExecOnAssign.ACTION_ASSIGN_TAGS;
                        final MenuItem action_item = new MenuItem(eoa_menu, SWT.PUSH);
                        List<Tag> tags = is_assign ? tf_eoa.getTagAssigns() : tf_eoa.getTagRemoves();
                        String msg = MessageText.getString(action_keys[i]);
                        String tag_str = "";
                        for (Tag t : tags) {
                            tag_str += (tag_str == "" ? "" : ",") + t.getTagName(true);
                        }
                        if (!tag_str.isEmpty()) {
                            msg += ": " + tag_str;
                        }
                        msg += "...";
                        action_item.setText(msg);
                        action_item.addListener(SWT.Selection, new Listener() {

                            @Override
                            public void handleEvent(Event event) {
                                TagManager tagManager = TagManagerFactory.getTagManager();
                                TagType tt = tagManager.getTagType(TagType.TT_DOWNLOAD_CATEGORY);
                                List<Tag> all_tags = new ArrayList<>(tt.getTags());
                                tt = tagManager.getTagType(TagType.TT_DOWNLOAD_MANUAL);
                                all_tags.addAll(tt.getTags());
                                all_tags.remove(tag);
                                TagUIUtilsV3.showTagSelectionDialog(all_tags, tags, new TagUIUtilsV3.TagSelectionListener() {

                                    @Override
                                    public void selected(List<Tag> tags) {
                                        if (is_assign) {
                                            tf_eoa.setTagAssigns(tags);
                                        } else {
                                            tf_eoa.setTagRemoves(tags);
                                        }
                                    }
                                });
                            }
                        });
                    } else {
                        if (action_id == TagFeatureExecOnAssign.ACTION_HOST) {
                            new MenuItem(eoa_menu, SWT.SEPARATOR);
                        }
                        final MenuItem action_item = new MenuItem(eoa_menu, SWT.CHECK);
                        Messages.setLanguageText(action_item, action_keys[i]);
                        action_item.setSelection(tf_eoa.isActionEnabled(action_id));
                        action_item.addListener(SWT.Selection, new Listener() {

                            @Override
                            public void handleEvent(Event event) {
                                tf_eoa.setActionEnabled(action_id, action_item.getSelection());
                            }
                        });
                        if (action_id == TagFeatureExecOnAssign.ACTION_MOVE_INIT_SAVE_LOC) {
                            TagFeatureFileLocation fl = (TagFeatureFileLocation) tag;
                            boolean enable = false;
                            if (fl.supportsTagInitialSaveFolder()) {
                                File f = fl.getTagInitialSaveFolder();
                                enable = f != null;
                            }
                            action_item.setEnabled(enable);
                        }
                    }
                }
            }
        }
    }
    if (tag instanceof TagDownload) {
        needs_separator_next = true;
        MenuItem itemOptions = new MenuItem(menu, SWT.PUSH);
        final Set<DownloadManager> dms = ((TagDownload) tag).getTaggedDownloads();
        Messages.setLanguageText(itemOptions, "cat.options");
        itemOptions.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
                if (uiFunctions != null) {
                    uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_OPTIONS, dms.toArray(new DownloadManager[dms.size()]));
                }
            }
        });
        if (dms.size() == 0) {
            itemOptions.setEnabled(false);
        }
    }
    if (userMode > 0) {
        createTFProperitesMenuItems(menu, tag);
    }
    if (menu.getItemCount() > countBefore) {
        needs_separator_next = true;
    }
    if (needs_separator_next) {
        new MenuItem(menu, SWT.SEPARATOR);
        needs_separator_next = false;
    }
    /* Seldom Used: Can be set in Tags Overview
		// sharing
		if ( tag.canBePublic()){

			needs_separator_next = true;

			final MenuItem itemPublic = new MenuItem(menu, SWT.CHECK );

			itemPublic.setSelection( tag.isPublic());

			Messages.setLanguageText(itemPublic, "tag.share");

			itemPublic.addListener(SWT.Selection, new Listener() {
				public void handleEvent(Event event) {

					tag.setPublic( itemPublic.getSelection());
				}});
		}
		*/
    int tt = tag_type.getTagType();
    if (tt == TagType.TT_DOWNLOAD_MANUAL || tt == TagType.TT_SWARM_TAG) {
        needs_separator_next = true;
        MenuItem search = new MenuItem(menu, SWT.PUSH);
        Messages.setLanguageText(search, "tag.search");
        search.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                UIFunctionsManager.getUIFunctions().doSearch("tag:" + tag.getTagName(true).replace(' ', '+'));
            }
        });
    }
    // share with friends
    addShareWithFriendsMenuItems(menu, tag, tag_type);
    if (tag_type.hasTagTypeFeature(TagFeature.TF_RSS_FEED)) {
        final TagFeatureRSSFeed tfrss = (TagFeatureRSSFeed) tag;
        // rss feed
        final MenuItem rssOption = new MenuItem(menu, SWT.CHECK);
        rssOption.setSelection(tfrss.isTagRSSFeedEnabled());
        Messages.setLanguageText(rssOption, "cat.rss.gen");
        rssOption.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                boolean set = rssOption.getSelection();
                tfrss.setTagRSSFeedEnabled(set);
            }
        });
    }
    if (tag_type.hasTagTypeFeature(TagFeature.TF_XCODE)) {
        createXCodeMenuItems(menu, tag);
    }
    if (tag_type.hasTagTypeFeature(TagFeature.TF_NOTIFICATIONS)) {
        TagFeatureNotifications tfn = (TagFeatureNotifications) tag;
        String chat_str = tfn.getNotifyMessageChannel();
        MenuBuildUtils.addChatSelectionMenu(menu, "label.notify.magnets.to.chat", chat_str, new MenuBuildUtils.ChatSelectionListener() {

            @Override
            public void chatSelected(Object target, String chat) {
                tfn.setNotifyMessageChannel(chat);
            }

            @Override
            public void chatAvailable(Object target, ChatInstance chat) {
            }
        });
    }
    needs_separator_next = true;
    if (tag_type.getTagType() == TagType.TT_DOWNLOAD_MANUAL) {
        MenuBuildUtils.addChatMenu(menu, "menu.discuss.tag", getChatKey(tag));
    }
    MenuItem itemShowStats = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(itemShowStats, "tag.show.stats");
    itemShowStats.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
            uiFunctions.getMDI().loadEntryByID(StatsView.VIEW_ID, true, false, "TagStatsView");
        }
    });
    if (tag.getTaggableTypes() == Taggable.TT_DOWNLOAD) {
        MenuItem itemShowFiles = new MenuItem(menu, SWT.PUSH);
        Messages.setLanguageText(itemShowFiles, "menu.show.files");
        itemShowFiles.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                showFilesView((TagDownload) tag);
            }
        });
    }
    if (needs_separator_next) {
        new MenuItem(menu, SWT.SEPARATOR);
        needs_separator_next = false;
    }
    boolean auto = tag_type.isTagTypeAuto();
    boolean closable = auto;
    if (tag.getTaggableTypes() == Taggable.TT_DOWNLOAD) {
        // extended closable tags to include manual ones due to user request
        closable = true;
    }
    Menu[] menuShowHide = { null };
    if (closable) {
        createCloseableMenuItems(menu, tag, tag_type, menuShowHide, needs_separator_next);
    }
    if (!auto) {
        createNonAutoMenuItems(menu, tag, tag_type, menuShowHide);
    }
    if (tag_type.getTagType() == TagType.TT_DOWNLOAD_MANUAL) {
        MenuItem itemDuplicate = new MenuItem(menu, SWT.PUSH);
        Messages.setLanguageText(itemDuplicate, "Subscription.menu.duplicate");
        itemDuplicate.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                duplicate(Collections.singletonList(tag));
            }
        });
        MenuItem itemExport = new MenuItem(menu, SWT.PUSH);
        Messages.setLanguageText(itemExport, "Subscription.menu.export");
        itemExport.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                export(Collections.singletonList(tag));
            }
        });
    }
    MenuItem menuSettings = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(menuSettings, "TagSettingsView.title");
    menuSettings.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
            tag.setTransientProperty(Tag.TP_SETTINGS_REQUESTED, true);
            uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TAGS, tag);
        }
    });
    com.biglybt.pif.ui.menus.MenuItem[] items = MenuItemManager.getInstance().getAllAsArray(MenuManager.MENU_TAG_CONTEXT);
    if (items.length > 0) {
        MenuFactory.addSeparatorMenuItem(menu);
        // TODO: Don't send Tag.. send a yet-to-be-created plugin interface version of Tag
        MenuBuildUtils.addPluginMenuItems(items, menu, true, true, new MenuBuildUtils.MenuItemPluginMenuControllerImpl(new Tag[] { tag }));
    }
}
Also used : Category(com.biglybt.core.category.Category) DisposeListener(org.eclipse.swt.events.DisposeListener) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) MenuListener(org.eclipse.swt.events.MenuListener) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) TrackerEditorListener(com.biglybt.ui.swt.maketorrent.TrackerEditorListener) ChatInstance(com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance) DownloadManager(com.biglybt.core.download.DownloadManager) UIFunctions(com.biglybt.ui.UIFunctions) List(java.util.List) TagUIUtilsV3(com.biglybt.ui.swt.utils.TagUIUtilsV3) Point(org.eclipse.swt.graphics.Point) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) DisposeEvent(org.eclipse.swt.events.DisposeEvent) MenuEvent(org.eclipse.swt.events.MenuEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) File(java.io.File)

Aggregations

UIInputReceiver (com.biglybt.pif.ui.UIInputReceiver)2 UIInputReceiverListener (com.biglybt.pif.ui.UIInputReceiverListener)2 UIFunctions (com.biglybt.ui.UIFunctions)2 UserPrompterResultListener (com.biglybt.ui.UserPrompterResultListener)2 TagUIUtilsV3 (com.biglybt.ui.swt.utils.TagUIUtilsV3)2 List (java.util.List)2 Point (org.eclipse.swt.graphics.Point)2 CoreRunningListener (com.biglybt.core.CoreRunningListener)1 Category (com.biglybt.core.category.Category)1 COConfigurationManager (com.biglybt.core.config.COConfigurationManager)1 DownloadManager (com.biglybt.core.download.DownloadManager)1 MessageText (com.biglybt.core.internat.MessageText)1 CryptoHandler (com.biglybt.core.security.CryptoHandler)1 CryptoManager (com.biglybt.core.security.CryptoManager)1 CryptoManagerFactory (com.biglybt.core.security.CryptoManagerFactory)1 CryptoManagerKeyListener (com.biglybt.core.security.CryptoManagerKeyListener)1 Tag (com.biglybt.core.tag.Tag)1 TagManager (com.biglybt.core.tag.TagManager)1 TagManagerFactory (com.biglybt.core.tag.TagManagerFactory)1 TagType (com.biglybt.core.tag.TagType)1