Search in sources :

Example 31 with UIInputReceiver

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

the class MultiTrackerEditor method createWindow.

private void createWindow(Shell parent_shell) {
    if (parent_shell == null) {
        this.shell = ShellFactory.createMainShell(SWT.DIALOG_TRIM | SWT.RESIZE);
    } else {
        this.shell = ShellFactory.createShell(parent_shell, SWT.DIALOG_TRIM | SWT.RESIZE);
    }
    Messages.setLanguageText(this.shell, anonymous ? "wizard.multitracker.edit.title" : "wizard.multitracker.template.title");
    Utils.setShellIcon(shell);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    shell.setLayout(layout);
    GridData gridData;
    if (!anonymous) {
        Label labelName = new Label(shell, SWT.NULL);
        Messages.setLanguageText(labelName, "wizard.multitracker.edit.name");
        textName = new Text(shell, SWT.BORDER);
        textName.setText(currentName);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.horizontalSpan = 2;
        textName.setLayoutData(gridData);
        textName.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent arg0) {
                currentName = textName.getText();
                computeSaveEnable();
            }
        });
    }
    treeGroups = new Tree(shell, SWT.BORDER);
    gridData = new GridData(GridData.FILL_BOTH);
    gridData.horizontalSpan = 3;
    gridData.heightHint = 150;
    treeGroups.setLayoutData(gridData);
    treeGroups.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDoubleClick(MouseEvent arg0) {
            if (treeGroups.getSelectionCount() == 1) {
                TreeItem treeItem = treeGroups.getSelection()[0];
                String type = (String) treeItem.getData("type");
                if (type.equals("tracker")) {
                    editTreeItem(treeItem);
                }
            }
        }
    });
    if (showTemplates) {
        addTemplates();
    }
    Label labelSeparator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 3;
    labelSeparator.setLayoutData(gridData);
    // button row
    Composite cButtons = new Composite(shell, SWT.NONE);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 3;
    cButtons.setLayoutData(gridData);
    GridLayout layoutButtons = new GridLayout();
    layoutButtons.numColumns = 5;
    cButtons.setLayout(layoutButtons);
    List<Button> buttons = new ArrayList<>();
    final Button btnedittext = new Button(cButtons, SWT.PUSH);
    buttons.add(btnedittext);
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.END;
    btnedittext.setLayoutData(gridData);
    Messages.setLanguageText(btnedittext, "wizard.multitracker.edit.text");
    btnedittext.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            btnSave.setEnabled(false);
            btnedittext.setEnabled(false);
            trackers = new ArrayList<>();
            TreeItem[] groupItems = treeGroups.getItems();
            for (int i = 0; i < groupItems.length; i++) {
                TreeItem group = groupItems[i];
                TreeItem[] trackerItems = group.getItems();
                List<String> groupList = new ArrayList<>(group.getItemCount());
                for (int j = 0; j < trackerItems.length; j++) {
                    groupList.add(trackerItems[j].getText());
                }
                trackers.add(groupList);
            }
            final String old_text = TorrentUtils.announceGroupsToText(trackers);
            final TextViewerWindow viewer = new TextViewerWindow(shell, "wizard.multitracker.edit.text.title", "wizard.multitracker.edit.text.msg", old_text, false, false);
            viewer.setEditable(true);
            viewer.addListener(new TextViewerWindow.TextViewerWindowListener() {

                @Override
                public void closed() {
                    try {
                        if (viewer.getOKPressed()) {
                            String new_text = viewer.getText();
                            if (!old_text.equals(new_text)) {
                                String[] lines = new_text.split("\n");
                                StringBuilder valid_text = new StringBuilder(new_text.length() + 1);
                                for (String line : lines) {
                                    line = line.trim();
                                    if (line.length() > 0) {
                                        if (!validURL(line)) {
                                            continue;
                                        }
                                    }
                                    valid_text.append(line);
                                    valid_text.append("\n");
                                }
                                trackers = TorrentUtils.announceTextToGroups(valid_text.toString());
                                refresh();
                            }
                        }
                    } finally {
                        computeSaveEnable();
                        btnedittext.setEnabled(true);
                    }
                }
            });
        }
    });
    final Button btnAddTrackerList = new Button(cButtons, SWT.PUSH);
    buttons.add(btnAddTrackerList);
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.END;
    btnAddTrackerList.setLayoutData(gridData);
    Messages.setLanguageText(btnAddTrackerList, "wizard.multitracker.add.trackerlist");
    btnAddTrackerList.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("enter.url", "enter.trackerlist.url");
            entryWindow.prompt(new UIInputReceiverListener() {

                @Override
                public void UIInputReceiverClosed(UIInputReceiver receiver) {
                    if (!receiver.hasSubmittedInput()) {
                        return;
                    }
                    String url = receiver.getSubmittedInput().trim();
                    if (!url.isEmpty()) {
                        TreeItem group = newGroup();
                        TreeItem itemTracker = newTracker(group, "trackerlist:" + url.trim());
                    }
                }
            });
        }
    });
    Label label = new Label(cButtons, SWT.NULL);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    label.setLayoutData(gridData);
    btnSave = new Button(cButtons, SWT.PUSH);
    buttons.add(btnSave);
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.END;
    btnSave.setLayoutData(gridData);
    Messages.setLanguageText(btnSave, "wizard.multitracker.edit.save");
    btnSave.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            update();
            shell.dispose();
        }
    });
    btnCancel = new Button(cButtons, SWT.PUSH);
    buttons.add(btnCancel);
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.END;
    btnCancel.setLayoutData(gridData);
    Messages.setLanguageText(btnCancel, "Button.cancel");
    btnCancel.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            shell.dispose();
        }
    });
    Utils.makeButtonsEqualWidth(buttons);
    shell.setDefaultButton(btnSave);
    shell.addListener(SWT.Traverse, new Listener() {

        @Override
        public void handleEvent(Event e) {
            if (e.character == SWT.ESC) {
                shell.dispose();
            }
        }
    });
    computeSaveEnable();
    refresh();
    constructMenu();
    editor = new TreeEditor(treeGroups);
    treeGroups.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            if (itemEdited != null && !itemEdited.isDisposed() && !editor.getEditor().isDisposed()) {
                itemEdited.setText(((Text) editor.getEditor()).getText());
            }
            removeEditor();
        }
    });
    Point size = shell.computeSize(500, SWT.DEFAULT);
    shell.setSize(size);
    Utils.centreWindow(shell);
    shell.open();
}
Also used : UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) ArrayList(java.util.ArrayList) GridLayout(org.eclipse.swt.layout.GridLayout) SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) ArrayList(java.util.ArrayList) List(java.util.List) TextViewerWindow(com.biglybt.ui.swt.TextViewerWindow) TreeEditor(org.eclipse.swt.custom.TreeEditor) MessageText(com.biglybt.core.internat.MessageText) Point(org.eclipse.swt.graphics.Point) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) GridData(org.eclipse.swt.layout.GridData) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener)

Example 32 with UIInputReceiver

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

the class BYOPanel method editSelected.

protected void editSelected() {
    final TreeItem[] selection = tree.getSelection();
    if (selection.length == 1) {
        SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("wizard.newtorrent.byo.editname.title", "wizard.newtorrent.byo.editname.text");
        entryWindow.setPreenteredText(selection[0].getText(), false);
        entryWindow.prompt(new UIInputReceiverListener() {

            @Override
            public void UIInputReceiverClosed(UIInputReceiver receiver) {
                if (receiver.hasSubmittedInput()) {
                    selection[0].setText(receiver.getSubmittedInput());
                }
            }
        });
    }
}
Also used : SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener)

Example 33 with UIInputReceiver

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

the class BYOPanel method show.

/*
	 * (non-Javadoc)
	 *
	 * @see com.biglybt.ui.swt.maketorrent.IWizardPanel#show()
	 */
@Override
public void show() {
    wizard.setTitle(MessageText.getString("wizard.newtorrent.byo"));
    wizard.setCurrentInfo(MessageText.getString("wizard.newtorrent.byo.info"));
    Composite panel = wizard.getPanel();
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    panel.setLayout(layout);
    GridData gridData;
    tree = new Tree(panel, SWT.BORDER | SWT.MULTI);
    tree.setHeaderVisible(true);
    TreeColumn treeColumn = new TreeColumn(tree, 0);
    Messages.setLanguageText(treeColumn, "label.torrent.structure");
    treeColumn.setWidth(180);
    treeColumn = new TreeColumn(tree, 0);
    Messages.setLanguageText(treeColumn, "label.original.file");
    treeColumn.setWidth(500);
    gridData = new GridData(GridData.FILL_BOTH);
    tree.setLayoutData(gridData);
    createDropTarget(tree);
    createDragSource(tree);
    tree.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            editSelected();
            e.doit = false;
        }
    });
    tree.addKeyListener(new KeyListener() {

        @Override
        public void keyReleased(KeyEvent e) {
        }

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.F2) {
                editSelected();
            } else if (e.keyCode == SWT.DEL) {
                TreeItem[] selection = tree.getSelection();
                for (TreeItem treeItem : selection) {
                    Object data = treeItem.getData();
                    treeItem.dispose();
                }
            }
        }
    });
    Composite cButtons = new Composite(panel, 0);
    cButtons.setLayout(new RowLayout());
    cButtons.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Button btnAddContainer = new Button(cButtons, SWT.PUSH);
    Messages.setLanguageText(btnAddContainer, "button.add.container");
    btnAddContainer.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("wizard.newtorrent.byo.addcontainer.title", "wizard.newtorrent.byo.addcontainer.text");
            entryWindow.setPreenteredText("files", true);
            entryWindow.prompt(new UIInputReceiverListener() {

                @Override
                public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
                    if (entryWindow.hasSubmittedInput()) {
                        createContainer(null, entryWindow.getSubmittedInput());
                    }
                }
            });
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    Button btnAddFiles = new Button(cButtons, SWT.PUSH);
    Messages.setLanguageText(btnAddFiles, "OpenTorrentWindow.addFiles");
    btnAddFiles.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog fDialog = new FileDialog(Utils.findAnyShell(), SWT.OPEN | SWT.MULTI);
            fDialog.setFilterPath(TorrentOpener.getFilterPathData());
            fDialog.setText(MessageText.getString("MainWindow.dialog.choose.file"));
            if (fDialog.open() != null) {
                String[] fileNames = fDialog.getFileNames();
                File last_file = null;
                for (String fileName : fileNames) {
                    File f = new File(fDialog.getFilterPath(), fileName);
                    addFilename(f);
                    last_file = f;
                }
                if (last_file != null) {
                    TorrentOpener.setFilterPathData(last_file.getAbsolutePath());
                }
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    Button btnAddFolder = new Button(cButtons, SWT.PUSH);
    Messages.setLanguageText(btnAddFolder, "OpenTorrentWindow.addFiles.Folder");
    btnAddFolder.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            DirectoryDialog fDialog = new DirectoryDialog(Utils.findAnyShell(), SWT.NULL);
            fDialog.setFilterPath(TorrentOpener.getFilterPathData());
            fDialog.setMessage(MessageText.getString("MainWindow.dialog.choose.folder"));
            String path = fDialog.open();
            if (path != null) {
                File f = new File(path);
                addFilename(f);
                if (f.isDirectory()) {
                    TorrentOpener.setFilterPathData(f.getAbsolutePath());
                }
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    if (wizard.byo_map != null) {
        List list = (List) wizard.byo_map.get("file_map");
        if (list != null) {
            for (Iterator iterator = list.iterator(); iterator.hasNext(); ) {
                Map map = (Map) iterator.next();
                String target = MapUtils.getMapString(map, "target", null);
                List path = MapUtils.getMapList(map, "logical_path", null);
                if (target != null && path != null) {
                    File targetFile = new File(target);
                    if (path.size() == 1) {
                        addFilename(targetFile, (String) path.get(0), null, true);
                    } else {
                        TreeItem[] items = tree.getItems();
                        TreeItem parent = null;
                        for (int i = 0; i < path.size() - 1; i++) {
                            TreeItem lastParent = parent;
                            String name = (String) path.get(i);
                            boolean found = false;
                            for (TreeItem item : items) {
                                if (item.getText().equals(name)) {
                                    parent = item;
                                    found = true;
                                    break;
                                }
                            }
                            if (!found) {
                                parent = createContainer(lastParent, name);
                            }
                            items = parent.getItems();
                        }
                        String name = (String) path.get(path.size() - 1);
                        addFilename(targetFile, name, parent, false);
                    }
                }
            }
        }
    }
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) RowLayout(org.eclipse.swt.layout.RowLayout) SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) List(java.util.List) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) GridData(org.eclipse.swt.layout.GridData) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) File(java.io.File)

Example 34 with UIInputReceiver

use of com.biglybt.pif.ui.UIInputReceiver 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)

Example 35 with UIInputReceiver

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

the class TagUIUtils method createTagGroupMenu.

private static void createTagGroupMenu(Menu menu, TagType tag_type, List<Tag> tagz) {
    if (tag_type.getTagType() != TagType.TT_DOWNLOAD_MANUAL || tagz.isEmpty()) {
        return;
    }
    List<TagGroup> groups = new ArrayList<>();
    List<Tag> all_tags = tag_type.getTags();
    for (Tag t : all_tags) {
        TagGroup group = t.getGroupContainer();
        if (group != null && group.getName() != null && !groups.contains(group)) {
            groups.add(group);
        }
    }
    groups = TagUtils.sortTagGroups(groups);
    Menu groups_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
    MenuItem groups_item = new MenuItem(menu, SWT.CASCADE);
    Messages.setLanguageText(groups_item, "TableColumn.header.tag.group");
    groups_item.setMenu(groups_menu);
    String existing_group = tagz.get(0).getGroup();
    if (existing_group == null) {
        existing_group = "";
    }
    for (Tag t : tagz) {
        String g = t.getGroup();
        if (g == null) {
            g = "";
        }
        if (!g.equals(existing_group)) {
            existing_group = null;
            break;
        }
    }
    MenuItem item_none = new MenuItem(groups_menu, SWT.RADIO);
    Messages.setLanguageText(item_none, "label.none");
    item_none.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            for (Tag t : tagz) {
                t.setGroup(null);
            }
        }
    });
    item_none.setSelection(existing_group != null && existing_group.isEmpty());
    new MenuItem(groups_menu, SWT.SEPARATOR);
    if (!groups.isEmpty()) {
        for (TagGroup g : groups) {
            MenuItem item_group = new MenuItem(groups_menu, SWT.RADIO);
            item_group.setText(g.getName());
            item_group.setSelection(g.getName().equals(existing_group));
            item_group.addListener(SWT.Selection, new Listener() {

                public void handleEvent(Event event) {
                    for (Tag t : tagz) {
                        t.setGroup(g.getName());
                    }
                }
            });
        }
        new MenuItem(groups_menu, SWT.SEPARATOR);
    }
    MenuItem item_add = new MenuItem(groups_menu, SWT.PUSH);
    final String f_existing_group = existing_group;
    Messages.setLanguageText(item_add, "menu.add.group");
    item_add.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("TagGroupWindow.title", "TagGroupWindow.message");
            if (f_existing_group != null) {
                entryWindow.setPreenteredText(f_existing_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;
                        }
                        for (Tag t : tagz) {
                            t.setGroup(group);
                        }
                    } catch (Throwable e) {
                        Debug.out(e);
                    }
                }
            });
        }
    });
    new MenuItem(groups_menu, SWT.SEPARATOR);
    Menu settings_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
    MenuItem settings_item = new MenuItem(groups_menu, SWT.CASCADE);
    Messages.setLanguageText(settings_item, "TagSettingsView.title");
    settings_item.setMenu(settings_menu);
    if (groups.isEmpty()) {
        settings_menu.setEnabled(false);
    } else {
        for (TagGroup g : groups) {
            Menu tg_settings_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
            MenuItem tg_settings_item = new MenuItem(settings_menu, SWT.CASCADE);
            tg_settings_item.setText(g.getName());
            tg_settings_item.setMenu(tg_settings_menu);
            addTagGroupMenu(tg_settings_menu, g);
        }
    }
}
Also used : 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) 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)

Aggregations

UIInputReceiver (com.biglybt.pif.ui.UIInputReceiver)38 UIInputReceiverListener (com.biglybt.pif.ui.UIInputReceiverListener)36 SimpleTextEntryWindow (com.biglybt.ui.swt.SimpleTextEntryWindow)21 List (java.util.List)11 DownloadManager (com.biglybt.core.download.DownloadManager)9 UserPrompterResultListener (com.biglybt.ui.UserPrompterResultListener)9 SelectionEvent (org.eclipse.swt.events.SelectionEvent)9 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)7 TrackerEditorListener (com.biglybt.ui.swt.maketorrent.TrackerEditorListener)7 Point (org.eclipse.swt.graphics.Point)7 CoreRunningListener (com.biglybt.core.CoreRunningListener)6 File (java.io.File)6 MenuEvent (org.eclipse.swt.events.MenuEvent)6 ParameterListener (com.biglybt.core.config.ParameterListener)5 MessageText (com.biglybt.core.internat.MessageText)5 UISWTViewEvent (com.biglybt.ui.swt.pif.UISWTViewEvent)5 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)5 TableViewSWTMenuFillListener (com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener)5 DisposeEvent (org.eclipse.swt.events.DisposeEvent)5 DisposeListener (org.eclipse.swt.events.DisposeListener)5