001package votorola.a.web.wic; // Copyright 2008, 2012-2013, Michael Allan.  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE.
002
003import org.apache.wicket.*;
004import org.apache.wicket.feedback.*;
005import org.apache.wicket.markup.html.*;
006import org.apache.wicket.markup.html.basic.*;
007import org.apache.wicket.markup.html.link.*;
008import org.apache.wicket.markup.repeater.*;
009import votorola.g.lang.*;
010import votorola.g.locale.*;
011import votorola.g.web.wic.*;
012
013
014/** A general purpose message page for displaying messages outside their page of origin.
015  * This is intended for exceptional messages that can suffer a generic presentation
016  * removed from the context of the source page.
017  *
018  *     @see <a href='../../../../../../a/web/wic/WP_Message.html'
019  *                                 target='_top'>WP_Message.html</a>
020  */
021public @ThreadRestricted("wicket") final class WP_Message extends VPageHTML
022{
023    // It cannot be stateless.  It is normally preconstructed and set as the response page
024    // (a redirect).  Therefore it is held in the session and is stateful.
025
026
027    /** Constructs a WP_Message that displays the session's feedback messages and then
028      * clears them.
029      */
030    public WP_Message()
031    {
032        final VRequestCycle cycle = VRequestCycle.get();
033     // add( new WC_NavigationHead( "navHead", WP_Message.this, cycle )); // add to all constructors
034     /// but using its login facility lands user back on this page, which says "Something is wrong"
035
036      // Title
037      // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
038        {
039            final String title = cycle.bunW().l( "a.web.wic.WP_Message.sessionFeedbackDump" );
040            add( new Label( "title", title ));
041            add( new Label( "titleH", title ));
042        }
043
044      // Messages
045      // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
046        messagesDiv = new WebMarkupContainer( "messages" );
047        add( messagesDiv );
048
049        final RepeatingView repeating = new RepeatingView( "messageRepeating" );
050        final FeedbackMessages mm = VSession.get().getFeedbackMessages();
051        for( Object o: mm.messages( /*filter*/null ))
052        {
053            final FeedbackMessage m = (FeedbackMessage)o;
054            final WebMarkupContainer y = new WebMarkupContainer( repeating.newChildId() );
055         // final Label body = new Label( "messageRepeating-body", m.getMessage().toString() );
056            final Label body = new Label( "messageRepeating-body", m.toString() );
057         // if( message.isWarning() ) VPageHTML.appendStyleClass( label, "invalid" );
058            body.setRenderBodyOnly( true );
059            y.add( body );
060            repeating.add( y );
061        }
062        mm.clear(); // or ought I call Session.cleanupFeedbackMessages()?
063        messagesDiv.add( repeating );
064
065      // Links
066      // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
067        init();
068    }
069
070
071
072    /** Constructs a WP_Message that displays the specified messages.
073      */
074    public WP_Message( final String title, final Object... messages )
075    {
076        final VRequestCycle cycle = VRequestCycle.get();
077
078      // Title
079      // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
080        add( new Label( "title", title ));
081        add( new Label( "titleH", title ));
082
083      // Messages
084      // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
085        messagesDiv = new WebMarkupContainer( "messages" );
086        add( messagesDiv );
087
088        final RepeatingView repeating = new RepeatingView( "messageRepeating" );
089        for( Object o: messages )
090        {
091            final WebMarkupContainer y = new WebMarkupContainer( repeating.newChildId() );
092            y.add( new Label( "messageRepeating-body", o.toString() ).setRenderBodyOnly( true ));
093            repeating.add( y );
094        }
095        messagesDiv.add( repeating );
096
097      // Links
098      // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
099        init();
100    }
101
102
103
104    private void init() { add( linkRepeating ); }
105
106
107
108   // ------------------------------------------------------------------------------------
109
110
111    /** Adds links to the bottom of the page.  The ID of each link must be 'link'.
112      *
113      *     @return this message page.
114      */
115    public WP_Message addLinks( final AbstractLink... links )
116    {
117        for( AbstractLink link: links )
118        {
119            assert "link".equals( link.getId() );
120            final WebMarkupContainer y = new WebMarkupContainer( linkRepeating.newChildId() );
121            y.add( link );
122            linkRepeating.add( y );
123        }
124        return WP_Message.this;
125    }
126
127
128
129    /** Sets preformatted styling, effectively displaying the messages in 'pre' tags as
130      * opposed to 'p'.
131      *
132      *     @return this message page.
133      */
134    public final WP_Message pre()
135    {
136        appendStyleClass( messagesDiv, "pre" );
137        return WP_Message.this;
138    }
139
140
141
142    private final RepeatingView linkRepeating = new RepeatingView( "linkRepeating" );
143
144
145
146    private final WebMarkupContainer messagesDiv;
147
148
149}