use of org.apache.pivot.util.Vote in project pivot by apache.
the class Expander method setExpanded.
public void setExpanded(boolean expanded) {
if (expanded != this.expanded) {
if (!collapsible && !expanded) {
throw new IllegalStateException("Expander cannot be collapsed and yet not collapsible.");
}
Vote vote = expanderListeners.previewExpandedChange(this);
if (vote == Vote.APPROVE) {
this.expanded = expanded;
expanderListeners.expandedChanged(this);
} else {
expanderListeners.expandedChangeVetoed(this, vote);
}
}
}
use of org.apache.pivot.util.Vote in project pivot by apache.
the class MenuPopup method close.
public void close(boolean immediate) {
if (!isClosed()) {
closing = true;
Vote vote = menuPopupStateListeners.previewMenuPopupClose(this, immediate);
if (vote == Vote.APPROVE) {
super.close();
closing = super.isClosing();
if (isClosed()) {
menuPopupStateListeners.menuPopupClosed(this);
}
} else if (vote == Vote.DENY) {
closing = false;
menuPopupStateListeners.menuPopupCloseVetoed(this, vote);
}
}
if (isClosed()) {
contextMenu = false;
}
}
use of org.apache.pivot.util.Vote in project pivot by apache.
the class TerraTextInputSkin method previewInsertText.
// Text input character events
@Override
public Vote previewInsertText(TextInput textInput, CharSequence text, int index) {
Vote vote = Vote.APPROVE;
if (textInput.isStrictValidation()) {
Validator validator = textInput.getValidator();
if (validator != null) {
StringBuilder textBuilder = new StringBuilder();
textBuilder.append(textInput.getText(0, index));
textBuilder.append(text);
textBuilder.append(textInput.getText(index, textInput.getCharacterCount()));
if (!validator.isValid(textBuilder.toString())) {
vote = Vote.DENY;
Toolkit.getDefaultToolkit().beep();
}
}
}
return vote;
}
use of org.apache.pivot.util.Vote in project pivot by apache.
the class TerraTextInputSkin method previewRemoveText.
@Override
public Vote previewRemoveText(TextInput textInput, int index, int count) {
Vote vote = Vote.APPROVE;
if (textInput.isStrictValidation()) {
Validator validator = textInput.getValidator();
if (validator != null) {
StringBuilder textBuilder = new StringBuilder();
textBuilder.append(textInput.getText(0, index));
textBuilder.append(textInput.getText(index + count, textInput.getCharacterCount()));
if (!validator.isValid(textBuilder.toString())) {
vote = Vote.DENY;
Toolkit.getDefaultToolkit().beep();
}
}
}
return vote;
}
use of org.apache.pivot.util.Vote in project pivot by apache.
the class TerraFileBrowserSheetSkin 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;
FileBrowserSheet fileBrowserSheet = (FileBrowserSheet) sheet;
FileBrowserSheet.Mode mode = fileBrowserSheet.getMode();
switch(mode) {
case OPEN:
case OPEN_MULTIPLE:
case SAVE_TO:
{
fileBrowserSheet.setSelectedFiles(fileBrowser.getSelectedFiles());
break;
}
case SAVE_AS:
{
String fileName = saveAsTextInput.getText();
// Contents of the entry field could be:
// 1. Just a new file name in the current root directory
// 2. A relative or absolute path that is an existing directory
// to navigate to
// 3. A relative or absolute path including the new file name
// in an existing directory
// So, first make it an absolute path
File selectedFile = new File(fileName);
if (!selectedFile.isAbsolute() && !fileName.startsWith(File.separator)) {
selectedFile = new File(fileBrowser.getRootDirectory(), fileName);
} else {
selectedFile = selectedFile.getAbsoluteFile();
}
if (selectedFile.exists() && selectedFile.isDirectory()) {
try {
File root = selectedFile.getCanonicalFile();
fileBrowserSheet.setRootDirectory(root);
fileBrowser.setRootDirectory(root);
saveAsTextInput.setText("");
} catch (IOException ioe) {
Form.setFlag(saveAsBoxPane, new Form.Flag());
}
selectedFile = null;
vote = Vote.DENY;
} else {
File root = selectedFile.getParentFile();
if (root != null && root.exists() && root.isDirectory()) {
try {
fileBrowserSheet.setRootDirectory(root.getCanonicalFile());
selectedFile = new File(selectedFile.getName());
} 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));
}
break;
}
default:
{
break;
}
}
updatingSelection = false;
}
if (vote == null) {
vote = super.previewSheetClose(sheet, result);
}
}
return vote;
}
Aggregations