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.metadata.range.swing.propertyhandling;
020:
021: import java.awt.*;
022: import java.util.*;
023: import java.util.List;
024:
025: import javax.swing.*;
026:
027: import org.openharmonise.him.*;
028: import org.openharmonise.him.metadata.range.swing.*;
029: import org.openharmonise.him.metadata.swing.*;
030: import org.openharmonise.vfs.*;
031: import org.openharmonise.vfs.metadata.*;
032: import org.openharmonise.vfs.metadata.range.*;
033: import org.openharmonise.vfs.metadata.value.*;
034: import org.openharmonise.vfs.servers.ServerList;
035:
036: /**
037: * @author Matthew Large
038: *
039: */
040: public class PropertyValuePanel extends AbstractRangeDisplay implements
041: RangeDisplay, LayoutManager {
042:
043: ArrayList m_propDiaplays = new ArrayList(3);
044: protected int m_nHeight = 300;
045:
046: private HashMap m_pathOrderMapping = new HashMap();
047:
048: private SortedSet m_propPanels = new TreeSet();
049:
050: private int m_nNextOrderVal = 1;
051:
052: private PropertyValue m_propValue = null;
053:
054: private PropertyRangeDisplay m_display = null;
055:
056: /**
057: * @param propInstance
058: */
059: public PropertyValuePanel(PropertyRangeDisplay display,
060: PropertyInstance propInstance, PropertyValue propValue) {
061: super (propInstance);
062: this .m_display = display;
063: this .m_propValue = propValue;
064: this .setup();
065: }
066:
067: public PropertyValue getValue() {
068: return this .m_propValue;
069: }
070:
071: private void setup() {
072: this .setLayout(this );
073:
074: PropertyRange propRange = (PropertyRange) this
075: .getPropertyInstance().getDefinition().getRange();
076: List aHREFs = propRange.getHREFs();
077: AbstractVirtualFileSystem vfs = ServerList.getInstance()
078: .getHarmoniseServer().getVFS();
079:
080: Iterator itor = aHREFs.iterator();
081: while (itor.hasNext()) {
082: String sGroupPath = (String) itor.next();
083: VirtualFile vfPropGroup = vfs.getVirtualFile(sGroupPath)
084: .getResource();
085: if (vfPropGroup != null) {
086: int nCount = 1;
087: Iterator itor2 = vfPropGroup.getChildren().iterator();
088: while (itor2.hasNext()) {
089: String sPath = (String) itor2.next();
090: this .m_pathOrderMapping.put(sPath, new Integer(
091: nCount));
092: nCount++;
093: }
094: this .m_nNextOrderVal = nCount;
095: }
096: }
097: }
098:
099: /* (non-Javadoc)
100: * @see com.simulacramedia.contentmanager.metadata.range.swing.RangeDisplay#getPanel()
101: */
102: public JPanel getPanel() {
103: PropertyRange range = (PropertyRange) this
104: .getPropertyInstance().getDefinition().getRange();
105:
106: List props = range.getProperties();
107: List propInstances = this .m_propValue.getValue();
108: Iterator itor = props.iterator();
109:
110: ArrayList aFillingPropInstances = new ArrayList();
111: aFillingPropInstances.addAll(propInstances);
112:
113: while (itor.hasNext()) {
114: Property prop = (Property) itor.next();
115: Iterator itor2 = propInstances.iterator();
116:
117: PropertyInstance propInst = null;
118: while (itor2.hasNext()) {
119: PropertyInstance propInstTemp = (PropertyInstance) itor2
120: .next();
121: if (prop.getName().equals(propInstTemp.getName())
122: && prop.getNamespace().equals(
123: propInstTemp.getNamespaceURI())) {
124: propInst = propInstTemp;
125: }
126: }
127:
128: if (propInst == null) {
129: propInst = new PropertyInstance(prop.getNamespace(),
130: prop.getName());
131: propInst.setDefinitionPath(prop.getHREF(), prop
132: .getVersion());
133: aFillingPropInstances.add(propInst);
134:
135: propInst.setVirtualFile(this .getPropertyInstance()
136: .getVirtualFile());
137:
138: }
139:
140: RangeDisplay display = RangeDisplayFactory
141: .getRangeDisplay(propInst);
142:
143: if (display instanceof PropertyRangeDisplay) {
144: PropertyPanel groupPanel = new PropertyPanel(propInst,
145: true);
146: groupPanel.add(display.getPanel());
147: PropNamePanel propPanel = new PropNamePanel(prop
148: .getDisplayName(), groupPanel, true);
149: this .m_propDiaplays.add(propPanel);
150:
151: if (prop != null
152: && this .m_pathOrderMapping.get(prop.getHREF()) != null) {
153: int nOrder = ((Integer) this .m_pathOrderMapping
154: .get(prop.getHREF())).intValue();
155: OrderedNamedProp orderedProp = new OrderedNamedProp(
156: nOrder, propPanel);
157: this .m_propPanels.add(orderedProp);
158: } else {
159: OrderedNamedProp orderedProp = new OrderedNamedProp(
160: this .m_nNextOrderVal, propPanel);
161: this .m_nNextOrderVal++;
162: this .m_propPanels.add(orderedProp);
163: }
164: } else {
165: PropNamePanel propPanel = new PropNamePanel(prop
166: .getDisplayName(), display.getPanel(), false);
167: this .m_propDiaplays.add(propPanel);
168:
169: if (prop != null
170: && this .m_pathOrderMapping.get(prop.getHREF()) != null) {
171: int nOrder = ((Integer) this .m_pathOrderMapping
172: .get(prop.getHREF())).intValue();
173: OrderedNamedProp orderedProp = new OrderedNamedProp(
174: nOrder, propPanel);
175: this .m_propPanels.add(orderedProp);
176: } else {
177: OrderedNamedProp orderedProp = new OrderedNamedProp(
178: this .m_nNextOrderVal, propPanel);
179: this .m_nNextOrderVal++;
180: this .m_propPanels.add(orderedProp);
181: }
182: }
183: }
184:
185: if (aFillingPropInstances.size() > propInstances.size()) {
186: this .m_propValue.setValue(aFillingPropInstances);
187: }
188:
189: itor = this .m_propDiaplays.iterator();
190: while (itor.hasNext()) {
191: PropNamePanel display = (PropNamePanel) itor.next();
192: this .add(display.getPanel());
193: if (!display.isComplex()) {
194: this .add(display.getLabel());
195: }
196: }
197:
198: return this ;
199: }
200:
201: /* (non-Javadoc)
202: * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
203: */
204: public void removeLayoutComponent(Component arg0) {
205: }
206:
207: /* (non-Javadoc)
208: * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
209: */
210: public void layoutContainer(Container arg0) {
211: this .setSize(this .getPreferredSize());
212:
213: int nHeight = 10;
214:
215: Iterator itor = this .m_propPanels.iterator();
216: while (itor.hasNext()) {
217: OrderedNamedProp propPanel = (OrderedNamedProp) itor.next();
218: ;
219: JPanel panel = propPanel.getPropPanel().getPanel();
220:
221: if (!propPanel.getPropPanel().isComplex()) {
222: JLabel label = propPanel.getPropPanel().getLabel();
223: label.setSize(this .getWidth() - 30, 20);
224: label.setLocation(10, nHeight);
225: }
226:
227: nHeight = nHeight + 20;
228:
229: panel.setSize(panel.getPreferredSize());
230: panel.setLocation(10, nHeight);
231: nHeight = nHeight + panel.getSize().height;
232: panel.repaint();
233: }
234:
235: this .m_nHeight = nHeight;
236:
237: this .repaint();
238: }
239:
240: /* (non-Javadoc)
241: * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
242: */
243: public void addLayoutComponent(String arg0, Component arg1) {
244: }
245:
246: /* (non-Javadoc)
247: * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
248: */
249: public Dimension minimumLayoutSize(Container arg0) {
250: return this .getPreferredSize();
251: }
252:
253: /* (non-Javadoc)
254: * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
255: */
256: public Dimension preferredLayoutSize(Container arg0) {
257: return this .getPreferredSize();
258: }
259:
260: /* (non-Javadoc)
261: * @see java.awt.Component#getPreferredSize()
262: */
263: public Dimension getPreferredSize() {
264: int nWidth = this .getParent().getWidth() - 50;
265: return new Dimension(nWidth, this .m_nHeight);
266: }
267:
268: /* (non-Javadoc)
269: * @see com.simulacramedia.contentmanager.metadata.range.swing.AbstractRangeDisplay#isValid()
270: */
271: public boolean isMetadataValid() {
272: boolean bValid = true;
273: for (int i = 0; i < this .getComponentCount(); i++) {
274: Component comp = this .getComponent(i);
275: if (comp instanceof AbstractRangeDisplay) {
276: if (!((AbstractRangeDisplay) comp).isMetadataValid()) {
277: bValid = false;
278: }
279: }
280: }
281: return bValid;
282: }
283:
284: }
|