Search in sources :

Example 6 with TableManager

use of com.biglybt.pif.ui.tables.TableManager 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 7 with TableManager

use of com.biglybt.pif.ui.tables.TableManager 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)

Aggregations

TableManager (com.biglybt.pif.ui.tables.TableManager)7 UIManager (com.biglybt.pif.ui.UIManager)4 TableColumn (com.biglybt.pif.ui.tables.TableColumn)4 TableColumnCreationListener (com.biglybt.pif.ui.tables.TableColumnCreationListener)4 TableColumnManager (com.biglybt.ui.common.table.impl.TableColumnManager)4 TableCell (com.biglybt.pif.ui.tables.TableCell)3 TableCellRefreshListener (com.biglybt.pif.ui.tables.TableCellRefreshListener)3 Subscription (com.biglybt.core.subs.Subscription)2 Download (com.biglybt.pif.download.Download)2 TableContextMenuItem (com.biglybt.pif.ui.tables.TableContextMenuItem)2 UISWTViewEvent (com.biglybt.ui.swt.pif.UISWTViewEvent)2 TableCellSWT (com.biglybt.ui.swt.views.table.TableCellSWT)2 ArrayList (java.util.ArrayList)2 Image (org.eclipse.swt.graphics.Image)2 UnassociatedDevice (com.biglybt.core.devices.DeviceManager.UnassociatedDevice)1 DownloadManager (com.biglybt.core.download.DownloadManager)1 Engine (com.biglybt.core.metasearch.Engine)1 SubscriptionManagerListener (com.biglybt.core.subs.SubscriptionManagerListener)1 Tag (com.biglybt.core.tag.Tag)1 TagType (com.biglybt.core.tag.TagType)1