use of org.apache.pivot.wtk.VFSBrowserSheet in project pivot by apache.
the class TerraVFSBrowserSheetSkin method previewSheetClose.
@Override
public Vote previewSheetClose(final Sheet sheet, final boolean result) {
Vote vote = null;
if (result && !okButton.isEnabled()) {
vote = Vote.DENY;
} else {
if (result) {
updatingSelection = true;
VFSBrowserSheet fileBrowserSheet = (VFSBrowserSheet) sheet;
VFSBrowserSheet.Mode mode = fileBrowserSheet.getMode();
FileSystemManager manager = fileBrowserSheet.getManager();
FileName baseFileName = fileBrowserSheet.getBaseFileName();
switch(mode) {
case OPEN:
case OPEN_MULTIPLE:
case SAVE_TO:
{
try {
fileBrowserSheet.setSelectedFiles(fileBrowser.getSelectedFiles());
} catch (FileSystemException fse) {
throw new RuntimeException(fse);
}
break;
}
case SAVE_AS:
{
String fileName = saveAsTextInput.getText();
// current location and let the chips fall ...
try {
FileObject selectedFile = manager.resolveFile(fileBrowser.getRootDirectory(), fileName);
// !fileName.startsWith(File.separator)) {
if (selectedFile.exists() && selectedFile.getType() == FileType.FOLDER) {
try {
// TODO: what to do about canonical file representations?
FileObject root = /* selectedFile.getCanonicalFile(); */
selectedFile;
fileBrowserSheet.setRootDirectory(root);
fileBrowser.setRootDirectory(root);
setHostLabel(root);
saveAsTextInput.setText("");
} catch (IOException ioe) {
Form.setFlag(saveAsBoxPane, new Form.Flag());
}
selectedFile = null;
vote = Vote.DENY;
} else {
FileObject root = selectedFile.getParent();
if (root != null && root.exists() && root.getType() == FileType.FOLDER) {
try {
// TODO: canonical file again
// fileBrowserSheet.setRootDirectory(root.getCanonicalFile());
fileBrowserSheet.setRootDirectory(root);
setHostLabel(root);
selectedFile = manager.resolveFile(selectedFile.getName().getURI());
} catch (IOException ioe) {
Form.setFlag(saveAsBoxPane, new Form.Flag());
selectedFile = null;
vote = Vote.DENY;
}
} else {
// Could be an error message here
// ("Directory does not exist")
Form.setFlag(saveAsBoxPane, new Form.Flag());
selectedFile = null;
vote = Vote.DENY;
}
}
if (selectedFile != null) {
fileBrowserSheet.setSelectedFiles(new ArrayList<>(selectedFile));
}
} catch (FileSystemException fse) {
Form.setFlag(saveAsBoxPane, new Form.Flag());
vote = Vote.DENY;
}
break;
}
default:
break;
}
updatingSelection = false;
}
if (vote == null) {
vote = super.previewSheetClose(sheet, result);
}
}
return vote;
}
use of org.apache.pivot.wtk.VFSBrowserSheet in project pivot by apache.
the class TerraVFSBrowserSheetSkin method updateOKButtonState.
private void updateOKButtonState() {
VFSBrowserSheet fileBrowserSheet = (VFSBrowserSheet) getComponent();
VFSBrowserSheet.Mode mode = fileBrowserSheet.getMode();
Sequence<FileObject> selectedFiles = fileBrowser.getSelectedFiles();
switch(mode) {
case OPEN:
case OPEN_MULTIPLE:
{
okButton.setEnabled(selectedFiles.getLength() > 0 && selectedDirectoryCount == 0);
break;
}
case SAVE_AS:
{
okButton.setEnabled(saveAsTextInput.getCharacterCount() > 0);
break;
}
case SAVE_TO:
{
okButton.setEnabled(selectedDirectoryCount > 0);
break;
}
default:
break;
}
}
use of org.apache.pivot.wtk.VFSBrowserSheet in project pivot by apache.
the class VFSBrowserTest method startup.
@Override
public void startup(final Display display, final Map<String, String> properties) throws Exception {
BoxPane windowContent = new BoxPane();
windowContent.getStyles().put(Style.verticalAlignment, VerticalAlignment.CENTER);
final Checkbox showHiddenCheckbox = new Checkbox("Show hidden files");
windowContent.add(showHiddenCheckbox);
PushButton button = new PushButton("Open File Browser");
button.getStyles().put(Style.padding, "[2, 4, 2, 4]");
button.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(final Button buttonArgument) {
try {
final VFSBrowserSheet vfsBrowserSheet = new VFSBrowserSheet(VFSBrowserSheet.Mode.OPEN);
vfsBrowserSheet.getStyles().put(Style.showHiddenFiles, showHiddenCheckbox.isSelected());
vfsBrowserSheet.open(frame, new SheetCloseListener() {
@Override
public void sheetClosed(final Sheet sheet) {
if (sheet.getResult()) {
Sequence<FileObject> selectedFiles = vfsBrowserSheet.getSelectedFiles();
ListView listView = new ListView();
listView.setListData(new ArrayList<>(selectedFiles));
listView.setSelectMode(ListView.SelectMode.NONE);
listView.getStyles().put(Style.backgroundColor, null);
Alert.alert(MessageType.INFO, "You selected:", listView, frame);
} else {
Alert.alert(MessageType.INFO, "You didn't select anything.", frame);
}
}
});
} catch (FileSystemException fse) {
Alert.alert(MessageType.ERROR, String.format("File System Exception: %1$s", fse.getMessage()), frame);
}
}
});
windowContent.add(button);
frame = new Frame(windowContent);
frame.setMaximized(true);
frame.open(display);
}
use of org.apache.pivot.wtk.VFSBrowserSheet in project pivot by apache.
the class TerraVFSBrowserSheetSkin method install.
@Override
public void install(Component component) {
super.install(component);
final VFSBrowserSheet fileBrowserSheet = (VFSBrowserSheet) component;
fileBrowserSheet.setMinimumWidth(360);
fileBrowserSheet.setMinimumHeight(180);
// Load the sheet content
BXMLSerializer bxmlSerializer = new BXMLSerializer();
Component content;
try {
content = (Component) bxmlSerializer.readObject(TerraVFSBrowserSheetSkin.class, "terra_vfs_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, TerraVFSBrowserSheetSkin.class);
// set the same rootDirectory as the component
try {
FileObject rootDirectory = fileBrowserSheet.getRootDirectory();
fileBrowser.setRootDirectory(rootDirectory);
setHostLabel(rootDirectory);
} catch (FileSystemException fse) {
throw new RuntimeException(fse);
}
// set the same homeDirectory as the component
try {
fileBrowser.setHomeDirectory(fileBrowserSheet.getHomeDirectory());
} catch (FileSystemException fse) {
throw new RuntimeException(fse);
}
saveAsTextInput.getTextInputContentListeners().add(new TextInputContentListener() {
@Override
public void textChanged(TextInput textInput) {
Form.clearFlag(saveAsBoxPane);
updateOKButtonState();
}
});
fileBrowser.getFileBrowserListeners().add(new VFSBrowserListener() {
@Override
public void rootDirectoryChanged(VFSBrowser fileBrowserArgument, FileObject previousRootDirectory) {
updatingSelection = true;
try {
FileObject rootDirectory = fileBrowserArgument.getRootDirectory();
fileBrowserSheet.setRootDirectory(rootDirectory);
setHostLabel(rootDirectory);
} catch (FileSystemException fse) {
throw new RuntimeException(fse);
}
updatingSelection = false;
selectedDirectoryCount = 0;
updateOKButtonState();
}
@Override
public void homeDirectoryChanged(VFSBrowser fileBrowserArgument, FileObject previousHomeDirectory) {
updatingSelection = true;
try {
fileBrowserSheet.setHomeDirectory(fileBrowserArgument.getHomeDirectory());
} catch (FileSystemException fse) {
throw new RuntimeException(fse);
}
updatingSelection = false;
}
@Override
public void selectedFileAdded(VFSBrowser fileBrowserArgument, FileObject file) {
if (file.getName().getType() == FileType.FOLDER) {
selectedDirectoryCount++;
}
updateOKButtonState();
}
@Override
public void selectedFileRemoved(VFSBrowser fileBrowserArgument, FileObject file) {
if (file.getName().getType() == FileType.FOLDER) {
selectedDirectoryCount--;
}
updateOKButtonState();
}
@Override
public void selectedFilesChanged(VFSBrowser fileBrowserArgument, Sequence<FileObject> previousSelectedFiles) {
selectedDirectoryCount = 0;
Sequence<FileObject> selectedFiles = fileBrowserArgument.getSelectedFiles();
for (int i = 0, n = selectedFiles.getLength(); i < n; i++) {
FileObject selectedFile = selectedFiles.get(i);
if (selectedFile.getName().getType() == FileType.FOLDER) {
selectedDirectoryCount++;
}
}
if (!fileBrowserArgument.isMultiSelect()) {
FileObject selectedFile = fileBrowserArgument.getSelectedFile();
if (selectedFile != null && selectedFile.getName().getType() != FileType.FOLDER) {
saveAsTextInput.setText(selectedFile.getName().getPath());
}
}
updateOKButtonState();
}
});
fileBrowser.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener() {
private FileObject file = null;
@Override
public boolean mouseClick(Component componentArgument, Mouse.Button button, int x, int y, int count) {
boolean consumed = false;
VFSBrowserSheet.Mode mode = fileBrowserSheet.getMode();
if (count == 1) {
file = fileBrowser.getFileAt(x, y);
} else if (count == 2) {
FileObject fileLocal = fileBrowser.getFileAt(x, y);
if (fileLocal != null && this.file != null && fileLocal.equals(this.file) && fileBrowser.isFileSelected(fileLocal)) {
if (mode == VFSBrowserSheet.Mode.OPEN || mode == VFSBrowserSheet.Mode.OPEN_MULTIPLE) {
if (fileLocal.getName().getType() != FileType.FOLDER) {
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);
homeDirectoryChanged(fileBrowserSheet, null);
rootDirectoryChanged(fileBrowserSheet, null);
selectedFilesChanged(fileBrowserSheet, null);
}
use of org.apache.pivot.wtk.VFSBrowserSheet in project pivot by apache.
the class TerraVFSBrowserSheetSkin method updateDisabledFileFilter.
private void updateDisabledFileFilter() {
VFSBrowserSheet fileBrowserSheet = (VFSBrowserSheet) getComponent();
Filter<FileObject> disabledFileFilter = fileBrowserSheet.getDisabledFileFilter();
VFSBrowserSheet.Mode mode = fileBrowserSheet.getMode();
if (mode == VFSBrowserSheet.Mode.SAVE_TO) {
disabledFileFilter = new SaveToFileFilter(disabledFileFilter);
}
fileBrowser.setDisabledFileFilter(disabledFileFilter);
}
Aggregations