KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > editors > report > AttributePanel


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.editors.report;
20
21 import java.awt.*;
22 import java.awt.event.*;
23 import java.util.*;
24 import java.util.List JavaDoc;
25
26 import javax.swing.*;
27 import javax.swing.tree.*;
28
29 import org.openharmonise.him.*;
30 import org.openharmonise.him.editors.report.rqom.*;
31 import org.openharmonise.him.editors.report.swing.*;
32 import org.openharmonise.him.harmonise.*;
33 import org.openharmonise.vfs.*;
34 import org.openharmonise.vfs.servers.ServerList;
35
36
37 /**
38  * @author MATT TREANOR
39  * @version $Revision: 1.1 $
40  *
41  */

42 public class AttributePanel extends JPanel implements LayoutManager, ActionListener {
43
44     private ReportQuery m_reportQuery;
45     private JComboTree m_propertyCombo;
46     private JLabel m_propLabel;
47     private String JavaDoc m_sLabelText;
48     private List JavaDoc m_metadataList;
49     
50
51     /**
52      * Contructs new AttributePanel
53      */

54     public AttributePanel(ReportQuery query, List JavaDoc list, String JavaDoc label) {
55         super();
56         this.m_metadataList = list;
57         this.m_reportQuery = query;
58         this.m_sLabelText = label;
59         this.setup();
60     }
61
62     /**
63      * Configures this component.
64      *
65      */

66     private void setup() {
67         this.setLayout(this);
68         
69         AbstractVirtualFileSystem vfs = ServerList.getInstance().getHarmoniseServer().getVFS();
70         
71         this.m_propertyCombo = new JComboTree();
72         this.m_propertyCombo.setResourceTreeFilter(new ReportResourceFilter(m_reportQuery));
73         this.m_propertyCombo.setActionCommand("PROPCOMBO");
74         this.m_propertyCombo.addActionListener(this);
75         this.m_propertyCombo.setAllowClear(false);
76         this.m_propertyCombo.setShowLeafNodes(true);
77         this.m_propertyCombo.setSelectedLeafOnly(true);
78         this.m_propertyCombo.setSelectionMode(TreeSelectionModel.CONTIGUOUS_TREE_SELECTION);
79         this.m_propertyCombo.addCollectionPath(HarmonisePaths.PATH_SYSTEM_PROPS);
80         this.m_propertyCombo.addCollectionPath(HarmonisePaths.PATH_PROPERTIES);
81         this.add(m_propertyCombo);
82         
83         if(this.m_metadataList.size()>0) {
84             Iterator iter = m_metadataList.iterator();
85             ArrayList paths = new ArrayList();
86             while(iter.hasNext()){
87                 Metadata metadata = (Metadata)iter.next();
88                 paths.add(metadata.getPath());
89             }
90             this.m_propertyCombo.setPaths(vfs, paths);
91         }
92
93         String JavaDoc fontName = "Dialog";
94         int fontSize = 11;
95         Font font = new Font(fontName, Font.PLAIN, fontSize);
96         
97         if(m_sLabelText!=null && m_sLabelText.length()>0){
98             this.m_propLabel = new JLabel(m_sLabelText);
99             this.m_propLabel.setFont(font);
100             this.add(this.m_propLabel);
101         }
102     }
103     /**
104      * Returns the metadata data.
105      *
106      * @return Data
107      */

108     public List JavaDoc getMetadataList() {
109         return this.m_metadataList;
110     }
111
112     /* (non-Javadoc)
113      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
114      */

115     public void removeLayoutComponent(Component comp) {
116     }
117
118     /* (non-Javadoc)
119      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
120      */

121     public void layoutContainer(Container parent) {
122         int x = 0;
123         int y = 0;
124         if(m_propLabel!=null){
125             this.m_propLabel.setSize(this.m_propLabel.getPreferredSize());
126             this.m_propLabel.setLocation(x, y);
127             y += 15;
128         }
129         
130         this.m_propertyCombo.setSize(this.m_propertyCombo.getPreferredSize());
131         this.m_propertyCombo.setLocation(x, y);
132     }
133
134     /* (non-Javadoc)
135      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
136      */

137     public void addLayoutComponent(String JavaDoc name, Component comp) {
138     }
139     public Dimension getPreferredSize() {
140         return new Dimension(220, 20);
141         
142     }
143
144     /* (non-Javadoc)
145      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
146      */

147     public Dimension minimumLayoutSize(Container parent) {
148         return this.getPreferredSize();
149     }
150
151     /* (non-Javadoc)
152      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
153      */

154     public Dimension preferredLayoutSize(Container parent) {
155         return this.getPreferredSize();
156     }
157
158     /* (non-Javadoc)
159      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
160      */

161     public void actionPerformed(ActionEvent e) {
162         if(e.getActionCommand().equals("PROPCOMBO")) {
163             this.m_metadataList = new ArrayList();
164             m_reportQuery.clearDisplayAttributes();
165             Iterator iter = this.m_propertyCombo.getPaths().iterator();
166             while(iter.hasNext()){
167                 String JavaDoc path = (String JavaDoc)iter.next();
168                 Metadata metadata = new Metadata(path, this.m_reportQuery);
169                 m_metadataList.add(metadata);
170                 this.m_reportQuery.addDisplayAttributes(metadata);
171             }
172             this.layoutContainer(null);
173             this.validateTree();
174             this.repaint();
175         }
176     }
177
178 }
Popular Tags