KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > metadata > range > swing > resourcehandling > ResourceRangeDisplay


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.metadata.range.swing.resourcehandling;
20 import java.awt.*;
21 import java.awt.event.*;
22 import java.util.*;
23
24 import javax.swing.*;
25
26 import org.openharmonise.him.*;
27 import org.openharmonise.him.metadata.range.swing.*;
28 import org.openharmonise.him.swing.resourcetree.*;
29 import org.openharmonise.vfs.*;
30 import org.openharmonise.vfs.gui.*;
31 import org.openharmonise.vfs.metadata.*;
32 import org.openharmonise.vfs.servers.*;
33
34
35 /**
36
37  * @author Matthew Large
38  * @version $Revision: 1.1 $
39  */

40 public class ResourceRangeDisplay
41     extends AbstractRangeDisplay
42     implements RangeDisplay, LayoutManager, ActionListener {
43
44     private ArrayList m_aPropertyInstances = new ArrayList();
45     
46     private ResourceTree m_tree = null;
47     
48     private JButton m_addButton = null;
49     private JButton m_removeButton = null;
50     
51     private ResourceSelectionList m_selectionList = null;
52     
53     private JLabel m_warningHeader = null;
54     private ArrayList m_aWarnings = new ArrayList();
55     private ArrayList m_aReasons = new ArrayList();
56
57     /**
58      * @param propInstance
59      */

60     public ResourceRangeDisplay(PropertyInstance propInstance) {
61         super(propInstance);
62         this.setup();
63         this.addRelationship(propInstance);
64     }
65     
66     public void setup() {
67         this.setLayout(this);
68         m_tree = new ResourceTree();
69         m_tree.setShowLeafNodes(true);
70         m_tree.setShowApprovedOnly(true);
71         m_tree.setBorder(BorderFactory.createEtchedBorder());
72         
73         this.m_addButton = new JButton();
74         this.m_addButton.setIcon( IconManager.getInstance().getIcon("16-command-value-plus.gif") );
75         this.m_addButton.setActionCommand("ADD");
76         this.m_addButton.setToolTipText("Add");
77         this.m_addButton.addActionListener(this);
78         this.add(this.m_addButton);
79         this.m_removeButton = new JButton();
80         this.m_removeButton.setIcon( IconManager.getInstance().getIcon("16-command-value-minus.gif") );
81         this.m_removeButton.setActionCommand("REMOVE");
82         this.m_removeButton.setToolTipText("Remove");
83         this.m_removeButton.addActionListener(this);
84         this.add(this.m_removeButton);
85         
86         String JavaDoc[] data = new String JavaDoc[0];
87         
88         this.m_selectionList = new ResourceSelectionList(this);
89         m_selectionList.setBorder(BorderFactory.createEtchedBorder());
90         this.add(this.m_selectionList);
91         
92         this.add(m_tree);
93     }
94
95     /* (non-Javadoc)
96      * @see com.simulacramedia.contentmanager.metadata.range.swing.RangeDisplay#getPanel()
97      */

98     public JPanel getPanel() {
99         
100         
101         
102         return this;
103     }
104
105     /**
106      * @param display
107      */

108     public void addRelationship(PropertyInstance propInstance) {
109         Reason reason = new Reason(propInstance, this);
110         
111         Iterator itor = reason.getHREFs().iterator();
112         while(itor.hasNext()) {
113             //URI uri;
114
String JavaDoc sPath = (String JavaDoc)itor.next();
115             if(sPath.trim().equals(".")) {
116                 Server server = ServerList.getInstance().getHarmoniseServer();
117             
118                 VersionedVirtualFile vfLogicalFile = (VersionedVirtualFile) propInstance.getVirtualFile();
119                 if(vfLogicalFile.getState()==VirtualFile.STATE_PENDING && vfLogicalFile.getLiveVersionPath()!=null) {
120                     vfLogicalFile = (VersionedVirtualFile) vfLogicalFile.getVFS().getVirtualFile(vfLogicalFile.getLiveVersionPath()).getResource();
121                 }
122             
123                 VirtualFile vfFile = server.getVFS().getVirtualFile( vfLogicalFile.getFilePath() ).getResource();
124             
125                 this.m_tree.addCollection(vfFile);
126             } else {
127                 Server server = ServerList.getInstance().getHarmoniseServer();
128             
129                 VirtualFile vfFile = server.getVFS().getVirtualFile(sPath).getResource();
130             
131                 this.m_tree.addCollection(vfFile);
132             }
133         }
134         
135         WarningsLabel warning = reason.buildWarning();
136         this.m_aWarnings.add(warning);
137         this.add(warning);
138         this.m_selectionList.addReason(reason);
139     }
140
141     /**
142      * @param display
143      */

144     public void addRelationship(ResourceRangeDisplay display) {
145         this.addRelationship(display.getPropertyInstance());
146     }
147
148     /* (non-Javadoc)
149      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
150      */

151     public void removeLayoutComponent(Component arg0) {
152     }
153
154     /* (non-Javadoc)
155      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
156      */

157     public void layoutContainer(Container arg0) {
158         int nHeight = 0;
159         
160         this.m_tree.setSize(200,300);
161         this.m_tree.setLocation(20,nHeight);
162         
163         this.m_addButton.setSize(this.m_addButton.getPreferredSize());
164         this.m_addButton.setLocation(240, nHeight+120);
165         this.m_removeButton.setSize(this.m_addButton.getPreferredSize());
166         this.m_removeButton.setLocation(240, nHeight+150);
167         
168         this.m_selectionList.setSize(290,300);
169         this.m_selectionList.setLocation(300 ,nHeight);
170     }
171
172     /* (non-Javadoc)
173      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
174      */

175     public void addLayoutComponent(String JavaDoc arg0, Component arg1) {
176     }
177
178     /* (non-Javadoc)
179      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
180      */

181     public Dimension minimumLayoutSize(Container arg0) {
182         return this.getPreferredSize();
183     }
184
185     /* (non-Javadoc)
186      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
187      */

188     public Dimension preferredLayoutSize(Container arg0) {
189         return this.getPreferredSize();
190     }
191
192     /* (non-Javadoc)
193      * @see java.awt.Component#getPreferredSize()
194      */

195     public Dimension getPreferredSize() {
196         return new Dimension(600, 330);
197     }
198
199     /* (non-Javadoc)
200      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
201      */

202     public void actionPerformed(ActionEvent ae) {
203         if(ae.getActionCommand().equals("ADD")) {
204             VirtualFile vfFile = this.m_tree.getSelectedResource();
205             this.m_selectionList.addResource(vfFile);
206         } else if(ae.getActionCommand().equals("REMOVE")) {
207             this.m_selectionList.removeSelectedCell();
208         }
209         this.validateTree();
210         super.validateTab();
211     }
212
213     /* (non-Javadoc)
214      * @see com.simulacramedia.contentmanager.metadata.range.swing.AbstractRangeDisplay#isValid()
215      */

216     public boolean isMetadataValid() {
217         return this.m_selectionList.isValid();
218     }
219     
220     public void validateTab() {
221         super.validateTab();
222     }
223
224     /* (non-Javadoc)
225      * @see com.simulacramedia.contentmanager.metadata.range.swing.AbstractRangeDisplay#isWidthResizable()
226      */

227     public boolean isResizeWidthEnabled() {
228         return false;
229     }
230
231 }
232
Popular Tags