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.domain;
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:
028: import org.openharmonise.him.*;
029: import org.openharmonise.him.harmonise.*;
030: import org.openharmonise.him.metadata.range.swing.*;
031: import org.openharmonise.him.swing.resourcetree.*;
032: import org.openharmonise.him.window.messages.*;
033: import org.openharmonise.vfs.*;
034: import org.openharmonise.vfs.gui.*;
035: import org.openharmonise.vfs.metadata.*;
036: import org.openharmonise.vfs.metadata.value.*;
037: import org.openharmonise.vfs.servers.*;
038:
039: /**
040: * @author Matthew Large
041: * @version $Revision: 1.1 $
042: *
043: */
044: public class DomainRangeDisplay extends AbstractRangeDisplay implements
045: RangeDisplay, LayoutManager, ActionListener {
046:
047: private JLabel m_domainLabel = null;
048: private JLabel m_domainLabel2 = null;
049:
050: private ResourceTree m_tree = null;
051:
052: private JButton m_addButton = null;
053: private JButton m_removeButton = null;
054:
055: private DomainSelectionList m_selectionList = null;
056:
057: private int m_nHeight = 400;
058:
059: private static List m_hiddenRootPaths = new ArrayList();
060:
061: static {
062: m_hiddenRootPaths.add(HarmonisePaths.PATH_ARCHIVE);
063: m_hiddenRootPaths.add(HarmonisePaths.PATH_WORKFLOW_DEFINITIONS);
064: m_hiddenRootPaths.add(HarmonisePaths.PATH_WORKFLOW_PROPS);
065: m_hiddenRootPaths.add(HarmonisePaths.PATH_WORKFLOW_STAGES);
066: }
067:
068: /**
069: * @param propInstance
070: */
071: public DomainRangeDisplay(PropertyInstance propInstance) {
072: super (propInstance);
073: this .setup();
074: }
075:
076: private void setup() {
077: this .setLayout(this );
078:
079: m_tree = new ResourceTree();
080: this .m_tree.setBorder(BorderFactory.createEtchedBorder());
081: m_tree.setShowLeafNodes(false);
082: this .add(m_tree);
083:
084: this .m_domainLabel = new JLabel(
085: "The Domain applies to all the children of the collection i.e. all the collections or resources under the selected");
086: this .add(m_domainLabel);
087: this .m_domainLabel2 = new JLabel(
088: "collection, not to the collection itself.");
089: this .add(m_domainLabel2);
090:
091: this .m_addButton = new JButton();
092: this .m_addButton.setIcon(IconManager.getInstance().getIcon(
093: "16-command-value-plus.gif"));
094: this .m_addButton.setActionCommand("ADD");
095: this .m_addButton.setToolTipText("Add");
096: this .m_addButton.addActionListener(this );
097: this .add(this .m_addButton);
098: this .m_removeButton = new JButton();
099: this .m_removeButton.setIcon(IconManager.getInstance().getIcon(
100: "16-command-value-minus.gif"));
101: this .m_removeButton.setActionCommand("REMOVE");
102: this .m_removeButton.setToolTipText("Remove");
103: this .m_removeButton.addActionListener(this );
104: this .add(this .m_removeButton);
105:
106: Server server = ServerList.getInstance().getHarmoniseServer();
107: VirtualFile vfFile = server.getVFS().getVirtualFile(
108: "/" + server.getVFS().getRootPathSegment() + "/")
109: .getResource();
110: List children = vfFile.getChildren();
111: Iterator itor2 = children.iterator();
112: while (itor2.hasNext()) {
113: VirtualFile vfDir = server.getVFS().getVirtualFile(
114: (String) itor2.next()).getResource();
115: if (vfDir.isDirectory()
116: && !this .isPathHiddenRoot(vfDir.getFullPath())) {
117: this .m_tree.addCollection(vfDir);
118: }
119: }
120:
121: this .m_selectionList = new DomainSelectionList(this );
122: this .m_selectionList.setBorder(BorderFactory
123: .createEtchedBorder());
124: this .add(this .m_selectionList);
125: this .m_selectionList.setListenToCombo(false);
126: Iterator itor = this .getPropertyInstance().getValues()
127: .iterator();
128: while (itor.hasNext()) {
129: DomainValue value = (DomainValue) itor.next();
130: this .m_selectionList.addDomain(value);
131: }
132: this .m_selectionList.setListenToCombo(true);
133:
134: }
135:
136: private boolean isPathHiddenRoot(String sPath) {
137: boolean bHidden = false;
138:
139: Iterator itor = DomainRangeDisplay.m_hiddenRootPaths.iterator();
140: while (itor.hasNext()) {
141: String sRootPath = (String) itor.next();
142: if (sPath.equals(sRootPath) || sPath.startsWith(sRootPath)) {
143: bHidden = true;
144: }
145: }
146:
147: return bHidden;
148: }
149:
150: /* (non-Javadoc)
151: * @see com.simulacramedia.contentmanager.metadata.range.swing.RangeDisplay#getPanel()
152: */
153: public JPanel getPanel() {
154: return this ;
155: }
156:
157: /* (non-Javadoc)
158: * @see java.awt.Component#getPreferredSize()
159: */
160: public Dimension getPreferredSize() {
161: return new Dimension(580, 300);
162: }
163:
164: /* (non-Javadoc)
165: * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
166: */
167: public void removeLayoutComponent(Component arg0) {
168: }
169:
170: /* (non-Javadoc)
171: * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
172: */
173: public void layoutContainer(Container arg0) {
174: int nHeight = 0;
175:
176: this .m_domainLabel.setSize(this .m_domainLabel
177: .getPreferredSize());
178: this .m_domainLabel.setLocation(20, nHeight);
179: nHeight = nHeight + 15;
180:
181: this .m_domainLabel2.setSize(this .m_domainLabel2
182: .getPreferredSize());
183: this .m_domainLabel2.setLocation(20, nHeight);
184:
185: this .m_tree.setSize(150, 250);
186: this .m_tree.setLocation(20, nHeight + 20);
187:
188: this .m_addButton.setSize(30, 30);
189: this .m_addButton.setLocation(180, nHeight + 40);
190: this .m_removeButton.setSize(30, 30);
191: this .m_removeButton.setLocation(180, nHeight + 90);
192:
193: this .m_selectionList.setSize(this .m_selectionList
194: .getPreferredSize());
195: this .m_selectionList.setLocation(220, nHeight + 20);
196:
197: }
198:
199: /* (non-Javadoc)
200: * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
201: */
202: public void addLayoutComponent(String arg0, Component arg1) {
203: }
204:
205: /* (non-Javadoc)
206: * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
207: */
208: public Dimension minimumLayoutSize(Container arg0) {
209: return this .getPreferredSize();
210: }
211:
212: /* (non-Javadoc)
213: * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
214: */
215: public Dimension preferredLayoutSize(Container arg0) {
216: return this .getPreferredSize();
217: }
218:
219: protected void domainValuesChanged() {
220: List aValues = this .m_selectionList.getValues();
221: this .getPropertyInstance().setValues(aValues);
222: }
223:
224: protected DomainValue getNewValueInstance() {
225: return (DomainValue) this .getPropertyInstance()
226: .getNewValueInstance();
227: }
228:
229: /* (non-Javadoc)
230: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
231: */
232: public void actionPerformed(ActionEvent ae) {
233: if (ae.getActionCommand().equals("ADD")) {
234: VirtualFile vfFile = this .m_tree.getSelectedResource();
235: boolean bFound = false;
236: if (vfFile.isVirtualDirectory()) {
237: MessageHandler
238: .getInstance()
239: .fireMessageEvent(
240: "The collection "
241: + vfFile
242: .getVFS()
243: .getVirtualFileSystemView()
244: .getDisplayName(vfFile)
245: + " cannot be used as a Domain as it is a virtual collection. Try using child collections of this one.",
246: MessageHandler.TYPE_ERROR);
247: bFound = true;
248: }
249: Iterator itor = this .getPropertyInstance().getValues()
250: .iterator();
251: while (itor.hasNext()) {
252: DomainValue element = (DomainValue) itor.next();
253: if (element.getPath().equals(vfFile.getFullPath())) {
254: bFound = true;
255: break;
256: }
257: }
258: if (!bFound) {
259: DomainValue value = (DomainValue) this
260: .getPropertyInstance().getNewValueInstance();
261: value.setPath(vfFile.getFullPath());
262: this .getPropertyInstance().addValue(value);
263: this .m_selectionList.addDomain(value);
264: }
265: } else if (ae.getActionCommand().equals("REMOVE")) {
266: this .m_selectionList.removeSelectedCell();
267: this .revalidate();
268: this .repaint();
269: this .domainValuesChanged();
270: }
271: }
272:
273: /* (non-Javadoc)
274: * @see com.simulacramedia.contentmanager.metadata.range.swing.AbstractRangeDisplay#isValid()
275: */
276: public boolean isMetadataValid() {
277: return true;
278: }
279:
280: /* (non-Javadoc)
281: * @see com.simulacramedia.contentmanager.metadata.range.swing.AbstractRangeDisplay#isWidthResizable()
282: */
283: public boolean isResizeWidthEnabled() {
284: return false;
285: }
286:
287: }
|