KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > ui > component > FilterPanelComponent


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11  * the license for the specific language governing your rights and limitations.
12  *
13  * @created Aug 31, 2005
14  * @author James Dixon
15  */

16
17 package org.pentaho.ui.component;
18
19 import java.io.File JavaDoc;
20 import java.io.IOException JavaDoc;
21 import java.util.HashMap JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.Map JavaDoc;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.dom4j.Document;
28 import org.pentaho.core.solution.ActionResource;
29 import org.pentaho.core.solution.IActionResource;
30 import org.pentaho.core.system.PentahoSystem;
31 import org.pentaho.core.ui.IPentahoUrlFactory;
32 import org.pentaho.ui.XmlComponent;
33
34 /**
35  * This class provides a user interface that lets users select items from lists
36  * or radio buttons. The selections are used by other components to filter
37  * queries used to populate data.
38  *
39  * @author James Dixon
40  */

41 public class FilterPanelComponent extends XmlComponent {
42
43     /**
44      *
45      */

46     private static final long serialVersionUID = 700681534058825526L;
47
48     private static final Log logger = LogFactory.getLog(FilterPanelComponent.class);
49
50     private String JavaDoc definitionPath;
51
52     private FilterPanel filterPanel;
53
54     private String JavaDoc xslName;
55
56     private Map JavaDoc defaultValues;
57
58     public FilterPanelComponent(String JavaDoc definitionPath, String JavaDoc xslName, IPentahoUrlFactory urlFactory, List JavaDoc messages) {
59         super(urlFactory, messages, null);
60         this.definitionPath = definitionPath;
61         if (xslName == null) {
62             // use a default XSL
63
xslName = "FilterPanelDefault.xsl"; //$NON-NLS-1$
64
}
65         String JavaDoc info[] = PentahoSystem.parseActionString(definitionPath);
66         if (info != null && info.length == 3) {
67             setSourcePath(info[0] + File.separator + info[1]);
68         }
69         this.xslName = xslName;
70         defaultValues = new HashMap JavaDoc();
71     }
72
73     public void setDefaultValue(String JavaDoc filterName, String JavaDoc[] defaultValue) {
74         defaultValues.put(filterName, defaultValue);
75     }
76
77     public Log getLogger() {
78         return logger;
79     }
80
81     public boolean validate() {
82         return true;
83     }
84
85     public List JavaDoc getFilters() {
86         return filterPanel.getFilters();
87     }
88
89     public boolean init() {
90         if (filterPanel == null) {
91             // load the XML document that defines the dial
92
ActionResource resource = new ActionResource("", IActionResource.SOLUTION_FILE_RESOURCE, "text/xml", //$NON-NLS-1$ //$NON-NLS-2$
93
definitionPath);
94             Document filterDocument = null;
95             try {
96                 filterDocument = PentahoSystem.getSolutionRepository(getSession()).getResourceAsDocument(resource);
97                 filterPanel = getFilterPanel(filterDocument);
98                 return true;
99             } catch (IOException JavaDoc e) {
100             }
101             return false;
102         } else {
103             return true;
104         }
105     }
106
107     public Document getXmlContent() {
108
109         boolean ok = filterPanel.populate(getParameterProviders(), defaultValues);
110
111         if (!ok) {
112             // TODO surface this error
113
}
114
115         Document xForm = filterPanel.getXForm();
116
117         setXsl("text/html", xslName); //$NON-NLS-1$
118

119         return xForm;
120     }
121
122     private FilterPanel getFilterPanel(Document filterDocument) {
123         FilterPanel newFilterPanel = new FilterPanel(getSession(), filterDocument, getUrlFactory(), this);
124         return newFilterPanel;
125     }
126
127 }
128
Popular Tags