Search in sources :

Example 21 with Vote

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

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

Example 23 with Vote

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

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

Example 25 with 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;
}
Also used : Vote(org.apache.pivot.util.Vote) FileBrowserSheet(org.apache.pivot.wtk.FileBrowserSheet) Form(org.apache.pivot.wtk.Form) ArrayList(org.apache.pivot.collections.ArrayList) IOException(java.io.IOException) File(java.io.File)

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