1 19 package org.openharmonise.him.serverconfig.permissions; 20 21 import java.awt.*; 22 import java.awt.event.*; 23 import java.util.*; 24 import java.util.List ; 25 26 import javax.swing.*; 27 import javax.swing.tree.*; 28 29 import org.openharmonise.him.*; 30 import org.openharmonise.him.configuration.*; 31 import org.openharmonise.him.context.StateHandler; 32 import org.openharmonise.him.editors.*; 33 import org.openharmonise.him.serverconfig.*; 34 import org.openharmonise.him.serverconfig.permissions.list.*; 35 import org.openharmonise.him.serverconfig.permissions.tree.*; 36 import org.openharmonise.him.swing.resourcetree.TreeModel; 37 import org.openharmonise.swing.*; 38 import org.openharmonise.vfs.*; 39 import org.openharmonise.vfs.context.*; 40 import org.openharmonise.vfs.event.*; 41 import org.openharmonise.vfs.gui.*; 42 import org.openharmonise.vfs.metadata.*; 43 import org.openharmonise.vfs.metadata.range.*; 44 import org.openharmonise.vfs.servers.*; 45 import org.openharmonise.vfs.status.*; 46 47 55 public class PermissionsServerConfigOptions 56 extends AbstractServerConfigOptions 57 implements LayoutManager, ActionListener, ApplyChangesListener, PermissionsSelectionListener, Runnable , VirtualFileListener { 58 59 62 private JTextArea m_descriptionTextArea = null; 63 64 67 private JScrollPane m_scroller; 68 69 72 private AbstractVirtualFileSystem m_vfs = null; 73 74 77 private PermissionsSelectionList m_list = null; 78 79 82 private JTree m_tree = null; 83 84 87 private JButton m_newRoleButton = null; 88 89 92 private String m_sUsername = null; 93 94 97 private String m_sPassword = null; 98 99 102 private VirtualFile m_vfCurrentRole = null; 103 104 109 public PermissionsServerConfigOptions(ServerConfigDialog dialog) { 110 super(dialog); 111 dialog.addApplyChangesListener(this); 112 this.setup(); 113 } 114 115 119 private void setup() { 120 this.m_vfs = ServerList.getInstance().getHarmoniseServer().getVFS(); 121 this.setLayout(this); 122 123 this.m_sUsername = ServerList.getInstance().getHarmoniseServer().getVFS().getAuthentication().getUsername(); 124 this.m_sPassword = ServerList.getInstance().getHarmoniseServer().getVFS().getAuthentication().getPassword(); 125 126 String fontName = "Dialog"; 127 int fontSize = 11; 128 Font font = new Font(fontName, Font.PLAIN, fontSize); 129 130 this.m_descriptionTextArea = new JTextArea("Use the list below to grant or deny a user group permission to access different functionality."); 131 this.m_descriptionTextArea.setEditable(false); 132 this.m_descriptionTextArea.setBorder(BorderFactory.createEmptyBorder()); 133 this.m_descriptionTextArea.setWrapStyleWord(true); 134 this.m_descriptionTextArea.setLineWrap(true); 135 this.m_descriptionTextArea.setOpaque(false); 136 this.add(m_descriptionTextArea); 137 138 this.m_list = new PermissionsSelectionList(); 139 this.m_list.addPermissionsSelectionListener(this); 140 this.add(m_list); 141 VirtualFile vfRoleCollection = this.getRoleCollection(); 142 Iterator itor = vfRoleCollection.getChildren().iterator(); 143 while (itor.hasNext()) { 144 String sChildPath = (String ) itor.next(); 145 if(!sChildPath.equals("/webdav/RBS_VALS/roles/BROWSER")) { 146 this.m_list.addFile(sChildPath, vfRoleCollection.getVFS()); 147 } 148 } 149 150 DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("root"); 151 TreeModel treeModel = new TreeModel(rootNode); 152 this.m_tree = new JTree(treeModel); 153 this.m_tree.setRootVisible(false); 154 155 this.m_tree.setShowsRootHandles(true); 156 this.m_tree.setLargeModel(true); 157 158 this.m_tree.setCellRenderer( new PermissionsTreeCellRenderer()); 159 m_tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); 160 this.m_tree.setVisible(true); 161 this.m_tree.addTreeSelectionListener( new PermissionsTreeSelectionListener(this.m_tree)); 162 163 m_scroller = new JScrollPane(this.m_tree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, 164 JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 165 m_scroller.setBorder(BorderFactory.createLineBorder(Color.BLACK)); 166 this.add(m_scroller); 167 168 this.m_newRoleButton = new JButton("New role"); 169 this.m_newRoleButton.setFont(font); 170 this.m_newRoleButton.setActionCommand("NEW_ROLE"); 171 this.m_newRoleButton.addActionListener(this); 172 this.add(this.m_newRoleButton); 173 174 SwingUtilities.invokeLater(this); 175 } 176 177 180 public void layoutContainer(Container arg0) { 181 182 int nHeight = 20; 183 184 this.m_descriptionTextArea.setSize(350, 30); 185 this.m_descriptionTextArea.setLocation(20, nHeight); 186 nHeight = nHeight + this.m_descriptionTextArea.getSize().height + 10; 187 188 this.m_list.setLocation(20, nHeight); 189 this.m_list.setSize(340, 100); 190 nHeight = nHeight + this.m_list.getSize().height + 10; 191 192 this.m_newRoleButton.setLocation(280, nHeight); 193 this.m_newRoleButton.setSize(80, 20); 194 nHeight = nHeight + this.m_newRoleButton.getSize().height + 10; 195 196 this.m_scroller.setLocation(20, nHeight); 197 this.m_scroller.setSize(340, 180); 198 nHeight = nHeight + this.m_scroller.getSize().height + 10; 199 } 200 201 204 public void actionPerformed(ActionEvent ae) { 205 if(ae.getActionCommand().equals("NEW_ROLE")) { 206 JFrame frame = new JFrame(); 207 frame.setIconImage( ((ImageIcon)IconManager.getInstance().getIcon("32-sim-logo.gif")).getImage() ); 208 209 210 SingleTextEntryDialog txtEntry = new SingleTextEntryDialog(frame, "New Role Name"); 211 txtEntry.setLabelText("Enter the name of the new role."); 212 txtEntry.show(); 213 214 String sValue = txtEntry.getTextValue(); 215 if(sValue!=null && sValue.trim().length()>0) { 216 StateHandler.getInstance().addWait("NEW_ROLE"); 217 try { 218 VirtualFile vfRoleDir = this.getRoleCollection(); 219 String sPath = vfRoleDir.getFullPath() + "/" + txtEntry.getTextValue(); 220 if( EditorController.getInstance().createNew(sPath, vfRoleDir.getVFS()).isOK() ) { 221 VirtualFile vfTemp = this.m_vfs.getVirtualFile(sPath).getResource(); 222 if(vfTemp.isVersionable() && ((VersionedVirtualFile)vfTemp).hasPendingVersion()) { 223 VersionedVirtualFile vfPending = (VersionedVirtualFile) vfTemp.getVFS().getVirtualFile( ((VersionedVirtualFile)vfTemp).getPendingVersionPath() ).getResource(); 224 if(vfPending!=null) { 225 vfPending.checkin(); 226 } 227 } else if(vfTemp.isVersionable() && ((VersionedVirtualFile)vfTemp).getState()==VirtualFile.STATE_PENDING) { 228 ((VersionedVirtualFile)vfTemp).checkin(); 229 } 230 } 231 232 this.remove(m_list); 233 this.m_list = new PermissionsSelectionList(); 234 this.m_list.addPermissionsSelectionListener(this); 235 this.add(m_list); 236 VirtualFile vfRoleCollection = this.getRoleCollection(); 237 Iterator itor = vfRoleCollection.getChildren().iterator(); 238 while (itor.hasNext()) { 239 String sChildPath = (String ) itor.next(); 240 if(!sChildPath.equals("/webdav/RBS_VALS/roles/BROWSER")) { 241 this.m_list.addFile(sChildPath, vfRoleCollection.getVFS()); 242 } 243 } 244 245 this.m_list.selectPermission(sPath); 246 } catch(Exception e) { 247 e.printStackTrace(); 248 } finally { 249 StateHandler.getInstance().removeWait("NEW_ROLE"); 250 } 251 } 252 } 253 } 254 255 258 public void permissionSelected(String sPath) { 259 StateHandler.getInstance().addWait(this.m_dialog, "PERMISSIONS-SELECTION"); 260 try { 261 DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("root"); 262 TreeModel treeModel = new TreeModel(rootNode); 263 this.m_tree.setModel(treeModel); 264 this.m_tree.addMouseListener( new PermissionsTreeSelectionListener(this.m_tree)); 265 266 if(this.m_vfCurrentRole!=null) { 267 this.m_vfCurrentRole.removeVirtualFileListener(this); 268 } 269 270 VirtualFile vfRole = this.m_vfs.getVirtualFile(sPath).getResource(); 271 272 vfRole.addVirtualFileListener(this); 273 274 Iterator itor = getObjectPropertyDefinitions().iterator(); 275 while (itor.hasNext()) { 276 Property prop = (Property) itor.next(); 277 ValueRange range = (ValueRange)prop.getRange(); 278 PropertyInstance propInst = vfRole.getProperty(prop.getNamespace(), prop.getName()); 279 280 if(range.getValueGroups().size()>0) { 281 PermissionsTreeNode node = new PermissionsTreeNode(propInst, (ValueGroup)range.getValueGroups().get(0), true); 282 rootNode.add(node); 283 } else { 284 System.err.println("PERMISSIONS: No ValueGroup for Property [" + prop.getHREF() + "]"); 285 } 286 } 287 288 this.validateTree(); 289 290 SwingUtilities.invokeLater(this); 291 } catch (Exception e) { 292 e.printStackTrace(System.err); 293 } finally { 294 StateHandler.getInstance().removeWait(this.m_dialog, "PERMISSIONS-SELECTION"); 295 } 296 297 } 298 299 302 public boolean applyChanges() { 303 boolean bOk = true; 304 Iterator itor = this.getRoleCollection().getChildren().iterator(); 305 while (itor.hasNext()) { 306 String sPath = (String ) itor.next(); 307 VirtualFile vfTemp = this.m_vfs.getVirtualFile(sPath).getResource(); 308 if(vfTemp.isChanged()) { 309 StatusData status = vfTemp.sync(); 310 if(status.isOK()) { 311 vfTemp = this.m_vfs.getVirtualFile(sPath).getResource(); 312 if(vfTemp.isVersionable() && ((VersionedVirtualFile)vfTemp).hasPendingVersion()) { 313 VersionedVirtualFile vfPending = (VersionedVirtualFile) vfTemp.getVFS().getVirtualFile( ((VersionedVirtualFile)vfTemp).getPendingVersionPath() ).getResource(); 314 if(vfPending!=null) { 315 vfPending.checkin(); 316 } 317 } else if(vfTemp.getState()==VirtualFile.STATE_PENDING && vfTemp.isVersionable() && ((VersionedVirtualFile)vfTemp).getLiveVersionPath()==null) { 318 ((VersionedVirtualFile)vfTemp).checkin(); 319 } 320 this.permissionSelected(sPath); 321 } else { 322 bOk = false; 323 } 324 } 325 } 326 return bOk; 327 } 328 329 332 public void discardChanges() { 333 Iterator itor = this.getRoleCollection().getChildren().iterator(); 334 while (itor.hasNext()) { 335 String sPath = (String ) itor.next(); 336 this.m_vfs.discardFileChanges(sPath); 337 } 338 } 339 340 343 public void run() { 344 this.doLayout(); 345 this.m_tree.expandPath( new TreePath(((DefaultMutableTreeNode)this.m_tree.getModel().getRoot()).getPath()) ); 346 } 347 348 353 private VirtualFile getRoleCollection() { 354 return this.m_vfs.getVirtualFile("/webdav/RBS_VALS/roles").getResource(); 355 } 356 357 362 public static List getObjectPropertyDefinitions() { 363 ArrayList aProperties = new ArrayList(); 364 Server server = null; 365 server = ServerList.getInstance().getHarmoniseServer(); 366 VirtualFile vfCollection = server.getVFS().getVirtualFile("/webdav/RBS_PROPS/object").getResource(); 367 Iterator itor = vfCollection.getChildren().iterator(); 368 while (itor.hasNext()) { 369 String sPath = (String ) itor.next(); 370 Property prop = PropertyCache.getInstance().getPropertyByPath(sPath); 371 aProperties.add(prop); 372 } 373 374 return aProperties; 375 } 376 377 378 381 public Dimension getPreferredSize() { 382 return new Dimension(this.getParent().getSize().width-50, 100); 383 } 384 385 388 public Dimension minimumLayoutSize(Container arg0) { 389 return this.getPreferredSize(); 390 } 391 392 395 public Dimension preferredLayoutSize(Container arg0) { 396 return this.getPreferredSize(); 397 } 398 399 402 public void removeLayoutComponent(Component arg0) { 403 } 404 405 408 public void addLayoutComponent(String arg0, Component arg1) { 409 } 410 411 414 public void virtualFileChanged(VirtualFileEvent vfe) { 415 if(vfe.getEventType()==VirtualFileEvent.FILE_METADATA_CHANGED) { 416 this.fireChangesMade(); 417 } 418 } 419 420 } 421 | Popular Tags |