Search in sources :

Example 1 with SideBarEntrySWT

use of com.biglybt.ui.swt.views.skin.sidebar.SideBarEntrySWT in project BiglyBT by BiglySoftware.

the class UIFunctionsImpl method showURL.

/**
 * @param url
 * @param target
 */
private void showURL(final String url, String target) {
    if ("_blank".equalsIgnoreCase(target)) {
        Utils.launch(url);
        return;
    }
    if (target.startsWith("tab-")) {
        target = target.substring(4);
    }
    MultipleDocumentInterface mdi = UIFunctionsManager.getUIFunctions().getMDI();
    // by the caller
    if (mdi == null || !mdi.showEntryByID(target)) {
        Utils.launch(url);
        return;
    }
    MdiEntry entry = mdi.getEntry(target);
    entry.addListener(new MdiEntryOpenListener() {

        @Override
        public void mdiEntryOpen(MdiEntry entry) {
            entry.removeListener(this);
            mainWindow.setVisible(true, true);
            if (!(entry instanceof SideBarEntrySWT)) {
                return;
            }
            SideBarEntrySWT entrySWT = (SideBarEntrySWT) entry;
            SWTSkinObjectBrowser soBrowser = SWTSkinUtils.findBrowserSO(entrySWT.getSkinObject());
            if (soBrowser != null) {
                // ((SWTSkinObjectBrowser) skinObject).getBrowser().setVisible(false);
                if (url == null || url.length() == 0) {
                    soBrowser.restart();
                } else {
                    soBrowser.setURL(url);
                }
            }
        }
    });
}
Also used : MdiEntryOpenListener(com.biglybt.ui.mdi.MdiEntryOpenListener) BaseMdiEntry(com.biglybt.ui.swt.mdi.BaseMdiEntry) MdiEntry(com.biglybt.ui.mdi.MdiEntry) SideBarEntrySWT(com.biglybt.ui.swt.views.skin.sidebar.SideBarEntrySWT) MultipleDocumentInterface(com.biglybt.ui.mdi.MultipleDocumentInterface)

Example 2 with SideBarEntrySWT

use of com.biglybt.ui.swt.views.skin.sidebar.SideBarEntrySWT in project BiglyBT by BiglySoftware.

the class SB_Transfers method setupCategory.

public MdiEntry setupCategory(final Category category) {
    MultipleDocumentInterface mdi = UIFunctionsManager.getUIFunctions().getMDI();
    if (mdi == null) {
        return (null);
    }
    String name = category.getName();
    String id = "Cat." + Base32.encode(name.getBytes());
    MdiEntry existing = mdi.getEntry(id);
    if (existing != null) {
        return (existing);
    }
    category.addCategoryListener(categoryListener);
    String loc_name = name;
    if (category.getType() != Category.TYPE_USER) {
        name = "{" + name + "}";
        loc_name = MessageText.getString(loc_name);
    }
    ViewTitleInfo viewTitleInfo = new ViewTitleInfo() {

        @Override
        public Object getTitleInfoProperty(int propertyID) {
            if (propertyID == TITLE_INDICATOR_TEXT) {
                if (category.getType() == Category.TYPE_ALL) {
                    int all = core.getGlobalManager().getDownloadManagers().size();
                    return (String.valueOf(all));
                } else if (category.getType() == Category.TYPE_UNCATEGORIZED) {
                    int all = core.getGlobalManager().getDownloadManagers().size();
                    int num_cat = CategoryManager.getCategorisedDownloadCount();
                    return (String.valueOf(all - num_cat));
                } else {
                    List<?> dms = category.getDownloadManagers(null);
                    if (dms != null) {
                        return "" + dms.size();
                    }
                }
            } else if (propertyID == TITLE_INDICATOR_COLOR) {
                TagType tag_type = category.getTagType();
                int[] def_color = tag_type.getColorDefault();
                int[] tag_color = category.getColor();
                if (tag_color != def_color) {
                    return (tag_color);
                }
            } else if (propertyID == TITLE_INDICATOR_TEXT_TOOLTIP) {
                return (TagUtils.getTagTooltip(category));
            }
            return null;
        }
    };
    String prev_id = getCatPosition(mdi, MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, loc_name);
    MdiEntry entry = mdi.createEntryFromSkinRef(MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS, id, "library", name, viewTitleInfo, category, false, prev_id);
    if (entry != null) {
        entry.setImageLeftID("image.sidebar.library");
        entry.setUserData(CAT_KEY, category);
        addGeneralLibraryMenus(mdi, id);
        entry.addListener(new MdiEntryDropListener() {

            @Override
            public boolean mdiEntryDrop(MdiEntry entry, Object payload) {
                if (!(payload instanceof String)) {
                    return false;
                }
                String dropped = (String) payload;
                String[] split = RegExUtil.PAT_SPLIT_SLASH_N.split(dropped);
                if (split.length > 1) {
                    String type = split[0];
                    if (type.startsWith("DownloadManager")) {
                        GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
                        for (int i = 1; i < split.length; i++) {
                            String hash = split[i];
                            try {
                                DownloadManager dm = gm.getDownloadManager(new HashWrapper(Base32.decode(hash)));
                                if (dm != null) {
                                    TorrentUtil.assignToCategory(new Object[] { dm }, category);
                                }
                            } catch (Throwable t) {
                            }
                        }
                    }
                }
                return true;
            }
        });
    }
    if (entry instanceof SideBarEntrySWT) {
        final SideBarEntrySWT entrySWT = (SideBarEntrySWT) entry;
        entrySWT.addListener(new MdiSWTMenuHackListener() {

            @Override
            public void menuWillBeShown(MdiEntry entry, Menu menuTree) {
                CategoryUIUtils.createMenuItems(menuTree, category);
            }
        });
    }
    return (entry);
}
Also used : SideBarEntrySWT(com.biglybt.ui.swt.views.skin.sidebar.SideBarEntrySWT) MdiSWTMenuHackListener(com.biglybt.ui.swt.mdi.MdiSWTMenuHackListener) DownloadManager(com.biglybt.core.download.DownloadManager) Point(org.eclipse.swt.graphics.Point) GlobalManager(com.biglybt.core.global.GlobalManager) Menu(org.eclipse.swt.widgets.Menu) ViewTitleInfo(com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo)

Example 3 with SideBarEntrySWT

use of com.biglybt.ui.swt.views.skin.sidebar.SideBarEntrySWT in project BiglyBT by BiglySoftware.

the class SB_Transfers method setupTag.

public MdiEntry setupTag(final Tag tag) {
    MultipleDocumentInterfaceSWT mdi = UIFunctionsManagerSWT.getUIFunctionsSWT().getMDISWT();
    if (mdi == null) {
        return null;
    }
    if (!show_tag_tab_views) {
        return (null);
    }
    /*
			 * Can get hit here concurrently due to various threads interacting with tags...
			 */
    int tag_type = tag.getTagType().getTagType();
    synchronized (tag_setup_lock) {
        String id = "Tag." + tag_type + "." + tag.getTagID();
        String parent_id = MultipleDocumentInterface.SIDEBAR_HEADER_TRANSFERS;
        String group_id = null;
        if (show_tag_groups) {
            String tag_group = tag.getGroup();
            if (tag_group != null && !tag_group.isEmpty()) {
                if (tag.getTaggableTypes() == Taggable.TT_DOWNLOAD || tag.getTaggableTypes() == Taggable.TT_PEER) {
                    group_id = "Tag." + tag_type + ".group." + tag_group;
                    if (mdi.getEntry(group_id) == null) {
                        // Create Entry for Group
                        TagGroup group = tag.getGroupContainer();
                        String gid = group_id;
                        ViewTitleInfo viewTitleInfo = new ViewTitleInfo() {

                            @Override
                            public Object getTitleInfoProperty(int pid) {
                                if (pid == TITLE_TEXT) {
                                    return (tag_group);
                                } else if (pid == TITLE_INDICATOR_TEXT) {
                                    MdiEntry entry = mdi.getEntry(gid);
                                    if (entry != null && !entry.isExpanded()) {
                                        return (String.valueOf(group.getTags().size()));
                                    }
                                } else if (pid == TITLE_INDICATOR_COLOR) {
                                    int[] colour = group.getColor();
                                    return (colour);
                                } else if (pid == TITLE_INDICATOR_TEXT_TOOLTIP) {
                                }
                                return null;
                            }
                        };
                        TagGroupListener tgl = new TagGroupListener() {

                            @Override
                            public void tagRemoved(TagGroup group, Tag tag) {
                                update();
                            }

                            @Override
                            public void tagAdded(TagGroup group, Tag tag) {
                                update();
                            }

                            @Override
                            public void groupChanged(TagGroup group) {
                                update();
                            }

                            private void update() {
                                MdiEntry entry = mdi.getEntry(gid);
                                if (entry != null) {
                                    if (entry.isEntryDisposed()) {
                                        group.removeListener(this);
                                    } else {
                                        ViewTitleInfoManager.refreshTitleInfo(viewTitleInfo);
                                        requestRedraw(entry);
                                    }
                                }
                            }
                        };
                        group.addListener(tgl, false);
                        // find where to locate this in the sidebar
                        String prev_id = getTagPosition(mdi, parent_id, tag_type, tag_group);
                        MdiEntry entry;
                        boolean closeable = true;
                        if (tag.getTaggableTypes() == Taggable.TT_DOWNLOAD) {
                            entry = mdi.createEntryFromSkinRef(parent_id, group_id, "library", tag_group, viewTitleInfo, group, closeable, prev_id);
                        } else {
                            UISWTViewBuilderCore builder = new UISWTViewBuilderCore(group_id, null, PeersGeneralView.class);
                            builder.setParentEntryID(parent_id);
                            builder.setPreferredAfterID(prev_id).setInitialDatasource(group);
                            entry = mdi.createEntry(builder, closeable);
                            entry.setViewTitleInfo(viewTitleInfo);
                        }
                        setTagIcon(tag, entry, true);
                        entry.setUserData(TAG_TAG_OR_GROUP_KEY, group);
                        entry.addListener((e, user) -> {
                            if (user) {
                                List<Tag> kids = group.getTags();
                                for (Tag kid : kids) {
                                    kid.setVisible(false);
                                }
                            }
                        });
                        // remove header when there are no children
                        entry.addListener(new MdiChildCloseListener() {

                            boolean closed;

                            public void mdiChildEntryClosed(MdiEntry parent, MdiEntry child, boolean user) {
                                String viewID = parent.getViewID();
                                if (mdi.getChildrenOf(viewID).isEmpty()) {
                                    synchronized (this) {
                                        if (closed) {
                                            return;
                                        }
                                        closed = true;
                                    }
                                    // need to defer this in case there are outstanding sidebar
                                    // additions that are located relative to this entry...
                                    mdi.runWhenIdle(() -> {
                                        mdi.closeEntry(parent, false);
                                    });
                                }
                            }
                        });
                        if (entry instanceof MdiEntrySWT) {
                            final MdiEntrySWT entrySWT = (MdiEntrySWT) entry;
                            entry.addListener((entry1, droppedObject) -> {
                                List<Tag> tags = DragDropUtils.getTagsFromDroppedData(droppedObject);
                                if (tags.isEmpty()) {
                                    return false;
                                }
                                String groupName = tag.getGroupContainer().getName();
                                for (Tag droppedTag : tags) {
                                    droppedTag.setGroup(groupName);
                                }
                                return false;
                            });
                            entrySWT.addListener(new MdiSWTMenuHackListener() {

                                @Override
                                public void menuWillBeShown(MdiEntry entry, Menu menuTree) {
                                    if (tag.getTaggableTypes() == Taggable.TT_DOWNLOAD) {
                                        TagGroup tg = tag.getGroupContainer();
                                        addMenuCollapseAll(mdi, menuTree, entry.getViewID());
                                        new org.eclipse.swt.widgets.MenuItem(menuTree, SWT.SEPARATOR);
                                        TagUIUtils.createSideBarMenuItems(menuTree, tg);
                                    }
                                }
                            });
                        }
                    }
                    parent_id = group_id;
                }
            }
        }
        if (mdi.getEntry(id) != null) {
            return null;
        }
        // find where to locate this in the sidebar
        String prev_id = getTagPosition(mdi, parent_id, tag_type, tag.getTagName(true));
        boolean auto = tag.getTagType().isTagTypeAuto();
        ViewTitleInfo viewTitleInfo = new ViewTitleInfo() {

            @Override
            public Object getTitleInfoProperty(int pid) {
                if (pid == TITLE_TEXT) {
                    return (tag.getTagName(true));
                } else if (pid == TITLE_INDICATOR_TEXT) {
                    return (String.valueOf(tag.getTaggedCount()));
                } else if (pid == TITLE_INDICATOR_COLOR) {
                    TagType tag_type = tag.getTagType();
                    int[] def_color = tag_type.getColorDefault();
                    int[] tag_color = tag.getColor();
                    if (tag_color != def_color) {
                        return (tag_color);
                    }
                } else if (pid == TITLE_INDICATOR_TEXT_TOOLTIP) {
                    return (TagUtils.getTagTooltip(tag));
                }
                return null;
            }
        };
        MdiEntry entry;
        boolean closable = auto;
        if (tag.getTaggableTypes() == Taggable.TT_DOWNLOAD) {
            closable = true;
            String name = tag.getTagName(true);
            entry = mdi.createEntryFromSkinRef(parent_id, id, "library", name, viewTitleInfo, tag, closable, prev_id);
            addGeneralLibraryMenus(mdi, id);
        } else {
            UISWTViewBuilderCore builder = new UISWTViewBuilderCore(id, null, PeersGeneralView.class);
            builder.setParentEntryID(parent_id);
            builder.setPreferredAfterID(prev_id).setInitialDatasource(tag);
            entry = mdi.createEntry(builder, closable);
            entry.setViewTitleInfo(viewTitleInfo);
        }
        entry.setUserData(TAG_TAG_OR_GROUP_KEY, tag);
        if (closable) {
            entry.addListener(new MdiCloseListener() {

                @Override
                public void mdiEntryClosed(MdiEntry entry, boolean userClosed) {
                    if (userClosed && entry.getUserData(AUTO_CLOSE_KEY) == null) {
                        if (COConfigurationManager.getBooleanParameter("Library.TagInSideBar")) {
                            tag.setVisible(false);
                        }
                    }
                }
            });
        }
        if (entry != null) {
            setTagIcon(tag, entry, false);
        }
        if (entry instanceof SideBarEntrySWT) {
            final SideBarEntrySWT entrySWT = (SideBarEntrySWT) entry;
            entrySWT.addListener(new MdiSWTMenuHackListener() {

                @Override
                public void menuWillBeShown(MdiEntry entry, Menu menuTree) {
                    TagUIUtils.createSideBarMenuItems(menuTree, tag);
                }
            });
        }
        if (!auto && entry != null) {
            MdiEntryDropListener dl = new MdiEntryDropListener() {

                @Override
                public boolean mdiEntryDrop(MdiEntry entry, Object payload) {
                    if (!(payload instanceof String)) {
                        return false;
                    }
                    boolean[] auto = tag.isTagAuto();
                    if (auto[0] && auto[1]) {
                        return (false);
                    }
                    final String dropped = (String) payload;
                    new AEThread2("Tagger") {

                        @Override
                        public void run() {
                            dropTorrentOnTag(tag, dropped);
                        }
                    }.start();
                    return true;
                }

                private void dropTorrentOnTag(Tag tag, String dropped) {
                    List<DownloadManager> dms = DragDropUtils.getDownloadsFromDropData(dropped, true);
                    if (dms.isEmpty()) {
                        return;
                    }
                    boolean doAdd = false;
                    int mods = Utils.getDragDetectModifiers();
                    if ((mods & SWT.ALT) != 0) {
                        // / alt+drop -> addl shift+alt+drop -> remove otherwise existing togglish logic
                        doAdd = (mods & SWT.SHIFT) == 0;
                    } else {
                        for (DownloadManager dm : dms) {
                            if (!tag.hasTaggable(dm)) {
                                doAdd = true;
                                break;
                            }
                        }
                    }
                    boolean[] auto = tag.isTagAuto();
                    if (auto.length < 2 || (doAdd && auto[0]) || (!doAdd && auto[0] && auto[1])) {
                        return;
                    }
                    try {
                        tag.addTaggableBatch(true);
                        for (DownloadManager dm : dms) {
                            if (doAdd) {
                                if (!tag.hasTaggable(dm)) {
                                    tag.addTaggable(dm);
                                }
                            } else {
                                if (tag.hasTaggable(dm)) {
                                    tag.removeTaggable(dm);
                                }
                            }
                        }
                    } finally {
                        tag.addTaggableBatch(false);
                    }
                }
            };
            boolean[] tag_auto = tag.isTagAuto();
            entry.setUserData(TAG_DATA_KEY, new Object[] { dl, tag_auto });
            if (!(tag_auto[0] && tag_auto[1])) {
                entry.addListener(dl);
            }
        }
        return entry;
    }
}
Also used : SideBarEntrySWT(com.biglybt.ui.swt.views.skin.sidebar.SideBarEntrySWT) MdiSWTMenuHackListener(com.biglybt.ui.swt.mdi.MdiSWTMenuHackListener) DownloadManager(com.biglybt.core.download.DownloadManager) UISWTViewBuilderCore(com.biglybt.ui.swt.pifimpl.UISWTViewBuilderCore) MultipleDocumentInterfaceSWT(com.biglybt.ui.swt.mdi.MultipleDocumentInterfaceSWT) Menu(org.eclipse.swt.widgets.Menu) MdiEntrySWT(com.biglybt.ui.swt.mdi.MdiEntrySWT) Point(org.eclipse.swt.graphics.Point) ViewTitleInfo(com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo)

Example 4 with SideBarEntrySWT

use of com.biglybt.ui.swt.views.skin.sidebar.SideBarEntrySWT in project BiglyBT by BiglySoftware.

the class BaseMdiEntry method exportStandAlone.

public Map<String, Object> exportStandAlone() {
    Map<String, Object> result = new HashMap<>();
    result.put("mdi", (this instanceof SideBarEntrySWT) ? "sidebar" : "tabbed");
    String title = null;
    ViewTitleInfo vti = getViewTitleInfo();
    if (vti != null) {
        title = (String) vti.getTitleInfoProperty(ViewTitleInfo.TITLE_TEXT);
    }
    if (title == null || title.length() == 0) {
        title = getFullTitle();
    }
    result.put("title", title);
    result.put("skin_ref", getSkinRef());
    result.put("skin_id", skin.getSkinID());
    result.put("parent_id", getParentID());
    result.put("id", id);
    Object data_source = getDatasourceCore();
    if (data_source == null) {
        data_source = getInitialDataSource();
    }
    if (data_source != null) {
        if (data_source instanceof String) {
            result.put("data_source", data_source);
        } else if (data_source instanceof Integer) {
            List l = new ArrayList();
            l.add("i");
            l.add(((Integer) data_source).longValue());
            result.put("data_source", l);
        } else {
            result.put("data_source", DataSourceResolver.exportDataSource(data_source));
        }
    }
    result.put("control_type", getControlType());
    UISWTViewBuilderCore builder = getEventListenerBuilder();
    if (builder != null) {
        Map map = new HashMap();
        Class<? extends UISWTViewEventListener> cla = builder.getListenerClass();
        if (cla != null) {
            map.put("name", cla.getName());
        }
        PluginInterface pi = builder.getPluginInterface();
        if (pi != null) {
            map.put("plugin_id", pi.getPluginID());
            map.put("plugin_name", pi.getPluginName());
        }
        if (map.size() > 0) {
            result.put("event_listener", map);
        }
    }
    UISWTViewEventListener listener = getEventListener();
    if (listener instanceof UISWTViewEventListenerEx) {
        com.biglybt.ui.swt.pif.UISWTViewEventListenerEx.CloneConstructor cc = ((UISWTViewEventListenerEx) listener).getCloneConstructor();
        PluginInterface pi = cc.getPluginInterface();
        Map<String, Object> map = new HashMap<>();
        map.put("plugin_id", pi.getPluginID());
        map.put("plugin_name", pi.getPluginName());
        map.put("ipc_method", cc.getIPCMethod());
        List<Object> params = cc.getIPCParameters();
        if (params != null) {
            List p_types = new ArrayList<>();
            List p_vals = new ArrayList<>();
            map.put("p_types", p_types);
            map.put("p_vals", p_vals);
            for (Object p : params) {
                if (p instanceof Boolean) {
                    p_types.add("bool");
                    p_vals.add(new Long(((Boolean) p) ? 1 : 0));
                } else if (p instanceof Long) {
                    p_types.add("long");
                    p_vals.add(p);
                } else if (p instanceof String) {
                    p_types.add("string");
                    p_vals.add(p);
                } else {
                    Debug.out("Unsupported param type: " + p);
                }
            }
        }
        result.put("event_listener", map);
    }
    return (result);
}
Also used : PluginInterface(com.biglybt.pif.PluginInterface) SideBarEntrySWT(com.biglybt.ui.swt.views.skin.sidebar.SideBarEntrySWT)

Aggregations

SideBarEntrySWT (com.biglybt.ui.swt.views.skin.sidebar.SideBarEntrySWT)4 DownloadManager (com.biglybt.core.download.DownloadManager)2 ViewTitleInfo (com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo)2 MdiSWTMenuHackListener (com.biglybt.ui.swt.mdi.MdiSWTMenuHackListener)2 Point (org.eclipse.swt.graphics.Point)2 Menu (org.eclipse.swt.widgets.Menu)2 GlobalManager (com.biglybt.core.global.GlobalManager)1 PluginInterface (com.biglybt.pif.PluginInterface)1 MdiEntry (com.biglybt.ui.mdi.MdiEntry)1 MdiEntryOpenListener (com.biglybt.ui.mdi.MdiEntryOpenListener)1 MultipleDocumentInterface (com.biglybt.ui.mdi.MultipleDocumentInterface)1 BaseMdiEntry (com.biglybt.ui.swt.mdi.BaseMdiEntry)1 MdiEntrySWT (com.biglybt.ui.swt.mdi.MdiEntrySWT)1 MultipleDocumentInterfaceSWT (com.biglybt.ui.swt.mdi.MultipleDocumentInterfaceSWT)1 UISWTViewBuilderCore (com.biglybt.ui.swt.pifimpl.UISWTViewBuilderCore)1