Source Code Cross Referenced for PermissionsServerConfigOptions.java in  » Content-Management-System » harmonise » org » openharmonise » him » serverconfig » permissions » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » harmonise » org.openharmonise.him.serverconfig.permissions 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The contents of this file are subject to the 
003:         * Mozilla Public License Version 1.1 (the "License"); 
004:         * you may not use this file except in compliance with the License. 
005:         * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006:         *
007:         * Software distributed under the License is distributed on an "AS IS"
008:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 
009:         * See the License for the specific language governing rights and 
010:         * limitations under the License.
011:         *
012:         * The Initial Developer of the Original Code is Simulacra Media Ltd.
013:         * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014:         *
015:         * All Rights Reserved.
016:         *
017:         * Contributor(s):
018:         */
019:        package org.openharmonise.him.serverconfig.permissions;
020:
021:        import java.awt.*;
022:        import java.awt.event.*;
023:        import java.util.*;
024:        import java.util.List;
025:
026:        import javax.swing.*;
027:        import javax.swing.tree.*;
028:
029:        import org.openharmonise.him.*;
030:        import org.openharmonise.him.configuration.*;
031:        import org.openharmonise.him.context.StateHandler;
032:        import org.openharmonise.him.editors.*;
033:        import org.openharmonise.him.serverconfig.*;
034:        import org.openharmonise.him.serverconfig.permissions.list.*;
035:        import org.openharmonise.him.serverconfig.permissions.tree.*;
036:        import org.openharmonise.him.swing.resourcetree.TreeModel;
037:        import org.openharmonise.swing.*;
038:        import org.openharmonise.vfs.*;
039:        import org.openharmonise.vfs.context.*;
040:        import org.openharmonise.vfs.event.*;
041:        import org.openharmonise.vfs.gui.*;
042:        import org.openharmonise.vfs.metadata.*;
043:        import org.openharmonise.vfs.metadata.range.*;
044:        import org.openharmonise.vfs.servers.*;
045:        import org.openharmonise.vfs.status.*;
046:
047:        /**
048:         * Panel for configuring the permissions options of a Harmonise Information
049:         * Server.
050:         * 
051:         * @author Matthew Large
052:         * @version $Revision: 1.1 $
053:         *
054:         */
055:        public class PermissionsServerConfigOptions extends
056:                AbstractServerConfigOptions implements  LayoutManager,
057:                ActionListener, ApplyChangesListener,
058:                PermissionsSelectionListener, Runnable, VirtualFileListener {
059:
060:            /**
061:             * Description.
062:             */
063:            private JTextArea m_descriptionTextArea = null;
064:
065:            /**
066:             * Scroll pane.
067:             */
068:            private JScrollPane m_scroller;
069:
070:            /**
071:             * Virtual File System that roles are on.
072:             */
073:            private AbstractVirtualFileSystem m_vfs = null;
074:
075:            /**
076:             * List of roles.
077:             */
078:            private PermissionsSelectionList m_list = null;
079:
080:            /**
081:             * Permissions tree.
082:             */
083:            private JTree m_tree = null;
084:
085:            /**
086:             * New role button.
087:             */
088:            private JButton m_newRoleButton = null;
089:
090:            /**
091:             * Username for the current user.
092:             */
093:            private String m_sUsername = null;
094:
095:            /**
096:             * Password for the current user.
097:             */
098:            private String m_sPassword = null;
099:
100:            /**
101:             * Currently selected role.
102:             */
103:            private VirtualFile m_vfCurrentRole = null;
104:
105:            /**
106:             * Constructs a new cache configuration options panel.
107:             * 
108:             * @param dialog configuration dialog that this panel will be in.
109:             */
110:            public PermissionsServerConfigOptions(ServerConfigDialog dialog) {
111:                super (dialog);
112:                dialog.addApplyChangesListener(this );
113:                this .setup();
114:            }
115:
116:            /**
117:             * Initialises this component.
118:             *
119:             */
120:            private void setup() {
121:                this .m_vfs = ServerList.getInstance().getHarmoniseServer()
122:                        .getVFS();
123:                this .setLayout(this );
124:
125:                this .m_sUsername = ServerList.getInstance()
126:                        .getHarmoniseServer().getVFS().getAuthentication()
127:                        .getUsername();
128:                this .m_sPassword = ServerList.getInstance()
129:                        .getHarmoniseServer().getVFS().getAuthentication()
130:                        .getPassword();
131:
132:                String fontName = "Dialog";
133:                int fontSize = 11;
134:                Font font = new Font(fontName, Font.PLAIN, fontSize);
135:
136:                this .m_descriptionTextArea = new JTextArea(
137:                        "Use the list below to grant or deny a user group permission to access different functionality.");
138:                this .m_descriptionTextArea.setEditable(false);
139:                this .m_descriptionTextArea.setBorder(BorderFactory
140:                        .createEmptyBorder());
141:                this .m_descriptionTextArea.setWrapStyleWord(true);
142:                this .m_descriptionTextArea.setLineWrap(true);
143:                this .m_descriptionTextArea.setOpaque(false);
144:                this .add(m_descriptionTextArea);
145:
146:                this .m_list = new PermissionsSelectionList();
147:                this .m_list.addPermissionsSelectionListener(this );
148:                this .add(m_list);
149:                VirtualFile vfRoleCollection = this .getRoleCollection();
150:                Iterator itor = vfRoleCollection.getChildren().iterator();
151:                while (itor.hasNext()) {
152:                    String sChildPath = (String) itor.next();
153:                    if (!sChildPath.equals("/webdav/RBS_VALS/roles/BROWSER")) {
154:                        this .m_list.addFile(sChildPath, vfRoleCollection
155:                                .getVFS());
156:                    }
157:                }
158:
159:                DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(
160:                        "root");
161:                TreeModel treeModel = new TreeModel(rootNode);
162:                this .m_tree = new JTree(treeModel);
163:                this .m_tree.setRootVisible(false);
164:
165:                this .m_tree.setShowsRootHandles(true);
166:                this .m_tree.setLargeModel(true);
167:
168:                this .m_tree.setCellRenderer(new PermissionsTreeCellRenderer());
169:                m_tree.getSelectionModel().setSelectionMode(
170:                        TreeSelectionModel.SINGLE_TREE_SELECTION);
171:                this .m_tree.setVisible(true);
172:                this .m_tree
173:                        .addTreeSelectionListener(new PermissionsTreeSelectionListener(
174:                                this .m_tree));
175:
176:                m_scroller = new JScrollPane(this .m_tree,
177:                        JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
178:                        JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
179:                m_scroller.setBorder(BorderFactory
180:                        .createLineBorder(Color.BLACK));
181:                this .add(m_scroller);
182:
183:                this .m_newRoleButton = new JButton("New role");
184:                this .m_newRoleButton.setFont(font);
185:                this .m_newRoleButton.setActionCommand("NEW_ROLE");
186:                this .m_newRoleButton.addActionListener(this );
187:                this .add(this .m_newRoleButton);
188:
189:                SwingUtilities.invokeLater(this );
190:            }
191:
192:            /* (non-Javadoc)
193:             * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
194:             */
195:            public void layoutContainer(Container arg0) {
196:
197:                int nHeight = 20;
198:
199:                this .m_descriptionTextArea.setSize(350, 30);
200:                this .m_descriptionTextArea.setLocation(20, nHeight);
201:                nHeight = nHeight + this .m_descriptionTextArea.getSize().height
202:                        + 10;
203:
204:                this .m_list.setLocation(20, nHeight);
205:                this .m_list.setSize(340, 100);
206:                nHeight = nHeight + this .m_list.getSize().height + 10;
207:
208:                this .m_newRoleButton.setLocation(280, nHeight);
209:                this .m_newRoleButton.setSize(80, 20);
210:                nHeight = nHeight + this .m_newRoleButton.getSize().height + 10;
211:
212:                this .m_scroller.setLocation(20, nHeight);
213:                this .m_scroller.setSize(340, 180);
214:                nHeight = nHeight + this .m_scroller.getSize().height + 10;
215:            }
216:
217:            /* (non-Javadoc)
218:             * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
219:             */
220:            public void actionPerformed(ActionEvent ae) {
221:                if (ae.getActionCommand().equals("NEW_ROLE")) {
222:                    JFrame frame = new JFrame();
223:                    frame.setIconImage(((ImageIcon) IconManager.getInstance()
224:                            .getIcon("32-sim-logo.gif")).getImage());
225:
226:                    SingleTextEntryDialog txtEntry = new SingleTextEntryDialog(
227:                            frame, "New Role Name");
228:                    txtEntry.setLabelText("Enter the name of the new role.");
229:                    txtEntry.show();
230:
231:                    String sValue = txtEntry.getTextValue();
232:                    if (sValue != null && sValue.trim().length() > 0) {
233:                        StateHandler.getInstance().addWait("NEW_ROLE");
234:                        try {
235:                            VirtualFile vfRoleDir = this .getRoleCollection();
236:                            String sPath = vfRoleDir.getFullPath() + "/"
237:                                    + txtEntry.getTextValue();
238:                            if (EditorController.getInstance().createNew(sPath,
239:                                    vfRoleDir.getVFS()).isOK()) {
240:                                VirtualFile vfTemp = this .m_vfs.getVirtualFile(
241:                                        sPath).getResource();
242:                                if (vfTemp.isVersionable()
243:                                        && ((VersionedVirtualFile) vfTemp)
244:                                                .hasPendingVersion()) {
245:                                    VersionedVirtualFile vfPending = (VersionedVirtualFile) vfTemp
246:                                            .getVFS()
247:                                            .getVirtualFile(
248:                                                    ((VersionedVirtualFile) vfTemp)
249:                                                            .getPendingVersionPath())
250:                                            .getResource();
251:                                    if (vfPending != null) {
252:                                        vfPending.checkin();
253:                                    }
254:                                } else if (vfTemp.isVersionable()
255:                                        && ((VersionedVirtualFile) vfTemp)
256:                                                .getState() == VirtualFile.STATE_PENDING) {
257:                                    ((VersionedVirtualFile) vfTemp).checkin();
258:                                }
259:                            }
260:
261:                            this .remove(m_list);
262:                            this .m_list = new PermissionsSelectionList();
263:                            this .m_list.addPermissionsSelectionListener(this );
264:                            this .add(m_list);
265:                            VirtualFile vfRoleCollection = this 
266:                                    .getRoleCollection();
267:                            Iterator itor = vfRoleCollection.getChildren()
268:                                    .iterator();
269:                            while (itor.hasNext()) {
270:                                String sChildPath = (String) itor.next();
271:                                if (!sChildPath
272:                                        .equals("/webdav/RBS_VALS/roles/BROWSER")) {
273:                                    this .m_list.addFile(sChildPath,
274:                                            vfRoleCollection.getVFS());
275:                                }
276:                            }
277:
278:                            this .m_list.selectPermission(sPath);
279:                        } catch (Exception e) {
280:                            e.printStackTrace();
281:                        } finally {
282:                            StateHandler.getInstance().removeWait("NEW_ROLE");
283:                        }
284:                    }
285:                }
286:            }
287:
288:            /* (non-Javadoc)
289:             * @see com.simulacramedia.contentmanager.serverconfig.permissions.list.PermissionsSelectionListener#permissionSelected(java.lang.String)
290:             */
291:            public void permissionSelected(String sPath) {
292:                StateHandler.getInstance().addWait(this .m_dialog,
293:                        "PERMISSIONS-SELECTION");
294:                try {
295:                    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(
296:                            "root");
297:                    TreeModel treeModel = new TreeModel(rootNode);
298:                    this .m_tree.setModel(treeModel);
299:                    this .m_tree
300:                            .addMouseListener(new PermissionsTreeSelectionListener(
301:                                    this .m_tree));
302:
303:                    if (this .m_vfCurrentRole != null) {
304:                        this .m_vfCurrentRole.removeVirtualFileListener(this );
305:                    }
306:
307:                    VirtualFile vfRole = this .m_vfs.getVirtualFile(sPath)
308:                            .getResource();
309:
310:                    vfRole.addVirtualFileListener(this );
311:
312:                    Iterator itor = getObjectPropertyDefinitions().iterator();
313:                    while (itor.hasNext()) {
314:                        Property prop = (Property) itor.next();
315:                        ValueRange range = (ValueRange) prop.getRange();
316:                        PropertyInstance propInst = vfRole.getProperty(prop
317:                                .getNamespace(), prop.getName());
318:
319:                        if (range.getValueGroups().size() > 0) {
320:                            PermissionsTreeNode node = new PermissionsTreeNode(
321:                                    propInst, (ValueGroup) range
322:                                            .getValueGroups().get(0), true);
323:                            rootNode.add(node);
324:                        } else {
325:                            System.err
326:                                    .println("PERMISSIONS: No ValueGroup for Property ["
327:                                            + prop.getHREF() + "]");
328:                        }
329:                    }
330:
331:                    this .validateTree();
332:
333:                    SwingUtilities.invokeLater(this );
334:                } catch (Exception e) {
335:                    e.printStackTrace(System.err);
336:                } finally {
337:                    StateHandler.getInstance().removeWait(this .m_dialog,
338:                            "PERMISSIONS-SELECTION");
339:                }
340:
341:            }
342:
343:            /* (non-Javadoc)
344:             * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#applyChanges()
345:             */
346:            public boolean applyChanges() {
347:                boolean bOk = true;
348:                Iterator itor = this .getRoleCollection().getChildren()
349:                        .iterator();
350:                while (itor.hasNext()) {
351:                    String sPath = (String) itor.next();
352:                    VirtualFile vfTemp = this .m_vfs.getVirtualFile(sPath)
353:                            .getResource();
354:                    if (vfTemp.isChanged()) {
355:                        StatusData status = vfTemp.sync();
356:                        if (status.isOK()) {
357:                            vfTemp = this .m_vfs.getVirtualFile(sPath)
358:                                    .getResource();
359:                            if (vfTemp.isVersionable()
360:                                    && ((VersionedVirtualFile) vfTemp)
361:                                            .hasPendingVersion()) {
362:                                VersionedVirtualFile vfPending = (VersionedVirtualFile) vfTemp
363:                                        .getVFS()
364:                                        .getVirtualFile(
365:                                                ((VersionedVirtualFile) vfTemp)
366:                                                        .getPendingVersionPath())
367:                                        .getResource();
368:                                if (vfPending != null) {
369:                                    vfPending.checkin();
370:                                }
371:                            } else if (vfTemp.getState() == VirtualFile.STATE_PENDING
372:                                    && vfTemp.isVersionable()
373:                                    && ((VersionedVirtualFile) vfTemp)
374:                                            .getLiveVersionPath() == null) {
375:                                ((VersionedVirtualFile) vfTemp).checkin();
376:                            }
377:                            this .permissionSelected(sPath);
378:                        } else {
379:                            bOk = false;
380:                        }
381:                    }
382:                }
383:                return bOk;
384:            }
385:
386:            /* (non-Javadoc)
387:             * @see com.simulacramedia.contentmanager.configuration.ApplyChangesListener#discardChanges()
388:             */
389:            public void discardChanges() {
390:                Iterator itor = this .getRoleCollection().getChildren()
391:                        .iterator();
392:                while (itor.hasNext()) {
393:                    String sPath = (String) itor.next();
394:                    this .m_vfs.discardFileChanges(sPath);
395:                }
396:            }
397:
398:            /* (non-Javadoc)
399:             * @see java.lang.Runnable#run()
400:             */
401:            public void run() {
402:                this .doLayout();
403:                this .m_tree.expandPath(new TreePath(
404:                        ((DefaultMutableTreeNode) this .m_tree.getModel()
405:                                .getRoot()).getPath()));
406:            }
407:
408:            /**
409:             * Returns the collection containing the roles.
410:             * 
411:             * @return collection containing the roles.
412:             */
413:            private VirtualFile getRoleCollection() {
414:                return this .m_vfs.getVirtualFile("/webdav/RBS_VALS/roles")
415:                        .getResource();
416:            }
417:
418:            /**
419:             * Returns a list of  for Object Properties.
420:             * 
421:             * @return List of {@link Property} objects.
422:             */
423:            public static List getObjectPropertyDefinitions() {
424:                ArrayList aProperties = new ArrayList();
425:                Server server = null;
426:                server = ServerList.getInstance().getHarmoniseServer();
427:                VirtualFile vfCollection = server.getVFS().getVirtualFile(
428:                        "/webdav/RBS_PROPS/object").getResource();
429:                Iterator itor = vfCollection.getChildren().iterator();
430:                while (itor.hasNext()) {
431:                    String sPath = (String) itor.next();
432:                    Property prop = PropertyCache.getInstance()
433:                            .getPropertyByPath(sPath);
434:                    aProperties.add(prop);
435:                }
436:
437:                return aProperties;
438:            }
439:
440:            /* (non-Javadoc)
441:             * @see java.awt.Component#getPreferredSize()
442:             */
443:            public Dimension getPreferredSize() {
444:                return new Dimension(this .getParent().getSize().width - 50, 100);
445:            }
446:
447:            /* (non-Javadoc)
448:             * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
449:             */
450:            public Dimension minimumLayoutSize(Container arg0) {
451:                return this .getPreferredSize();
452:            }
453:
454:            /* (non-Javadoc)
455:             * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
456:             */
457:            public Dimension preferredLayoutSize(Container arg0) {
458:                return this .getPreferredSize();
459:            }
460:
461:            /* (non-Javadoc)
462:             * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
463:             */
464:            public void removeLayoutComponent(Component arg0) {
465:            }
466:
467:            /* (non-Javadoc)
468:             * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
469:             */
470:            public void addLayoutComponent(String arg0, Component arg1) {
471:            }
472:
473:            /* (non-Javadoc)
474:             * @see com.simulacramedia.vfs.event.VirtualFileListener#virtualFileChanged(com.simulacramedia.vfs.event.VirtualFileEvent)
475:             */
476:            public void virtualFileChanged(VirtualFileEvent vfe) {
477:                if (vfe.getEventType() == VirtualFileEvent.FILE_METADATA_CHANGED) {
478:                    this.fireChangesMade();
479:                }
480:            }
481:
482:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.