Changeset 2970


Ignore:
Timestamp:
06/01/13 11:24:46 (11 years ago)
Author:
keeloo
Message:

Some more work on theming. Now it is possible to add themes.

Location:
vlo/trunk/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • vlo/trunk/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/VloWebApplication.java

    r2965 r2970  
    55import eu.clarin.cmdi.vlo.dao.SearchResultsDao;
    66import eu.clarin.cmdi.vlo.pages.BasePage;
    7 import eu.clarin.cmdi.vlo.pages.FacetBoxPanel;
    8 import eu.clarin.cmdi.vlo.pages.FacetHeaderPanel;
    9 import eu.clarin.cmdi.vlo.pages.FacetLinkPanel;
     7import eu.clarin.cmdi.vlo.pages.BasePanel;
    108import eu.clarin.cmdi.vlo.pages.FacetedSearchPage;
    11 import eu.clarin.cmdi.vlo.pages.ShowResultPage;
    129import java.util.Map;
    1310import javax.servlet.ServletContext;
     
    2219
    2320/**
    24  *
    25  * {@literal V}irtual {@literal L}anguage {@literal O}bservatory web
    26  * application<br><br>
     21 * Virtual Language Observatory web application<br><br>
    2722 *
    2823 * <describe VLO>
     
    3227 */
    3328public class VloWebApplication extends WebApplication {
    34 
    35     /**
    36      * Remember the theme to be used<br><br>
    37      *
    38      * The theme parameter is one in a map of parameters that is associated
    39      * with a session rather than with some page or pages.
    40      */
    41     private String theme = "defaultTheme";
    42    
    43     /**
    44      * Get the name of the theme applied currently<br><br>
    45      *
    46      * @return the theme
    47      */
    48     public String getThemeName (){
    49         // maybe this method will not be needed anymore; query
    50         // the session parameters instead
    51         return theme;
    52     }
    53    
    54     /**
    55      * Set the name of the theme applied or to be applied
    56      */
    57     public void setThemeName (String theme){
    58         // store the name as a session parameter
    59         this.theme = theme;
    60     }
    61    
    62     /**
    63      * Install a theme
    64      *
    65      * @param name the name of the theme to be installed
    66      */
    67     public void setTheme (String name){
    68        // at some point invoke setThemeName (name)
    69        // at some point add the theme to the list of session parameters
    70     }
    71    
    72     /**
    73      * Remember a map of session level parameters<br><br>
    74      */
    75     PageParameters sessionParameters = new PageParameters ("theme", "defaultTheme");
    76    
    77     public PageParameters getSessionParameters (){
    78        
    79         return sessionParameters;
    80     }
    81    
    82     /**
    83      * Add the parameters persisting with the application object to an a list
    84      * of parameters existing outside the object.<br><br>
    85      *
    86      * Invoke this method from a component, after generating a list of
    87      * parameters.
    88      *
    89      * @param parameters the existing list of parameters
    90      * @return the concatenation of the existing list and the parameters
    91      * persisting with the application object.
    92      */
    93     public PageParameters addSessionParameters(PageParameters parameters) {
    94 
    95         // get the theme parameter from the application
    96 
    97         parameters.add("theme", getThemeName());
     29   
     30    /**
     31     * Remember the parameters that should persist in URLs to VLO pages <br><br>
     32     */
     33    public PageParameters persistentParameters = new PageParameters();
     34           
     35    /**
     36     * Reflect the persistent parameters in the page parameter map<br><br>
     37     *
     38     * @param parameters a page parameter map
     39     * @return the page parameter map including the current persistent parameters
     40     */
     41    public PageParameters reflectPersistentParameters(PageParameters parameters) {
     42       
     43        parameters.putAll(persistentParameters);
     44
     45        // parameters.add("theme", "defaultTheme");
    9846        return parameters;
    9947    }
     
    12876            // check if there is a theme parameter       
    12977            String[] object = map.get("theme");
    130            
     78                       
    13179            if (object == null) {
    132                 // no theme in the URL, do not change the value of the parameter
     80                // no theme choosen, keep the current one
    13381            } else {
    134                 // try to replace the reference via the indexs
    135                 if (theme.equals(object[0])){
    136                     // keep the theme that was installed on a previous request
     82                // check if the users requests a different theme
     83                if (object[0].matches(currentTheme.name)) {
     84                    // current theme requested, nothing to do
    13785                } else {
    138                     // theme not installed yet, first: remember it
    139                     VloWebApplication.this.setThemeName(object[0]);
    140                     // after that: determine the intended css and "install" it
    141                     // determine the intended picture and install it
     86                    // different theme requested, compose it
     87                    currentTheme = new Theme (object[0]);
    14288                }
    14389            }
     
    164110        return cycle;
    165111    }
    166 
    167     private SearchResultsDao searchResults;
    168    
     112   
     113    /**
     114     * Theme currently applied in the VLO web application
     115     */
     116    public Theme currentTheme = new Theme ("defaultTheme");
     117
     118    /**
     119     * A theme is defined by a CSS file, and two image files
     120     */
     121    public class Theme {
     122
     123        public String name, topLeftImage, topRightImage, cssFile;
     124
     125        /**
     126         * Compose a theme<br><br>
     127         *
     128         * @param name the name of the theme to be composed
     129         */
     130        public Theme(String themeName) {
     131
     132            if (themeName.matches("Clarin-d")) {
     133                // select the Clarin-d theme's components
     134               
     135                topLeftImage = "Images/topleftvlo.gif";
     136                topRightImage = "Images/toprightvlo.gif";
     137                cssFile = "css/main.css";
     138                name = "Clarin-d";
     139            } else {
     140                // select the default theme elements
     141               
     142                topLeftImage = "Images/topleftvlo.gif";
     143                topRightImage = "Images/toprightvlo.gif";
     144                cssFile = "css/main.css";
     145                name = "defaultTheme";
     146            }
     147            // remember the theme as a persistent parameter
     148            persistentParameters.put("theme", name);
     149        }
     150    }
     151
    169152    /**
    170153     * Flag indicating whether or not the application object lives in a web
     
    187170             * method, uniform approach might be the most prefarable one.
    188171             */
    189             ShowResultPage.setWebApp(this);
    190             FacetBoxPanel.setWebApp(this);
    191             FacetHeaderPanel.setWebApp(this);
    192             FacetLinkPanel.setWebApp(this);
    193             FacetedSearchPage.setWebApp(this);
     172            BasePage.setWebApp(this);
     173            BasePanel.setWebApp(this);
    194174           
    195175            // install theme -> compose theme
     
    209189        }
    210190
    211         // start the application
    212 
     191        // creata an object referring to the search results
    213192        searchResults = new SearchResultsDao();       
    214     }
    215 
     193
     194        // hand over control to the application
     195    }
     196   
     197    // remember the search results
     198    private SearchResultsDao searchResults;
     199   
    216200    /**
    217201     * Web application constructor<br><br>
     
    245229     * will create an object that will not look for an external configuration
    246230     * file; it will exclusively rely on the packaged configuration. Typically,
    247      * the application's tests will send false to the application constructor.<br><br>
     231     * the application's tests will send false to the application constructor.
     232     * <br><br>
    248233     *
    249234     * @param inContext If and only if this parameter equals true. later on, the
  • vlo/trunk/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/pages/BasePage.java

    r2965 r2970  
    1111import org.apache.wicket.resource.ContextRelativeResource;
    1212
     13/**
     14 * Properties common to all VLO web application's page objects
     15 *
     16 * @author keeloo
     17 */
    1318public class BasePage extends WebPage implements IHeaderContributor{
    1419   
     20    // reference to the web application object
     21    static VloWebApplication webApp;
     22
     23    /**
     24     * Make sure every web application object sends this message
     25     *
     26     * @param vloWebApplication reference to the web application object
     27     */
     28    public static void setWebApp(VloWebApplication vloWebApplication) {
     29        webApp = vloWebApplication;
     30    }
     31   
     32    /**
     33     * Install a VLO theme<br><br>
     34     *
     35     * A VLO theme is determined by a CSS file and a banner split in a left and
     36     * right image.
     37     *
     38     * The left part of the banner serves as a link to the faceted search page,
     39     * the 'local' home page. Next to this page there is the page the web
     40     * application is launched from. This home page is defined in the VloConfig
     41     * file.
     42     *   
     43     * @param parameters
     44     */
    1545    public BasePage(PageParameters parameters) {
     46
    1647        super(parameters);
    1748       
    18         // delete all parameters from the map, except theme
    19         String theme;
    20         theme = parameters.getKey("theme");
    21         if (theme == null){
    22             theme = "";
    23         }
    24         parameters = new PageParameters ();
    25         parameters.add("theme", theme);
     49        // set the applications local home page link to the faceted search page
     50        PageParameters homeLinkParameters = new PageParameters ();
    2651       
    27         // set the applications (local) homelink to the faceted search page
     52        webApp.reflectPersistentParameters(homeLinkParameters);
     53               
    2854                BookmarkablePageLink link = new BookmarkablePageLink("homeLink",
    29                 FacetedSearchPage.class, parameters);
     55                FacetedSearchPage.class, homeLinkParameters);
    3056        add(link);
    31                
     57                      
    3258        // refer to the the left part of the vlo banner as a resource
    3359        Resource leftImageRes;
    34         leftImageRes = new ContextRelativeResource("Images/topleftvlo.gif");
     60        leftImageRes = new ContextRelativeResource(webApp.currentTheme.topLeftImage);
    3561
    3662        // create the image
     
    4369        // refer to the right part of the vlo banner as a resource
    4470        Resource rightImageRes;
    45         rightImageRes = new ContextRelativeResource("Images/toprightvlo.gif");
     71        rightImageRes = new ContextRelativeResource(webApp.currentTheme.topRightImage);
    4672       
    4773        // create the image
     
    5379    }
    5480
     81    /**
     82     * Include the theme's CSS file in the HTML page<br><br>
     83     *
     84     * This method is invoked when Wicket renders a VLO page.
     85     *
     86     * @param response
     87     */
    5588    @Override
    5689    public void renderHead(IHeaderResponse response) {
    5790               
    58         response.renderCSSReference("css/main.css");
     91        response.renderCSSReference(webApp.currentTheme.cssFile);
    5992    }
    6093   
  • vlo/trunk/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/pages/FacetBoxPanel.java

    r2965 r2970  
    66import java.util.List;
    77import java.util.Set;
    8 
    98import org.apache.solr.client.solrj.response.FacetField;
    109import org.apache.solr.client.solrj.response.FacetField.Count;
     
    1514import org.apache.wicket.markup.html.list.ListItem;
    1615import org.apache.wicket.markup.html.list.ListView;
    17 import org.apache.wicket.markup.html.panel.Panel;
    1816import org.apache.wicket.model.IModel;
    1917import org.apache.wicket.model.Model;
    2018
    21 public class FacetBoxPanel extends Panel {
     19public class FacetBoxPanel extends BasePanel {
    2220    private static final Set<String> IGNORABLE_VALUES = new HashSet<String>();
    2321    static {
     
    3129    private FacetModel facetModel;
    3230    private int maxNrOfFacetValues;
    33 
    34     // reference to the web application object
    35     static VloWebApplication webApp;
    36    
    37     /**
    38      * Make sure every web application object sends this message
    39      *
    40      * @param vloWebApplication reference to the web application object
    41      */
    42     public static void setWebApp (VloWebApplication vloWebApplication){
    43         webApp = vloWebApplication;
    44     }
    4531   
    4632    public FacetBoxPanel(String id, IModel<FacetField> model) {
     
    8167        pageParameters.add(ShowAllFacetValuesPage.FACET_MIN_OCCURS, "1");
    8268
    83         pageParameters = webApp.addSessionParameters(pageParameters);
     69        pageParameters = webApp.reflectPersistentParameters(pageParameters);
    8470       
    8571        add(new BookmarkablePageLink("showMore", ShowAllFacetValuesPage.class, pageParameters) {
  • vlo/trunk/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/pages/FacetHeaderPanel.java

    r2965 r2970  
    55import org.apache.wicket.markup.html.basic.Label;
    66import org.apache.wicket.markup.html.link.BookmarkablePageLink;
    7 import org.apache.wicket.markup.html.panel.Panel;
    87import org.apache.wicket.model.IModel;
    98
    10 public class FacetHeaderPanel extends Panel {
     9public class FacetHeaderPanel extends BasePanel {
    1110
    1211    private static final long serialVersionUID = 1L;
    13    
    14     // reference to the web application object
    15     static VloWebApplication webApp;
    16    
    17     /**
    18      * Make sure every web application object sends this message
    19      *
    20      * @param vloWebApplication reference to the web application object
    21      */
    22     public static void setWebApp (VloWebApplication vloWebApplication){
    23         webApp = vloWebApplication;
    24     }
    2512
    2613    public FacetHeaderPanel(String id, IModel<FacetModel> model, final SearchPageQuery query) {
     
    3017        PageParameters pageParameters = copy.getPageParameters();
    3118       
    32         pageParameters = webApp.addSessionParameters(pageParameters);
     19        pageParameters = webApp.reflectPersistentParameters(pageParameters);
    3320       
    3421        add(new BookmarkablePageLink("allLink", FacetedSearchPage.class, pageParameters));
  • vlo/trunk/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/pages/FacetLinkPanel.java

    r2965 r2970  
    11package eu.clarin.cmdi.vlo.pages;
    22
    3 import eu.clarin.cmdi.vlo.VloWebApplication;
    43import org.apache.solr.client.solrj.response.FacetField.Count;
    54import org.apache.wicket.PageParameters;
    6 import org.apache.wicket.Session;
    75import org.apache.wicket.markup.html.basic.Label;
    86import org.apache.wicket.markup.html.link.BookmarkablePageLink;
    97import org.apache.wicket.markup.html.link.Link;
    10 import org.apache.wicket.markup.html.panel.Panel;
    118import org.apache.wicket.model.IModel;
    129
    13 public class FacetLinkPanel extends Panel {
     10public class FacetLinkPanel extends BasePanel {
    1411
    1512    private static final long serialVersionUID = 1L;
    16    
    17     // reference to the web application object
    18     static VloWebApplication webApp;
    19    
    20     /**
    21      * Make sure every web application object sends this message
    22      *
    23      * @param vloWebApplication reference to the web application object
    24      */
    25     public static void setWebApp (VloWebApplication vloWebApplication){
    26         webApp = vloWebApplication;
    27     }
    2813
    2914    public FacetLinkPanel(String id, IModel<Count> model, final SearchPageQuery query) {
     
    3520        PageParameters params = q.getPageParameters();
    3621
    37         params = webApp.addSessionParameters(params);
     22        params = webApp.reflectPersistentParameters(params);
    3823       
    3924        Link<Count> facetLink = new BookmarkablePageLink("facetLink", FacetedSearchPage.class, params);
  • vlo/trunk/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/pages/FacetedSearchPage.java

    r2969 r2970  
    3838    private final static AutoCompleteDao autoCompleteDao = new AutoCompleteDao();
    3939   
    40     // reference to the web application object
    41     static VloWebApplication webApp;
    42    
    43     /**
    44      * Make sure every web application object sends this message
    45      *
    46      * @param vloWebApplication reference to the web application object
    47      */
    48     public static void setWebApp (VloWebApplication vloWebApplication){
    49         webApp = vloWebApplication;
    50     }
    51    
    5240    /**
    5341     * @param parameters Page parameters
     
    8674            PageParameters pageParameters = query.getPageParameters();
    8775
    88             pageParameters = webApp.addSessionParameters(pageParameters);
     76            pageParameters = webApp.reflectPersistentParameters(pageParameters);
    8977           
    9078            setResponsePage(FacetedSearchPage.class, pageParameters);
  • vlo/trunk/vlo_web_app/src/main/java/eu/clarin/cmdi/vlo/pages/ShowResultPage.java

    r2969 r2970  
    8686            newParam.putAll(query.getPageParameters());
    8787            // add the persistent parameters to this map
    88             newParam = webApp.addSessionParameters(newParam);
     88            newParam = webApp.reflectPersistentParameters(newParam);
    8989           
    9090            BookmarkablePageLink<String> backLink = new BookmarkablePageLink<String>("backLink", FacetedSearchPage.class, newParam);
     
    406406        add(link);
    407407    }
    408    
    409     // reference to the web application object
    410     static VloWebApplication webApp;
    411    
    412     /**
    413      * Make sure every web application object sends this message
    414      *
    415      * @param vloWebApplication reference to the web application object
    416      */
    417     public static void setWebApp (VloWebApplication vloWebApplication){
    418         webApp = vloWebApplication;
    419     }
    420408
    421409    public static BookmarkablePageLink<ShowResultPage> createBookMarkableLink(String linkId, SearchPageQuery query, String docId) {
     
    423411        pageParameters.put(ShowResultPage.PARAM_DOC_ID, WicketURLEncoder.QUERY_INSTANCE.encode(docId));
    424412       
    425         webApp.addSessionParameters(pageParameters);
     413        webApp.reflectPersistentParameters(pageParameters);
    426414       
    427415        BookmarkablePageLink<ShowResultPage> docLink = new BookmarkablePageLink<ShowResultPage>(linkId, ShowResultPage.class,
Note: See TracChangeset for help on using the changeset viewer.