FileDocCategorySizeDatePackage
IPWListPanel.javaAPI DocAzureus 3.0.3.48238Mon Jul 02 14:00:28 BST 2007org.gudy.azureus2.ui.swt.pluginsinstaller

IPWListPanel

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

Fields Summary
org.eclipse.swt.widgets.Table
pluginList
org.gudy.azureus2.ui.swt.components.LinkArea
link_area
Constructors Summary
public IPWListPanel(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.IWizardPanelgetNextPanel()

    return new IPWInstallModePanel(wizard,this);
  
public booleanisNextEnabled()

		return(((InstallPluginWizard)wizard).getPluginList().size() > 0 );
	
protected voidloadPluginDetails(org.eclipse.swt.widgets.TableItem selected_item)

  		link_area.reset();
  		
	    link_area.addLine( MessageText.getString( "installPluginsWizard.details.loading"));
	   
	      final StandardPlugin plugin = (StandardPlugin) selected_item.getData();
	      
	      
	      AEThread detailsLoader = new AEThread("Detail Loader") {
	        public void runSupport() {	         
	         final String description = HTMLUtils.convertListToString(HTMLUtils.convertHTMLToText(plugin.getDescription(),""));
	         wizard.getDisplay().asyncExec(new AERunnable() {
			      public void runSupport() {
			        if(pluginList == null || pluginList.isDisposed() || pluginList.getSelectionCount() ==0)
			          return;
			        if(pluginList.getSelection()[0] != selected_item)
			          return;
			     
			        link_area.reset();
			        
			        link_area.setRelativeURLBase( plugin.getRelativeURLBase());
			        
			        link_area.addLine(description);
			      }
		      	});
	        }
	      };
	      
	      detailsLoader.setDaemon(true);
	      detailsLoader.start();
  	
public voidshow()

    wizard.setTitle(MessageText.getString("installPluginsWizard.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);
	GridData data = new GridData(GridData.FILL_HORIZONTAL);
	lblStatus.setLayoutData(data);
	Messages.setLanguageText(lblStatus,"installPluginsWizard.list.loading");
	
	pluginList = new Table(panel,SWT.BORDER | SWT.V_SCROLL | SWT.CHECK | SWT.FULL_SELECTION | SWT.SINGLE); 
	pluginList.setHeaderVisible(true);
	data = new GridData(GridData.FILL_HORIZONTAL);
	data.heightHint = 120;
	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);
		
	
	Label lblDescription = new Label(panel,SWT.NULL);
	Messages.setLanguageText(lblDescription,"installPluginsWizard.list.description");
	
	link_area = new LinkArea( panel );
	
	data = new GridData(GridData.FILL_HORIZONTAL);
	data.heightHint = 100;
	link_area.getComponent().setLayoutData(data);

	AEThread listLoader = new AEThread("Plugin List Loader") {
	  public void runSupport() {
	    final StandardPlugin plugins[];
	    try {
	      plugins = ((InstallPluginWizard)wizard).getStandardPlugins();
	      
	      Arrays.sort( 
	      	plugins,
		  	new Comparator()
			{
	      		public int 
				compare(
					Object o1, 
					Object o2)
	      		{
	      			return(((StandardPlugin)o1).getName().compareToIgnoreCase(((StandardPlugin)o2).getName()));
	      		}
			});
			
	    } catch(final Exception e) {
	    	
	    	Debug.printStackTrace(e);
		    wizard.getDisplay().asyncExec(new AERunnable() {
			      public void runSupport() {
			      	link_area.addLine( Debug.getNestedExceptionMessage(e));
			      }
		    });
		    
	    	return;
	    }
	    
	    wizard.getDisplay().asyncExec(new AERunnable() {
	      public void runSupport() {
	       
	        lblStatus.setText( ((InstallPluginWizard)wizard).getListTitleText());
	        
	        List	selected_plugins = ((InstallPluginWizard)wizard).getPluginList();

	        for(int i = 0 ; i < plugins.length ; i++) {
	          StandardPlugin plugin = plugins[i];
	          if(plugin.getAlreadyInstalledPlugin() == null) {
	            if(pluginList == null || pluginList.isDisposed())
	              return;
	            TableItem item = new TableItem(pluginList,SWT.NULL);
	            item.setData(plugin);
	            item.setText(0,plugin.getName());
	            boolean	selected = false;
	            for (int j=0;j<selected_plugins.size();j++){
	            	if (((StandardPlugin)selected_plugins.get(j)).getId() == plugin.getId()){
	            		selected = true;
	            	}
	            }
	            item.setChecked( selected );
	            item.setText(1,plugin.getVersion());
	          }
	        }
	        
	        	// if there's only one entry then we might as well pull it in (this is really to
	        	// support explicit install directions in the wizard as opposed to selection from
	        	// the SF list )
	        
	        if ( plugins.length == 1 && pluginList.getItemCount() > 0 ){
	        	
	        	pluginList.select(0);
	        	
	        	loadPluginDetails( pluginList.getItem(0));
	        }
	      }
	    });
	  }
	};
	
	listLoader.setDaemon(true);
	
	listLoader.start();
	
	
	pluginList.addListener(SWT.Selection,new Listener() {
	  public void handleEvent(Event e) {
	    if(pluginList.getSelectionCount() > 0) {
	    	loadPluginDetails( pluginList.getSelection()[0]);

	    }
	    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());
      }
    }
    ((InstallPluginWizard)wizard).setPluginList(list);
    ((InstallPluginWizard)wizard).setNextEnabled( isNextEnabled() );