use of com.biglybt.pif.ui.tables.TableColumn in project BiglyBT by BiglySoftware.
the class TableColumnCreatorV3 method initCoreColumns.
/**
* @since 3.1.1.1
*/
public static void initCoreColumns() {
TableColumnCreator.initCoreColumns();
// short variable names to reduce wrapping
final Map<String, cInfo> c = new LightHashMap<>(7);
c.put(ColumnUnopened.COLUMN_ID, new cInfo(ColumnUnopened.class, ColumnUnopened.DATASOURCE_TYPES));
c.put(ColumnThumbAndName.COLUMN_ID, new cInfo(ColumnThumbAndName.class, ColumnThumbAndName.DATASOURCE_TYPES));
c.put(ColumnStream.COLUMN_ID, new cInfo(ColumnStream.class, ColumnStream.DATASOURCE_TYPES));
c.put(DateAddedItem.COLUMN_ID, new cInfo(DateAddedItem.class, DateAddedItem.DATASOURCE_TYPE));
c.put(DateCompletedItem.COLUMN_ID, new cInfo(DateCompletedItem.class, DateCompletedItem.DATASOURCE_TYPE));
c.put(ColumnProgressETA.COLUMN_ID, new cInfo(ColumnProgressETA.class, ColumnProgressETA.DATASOURCE_TYPE));
c.put(ColumnChatMessageCount.COLUMN_ID, new cInfo(ColumnChatMessageCount.class, Download.class));
// ///////
final Class ac = ActivitiesEntry.class;
c.put(ColumnActivityNew.COLUMN_ID, new cInfo(ColumnActivityNew.class, ac));
c.put(ColumnActivityType.COLUMN_ID, new cInfo(ColumnActivityType.class, ac));
c.put(ColumnActivityText.COLUMN_ID, new cInfo(ColumnActivityText.class, ac));
c.put(ColumnActivityActions.COLUMN_ID, new cInfo(ColumnActivityActions.class, ac));
c.put(ColumnActivityDate.COLUMN_ID, new cInfo(ColumnActivityDate.class, ac));
c.put(ColumnThumbnail.COLUMN_ID, new cInfo(ColumnThumbnail.class, new Class[] { ac }));
// Core columns are implementors of TableColumn to save one class creation
// Otherwise, we'd have to create a generic TableColumnImpl class, pass it
// to another class so that it could manipulate it and act upon changes.
TableColumnManager tcManager = TableColumnManager.getInstance();
TableColumnCoreCreationListener tcCreator = new TableColumnCoreCreationListener() {
// @see com.biglybt.ui.swt.views.table.TableColumnCoreCreationListener#createTableColumnCore(java.lang.Class, java.lang.String, java.lang.String)
@Override
public TableColumnCore createTableColumnCore(Class forDataSourceType, String tableID, String columnID) {
cInfo info = c.get(columnID);
if (info.cla.isAssignableFrom(TableColumnCore.class)) {
return null;
}
try {
Constructor<TableColumnCore> constructor = info.cla.getDeclaredConstructor(String.class);
TableColumnCore column = constructor.newInstance(tableID);
return column;
} catch (NoSuchMethodException ignored) {
} catch (Exception e) {
Debug.out(e);
}
return null;
}
@Override
public void tableColumnCreated(TableColumn column) {
cInfo info = c.get(column.getName());
if (column.getClass().equals(info.cla)) {
return;
}
try {
Constructor constructor = info.cla.getDeclaredConstructor(TableColumn.class);
if (constructor != null) {
constructor.newInstance(column);
}
} catch (NoSuchMethodException e) {
} catch (Exception e) {
Debug.out(e);
}
}
};
tcManager.unregisterColumn(NameItem.DATASOURCE_TYPE, NameItem.COLUMN_ID, null);
for (String id : c.keySet()) {
cInfo info = c.get(id);
for (int i = 0; i < info.forDataSourceTypes.length; i++) {
Class cla = info.forDataSourceTypes[i];
tcManager.registerColumn(cla, id, tcCreator);
}
}
}
use of com.biglybt.pif.ui.tables.TableColumn in project BiglyBT by BiglySoftware.
the class SBC_DevicesView method initColumns.
/**
* @since 4.1.0.5
*/
private void initColumns(Core core) {
if (columnsAdded) {
return;
}
columnsAdded = true;
UIManager uiManager = PluginInitializer.getDefaultInterface().getUIManager();
TableManager tableManager = uiManager.getTableManager();
tableManager.registerColumn(TranscodeFile.class, ColumnTJ_Rank.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnTJ_Rank(column);
if (!column.getTableID().equals(TABLE_TRANSCODE_QUEUE)) {
column.setVisible(false);
}
}
});
tableManager.registerColumn(TranscodeFile.class, ColumnThumbnail.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnThumbnail(column);
column.setWidth(70);
column.setVisible(false);
}
});
tableManager.registerColumn(TranscodeFile.class, ColumnTJ_Name.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnTJ_Name(column);
if (column.getTableID().equals(TABLE_TRANSCODE_QUEUE)) {
column.setWidth(200);
} else if (!column.getTableID().endsWith(":type=1")) {
column.setWidth(140);
}
}
});
tableManager.registerColumn(TranscodeFile.class, ColumnTJ_Duration.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnTJ_Duration(column);
}
});
tableManager.registerColumn(TranscodeFile.class, ColumnTJ_Device.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnTJ_Device(column);
column.setVisible(false);
}
});
tableManager.registerColumn(TranscodeFile.class, ColumnTJ_Profile.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnTJ_Profile(column);
if (column.getTableID().equals(TABLE_TRANSCODE_QUEUE)) {
column.setWidth(70);
}
}
});
tableManager.registerColumn(TranscodeFile.class, ColumnTJ_Resolution.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnTJ_Resolution(column);
column.setVisible(false);
if (column.getTableID().equals(TABLE_TRANSCODE_QUEUE)) {
column.setWidth(95);
}
}
});
tableManager.registerColumn(TranscodeFile.class, ColumnTJ_Status.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnTJ_Status(column);
}
});
tableManager.registerColumn(TranscodeFile.class, ColumnTJ_Completion.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnTJ_Completion(column);
column.setWidth(145);
}
});
tableManager.registerColumn(TranscodeFile.class, ColumnTJ_CopiedToDevice.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnTJ_CopiedToDevice(column);
if (column.getTableID().endsWith(":type=1") || column.getTableID().equals(TABLE_TRANSCODE_QUEUE)) {
column.setVisible(false);
}
}
});
tableManager.registerColumn(TranscodeFile.class, ColumnTJ_Category.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnTJ_Category(column);
}
});
tableManager.registerColumn(TranscodeFile.class, ColumnTJ_Tags.COLUMN_ID, new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn column) {
new ColumnTJ_Tags(column);
}
});
TableColumnManager tcm = TableColumnManager.getInstance();
String[] defaultLibraryColumns = { ColumnTJ_Rank.COLUMN_ID, ColumnTJ_Name.COLUMN_ID, ColumnTJ_Duration.COLUMN_ID, ColumnTJ_Device.COLUMN_ID, ColumnTJ_Status.COLUMN_ID, ColumnTJ_Completion.COLUMN_ID };
tcm.setDefaultColumnNames(TABLE_TRANSCODE_QUEUE, defaultLibraryColumns);
String[] defaultQColumns = { ColumnTJ_Name.COLUMN_ID, ColumnTJ_Duration.COLUMN_ID, ColumnTJ_Profile.COLUMN_ID, ColumnTJ_Status.COLUMN_ID, ColumnTJ_Completion.COLUMN_ID };
tcm.setDefaultColumnNames(TABLE_DEVICE_LIBRARY, defaultQColumns);
}
use of com.biglybt.pif.ui.tables.TableColumn 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);
}
use of com.biglybt.pif.ui.tables.TableColumn in project BiglyBT by BiglySoftware.
the class BuddyPluginView method betaMessagePending.
protected void betaMessagePending(ChatInstance chat, Control comp_maybe_null, ChatMessage pending_message) {
synchronized (columns) {
for (TableColumn column : columns) {
column.invalidateCells();
}
}
synchronized (pending_msg_map) {
String key = chat.getNetAndKey();
Object[] entry = pending_msg_map.get(key);
if (pending_message != null) {
if (chat.isOldOutstandingMessage(pending_message)) {
return;
}
chat.setMessageOutstanding(pending_message);
if (entry == null) {
entry = new Object[] { 1, new HashSet<Control>(), chat };
pending_msg_map.put(key, entry);
} else {
entry[0] = ((Integer) entry[0]) + 1;
}
HashSet<Control> controls = (HashSet<Control>) entry[1];
if (controls.contains(comp_maybe_null)) {
return;
}
controls.add(comp_maybe_null);
if (pending_msg_event == null) {
pending_msg_event = SimpleTimer.addPeriodicEvent("BPPM", 2500, new TimerEventPerformer() {
private int tick_count = 0;
private Set<ChatInstance> prev_instances = new HashSet<>();
@Override
public void perform(TimerEvent event) {
tick_count++;
synchronized (pending_msg_map) {
Set<ChatInstance> current_instances = new HashSet<>();
Map<ChatInstance, Object> instance_map = new HashMap<>();
Iterator<Map.Entry<String, Object[]>> it = pending_msg_map.entrySet().iterator();
boolean has_new = false;
boolean has_mine = false;
while (it.hasNext()) {
Map.Entry<String, Object[]> map_entry = it.next();
Object[] entry = map_entry.getValue();
ChatInstance chat = (ChatInstance) entry[2];
if (chat.isDestroyed()) {
it.remove();
} else {
if (chat.hasUnseenMessageWithNick()) {
has_mine = true;
}
HashSet<Control> comps = ((HashSet<Control>) entry[1]);
Iterator<Control> control_it = comps.iterator();
while (control_it.hasNext()) {
Control c = control_it.next();
if (c != null && c.isDisposed()) {
it.remove();
}
}
if (comps.size() == 0) {
it.remove();
} else {
if (!chat.getDisableNewMsgIndications()) {
current_instances.add(chat);
if (!prev_instances.contains(chat)) {
has_new = true;
}
instance_map.put(chat, entry[0]);
}
}
}
}
if (pending_msg_map.size() == 0) {
pending_msg_event.cancel();
pending_msg_event = null;
}
if (current_instances.size() == 0) {
updateIdleTT(true);
} else {
String tt_text = "";
for (ChatInstance chat : sortChats(current_instances)) {
String short_name = chat.getShortName();
tt_text += (tt_text.length() == 0 ? "" : "\n") + instance_map.get(chat) + " - " + short_name;
}
buildMenu(current_instances);
if (has_new) {
playSound();
}
beta_status.setTooltipText(tt_text);
Image image = has_mine ? bs_chat_red : bs_chat_green;
if (plugin.getBeta().getFlashEnabled() && tick_count % 2 == 0) {
image = bs_chat_gray_text;
}
setBetaStatus(image);
}
prev_instances = current_instances;
}
}
});
}
} else {
chat.setUserData(CHAT_LM_KEY, chat.getLastMessageRequiringAttention());
chat.setMessageOutstanding(null);
if (entry != null) {
pending_msg_map.remove(key);
if (pending_msg_event == null) {
Debug.out("eh?");
}
}
}
}
}
use of com.biglybt.pif.ui.tables.TableColumn 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;
}
Aggregations