wizard.setTitle(MessageText.getString("wizard.singlefile"));
wizard.setCurrentInfo(MessageText.getString("wizard.choosefile"));
Composite panel = wizard.getPanel();
GridLayout layout = new GridLayout();
layout.numColumns = 3;
panel.setLayout(layout);
Label label = new Label(panel, SWT.NULL);
Messages.setLanguageText(label, "wizard.file");
file = new Text(panel, SWT.BORDER);
file.addModifyListener(new ModifyListener() {
/*
* (non-Javadoc)
*
* @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
*/
public void modifyText(ModifyEvent arg0) {
String fName = file.getText();
((NewTorrentWizard) wizard).singlePath = fName;
String error = "";
if (!fName.equals("")) {
File f = new File(file.getText());
if (!f.exists() || f.isDirectory()) {
error = MessageText.getString("wizard.invalidfile");
}else{
String parent = f.getParent();
if ( parent != null ){
((NewTorrentWizard) wizard).setDefaultOpenDir( parent );
}
}
}
wizard.setErrorMessage(error);
wizard.setNextEnabled(!((NewTorrentWizard) wizard).singlePath.equals("") && error.equals(""));
}
});
file.setText(((NewTorrentWizard) wizard).singlePath);
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
file.setLayoutData(gridData);
Button browse = new Button(panel, SWT.PUSH);
browse.addListener(SWT.Selection, new Listener() {
/*
* (non-Javadoc)
*
* @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
*/
public void handleEvent(Event arg0) {
FileDialog fd = new FileDialog(wizard.getWizardWindow());
if (wizard.getErrorMessage().equals("") && !((NewTorrentWizard) wizard).singlePath.equals("")) {
fd.setFileName(((NewTorrentWizard) wizard).singlePath);
}else{
String def = ((NewTorrentWizard) wizard).getDefaultOpenDir();
if ( def.length() > 0 & new File(def).isDirectory() ){
fd.setFilterPath( def );
}
}
String f = fd.open();
if (f != null){
file.setText(f);
File ff = new File(f);
String parent = ff.getParent();
if ( parent != null ){
((NewTorrentWizard) wizard).setDefaultOpenDir( parent );
}
}
}
});
Messages.setLanguageText(browse, "wizard.browse");
label = new Label(panel, SWT.NULL);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 3;
label.setLayoutData(gridData);
label.setText("\n");
label = new Label(panel, SWT.NULL);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 3;
label.setLayoutData(gridData);
label.setForeground(Colors.blue);
Messages.setLanguageText(label, "wizard.hint.file");