Program: 170799
Project: 170799
Buggy source:
public static void fillTorrentMenu(final Menu menu,final DownloadManager[] dms,final Core core,boolean include_show_details,int selected_dl_types,final TableView tv){
  Shell shell=Utils.findAnyShell();
  final boolean isSeedingView;
switch (selected_dl_types) {
case 1:
    isSeedingView=false;
  break;
case 2:
isSeedingView=true;
break;
case 0:
{
if (dms.length == 1) {
isSeedingView=dms[0].isDownloadComplete(false);
break;
}
}
default :
isSeedingView=false;
}
boolean hasSelection=dms.length > 0;
boolean isSingleSelection=dms.length == 1;
boolean isTrackerOn=TRTrackerUtils.isTrackerEnabled();
int userMode=COConfigurationManager.getIntParameter("String_Node_Str");
boolean bChangeDir=hasSelection;
boolean start, stop, changeUrl, barsOpened, forceStart;
boolean forceStartEnabled, recheck, manualUpdate, fileMove, fileRescan;
changeUrl=barsOpened=manualUpdate=fileMove=fileRescan=true;
forceStart=forceStartEnabled=recheck=start=stop=false;
boolean canSetSuperSeed=false;
boolean superSeedAllYes=true;
boolean superSeedAllNo=true;
boolean upSpeedDisabled=false;
long totalUpSpeed=0;
boolean upSpeedUnlimited=false;
long upSpeedSetMax=0;
boolean downSpeedDisabled=false;
long totalDownSpeed=0;
boolean downSpeedUnlimited=false;
long downSpeedSetMax=0;
boolean allScanSelected=true;
boolean allScanNotSelected=true;
boolean allStopped=true;
boolean allResumeIncomplete=true;
boolean hasClearableLinks=false;
boolean hasRevertableFiles=false;
if (hasSelection) {
for (int i=0; i < dms.length; i++) {
DownloadManager dm=(DownloadManager)dms[i];
try {
int maxul=dm.getStats().getUploadRateLimitBytesPerSecond();
if (maxul == 0) {
upSpeedUnlimited=true;
}
 else {
if (maxul > upSpeedSetMax) {
upSpeedSetMax=maxul;
}
}
if (maxul == -1) {
maxul=0;
upSpeedDisabled=true;
}
totalUpSpeed+=maxul;
int maxdl=dm.getStats().getDownloadRateLimitBytesPerSecond();
if (maxdl == 0) {
downSpeedUnlimited=true;
}
 else {
if (maxdl > downSpeedSetMax) {
downSpeedSetMax=maxdl;
}
}
if (maxdl == -1) {
maxdl=0;
downSpeedDisabled=true;
}
totalDownSpeed+=maxdl;
}
 catch (Exception ex) {
Debug.printStackTrace(ex);
}
if (barsOpened && !DownloadBar.getManager().isOpen(dm)) {
barsOpened=false;
}
stop=stop || ManagerUtils.isStopable(dm);
start=start || ManagerUtils.isStartable(dm);
recheck=recheck || dm.canForceRecheck();
forceStartEnabled=forceStartEnabled || ManagerUtils.isForceStartable(dm);
forceStart=forceStart || dm.isForceStart();
boolean stopped=ManagerUtils.isStopped(dm);
allStopped&=stopped;
fileMove=fileMove && dm.canMoveDataFiles();
if (userMode < 2) {
TRTrackerAnnouncer trackerClient=dm.getTrackerClient();
if (trackerClient != null) {
boolean update_state=((SystemTime.getCurrentTime() / 1000 - trackerClient.getLastUpdateTime() >= TRTrackerAnnouncer.REFRESH_MINIMUM_SECS));
manualUpdate=manualUpdate & update_state;
}
}
int state=dm.getState();
bChangeDir&=(state == DownloadManager.STATE_ERROR || state == DownloadManager.STATE_STOPPED || state == DownloadManager.STATE_QUEUED);
if (bChangeDir && dms.length == 1) {
bChangeDir=dm.isDataAlreadyAllocated();
if (bChangeDir && state == DownloadManager.STATE_ERROR) {
bChangeDir=!dm.filesExist(true);
}
 else {
bChangeDir=false;
}
}
DownloadManagerState dm_state=dm.getDownloadState();
boolean scan=dm_state.getFlag(DownloadManagerState.FLAG_SCAN_INCOMPLETE_PIECES);
boolean incomplete=!dm.isDownloadComplete(true);
allScanSelected=incomplete && allScanSelected && scan;
allScanNotSelected=incomplete && allScanNotSelected && !scan;
PEPeerManager pm=dm.getPeerManager();
if (pm != null) {
if (pm.canToggleSuperSeedMode()) {
canSetSuperSeed=true;
}
if (pm.isSuperSeedMode()) {
superSeedAllYes=false;
}
 else {
superSeedAllNo=false;
}
}
 else {
superSeedAllYes=false;
superSeedAllNo=false;
}
if (dm_state.isResumeDataComplete()) {
allResumeIncomplete=false;
}
if (stopped && !hasClearableLinks) {
if (dm.getDiskManagerFileInfoSet().nbFiles() > 1) {
if (dm_state.getFileLinks().hasLinks()) {
hasClearableLinks=true;
}
}
}
if (dm_state.getFileLinks().size() > 0) {
hasRevertableFiles=true;
}
}
fileRescan=allScanSelected || allScanNotSelected;
}
 else {
barsOpened=false;
forceStart=false;
forceStartEnabled=false;
start=false;
stop=false;
fileMove=false;
fileRescan=false;
upSpeedDisabled=true;
downSpeedDisabled=true;
changeUrl=false;
recheck=false;
manualUpdate=false;
}
if (bChangeDir) {
MenuItem menuItemChangeDir=new MenuItem(menu,SWT.PUSH);
Messages.setLanguageText(menuItemChangeDir,"String_Node_Str");
menuItemChangeDir.addListener(SWT.Selection,new Listener(){
@Override public void handleEvent(Event e){
changeDirSelectedTorrents(dms,shell);
}
}
);
}
if (include_show_details) {
final MenuItem itemDetails=new MenuItem(menu,SWT.PUSH);
Messages.setLanguageText(itemDetails,"String_Node_Str");
menu.setDefaultItem(itemDetails);
Utils.setMenuItemImage(itemDetails,"String_Node_Str");
itemDetails.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
UIFunctions uiFunctions=UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_DETAILS,dm);
}
}
}
);
itemDetails.setEnabled(hasSelection);
}
final MenuItem itemBar=new MenuItem(menu,SWT.CHECK);
Messages.setLanguageText(itemBar,"String_Node_Str");
Utils.setMenuItemImage(itemBar,"String_Node_Str");
itemBar.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
if (DownloadBar.getManager().isOpen(dm)) {
DownloadBar.close(dm);
}
 else {
DownloadBar.open(dm,menu.getShell());
}
}
}
);
itemBar.setEnabled(hasSelection);
itemBar.setSelection(barsOpened);
new MenuItem(menu,SWT.SEPARATOR);
final MenuItem itemOpen=new MenuItem(menu,SWT.PUSH);
Messages.setLanguageText(itemOpen,"String_Node_Str");
Utils.setMenuItemImage(itemOpen,"String_Node_Str");
itemOpen.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager[] dms){
runDataSources(dms);
}
}
);
itemOpen.setEnabled(hasSelection);
final boolean use_open_containing_folder=COConfigurationManager.getBooleanParameter("String_Node_Str");
final MenuItem itemExplore=new MenuItem(menu,SWT.PUSH);
Messages.setLanguageText(itemExplore,"String_Node_Str" + (use_open_containing_folder ? "String_Node_Str" : "String_Node_Str"));
itemExplore.addListener(SWT.Selection,new ListenerDMTask(dms,false){
@Override public void run(DownloadManager dm){
ManagerUtils.open(dm,use_open_containing_folder);
}
}
);
itemExplore.setEnabled(hasSelection);
final Menu menuBrowse=new Menu(menu.getShell(),SWT.DROP_DOWN);
final MenuItem itemBrowse=new MenuItem(menu,SWT.CASCADE);
Messages.setLanguageText(itemBrowse,"String_Node_Str");
itemBrowse.setMenu(menuBrowse);
final MenuItem itemBrowsePublic=new MenuItem(menuBrowse,SWT.PUSH);
itemBrowsePublic.setText(MessageText.getString("String_Node_Str") + "String_Node_Str");
itemBrowsePublic.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
ManagerUtils.browse(dm,false,true);
}
}
);
final MenuItem itemBrowseAnon=new MenuItem(menuBrowse,SWT.PUSH);
itemBrowseAnon.setText(MessageText.getString("String_Node_Str") + "String_Node_Str");
itemBrowseAnon.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
ManagerUtils.browse(dm,true,true);
}
}
);
new MenuItem(menuBrowse,SWT.SEPARATOR);
final MenuItem itemBrowseURL=new MenuItem(menuBrowse,SWT.PUSH);
Messages.setLanguageText(itemBrowseURL,"String_Node_Str");
itemBrowseURL.addListener(SWT.Selection,new Listener(){
@Override public void handleEvent(Event event){
Utils.getOffOfSWTThread(new AERunnable(){
@Override public void runSupport(){
String url=ManagerUtils.browse(dms[0],true,false);
if (url != null) {
ClipboardCopy.copyToClipBoard(url);
}
}
}
);
}
}
);
itemBrowseURL.setEnabled(isSingleSelection);
new MenuItem(menuBrowse,SWT.SEPARATOR);
final MenuItem itemBrowseDir=new MenuItem(menuBrowse,SWT.CHECK);
Messages.setLanguageText(itemBrowseDir,"String_Node_Str");
itemBrowseDir.setSelection(COConfigurationManager.getBooleanParameter("String_Node_Str"));
itemBrowseDir.addListener(SWT.Selection,new Listener(){
@Override public void handleEvent(Event event){
COConfigurationManager.setParameter("String_Node_Str",itemBrowseDir.getSelection());
}
}
);
itemBrowse.setEnabled(hasSelection);
final MenuItem itemAdvanced=new MenuItem(menu,SWT.CASCADE);
Messages.setLanguageText(itemAdvanced,"String_Node_Str");
itemAdvanced.setEnabled(hasSelection);
final Menu menuAdvanced=new Menu(menu.getShell(),SWT.DROP_DOWN);
itemAdvanced.setMenu(menuAdvanced);
long kInB=DisplayFormatters.getKinB();
long maxDownload=COConfigurationManager.getIntParameter("String_Node_Str",0) * kInB;
long maxUpload=COConfigurationManager.getIntParameter("String_Node_Str",0) * kInB;
ViewUtils.addSpeedMenu(menu.getShell(),menuAdvanced,true,true,true,hasSelection,downSpeedDisabled,downSpeedUnlimited,totalDownSpeed,downSpeedSetMax,maxDownload,upSpeedDisabled,upSpeedUnlimited,totalUpSpeed,upSpeedSetMax,maxUpload,dms.length,null,new ViewUtils.SpeedAdapter(){
@Override public void setDownSpeed(final int speed){
ListenerDMTask task=new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
dm.getStats().setDownloadRateLimitBytesPerSecond(speed);
}
}
;
task.go();
}
@Override public void setUpSpeed(final int speed){
ListenerDMTask task=new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
dm.getStats().setUploadRateLimitBytesPerSecond(speed);
}
}
;
task.go();
}
}
);
final Menu speedLimitsMenu=new Menu(menuAdvanced.getShell(),SWT.DROP_DOWN);
final MenuItem speedLimitsMenuItem=new MenuItem(menuAdvanced,SWT.CASCADE);
Messages.setLanguageText(speedLimitsMenuItem,IMenuConstants.MENU_ID_SPEED_LIMITS);
speedLimitsMenuItem.setMenu(speedLimitsMenu);
MenuBuildUtils.addMaintenanceListenerForMenu(speedLimitsMenu,new MenuBuildUtils.MenuBuilder(){
@Override public void buildMenu(Menu menu,MenuEvent menuEvent){
addSpeedLimitsMenu(dms,speedLimitsMenu);
}
}
);
final Menu menuTracker=new Menu(menu.getShell(),SWT.DROP_DOWN);
final MenuItem itemTracker=new MenuItem(menuAdvanced,SWT.CASCADE);
Messages.setLanguageText(itemTracker,"String_Node_Str");
itemTracker.setMenu(menuTracker);
itemExplore.setEnabled(hasSelection);
addTrackerTorrentMenu(menuTracker,dms,changeUrl,manualUpdate,allStopped,use_open_containing_folder);
final MenuItem itemFiles=new MenuItem(menuAdvanced,SWT.CASCADE);
Messages.setLanguageText(itemFiles,"String_Node_Str");
final Menu menuFiles=new Menu(shell,SWT.DROP_DOWN);
itemFiles.setMenu(menuFiles);
final MenuItem itemFileMoveData=new MenuItem(menuFiles,SWT.PUSH);
Messages.setLanguageText(itemFileMoveData,"String_Node_Str");
itemFileMoveData.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager[] dms){
moveDataFiles(shell,dms);
}
}
);
itemFileMoveData.setEnabled(fileMove);
final MenuItem itemFileMoveTorrent=new MenuItem(menuFiles,SWT.PUSH);
Messages.setLanguageText(itemFileMoveTorrent,"String_Node_Str");
itemFileMoveTorrent.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager[] dms){
moveTorrentFile(shell,dms);
}
}
);
itemFileMoveTorrent.setEnabled(fileMove);
final MenuItem itemCheckFilesExist=new MenuItem(menuFiles,SWT.PUSH);
Messages.setLanguageText(itemCheckFilesExist,"String_Node_Str");
itemCheckFilesExist.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
dm.filesExist(true);
}
}
);
final MenuItem itemLocateFiles=new MenuItem(menuFiles,SWT.PUSH);
Messages.setLanguageText(itemLocateFiles,"String_Node_Str");
itemLocateFiles.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager[] dms){
ManagerUtils.locateFiles(dms,menu.getShell());
}
}
);
final MenuItem itemFileRescan=new MenuItem(menuFiles,SWT.CHECK);
Messages.setLanguageText(itemFileRescan,"String_Node_Str");
itemFileRescan.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
dm.getDownloadState().setFlag(DownloadManagerState.FLAG_SCAN_INCOMPLETE_PIECES,itemFileRescan.getSelection());
}
}
);
itemFileRescan.setSelection(allScanSelected);
itemFileRescan.setEnabled(fileRescan);
final MenuItem itemRevertFiles=new MenuItem(menu,SWT.PUSH);
Messages.setLanguageText(itemRevertFiles,"String_Node_Str");
itemRevertFiles.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager[] dms){
FilesViewMenuUtil.revertFiles(tv,dms);
}
}
);
itemRevertFiles.setEnabled(hasRevertableFiles);
final MenuItem itemClearLinks=new MenuItem(menuFiles,SWT.PUSH);
Messages.setLanguageText(itemClearLinks,"String_Node_Str");
itemClearLinks.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
if (ManagerUtils.isStopped(dm) && dm.getDownloadState().getFileLinks().hasLinks()) {
DiskManagerFileInfoSet fis=dm.getDiskManagerFileInfoSet();
if (fis.nbFiles() > 1) {
DiskManagerFileInfo[] files=fis.getFiles();
for (DiskManagerFileInfo file_info : files) {
File file_link=file_info.getFile(true);
File file_nolink=file_info.getFile(false);
if (!file_nolink.getAbsolutePath().equals(file_link.getAbsolutePath())) {
  file_info.setLink(null);
}
}
}
}
}
}
);
itemClearLinks.setEnabled(hasClearableLinks);
MenuItem itemFileClearAlloc=new MenuItem(menuFiles,SWT.PUSH);
Messages.setLanguageText(itemFileClearAlloc,"String_Node_Str");
itemFileClearAlloc.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
dm.setDataAlreadyAllocated(false);
}
}
);
itemFileClearAlloc.setEnabled(allStopped);
MenuItem itemFileClearResume=new MenuItem(menuFiles,SWT.PUSH);
Messages.setLanguageText(itemFileClearResume,"String_Node_Str");
itemFileClearResume.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
dm.getDownloadState().clearResumeData();
}
}
);
itemFileClearResume.setEnabled(allStopped);
MenuItem itemFileSetResumeComplete=new MenuItem(menuFiles,SWT.PUSH);
Messages.setLanguageText(itemFileSetResumeComplete,"String_Node_Str");
itemFileSetResumeComplete.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
TorrentUtils.setResumeDataCompletelyValid(dm.getDownloadState());
}
}
);
itemFileSetResumeComplete.setEnabled(allStopped && allResumeIncomplete);
final List<Download> ar_dms=new ArrayList<>();
for (DownloadManager dm : dms) {
Download stub=PluginCoreUtils.wrap(dm);
if (!stub.canStubbify()) {
continue;
}
ar_dms.add(stub);
}
MenuItem itemArchive=new MenuItem(menuAdvanced,SWT.PUSH);
Messages.setLanguageText(itemArchive,"String_Node_Str");
Utils.setMenuItemImage(itemArchive,"String_Node_Str");
itemArchive.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
ManagerUtils.moveToArchive(ar_dms,null);
}
}
);
itemArchive.setEnabled(ar_dms.size() > 0);
final MenuItem itemRename=new MenuItem(menuAdvanced,SWT.DROP_DOWN);
Messages.setLanguageText(itemRename,"String_Node_Str");
itemRename.setEnabled(hasSelection);
itemRename.addListener(SWT.Selection,new Listener(){
@Override public void handleEvent(Event event){
for (DownloadManager dm : dms) {
AdvRenameWindow window=new AdvRenameWindow();
window.open(dm);
}
}
}
);
if (ManagerUtils.canFindMoreLikeThis()) {
final MenuItem itemFindMore=new MenuItem(menuAdvanced,SWT.PUSH);
Messages.setLanguageText(itemFindMore,"String_Node_Str");
itemFindMore.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager[] dms){
ManagerUtils.findMoreLikeThis(dms[0],menu.getShell());
}
}
);
itemFindMore.setSelection(isSingleSelection);
}
final Menu quickViewMenu=new Menu(menuAdvanced.getShell(),SWT.DROP_DOWN);
final MenuItem quickViewMenuItem=new MenuItem(menuAdvanced,SWT.CASCADE);
Messages.setLanguageText(quickViewMenuItem,IMenuConstants.MENU_ID_QUICK_VIEW);
quickViewMenuItem.setMenu(quickViewMenu);
MenuBuildUtils.addMaintenanceListenerForMenu(quickViewMenu,new MenuBuildUtils.MenuBuilder(){
@Override public void buildMenu(Menu menu,MenuEvent menuEvent){
DownloadManager dm=dms[0];
DiskManagerFileInfo[] files=dm.getDiskManagerFileInfoSet().getFiles();
int added=0;
for (final DiskManagerFileInfo file : files) {
if (Utils.isQuickViewSupported(file)) {
final MenuItem addItem=new MenuItem(menu,SWT.CHECK);
addItem.setSelection(Utils.isQuickViewActive(file));
addItem.setText(file.getTorrentFile().getRelativePath());
addItem.addListener(SWT.Selection,new Listener(){
@Override public void handleEvent(Event arg){
  Utils.setQuickViewActive(file,addItem.getSelection());
}
}
);
added++;
}
}
if (added == 0) {
final MenuItem addItem=new MenuItem(menu,SWT.PUSH);
addItem.setText(MessageText.getString("String_Node_Str"));
addItem.setEnabled(false);
}
}
}
);
quickViewMenuItem.setEnabled(isSingleSelection);
MenuFactory.addAlertsMenu(menuAdvanced,true,dms);
if (userMode > 0) {
final MenuItem itemExport=new MenuItem(menuAdvanced,SWT.CASCADE);
Messages.setLanguageText(itemExport,"String_Node_Str");
Utils.setMenuItemImage(itemExport,"String_Node_Str");
itemExport.setEnabled(hasSelection);
final Menu menuExport=new Menu(shell,SWT.DROP_DOWN);
itemExport.setMenu(menuExport);
final MenuItem itemExportXML=new MenuItem(menuExport,SWT.PUSH);
Messages.setLanguageText(itemExportXML,"String_Node_Str");
itemExportXML.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager[] dms){
DownloadManager dm=dms[0];
if (dm != null) new ExportTorrentWizard(itemExportXML.getDisplay(),dm);
}
}
);
final MenuItem itemExportTorrent=new MenuItem(menuExport,SWT.PUSH);
Messages.setLanguageText(itemExportTorrent,"String_Node_Str");
itemExportTorrent.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager[] dms){
exportTorrent(dms,shell);
}
}
);
final MenuItem itemWebSeed=new MenuItem(menuExport,SWT.PUSH);
Messages.setLanguageText(itemWebSeed,"String_Node_Str");
itemWebSeed.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager[] dms){
exportHTTPSeeds(dms);
}
}
);
}
if (userMode > 0) {
final MenuItem itemExportXML=new MenuItem(menuAdvanced,SWT.PUSH);
Messages.setLanguageText(itemExportXML,"String_Node_Str");
itemExportXML.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager[] dms){
UIFunctions uiFunctions=UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_OPTIONS,dms);
}
}
}
);
}
if (userMode > 0) {
final MenuItem itemPeerSource=new MenuItem(menuAdvanced,SWT.CASCADE);
Messages.setLanguageText(itemPeerSource,"String_Node_Str");
final Menu menuPeerSource=new Menu(shell,SWT.DROP_DOWN);
itemPeerSource.setMenu(menuPeerSource);
addPeerSourceSubMenu(dms,menuPeerSource);
}
{
final MenuItem dl_seq_enable=new MenuItem(menuAdvanced,SWT.CHECK);
Messages.setLanguageText(dl_seq_enable,"String_Node_Str");
dl_seq_enable.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
dm.getDownloadState().setFlag(DownloadManagerState.FLAG_SEQUENTIAL_DOWNLOAD,dl_seq_enable.getSelection());
}
}
);
boolean allSeq=true;
boolean AllNonSeq=true;
for (int j=0; j < dms.length; j++) {
DownloadManager dm=dms[j];
boolean seq=dm.getDownloadState().getFlag(DownloadManagerState.FLAG_SEQUENTIAL_DOWNLOAD);
if (seq) {
AllNonSeq=false;
}
 else {
allSeq=false;
}
}
boolean bChecked;
if (allSeq) {
bChecked=true;
}
 else if (AllNonSeq) {
bChecked=false;
}
 else {
bChecked=false;
}
dl_seq_enable.setSelection(bChecked);
}
if (userMode > 0) {
final MenuItem ipf_enable=new MenuItem(menuAdvanced,SWT.CHECK);
Messages.setLanguageText(ipf_enable,"String_Node_Str");
ipf_enable.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
dm.getDownloadState().setFlag(DownloadManagerState.FLAG_DISABLE_IP_FILTER,!ipf_enable.getSelection());
}
}
);
boolean bEnabled=IpFilterManagerFactory.getSingleton().getIPFilter().isEnabled();
if (bEnabled) {
boolean allChecked=true;
boolean allUnchecked=true;
for (int j=0; j < dms.length; j++) {
DownloadManager dm=(DownloadManager)dms[j];
boolean b=dm.getDownloadState().getFlag(DownloadManagerState.FLAG_DISABLE_IP_FILTER);
if (b) {
allUnchecked=false;
}
 else {
allChecked=false;
}
}
boolean bChecked;
if (allUnchecked) {
bChecked=true;
}
 else if (allChecked) {
bChecked=false;
}
 else {
bChecked=false;
}
ipf_enable.setSelection(bChecked);
}
ipf_enable.setEnabled(bEnabled);
}
if (userMode > 1) {
final MenuItem itemNetworks=new MenuItem(menuAdvanced,SWT.CASCADE);
Messages.setLanguageText(itemNetworks,"String_Node_Str");
final Menu menuNetworks=new Menu(shell,SWT.DROP_DOWN);
itemNetworks.setMenu(menuNetworks);
addNetworksSubMenu(dms,menuNetworks);
}
if (userMode > 1 && isSeedingView) {
final MenuItem itemSuperSeed=new MenuItem(menuAdvanced,SWT.CHECK);
Messages.setLanguageText(itemSuperSeed,"String_Node_Str");
boolean enabled=canSetSuperSeed && (superSeedAllNo || superSeedAllYes);
itemSuperSeed.setEnabled(enabled);
final boolean selected=superSeedAllNo;
if (enabled) {
itemSuperSeed.setSelection(selected);
itemSuperSeed.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
PEPeerManager pm=dm.getPeerManager();
if (pm != null) {
if (pm.isSuperSeedMode() == selected && pm.canToggleSuperSeedMode()) {
  pm.setSuperSeedMode(!selected);
}
}
}
}
);
}
}
if (userMode > 0) {
boolean can_pause=false;
for (int i=0; i < dms.length; i++) {
DownloadManager dm=dms[i];
if (ManagerUtils.isPauseable(dm)) {
can_pause=true;
break;
}
}
final MenuItem itemPauseFor=new MenuItem(menuAdvanced,SWT.PUSH);
itemPauseFor.setEnabled(can_pause);
Messages.setLanguageText(itemPauseFor,"String_Node_Str");
itemPauseFor.addSelectionListener(new SelectionAdapter(){
@Override public void widgetSelected(SelectionEvent e){
pauseDownloadsFor(dms);
}
}
);
}
final MenuItem itemPositionManual=new MenuItem(menuAdvanced,SWT.PUSH);
Messages.setLanguageText(itemPositionManual,"String_Node_Str");
Utils.setMenuItemImage(itemPositionManual,"String_Node_Str");
itemPositionManual.addSelectionListener(new SelectionAdapter(){
@Override public void widgetSelected(SelectionEvent e){
repositionManual(tv,dms,shell,isSeedingView);
}
}
);
if (userMode > 0 && isTrackerOn) {
final MenuItem itemHost=new MenuItem(menu,SWT.PUSH);
Messages.setLanguageText(itemHost,"String_Node_Str");
Utils.setMenuItemImage(itemHost,"String_Node_Str");
itemHost.addListener(SWT.Selection,new Listener(){
@Override public void handleEvent(Event event){
hostTorrents(dms);
}
}
);
final MenuItem itemPublish=new MenuItem(menu,SWT.PUSH);
Messages.setLanguageText(itemPublish,"String_Node_Str");
Utils.setMenuItemImage(itemPublish,"String_Node_Str");
itemPublish.addListener(SWT.Selection,new Listener(){
@Override public void handleEvent(Event event){
publishTorrents(dms);
}
}
);
itemHost.setEnabled(hasSelection);
itemPublish.setEnabled(hasSelection);
}
Menu menuCategory=new Menu(shell,SWT.DROP_DOWN);
final MenuItem itemCategory=new MenuItem(menu,SWT.CASCADE);
Messages.setLanguageText(itemCategory,"String_Node_Str");
itemCategory.setMenu(menuCategory);
itemCategory.setEnabled(hasSelection);
addCategorySubMenu(dms,menuCategory);
Menu menuTags=new Menu(shell,SWT.DROP_DOWN);
final MenuItem itemTags=new MenuItem(menu,SWT.CASCADE);
Messages.setLanguageText(itemTags,"String_Node_Str");
itemTags.setMenu(menuTags);
itemTags.setEnabled(hasSelection);
TagUIUtils.addLibraryViewTagsSubMenu(dms,menuTags);
if (isSeedingView) {
final MenuItem itemPersonalShare=new MenuItem(menu,SWT.PUSH);
Messages.setLanguageText(itemPersonalShare,"String_Node_Str");
itemPersonalShare.addListener(SWT.Selection,new ListenerDMTask(dms,false){
@Override public void run(DownloadManager dm){
File file=dm.getSaveLocation();
Map<String,String> properties=new HashMap<>();
properties.put(ShareManager.PR_PERSONAL,"String_Node_Str");
if (file.isFile()) {
ShareUtils.shareFile(file.getAbsolutePath(),properties);
}
 else if (file.isDirectory()) {
ShareUtils.shareDir(file.getAbsolutePath(),properties);
}
}
}
);
}
new MenuItem(menu,SWT.SEPARATOR);
final MenuItem itemQueue=new MenuItem(menu,SWT.PUSH);
Messages.setLanguageText(itemQueue,"String_Node_Str");
Utils.setMenuItemImage(itemQueue,"String_Node_Str");
itemQueue.addListener(SWT.Selection,new Listener(){
@Override public void handleEvent(Event event){
Utils.getOffOfSWTThread(new AERunnable(){
@Override public void runSupport(){
queueDataSources(dms,true);
}
}
);
}
}
);
itemQueue.setEnabled(start);
if (userMode > 0) {
final MenuItem itemForceStart=new MenuItem(menu,SWT.CHECK);
Messages.setLanguageText(itemForceStart,"String_Node_Str");
Utils.setMenuItemImage(itemForceStart,"String_Node_Str");
itemForceStart.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
if (ManagerUtils.isForceStartable(dm)) {
dm.setForceStart(itemForceStart.getSelection());
}
}
}
);
itemForceStart.setSelection(forceStart);
itemForceStart.setEnabled(forceStartEnabled);
}
if (userMode > 0) {
final MenuItem itemPause=new MenuItem(menu,SWT.PUSH);
Messages.setLanguageText(itemPause,"String_Node_Str");
Utils.setMenuItemImage(itemPause,"String_Node_Str");
itemPause.addListener(SWT.Selection,new Listener(){
@Override public void handleEvent(Event event){
Utils.getOffOfSWTThread(new AERunnable(){
@Override public void runSupport(){
pauseDataSources(dms);
}
}
);
}
}
);
itemPause.setEnabled(stop);
}
final MenuItem itemStop=new MenuItem(menu,SWT.PUSH);
Messages.setLanguageText(itemStop,"String_Node_Str");
Utils.setMenuItemImage(itemStop,"String_Node_Str");
itemStop.addListener(SWT.Selection,new Listener(){
@Override public void handleEvent(Event event){
Utils.getOffOfSWTThread(new AERunnable(){
@Override public void runSupport(){
stopDataSources(dms);
}
}
);
}
}
);
itemStop.setEnabled(stop);
final MenuItem itemRecheck=new MenuItem(menu,SWT.PUSH);
Messages.setLanguageText(itemRecheck,"String_Node_Str");
Utils.setMenuItemImage(itemRecheck,"String_Node_Str");
itemRecheck.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
if (dm.canForceRecheck()) {
dm.forceRecheck();
}
}
}
);
itemRecheck.setEnabled(recheck);
final MenuItem itemRemove=new MenuItem(menu,SWT.PUSH);
Messages.setLanguageText(itemRemove,"String_Node_Str");
Utils.setMenuItemImage(itemRemove,"String_Node_Str");
itemRemove.addListener(SWT.Selection,new Listener(){
@Override public void handleEvent(Event event){
removeDownloads(dms,null,true);
}
}
);
itemRemove.setEnabled(hasSelection);
}

Fixed version (ground truth):
public static void fillTorrentMenu(final Menu menu,final DownloadManager[] dms,final Core core,boolean include_show_details,int selected_dl_types,final TableView tv){
  Shell shell=Utils.findAnyShell();
  Shell menu_shell=menu.getShell();
  final boolean isSeedingView;
switch (selected_dl_types) {
case 1:
    isSeedingView=false;
  break;
case 2:
isSeedingView=true;
break;
case 0:
{
if (dms.length == 1) {
isSeedingView=dms[0].isDownloadComplete(false);
break;
}
}
default :
isSeedingView=false;
}
boolean hasSelection=dms.length > 0;
boolean isSingleSelection=dms.length == 1;
boolean isTrackerOn=TRTrackerUtils.isTrackerEnabled();
int userMode=COConfigurationManager.getIntParameter("String_Node_Str");
boolean bChangeDir=hasSelection;
boolean start, stop, changeUrl, barsOpened, forceStart;
boolean forceStartEnabled, recheck, manualUpdate, fileMove, fileRescan;
changeUrl=barsOpened=manualUpdate=fileMove=fileRescan=true;
forceStart=forceStartEnabled=recheck=start=stop=false;
boolean canSetSuperSeed=false;
boolean superSeedAllYes=true;
boolean superSeedAllNo=true;
boolean upSpeedDisabled=false;
long totalUpSpeed=0;
boolean upSpeedUnlimited=false;
long upSpeedSetMax=0;
boolean downSpeedDisabled=false;
long totalDownSpeed=0;
boolean downSpeedUnlimited=false;
long downSpeedSetMax=0;
boolean allScanSelected=true;
boolean allScanNotSelected=true;
boolean allStopped=true;
boolean allResumeIncomplete=true;
boolean hasClearableLinks=false;
boolean hasRevertableFiles=false;
if (hasSelection) {
for (int i=0; i < dms.length; i++) {
DownloadManager dm=(DownloadManager)dms[i];
try {
int maxul=dm.getStats().getUploadRateLimitBytesPerSecond();
if (maxul == 0) {
upSpeedUnlimited=true;
}
 else {
if (maxul > upSpeedSetMax) {
upSpeedSetMax=maxul;
}
}
if (maxul == -1) {
maxul=0;
upSpeedDisabled=true;
}
totalUpSpeed+=maxul;
int maxdl=dm.getStats().getDownloadRateLimitBytesPerSecond();
if (maxdl == 0) {
downSpeedUnlimited=true;
}
 else {
if (maxdl > downSpeedSetMax) {
downSpeedSetMax=maxdl;
}
}
if (maxdl == -1) {
maxdl=0;
downSpeedDisabled=true;
}
totalDownSpeed+=maxdl;
}
 catch (Exception ex) {
Debug.printStackTrace(ex);
}
if (barsOpened && !DownloadBar.getManager().isOpen(dm)) {
barsOpened=false;
}
stop=stop || ManagerUtils.isStopable(dm);
start=start || ManagerUtils.isStartable(dm);
recheck=recheck || dm.canForceRecheck();
forceStartEnabled=forceStartEnabled || ManagerUtils.isForceStartable(dm);
forceStart=forceStart || dm.isForceStart();
boolean stopped=ManagerUtils.isStopped(dm);
allStopped&=stopped;
fileMove=fileMove && dm.canMoveDataFiles();
if (userMode < 2) {
TRTrackerAnnouncer trackerClient=dm.getTrackerClient();
if (trackerClient != null) {
boolean update_state=((SystemTime.getCurrentTime() / 1000 - trackerClient.getLastUpdateTime() >= TRTrackerAnnouncer.REFRESH_MINIMUM_SECS));
manualUpdate=manualUpdate & update_state;
}
}
int state=dm.getState();
bChangeDir&=(state == DownloadManager.STATE_ERROR || state == DownloadManager.STATE_STOPPED || state == DownloadManager.STATE_QUEUED);
if (bChangeDir && dms.length == 1) {
bChangeDir=dm.isDataAlreadyAllocated();
if (bChangeDir && state == DownloadManager.STATE_ERROR) {
bChangeDir=!dm.filesExist(true);
}
 else {
bChangeDir=false;
}
}
DownloadManagerState dm_state=dm.getDownloadState();
boolean scan=dm_state.getFlag(DownloadManagerState.FLAG_SCAN_INCOMPLETE_PIECES);
boolean incomplete=!dm.isDownloadComplete(true);
allScanSelected=incomplete && allScanSelected && scan;
allScanNotSelected=incomplete && allScanNotSelected && !scan;
PEPeerManager pm=dm.getPeerManager();
if (pm != null) {
if (pm.canToggleSuperSeedMode()) {
canSetSuperSeed=true;
}
if (pm.isSuperSeedMode()) {
superSeedAllYes=false;
}
 else {
superSeedAllNo=false;
}
}
 else {
superSeedAllYes=false;
superSeedAllNo=false;
}
if (dm_state.isResumeDataComplete()) {
allResumeIncomplete=false;
}
if (stopped && !hasClearableLinks) {
if (dm.getDiskManagerFileInfoSet().nbFiles() > 1) {
if (dm_state.getFileLinks().hasLinks()) {
hasClearableLinks=true;
}
}
}
if (dm_state.getFileLinks().size() > 0) {
hasRevertableFiles=true;
}
}
fileRescan=allScanSelected || allScanNotSelected;
}
 else {
barsOpened=false;
forceStart=false;
forceStartEnabled=false;
start=false;
stop=false;
fileMove=false;
fileRescan=false;
upSpeedDisabled=true;
downSpeedDisabled=true;
changeUrl=false;
recheck=false;
manualUpdate=false;
}
if (bChangeDir) {
MenuItem menuItemChangeDir=new MenuItem(menu,SWT.PUSH);
Messages.setLanguageText(menuItemChangeDir,"String_Node_Str");
menuItemChangeDir.addListener(SWT.Selection,new Listener(){
@Override public void handleEvent(Event e){
changeDirSelectedTorrents(dms,shell);
}
}
);
}
if (include_show_details) {
final MenuItem itemDetails=new MenuItem(menu,SWT.PUSH);
Messages.setLanguageText(itemDetails,"String_Node_Str");
menu.setDefaultItem(itemDetails);
Utils.setMenuItemImage(itemDetails,"String_Node_Str");
itemDetails.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
UIFunctions uiFunctions=UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_DETAILS,dm);
}
}
}
);
itemDetails.setEnabled(hasSelection);
}
final MenuItem itemBar=new MenuItem(menu,SWT.CHECK);
Messages.setLanguageText(itemBar,"String_Node_Str");
Utils.setMenuItemImage(itemBar,"String_Node_Str");
itemBar.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
if (DownloadBar.getManager().isOpen(dm)) {
DownloadBar.close(dm);
}
 else {
DownloadBar.open(dm,shell);
}
}
}
);
itemBar.setEnabled(hasSelection);
itemBar.setSelection(barsOpened);
new MenuItem(menu,SWT.SEPARATOR);
final MenuItem itemOpen=new MenuItem(menu,SWT.PUSH);
Messages.setLanguageText(itemOpen,"String_Node_Str");
Utils.setMenuItemImage(itemOpen,"String_Node_Str");
itemOpen.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager[] dms){
runDataSources(dms);
}
}
);
itemOpen.setEnabled(hasSelection);
final boolean use_open_containing_folder=COConfigurationManager.getBooleanParameter("String_Node_Str");
final MenuItem itemExplore=new MenuItem(menu,SWT.PUSH);
Messages.setLanguageText(itemExplore,"String_Node_Str" + (use_open_containing_folder ? "String_Node_Str" : "String_Node_Str"));
itemExplore.addListener(SWT.Selection,new ListenerDMTask(dms,false){
@Override public void run(DownloadManager dm){
ManagerUtils.open(dm,use_open_containing_folder);
}
}
);
itemExplore.setEnabled(hasSelection);
final Menu menuBrowse=new Menu(menu_shell,SWT.DROP_DOWN);
final MenuItem itemBrowse=new MenuItem(menu,SWT.CASCADE);
Messages.setLanguageText(itemBrowse,"String_Node_Str");
itemBrowse.setMenu(menuBrowse);
final MenuItem itemBrowsePublic=new MenuItem(menuBrowse,SWT.PUSH);
itemBrowsePublic.setText(MessageText.getString("String_Node_Str") + "String_Node_Str");
itemBrowsePublic.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
ManagerUtils.browse(dm,false,true);
}
}
);
final MenuItem itemBrowseAnon=new MenuItem(menuBrowse,SWT.PUSH);
itemBrowseAnon.setText(MessageText.getString("String_Node_Str") + "String_Node_Str");
itemBrowseAnon.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
ManagerUtils.browse(dm,true,true);
}
}
);
new MenuItem(menuBrowse,SWT.SEPARATOR);
final MenuItem itemBrowseURL=new MenuItem(menuBrowse,SWT.PUSH);
Messages.setLanguageText(itemBrowseURL,"String_Node_Str");
itemBrowseURL.addListener(SWT.Selection,new Listener(){
@Override public void handleEvent(Event event){
Utils.getOffOfSWTThread(new AERunnable(){
@Override public void runSupport(){
String url=ManagerUtils.browse(dms[0],true,false);
if (url != null) {
ClipboardCopy.copyToClipBoard(url);
}
}
}
);
}
}
);
itemBrowseURL.setEnabled(isSingleSelection);
new MenuItem(menuBrowse,SWT.SEPARATOR);
final MenuItem itemBrowseDir=new MenuItem(menuBrowse,SWT.CHECK);
Messages.setLanguageText(itemBrowseDir,"String_Node_Str");
itemBrowseDir.setSelection(COConfigurationManager.getBooleanParameter("String_Node_Str"));
itemBrowseDir.addListener(SWT.Selection,new Listener(){
@Override public void handleEvent(Event event){
COConfigurationManager.setParameter("String_Node_Str",itemBrowseDir.getSelection());
}
}
);
itemBrowse.setEnabled(hasSelection);
final MenuItem itemAdvanced=new MenuItem(menu,SWT.CASCADE);
Messages.setLanguageText(itemAdvanced,"String_Node_Str");
itemAdvanced.setEnabled(hasSelection);
final Menu menuAdvanced=new Menu(menu_shell,SWT.DROP_DOWN);
itemAdvanced.setMenu(menuAdvanced);
long kInB=DisplayFormatters.getKinB();
long maxDownload=COConfigurationManager.getIntParameter("String_Node_Str",0) * kInB;
long maxUpload=COConfigurationManager.getIntParameter("String_Node_Str",0) * kInB;
ViewUtils.addSpeedMenu(menu_shell,menuAdvanced,true,true,true,hasSelection,downSpeedDisabled,downSpeedUnlimited,totalDownSpeed,downSpeedSetMax,maxDownload,upSpeedDisabled,upSpeedUnlimited,totalUpSpeed,upSpeedSetMax,maxUpload,dms.length,null,new ViewUtils.SpeedAdapter(){
@Override public void setDownSpeed(final int speed){
ListenerDMTask task=new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
dm.getStats().setDownloadRateLimitBytesPerSecond(speed);
}
}
;
task.go();
}
@Override public void setUpSpeed(final int speed){
ListenerDMTask task=new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
dm.getStats().setUploadRateLimitBytesPerSecond(speed);
}
}
;
task.go();
}
}
);
final Menu speedLimitsMenu=new Menu(menuAdvanced.getShell(),SWT.DROP_DOWN);
final MenuItem speedLimitsMenuItem=new MenuItem(menuAdvanced,SWT.CASCADE);
Messages.setLanguageText(speedLimitsMenuItem,IMenuConstants.MENU_ID_SPEED_LIMITS);
speedLimitsMenuItem.setMenu(speedLimitsMenu);
MenuBuildUtils.addMaintenanceListenerForMenu(speedLimitsMenu,new MenuBuildUtils.MenuBuilder(){
@Override public void buildMenu(Menu menu,MenuEvent menuEvent){
addSpeedLimitsMenu(dms,speedLimitsMenu);
}
}
);
final Menu menuTracker=new Menu(menu_shell,SWT.DROP_DOWN);
final MenuItem itemTracker=new MenuItem(menuAdvanced,SWT.CASCADE);
Messages.setLanguageText(itemTracker,"String_Node_Str");
itemTracker.setMenu(menuTracker);
itemExplore.setEnabled(hasSelection);
addTrackerTorrentMenu(menuTracker,dms,changeUrl,manualUpdate,allStopped,use_open_containing_folder);
final MenuItem itemFiles=new MenuItem(menuAdvanced,SWT.CASCADE);
Messages.setLanguageText(itemFiles,"String_Node_Str");
final Menu menuFiles=new Menu(menu_shell,SWT.DROP_DOWN);
itemFiles.setMenu(menuFiles);
final MenuItem itemFileMoveData=new MenuItem(menuFiles,SWT.PUSH);
Messages.setLanguageText(itemFileMoveData,"String_Node_Str");
itemFileMoveData.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager[] dms){
moveDataFiles(shell,dms);
}
}
);
itemFileMoveData.setEnabled(fileMove);
final MenuItem itemFileMoveTorrent=new MenuItem(menuFiles,SWT.PUSH);
Messages.setLanguageText(itemFileMoveTorrent,"String_Node_Str");
itemFileMoveTorrent.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager[] dms){
moveTorrentFile(shell,dms);
}
}
);
itemFileMoveTorrent.setEnabled(fileMove);
final MenuItem itemCheckFilesExist=new MenuItem(menuFiles,SWT.PUSH);
Messages.setLanguageText(itemCheckFilesExist,"String_Node_Str");
itemCheckFilesExist.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
dm.filesExist(true);
}
}
);
final MenuItem itemLocateFiles=new MenuItem(menuFiles,SWT.PUSH);
Messages.setLanguageText(itemLocateFiles,"String_Node_Str");
itemLocateFiles.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager[] dms){
ManagerUtils.locateFiles(dms,shell);
}
}
);
final MenuItem itemFileRescan=new MenuItem(menuFiles,SWT.CHECK);
Messages.setLanguageText(itemFileRescan,"String_Node_Str");
itemFileRescan.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
dm.getDownloadState().setFlag(DownloadManagerState.FLAG_SCAN_INCOMPLETE_PIECES,itemFileRescan.getSelection());
}
}
);
itemFileRescan.setSelection(allScanSelected);
itemFileRescan.setEnabled(fileRescan);
final MenuItem itemRevertFiles=new MenuItem(menu,SWT.PUSH);
Messages.setLanguageText(itemRevertFiles,"String_Node_Str");
itemRevertFiles.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager[] dms){
FilesViewMenuUtil.revertFiles(tv,dms);
}
}
);
itemRevertFiles.setEnabled(hasRevertableFiles);
final MenuItem itemClearLinks=new MenuItem(menuFiles,SWT.PUSH);
Messages.setLanguageText(itemClearLinks,"String_Node_Str");
itemClearLinks.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
if (ManagerUtils.isStopped(dm) && dm.getDownloadState().getFileLinks().hasLinks()) {
DiskManagerFileInfoSet fis=dm.getDiskManagerFileInfoSet();
if (fis.nbFiles() > 1) {
DiskManagerFileInfo[] files=fis.getFiles();
for (DiskManagerFileInfo file_info : files) {
File file_link=file_info.getFile(true);
File file_nolink=file_info.getFile(false);
if (!file_nolink.getAbsolutePath().equals(file_link.getAbsolutePath())) {
  file_info.setLink(null);
}
}
}
}
}
}
);
itemClearLinks.setEnabled(hasClearableLinks);
MenuItem itemFileClearAlloc=new MenuItem(menuFiles,SWT.PUSH);
Messages.setLanguageText(itemFileClearAlloc,"String_Node_Str");
itemFileClearAlloc.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
dm.setDataAlreadyAllocated(false);
}
}
);
itemFileClearAlloc.setEnabled(allStopped);
MenuItem itemFileClearResume=new MenuItem(menuFiles,SWT.PUSH);
Messages.setLanguageText(itemFileClearResume,"String_Node_Str");
itemFileClearResume.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
dm.getDownloadState().clearResumeData();
}
}
);
itemFileClearResume.setEnabled(allStopped);
MenuItem itemFileSetResumeComplete=new MenuItem(menuFiles,SWT.PUSH);
Messages.setLanguageText(itemFileSetResumeComplete,"String_Node_Str");
itemFileSetResumeComplete.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
TorrentUtils.setResumeDataCompletelyValid(dm.getDownloadState());
}
}
);
itemFileSetResumeComplete.setEnabled(allStopped && allResumeIncomplete);
final List<Download> ar_dms=new ArrayList<>();
for (DownloadManager dm : dms) {
Download stub=PluginCoreUtils.wrap(dm);
if (!stub.canStubbify()) {
continue;
}
ar_dms.add(stub);
}
MenuItem itemArchive=new MenuItem(menuAdvanced,SWT.PUSH);
Messages.setLanguageText(itemArchive,"String_Node_Str");
Utils.setMenuItemImage(itemArchive,"String_Node_Str");
itemArchive.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
ManagerUtils.moveToArchive(ar_dms,null);
}
}
);
itemArchive.setEnabled(ar_dms.size() > 0);
final MenuItem itemRename=new MenuItem(menuAdvanced,SWT.DROP_DOWN);
Messages.setLanguageText(itemRename,"String_Node_Str");
itemRename.setEnabled(hasSelection);
itemRename.addListener(SWT.Selection,new Listener(){
@Override public void handleEvent(Event event){
for (DownloadManager dm : dms) {
AdvRenameWindow window=new AdvRenameWindow();
window.open(dm);
}
}
}
);
if (ManagerUtils.canFindMoreLikeThis()) {
final MenuItem itemFindMore=new MenuItem(menuAdvanced,SWT.PUSH);
Messages.setLanguageText(itemFindMore,"String_Node_Str");
itemFindMore.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager[] dms){
ManagerUtils.findMoreLikeThis(dms[0],shell);
}
}
);
itemFindMore.setSelection(isSingleSelection);
}
final Menu quickViewMenu=new Menu(menuAdvanced.getShell(),SWT.DROP_DOWN);
final MenuItem quickViewMenuItem=new MenuItem(menuAdvanced,SWT.CASCADE);
Messages.setLanguageText(quickViewMenuItem,IMenuConstants.MENU_ID_QUICK_VIEW);
quickViewMenuItem.setMenu(quickViewMenu);
MenuBuildUtils.addMaintenanceListenerForMenu(quickViewMenu,new MenuBuildUtils.MenuBuilder(){
@Override public void buildMenu(Menu menu,MenuEvent menuEvent){
DownloadManager dm=dms[0];
DiskManagerFileInfo[] files=dm.getDiskManagerFileInfoSet().getFiles();
int added=0;
for (final DiskManagerFileInfo file : files) {
if (Utils.isQuickViewSupported(file)) {
final MenuItem addItem=new MenuItem(menu,SWT.CHECK);
addItem.setSelection(Utils.isQuickViewActive(file));
addItem.setText(file.getTorrentFile().getRelativePath());
addItem.addListener(SWT.Selection,new Listener(){
@Override public void handleEvent(Event arg){
  Utils.setQuickViewActive(file,addItem.getSelection());
}
}
);
added++;
}
}
if (added == 0) {
final MenuItem addItem=new MenuItem(menu,SWT.PUSH);
addItem.setText(MessageText.getString("String_Node_Str"));
addItem.setEnabled(false);
}
}
}
);
quickViewMenuItem.setEnabled(isSingleSelection);
MenuFactory.addAlertsMenu(menuAdvanced,true,dms);
if (userMode > 0) {
final MenuItem itemExport=new MenuItem(menuAdvanced,SWT.CASCADE);
Messages.setLanguageText(itemExport,"String_Node_Str");
Utils.setMenuItemImage(itemExport,"String_Node_Str");
itemExport.setEnabled(hasSelection);
final Menu menuExport=new Menu(menu_shell,SWT.DROP_DOWN);
itemExport.setMenu(menuExport);
final MenuItem itemExportXML=new MenuItem(menuExport,SWT.PUSH);
Messages.setLanguageText(itemExportXML,"String_Node_Str");
itemExportXML.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager[] dms){
DownloadManager dm=dms[0];
if (dm != null) new ExportTorrentWizard(itemExportXML.getDisplay(),dm);
}
}
);
final MenuItem itemExportTorrent=new MenuItem(menuExport,SWT.PUSH);
Messages.setLanguageText(itemExportTorrent,"String_Node_Str");
itemExportTorrent.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager[] dms){
exportTorrent(dms,shell);
}
}
);
final MenuItem itemWebSeed=new MenuItem(menuExport,SWT.PUSH);
Messages.setLanguageText(itemWebSeed,"String_Node_Str");
itemWebSeed.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager[] dms){
exportHTTPSeeds(dms);
}
}
);
}
if (userMode > 0) {
final MenuItem itemExportXML=new MenuItem(menuAdvanced,SWT.PUSH);
Messages.setLanguageText(itemExportXML,"String_Node_Str");
itemExportXML.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager[] dms){
UIFunctions uiFunctions=UIFunctionsManager.getUIFunctions();
if (uiFunctions != null) {
uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_OPTIONS,dms);
}
}
}
);
}
if (userMode > 0) {
final MenuItem itemPeerSource=new MenuItem(menuAdvanced,SWT.CASCADE);
Messages.setLanguageText(itemPeerSource,"String_Node_Str");
final Menu menuPeerSource=new Menu(menu_shell,SWT.DROP_DOWN);
itemPeerSource.setMenu(menuPeerSource);
addPeerSourceSubMenu(dms,menuPeerSource);
}
{
final MenuItem dl_seq_enable=new MenuItem(menuAdvanced,SWT.CHECK);
Messages.setLanguageText(dl_seq_enable,"String_Node_Str");
dl_seq_enable.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
dm.getDownloadState().setFlag(DownloadManagerState.FLAG_SEQUENTIAL_DOWNLOAD,dl_seq_enable.getSelection());
}
}
);
boolean allSeq=true;
boolean AllNonSeq=true;
for (int j=0; j < dms.length; j++) {
DownloadManager dm=dms[j];
boolean seq=dm.getDownloadState().getFlag(DownloadManagerState.FLAG_SEQUENTIAL_DOWNLOAD);
if (seq) {
AllNonSeq=false;
}
 else {
allSeq=false;
}
}
boolean bChecked;
if (allSeq) {
bChecked=true;
}
 else if (AllNonSeq) {
bChecked=false;
}
 else {
bChecked=false;
}
dl_seq_enable.setSelection(bChecked);
}
if (userMode > 0) {
final MenuItem ipf_enable=new MenuItem(menuAdvanced,SWT.CHECK);
Messages.setLanguageText(ipf_enable,"String_Node_Str");
ipf_enable.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
dm.getDownloadState().setFlag(DownloadManagerState.FLAG_DISABLE_IP_FILTER,!ipf_enable.getSelection());
}
}
);
boolean bEnabled=IpFilterManagerFactory.getSingleton().getIPFilter().isEnabled();
if (bEnabled) {
boolean allChecked=true;
boolean allUnchecked=true;
for (int j=0; j < dms.length; j++) {
DownloadManager dm=(DownloadManager)dms[j];
boolean b=dm.getDownloadState().getFlag(DownloadManagerState.FLAG_DISABLE_IP_FILTER);
if (b) {
allUnchecked=false;
}
 else {
allChecked=false;
}
}
boolean bChecked;
if (allUnchecked) {
bChecked=true;
}
 else if (allChecked) {
bChecked=false;
}
 else {
bChecked=false;
}
ipf_enable.setSelection(bChecked);
}
ipf_enable.setEnabled(bEnabled);
}
if (userMode > 1) {
final MenuItem itemNetworks=new MenuItem(menuAdvanced,SWT.CASCADE);
Messages.setLanguageText(itemNetworks,"String_Node_Str");
final Menu menuNetworks=new Menu(menu_shell,SWT.DROP_DOWN);
itemNetworks.setMenu(menuNetworks);
addNetworksSubMenu(dms,menuNetworks);
}
if (userMode > 1 && isSeedingView) {
final MenuItem itemSuperSeed=new MenuItem(menuAdvanced,SWT.CHECK);
Messages.setLanguageText(itemSuperSeed,"String_Node_Str");
boolean enabled=canSetSuperSeed && (superSeedAllNo || superSeedAllYes);
itemSuperSeed.setEnabled(enabled);
final boolean selected=superSeedAllNo;
if (enabled) {
itemSuperSeed.setSelection(selected);
itemSuperSeed.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
PEPeerManager pm=dm.getPeerManager();
if (pm != null) {
if (pm.isSuperSeedMode() == selected && pm.canToggleSuperSeedMode()) {
  pm.setSuperSeedMode(!selected);
}
}
}
}
);
}
}
if (userMode > 0) {
boolean can_pause=false;
for (int i=0; i < dms.length; i++) {
DownloadManager dm=dms[i];
if (ManagerUtils.isPauseable(dm)) {
can_pause=true;
break;
}
}
final MenuItem itemPauseFor=new MenuItem(menuAdvanced,SWT.PUSH);
itemPauseFor.setEnabled(can_pause);
Messages.setLanguageText(itemPauseFor,"String_Node_Str");
itemPauseFor.addSelectionListener(new SelectionAdapter(){
@Override public void widgetSelected(SelectionEvent e){
pauseDownloadsFor(dms);
}
}
);
}
final MenuItem itemPositionManual=new MenuItem(menuAdvanced,SWT.PUSH);
Messages.setLanguageText(itemPositionManual,"String_Node_Str");
Utils.setMenuItemImage(itemPositionManual,"String_Node_Str");
itemPositionManual.addSelectionListener(new SelectionAdapter(){
@Override public void widgetSelected(SelectionEvent e){
repositionManual(tv,dms,shell,isSeedingView);
}
}
);
if (userMode > 0 && isTrackerOn) {
final MenuItem itemHost=new MenuItem(menu,SWT.PUSH);
Messages.setLanguageText(itemHost,"String_Node_Str");
Utils.setMenuItemImage(itemHost,"String_Node_Str");
itemHost.addListener(SWT.Selection,new Listener(){
@Override public void handleEvent(Event event){
hostTorrents(dms);
}
}
);
final MenuItem itemPublish=new MenuItem(menu,SWT.PUSH);
Messages.setLanguageText(itemPublish,"String_Node_Str");
Utils.setMenuItemImage(itemPublish,"String_Node_Str");
itemPublish.addListener(SWT.Selection,new Listener(){
@Override public void handleEvent(Event event){
publishTorrents(dms);
}
}
);
itemHost.setEnabled(hasSelection);
itemPublish.setEnabled(hasSelection);
}
Menu menuCategory=new Menu(menu_shell,SWT.DROP_DOWN);
final MenuItem itemCategory=new MenuItem(menu,SWT.CASCADE);
Messages.setLanguageText(itemCategory,"String_Node_Str");
itemCategory.setMenu(menuCategory);
itemCategory.setEnabled(hasSelection);
addCategorySubMenu(dms,menuCategory);
Menu menuTags=new Menu(menu_shell,SWT.DROP_DOWN);
final MenuItem itemTags=new MenuItem(menu,SWT.CASCADE);
Messages.setLanguageText(itemTags,"String_Node_Str");
itemTags.setMenu(menuTags);
itemTags.setEnabled(hasSelection);
TagUIUtils.addLibraryViewTagsSubMenu(dms,menuTags);
if (isSeedingView) {
final MenuItem itemPersonalShare=new MenuItem(menu,SWT.PUSH);
Messages.setLanguageText(itemPersonalShare,"String_Node_Str");
itemPersonalShare.addListener(SWT.Selection,new ListenerDMTask(dms,false){
@Override public void run(DownloadManager dm){
File file=dm.getSaveLocation();
Map<String,String> properties=new HashMap<>();
properties.put(ShareManager.PR_PERSONAL,"String_Node_Str");
if (file.isFile()) {
ShareUtils.shareFile(file.getAbsolutePath(),properties);
}
 else if (file.isDirectory()) {
ShareUtils.shareDir(file.getAbsolutePath(),properties);
}
}
}
);
}
new MenuItem(menu,SWT.SEPARATOR);
final MenuItem itemQueue=new MenuItem(menu,SWT.PUSH);
Messages.setLanguageText(itemQueue,"String_Node_Str");
Utils.setMenuItemImage(itemQueue,"String_Node_Str");
itemQueue.addListener(SWT.Selection,new Listener(){
@Override public void handleEvent(Event event){
Utils.getOffOfSWTThread(new AERunnable(){
@Override public void runSupport(){
queueDataSources(dms,true);
}
}
);
}
}
);
itemQueue.setEnabled(start);
if (userMode > 0) {
final MenuItem itemForceStart=new MenuItem(menu,SWT.CHECK);
Messages.setLanguageText(itemForceStart,"String_Node_Str");
Utils.setMenuItemImage(itemForceStart,"String_Node_Str");
itemForceStart.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
if (ManagerUtils.isForceStartable(dm)) {
dm.setForceStart(itemForceStart.getSelection());
}
}
}
);
itemForceStart.setSelection(forceStart);
itemForceStart.setEnabled(forceStartEnabled);
}
if (userMode > 0) {
final MenuItem itemPause=new MenuItem(menu,SWT.PUSH);
Messages.setLanguageText(itemPause,"String_Node_Str");
Utils.setMenuItemImage(itemPause,"String_Node_Str");
itemPause.addListener(SWT.Selection,new Listener(){
@Override public void handleEvent(Event event){
Utils.getOffOfSWTThread(new AERunnable(){
@Override public void runSupport(){
pauseDataSources(dms);
}
}
);
}
}
);
itemPause.setEnabled(stop);
}
final MenuItem itemStop=new MenuItem(menu,SWT.PUSH);
Messages.setLanguageText(itemStop,"String_Node_Str");
Utils.setMenuItemImage(itemStop,"String_Node_Str");
itemStop.addListener(SWT.Selection,new Listener(){
@Override public void handleEvent(Event event){
Utils.getOffOfSWTThread(new AERunnable(){
@Override public void runSupport(){
stopDataSources(dms);
}
}
);
}
}
);
itemStop.setEnabled(stop);
final MenuItem itemRecheck=new MenuItem(menu,SWT.PUSH);
Messages.setLanguageText(itemRecheck,"String_Node_Str");
Utils.setMenuItemImage(itemRecheck,"String_Node_Str");
itemRecheck.addListener(SWT.Selection,new ListenerDMTask(dms){
@Override public void run(DownloadManager dm){
if (dm.canForceRecheck()) {
dm.forceRecheck();
}
}
}
);
itemRecheck.setEnabled(recheck);
final MenuItem itemRemove=new MenuItem(menu,SWT.PUSH);
Messages.setLanguageText(itemRemove,"String_Node_Str");
Utils.setMenuItemImage(itemRemove,"String_Node_Str");
itemRemove.addListener(SWT.Selection,new Listener(){
@Override public void handleEvent(Event event){
removeDownloads(dms,null,true);
}
}
);
itemRemove.setEnabled(hasSelection);
}