use of org.apache.pivot.util.Vote 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.util.Vote in project pivot by apache.
the class TerraExpanderSkin method previewExpandedChange.
/**
* {@inheritDoc}
*/
@Override
public Vote previewExpandedChange(final Expander expander) {
Vote vote;
if (expander.isShowing() && expandTransition == null && expander.getContent() != null) {
final boolean expanded = expander.isExpanded();
shadeButton.setButtonData(expanded ? collapseImage : expandImage);
expandTransition = new ExpandTransition(expanded);
expandTransition.start(new TransitionListener() {
@Override
public void transitionCompleted(Transition transition) {
expander.setExpanded(!expanded);
expandTransition = null;
}
});
}
if (expandTransition == null || !expandTransition.isRunning()) {
vote = Vote.APPROVE;
} else {
vote = Vote.DEFER;
}
return vote;
}
use of org.apache.pivot.util.Vote in project pivot by apache.
the class TerraSheetSkin method previewSheetClose.
@Override
public Vote previewSheetClose(Sheet sheet, boolean result) {
Vote vote = Vote.APPROVE;
// Don't start the transition if the sheet is being closed as a result
// of the owner closing
Window owner = sheet.getOwner();
if (!(owner.isClosing() || owner.isClosed() || doingFinalClose)) {
if (openTransition == null) {
// Setup for the close transition
// Don't start it until we know that everyone
// else is okay with it
openTransition = new OpenTransition(true);
closingResult = result;
} else {
// Reverse the open transition
if (openTransition.isRunning()) {
openTransition.reverse();
}
}
vote = (openTransition != null) ? Vote.DEFER : Vote.APPROVE;
}
return vote;
}
use of org.apache.pivot.util.Vote in project pivot by apache.
the class TerraRollupSkin method previewExpandedChange.
// Rollup state events
@Override
public Vote previewExpandedChange(final Rollup rollup) {
Vote vote;
if (rollup.isShowing() && expandTransition == null && rollup.getContent() != null) {
final boolean expanded = rollup.isExpanded();
expandTransition = new ExpandTransition(expanded);
expandTransition.start(new TransitionListener() {
@Override
public void transitionCompleted(Transition transition) {
rollup.setExpanded(!expanded);
expandTransition = null;
}
});
}
if (expandTransition == null || !expandTransition.isRunning()) {
vote = Vote.APPROVE;
} else {
vote = Vote.DEFER;
}
return vote;
}
use of org.apache.pivot.util.Vote in project pivot by apache.
the class Accordions method initialize.
@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
accordion = (Accordion) namespace.get("accordion");
accordion.getAccordionSelectionListeners().add(new AccordionSelectionListener() {
private int selectedIndex = -1;
@Override
public Vote previewSelectedIndexChange(Accordion accordionArgument, int selectedIndexArgument) {
this.selectedIndex = selectedIndexArgument;
// transition looks smoother
if (selectedIndexArgument != -1) {
int previousSelectedIndex = accordionArgument.getSelectedIndex();
if (selectedIndexArgument > previousSelectedIndex) {
accordionArgument.getPanels().get(selectedIndexArgument).setEnabled(true);
} else {
accordionArgument.getPanels().get(previousSelectedIndex).setEnabled(false);
}
}
return Vote.APPROVE;
}
@Override
public void selectedIndexChangeVetoed(Accordion accordionArgument, Vote reason) {
if (reason == Vote.DENY && selectedIndex != -1) {
Component panel = accordionArgument.getPanels().get(selectedIndex);
panel.setEnabled(!panel.isEnabled());
}
}
@Override
public void selectedIndexChanged(Accordion accordionArgument, int previousSelection) {
updateAccordion();
}
});
updateAccordion();
}
Aggregations