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.resourcehandling;
020:
021: import java.awt.*;
022: import java.awt.event.*;
023: import java.util.*;
024:
025: import javax.swing.*;
026:
027: import org.openharmonise.him.*;
028: import org.openharmonise.him.metadata.range.swing.*;
029: import org.openharmonise.him.swing.resourcetree.*;
030: import org.openharmonise.vfs.*;
031: import org.openharmonise.vfs.gui.*;
032: import org.openharmonise.vfs.metadata.*;
033: import org.openharmonise.vfs.servers.*;
034:
035: /**
036:
037: * @author Matthew Large
038: * @version $Revision: 1.1 $
039: */
040: public class ResourceRangeDisplay extends AbstractRangeDisplay
041: implements RangeDisplay, LayoutManager, ActionListener {
042:
043: private ArrayList m_aPropertyInstances = new ArrayList();
044:
045: private ResourceTree m_tree = null;
046:
047: private JButton m_addButton = null;
048: private JButton m_removeButton = null;
049:
050: private ResourceSelectionList m_selectionList = null;
051:
052: private JLabel m_warningHeader = null;
053: private ArrayList m_aWarnings = new ArrayList();
054: private ArrayList m_aReasons = new ArrayList();
055:
056: /**
057: * @param propInstance
058: */
059: public ResourceRangeDisplay(PropertyInstance propInstance) {
060: super (propInstance);
061: this .setup();
062: this .addRelationship(propInstance);
063: }
064:
065: public void setup() {
066: this .setLayout(this );
067: m_tree = new ResourceTree();
068: m_tree.setShowLeafNodes(true);
069: m_tree.setShowApprovedOnly(true);
070: m_tree.setBorder(BorderFactory.createEtchedBorder());
071:
072: this .m_addButton = new JButton();
073: this .m_addButton.setIcon(IconManager.getInstance().getIcon(
074: "16-command-value-plus.gif"));
075: this .m_addButton.setActionCommand("ADD");
076: this .m_addButton.setToolTipText("Add");
077: this .m_addButton.addActionListener(this );
078: this .add(this .m_addButton);
079: this .m_removeButton = new JButton();
080: this .m_removeButton.setIcon(IconManager.getInstance().getIcon(
081: "16-command-value-minus.gif"));
082: this .m_removeButton.setActionCommand("REMOVE");
083: this .m_removeButton.setToolTipText("Remove");
084: this .m_removeButton.addActionListener(this );
085: this .add(this .m_removeButton);
086:
087: String[] data = new String[0];
088:
089: this .m_selectionList = new ResourceSelectionList(this );
090: m_selectionList.setBorder(BorderFactory.createEtchedBorder());
091: this .add(this .m_selectionList);
092:
093: this .add(m_tree);
094: }
095:
096: /* (non-Javadoc)
097: * @see com.simulacramedia.contentmanager.metadata.range.swing.RangeDisplay#getPanel()
098: */
099: public JPanel getPanel() {
100:
101: return this ;
102: }
103:
104: /**
105: * @param display
106: */
107: public void addRelationship(PropertyInstance propInstance) {
108: Reason reason = new Reason(propInstance, this );
109:
110: Iterator itor = reason.getHREFs().iterator();
111: while (itor.hasNext()) {
112: //URI uri;
113: String sPath = (String) itor.next();
114: if (sPath.trim().equals(".")) {
115: Server server = ServerList.getInstance()
116: .getHarmoniseServer();
117:
118: VersionedVirtualFile vfLogicalFile = (VersionedVirtualFile) propInstance
119: .getVirtualFile();
120: if (vfLogicalFile.getState() == VirtualFile.STATE_PENDING
121: && vfLogicalFile.getLiveVersionPath() != null) {
122: vfLogicalFile = (VersionedVirtualFile) vfLogicalFile
123: .getVFS().getVirtualFile(
124: vfLogicalFile.getLiveVersionPath())
125: .getResource();
126: }
127:
128: VirtualFile vfFile = server.getVFS().getVirtualFile(
129: vfLogicalFile.getFilePath()).getResource();
130:
131: this .m_tree.addCollection(vfFile);
132: } else {
133: Server server = ServerList.getInstance()
134: .getHarmoniseServer();
135:
136: VirtualFile vfFile = server.getVFS().getVirtualFile(
137: sPath).getResource();
138:
139: this .m_tree.addCollection(vfFile);
140: }
141: }
142:
143: WarningsLabel warning = reason.buildWarning();
144: this .m_aWarnings.add(warning);
145: this .add(warning);
146: this .m_selectionList.addReason(reason);
147: }
148:
149: /**
150: * @param display
151: */
152: public void addRelationship(ResourceRangeDisplay display) {
153: this .addRelationship(display.getPropertyInstance());
154: }
155:
156: /* (non-Javadoc)
157: * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
158: */
159: public void removeLayoutComponent(Component arg0) {
160: }
161:
162: /* (non-Javadoc)
163: * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
164: */
165: public void layoutContainer(Container arg0) {
166: int nHeight = 0;
167:
168: this .m_tree.setSize(200, 300);
169: this .m_tree.setLocation(20, nHeight);
170:
171: this .m_addButton.setSize(this .m_addButton.getPreferredSize());
172: this .m_addButton.setLocation(240, nHeight + 120);
173: this .m_removeButton
174: .setSize(this .m_addButton.getPreferredSize());
175: this .m_removeButton.setLocation(240, nHeight + 150);
176:
177: this .m_selectionList.setSize(290, 300);
178: this .m_selectionList.setLocation(300, nHeight);
179: }
180:
181: /* (non-Javadoc)
182: * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
183: */
184: public void addLayoutComponent(String arg0, Component arg1) {
185: }
186:
187: /* (non-Javadoc)
188: * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
189: */
190: public Dimension minimumLayoutSize(Container arg0) {
191: return this .getPreferredSize();
192: }
193:
194: /* (non-Javadoc)
195: * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
196: */
197: public Dimension preferredLayoutSize(Container arg0) {
198: return this .getPreferredSize();
199: }
200:
201: /* (non-Javadoc)
202: * @see java.awt.Component#getPreferredSize()
203: */
204: public Dimension getPreferredSize() {
205: return new Dimension(600, 330);
206: }
207:
208: /* (non-Javadoc)
209: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
210: */
211: public void actionPerformed(ActionEvent ae) {
212: if (ae.getActionCommand().equals("ADD")) {
213: VirtualFile vfFile = this .m_tree.getSelectedResource();
214: this .m_selectionList.addResource(vfFile);
215: } else if (ae.getActionCommand().equals("REMOVE")) {
216: this .m_selectionList.removeSelectedCell();
217: }
218: this .validateTree();
219: super .validateTab();
220: }
221:
222: /* (non-Javadoc)
223: * @see com.simulacramedia.contentmanager.metadata.range.swing.AbstractRangeDisplay#isValid()
224: */
225: public boolean isMetadataValid() {
226: return this .m_selectionList.isValid();
227: }
228:
229: public void validateTab() {
230: super .validateTab();
231: }
232:
233: /* (non-Javadoc)
234: * @see com.simulacramedia.contentmanager.metadata.range.swing.AbstractRangeDisplay#isWidthResizable()
235: */
236: public boolean isResizeWidthEnabled() {
237: return false;
238: }
239:
240: }
|