Search in sources :

Example 1 with UIInputReceiverListener

use of com.biglybt.pif.ui.UIInputReceiverListener in project BiglyBT by BiglySoftware.

the class TableViewSWT_Common method fillColumnMenu.

/**
 * SubMenu for column specific tasks.
 *
 * @param iColumn Column # that tasks apply to.
 */
public void fillColumnMenu(final Menu menu, final TableColumnCore column, boolean isBlankArea) {
    String tableID = tv.getTableID();
    int hiddenColumnCount = 0;
    if (!isBlankArea) {
        TableColumnManager tcm = TableColumnManager.getInstance();
        TableColumnCore[] allTableColumns = tcm.getAllTableColumnCoreAsArray(tv.getDataSourceType(), tableID);
        Arrays.sort(allTableColumns, TableColumnManager.getTableColumnOrderComparator());
        for (final TableColumnCore tc : allTableColumns) {
            boolean visible = tc.isVisible();
            if (!visible) {
                TableColumnInfo columnInfo = tcm.getColumnInfo(tv.getDataSourceType(), tableID, tc.getName());
                if (columnInfo.getProficiency() != TableColumnInfo.PROFICIENCY_BEGINNER) {
                    hiddenColumnCount++;
                    continue;
                }
            }
            MenuItem menuItem = new MenuItem(menu, SWT.CHECK);
            Messages.setLanguageText(menuItem, tc.getTitleLanguageKey());
            if (visible) {
                menuItem.setSelection(true);
            }
            menuItem.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event e) {
                    tc.setVisible(!tc.isVisible());
                    TableColumnManager tcm = TableColumnManager.getInstance();
                    String tableID = tv.getTableID();
                    tcm.saveTableColumns(tv.getDataSourceType(), tableID);
                    if (tv instanceof TableStructureModificationListener) {
                        ((TableStructureModificationListener) tv).tableStructureChanged(true, null);
                    }
                    TableStructureEventDispatcher.getInstance(tableID).tableStructureChanged(true, null);
                }
            });
        }
    }
    if (hiddenColumnCount > 0) {
        MenuItem itemMoreHidden = new MenuItem(menu, SWT.PUSH);
        Messages.setLanguageText(itemMoreHidden, "MyTorrentsView.menu.moreColHidden", new String[] { String.valueOf(hiddenColumnCount) });
        itemMoreHidden.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event e) {
                showColumnEditor();
            }
        });
    }
    if (menu.getItemCount() > 0) {
        new MenuItem(menu, SWT.SEPARATOR);
    }
    if (column != null) {
        final MenuItem renameColumn = new MenuItem(menu, SWT.PUSH);
        Messages.setLanguageText(renameColumn, "MyTorrentsView.menu.renameColumn");
        renameColumn.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event e) {
                SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("ColumnRenameWindow.title", "ColumnRenameWindow.message");
                String existing_name = column.getNameOverride();
                if (existing_name == null) {
                    existing_name = "";
                }
                entryWindow.setPreenteredText(existing_name, false);
                entryWindow.selectPreenteredText(true);
                entryWindow.prompt(new UIInputReceiverListener() {

                    @Override
                    public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
                        if (!entryWindow.hasSubmittedInput()) {
                            return;
                        }
                        String name = entryWindow.getSubmittedInput().trim();
                        if (name.length() == 0) {
                            name = null;
                        }
                        column.setNameOverride(name);
                        TableColumnManager tcm = TableColumnManager.getInstance();
                        String tableID = tv.getTableID();
                        tcm.saveTableColumns(tv.getDataSourceType(), tableID);
                        TableStructureEventDispatcher.getInstance(tableID).tableStructureChanged(true, null);
                    }
                });
            }
        });
        final MenuItem itemPrefSize = new MenuItem(menu, SWT.PUSH);
        Messages.setLanguageText(itemPrefSize, "table.columns.pref.size");
        itemPrefSize.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event e) {
                Utils.execSWTThread(new Runnable() {

                    @Override
                    public void run() {
                        column.setPreferredWidth(-1);
                        tv.runForAllRows(new TableGroupRowRunner() {

                            @Override
                            public void run(TableRowCore row) {
                                row.fakeRedraw(column.getName());
                            }
                        });
                        int pref = column.getPreferredWidth();
                        if (pref != -1) {
                            column.setWidth(pref);
                        }
                    }
                });
            }
        });
    }
    final MenuItem itemResetColumns = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(itemResetColumns, "table.columns.reset");
    itemResetColumns.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            String tableID = tv.getTableID();
            TableColumnManager tcm = TableColumnManager.getInstance();
            tcm.resetColumns(tv.getDataSourceType(), tableID);
        }
    });
    final MenuItem itemChangeTable = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(itemChangeTable, "MyTorrentsView.menu.editTableColumns");
    Utils.setMenuItemImage(itemChangeTable, "columns");
    itemChangeTable.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            showColumnEditor();
        }
    });
    menu.setData("column", column);
    if (column == null) {
        return;
    }
    String sColumnName = column.getName();
    if (sColumnName != null) {
        Object[] listeners = listenersMenuFill.toArray();
        for (int i = 0; i < listeners.length; i++) {
            TableViewSWTMenuFillListener l = (TableViewSWTMenuFillListener) listeners[i];
            l.addThisColumnSubMenu(sColumnName, menu);
        }
    }
    final MenuItem at_item = new MenuItem(menu, SWT.CHECK);
    Messages.setLanguageText(at_item, "MyTorrentsView.menu.thisColumn.autoTooltip");
    at_item.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            TableColumnCore tcc = (TableColumnCore) menu.getData("column");
            tcc.setAutoTooltip(at_item.getSelection());
            tcc.invalidateCells();
        }
    });
    at_item.setSelection(column.doesAutoTooltip());
    at_item.setEnabled(!TableTooltips.tooltips_disabled);
    // Add Plugin Context menus..
    TableContextMenuItem[] items = column.getContextMenuItems(TableColumnCore.MENU_STYLE_HEADER);
    if (items.length > 0) {
        new MenuItem(menu, SWT.SEPARATOR);
        MenuBuildUtils.addPluginMenuItems(items, menu, true, true, new MenuBuildUtils.MenuItemPluginMenuControllerImpl(tv.getSelectedDataSources(true)));
    }
}
Also used : UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) TableColumnManager(com.biglybt.ui.common.table.impl.TableColumnManager) SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) MenuBuildUtils(com.biglybt.ui.swt.MenuBuildUtils)

Example 2 with UIInputReceiverListener

use of com.biglybt.pif.ui.UIInputReceiverListener in project BiglyBT by BiglySoftware.

the class ManagerUtils method findMoreLikeThis.

private static void findMoreLikeThis(final DownloadManager dm, final DiskManagerFileInfo file, Shell shell) {
    String expression = file == null ? dm.getDisplayName() : file.getFile(true).getName();
    SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("find.more.like.title", "find.more.like.msg");
    entryWindow.setPreenteredText(expression, false);
    entryWindow.selectPreenteredText(true);
    entryWindow.prompt(new UIInputReceiverListener() {

        @Override
        public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
            if (!entryWindow.hasSubmittedInput()) {
                return;
            }
            String expression = entryWindow.getSubmittedInput();
            if (expression != null && expression.trim().length() > 0) {
                expression = expression.trim();
                try {
                    PluginInterface pi = CoreFactory.getSingleton().getPluginManager().getPluginInterfaceByID("aercm");
                    if (pi != null && pi.getPluginState().isOperational() && pi.getIPC().canInvoke("lookupByExpression", new Object[] { "", new String[0], new HashMap() })) {
                        Map<String, Object> options = new HashMap<>();
                        options.put("Subscription", true);
                        options.put("Name", MessageText.getString("label.more") + ": " + expression);
                        pi.getIPC().invoke("lookupByExpression", new Object[] { expression, dm.getDownloadState().getNetworks(), options });
                    }
                } catch (Throwable e) {
                    Debug.out(e);
                }
            }
        }
    });
}
Also used : SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) PluginInterface(com.biglybt.pif.PluginInterface) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener)

Example 3 with UIInputReceiverListener

use of com.biglybt.pif.ui.UIInputReceiverListener in project BiglyBT by BiglySoftware.

the class TagUIUtils method createTFProperitesMenuItems.

private static void createTFProperitesMenuItems(Menu menu, Tag tag) {
    TagFeatureProperties props = (TagFeatureProperties) tag;
    TagProperty[] tps = props.getSupportedProperties();
    if (tps.length > 0) {
        final Menu props_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
        MenuItem props_item = new MenuItem(menu, SWT.CASCADE);
        Messages.setLanguageText(props_item, "label.properties");
        props_item.setMenu(props_menu);
        for (final TagProperty tp : tps) {
            if (tp.getType() == TagFeatureProperties.PT_STRING_LIST) {
                String tp_name = tp.getName(false);
                if (tp_name.equals(TagFeatureProperties.PR_CONSTRAINT)) {
                    MenuItem const_item = new MenuItem(props_menu, SWT.PUSH);
                    Messages.setLanguageText(const_item, "label.contraints");
                    const_item.addListener(SWT.Selection, new Listener() {

                        @Override
                        public void handleEvent(Event event) {
                            final String[] old_value = tp.getStringList();
                            String def_val;
                            if (old_value != null && old_value.length > 0) {
                                def_val = old_value[0];
                            } else {
                                def_val = "";
                            }
                            String msg = MessageText.getString("UpdateConstraint.message");
                            SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("UpdateConstraint.title", "!" + msg + "!");
                            entryWindow.setPreenteredText(def_val, false);
                            entryWindow.selectPreenteredText(true);
                            entryWindow.prompt(new UIInputReceiverListener() {

                                @Override
                                public void UIInputReceiverClosed(UIInputReceiver receiver) {
                                    if (!receiver.hasSubmittedInput()) {
                                        return;
                                    }
                                    try {
                                        String text = receiver.getSubmittedInput().trim();
                                        if (text.length() == 0) {
                                            tp.setStringList(null);
                                        } else {
                                            String old_options = old_value.length > 1 ? old_value[1] : "";
                                            tp.setStringList(new String[] { text, old_options });
                                        }
                                    } catch (Throwable e) {
                                        Debug.out(e);
                                    }
                                }
                            });
                        }
                    });
                } else if (tp_name.equals(TagFeatureProperties.PR_TRACKER_TEMPLATES)) {
                    final TrackersUtil tut = TrackersUtil.getInstance();
                    List<String> templates = new ArrayList<>(tut.getMultiTrackers().keySet());
                    String str_merge = MessageText.getString("label.merge");
                    String str_replace = MessageText.getString("label.replace");
                    String str_remove = MessageText.getString("Button.remove");
                    String[] val = tp.getStringList();
                    String def_str;
                    final List<String> selected = new ArrayList<>();
                    if (val == null || val.length == 0) {
                        def_str = "";
                    } else {
                        def_str = "";
                        for (String v : val) {
                            String[] bits = v.split(":");
                            if (bits.length == 2) {
                                String tn = bits[1];
                                if (templates.contains(tn)) {
                                    String type = bits[0];
                                    if (type.equals("m")) {
                                        tn += ": " + str_merge;
                                    } else if (type.equals("r")) {
                                        tn += ": " + str_replace;
                                    } else {
                                        tn += ": " + str_remove;
                                    }
                                    selected.add(v);
                                    def_str += (def_str.length() == 0 ? "" : ", ") + tn;
                                }
                            }
                        }
                    }
                    Collections.sort(templates);
                    // deliberately hanging this off the main menu, not properties...
                    Menu ttemp_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
                    MenuItem ttemp_item = new MenuItem(menu, SWT.CASCADE);
                    ttemp_item.setText(MessageText.getString("label.tracker.templates") + (def_str.length() == 0 ? "" : (" (" + def_str + ")  ")));
                    ttemp_item.setMenu(ttemp_menu);
                    MenuItem new_item = new MenuItem(ttemp_menu, SWT.PUSH);
                    Messages.setLanguageText(new_item, "wizard.multitracker.new");
                    new_item.addListener(SWT.Selection, new Listener() {

                        @Override
                        public void handleEvent(Event event) {
                            List<List<String>> group = new ArrayList<>();
                            List<String> tracker = new ArrayList<>();
                            group.add(tracker);
                            new MultiTrackerEditor(props_menu.getShell(), null, group, new TrackerEditorListener() {

                                @Override
                                public void trackersChanged(String oldName, String newName, List<List<String>> trackers) {
                                    if (trackers != null) {
                                        tut.addMultiTracker(newName, trackers);
                                    }
                                }
                            });
                        }
                    });
                    MenuItem reapply_item = new MenuItem(ttemp_menu, SWT.PUSH);
                    Messages.setLanguageText(reapply_item, "label.reapply");
                    reapply_item.addListener(SWT.Selection, new Listener() {

                        @Override
                        public void handleEvent(Event event) {
                            tp.syncListeners();
                        }
                    });
                    reapply_item.setEnabled(def_str.length() > 0);
                    if (templates.size() > 0) {
                        new MenuItem(ttemp_menu, SWT.SEPARATOR);
                        for (final String template_name : templates) {
                            Menu t_menu = new Menu(ttemp_menu.getShell(), SWT.DROP_DOWN);
                            MenuItem t_item = new MenuItem(ttemp_menu, SWT.CASCADE);
                            t_item.setText(template_name);
                            t_item.setMenu(t_menu);
                            boolean r_selected = false;
                            for (int i = 0; i < 3; i++) {
                                final MenuItem sel_item = new MenuItem(t_menu, SWT.CHECK);
                                final String key = (i == 0 ? "m" : (i == 1 ? "r" : "x")) + ":" + template_name;
                                sel_item.setText(i == 0 ? str_merge : (i == 1 ? str_replace : str_remove));
                                boolean is_sel = selected.contains(key);
                                r_selected |= is_sel;
                                sel_item.setSelection(is_sel);
                                sel_item.addListener(SWT.Selection, new Listener() {

                                    @Override
                                    public void handleEvent(Event event) {
                                        if (sel_item.getSelection()) {
                                            selected.add(key);
                                        } else {
                                            selected.remove(key);
                                        }
                                        Utils.getOffOfSWTThread(new AERunnable() {

                                            @Override
                                            public void runSupport() {
                                                tp.setStringList(selected.toArray(new String[selected.size()]));
                                            }
                                        });
                                    }
                                });
                            }
                            if (r_selected) {
                                Utils.setMenuItemImage(t_item, "graytick");
                            }
                            new MenuItem(t_menu, SWT.SEPARATOR);
                            MenuItem edit_item = new MenuItem(t_menu, SWT.PUSH);
                            Messages.setLanguageText(edit_item, "wizard.multitracker.edit");
                            edit_item.addListener(SWT.Selection, new Listener() {

                                @Override
                                public void handleEvent(Event event) {
                                    new MultiTrackerEditor(props_menu.getShell(), template_name, tut.getMultiTrackers().get(template_name), new TrackerEditorListener() {

                                        @Override
                                        public void trackersChanged(String oldName, String newName, List<List<String>> trackers) {
                                            if (oldName != null && !oldName.equals(newName)) {
                                                tut.removeMultiTracker(oldName);
                                            }
                                            tut.addMultiTracker(newName, trackers);
                                        }
                                    });
                                }
                            });
                            MenuItem del_item = new MenuItem(t_menu, SWT.PUSH);
                            Messages.setLanguageText(del_item, "FileItem.delete");
                            Utils.setMenuItemImage(del_item, "delete");
                            del_item.addListener(SWT.Selection, new Listener() {

                                @Override
                                public void handleEvent(Event event) {
                                    MessageBoxShell mb = new MessageBoxShell(MessageText.getString("message.confirm.delete.title"), MessageText.getString("message.confirm.delete.text", new String[] { template_name }), new String[] { MessageText.getString("Button.yes"), MessageText.getString("Button.no") }, 1);
                                    mb.open(new UserPrompterResultListener() {

                                        @Override
                                        public void prompterClosed(int result) {
                                            if (result == 0) {
                                                tut.removeMultiTracker(template_name);
                                            }
                                        }
                                    });
                                }
                            });
                        }
                    }
                } else {
                    String[] val = tp.getStringList();
                    String def_str;
                    if (val == null || val.length == 0) {
                        def_str = "";
                    } else {
                        def_str = "";
                        for (String v : val) {
                            def_str += (def_str.length() == 0 ? "" : ", ") + v;
                        }
                    }
                    MenuItem set_item = new MenuItem(props_menu, SWT.PUSH);
                    set_item.setText(tp.getName(true) + (def_str.length() == 0 ? "" : (" (" + def_str + ") ")) + "...");
                    final String f_def_str = def_str;
                    set_item.addListener(SWT.Selection, new Listener() {

                        @Override
                        public void handleEvent(Event event) {
                            String msg = MessageText.getString("UpdateProperty.list.message", new String[] { tp.getName(true) });
                            SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("UpdateProperty.title", "!" + msg + "!");
                            entryWindow.setPreenteredText(f_def_str, false);
                            entryWindow.selectPreenteredText(true);
                            entryWindow.prompt(new UIInputReceiverListener() {

                                @Override
                                public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
                                    if (!entryWindow.hasSubmittedInput()) {
                                        return;
                                    }
                                    try {
                                        String text = entryWindow.getSubmittedInput().trim();
                                        if (text.length() == 0) {
                                            tp.setStringList(null);
                                        } else {
                                            text = text.replace(';', ',');
                                            text = text.replace(' ', ',');
                                            text = text.replaceAll("[,]+", ",");
                                            String[] bits = text.split(",");
                                            List<String> vals = new ArrayList<>();
                                            for (String bit : bits) {
                                                bit = bit.trim();
                                                if (bit.length() > 0) {
                                                    vals.add(bit);
                                                }
                                            }
                                            if (vals.size() == 0) {
                                                tp.setStringList(null);
                                            } else {
                                                tp.setStringList(vals.toArray(new String[vals.size()]));
                                            }
                                        }
                                    } catch (Throwable e) {
                                        Debug.out(e);
                                    }
                                }
                            });
                        }
                    });
                }
            } else if (tp.getType() == TagFeatureProperties.PT_BOOLEAN) {
                final MenuItem set_item = new MenuItem(props_menu, SWT.CHECK);
                set_item.setText(tp.getName(true));
                Boolean val = tp.getBoolean();
                set_item.setSelection(val != null && val);
                set_item.addListener(SWT.Selection, new Listener() {

                    @Override
                    public void handleEvent(Event event) {
                        tp.setBoolean(set_item.getSelection());
                    }
                });
            } else {
                Debug.out("Unknown property");
            }
        }
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) TrackerEditorListener(com.biglybt.ui.swt.maketorrent.TrackerEditorListener) SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) List(java.util.List) TagProperty(com.biglybt.core.tag.TagFeatureProperties.TagProperty) TrackerEditorListener(com.biglybt.ui.swt.maketorrent.TrackerEditorListener) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) MultiTrackerEditor(com.biglybt.ui.swt.maketorrent.MultiTrackerEditor) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) DisposeEvent(org.eclipse.swt.events.DisposeEvent) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener)

Example 4 with UIInputReceiverListener

use of com.biglybt.pif.ui.UIInputReceiverListener in project BiglyBT by BiglySoftware.

the class TagUIUtils method createSideBarMenuItems.

public static void createSideBarMenuItems(final Menu menu, final List<Tag> _tags) {
    final List<Tag> tags = new ArrayList<>(_tags);
    Iterator<Tag> it = tags.iterator();
    boolean can_show = false;
    boolean can_hide = false;
    while (it.hasNext()) {
        Tag tag = it.next();
        if (tag.getTagType().getTagType() != TagType.TT_DOWNLOAD_MANUAL) {
            it.remove();
        } else {
            if (tag.isVisible()) {
                can_hide = true;
            } else {
                can_show = true;
            }
        }
    }
    if (tags.size() == 0) {
        return;
    }
    MenuItem itemShow = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(itemShow, "Button.bar.show");
    itemShow.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            for (Tag tag : tags) {
                tag.setVisible(true);
            }
        }
    });
    itemShow.setEnabled(can_show);
    MenuItem itemHide = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(itemHide, "Button.bar.hide");
    itemHide.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            for (Tag tag : tags) {
                tag.setVisible(false);
            }
        }
    });
    itemHide.setEnabled(can_hide);
    MenuItem itemGroup = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(itemGroup, "MyTorrentsView.menu.group");
    itemGroup.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("TagGroupWindow.title", "TagGroupWindow.message");
            entryWindow.setPreenteredText("", false);
            entryWindow.selectPreenteredText(true);
            entryWindow.prompt(new UIInputReceiverListener() {

                @Override
                public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
                    if (!entryWindow.hasSubmittedInput()) {
                        return;
                    }
                    try {
                        String group = entryWindow.getSubmittedInput().trim();
                        if (group.length() == 0) {
                            group = null;
                        }
                        for (Tag tag : tags) {
                            tag.setGroup(group);
                        }
                    } catch (Throwable e) {
                        Debug.out(e);
                    }
                }
            });
        }
    });
    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(tags);
        }
    });
    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(tags.toArray(new Tag[0])));
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) TrackerEditorListener(com.biglybt.ui.swt.maketorrent.TrackerEditorListener) SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) DisposeEvent(org.eclipse.swt.events.DisposeEvent) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) MenuBuildUtils(com.biglybt.ui.swt.MenuBuildUtils)

Example 5 with UIInputReceiverListener

use of com.biglybt.pif.ui.UIInputReceiverListener in project BiglyBT by BiglySoftware.

the class TagUIUtils method createNonAutoMenuItems.

private static void createNonAutoMenuItems(final Menu menu, final Tag tag, final TagType tag_type, Menu[] menuShowHide) {
    if (tag_type.hasTagTypeFeature(TagFeature.TF_PROPERTIES)) {
        TagFeatureProperties props = (TagFeatureProperties) tag;
        boolean has_ut = props.getProperty(TagFeatureProperties.PR_UNTAGGED) != null;
        if (has_ut) {
            has_ut = false;
            for (Tag t : tag_type.getTags()) {
                props = (TagFeatureProperties) t;
                TagProperty prop = props.getProperty(TagFeatureProperties.PR_UNTAGGED);
                if (prop != null) {
                    Boolean b = prop.getBoolean();
                    if (b != null && b) {
                        has_ut = true;
                        break;
                    }
                }
            }
            if (!has_ut) {
                if (menuShowHide[0] == null) {
                    menuShowHide[0] = new Menu(menu.getShell(), SWT.DROP_DOWN);
                    MenuItem showhideitem = new MenuItem(menu, SWT.CASCADE);
                    showhideitem.setText(MessageText.getString("label.showhide.tag"));
                    showhideitem.setMenu(menuShowHide[0]);
                } else {
                    new MenuItem(menuShowHide[0], SWT.SEPARATOR);
                }
                MenuItem showAll = new MenuItem(menuShowHide[0], SWT.PUSH);
                Messages.setLanguageText(showAll, "label.untagged");
                showAll.addListener(SWT.Selection, new Listener() {

                    @Override
                    public void handleEvent(Event event) {
                        try {
                            String tag_name = MessageText.getString("label.untagged");
                            Tag ut_tag = tag_type.getTag(tag_name, true);
                            if (ut_tag == null) {
                                ut_tag = tag_type.createTag(tag_name, true);
                            }
                            TagFeatureProperties tp = (TagFeatureProperties) ut_tag;
                            tp.getProperty(TagFeatureProperties.PR_UNTAGGED).setBoolean(true);
                        } catch (TagException e) {
                            Debug.out(e);
                        }
                    }
                });
            }
        }
    }
    /*
		MenuItem item_create = new MenuItem( menu, SWT.PUSH);

		Messages.setLanguageText(item_create, "label.add.tag");
		item_create.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event event) {

				createManualTag(null);
			}
		});
		*/
    /* Seldom Used: Color can be set in Tags Overview
		MenuItem itemSetColor = new MenuItem(menu, SWT.PUSH);

		itemSetColor.setText( MessageText.getString( "label.color") + "..." );

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

				int[] existing = tag.getColor();

				RGB e_rg = existing==null?null:new RGB(existing[0],existing[1],existing[2]);

				RGB rgb = Utils.showColorDialog( menu.getShell(), e_rg );

				if ( rgb != null ){

					tag.setColor( new int[]{ rgb.red, rgb.green, rgb.blue });
				}
			}
		});
	 */
    MenuItem itemGroup = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(itemGroup, "MyTorrentsView.menu.group");
    itemGroup.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("TagGroupWindow.title", "TagGroupWindow.message");
            String group = tag.getGroup();
            if (group == null) {
                group = "";
            }
            entryWindow.setPreenteredText(group, false);
            entryWindow.selectPreenteredText(true);
            entryWindow.prompt(new UIInputReceiverListener() {

                @Override
                public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
                    if (!entryWindow.hasSubmittedInput()) {
                        return;
                    }
                    try {
                        String group = entryWindow.getSubmittedInput().trim();
                        if (group.length() == 0) {
                            group = null;
                        }
                        tag.setGroup(group);
                    } catch (Throwable e) {
                        Debug.out(e);
                    }
                }
            });
        }
    });
    MenuItem itemDelete = new MenuItem(menu, SWT.PUSH);
    Utils.setMenuItemImage(itemDelete, "delete");
    Messages.setLanguageText(itemDelete, "FileItem.delete");
    itemDelete.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            tag.removeTag();
        }
    });
}
Also used : TagProperty(com.biglybt.core.tag.TagFeatureProperties.TagProperty) DisposeListener(org.eclipse.swt.events.DisposeListener) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) CoreRunningListener(com.biglybt.core.CoreRunningListener) TrackerEditorListener(com.biglybt.ui.swt.maketorrent.TrackerEditorListener) SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) DisposeEvent(org.eclipse.swt.events.DisposeEvent) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener)

Aggregations

UIInputReceiver (com.biglybt.pif.ui.UIInputReceiver)29 UIInputReceiverListener (com.biglybt.pif.ui.UIInputReceiverListener)29 SimpleTextEntryWindow (com.biglybt.ui.swt.SimpleTextEntryWindow)21 DownloadManager (com.biglybt.core.download.DownloadManager)8 UserPrompterResultListener (com.biglybt.ui.UserPrompterResultListener)8 CoreRunningListener (com.biglybt.core.CoreRunningListener)7 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)6 TrackerEditorListener (com.biglybt.ui.swt.maketorrent.TrackerEditorListener)6 DisposeEvent (org.eclipse.swt.events.DisposeEvent)6 DisposeListener (org.eclipse.swt.events.DisposeListener)6 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)5 List (java.util.List)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 UIManagerListener (com.biglybt.pif.ui.UIManagerListener)3 MenuBuildUtils (com.biglybt.ui.swt.MenuBuildUtils)3 Core (com.biglybt.core.Core)2 MessageText (com.biglybt.core.internat.MessageText)2 PEPeer (com.biglybt.core.peer.PEPeer)2 PEPeerManager (com.biglybt.core.peer.PEPeerManager)2 TagProperty (com.biglybt.core.tag.TagFeatureProperties.TagProperty)2