Search in sources :

Example 1 with Vote

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);
}
Also used : Window(org.apache.pivot.wtk.Window) Vote(org.apache.pivot.util.Vote) WindowStateListener(org.apache.pivot.wtk.WindowStateListener) MenuButton(org.apache.pivot.wtk.MenuButton) Menu(org.apache.pivot.wtk.Menu) Display(org.apache.pivot.wtk.Display)

Example 2 with Vote

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);
        }
    }
}
Also used : Vote(org.apache.pivot.util.Vote)

Example 3 with 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);
        }
    }
}
Also used : Vote(org.apache.pivot.util.Vote)

Example 4 with 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);
        }
    }
}
Also used : Vote(org.apache.pivot.util.Vote) ImmutablePath(org.apache.pivot.collections.Sequence.Tree.ImmutablePath)

Example 5 with Vote

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);
            }
        }
    }
}
Also used : Vote(org.apache.pivot.util.Vote) ArrayList(org.apache.pivot.collections.ArrayList)

Aggregations

Vote (org.apache.pivot.util.Vote)28 ArrayList (org.apache.pivot.collections.ArrayList)4 Transition (org.apache.pivot.wtk.effects.Transition)4 TransitionListener (org.apache.pivot.wtk.effects.TransitionListener)4 IOException (java.io.IOException)2 Button (org.apache.pivot.wtk.Button)2 Component (org.apache.pivot.wtk.Component)2 Form (org.apache.pivot.wtk.Form)2 Window (org.apache.pivot.wtk.Window)2 Validator (org.apache.pivot.wtk.validation.Validator)2 GradientPaint (java.awt.GradientPaint)1 File (java.io.File)1 FileName (org.apache.commons.vfs2.FileName)1 FileObject (org.apache.commons.vfs2.FileObject)1 FileSystemException (org.apache.commons.vfs2.FileSystemException)1 FileSystemManager (org.apache.commons.vfs2.FileSystemManager)1 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)1 ImmutablePath (org.apache.pivot.collections.Sequence.Tree.ImmutablePath)1 VoteResult (org.apache.pivot.util.VoteResult)1 Accordion (org.apache.pivot.wtk.Accordion)1