KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > serverconfig > RelatedResourceDisplay


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.serverconfig;
20
21 import java.awt.event.*;
22 import java.util.*;
23
24 import org.openharmonise.commons.xml.namespace.*;
25 import org.openharmonise.him.*;
26 import org.openharmonise.him.editors.report.swing.*;
27 import org.openharmonise.vfs.*;
28 import org.openharmonise.vfs.metadata.*;
29 import org.openharmonise.vfs.metadata.range.*;
30 import org.openharmonise.vfs.metadata.value.*;
31 import org.openharmonise.vfs.servers.ServerList;
32 import org.openharmonise.webdav.client.value.*;
33
34
35 /**
36  *
37  * @author matt treanor
38  * @version $Revision: 1.2 $
39  *
40  */

41 public class RelatedResourceDisplay extends JComboTree {
42
43     private PropertyInstance m_prop = null;
44     private HashMap m_changedValues = null;
45     private PropertyInstance m_propInst = null;
46     private static final String JavaDoc COMMAND_CHANGE = "CHANGE";
47     private AbstractPreviewConfigOptions m_options = null;
48     /**
49      *
50      */

51     public RelatedResourceDisplay(AbstractPreviewConfigOptions options) {
52         super();
53         m_options = options;
54         m_changedValues = new HashMap();
55         this.setActionCommand(COMMAND_CHANGE);
56         this.addActionListener(this);
57     }
58     public void actionPerformed(ActionEvent ae) {
59         
60         if(ae.getActionCommand().equals(COMMAND_CHANGE)) {
61             String JavaDoc valPath = getPath();
62             String JavaDoc sPath = m_propInst.getVirtualFile().getFullPath();
63             this.m_changedValues.put(sPath,valPath);
64             m_options.fireChangesMade();
65         } else {
66             super.actionPerformed(ae);
67         }
68     }
69     public void populate(PropertyInstance propInst){
70         AbstractVirtualFileSystem vfs = propInst.getVirtualFile().getVFS();
71         m_propInst = propInst;
72         VirtualFile vFile = propInst.getVirtualFile();
73         String JavaDoc path = vFile.getFullPath();
74         if(m_changedValues!= null && m_changedValues.containsKey(path)){
75             String JavaDoc pagePath = (String JavaDoc)m_changedValues.get(path);
76             this.setPath(vfs,pagePath);
77         } else {
78             Property prop = propInst.getDefinition();
79     
80             ResourceRange propRange =
81                 (ResourceRange)
82                     prop
83                     .getRange();
84             List aHREFs = propRange.getHREFs();
85     
86             Iterator itor = aHREFs.iterator();
87             String JavaDoc sGroupPath = null;
88             while (itor.hasNext()) {
89                 sGroupPath = (String JavaDoc) itor.next();
90                 this.addCollectionPath(sGroupPath);
91                 Iterator iter = propInst.getValues().iterator();
92                 String JavaDoc sPath = null;
93                 if(iter.hasNext()){
94                     ResourceValue val = (ResourceValue)iter.next();
95                     sPath = val.getValue();
96                 }
97                 if(sPath!=null){
98                     this.setPath(vfs,sPath);
99                 } else {
100                     this.m_value.setText("");
101                 }
102             }
103         }
104     }
105     public void saveChangedValues(){
106         Iterator itor = m_changedValues.keySet().iterator();
107         String JavaDoc pagePath = null;
108         String JavaDoc valPath = null;
109         AbstractVirtualFileSystem vfs = ServerList.getInstance().getHarmoniseServer().getVFS();
110         while (itor.hasNext()) {
111             pagePath = (String JavaDoc)itor.next();
112             valPath = (String JavaDoc)m_changedValues.get(pagePath);
113             VirtualFile vFile = vfs.getVirtualFile(pagePath).getResource();
114             PropertyInstance propInst = vFile.getProperty(NamespaceType.OHRM.getURI(),"PREVIEWPAGE");
115             DAVResourceValue val = new DAVResourceValue();
116             val.setValue(valPath);
117             propInst.setValue(val);
118             vFile.sync();
119         }
120     }
121
122     public static void main(String JavaDoc[] args) {
123     }
124 }
125
Popular Tags