FileDocCategorySizeDatePackage
ManagerView.javaAPI DocAzureus 3.0.3.412535Thu Aug 02 17:32:30 BST 2007org.gudy.azureus2.ui.swt.views

ManagerView

public class ManagerView extends AbstractIView implements org.gudy.azureus2.core3.download.DownloadManagerListener, org.gudy.azureus2.ui.swt.debug.ObfusticateTab, org.gudy.azureus2.ui.swt.debug.ObfusticateImage
Torrent download view, consisting of several information tabs
author
Olivier

Fields Summary
private com.aelitis.azureus.core.AzureusCore
azureus_core
private org.gudy.azureus2.core3.download.DownloadManager
manager
private TabFolder
folder
private ArrayList
tabViews
Constructors Summary
public ManagerView(com.aelitis.azureus.core.AzureusCore _azureus_core, org.gudy.azureus2.core3.download.DownloadManager manager)

  
   
  
  			
	  
  
  	azureus_core	= _azureus_core;
  	dataSourceChanged(manager);
    
  
Methods Summary
public voidaddSection(org.gudy.azureus2.ui.swt.pluginsimpl.UISWTViewImpl view)

		Object pluginDataSource = null;
		try {
			pluginDataSource = DownloadManagerImpl.getDownloadStatic(manager);
		} catch (DownloadException e) { 
			/* Ignore */
		}
		addSection(view, pluginDataSource);
	
private voidaddSection(IView view, java.lang.Object dataSource)

		if (view == null)
			return;

		view.dataSourceChanged(dataSource);

		TabItem item = new TabItem(folder, SWT.NULL);
		Messages.setLanguageText(item, view.getData());
		item.setData("IView", view);
		tabViews.add(view);
	
public voidcompletionChanged(org.gudy.azureus2.core3.download.DownloadManager manager, boolean bCompleted)

  
public voiddataSourceChanged(java.lang.Object newDataSource)

  	super.dataSourceChanged(newDataSource);

    if (manager != null) {
    	manager.removeListener(this);
    }

  	DownloadImpl dataSourcePlugin = null;
  	if (newDataSource instanceof DownloadImpl) {
  		dataSourcePlugin = (DownloadImpl) newDataSource;
  		manager = dataSourcePlugin.getDownload();
  	} else if (newDataSource instanceof DownloadManager) {
    	manager = (DownloadManager) newDataSource;
      try {
      	dataSourcePlugin = DownloadManagerImpl.getDownloadStatic(manager);
      } catch (DownloadException e) { /* Ignore */ }
  	} else {
  		manager = null;
  	}
  	
    if (manager != null) {
    	manager.addListener(this);
    }

		for (int i = 0; i < tabViews.size(); i++) {
			IView view = (IView) tabViews.get(i);
			if (view != null) {
				if (view instanceof UISWTViewImpl) {
					((UISWTViewImpl) view).dataSourceChanged(dataSourcePlugin);
				} else {
					view.dataSourceChanged(newDataSource);
				}
			}
		}
  
public voiddelete()

  	UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
  	if (uiFunctions != null) {
  		uiFunctions.removeManagerView(manager);
  	}
  	if (manager != null) {
  		manager.removeListener(this);
  	}
    
    if ( !folder.isDisposed()){
    	
    	folder.setSelection(0);
    }
    
    //Don't ask me why, but without this an exception is thrown further
    // (in folder.dispose() )
    //TODO : Investigate to see if it's a platform (OSX-Carbon) BUG, and report to SWT team.
    if(Constants.isOSX) {
      if(folder != null && !folder.isDisposed()) {
        TabItem[] items = folder.getItems();
        for(int i=0 ; i < items.length ; i++) {
          if (!items[i].isDisposed())
            items[i].dispose();
        }
      }
    }

    for (int i = 0; i < tabViews.size(); i++) {
    	IView view = (IView) tabViews.get(i);
    	if (view != null)
    		view.delete();
    }
    tabViews.clear();

    if (folder != null && !folder.isDisposed()) {
      folder.dispose();
    }
  
public voiddownloadComplete(org.gudy.azureus2.core3.download.DownloadManager manager)

   
  
protected static java.lang.StringescapeAccelerators(java.lang.String str)

	  if ( str == null ){
		  
		  return( str );
	  }
	  
	  return( str.replaceAll( "&", "&&" ));
  
public voidfilePriorityChanged(org.gudy.azureus2.core3.download.DownloadManager download, org.gudy.azureus2.core3.disk.DiskManagerFileInfo file)

	  
  
private IViewgetActiveView()

		int index = folder.getSelectionIndex();
		if (index == -1) {
			return null;
		}

		TabItem ti = folder.getItem(index);
		if (ti.isDisposed()) {
			return null;
		}

		return (IView) ti.getData("IView");
  
public CompositegetComposite()

    return folder;
  
public org.gudy.azureus2.core3.download.DownloadManagergetDownload()

return manager;
public java.lang.StringgetFullTitle()

    int completed = manager.getStats().getCompleted();
    return DisplayFormatters.formatPercentFromThousands(completed) + " : " + manager.getDisplayName();
  
public java.lang.StringgetObfusticatedHeader()

    int completed = manager.getStats().getCompleted();
    return DisplayFormatters.formatPercentFromThousands(completed) + " : " + manager;
	
public voidinitialize(Composite composite)


  	if (folder == null) {
			folder = new TabFolder(composite, SWT.LEFT);
		} else {
			System.out.println("ManagerView::initialize : folder isn't null !!!");
		}
  	
	  IView views[] = { new GeneralView(), new PeersView(),
			new PeersGraphicView(), new PiecesView(), new FilesView(), new TorrentInfoView( manager ),
			new TorrentOptionsView( manager ), new LoggerView() };

		for (int i = 0; i < views.length; i++)
			addSection(views[i], manager);

    // Call plugin listeners
		UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
		if (uiFunctions != null) {
			UISWTInstanceImpl pluginUI = uiFunctions.getSWTPluginInstanceImpl();
			Map pluginViews = pluginUI == null ? null
					: pluginUI.getViewListeners(UISWTInstance.VIEW_MYTORRENTS);
			if (pluginViews != null) {
				String[] sNames = (String[]) pluginViews.keySet().toArray(new String[0]);
				for (int i = 0; i < sNames.length; i++) {
					UISWTViewEventListener l = (UISWTViewEventListener) pluginViews.get(sNames[i]);
					if (l != null) {
						try {
							UISWTViewImpl view = new UISWTViewImpl(
									UISWTInstance.VIEW_MYTORRENTS, sNames[i], l);
							addSection(view);
						} catch (Exception e) {
							// skip
						}
					}
				}
			}
		}
		
    
    // Initialize view when user selects it
    folder.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent e) {
        TabItem item = (TabItem)e.item;
        if (item != null && item.getControl() == null) {
        	IView view = (IView)item.getData("IView");
        	
        	view.initialize(folder);
        	item.setControl(view.getComposite());
        }
        refresh();
      }
    });
    
    
    views[0].initialize(folder);
    folder.getItem(0).setControl(views[0].getComposite());
    views[0].refresh();
    views[0].getComposite().layout(true);
  
public booleanisEnabled(java.lang.String itemKey)

		if (itemKey.equals("run"))
			return true;

		if (itemKey.equals("start"))
			return ManagerUtils.isStartable(manager);

		if (itemKey.equals("stop"))
			return ManagerUtils.isStopable(manager);

		if (itemKey.equals("host"))
			return true;
		
		if (itemKey.equals("publish"))
			return true;

		if (itemKey.equals("remove"))
			return true;
		
		return false;
	
public voiditemActivated(java.lang.String itemKey)

		if (itemKey.equals("run")) {
			ManagerUtils.run(manager);
			return;
		}
		
		if (itemKey.equals("start")) {
			ManagerUtils.queue(manager, folder.getShell());
			return;
		}
		
		if (itemKey.equals("stop")) {
			ManagerUtils.stop(manager, folder.getShell());
			return;
		}
		
		if (itemKey.equals("host")) {
			ManagerUtils.host(azureus_core, manager, folder);
			UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
			if (uiFunctions != null) {
				uiFunctions.showMyTracker();
			}
			return;
		}
		
		if (itemKey.equals("publish")) {
			ManagerUtils.publish(azureus_core, manager, folder);
			UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
			if (uiFunctions != null) {
				uiFunctions.showMyTracker();
			}
			return;
		}
		
		if (itemKey.equals("remove")) {
			ManagerUtils.remove(manager, null, false, false);
		}
	
public org.eclipse.swt.graphics.ImageobfusticatedImage(org.eclipse.swt.graphics.Image image, org.eclipse.swt.graphics.Point shellOffset)

		IView view = getActiveView();
		if (view instanceof ObfusticateImage) {
			try {
				((ObfusticateImage)view).obfusticatedImage(image, shellOffset);
			} catch (Exception e) {
				Debug.out("Obfusticating " + view, e);
			}
		}
		return image;
	
public voidpositionChanged(org.gudy.azureus2.core3.download.DownloadManager download, int oldPosition, int newPosition)

  
public voidrefresh()

		if (getComposite() == null || getComposite().isDisposed())
			return;

		try {
			IView view = getActiveView();
			if (view != null)
				view.refresh();

			TabItem[] items = folder.getItems();
			
	    for (int i = 0; i < items.length; i++) {
	    	TabItem item = items[i];
	    	view = (IView) item.getData("IView");
        try {
          if (item.isDisposed())
            continue;
          String lastTitle = item.getText();
          String newTitle = view.getShortTitle();
          if (lastTitle == null || !lastTitle.equals(newTitle)) {
            item.setText(escapeAccelerators(newTitle));
          }
          String lastToolTip = item.getToolTipText();
          String newToolTip = view.getFullTitle() + " " +
					 MessageText.getString("Tab.closeHint");
          if (lastToolTip == null || !lastToolTip.equals(newToolTip)) {
            item.setToolTipText(newToolTip);
          }
        }
        catch (Exception e){
        	Debug.printStackTrace(e);
        }
      }
		} catch (Exception e) {
			Debug.printStackTrace(e);
		}
	
public voidstateChanged(org.gudy.azureus2.core3.download.DownloadManager manager, int state)

    if(folder == null || folder.isDisposed())
      return;    
    Display display = folder.getDisplay();
    if(display == null || display.isDisposed())
      return;
    Utils.execSWTThread(new AERunnable() {
	    public void runSupport() {
				UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
				if (uiFunctions != null) {
					uiFunctions.refreshIconBar();
				}
	    }
    });