Search in sources :

Example 11 with Vote

use of org.apache.pivot.util.Vote in project pivot by apache.

the class TerraVFSBrowserSheetSkin 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;
            VFSBrowserSheet fileBrowserSheet = (VFSBrowserSheet) sheet;
            VFSBrowserSheet.Mode mode = fileBrowserSheet.getMode();
            FileSystemManager manager = fileBrowserSheet.getManager();
            FileName baseFileName = fileBrowserSheet.getBaseFileName();
            switch(mode) {
                case OPEN:
                case OPEN_MULTIPLE:
                case SAVE_TO:
                    {
                        try {
                            fileBrowserSheet.setSelectedFiles(fileBrowser.getSelectedFiles());
                        } catch (FileSystemException fse) {
                            throw new RuntimeException(fse);
                        }
                        break;
                    }
                case SAVE_AS:
                    {
                        String fileName = saveAsTextInput.getText();
                        // current location and let the chips fall ...
                        try {
                            FileObject selectedFile = manager.resolveFile(fileBrowser.getRootDirectory(), fileName);
                            // !fileName.startsWith(File.separator)) {
                            if (selectedFile.exists() && selectedFile.getType() == FileType.FOLDER) {
                                try {
                                    // TODO: what to do about canonical file representations?
                                    FileObject root = /* selectedFile.getCanonicalFile(); */
                                    selectedFile;
                                    fileBrowserSheet.setRootDirectory(root);
                                    fileBrowser.setRootDirectory(root);
                                    setHostLabel(root);
                                    saveAsTextInput.setText("");
                                } catch (IOException ioe) {
                                    Form.setFlag(saveAsBoxPane, new Form.Flag());
                                }
                                selectedFile = null;
                                vote = Vote.DENY;
                            } else {
                                FileObject root = selectedFile.getParent();
                                if (root != null && root.exists() && root.getType() == FileType.FOLDER) {
                                    try {
                                        // TODO: canonical file again
                                        // fileBrowserSheet.setRootDirectory(root.getCanonicalFile());
                                        fileBrowserSheet.setRootDirectory(root);
                                        setHostLabel(root);
                                        selectedFile = manager.resolveFile(selectedFile.getName().getURI());
                                    } 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));
                            }
                        } catch (FileSystemException fse) {
                            Form.setFlag(saveAsBoxPane, new Form.Flag());
                            vote = Vote.DENY;
                        }
                        break;
                    }
                default:
                    break;
            }
            updatingSelection = false;
        }
        if (vote == null) {
            vote = super.previewSheetClose(sheet, result);
        }
    }
    return vote;
}
Also used : Vote(org.apache.pivot.util.Vote) Form(org.apache.pivot.wtk.Form) FileName(org.apache.commons.vfs2.FileName) ArrayList(org.apache.pivot.collections.ArrayList) IOException(java.io.IOException) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) FileSystemException(org.apache.commons.vfs2.FileSystemException) VFSBrowserSheet(org.apache.pivot.wtk.VFSBrowserSheet) FileObject(org.apache.commons.vfs2.FileObject)

Example 12 with Vote

use of org.apache.pivot.util.Vote in project pivot by apache.

the class TerraExpanderSkin method previewExpandedChange.

/**
 * {@inheritDoc}
 */
@Override
public Vote previewExpandedChange(final Expander expander) {
    Vote vote;
    if (expander.isShowing() && expandTransition == null && expander.getContent() != null) {
        final boolean expanded = expander.isExpanded();
        shadeButton.setButtonData(expanded ? collapseImage : expandImage);
        expandTransition = new ExpandTransition(expanded);
        expandTransition.start(new TransitionListener() {

            @Override
            public void transitionCompleted(Transition transition) {
                expander.setExpanded(!expanded);
                expandTransition = null;
            }
        });
    }
    if (expandTransition == null || !expandTransition.isRunning()) {
        vote = Vote.APPROVE;
    } else {
        vote = Vote.DEFER;
    }
    return vote;
}
Also used : Vote(org.apache.pivot.util.Vote) Transition(org.apache.pivot.wtk.effects.Transition) TransitionListener(org.apache.pivot.wtk.effects.TransitionListener)

Example 13 with Vote

use of org.apache.pivot.util.Vote in project pivot by apache.

the class TerraSheetSkin method previewSheetClose.

@Override
public Vote previewSheetClose(Sheet sheet, boolean result) {
    Vote vote = Vote.APPROVE;
    // Don't start the transition if the sheet is being closed as a result
    // of the owner closing
    Window owner = sheet.getOwner();
    if (!(owner.isClosing() || owner.isClosed() || doingFinalClose)) {
        if (openTransition == null) {
            // Setup for the close transition
            // Don't start it until we know that everyone
            // else is okay with it
            openTransition = new OpenTransition(true);
            closingResult = result;
        } else {
            // Reverse the open transition
            if (openTransition.isRunning()) {
                openTransition.reverse();
            }
        }
        vote = (openTransition != null) ? Vote.DEFER : Vote.APPROVE;
    }
    return vote;
}
Also used : Window(org.apache.pivot.wtk.Window) Vote(org.apache.pivot.util.Vote)

Example 14 with Vote

use of org.apache.pivot.util.Vote in project pivot by apache.

the class TerraRollupSkin method previewExpandedChange.

// Rollup state events
@Override
public Vote previewExpandedChange(final Rollup rollup) {
    Vote vote;
    if (rollup.isShowing() && expandTransition == null && rollup.getContent() != null) {
        final boolean expanded = rollup.isExpanded();
        expandTransition = new ExpandTransition(expanded);
        expandTransition.start(new TransitionListener() {

            @Override
            public void transitionCompleted(Transition transition) {
                rollup.setExpanded(!expanded);
                expandTransition = null;
            }
        });
    }
    if (expandTransition == null || !expandTransition.isRunning()) {
        vote = Vote.APPROVE;
    } else {
        vote = Vote.DEFER;
    }
    return vote;
}
Also used : Vote(org.apache.pivot.util.Vote) Transition(org.apache.pivot.wtk.effects.Transition) TransitionListener(org.apache.pivot.wtk.effects.TransitionListener)

Example 15 with Vote

use of org.apache.pivot.util.Vote in project pivot by apache.

the class Accordions method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    accordion = (Accordion) namespace.get("accordion");
    accordion.getAccordionSelectionListeners().add(new AccordionSelectionListener() {

        private int selectedIndex = -1;

        @Override
        public Vote previewSelectedIndexChange(Accordion accordionArgument, int selectedIndexArgument) {
            this.selectedIndex = selectedIndexArgument;
            // transition looks smoother
            if (selectedIndexArgument != -1) {
                int previousSelectedIndex = accordionArgument.getSelectedIndex();
                if (selectedIndexArgument > previousSelectedIndex) {
                    accordionArgument.getPanels().get(selectedIndexArgument).setEnabled(true);
                } else {
                    accordionArgument.getPanels().get(previousSelectedIndex).setEnabled(false);
                }
            }
            return Vote.APPROVE;
        }

        @Override
        public void selectedIndexChangeVetoed(Accordion accordionArgument, Vote reason) {
            if (reason == Vote.DENY && selectedIndex != -1) {
                Component panel = accordionArgument.getPanels().get(selectedIndex);
                panel.setEnabled(!panel.isEnabled());
            }
        }

        @Override
        public void selectedIndexChanged(Accordion accordionArgument, int previousSelection) {
            updateAccordion();
        }
    });
    updateAccordion();
}
Also used : Vote(org.apache.pivot.util.Vote) Accordion(org.apache.pivot.wtk.Accordion) AccordionSelectionListener(org.apache.pivot.wtk.AccordionSelectionListener) Component(org.apache.pivot.wtk.Component)

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