1 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 47 public class RoleRangeDisplay 48 extends AbstractRangeDisplay 49 implements RangeDisplay, LayoutManager, ActionListener, Runnable { 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 WAIT_LABEL = "SET_SUPER-ACTION"; 58 59 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 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 95 private void setIsSuperUser(boolean bIsSuper) { 96 Server server = null; 97 server = ServerList.getInstance().getHarmoniseServer(); 98 URI uri = server.getURI(); 99 100 String 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 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 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 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 174 public boolean isMetadataValid() { 175 return this.m_valueDisplay.isMetadataValid(); 176 } 177 178 181 public JPanel getPanel() { 182 return this; 183 } 184 185 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 202 public Dimension minimumLayoutSize(Container arg0) { 203 return this.m_valueDisplay.minimumLayoutSize(arg0); 204 } 205 206 209 public Dimension preferredLayoutSize(Container arg0) { 210 return this.m_valueDisplay.preferredLayoutSize(arg0); 211 } 212 213 216 public void removeLayoutComponent(Component arg0) { 217 } 219 220 223 public void addLayoutComponent(String arg0, Component arg1) { 224 } 226 227 230 public Dimension getPreferredSize() { 231 int nWidth = this.getParent().getWidth() - 40; 232 int nHeight = 200; 233 return new Dimension(nWidth, nHeight); 234 } 235 236 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 |