Search in sources :

Example 36 with TableColumnCore

use of com.biglybt.ui.common.table.TableColumnCore in project BiglyBT by BiglySoftware.

the class TableColumnCreator method initCoreColumns.

/**
 * @since 3.1.1.1
 */
public static void initCoreColumns() {
    // short variable names to reduce wrapping
    final Map<String, cInfo> c = new LightHashMap(50);
    final Class tc = TableColumn.class;
    c.put(RankItem.COLUMN_ID, new cInfo(RankItem.class, RankItem.DATASOURCE_TYPE));
    c.put(NameItem.COLUMN_ID, new cInfo(NameItem.class, NameItem.DATASOURCE_TYPE));
    c.put(SizeItem.COLUMN_ID, new cInfo(SizeItem.class, SizeItem.DATASOURCE_TYPE));
    c.put(ColumnSizeWithDND.COLUMN_ID, new cInfo(ColumnSizeWithDND.class, ColumnSizeWithDND.DATASOURCE_TYPE));
    c.put(DoneItem.COLUMN_ID, new cInfo(DoneItem.class, DoneItem.DATASOURCE_TYPE));
    c.put(ColumnDoneWithDND.COLUMN_ID, new cInfo(ColumnDoneWithDND.class, ColumnDoneWithDND.DATASOURCE_TYPE));
    c.put(StatusItem.COLUMN_ID, new cInfo(StatusItem.class, StatusItem.DATASOURCE_TYPE));
    c.put(ETAItem.COLUMN_ID, new cInfo(ETAItem.class, ETAItem.DATASOURCE_TYPE));
    c.put(HealthItem.COLUMN_ID, new cInfo(HealthItem.class, HealthItem.DATASOURCE_TYPE));
    c.put(CommentIconItem.COLUMN_ID, new cInfo(CommentIconItem.class, CommentIconItem.DATASOURCE_TYPE));
    c.put(DownItem.COLUMN_ID, new cInfo(DownItem.class, DownItem.DATASOURCE_TYPE));
    c.put(SeedsItem.COLUMN_ID, new cInfo(SeedsItem.class, SeedsItem.DATASOURCE_TYPE));
    c.put(PeersItem.COLUMN_ID, new cInfo(PeersItem.class, PeersItem.DATASOURCE_TYPE));
    c.put(DownSpeedItem.COLUMN_ID, new cInfo(DownSpeedItem.class, DownSpeedItem.DATASOURCE_TYPE));
    c.put(UpSpeedItem.COLUMN_ID, new cInfo(UpSpeedItem.class, UpSpeedItem.DATASOURCE_TYPE));
    c.put(UpSpeedLimitItem.COLUMN_ID, new cInfo(UpSpeedLimitItem.class, UpSpeedLimitItem.DATASOURCE_TYPE));
    c.put(TrackerStatusItem.COLUMN_ID, new cInfo(TrackerStatusItem.class, TrackerStatusItem.DATASOURCE_TYPE));
    c.put(CompletedItem.COLUMN_ID, new cInfo(CompletedItem.class, CompletedItem.DATASOURCE_TYPE));
    c.put(ShareRatioItem.COLUMN_ID, new cInfo(ShareRatioItem.class, ShareRatioItem.DATASOURCE_TYPE));
    c.put(ShareRatioProgressItem.COLUMN_ID, new cInfo(ShareRatioProgressItem.class, ShareRatioProgressItem.DATASOURCE_TYPE));
    c.put(UpItem.COLUMN_ID, new cInfo(UpItem.class, UpItem.DATASOURCE_TYPE));
    c.put(RemainingItem.COLUMN_ID, new cInfo(RemainingItem.class, RemainingItem.DATASOURCE_TYPE));
    c.put(PiecesItem.COLUMN_ID, new cInfo(PiecesItem.class, PiecesItem.DATASOURCE_TYPE));
    c.put(CompletionItem.COLUMN_ID, new cInfo(CompletionItem.class, CompletionItem.DATASOURCE_TYPE));
    c.put(CommentItem.COLUMN_ID, new cInfo(CommentItem.class, CommentItem.DATASOURCE_TYPE));
    c.put(MaxUploadsItem.COLUMN_ID, new cInfo(MaxUploadsItem.class, MaxUploadsItem.DATASOURCE_TYPE));
    c.put(TotalSpeedItem.COLUMN_ID, new cInfo(TotalSpeedItem.class, TotalSpeedItem.DATASOURCE_TYPE));
    c.put(FilesDoneItem.COLUMN_ID, new cInfo(FilesDoneItem.class, FilesDoneItem.DATASOURCE_TYPE));
    c.put(FilesLinkedItem.COLUMN_ID, new cInfo(FilesLinkedItem.class, FilesLinkedItem.DATASOURCE_TYPE));
    c.put(FileExtensionItem.COLUMN_ID, new cInfo(FileExtensionItem.class, FileExtensionItem.DATASOURCE_TYPE));
    c.put(SavePathItem.COLUMN_ID, new cInfo(SavePathItem.class, SavePathItem.DATASOURCE_TYPE));
    c.put(TorrentPathItem.COLUMN_ID, new cInfo(TorrentPathItem.class, TorrentPathItem.DATASOURCE_TYPE));
    c.put(CategoryItem.COLUMN_ID, new cInfo(CategoryItem.class, CategoryItem.DATASOURCE_TYPE));
    c.put(TagsItem.COLUMN_ID, new cInfo(TagsItem.class, TagsItem.DATASOURCE_TYPE));
    c.put(TagColorsItem.COLUMN_ID, new cInfo(TagColorsItem.class, TagColorsItem.DATASOURCE_TYPE));
    c.put(TagAddedToDateItem.COLUMN_ID, new cInfo(TagAddedToDateItem.class, TagAddedToDateItem.DATASOURCE_TYPE));
    c.put(NetworksItem.COLUMN_ID, new cInfo(NetworksItem.class, NetworksItem.DATASOURCE_TYPE));
    c.put(PeerSourcesItem.COLUMN_ID, new cInfo(PeerSourcesItem.class, PeerSourcesItem.DATASOURCE_TYPE));
    c.put(AvailabilityItem.COLUMN_ID, new cInfo(AvailabilityItem.class, AvailabilityItem.DATASOURCE_TYPE));
    c.put(AvgAvailItem.COLUMN_ID, new cInfo(AvgAvailItem.class, AvgAvailItem.DATASOURCE_TYPE));
    c.put(SecondsSeedingItem.COLUMN_ID, new cInfo(SecondsSeedingItem.class, SecondsSeedingItem.DATASOURCE_TYPE));
    c.put(SecondsDownloadingItem.COLUMN_ID, new cInfo(SecondsDownloadingItem.class, SecondsDownloadingItem.DATASOURCE_TYPE));
    c.put(TimeSinceDownloadItem.COLUMN_ID, new cInfo(TimeSinceDownloadItem.class, TimeSinceDownloadItem.DATASOURCE_TYPE));
    c.put(TimeSinceUploadItem.COLUMN_ID, new cInfo(TimeSinceUploadItem.class, TimeSinceUploadItem.DATASOURCE_TYPE));
    c.put(OnlyCDing4Item.COLUMN_ID, new cInfo(OnlyCDing4Item.class, OnlyCDing4Item.DATASOURCE_TYPE));
    c.put(TrackerNextAccessItem.COLUMN_ID, new cInfo(TrackerNextAccessItem.class, TrackerNextAccessItem.DATASOURCE_TYPE));
    c.put(TrackerNameItem.COLUMN_ID, new cInfo(TrackerNameItem.class, TrackerNameItem.DATASOURCE_TYPE));
    c.put(SeedToPeerRatioItem.COLUMN_ID, new cInfo(SeedToPeerRatioItem.class, SeedToPeerRatioItem.DATASOURCE_TYPE));
    c.put(DownSpeedLimitItem.COLUMN_ID, new cInfo(DownSpeedLimitItem.class, DownSpeedLimitItem.DATASOURCE_TYPE));
    c.put(SwarmAverageSpeed.COLUMN_ID, new cInfo(SwarmAverageSpeed.class, SwarmAverageSpeed.DATASOURCE_TYPE));
    c.put(SwarmAverageCompletion.COLUMN_ID, new cInfo(SwarmAverageCompletion.class, SwarmAverageCompletion.DATASOURCE_TYPE));
    c.put(SwarmMaxCompletion.COLUMN_ID, new cInfo(SwarmMaxCompletion.class, SwarmMaxCompletion.DATASOURCE_TYPE));
    c.put(LeecherMaxCompletion.COLUMN_ID, new cInfo(LeecherMaxCompletion.class, LeecherMaxCompletion.DATASOURCE_TYPE));
    c.put(BadAvailTimeItem.COLUMN_ID, new cInfo(BadAvailTimeItem.class, BadAvailTimeItem.DATASOURCE_TYPE));
    c.put(ColumnFileCount.COLUMN_ID, new cInfo(ColumnFileCount.class, ColumnFileCount.DATASOURCE_TYPE));
    c.put(ColumnTorrentSpeed.COLUMN_ID, new cInfo(ColumnTorrentSpeed.class, ColumnTorrentSpeed.DATASOURCE_TYPE));
    c.put(MoveOnCompleteItem.COLUMN_ID, new cInfo(MoveOnCompleteItem.class, MoveOnCompleteItem.DATASOURCE_TYPE));
    c.put(DateCompletedItem.COLUMN_ID, new cInfo(DateCompletedItem.class, DateCompletedItem.DATASOURCE_TYPE));
    c.put(DateFileCompletedItem.COLUMN_ID, new cInfo(DateFileCompletedItem.class, DateFileCompletedItem.DATASOURCE_TYPE));
    c.put(DateAddedItem.COLUMN_ID, new cInfo(DateAddedItem.class, DateAddedItem.DATASOURCE_TYPE));
    c.put(DateLastActiveItem.COLUMN_ID, new cInfo(DateLastActiveItem.class, DateLastActiveItem.DATASOURCE_TYPE));
    c.put(IPFilterItem.COLUMN_ID, new cInfo(IPFilterItem.class, IPFilterItem.DATASOURCE_TYPE));
    c.put(AlertsItem.COLUMN_ID, new cInfo(AlertsItem.class, AlertsItem.DATASOURCE_TYPE));
    c.put(TorrentCreateDateItem.COLUMN_ID, new cInfo(TorrentCreateDateItem.class, TorrentCreateDateItem.DATASOURCE_TYPE));
    c.put(ColumnTC_NameInfo.COLUMN_ID, new cInfo(ColumnTC_NameInfo.class, tc));
    c.put(ColumnTC_Sample.COLUMN_ID, new cInfo(ColumnTC_Sample.class, tc));
    c.put(ColumnTC_ChosenColumn.COLUMN_ID, new cInfo(ColumnTC_ChosenColumn.class, tc));
    c.put(PeakUpItem.COLUMN_ID, new cInfo(PeakUpItem.class, PeakUpItem.DATASOURCE_TYPE));
    c.put(PeakDownItem.COLUMN_ID, new cInfo(PeakDownItem.class, PeakDownItem.DATASOURCE_TYPE));
    c.put(SmoothedUpItem.COLUMN_ID, new cInfo(SmoothedUpItem.class, SmoothedUpItem.DATASOURCE_TYPE));
    c.put(SmoothedDownItem.COLUMN_ID, new cInfo(SmoothedDownItem.class, SmoothedDownItem.DATASOURCE_TYPE));
    c.put(SmoothedETAItem.COLUMN_ID, new cInfo(SmoothedETAItem.class, SmoothedETAItem.DATASOURCE_TYPE));
    c.put(MinSRItem.COLUMN_ID, new cInfo(MinSRItem.class, MinSRItem.DATASOURCE_TYPE));
    c.put(MaxSRItem.COLUMN_ID, new cInfo(MaxSRItem.class, MaxSRItem.DATASOURCE_TYPE));
    c.put(SessionUpItem.COLUMN_ID, new cInfo(SessionUpItem.class, SessionUpItem.DATASOURCE_TYPE));
    c.put(SessionDownItem.COLUMN_ID, new cInfo(SessionDownItem.class, SessionDownItem.DATASOURCE_TYPE));
    c.put(MergedDataItem.COLUMN_ID, new cInfo(MergedDataItem.class, MergedDataItem.DATASOURCE_TYPE));
    c.put(DescriptionItem.COLUMN_ID, new cInfo(DescriptionItem.class, DescriptionItem.DATASOURCE_TYPE));
    // Core columns are implementors of TableColumn to save one class creation
    // Otherwise, we'd have to create a generic TableColumnImpl class, pass it
    // to another class so that it could manipulate it and act upon changes.
    TableColumnManager tcManager = TableColumnManager.getInstance();
    TableColumnCoreCreationListener tcCreator = new TableColumnCoreCreationListener() {

        // @see com.biglybt.ui.swt.views.table.TableColumnCoreCreationListener#createTableColumnCore(java.lang.Class, java.lang.String, java.lang.String)
        @Override
        public TableColumnCore createTableColumnCore(Class forDataSourceType, String tableID, String columnID) {
            cInfo info = (cInfo) c.get(columnID);
            try {
                Constructor constructor = info.cla.getDeclaredConstructor(new Class[] { String.class });
                TableColumnCore column = (TableColumnCore) constructor.newInstance(new Object[] { tableID });
                return column;
            } catch (Exception e) {
                Debug.out(e);
            }
            return null;
        }

        @Override
        public void tableColumnCreated(TableColumn column) {
        }
    };
    for (Iterator<String> iter = c.keySet().iterator(); iter.hasNext(); ) {
        String id = iter.next();
        cInfo info = c.get(id);
        tcManager.registerColumn(info.forDataSourceType, id, tcCreator);
    }
}
Also used : TableColumnManager(com.biglybt.ui.common.table.impl.TableColumnManager) ColumnTC_Sample(com.biglybt.ui.swt.views.columnsetup.ColumnTC_Sample) LightHashMap(com.biglybt.core.util.LightHashMap) TableColumn(com.biglybt.pif.ui.tables.TableColumn) TableColumnCore(com.biglybt.ui.common.table.TableColumnCore) Constructor(java.lang.reflect.Constructor) ColumnTC_NameInfo(com.biglybt.ui.swt.views.columnsetup.ColumnTC_NameInfo) ColumnTC_ChosenColumn(com.biglybt.ui.swt.views.columnsetup.ColumnTC_ChosenColumn) TableColumnCoreCreationListener(com.biglybt.ui.common.table.TableColumnCoreCreationListener)

Example 37 with TableColumnCore

use of com.biglybt.ui.common.table.TableColumnCore 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 38 with TableColumnCore

use of com.biglybt.ui.common.table.TableColumnCore in project BiglyBT by BiglySoftware.

the class SubscriptionWizard method initColumns.

private static void initColumns() {
    if (columnsAdded) {
        return;
    }
    columnsAdded = true;
    UIManager uiManager = PluginInitializer.getDefaultInterface().getUIManager();
    TableManager tableManager = uiManager.getTableManager();
    tableManager.registerColumn(Subscription.class, "SubWizName", new TableColumnCreationListener() {

        private Image rssIcon;

        @Override
        public void tableColumnCreated(com.biglybt.pif.ui.tables.TableColumn column) {
            // this'll get triggered for the Subscriptions Overview table too - easiest fix is to default to hidden there
            column.setVisible(column.getTableID().equals("SubscriptionWizard"));
            ImageLoader imageLoader = ImageLoader.getInstance();
            rssIcon = imageLoader.getImage("icon_rss");
            column.addCellAddedListener(new TableCellAddedListener() {

                @Override
                public void cellAdded(TableCell cell) {
                    Subscription sub = (Subscription) cell.getDataSource();
                    if (sub.isSubscribed()) {
                        cell.setForeground(0xa0, 0xa0, 0xa0);
                    }
                    cell.setText(sub.getName());
                    ((TableCellSWT) cell).setIcon(rssIcon);
                    cell.setToolTip(sub.getNameEx());
                }
            });
        }
    });
    tableManager.registerColumn(Subscription.class, "SubWizRank", new TableColumnCreationListener() {

        @Override
        public void tableColumnCreated(com.biglybt.pif.ui.tables.TableColumn column) {
            column.setWidthLimits(RANK_COLUMN_WIDTH, RANK_COLUMN_WIDTH);
            // as above
            column.setVisible(column.getTableID().equals("SubscriptionWizard"));
            column.addCellRefreshListener(new TableCellRefreshListener() {

                @Override
                public void refresh(TableCell cell) {
                    Subscription sub = (Subscription) cell.getDataSource();
                    cell.setSortValue(sub.getCachedPopularity());
                }
            });
            if (column instanceof TableColumnCore) {
                TableColumnCore columnCore = (TableColumnCore) column;
                columnCore.setSortAscending(false);
                columnCore.addCellOtherListener("SWTPaint", new TableCellSWTPaintListener() {

                    @Override
                    public void cellPaint(GC gc, TableCellSWT cell) {
                        Subscription sub = (Subscription) cell.getDataSource();
                        Rectangle bounds = cell.getBounds();
                        bounds.width -= 5;
                        bounds.height -= 7;
                        bounds.x += 2;
                        bounds.y += 3;
                        gc.setBackground(ColorCache.getColor(gc.getDevice(), 255, 255, 255));
                        gc.fillRectangle(bounds);
                        gc.setForeground(ColorCache.getColor(gc.getDevice(), 200, 200, 200));
                        gc.drawRectangle(bounds);
                        bounds.width -= 2;
                        bounds.height -= 2;
                        bounds.x += 1;
                        bounds.y += 1;
                        long popularity = sub.getCachedPopularity();
                        // Rank in pixels between 0 and 80
                        // 0 -> no subscriber
                        // 80 -> 1000 subscribers
                        int rank = 80 * (int) popularity / 1000;
                        if (rank > 80)
                            rank = 80;
                        if (rank < 5)
                            rank = 5;
                        Rectangle clipping = gc.getClipping();
                        bounds.width = rank;
                        bounds.height -= 1;
                        bounds.x += 1;
                        bounds.y += 1;
                        Utils.setClipping(gc, bounds);
                        ImageLoader imageLoader = ImageLoader.getInstance();
                        Image rankingBars = imageLoader.getImage("ranking_bars");
                        gc.drawImage(rankingBars, bounds.x, bounds.y);
                        imageLoader.releaseImage("ranking_bars");
                        Utils.setClipping(gc, clipping);
                    }
                });
            }
        }
    });
    TableColumnManager tcm = TableColumnManager.getInstance();
    tcm.setDefaultColumnNames(TABLE_SUB_WIZ, new String[] { "SubWizName", "SubWizRank" });
}
Also used : TableCellSWTPaintListener(com.biglybt.ui.swt.views.table.TableCellSWTPaintListener) TableCellSWT(com.biglybt.ui.swt.views.table.TableCellSWT) Rectangle(org.eclipse.swt.graphics.Rectangle) UIManager(com.biglybt.pif.ui.UIManager) TableColumnCore(com.biglybt.ui.common.table.TableColumnCore) Image(org.eclipse.swt.graphics.Image) TableCellAddedListener(com.biglybt.pif.ui.tables.TableCellAddedListener) TableColumnManager(com.biglybt.ui.common.table.impl.TableColumnManager) TableCellRefreshListener(com.biglybt.pif.ui.tables.TableCellRefreshListener) TableColumnCreationListener(com.biglybt.pif.ui.tables.TableColumnCreationListener) TableCell(com.biglybt.pif.ui.tables.TableCell) TableManager(com.biglybt.pif.ui.tables.TableManager) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader) Subscription(com.biglybt.core.subs.Subscription) GC(org.eclipse.swt.graphics.GC)

Example 39 with TableColumnCore

use of com.biglybt.ui.common.table.TableColumnCore in project BiglyBT by BiglySoftware.

the class SBC_LibraryTableView method initShow.

public void initShow(Core core) {
    Object data = soParent.getControl().getData("TorrentFilterMode");
    if (data instanceof Long) {
        torrentFilterMode = (int) ((Long) data).longValue();
    }
    data = soParent.getControl().getData("DataSource");
    boolean useBigTable = useBigTable();
    SWTSkinObjectTextbox soFilter = (SWTSkinObjectTextbox) skin.getSkinObject("library-filter", soParent.getParent());
    Text txtFilter = soFilter == null ? null : soFilter.getTextControl();
    SWTSkinObjectContainer soCats = (SWTSkinObjectContainer) skin.getSkinObject("library-categories", soParent.getParent());
    Composite cCats = soCats == null ? null : soCats.getComposite();
    // columns not needed for small mode, all torrents
    TableColumnCore[] columns = useBigTable || torrentFilterMode != SBC_LibraryView.TORRENTS_ALL ? getColumns() : null;
    if (null != columns) {
        TableColumnManager tcManager = TableColumnManager.getInstance();
        tcManager.addColumns(columns);
    }
    if (useBigTable) {
        if (torrentFilterMode == SBC_LibraryView.TORRENTS_COMPLETE || torrentFilterMode == SBC_LibraryView.TORRENTS_INCOMPLETE || torrentFilterMode == SBC_LibraryView.TORRENTS_UNOPENED) {
            swtViewListener = torrentView = new MyTorrentsView_Big(core, torrentFilterMode, columns, txtFilter, cCats);
        } else {
            swtViewListener = torrentView = new MyTorrentsView_Big(core, torrentFilterMode, columns, txtFilter, cCats);
        }
    } else {
        String tableID = SB_Transfers.getTableIdFromFilterMode(torrentFilterMode, false);
        if (torrentFilterMode == SBC_LibraryView.TORRENTS_COMPLETE) {
            swtViewListener = torrentView = new MyTorrentsView(core, tableID, true, columns, txtFilter, cCats, true);
        } else if (torrentFilterMode == SBC_LibraryView.TORRENTS_INCOMPLETE) {
            swtViewListener = torrentView = new MyTorrentsView(core, tableID, false, columns, txtFilter, cCats, true);
        } else if (torrentFilterMode == SBC_LibraryView.TORRENTS_UNOPENED) {
            swtViewListener = torrentView = new MyTorrentsView(core, tableID, true, columns, txtFilter, cCats, true) {

                @Override
                public boolean isOurDownloadManager(DownloadManager dm) {
                    if (PlatformTorrentUtils.getHasBeenOpened(dm)) {
                        return false;
                    }
                    return super.isOurDownloadManager(dm);
                }
            };
        } else {
            swtViewListener = new MyTorrentsSuperView(txtFilter, cCats) {

                @Override
                public void initializeDone() {
                    MyTorrentsView seedingview = getSeedingview();
                    if (seedingview != null) {
                        seedingview.overrideDefaultSelected(new TableSelectionAdapter() {

                            @Override
                            public void defaultSelected(TableRowCore[] rows, int stateMask, int origin) {
                                doDefaultClick(rows, stateMask, false, origin);
                            }
                        });
                        MyTorrentsView torrentview = getTorrentview();
                        if (torrentview != null) {
                            torrentview.overrideDefaultSelected(new TableSelectionAdapter() {

                                @Override
                                public void defaultSelected(TableRowCore[] rows, int stateMask, int origin) {
                                    doDefaultClick(rows, stateMask, false, origin);
                                }
                            });
                        }
                    }
                }
            };
        }
        if (torrentView != null) {
            torrentView.overrideDefaultSelected(new TableSelectionAdapter() {

                @Override
                public void defaultSelected(TableRowCore[] rows, int stateMask, int origin) {
                    doDefaultClick(rows, stateMask, false, origin);
                }
            });
        }
    }
    if (torrentView != null) {
        tv = torrentView.getTableView();
        if (torrentFilterMode == SBC_LibraryView.TORRENTS_UNOPENED) {
            torrentView.setRebuildListOnFocusGain(true);
        }
    }
    try {
        view = new UISWTViewImpl(ID + torrentFilterMode, UISWTInstance.VIEW_MAIN, false);
        view.setDatasource(data);
        view.setEventListener(swtViewListener, true);
    } catch (Exception e) {
        Debug.out(e);
    }
    SWTSkinObjectContainer soContents = new SWTSkinObjectContainer(skin, skin.getSkinProperties(), getUpdateUIName(), "", soMain);
    skin.layout();
    viewComposite = soContents.getComposite();
    viewComposite.setLayoutData(Utils.getFilledFormData());
    GridLayout gridLayout = new GridLayout();
    gridLayout.horizontalSpacing = gridLayout.verticalSpacing = gridLayout.marginHeight = gridLayout.marginWidth = 0;
    viewComposite.setLayout(gridLayout);
    view.initialize(viewComposite);
    SWTSkinObject soSizeSlider = skin.getSkinObject("table-size-slider", soParent.getParent());
    if (soSizeSlider instanceof SWTSkinObjectContainer) {
        SWTSkinObjectContainer so = (SWTSkinObjectContainer) soSizeSlider;
        if (tv != null && !tv.enableSizeSlider(so.getComposite(), 16, 100)) {
            so.setVisible(false);
        }
    }
    if (torrentFilterMode == SBC_LibraryView.TORRENTS_ALL && tv != null) {
        tv.addRefreshListener(new TableRowRefreshListener() {

            @Override
            public void rowRefresh(TableRow row) {
                TableRowSWT rowCore = (TableRowSWT) row;
                Object ds = rowCore.getDataSource(true);
                if (!(ds instanceof DownloadManager)) {
                    return;
                }
                DownloadManager dm = (DownloadManager) ds;
                boolean changed = false;
                boolean assumedComplete = dm.getAssumedComplete();
                if (!assumedComplete) {
                    changed |= rowCore.setAlpha(160);
                } else if (!PlatformTorrentUtils.getHasBeenOpened(dm)) {
                    changed |= rowCore.setAlpha(255);
                } else {
                    changed |= rowCore.setAlpha(255);
                }
            }
        });
    }
    viewComposite.getParent().layout(true);
}
Also used : TableSelectionAdapter(com.biglybt.ui.common.table.TableSelectionAdapter) TableRowSWT(com.biglybt.ui.swt.views.table.TableRowSWT) TableColumnCore(com.biglybt.ui.common.table.TableColumnCore) DownloadManager(com.biglybt.core.download.DownloadManager) TableColumnManager(com.biglybt.ui.common.table.impl.TableColumnManager) TableRowCore(com.biglybt.ui.common.table.TableRowCore) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) GridLayout(org.eclipse.swt.layout.GridLayout) SWTSkinObjectContainer(com.biglybt.ui.swt.skin.SWTSkinObjectContainer) SWTSkinObjectTextbox(com.biglybt.ui.swt.skin.SWTSkinObjectTextbox) MyTorrentsSuperView(com.biglybt.ui.swt.views.MyTorrentsSuperView) Composite(org.eclipse.swt.widgets.Composite) TableRowRefreshListener(com.biglybt.pif.ui.tables.TableRowRefreshListener) Text(org.eclipse.swt.widgets.Text) MyTorrentsView(com.biglybt.ui.swt.views.MyTorrentsView) UISWTViewImpl(com.biglybt.ui.swt.pifimpl.UISWTViewImpl) TableRow(com.biglybt.pif.ui.tables.TableRow) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject)

Example 40 with TableColumnCore

use of com.biglybt.ui.common.table.TableColumnCore in project BiglyBT by BiglySoftware.

the class TableCellSWTBase method refresh.

// @see TableCellCore#refresh(boolean, boolean, boolean)
@Override
public boolean refresh(boolean bDoGraphics, boolean bRowVisible, boolean bCellVisible) {
    // if (Utils.isThisThreadSWT()) {
    // System.out.println("ONSWT: " + Debug.getCompressedStackTrace());
    // }
    TableColumnCore tc = tableColumn;
    if (tc == null) {
        return false;
    }
    boolean ret = getVisuallyChangedSinceRefresh();
    // don't clear flag -- since anyone can call refresh(), only the code that
    // actually refreshes the display should clear the flag.
    // clearFlag(FLAG_VISUALLY_CHANGED_SINCE_REFRESH);
    int iErrCount = 0;
    if (refreshErrLoopCount > 2) {
        return ret;
    }
    iErrCount = tc.getConsecutiveErrCount();
    if (iErrCount > 10) {
        refreshErrLoopCount = 3;
        return ret;
    }
    if (bInRefresh) {
        // if we ever introduce plugins to refresh.
        if (bDebug)
            debug("Calling Refresh from Refresh :) Skipping.");
        return ret;
    }
    try {
        bInRefresh = true;
        if (ret) {
            long now = SystemTime.getCurrentTime();
            if (now - lastRefresh < MAX_REFRESHES_WITHIN_MS) {
                numFastRefreshes++;
                if (numFastRefreshes >= MAX_REFRESHES) {
                    if ((numFastRefreshes % MAX_REFRESHES) == 0) {
                        pluginError("this plugin is crazy. tried to refresh " + numFastRefreshes + " times in " + (now - lastRefresh) + "ms");
                    }
                    return ret;
                }
            } else {
                numFastRefreshes = 0;
                lastRefresh = now;
            }
        }
        // See bIsUpToDate variable comments
        if (bCellVisible && !isUpToDate()) {
            if (bDebug)
                debug("Setting Invalid because visible & not up to date");
            clearFlag(FLAG_VALID);
            setFlag(FLAG_UPTODATE);
        } else if (!bCellVisible && isUpToDate()) {
            if (bDebug)
                debug("Setting not up to date because cell not visible " + Debug.getCompressedStackTrace());
            clearFlag(FLAG_UPTODATE);
        }
        if (bDebug) {
            debug("Cell Valid?" + hasFlag(FLAG_VALID) + "; Visible?" + tableRow.isVisible() + "/" + isShown());
        }
        int iInterval = tc.getRefreshInterval();
        if (iInterval == TableColumnCore.INTERVAL_INVALID_ONLY && !hasFlag(FLAG_MUSTREFRESH | FLAG_VALID) && hasFlag(FLAG_SORTVALUEISTEXT) && sortValue != null && tc.getType() == TableColumnCore.TYPE_TEXT_ONLY) {
            if (bCellVisible) {
                if (bDebug)
                    debug("fast refresh: setText");
                ret = setText((String) sortValue);
                setFlag(FLAG_VALID);
            }
        } else if ((iInterval == TableColumnCore.INTERVAL_LIVE || (iInterval == TableColumnCore.INTERVAL_GRAPHIC && bDoGraphics) || (iInterval > 0 && (loopFactor % iInterval) == 0) || !hasFlag(FLAG_VALID) || hasFlag(FLAG_MUSTREFRESH))) {
            boolean bWasValid = isValid();
            ret = hasFlag(FLAG_MUSTREFRESH);
            if (ret) {
                clearFlag(FLAG_MUSTREFRESH);
            }
            if (bDebug) {
                debug("invoke refresh; wasValid? " + bWasValid);
            }
            long lTimeStart = Constants.isCVSVersion() ? SystemTime.getMonotonousTime() : 0;
            tc.invokeCellRefreshListeners(this, !bCellVisible);
            if (refreshListeners != null) {
                for (TableCellRefreshListener l : refreshListeners) {
                    if (l instanceof TableCellLightRefreshListener) {
                        ((TableCellLightRefreshListener) l).refresh(this, !bCellVisible);
                    } else {
                        l.refresh(this);
                    }
                }
            }
            if (Constants.isCVSVersion()) {
                long lTimeEnd = SystemTime.getMonotonousTime();
                tc.addRefreshTime(lTimeEnd - lTimeStart);
            }
            // This is in case the listeners set valid to false when it was true
            if (!bWasValid && !hasFlag(FLAG_MUSTREFRESH)) {
                setFlag(FLAG_VALID);
            }
        } else {
            if (bCellVisible && bDebug) {
                debug("Skipped refresh; Interval=" + iInterval);
            }
        }
        loopFactor++;
        refreshErrLoopCount = 0;
        if (iErrCount > 0)
            tc.setConsecutiveErrCount(0);
        // has changed if visually changed or "must refresh"
        ret |= getVisuallyChangedSinceRefresh();
        if (bDebug)
            debug("refresh done; visual change? " + ret + ";" + Debug.getCompressedStackTrace());
    } catch (Throwable e) {
        refreshErrLoopCount++;
        if (tc != null) {
            tc.setConsecutiveErrCount(++iErrCount);
        }
        pluginError(e);
        if (refreshErrLoopCount > 2)
            Logger.log(new LogEvent(LOGID, LogEvent.LT_ERROR, "TableCell will not be refreshed anymore this session."));
    } finally {
        bInRefresh = false;
    }
    return ret;
}
Also used : LogEvent(com.biglybt.core.logging.LogEvent) TableColumnCore(com.biglybt.ui.common.table.TableColumnCore)

Aggregations

TableColumnCore (com.biglybt.ui.common.table.TableColumnCore)41 TableColumnManager (com.biglybt.ui.common.table.impl.TableColumnManager)16 TableColumn (com.biglybt.pif.ui.tables.TableColumn)5 LightHashMap (com.biglybt.core.util.LightHashMap)4 TableRowCore (com.biglybt.ui.common.table.TableRowCore)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 TableCellCore (com.biglybt.ui.common.table.TableCellCore)3 TableColumnCoreCreationListener (com.biglybt.ui.common.table.TableColumnCoreCreationListener)3 Composite (org.eclipse.swt.widgets.Composite)3 DownloadManager (com.biglybt.core.download.DownloadManager)2 Subscription (com.biglybt.core.subs.Subscription)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 GCStringPrinter (com.biglybt.ui.swt.shells.GCStringPrinter)2 SWTSkinObject (com.biglybt.ui.swt.skin.SWTSkinObject)2 TableCellSWTPaintListener (com.biglybt.ui.swt.views.table.TableCellSWTPaintListener)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2