final TextBox fileTextBox = new TextBox();
fileTextBox.setHeight( "26px" );
fileTextBox.setEnabled( false );
//We use an fileNameOverride because FileUpload can only handle US character set reliably.
final Hidden fileNameOverride = new Hidden( "fileNameOverride" );
final FileUpload upload = new FileUpload();
upload.setName( "fileUpload" );
ChangeHandler fileUploadHandler = new ChangeHandler() {
@Override
public void onChange( ChangeEvent event ) {
fileTextBox.setText( upload.getFilename() );
if ( !"".equals( importDir.getValue() ) ) {
//Set the fileNameOverride because the fileUpload object can only reliably transmit US-ASCII
//character set. See RFC283 section 2.3 for details
String fileNameValue = upload.getFilename().replaceAll( "\\\\", "/" );
fileNameValue = fileNameValue.substring( fileNameValue.lastIndexOf( "/" ) + 1 );
fileNameOverride.setValue( fileNameValue );
okButton.setEnabled( true );
} else {
okButton.setEnabled( false );
}
}
};
upload.addChangeHandler( fileUploadHandler );
upload.setVisible( false );
HorizontalPanel fileUploadPanel = new HorizontalPanel();
fileUploadPanel.add( fileTextBox );
fileUploadPanel.add( new HTML( " " ) );
Button browseButton = new Button( Messages.getString( "browse" ) + "..." );
browseButton.setStyleName( "pentaho-button" );
fileUploadPanel.add( browseButton );
browseButton.addClickHandler( new ClickHandler() {
@Override
public void onClick( ClickEvent event ) {
setRetainOwnershipState();
jsClickUpload( upload.getElement() );
}
} );
rootPanel.add( fileUploadPanel );
rootPanel.add( upload );
applyAclPermissions.setName( "applyAclPermissions" );
applyAclPermissions.setValue( Boolean.FALSE );
applyAclPermissions.setFormValue( "false" );
applyAclPermissions.setEnabled( true );
applyAclPermissions.setVisible( false );
final CheckBox overwriteAclPermissions = new CheckBox( Messages.getString( "overwriteAclPermissions" ), true );
overwriteAclPermissions.setName( "overwriteAclPermissions" );
applyAclPermissions.setValue( Boolean.FALSE );
applyAclPermissions.setFormValue( "false" );
overwriteAclPermissions.setEnabled( true );
overwriteAclPermissions.setVisible( false );
final Hidden overwriteFile = new Hidden( "overwriteFile" );
overwriteFile.setValue( "true" );
final Hidden logLevel = new Hidden( "logLevel" );
logLevel.setValue( "ERROR" );
final Hidden retainOwnership = new Hidden( "retainOwnership" );
retainOwnership.setValue( "true" );
rootPanel.add( applyAclPermissions );
rootPanel.add( overwriteAclPermissions );
rootPanel.add( overwriteFile );
rootPanel.add( logLevel );
rootPanel.add( retainOwnership );
rootPanel.add( fileNameOverride );
spacer = new VerticalPanel();
spacer.setHeight( "4px" );
rootPanel.add( spacer );
DisclosurePanel disclosurePanel = new DisclosurePanel( Messages.getString( "advancedOptions" ) );
disclosurePanel.getHeader().setStyleName( "gwt-Label" );
HorizontalPanel mainPanel = new HorizontalPanel();
mainPanel.add( new HTML( " " ) );
VerticalPanel disclosureContent = new VerticalPanel();
HTML replaceLabel = new HTML( Messages.getString( "fileExists" ) );
replaceLabel.setStyleName( "gwt-Label" );
disclosureContent.add( replaceLabel );
final CustomListBox overwriteFileDropDown = new CustomListBox();
final CustomListBox filePermissionsDropDown = new CustomListBox();
DefaultListItem replaceListItem = new DefaultListItem( Messages.getString( "replaceFile" ) );
replaceListItem.setValue( "true" );
overwriteFileDropDown.addItem( replaceListItem );
DefaultListItem doNotImportListItem = new DefaultListItem( Messages.getString( "doNotImport" ) );
doNotImportListItem.setValue( "false" );
overwriteFileDropDown.addItem( doNotImportListItem );
overwriteFileDropDown.setVisibleRowCount( 1 );
disclosureContent.add( overwriteFileDropDown );
spacer = new VerticalPanel();
spacer.setHeight( "4px" );
disclosureContent.add( spacer );
HTML filePermissionsLabel = new HTML( Messages.getString( "filePermissions" ) );
filePermissionsLabel.setStyleName( "gwt-Label" );
disclosureContent.add( filePermissionsLabel );
DefaultListItem usePermissionsListItem = new DefaultListItem( Messages.getString( "usePermissions" ) );
usePermissionsListItem.setValue( "false" );
filePermissionsDropDown.addItem( usePermissionsListItem ); // If selected set "overwriteAclPermissions" to
// false.
DefaultListItem retainPermissionsListItem = new DefaultListItem( Messages.getString( "retainPermissions" ) );
retainPermissionsListItem.setValue( "true" );
filePermissionsDropDown.addItem( retainPermissionsListItem ); // If selected set "overwriteAclPermissions" to
// true.
final ChangeListener filePermissionsHandler = new ChangeListener() {
@Override
public void onChange( Widget sender ) {
String value = filePermissionsDropDown.getSelectedItem().getValue().toString();
applyAclPermissions.setValue( Boolean.valueOf( value ) );
applyAclPermissions.setFormValue( value );
overwriteAclPermissions.setFormValue( value );
overwriteAclPermissions.setValue( Boolean.valueOf( value ) );
setRetainOwnershipState();
}
};
filePermissionsDropDown.addChangeListener( filePermissionsHandler );
filePermissionsDropDown.setVisibleRowCount( 1 );
disclosureContent.add( filePermissionsDropDown );
spacer = new VerticalPanel();
spacer.setHeight( "4px" );
disclosureContent.add( spacer );
HTML fileOwnershipLabel = new HTML( Messages.getString( "fileOwnership" ) );
fileOwnershipLabel.setStyleName( "gwt-Label" );
disclosureContent.add( fileOwnershipLabel );
retainOwnershipDropDown.addChangeListener( new ChangeListener() {
@Override
public void onChange( Widget sender ) {
String value = retainOwnershipDropDown.getSelectedItem().getValue().toString();
retainOwnership.setValue( value );
}
} );
DefaultListItem keepOwnershipListItem = new DefaultListItem( Messages.getString( "keepOwnership" ) );
keepOwnershipListItem.setValue( "true" );
retainOwnershipDropDown.addItem( keepOwnershipListItem );