@Override
public void install(Component component) {
super.install(component);
final FileBrowserSheet fileBrowserSheet = (FileBrowserSheet)component;
final FileBrowserSheet.Mode mode = fileBrowserSheet.getMode();
// Load the sheet content
Resources resources;
try {
resources = new Resources(getClass().getName());
} catch (IOException exception) {
throw new RuntimeException(exception);
} catch (SerializationException exception) {
throw new RuntimeException(exception);
}
WTKXSerializer wtkxSerializer = new WTKXSerializer(resources);
Component content;
try {
content = (Component)wtkxSerializer.readObject(this, "terra_file_browser_sheet_skin.wtkx");
} catch (IOException exception) {
throw new RuntimeException(exception);
} catch (SerializationException exception) {
throw new RuntimeException(exception);
}
fileBrowserSheet.setContent(content);
wtkxSerializer.bind(this, TerraFileBrowserSheetSkin.class);
saveAsTextInput.getTextInputTextListeners().add(new TextInputTextListener() {
@Override
public void textChanged(TextInput textInput) {
updateOKButtonState();
}
});
fileBrowser.getStyles().put("keyboardFolderTraversalEnabled",
(mode != FileBrowserSheet.Mode.SAVE_TO));
fileBrowser.getFileBrowserListeners().add(new FileBrowserListener.Adapter() {
@Override
public void rootDirectoryChanged(FileBrowser fileBrowser,
File previousRootDirectory) {
updatingSelection = true;
fileBrowserSheet.setRootDirectory(fileBrowser.getRootDirectory());
updatingSelection = false;
selectedDirectoryCount = 0;
updateOKButtonState();
}
@Override
public void selectedFileAdded(FileBrowser fileBrowser, File file) {
if (file.isDirectory()) {
selectedDirectoryCount++;
}
updateOKButtonState();
}
@Override
public void selectedFileRemoved(FileBrowser fileBrowser, File file) {
if (file.isDirectory()) {
selectedDirectoryCount--;
}
updateOKButtonState();
}
@Override
public void selectedFilesChanged(FileBrowser fileBrowser,
Sequence<File> previousSelectedFiles) {
selectedDirectoryCount = 0;
Sequence<File> selectedFiles = fileBrowser.getSelectedFiles();
for (int i = 0, n = selectedFiles.getLength(); i < n; i++) {
File selectedFile = selectedFiles.get(i);
if (selectedFile.isDirectory()) {
selectedDirectoryCount++;
}
}
if (!fileBrowser.isMultiSelect()) {
File selectedFile = fileBrowser.getSelectedFile();
if (selectedFile == null) {
saveAsTextInput.setText("");
} else if (!selectedFile.isDirectory()) {
saveAsTextInput.setText(selectedFile.getName());
}
}
updateOKButtonState();
}
});
fileBrowser.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener.Adapter() {
private File file = null;
@Override
public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
boolean consumed = super.mouseClick(component, button, x, y, count);
if (count == 1) {
file = fileBrowser.getFileAt(x, y);
} else if (count == 2) {
File file = fileBrowser.getFileAt(x, y);
if (file != null
&& this.file != null
&& file.equals(this.file)
&& fileBrowser.isFileSelected(file)) {
if (mode == FileBrowserSheet.Mode.OPEN
|| mode == FileBrowserSheet.Mode.OPEN_MULTIPLE) {
if (!file.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);
// Initialize layout and file browser selection state
switch (mode) {
case OPEN: {
saveAsBoxPane.setVisible(false);