Search in sources :

Example 1 with TableCellMouseEvent

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

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

the class ColumnTorrentFileProgress method fileInfoMouseTrigger.

public void fileInfoMouseTrigger(TableCellMouseEvent event) {
    if (event.eventType != TableRowMouseEvent.EVENT_MOUSEDOWN) {
        return;
    }
    final Object dataSource = ((TableRowCore) event.row).getDataSource(true);
    if (dataSource instanceof DiskManagerFileInfo) {
        final DiskManagerFileInfo fileInfo = (DiskManagerFileInfo) dataSource;
        Rectangle hilowBounds = (Rectangle) event.row.getData("hilowBounds");
        if (event.button == 1 && hilowBounds != null && hilowBounds.contains(event.x, event.y)) {
            if (fileInfo.getPriority() > 0) {
                fileInfo.setPriority(0);
            } else {
                fileInfo.setPriority(1);
            }
            ((TableRowCore) event.row).redraw();
        }
        Rectangle buttonBounds = (Rectangle) event.row.getData("buttonBounds");
        if (buttonBounds != null && buttonBounds.contains(event.x, event.y)) {
            Menu menu = new Menu(Display.getDefault().getActiveShell(), SWT.POP_UP);
            MenuItem itemHigh = new MenuItem(menu, SWT.RADIO);
            Messages.setLanguageText(itemHigh, "priority.high");
            itemHigh.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    FilesViewMenuUtil.changePriority(FilesViewMenuUtil.PRIORITY_HIGH, Arrays.asList(new DiskManagerFileInfo[] { fileInfo }));
                }
            });
            itemHigh.setSelection(fileInfo.getPriority() != 0);
            MenuItem itemNormal = new MenuItem(menu, SWT.RADIO);
            Messages.setLanguageText(itemNormal, "priority.normal");
            itemNormal.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    FilesViewMenuUtil.changePriority(FilesViewMenuUtil.PRIORITY_NORMAL, Arrays.asList(new DiskManagerFileInfo[] { fileInfo }));
                }
            });
            itemNormal.setSelection(fileInfo.getPriority() == 0);
            new MenuItem(menu, SWT.SEPARATOR);
            boolean canStart = fileInfo.isSkipped() || fileInfo.getDownloadManager().getState() == DownloadManager.STATE_STOPPED;
            MenuItem itemStop = new MenuItem(menu, SWT.PUSH);
            Messages.setLanguageText(itemStop, "v3.MainWindow.button.stop");
            itemStop.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    FilesViewMenuUtil.changePriority(FilesViewMenuUtil.PRIORITY_SKIPPED, Arrays.asList(new DiskManagerFileInfo[] { fileInfo }));
                }
            });
            itemStop.setEnabled(!canStart);
            MenuItem itemStart = new MenuItem(menu, SWT.PUSH);
            Messages.setLanguageText(itemStart, "v3.MainWindow.button.start");
            itemStart.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    if (fileInfo.getDownloadManager().getState() == DownloadManager.STATE_STOPPED) {
                        TorrentUtil.queueDataSources(new Object[] { dataSource }, true);
                    }
                    FilesViewMenuUtil.changePriority(FilesViewMenuUtil.PRIORITY_NORMAL, Arrays.asList(new DiskManagerFileInfo[] { fileInfo }));
                }
            });
            itemStart.setEnabled(canStart);
            new MenuItem(menu, SWT.SEPARATOR);
            MenuItem itemDelete = new MenuItem(menu, SWT.PUSH);
            Messages.setLanguageText(itemDelete, "v3.MainWindow.button.delete");
            itemDelete.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    FilesViewMenuUtil.changePriority(FilesViewMenuUtil.PRIORITY_DELETE, Arrays.asList(new DiskManagerFileInfo[] { fileInfo }));
                }
            });
            menu.setVisible(true);
            event.skipCoreFunctionality = true;
        }
    /*
			if (buttonBounds != null && buttonBounds.contains(event.x, event.y)) {
				int st = fileInfo.getStorageType();
				if ((st == DiskManagerFileInfo.ST_COMPACT || st == DiskManagerFileInfo.ST_REORDER_COMPACT)
						&& fileInfo.isSkipped()) {
					// deleted: Move to normal
					fileInfo.setPriority(0);
					fileInfo.setSkipped(false);
				} else if (fileInfo.isSkipped()) {
					// skipped: move to normal
					fileInfo.setPriority(0);
					fileInfo.setSkipped(false);
				} else if (fileInfo.getPriority() > 0) {

					// high: move to skipped
					fileInfo.setSkipped(true);
				} else {
					// normal: move to high
					fileInfo.setPriority(1);
				}
				//((TableRowCore) event.row).invalidate();
				((TableRowCore) event.row).redraw();
			}
			*/
    }
}
Also used : TableRowCore(com.biglybt.ui.common.table.TableRowCore) DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) TableCellMouseEvent(com.biglybt.pif.ui.tables.TableCellMouseEvent) TableRowMouseEvent(com.biglybt.pif.ui.tables.TableRowMouseEvent)

Aggregations

TableCellMouseEvent (com.biglybt.pif.ui.tables.TableCellMouseEvent)2 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)1 DownloadManager (com.biglybt.core.download.DownloadManager)1 Tag (com.biglybt.core.tag.Tag)1 TagType (com.biglybt.core.tag.TagType)1 Taggable (com.biglybt.core.tag.Taggable)1 TaggableLifecycleAdapter (com.biglybt.core.tag.TaggableLifecycleAdapter)1 Download (com.biglybt.pif.download.Download)1 TableCell (com.biglybt.pif.ui.tables.TableCell)1 TableCellMouseListener (com.biglybt.pif.ui.tables.TableCellMouseListener)1 TableCellRefreshListener (com.biglybt.pif.ui.tables.TableCellRefreshListener)1 TableColumn (com.biglybt.pif.ui.tables.TableColumn)1 TableColumnCreationListener (com.biglybt.pif.ui.tables.TableColumnCreationListener)1 TableManager (com.biglybt.pif.ui.tables.TableManager)1 TableRowMouseEvent (com.biglybt.pif.ui.tables.TableRowMouseEvent)1 ChatInstance (com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance)1 TableRowCore (com.biglybt.ui.common.table.TableRowCore)1 UISWTView (com.biglybt.ui.swt.pif.UISWTView)1 UISWTViewEvent (com.biglybt.ui.swt.pif.UISWTViewEvent)1 UISWTViewEventListener (com.biglybt.ui.swt.pif.UISWTViewEventListener)1