Search in sources :

Example 1 with TableViewSWTMenuFillListener

use of com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener in project BiglyBT by BiglySoftware.

the class SBC_DevicesView method initTranscodeQueueTable.

/**
 * @param control
 *
 * @since 4.1.0.5
 */
private void initTranscodeQueueTable(Composite control) {
    String tableID;
    if (device == null) {
        tableID = TABLE_TRANSCODE_QUEUE;
    } else {
        tableID = TABLE_DEVICE_LIBRARY;
        if (device instanceof DeviceMediaRenderer) {
            DeviceMediaRenderer dmr = (DeviceMediaRenderer) device;
            if (!(dmr.canCopyToDevice() || dmr.canCopyToFolder())) {
                tableID += ":type=1";
            }
        }
    }
    tvFiles = TableViewFactory.createTableViewSWT(TranscodeFile.class, tableID, tableID, new TableColumnCore[0], device == null ? ColumnTJ_Rank.COLUMN_ID : ColumnTJ_Status.COLUMN_ID, SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
    tvFiles.setRowDefaultHeightEM(1.5f);
    tvFiles.setHeaderVisible(true);
    tvFiles.setParentDataSource(device);
    tableJobsParent = new Composite(control, SWT.NONE);
    tableJobsParent.setLayoutData(Utils.getFilledFormData());
    GridLayout layout = new GridLayout();
    layout.marginHeight = layout.marginWidth = layout.verticalSpacing = layout.horizontalSpacing = 0;
    tableJobsParent.setLayout(layout);
    tvFiles.addSelectionListener(new TableSelectionListener() {

        @Override
        public void selected(TableRowCore[] row) {
            updateSelectedContent();
        }

        @Override
        public void mouseExit(TableRowCore row) {
        }

        @Override
        public void mouseEnter(TableRowCore row) {
        }

        @Override
        public void focusChanged(TableRowCore focus) {
        }

        @Override
        public void deselected(TableRowCore[] rows) {
            updateSelectedContent();
        }

        @Override
        public void defaultSelected(TableRowCore[] rows, int stateMask) {
        }
    }, false);
    tvFiles.addLifeCycleListener(new TableLifeCycleListener() {

        @Override
        public void tableLifeCycleEventOccurred(TableView tv, int eventType, Map<String, Object> data) {
            switch(eventType) {
                case EVENT_TABLELIFECYCLE_INITIALIZED:
                    if (transTarget == null) {
                        // just add all jobs' files
                        TranscodeJob[] jobs = transcode_queue.getJobs();
                        for (TranscodeJob job : jobs) {
                            TranscodeFile file = job.getTranscodeFile();
                            if (file != null) {
                                tvFiles.addDataSource(file);
                            }
                        }
                    } else {
                        tvFiles.addDataSources(transTarget.getFiles());
                    }
                    updateSelectedContent();
                    break;
            }
        }
    });
    tvFiles.addMenuFillListener(new TableViewSWTMenuFillListener() {

        @Override
        public void fillMenu(String sColumnName, Menu menu) {
            SBC_DevicesView.this.fillMenu(menu);
        }

        @Override
        public void addThisColumnSubMenu(String columnName, Menu menuThisColumn) {
        }
    });
    tvFiles.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.stateMask == 0 && e.keyCode == SWT.DEL) {
                TranscodeFile[] selected;
                synchronized (this) {
                    if (tvFiles == null) {
                        selected = new TranscodeFile[0];
                    } else {
                        List<Object> selectedDataSources = tvFiles.getSelectedDataSources();
                        selected = selectedDataSources.toArray(new TranscodeFile[0]);
                    }
                }
                if (selected.length > 0) {
                    deleteFiles(selected, 0);
                }
                e.doit = false;
            }
        }

        @Override
        public void keyReleased(KeyEvent arg0) {
        }
    });
    tvFiles.initialize(tableJobsParent);
    control.layout(true, true);
}
Also used : TableViewSWTMenuFillListener(com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) KeyListener(org.eclipse.swt.events.KeyListener) List(java.util.List)

Example 2 with TableViewSWTMenuFillListener

use of com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener in project BiglyBT by BiglySoftware.

the class OpenTorrentOptionsWindow method setupTVTorrents.

private void setupTVTorrents(Composite parent) {
    GridLayout layout = new GridLayout();
    layout.marginWidth = layout.marginHeight = 0;
    layout.horizontalSpacing = layout.verticalSpacing = 0;
    parent.setLayout(layout);
    GridData gd;
    // table
    Composite table_area = new Composite(parent, SWT.NULL);
    layout = new GridLayout();
    layout.marginWidth = layout.marginHeight = 0;
    layout.horizontalSpacing = layout.verticalSpacing = 0;
    table_area.setLayout(layout);
    gd = new GridData(GridData.FILL_BOTH);
    Utils.setLayoutData(table_area, gd);
    // toolbar area
    Composite button_area = new Composite(parent, SWT.NULL);
    layout = new GridLayout(5, false);
    layout.marginWidth = layout.marginHeight = 0;
    layout.horizontalSpacing = layout.verticalSpacing = 0;
    layout.marginTop = 5;
    button_area.setLayout(layout);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(button_area, gd);
    Label label = new Label(button_area, SWT.NULL);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(label, gd);
    buttonTorrentUp = new Button(button_area, SWT.PUSH);
    buttonTorrentUp.setImage(loadImage("image.toolbar.up"));
    buttonTorrentUp.setToolTipText(MessageText.getString("Button.moveUp"));
    buttonTorrentUp.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            List<OpenTorrentInstance> selected = (List<OpenTorrentInstance>) (Object) tvTorrents.getSelectedDataSources();
            if (selected.size() > 1) {
                Collections.sort(selected, new Comparator<OpenTorrentInstance>() {

                    @Override
                    public int compare(OpenTorrentInstance o1, OpenTorrentInstance o2) {
                        return (o1.getIndex() - o2.getIndex());
                    }
                });
            }
            boolean modified = false;
            for (OpenTorrentInstance instance : selected) {
                int index = instance.getIndex();
                if (index > 0) {
                    open_instances.remove(instance);
                    open_instances.add(index - 1, instance);
                    modified = true;
                }
            }
            if (modified) {
                swt_updateTVTorrentButtons();
                refreshTVTorrentIndexes();
            }
        }
    });
    buttonTorrentDown = new Button(button_area, SWT.PUSH);
    buttonTorrentDown.setImage(loadImage("image.toolbar.down"));
    buttonTorrentDown.setToolTipText(MessageText.getString("Button.moveDown"));
    buttonTorrentDown.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            List<OpenTorrentInstance> selected = (List<OpenTorrentInstance>) (Object) tvTorrents.getSelectedDataSources();
            if (selected.size() > 1) {
                Collections.sort(selected, new Comparator<OpenTorrentInstance>() {

                    @Override
                    public int compare(OpenTorrentInstance o1, OpenTorrentInstance o2) {
                        return (o2.getIndex() - o1.getIndex());
                    }
                });
            }
            boolean modified = false;
            for (Object obj : selected) {
                OpenTorrentInstance instance = (OpenTorrentInstance) obj;
                int index = instance.getIndex();
                if (index < open_instances.size() - 1) {
                    open_instances.remove(instance);
                    open_instances.add(index + 1, instance);
                    modified = true;
                }
            }
            if (modified) {
                swt_updateTVTorrentButtons();
                refreshTVTorrentIndexes();
            }
        }
    });
    buttonTorrentRemove = new Button(button_area, SWT.PUSH);
    buttonTorrentRemove.setToolTipText(MessageText.getString("OpenTorrentWindow.torrent.remove"));
    buttonTorrentRemove.setImage(loadImage("image.toolbar.remove"));
    buttonTorrentRemove.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            List<Object> selected = tvTorrents.getSelectedDataSources();
            for (Object obj : selected) {
                OpenTorrentInstance instance = (OpenTorrentInstance) obj;
                removeInstance(instance, true);
            }
        }
    });
    buttonTorrentUp.setEnabled(false);
    buttonTorrentDown.setEnabled(false);
    buttonTorrentRemove.setEnabled(false);
    label = new Label(button_area, SWT.NULL);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    Utils.setLayoutData(label, gd);
    TableColumnManager tcm = TableColumnManager.getInstance();
    if (tcm.getDefaultColumnNames(TABLEID_TORRENTS) == null) {
        tcm.registerColumn(OpenTorrentInstance.class, TableColumnOTOT_Position.COLUMN_ID, new TableColumnCreationListener() {

            @Override
            public void tableColumnCreated(TableColumn column) {
                new TableColumnOTOT_Position(column);
            }
        });
        tcm.registerColumn(OpenTorrentInstance.class, TableColumnOTOT_Name.COLUMN_ID, new TableColumnCreationListener() {

            @Override
            public void tableColumnCreated(TableColumn column) {
                new TableColumnOTOT_Name(column);
            }
        });
        tcm.registerColumn(OpenTorrentInstance.class, TableColumnOTOT_Size.COLUMN_ID, new TableColumnCreationListener() {

            @Override
            public void tableColumnCreated(TableColumn column) {
                new TableColumnOTOT_Size(column);
            }
        });
        tcm.setDefaultColumnNames(TABLEID_TORRENTS, new String[] { TableColumnOTOT_Position.COLUMN_ID, TableColumnOTOT_Name.COLUMN_ID, TableColumnOTOT_Size.COLUMN_ID });
        tcm.setDefaultSortColumnName(TABLEID_TORRENTS, TableColumnOTOT_Position.COLUMN_ID);
    }
    tvTorrents = TableViewFactory.createTableViewSWT(OpenTorrentInstance.class, TABLEID_TORRENTS, TABLEID_TORRENTS, null, "#", SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
    tvTorrents.initialize(table_area);
    tvTorrents.setRowDefaultHeightEM(1.4f);
    tvTorrents.addMenuFillListener(new TableViewSWTMenuFillListener() {

        @Override
        public void fillMenu(String sColumnName, Menu menu) {
            final List<Object> selected = tvTorrents.getSelectedDataSources();
            if (selected.size() > 0) {
                final List<OpenTorrentInstance> instances = new ArrayList<>(selected.size());
                final List<OpenTorrentInstance> non_simple_instances = new ArrayList<>();
                boolean can_rtlf = false;
                for (Object o : selected) {
                    OpenTorrentInstance oti = (OpenTorrentInstance) o;
                    instances.add(oti);
                    if (!oti.getOptions().isSimpleTorrent()) {
                        non_simple_instances.add(oti);
                        if (oti.canRemoveTopLevelFolder()) {
                            can_rtlf = true;
                        }
                    }
                }
                {
                    MenuItem item = new MenuItem(menu, SWT.PUSH);
                    Messages.setLanguageText(item, "OpenTorrentWindow.fileList.changeDestination");
                    item.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            for (Object obj : selected) {
                                OpenTorrentInstance instance = (OpenTorrentInstance) obj;
                                instance.setSavePath();
                            }
                        }
                    });
                }
                {
                    MenuItem item = new MenuItem(menu, SWT.PUSH);
                    Messages.setLanguageText(item, "OpenTorrentWindow.tlf.remove");
                    item.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            for (Object obj : selected) {
                                OpenTorrentInstance instance = (OpenTorrentInstance) obj;
                                if (instance.canRemoveTopLevelFolder()) {
                                    instance.removeTopLevelFolder();
                                }
                            }
                        }
                    });
                    item.setEnabled(can_rtlf);
                }
                {
                    MenuItem item = new MenuItem(menu, SWT.CHECK);
                    item.setData(COConfigurationManager.getBooleanParameter("open.torrent.window.rename.on.tlf.change"));
                    Messages.setLanguageText(item, "OpenTorrentWindow.tlf.rename");
                    item.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            COConfigurationManager.setParameter("open.torrent.window.rename.on.tlf.change", ((MenuItem) e.widget).getSelection());
                        }
                    });
                    item.setEnabled(non_simple_instances.size() > 0);
                }
                new MenuItem(menu, SWT.SEPARATOR);
                MenuItem item = new MenuItem(menu, SWT.PUSH);
                Messages.setLanguageText(item, "Button.remove");
                item.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        for (Object obj : selected) {
                            OpenTorrentInstance instance = (OpenTorrentInstance) obj;
                            removeInstance(instance, true);
                        }
                    }
                });
                new MenuItem(menu, SWT.SEPARATOR);
            }
        }

        @Override
        public void addThisColumnSubMenu(String sColumnName, Menu menuThisColumn) {
        }
    });
    tvTorrents.addSelectionListener(new TableSelectionListener() {

        @Override
        public void selected(TableRowCore[] rows_not_used) {
            TableRowCore[] rows = tvTorrents.getSelectedRows();
            List<OpenTorrentInstance> instances = new ArrayList<>();
            for (TableRowCore row : rows) {
                instances.add((OpenTorrentInstance) row.getDataSource());
            }
            selectInstances(instances);
            updateButtons();
        }

        @Override
        public void mouseExit(TableRowCore row) {
        }

        @Override
        public void mouseEnter(TableRowCore row) {
        }

        @Override
        public void focusChanged(TableRowCore focus) {
        }

        @Override
        public void deselected(TableRowCore[] rows) {
            selected(rows);
        }

        private void updateButtons() {
            Utils.execSWTThread(new Runnable() {

                @Override
                public void run() {
                    swt_updateTVTorrentButtons();
                }
            });
        }

        @Override
        public void defaultSelected(TableRowCore[] rows, int stateMask) {
        }
    }, false);
}
Also used : TableViewSWTMenuFillListener(com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener) TableSelectionListener(com.biglybt.ui.common.table.TableSelectionListener) InitializerListener(com.biglybt.ui.InitializerListener) FileListener(com.biglybt.core.torrent.impl.TorrentOpenOptions.FileListener) TableViewSWTMenuFillListener(com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener) RelatedAttributeLookupListener(com.biglybt.core.content.RelatedAttributeLookupListener) TableColumnCreationListener(com.biglybt.pif.ui.tables.TableColumnCreationListener) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) TrackerEditorListener(com.biglybt.ui.swt.maketorrent.TrackerEditorListener) TableColumnManager(com.biglybt.ui.common.table.impl.TableColumnManager) TableColumnCreationListener(com.biglybt.pif.ui.tables.TableColumnCreationListener) TableRowCore(com.biglybt.ui.common.table.TableRowCore) List(java.util.List) TableSelectionListener(com.biglybt.ui.common.table.TableSelectionListener) TableColumn(com.biglybt.pif.ui.tables.TableColumn) Point(org.eclipse.swt.graphics.Point)

Example 3 with TableViewSWTMenuFillListener

use of com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener in project BiglyBT by BiglySoftware.

the class SBC_SubscriptionResultsView method initTable.

private void initTable(Composite control) {
    tv_subs_results = TableViewFactory.createTableViewSWT(SBC_SubscriptionResult.class, TABLE_SR, TABLE_SR, new TableColumnCore[0], ColumnSearchSubResultAge.COLUMN_ID, SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
    TableColumnManager tableManager = TableColumnManager.getInstance();
    tableManager.setDefaultColumnNames(TABLE_SR, new String[] { ColumnSubResultNew.COLUMN_ID, ColumnSearchSubResultType.COLUMN_ID, ColumnSearchSubResultName.COLUMN_ID, ColumnSearchSubResultActions.COLUMN_ID, ColumnSearchSubResultSize.COLUMN_ID, ColumnSearchSubResultSeedsPeers.COLUMN_ID, ColumnSearchSubResultRatings.COLUMN_ID, ColumnSearchSubResultAge.COLUMN_ID, ColumnSearchSubResultRank.COLUMN_ID, ColumnSearchSubResultCategory.COLUMN_ID });
    tableManager.setDefaultSortColumnName(TABLE_SR, ColumnSearchSubResultAge.COLUMN_ID);
    TableColumnCore tcc = tableManager.getTableColumnCore(TABLE_SR, ColumnSearchSubResultAge.COLUMN_ID);
    if (tcc != null) {
        tcc.setDefaultSortAscending(true);
    }
    if (txtFilter != null) {
        tv_subs_results.enableFilterCheck(txtFilter, this);
    }
    tv_subs_results.setRowDefaultHeight(COConfigurationManager.getIntParameter("Search Subs Row Height"));
    SWTSkinObject soSizeSlider = getSkinObject("table-size-slider");
    if (soSizeSlider instanceof SWTSkinObjectContainer) {
        SWTSkinObjectContainer so = (SWTSkinObjectContainer) soSizeSlider;
        if (!tv_subs_results.enableSizeSlider(so.getComposite(), 16, 100)) {
            so.setVisible(false);
        }
    }
    table_parent = new Composite(control, SWT.NONE);
    table_parent.setLayoutData(Utils.getFilledFormData());
    GridLayout layout = new GridLayout();
    layout.marginHeight = layout.marginWidth = layout.verticalSpacing = layout.horizontalSpacing = 0;
    table_parent.setLayout(layout);
    tv_subs_results.addSelectionListener(new TableSelectionListener() {

        @Override
        public void selected(TableRowCore[] _rows) {
            updateSelectedContent();
        }

        @Override
        public void mouseExit(TableRowCore row) {
        }

        @Override
        public void mouseEnter(TableRowCore row) {
        }

        @Override
        public void focusChanged(TableRowCore focus) {
            UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
            if (uiFunctions != null) {
                uiFunctions.refreshIconBar();
            }
        }

        @Override
        public void deselected(TableRowCore[] rows) {
            updateSelectedContent();
        }

        @Override
        public void defaultSelected(TableRowCore[] rows, int stateMask) {
            if (rows.length == 1) {
                SBC_SubscriptionResult rc = (SBC_SubscriptionResult) rows[0].getDataSource();
                SBC_SearchResultsView.downloadAction(rc);
            }
        }

        private void updateSelectedContent() {
            TableRowCore[] rows = tv_subs_results.getSelectedRows();
            ArrayList<ISelectedContent> valid = new ArrayList<>();
            last_selected_content.clear();
            for (int i = 0; i < rows.length; i++) {
                SBC_SubscriptionResult rc = (SBC_SubscriptionResult) rows[i].getDataSource();
                last_selected_content.add(rc);
                byte[] hash = rc.getHash();
                if (hash != null && hash.length > 0) {
                    SelectedContent sc = new SelectedContent(Base32.encode(hash), rc.getName());
                    sc.setDownloadInfo(new DownloadUrlInfo(getDownloadURI(rc)));
                    valid.add(sc);
                }
            }
            ISelectedContent[] sels = valid.toArray(new ISelectedContent[valid.size()]);
            SelectedContentManager.changeCurrentlySelectedContent("IconBarEnabler", sels, tv_subs_results);
            UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
            if (uiFunctions != null) {
                uiFunctions.refreshIconBar();
            }
        }
    }, false);
    tv_subs_results.addLifeCycleListener(new TableLifeCycleListener() {

        @Override
        public void tableLifeCycleEventOccurred(TableView tv, int eventType, Map<String, Object> data) {
            if (eventType == TableLifeCycleListener.EVENT_TABLELIFECYCLE_INITIALIZED) {
                reconcileResults(ds);
            }
        }
    });
    tv_subs_results.addMenuFillListener(new TableViewSWTMenuFillListener() {

        @Override
        public void fillMenu(String sColumnName, Menu menu) {
            Object[] _related_content = tv_subs_results.getSelectedDataSources().toArray();
            final SBC_SubscriptionResult[] results = new SBC_SubscriptionResult[_related_content.length];
            System.arraycopy(_related_content, 0, results, 0, results.length);
            MenuItem item = new MenuItem(menu, SWT.PUSH);
            item.setText(MessageText.getString("label.copy.url.to.clip"));
            item.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    StringBuffer buffer = new StringBuffer(1024);
                    for (SBC_SubscriptionResult result : results) {
                        if (buffer.length() > 0) {
                            buffer.append("\r\n");
                        }
                        buffer.append(getDownloadURI(result));
                    }
                    ClipboardCopy.copyToClipBoard(buffer.toString());
                }
            });
            item.setEnabled(results.length > 0);
            SearchSubsUtils.addMenu(results, menu);
            new MenuItem(menu, SWT.SEPARATOR);
            if (results.length == 1) {
                if (SearchSubsUtils.addMenu(results[0], menu)) {
                    new MenuItem(menu, SWT.SEPARATOR);
                }
            }
            final MenuItem remove_item = new MenuItem(menu, SWT.PUSH);
            remove_item.setText(MessageText.getString("azbuddy.ui.menu.remove"));
            Utils.setMenuItemImage(remove_item, "delete");
            remove_item.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    userDelete(results);
                }
            });
            remove_item.setEnabled(results.length > 0);
            new MenuItem(menu, SWT.SEPARATOR);
        }

        @Override
        public void addThisColumnSubMenu(String columnName, Menu menuThisColumn) {
        }
    });
    tv_subs_results.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.stateMask == 0 && e.keyCode == SWT.DEL) {
                Object[] selected;
                synchronized (this) {
                    if (tv_subs_results == null) {
                        selected = new Object[0];
                    } else {
                        selected = tv_subs_results.getSelectedDataSources().toArray();
                    }
                }
                SBC_SubscriptionResult[] content = new SBC_SubscriptionResult[selected.length];
                for (int i = 0; i < content.length; i++) {
                    content[i] = (SBC_SubscriptionResult) selected[i];
                }
                userDelete(content);
                e.doit = false;
            }
        }

        @Override
        public void keyReleased(KeyEvent arg0) {
        }
    });
    /*
		if (ds instanceof RCMItemSubView) {
	  		tv_related_content.addCountChangeListener(new TableCountChangeListener() {

	  			public void rowRemoved(TableRowCore row) {
	  				updateCount();
	  			}

	  			public void rowAdded(TableRowCore row) {
	  				updateCount();
	  			}

					private void updateCount() {
						int size = tv_related_content == null ? 0 : tv_related_content.size(false);
						((RCMItemSubView) ds).setCount(size);
					}
	  		});
	  		((RCMItemSubView) ds).setCount(0);
		}
		*/
    tv_subs_results.initialize(table_parent);
    control.layout(true);
}
Also used : DownloadUrlInfo(com.biglybt.ui.selectedcontent.DownloadUrlInfo) TableViewSWTMenuFillListener(com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener) TableColumnManager(com.biglybt.ui.common.table.impl.TableColumnManager) UIFunctions(com.biglybt.ui.UIFunctions) SelectedContent(com.biglybt.ui.selectedcontent.SelectedContent) ISelectedContent(com.biglybt.ui.selectedcontent.ISelectedContent) ISelectedContent(com.biglybt.ui.selectedcontent.ISelectedContent)

Example 4 with TableViewSWTMenuFillListener

use of com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener in project BiglyBT by BiglySoftware.

the class SBC_SearchResultsView method initTable.

private void initTable(Composite control) {
    tv_subs_results = TableViewFactory.createTableViewSWT(SBC_SearchResult.class, TABLE_SR, TABLE_SR, new TableColumnCore[0], ColumnSearchSubResultName.COLUMN_ID, SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
    TableColumnManager tableManager = TableColumnManager.getInstance();
    tableManager.setDefaultColumnNames(TABLE_SR, new String[] { ColumnSearchSubResultType.COLUMN_ID, ColumnSearchSubResultName.COLUMN_ID, ColumnSearchSubResultActions.COLUMN_ID, ColumnSearchSubResultSize.COLUMN_ID, ColumnSearchSubResultSeedsPeers.COLUMN_ID, ColumnSearchSubResultRatings.COLUMN_ID, ColumnSearchSubResultAge.COLUMN_ID, ColumnSearchSubResultRank.COLUMN_ID, ColumnSearchSubResultCategory.COLUMN_ID, ColumnSearchResultSite.COLUMN_ID });
    tableManager.setDefaultSortColumnName(TABLE_SR, ColumnSearchSubResultRank.COLUMN_ID);
    if (txtFilter != null) {
        tv_subs_results.enableFilterCheck(txtFilter, this);
    }
    tv_subs_results.setRowDefaultHeight(COConfigurationManager.getIntParameter("Search Subs Row Height"));
    SWTSkinObject soSizeSlider = getSkinObject("table-size-slider");
    if (soSizeSlider instanceof SWTSkinObjectContainer) {
        SWTSkinObjectContainer so = (SWTSkinObjectContainer) soSizeSlider;
        if (!tv_subs_results.enableSizeSlider(so.getComposite(), 16, 100)) {
            so.setVisible(false);
        }
    }
    table_parent = new Composite(control, SWT.NONE);
    table_parent.setLayoutData(Utils.getFilledFormData());
    GridLayout layout = new GridLayout();
    layout.marginHeight = layout.marginWidth = layout.verticalSpacing = layout.horizontalSpacing = 0;
    table_parent.setLayout(layout);
    tv_subs_results.addSelectionListener(new TableSelectionListener() {

        @Override
        public void selected(TableRowCore[] _rows) {
            updateSelectedContent();
        }

        @Override
        public void mouseExit(TableRowCore row) {
        }

        @Override
        public void mouseEnter(TableRowCore row) {
        }

        @Override
        public void focusChanged(TableRowCore focus) {
            UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
            if (uiFunctions != null) {
                uiFunctions.refreshIconBar();
            }
        }

        @Override
        public void deselected(TableRowCore[] rows) {
            updateSelectedContent();
        }

        @Override
        public void defaultSelected(TableRowCore[] rows, int stateMask) {
            if (rows.length == 1) {
                SBC_SearchResult rc = (SBC_SearchResult) rows[0].getDataSource();
                downloadAction(rc);
            }
        }

        private void updateSelectedContent() {
            TableRowCore[] rows = tv_subs_results.getSelectedRows();
            ArrayList<ISelectedContent> valid = new ArrayList<>();
            last_selected_content.clear();
            for (int i = 0; i < rows.length; i++) {
                SBC_SearchResult rc = (SBC_SearchResult) rows[i].getDataSource();
                last_selected_content.add(rc);
                byte[] hash = rc.getHash();
                if (hash != null && hash.length > 0) {
                    SelectedContent sc = new SelectedContent(Base32.encode(hash), rc.getName());
                    sc.setDownloadInfo(new DownloadUrlInfo(getDownloadURI(rc)));
                    valid.add(sc);
                }
            }
            ISelectedContent[] sels = valid.toArray(new ISelectedContent[valid.size()]);
            SelectedContentManager.changeCurrentlySelectedContent("IconBarEnabler", sels, tv_subs_results);
            UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
            if (uiFunctions != null) {
                uiFunctions.refreshIconBar();
            }
        }
    }, false);
    tv_subs_results.addMenuFillListener(new TableViewSWTMenuFillListener() {

        @Override
        public void fillMenu(String sColumnName, Menu menu) {
            Object[] _related_content = tv_subs_results.getSelectedDataSources().toArray();
            final SBC_SearchResult[] results = new SBC_SearchResult[_related_content.length];
            System.arraycopy(_related_content, 0, results, 0, results.length);
            MenuItem item = new MenuItem(menu, SWT.PUSH);
            item.setText(MessageText.getString("label.copy.url.to.clip"));
            item.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    StringBuffer buffer = new StringBuffer(1024);
                    for (SBC_SearchResult result : results) {
                        if (buffer.length() > 0) {
                            buffer.append("\r\n");
                        }
                        buffer.append(getDownloadURI(result));
                    }
                    ClipboardCopy.copyToClipBoard(buffer.toString());
                }
            });
            item.setEnabled(results.length > 0);
            SearchSubsUtils.addMenu(results, menu);
            new MenuItem(menu, SWT.SEPARATOR);
            if (results.length == 1) {
                if (SearchSubsUtils.addMenu(results[0], menu)) {
                    new MenuItem(menu, SWT.SEPARATOR);
                }
            }
        }

        @Override
        public void addThisColumnSubMenu(String columnName, Menu menuThisColumn) {
        }
    });
    tv_subs_results.initialize(table_parent);
    control.layout(true);
}
Also used : DownloadUrlInfo(com.biglybt.ui.selectedcontent.DownloadUrlInfo) TableViewSWTMenuFillListener(com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener) TableColumnManager(com.biglybt.ui.common.table.impl.TableColumnManager) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) GridLayout(org.eclipse.swt.layout.GridLayout) SWTSkinObjectContainer(com.biglybt.ui.swt.skin.SWTSkinObjectContainer) UIFunctions(com.biglybt.ui.UIFunctions) Menu(org.eclipse.swt.widgets.Menu) SelectedContent(com.biglybt.ui.selectedcontent.SelectedContent) ISelectedContent(com.biglybt.ui.selectedcontent.ISelectedContent) ISelectedContent(com.biglybt.ui.selectedcontent.ISelectedContent) Composite(org.eclipse.swt.widgets.Composite) MenuItem(org.eclipse.swt.widgets.MenuItem)

Aggregations

TableViewSWTMenuFillListener (com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener)4 TableColumnManager (com.biglybt.ui.common.table.impl.TableColumnManager)3 UIFunctions (com.biglybt.ui.UIFunctions)2 DownloadUrlInfo (com.biglybt.ui.selectedcontent.DownloadUrlInfo)2 ISelectedContent (com.biglybt.ui.selectedcontent.ISelectedContent)2 SelectedContent (com.biglybt.ui.selectedcontent.SelectedContent)2 SWTSkinObject (com.biglybt.ui.swt.skin.SWTSkinObject)2 List (java.util.List)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 RelatedAttributeLookupListener (com.biglybt.core.content.RelatedAttributeLookupListener)1 FileListener (com.biglybt.core.torrent.impl.TorrentOpenOptions.FileListener)1 UIInputReceiverListener (com.biglybt.pif.ui.UIInputReceiverListener)1 TableColumn (com.biglybt.pif.ui.tables.TableColumn)1 TableColumnCreationListener (com.biglybt.pif.ui.tables.TableColumnCreationListener)1 InitializerListener (com.biglybt.ui.InitializerListener)1 TableRowCore (com.biglybt.ui.common.table.TableRowCore)1 TableSelectionListener (com.biglybt.ui.common.table.TableSelectionListener)1 TrackerEditorListener (com.biglybt.ui.swt.maketorrent.TrackerEditorListener)1 SWTSkinObjectContainer (com.biglybt.ui.swt.skin.SWTSkinObjectContainer)1 KeyEvent (org.eclipse.swt.events.KeyEvent)1