KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > metadata > range > swing > domain > DomainSelectionList


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.domain;
20
21 import java.awt.BorderLayout JavaDoc;
22 import java.awt.Color JavaDoc;
23 import java.awt.Component JavaDoc;
24 import java.awt.Container JavaDoc;
25 import java.awt.Dimension JavaDoc;
26 import java.awt.LayoutManager JavaDoc;
27 import java.awt.event.MouseEvent JavaDoc;
28 import java.awt.event.MouseListener JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.List JavaDoc;
31
32 import javax.swing.BorderFactory JavaDoc;
33 import javax.swing.JPanel JavaDoc;
34 import javax.swing.JScrollPane JavaDoc;
35
36 import org.openharmonise.him.harmonise.*;
37 import org.openharmonise.him.window.messages.*;
38 import org.openharmonise.vfs.metadata.value.*;
39
40
41 /**
42  * @author Matthew Large
43  * @version $Revision: 1.1 $
44  *
45  */

46 public class DomainSelectionList
47     extends JPanel JavaDoc
48     implements MouseListener JavaDoc, LayoutManager JavaDoc {
49
50     private JPanel JavaDoc m_listPanel = null;
51
52     private DomainRangeDisplay m_display = null;
53
54     private boolean m_bListenToCombo = true;
55
56     /**
57      *
58      */

59     public DomainSelectionList(DomainRangeDisplay display) {
60         super();
61         this.m_display = display;
62         this.setup();
63     }
64     
65     private void setup() {
66         this.setBackground(Color.WHITE);
67         this.setLayout(new BorderLayout JavaDoc());
68         
69         this.m_listPanel = new JPanel JavaDoc();
70         this.m_listPanel.setLayout(this);
71         this.m_listPanel.setBackground(Color.WHITE);
72
73         this.m_listPanel.add( new DomainSelectionHeader() );
74         
75         JScrollPane JavaDoc scroller = new JScrollPane JavaDoc(this.m_listPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
76         scroller.setBorder(BorderFactory.createEmptyBorder());
77         this.add(scroller);
78         
79     }
80     
81     protected void setListenToCombo(boolean bListenToCombo) {
82         this.m_bListenToCombo = bListenToCombo;
83     }
84     
85     public void addDomain(DomainValue value) {
86         boolean bFound = false;
87         for(int i=0; i<this.m_listPanel.getComponentCount(); i++) {
88             Component JavaDoc comp = this.m_listPanel.getComponent(i);
89             if(comp instanceof DomainSelectionCell && ((DomainSelectionCell)comp).getPath().equals(value.getPath()) ) {
90                 if(this.m_bListenToCombo==false) {
91                     ((DomainSelectionCell)comp).setListenToCombo(false);
92                 }
93                 ((DomainSelectionCell)comp).setType(DomainSelectionCell.TYPE_BOTH);
94                 if(this.m_bListenToCombo==false) {
95                     ((DomainSelectionCell)comp).setListenToCombo(true);
96                 }
97                 bFound=true;
98             }
99         }
100         if(!bFound) {
101             try {
102                 DomainSelectionCell cell = new DomainSelectionCell(this, value);
103                 if( this.m_display.getPropertyInstance().getVirtualFile().getFullPath().startsWith(HarmonisePaths.PATH_WORKFLOW_PROPS) ) {
104                     cell.setOccursSpinnersEnabled(false);
105                 }
106                 this.m_listPanel.add( cell );
107                 this.m_listPanel.setPreferredSize(new Dimension JavaDoc(300, 20*this.m_listPanel.getComponentCount()) );
108             } catch(Exception JavaDoc e) {
109                 e.printStackTrace();
110                 MessageHandler.getInstance().fireMessageEvent("One of the Domains contains a reference to a Collection that cannot be found on the server [" + value.getPath() + "]. This domain has been removed.", MessageHandler.TYPE_ERROR);
111             }
112         }
113         this.validateTree();
114     }
115     
116     public void removeSelectedCell() {
117         DomainSelectionCell cell = this.getSelectedCell();
118         if(cell!=null) {
119             this.m_listPanel.remove(cell);
120         }
121     }
122     
123     private DomainSelectionCell getSelectedCell() {
124         DomainSelectionCell cell = null;
125         for(int i=0; i<this.m_listPanel.getComponentCount(); i++) {
126             Component JavaDoc comp = this.m_listPanel.getComponent(i);
127             if(comp instanceof DomainSelectionCell && ((DomainSelectionCell)comp).isSelected() ) {
128                 cell = (DomainSelectionCell) comp;
129             }
130         }
131         return cell;
132     }
133     
134     public void cellSelected(DomainSelectionCell cell) {
135         for(int i=0; i<this.m_listPanel.getComponentCount(); i++) {
136             Component JavaDoc comp = this.m_listPanel.getComponent(i);
137             if(comp instanceof DomainSelectionCell) {
138                 ((DomainSelectionCell)comp).setCellSelected(false);
139             }
140         }
141         cell.setCellSelected(true);
142         this.validateTree();
143         this.repaint();
144     }
145     
146     protected DomainValue getNewValueInstance() {
147         return this.m_display.getNewValueInstance();
148     }
149     
150     protected void domainValuesChanged() {
151         this.m_display.domainValuesChanged();
152     }
153     
154     protected List JavaDoc getValues() {
155         ArrayList JavaDoc aValues = new ArrayList JavaDoc();
156         
157         for(int i=0; i<this.m_listPanel.getComponentCount(); i++) {
158             Component JavaDoc comp = this.m_listPanel.getComponent(i);
159             if(comp instanceof DomainSelectionCell) {
160                 aValues.addAll( ((DomainSelectionCell)comp).getValues() );
161             }
162         }
163         
164         return aValues;
165     }
166
167     /* (non-Javadoc)
168      * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
169      */

170     public void mouseClicked(MouseEvent JavaDoc arg0) {
171         
172     }
173
174     /* (non-Javadoc)
175      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
176      */

177     public void layoutContainer(Container JavaDoc arg0) {
178         
179         for(int i=0; i<this.m_listPanel.getComponentCount(); i++) {
180             Component JavaDoc comp = this.m_listPanel.getComponent(i);
181             comp.setSize(comp.getPreferredSize());
182             comp.setLocation(0, i*20);
183         }
184     }
185
186     /* (non-Javadoc)
187      * @see java.awt.Component#getPreferredSize()
188      */

189     public Dimension JavaDoc getPreferredSize() {
190         return new Dimension JavaDoc(320,250);
191     }
192
193     /* (non-Javadoc)
194      * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
195      */

196     public void mouseEntered(MouseEvent JavaDoc arg0) {
197     }
198
199     /* (non-Javadoc)
200      * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
201      */

202     public void mouseExited(MouseEvent JavaDoc arg0) {
203     }
204
205     /* (non-Javadoc)
206      * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
207      */

208     public void mousePressed(MouseEvent JavaDoc arg0) {
209     }
210
211     /* (non-Javadoc)
212      * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
213      */

214     public void mouseReleased(MouseEvent JavaDoc arg0) {
215     }
216
217     /* (non-Javadoc)
218      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
219      */

220     public void removeLayoutComponent(Component JavaDoc arg0) {
221     }
222
223     /* (non-Javadoc)
224      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
225      */

226     public void addLayoutComponent(String JavaDoc arg0, Component JavaDoc arg1) {
227     }
228
229     /* (non-Javadoc)
230      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
231      */

232     public Dimension JavaDoc minimumLayoutSize(Container JavaDoc arg0) {
233         return this.getPreferredSize();
234     }
235
236     /* (non-Javadoc)
237      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
238      */

239     public Dimension JavaDoc preferredLayoutSize(Container JavaDoc arg0) {
240         return this.getPreferredSize();
241     }
242
243     /**
244      * @param arg0
245      */

246     private DomainSelectionList(boolean arg0) {
247         super(arg0);
248     }
249
250     /**
251      * @param arg0
252      */

253     private DomainSelectionList(LayoutManager JavaDoc arg0) {
254         super(arg0);
255     }
256
257     /**
258      * @param arg0
259      * @param arg1
260      */

261     private DomainSelectionList(LayoutManager JavaDoc arg0, boolean arg1) {
262         super(arg0, arg1);
263     }
264
265 }
266
Popular Tags