KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > metadata > range > swing > rolehandling > RoleRangeDisplay


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.rolehandling;
20
21 import java.awt.*;
22 import java.awt.event.*;
23 import java.net.*;
24 import java.rmi.*;
25
26 import javax.swing.*;
27 import javax.xml.rpc.*;
28
29 import org.openharmonise.him.*;
30 import org.openharmonise.him.context.StateHandler;
31 import org.openharmonise.him.harmonise.*;
32 import org.openharmonise.him.metadata.range.swing.*;
33 import org.openharmonise.him.metadata.range.swing.valuehandling.*;
34 import org.openharmonise.him.window.messages.*;
35 import org.openharmonise.vfs.authentication.*;
36 import org.openharmonise.vfs.context.*;
37 import org.openharmonise.vfs.metadata.*;
38 import org.openharmonise.vfs.servers.*;
39
40
41 /**
42  *
43  * @author Matthew Large
44  * @version $Revision: 1.2 $
45  *
46  */

47 public class RoleRangeDisplay
48     extends AbstractRangeDisplay
49     implements RangeDisplay, LayoutManager, ActionListener, Runnable JavaDoc {
50         
51     private ValueRangeDisplay m_valueDisplay = null;
52     
53     private JCheckBox m_superCheckBox = null;
54     
55     private JLabel m_superLabel = null;
56     
57     private static final String JavaDoc WAIT_LABEL = "SET_SUPER-ACTION";
58
59     /**
60      * @param propInstance
61      */

62     public RoleRangeDisplay(PropertyInstance propInstance) {
63         super(propInstance);
64         this.setup();
65     }
66     
67     private void setup() {
68         this.setLayout(this);
69         this.m_valueDisplay = new ValueRangeDisplay(super.getPropertyInstance());
70         this.add(m_valueDisplay.getPanel());
71         
72         this.m_superCheckBox = new JCheckBox();
73         this.m_superCheckBox.setActionCommand("SUPER_CHECK");
74         this.m_superCheckBox.addActionListener(this);
75         if(this.isSuperUser()){
76             m_superCheckBox.setSelected(true);
77             this.m_valueDisplay.setEnabled(false);
78         }
79         this.add(this.m_superCheckBox);
80
81         String JavaDoc fontName = "Dialog";
82         int fontSize = 11;
83         Font font = new Font(fontName, Font.PLAIN, fontSize);
84         
85         this.m_superLabel = new JLabel("Super User");
86         this.m_superLabel.setFont(font);
87         this.add(this.m_superLabel);
88         
89         SwingUtilities.invokeLater(this);
90     }
91     /**
92      * Set the super user flag for the User currently being edited.
93      * @param bIsSuper
94      */

95     private void setIsSuperUser(boolean bIsSuper) {
96         Server server = null;
97         server = ServerList.getInstance().getHarmoniseServer();
98         URI uri = server.getURI();
99         
100         String JavaDoc sURI = uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort() + "/webdav/services/HarmoniseService";
101         URL url = null;
102         try {
103             url = new URL(sURI);
104         } catch (MalformedURLException e2) {
105             e2.printStackTrace();
106             System.exit(1);
107         }
108         
109         AuthInfo auth = server.getVFS().getAuthentication();
110         
111         try {
112             UserConfigClient.setIsSuperUser(url, auth.getUsername(), auth.getPassword(), this.getPropertyInstance().getVirtualFile().getFileName(), bIsSuper);
113             if(bIsSuper) {
114                 MessageHandler.getInstance().fireMessageEvent("User \"" + this.getPropertyInstance().getVirtualFile().getVFS().getVirtualFileSystemView().getDisplayName(this.getPropertyInstance().getVirtualFile()) + "\" is now a Super User.", MessageHandler.TYPE_CONFIRM);
115             } else {
116                 MessageHandler.getInstance().fireMessageEvent("User \"" + this.getPropertyInstance().getVirtualFile().getVFS().getVirtualFileSystemView().getDisplayName(this.getPropertyInstance().getVirtualFile()) + "\" is not a Super User anymore.", MessageHandler.TYPE_CONFIRM);
117             }
118         } catch (RemoteException e) {
119             e.printStackTrace();
120             MessageHandler.getInstance().fireMessageEvent("Error changing Super User status for user \"" + this.getPropertyInstance().getVirtualFile().getVFS().getVirtualFileSystemView().getDisplayName(this.getPropertyInstance().getVirtualFile()) + "\".There was a problem communicating with the server.", MessageHandler.TYPE_ERROR);
121         } catch (ServiceException e) {
122             MessageHandler.getInstance().fireMessageEvent("Error changing Super User status for user \"" + this.getPropertyInstance().getVirtualFile().getVFS().getVirtualFileSystemView().getDisplayName(this.getPropertyInstance().getVirtualFile()) + "\".There was a problem communicating with the server.", MessageHandler.TYPE_ERROR);
123             e.printStackTrace();
124         }
125     }
126     /**
127      * Check whether the User curently being edited is a super user
128      * @return true or false
129      */

130     private boolean isSuperUser() {
131         boolean bRetn = false;
132         Server server = null;
133         server = ServerList.getInstance().getHarmoniseServer();
134         URI uri = server.getURI();
135         
136         String JavaDoc sURI = uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort() + "/webdav/services/HarmoniseService";
137         URL url = null;
138         try {
139             url = new URL(sURI);
140         } catch (MalformedURLException e2) {
141             e2.printStackTrace();
142             System.exit(1);
143         }
144         
145         AuthInfo auth = server.getVFS().getAuthentication();
146         
147         try {
148             if( UserConfigClient.isSuperUser(url, auth.getUsername(), auth.getPassword(),getPropertyInstance().getVirtualFile().getFileName()) ) {
149                 bRetn=true;
150             }
151         } catch (RemoteException e) {
152             e.printStackTrace();
153         } catch (ServiceException e) {
154             e.printStackTrace();
155         }
156         return bRetn;
157     }
158     /* (non-Javadoc)
159      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
160      */

161     public void actionPerformed(ActionEvent ae) {
162         if(ae.getActionCommand().equals("SUPER_CHECK")) {
163             boolean bSelected = this.m_superCheckBox.isSelected();
164             this.m_valueDisplay.setEnabled(!bSelected);
165             StateHandler.getInstance().addWait(WAIT_LABEL);
166             this.setIsSuperUser(bSelected);
167             StateHandler.getInstance().removeWait(WAIT_LABEL);
168         }
169     }
170
171     /* (non-Javadoc)
172      * @see com.simulacramedia.contentmanager.metadata.range.swing.AbstractRangeDisplay#isMetadataValid()
173      */

174     public boolean isMetadataValid() {
175         return this.m_valueDisplay.isMetadataValid();
176     }
177
178     /* (non-Javadoc)
179      * @see com.simulacramedia.contentmanager.metadata.range.swing.RangeDisplay#getPanel()
180      */

181     public JPanel getPanel() {
182         return this;
183     }
184
185     /* (non-Javadoc)
186      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
187      */

188     public void layoutContainer(Container arg0) {
189         this.m_valueDisplay.setSize(this.m_valueDisplay.getPreferredSize());
190         this.m_valueDisplay.setLocation(0,0);
191         
192         this.m_superCheckBox.setSize(this.m_superCheckBox.getPreferredSize());
193         this.m_superCheckBox.setLocation(20, this.m_valueDisplay.getHeight()+10);
194         
195         this.m_superLabel.setSize(this.m_superLabel.getPreferredSize());
196         this.m_superLabel.setLocation(22 + this.m_superCheckBox.getWidth(), this.m_valueDisplay.getHeight()+13);
197     }
198
199     /* (non-Javadoc)
200      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
201      */

202     public Dimension minimumLayoutSize(Container arg0) {
203         return this.m_valueDisplay.minimumLayoutSize(arg0);
204     }
205
206     /* (non-Javadoc)
207      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
208      */

209     public Dimension preferredLayoutSize(Container arg0) {
210         return this.m_valueDisplay.preferredLayoutSize(arg0);
211     }
212
213     /* (non-Javadoc)
214      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
215      */

216     public void removeLayoutComponent(Component arg0) {
217         // NO-OP
218
}
219
220     /* (non-Javadoc)
221      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
222      */

223     public void addLayoutComponent(String JavaDoc arg0, Component arg1) {
224         // NO-OP
225
}
226
227     /* (non-Javadoc)
228      * @see java.awt.Component#getPreferredSize()
229      */

230     public Dimension getPreferredSize() {
231         int nWidth = this.getParent().getWidth() - 40;
232         int nHeight = 200;
233         return new Dimension(nWidth, nHeight);
234     }
235
236     /* (non-Javadoc)
237      * @see java.lang.Runnable#run()
238      */

239     public void run() {
240         if(this.isSuperUser()){
241             m_superCheckBox.setSelected(true);
242             this.m_valueDisplay.setEnabled(false);
243         }
244     }
245
246 }
247
Popular Tags