use of org.apache.pivot.util.Vote in project pivot by apache.
the class Pivot765 method startup.
@Override
public void startup(final Display display, Map<String, String> properties) throws Exception {
final MenuButton button = new MenuButton();
button.setButtonData("Populate menu and open!");
Window window = new Window(button);
button.getListPopup().getWindowStateListeners().add(new WindowStateListener() {
@Override
public Vote previewWindowOpen(Window windowArgument) {
Menu menu = new Menu();
Menu.Section section = new Menu.Section();
menu.getSections().add(section);
section.add(new Menu.Item("A dynamically added menu item"));
button.setMenu(menu);
menuPopulated = true;
return Vote.APPROVE;
}
@Override
public void windowOpened(Window windowArgument) {
if (!menuPopulated) {
Alert.alert("Window was opened before the menu was populated." + "Either previewWindowOpen threw an exception, or it wasn't called before the Window was opened.", windowArgument);
}
}
@Override
public void windowClosed(Window windowArgument, Display displayArgument, Window owner) {
// Remove menu for subsequent open attempt
button.setMenu(null);
menuPopulated = false;
}
});
window.open(display);
}
use of org.apache.pivot.util.Vote in project pivot by apache.
the class Sheet method close.
public void close(boolean resultArgument) {
if (!isClosed()) {
closing = true;
Vote vote = sheetStateListeners.previewSheetClose(this, resultArgument);
if (vote == Vote.APPROVE) {
Window owner = getOwner();
super.close();
closing = super.isClosing();
if (isClosed()) {
this.result = resultArgument;
// Move the owner to the front
if (owner.isOpen()) {
owner.moveToFront();
}
// Notify listeners
sheetStateListeners.sheetClosed(this);
if (sheetCloseListener != null) {
sheetCloseListener.sheetClosed(this);
sheetCloseListener = null;
}
}
} else {
if (vote == Vote.DENY) {
closing = false;
}
sheetStateListeners.sheetCloseVetoed(this, vote);
}
}
}
use of org.apache.pivot.util.Vote in project pivot by apache.
the class SuggestionPopup method close.
public void close(boolean resultArgument) {
if (!isClosed()) {
closing = true;
Vote vote = suggestionPopupStateListeners.previewSuggestionPopupClose(this, resultArgument);
if (vote == Vote.APPROVE) {
super.close();
closing = super.isClosing();
if (isClosed()) {
this.result = resultArgument;
suggestionPopupStateListeners.suggestionPopupClosed(this);
if (suggestionPopupCloseListener != null) {
suggestionPopupCloseListener.suggestionPopupClosed(this);
suggestionPopupCloseListener = null;
}
}
} else {
if (vote == Vote.DENY) {
closing = false;
}
suggestionPopupStateListeners.suggestionPopupCloseVetoed(this, vote);
}
}
}
use of org.apache.pivot.util.Vote in project pivot by apache.
the class TreeView method setBranchExpanded.
/**
* Sets the expansion state of the specified branch. If the branch already
* has the specified expansion state, nothing happens.
* <p> The listeners are polled first to give them a chance to veto the operation
* for any reason. If the vote passes, then the state is changed.
*
* @param path The path to the branch node.
* @param expanded <tt>true</tt> to expand the branch; <tt>false</tt> to
* collapse it.
*/
public void setBranchExpanded(Path path, boolean expanded) {
checkNullOrEmpty(path);
// Give listeners a chance to veto the operation
Vote vote = treeViewBranchListeners.previewBranchExpandedChange(this, path);
if (vote != Vote.APPROVE) {
treeViewBranchListeners.branchExpandedChangeVetoed(this, path, vote);
} else {
int index = expandedPaths.indexOf(path);
if (expanded && index < 0) {
// Monitor the branch itself
monitorBranch(path, true);
// Update the expanded paths
expandedPaths.add(new ImmutablePath(path));
// Notify listeners
treeViewBranchListeners.branchExpanded(this, path);
} else if (!expanded && index >= 0) {
// Update the expanded paths
expandedPaths.remove(index, 1);
// Notify listeners
treeViewBranchListeners.branchCollapsed(this, path);
}
}
}
use of org.apache.pivot.util.Vote in project pivot by apache.
the class Window method close.
/**
* Closes the window and all of its owned windows. If any owned window fails
* to close, this window will also fail to close.
*/
public void close() {
if (!isClosed()) {
closing = true;
// Close all owned windows (create a copy of the owned window
// list so owned windows can remove themselves from the list
// without interrupting the iteration)
boolean cancel = false;
for (Window ownedWindow : new ArrayList<>(this.ownedWindows)) {
ownedWindow.close();
cancel |= !(ownedWindow.isClosing() || ownedWindow.isClosed());
}
// in parallel, forcing them to run in series)
if (cancel) {
closing = false;
} else {
Vote vote = windowStateListeners.previewWindowClose(this);
if (vote == Vote.APPROVE) {
// Remove the window from the display
Display display = getDisplay();
display.remove(this);
// Clear the owner and remove from the owner's owned window list
Window ownerValue = this.owner;
this.owner = null;
if (ownerValue != null) {
ownerValue.ownedWindows.remove(this);
}
// Notify listeners
closing = false;
windowStateListeners.windowClosed(this, display, ownerValue);
} else {
if (vote == Vote.DENY) {
closing = false;
}
windowStateListeners.windowCloseVetoed(this, vote);
}
}
}
}
Aggregations