KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > gui > dialog > DialogDate


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.gui.dialog;
14
15 import info.magnolia.cms.core.Content;
16 import info.magnolia.cms.i18n.MessagesManager;
17
18 import java.text.SimpleDateFormat JavaDoc;
19 import java.util.Calendar JavaDoc;
20 import java.util.Date JavaDoc;
21
22 import javax.jcr.PropertyType;
23 import javax.jcr.RepositoryException;
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25 import javax.servlet.http.HttpServletResponse JavaDoc;
26
27
28 /**
29  * @author Vinzenz Wyser
30  * @version 2.0
31  */

32 public class DialogDate extends DialogEditWithButton {
33
34     /**
35      * Empty constructor should only be used by DialogFactory.
36      */

37     protected DialogDate() {
38     }
39
40     /**
41      * @see info.magnolia.cms.gui.dialog.DialogInterface#init(HttpServletRequest, HttpServletResponse, Content, Content)
42      */

43     public void init(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, Content websiteNode, Content configNode)
44         throws RepositoryException {
45         super.init(request, response, websiteNode, configNode);
46         // set buttonlabel in config
47
this.getButton().setLabel(MessagesManager.get(getRequest(), "dialog.date.select")); //$NON-NLS-1$
48
this.getButton().setSaveInfo(false);
49         this.getButton().setOnclick(
50             "mgnlDialogOpenCalendar('" + this.getName() + "'," + this.getConfigValue("time", "false") + ");"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
51
String JavaDoc format = "yyyy-MM-dd"; //$NON-NLS-1$
52
String JavaDoc pattern = "XXXX-XX-XX"; //$NON-NLS-1$
53
if (!this.getConfigValue("time", "false").equals("false")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
54
format += "'T'HH:mm:ss"; //$NON-NLS-1$
55
pattern += "TXX:XX:XX"; //$NON-NLS-1$
56
}
57         this.setConfig("onchange", "mgnlDialogDatePatternCheck(this,'" + pattern + "');"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
58
if (this.getWebsiteNode() != null && this.getWebsiteNode().getNodeData(this.getName()).isExist()) {
59             Calendar JavaDoc valueCalendar = this.getWebsiteNode().getNodeData(this.getName()).getDate();
60             Date JavaDoc valueDate = valueCalendar.getTime();
61             SimpleDateFormat JavaDoc sdf = new SimpleDateFormat JavaDoc(format);
62             this.setValue(sdf.format(valueDate));
63             this.clearWebsiteNode(); // workaround so the value is taken... hm, pfusch
64
}
65         // check this!
66
this.setConfig("type", this.getConfigValue("type", PropertyType.TYPENAME_DATE)); //$NON-NLS-1$ //$NON-NLS-2$
67
}
68
69 }
70
Popular Tags