Search in sources :

Example 1 with UIFunctionsSWT

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

the class SBC_TagsOverview method initTable.

/**
 * @param control
 *
 * @since 4.6.0.5
 */
private void initTable(Composite control) {
    UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
    if (uiFunctions != null) {
        UISWTInstance pluginUI = uiFunctions.getUISWTInstance();
        registerPluginViews(pluginUI);
    }
    if (tv == null) {
        tv = TableViewFactory.createTableViewSWT(Tag.class, TABLE_TAGS, TABLE_TAGS, new TableColumnCore[0], ColumnTagName.COLUMN_ID, SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
        if (txtFilter != null) {
            tv.enableFilterCheck(txtFilter, this);
        }
        tv.setRowDefaultHeightEM(1);
        tv.setEnableTabViews(true, true, null);
        table_parent = new Composite(control, SWT.BORDER);
        table_parent.setLayoutData(Utils.getFilledFormData());
        GridLayout layout = new GridLayout();
        layout.marginHeight = layout.marginWidth = layout.verticalSpacing = layout.horizontalSpacing = 0;
        table_parent.setLayout(layout);
        table_parent.addListener(SWT.Activate, new Listener() {

            @Override
            public void handleEvent(Event event) {
                // viewActive = true;
                updateSelectedContent();
            }
        });
        /*
			table_parent.addListener(SWT.Deactivate, new Listener() {
				public void handleEvent(Event event) {
					//viewActive = false;
					// don't updateSelectedContent() because we may have switched
					// to a button or a text field, and we still want out content to be
					// selected
				}
			})
			*/
        tv.addMenuFillListener(this);
        tv.addSelectionListener(this, false);
        tv.initialize(table_parent);
        tv.addCountChangeListener(new TableCountChangeListener() {

            @Override
            public void rowRemoved(TableRowCore row) {
            }

            @Override
            public void rowAdded(TableRowCore row) {
                if (datasource == row.getDataSource()) {
                    tv.setSelectedRows(new TableRowCore[] { row });
                }
            }
        });
    }
    control.layout(true);
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) UIManagerListener(com.biglybt.pif.ui.UIManagerListener) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) UIPluginViewToolBarListener(com.biglybt.pif.ui.UIPluginViewToolBarListener) TableViewSWTMenuFillListener(com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener) TableColumnCreationListener(com.biglybt.pif.ui.tables.TableColumnCreationListener) UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT) UISWTInstance(com.biglybt.ui.swt.pif.UISWTInstance)

Example 2 with UIFunctionsSWT

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

the class SBC_TorrentDetailsView method initialize.

private void initialize(Composite composite) {
    Composite main_area = new Composite(composite, SWT.NULL);
    main_area.setLayout(new FormLayout());
    // Color bg_color = ColorCache.getColor(composite.getDisplay(), "#c0cbd4");
    UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
    this.parent = composite;
    if (tabbedMDI == null) {
        tabbedMDI = uiFunctions.createTabbedMDI(main_area, "detailsview");
    } else {
        System.out.println("ManagerView::initialize : folder isn't null !!!");
    }
    if (composite.getLayout() instanceof FormLayout) {
        main_area.setLayoutData(Utils.getFilledFormData());
    } else if (composite.getLayout() instanceof GridLayout) {
        main_area.setLayoutData(new GridData(GridData.FILL_BOTH));
    }
    composite.layout();
    // Call plugin listeners
    if (uiFunctions != null) {
        UISWTInstance pluginUI = uiFunctions.getUISWTInstance();
        if (pluginUI != null) {
            MyTorrentsView.registerPluginViews(pluginUI);
            for (String id : new String[] { UISWTInstance.VIEW_MYTORRENTS, UISWTInstance.VIEW_TORRENT_DETAILS }) {
                UISWTViewEventListenerWrapper[] pluginViews = pluginUI.getViewListeners(id);
                for (UISWTViewEventListenerWrapper l : pluginViews) {
                    if (id == UISWTInstance.VIEW_MYTORRENTS && l.getViewID() == PieceInfoView.MSGID_PREFIX) {
                        // Simple hack to exlude PieceInfoView tab as it's already within Pieces View
                        continue;
                    }
                    if (l != null) {
                        try {
                            tabbedMDI.createEntryFromEventListener(null, UISWTInstance.VIEW_TORRENT_DETAILS, l, l.getViewID(), false, manager, null);
                        } catch (Throwable e) {
                            Debug.out(e);
                        }
                    }
                }
            }
        }
    }
    SelectedContentManager.addCurrentlySelectedContentListener(this);
    tabbedMDI.addListener(new MdiSWTMenuHackListener() {

        @Override
        public void menuWillBeShown(MdiEntry entry, Menu menuTree) {
            menuTree.setData("downloads", new DownloadManager[] { manager });
            menuTree.setData("is_detailed_view", true);
            MenuFactory.buildTorrentMenu(menuTree);
        }
    });
    if (dataSource instanceof Object[] && ((Object[]) dataSource)[0] instanceof PEPeer) {
        tabbedMDI.showEntryByID(PeersView.MSGID_PREFIX);
    } else {
        MdiEntry[] entries = tabbedMDI.getEntries();
        if (entries.length > 0) {
            tabbedMDI.showEntry(entries[0]);
        }
    }
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) PEPeer(com.biglybt.core.peer.PEPeer) Composite(org.eclipse.swt.widgets.Composite) UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT) DownloadManager(com.biglybt.core.download.DownloadManager) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) UISWTViewEventListenerWrapper(com.biglybt.ui.swt.pif.UISWTInstance.UISWTViewEventListenerWrapper) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) UISWTInstance(com.biglybt.ui.swt.pif.UISWTInstance) Menu(org.eclipse.swt.widgets.Menu)

Example 3 with UIFunctionsSWT

use of com.biglybt.ui.swt.UIFunctionsSWT 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 4 with UIFunctionsSWT

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

the class ToolBarView method _refreshCoreToolBarItems.

public void _refreshCoreToolBarItems() {
    if (DEBUG && !isVisible()) {
        Debug.out("Trying to refresh core toolbar items when toolbar is not visible " + this + getMainSkinObject());
    }
    UIFunctionsSWT uiFunctionsSWT = UIFunctionsManagerSWT.getUIFunctionsSWT();
    MultipleDocumentInterfaceSWT mdi = uiFunctionsSWT != null ? uiFunctionsSWT.getMDISWT() : null;
    if (mdi != null) {
        UIToolBarItem[] allToolBarItems = tbm.getAllToolBarItems();
        MdiEntrySWT entry = mdi.getCurrentEntrySWT();
        Map<String, Long> mapStates = new HashMap<>();
        if (entry != null) {
            UIToolBarEnablerBase[] enablers = entry.getToolbarEnablers();
            for (UIToolBarEnablerBase enabler : enablers) {
                if (enabler instanceof UIPluginViewToolBarListener) {
                    try {
                        ((UIPluginViewToolBarListener) enabler).refreshToolBarItems(mapStates);
                    } catch (Throwable e) {
                        // don't trust them plugins
                        Debug.out(e);
                    }
                }
            }
        }
        ISelectedContent[] currentContent = SelectedContentManager.getCurrentlySelectedContent();
        synchronized (dm_listener_map) {
            Map<DownloadManager, DownloadManagerListener> copy = new IdentityHashMap<>(dm_listener_map);
            for (ISelectedContent content : currentContent) {
                DownloadManager dm = content.getDownloadManager();
                if (dm != null) {
                    copy.remove(dm);
                    if (!dm_listener_map.containsKey(dm)) {
                        DownloadManagerListener l = new DownloadManagerListener() {

                            @Override
                            public void stateChanged(DownloadManager manager, int state) {
                                refreshCoreToolBarItems();
                            }

                            @Override
                            public void downloadComplete(DownloadManager manager) {
                                refreshCoreToolBarItems();
                            }

                            @Override
                            public void completionChanged(DownloadManager manager, boolean bCompleted) {
                                refreshCoreToolBarItems();
                            }

                            @Override
                            public void positionChanged(DownloadManager download, int oldPosition, int newPosition) {
                                refreshCoreToolBarItems();
                            }

                            @Override
                            public void filePriorityChanged(DownloadManager download, DiskManagerFileInfo file) {
                                refreshCoreToolBarItems();
                            }
                        };
                        dm.addListener(l, false);
                        dm_listener_map.put(dm, l);
                    // System.out.println( "Added " + dm.getDisplayName() + " - size=" + dm_listener_map.size());
                    }
                }
            }
            for (Map.Entry<DownloadManager, DownloadManagerListener> e : copy.entrySet()) {
                DownloadManager dm = e.getKey();
                dm.removeListener(e.getValue());
                dm_listener_map.remove(dm);
            // System.out.println( "Removed " + dm.getDisplayName() + " - size=" + dm_listener_map.size());
            }
        }
        boolean has1Selection = currentContent.length == 1;
        boolean can_play = false;
        boolean can_stream = false;
        boolean stream_permitted = false;
        if (has1Selection) {
            if (!(currentContent[0] instanceof ISelectedVuzeFileContent)) {
                can_play = PlayUtils.canPlayDS(currentContent[0], currentContent[0].getFileIndex(), false);
                can_stream = PlayUtils.canStreamDS(currentContent[0], currentContent[0].getFileIndex(), false);
                if (can_stream) {
                    stream_permitted = PlayUtils.isStreamPermitted();
                }
            }
        }
        if (mapStates.containsKey("play")) {
            can_play |= (mapStates.get("play") & UIToolBarItem.STATE_ENABLED) > 0;
        }
        if (mapStates.containsKey("stream")) {
            can_stream |= (mapStates.get("stream") & UIToolBarItem.STATE_ENABLED) > 0;
        }
        mapStates.put("play", can_play | can_stream ? UIToolBarItem.STATE_ENABLED : 0);
        UIToolBarItem pitem = tbm.getToolBarItem("play");
        if (pitem != null) {
            if (can_stream) {
                pitem.setImageID(stream_permitted ? "image.button.stream" : "image.button.pstream");
                pitem.setTextID(stream_permitted ? "iconBar.stream" : "iconBar.pstream");
            } else {
                pitem.setImageID("image.button.play");
                pitem.setTextID("iconBar.play");
            }
        }
        UIToolBarItem ssItem = tbm.getToolBarItem("startstop");
        if (ssItem != null) {
            boolean shouldStopGroup;
            if (currentContent.length == 0 && mapStates.containsKey("start") && (!mapStates.containsKey("stop") || (mapStates.get("stop") & UIToolBarItem.STATE_ENABLED) == 0) && (mapStates.get("start") & UIToolBarItem.STATE_ENABLED) > 0) {
                shouldStopGroup = false;
            } else {
                shouldStopGroup = TorrentUtil.shouldStopGroup(currentContent);
            }
            ssItem.setTextID(shouldStopGroup ? "iconBar.stop" : "iconBar.start");
            ssItem.setImageID("image.toolbar.startstop." + (shouldStopGroup ? "stop" : "start"));
            if (currentContent.length == 0 && !mapStates.containsKey("startstop")) {
                boolean can_stop = mapStates.containsKey("stop") && (mapStates.get("stop") & UIToolBarItem.STATE_ENABLED) > 0;
                boolean can_start = mapStates.containsKey("start") && (mapStates.get("start") & UIToolBarItem.STATE_ENABLED) > 0;
                if (can_start && can_stop) {
                    can_stop = false;
                }
                if (can_start || can_stop) {
                    ssItem.setTextID(can_stop ? "iconBar.stop" : "iconBar.start");
                    ssItem.setImageID("image.toolbar.startstop." + (can_stop ? "stop" : "start"));
                    mapStates.put("startstop", UIToolBarItem.STATE_ENABLED);
                }
            }
        }
        Map<String, Long> fallBackStates = TorrentUtil.calculateToolbarStates(currentContent, null);
        for (String key : fallBackStates.keySet()) {
            if (!mapStates.containsKey(key)) {
                mapStates.put(key, fallBackStates.get(key));
            }
        }
        final String[] TBKEYS = new String[] { "play", "run", "top", "up", "down", "bottom", "start", "stop", "startstop", "remove" };
        for (String key : TBKEYS) {
            if (!mapStates.containsKey(key)) {
                mapStates.put(key, 0L);
            }
        }
        for (int i = 0; i < allToolBarItems.length; i++) {
            UIToolBarItem toolBarItem = allToolBarItems[i];
            Long state = mapStates.get(toolBarItem.getID());
            if (state != null) {
                toolBarItem.setState(state);
            }
        }
    }
}
Also used : DownloadManagerListener(com.biglybt.core.download.DownloadManagerListener) DownloadManager(com.biglybt.core.download.DownloadManager) MultipleDocumentInterfaceSWT(com.biglybt.ui.swt.mdi.MultipleDocumentInterfaceSWT) ISelectedVuzeFileContent(com.biglybt.ui.selectedcontent.ISelectedVuzeFileContent) DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) ISelectedContent(com.biglybt.ui.selectedcontent.ISelectedContent) UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT) MdiEntrySWT(com.biglybt.ui.swt.mdi.MdiEntrySWT) UIPluginViewToolBarListener(com.biglybt.pif.ui.UIPluginViewToolBarListener)

Example 5 with UIFunctionsSWT

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

the class ToolBarView method currentlySelectedContentChanged.

@Override
public void currentlySelectedContentChanged(ISelectedContent[] currentContent, String viewID) {
    // System.err.println("currentlySelectedContentChanged " + viewID + ";" + currentContent + ";" + getMainSkinObject() + this + " via " + Debug.getCompressedStackTrace());
    refreshCoreToolBarItems();
    UIFunctionsSWT uiFunctionsSWT = UIFunctionsManagerSWT.getUIFunctionsSWT();
    if (uiFunctionsSWT != null) {
        uiFunctionsSWT.refreshTorrentMenu();
    }
}
Also used : UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT)

Aggregations

UIFunctionsSWT (com.biglybt.ui.swt.UIFunctionsSWT)33 UISWTInstance (com.biglybt.ui.swt.pif.UISWTInstance)10 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)6 UserPrompterResultListener (com.biglybt.ui.UserPrompterResultListener)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 DownloadManager (com.biglybt.core.download.DownloadManager)3 UIFunctions (com.biglybt.ui.UIFunctions)3 Composite (org.eclipse.swt.widgets.Composite)3 ActivitiesEntry (com.biglybt.activities.ActivitiesEntry)2 Core (com.biglybt.core.Core)2 CoreRunningListener (com.biglybt.core.CoreRunningListener)2 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)2 PEPeer (com.biglybt.core.peer.PEPeer)2 AERunnable (com.biglybt.core.util.AERunnable)2 UIManagerListener (com.biglybt.pif.ui.UIManagerListener)2 UIPluginViewToolBarListener (com.biglybt.pif.ui.UIPluginViewToolBarListener)2 TabbedMdiMaximizeListener (com.biglybt.ui.swt.mdi.TabbedMdiMaximizeListener)2 UISWTViewEventListenerWrapper (com.biglybt.ui.swt.pif.UISWTInstance.UISWTViewEventListenerWrapper)2