directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tbenn...@apache.org
Subject svn commit: r486187 [30/49] - in /directory/trunks/triplesec: ./ admin-api/ admin-api/src/ admin-api/src/main/ admin-api/src/main/java/ admin-api/src/main/java/org/ admin-api/src/main/java/org/safehaus/ admin-api/src/main/java/org/safehaus/triplesec/ a...
Date Tue, 12 Dec 2006 15:24:14 GMT
Added: directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/NewRolePanel.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/NewRolePanel.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/NewRolePanel.java (added)
+++ directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/NewRolePanel.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,649 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.safehaus.triplesec.admin.swing;
+
+
+import java.awt.BorderLayout;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.util.Collections;
+import java.util.Enumeration;
+
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTabbedPane;
+import javax.swing.JTable;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+import javax.swing.ListSelectionModel;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+import javax.swing.table.AbstractTableModel;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeModel;
+
+import org.safehaus.triplesec.admin.Application;
+import org.safehaus.triplesec.admin.DataAccessException;
+import org.safehaus.triplesec.admin.Role;
+import org.safehaus.triplesec.admin.RoleModifier;
+
+
+public class NewRolePanel extends JPanel
+{
+    private static final long serialVersionUID = 1L;
+    private JPanel mainPanel = null;
+    private JPanel buttonPanel = null;
+    private JButton createButton = null;
+    private JPanel aboveButtonPanel = null;
+    private JPanel northPanel = null;
+    private JPanel southPanel = null;
+    private JLabel iconLabel = null;
+    private JPanel jPanel = null;
+    private JTextArea descriptionTextArea = null;
+    private JPanel iconPanel = null;
+    private DefaultMutableTreeNode node = null;
+    private LeftTreeNavigation leftTreeNavigation;
+    private JTabbedPane centerTabbedPane = null;
+    private JPanel existingPanelTab = null;
+    private JScrollPane jScrollPane = null;
+    private JTable existingRolesTable = null;
+    private ExistingRolesTableModel existingRolesTableModel = null; //  @jve:decl-index=0:visual-constraint=""
+    private JLabel jLabel = null;
+    private JTextField statusTextField = null;
+    private JLabel jLabel1 = null;
+    private JTextField roleNameTextField = null;
+    private JLabel jLabel2 = null;
+    private JTextField applicationNameTextField = null;
+    private RoleGrantsPanel roleGrantsPanel;
+    
+    
+    public void setLeftTreeNavigation( LeftTreeNavigation leftTreeNavigation )
+    {
+        this.leftTreeNavigation = leftTreeNavigation;
+    }
+
+
+    /**
+     * This is the default constructor
+     */
+    public NewRolePanel()
+    {
+        super();
+        initialize();
+    }
+
+
+    /**
+     * This method initializes this
+     * 
+     * @return void
+     */
+    private void initialize()
+    {
+        GridBagConstraints gridBagConstraints = new GridBagConstraints();
+        gridBagConstraints.gridx = 0;
+        gridBagConstraints.weightx = 1.0D;
+        gridBagConstraints.weighty = 1.0D;
+        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
+        gridBagConstraints.insets = new java.awt.Insets( 10, 10, 10, 10 );
+        gridBagConstraints.gridy = 0;
+        this.setLayout( new GridBagLayout() );
+        this.setSize( 550, 417 );
+        this.setBorder( javax.swing.BorderFactory.createTitledBorder( null, "New Role",
+            javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION,
+            null, null ) );
+        this.add( getMainPanel(), gridBagConstraints );
+    }
+
+
+    /**
+     * This method initializes jPanel	
+     * 	
+     * @return javax.swing.JPanel	
+     */
+    private JPanel getMainPanel()
+    {
+        if ( mainPanel == null )
+        {
+            mainPanel = new JPanel();
+            mainPanel.setLayout( new BorderLayout() );
+            mainPanel.add( getButtonPanel(), java.awt.BorderLayout.SOUTH );
+            mainPanel.add( getAboveButtonPanel(), java.awt.BorderLayout.CENTER );
+        }
+        return mainPanel;
+    }
+
+
+    /**
+     * This method initializes jPanel	
+     * 	
+     * @return javax.swing.JPanel	
+     */
+    private JPanel getButtonPanel()
+    {
+        if ( buttonPanel == null )
+        {
+            buttonPanel = new JPanel();
+            buttonPanel.setBorder( javax.swing.BorderFactory.createEmptyBorder( 0, 0, 0, 0 ) );
+            buttonPanel.add( getCreateButton(), null );
+        }
+        return buttonPanel;
+    }
+
+
+    /**
+     * This method initializes jButton	
+     * 	
+     * @return javax.swing.JButton	
+     */
+    private JButton getCreateButton()
+    {
+        if ( createButton == null )
+        {
+            createButton = new JButton();
+            createButton.setText( "Create" );
+            createButton.addActionListener( new java.awt.event.ActionListener()
+            {
+                public void actionPerformed( java.awt.event.ActionEvent e )
+                {
+                    createAction();
+                }
+            } );
+        }
+        return createButton;
+    }
+
+
+    /**
+     * This method initializes jPanel	
+     * 	
+     * @return javax.swing.JPanel	
+     */
+    private JPanel getAboveButtonPanel()
+    {
+        if ( aboveButtonPanel == null )
+        {
+            aboveButtonPanel = new JPanel();
+            aboveButtonPanel.setLayout( new BorderLayout() );
+            aboveButtonPanel.add( getNorthPanel(), java.awt.BorderLayout.NORTH );
+            aboveButtonPanel.add( getSouthPanel(), java.awt.BorderLayout.SOUTH );
+            aboveButtonPanel.add( getCenterTabbedPane(), java.awt.BorderLayout.CENTER );
+        }
+        return aboveButtonPanel;
+    }
+
+
+    /**
+     * This method initializes jPanel	
+     * 	
+     * @return javax.swing.JPanel	
+     */
+    private JPanel getNorthPanel()
+    {
+        if ( northPanel == null )
+        {
+            GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
+            gridBagConstraints1.gridx = 1;
+            gridBagConstraints1.weightx = 1.0D;
+            gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
+            gridBagConstraints1.gridheight = 3;
+            gridBagConstraints1.insets = new java.awt.Insets( 0, 10, 0, 10 );
+            gridBagConstraints1.weighty = 1.0D;
+            gridBagConstraints1.gridy = 0;
+            northPanel = new JPanel();
+            northPanel.setLayout( new GridBagLayout() );
+            northPanel.setPreferredSize( new java.awt.Dimension( 179, 68 ) );
+            northPanel.add( getIconPanel(), new GridBagConstraints() );
+            northPanel.add( getJPanel(), gridBagConstraints1 );
+        }
+        return northPanel;
+    }
+
+
+    /**
+     * This method initializes jPanel	
+     * 	
+     * @return javax.swing.JPanel	
+     */
+    private JPanel getSouthPanel()
+    {
+        if ( southPanel == null )
+        {
+            southPanel = new JPanel();
+            southPanel.setLayout( new BorderLayout() );
+            southPanel.setBorder( javax.swing.BorderFactory.createTitledBorder( null, "Description",
+                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
+                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null ) );
+            southPanel.add( getDescriptionTextArea(), java.awt.BorderLayout.NORTH );
+        }
+        return southPanel;
+    }
+
+
+    /**
+     * This method initializes iconLabel
+     * 	
+     * @return javax.swing.JLabel	
+     */
+    private JLabel getIconLabel()
+    {
+        if ( iconLabel == null )
+        {
+            iconLabel = new JLabel();
+            iconLabel.setIcon( new ImageIcon( getClass().getResource(
+                "/org/safehaus/triplesec/admin/swing/new_role_48x48.png" ) ) );
+            iconLabel.setPreferredSize( new java.awt.Dimension( 48, 48 ) );
+            iconLabel.setText( "" );
+            iconLabel.setVerticalTextPosition( javax.swing.SwingConstants.BOTTOM );
+            iconLabel.setVerticalAlignment( javax.swing.SwingConstants.BOTTOM );
+            iconLabel.setEnabled( true );
+        }
+        return iconLabel;
+    }
+
+
+    /**
+     * This method initializes jPanel	
+     * 	
+     * @return javax.swing.JPanel	
+     */
+    private JPanel getJPanel()
+    {
+        if ( jPanel == null )
+        {
+            GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
+            gridBagConstraints8.fill = java.awt.GridBagConstraints.HORIZONTAL;
+            gridBagConstraints8.gridy = 1;
+            gridBagConstraints8.weightx = 1.0;
+            gridBagConstraints8.insets = new java.awt.Insets(0,0,5,0);
+            gridBagConstraints8.gridx = 1;
+            GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
+            gridBagConstraints7.gridx = 0;
+            gridBagConstraints7.fill = java.awt.GridBagConstraints.HORIZONTAL;
+            gridBagConstraints7.insets = new java.awt.Insets(0,0,5,5);
+            gridBagConstraints7.gridy = 1;
+            jLabel2 = new JLabel();
+            jLabel2.setText("Application Name:");
+            jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
+            GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
+            gridBagConstraints6.fill = java.awt.GridBagConstraints.HORIZONTAL;
+            gridBagConstraints6.insets = new java.awt.Insets( 0, 0, 5, 5 );
+            GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
+            gridBagConstraints5.fill = java.awt.GridBagConstraints.HORIZONTAL;
+            gridBagConstraints5.gridy = 2;
+            gridBagConstraints5.weightx = 1.0;
+            gridBagConstraints5.gridx = 1;
+            GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
+            gridBagConstraints3.gridx = 0;
+            gridBagConstraints3.fill = java.awt.GridBagConstraints.HORIZONTAL;
+            gridBagConstraints3.insets = new java.awt.Insets( 0, 0, 0, 5 );
+            gridBagConstraints3.gridy = 2;
+            jLabel1 = new JLabel();
+            jLabel1.setText("Role Name:");
+            jLabel1.setHorizontalAlignment( javax.swing.SwingConstants.RIGHT );
+            GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
+            gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
+            gridBagConstraints2.gridy = 0;
+            gridBagConstraints2.weightx = 1.0;
+            gridBagConstraints2.insets = new java.awt.Insets( 0, 0, 5, 0 );
+            gridBagConstraints2.gridx = 1;
+            jLabel = new JLabel();
+            jLabel.setText( "Status:" );
+            jLabel.setHorizontalAlignment( javax.swing.SwingConstants.RIGHT );
+            jPanel = new JPanel();
+            jPanel.setLayout( new GridBagLayout() );
+            jPanel.setPreferredSize( new java.awt.Dimension( 131, 88 ) );
+            jPanel.add( jLabel, gridBagConstraints6 );
+            jPanel.add( getStatusTextField(), gridBagConstraints2 );
+            jPanel.add(jLabel1, gridBagConstraints3);
+            jPanel.add(getRoleNameTextField(), gridBagConstraints5);
+            jPanel.add(jLabel2, gridBagConstraints7);
+            jPanel.add(getApplicationNameTextField(), gridBagConstraints8);
+        }
+        return jPanel;
+    }
+
+
+    /**
+     * This method initializes jTextArea	
+     * 	
+     * @return javax.swing.JTextArea	
+     */
+    private JTextArea getDescriptionTextArea()
+    {
+        if ( descriptionTextArea == null )
+        {
+            descriptionTextArea = new JTextArea();
+            descriptionTextArea.setRows( 3 );
+        }
+        return descriptionTextArea;
+    }
+
+
+    /**
+     * This method initializes jPanel4	
+     * 	
+     * @return javax.swing.JPanel	
+     */
+    private JPanel getIconPanel()
+    {
+        if ( iconPanel == null )
+        {
+            iconPanel = new JPanel();
+            iconPanel
+                .setBorder( javax.swing.BorderFactory.createEtchedBorder( javax.swing.border.EtchedBorder.RAISED ) );
+            iconPanel.add( getIconLabel(), null );
+        }
+        return iconPanel;
+    }
+
+
+    public void setTreeNode( DefaultMutableTreeNode node )
+    {
+        this.node = node;
+        existingRolesTable.setModel( new ExistingRolesTableModel() );
+        DefaultMutableTreeNode appNode = ( DefaultMutableTreeNode ) node.getParent();
+        Application application = ( Application ) appNode.getUserObject();
+        applicationNameTextField.setText( application.getName() );
+        roleGrantsPanel.populateLists( appNode, Collections.EMPTY_SET );
+    }
+
+
+    public String noNull( Object obj )
+    {
+        if ( obj == null )
+        {
+            return "";
+        }
+        return obj.toString();
+    }
+
+
+    public DefaultMutableTreeNode getTreeNode()
+    {
+        return node;
+    }
+
+
+    public void createAction()
+    {
+        if ( roleNameTextField.getText() == null || roleNameTextField.getText().equals( "" ) )
+        {
+            return;
+        }
+        
+        DefaultMutableTreeNode appNode = ( DefaultMutableTreeNode ) node.getParent();
+        Application application = ( Application ) appNode.getUserObject();
+        Role role;
+        RoleModifier modifier = application.modifier().newRole( roleNameTextField.getText() )
+            .setDescription( descriptionTextArea.getText() );
+        
+        for ( Enumeration ii = roleGrantsPanel.getRoleGrantsModel().elements(); ii.hasMoreElements(); /**/ )
+        {
+            modifier.addGrant( ( String ) ii.nextElement() );
+        }
+        for ( Enumeration ii = roleGrantsPanel.getAvailablePermssionsModel().elements(); ii.hasMoreElements(); /**/ )
+        {
+            modifier.removeGrant( ( String ) ii.nextElement() );
+        }
+        
+        try
+        {
+            role = modifier.add();
+            DefaultMutableTreeNode roleNode = new DefaultMutableTreeNode( role );
+            DefaultTreeModel model = ( DefaultTreeModel ) leftTreeNavigation.getTree().getModel();
+            model.insertNodeInto( roleNode, node, 0 );
+            existingRolesTableModel.fireTableDataChanged();
+        }
+        catch ( DataAccessException e )
+        {
+            JOptionPane.showMessageDialog( this,
+                UiUtils.wrap( "Failed to create role:\n" + e.getMessage(), 79 ),
+                "Role creation failure!", JOptionPane.ERROR_MESSAGE );
+            return;
+        }
+        roleNameTextField.setText( null );
+        statusTextField.setText( null );
+    }
+
+
+    /**
+     * This method initializes jTabbedPane	
+     * 	
+     * @return javax.swing.JTabbedPane	
+     */
+    private JTabbedPane getCenterTabbedPane()
+    {
+        if ( centerTabbedPane == null )
+        {
+            centerTabbedPane = new JTabbedPane();
+            centerTabbedPane.addTab( "Existing", null, getExistingPanelTab(),
+                "Copy a role from any one of these existing roles." );
+            centerTabbedPane.addTab( "Grants", null, getRoleGrantsPanel() );
+        }
+        return centerTabbedPane;
+    }
+
+    
+    private RoleGrantsPanel getRoleGrantsPanel()
+    {
+        if ( roleGrantsPanel == null )
+        {
+            roleGrantsPanel = new RoleGrantsPanel();
+        }
+        return roleGrantsPanel;
+    }
+    
+
+    /**
+     * This method initializes jPanel3	
+     * 	
+     * @return javax.swing.JPanel	
+     */
+    private JPanel getExistingPanelTab()
+    {
+        if ( existingPanelTab == null )
+        {
+            GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
+            gridBagConstraints4.fill = java.awt.GridBagConstraints.BOTH;
+            gridBagConstraints4.gridy = 0;
+            gridBagConstraints4.weightx = 1.0;
+            gridBagConstraints4.weighty = 1.0;
+            gridBagConstraints4.gridx = 0;
+            existingPanelTab = new JPanel();
+            existingPanelTab.setLayout( new GridBagLayout() );
+            existingPanelTab.add( getJScrollPane(), gridBagConstraints4 );
+        }
+        return existingPanelTab;
+    }
+
+
+    /**
+     * This method initializes jScrollPane	
+     * 	
+     * @return javax.swing.JScrollPane	
+     */
+    private JScrollPane getJScrollPane()
+    {
+        if ( jScrollPane == null )
+        {
+            jScrollPane = new JScrollPane();
+            jScrollPane.setViewportView( getExistingRolesTable() );
+        }
+        return jScrollPane;
+    }
+
+
+    /**
+     * This method initializes jTable	
+     * 	
+     * @return javax.swing.JTable	
+     */
+    private JTable getExistingRolesTable()
+    {
+        if ( existingRolesTable == null )
+        {
+            existingRolesTable = new JTable();
+            existingRolesTable.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
+            existingRolesTable.getSelectionModel().addListSelectionListener( new ListSelectionListener()
+            {
+                public void valueChanged( ListSelectionEvent e )
+                {
+                    int index = existingRolesTable.getSelectionModel().getAnchorSelectionIndex();
+                    if ( existingRolesTableModel.getRowCount() == 0 || index < 0 )
+                    {
+                        return;
+                    }
+                    Role role = ( Role ) existingRolesTableModel.getValueAt( index, 0 );
+                    roleNameTextField.setText( "CopyOf" + role.getName() );
+                    descriptionTextArea.setText( role.getDescription() );
+                    roleGrantsPanel.populateLists( ( DefaultMutableTreeNode ) node.getParent(), role.getGrants() );
+                }
+            } );
+            existingRolesTable.setModel( getExistingRolesTableModel() );
+        }
+        return existingRolesTable;
+    }
+
+
+    /**
+     * This method initializes defaultTableModel	
+     * 	
+     * @return javax.swing.table.DefaultTableModel	
+     */
+    private ExistingRolesTableModel getExistingRolesTableModel()
+    {
+        if ( existingRolesTableModel == null )
+        {
+            existingRolesTableModel = new ExistingRolesTableModel();
+        }
+        return existingRolesTableModel;
+    }
+    
+
+    class ExistingRolesTableModel extends AbstractTableModel
+    {
+        private static final long serialVersionUID = 1L;
+
+
+        public int getRowCount()
+        {
+            if ( node == null )
+            {
+                return 0;
+            }
+            return node.getChildCount();
+        }
+
+
+        public int getColumnCount()
+        {
+            return 3;
+        }
+
+
+        public Object getValueAt( int rowIndex, int columnIndex )
+        {
+            if ( node == null )
+            {
+                return null;
+            }
+
+            DefaultMutableTreeNode child = ( DefaultMutableTreeNode ) node.getChildAt( rowIndex );
+            switch ( columnIndex )
+            {
+                case ( 0 ):
+                    return child.getUserObject();
+                case ( 1 ):
+                    return ( ( Role ) child.getUserObject() ).getCreatorsName();
+                case ( 2 ):
+                    return ( ( Role) child.getUserObject() ).getCreateTimestamp();
+            }
+            return child.getUserObject();
+        }
+
+    
+        public String getColumnName( int columnIndex )
+        {
+            switch ( columnIndex )
+            {
+                case ( 0 ):
+                    return "Existing Role";
+                case ( 1 ):
+                    return "Creator's Name";
+                case ( 2 ):
+                    return "Create Timestamp";
+                default:
+                    throw new IndexOutOfBoundsException();
+            }
+        }
+    }
+
+
+    /**
+     * This method initializes jTextField	
+     * 	
+     * @return javax.swing.JTextField	
+     */
+    private JTextField getStatusTextField()
+    {
+        if ( statusTextField == null )
+        {
+            statusTextField = new JTextField();
+            statusTextField.setEditable( false );
+        }
+        return statusTextField;
+    }
+
+
+    /**
+     * This method initializes jTextField1	
+     * 	
+     * @return javax.swing.JTextField	
+     */
+    private JTextField getRoleNameTextField()
+    {
+        if ( roleNameTextField == null )
+        {
+            roleNameTextField = new JTextField();
+        }
+        return roleNameTextField;
+    }
+
+
+    /**
+     * This method initializes jTextField	
+     * 	
+     * @return javax.swing.JTextField	
+     */
+    private JTextField getApplicationNameTextField()
+    {
+        if ( applicationNameTextField == null )
+        {
+            applicationNameTextField = new JTextField();
+            applicationNameTextField.setEditable(false);
+        }
+        return applicationNameTextField;
+    }
+} //  @jve:decl-index=0:visual-constraint="10,10"

Added: directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/NewUserPanel.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/NewUserPanel.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/NewUserPanel.java (added)
+++ directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/NewUserPanel.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,738 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.safehaus.triplesec.admin.swing;
+
+
+import java.awt.BorderLayout;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTabbedPane;
+import javax.swing.JTable;
+import javax.swing.JTextArea;
+import javax.swing.ListSelectionModel;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+import javax.swing.table.AbstractTableModel;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeModel;
+
+import org.safehaus.triplesec.admin.DataAccessException;
+import org.safehaus.triplesec.admin.ExternalUser;
+import org.safehaus.triplesec.admin.ExternalUserModifier;
+import org.safehaus.triplesec.admin.HauskeysUser;
+import org.safehaus.triplesec.admin.HauskeysUserModifier;
+import org.safehaus.triplesec.admin.LocalUser;
+import org.safehaus.triplesec.admin.LocalUserModifier;
+import org.safehaus.triplesec.admin.TriplesecAdmin;
+import org.safehaus.triplesec.admin.User;
+
+
+public class NewUserPanel extends JPanel implements StatusListener, StatusObject, KeyListener, FocusListener
+{
+    private static final long serialVersionUID = 1L;
+    private JPanel mainPanel = null;
+    private JPanel buttonPanel = null;
+    private JButton createButton = null;
+    private JPanel aboveButtonPanel = null;
+    private UserNorthPanel userNorthPanel = null;
+    private JPanel southPanel = null;
+    private JTextArea descriptionTextArea = null;
+    private DefaultMutableTreeNode node = null;
+    private LeftTreeNavigation leftTreeNavigation;
+    private JTabbedPane centerTabbedPane = null;
+    private JPanel existingPanelTab = null;
+    private JScrollPane jScrollPane = null;
+    private JTable existingUsersTable = null;
+    private TriplesecAdmin triplesecAdmin;
+    private ExistingUsersTableModel existingUsersTableModel = null; //  @jve:decl-index=0:visual-constraint=""
+    private ImageIcon newUserIcon = new ImageIcon( getClass().getResource(
+        "/org/safehaus/triplesec/admin/swing/new_user_48x48.png" ) );
+    private ProvisioningPanel provisioningPanel;
+    private HotpSettingsPanel hotpSettingsPanel;
+    private ExternalLinkPanel externalLinkPanel;
+    private UserInfoPanel userInfoPanel;
+    private boolean lastStatusState = true;
+    private StatusListener listener = this;
+
+
+    public void setLeftTreeNavigation( LeftTreeNavigation leftTreeNavigation )
+    {
+        this.leftTreeNavigation = leftTreeNavigation;
+    }
+
+
+    public void setTriplesecAdmin( TriplesecAdmin triplesecAdmin )
+    {
+        this.triplesecAdmin = triplesecAdmin;
+    }
+
+
+    /**
+     * This is the default constructor
+     */
+    public NewUserPanel()
+    {
+        super();
+        initialize();
+    }
+
+
+    /**
+     * This method initializes this
+     * 
+     * @return void
+     */
+    private void initialize()
+    {
+        GridBagConstraints gridBagConstraints = new GridBagConstraints();
+        gridBagConstraints.gridx = 0;
+        gridBagConstraints.weightx = 1.0D;
+        gridBagConstraints.weighty = 1.0D;
+        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
+        gridBagConstraints.insets = new java.awt.Insets( 10, 10, 10, 10 );
+        gridBagConstraints.gridy = 0;
+        this.setLayout( new GridBagLayout() );
+        this.setSize( 550, 417 );
+        this.setBorder( javax.swing.BorderFactory.createTitledBorder( null, "New User",
+            javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION,
+            null, null ) );
+        this.add( getMainPanel(), gridBagConstraints );
+    }
+
+
+    /**
+     * This method initializes jPanel	
+     * 	
+     * @return javax.swing.JPanel	
+     */
+    private JPanel getMainPanel()
+    {
+        if ( mainPanel == null )
+        {
+            mainPanel = new JPanel();
+            mainPanel.setLayout( new BorderLayout() );
+            mainPanel.add( getButtonPanel(), java.awt.BorderLayout.SOUTH );
+            mainPanel.add( getAboveButtonPanel(), java.awt.BorderLayout.CENTER );
+        }
+        return mainPanel;
+    }
+
+
+    /**
+     * This method initializes jPanel	
+     * 	
+     * @return javax.swing.JPanel	
+     */
+    private JPanel getButtonPanel()
+    {
+        if ( buttonPanel == null )
+        {
+            buttonPanel = new JPanel();
+            buttonPanel.setBorder( javax.swing.BorderFactory.createEmptyBorder( 0, 0, 0, 0 ) );
+            buttonPanel.add( getCreateButton(), null );
+        }
+        return buttonPanel;
+    }
+
+
+    /**
+     * This method initializes jButton	
+     * 	
+     * @return javax.swing.JButton	
+     */
+    private JButton getCreateButton()
+    {
+        if ( createButton == null )
+        {
+            createButton = new JButton();
+            createButton.setText( "Create" );
+            createButton.addActionListener( new java.awt.event.ActionListener()
+            {
+                public void actionPerformed( java.awt.event.ActionEvent e )
+                {
+                    createAction();
+                }
+            } );
+        }
+        return createButton;
+    }
+
+
+    /**
+     * This method initializes jPanel	
+     * 	
+     * @return javax.swing.JPanel	
+     */
+    private JPanel getAboveButtonPanel()
+    {
+        if ( aboveButtonPanel == null )
+        {
+            aboveButtonPanel = new JPanel();
+            aboveButtonPanel.setLayout( new BorderLayout() );
+            aboveButtonPanel.add( getUserNorthPanel(), java.awt.BorderLayout.NORTH );
+            aboveButtonPanel.add( getSouthPanel(), java.awt.BorderLayout.SOUTH );
+            aboveButtonPanel.add( getCenterTabbedPane(), java.awt.BorderLayout.CENTER );
+        }
+        return aboveButtonPanel;
+    }
+
+
+    /**
+     * This method initializes jPanel	
+     * 	
+     * @return javax.swing.JPanel	
+     */
+    private UserNorthPanel getUserNorthPanel()
+    {
+        if ( userNorthPanel == null )
+        {
+            userNorthPanel = new UserNorthPanel();
+            userNorthPanel.setNewEntityMode( true );
+            userNorthPanel.setStatusListener( this );
+            userNorthPanel.setIcon( newUserIcon );
+            userNorthPanel.addActionListener( new ActionListener()
+            {
+                public void actionPerformed( ActionEvent e )
+                {
+                    if ( userNorthPanel.isExternalUserSelected() )
+                    {
+                        centerTabbedPane.removeAll();
+                        centerTabbedPane.addTab( "Existing", null, existingPanelTab );
+                        centerTabbedPane.addTab( "External Link", null, externalLinkPanel );
+                    }
+                    else if ( userNorthPanel.isLocalUserSelected() )
+                    {
+                        centerTabbedPane.removeAll();
+                        centerTabbedPane.addTab( "Existing", null, existingPanelTab );
+                        centerTabbedPane.addTab( "User Info", null, userInfoPanel );
+                    }
+                    else if ( userNorthPanel.isHauskeysUserSelected() )
+                    {
+                        centerTabbedPane.removeAll();
+                        centerTabbedPane.addTab( "Existing", null, existingPanelTab );
+                        centerTabbedPane.addTab( "User Info", null, userInfoPanel );
+                        centerTabbedPane.addTab( "Provisioning", null, provisioningPanel );
+                        centerTabbedPane.addTab( "HOTP Settings", null, hotpSettingsPanel );
+                    }
+                    else
+                    {
+                        throw new IllegalStateException( "Radio buttons should be mutually exclusive!" );
+                    }
+                }
+            } );
+        }
+        return userNorthPanel;
+    }
+
+
+    /**
+     * This method initializes jPanel	
+     * 	
+     * @return javax.swing.JPanel	
+     */
+    private JPanel getSouthPanel()
+    {
+        if ( southPanel == null )
+        {
+            southPanel = new JPanel();
+            southPanel.setLayout( new BorderLayout() );
+            southPanel.setBorder( javax.swing.BorderFactory.createTitledBorder( null, "Description",
+                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
+                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null ) );
+            southPanel.add( getDescriptionTextArea(), java.awt.BorderLayout.NORTH );
+        }
+        return southPanel;
+    }
+
+
+    /**
+     * This method initializes jTextArea	
+     * 	
+     * @return javax.swing.JTextArea	
+     */
+    private JTextArea getDescriptionTextArea()
+    {
+        if ( descriptionTextArea == null )
+        {
+            descriptionTextArea = new JTextArea();
+            descriptionTextArea.setRows( 3 );
+            descriptionTextArea.addKeyListener( this );
+            descriptionTextArea.addFocusListener( this );
+        }
+        return descriptionTextArea;
+    }
+
+
+    public void setTreeNode( DefaultMutableTreeNode node )
+    {
+        this.node = node;
+        existingUsersTable.setModel( new ExistingUsersTableModel() );
+    }
+
+
+    public DefaultMutableTreeNode getTreeNode()
+    {
+        return node;
+    }
+
+
+    public void createExternalUser()
+    {
+        ExternalUser user;
+        ExternalUserModifier modifier = triplesecAdmin.newExternalUser( userNorthPanel.getId(),
+            externalLinkPanel.getReferral() ).setDescription( descriptionTextArea.getText() );
+        try
+        {
+            user = modifier.add();
+            DefaultMutableTreeNode userNode = new DefaultMutableTreeNode( user );
+            DefaultTreeModel model = ( DefaultTreeModel ) leftTreeNavigation.getTree().getModel();
+            model.insertNodeInto( userNode, node, 0 );
+            existingUsersTableModel.fireTableDataChanged();
+        }
+        catch ( DataAccessException e )
+        {
+            JOptionPane.showMessageDialog( this, UiUtils.wrap( "Failed to create user:\n" + e.getMessage(), 79 ),
+                "User creation failure!", JOptionPane.ERROR_MESSAGE );
+            return;
+        }
+    }
+
+
+    public void createLocalUser()
+    {
+        if ( ! userInfoPanel.isPasswordOk() )
+        {
+            JOptionPane.showMessageDialog( this, "Passwords are not equal or are invalid.  Create aborted!" );
+            return;
+        }
+        
+        LocalUser user;
+        LocalUserModifier modifier = triplesecAdmin.newLocalUser( userNorthPanel.getId(), userInfoPanel.getFirstName(), 
+                userInfoPanel.getLastName(), userInfoPanel.getPassword() );
+        modifier.setDescription( descriptionTextArea.getText() );
+        try
+        {
+            user = modifier.add();
+            DefaultMutableTreeNode userNode = new DefaultMutableTreeNode( user );
+            DefaultTreeModel model = ( DefaultTreeModel ) leftTreeNavigation.getTree().getModel();
+            model.insertNodeInto( userNode, node, 0 );
+            existingUsersTableModel.fireTableDataChanged();
+        }
+        catch ( DataAccessException e )
+        {
+            JOptionPane.showMessageDialog( this, UiUtils.wrap( "Failed to create user:\n" + e.getMessage(), 79 ),
+                "User creation failure!", JOptionPane.ERROR_MESSAGE );
+            return;
+        }
+    }
+
+
+    public void createHauskeysUser()
+    {
+        if ( ! userInfoPanel.isPasswordOk() )
+        {
+            JOptionPane.showMessageDialog( this, "Passwords are not equal or are invalid.  Create aborted!" );
+            return;
+        }
+
+        HauskeysUser user;
+        HauskeysUserModifier modifier = triplesecAdmin
+            .newHauskeysUser( userNorthPanel.getId(), userInfoPanel.getFirstName(), 
+                userInfoPanel.getLastName(), userInfoPanel.getPassword() )
+            .setDescription( descriptionTextArea.getText() ).setPassword( userInfoPanel.getPassword() )
+            .setActivationKey( hotpSettingsPanel.getActivationKey() )
+            .setSecret( hotpSettingsPanel.getSecret() )
+            .setMovingFactor( hotpSettingsPanel.getMovingFactor() )
+            .setFailuresInEpoch( hotpSettingsPanel.getFailuresInEpoch() )
+            .setEmail( provisioningPanel.getEmail() )
+            .setMidletName( provisioningPanel.getMidletName() )
+            .setMobile( provisioningPanel.getMobile() )
+            .setMobileCarrier( String.valueOf( provisioningPanel.getMobileCarrier() ) )
+            .setNotifyBy( provisioningPanel.getNotifyBy() )
+            .setRealm( userInfoPanel.getRealm() )
+            .setTokenPin( provisioningPanel.getTokenPin() );
+        try
+        {
+            user = modifier.add();
+            DefaultMutableTreeNode userNode = new DefaultMutableTreeNode( user );
+            DefaultTreeModel model = ( DefaultTreeModel ) leftTreeNavigation.getTree().getModel();
+            model.insertNodeInto( userNode, node, 0 );
+            existingUsersTableModel.fireTableDataChanged();
+        }
+        catch ( DataAccessException e )
+        {
+            JOptionPane.showMessageDialog( this, UiUtils.wrap( "Failed to create user:\n" + e.getMessage(), 79 ),
+                "User creation failure!", JOptionPane.ERROR_MESSAGE );
+            return;
+        }
+    }
+
+
+    public void createAction()
+    {
+        if ( userNorthPanel.getId() == null || userNorthPanel.getId().equals( "" ) )
+        {
+            return;
+        }
+
+        if ( userNorthPanel.isExternalUserSelected() )
+        {
+            createExternalUser();
+        }
+        else if ( userNorthPanel.isLocalUserSelected() )
+        {
+            createLocalUser();
+        }
+        else if ( userNorthPanel.isHauskeysUserSelected() )
+        {
+            createHauskeysUser();
+        }
+        else
+        {
+            throw new IllegalStateException( "Radio buttons on north user panel should be mutually exclusive." );
+        }
+
+        clearAll();
+    }
+
+
+    public void clearAll()
+    {
+        userNorthPanel.setId( null );
+        userNorthPanel.setStatus( null );
+        this.lastStatusState = true;
+    }
+
+
+    /**
+     * This method initializes jTabbedPane	
+     * 	
+     * @return javax.swing.JTabbedPane	
+     */
+    private JTabbedPane getCenterTabbedPane()
+    {
+        if ( centerTabbedPane == null )
+        {
+            centerTabbedPane = new JTabbedPane();
+            centerTabbedPane.addTab( "Existing", null, getExistingPanelTab(),
+                "Copy a user from any one of these existing users." );
+            getExternalLinkPanel();
+            getUserInfoPanel();
+            getProvisioningPanel();
+            getHotpSettingsPanel();
+        }
+        return centerTabbedPane;
+    }
+
+
+    private HotpSettingsPanel getHotpSettingsPanel()
+    {
+        if ( hotpSettingsPanel == null )
+        {
+            hotpSettingsPanel = new HotpSettingsPanel();
+            hotpSettingsPanel.setNewEntityMode( true );
+            hotpSettingsPanel.setStatusListener( this );
+        }
+        return hotpSettingsPanel;
+    }
+
+
+    private ExternalLinkPanel getExternalLinkPanel()
+    {
+        if ( externalLinkPanel == null )
+        {
+            externalLinkPanel = new ExternalLinkPanel();
+            externalLinkPanel.setNewEntityMode( true );
+            externalLinkPanel.setStatusListener( this );
+        }
+        return externalLinkPanel;
+    }
+
+
+    private UserInfoPanel getUserInfoPanel()
+    {
+        if ( userInfoPanel == null )
+        {
+            userInfoPanel = new UserInfoPanel();
+            userInfoPanel.setNewEntityMode( true );
+            userInfoPanel.setStatusListener( this );
+        }
+        return userInfoPanel;
+    }
+
+
+    private ProvisioningPanel getProvisioningPanel()
+    {
+        if ( provisioningPanel == null )
+        {
+            provisioningPanel = new ProvisioningPanel();
+            provisioningPanel.setNewEntityMode( true );
+            provisioningPanel.setStatusListener( this );
+        }
+        return provisioningPanel;
+    }
+
+
+    /**
+     * This method initializes jPanel3	
+     * 	
+     * @return javax.swing.JPanel	
+     */
+    private JPanel getExistingPanelTab()
+    {
+        if ( existingPanelTab == null )
+        {
+            GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
+            gridBagConstraints4.fill = java.awt.GridBagConstraints.BOTH;
+            gridBagConstraints4.gridy = 0;
+            gridBagConstraints4.weightx = 1.0;
+            gridBagConstraints4.weighty = 1.0;
+            gridBagConstraints4.gridx = 0;
+            existingPanelTab = new JPanel();
+            existingPanelTab.setLayout( new GridBagLayout() );
+            existingPanelTab.add( getJScrollPane(), gridBagConstraints4 );
+        }
+        return existingPanelTab;
+    }
+
+
+    /**
+     * This method initializes jScrollPane	
+     * 	
+     * @return javax.swing.JScrollPane	
+     */
+    private JScrollPane getJScrollPane()
+    {
+        if ( jScrollPane == null )
+        {
+            jScrollPane = new JScrollPane();
+            jScrollPane.setViewportView( getExistingUsersTable() );
+        }
+        return jScrollPane;
+    }
+
+
+    /**
+     * This method initializes jTable	
+     * 	
+     * @return javax.swing.JTable	
+     */
+    private JTable getExistingUsersTable()
+    {
+        if ( existingUsersTable == null )
+        {
+            existingUsersTable = new JTable();
+            existingUsersTable.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
+            existingUsersTable.setModel( getExistingUsersTableModel() );
+            existingUsersTable.getSelectionModel().addListSelectionListener( new ListSelectionListener() {
+                public void valueChanged( ListSelectionEvent e )
+                {
+                    int index = existingUsersTable.getSelectionModel().getAnchorSelectionIndex();
+                    if ( index < 0 )
+                    {
+                        return;
+                    }
+
+                    User archetype = ( User ) existingUsersTable.getValueAt( index, 0 );
+                    userNorthPanel.setFields( archetype );
+                    userNorthPanel.setIcon( newUserIcon );
+                    userNorthPanel.setId( "CopyOf" + archetype.getId() );
+                    if ( archetype instanceof ExternalUser )
+                    {
+                        externalLinkPanel.setFields( ( ExternalUser ) archetype );
+                        descriptionTextArea.setText( ( ( ExternalUser ) archetype ).getDescription() );
+                        centerTabbedPane.removeAll();
+                        centerTabbedPane.addTab( "Existing", null, existingPanelTab );
+                        centerTabbedPane.addTab( "External Link", null, externalLinkPanel );
+                    }
+                    else if ( archetype instanceof LocalUser )
+                    {
+                        userInfoPanel.setFields( ( LocalUser ) archetype, "Not implemented" );
+                        descriptionTextArea.setText( ( ( LocalUser ) archetype ).getDescription() );
+                        centerTabbedPane.removeAll();
+                        centerTabbedPane.addTab( "Existing", null, existingPanelTab );
+                        centerTabbedPane.addTab( "User Info", null, userInfoPanel );
+                    }
+                    else if ( archetype instanceof HauskeysUser )
+                    {
+                        userInfoPanel.setFields( ( HauskeysUser ) archetype );
+                        hotpSettingsPanel.setFields( ( HauskeysUser ) archetype );
+                        provisioningPanel.setFields( ( HauskeysUser ) archetype );
+                        descriptionTextArea.setText( ( ( HauskeysUser ) archetype ).getDescription() );
+                        centerTabbedPane.removeAll();
+                        centerTabbedPane.addTab( "Existing", null, existingPanelTab );
+                        centerTabbedPane.addTab( "User Info", null, userInfoPanel );
+                        centerTabbedPane.addTab( "Provisioning", null, provisioningPanel );
+                        centerTabbedPane.addTab( "HOTP Settings", null, hotpSettingsPanel );
+                    }
+//                    userNorthPanel.setStatus( Color.RED, "Create operation needed!" );
+                }});
+        }
+        return existingUsersTable;
+    }
+
+
+    /**
+     * This method initializes defaultTableModel	
+     * 	
+     * @return javax.swing.table.DefaultTableModel	
+     */
+    private ExistingUsersTableModel getExistingUsersTableModel()
+    {
+        if ( existingUsersTableModel == null )
+        {
+            existingUsersTableModel = new ExistingUsersTableModel();
+        }
+        return existingUsersTableModel;
+    }
+
+    class ExistingUsersTableModel extends AbstractTableModel
+    {
+        private static final long serialVersionUID = 1L;
+
+
+        public int getRowCount()
+        {
+            if ( node == null )
+            {
+                return 0;
+            }
+            return node.getChildCount();
+        }
+
+
+        public int getColumnCount()
+        {
+            return 3;
+        }
+
+
+        public Object getValueAt( int rowIndex, int columnIndex )
+        {
+            if ( node == null )
+            {
+                return null;
+            }
+
+            DefaultMutableTreeNode child = ( DefaultMutableTreeNode ) node.getChildAt( rowIndex );
+            switch ( columnIndex )
+            {
+                case ( 0 ):
+                    return child.getUserObject();
+                case ( 1 ):
+                    return ( ( User ) child.getUserObject() ).getCreatorsName();
+                case ( 2 ):
+                    return ( ( User ) child.getUserObject() ).getCreateTimestamp();
+            }
+            return child.getUserObject();
+        }
+
+
+        public String getColumnName( int columnIndex )
+        {
+            switch ( columnIndex )
+            {
+                case ( 0 ):
+                    return "Existing User";
+                case ( 1 ):
+                    return "Creator's Name";
+                case ( 2 ):
+                    return "Create Timestamp";
+                default:
+                    throw new IndexOutOfBoundsException();
+            }
+        }
+    }
+
+
+    public void statusChanged( StatusObject obj )
+    {
+        if ( ! obj.isUpToDate() )
+        {
+//            userNorthPanel.setStatus( Color.RED, "Create operation needed!" );
+            return;
+        }
+        
+        if ( isUpToDate() && userNorthPanel.isUpToDate() && userInfoPanel.isUpToDate() 
+            && provisioningPanel.isUpToDate() && hotpSettingsPanel.isUpToDate() )
+        {
+//            userNorthPanel.setStatus( Color.GREEN, "Nothing to do!" );
+        }
+    }
+
+
+    public void checkStatus()
+    {
+        boolean upToDate = isUpToDate();
+        if ( listener != null && lastStatusState != upToDate )
+        {
+            listener.statusChanged( NewUserPanel.this );
+            lastStatusState = upToDate;
+        }
+    }
+    
+    
+    public boolean isUpToDate()
+    {
+        return UiUtils.isFieldUpToDate( descriptionTextArea, null );
+    }
+
+
+    public void keyTyped( KeyEvent e )
+    {
+        checkStatus();
+    }
+
+
+    public void keyPressed( KeyEvent e )
+    {
+        checkStatus();
+    }
+
+
+    public void keyReleased( KeyEvent e )
+    {
+        checkStatus();
+    }
+
+
+    public void focusGained( FocusEvent e )
+    {
+        checkStatus();
+    }
+
+
+    public void focusLost( FocusEvent e )
+    {
+        checkStatus();
+    }
+} //  @jve:decl-index=0:visual-constraint="10,10"

Added: directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/PermissionDependentsPanel.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/PermissionDependentsPanel.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/PermissionDependentsPanel.java (added)
+++ directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/PermissionDependentsPanel.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,376 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.safehaus.triplesec.admin.swing;
+
+
+import javax.swing.JPanel;
+import java.awt.BorderLayout;
+import javax.swing.JButton;
+import java.awt.GridBagLayout;
+
+import javax.swing.JOptionPane;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import java.awt.GridBagConstraints;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import javax.swing.table.AbstractTableModel;
+import javax.swing.tree.DefaultMutableTreeNode;
+
+import org.safehaus.triplesec.admin.DataAccessException;
+import org.safehaus.triplesec.admin.Permission;
+import org.safehaus.triplesec.admin.Profile;
+import org.safehaus.triplesec.admin.Role;
+
+
+public class PermissionDependentsPanel extends JPanel
+{
+    private static final long serialVersionUID = -5711894948847093836L;
+    private JPanel centerPanel = null;
+    private JPanel southPanel = null;
+    private JButton removeButton = null;
+    private JScrollPane jScrollPane = null;
+    private JTable dependentsTable = null;
+    private List dependents = new ArrayList();
+    private Permission permission;
+    private DependencyModel dependencyModel = null;
+    
+
+    /**
+     * This is the default constructor
+     */
+    public PermissionDependentsPanel()
+    {
+        super();
+        initialize();
+    }
+
+
+    public void setSelectedNode( DefaultMutableTreeNode node )
+    {
+        this.permission = ( Permission ) node.getUserObject();
+        this.dependents.clear();
+        
+        if ( node == null || node.getParent() == null || node.getParent().getParent() == null )
+        {
+            return;
+        }
+
+        // -------------------------------------------------------------------
+        // Find the application, and subordinate "Profiles" and "Roles" nodes
+        // -------------------------------------------------------------------
+
+        DefaultMutableTreeNode applicationNode = ( DefaultMutableTreeNode ) node.getParent().getParent();
+        DefaultMutableTreeNode rolesNode = null;
+        DefaultMutableTreeNode profilesNode = null;
+        for ( Enumeration ii = applicationNode.children(); ii.hasMoreElements(); /**/ )
+        {
+            DefaultMutableTreeNode child = ( DefaultMutableTreeNode ) ii.nextElement();
+            if ( "Roles".equals( child.getUserObject() ) )
+            {
+                rolesNode = child;
+            }
+            if ( "Profiles".equals( child.getUserObject() ) )
+            {
+                profilesNode = child;
+            }
+        }
+        
+        // -------------------------------------------------------------------
+        // Find the role dependents
+        // -------------------------------------------------------------------
+        
+        for ( Enumeration ii = rolesNode.children(); ii.hasMoreElements(); /**/ )
+        {
+            DefaultMutableTreeNode child = ( DefaultMutableTreeNode ) ii.nextElement();
+            Role role = ( Role ) child.getUserObject();
+            if ( role.getGrants().contains( permission.getName() ) )
+            {
+                dependents.add( child );
+            }
+        }
+
+        // -------------------------------------------------------------------
+        // Find the profile dependents
+        // -------------------------------------------------------------------
+        
+        for ( Enumeration ii = profilesNode.children(); ii.hasMoreElements(); /**/ )
+        {
+            DefaultMutableTreeNode child = ( DefaultMutableTreeNode ) ii.nextElement();
+            Profile profile = ( Profile ) ( child ).getUserObject();
+            if ( profile.getGrants().contains( permission.getName() ) || 
+                profile.getDenials().contains( permission.getName() ) )
+            {
+                dependents.add( child );
+            }
+        }
+        
+        dependencyModel.fireTableDataChanged();
+    }
+    
+    
+    /**
+     * This method initializes this
+     * 
+     * @return void
+     */
+    private void initialize()
+    {
+        this.setLayout(new BorderLayout());
+        this.setSize(590, 289);
+        this.add(getCenterPanel(), java.awt.BorderLayout.CENTER);
+        this.add(getSouthPanel(), java.awt.BorderLayout.SOUTH);
+    }
+
+
+    /**
+     * This method initializes jPanel	
+     * 	
+     * @return javax.swing.JPanel	
+     */
+    private JPanel getCenterPanel()
+    {
+        if ( centerPanel == null )
+        {
+            GridBagConstraints gridBagConstraints = new GridBagConstraints();
+            gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
+            gridBagConstraints.gridy = 0;
+            gridBagConstraints.weightx = 1.0;
+            gridBagConstraints.weighty = 1.0;
+            gridBagConstraints.insets = new java.awt.Insets(10,10,10,10);
+            gridBagConstraints.gridx = 0;
+            centerPanel = new JPanel();
+            centerPanel.setLayout(new GridBagLayout());
+            centerPanel.add(getJScrollPane(), gridBagConstraints);
+        }
+        return centerPanel;
+    }
+
+
+    /**
+     * This method initializes jPanel1	
+     * 	
+     * @return javax.swing.JPanel	
+     */
+    private JPanel getSouthPanel()
+    {
+        if ( southPanel == null )
+        {
+            southPanel = new JPanel();
+            southPanel.add(getRemoveButton(), null);
+        }
+        return southPanel;
+    }
+
+
+    /**
+     * This method initializes jButton	
+     * 	
+     * @return javax.swing.JButton	
+     */
+    private JButton getRemoveButton()
+    {
+        if ( removeButton == null )
+        {
+            removeButton = new JButton();
+            removeButton.setText("Remove");
+            removeButton.setToolTipText("Remove the link to the dependent object");
+            removeButton.addActionListener( new java.awt.event.ActionListener()
+            {
+                public void actionPerformed( java.awt.event.ActionEvent e )
+                {
+                    String msg = UiUtils.wrap( "Removing dependency relationships will effect " +
+                            "entities other than this permission.  You cannot automatically revert from operation.  " +
+                            "Would you like to continue?", 79 );
+                    int response = JOptionPane.showOptionDialog( PermissionDependentsPanel.this, msg, 
+                        "Irreverable operation!", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, 
+                        null, null, null );
+                    if ( response == JOptionPane.NO_OPTION )
+                    {
+                        return;
+                    }
+                    
+                    int[] selectedRows = dependentsTable.getSelectedRows();
+                    Set removed = new HashSet();
+                    for ( int ii = 0; ii < selectedRows.length; ii++ )
+                    {
+                        DefaultMutableTreeNode dependentNode = 
+                            ( DefaultMutableTreeNode ) dependents.get( selectedRows[ii] ); 
+                        Object dependent = dependentNode.getUserObject();
+                        try
+                        {
+                            if ( dependent instanceof Role )
+                            {
+                                Role role = ( Role ) dependent;
+                                dependentNode.setUserObject( role.modifier()
+                                    .removeGrant( permission.getName() ).modify() );
+                                removed.add( dependentNode );
+                            }
+                            else if ( dependent instanceof Profile )
+                            {
+                                Profile profile = ( Profile ) dependent;
+                                dependentNode.setUserObject( profile.modifier().removeDenial( permission.getName() )
+                                    .removeGrant( permission.getName() ).modify() );
+                                removed.add( dependentNode );
+                            }
+                        }
+                        catch ( DataAccessException dae )
+                        {
+                            msg = UiUtils.wrap( "Failed to remove all dependency relationships for permission: "
+                                + dae.getMessage(), 79 );
+                            JOptionPane.showMessageDialog( PermissionDependentsPanel.this, msg, 
+                                "Dependency removal failure!", JOptionPane.ERROR_MESSAGE );
+                        }
+                    }
+                    
+                    for ( Iterator ii = removed.iterator(); ii.hasNext(); /**/ )
+                    {
+                        dependents.remove( ii.next() );
+                    }
+                    
+                    if ( removed.size() > 0 )
+                    {
+                        dependencyModel.fireTableDataChanged();
+                    }
+                }
+            } );
+        }
+        return removeButton;
+    }
+
+
+    /**
+     * This method initializes jScrollPane	
+     * 	
+     * @return javax.swing.JScrollPane	
+     */
+    private JScrollPane getJScrollPane()
+    {
+        if ( jScrollPane == null )
+        {
+            jScrollPane = new JScrollPane();
+            jScrollPane.setViewportView(getDependentsTable());
+        }
+        return jScrollPane;
+    }
+
+
+    /**
+     * This method initializes jTable	
+     * 	
+     * @return javax.swing.JTable	
+     */
+    private JTable getDependentsTable()
+    {
+        if ( dependentsTable == null )
+        {
+            dependentsTable = new JTable();
+            dependentsTable.setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
+            dependentsTable.setToolTipText("Permission dependents");
+            dependencyModel = new DependencyModel();
+            dependentsTable.setModel( dependencyModel );
+            dependentsTable.setShowGrid(true);
+        }
+        return dependentsTable;
+    }
+
+    
+    class DependencyModel extends AbstractTableModel
+    {
+        private static final long serialVersionUID = 5348529870374118604L;
+        private final String[] COLNAMES = new String[] { "Type", "Name/Id", "Nature" };
+
+
+        public String getColumnName( int columnIndex )
+        {
+            return COLNAMES[columnIndex];
+        }
+        
+        public int getRowCount()
+        {
+            return dependents.size();
+        }
+
+        public int getColumnCount()
+        {
+            return 3;
+        }
+
+        public Object getValueAt( int rowIndex, int columnIndex )
+        {
+            Object dependent = ( ( DefaultMutableTreeNode ) dependents.get( rowIndex ) ).getUserObject();
+            if ( dependent instanceof Role )
+            {
+                switch( columnIndex )
+                {
+                    case ( 0 ):
+                        return "Role";
+                    case ( 1 ):
+                        return dependent;
+                    case ( 2 ):
+                        return "grant";
+                    default:
+                        throw new IndexOutOfBoundsException( "Only 3 columns present so columnIndex is invalid: "
+                            + columnIndex );
+                }
+            }
+            else if ( dependent instanceof Profile )
+            {
+                switch( columnIndex )
+                {
+                    case ( 0 ):
+                        return "Profile";
+                    case ( 1 ):
+                        return dependent;
+                    case ( 2 ):
+                        Profile profile = ( Profile ) dependent;
+                        Set grants = profile.getGrants();
+                        Set denials = profile.getDenials();
+                        // odd case to have permission in both grants and denials of role but it's possible
+                        if ( grants.contains( permission.getName() ) && denials.contains( permission.getName() ) )
+                        {
+                            return "both";
+                        }
+                        else if ( grants.contains( permission.getName() ) )
+                        {
+                            return "grant";
+                        }
+                        else
+                        {
+                            return "denial";
+                        }
+                    default:
+                        throw new IndexOutOfBoundsException( "Only 3 columns present so columnIndex is invalid: "
+                            + columnIndex );
+                }
+            }
+            else
+            {
+                throw new IllegalStateException( "Only expecting Role and Profile dependents for Permissions not " 
+                    + dependent.getClass() );
+            }
+        }
+    }
+}  //  @jve:decl-index=0:visual-constraint="10,10"

Added: directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/PermissionPanel.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/PermissionPanel.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/PermissionPanel.java (added)
+++ directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/PermissionPanel.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,579 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.safehaus.triplesec.admin.swing;
+
+
+import javax.swing.JPanel;
+import java.awt.BorderLayout;
+
+import javax.swing.ImageIcon;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JTabbedPane;
+import javax.swing.JButton;
+import javax.swing.JTree;
+
+import java.awt.GridBagLayout;
+import java.awt.GridBagConstraints;
+import javax.swing.JTextField;
+import javax.swing.JTextArea;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeModel;
+import javax.swing.tree.TreePath;
+
+import org.safehaus.triplesec.admin.DataAccessException;
+import org.safehaus.triplesec.admin.Permission;
+import org.safehaus.triplesec.admin.PermissionModifier;
+
+
+public class PermissionPanel extends JPanel
+{
+    private static final long serialVersionUID = 1L;
+    private JPanel mainPanel = null;
+    private JPanel buttonPanel = null;
+    private JButton revertButton = null;
+    private JButton saveButton = null;
+    private JPanel aboveButtonPanel = null;
+    private JPanel northPanel = null;
+    private JTabbedPane centerTabbedPane = null;
+    private JPanel southPanel = null;
+    private GeneralPanel generalPanel = null;
+    private JLabel iconLabel = null;
+    private JPanel jPanel = null;
+    private JTextArea descriptionTextArea = null;
+    private JPanel jPanel4 = null;
+    private PermissionDependentsPanel permissionDependentsPanel;
+
+
+    /**
+     * This is the default constructor
+     */
+    public PermissionPanel()
+    {
+        super();
+        initialize();
+    }
+
+
+    /**
+     * This method initializes this
+     * 
+     * @return void
+     */
+    private void initialize()
+    {
+        GridBagConstraints gridBagConstraints = new GridBagConstraints();
+        gridBagConstraints.gridx = 0;
+        gridBagConstraints.weightx = 1.0D;
+        gridBagConstraints.weighty = 1.0D;
+        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
+        gridBagConstraints.insets = new java.awt.Insets( 10, 10, 10, 10 );
+        gridBagConstraints.gridy = 0;
+        this.setLayout( new GridBagLayout() );
+        this.setSize( 550, 417 );
+        this.setBorder( javax.swing.BorderFactory.createTitledBorder( null, "Existing Permission",
+            javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION,
+            null, null ) );
+        this.add( getMainPanel(), gridBagConstraints );
+    }
+
+
+    /**
+     * This method initializes jPanel
+     * 
+     * @return javax.swing.JPanel
+     */
+    private JPanel getMainPanel()
+    {
+        if ( mainPanel == null )
+        {
+            mainPanel = new JPanel();
+            mainPanel.setLayout( new BorderLayout() );
+            mainPanel.add( getButtonPanel(), java.awt.BorderLayout.SOUTH );
+            mainPanel.add( getAboveButtonPanel(), java.awt.BorderLayout.CENTER );
+        }
+        return mainPanel;
+    }
+
+
+    /**
+     * This method initializes jPanel
+     * 
+     * @return javax.swing.JPanel
+     */
+    private JPanel getButtonPanel()
+    {
+        if ( buttonPanel == null )
+        {
+            buttonPanel = new JPanel();
+            buttonPanel.setBorder( javax.swing.BorderFactory.createEmptyBorder( 0, 0, 0, 0 ) );
+            buttonPanel.add(getDeleteButton(), null);
+            buttonPanel.add(getRevertButton(), null);
+            buttonPanel.add(getSaveButton(), null);
+        }
+        return buttonPanel;
+    }
+
+
+    /**
+     * This method initializes jButton
+     * 
+     * @return javax.swing.JButton
+     */
+    private JButton getRevertButton()
+    {
+        if ( revertButton == null )
+        {
+            revertButton = new JButton();
+            revertButton.setText( "Revert" );
+            revertButton.addActionListener( new java.awt.event.ActionListener()
+            {
+                public void actionPerformed( java.awt.event.ActionEvent e )
+                {
+                    setPermissionFields();
+                }
+            } );
+        }
+        return revertButton;
+    }
+
+
+    /**
+     * This method initializes jButton
+     * 
+     * @return javax.swing.JButton
+     */
+    private JButton getSaveButton()
+    {
+        if ( saveButton == null )
+        {
+            saveButton = new JButton();
+            saveButton.setText( "Save" );
+            saveButton.addActionListener( new java.awt.event.ActionListener()
+            {
+                public void actionPerformed( java.awt.event.ActionEvent e )
+                {
+                    saveAction();
+                }
+            } );
+        }
+        return saveButton;
+    }
+
+
+    /**
+     * This method initializes jPanel
+     * 
+     * @return javax.swing.JPanel
+     */
+    private JPanel getAboveButtonPanel()
+    {
+        if ( aboveButtonPanel == null )
+        {
+            aboveButtonPanel = new JPanel();
+            aboveButtonPanel.setLayout( new BorderLayout() );
+            aboveButtonPanel.add( getNorthPanel(), java.awt.BorderLayout.NORTH );
+            aboveButtonPanel.add( getCenterTabbedPane(), java.awt.BorderLayout.CENTER );
+            aboveButtonPanel.add( getSouthPanel(), java.awt.BorderLayout.SOUTH );
+        }
+        return aboveButtonPanel;
+    }
+
+
+    /**
+     * This method initializes jPanel
+     * 
+     * @return javax.swing.JPanel
+     */
+    private JPanel getNorthPanel()
+    {
+        if ( northPanel == null )
+        {
+            GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
+            gridBagConstraints1.gridx = 1;
+            gridBagConstraints1.weightx = 1.0D;
+            gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
+            gridBagConstraints1.gridheight = 3;
+            gridBagConstraints1.insets = new java.awt.Insets( 0, 10, 0, 10 );
+            gridBagConstraints1.weighty = 1.0D;
+            gridBagConstraints1.gridy = 0;
+            northPanel = new JPanel();
+            northPanel.setLayout( new GridBagLayout() );
+            northPanel.setPreferredSize( new java.awt.Dimension( 179, 68 ) );
+            northPanel.add( getJPanel4(), new GridBagConstraints() );
+            northPanel.add( getJPanel(), gridBagConstraints1 );
+        }
+        return northPanel;
+    }
+
+
+    /**
+     * This method initializes jTabbedPane
+     * 
+     * @return javax.swing.JTabbedPane
+     */
+    private JTabbedPane getCenterTabbedPane()
+    {
+        if ( centerTabbedPane == null )
+        {
+            centerTabbedPane = new JTabbedPane();
+            centerTabbedPane.addTab( "General", null, getGeneralPanel(), null );
+            centerTabbedPane.addTab( "Dependents", null, getPermissionDependentsPanel(), null );
+        }
+        return centerTabbedPane;
+    }
+
+
+    private PermissionDependentsPanel getPermissionDependentsPanel()
+    {
+        if ( permissionDependentsPanel == null )
+        {
+            permissionDependentsPanel = new PermissionDependentsPanel();
+        }
+        return permissionDependentsPanel;
+    }
+
+
+    /**
+     * This method initializes jPanel
+     * 
+     * @return javax.swing.JPanel
+     */
+    private JPanel getSouthPanel()
+    {
+        if ( southPanel == null )
+        {
+            southPanel = new JPanel();
+            southPanel.setLayout( new BorderLayout() );
+            southPanel.setBorder( javax.swing.BorderFactory.createTitledBorder( null, "Description",
+                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
+                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null ) );
+            southPanel.add( getDescriptionTextArea(), java.awt.BorderLayout.NORTH );
+        }
+        return southPanel;
+    }
+
+
+    /**
+     * This method initializes jPanel
+     * 
+     * @return javax.swing.JPanel
+     */
+    private GeneralPanel getGeneralPanel()
+    {
+        if ( generalPanel == null )
+        {
+            generalPanel = new GeneralPanel();
+        }
+        return generalPanel;
+    }
+
+
+    /**
+     * This method initializes iconLabel
+     * 
+     * @return javax.swing.JLabel
+     */
+    private JLabel getIconLabel()
+    {
+        if ( iconLabel == null )
+        {
+            iconLabel = new JLabel();
+            iconLabel.setIcon( new ImageIcon( getClass().getResource(
+                "/org/safehaus/triplesec/admin/swing/permission2_48x48.png" ) ) );
+            iconLabel.setPreferredSize( new java.awt.Dimension( 48, 48 ) );
+            iconLabel.setText( "" );
+            iconLabel.setVerticalTextPosition( javax.swing.SwingConstants.BOTTOM );
+            iconLabel.setVerticalAlignment( javax.swing.SwingConstants.BOTTOM );
+            iconLabel.setEnabled( true );
+        }
+        return iconLabel;
+    }
+
+
+    /**
+     * This method initializes jPanel
+     * 
+     * @return javax.swing.JPanel
+     */
+    private JPanel getJPanel()
+    {
+        if ( jPanel == null )
+        {
+            GridBagConstraints gridBagConstraints15 = new GridBagConstraints();
+            gridBagConstraints15.fill = java.awt.GridBagConstraints.HORIZONTAL;
+            gridBagConstraints15.gridy = 2;
+            gridBagConstraints15.weightx = 1.0;
+            gridBagConstraints15.gridx = 1;
+            GridBagConstraints gridBagConstraints14 = new GridBagConstraints();
+            gridBagConstraints14.gridx = 0;
+            gridBagConstraints14.fill = java.awt.GridBagConstraints.HORIZONTAL;
+            gridBagConstraints14.insets = new java.awt.Insets( 0, 0, 0, 5 );
+            gridBagConstraints14.gridy = 2;
+            jLabel2 = new JLabel();
+            jLabel2.setText( "Permission Name:" );
+            jLabel2.setHorizontalAlignment( javax.swing.SwingConstants.RIGHT );
+            GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
+            gridBagConstraints5.fill = java.awt.GridBagConstraints.HORIZONTAL;
+            gridBagConstraints5.gridy = 1;
+            gridBagConstraints5.weightx = 1.0;
+            gridBagConstraints5.insets = new java.awt.Insets( 0, 0, 5, 0 );
+            gridBagConstraints5.gridx = 1;
+            GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
+            gridBagConstraints4.gridx = 0;
+            gridBagConstraints4.insets = new java.awt.Insets( 0, 0, 5, 5 );
+            gridBagConstraints4.fill = java.awt.GridBagConstraints.HORIZONTAL;
+            gridBagConstraints4.gridy = 1;
+            jLabel1 = new JLabel();
+            jLabel1.setText( "Application Name:" );
+            jLabel1.setHorizontalAlignment( javax.swing.SwingConstants.RIGHT );
+            GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
+            gridBagConstraints3.fill = java.awt.GridBagConstraints.HORIZONTAL;
+            gridBagConstraints3.gridy = 0;
+            gridBagConstraints3.weightx = 1.0;
+            gridBagConstraints3.insets = new java.awt.Insets( 0, 0, 5, 0 );
+            gridBagConstraints3.gridx = 1;
+            GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
+            gridBagConstraints2.insets = new java.awt.Insets( 0, 0, 5, 5 );
+            gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
+            jLabel = new JLabel();
+            jLabel.setText( "Status:" );
+            jLabel.setHorizontalAlignment( javax.swing.SwingConstants.RIGHT );
+            jPanel = new JPanel();
+            jPanel.setLayout( new GridBagLayout() );
+            jPanel.setPreferredSize( new java.awt.Dimension( 131, 88 ) );
+            jPanel.add( jLabel, gridBagConstraints2 );
+            jPanel.add( getStatusTextField(), gridBagConstraints3 );
+            jPanel.add( jLabel1, gridBagConstraints4 );
+            jPanel.add( getApplicationNameTextField(), gridBagConstraints5 );
+            jPanel.add( jLabel2, gridBagConstraints14 );
+            jPanel.add( getPermissionNameTextField(), gridBagConstraints15 );
+        }
+        return jPanel;
+    }
+
+
+    /**
+     * This method initializes jTextArea
+     * 
+     * @return javax.swing.JTextArea
+     */
+    private JTextArea getDescriptionTextArea()
+    {
+        if ( descriptionTextArea == null )
+        {
+            descriptionTextArea = new JTextArea();
+            descriptionTextArea.setRows( 3 );
+        }
+        return descriptionTextArea;
+    }
+
+
+    /**
+     * This method initializes jPanel4
+     * 
+     * @return javax.swing.JPanel
+     */
+    private JPanel getJPanel4()
+    {
+        if ( jPanel4 == null )
+        {
+            jPanel4 = new JPanel();
+            jPanel4.setBorder( javax.swing.BorderFactory.createEtchedBorder( javax.swing.border.EtchedBorder.RAISED ) );
+            jPanel4.add( getIconLabel(), null );
+        }
+        return jPanel4;
+    }
+
+
+    private void setPermissionFields()
+    {
+        generalPanel.setFields( permission );
+        applicationNameTextField.setText( permission.getApplicationName() );
+        permissionNameTextField.setText( permission.getName() );
+        descriptionTextArea.setText( permission.getDescription() );
+    }
+
+    private JTree tree = null;
+    private Permission permission = null;
+    private DefaultMutableTreeNode node = null;
+    private JLabel jLabel = null;
+    private JTextField statusTextField = null;
+    private JLabel jLabel1 = null;
+    private JTextField applicationNameTextField = null;
+    private JLabel jLabel2 = null;
+    private JTextField permissionNameTextField = null;
+    private JButton deleteButton = null;
+
+
+    public void setTree( JTree tree )
+    {
+        this.tree = tree;
+    }
+
+
+    public void setTreeNode( DefaultMutableTreeNode node )
+    {
+        this.node = node;
+        this.permission = ( Permission ) node.getUserObject();
+        setPermissionFields();
+        this.permissionDependentsPanel.setSelectedNode( node );
+    }
+
+
+    public String noNull( Object obj )
+    {
+        if ( obj == null )
+        {
+            return "";
+        }
+        return obj.toString();
+    }
+
+
+    public DefaultMutableTreeNode getTreeNode()
+    {
+        return node;
+    }
+
+
+    public void saveAction()
+    {
+        PermissionModifier modifier = permission.modifier().setDescription( descriptionTextArea.getText() );
+        if ( modifier.isUpdateNeeded() )
+        {
+            try
+            {
+                permission = modifier.modify();
+            }
+            catch ( DataAccessException e )
+            {
+                JOptionPane.showMessageDialog( this, UiUtils.wrap( "Failed to modify permission:\n" + e.getMessage(),
+                    79 ), "Permission modification failure!", JOptionPane.ERROR_MESSAGE );
+                return;
+            }
+            node.setUserObject( permission );
+        }
+
+        if ( !permission.getName().equals( permissionNameTextField.getText() ) )
+        {
+            try
+            {
+                permission = permission.modifier().rename( permissionNameTextField.getText() );
+                ( ( DefaultTreeModel ) tree.getModel() ).valueForPathChanged( new TreePath( node.getPath() ),
+                    permission );
+            }
+            catch ( DataAccessException e )
+            {
+                JOptionPane.showMessageDialog( this, UiUtils.wrap( "Failed to rename permission:\n" + e.getMessage(),
+                    79 ), "Permission rename failure!", JOptionPane.ERROR_MESSAGE );
+                return;
+            }
+        }
+
+        node.setUserObject( permission );
+        setPermissionFields();
+    }
+
+
+    /**
+     * This method initializes jTextField	
+     * 	
+     * @return javax.swing.JTextField	
+     */
+    private JTextField getStatusTextField()
+    {
+        if ( statusTextField == null )
+        {
+            statusTextField = new JTextField();
+            statusTextField.setEditable( false );
+        }
+        return statusTextField;
+    }
+
+
+    /**
+     * This method initializes jTextField1	
+     * 	
+     * @return javax.swing.JTextField	
+     */
+    private JTextField getApplicationNameTextField()
+    {
+        if ( applicationNameTextField == null )
+        {
+            applicationNameTextField = new JTextField();
+            applicationNameTextField.setEditable( false );
+        }
+        return applicationNameTextField;
+    }
+
+
+    /**
+     * This method initializes jTextField2	
+     * 	
+     * @return javax.swing.JTextField	
+     */
+    private JTextField getPermissionNameTextField()
+    {
+        if ( permissionNameTextField == null )
+        {
+            permissionNameTextField = new JTextField();
+        }
+        return permissionNameTextField;
+    }
+
+
+    /**
+     * This method initializes jButton	
+     * 	
+     * @return javax.swing.JButton	
+     */
+    private JButton getDeleteButton()
+    {
+        if ( deleteButton == null )
+        {
+            deleteButton = new JButton();
+            deleteButton.setText("Delete");
+            deleteButton.addActionListener( new java.awt.event.ActionListener()
+            {
+                public void actionPerformed( java.awt.event.ActionEvent e )
+                {
+                    try
+                    {
+                        permission.modifier().delete();
+                        DefaultMutableTreeNode parentNode = ( DefaultMutableTreeNode ) node.getParent();
+                        DefaultTreeModel treeModel = ( DefaultTreeModel ) tree.getModel();
+                        treeModel.removeNodeFromParent( node );
+                        TreePath path = new TreePath( parentNode.getPath() );
+                        tree.setSelectionPaths( new TreePath[] { path } );
+                    }
+                    catch ( DataAccessException e1 )
+                    {
+                        JOptionPane.showMessageDialog( PermissionPanel.this, 
+                            "Failed to delete permission: " + e1.getMessage(), "Delete Failed", 
+                            JOptionPane.ERROR_MESSAGE );
+                    }
+                }
+            } );
+        }
+        return deleteButton;
+    }
+
+} // @jve:decl-index=0:visual-constraint="10,10"



Mime
View raw message