Search in sources :

Example 1 with SubscriptionDownloadDetails

use of com.biglybt.core.subs.SubscriptionUtils.SubscriptionDownloadDetails in project BiglyBT by BiglySoftware.

the class SubscriptionWizard method setInitialViews.

protected void setInitialViews() {
    if (availableSubscriptions != null) {
        for (int i = 0; i < availableSubscriptions.length; i++) {
            SubscriptionDownloadDetails details = availableSubscriptions[i];
            if (details.getDownload() == download) {
                final int f_i = i;
                Utils.execSWTThread(new Runnable() {

                    @Override
                    public void run() {
                        libraryTable.setTopIndex(f_i);
                    }
                });
            }
        }
    }
}
Also used : SubscriptionDownloadDetails(com.biglybt.core.subs.SubscriptionUtils.SubscriptionDownloadDetails) AERunnable(com.biglybt.core.util.AERunnable)

Example 2 with SubscriptionDownloadDetails

use of com.biglybt.core.subs.SubscriptionUtils.SubscriptionDownloadDetails in project BiglyBT by BiglySoftware.

the class SubscriptionWizard method createAvailableSubscriptionComposite.

private Composite createAvailableSubscriptionComposite(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    Label hsep1 = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
    Label hsep2 = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
    Label vsep = new Label(composite, SWT.SEPARATOR | SWT.VERTICAL);
    Label subtitle1 = new Label(composite, SWT.NONE);
    Label subtitle2 = new Label(composite, SWT.NONE);
    subtitle1.setFont(subTitleFont);
    subtitle2.setFont(subTitleFont);
    subtitle1.setText(MessageText.getString("Wizard.Subscription.subscribe.library"));
    subtitle2.setText(MessageText.getString("Wizard.Subscription.subscribe.subscriptions"));
    libraryTable = new Table(composite, SWT.FULL_SELECTION | SWT.VIRTUAL | SWT.V_SCROLL | SWT.SINGLE);
    final TableColumn torrentColumn = new TableColumn(libraryTable, SWT.NONE);
    torrentColumn.setWidth(Utils.adjustPXForDPI(50));
    final Composite compEmpty = new Composite(composite, SWT.NONE);
    compEmpty.setBackground(Colors.getSystemColor(display, SWT.COLOR_WHITE));
    compEmpty.setBackgroundMode(SWT.INHERIT_DEFAULT);
    FillLayout fl = new FillLayout();
    fl.marginHeight = 15;
    fl.marginWidth = 15;
    compEmpty.setLayout(fl);
    compEmpty.setVisible(false);
    final Link labelEmpty = new Link(compEmpty, SWT.WRAP);
    labelEmpty.setText(MessageText.getString("Wizard.Subscription.subscribe.library.empty"));
    labelEmpty.setFont(subTitleFont);
    labelEmpty.setForeground(ColorCache.getColor(composite.getDisplay(), "#6D6F6E"));
    labelEmpty.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            if (event.text != null && (event.text.startsWith("http://") || event.text.startsWith("https://"))) {
                Utils.launch(event.text);
            }
        }
    });
    initColumns();
    final Composite cTV = new Composite(composite, SWT.NONE);
    cTV.setLayoutData(Utils.getFilledFormData());
    GridLayout layout = new GridLayout();
    layout.marginHeight = layout.marginWidth = layout.verticalSpacing = layout.horizontalSpacing = 0;
    cTV.setLayout(layout);
    tvSubscriptions = TableViewFactory.createTableViewSWT(Subscription.class, TABLE_SUB_WIZ, TABLE_SUB_WIZ, new TableColumnCore[0], "SubWizRank", SWT.FULL_SELECTION | SWT.VIRTUAL | SWT.V_SCROLL | SWT.SINGLE);
    tvSubscriptions.setMenuEnabled(false);
    tvSubscriptions.setHeaderVisible(false);
    tvSubscriptions.setRowDefaultHeightEM(1.4f);
    tvSubscriptions.initialize(cTV);
    tvSubscriptions.getComposite().addListener(SWT.Resize, new Listener() {

        @Override
        public void handleEvent(Event event) {
            com.biglybt.pif.ui.tables.TableColumn tcName = tvSubscriptions.getTableColumn("SubWizName");
            com.biglybt.pif.ui.tables.TableColumn tcRank = tvSubscriptions.getTableColumn("SubWizRank");
            Rectangle clientArea = ((Composite) event.widget).getClientArea();
            tcName.setWidthPX(clientArea.width - tcRank.getWidth() - 1);
        }
    });
    tvSubscriptions.addSelectionListener(new TableSelectionListener() {

        @Override
        public void selected(TableRowCore[] row) {
            Utils.execSWTThread(new AERunnable() {

                @Override
                public void runSupport() {
                    if (tvSubscriptions.getSelectedRowsSize() == 0) {
                        addButton.setEnabled(false);
                    } else {
                        addButton.setEnabled(true);
                        TableRowCore[] rows = tvSubscriptions.getSelectedRows();
                        Subscription subscription = (Subscription) rows[0].getDataSource();
                        if (subscription.isSubscribed()) {
                            addButton.setEnabled(false);
                        } else {
                            addButton.setEnabled(true);
                        }
                        addButton.setData("subscription", subscription);
                    }
                }
            });
        }

        @Override
        public void mouseExit(TableRowCore row) {
        }

        @Override
        public void mouseEnter(TableRowCore row) {
        }

        @Override
        public void focusChanged(TableRowCore focus) {
        }

        @Override
        public void deselected(TableRowCore[] rows) {
            Utils.execSWTThread(new AERunnable() {

                @Override
                public void runSupport() {
                    if (tvSubscriptions.getSelectedRowsSize() == 0) {
                        addButton.setEnabled(false);
                    }
                }
            });
        }

        @Override
        public void defaultSelected(TableRowCore[] rows, int stateMask) {
        }
    }, false);
    UIUpdaterSWT.getInstance().addUpdater(new UIUpdatable() {

        @Override
        public void updateUI() {
            if (tvSubscriptions != null) {
                tvSubscriptions.refreshTable(false);
            }
        }

        @Override
        public String getUpdateUIName() {
            return "SubWiz";
        }
    });
    Listener resizeListener = new Listener() {

        int last_width;

        @Override
        public void handleEvent(Event event) {
            Table table = (Table) event.widget;
            Rectangle rect = table.getClientArea();
            int width = rect.width - 3;
            if (width == last_width) {
                return;
            }
            last_width = width;
            int nbColumns = table.getColumnCount();
            if (nbColumns == 1) {
                table.getColumns()[0].setWidth(width);
            }
            ((Table) event.widget).update();
        }
    };
    // subscriptionTable.addListener(SWT.Resize , resizeListener);
    libraryTable.addListener(SWT.Resize, resizeListener);
    final Listener selectionListener = new Listener() {

        @Override
        public void handleEvent(Event event) {
            TableItem item = (TableItem) event.item;
            subscriptions = (Subscription[]) item.getData("subscriptions");
            tvSubscriptions.removeDataSources(tvSubscriptions.getDataSources().toArray(new Subscription[0]));
            if (subscriptions != null) {
                tvSubscriptions.addDataSources(subscriptions);
            }
            tvSubscriptions.processDataSourceQueueSync();
            addButton.setEnabled(false);
            addButton.setData("subscription", null);
            tvSubscriptions.setSelectedRows(new TableRowCore[0]);
            if (subscriptions != null && subscriptions.length > 0) {
                TableRowCore row = tvSubscriptions.getRow(subscriptions[0]);
                if (row != null) {
                    row.setSelected(true);
                }
            }
        }
    };
    libraryTable.addListener(SWT.Selection, selectionListener);
    if (availableSubscriptions != null) {
        libraryTable.addListener(SWT.SetData, new Listener() {

            @Override
            public void handleEvent(Event event) {
                TableItem item = (TableItem) event.item;
                int index = libraryTable.indexOf(item);
                SubscriptionDownloadDetails subInfo = availableSubscriptions[index];
                item.setText(subInfo.getDownload().getDisplayName());
                item.setData("subscriptions", subInfo.getSubscriptions());
                boolean isSubscribed = false;
                Subscription[] subs = subInfo.getSubscriptions();
                for (int i = 0; i < subs.length; i++) {
                    if (subs[i].isSubscribed())
                        isSubscribed = true;
                }
                if (isSubscribed) {
                    item.setForeground(Colors.getSystemColor(display, SWT.COLOR_GRAY));
                }
                if (subInfo.getDownload() == download) {
                    libraryTable.setSelection(item);
                    selectionListener.handleEvent(event);
                }
                if (index == 0 && download == null) {
                    libraryTable.setSelection(item);
                    selectionListener.handleEvent(event);
                }
                if (libraryTable.getSelectionIndex() == index) {
                    // If the item was already selected and we got the SetData afterwards, then let's populate the
                    // subscriptionsTable
                    selectionListener.handleEvent(event);
                }
            }
        });
        libraryTable.setItemCount(availableSubscriptions.length);
        if (availableSubscriptions.length == 0) {
            libraryTable.setVisible(false);
            compEmpty.setVisible(true);
        }
    } else {
        // Test code
        libraryTable.addListener(SWT.SetData, new Listener() {

            @Override
            public void handleEvent(Event event) {
                TableItem item = (TableItem) event.item;
                int index = libraryTable.indexOf(item);
                item.setText("test " + index);
            }
        });
        libraryTable.setItemCount(20);
    }
    addButton.setEnabled(false);
    addButton.setData("subscription", null);
    // final Image rssIcon = imageLoader.getImage("icon_rss");
    libraryTable.addListener(SWT.MeasureItem, new Listener() {

        @Override
        public void handleEvent(Event event) {
            event.height = 20;
        }
    });
    FormLayout formLayout = new FormLayout();
    composite.setLayout(formLayout);
    FormData data;
    data = new FormData();
    data.top = new FormAttachment(0, 0);
    data.left = new FormAttachment(40, 0);
    data.bottom = new FormAttachment(100, 0);
    vsep.setLayoutData(data);
    data = new FormData();
    data.top = new FormAttachment(0, 5);
    data.right = new FormAttachment(vsep, 0);
    data.left = new FormAttachment(0, 5);
    subtitle1.setLayoutData(data);
    data = new FormData();
    data.top = new FormAttachment(0, 5);
    data.left = new FormAttachment(vsep, 5);
    data.right = new FormAttachment(100, 0);
    subtitle2.setLayoutData(data);
    data = new FormData();
    data.top = new FormAttachment(subtitle1, 5);
    data.right = new FormAttachment(vsep, 0);
    data.left = new FormAttachment(0, 0);
    hsep1.setLayoutData(data);
    data = new FormData();
    data.top = new FormAttachment(subtitle2, 5);
    data.left = new FormAttachment(vsep, -1);
    data.right = new FormAttachment(100, 0);
    hsep2.setLayoutData(data);
    data = new FormData();
    data.top = new FormAttachment(hsep1, 0);
    data.right = new FormAttachment(vsep, 0);
    data.left = new FormAttachment(0, 0);
    data.bottom = new FormAttachment(100, 0);
    if (availableSubscriptions != null && availableSubscriptions.length > 0) {
        libraryTable.setLayoutData(data);
    } else {
        // hack: dispose libraryTable as it's not needed and draws over controls
        // (makes a white box covering text).  Would be smarter to not
        // create the libraryTable at all..
        libraryTable.dispose();
        cancelButton.setFocus();
        shell.setDefaultButton(cancelButton);
        compEmpty.setLayoutData(data);
    }
    data = new FormData();
    data.top = new FormAttachment(hsep2, 0);
    data.left = new FormAttachment(vsep, 0);
    data.right = new FormAttachment(100, 0);
    data.bottom = new FormAttachment(100, 0);
    cTV.setLayoutData(data);
    return composite;
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) TableCellAddedListener(com.biglybt.pif.ui.tables.TableCellAddedListener) TableSelectionListener(com.biglybt.ui.common.table.TableSelectionListener) TableCellSWTPaintListener(com.biglybt.ui.swt.views.table.TableCellSWTPaintListener) TableColumnCreationListener(com.biglybt.pif.ui.tables.TableColumnCreationListener) TableCellRefreshListener(com.biglybt.pif.ui.tables.TableCellRefreshListener) Listener(org.eclipse.swt.widgets.Listener) CoreRunningListener(com.biglybt.core.CoreRunningListener) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) Rectangle(org.eclipse.swt.graphics.Rectangle) TableColumnCore(com.biglybt.ui.common.table.TableColumnCore) TableRowCore(com.biglybt.ui.common.table.TableRowCore) GridLayout(org.eclipse.swt.layout.GridLayout) Subscription(com.biglybt.core.subs.Subscription) FormAttachment(org.eclipse.swt.layout.FormAttachment) UIUpdatable(com.biglybt.ui.common.updater.UIUpdatable) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) FillLayout(org.eclipse.swt.layout.FillLayout) TableSelectionListener(com.biglybt.ui.common.table.TableSelectionListener) TableColumn(org.eclipse.swt.widgets.TableColumn) SubscriptionDownloadDetails(com.biglybt.core.subs.SubscriptionUtils.SubscriptionDownloadDetails) Event(org.eclipse.swt.widgets.Event) Link(org.eclipse.swt.widgets.Link)

Example 3 with SubscriptionDownloadDetails

use of com.biglybt.core.subs.SubscriptionUtils.SubscriptionDownloadDetails in project BiglyBT by BiglySoftware.

the class SubscriptionWizard method init.

protected void init(Core core) {
    imageLoader = ImageLoader.getInstance();
    /*SubscriptionDownloadDetails[] allSubscriptions = SubscriptionUtils.getAllCachedDownloadDetails();
		List notYetSubscribed = new ArrayList(allSubscriptions.length);
		for(int i = 0 ; i < allSubscriptions.length ; i++) {
			Subscription[] subs = allSubscriptions[i].getSubscriptions();
			boolean subscribedToAll = true;
			for(int j = 0 ; j < subs.length ; j++) {
				subscribedToAll = subscribedToAll && subs[j].isSubscribed();
			}
			if(!subscribedToAll) {
				notYetSubscribed.add(allSubscriptions[i]);
			}
		}
		availableSubscriptions = (SubscriptionDownloadDetails[]) notYetSubscribed.toArray(new SubscriptionDownloadDetails[notYetSubscribed.size()]);*/
    availableSubscriptions = SubscriptionUtils.getAllCachedDownloadDetails(core);
    Arrays.sort(availableSubscriptions, new Comparator<SubscriptionDownloadDetails>() {

        @Override
        public int compare(SubscriptionDownloadDetails o1, SubscriptionDownloadDetails o2) {
            if (o1 == null || o2 == null)
                return 0;
            return o1.getDownload().getDisplayName().compareTo(o2.getDownload().getDisplayName());
        }
    });
    shell = ShellFactory.createMainShell(SWT.TITLE | SWT.CLOSE | SWT.RESIZE);
    shell.setSize(650, 400);
    Utils.centreWindow(shell);
    shell.setMinimumSize(550, 400);
    display = shell.getDisplay();
    Utils.setShellIcon(shell);
    rankingBars = imageLoader.getImage("ranking_bars");
    rankingBorderColor = new Color(display, 200, 200, 200);
    createFonts();
    shell.setText(MessageText.getString("Wizard.Subscription.title"));
    shell.addListener(SWT.Dispose, new Listener() {

        @Override
        public void handleEvent(Event event) {
            imageLoader.releaseImage("ranking_bars");
            imageLoader.releaseImage("wizard_header_bg");
            imageLoader.releaseImage("icon_rss");
            if (titleFont != null && !titleFont.isDisposed()) {
                titleFont.dispose();
            }
            if (textInputFont != null && !textInputFont.isDisposed()) {
                textInputFont.dispose();
            }
            if (boldFont != null && !boldFont.isDisposed()) {
                boldFont.dispose();
            }
            if (subTitleFont != null && !subTitleFont.isDisposed()) {
                subTitleFont.dispose();
            }
            if (rankingBorderColor != null && !rankingBorderColor.isDisposed()) {
                rankingBorderColor.dispose();
            }
        }
    });
    Composite header = new Composite(shell, SWT.NONE);
    header.setBackgroundMode(SWT.INHERIT_DEFAULT);
    header.setBackgroundImage(imageLoader.getImage("wizard_header_bg"));
    Label topSeparator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
    main = new Composite(shell, SWT.NONE);
    Label bottomSeparator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
    Composite footer = new Composite(shell, SWT.NONE);
    FormLayout layout = new FormLayout();
    shell.setLayout(layout);
    FormData data;
    data = new FormData();
    data.top = new FormAttachment(0, 0);
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    // data.height = 50;
    header.setLayoutData(data);
    data = new FormData();
    data.top = new FormAttachment(header, 0);
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    topSeparator.setLayoutData(data);
    data = new FormData();
    data.top = new FormAttachment(topSeparator, 0);
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    data.bottom = new FormAttachment(bottomSeparator, 0);
    main.setLayoutData(data);
    data = new FormData();
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    data.bottom = new FormAttachment(footer, 0);
    bottomSeparator.setLayoutData(data);
    data = new FormData();
    data.bottom = new FormAttachment(100, 0);
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    // data.height = 100;
    footer.setLayoutData(data);
    populateHeader(header);
    populateFooter(footer);
    mainLayout = new StackLayout();
    main.setLayout(mainLayout);
    optinComposite = createOptInComposite(main);
    createComposite = createCreateComposite(main);
    availableSubscriptionComposite = createAvailableSubscriptionComposite(main);
    setDefaultAvailableMode();
    shell.layout();
    shell.open();
    setInitialViews();
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) TableCellAddedListener(com.biglybt.pif.ui.tables.TableCellAddedListener) TableSelectionListener(com.biglybt.ui.common.table.TableSelectionListener) TableCellSWTPaintListener(com.biglybt.ui.swt.views.table.TableCellSWTPaintListener) TableColumnCreationListener(com.biglybt.pif.ui.tables.TableColumnCreationListener) TableCellRefreshListener(com.biglybt.pif.ui.tables.TableCellRefreshListener) Listener(org.eclipse.swt.widgets.Listener) CoreRunningListener(com.biglybt.core.CoreRunningListener) Composite(org.eclipse.swt.widgets.Composite) SubscriptionDownloadDetails(com.biglybt.core.subs.SubscriptionUtils.SubscriptionDownloadDetails) Color(org.eclipse.swt.graphics.Color) Label(org.eclipse.swt.widgets.Label) StackLayout(org.eclipse.swt.custom.StackLayout) Event(org.eclipse.swt.widgets.Event) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Aggregations

SubscriptionDownloadDetails (com.biglybt.core.subs.SubscriptionUtils.SubscriptionDownloadDetails)3 CoreRunningListener (com.biglybt.core.CoreRunningListener)2 AERunnable (com.biglybt.core.util.AERunnable)2 TableCellAddedListener (com.biglybt.pif.ui.tables.TableCellAddedListener)2 TableCellRefreshListener (com.biglybt.pif.ui.tables.TableCellRefreshListener)2 TableColumnCreationListener (com.biglybt.pif.ui.tables.TableColumnCreationListener)2 TableSelectionListener (com.biglybt.ui.common.table.TableSelectionListener)2 TableCellSWTPaintListener (com.biglybt.ui.swt.views.table.TableCellSWTPaintListener)2 FormAttachment (org.eclipse.swt.layout.FormAttachment)2 FormData (org.eclipse.swt.layout.FormData)2 FormLayout (org.eclipse.swt.layout.FormLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 Event (org.eclipse.swt.widgets.Event)2 Label (org.eclipse.swt.widgets.Label)2 Listener (org.eclipse.swt.widgets.Listener)2 Subscription (com.biglybt.core.subs.Subscription)1 TableColumnCore (com.biglybt.ui.common.table.TableColumnCore)1 TableRowCore (com.biglybt.ui.common.table.TableRowCore)1 UIUpdatable (com.biglybt.ui.common.updater.UIUpdatable)1 StackLayout (org.eclipse.swt.custom.StackLayout)1