directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tbenn...@apache.org
Subject svn commit: r486187 [31/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/ProfilePanel.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/ProfilePanel.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/ProfilePanel.java (added)
+++ directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/ProfilePanel.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,812 @@
+/*
+ *  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.DefaultComboBoxModel;
+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 java.util.Enumeration;
+import java.util.Set;
+
+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.Profile;
+import org.safehaus.triplesec.admin.ProfileModifier;
+import org.safehaus.triplesec.admin.User;
+
+import javax.swing.JComboBox;
+import javax.swing.JCheckBox;
+
+
+public class ProfilePanel 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 JTree tree = null;
+    private Profile profile = null;
+    private DefaultMutableTreeNode node = null;
+    private DefaultComboBoxModel usersComboBoxModel = new DefaultComboBoxModel();
+    private JLabel jLabel = null;
+    private JLabel jLabel1 = null;
+    private JLabel jLabel2 = null;
+    private JTextField statusTextField = null;
+    private JTextField applicationNameTextField = null;
+    private JButton deleteButton = null;
+    private JPanel jPanel1 = null;
+    private JTextField profileIdTextField = null;
+    private JLabel jLabel7 = null;
+    private JComboBox usersComboBox = null;
+    private ProfilePermissionsPanel profileGrantsPanel;
+    private ProfilePermissionsPanel profileDenialsPanel;
+    private ProfileRolesPanel profileRolesPanel;
+    private JLabel jLabel3 = null;
+    private JCheckBox disabledCheckBox = null;
+
+
+    /**
+     * This is the default constructor
+     */
+    public ProfilePanel()
+    {
+        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 Profile",
+            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 )
+                {
+                    try
+                    {
+                        setProfileFields();
+                    }
+                    catch ( DataAccessException e1 )
+                    {
+                        JOptionPane.showMessageDialog( ProfilePanel.this,
+                            "Failed to access application permissions for profile: " + profile.getId() + "\n\n"
+                                + e1.getMessage(), "Data access error", JOptionPane.ERROR_MESSAGE );
+                    }
+                }
+            } );
+        }
+        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( "Grants", null, getProfileGrantsPanel(), null );
+            centerTabbedPane.addTab( "Denials", null, getProfileDenialsPanel(), null );
+            centerTabbedPane.addTab( "Roles", null, getProfileRolesPanel(), null );
+        }
+        return centerTabbedPane;
+    }
+
+
+    /**
+     * 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 )
+        {
+            GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
+            gridBagConstraints6.gridx = 1;
+            gridBagConstraints6.fill = java.awt.GridBagConstraints.HORIZONTAL;
+            gridBagConstraints6.insets = new java.awt.Insets(0,0,0,05);
+            gridBagConstraints6.gridy = 4;
+            GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
+            gridBagConstraints5.gridx = 0;
+            gridBagConstraints5.fill = java.awt.GridBagConstraints.HORIZONTAL;
+            gridBagConstraints5.insets = new java.awt.Insets(0,0,0,5);
+            gridBagConstraints5.gridy = 4;
+            jLabel3 = new JLabel();
+            jLabel3.setText("Disabled:");
+            jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
+            generalPanel = new GeneralPanel();
+            generalPanel.add(jLabel3, gridBagConstraints5);
+            generalPanel.add(getDisabledCheckBox(), gridBagConstraints6);
+        }
+        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/profile2_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 gridBagConstraints17 = new GridBagConstraints();
+            gridBagConstraints17.gridx = 1;
+            gridBagConstraints17.fill = java.awt.GridBagConstraints.BOTH;
+            gridBagConstraints17.gridy = 2;
+            GridBagConstraints gridBagConstraints16 = new GridBagConstraints();
+            gridBagConstraints16.fill = java.awt.GridBagConstraints.HORIZONTAL;
+            gridBagConstraints16.gridy = 1;
+            gridBagConstraints16.weightx = 1.0;
+            gridBagConstraints16.insets = new java.awt.Insets( 0, 0, 5, 0 );
+            gridBagConstraints16.gridx = 1;
+            GridBagConstraints gridBagConstraints15 = new GridBagConstraints();
+            gridBagConstraints15.fill = java.awt.GridBagConstraints.HORIZONTAL;
+            gridBagConstraints15.gridy = 0;
+            gridBagConstraints15.weightx = 1.0;
+            gridBagConstraints15.insets = new java.awt.Insets( 0, 0, 5, 0 );
+            gridBagConstraints15.gridx = 1;
+            GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
+            gridBagConstraints4.fill = java.awt.GridBagConstraints.HORIZONTAL;
+            gridBagConstraints4.insets = new java.awt.Insets( 0, 0, 5, 5 );
+            GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
+            gridBagConstraints3.gridx = 0;
+            gridBagConstraints3.insets = new java.awt.Insets( 0, 0, 0, 5 );
+            gridBagConstraints3.fill = java.awt.GridBagConstraints.HORIZONTAL;
+            gridBagConstraints3.gridy = 2;
+            jLabel2 = new JLabel();
+            jLabel2.setText( "Profile Id:" );
+            jLabel2.setHorizontalAlignment( javax.swing.SwingConstants.RIGHT );
+            GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
+            gridBagConstraints2.gridx = 0;
+            gridBagConstraints2.insets = new java.awt.Insets( 0, 0, 5, 5 );
+            gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
+            gridBagConstraints2.gridy = 1;
+            jLabel1 = new JLabel();
+            jLabel1.setText( "Application Name:" );
+            jLabel1.setHorizontalAlignment( javax.swing.SwingConstants.RIGHT );
+            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, gridBagConstraints4 );
+            jPanel.add( jLabel1, gridBagConstraints2 );
+            jPanel.add( jLabel2, gridBagConstraints3 );
+            jPanel.add( getStatusTextField(), gridBagConstraints15 );
+            jPanel.add( getApplicationNameTextField(), gridBagConstraints16 );
+            jPanel.add( getJPanel1(), gridBagConstraints17 );
+        }
+        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 setProfileFields() throws DataAccessException
+    {
+        if ( profile == null || node == null || node.getParent() == null )
+        {
+            return;
+        }
+        disabledCheckBox.setSelected( profile.isDisabled() );
+        generalPanel.setFields( profile );
+        applicationNameTextField.setText( profile.getApplicationName() );
+        profileIdTextField.setText( profile.getId() );
+        descriptionTextArea.setText( profile.getDescription() );
+
+        DefaultMutableTreeNode applicationNode = ( DefaultMutableTreeNode ) node.getParent().getParent();
+
+        // -------------------------------------------------------------------
+        // load the grants, denials and roles into respective panels
+        // -------------------------------------------------------------------
+
+        Set grants = profile.getGrants();
+        profileGrantsPanel.populateLists( applicationNode, grants );
+        Set denials = profile.getDenials();
+        profileDenialsPanel.populateLists( applicationNode, denials );
+        Set roles = profile.getRoles();
+        profileRolesPanel.populateLists( applicationNode, roles );
+
+        // -------------------------------------------------------------------
+        // clear and load users into the user combo box
+        // -------------------------------------------------------------------
+
+        usersComboBoxModel.removeAllElements();
+        DefaultMutableTreeNode rootNode = ( DefaultMutableTreeNode ) applicationNode.getParent().getParent();
+        DefaultMutableTreeNode usersNode = null;
+        for ( Enumeration ii = rootNode.children(); ii.hasMoreElements(); /**/)
+        {
+            DefaultMutableTreeNode child = ( DefaultMutableTreeNode ) ii.nextElement();
+            if ( child.getUserObject() instanceof String )
+            {
+                if ( "Users".equals( child.getUserObject() ) )
+                {
+                    usersNode = child;
+                }
+            }
+        }
+
+        for ( Enumeration ii = usersNode.children(); ii.hasMoreElements(); /**/)
+        {
+            DefaultMutableTreeNode userNode = ( DefaultMutableTreeNode ) ii.nextElement();
+            usersComboBoxModel.addElement( ( ( User ) userNode.getUserObject() ).getId() );
+        }
+        usersComboBox.setSelectedItem( profile.getUser() );
+    }
+
+
+    public void setTree( JTree tree )
+    {
+        this.tree = tree;
+    }
+
+
+    public void setTreeNode( DefaultMutableTreeNode node )
+    {
+        if ( node == null )
+        {
+            return;
+        }
+        this.node = node;
+        this.profile = ( Profile ) node.getUserObject();
+
+        try
+        {
+            setProfileFields();
+        }
+        catch ( DataAccessException e )
+        {
+            JOptionPane.showMessageDialog( ProfilePanel.this, "Failed to access application permissions for profile: "
+                + profile.getId() + "\n\n" + e.getMessage(), "Data access error", JOptionPane.ERROR_MESSAGE );
+        }
+    }
+
+
+    public String noNull( Object obj )
+    {
+        if ( obj == null )
+        {
+            return "";
+        }
+        return obj.toString();
+    }
+
+
+    public DefaultMutableTreeNode getTreeNode()
+    {
+        return node;
+    }
+
+
+    public void saveAction()
+    {
+        if ( profile == null )
+        {
+            return;
+        }
+
+        // change the description and add remove values from list views then see if anything changed
+        ProfileModifier modifier = profile.modifier().setDescription( descriptionTextArea.getText() );
+        modifier.setUser( ( String ) usersComboBox.getSelectedItem() );
+        modifier.setDisable( disabledCheckBox.isSelected() );
+        for ( Enumeration ii = profileGrantsPanel.getAvailableModel().elements(); ii.hasMoreElements(); /**/)
+        {
+            modifier.removeGrant( ( String ) ii.nextElement() );
+        }
+        for ( Enumeration ii = profileGrantsPanel.getExistingModel().elements(); ii.hasMoreElements(); /**/)
+        {
+            modifier.addGrant( ( String ) ii.nextElement() );
+        }
+
+        for ( Enumeration ii = profileDenialsPanel.getAvailableModel().elements(); ii.hasMoreElements(); /**/)
+        {
+            modifier.removeDenial( ( String ) ii.nextElement() );
+        }
+        for ( Enumeration ii = profileDenialsPanel.getExistingModel().elements(); ii.hasMoreElements(); /**/)
+        {
+            modifier.addDenial( ( String ) ii.nextElement() );
+        }
+
+        for ( Enumeration ii = profileRolesPanel.getAvailableRolesModel().elements(); ii.hasMoreElements(); /**/)
+        {
+            modifier.removeRole( ( String ) ii.nextElement() );
+        }
+        for ( Enumeration ii = profileRolesPanel.getProfileRolesModel().elements(); ii.hasMoreElements(); /**/)
+        {
+            modifier.addRole( ( String ) ii.nextElement() );
+        }
+
+        if ( modifier.isUpdateNeeded() )
+        {
+            try
+            {
+                profile = modifier.modify();
+            }
+            catch ( DataAccessException e )
+            {
+                JOptionPane.showMessageDialog( this,
+                    UiUtils.wrap( "Failed to modify profile:\n" + e.getMessage(), 79 ),
+                    "Profile modification failure!", JOptionPane.ERROR_MESSAGE );
+                return;
+            }
+        }
+
+        if ( !profile.getId().equals( profileIdTextField.getText() ) )
+        {
+            try
+            {
+                profile = profile.modifier().rename( profileIdTextField.getText() );
+                ( ( DefaultTreeModel ) tree.getModel() ).valueForPathChanged( new TreePath( node.getPath() ), profile );
+            }
+            catch ( DataAccessException e )
+            {
+                JOptionPane.showMessageDialog( this,
+                    UiUtils.wrap( "Failed to rename profile:\n" + e.getMessage(), 79 ), "Profile rename failure!",
+                    JOptionPane.ERROR_MESSAGE );
+                return;
+            }
+        }
+
+        node.setUserObject( profile );
+        try
+        {
+            setProfileFields();
+        }
+        catch ( DataAccessException e )
+        {
+            JOptionPane.showMessageDialog( ProfilePanel.this, "Failed to access application permissions for profile: "
+                + profile.getId() + "\n\n" + e.getMessage(), "Data access error", JOptionPane.ERROR_MESSAGE );
+        }
+    }
+
+
+    /**
+     * This method initializes jPanel5
+     * 
+     * @return javax.swing.JPanel
+     */
+    private ProfilePermissionsPanel getProfileGrantsPanel()
+    {
+        if ( profileGrantsPanel == null )
+        {
+            profileGrantsPanel = new ProfilePermissionsPanel();
+        }
+        return profileGrantsPanel;
+    }
+
+
+    /**
+     * This method initializes jPanel5
+     * 
+     * @return javax.swing.JPanel
+     */
+    private ProfilePermissionsPanel getProfileDenialsPanel()
+    {
+        if ( profileDenialsPanel == null )
+        {
+            profileDenialsPanel = new ProfilePermissionsPanel( false );
+        }
+        return profileDenialsPanel;
+    }
+
+    
+    private ProfileRolesPanel getProfileRolesPanel()
+    {
+        if ( profileRolesPanel == null )
+        {
+            profileRolesPanel = new ProfileRolesPanel();
+        }
+        return profileRolesPanel;
+    }
+    
+
+    /**
+     * 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 jTextField	
+     * 	
+     * @return javax.swing.JTextField	
+     */
+    private JTextField getApplicationNameTextField()
+    {
+        if ( applicationNameTextField == null )
+        {
+            applicationNameTextField = new JTextField();
+            applicationNameTextField.setEditable( false );
+        }
+        return applicationNameTextField;
+    }
+
+
+    /**
+     * 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
+                    {
+                        profile.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( ProfilePanel.this, "Failed to delete profile: "
+                            + e1.getMessage(), "Delete Failed", JOptionPane.ERROR_MESSAGE );
+                    }
+                }
+            } );
+        }
+        return deleteButton;
+    }
+
+
+    /**
+     * This method initializes jPanel1	
+     * 	
+     * @return javax.swing.JPanel	
+     */
+    private JPanel getJPanel1()
+    {
+        if ( jPanel1 == null )
+        {
+            GridBagConstraints gridBagConstraints20 = new GridBagConstraints();
+            gridBagConstraints20.fill = java.awt.GridBagConstraints.HORIZONTAL;
+            gridBagConstraints20.weightx = 1.0;
+            GridBagConstraints gridBagConstraints19 = new GridBagConstraints();
+            gridBagConstraints19.fill = java.awt.GridBagConstraints.HORIZONTAL;
+            gridBagConstraints19.insets = new java.awt.Insets( 0, 5, 0, 5 );
+            jLabel7 = new JLabel();
+            jLabel7.setText( "User:" );
+            jLabel7.setHorizontalAlignment( javax.swing.SwingConstants.RIGHT );
+            GridBagConstraints gridBagConstraints18 = new GridBagConstraints();
+            gridBagConstraints18.fill = java.awt.GridBagConstraints.HORIZONTAL;
+            gridBagConstraints18.gridy = 0;
+            gridBagConstraints18.weightx = 1.0;
+            gridBagConstraints18.gridx = 0;
+            jPanel1 = new JPanel();
+            jPanel1.setLayout( new GridBagLayout() );
+            jPanel1.add( getJTextField(), gridBagConstraints18 );
+            jPanel1.add( jLabel7, gridBagConstraints19 );
+            jPanel1.add( getJComboBox(), gridBagConstraints20 );
+        }
+        return jPanel1;
+    }
+
+
+    /**
+     * This method initializes jTextField	
+     * 	
+     * @return javax.swing.JTextField	
+     */
+    private JTextField getJTextField()
+    {
+        if ( profileIdTextField == null )
+        {
+            profileIdTextField = new JTextField();
+        }
+        return profileIdTextField;
+    }
+
+
+    /**
+     * This method initializes jComboBox	
+     * 	
+     * @return javax.swing.JComboBox	
+     */
+    private JComboBox getJComboBox()
+    {
+        if ( usersComboBox == null )
+        {
+            usersComboBox = new JComboBox();
+            usersComboBox.setModel( usersComboBoxModel );
+            usersComboBox.setPreferredSize( new java.awt.Dimension( 32, 19 ) );
+        }
+        return usersComboBox;
+    }
+
+
+    /**
+     * This method initializes jCheckBox	
+     * 	
+     * @return javax.swing.JCheckBox	
+     */
+    private JCheckBox getDisabledCheckBox()
+    {
+        if ( disabledCheckBox == null )
+        {
+            disabledCheckBox = new JCheckBox();
+        }
+        return disabledCheckBox;
+    }
+} // @jve:decl-index=0:visual-constraint="10,10"

Added: directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/ProfilePermissionsPanel.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/ProfilePermissionsPanel.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/ProfilePermissionsPanel.java (added)
+++ directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/ProfilePermissionsPanel.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,438 @@
+/*
+ *  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.Enumeration;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.swing.DefaultListModel;
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.tree.DefaultMutableTreeNode;
+
+import org.safehaus.triplesec.admin.Permission;
+
+
+public class ProfilePermissionsPanel extends JPanel
+{
+    private static final long serialVersionUID = 789126136169615296L;
+
+    private JPanel jPanel5 = null;
+    private JPanel jPanel6 = null;
+    private JPanel jPanel7 = null;
+    private JList availableList = null;
+    private JScrollPane jScrollPane = null;
+    private JScrollPane jScrollPane1 = null;
+    private JList existingList = null;
+    private JButton addButton = null;
+    private JButton removeButton = null;
+    private DefaultListModel availableModel = null; // @jve:decl-index=0:visual-constraint=""
+    private DefaultListModel existingModel = null; // @jve:decl-index=0:visual-constraint=""
+    private final boolean forGrants;
+
+    
+    /**
+     * This is the default constructor
+     */
+    public ProfilePermissionsPanel()
+    {
+        super();
+        initialize();
+        forGrants = true;
+    }
+
+
+    /**
+     * This is the default constructor
+     */
+    public ProfilePermissionsPanel( boolean forGrants )
+    {
+        super();
+        initialize();
+        this.forGrants = forGrants;
+    }
+
+
+    public void populateLists( DefaultMutableTreeNode applicationNode, Set existing )
+    {
+        // -------------------------------------------------------------------
+        // clear both lists and find the permissions container for the app
+        // -------------------------------------------------------------------
+        
+        availableModel.clear();
+        existingModel.clear();
+        if ( applicationNode == null )
+        {
+            return;
+        }
+        DefaultMutableTreeNode permissionsNode = null;
+        for ( Enumeration ii = applicationNode.children(); ii.hasMoreElements(); /**/ )
+        {
+            DefaultMutableTreeNode child = ( DefaultMutableTreeNode ) ii.nextElement();
+            if ( "Permissions".equals( child.getUserObject() ) )
+            {
+                permissionsNode = child;
+                break;
+            }
+        }
+        
+        // -------------------------------------------------------------------
+        // load both lists: do not include perms as available if in grants
+        // -------------------------------------------------------------------
+        
+        for ( Enumeration ii = permissionsNode.children(); ii.hasMoreElements(); /**/)
+        {
+            Permission permission = ( Permission ) ( ( DefaultMutableTreeNode ) ii.nextElement() ).getUserObject();
+            if ( ! existing.contains( permission.getName() ) )
+            {
+                availableModel.addElement( permission.getName() );
+            }
+        }
+        for ( Iterator ii = existing.iterator(); ii.hasNext(); /**/)
+        {
+            existingModel.addElement( ii.next() );
+        }
+    }
+    
+    
+    public DefaultListModel getAvailableModel()
+    {
+        return availableModel;
+    }
+
+
+    public DefaultListModel getExistingModel()
+    {
+        return existingModel;
+    }
+
+
+    /**
+     * This method initializes this
+     * 
+     * @return void
+     */
+    private void initialize()
+    {
+        this.setSize( 637, 268 );
+        setLayout( new BorderLayout() );
+        add( getAvailablePanel(), java.awt.BorderLayout.WEST );
+        add( getButtonPanel(), java.awt.BorderLayout.CENTER );
+        add( getExistingPanel(), java.awt.BorderLayout.EAST );
+    }
+
+
+    /**
+     * This method initializes jPanel5
+     * 
+     * @return javax.swing.JPanel
+     */
+    private JPanel getAvailablePanel()
+    {
+        if ( jPanel5 == null )
+        {
+            jPanel5 = new JPanel();
+            jPanel5.setLayout( new BorderLayout() );
+            String title = null;
+            if ( forGrants )
+            {
+                title = "Available Grants";
+            }
+            else
+            {
+                title = "Available Denials";
+            }
+            jPanel5.setBorder( javax.swing.BorderFactory.createTitledBorder( null, title,
+                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
+                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null ) );
+            jPanel5.setPreferredSize( new java.awt.Dimension( 200, 35 ) );
+            jPanel5.add( getJScrollPane(), java.awt.BorderLayout.CENTER );
+        }
+        return jPanel5;
+    }
+
+
+    /**
+     * This method initializes jPanel6
+     * 
+     * @return javax.swing.JPanel
+     */
+    private JPanel getButtonPanel()
+    {
+        if ( jPanel6 == null )
+        {
+            GridBagConstraints gridBagConstraints14 = new GridBagConstraints();
+            gridBagConstraints14.gridx = 0;
+            gridBagConstraints14.insets = new java.awt.Insets( 10, 0, 0, 0 );
+            gridBagConstraints14.gridy = 1;
+            GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
+            gridBagConstraints5.gridx = 0;
+            gridBagConstraints5.gridy = 0;
+            jPanel6 = new JPanel();
+            jPanel6.setLayout( new GridBagLayout() );
+            jPanel6.add( getAddPermissionButton(), gridBagConstraints5 );
+            jPanel6.add( getRemovePermissionButton(), gridBagConstraints14 );
+        }
+        return jPanel6;
+    }
+
+
+    /**
+     * This method initializes jPanel7
+     * 
+     * @return javax.swing.JPanel
+     */
+    private JPanel getExistingPanel()
+    {
+        if ( jPanel7 == null )
+        {
+            jPanel7 = new JPanel();
+            jPanel7.setLayout( new BorderLayout() );
+            jPanel7.setPreferredSize( new java.awt.Dimension( 200, 10 ) );
+            String title = null;
+            if ( forGrants )
+            {
+                title = "Available Grants";
+            }
+            else
+            {
+                title = "Available Denials";
+            }
+            jPanel7.setBorder( javax.swing.BorderFactory.createTitledBorder( null, title,
+                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
+                javax.swing.border.TitledBorder.DEFAULT_POSITION,
+                new java.awt.Font( "Dialog", java.awt.Font.BOLD, 12 ), new java.awt.Color( 51, 51, 51 ) ) );
+            jPanel7.add( getJScrollPane1(), java.awt.BorderLayout.CENTER );
+        }
+        return jPanel7;
+    }
+
+
+    /**
+     * This method initializes jButton
+     * 
+     * @return javax.swing.JButton
+     */
+    private JButton getAddPermissionButton()
+    {
+        if ( addButton == null )
+        {
+            addButton = new JButton();
+            String tooltip = null;
+            if ( forGrants )
+            {
+                tooltip = "Add selected permissions to profile grants";
+            }
+            else
+            {
+                tooltip = "Add selected permissions to profile denials";
+            }
+            addButton.setToolTipText( tooltip );
+            addButton.setIcon( new ImageIcon( getClass().getResource(
+                "/org/safehaus/triplesec/admin/swing/rightarrow_16x16.png" ) ) );
+            addButton.addActionListener( new java.awt.event.ActionListener()
+            {
+                public void actionPerformed( java.awt.event.ActionEvent e )
+                {
+                    Object[] selectedValues = availableList.getSelectedValues();
+                    if ( selectedValues == null || selectedValues.length == 0 )
+                    {
+                        return;
+                    }
+
+                    for ( int ii = 0; ii < selectedValues.length; ii++ )
+                    {
+                        availableModel.removeElement( selectedValues[ii] );
+                        existingModel.add( 0, selectedValues[ii] );
+                    }
+                }
+            } );
+        }
+        return addButton;
+    }
+
+
+    /**
+     * This method initializes jButton1
+     * 
+     * @return javax.swing.JButton
+     */
+    private JButton getRemovePermissionButton()
+    {
+        if ( removeButton == null )
+        {
+            removeButton = new JButton();
+            String tooltip = null;
+            if ( forGrants )
+            {
+                tooltip = "Remove selected permissions from profile grants";
+            }
+            else
+            {
+                tooltip = "Remove selected permissions from profile denials";
+            }
+            removeButton.setToolTipText( tooltip );
+            removeButton.setIcon( new ImageIcon( getClass().getResource(
+                "/org/safehaus/triplesec/admin/swing/leftarrow_16x16.png" ) ) );
+            removeButton.addActionListener( new java.awt.event.ActionListener()
+            {
+                public void actionPerformed( java.awt.event.ActionEvent e )
+                {
+                    Object[] selectedValues = existingList.getSelectedValues();
+                    if ( selectedValues == null || selectedValues.length == 0 )
+                    {
+                        return;
+                    }
+
+                    for ( int ii = 0; ii < selectedValues.length; ii++ )
+                    {
+                        existingModel.removeElement( selectedValues[ii] );
+                        availableModel.add( 0, selectedValues[ii] );
+                    }
+                }
+            } );
+        }
+        return removeButton;
+    }
+
+
+    /**
+     * This method initializes jScrollPane  
+     *  
+     * @return javax.swing.JScrollPane  
+     */
+    private JScrollPane getJScrollPane()
+    {
+        if ( jScrollPane == null )
+        {
+            jScrollPane = new JScrollPane();
+            jScrollPane.setViewportView( getApplicationPermissions() );
+        }
+        return jScrollPane;
+    }
+
+
+    /**
+     * This method initializes jScrollPane1 
+     *  
+     * @return javax.swing.JScrollPane  
+     */
+    private JScrollPane getJScrollPane1()
+    {
+        if ( jScrollPane1 == null )
+        {
+            jScrollPane1 = new JScrollPane();
+            jScrollPane1.setViewportView( getProfileGrants() );
+        }
+        return jScrollPane1;
+    }
+
+
+    /**
+     * This method initializes jList
+     * 
+     * @return javax.swing.JList
+     */
+    private JList getApplicationPermissions()
+    {
+        if ( availableList == null )
+        {
+            availableList = new JList();
+            availableList.setPreferredSize( new java.awt.Dimension( 0, 0 ) );
+            String tooltip = null;
+            if ( forGrants )
+            {
+                tooltip = "Application permissions assignable to profile grants";
+            }
+            else
+            {
+                tooltip = "Application permissions assignable to profile denials";
+            }
+            availableList.setToolTipText( tooltip );
+            availableList.setModel( getDefaultListModel() );
+        }
+        return availableList;
+    }
+
+
+    /**
+     * This method initializes jList1
+     * 
+     * @return javax.swing.JList
+     */
+    private JList getProfileGrants()
+    {
+        if ( existingList == null )
+        {
+            existingList = new JList();
+            String tooltip = null;
+            if ( forGrants )
+            {
+                tooltip = "Permissions already assigned to profile grants";
+            }
+            else
+            {
+                tooltip = "Permissions already assigned to profile denials";
+            }
+            existingList.setToolTipText( tooltip );
+            existingList.setModel( getDefaultListModel1() );
+        }
+        return existingList;
+    }
+
+
+    /**
+     * This method initializes defaultListModel
+     * 
+     * @return javax.swing.DefaultListModel
+     */
+    private DefaultListModel getDefaultListModel()
+    {
+        if ( availableModel == null )
+        {
+            availableModel = new DefaultListModel();
+        }
+        return availableModel;
+    }
+
+
+    /**
+     * This method initializes defaultListModel1
+     * 
+     * @return javax.swing.DefaultListModel
+     */
+    private DefaultListModel getDefaultListModel1()
+    {
+        if ( existingModel == null )
+        {
+            existingModel = new DefaultListModel();
+        }
+        return existingModel;
+    }
+
+} //  @jve:decl-index=0:visual-constraint="10,10"

Added: directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/ProfileRolesPanel.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/ProfileRolesPanel.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/ProfileRolesPanel.java (added)
+++ directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/ProfileRolesPanel.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,373 @@
+/*
+ *  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.Enumeration;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.swing.DefaultListModel;
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.tree.DefaultMutableTreeNode;
+
+import org.safehaus.triplesec.admin.Role;
+
+
+public class ProfileRolesPanel extends JPanel
+{
+    private static final long serialVersionUID = 5014497087645715424L;
+
+    private JPanel jPanelRoles5 = null;
+    private JPanel jPanelRoles6 = null;
+    private JPanel jPanelRoles7 = null;
+    private JList availableRoles = null;
+    private JList existingRoles = null;
+    private JButton addButton = null;
+    private JButton removeButton = null;
+    private JScrollPane jScrollPane4 = null;
+    private JScrollPane jScrollPane5 = null;
+    private DefaultListModel availableModel = null; // @jve:decl-index=0:visual-constraint=""
+    private DefaultListModel existingModel = null; // @jve:decl-index=0:visual-constraint=""
+
+    
+    /**
+     * This is the default constructor
+     */
+    public ProfileRolesPanel()
+    {
+        super();
+        initialize();
+    }
+
+    
+    public void populateLists( DefaultMutableTreeNode applicationNode, Set roles )
+    {
+        if ( applicationNode == null )
+        {
+            return;
+        }
+        
+        // -------------------------------------------------------------------
+        // Find the Roles container under the application and clear lists
+        // -------------------------------------------------------------------
+        
+        availableModel.clear();
+        existingModel.clear();
+        DefaultMutableTreeNode rolesNode = null;
+        for ( Enumeration ii = applicationNode.children(); ii.hasMoreElements(); /**/ )
+        {
+            DefaultMutableTreeNode child = ( DefaultMutableTreeNode ) ii.nextElement();
+            if ( "Roles".equals( child.getUserObject() ) )
+            {
+                rolesNode = child;
+                break;
+            }
+        }
+        
+        // -------------------------------------------------------------------
+        // Fill up the available roles list and the existing roles list
+        // -------------------------------------------------------------------
+        
+        for ( Enumeration ii = rolesNode.children(); ii.hasMoreElements(); /**/)
+        {
+            Role role = ( Role ) ( ( DefaultMutableTreeNode ) ii.nextElement() ).getUserObject();
+            if ( !roles.contains( role.getName() ) )
+            {
+                availableModel.addElement( role.getName() );
+            }
+        }
+        for ( Iterator ii = roles.iterator(); ii.hasNext(); /**/)
+        {
+            existingModel.addElement( ii.next() );
+        }
+    }
+    
+
+    public DefaultListModel getAvailableRolesModel()
+    {
+        return availableModel;
+    }
+    
+    
+    public DefaultListModel getProfileRolesModel()
+    {
+        return existingModel;
+    }
+    
+    
+    /**
+     * This method initializes this
+     * 
+     * @return void
+     */
+    private void initialize()
+    {
+        this.setSize(613, 254);
+        setLayout( new BorderLayout() );
+        add( getAvailableRolesPanel(), java.awt.BorderLayout.WEST );
+        add( getButtonPanel(), java.awt.BorderLayout.CENTER );
+        add( getExistingRolesPanel(), java.awt.BorderLayout.EAST );
+    }
+
+
+    /**
+     * This method initializes jPanel5
+     * 
+     * @return javax.swing.JPanel
+     */
+    private JPanel getAvailableRolesPanel()
+    {
+        if ( jPanelRoles5 == null )
+        {
+            jPanelRoles5 = new JPanel();
+            jPanelRoles5.setLayout( new BorderLayout() );
+            jPanelRoles5.setBorder( javax.swing.BorderFactory.createTitledBorder( null, "Available Roles",
+                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
+                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null ) );
+            jPanelRoles5.setPreferredSize( new java.awt.Dimension( 200, 35 ) );
+            jPanelRoles5.add( getJScrollPane4(), java.awt.BorderLayout.CENTER );
+        }
+        return jPanelRoles5;
+    }
+
+
+    /**
+     * This method initializes jPanel6
+     * 
+     * @return javax.swing.JPanel
+     */
+    private JPanel getButtonPanel()
+    {
+        if ( jPanelRoles6 == null )
+        {
+            GridBagConstraints gridBagConstraints14 = new GridBagConstraints();
+            gridBagConstraints14.gridx = 0;
+            gridBagConstraints14.insets = new java.awt.Insets( 10, 0, 0, 0 );
+            gridBagConstraints14.gridy = 1;
+            GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
+            gridBagConstraints5.gridx = 0;
+            gridBagConstraints5.gridy = 0;
+            jPanelRoles6 = new JPanel();
+            jPanelRoles6.setLayout( new GridBagLayout() );
+            jPanelRoles6.add( getAddRolesButton(), gridBagConstraints5 );
+            jPanelRoles6.add( getRemoveRolesButton(), gridBagConstraints14 );
+        }
+        return jPanelRoles6;
+    }
+
+
+    /**
+     * This method initializes jPanel7
+     * 
+     * @return javax.swing.JPanel
+     */
+    private JPanel getExistingRolesPanel()
+    {
+        if ( jPanelRoles7 == null )
+        {
+            jPanelRoles7 = new JPanel();
+            jPanelRoles7.setLayout( new BorderLayout() );
+            jPanelRoles7.setPreferredSize( new java.awt.Dimension( 200, 10 ) );
+            jPanelRoles7.setBorder( javax.swing.BorderFactory.createTitledBorder( null, "Profile Roles",
+                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
+                javax.swing.border.TitledBorder.DEFAULT_POSITION,
+                new java.awt.Font( "Dialog", java.awt.Font.BOLD, 12 ), new java.awt.Color( 51, 51, 51 ) ) );
+            jPanelRoles7.add( getJScrollPane5(), java.awt.BorderLayout.CENTER );
+        }
+        return jPanelRoles7;
+    }
+
+
+    /**
+     * This method initializes jButton
+     * 
+     * @return javax.swing.JButton
+     */
+    private JButton getAddRolesButton()
+    {
+        if ( addButton == null )
+        {
+            addButton = new JButton();
+            addButton.setToolTipText( "Add selected roles to profile" );
+            addButton.setIcon( new ImageIcon( getClass().getResource(
+                "/org/safehaus/triplesec/admin/swing/rightarrow_16x16.png" ) ) );
+            addButton.addActionListener( new java.awt.event.ActionListener()
+            {
+                public void actionPerformed( java.awt.event.ActionEvent e )
+                {
+                    Object[] selectedValues = availableRoles.getSelectedValues();
+                    if ( selectedValues == null || selectedValues.length == 0 )
+                    {
+                        return;
+                    }
+
+                    for ( int ii = 0; ii < selectedValues.length; ii++ )
+                    {
+                        availableModel.removeElement( selectedValues[ii] );
+                        existingModel.add( 0, selectedValues[ii] );
+                    }
+                }
+            } );
+        }
+        return addButton;
+    }
+
+
+    /**
+     * This method initializes jButton1
+     * 
+     * @return javax.swing.JButton
+     */
+    private JButton getRemoveRolesButton()
+    {
+        if ( removeButton == null )
+        {
+            removeButton = new JButton();
+            removeButton.setToolTipText( "Remove selected roles from profile" );
+            removeButton.setIcon( new ImageIcon( getClass().getResource(
+                "/org/safehaus/triplesec/admin/swing/leftarrow_16x16.png" ) ) );
+            removeButton.addActionListener( new java.awt.event.ActionListener()
+            {
+                public void actionPerformed( java.awt.event.ActionEvent e )
+                {
+                    Object[] selectedValues = existingRoles.getSelectedValues();
+                    if ( selectedValues == null || selectedValues.length == 0 )
+                    {
+                        return;
+                    }
+
+                    for ( int ii = 0; ii < selectedValues.length; ii++ )
+                    {
+                        existingModel.removeElement( selectedValues[ii] );
+                        availableModel.add( 0, selectedValues[ii] );
+                    }
+                }
+            } );
+        }
+        return removeButton;
+    }
+
+
+    /**
+     * This method initializes jScrollPane4 
+     *  
+     * @return javax.swing.JScrollPane  
+     */
+    private JScrollPane getJScrollPane4()
+    {
+        if ( jScrollPane4 == null )
+        {
+            jScrollPane4 = new JScrollPane();
+            jScrollPane4.setViewportView( getApplicationRoles() );
+        }
+        return jScrollPane4;
+    }
+
+
+    /**
+     * This method initializes jScrollPane5 
+     *  
+     * @return javax.swing.JScrollPane  
+     */
+    private JScrollPane getJScrollPane5()
+    {
+        if ( jScrollPane5 == null )
+        {
+            jScrollPane5 = new JScrollPane();
+            jScrollPane5.setViewportView( getProfileRoles() );
+        }
+        return jScrollPane5;
+    }
+
+
+    /**
+     * This method initializes jList1
+     * 
+     * @return javax.swing.JList
+     */
+    private JList getProfileRoles()
+    {
+        if ( existingRoles == null )
+        {
+            existingRoles = new JList();
+            existingRoles.setToolTipText( "Roles already assigned to profile roles" );
+            existingRoles.setModel( getRolesDefaultListModel1() );
+        }
+        return existingRoles;
+    }
+
+
+    /**
+     * This method initializes jList
+     * 
+     * @return javax.swing.JList
+     */
+    private JList getApplicationRoles()
+    {
+        if ( availableRoles == null )
+        {
+            availableRoles = new JList();
+            availableRoles.setPreferredSize( new java.awt.Dimension( 0, 0 ) );
+            availableRoles.setToolTipText( "Application roles assignable to profile" );
+            availableRoles.setModel( getRolesDefaultListModel() );
+        }
+        return availableRoles;
+    }
+
+
+    /**
+     * This method initializes defaultListModel
+     * 
+     * @return javax.swing.DefaultListModel
+     */
+    private DefaultListModel getRolesDefaultListModel()
+    {
+        if ( availableModel == null )
+        {
+            availableModel = new DefaultListModel();
+        }
+        return availableModel;
+    }
+
+
+    /**
+     * This method initializes defaultListModel1
+     * 
+     * @return javax.swing.DefaultListModel
+     */
+    private DefaultListModel getRolesDefaultListModel1()
+    {
+        if ( existingModel == null )
+        {
+            existingModel = new DefaultListModel();
+        }
+        return existingModel;
+    }
+
+
+}  //  @jve:decl-index=0:visual-constraint="10,10"

Added: directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/ProvisioningPanel.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/ProvisioningPanel.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/ProvisioningPanel.java (added)
+++ directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/ProvisioningPanel.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,809 @@
+/*
+ *  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.FlowLayout;
+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 java.io.IOException;
+import java.util.Date;
+import java.util.Properties;
+
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.internet.AddressException;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+import javax.swing.ButtonGroup;
+import javax.swing.JComboBox;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JPasswordField;
+import javax.swing.JRadioButton;
+import javax.swing.JTextField;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.NameValuePair;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.safehaus.triplesec.admin.HauskeysUser;
+import org.safehaus.triplesec.admin.HauskeysUserModifier;
+import org.safehaus.triplesec.configuration.MutableTriplesecStartupConfiguration;
+
+import com.sun.mail.smtp.SMTPTransport;
+
+import javax.swing.JButton;
+
+
+public class ProvisioningPanel extends JPanel implements StatusObject, KeyListener, FocusListener
+{
+    private static final long serialVersionUID = 1L;
+
+    private JTextField emailTextField = null;
+    private JTextField mobileTextField = null;
+    private JComboBox mobileCarrierComboBox = null;
+    private JPasswordField tokenPinPasswordField = null;
+    private JTextField midletNameTextField = null;
+    private JPanel jPanel5 = null;
+    private JRadioButton emailRadioButton = null;
+    private JRadioButton smsRadioButton = null;
+    private ButtonGroup notifyByButtonGroup;
+    private HauskeysUser user;
+    private StatusListener listener;
+    private boolean lastStatusState = true;  // true = up to date, false means it was not up to date
+    private boolean newEntityMode = false;
+    private JButton deployButton = null;
+    private AdminFrame adminFrame = null;
+    
+    
+    /**
+     * This is the default constructor
+     */
+    public ProvisioningPanel()
+    {
+        super();
+        initialize();
+    }
+    
+    
+    public void setAdminFrame( AdminFrame adminFrame )
+    {
+        this.adminFrame = adminFrame;
+    }
+    
+    
+    public void setNewEntityMode( boolean newEnityMode )
+    {
+        this.newEntityMode = newEnityMode;
+    }
+    
+    
+    public void setStatusListener( StatusListener listener )
+    {
+        this.listener = listener;
+    }
+    
+    
+    public void setFields( HauskeysUser hauskeysUser )
+    {
+        user = hauskeysUser;
+        this.lastStatusState = true;
+        emailTextField.setText( hauskeysUser.getEmail() );
+        mobileTextField.setText( hauskeysUser.getMobile() );
+        tokenPinPasswordField.setText( hauskeysUser.getTokenPin() );
+        midletNameTextField.setText( hauskeysUser.getMidletName() );
+        if ( hauskeysUser.getNotifyBy() == null || hauskeysUser.getNotifyBy().equals( "null" ) )
+        {
+            notifyByButtonGroup.setSelected( null, false );
+            notifyByButtonGroup.remove( smsRadioButton );
+            notifyByButtonGroup.remove( emailRadioButton );
+            smsRadioButton.setSelected( false );
+            emailRadioButton.setSelected( false );
+            notifyByButtonGroup.add( smsRadioButton );
+            notifyByButtonGroup.add( emailRadioButton );
+        }
+        else if ( hauskeysUser.getNotifyBy().equalsIgnoreCase( "sms" ) )
+        {
+            notifyByButtonGroup.setSelected( smsRadioButton.getModel(), true );
+        }
+        else if ( hauskeysUser.getNotifyBy().equalsIgnoreCase( "email" ) )
+        {
+            notifyByButtonGroup.setSelected( emailRadioButton.getModel(), true );
+        }
+        else
+        {
+            throw new IllegalStateException( "Unknown value for notifyBy property in user: " 
+                + hauskeysUser.getNotifyBy() );
+        }
+
+        if ( hauskeysUser.getMobileCarrier() != null && ! hauskeysUser.getMobileCarrier().equals( "null" ) )
+        {
+            Carrier carrier = Carrier.getCarrier( hauskeysUser.getMobileCarrier() );
+            mobileCarrierComboBox.setSelectedItem( carrier );
+        }
+        else
+        {
+            mobileCarrierComboBox.setSelectedIndex( -1 );
+        }
+    }
+    
+    
+    public void alterModifier( HauskeysUserModifier modifier )
+    {
+        modifier.setEmail( emailTextField.getText() );
+        modifier.setMobile( mobileTextField.getText() );
+        modifier.setMobileCarrier( String.valueOf( mobileCarrierComboBox.getSelectedItem() ) );
+        modifier.setTokenPin( new String( tokenPinPasswordField.getPassword() ) );
+        modifier.setMidletName( midletNameTextField.getText() );
+        if ( emailRadioButton.isSelected() )
+        {
+            modifier.setNotifyBy( "email" );
+        }
+        else
+        {
+            modifier.setNotifyBy( "sms" );
+        }
+    }
+
+
+    /**
+     * This method initializes this
+     * 
+     * @return void
+     */
+    private void initialize()
+    {
+        GridBagConstraints gridBagConstraints = new GridBagConstraints();
+        gridBagConstraints.gridx = 1;
+        gridBagConstraints.gridy = 6;
+        this.setSize(525, 242);
+        GridBagConstraints gridBagConstraints44 = new GridBagConstraints();
+        gridBagConstraints44.gridx = 1;
+        gridBagConstraints44.fill = java.awt.GridBagConstraints.HORIZONTAL;
+        gridBagConstraints44.insets = new java.awt.Insets(0,0,5,5);
+        gridBagConstraints44.gridy = 5;
+        GridBagConstraints gridBagConstraints43 = new GridBagConstraints();
+        gridBagConstraints43.gridx = 0;
+        gridBagConstraints43.fill = java.awt.GridBagConstraints.HORIZONTAL;
+        gridBagConstraints43.insets = new java.awt.Insets( 0, 5, 5, 5 );
+        gridBagConstraints43.gridy = 5;
+        JLabel jLabel20 = new JLabel();
+        jLabel20.setText( "Provisioning Mechanism:" );
+        jLabel20.setHorizontalAlignment( javax.swing.SwingConstants.RIGHT );
+        GridBagConstraints gridBagConstraints42 = new GridBagConstraints();
+        gridBagConstraints42.fill = java.awt.GridBagConstraints.HORIZONTAL;
+        gridBagConstraints42.gridy = 4;
+        gridBagConstraints42.weightx = 1.0;
+        gridBagConstraints42.insets = new java.awt.Insets( 0, 0, 5, 5 );
+        gridBagConstraints42.gridx = 1;
+        GridBagConstraints gridBagConstraints41 = new GridBagConstraints();
+        gridBagConstraints41.gridx = 0;
+        gridBagConstraints41.fill = java.awt.GridBagConstraints.HORIZONTAL;
+        gridBagConstraints41.insets = new java.awt.Insets( 0, 5, 5, 5 );
+        gridBagConstraints41.gridy = 4;
+        JLabel jLabel19 = new JLabel();
+        jLabel19.setText( "Midlet Name:" );
+        jLabel19.setHorizontalAlignment( javax.swing.SwingConstants.RIGHT );
+        GridBagConstraints gridBagConstraints40 = new GridBagConstraints();
+        gridBagConstraints40.fill = java.awt.GridBagConstraints.HORIZONTAL;
+        gridBagConstraints40.gridy = 3;
+        gridBagConstraints40.weightx = 1.0;
+        gridBagConstraints40.insets = new java.awt.Insets( 0, 0, 5, 5 );
+        gridBagConstraints40.gridx = 1;
+        GridBagConstraints gridBagConstraints39 = new GridBagConstraints();
+        gridBagConstraints39.gridx = 0;
+        gridBagConstraints39.fill = java.awt.GridBagConstraints.HORIZONTAL;
+        gridBagConstraints39.insets = new java.awt.Insets( 0, 5, 5, 5 );
+        gridBagConstraints39.gridy = 3;
+        JLabel jLabel18 = new JLabel();
+        jLabel18.setText( "Hauskeys Pin:" );
+        jLabel18.setHorizontalAlignment( javax.swing.SwingConstants.RIGHT );
+        GridBagConstraints gridBagConstraints38 = new GridBagConstraints();
+        gridBagConstraints38.fill = java.awt.GridBagConstraints.HORIZONTAL;
+        gridBagConstraints38.gridy = 2;
+        gridBagConstraints38.weightx = 0.5D;
+        gridBagConstraints38.insets = new java.awt.Insets( 0, 0, 5, 200 );
+        gridBagConstraints38.gridx = 1;
+        GridBagConstraints gridBagConstraints37 = new GridBagConstraints();
+        gridBagConstraints37.gridx = 0;
+        gridBagConstraints37.fill = java.awt.GridBagConstraints.HORIZONTAL;
+        gridBagConstraints37.insets = new java.awt.Insets( 0, 5, 5, 5 );
+        gridBagConstraints37.gridy = 2;
+        JLabel jLabel17 = new JLabel();
+        jLabel17.setText( "Mobile Carrier:" );
+        jLabel17.setHorizontalAlignment( javax.swing.SwingConstants.RIGHT );
+        GridBagConstraints gridBagConstraints36 = new GridBagConstraints();
+        gridBagConstraints36.fill = java.awt.GridBagConstraints.HORIZONTAL;
+        gridBagConstraints36.gridy = 1;
+        gridBagConstraints36.weightx = 1.0;
+        gridBagConstraints36.insets = new java.awt.Insets( 0, 0, 5, 5 );
+        gridBagConstraints36.gridx = 1;
+        GridBagConstraints gridBagConstraints35 = new GridBagConstraints();
+        gridBagConstraints35.gridx = 0;
+        gridBagConstraints35.fill = java.awt.GridBagConstraints.HORIZONTAL;
+        gridBagConstraints35.insets = new java.awt.Insets( 0, 5, 5, 5 );
+        gridBagConstraints35.gridy = 1;
+        JLabel jLabel16 = new JLabel();
+        jLabel16.setText( "Mobile:" );
+        jLabel16.setHorizontalAlignment( javax.swing.SwingConstants.RIGHT );
+        GridBagConstraints gridBagConstraints34 = new GridBagConstraints();
+        gridBagConstraints34.fill = java.awt.GridBagConstraints.HORIZONTAL;
+        gridBagConstraints34.gridy = 0;
+        gridBagConstraints34.weightx = 1.0;
+        gridBagConstraints34.insets = new java.awt.Insets( 0, 0, 5, 5 );
+        gridBagConstraints34.gridx = 1;
+        GridBagConstraints gridBagConstraints33 = new GridBagConstraints();
+        gridBagConstraints33.gridx = 0;
+        gridBagConstraints33.insets = new java.awt.Insets( 0, 5, 5, 5 );
+        gridBagConstraints33.fill = java.awt.GridBagConstraints.HORIZONTAL;
+        gridBagConstraints33.gridy = 0;
+        JLabel jLabel15 = new JLabel();
+        jLabel15.setText( "Email:" );
+        jLabel15.setHorizontalAlignment( javax.swing.SwingConstants.RIGHT );
+        setLayout( new GridBagLayout() );
+        add( jLabel15, gridBagConstraints33 );
+        add( getEmailTextField(), gridBagConstraints34 );
+        add( jLabel16, gridBagConstraints35 );
+        add( getMobileTextField(), gridBagConstraints36 );
+        add( jLabel17, gridBagConstraints37 );
+        add( getMobileCarrierComboBox(), gridBagConstraints38 );
+        add( jLabel18, gridBagConstraints39 );
+        add( getTokenPinPasswordField(), gridBagConstraints40 );
+        add( jLabel19, gridBagConstraints41 );
+        add( getMidletNameTextField(), gridBagConstraints42 );
+        add( jLabel20, gridBagConstraints43 );
+        this.add(getJPanel5(), gridBagConstraints44);
+        this.add(getDeployButton(), gridBagConstraints);
+    }
+
+    
+    /**
+     * This method initializes jTextField   
+     *  
+     * @return javax.swing.JTextField   
+     */
+    private JTextField getEmailTextField()
+    {
+        if ( emailTextField == null )
+        {
+            emailTextField = new JTextField();
+            emailTextField.addFocusListener( this );
+            emailTextField.addKeyListener( this );
+        }
+        return emailTextField;
+    }
+
+
+    /**
+     * This method initializes jTextField   
+     *  
+     * @return javax.swing.JTextField   
+     */
+    private JTextField getMobileTextField()
+    {
+        if ( mobileTextField == null )
+        {
+            mobileTextField = new JTextField();
+            mobileTextField.addFocusListener( this );
+            mobileTextField.addKeyListener( this );
+        }
+        return mobileTextField;
+    }
+
+
+    /**
+     * This method initializes jComboBox    
+     *  
+     * @return javax.swing.JComboBox    
+     */
+    private JComboBox getMobileCarrierComboBox()
+    {
+        if ( mobileCarrierComboBox == null )
+        {
+            mobileCarrierComboBox = new JComboBox( Carrier.CARRIERS );
+            mobileCarrierComboBox.setPreferredSize( new java.awt.Dimension( 32, 19 ) );
+            mobileCarrierComboBox.addActionListener( new ActionListener () {
+                public void actionPerformed( ActionEvent e )
+                {
+                    checkStatus();
+                }});
+        }
+        return mobileCarrierComboBox;
+    }
+
+
+    /**
+     * This method initializes jPasswordField   
+     *  
+     * @return javax.swing.JPasswordField   
+     */
+    private JPasswordField getTokenPinPasswordField()
+    {
+        if ( tokenPinPasswordField == null )
+        {
+            tokenPinPasswordField = new JPasswordField();
+            tokenPinPasswordField.addFocusListener( this );
+            tokenPinPasswordField.addKeyListener( this );
+        }
+        return tokenPinPasswordField;
+    }
+
+
+    /**
+     * This method initializes jTextField   
+     *  
+     * @return javax.swing.JTextField   
+     */
+    private JTextField getMidletNameTextField()
+    {
+        if ( midletNameTextField == null )
+        {
+            midletNameTextField = new JTextField();
+            midletNameTextField.addFocusListener( this );
+            midletNameTextField.addKeyListener( this );
+        }
+        return midletNameTextField;
+    }
+
+
+    /**
+     * This method initializes jPanel5  
+     *  
+     * @return javax.swing.JPanel   
+     */
+    private JPanel getJPanel5()
+    {
+        if ( jPanel5 == null )
+        {
+            FlowLayout flowLayout1 = new FlowLayout();
+            flowLayout1.setAlignment( java.awt.FlowLayout.LEFT );
+            flowLayout1.setHgap(10);
+            jPanel5 = new JPanel();
+            jPanel5.setLayout( flowLayout1 );
+            jPanel5.add( getEmailRadioButton(), null );
+            jPanel5.add( getSmsRadioButton(), null );
+            notifyByButtonGroup = new ButtonGroup();
+            notifyByButtonGroup.add( getEmailRadioButton() );
+            notifyByButtonGroup.add( getSmsRadioButton() );
+        }
+        return jPanel5;
+    }
+
+
+    /**
+     * This method initializes jRadioButton 
+     *  
+     * @return javax.swing.JRadioButton 
+     */
+    private JRadioButton getEmailRadioButton()
+    {
+        if ( emailRadioButton == null )
+        {
+            emailRadioButton = new JRadioButton();
+            emailRadioButton.setText( "Email" );
+            emailRadioButton.addActionListener( new ActionListener() {
+                public void actionPerformed( ActionEvent e )
+                {
+                    checkStatus();
+                }} );
+        }
+        return emailRadioButton;
+    }
+
+
+    /**
+     * This method initializes jRadioButton1    
+     *  
+     * @return javax.swing.JRadioButton 
+     */
+    private JRadioButton getSmsRadioButton()
+    {
+        if ( smsRadioButton == null )
+        {
+            smsRadioButton = new JRadioButton();
+            smsRadioButton.setText( "SMS WAP Push" );
+            smsRadioButton.addActionListener( new ActionListener() {
+                public void actionPerformed( ActionEvent e )
+                {
+                    checkStatus();
+                }} );
+        }
+        return smsRadioButton;
+    }
+
+
+    public String getEmail()
+    {
+        return emailTextField.getText();
+    }
+    
+    
+    public String getMobile()
+    {
+        return mobileTextField.getText();
+    }
+    
+    
+    public Carrier getMobileCarrier()
+    {
+        return ( Carrier ) mobileCarrierComboBox.getSelectedItem();
+    }
+    
+    
+    public String getTokenPin()
+    {
+        return new String( tokenPinPasswordField.getPassword() );
+    }
+    
+    
+    public String getMidletName()
+    {
+        return midletNameTextField.getText();
+    }
+    
+    
+    public String getNotifyBy()
+    {
+        if ( emailRadioButton.isSelected() )
+        {
+            return "email";
+        }
+        return "sms";
+    }
+
+    
+    private void checkStatus()
+    {
+        boolean upToDate = isUpToDate();
+        if ( listener != null && lastStatusState != upToDate )
+        {
+            listener.statusChanged( ProvisioningPanel.this );
+            lastStatusState = upToDate;
+        }
+    }
+
+    
+    public void focusGained( FocusEvent e )
+    {
+        checkStatus();
+    }
+
+
+    public void focusLost( FocusEvent e )
+    {
+        checkStatus();
+    }
+
+
+    public void keyTyped( KeyEvent e )
+    {
+        checkStatus();
+    }
+
+
+    public void keyPressed( KeyEvent e )
+    {
+        checkStatus();
+    }
+
+
+    public void keyReleased( KeyEvent e )
+    {
+        checkStatus();
+    }
+
+
+    private boolean isNotifyByUpToDate( String value )
+    {
+        if ( value == null && !emailRadioButton.isSelected() && !smsRadioButton.isSelected() )
+        {
+            return true;
+        }
+        
+        if ( value == null )
+        {
+            return false;
+        }
+        
+        if ( emailRadioButton.isSelected() && value.equals( "email" ) )
+        {
+            return true;
+        }
+        
+        if ( this.smsRadioButton.isSelected() && value.equals( "sms" ) )
+        {
+            return true;
+        }
+        
+        return false;
+    }
+    
+    
+    private boolean isCarrierUpToDate( String carrier )
+    {
+        if ( carrier == null && mobileCarrierComboBox.getSelectedIndex() == -1 )
+        {
+            return true;
+        }
+
+        if ( carrier == null )
+        {
+            return false;
+        }
+
+        if ( carrier.equals( "null" ) )
+        {
+            return true;
+        }   
+        
+        return carrier.equals( mobileCarrierComboBox.getSelectedItem().toString() );
+    }
+
+    
+    public boolean isUpToDate()
+    {
+        if ( newEntityMode )
+        {
+            return UiUtils.isFieldUpToDate( this.emailTextField, null ) &&
+            UiUtils.isFieldUpToDate( this.midletNameTextField, null ) &&
+            UiUtils.isFieldUpToDate( this.mobileTextField, null ) &&
+            UiUtils.isFieldUpToDate( this.tokenPinPasswordField, null ) &&
+            isNotifyByUpToDate( null ) && isCarrierUpToDate( null );
+        }
+        return UiUtils.isFieldUpToDate( this.emailTextField, user.getEmail() ) &&
+            UiUtils.isFieldUpToDate( this.midletNameTextField, user.getMidletName() ) &&
+            UiUtils.isFieldUpToDate( this.mobileTextField, user.getMobile() ) &&
+            UiUtils.isFieldUpToDate( this.tokenPinPasswordField, user.getTokenPin() ) &&
+            isNotifyByUpToDate( user.getNotifyBy() ) && isCarrierUpToDate( user.getMobileCarrier() );
+    }
+
+
+    /**
+     * This method initializes jButton	
+     * 	
+     * @return javax.swing.JButton	
+     */
+    private JButton getDeployButton()
+    {
+        if ( deployButton == null )
+        {
+            deployButton = new JButton();
+            deployButton.setText("Deploy");
+            deployButton.addActionListener( new java.awt.event.ActionListener()
+            {
+                public void actionPerformed( java.awt.event.ActionEvent e )
+                {
+                    if ( emailRadioButton.isSelected() )
+                    {
+                        if ( emailTextField.getText() == null || emailTextField.getText().length() == 0 )
+                        {
+                            JOptionPane.showMessageDialog( ProvisioningPanel.this, 
+                                "Cannot deploy via email without a valid email address." );
+                            return;
+                        }
+                        
+                        try
+                        {
+                            deployByEmail();
+                        }
+                        catch ( Exception e1 )
+                        {
+                            String msg = UiUtils.wrap( "Failed to provision application: " + e1.getMessage(), 79 );
+                            JOptionPane.showMessageDialog( ProvisioningPanel.this, 
+                                msg, "Failed to deploy!", JOptionPane.ERROR_MESSAGE );
+                            return;
+                        }
+                    }
+                    else
+                    {
+                        if ( mobileTextField.getText() == null || mobileTextField.getText().length() == 0 )
+                        {
+                            JOptionPane.showMessageDialog( ProvisioningPanel.this, 
+                                "Cannot deploy via email without a valid email address." );
+                            return;
+                        }
+                        
+                        try
+                        {
+                            deployBySms();
+                        }
+                        catch ( Exception e1 )
+                        {
+                            String msg = UiUtils.wrap( "Failed to provision application: " + e1.getMessage(), 79 );
+                            JOptionPane.showMessageDialog( ProvisioningPanel.this, 
+                                msg, "Failed to deploy!", JOptionPane.ERROR_MESSAGE );
+                            return;
+                        }
+                    }
+                }
+
+            } );
+        }
+        return deployButton;
+    }
+
+    
+    private void deployBySms() throws HttpException, IOException
+    {
+        String smsTransportUrl = null;
+        String activationUrl = null;
+        String mobile = mobileTextField.getText();
+        String activationKey = user.getActivationKey();
+        String smsUsername = null; 
+        String smsAccountName = null;
+        String smsPassword = null;
+        String carrier = this.getMobileCarrierComboBox().getSelectedItem().toString();
+        
+        if ( adminFrame.getSettings() == null && !adminFrame.getConfigurationFileManager().isConfigurationLoaded() )
+        {
+            if ( ! adminFrame.doLoadSettings() )
+            {
+                return;
+            }
+            
+            smsTransportUrl = adminFrame.getSettings().getDefaultSmsConfig().getSmsTransportUrl();
+            smsPassword = adminFrame.getSettings().getDefaultSmsConfig().getSmsPassword();
+            smsUsername = adminFrame.getSettings().getDefaultSmsConfig().getSmsUsername();
+            smsAccountName = adminFrame.getSettings().getDefaultSmsConfig().getSmsAccountName();
+            activationUrl = adminFrame.getSettings().getPresentationBaseUrl() + "/activation";
+        }
+        else if ( adminFrame.getConfigurationFileManager().isConfigurationLoaded() )
+        {
+            MutableTriplesecStartupConfiguration config = adminFrame.getConfigurationFileManager().getConfiguration();
+            smsTransportUrl = config.getSmsConfiguration().getSmsTransportUrl();
+            smsUsername = config.getSmsConfiguration().getSmsUsername();
+            smsAccountName = config.getSmsConfiguration().getSmsAccountName();
+            smsPassword = config.getSmsConfiguration().getSmsPassword();
+            activationUrl = config.getPresentationBaseUrl() + "/activation";
+        }
+        
+        HttpClient client = new HttpClient();
+        HttpMethod method = new PostMethod( smsTransportUrl );
+        int carrierCode = 31004;
+        if ( carrier.equalsIgnoreCase( "AT&T" ) )
+        {
+            carrierCode = 31001;
+        }
+        else if ( carrier.equalsIgnoreCase( "Cingular" ) )
+        {
+            carrierCode = 31002;
+        }
+        else if ( carrier.equalsIgnoreCase( "Verizon" ) )
+        {
+            carrierCode = 31003;
+        }
+        else if ( carrier.equalsIgnoreCase( "T-Mobile" ) )
+        {
+            carrierCode = 31004;
+        }
+        else if ( carrier.equalsIgnoreCase( "Sprint" ) )
+        {
+            carrierCode = 31005;
+        }
+        else if ( carrier.equalsIgnoreCase( "Nextel" ) )
+        {
+            carrierCode = 31007;
+        }
+
+        if ( mobile.startsWith( "+" ) )
+        {
+            mobile = mobile.substring( 1 );
+        }
+        
+        if ( mobile.startsWith( "1" ) )
+        {
+            mobile = mobile.substring( 1 );
+            if ( mobile.length() < 10 )
+            {
+                throw new RuntimeException( "mobile phone number was not 10 digits in length" );
+            }
+        }
+        NameValuePair[] params = new NameValuePair[] {
+                new NameValuePair( "Carrier", String.valueOf( carrierCode ) ),
+                new NameValuePair( "UID", smsUsername ),
+                new NameValuePair( "PWD", smsPassword ),
+                new NameValuePair( "Campaign", smsAccountName ),
+                new NameValuePair( "CellNumber", mobile ),
+                new NameValuePair( "msg", activationUrl + "/" + activationKey + "/HausKeys.jar")
+        };
+        method.setQueryString( params );
+        client.executeMethod( method );
+    }
+    
+
+    private void deployByEmail() throws AddressException, MessagingException
+    {
+        String email = emailTextField.getText();
+        String activationKey = user.getActivationKey();
+        String activationUrl = null;
+        String smtpHost = null;
+        String smtpFrom = null;
+        boolean doAuthentication = false;
+        String smtpUsername = null;
+        String smtpPassword = null;
+        
+        
+        if ( adminFrame.getSettings() == null && !adminFrame.getConfigurationFileManager().isConfigurationLoaded() )
+        {
+            if ( ! adminFrame.doLoadSettings() )
+            {
+                return;
+            }
+            
+            smtpHost = adminFrame.getSettings().getDefaultSmtpConfig().getSmtpHost();
+            smtpFrom = adminFrame.getSettings().getDefaultSmtpConfig().getSmtpFrom();
+            doAuthentication = adminFrame.getSettings().getDefaultSmtpConfig().isSmtpAuthenticate();
+            smtpUsername = adminFrame.getSettings().getDefaultSmtpConfig().getSmtpUsername();
+            smtpPassword = adminFrame.getSettings().getDefaultSmtpConfig().getSmtpPassword();
+            activationUrl = adminFrame.getSettings().getPresentationBaseUrl() + "/activation";
+        }
+        else if ( adminFrame.getConfigurationFileManager().isConfigurationLoaded() )
+        {
+            MutableTriplesecStartupConfiguration config = adminFrame.getConfigurationFileManager().getConfiguration();
+            activationUrl = config.getPresentationBaseUrl() + "/activation";
+            smtpHost = config.getSmtpConfiguration().getSmtpHost();
+            smtpFrom = config.getSmtpConfiguration().getSmtpFrom();
+            smtpUsername = config.getSmtpConfiguration().getSmtpUsername();
+            smtpPassword = config.getSmtpConfiguration().getSmtpPassword();
+            doAuthentication = config.getSmtpConfiguration().isSmtpAuthenticate();
+        }
+
+        Properties props = new Properties();
+        props.setProperty( "mail.smtp.host", smtpHost );
+        Session session = Session.getInstance( props, null );
+
+        MimeMessage msg = new MimeMessage( session );
+        if ( smtpFrom != null )
+        {
+            msg.setFrom( new InternetAddress( smtpFrom ) );
+        }
+        else
+        {
+            msg.setFrom();
+        }
+
+        msg.setRecipients( Message.RecipientType.TO, InternetAddress.parse( email, false ) );
+        msg.setSubject( "Triplesec account ready for download." );
+        msg.setText( "Download your custom built hauskeys application here:\n" 
+            + activationUrl + "/" + activationKey + "/HausKeys.jar" );
+        msg.setHeader( "X-Mailer", "triplesec-registration" );
+        msg.setSentDate( new Date() );
+        SMTPTransport transport = ( SMTPTransport ) session.getTransport( "smtp" );
+        if ( doAuthentication )
+        {
+            transport.connect( smtpHost, smtpUsername, smtpPassword );
+        }
+        else
+        {
+            transport.connect();
+        }
+        transport.sendMessage( msg, msg.getAllRecipients() );
+    }
+}  //  @jve:decl-index=0:visual-constraint="10,10"



Mime
View raw message