use of com.biglybt.ui.swt.pifimpl.UISWTViewBuilderCore in project BiglyBT by BiglySoftware.
the class SBC_ChatOverview method createChatMdiEntry.
private static MdiEntry createChatMdiEntry(UIManager ui_manager, ChatInstance chat) {
MultipleDocumentInterfaceSWT mdi = UIFunctionsManagerSWT.getUIFunctionsSWT().getMDISWT();
if (mdi == null) {
return (null);
}
try {
String key = "Chat_" + chat.getNetwork() + ":" + Base32.encode(chat.getKey().getBytes("UTF-8"));
MdiEntry existing = mdi.getEntry(key);
if (existing != null) {
chat.destroy();
return (existing);
}
BuddyPluginBeta bp = BuddyPluginUtils.getBetaPlugin();
TreeMap<ChatInstance, String> name_map = new TreeMap<>(new Comparator<ChatInstance>() {
@Override
public int compare(ChatInstance o1, ChatInstance o2) {
return (o1.getName().compareTo(o2.getName()));
}
});
name_map.put(chat, key);
List<ChatInstance> all_chats = bp.getChats();
for (ChatInstance c : all_chats) {
try {
String k = "Chat_" + c.getNetwork() + ":" + Base32.encode(c.getKey().getBytes("UTF-8"));
if (mdi.getEntry(k) != null) {
name_map.put(c, k);
}
} catch (Throwable e) {
}
}
String prev_id = null;
for (String this_id : name_map.values()) {
if (this_id == key) {
break;
}
prev_id = this_id;
}
if (prev_id == null && name_map.size() > 1) {
Iterator<String> it = name_map.values().iterator();
it.next();
prev_id = "~" + it.next();
}
UISWTViewBuilderCore builder = new UISWTViewBuilderCore(key, null, ChatView.class);
builder.setParentEntryID(MultipleDocumentInterface.SIDEBAR_SECTION_CHAT);
builder.setInitialDatasource(chat);
builder.setPreferredAfterID(prev_id);
MdiEntry entry = mdi.createEntry(builder, true);
ChatMDIEntry entry_info = new ChatMDIEntry(ui_manager, chat, entry);
chat.setUserData(MDI_KEY, entry_info);
entry.addListener(new MdiCloseListener() {
@Override
public void mdiEntryClosed(MdiEntry entry, boolean userClosed) {
chat.setUserData(MDI_KEY, null);
}
});
return (entry);
} catch (Throwable e) {
Debug.out(e);
return (null);
}
}
use of com.biglybt.ui.swt.pifimpl.UISWTViewBuilderCore in project BiglyBT by BiglySoftware.
the class DeviceManagerUI method addDeviceCategory.
protected categoryView addDeviceCategory(int device_type, String category_title, String category_image_id) {
String key = "Device_" + category_title + ":" + nextSidebarID();
categoryView eventListener;
if (device_type == Device.DT_INTERNET) {
eventListener = new DeviceInternetView(this, category_title);
} else {
eventListener = new categoryViewGeneric(this, device_type, category_title);
}
// Pass already created eventListener to builder, because this class needs
// a reference to fiddle with. Might cause problems with cloning.
UISWTViewBuilderCore builder = new UISWTViewBuilderCore(key, null).setInitialDatasource(device_type).setListenerInstantiator(false, (Builder, view) -> eventListener).setParentEntryID(SideBar.SIDEBAR_HEADER_DEVICES);
MdiEntry entry = mdi.createEntry(builder, false);
addDefaultDropListener(entry);
entry.setImageLeftID(category_image_id);
eventListener.setDetails(entry, key);
return (eventListener);
}
use of com.biglybt.ui.swt.pifimpl.UISWTViewBuilderCore 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;
}
}
use of com.biglybt.ui.swt.pifimpl.UISWTViewBuilderCore in project BiglyBT by BiglySoftware.
the class SBC_TagsOverview method registerPluginViews.
private static void registerPluginViews() {
ViewManagerSWT vm = ViewManagerSWT.getInstance();
if (vm.areCoreViewsRegistered(PLUGIN_DS_TYPE)) {
return;
}
vm.registerView(PLUGIN_DS_TYPE, new UISWTViewBuilderCore(TagSettingsView.VIEW_ID, null, TagSettingsView.class));
vm.registerView(PLUGIN_DS_TYPE, new UISWTViewBuilderCore(MyTorrentsSubView.MSGID_PREFIX, null, MyTorrentsSubView.class));
vm.registerView(PLUGIN_DS_TYPE, new UISWTViewBuilderCore(FilesView.MSGID_PREFIX, null, FilesView.class));
vm.setCoreViewsRegistered(PLUGIN_DS_TYPE);
}
use of com.biglybt.ui.swt.pifimpl.UISWTViewBuilderCore in project BiglyBT by BiglySoftware.
the class ColumnFileCount method openFilesMiniView.
private void openFilesMiniView(DownloadManager dm, TableCell cell) {
UISWTViewBuilderCore builder = ViewManagerSWT.getInstance().getBuilder(Download.class, FilesView.MSGID_PREFIX);
if (builder == null) {
return;
}
SkinnedDialog skinnedDialog = BaseMdiEntry.buildSkinnedDialog("FilesView", dm, builder);
if (skinnedDialog == null) {
return;
}
skinnedDialog.setTitle(dm.getDisplayName());
Shell shell = skinnedDialog.getShell();
Rectangle bounds = ((TableCellSWT) cell).getBoundsOnDisplay();
bounds.y += bounds.height;
bounds.width = 630;
bounds.height = (16 * dm.getNumFileInfos()) + 60;
Rectangle realBounds = shell.computeTrim(0, 0, bounds.width, bounds.height);
realBounds.width -= realBounds.x;
realBounds.height -= realBounds.y;
realBounds.x = bounds.x;
realBounds.y = bounds.y;
if (bounds.height > 500) {
bounds.height = 500;
}
shell.setBounds(realBounds);
shell.setAlpha(230);
Utils.verifyShellRect(shell, true);
skinnedDialog.openUnadjusted();
}
Aggregations