@Override
public void install(Component component) {
super.install(component);
final FileBrowserSheet fileBrowserSheet = (FileBrowserSheet)component;
fileBrowserSheet.setMinimumWidth(360);
fileBrowserSheet.setMinimumHeight(180);
// Load the sheet content
BXMLSerializer bxmlSerializer = new BXMLSerializer();
Component content;
try {
content = (Component)bxmlSerializer.readObject(TerraFileBrowserSheetSkin.class,
"terra_file_browser_sheet_skin.bxml", true);
} catch (IOException exception) {
throw new RuntimeException(exception);
} catch (SerializationException exception) {
throw new RuntimeException(exception);
}
fileBrowserSheet.setContent(content);
bxmlSerializer.bind(this, TerraFileBrowserSheetSkin.class);
// set the same rootDirectory to fileBrowser
fileBrowser.setRootDirectory(fileBrowserSheet.getRootDirectory());
saveAsTextInput.getTextInputContentListeners().add(new TextInputContentListener.Adapter() {
@Override
public void textChanged(TextInput textInput) {
Form.clearFlag(saveAsBoxPane);
updateOKButtonState();
}
});
fileBrowser.getFileBrowserListeners().add(new FileBrowserListener.Adapter() {
@Override
public void rootDirectoryChanged(FileBrowser fileBrowserArgument,
File previousRootDirectory) {
updatingSelection = true;
fileBrowserSheet.setRootDirectory(fileBrowserArgument.getRootDirectory());
updatingSelection = false;
selectedDirectoryCount = 0;
updateOKButtonState();
}
@Override
public void selectedFileAdded(FileBrowser fileBrowserArgument, File file) {
if (file.isDirectory()) {
selectedDirectoryCount++;
}
updateOKButtonState();
}
@Override
public void selectedFileRemoved(FileBrowser fileBrowserArgument, File file) {
if (file.isDirectory()) {
selectedDirectoryCount--;
}
updateOKButtonState();
}
@Override
public void selectedFilesChanged(FileBrowser fileBrowserArgument,
Sequence<File> previousSelectedFiles) {
selectedDirectoryCount = 0;
Sequence<File> selectedFiles = fileBrowserArgument.getSelectedFiles();
for (int i = 0, n = selectedFiles.getLength(); i < n; i++) {
File selectedFile = selectedFiles.get(i);
if (selectedFile.isDirectory()) {
selectedDirectoryCount++;
}
}
if (!fileBrowserArgument.isMultiSelect()) {
File selectedFile = fileBrowserArgument.getSelectedFile();
if (selectedFile != null
&& !selectedFile.isDirectory()) {
saveAsTextInput.setText(selectedFile.getName());
}
}
updateOKButtonState();
}
});
fileBrowser.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener.Adapter() {
private File file = null;
@Override
public boolean mouseClick(Component componentArgument, Mouse.Button button, int x, int y, int count) {
boolean consumed = super.mouseClick(componentArgument, button, x, y, count);
FileBrowserSheet.Mode mode = fileBrowserSheet.getMode();
if (count == 1) {
file = fileBrowser.getFileAt(x, y);
} else if (count == 2) {
File fileLocal = fileBrowser.getFileAt(x, y);
if (fileLocal != null
&& this.file != null
&& fileLocal.equals(this.file)
&& fileBrowser.isFileSelected(fileLocal)) {
if (mode == FileBrowserSheet.Mode.OPEN
|| mode == FileBrowserSheet.Mode.OPEN_MULTIPLE) {
if (!fileLocal.isDirectory()) {
fileBrowserSheet.close(true);
consumed = true;
}
}
}
}
return consumed;
}
});
okButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
fileBrowserSheet.close(true);
}
});
cancelButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
fileBrowserSheet.close(false);
}
});
// Add this as a file browser sheet listener
fileBrowserSheet.getFileBrowserSheetListeners().add(this);
modeChanged(fileBrowserSheet, null);
rootDirectoryChanged(fileBrowserSheet, null);
selectedFilesChanged(fileBrowserSheet, null);
}