use of org.apache.pivot.util.Vote in project pivot by apache.
the class TabPanes method initialize.
@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
confirmCloseTabPrompt = (Prompt) namespace.get("confirmCloseTabPrompt");
tabPane = (TabPane) namespace.get("tabPane");
closeableCheckbox = (Checkbox) namespace.get("closeableCheckbox");
collapsibleCheckbox = (Checkbox) namespace.get("collapsibleCheckbox");
horizontalRadioButton = (RadioButton) namespace.get("horizontalRadioButton");
verticalRadioButton = (RadioButton) namespace.get("verticalRadioButton");
cornerBoxPane = (BoxPane) namespace.get("cornerBoxPane");
tabPane.getTabPaneListeners().add(new TabPaneListener() {
@Override
public Vote previewRemoveTabs(final TabPane tabPaneArgument, final int index, final int count) {
Vote vote;
if (confirmCloseTab) {
confirmCloseTabPrompt.open(TabPanes.this, new SheetCloseListener() {
@Override
public void sheetClosed(Sheet sheet) {
if (confirmCloseTabPrompt.getResult() && confirmCloseTabPrompt.getSelectedOptionIndex() == 1) {
confirmCloseTab = false;
int n = tabPaneArgument.getTabs().getLength();
if (index < n - 1) {
tabPaneArgument.setSelectedIndex(index + 1);
} else {
tabPaneArgument.setSelectedIndex(index - 1);
}
tabPaneArgument.getTabs().remove(index, count);
confirmCloseTab = true;
}
}
});
vote = Vote.DENY;
} else {
vote = Vote.APPROVE;
}
return vote;
}
});
ButtonStateListener checkboxStateListener = new ButtonStateListener() {
@Override
public void stateChanged(Button button, Button.State previousState) {
updateTabPane();
}
};
closeableCheckbox.getButtonStateListeners().add(checkboxStateListener);
collapsibleCheckbox.getButtonStateListeners().add(checkboxStateListener);
ButtonStateListener radioButtonStateListener = new ButtonStateListener() {
@Override
public void stateChanged(Button button, Button.State previousState) {
if (button.isSelected()) {
updateTabPane();
}
}
};
horizontalRadioButton.getButtonStateListeners().add(radioButtonStateListener);
verticalRadioButton.getButtonStateListeners().add(radioButtonStateListener);
updateTabPane();
}
use of org.apache.pivot.util.Vote in project pivot by apache.
the class Window method open.
/**
* Opens the window. <p> Note that this method is not a synchronous call, it
* schedules an event to open the window.
*
* @param display The display on which the window will be opened.
* @param ownerArgument The window's owner, or <tt>null</tt> if the window
* has no owner.
*/
public void open(Display display, Window ownerArgument) {
Utils.checkNull(display, "display");
if (ownerArgument != null) {
if (!ownerArgument.isOpen()) {
throw new IllegalArgumentException("owner is not open.");
}
if (isOwner(ownerArgument)) {
throw new IllegalArgumentException("owner is an owned descendant of this window.");
}
}
if (isOpen()) {
if (getDisplay() != display) {
throw new IllegalStateException("Window is already open on a different display.");
}
if (this.owner != ownerArgument) {
throw new IllegalStateException("Window is already open with a different owner.");
}
}
if (!isOpen()) {
opening = true;
Vote vote = windowStateListeners.previewWindowOpen(this);
if (vote == Vote.APPROVE) {
// Set the owner and add to the owner's owned window list
this.owner = ownerArgument;
if (ownerArgument != null) {
ownerArgument.ownedWindows.add(this);
}
// Add the window to the display
display.add(this);
// Notify listeners
opening = false;
windowStateListeners.windowOpened(this);
moveToFront();
} else {
if (vote == Vote.DENY) {
opening = false;
}
windowStateListeners.windowOpenVetoed(this, vote);
}
}
}
use of org.apache.pivot.util.Vote in project pivot by apache.
the class TabPane method setSelectedIndex.
public void setSelectedIndex(int selectedIndex) {
indexBoundsCheck("selectedIndex", selectedIndex, -1, tabs.getLength() - 1);
int previousSelectedIndex = this.selectedIndex;
if (previousSelectedIndex != selectedIndex) {
Vote vote = tabPaneSelectionListeners.previewSelectedIndexChange(this, selectedIndex);
if (vote == Vote.APPROVE) {
this.selectedIndex = selectedIndex;
tabPaneSelectionListeners.selectedIndexChanged(this, previousSelectedIndex);
} else {
tabPaneSelectionListeners.selectedIndexChangeVetoed(this, vote);
}
}
}
use of org.apache.pivot.util.Vote in project pivot by apache.
the class Rollup method setExpanded.
public void setExpanded(boolean expanded) {
if (expanded != this.expanded) {
Vote vote = rollupStateListeners.previewExpandedChange(this);
if (vote == Vote.APPROVE) {
this.expanded = expanded;
rollupStateListeners.expandedChanged(this);
} else {
rollupStateListeners.expandedChangeVetoed(this, vote);
}
}
}
use of org.apache.pivot.util.Vote in project pivot by apache.
the class Dialog method close.
public void close(boolean resultArgument) {
if (!isClosed()) {
closing = true;
Vote vote = dialogStateListeners.previewDialogClose(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 != null && owner.isOpen()) {
owner.moveToFront();
}
// Notify listeners
dialogStateListeners.dialogClosed(this, modal);
if (dialogCloseListener != null) {
dialogCloseListener.dialogClosed(this, modal);
dialogCloseListener = null;
}
}
} else {
if (vote == Vote.DENY) {
closing = false;
}
dialogStateListeners.dialogCloseVetoed(this, vote);
}
}
}
Aggregations