IzPack
  1. IzPack
  2. IZPACK-604

The ability manipulate the Quit button and process Quit events

    Details

    • Type: Improvement Improvement
    • Status: Resolved Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 4.3.2, 4.3.3
    • Fix Version/s: 5.0
    • Component/s: Installer
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Currently Izpack has the following limitations:
      a) You cannot hide or disable the Quit button on the InstallerFrame. In our scenario we have optional panels for rollback if anything should fail during installation and we definitively don't want the user to be able to Quit before we can do rollback.
      b) The Quit button doesn't allow custom handling of events. If a user chooses yes, I would like to be able to veto his decision and do different processing like displaying a message, or just add some logic to the quit process.

      Please give panels access to the quit button and also the ability process the quit events.

        Activity

        Hide
        Tim Anderson added a comment -

        Would an API like the following suffice?
        You would have access to the 3 buttons, 'Next', 'Previous' and 'Quit' and be able to register a VetoableEventListener for each to veto the default behaviour of next(), previous() and quit().

        
        public class InstallerFrame  {
        
             public Navigator getNavigator() { ... }
        
        }
        
        public interface Navigator
        {
        
            /**
             * Returns the button to navigate to the next panel.
             *
             * @return the 'next' button
             */
            JButton getNext();
        
            /**
             * Registers a listener that may veto navigation to the next panel.
             *
             * @param listener the listener. May be <tt>null</tt>
             */
            void setNextListener(VetoableEventListener listener);
        
            /**
             * Returns the button to navigate to the previous panel.
             *
             * @return the 'previous' button
             */
            JButton getPrevious();
        
            /**
             * Registers a listener that may veto navigation to the previous panel.
             *
             * @param listener the listener. May be <tt>null</tt>
             */
            void setPreviousListener(VetoableEventListener listener);
        
            /**
             * Returns the button to quit installation.
             *
             * @return the 'quit' button
             */
            JButton getQuit();
        
            /**
             * Registers a listener that may veto quitting installation.
             *
             * @param listener the listener. May be <tt>null</tt>
             */
            void setQuitListener(VetoableEventListener listener);
        
            /**
             * Navigates to the next panel.
             *
             * @return <tt>true</tt> if the next panel was displayed, or <tt>false</tt> if the last panel is displayed or
             *         navigation is vetoed
             */
            boolean next();
        
            /**
             * Navigates to the previous panel.
             *
             * @return <tt>true</tt> if the previous panel was displayed, or <tt>false</tt> if the first panel is displayed or
             *         navigation is vetoed
             */
            boolean previous();
        
            /**
             * Quits installation.
             *
             * @return <tt>true</tt> if installation was quit, or <tt>false</tt> if quit failed was vetoed
             */
            boolean quit();
        
        }
        
        public interface VetoableEventListener extends EventListener
        {
        
            /**
             * Invoked to determine if an event should be vetoed.
             *
             * @param source the source that triggered the event
             * @return <tt>true</tt> if the event should be vetoed, or <tt>false</tt> if it should proceed
             */
            boolean veto(Object source);
        }
        
        
        Show
        Tim Anderson added a comment - Would an API like the following suffice? You would have access to the 3 buttons, 'Next', 'Previous' and 'Quit' and be able to register a VetoableEventListener for each to veto the default behaviour of next(), previous() and quit(). public class InstallerFrame { public Navigator getNavigator() { ... } } public interface Navigator { /** * Returns the button to navigate to the next panel. * * @ return the 'next' button */ JButton getNext(); /** * Registers a listener that may veto navigation to the next panel. * * @param listener the listener. May be <tt> null </tt> */ void setNextListener(VetoableEventListener listener); /** * Returns the button to navigate to the previous panel. * * @ return the 'previous' button */ JButton getPrevious(); /** * Registers a listener that may veto navigation to the previous panel. * * @param listener the listener. May be <tt> null </tt> */ void setPreviousListener(VetoableEventListener listener); /** * Returns the button to quit installation. * * @ return the 'quit' button */ JButton getQuit(); /** * Registers a listener that may veto quitting installation. * * @param listener the listener. May be <tt> null </tt> */ void setQuitListener(VetoableEventListener listener); /** * Navigates to the next panel. * * @ return <tt> true </tt> if the next panel was displayed, or <tt> false </tt> if the last panel is displayed or * navigation is vetoed */ boolean next(); /** * Navigates to the previous panel. * * @ return <tt> true </tt> if the previous panel was displayed, or <tt> false </tt> if the first panel is displayed or * navigation is vetoed */ boolean previous(); /** * Quits installation. * * @ return <tt> true </tt> if installation was quit, or <tt> false </tt> if quit failed was vetoed */ boolean quit(); } public interface VetoableEventListener extends EventListener { /** * Invoked to determine if an event should be vetoed. * * @param source the source that triggered the event * @ return <tt> true </tt> if the event should be vetoed, or <tt> false </tt> if it should proceed */ boolean veto( Object source); }
        Hide
        Alwyn Schoeman added a comment -

        It would definitively help in the cases where you want to be able to tell the user he can't quit right now. Obviously this doesn't give the ability to disable or hide the quit button.

        Show
        Alwyn Schoeman added a comment - It would definitively help in the cases where you want to be able to tell the user he can't quit right now. Obviously this doesn't give the ability to disable or hide the quit button.
        Hide
        Tim Anderson added a comment -

        You can via:

        navigator.getQuit().setEnabled(false);
        navigator.getQuit().setVisible(false);
        
        Show
        Tim Anderson added a comment - You can via: navigator.getQuit().setEnabled( false ); navigator.getQuit().setVisible( false );
        Hide
        Tim Anderson added a comment -

        Here's the new API. Amongst other things, it allows you enable/disable quit, and make it visible/invisible.

        public interface Navigator
        {
        
            /**
             * Determines if the next panel may be navigated to.
             *
             * @return {@code true} if the next panel may be navigated to
             */
            boolean isNextEnabled();
        
            /**
             * Determines if the next panel may be navigated to.
             *
             * @param enable if {@code true}, enable navigation, otherwise disable it
             */
            void setNextEnabled(boolean enable);
        
            /**
             * Makes the 'next' button visible or invisible.
             *
             * @param visible if {@code true} makes the button visible, otherwise makes it invisible.
             */
            void setNextVisible(boolean visible);
        
            /**
             * Sets the text for the 'next' button.
             *
             * @param text the button text. May be {@code null}
             */
            void setNextText(String text);
        
            /**
             * Sets the icon for the 'next' button.
             *
             * @param icon the icon. May be {@code null}
             */
            void setNextIcon(Icon icon);
        
            /**
             * Determines if the previous panel may be navigated to.
             *
             * @return {@code true} if the previous panel may be navigated to
             */
            boolean isPreviousEnabled();
        
            /**
             * Determines if the previous panel may be navigated to.
             *
             * @param enable if {@code true}, enable navigation, otherwise disable it
             */
            void setPreviousEnabled(boolean enable);
        
            /**
             * Makes the 'previous' button visible/invisible.
             *
             * @param visible if {@code true} makes the button visible, otherwise makes it invisible.
             */
            void setPreviousVisible(boolean visible);
        
            /**
             * Sets the text for the 'previous' button.
             *
             * @param text the button text. May be {@code null}
             */
            void setPreviousText(String text);
        
            /**
             * Sets the icon for the 'previous' button.
             *
             * @param icon the icon. May be {@code null}
             */
            void setPreviousIcon(Icon icon);
        
            /**
             * Determines if the 'quit' button is enabled.
             *
             * @return {@code true} if the 'quit' button is enabled
             */
            boolean isQuitEnabled();
        
            /**
             * Determines if the 'quit' button is enabled.
             *
             * @param enable if {@code true}, enable quit, otherwise disable it
             */
            void setQuitEnabled(boolean enable);
        
            /**
             * Makes the 'quit' button visible/invisible.
             *
             * @param visible if {@code true} makes the button visible, otherwise makes it invisible.
             */
            void setQuitVisible(boolean visible);
        
            /**
             * Sets the text for the 'quit' button.
             *
             * @param text the button text. May be {@code null}
             */
            void setQuitText(String text);
        
            /**
             * Sets the icon for the 'quit' button.
             *
             * @param icon the icon. May be {@code null}
             */
            void setQuitIcon(Icon icon);
        
            /**
             * Navigates to the next panel.
             *
             * @return {@code true} if the next panel was displayed, or {@code false} if the last panel is displayed
             */
            boolean next();
        
            /**
             * Navigates to the previous panel.
             *
             * @return {@code true} if the previous panel was displayed, or {@code false} if the first panel is displayed
             */
            boolean previous();
        
            /**
             * Quits installation, if quit is enabled, and installation is complete.
             * <p/>
             * This method does not return if the quit is accepted.
             */
            void quit();
        }
        

        To use this, either specify it in your panel/installer listener constructor, and it will be injected, or use InstallerFrame.getNavigator().

        The changes can be accessed via https://github.com/izpack/izpack/pull/24

        I've ditched the VetoableEventListener support for now. If you want it, raise a new JIRA.

        Show
        Tim Anderson added a comment - Here's the new API. Amongst other things, it allows you enable/disable quit, and make it visible/invisible. public interface Navigator { /** * Determines if the next panel may be navigated to. * * @return {@code true} if the next panel may be navigated to */ boolean isNextEnabled(); /** * Determines if the next panel may be navigated to. * * @param enable if {@code true}, enable navigation, otherwise disable it */ void setNextEnabled(boolean enable); /** * Makes the 'next' button visible or invisible. * * @param visible if {@code true} makes the button visible, otherwise makes it invisible. */ void setNextVisible(boolean visible); /** * Sets the text for the 'next' button. * * @param text the button text. May be {@code null} */ void setNextText(String text); /** * Sets the icon for the 'next' button. * * @param icon the icon. May be {@code null} */ void setNextIcon(Icon icon); /** * Determines if the previous panel may be navigated to. * * @return {@code true} if the previous panel may be navigated to */ boolean isPreviousEnabled(); /** * Determines if the previous panel may be navigated to. * * @param enable if {@code true}, enable navigation, otherwise disable it */ void setPreviousEnabled(boolean enable); /** * Makes the 'previous' button visible/invisible. * * @param visible if {@code true} makes the button visible, otherwise makes it invisible. */ void setPreviousVisible(boolean visible); /** * Sets the text for the 'previous' button. * * @param text the button text. May be {@code null} */ void setPreviousText(String text); /** * Sets the icon for the 'previous' button. * * @param icon the icon. May be {@code null} */ void setPreviousIcon(Icon icon); /** * Determines if the 'quit' button is enabled. * * @return {@code true} if the 'quit' button is enabled */ boolean isQuitEnabled(); /** * Determines if the 'quit' button is enabled. * * @param enable if {@code true}, enable quit, otherwise disable it */ void setQuitEnabled(boolean enable); /** * Makes the 'quit' button visible/invisible. * * @param visible if {@code true} makes the button visible, otherwise makes it invisible. */ void setQuitVisible(boolean visible); /** * Sets the text for the 'quit' button. * * @param text the button text. May be {@code null} */ void setQuitText(String text); /** * Sets the icon for the 'quit' button. * * @param icon the icon. May be {@code null} */ void setQuitIcon(Icon icon); /** * Navigates to the next panel. * * @return {@code true} if the next panel was displayed, or {@code false} if the last panel is displayed */ boolean next(); /** * Navigates to the previous panel. * * @return {@code true} if the previous panel was displayed, or {@code false} if the first panel is displayed */ boolean previous(); /** * Quits installation, if quit is enabled, and installation is complete. * <p/> * This method does not return if the quit is accepted. */ void quit(); } To use this, either specify it in your panel/installer listener constructor, and it will be injected, or use InstallerFrame.getNavigator(). The changes can be accessed via https://github.com/izpack/izpack/pull/24 I've ditched the VetoableEventListener support for now. If you want it, raise a new JIRA.
        Hide
        Tim Anderson added a comment -

        Pull request merged.

        Show
        Tim Anderson added a comment - Pull request merged.

          People

          • Assignee:
            Tim Anderson
            Reporter:
            Alwyn Schoeman
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: