Search in sources :

Example 16 with TableColumn

use of com.biglybt.pif.ui.tables.TableColumn in project BiglyBT by BiglySoftware.

the class LocProvUtils method addColumns.

private void addColumns() {
    synchronized (this) {
        if (cl_installed || active_provider == null) {
            return;
        }
        TableManager tm = core.getPluginManager().getDefaultPluginInterface().getUIManager().getTableManager();
        String[] peer_tables = new String[] { TableManager.TABLE_TORRENT_PEERS, TableManager.TABLE_ALL_PEERS };
        for (int i = 0; i < peer_tables.length; i++) {
            TableColumn iso3166Column = tm.createColumn(peer_tables[i], "CountryCode");
            iso3166Column.initialize(TableColumn.ALIGN_LEAD, TableColumn.POSITION_LAST, 30, TableColumn.INTERVAL_INVALID_ONLY);
            iso3166Column.addCellRefreshListener(new TableCellRefreshListener() {

                @Override
                public void refresh(TableCell cell) {
                    Peer peer = (Peer) cell.getDataSource();
                    String s = getCountryCode(peer);
                    if (!cell.setSortValue(s) && cell.isValid()) {
                        return;
                    }
                    cell.setText(s);
                }
            });
            tm.addColumn(iso3166Column);
            columns.add(iso3166Column);
            // Country Name
            TableColumn countryColumn = tm.createColumn(peer_tables[i], "Country");
            countryColumn.initialize(TableColumn.ALIGN_LEAD, TableColumn.POSITION_INVISIBLE, 80, TableColumn.INTERVAL_INVALID_ONLY);
            countryColumn.addCellRefreshListener(new TableCellRefreshListener() {

                @Override
                public void refresh(TableCell cell) {
                    Peer peer = (Peer) cell.getDataSource();
                    String s = getCountryName(peer);
                    if (!cell.setSortValue(s) && cell.isValid()) {
                        return;
                    }
                    cell.setText(s);
                }
            });
            tm.addColumn(countryColumn);
            columns.add(countryColumn);
            // Small Flags
            TableColumn flagsColumn = tm.createColumn(peer_tables[i], "CountryFlagSmall");
            flagsColumn.initialize(TableColumn.ALIGN_LEAD, TableColumn.POSITION_INVISIBLE, 25, TableColumn.INTERVAL_INVALID_ONLY);
            flagsColumn.setType(TableColumn.TYPE_GRAPHIC);
            FlagListener flagListener = new FlagListener(true);
            flagsColumn.addCellRefreshListener(flagListener);
            flagsColumn.addCellToolTipListener(flagListener);
            tm.addColumn(flagsColumn);
            columns.add(flagsColumn);
            // Normal Flags
            flagsColumn = tm.createColumn(peer_tables[i], "CountryFlag");
            flagsColumn.initialize(TableColumn.ALIGN_LEAD, TableColumn.POSITION_LAST, 25, TableColumn.INTERVAL_INVALID_ONLY);
            flagsColumn.setType(TableColumn.TYPE_GRAPHIC);
            flagListener = new FlagListener(false);
            flagsColumn.addCellRefreshListener(flagListener);
            flagsColumn.addCellToolTipListener(flagListener);
            tm.addColumn(flagsColumn);
            columns.add(flagsColumn);
        }
    }
}
Also used : TableCellRefreshListener(com.biglybt.pif.ui.tables.TableCellRefreshListener) TableCell(com.biglybt.pif.ui.tables.TableCell) Peer(com.biglybt.pif.peers.Peer) TableManager(com.biglybt.pif.ui.tables.TableManager) TableColumn(com.biglybt.pif.ui.tables.TableColumn)

Example 17 with TableColumn

use of com.biglybt.pif.ui.tables.TableColumn in project BiglyBT by BiglySoftware.

the class BuddyPluginView method addBetaSubviews.

private void addBetaSubviews(boolean enable) {
    String[] views = { TableManager.TABLE_MYTORRENTS_ALL_BIG, TableManager.TABLE_MYTORRENTS_INCOMPLETE, TableManager.TABLE_MYTORRENTS_INCOMPLETE_BIG, TableManager.TABLE_MYTORRENTS_COMPLETE, "TagsView" };
    if (enable) {
        taggableLifecycleAdapter = new TaggableLifecycleAdapter() {

            @Override
            public void taggableTagged(TagType tag_type, Tag tag, Taggable taggable) {
                if (tag_type.getTagType() == TagType.TT_DOWNLOAD_MANUAL) {
                    DownloadManager dm = (DownloadManager) taggable;
                    for (BetaSubViewHolder h : beta_subviews.values()) {
                        h.tagsUpdated(dm);
                    }
                }
            }

            @Override
            public void taggableUntagged(TagType tag_type, Tag tag, Taggable taggable) {
                if (tag_type.getTagType() == TagType.TT_DOWNLOAD_MANUAL) {
                    DownloadManager dm = (DownloadManager) taggable;
                    for (BetaSubViewHolder h : beta_subviews.values()) {
                        h.tagsUpdated(dm);
                    }
                }
            }
        };
        TagManagerFactory.getTagManager().addTaggableLifecycleListener(Taggable.TT_DOWNLOAD, taggableLifecycleAdapter);
        UISWTViewEventListener listener = new UISWTViewEventListener() {

            @Override
            public boolean eventOccurred(UISWTViewEvent event) {
                UISWTView currentView = event.getView();
                switch(event.getType()) {
                    case UISWTViewEvent.TYPE_CREATE:
                        {
                            beta_subviews.put(currentView, new BetaSubViewHolder());
                            currentView.setDestroyOnDeactivate(false);
                            break;
                        }
                    case UISWTViewEvent.TYPE_INITIALIZE:
                        {
                            BetaSubViewHolder subview = beta_subviews.get(currentView);
                            if (subview != null) {
                                subview.initialise(event.getView(), (Composite) event.getData());
                            }
                            break;
                        }
                    case UISWTViewEvent.TYPE_DATASOURCE_CHANGED:
                        {
                            BetaSubViewHolder subview = beta_subviews.get(currentView);
                            if (subview != null) {
                                subview.setDataSource(event.getData());
                            }
                            break;
                        }
                    case UISWTViewEvent.TYPE_FOCUSGAINED:
                        {
                            BetaSubViewHolder subview = beta_subviews.get(currentView);
                            if (subview != null) {
                                subview.gotFocus();
                            }
                            break;
                        }
                    case UISWTViewEvent.TYPE_FOCUSLOST:
                        {
                            BetaSubViewHolder subview = beta_subviews.get(currentView);
                            if (subview != null) {
                                subview.lostFocus();
                            }
                            break;
                        }
                    case UISWTViewEvent.TYPE_DESTROY:
                        {
                            BetaSubViewHolder subview = beta_subviews.remove(currentView);
                            if (subview != null) {
                                subview.destroy();
                            }
                            break;
                        }
                }
                return true;
            }
        };
        for (String table_id : views) {
            ui_instance.addView(table_id, "azbuddy.ui.menu.chat", listener);
        }
        TableManager table_manager = plugin.getPluginInterface().getUIManager().getTableManager();
        TableCellRefreshListener msg_refresh_listener = new TableCellRefreshListener() {

            @Override
            public void refresh(TableCell _cell) {
                TableCellSWT cell = (TableCellSWT) _cell;
                Download dl = (Download) cell.getDataSource();
                if (dl == null) {
                    return;
                }
                List<ChatInstance> instances = BuddyPluginUtils.peekChatInstances(dl);
                boolean is_pending = false;
                for (ChatInstance instance : instances) {
                    if (instance.getMessageOutstanding()) {
                        is_pending = true;
                    }
                }
                Image graphic;
                String tooltip;
                int sort_order;
                if (is_pending) {
                    graphic = bs_chat_gray_text;
                    tooltip = MessageText.getString("TableColumn.header.chat.msg.out");
                    sort_order = 1;
                } else {
                    graphic = null;
                    tooltip = MessageText.getString("label.no.messages");
                    sort_order = 0;
                }
                cell.setMarginHeight(0);
                cell.setGraphic(graphic);
                cell.setToolTip(tooltip);
                cell.setSortValue(sort_order);
                cell.setCursorID(graphic == null ? SWT.CURSOR_ARROW : SWT.CURSOR_HAND);
            }
        };
        TableCellMouseListener msg_mouse_listener = new TableCellMouseListener() {

            @Override
            public void cellMouseTrigger(TableCellMouseEvent event) {
                if (event.eventType == TableCellMouseEvent.EVENT_MOUSEUP) {
                    TableCell cell = event.cell;
                    Download dl = (Download) cell.getDataSource();
                    if (dl != null) {
                        List<ChatInstance> instances = BuddyPluginUtils.peekChatInstances(dl);
                        for (ChatInstance instance : instances) {
                            if (instance.getMessageOutstanding()) {
                                try {
                                    BuddyPluginUtils.getBetaPlugin().showChat(instance);
                                } catch (Throwable e) {
                                    Debug.out(e);
                                }
                            }
                        }
                    }
                }
            }
        };
        columnMessagePending = new TableColumnCreationListener() {

            @Override
            public void tableColumnCreated(TableColumn result) {
                result.setAlignment(TableColumn.ALIGN_CENTER);
                result.setPosition(TableColumn.POSITION_LAST);
                result.setWidth(32);
                result.setRefreshInterval(TableColumn.INTERVAL_INVALID_ONLY);
                result.setType(TableColumn.TYPE_GRAPHIC);
                result.addCellRefreshListener(msg_refresh_listener);
                result.addCellMouseListener(msg_mouse_listener);
                result.setIconReference("dchat_gray", true);
                synchronized (columns) {
                    columns.add(result);
                }
            }
        };
        table_manager.registerColumn(Download.class, "azbuddy.ui.column.msgpending", columnMessagePending);
    } else {
        for (String table_id : views) {
            ui_instance.removeViews(table_id, "azbuddy.ui.menu.chat");
        }
        for (UISWTView entry : new ArrayList<>(beta_subviews.keySet())) {
            entry.closeView();
        }
        if (taggableLifecycleAdapter != null) {
            TagManagerFactory.getTagManager().removeTaggableLifecycleListener(Taggable.TT_DOWNLOAD, taggableLifecycleAdapter);
            taggableLifecycleAdapter = null;
        }
        beta_subviews.clear();
        if (columnMessagePending != null) {
            TableManager table_manager = plugin.getPluginInterface().getUIManager().getTableManager();
            table_manager.unregisterColumn(Download.class, "azbuddy.ui.column.msgpending", columnMessagePending);
            columnMessagePending = null;
            synchronized (columns) {
                columns.clear();
            }
        }
    }
}
Also used : ChatInstance(com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance) TableCellSWT(com.biglybt.ui.swt.views.table.TableCellSWT) TaggableLifecycleAdapter(com.biglybt.core.tag.TaggableLifecycleAdapter) ArrayList(java.util.ArrayList) Image(org.eclipse.swt.graphics.Image) DownloadManager(com.biglybt.core.download.DownloadManager) TableCellMouseListener(com.biglybt.pif.ui.tables.TableCellMouseListener) TableColumnCreationListener(com.biglybt.pif.ui.tables.TableColumnCreationListener) TableCell(com.biglybt.pif.ui.tables.TableCell) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) TableManager(com.biglybt.pif.ui.tables.TableManager) Download(com.biglybt.pif.download.Download) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) UISWTViewEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener) TableColumn(com.biglybt.pif.ui.tables.TableColumn) Point(org.eclipse.swt.graphics.Point) TagType(com.biglybt.core.tag.TagType) UISWTView(com.biglybt.ui.swt.pif.UISWTView) TableCellRefreshListener(com.biglybt.pif.ui.tables.TableCellRefreshListener) TableCellMouseEvent(com.biglybt.pif.ui.tables.TableCellMouseEvent) Tag(com.biglybt.core.tag.Tag) Taggable(com.biglybt.core.tag.Taggable)

Example 18 with TableColumn

use of com.biglybt.pif.ui.tables.TableColumn in project BiglyBT by BiglySoftware.

the class ColumnCS_Sent method refresh.

@Override
public void refresh(TableCell cell) {
    ClientStatsDataSource ds = (ClientStatsDataSource) cell.getDataSource();
    if (ds == null) {
        return;
    }
    long val = ds.bytesSent;
    TableColumn column = cell.getTableColumn();
    if (column != null) {
        String network = column.getUserDataString("network");
        if (network != null) {
            Map<String, Object> map = ds.perNetworkStats.get(network);
            if (map != null) {
                val = MapUtils.getMapLong(map, "bytesSent", 0);
            } else {
                val = 0;
            }
        }
    }
    if (cell.setSortValue(val) || !cell.isValid()) {
        cell.setText(DisplayFormatters.formatByteCountToKiBEtc(val));
    }
}
Also used : TableColumn(com.biglybt.pif.ui.tables.TableColumn)

Example 19 with TableColumn

use of com.biglybt.pif.ui.tables.TableColumn in project BiglyBT by BiglySoftware.

the class TableColumnSetupWindow method createTVAvail.

/**
 * @return
 *
 * @since 4.0.0.5
 */
private TableViewSWT<TableColumn> createTVAvail() {
    final TableColumnManager tcm = TableColumnManager.getInstance();
    Map<String, TableColumnCore> mapColumns = tcm.getTableColumnsAsMap(TableColumn.class, TABLEID_AVAIL);
    TableColumnCore[] columns;
    int[] widths = { 405, 105 };
    if (sampleRow == null) {
        columns = new TableColumnCore[] { mapColumns.get(ColumnTC_NameInfo.COLUMN_ID) };
        widths = new int[] { 510 };
    } else {
        columns = new TableColumnCore[] { mapColumns.get(ColumnTC_NameInfo.COLUMN_ID), mapColumns.get(ColumnTC_Sample.COLUMN_ID) };
    }
    for (int i = 0; i < columns.length; i++) {
        TableColumnCore column = columns[i];
        if (column != null) {
            column.setVisible(true);
            column.setPositionNoShift(i);
            column.setWidth(widths[i]);
        }
    }
    final TableViewSWT<TableColumn> tvAvail = TableViewFactory.createTableViewSWT(TableColumn.class, TABLEID_AVAIL, TABLEID_AVAIL, columns, ColumnTC_NameInfo.COLUMN_ID, SWT.FULL_SELECTION | SWT.VIRTUAL | SWT.SINGLE);
    tvAvail.setParentDataSource(this);
    tvAvail.setMenuEnabled(false);
    tvAvail.setRowDefaultHeightEM(5);
    tvAvail.addLifeCycleListener(new TableLifeCycleListener() {

        private DragSource dragSource;

        private DropTarget dropTarget;

        @Override
        public void tableLifeCycleEventOccurred(TableView tv, int eventType, Map<String, Object> data) {
            switch(eventType) {
                case EVENT_TABLELIFECYCLE_INITIALIZED:
                    tableViewInitialized();
                    break;
                case EVENT_TABLELIFECYCLE_DESTROYED:
                    tableViewDestroyed();
                    break;
            }
        }

        private void tableViewInitialized() {
            dragSource = tvAvail.createDragSource(DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK);
            dragSource.setTransfer(new Transfer[] { TextTransfer.getInstance() });
            dragSource.setData("tv", tvAvail);
            dragSource.addDragListener(dragSourceListener);
            dropTarget = tvAvail.createDropTarget(DND.DROP_DEFAULT | DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK | DND.DROP_TARGET_MOVE);
            dropTarget.setTransfer(new Transfer[] { TextTransfer.getInstance() });
            dropTarget.addDropListener(new DropTargetAdapter() {

                @Override
                public void drop(DropTargetEvent event) {
                    String id = (String) event.data;
                    if (!id.equals("c")) {
                        return;
                    }
                    removeSelectedChosen();
                }
            });
        }

        private void tableViewDestroyed() {
            if (dragSource != null && !dragSource.isDisposed()) {
                dragSource.dispose();
            }
            if (dropTarget != null && !dropTarget.isDisposed()) {
                dropTarget.dispose();
            }
        }
    });
    tvAvail.addSelectionListener(new TableSelectionAdapter() {

        @Override
        public void defaultSelected(TableRowCore[] rows, int stateMask) {
            for (int i = 0; i < rows.length; i++) {
                TableRowCore row = rows[i];
                TableColumnCore column = (TableColumnCore) row.getDataSource();
                chooseColumn(column, null, false);
            }
        }
    }, false);
    tvAvail.addKeyListener(new KeyListener() {

        @Override
        public void keyReleased(KeyEvent e) {
        }

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.stateMask == 0) {
                if (e.keyCode == SWT.ARROW_RIGHT) {
                    TableRowCore[] selectedRows = tvAvail.getSelectedRows();
                    for (int i = 0; i < selectedRows.length; i++) {
                        TableRowCore row = selectedRows[i];
                        TableColumnCore column = (TableColumnCore) row.getDataSource();
                        chooseColumn(column, null, false);
                        tvChosen.processDataSourceQueue();
                        row.redraw();
                    }
                    e.doit = false;
                } else if (e.keyCode == SWT.ARROW_LEFT) {
                    TableRowCore[] selectedRows = tvAvail.getSelectedRows();
                    for (int i = 0; i < selectedRows.length; i++) {
                        TableRowCore row = selectedRows[i];
                        TableColumnCore column = (TableColumnCore) row.getDataSource();
                        mapNewVisibility.put(column, Boolean.FALSE);
                        tvChosen.removeDataSource(column);
                        tvChosen.processDataSourceQueue();
                        row.redraw();
                    }
                    e.doit = false;
                }
            }
        }
    });
    return tvAvail;
}
Also used : TableColumn(com.biglybt.pif.ui.tables.TableColumn) TableColumnManager(com.biglybt.ui.common.table.impl.TableColumnManager)

Example 20 with TableColumn

use of com.biglybt.pif.ui.tables.TableColumn in project BiglyBT by BiglySoftware.

the class TableColumnSetupWindow method removeSelectedChosen.

/**
 * @since 4.0.0.5
 */
protected void removeSelectedChosen() {
    Object[] datasources = tvChosen.getSelectedDataSources().toArray();
    for (int i = 0; i < datasources.length; i++) {
        TableColumnCore column = (TableColumnCore) datasources[i];
        mapNewVisibility.put(column, Boolean.FALSE);
    }
    tvChosen.removeDataSources(datasources);
    tvChosen.processDataSourceQueue();
    for (int i = 0; i < datasources.length; i++) {
        TableRowSWT row = (TableRowSWT) tvAvail.getRow((TableColumn) datasources[i]);
        if (row != null) {
            row.redraw();
        }
    }
}
Also used : TableRowSWT(com.biglybt.ui.swt.views.table.TableRowSWT) TableColumn(com.biglybt.pif.ui.tables.TableColumn)

Aggregations

TableColumn (com.biglybt.pif.ui.tables.TableColumn)29 TableColumnManager (com.biglybt.ui.common.table.impl.TableColumnManager)13 TableColumnCreationListener (com.biglybt.pif.ui.tables.TableColumnCreationListener)11 ColumnDateSizer (com.biglybt.ui.swt.views.tableitems.ColumnDateSizer)7 TableColumnCore (com.biglybt.ui.common.table.TableColumnCore)5 DownloadHistory (com.biglybt.core.history.DownloadHistory)4 TableManager (com.biglybt.pif.ui.tables.TableManager)4 DownloadManager (com.biglybt.core.download.DownloadManager)2 LightHashMap (com.biglybt.core.util.LightHashMap)2 Download (com.biglybt.pif.download.Download)2 UIInputReceiverListener (com.biglybt.pif.ui.UIInputReceiverListener)2 UIManager (com.biglybt.pif.ui.UIManager)2 TableCell (com.biglybt.pif.ui.tables.TableCell)2 TableCellRefreshListener (com.biglybt.pif.ui.tables.TableCellRefreshListener)2 ChatInstance (com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance)2 TableCellCore (com.biglybt.ui.common.table.TableCellCore)2 TableColumnCoreCreationListener (com.biglybt.ui.common.table.TableColumnCoreCreationListener)2 TableRowCore (com.biglybt.ui.common.table.TableRowCore)2 UISWTViewEvent (com.biglybt.ui.swt.pif.UISWTViewEvent)2 ActivitiesEntry (com.biglybt.activities.ActivitiesEntry)1