KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > pages > riot > chooser > InternalLinkField


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1
3  * The contents of this file are subject to the Mozilla Public License Version
4  * 1.1 (the "License"); you may not use this file except in compliance with
5  * the License. You may obtain a copy of the License at
6  * http://www.mozilla.org/MPL/
7  *
8  * Software distributed under the License is distributed on an "AS IS" basis,
9  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10  * for the specific language governing rights and limitations under the
11  * License.
12  *
13  * The Original Code is Riot.
14  *
15  * The Initial Developer of the Original Code is
16  * Neteye GmbH.
17  * Portions created by the Initial Developer are Copyright (C) 2006
18  * the Initial Developer. All Rights Reserved.
19  *
20  * Contributor(s):
21  * Felix Gnass [fgnass at neteye dot de]
22  *
23  * ***** END LICENSE BLOCK ***** */

24 package org.riotfamily.pages.riot.chooser;
25
26 import java.io.PrintWriter JavaDoc;
27
28 import org.riotfamily.common.markup.DocumentWriter;
29 import org.riotfamily.common.markup.Html;
30 import org.riotfamily.forms.DHTMLElement;
31 import org.riotfamily.forms.MessageUtils;
32 import org.riotfamily.forms.TemplateUtils;
33 import org.riotfamily.forms.element.TextField;
34 import org.riotfamily.forms.resource.FormResource;
35 import org.riotfamily.forms.resource.ResourceElement;
36 import org.riotfamily.forms.resource.Resources;
37 import org.riotfamily.forms.resource.ScriptResource;
38 import org.riotfamily.forms.resource.StylesheetResource;
39
40 public class InternalLinkField extends TextField implements ResourceElement,
41     DHTMLElement {
42
43     private static final ScriptResource RESOURCE = new ScriptResource(
44             "riot-js/window-callback.js", "WindowCallback",
45             new FormResource[] {
46                 Resources.PROTOTYPE,
47                 new StylesheetResource("style/internal-link-field.css")
48             }
49     );
50
51     private String JavaDoc chooserUrl = "/riot/pages/chooser";
52
53
54     public InternalLinkField() {
55         setStyleClass("text internal-link");
56     }
57
58     public String JavaDoc getChooserUrl() {
59         return this.chooserUrl;
60     }
61
62     public void setChooserUrl(String JavaDoc chooserUrl) {
63         this.chooserUrl = chooserUrl;
64     }
65
66     public FormResource getResource() {
67         return RESOURCE;
68     }
69
70     public String JavaDoc getInitScript() {
71         return TemplateUtils.getInitScript(this);
72     }
73
74     public String JavaDoc getButtonId() {
75         return getId() + "-button";
76     }
77
78     public void renderInternal(PrintWriter JavaDoc writer) {
79         DocumentWriter doc = new DocumentWriter(writer);
80         doc.start(Html.DIV).attribute(Html.COMMON_CLASS, "internal-link");
81         doc.start(Html.DIV).attribute(Html.COMMON_CLASS, "input-wrapper");
82         doc.body();
83
84         super.renderInternal(writer);
85
86         doc.end();
87         String JavaDoc buttonLabel = MessageUtils.getMessage(this,
88                 "internalLinkField.buttonLabel", null, "Internal ...");
89
90         doc.startEmpty(Html.INPUT)
91                 .attribute(Html.INPUT_TYPE, "button")
92                 .attribute(Html.INPUT_VALUE, buttonLabel)
93                 .attribute(Html.COMMON_ID, getButtonId())
94                 .attribute(Html.COMMON_CLASS, "button")
95                 .closeAll();
96     }
97
98 }
99
Popular Tags