Search in sources :

Example 31 with TableColumnManager

use of com.biglybt.ui.common.table.impl.TableColumnManager 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 32 with TableColumnManager

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

the class SBC_SubscriptionResultsView method initColumns.

private void initColumns(Core core) {
    synchronized (SBC_SubscriptionResultsView.class) {
        if (columnsAdded) {
            return;
        }
        columnsAdded = true;
    }
    TableColumnManager tableManager = TableColumnManager.getInstance();
    tableManager.registerColumn(SBC_SubscriptionResult.class, ColumnSubResultNew.COLUMN_ID, new TableColumnCreationListener() {

        @Override
        public void tableColumnCreated(TableColumn column) {
            new ColumnSubResultNew(column);
        }
    });
    tableManager.registerColumn(SBC_SubscriptionResult.class, ColumnSearchSubResultType.COLUMN_ID, new TableColumnCreationListener() {

        @Override
        public void tableColumnCreated(TableColumn column) {
            new ColumnSearchSubResultType(column);
        }
    });
    tableManager.registerColumn(SBC_SubscriptionResult.class, ColumnSearchSubResultName.COLUMN_ID, new TableColumnCreationListener() {

        @Override
        public void tableColumnCreated(TableColumn column) {
            new ColumnSearchSubResultName(column);
        }
    });
    tableManager.registerColumn(SBC_SubscriptionResult.class, ColumnSearchSubResultActions.COLUMN_ID, new TableColumnCreationListener() {

        @Override
        public void tableColumnCreated(TableColumn column) {
            new ColumnSearchSubResultActions(column);
        }
    });
    tableManager.registerColumn(SBC_SubscriptionResult.class, ColumnSearchSubResultSize.COLUMN_ID, new TableColumnCreationListener() {

        @Override
        public void tableColumnCreated(TableColumn column) {
            new ColumnSearchSubResultSize(column);
        }
    });
    tableManager.registerColumn(SBC_SubscriptionResult.class, ColumnSearchSubResultSeedsPeers.COLUMN_ID, new TableColumnCreationListener() {

        @Override
        public void tableColumnCreated(TableColumn column) {
            new ColumnSearchSubResultSeedsPeers(column);
        }
    });
    tableManager.registerColumn(SBC_SubscriptionResult.class, ColumnSearchSubResultRatings.COLUMN_ID, new TableColumnCreationListener() {

        @Override
        public void tableColumnCreated(TableColumn column) {
            new ColumnSearchSubResultRatings(column);
        }
    });
    tableManager.registerColumn(SBC_SubscriptionResult.class, ColumnSearchSubResultAge.COLUMN_ID, new TableColumnCreationListener() {

        @Override
        public void tableColumnCreated(TableColumn column) {
            new ColumnSearchSubResultAge(column);
        }
    });
    tableManager.registerColumn(SBC_SubscriptionResult.class, ColumnSearchSubResultRank.COLUMN_ID, new TableColumnCreationListener() {

        @Override
        public void tableColumnCreated(TableColumn column) {
            new ColumnSearchSubResultRank(column);
        }
    });
    tableManager.registerColumn(SBC_SubscriptionResult.class, ColumnSearchSubResultCategory.COLUMN_ID, new TableColumnCreationListener() {

        @Override
        public void tableColumnCreated(TableColumn column) {
            new ColumnSearchSubResultCategory(column);
        }
    });
    tableManager.registerColumn(SBC_SubscriptionResult.class, ColumnSearchSubResultHash.COLUMN_ID, new TableColumnCreationListener() {

        @Override
        public void tableColumnCreated(TableColumn column) {
            new ColumnSearchSubResultHash(column);
        }
    });
    tableManager.registerColumn(SBC_SubscriptionResult.class, ColumnSearchSubResultExisting.COLUMN_ID, new TableColumnCreationListener() {

        @Override
        public void tableColumnCreated(TableColumn column) {
            new ColumnSearchSubResultExisting(column);
        }
    });
}
Also used : ColumnSubResultNew(com.biglybt.ui.swt.columns.subscriptions.ColumnSubResultNew) TableColumn(com.biglybt.pif.ui.tables.TableColumn) TableColumnManager(com.biglybt.ui.common.table.impl.TableColumnManager) TableColumnCreationListener(com.biglybt.pif.ui.tables.TableColumnCreationListener)

Example 33 with TableColumnManager

use of com.biglybt.ui.common.table.impl.TableColumnManager 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 34 with TableColumnManager

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

the class SubscriptionsView method initialize.

private void initialize(Composite parent) {
    viewComposite = new Composite(parent, SWT.NONE);
    viewComposite.setLayout(new FormLayout());
    TableColumnCore[] columns = new TableColumnCore[] { new ColumnSubscriptionNew(TABLE_ID), new ColumnSubscriptionName(TABLE_ID), new ColumnSubscriptionNbNewResults(TABLE_ID), new ColumnSubscriptionNbResults(TABLE_ID), new ColumnSubscriptionMaxResults(TABLE_ID), new ColumnSubscriptionLastChecked(TABLE_ID), new ColumnSubscriptionSubscribers(TABLE_ID), new ColumnSubscriptionEnabled(TABLE_ID), new ColumnSubscriptionAutoDownload(TABLE_ID), new ColumnSubscriptionCategory(TABLE_ID), new ColumnSubscriptionTag(TABLE_ID), new ColumnSubscriptionParent(TABLE_ID), new ColumnSubscriptionError(TABLE_ID) };
    TableColumnManager tcm = TableColumnManager.getInstance();
    tcm.setDefaultColumnNames(TABLE_ID, new String[] { ColumnSubscriptionNew.COLUMN_ID, ColumnSubscriptionName.COLUMN_ID, ColumnSubscriptionNbNewResults.COLUMN_ID, ColumnSubscriptionNbResults.COLUMN_ID, ColumnSubscriptionAutoDownload.COLUMN_ID });
    view = TableViewFactory.createTableViewSWT(Subscription.class, TABLE_ID, TABLE_ID, columns, "name", SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
    view.addLifeCycleListener(new TableLifeCycleListener() {

        @Override
        public void tableLifeCycleEventOccurred(TableView tv, int eventType, Map<String, Object> data) {
            switch(eventType) {
                case EVENT_TABLELIFECYCLE_INITIALIZED:
                    SubscriptionManagerFactory.getSingleton().addListener(SubscriptionsView.this);
                    view.addDataSources(SubscriptionManagerFactory.getSingleton().getSubscriptions(true));
                    break;
                case EVENT_TABLELIFECYCLE_DESTROYED:
                    SubscriptionManagerFactory.getSingleton().removeListener(SubscriptionsView.this);
                    break;
            }
        }
    });
    view.addSelectionListener(new TableSelectionAdapter() {

        PluginInterface pi = PluginInitializer.getDefaultInterface();

        UIManager uim = pi.getUIManager();

        MenuManager menu_manager = uim.getMenuManager();

        TableManager table_manager = uim.getTableManager();

        ArrayList<TableContextMenuItem> menu_items = new ArrayList<>();

        SubscriptionManagerUI.MenuCreator menu_creator = new SubscriptionManagerUI.MenuCreator() {

            @Override
            public com.biglybt.pif.ui.menus.MenuItem createMenu(String resource_id) {
                TableContextMenuItem menu = table_manager.addContextMenuItem(TABLE_ID, resource_id);
                menu.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                menu_items.add(menu);
                return (menu);
            }

            @Override
            public void refreshView() {
            }
        };

        @Override
        public void defaultSelected(TableRowCore[] rows, int stateMask) {
            if (rows.length == 1) {
                TableRowCore row = rows[0];
                Subscription sub = (Subscription) row.getDataSource();
                if (sub == null) {
                    return;
                }
                if (sub.isSearchTemplate()) {
                    try {
                        VuzeFile vf = sub.getSearchTemplateVuzeFile();
                        if (vf != null) {
                            sub.setSubscribed(true);
                            VuzeFileHandler.getSingleton().handleFiles(new VuzeFile[] { vf }, VuzeFileComponent.COMP_TYPE_NONE);
                            for (VuzeFileComponent comp : vf.getComponents()) {
                                Engine engine = (Engine) comp.getData(Engine.VUZE_FILE_COMPONENT_ENGINE_KEY);
                                if (engine != null && (engine.getSelectionState() == Engine.SEL_STATE_DESELECTED || engine.getSelectionState() == Engine.SEL_STATE_FORCE_DESELECTED)) {
                                    engine.setSelectionState(Engine.SEL_STATE_MANUAL_SELECTED);
                                }
                            }
                        }
                    } catch (Throwable e) {
                        Debug.out(e);
                    }
                } else {
                    String key = "Subscription_" + ByteFormatter.encodeString(sub.getPublicKey());
                    MultipleDocumentInterface mdi = UIFunctionsManager.getUIFunctions().getMDI();
                    if (mdi != null) {
                        mdi.showEntryByID(key);
                    }
                }
            }
        }

        @Override
        public void selected(TableRowCore[] rows) {
            rows = view.getSelectedRows();
            ISelectedContent[] sels = new ISelectedContent[rows.length];
            java.util.List<Subscription> subs = new ArrayList<>();
            for (int i = 0; i < rows.length; i++) {
                Subscription sub = (Subscription) rows[i].getDataSource();
                sels[i] = new SubscriptionSelectedContent(sub);
                if (sub != null) {
                    subs.add(sub);
                }
            }
            SelectedContentManager.changeCurrentlySelectedContent(view.getTableID(), sels, view);
            for (TableContextMenuItem mi : menu_items) {
                mi.remove();
            }
            if (subs.size() > 0) {
                SubscriptionManagerUI.createMenus(menu_manager, menu_creator, subs.toArray(new Subscription[0]));
            }
        }
    }, false);
    view.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent event) {
        }

        @Override
        public void keyReleased(KeyEvent event) {
            if (event.keyCode == SWT.DEL) {
                removeSelected();
            }
        }
    });
    view.setRowDefaultHeightEM(1.4f);
    view.initialize(viewComposite);
    final Composite composite = new Composite(viewComposite, SWT.BORDER);
    composite.setBackgroundMode(SWT.INHERIT_DEFAULT);
    composite.setBackground(ColorCache.getColor(composite.getDisplay(), "#F1F9F8"));
    Font font = composite.getFont();
    FontData[] fDatas = font.getFontData();
    for (int i = 0; i < fDatas.length; i++) {
        fDatas[i].setHeight(150 * fDatas[i].getHeight() / 100);
        if (Constants.isWindows) {
            fDatas[i].setStyle(SWT.BOLD);
        }
    }
    textFont1 = new Font(composite.getDisplay(), fDatas);
    fDatas = font.getFontData();
    for (int i = 0; i < fDatas.length; i++) {
        fDatas[i].setHeight(120 * fDatas[i].getHeight() / 100);
    }
    textFont2 = new Font(composite.getDisplay(), fDatas);
    Label preText = new Label(composite, SWT.NONE);
    preText.setForeground(ColorCache.getColor(composite.getDisplay(), "#6D6F6E"));
    preText.setFont(textFont1);
    preText.setText(MessageText.getString("subscriptions.view.help.1"));
    Label image = new Label(composite, SWT.NONE);
    ImageLoader.getInstance().setLabelImage(image, "btn_rss_add");
    Link postText = new Link(composite, SWT.NONE);
    postText.setForeground(ColorCache.getColor(composite.getDisplay(), "#6D6F6E"));
    postText.setFont(textFont2);
    postText.setText(MessageText.getString("subscriptions.view.help.2"));
    postText.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);
            }
        }
    });
    Label close = new Label(composite, SWT.NONE);
    ImageLoader.getInstance().setLabelImage(close, "image.dismissX");
    close.setCursor(composite.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
    close.addListener(SWT.MouseUp, new Listener() {

        @Override
        public void handleEvent(Event arg0) {
            COConfigurationManager.setParameter("subscriptions.view.showhelp", false);
            composite.setVisible(false);
            FormData data = (FormData) view.getComposite().getLayoutData();
            data.bottom = new FormAttachment(100, 0);
            viewComposite.layout(true);
        }
    });
    FormLayout layout = new FormLayout();
    composite.setLayout(layout);
    FormData data;
    data = new FormData();
    data.left = new FormAttachment(0, 15);
    data.top = new FormAttachment(0, 20);
    data.bottom = new FormAttachment(postText, -5);
    preText.setLayoutData(data);
    data = new FormData();
    data.left = new FormAttachment(preText, 5);
    data.top = new FormAttachment(preText, 0, SWT.CENTER);
    image.setLayoutData(data);
    data = new FormData();
    data.left = new FormAttachment(preText, 0, SWT.LEFT);
    // data.top = new FormAttachment(preText,5);
    data.bottom = new FormAttachment(100, -20);
    postText.setLayoutData(data);
    data = new FormData();
    data.right = new FormAttachment(100, -10);
    data.top = new FormAttachment(0, 10);
    close.setLayoutData(data);
    data = new FormData();
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    data.top = new FormAttachment(0, 0);
    data.bottom = new FormAttachment(composite, 0);
    viewComposite.setLayoutData(data);
    data = new FormData();
    data.left = new FormAttachment(0, 0);
    data.right = new FormAttachment(100, 0);
    data.bottom = new FormAttachment(100, 0);
    composite.setLayoutData(data);
    COConfigurationManager.setBooleanDefault("subscriptions.view.showhelp", true);
    if (!COConfigurationManager.getBooleanParameter("subscriptions.view.showhelp")) {
        composite.setVisible(false);
        data = (FormData) viewComposite.getLayoutData();
        data.bottom = new FormAttachment(100, 0);
        viewComposite.layout(true);
    }
}
Also used : ArrayList(java.util.ArrayList) UIManager(com.biglybt.pif.ui.UIManager) TableColumnManager(com.biglybt.ui.common.table.impl.TableColumnManager) ArrayList(java.util.ArrayList) Subscription(com.biglybt.core.subs.Subscription) Engine(com.biglybt.core.metasearch.Engine) FormAttachment(org.eclipse.swt.layout.FormAttachment) FormData(org.eclipse.swt.layout.FormData) FontData(org.eclipse.swt.graphics.FontData) MultipleDocumentInterface(com.biglybt.ui.mdi.MultipleDocumentInterface) SubscriptionManagerListener(com.biglybt.core.subs.SubscriptionManagerListener) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) UIPluginViewToolBarListener(com.biglybt.pif.ui.UIPluginViewToolBarListener) UISWTViewCoreEventListener(com.biglybt.ui.swt.pifimpl.UISWTViewCoreEventListener) KeyListener(org.eclipse.swt.events.KeyListener) VuzeFileComponent(com.biglybt.core.vuzefile.VuzeFileComponent) TableContextMenuItem(com.biglybt.pif.ui.tables.TableContextMenuItem) Font(org.eclipse.swt.graphics.Font) KeyEvent(org.eclipse.swt.events.KeyEvent) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) TableManager(com.biglybt.pif.ui.tables.TableManager) com.biglybt.pif.ui.menus(com.biglybt.pif.ui.menus) FormLayout(org.eclipse.swt.layout.FormLayout) PluginInterface(com.biglybt.pif.PluginInterface) KeyEvent(org.eclipse.swt.events.KeyEvent) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) KeyListener(org.eclipse.swt.events.KeyListener)

Example 35 with TableColumnManager

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

the class SBC_ArchivedDownloadsView method initColumns.

protected void initColumns() {
    synchronized (SBC_ArchivedDownloadsView.class) {
        if (columnsAdded) {
            return;
        }
        columnsAdded = true;
    }
    TableColumnManager tableManager = TableColumnManager.getInstance();
    tableManager.registerColumn(DownloadStub.class, ColumnArchiveDLName.COLUMN_ID, new TableColumnCreationListener() {

        @Override
        public void tableColumnCreated(TableColumn column) {
            new ColumnArchiveDLName(column);
        }
    });
    tableManager.registerColumn(DownloadStub.class, ColumnArchiveDLSize.COLUMN_ID, new TableColumnCreationListener() {

        @Override
        public void tableColumnCreated(TableColumn column) {
            new ColumnArchiveDLSize(column);
        }
    });
    tableManager.registerColumn(DownloadStub.class, ColumnArchiveDLFileCount.COLUMN_ID, new TableColumnCreationListener() {

        @Override
        public void tableColumnCreated(TableColumn column) {
            new ColumnArchiveDLFileCount(column);
        }
    });
    tableManager.registerColumn(DownloadStub.class, ColumnArchiveDLDate.COLUMN_ID, new TableColumnCoreCreationListener() {

        @Override
        public TableColumnCore createTableColumnCore(Class<?> forDataSourceType, String tableID, String columnID) {
            return new ColumnDateSizer(DownloadStub.class, columnID, TableColumnCreator.DATE_COLUMN_WIDTH, tableID) {
            };
        }

        @Override
        public void tableColumnCreated(TableColumn column) {
            new ColumnArchiveDLDate(column);
        }
    });
    tableManager.registerColumn(DownloadStub.class, ColumnArchiveDLTags.COLUMN_ID, new TableColumnCreationListener() {

        @Override
        public void tableColumnCreated(TableColumn column) {
            new ColumnArchiveDLTags(column);
        }
    });
    tableManager.registerColumn(DownloadStub.class, ColumnArchiveShareRatio.COLUMN_ID, new TableColumnCreationListener() {

        @Override
        public void tableColumnCreated(TableColumn column) {
            new ColumnArchiveShareRatio(column);
        }
    });
    tableManager.setDefaultColumnNames(TABLE_NAME, new String[] { ColumnArchiveDLName.COLUMN_ID, ColumnArchiveDLSize.COLUMN_ID, ColumnArchiveDLFileCount.COLUMN_ID, ColumnArchiveDLDate.COLUMN_ID, ColumnArchiveShareRatio.COLUMN_ID });
    tableManager.setDefaultSortColumnName(TABLE_NAME, ColumnArchiveDLName.COLUMN_ID);
}
Also used : ColumnDateSizer(com.biglybt.ui.swt.views.tableitems.ColumnDateSizer) TableColumn(com.biglybt.pif.ui.tables.TableColumn) TableColumnManager(com.biglybt.ui.common.table.impl.TableColumnManager) DownloadStub(com.biglybt.pif.download.DownloadStub) TableColumnCreationListener(com.biglybt.pif.ui.tables.TableColumnCreationListener)

Aggregations

TableColumnManager (com.biglybt.ui.common.table.impl.TableColumnManager)38 TableColumnCore (com.biglybt.ui.common.table.TableColumnCore)16 TableColumn (com.biglybt.pif.ui.tables.TableColumn)13 TableColumnCreationListener (com.biglybt.pif.ui.tables.TableColumnCreationListener)11 LightHashMap (com.biglybt.core.util.LightHashMap)4 UIManager (com.biglybt.pif.ui.UIManager)4 TableManager (com.biglybt.pif.ui.tables.TableManager)4 ISelectedContent (com.biglybt.ui.selectedcontent.ISelectedContent)3 Subscription (com.biglybt.core.subs.Subscription)2 UIInputReceiverListener (com.biglybt.pif.ui.UIInputReceiverListener)2 UIPluginViewToolBarListener (com.biglybt.pif.ui.UIPluginViewToolBarListener)2 UIFunctions (com.biglybt.ui.UIFunctions)2 TableColumnCoreCreationListener (com.biglybt.ui.common.table.TableColumnCoreCreationListener)2 TableRowCore (com.biglybt.ui.common.table.TableRowCore)2 DownloadUrlInfo (com.biglybt.ui.selectedcontent.DownloadUrlInfo)2 SWTSkinObject (com.biglybt.ui.swt.skin.SWTSkinObject)2 SWTSkinObjectContainer (com.biglybt.ui.swt.skin.SWTSkinObjectContainer)2 TableViewSWTMenuFillListener (com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener)2 ColumnDateSizer (com.biglybt.ui.swt.views.tableitems.ColumnDateSizer)2 Map (java.util.Map)2