FileDocCategorySizeDatePackage
UIPWListPanel.javaAPI DocAzureus 3.0.3.46690Thu Feb 09 19:42:48 GMT 2006org.gudy.azureus2.ui.swt.pluginsuninstaller

UIPWListPanel

public class UIPWListPanel extends org.gudy.azureus2.ui.swt.wizard.AbstractWizardPanel
author
Olivier Chalouhi

Fields Summary
org.eclipse.swt.widgets.Table
pluginList
Constructors Summary
public UIPWListPanel(org.gudy.azureus2.ui.swt.wizard.Wizard wizard, org.gudy.azureus2.ui.swt.wizard.IWizardPanel previous)

	super(wizard, previous);
  
Methods Summary
public org.gudy.azureus2.ui.swt.wizard.IWizardPanelgetFinishPanel()

	    return new UIPWFinishPanel(wizard,this);
	
public booleanisFinishEnabled()

		return(((UnInstallPluginWizard)wizard).getPluginList().size() > 0 );
	
public voidshow()

    wizard.setTitle(MessageText.getString("uninstallPluginsWizard.list.title"));
    wizard.setErrorMessage("");
    
	Composite rootPanel = wizard.getPanel();
	GridLayout layout = new GridLayout();
	layout.numColumns = 1;
	rootPanel.setLayout(layout);

	Composite panel = new Composite(rootPanel, SWT.NULL);
	GridData gridData = new GridData(GridData.VERTICAL_ALIGN_CENTER | GridData.FILL_HORIZONTAL);
	panel.setLayoutData(gridData);
	layout = new GridLayout();
	layout.numColumns = 1;
	panel.setLayout(layout);
	
	final Label lblStatus = new Label(panel,SWT.NULL);
	Messages.setLanguageText(lblStatus,"uninstallPluginsWizard.list.loaded");
	
	pluginList = new Table(panel,SWT.BORDER | SWT.V_SCROLL | SWT.CHECK | SWT.FULL_SELECTION | SWT.SINGLE); 
	pluginList.setHeaderVisible(true);
	GridData data = new GridData(GridData.FILL_HORIZONTAL);
	data.heightHint = 200;
	pluginList.setLayoutData(data);
	
	
	TableColumn tcName = new TableColumn(pluginList,SWT.LEFT);
	Messages.setLanguageText(tcName,"installPluginsWizard.list.name");
	tcName.setWidth(200);
	
	TableColumn tcVersion = new TableColumn(pluginList,SWT.LEFT);
	Messages.setLanguageText(tcVersion,"installPluginsWizard.list.version");
	tcVersion.setWidth(150);

    PluginInterface plugins[] = new PluginInterface[0];
    try {
      plugins = wizard.getAzureusCore().getPluginManager().getPluginInterfaces();
      
      Arrays.sort( 
	      	plugins,
		  	new Comparator()
			{
	      		public int 
				compare(
					Object o1, 
					Object o2)
	      		{
	      			return(((PluginInterface)o1).getPluginName().compareTo(((PluginInterface)o2).getPluginName()));
	      		}
			});
    } catch(final Exception e) {
    	
    	Debug.printStackTrace(e);
    }
     
    	// one "plugin" can have multiple interfaces. We need to group by their id
    
    Map	pid_map = new HashMap();
    
    for(int i = 0 ; i < plugins.length ; i++){
    	
        PluginInterface plugin = plugins[i];
                
        String	pid   = plugin.getPluginID();
        
        ArrayList	pis = (ArrayList)pid_map.get( pid );
        
        if ( pis == null ){
        	
        	pis = new ArrayList();
        	
        	pid_map.put( pid, pis );
        }
        
        pis.add( plugin );
    }
    
    ArrayList[]	pid_list = new ArrayList[pid_map.size()];
    
    pid_map.values().toArray( pid_list );
	
    Arrays.sort( 
    		pid_list,
		  	new Comparator()
			{
	      		public int 
				compare(
					Object o1, 
					Object o2)
	      		{
	      			ArrayList	l1 = (ArrayList)o1;
	      			ArrayList	l2 = (ArrayList)o2;
	      			
	      			return(((PluginInterface)l1.get(0)).getPluginName().compareTo(((PluginInterface)l2.get(0)).getPluginName()));
	      		}
			});
    
    for(int i = 0 ; i < pid_list.length ; i++){
    	
      ArrayList	pis = pid_list[i];
      
      boolean	skip = false;
      
      String	display_name = "";
      	
      for (int j=0;j<pis.size();j++){
      	
      	PluginInterface	pi = (PluginInterface)pis.get(j);
      	
      	if ( pi.isMandatory() || pi.isBuiltIn()){
      		
      		skip = true;
      		
      		break;
      	}
      	
      	display_name += (j==0?"":",") + pi.getPluginName();
      }
      
      if ( skip ){
      	
      	continue;
      }
      
      PluginInterface plugin = (PluginInterface)pis.get(0);
      
      List	selected_plugins = ((UnInstallPluginWizard)wizard).getPluginList();
      
      TableItem item = new TableItem(pluginList,SWT.NULL);
      item.setData(plugin);
      item.setText(0, display_name);
      item.setChecked( selected_plugins.contains( plugin ));
      String version = plugin.getPluginVersion();
      if(version == null) version = MessageText.getString("installPluginsWizard.list.nullversion");
      item.setText(1,version);
    }
	
	pluginList.addListener(SWT.Selection,new Listener() {
	  public void handleEvent(Event e) {
	    updateList();	  
	  }
	});
  
public voidupdateList()

    ArrayList list = new ArrayList();
    TableItem[] items = pluginList.getItems();
    for(int i = 0 ; i < items.length ; i++) {
      if(items[i].getChecked())
        list.add(items[i].getData());          
    }
    ((UnInstallPluginWizard)wizard).setPluginList(list);
    ((UnInstallPluginWizard)wizard).setFinishEnabled( isFinishEnabled() );