use of com.biglybt.ui.swt.mdi.MultipleDocumentInterfaceSWT in project BiglyBT by BiglySoftware.
the class TorrentUtil method calculateToolbarStates.
// XXX Don't think *View's need this call anymore. ToolBarView does it fo them
public static Map<String, Long> calculateToolbarStates(ISelectedContent[] currentContent, String viewID_unused) {
// System.out.println("calculateToolbarStates(" + currentContent.length + ", " + viewID_unused + " via " + Debug.getCompressedStackTrace());
/*
String[] TBKEYS = new String[] {
"download",
"play",
"stream",
"run",
"top",
"up",
"down",
"bottom",
"start",
"stop",
"remove"
};
*/
Map<String, Long> mapNewToolbarStates = new HashMap<>();
String[] itemsNeedingSelection = {};
String[] itemsNeedingRealDMSelection = { "remove", "top", "bottom", "transcode", "startstop" };
String[] itemsRequiring1DMwithHash = { "details", "comment", "up", "down" };
String[] itemsRequiring1DMSelection = {};
int numSelection = currentContent.length;
boolean hasSelection = numSelection > 0;
boolean has1Selection = numSelection == 1;
for (int i = 0; i < itemsNeedingSelection.length; i++) {
String itemID = itemsNeedingSelection[i];
mapNewToolbarStates.put(itemID, hasSelection ? UIToolBarItem.STATE_ENABLED : 0);
}
TableView tv = SelectedContentManager.getCurrentlySelectedTableView();
// not sure why we assume that the existance of any table view
boolean hasRealDM = tv != null;
if (!hasRealDM && numSelection > 0) {
hasRealDM = true;
for (int i = 0; i < currentContent.length; i++) {
ISelectedContent content = currentContent[i];
DownloadManager dm = content.getDownloadManager();
if (dm == null) {
hasRealDM = false;
break;
}
}
}
if (!hasRealDM) {
MultipleDocumentInterfaceSWT mdi = UIFunctionsManagerSWT.getUIFunctionsSWT().getMDISWT();
if (mdi != null) {
MdiEntrySWT entry = mdi.getCurrentEntrySWT();
if (entry != null) {
if (entry.getDatasource() instanceof DownloadManager) {
hasRealDM = true;
} else if ((entry instanceof UIPluginView) && (((UIPluginView) entry).getDataSource() instanceof DownloadManager)) {
hasRealDM = true;
}
}
}
}
boolean canStart = false;
boolean canStop = false;
boolean canRemoveFileInfo = false;
boolean canRunFileInfo = false;
boolean canCheckExist = false;
boolean hasDM = false;
boolean canRecheck = false;
if (currentContent.length > 0 && hasRealDM) {
// well, in fact, we can have hasRealDM set to true here (because tv isn't null) and actually not have a real dm.
// fancy that - protect against null DownloadManagers...
boolean canMoveUp = false;
boolean canMoveDown = false;
boolean canDownload = false;
canCheckExist = true;
GlobalManager gm = null;
for (int i = 0; i < currentContent.length; i++) {
ISelectedContent content = currentContent[i];
DownloadManager dm = content.getDownloadManager();
if (dm == null) {
if (!canDownload && content.getDownloadInfo() != null) {
canDownload = true;
}
continue;
}
if (gm == null) {
gm = dm.getGlobalManager();
}
int state = dm.getState();
canCheckExist &= (state == DownloadManager.STATE_ERROR || state == DownloadManager.STATE_STOPPED || state == DownloadManager.STATE_QUEUED);
int fileIndex = content.getFileIndex();
if (fileIndex == -1) {
if (!canMoveUp && gm.isMoveableUp(dm)) {
canMoveUp = true;
}
if (!canMoveDown && gm.isMoveableDown(dm)) {
canMoveDown = true;
}
hasDM = true;
if (!canStart && ManagerUtils.isStartable(dm)) {
canStart = true;
}
if (!canStop && ManagerUtils.isStopable(dm)) {
canStop = true;
}
} else {
DiskManagerFileInfoSet fileInfos = dm.getDiskManagerFileInfoSet();
if (fileIndex < fileInfos.nbFiles()) {
DiskManagerFileInfo fileInfo = fileInfos.getFiles()[fileIndex];
if (!canStart && (fileInfo.isSkipped())) {
canStart = true;
}
if (!canStop && !fileInfo.isSkipped()) {
canStop = true;
}
if (!canRemoveFileInfo && !fileInfo.isSkipped()) {
int storageType = fileInfo.getStorageType();
if (storageType == DiskManagerFileInfo.ST_LINEAR || storageType == DiskManagerFileInfo.ST_COMPACT) {
canRemoveFileInfo = true;
}
}
if (!canRunFileInfo && fileInfo.getAccessMode() == DiskManagerFileInfo.READ && fileInfo.getDownloaded() == fileInfo.getLength() && fileInfo.getFile(true).exists()) {
canRunFileInfo = true;
}
}
}
canRecheck = canRecheck || dm.canForceRecheck();
}
boolean canRemove = hasDM || canRemoveFileInfo;
mapNewToolbarStates.put("remove", canRemove ? UIToolBarItem.STATE_ENABLED : 0);
mapNewToolbarStates.put("download", canDownload ? UIToolBarItem.STATE_ENABLED : 0);
if (currentContent.length == 1) {
mapNewToolbarStates.put("up", canMoveUp ? UIToolBarItem.STATE_ENABLED : 0);
mapNewToolbarStates.put("down", canMoveDown ? UIToolBarItem.STATE_ENABLED : 0);
}
}
boolean canRun = has1Selection && ((hasDM && !canRunFileInfo) || (!hasDM && canRunFileInfo));
if (canRun) {
ISelectedContent content = currentContent[0];
DownloadManager dm = content.getDownloadManager();
if (dm == null) {
canRun = false;
} else {
TOTorrent torrent = dm.getTorrent();
if (torrent == null) {
canRun = false;
} else if (!dm.getAssumedComplete() && torrent.isSimpleTorrent()) {
canRun = false;
/*
} else if (PlatformTorrentUtils.useEMP(torrent)
&& PlatformTorrentUtils.embeddedPlayerAvail()
&& PlayUtils.canProgressiveOrIsComplete(torrent)) {
// play button enabled and not UMP.. don't need launch
canRun = false;
}
*/
}
}
}
mapNewToolbarStates.put("run", canRun ? UIToolBarItem.STATE_ENABLED : 0);
mapNewToolbarStates.put("start", canStart ? UIToolBarItem.STATE_ENABLED : 0);
mapNewToolbarStates.put("stop", canStop ? UIToolBarItem.STATE_ENABLED : 0);
mapNewToolbarStates.put("startstop", canStart || canStop ? UIToolBarItem.STATE_ENABLED : 0);
for (int i = 0; i < itemsNeedingRealDMSelection.length; i++) {
String itemID = itemsNeedingRealDMSelection[i];
if (!mapNewToolbarStates.containsKey(itemID)) {
mapNewToolbarStates.put(itemID, hasSelection && hasDM && hasRealDM ? UIToolBarItem.STATE_ENABLED : 0);
}
}
for (int i = 0; i < itemsRequiring1DMSelection.length; i++) {
String itemID = itemsRequiring1DMSelection[i];
if (!mapNewToolbarStates.containsKey(itemID)) {
mapNewToolbarStates.put(itemID, has1Selection && hasDM ? UIToolBarItem.STATE_ENABLED : 0);
}
}
for (int i = 0; i < itemsRequiring1DMwithHash.length; i++) {
String itemID = itemsRequiring1DMwithHash[i];
if (!mapNewToolbarStates.containsKey(itemID)) {
mapNewToolbarStates.put(itemID, hasDM ? UIToolBarItem.STATE_ENABLED : 0);
}
}
mapNewToolbarStates.put("download", has1Selection && (!(currentContent[0] instanceof ISelectedVuzeFileContent)) && currentContent[0].getDownloadManager() == null && (currentContent[0].getHash() != null || currentContent[0].getDownloadInfo() != null) ? UIToolBarItem.STATE_ENABLED : 0);
if (tv != null) {
TableColumn tc = tv.getTableColumn(RankItem.COLUMN_ID);
if (tc != null && !tc.isVisible()) {
mapNewToolbarStates.put("up", 0L);
mapNewToolbarStates.put("down", 0L);
}
}
mapNewToolbarStates.put(TU_ITEM_RECHECK, canRecheck ? UIToolBarItem.STATE_ENABLED : 0);
mapNewToolbarStates.put(TU_ITEM_CHECK_FILES, canCheckExist ? UIToolBarItem.STATE_ENABLED : 0);
return mapNewToolbarStates;
}
use of com.biglybt.ui.swt.mdi.MultipleDocumentInterfaceSWT in project BiglyBT by BiglySoftware.
the class SubscriptionManagerUI method setupSideBar.
protected void setupSideBar(final UISWTInstance swt_ui) {
MultipleDocumentInterfaceSWT mdi = UIFunctionsManagerSWT.getUIFunctionsSWT().getMDISWT();
if (mdi == null) {
return;
}
mdiEntryOverview = mdi.createEntryFromEventListener(MultipleDocumentInterface.SIDEBAR_HEADER_DISCOVERY, new UISWTViewEventListenerHolder(MultipleDocumentInterface.SIDEBAR_SECTION_SUBSCRIPTIONS, SubscriptionsView.class, null, null), MultipleDocumentInterface.SIDEBAR_SECTION_SUBSCRIPTIONS, false, null, null);
if (mdiEntryOverview == null) {
return;
}
mdiEntryOverview.setDefaultExpanded(true);
synchronized (this) {
if (sidebar_setup_done) {
return;
}
sidebar_setup_done = true;
}
mdiEntryOverview.setImageLeftID("image.sidebar.subscriptions");
setupHeader(mdi, mdiEntryOverview);
String parentID = "sidebar." + MultipleDocumentInterface.SIDEBAR_SECTION_SUBSCRIPTIONS;
MenuManager menu_manager = ui_manager.getMenuManager();
MenuItem mi = menu_manager.addMenuItem(parentID, "menu.update.all.now");
mi.setDisposeWithUIDetach(UIInstance.UIT_SWT);
mi.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
SubscriptionManager subs_man = SubscriptionManagerFactory.getSingleton();
SubscriptionScheduler sched = subs_man.getScheduler();
Subscription[] subs = subs_man.getSubscriptions(true);
for (Subscription sub : subs) {
if (!sub.isSearchTemplate()) {
if (sub.getHistory().isEnabled()) {
try {
sched.downloadAsync(sub, true);
} catch (Throwable e) {
Debug.out(e);
}
}
}
}
}
});
mi = menu_manager.addMenuItem(parentID, "sep1");
mi.setDisposeWithUIDetach(UIInstance.UIT_SWT);
mi.setStyle(MenuItem.STYLE_SEPARATOR);
mi = menu_manager.addMenuItem(parentID, "MainWindow.menu.view.configuration");
mi.setDisposeWithUIDetach(UIInstance.UIT_SWT);
mi.addListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object target) {
UIFunctions uif = UIFunctionsManager.getUIFunctions();
if (uif != null) {
uif.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, CONFIG_SECTION_ID);
}
}
});
}
use of com.biglybt.ui.swt.mdi.MultipleDocumentInterfaceSWT in project BiglyBT by BiglySoftware.
the class SubscriptionManagerUI method createSubscriptionMdiEntry.
private MdiEntry createSubscriptionMdiEntry(final Subscription subs) {
if (!subs.isSubscribed()) {
return null;
}
MultipleDocumentInterfaceSWT mdi = UIFunctionsManagerSWT.getUIFunctionsSWT().getMDISWT();
if (mdi == null) {
return (null);
}
String parent_name = subs.getParent();
if (parent_name != null && parent_name.length() == 0) {
parent_name = null;
}
final String key = getKey(subs);
String subs_name = subs.getName();
TreeMap<String, String> name_map = new TreeMap<String, String>(new FormattersImpl().getAlphanumericComparator(true));
name_map.put(subs_name, key);
MdiEntry[] existing = mdi.getEntries();
for (MdiEntry e : existing) {
String id = e.getId();
if (id.startsWith("Subscription_")) {
Object ds = e.getDatasource();
if (ds instanceof Subscription) {
String sp = ((Subscription) ds).getParent();
if (sp != null && sp.length() == 0) {
sp = null;
}
if (sp == parent_name || (sp != null && parent_name != null && sp.equals(parent_name))) {
name_map.put(e.getTitle(), id);
}
}
}
}
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();
}
MdiEntry entry;
if (parent_name == null || parent_name.length() == 0) {
entry = mdi.createEntryFromEventListener(MultipleDocumentInterface.SIDEBAR_SECTION_SUBSCRIPTIONS, new UISWTViewEventListenerHolder(key, SubscriptionView.class, subs, null), key, true, subs, prev_id);
} else {
MdiEntry parent_entry;
synchronized (parent_views) {
parent_entry = parent_views.get(parent_name);
if (parent_entry == null) {
SubsParentView parent = new SubsParentView(parent_name);
String parent_key = getParentKey(parent_name);
String parent_prev_id = null;
parent_views.put(parent_name, parent_entry);
String parent_prev = null;
for (String pn : parent_views.keySet()) {
if (pn == parent_name) {
break;
}
parent_prev = pn;
}
boolean is_before;
if (parent_prev == null && parent_views.size() > 1) {
Iterator<String> it = parent_views.keySet().iterator();
it.next();
parent_prev = it.next();
is_before = true;
} else {
is_before = false;
}
if (parent_prev != null) {
parent_prev_id = getParentKey(parent_prev);
if (is_before) {
parent_prev_id = "~" + parent_prev_id;
}
}
parent_entry = mdi.createEntryFromSkinRef(MultipleDocumentInterface.SIDEBAR_SECTION_SUBSCRIPTIONS, parent_key, null, parent_name, parent, null, false, parent_prev_id);
}
}
entry = mdi.createEntryFromEventListener(parent_entry.getId(), new UISWTViewEventListenerHolder(key, SubscriptionView.class, subs, null), key, true, subs, prev_id);
}
// This sets up the entry (menu, etc)
SubscriptionMDIEntry entryInfo = new SubscriptionMDIEntry(subs, entry);
subs.setUserData(SUB_ENTRYINFO_KEY, entryInfo);
entry.addListener(new MdiCloseListener() {
@Override
public void mdiEntryClosed(MdiEntry entry, boolean userClosed) {
subs.setUserData(SUB_ENTRYINFO_KEY, null);
}
});
return entry;
}
use of com.biglybt.ui.swt.mdi.MultipleDocumentInterfaceSWT in project BiglyBT by BiglySoftware.
the class SBC_DevicesView method skinObjectInitialShow.
// @see SkinView#skinObjectInitialShow(SWTSkinObject, java.lang.Object)
@Override
public Object skinObjectInitialShow(SWTSkinObject skinObject, Object params) {
CoreFactory.addCoreRunningListener(new CoreRunningListener() {
@Override
public void coreRunning(Core core) {
initColumns(core);
}
});
device_manager = DeviceManagerFactory.getSingleton();
transcode_manager = device_manager.getTranscodeManager();
transcode_queue = transcode_manager.getQueue();
MultipleDocumentInterfaceSWT mdi = UIFunctionsManagerSWT.getUIFunctionsSWT().getMDISWT();
if (mdi != null) {
mdiEntry = mdi.getCurrentEntrySWT();
Object ds = mdiEntry.getDatasource();
if (!(ds instanceof Device)) {
return (null);
}
device = (Device) ds;
}
if (device instanceof TranscodeTarget) {
transTarget = (TranscodeTarget) device;
}
if (device == null) {
new InfoBarUtil(skinObject, "devicesview.infobar", false, "DeviceView.infobar", "v3.deviceview.infobar") {
@Override
public boolean allowShow() {
return true;
}
};
} else if (device instanceof DeviceMediaRenderer) {
DeviceMediaRenderer renderer = (DeviceMediaRenderer) device;
int species = renderer.getRendererSpecies();
String speciesID = null;
switch(species) {
case DeviceMediaRenderer.RS_ITUNES:
speciesID = "itunes";
break;
case DeviceMediaRenderer.RS_PS3:
speciesID = "ps3";
break;
case DeviceMediaRenderer.RS_XBOX:
speciesID = "xbox";
break;
case DeviceMediaRenderer.RS_OTHER:
{
String classification = renderer.getClassification();
if (classification.equals("sony.PSP")) {
speciesID = "psp";
} else if (classification.startsWith("tivo.")) {
speciesID = "tivo";
} else if (classification.toLowerCase().contains("android")) {
speciesID = "android";
}
}
default:
break;
}
if (speciesID != null) {
final String fSpeciesID = speciesID;
new InfoBarUtil(skinObject, "devicesview.infobar", false, "DeviceView.infobar." + speciesID, "v3.deviceview.infobar") {
@Override
public boolean allowShow() {
return true;
}
// @see InfoBarUtil#created(SWTSkinObject)
@Override
protected void created(SWTSkinObject parent) {
SWTSkinObjectText soLine1 = (SWTSkinObjectText) skin.getSkinObject("line1", parent);
soLine1.setTextID("v3.deviceview.infobar.line1.generic", new String[] { device.getName() });
SWTSkinObjectText soLine2 = (SWTSkinObjectText) skin.getSkinObject("line2", parent);
soLine2.setTextID("v3.deviceview.infobar.line2." + fSpeciesID);
}
};
}
}
SWTSkinObject soAdvInfo = getSkinObject("advinfo");
if (soAdvInfo != null) {
initAdvInfo(soAdvInfo);
}
if (device != null) {
device_name = device.getName();
SWTSkinObject soTitle = getSkinObject("title");
if (soTitle instanceof SWTSkinObjectText) {
((SWTSkinObjectText) soTitle).setTextID("device.view.heading", new String[] { device_name });
}
}
return null;
}
use of com.biglybt.ui.swt.mdi.MultipleDocumentInterfaceSWT in project BiglyBT by BiglySoftware.
the class SBC_ChatOverview method createChatMdiEntry.
private static MdiEntry createChatMdiEntry(final 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();
}
MdiEntry entry = mdi.createEntryFromEventListener(MultipleDocumentInterface.SIDEBAR_SECTION_CHAT, new UISWTViewEventListenerHolder(key, ChatView.class, chat, null), key, true, chat, prev_id);
ChatMDIEntry entry_info = new ChatMDIEntry(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);
}
}
Aggregations