FileDocCategorySizeDatePackage
IPWFilePanel.javaAPI DocAzureus 3.0.3.44993Fri Aug 31 16:33:30 BST 2007org.gudy.azureus2.ui.swt.pluginsinstaller

IPWFilePanel

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

Fields Summary
org.eclipse.swt.widgets.Text
txtFile
boolean
valid
Constructors Summary
public IPWFilePanel(org.gudy.azureus2.ui.swt.wizard.Wizard wizard, org.gudy.azureus2.ui.swt.wizard.IWizardPanel previous)

  
   
       
        
    super(wizard,previous);
  
Methods Summary
private voidcheckValidFile()

    String fileName = txtFile.getText();
    String error_message = null;
    try {
      File f = new File(fileName);
      if(f.isFile() && (f.getName().endsWith(".jar") || f.getName().endsWith(".zip")) ) {
        wizard.setErrorMessage("");
        wizard.setNextEnabled(true);
        List list = new ArrayList();
        InstallablePlugin plugin = wizard.getAzureusCore().getPluginManager().getPluginInstaller().installFromFile(f);
        list.add(plugin);
        ((InstallPluginWizard)wizard).plugins = list;
        valid = true;
        return;
      }
    } catch (org.gudy.azureus2.plugins.PluginException e) {
    	error_message = e.getMessage();
    	Debug.printStackTrace(e);
    } catch(Exception e) {    
    	error_message = null;
    	Debug.printStackTrace(e);
    }
    valid = false;
    if (!fileName.equals("")) {
    	String error_message_full;
    	if (new File(fileName).isFile()) {
    		error_message_full = MessageText.getString("installPluginsWizard.file.invalidfile");
    	}
    	else {
    		error_message_full = MessageText.getString("installPluginsWizard.file.no_such_file");
    	}
    	if (error_message != null) {error_message_full += " (" + error_message + ")";}
    	wizard.setErrorMessage(error_message_full);
    	wizard.setNextEnabled(false);
    }
  
public org.gudy.azureus2.ui.swt.wizard.IWizardPanelgetNextPanel()

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

	   return valid;
	
public voidshow()

    wizard.setTitle(MessageText.getString("installPluginsWizard.file.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 = 3;
	panel.setLayout(layout);
	
	Label label = new Label(panel,SWT.NULL);
	Messages.setLanguageText(label,"installPluginsWizard.file.file");
	
	txtFile = new Text(panel,SWT.BORDER);
	GridData data = new GridData(GridData.FILL_HORIZONTAL);
	txtFile.setLayoutData(data);
	txtFile.addListener(SWT.Modify,new Listener() {
	  public void handleEvent(Event event) {
	    checkValidFile();
	  }
	}
	);
	
	
	Button btnBrowse = new Button(panel,SWT.PUSH);
	Messages.setLanguageText(btnBrowse,"installPluginsWizard.file.browse");
	btnBrowse.addListener(SWT.Selection,new Listener() {
	  public void handleEvent(Event event) {
	    FileDialog fd = new FileDialog(wizard.getWizardWindow());
	    fd.setFilterExtensions(new String[] {"*.zip;*.jar"});
	    fd.setFilterNames(new String[] {"Azureus Plugins"});
	    String fileName = fd.open();
	    if(fileName != null) txtFile.setText(fileName);	    
	  }
	});	
	
	checkValidFile();