Search in sources :

Example 6 with MessageBoxShell

use of com.biglybt.ui.swt.shells.MessageBoxShell in project BiglyBT by BiglySoftware.

the class ManagerUtils method moveToArchive.

public static void moveToArchive(final List<Download> downloads, ArchiveCallback _run_when_complete) {
    final ArchiveCallback run_when_complete = _run_when_complete == null ? new ArchiveCallback() : _run_when_complete;
    Utils.getOffOfSWTThread(new AERunnable() {

        @Override
        public void runSupport() {
            try {
                String title = MessageText.getString("archive.info.title");
                String text = MessageText.getString("archive.info.text");
                MessageBoxShell prompter = new MessageBoxShell(title, text, new String[] { MessageText.getString("Button.ok") }, 0);
                String remember_id = "managerutils.archive.info";
                prompter.setRemember(remember_id, true, MessageText.getString("MessageBoxWindow.nomoreprompting"));
                prompter.setAutoCloseInMS(0);
                prompter.open(null);
                prompter.waitUntilClosed();
                for (Download dm : downloads) {
                    try {
                        DownloadStub stub = dm.stubbify();
                        run_when_complete.success(dm, stub);
                    } catch (Throwable e) {
                        run_when_complete.failed(dm, e);
                        Debug.out(e);
                    }
                }
            } finally {
                run_when_complete.completed();
            }
        }
    });
}
Also used : DownloadStub(com.biglybt.pif.download.DownloadStub) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) Download(com.biglybt.pif.download.Download)

Example 7 with MessageBoxShell

use of com.biglybt.ui.swt.shells.MessageBoxShell 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 8 with MessageBoxShell

use of com.biglybt.ui.swt.shells.MessageBoxShell in project BiglyBT by BiglySoftware.

the class BuddyPluginViewInstance method addPartialBuddyTable.

private Comparator<PartialBuddy> addPartialBuddyTable(Composite child1) {
    partial_buddy_table = new Table(child1, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION | SWT.VIRTUAL);
    final String[] headers = { "azbuddy.ui.pbtable.peer", "azbuddy.ui.pbtable.downloads" };
    int[] sizes = { 250, 400 };
    int[] aligns = { SWT.LEFT, SWT.LEFT };
    for (int i = 0; i < headers.length; i++) {
        TableColumn tc = new TableColumn(partial_buddy_table, aligns[i]);
        tc.setWidth(Utils.adjustPXForDPI(sizes[i]));
        Messages.setLanguageText(tc, headers[i]);
    }
    partial_buddy_table.setHeaderVisible(true);
    TableColumn[] columns = partial_buddy_table.getColumns();
    columns[0].setData(new Integer(PBFilterComparator.FIELD_PEER));
    columns[1].setData(new Integer(PBFilterComparator.FIELD_DOWNLOADS));
    final PBFilterComparator comparator = new PBFilterComparator();
    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(partial_buddies, comparator);
            updateTable();
        }
    };
    for (int i = 0; i < columns.length; i++) {
        columns[i].addListener(SWT.Selection, sort_listener);
    }
    GridData gridData = new GridData(GridData.FILL_BOTH);
    gridData.heightHint = partial_buddy_table.getHeaderHeight() * 3;
    Utils.setLayoutData(partial_buddy_table, gridData);
    partial_buddy_table.addListener(SWT.SetData, new Listener() {

        @Override
        public void handleEvent(Event event) {
            TableItem item = (TableItem) event.item;
            int index = partial_buddy_table.indexOf(item);
            if (index < 0 || index >= partial_buddies.size()) {
                return;
            }
            PartialBuddy buddy = partial_buddies.get(index);
            item.setText(0, buddy.ip);
            item.setText(1, buddy.getDownloadsSummary());
            item.setData(buddy);
        }
    });
    final Menu menu = new Menu(partial_buddy_table);
    final MenuItem remove_item = new MenuItem(menu, SWT.PUSH);
    remove_item.setText(lu.getLocalisedMessageText("azbuddy.ui.menu.remove"));
    remove_item.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            TableItem[] selection = partial_buddy_table.getSelection();
            for (int i = 0; i < selection.length; i++) {
                PartialBuddy buddy = (PartialBuddy) selection[i].getData();
                buddy.remove();
            }
        }
    });
    partial_buddy_table.setMenu(menu);
    partial_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') {
                    partial_buddy_table.selectAll();
                    event.doit = false;
                }
            } else if (event.stateMask == 0 && event.keyCode == SWT.DEL) {
                TableItem[] selection = partial_buddy_table.getSelection();
                String str = "";
                for (int i = 0; i < selection.length; i++) {
                    PartialBuddy buddy = (PartialBuddy) selection[i].getData();
                    str += (str.isEmpty() ? "" : ", ") + buddy.ip;
                }
                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++) {
                                PartialBuddy buddy = (PartialBuddy) selection[i].getData();
                                buddy.remove();
                            }
                            partial_buddy_table.setSelection(new int[0]);
                        }
                    }
                });
                event.doit = false;
            }
        }
    });
    menu.addMenuListener(new MenuListener() {

        @Override
        public void menuShown(MenuEvent arg0) {
            TableItem[] selection = partial_buddy_table.getSelection();
            remove_item.setEnabled(selection.length > 0);
        }

        @Override
        public void menuHidden(MenuEvent arg0) {
        }
    });
    return (comparator);
}
Also used : UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) Point(org.eclipse.swt.graphics.Point) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) UIManagerEvent(com.biglybt.pif.ui.UIManagerEvent)

Example 9 with MessageBoxShell

use of com.biglybt.ui.swt.shells.MessageBoxShell in project BiglyBT by BiglySoftware.

the class DeviceManagerUI method uiAttachedAndCoreRunning.

private void uiAttachedAndCoreRunning(Core core) {
    Utils.execSWTThread(new AERunnable() {

        @Override
        public void runSupport() {
            MultipleDocumentInterfaceSWT mdi = UIFunctionsManagerSWT.getUIFunctionsSWT().getMDISWT();
            if (mdi != null) {
                setupUI(mdi);
            } else {
                SkinViewManager.addListener(new SkinViewManagerListener() {

                    @Override
                    public void skinViewAdded(SkinView skinview) {
                        if (skinview instanceof SideBar) {
                            setupUI((SideBar) skinview);
                            SkinViewManager.RemoveListener(this);
                        }
                    }
                });
            }
        }
    });
    canCloseListener = new canCloseListener() {

        @Override
        public boolean canClose() {
            try {
                if (device_manager == null) {
                    return (true);
                }
                if (!device_manager.isTranscodeManagerInitialized()) {
                    return true;
                }
                final TranscodeJob job = device_manager.getTranscodeManager().getQueue().getCurrentJob();
                if (job == null || job.getState() != TranscodeJob.ST_RUNNING) {
                    return (true);
                }
                if (job.getTranscodeFile().getDevice().isHidden()) {
                    return (true);
                }
                String title = MessageText.getString("device.quit.transcoding.title");
                String text = MessageText.getString("device.quit.transcoding.text", new String[] { job.getName(), job.getTarget().getDevice().getName(), String.valueOf(job.getPercentComplete()) });
                MessageBoxShell mb = new MessageBoxShell(title, text, new String[] { MessageText.getString("UpdateWindow.quit"), MessageText.getString("Content.alert.notuploaded.button.abort") }, 1);
                mb.open(null);
                mb.waitUntilClosed();
                return mb.getResult() == 0;
            } catch (Throwable e) {
                Debug.out(e);
                return true;
            }
        }
    };
    UIExitUtilsSWT.addListener(canCloseListener);
}
Also used : SkinViewManagerListener(com.biglybt.ui.swt.views.skin.SkinViewManager.SkinViewManagerListener) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) MultipleDocumentInterfaceSWT(com.biglybt.ui.swt.mdi.MultipleDocumentInterfaceSWT) SkinView(com.biglybt.ui.swt.views.skin.SkinView) SideBar(com.biglybt.ui.swt.views.skin.sidebar.SideBar) UIExitUtilsSWT.canCloseListener(com.biglybt.ui.swt.UIExitUtilsSWT.canCloseListener)

Example 10 with MessageBoxShell

use of com.biglybt.ui.swt.shells.MessageBoxShell in project BiglyBT by BiglySoftware.

the class TranscodeChooser method noDevices.

/**
 * @since 4.1.0.5
 */
private void noDevices() {
    new MessageBoxShell(SWT.OK, "No Devices Found", "We couldn't find any devices.  Maybe you didn't install the Vuze Transcoder Plugin?").open(null);
    shell.dispose();
}
Also used : MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell)

Aggregations

MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)53 UserPrompterResultListener (com.biglybt.ui.UserPrompterResultListener)24 File (java.io.File)10 ArrayList (java.util.ArrayList)7 GridData (org.eclipse.swt.layout.GridData)7 DownloadManager (com.biglybt.core.download.DownloadManager)6 UIInputReceiverListener (com.biglybt.pif.ui.UIInputReceiverListener)6 GridLayout (org.eclipse.swt.layout.GridLayout)6 Map (java.util.Map)5 TOTorrent (com.biglybt.core.torrent.TOTorrent)4 TOTorrentFile (com.biglybt.core.torrent.TOTorrentFile)4 AERunnable (com.biglybt.core.util.AERunnable)4 UIInputReceiver (com.biglybt.pif.ui.UIInputReceiver)4 UIFunctionsSWT (com.biglybt.ui.swt.UIFunctionsSWT)4 URL (java.net.URL)4 HashMap (java.util.HashMap)4 List (java.util.List)4 MouseAdapter (org.eclipse.swt.events.MouseAdapter)4 MouseEvent (org.eclipse.swt.events.MouseEvent)4 Point (org.eclipse.swt.graphics.Point)4