Search in sources :

Example 1 with UserPrompterResultListener

use of com.biglybt.ui.UserPrompterResultListener in project BiglyBT by BiglySoftware.

the class SBC_TagsOverview method toolBarItemActivated.

// @see com.biglybt.pif.ui.toolbar.UIToolBarActivationListener#toolBarItemActivated(ToolBarItem, long, java.lang.Object)
@Override
public boolean toolBarItemActivated(ToolBarItem item, long activationType, Object datasource) {
    // Send to active view.  mostly works
    // except MyTorrentsSubView always takes focus after tag is selected..
    boolean isTableSelected = false;
    if (tv instanceof TableViewImpl) {
        isTableSelected = ((TableViewImpl) tv).isTableSelected();
    }
    if (!isTableSelected) {
        UISWTViewCore active_view = getActiveView();
        if (active_view != null) {
            UIPluginViewToolBarListener l = active_view.getToolBarListener();
            if (l != null && l.toolBarItemActivated(item, activationType, datasource)) {
                return true;
            }
        }
        return false;
    }
    if (tv == null || !tv.isVisible()) {
        return (false);
    }
    if (item.getID().equals("remove")) {
        Object[] datasources = tv.getSelectedDataSources().toArray();
        if (datasources.length > 0) {
            for (Object object : datasources) {
                if (object instanceof Tag) {
                    final Tag tag = (Tag) object;
                    if (tag.getTagType().getTagType() != TagType.TT_DOWNLOAD_MANUAL) {
                        continue;
                    }
                    MessageBoxShell mb = new MessageBoxShell(MessageText.getString("message.confirm.delete.title"), MessageText.getString("message.confirm.delete.text", new String[] { tag.getTagName(true) }), new String[] { MessageText.getString("Button.yes"), MessageText.getString("Button.no") }, 1);
                    mb.open(new UserPrompterResultListener() {

                        @Override
                        public void prompterClosed(int result) {
                            if (result == 0) {
                                tag.removeTag();
                            }
                        }
                    });
                }
            }
            return true;
        }
    }
    return false;
}
Also used : TableViewImpl(com.biglybt.ui.common.table.impl.TableViewImpl) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) UISWTViewCore(com.biglybt.ui.swt.pifimpl.UISWTViewCore) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) UIPluginViewToolBarListener(com.biglybt.pif.ui.UIPluginViewToolBarListener)

Example 2 with UserPrompterResultListener

use of com.biglybt.ui.UserPrompterResultListener in project BiglyBT by BiglySoftware.

the class ConfigSectionSecurity method configSectionCreate.

@Override
public Composite configSectionCreate(final Composite parent) {
    int userMode = COConfigurationManager.getIntParameter("User Mode");
    java.util.List<Button> buttons = new ArrayList<>();
    GridData gridData;
    Composite gSecurity = new Composite(parent, SWT.NULL);
    gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
    gSecurity.setLayoutData(gridData);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    gSecurity.setLayout(layout);
    // row
    Label cert_label = new Label(gSecurity, SWT.NULL);
    Messages.setLanguageText(cert_label, "ConfigView.section.tracker.createcert");
    Button cert_button = new Button(gSecurity, SWT.PUSH);
    buttons.add(cert_button);
    Messages.setLanguageText(cert_button, "ConfigView.section.tracker.createbutton");
    cert_button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            new CertificateCreatorWindow();
        }
    });
    new Label(gSecurity, SWT.NULL);
    // row
    Label reset_certs_label = new Label(gSecurity, SWT.NULL);
    Messages.setLanguageText(reset_certs_label, "ConfigView.section.security.resetcerts");
    Button reset_certs_button = new Button(gSecurity, SWT.PUSH);
    buttons.add(reset_certs_button);
    Messages.setLanguageText(reset_certs_button, "Button.reset");
    reset_certs_button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            MessageBoxShell mb = new MessageBoxShell(SWT.ICON_WARNING | SWT.OK | SWT.CANCEL, MessageText.getString("ConfigView.section.security.resetcerts.warning.title"), MessageText.getString("ConfigView.section.security.resetcerts.warning.msg"));
            mb.setDefaultButtonUsingStyle(SWT.CANCEL);
            mb.setParent(parent.getShell());
            mb.open(new UserPrompterResultListener() {

                @Override
                public void prompterClosed(int returnVal) {
                    if (returnVal != SWT.OK) {
                        return;
                    }
                    if (SESecurityManager.resetTrustStore(false)) {
                        MessageBoxShell mb = new MessageBoxShell(SWT.ICON_INFORMATION | SWT.OK, MessageText.getString("ConfigView.section.security.restart.title"), MessageText.getString("ConfigView.section.security.restart.msg"));
                        mb.setParent(parent.getShell());
                        mb.open(null);
                        UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
                        if (uiFunctions != null) {
                            uiFunctions.dispose(true, false);
                        }
                    } else {
                        MessageBoxShell mb = new MessageBoxShell(SWT.ICON_ERROR | SWT.OK, MessageText.getString("ConfigView.section.security.resetcerts.error.title"), MessageText.getString("ConfigView.section.security.resetcerts.error.msg"));
                        mb.setParent(parent.getShell());
                        mb.open(null);
                    }
                }
            });
        }
    });
    reset_certs_button.setEnabled(SESecurityManager.resetTrustStore(true));
    new Label(gSecurity, SWT.NULL);
    // row
    gridData = new GridData();
    gridData.horizontalSpan = 3;
    new BooleanParameter(gSecurity, "security.cert.auto.install", "security.cert.auto.install").setLayoutData(gridData);
    // row
    Label info_label = new Label(gSecurity, SWT.WRAP);
    Messages.setLanguageText(info_label, "ConfigView.section.security.toolsinfo");
    info_label.setLayoutData(Utils.getWrappableLabelGridData(3, 0));
    // row
    Label lStatsPath = new Label(gSecurity, SWT.NULL);
    // $NON-NLS-1$
    Messages.setLanguageText(lStatsPath, "ConfigView.section.security.toolsdir");
    ImageLoader imageLoader = ImageLoader.getInstance();
    Image imgOpenFolder = imageLoader.getImage("openFolderButton");
    gridData = new GridData();
    gridData.widthHint = 150;
    // $NON-NLS-1$ //$NON-NLS-2$
    final StringParameter pathParameter = new StringParameter(gSecurity, "Security.JAR.tools.dir", "");
    pathParameter.setLayoutData(gridData);
    Button browse = new Button(gSecurity, SWT.PUSH);
    browse.setImage(imgOpenFolder);
    imgOpenFolder.setBackground(browse.getBackground());
    browse.setToolTipText(MessageText.getString("ConfigView.button.browse"));
    browse.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            DirectoryDialog dialog = new DirectoryDialog(parent.getShell(), SWT.APPLICATION_MODAL);
            dialog.setFilterPath(pathParameter.getValue());
            // $NON-NLS-1$
            dialog.setText(MessageText.getString("ConfigView.section.security.choosetoolssavedir"));
            String path = dialog.open();
            if (path != null) {
                pathParameter.setValue(path);
            }
        }
    });
    // row
    Label pw_label = new Label(gSecurity, SWT.NULL);
    Messages.setLanguageText(pw_label, "ConfigView.section.security.clearpasswords");
    Button pw_button = new Button(gSecurity, SWT.PUSH);
    buttons.add(pw_button);
    Messages.setLanguageText(pw_button, "ConfigView.section.security.clearpasswords.button");
    pw_button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            SESecurityManager.clearPasswords();
            CryptoManagerFactory.getSingleton().clearPasswords();
        }
    });
    new Label(gSecurity, SWT.NULL);
    if (userMode >= 2) {
        final CryptoManager crypt_man = CryptoManagerFactory.getSingleton();
        final Group crypto_group = new Group(gSecurity, SWT.NULL);
        gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.FILL_HORIZONTAL);
        gridData.horizontalSpan = 3;
        crypto_group.setLayoutData(gridData);
        layout = new GridLayout();
        layout.numColumns = 3;
        crypto_group.setLayout(layout);
        Messages.setLanguageText(crypto_group, "ConfigView.section.security.group.crypto");
        // wiki link
        final Label linkLabel = new Label(crypto_group, SWT.NULL);
        linkLabel.setText(MessageText.getString("ConfigView.label.please.visit.here"));
        linkLabel.setData(Constants.URL_WIKI + "w/Public_Private_Keys");
        linkLabel.setCursor(linkLabel.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
        linkLabel.setForeground(Colors.blue);
        gridData = new GridData();
        gridData.horizontalSpan = 3;
        linkLabel.setLayoutData(gridData);
        linkLabel.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseDoubleClick(MouseEvent arg0) {
                Utils.launch((String) ((Label) arg0.widget).getData());
            }

            @Override
            public void mouseDown(MouseEvent arg0) {
                Utils.launch((String) ((Label) arg0.widget).getData());
            }
        });
        ClipboardCopy.addCopyToClipMenu(linkLabel);
        // publick key display
        byte[] public_key = crypt_man.getECCHandler().peekPublicKey();
        Label public_key_label = new Label(crypto_group, SWT.NULL);
        Messages.setLanguageText(public_key_label, "ConfigView.section.security.publickey");
        final Label public_key_value = new Label(crypto_group, SWT.NULL);
        if (public_key == null) {
            Messages.setLanguageText(public_key_value, "ConfigView.section.security.publickey.undef");
        } else {
            public_key_value.setText(Base32.encode(public_key));
        }
        Messages.setLanguageText(public_key_value, "ConfigView.copy.to.clipboard.tooltip", true);
        public_key_value.setCursor(public_key_value.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
        public_key_value.setForeground(Colors.blue);
        public_key_value.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseDoubleClick(MouseEvent arg0) {
                copyToClipboard();
            }

            @Override
            public void mouseDown(MouseEvent arg0) {
                copyToClipboard();
            }

            protected void copyToClipboard() {
                new Clipboard(parent.getDisplay()).setContents(new Object[] { public_key_value.getText() }, new Transfer[] { TextTransfer.getInstance() });
            }
        });
        final CryptoManagerKeyListener cryptoManagerKeyListener = new CryptoManagerKeyListener() {

            @Override
            public void keyChanged(final CryptoHandler handler) {
                final CryptoManagerKeyListener me = this;
                Utils.execSWTThread(new Runnable() {

                    @Override
                    public void run() {
                        if (public_key_value.isDisposed()) {
                            crypt_man.removeKeyListener(me);
                        } else {
                            if (handler.getType() == CryptoManager.HANDLER_ECC) {
                                byte[] public_key = handler.peekPublicKey();
                                if (public_key == null) {
                                    Messages.setLanguageText(public_key_value, "ConfigView.section.security.publickey.undef");
                                } else {
                                    public_key_value.setText(Base32.encode(public_key));
                                }
                                crypto_group.layout();
                            }
                        }
                    }
                });
            }

            @Override
            public void keyLockStatusChanged(CryptoHandler handler) {
            }
        };
        crypt_man.addKeyListener(cryptoManagerKeyListener);
        parent.addDisposeListener(new DisposeListener() {

            @Override
            public void widgetDisposed(DisposeEvent e) {
                if (cryptoManagerKeyListener != null) {
                    CryptoManagerFactory.getSingleton().removeKeyListener(cryptoManagerKeyListener);
                }
            }
        });
        new Label(crypto_group, SWT.NULL);
        // manage keys
        /*
		    gridData = new GridData();
		    gridData.horizontalSpan = 3;

		    final BooleanParameter manage_keys = new BooleanParameter(
		    		crypto_group, "crypto.keys.system.managed.temp",
		    		"ConfigView.section.security.system.managed");

		    manage_keys.setLayoutData( gridData );

		    final ClientCryptoManager crypto_man 	= CryptoManagerFactory.getSingleton();
			final CryptoHandler ecc_handler = crypto_man.getECCHandler();

		    manage_keys.setSelected(
		    		ecc_handler.getDefaultPasswordHandlerType() == CryptoManagerPasswordHandler.HANDLER_TYPE_SYSTEM );


		    manage_keys.addChangeListener(
		    	new ParameterChangeAdapter ()
		    	{
		    		public void
		    		parameterChanged(
		    			Parameter 	p,
		    			boolean 	caused_internally )
		    		{
	    				boolean existing_value = ecc_handler.getDefaultPasswordHandlerType() == CryptoManagerPasswordHandler.HANDLER_TYPE_SYSTEM;

	    				if ( existing_value == manage_keys.isSelected()){

	    					return;
	    				}

	    				String	error = null;

	    				int	new_type = manage_keys.isSelected()?CryptoManagerPasswordHandler.HANDLER_TYPE_SYSTEM:CryptoManagerPasswordHandler.HANDLER_TYPE_USER;

    					try{
    						ecc_handler.setDefaultPasswordHandlerType( new_type );

    						error = null;

    					}catch( CryptoManagerPasswordException e ){

    						if ( e.wasIncorrect()){

    							error = MessageText.getString( "ConfigView.section.security.unlockkey.error" );

    						}else{

    							if ( existing_value || !ecc_handler.isUnlocked()){

    								error = MessageText.getString( "Torrent.create.progress.cancelled" );

    							}else{

    								error = MessageText.getString( "ConfigView.section.security.vuze.login" );
    							}
    						}
    					}catch( Throwable e ){

    						error = Debug.getNestedExceptionMessage( e );
    					}

	    				if ( error != null ){

	    					MessageBoxShell mb = new MessageBoxShell(
	    							SWT.ICON_ERROR | SWT.OK,
	    							MessageText.getString("ConfigView.section.security.op.error.title"),
	    							MessageText.getString("ConfigView.section.security.op.error",
	    									new String[] { error }));
	      				mb.setParent(parent.getShell());
	    					mb.open(null);
	    				}

	    				boolean new_value = ecc_handler.getDefaultPasswordHandlerType() == CryptoManagerPasswordHandler.HANDLER_TYPE_SYSTEM;

	    				if ( new_value != manage_keys.isSelected()){

	    					manage_keys.setSelected( new_value );
	    				}
		    		}
		    	});
		    */
        // reset keys
        Label reset_key_label = new Label(crypto_group, SWT.NULL);
        Messages.setLanguageText(reset_key_label, "ConfigView.section.security.resetkey");
        Button reset_key_button = new Button(crypto_group, SWT.PUSH);
        buttons.add(reset_key_button);
        Messages.setLanguageText(reset_key_button, "ConfigView.section.security.clearpasswords.button");
        reset_key_button.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                MessageBoxShell mb = new MessageBoxShell(SWT.ICON_WARNING | SWT.OK | SWT.CANCEL, MessageText.getString("ConfigView.section.security.resetkey.warning.title"), MessageText.getString("ConfigView.section.security.resetkey.warning"));
                mb.setDefaultButtonUsingStyle(SWT.CANCEL);
                mb.setParent(parent.getShell());
                mb.open(new UserPrompterResultListener() {

                    @Override
                    public void prompterClosed(int returnVal) {
                        if (returnVal != SWT.OK) {
                            return;
                        }
                        try {
                            crypt_man.getECCHandler().resetKeys("Manual key reset");
                        } catch (Throwable e) {
                            MessageBoxShell mb = new MessageBoxShell(SWT.ICON_ERROR | SWT.OK, MessageText.getString("ConfigView.section.security.resetkey.error.title"), getError(e));
                            mb.setParent(parent.getShell());
                            mb.open(null);
                        }
                    }
                });
            }
        });
        new Label(crypto_group, SWT.NULL);
        // unlock
        Label priv_key_label = new Label(crypto_group, SWT.NULL);
        Messages.setLanguageText(priv_key_label, "ConfigView.section.security.unlockkey");
        Button priv_key_button = new Button(crypto_group, SWT.PUSH);
        buttons.add(priv_key_button);
        Messages.setLanguageText(priv_key_button, "ConfigView.section.security.unlockkey.button");
        priv_key_button.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                try {
                    crypt_man.getECCHandler().getEncryptedPrivateKey("Manual unlock");
                } catch (Throwable e) {
                    MessageBoxShell mb = new MessageBoxShell(SWT.ICON_ERROR | SWT.OK, MessageText.getString("ConfigView.section.security.resetkey.error.title"), getError(e));
                    mb.setParent(parent.getShell());
                    mb.open(null);
                }
            }
        });
        new Label(crypto_group, SWT.NULL);
        // backup
        Label backup_keys_label = new Label(crypto_group, SWT.NULL);
        Messages.setLanguageText(backup_keys_label, "ConfigView.section.security.backupkeys");
        final Button backup_keys_button = new Button(crypto_group, SWT.PUSH);
        buttons.add(backup_keys_button);
        Messages.setLanguageText(backup_keys_button, "ConfigView.section.security.backupkeys.button");
        backup_keys_button.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                FileDialog dialog = new FileDialog(backup_keys_button.getShell(), SWT.APPLICATION_MODAL);
                String target = dialog.open();
                if (target != null) {
                    try {
                        String keys = crypt_man.getECCHandler().exportKeys();
                        PrintWriter pw = new PrintWriter(new FileWriter(target));
                        pw.println(keys);
                        pw.close();
                    } catch (Throwable e) {
                        MessageBoxShell mb = new MessageBoxShell(SWT.ICON_ERROR | SWT.OK, MessageText.getString("ConfigView.section.security.op.error.title"), MessageText.getString("ConfigView.section.security.op.error", new String[] { getError(e) }));
                        mb.setParent(parent.getShell());
                        mb.open(null);
                    }
                }
            }
        });
        new Label(crypto_group, SWT.NULL);
        // restore
        Label restore_keys_label = new Label(crypto_group, SWT.NULL);
        Messages.setLanguageText(restore_keys_label, "ConfigView.section.security.restorekeys");
        final Button restore_keys_button = new Button(crypto_group, SWT.PUSH);
        buttons.add(restore_keys_button);
        Messages.setLanguageText(restore_keys_button, "ConfigView.section.security.restorekeys.button");
        restore_keys_button.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                FileDialog dialog = new FileDialog(backup_keys_button.getShell(), SWT.APPLICATION_MODAL);
                String target = dialog.open();
                if (target != null) {
                    try {
                        LineNumberReader reader = new LineNumberReader(new FileReader(target));
                        String str = "";
                        try {
                            while (true) {
                                String line = reader.readLine();
                                if (line == null) {
                                    break;
                                }
                                str += line + "\r\n";
                            }
                        } finally {
                            reader.close();
                        }
                        boolean restart = crypt_man.getECCHandler().importKeys(str);
                        if (restart) {
                            MessageBoxShell mb = new MessageBoxShell(SWT.ICON_INFORMATION | SWT.OK, MessageText.getString("ConfigView.section.security.restart.title"), MessageText.getString("ConfigView.section.security.restart.msg"));
                            mb.setParent(parent.getShell());
                            mb.open(null);
                            UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
                            if (uiFunctions != null) {
                                uiFunctions.dispose(true, false);
                            }
                        }
                    } catch (Throwable e) {
                        MessageBoxShell mb = new MessageBoxShell(SWT.ICON_ERROR | SWT.OK, MessageText.getString("ConfigView.section.security.op.error.title"), MessageText.getString("ConfigView.section.security.op.error", new String[] { getError(e) }));
                        mb.setParent(parent.getShell());
                        mb.open(null);
                    }
                }
            }
        });
        new Label(crypto_group, SWT.NULL);
    }
    Utils.makeButtonsEqualWidth(buttons);
    return gSecurity;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) DisposeListener(org.eclipse.swt.events.DisposeListener) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) ArrayList(java.util.ArrayList) Image(org.eclipse.swt.graphics.Image) DisposeEvent(org.eclipse.swt.events.DisposeEvent) GridLayout(org.eclipse.swt.layout.GridLayout) MouseEvent(org.eclipse.swt.events.MouseEvent) CertificateCreatorWindow(com.biglybt.ui.swt.auth.CertificateCreatorWindow) MouseAdapter(org.eclipse.swt.events.MouseAdapter) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) GridData(org.eclipse.swt.layout.GridData) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Transfer(org.eclipse.swt.dnd.Transfer) DisposeEvent(org.eclipse.swt.events.DisposeEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) Clipboard(org.eclipse.swt.dnd.Clipboard) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader)

Example 3 with UserPrompterResultListener

use of com.biglybt.ui.UserPrompterResultListener in project BiglyBT by BiglySoftware.

the class TorrentListViewsUtils method handleNoFileExists.

/**
 * @param dm
 *
 * @since 3.0.0.7
 */
private static void handleNoFileExists(final DownloadManager dm) {
    final UIFunctionsSWT functionsSWT = UIFunctionsManagerSWT.getUIFunctionsSWT();
    if (functionsSWT == null) {
        return;
    }
    ManagerUtils.start(dm);
    MessageBoxShell mb = new MessageBoxShell(MessageText.getString("v3.mb.PlayFileNotFound.title"), MessageText.getString("v3.mb.PlayFileNotFound.text", new String[] { dm.getDisplayName() }), new String[] { MessageText.getString("v3.mb.PlayFileNotFound.button.remove"), MessageText.getString("v3.mb.PlayFileNotFound.button.redownload"), MessageText.getString("Button.cancel") }, 2);
    mb.setRelatedObject(dm);
    mb.open(new UserPrompterResultListener() {

        @Override
        public void prompterClosed(int i) {
            if (i == 0) {
                ManagerUtils.asyncStopDelete(dm, DownloadManager.STATE_STOPPED, true, false, null);
            } else if (i == 1) {
                dm.forceRecheck(new ForceRecheckListener() {

                    @Override
                    public void forceRecheckComplete(DownloadManager dm) {
                        ManagerUtils.start(dm);
                    }
                });
            }
        }
    });
}
Also used : UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT)

Example 4 with UserPrompterResultListener

use of com.biglybt.ui.UserPrompterResultListener in project BiglyBT by BiglySoftware.

the class SubscriptionsView method removeSubs.

private void removeSubs(final Subscription[] toRemove, final int startIndex) {
    if (toRemove == null || startIndex >= toRemove.length) {
        return;
    }
    if (toRemove[startIndex] == null) {
        int nextIndex = startIndex + 1;
        if (nextIndex < toRemove.length) {
            removeSubs(toRemove, nextIndex);
        }
        return;
    }
    MessageBoxShell mb = new MessageBoxShell(MessageText.getString("message.confirm.delete.title"), MessageText.getString("message.confirm.delete.text", new String[] { toRemove[startIndex].getName() }));
    if (startIndex == toRemove.length - 1) {
        mb.setButtons(0, new String[] { MessageText.getString("Button.yes"), MessageText.getString("Button.no") }, new Integer[] { 0, 1 });
    } else {
        mb.setButtons(1, new String[] { MessageText.getString("Button.removeAll"), MessageText.getString("Button.yes"), MessageText.getString("Button.no") }, new Integer[] { 2, 0, 1 });
    }
    mb.open(new UserPrompterResultListener() {

        @Override
        public void prompterClosed(int result) {
            if (result == 0) {
                toRemove[startIndex].remove();
            } else if (result == 2) {
                for (int i = startIndex; i < toRemove.length; i++) {
                    if (toRemove[i] != null) {
                        toRemove[i].remove();
                    }
                }
                return;
            }
            int nextIndex = startIndex + 1;
            if (nextIndex < toRemove.length) {
                removeSubs(toRemove, nextIndex);
            }
        }
    });
}
Also used : UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell)

Example 5 with UserPrompterResultListener

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

Aggregations

UserPrompterResultListener (com.biglybt.ui.UserPrompterResultListener)32 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)25 GridLayout (org.eclipse.swt.layout.GridLayout)6 UIInputReceiverListener (com.biglybt.pif.ui.UIInputReceiverListener)5 ArrayList (java.util.ArrayList)5 GridData (org.eclipse.swt.layout.GridData)5 SWTSkin (com.biglybt.ui.swt.skin.SWTSkin)4 SWTSkinObjectContainer (com.biglybt.ui.swt.skin.SWTSkinObjectContainer)4 List (java.util.List)4 MouseAdapter (org.eclipse.swt.events.MouseAdapter)4 MouseEvent (org.eclipse.swt.events.MouseEvent)4 Composite (org.eclipse.swt.widgets.Composite)4 AERunnable (com.biglybt.core.util.AERunnable)3 UIInputReceiver (com.biglybt.pif.ui.UIInputReceiver)3 UIManagerEvent (com.biglybt.pif.ui.UIManagerEvent)3 UIFunctionsSWT (com.biglybt.ui.swt.UIFunctionsSWT)3 ImageLoader (com.biglybt.ui.swt.imageloader.ImageLoader)3 VuzeMessageBox (com.biglybt.ui.swt.views.skin.VuzeMessageBox)3 VuzeMessageBoxListener (com.biglybt.ui.swt.views.skin.VuzeMessageBoxListener)3 File (java.io.File)3