d4bdc115b3c0a57264c773f0b94c6009ce7f7d16
[photos] / src / main / java / org / wamblee / photos / wicket / BasePage.java
1 /*
2  * Copyright 2005-2010 the original author or authors.
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.wamblee.photos.wicket;
17
18 import org.apache.wicket.markup.html.CSSPackageResource;
19 import org.apache.wicket.markup.html.WebPage;
20 import org.apache.wicket.markup.html.basic.Label;
21 import org.apache.wicket.markup.html.link.Link;
22 import org.apache.wicket.markup.html.panel.FeedbackPanel;
23 import org.apache.wicket.model.IModel;
24 import org.wamblee.wicket.behavior.TitleAttributeTooltipBehavior;
25 import org.wamblee.wicket.css.ResetCssBehavior;
26 import org.wamblee.wicket.page.ExpireBehavior;
27 import org.wamblee.wicket.page.WebApplicationBasePage;
28
29 public class BasePage extends WebApplicationBasePage {
30
31     private boolean isExpired = false;
32
33     public BasePage() {
34         this(null);
35     }
36
37     public BasePage(IModel aModel) {
38         super(aModel);
39         add(new ResetCssBehavior());
40         add(new TitleAttributeTooltipBehavior());
41         add(CSSPackageResource.getHeaderContribution(BasePage.class,
42             "photos.css"));
43         disableCaching();
44
45         add(new FeedbackPanel("feedback"));
46         add(new Label("title", getTitle()));
47
48         addBehavior(new ExpireBehavior() {
49             @Override
50             protected boolean isExpired(WebPage aPage) {
51                 return isExpired;
52             }
53         });
54
55         add(new Link("logout") {
56             @Override
57             public void onClick() {
58                 getRequestCycle().getSession().invalidate();
59             }
60         });
61     }
62
63     public void setExpired(boolean aExpired) {
64         isExpired = aExpired;
65     }
66
67     private String getTitle() {
68         String name = getClass().getSimpleName();
69         name = name.replaceAll("([A-Z]+)([A-Z][a-z])", "$1 $2");
70         name = name.replaceAll("[A-Z]+", " $0");
71         name = name.replaceAll("^ ", "");
72         name = name.replaceAll("  ", " ");
73         return name;
74     }
75 }