001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.him.editors.report;
020:
021: import java.awt.*;
022: import java.awt.event.*;
023: import java.util.*;
024: import java.util.List;
025:
026: import javax.swing.*;
027: import javax.swing.tree.*;
028:
029: import org.openharmonise.him.*;
030: import org.openharmonise.him.editors.report.rqom.*;
031: import org.openharmonise.him.editors.report.swing.*;
032: import org.openharmonise.him.harmonise.*;
033: import org.openharmonise.vfs.*;
034: import org.openharmonise.vfs.servers.ServerList;
035:
036: /**
037: * @author MATT TREANOR
038: * @version $Revision: 1.1 $
039: *
040: */
041: public class AttributePanel extends JPanel implements LayoutManager,
042: ActionListener {
043:
044: private ReportQuery m_reportQuery;
045: private JComboTree m_propertyCombo;
046: private JLabel m_propLabel;
047: private String m_sLabelText;
048: private List m_metadataList;
049:
050: /**
051: * Contructs new AttributePanel
052: */
053: public AttributePanel(ReportQuery query, List list, String label) {
054: super ();
055: this .m_metadataList = list;
056: this .m_reportQuery = query;
057: this .m_sLabelText = label;
058: this .setup();
059: }
060:
061: /**
062: * Configures this component.
063: *
064: */
065: private void setup() {
066: this .setLayout(this );
067:
068: AbstractVirtualFileSystem vfs = ServerList.getInstance()
069: .getHarmoniseServer().getVFS();
070:
071: this .m_propertyCombo = new JComboTree();
072: this .m_propertyCombo
073: .setResourceTreeFilter(new ReportResourceFilter(
074: m_reportQuery));
075: this .m_propertyCombo.setActionCommand("PROPCOMBO");
076: this .m_propertyCombo.addActionListener(this );
077: this .m_propertyCombo.setAllowClear(false);
078: this .m_propertyCombo.setShowLeafNodes(true);
079: this .m_propertyCombo.setSelectedLeafOnly(true);
080: this .m_propertyCombo
081: .setSelectionMode(TreeSelectionModel.CONTIGUOUS_TREE_SELECTION);
082: this .m_propertyCombo
083: .addCollectionPath(HarmonisePaths.PATH_SYSTEM_PROPS);
084: this .m_propertyCombo
085: .addCollectionPath(HarmonisePaths.PATH_PROPERTIES);
086: this .add(m_propertyCombo);
087:
088: if (this .m_metadataList.size() > 0) {
089: Iterator iter = m_metadataList.iterator();
090: ArrayList paths = new ArrayList();
091: while (iter.hasNext()) {
092: Metadata metadata = (Metadata) iter.next();
093: paths.add(metadata.getPath());
094: }
095: this .m_propertyCombo.setPaths(vfs, paths);
096: }
097:
098: String fontName = "Dialog";
099: int fontSize = 11;
100: Font font = new Font(fontName, Font.PLAIN, fontSize);
101:
102: if (m_sLabelText != null && m_sLabelText.length() > 0) {
103: this .m_propLabel = new JLabel(m_sLabelText);
104: this .m_propLabel.setFont(font);
105: this .add(this .m_propLabel);
106: }
107: }
108:
109: /**
110: * Returns the metadata data.
111: *
112: * @return Data
113: */
114: public List getMetadataList() {
115: return this .m_metadataList;
116: }
117:
118: /* (non-Javadoc)
119: * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
120: */
121: public void removeLayoutComponent(Component comp) {
122: }
123:
124: /* (non-Javadoc)
125: * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
126: */
127: public void layoutContainer(Container parent) {
128: int x = 0;
129: int y = 0;
130: if (m_propLabel != null) {
131: this .m_propLabel.setSize(this .m_propLabel
132: .getPreferredSize());
133: this .m_propLabel.setLocation(x, y);
134: y += 15;
135: }
136:
137: this .m_propertyCombo.setSize(this .m_propertyCombo
138: .getPreferredSize());
139: this .m_propertyCombo.setLocation(x, y);
140: }
141:
142: /* (non-Javadoc)
143: * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
144: */
145: public void addLayoutComponent(String name, Component comp) {
146: }
147:
148: public Dimension getPreferredSize() {
149: return new Dimension(220, 20);
150:
151: }
152:
153: /* (non-Javadoc)
154: * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
155: */
156: public Dimension minimumLayoutSize(Container parent) {
157: return this .getPreferredSize();
158: }
159:
160: /* (non-Javadoc)
161: * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
162: */
163: public Dimension preferredLayoutSize(Container parent) {
164: return this .getPreferredSize();
165: }
166:
167: /* (non-Javadoc)
168: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
169: */
170: public void actionPerformed(ActionEvent e) {
171: if (e.getActionCommand().equals("PROPCOMBO")) {
172: this .m_metadataList = new ArrayList();
173: m_reportQuery.clearDisplayAttributes();
174: Iterator iter = this .m_propertyCombo.getPaths().iterator();
175: while (iter.hasNext()) {
176: String path = (String) iter.next();
177: Metadata metadata = new Metadata(path,
178: this.m_reportQuery);
179: m_metadataList.add(metadata);
180: this.m_reportQuery.addDisplayAttributes(metadata);
181: }
182: this.layoutContainer(null);
183: this.validateTree();
184: this.repaint();
185: }
186: }
187:
188: }
|