directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tbenn...@apache.org
Subject svn commit: r486187 [28/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/HotpSettingsPanel.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/HotpSettingsPanel.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/HotpSettingsPanel.java (added)
+++ directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/HotpSettingsPanel.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,321 @@
+/*
+ *  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.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JPasswordField;
+import javax.swing.JTextField;
+
+import org.safehaus.triplesec.admin.HauskeysUser;
+import org.safehaus.triplesec.admin.HauskeysUserModifier;
+
+
+public class HotpSettingsPanel extends JPanel implements StatusObject, KeyListener, FocusListener
+{
+    private static final long serialVersionUID = 1L;
+    private JPasswordField secretPasswordField = null;
+    private JTextField movingFactorTextField = null;
+    private JTextField activationKeyTextField = null;
+    private JTextField failuresInEpochTextField = null;
+    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;
+    
+
+    /**
+     * This is the default constructor
+     */
+    public HotpSettingsPanel()
+    {
+        super();
+        initialize();
+    }
+
+    
+    public void setNewEntityMode( boolean newEntityMode )
+    {
+        this.newEntityMode = newEntityMode;
+    }
+    
+    
+    public void alterModifier( Object unkownModifier )
+    {
+        if ( unkownModifier instanceof HauskeysUserModifier )
+        {
+            HauskeysUserModifier modifier = ( HauskeysUserModifier ) unkownModifier;
+            modifier.setSecret( new String( secretPasswordField.getPassword() ) );
+            modifier.setMovingFactor( movingFactorTextField.getText() );
+            modifier.setActivationKey( activationKeyTextField.getText() );
+            modifier.setFailuresInEpoch( failuresInEpochTextField.getText() );
+        }
+    }
+    
+    
+    public void setFields( HauskeysUser user )
+    {
+        this.user = user;
+        this.lastStatusState = true;
+        secretPasswordField.setText( user.getSecret() );
+        movingFactorTextField.setText( user.getMovingFactor() );
+        activationKeyTextField.setText( user.getActivationKey() );
+        failuresInEpochTextField.setText( user.getFailuresInEpoch() );
+    }
+
+
+    /**
+     * This method initializes this
+     * 
+     * @return void
+     */
+    private void initialize()
+    {
+        this.setSize(517, 241);
+        GridBagConstraints gridBagConstraints52 = new GridBagConstraints();
+        gridBagConstraints52.fill = java.awt.GridBagConstraints.HORIZONTAL;
+        gridBagConstraints52.gridy = 3;
+        gridBagConstraints52.weightx = 1.0;
+        gridBagConstraints52.insets = new java.awt.Insets( 0, 0, 0, 5 );
+        gridBagConstraints52.gridx = 1;
+        GridBagConstraints gridBagConstraints51 = new GridBagConstraints();
+        gridBagConstraints51.gridx = 0;
+        gridBagConstraints51.fill = java.awt.GridBagConstraints.HORIZONTAL;
+        gridBagConstraints51.insets = new java.awt.Insets(0,0,0,5);
+        gridBagConstraints51.gridy = 3;
+        JLabel jLabel24 = new JLabel();
+        jLabel24.setText( "Failures In Epoch:" );
+        jLabel24.setHorizontalAlignment( javax.swing.SwingConstants.RIGHT );
+        GridBagConstraints gridBagConstraints50 = new GridBagConstraints();
+        gridBagConstraints50.fill = java.awt.GridBagConstraints.HORIZONTAL;
+        gridBagConstraints50.gridy = 2;
+        gridBagConstraints50.weightx = 1.0;
+        gridBagConstraints50.insets = new java.awt.Insets( 0, 0, 5, 5 );
+        gridBagConstraints50.gridx = 1;
+        GridBagConstraints gridBagConstraints49 = new GridBagConstraints();
+        gridBagConstraints49.gridx = 0;
+        gridBagConstraints49.fill = java.awt.GridBagConstraints.HORIZONTAL;
+        gridBagConstraints49.insets = new java.awt.Insets( 0, 5, 5, 5 );
+        gridBagConstraints49.gridy = 2;
+        JLabel jLabel23 = new JLabel();
+        jLabel23.setText( "Activation Key:" );
+        jLabel23.setHorizontalAlignment( javax.swing.SwingConstants.RIGHT );
+        GridBagConstraints gridBagConstraints48 = new GridBagConstraints();
+        gridBagConstraints48.fill = java.awt.GridBagConstraints.HORIZONTAL;
+        gridBagConstraints48.gridy = 1;
+        gridBagConstraints48.weightx = 1.0;
+        gridBagConstraints48.insets = new java.awt.Insets( 0, 0, 5, 5 );
+        gridBagConstraints48.gridx = 1;
+        GridBagConstraints gridBagConstraints47 = new GridBagConstraints();
+        gridBagConstraints47.gridx = 0;
+        gridBagConstraints47.fill = java.awt.GridBagConstraints.HORIZONTAL;
+        gridBagConstraints47.insets = new java.awt.Insets( 0, 5, 5, 5 );
+        gridBagConstraints47.gridy = 1;
+        JLabel jLabel22 = new JLabel();
+        jLabel22.setText( "Moving Factor:" );
+        jLabel22.setHorizontalAlignment( javax.swing.SwingConstants.RIGHT );
+        GridBagConstraints gridBagConstraints46 = new GridBagConstraints();
+        gridBagConstraints46.fill = java.awt.GridBagConstraints.HORIZONTAL;
+        gridBagConstraints46.gridy = 0;
+        gridBagConstraints46.weightx = 1.0;
+        gridBagConstraints46.insets = new java.awt.Insets( 0, 0, 5, 5 );
+        gridBagConstraints46.gridx = 1;
+        GridBagConstraints gridBagConstraints45 = new GridBagConstraints();
+        gridBagConstraints45.gridx = 0;
+        gridBagConstraints45.fill = java.awt.GridBagConstraints.HORIZONTAL;
+        gridBagConstraints45.insets = new java.awt.Insets( 0, 5, 5, 5 );
+        gridBagConstraints45.gridy = 0;
+        JLabel jLabel21 = new JLabel();
+        jLabel21.setText( "Secret:" );
+        jLabel21.setHorizontalAlignment( javax.swing.SwingConstants.RIGHT );
+        setLayout( new GridBagLayout() );
+        add( jLabel21, gridBagConstraints45 );
+        add( getSecretPasswordField(), gridBagConstraints46 );
+        add( jLabel22, gridBagConstraints47 );
+        add( getMovingFactorTextField(), gridBagConstraints48 );
+        add( jLabel23, gridBagConstraints49 );
+        add( getActivationKeyTextField(), gridBagConstraints50 );
+        this.add(jLabel24, gridBagConstraints51);
+        add( getFailuresInEpochTextField(), gridBagConstraints52 );
+    }
+
+
+    /**
+     * This method initializes jPasswordField   
+     *  
+     * @return javax.swing.JPasswordField   
+     */
+    private JPasswordField getSecretPasswordField()
+    {
+        if ( secretPasswordField == null )
+        {
+            secretPasswordField = new JPasswordField();
+            secretPasswordField.addFocusListener( this );
+            secretPasswordField.addKeyListener( this );
+        }
+        return secretPasswordField;
+    }
+
+
+    /**
+     * This method initializes jTextField   
+     *  
+     * @return javax.swing.JTextField   
+     */
+    private JTextField getMovingFactorTextField()
+    {
+        if ( movingFactorTextField == null )
+        {
+            movingFactorTextField = new JTextField();
+            movingFactorTextField.addFocusListener( this );
+            movingFactorTextField.addKeyListener( this );
+        }
+        return movingFactorTextField;
+    }
+
+
+    /**
+     * This method initializes jTextField   
+     *  
+     * @return javax.swing.JTextField   
+     */
+    private JTextField getActivationKeyTextField()
+    {
+        if ( activationKeyTextField == null )
+        {
+            activationKeyTextField = new JTextField();
+            activationKeyTextField.addFocusListener( this );
+            activationKeyTextField.addKeyListener( this );
+        }
+        return activationKeyTextField;
+    }
+
+
+    /**
+     * This method initializes jTextField   
+     *  
+     * @return javax.swing.JTextField   
+     */
+    private JTextField getFailuresInEpochTextField()
+    {
+        if ( failuresInEpochTextField == null )
+        {
+            failuresInEpochTextField = new JTextField();
+            failuresInEpochTextField.addFocusListener( this );
+            failuresInEpochTextField.addKeyListener( this );
+        }
+        return failuresInEpochTextField;
+    }
+
+
+    public String getActivationKey()
+    {
+        return activationKeyTextField.getText();
+    }
+    
+    
+    public String getFailuresInEpoch()
+    {
+        return failuresInEpochTextField.getText();
+    }
+    
+    
+    public String getSecret()
+    {
+        return new String( secretPasswordField.getPassword() );
+    }
+
+
+    public String getMovingFactor()
+    {
+        return movingFactorTextField.getText();
+    }
+
+
+    public boolean isUpToDate()
+    {
+        if ( newEntityMode )
+        {
+            return UiUtils.isFieldUpToDate( this.activationKeyTextField, null ) &&
+            UiUtils.isFieldUpToDate( this.failuresInEpochTextField, null ) &&
+            UiUtils.isFieldUpToDate( this.movingFactorTextField, null ) &&
+            UiUtils.isFieldUpToDate( this.secretPasswordField, null );
+        }
+        return UiUtils.isFieldUpToDate( this.activationKeyTextField, user.getActivationKey() ) &&
+            UiUtils.isFieldUpToDate( this.failuresInEpochTextField, user.getFailuresInEpoch() ) &&
+            UiUtils.isFieldUpToDate( this.movingFactorTextField, user.getMovingFactor() ) &&
+            UiUtils.isFieldUpToDate( this.secretPasswordField, user.getSecret() );
+    }
+
+    
+    public void setStatusListener( StatusListener listener ) 
+    {
+        this.listener = listener;
+    }
+    
+    
+    private void checkStatus()
+    {
+        boolean upToDate = isUpToDate();
+        if ( listener != null && lastStatusState != upToDate )
+        {
+            listener.statusChanged( HotpSettingsPanel.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();
+    }
+}  //  @jve:decl-index=0:visual-constraint="10,10"

Added: directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/LeftTreeCellRenderer.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/LeftTreeCellRenderer.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/LeftTreeCellRenderer.java (added)
+++ directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/LeftTreeCellRenderer.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,427 @@
+/*
+ *  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.Component;
+
+import javax.swing.ImageIcon;
+import javax.swing.JTree;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeCellRenderer;
+
+import org.safehaus.triplesec.admin.Application;
+import org.safehaus.triplesec.admin.ExternalUser;
+import org.safehaus.triplesec.admin.Group;
+import org.safehaus.triplesec.admin.HauskeysUser;
+import org.safehaus.triplesec.admin.LocalUser;
+import org.safehaus.triplesec.admin.Permission;
+import org.safehaus.triplesec.admin.Profile;
+import org.safehaus.triplesec.admin.Role;
+
+
+/**
+ * The left tree navigation cell renderer.
+ * 
+ * @author <a href="mailto:akarasulu@safehaus.org">Alex Karasulu</a>
+ * @version $Rev$
+ */
+public class LeftTreeCellRenderer extends DefaultTreeCellRenderer
+{
+    private static final long serialVersionUID = 1L;
+    
+    // -----------------------------------------------------------------------
+    // Leaf node icons
+    // -----------------------------------------------------------------------
+    
+    private ImageIcon rootIcon = new ImageIcon( 
+        getClass().getResource( "/org/safehaus/triplesec/admin/swing/home2_16x16.png" ) );
+    
+    private ImageIcon localUserIcon = new ImageIcon( 
+        getClass().getResource( "/org/safehaus/triplesec/admin/swing/local_user_16x16.png" ) );
+    private ImageIcon externalUserIcon = new ImageIcon( 
+        getClass().getResource( "/org/safehaus/triplesec/admin/swing/external_user_16x16.png" ) );
+    private ImageIcon hauskeysUserIcon = new ImageIcon( 
+        getClass().getResource( "/org/safehaus/triplesec/admin/swing/hauskeys_user_16x16.png" ) );
+    
+    private ImageIcon userContainerClosedIcon = new ImageIcon( 
+        getClass().getResource( "/org/safehaus/triplesec/admin/swing/user_container_closed_16x16.png" ) );
+    private ImageIcon userContainerOpenedIcon = new ImageIcon( 
+        getClass().getResource( "/org/safehaus/triplesec/admin/swing/user_container_opened_16x16.png" ) );
+    
+    private ImageIcon profileIcon = new ImageIcon( 
+        getClass().getResource( "/org/safehaus/triplesec/admin/swing/profile2_16x16.png" ) );
+    private ImageIcon profileContainerClosedIcon = new ImageIcon( 
+        getClass().getResource( "/org/safehaus/triplesec/admin/swing/profile_container_closed_16x16.png" ) );
+    private ImageIcon profileContainerOpenedIcon = new ImageIcon( 
+        getClass().getResource( "/org/safehaus/triplesec/admin/swing/profile_container_opened_16x16.png" ) );
+    
+    private ImageIcon permissionIcon = new ImageIcon( 
+        getClass().getResource( "/org/safehaus/triplesec/admin/swing/permission2_16x16.png" ) );
+    private ImageIcon permissionContainerClosedIcon = new ImageIcon( 
+        getClass().getResource( "/org/safehaus/triplesec/admin/swing/permission_container_closed_16x16.png" ) );
+    private ImageIcon permissionContainerOpenedIcon = new ImageIcon( 
+        getClass().getResource( "/org/safehaus/triplesec/admin/swing/permission_container_opened_16x16.png" ) );
+    
+    private ImageIcon applicationIcon = new ImageIcon( 
+        getClass().getResource( "/org/safehaus/triplesec/admin/swing/application_16x16.png" ) );
+    private ImageIcon applicationContainerClosedIcon = new ImageIcon( 
+        getClass().getResource( "/org/safehaus/triplesec/admin/swing/application_container_closed_16x16.png" ) );
+    private ImageIcon applicationContainerOpenedIcon = new ImageIcon( 
+        getClass().getResource( "/org/safehaus/triplesec/admin/swing/application_container_opened_16x16.png" ) );
+
+    private ImageIcon roleIcon = new ImageIcon( 
+        getClass().getResource( "/org/safehaus/triplesec/admin/swing/role_16x16.png" ) );
+    private ImageIcon roleContainerClosedIcon = new ImageIcon( 
+        getClass().getResource( "/org/safehaus/triplesec/admin/swing/role_container_closed_16x16.png" ) );
+    private ImageIcon roleContainerOpenedIcon = new ImageIcon( 
+        getClass().getResource( "/org/safehaus/triplesec/admin/swing/role_container_opened_16x16.png" ) );
+
+    private ImageIcon groupIcon = new ImageIcon( 
+        getClass().getResource( "/org/safehaus/triplesec/admin/swing/group_16x16.png" ) );
+    private ImageIcon groupContainerClosedIcon = new ImageIcon( 
+        getClass().getResource( "/org/safehaus/triplesec/admin/swing/group_container_closed_16x16.png" ) );
+    private ImageIcon groupContainerOpenedIcon = new ImageIcon( 
+        getClass().getResource( "/org/safehaus/triplesec/admin/swing/group_container_opened_16x16.png" ) );
+
+    private DefaultMutableTreeNode rootNode;
+
+    // -----------------------------------------------------------------------
+    // Branch node icons
+    // -----------------------------------------------------------------------
+
+    
+    public LeftTreeCellRenderer ( DefaultMutableTreeNode rootNode )
+    {
+        this.rootNode = rootNode;
+    }
+    
+    
+    public Component getTreeCellRendererComponent( JTree tree, Object value, boolean sel, boolean expanded,
+        boolean leaf, int row, boolean hasFocus ) 
+    {
+        super.getTreeCellRendererComponent( tree, value, sel, expanded, leaf, row, hasFocus );
+
+        if ( isRoot( value ) )
+        {
+            setIcon( rootIcon );
+        }
+        else if ( isContainer( "Permissions", value ) )
+        {
+            if ( expanded )
+            {
+                setIcon( permissionContainerOpenedIcon );
+            }
+            else
+            {
+                setIcon( permissionContainerClosedIcon );
+            }
+        }
+        else if ( isContainer( "Roles", value ) )
+        {
+            if ( expanded )
+            {
+                setIcon( roleContainerOpenedIcon );
+            }
+            else
+            {
+                setIcon( roleContainerClosedIcon );
+            }
+        }
+        else if ( isContainer( "Profiles", value ) )
+        {
+            if ( expanded )
+            {
+                setIcon( profileContainerOpenedIcon );
+            }
+            else
+            {
+                setIcon( profileContainerClosedIcon );
+            }
+        }
+        else if ( isContainer( "Users", value ) )
+        {
+            if ( expanded )
+            {
+                setIcon( userContainerOpenedIcon );
+            }
+            else
+            {
+                setIcon( userContainerClosedIcon );
+            }
+        }
+        else if ( isContainer( "Groups", value ) )
+        {
+            if ( expanded )
+            {
+                setIcon( groupContainerOpenedIcon );
+            }
+            else
+            {
+                setIcon( groupContainerClosedIcon );
+            }
+        }
+        else if ( isContainer( "Applications", value ) )
+        {
+            if ( expanded )
+            {
+                setIcon( applicationContainerOpenedIcon );
+            }
+            else
+            {
+                setIcon( applicationContainerClosedIcon );
+            }
+        }
+        else if ( leaf && isPermission( value ) ) 
+        {
+            setIcon( permissionIcon );
+            Permission permission = getPermission( value );
+            if ( permission.getDescription() != null )
+            {
+                setToolTipText( permission.getDescription() );
+            }
+        }
+        else if ( isApplication( value ) )
+        {
+            setIcon( applicationIcon );
+            Application app = getApplication( value );
+            if ( app.getDescription() != null )
+            {
+                setToolTipText( app.getDescription() );
+            }
+        }
+        else if ( leaf && isRole( value ) )
+        {
+            setIcon( roleIcon );
+            Role role = getRole( value );
+            if ( role.getDescription() != null )
+            {
+                setToolTipText( role.getDescription() );
+            }
+        }
+        else if ( leaf && isProfile( value ) )
+        {
+            setIcon( profileIcon );
+            Profile profile = getProfile( value );
+            if ( profile.getDescription() != null )
+            {
+                setToolTipText( profile.getDescription() );
+            }
+        }
+        else if ( leaf && isGroup( value ) )
+        {
+            setIcon( groupIcon );
+            Group group = getGroup( value );
+            if ( group.getName() != null )
+            {
+                setToolTipText( group.getName() );
+            }
+        }
+        else if ( leaf && isLocalUser( value ) )
+        {
+            setIcon( localUserIcon );
+            LocalUser user = getLocalUser( value );
+            setToolTipText( "Local User: " + user.getId() );
+        }
+        else if ( leaf && isHauskeysUser( value ) )
+        {
+            setIcon( hauskeysUserIcon );
+            HauskeysUser user = getHauskeysUser( value );
+            setToolTipText( "Hauskeys User: " + user.getId() );
+        }
+        else if ( leaf && isExternalUser( value ) )
+        {
+            setIcon( externalUserIcon );
+            ExternalUser user = getExternalUser( value );
+            setToolTipText( "External User: " + user.getId() + " -> " + user.getReferral() );
+        }
+        else 
+        {
+            setToolTipText( null ); //no tool tip
+        } 
+
+        return this;
+    }
+    
+
+    private boolean isContainer( String name, Object value )
+    {
+        DefaultMutableTreeNode node = ( DefaultMutableTreeNode ) value;
+        if ( node.getUserObject() instanceof String )
+        {
+            String nodeName = ( String ) node.getUserObject();
+            if ( nodeName.equals( name ) )
+            {
+                return true;
+            }
+        }
+        return false;
+    }
+
+
+    private boolean isRoot( Object value )
+    {
+        return rootNode.equals( value );
+    }
+    
+    
+    private Group getGroup( Object value )
+    {
+        DefaultMutableTreeNode node = ( DefaultMutableTreeNode ) value;
+        return ( Group ) node.getUserObject();
+    }
+
+
+    private boolean isGroup( Object value )
+    {
+        DefaultMutableTreeNode node = ( DefaultMutableTreeNode ) value;
+        if ( node.getUserObject() instanceof Group )
+        {
+            return true;
+        }
+        return false;
+    }
+
+
+    private Profile getProfile( Object value )
+    {
+        DefaultMutableTreeNode node = ( DefaultMutableTreeNode ) value;
+        return ( Profile ) node.getUserObject();
+    }
+
+
+    private LocalUser getLocalUser( Object value )
+    {
+        DefaultMutableTreeNode node = ( DefaultMutableTreeNode ) value;
+        return ( LocalUser ) node.getUserObject();
+    }
+
+
+    private ExternalUser getExternalUser( Object value )
+    {
+        DefaultMutableTreeNode node = ( DefaultMutableTreeNode ) value;
+        return ( ExternalUser ) node.getUserObject();
+    }
+
+
+    private HauskeysUser getHauskeysUser( Object value )
+    {
+        DefaultMutableTreeNode node = ( DefaultMutableTreeNode ) value;
+        return ( HauskeysUser ) node.getUserObject();
+    }
+
+
+    private boolean isProfile( Object value )
+    {
+        DefaultMutableTreeNode node = ( DefaultMutableTreeNode ) value;
+        if ( node.getUserObject() instanceof Profile )
+        {
+            return true;
+        }
+        return false;
+    }
+
+
+    private Role getRole( Object value )
+    {
+        DefaultMutableTreeNode node = ( DefaultMutableTreeNode ) value;
+        return ( Role ) node.getUserObject();
+    }
+
+
+    private boolean isRole( Object value )
+    {
+        DefaultMutableTreeNode node = ( DefaultMutableTreeNode ) value;
+        if ( node.getUserObject() instanceof Role )
+        {
+            return true;
+        }
+        return false;
+    }
+
+
+    private boolean isPermission( Object obj )
+    {
+        DefaultMutableTreeNode node = ( DefaultMutableTreeNode ) obj;
+        if ( node.getUserObject() instanceof Permission )
+        {
+            return true;
+        }
+        return false;
+    }
+    
+    
+    private boolean isLocalUser( Object obj )
+    {
+        DefaultMutableTreeNode node = ( DefaultMutableTreeNode ) obj;
+        if ( node.getUserObject() instanceof LocalUser )
+        {
+            return true;
+        }
+        return false;
+    }
+    
+    
+    private boolean isExternalUser( Object obj )
+    {
+        DefaultMutableTreeNode node = ( DefaultMutableTreeNode ) obj;
+        if ( node.getUserObject() instanceof ExternalUser )
+        {
+            return true;
+        }
+        return false;
+    }
+    
+    
+    private boolean isHauskeysUser( Object obj )
+    {
+        DefaultMutableTreeNode node = ( DefaultMutableTreeNode ) obj;
+        if ( node.getUserObject() instanceof HauskeysUser )
+        {
+            return true;
+        }
+        return false;
+    }
+    
+    
+    private Permission getPermission( Object obj )
+    {
+        DefaultMutableTreeNode node = ( DefaultMutableTreeNode ) obj;
+        return ( Permission ) node.getUserObject();
+    }
+    
+    
+    private boolean isApplication( Object obj )
+    {
+        DefaultMutableTreeNode node = ( DefaultMutableTreeNode ) obj;
+        if ( node.getUserObject() instanceof Application )
+        {
+            return true;
+        }
+        return false;
+    }
+    
+    
+    private Application getApplication( Object obj )
+    {
+        DefaultMutableTreeNode node = ( DefaultMutableTreeNode ) obj;
+        return ( Application ) node.getUserObject();
+    }
+}

Added: directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/LeftTreeNavigation.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/LeftTreeNavigation.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/LeftTreeNavigation.java (added)
+++ directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/LeftTreeNavigation.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,322 @@
+/*
+ *  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.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTree;
+import javax.swing.event.TreeSelectionListener;
+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.TriplesecAdmin;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.awt.GridLayout;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.Observable;
+import java.util.Observer;
+
+
+/**
+ * The left tree navigation.
+ * 
+ * @author <a href="mailto:akarasulu@safehaus.org">Alex Karasulu</a>
+ * @version $Rev$
+ */
+public class LeftTreeNavigation extends JPanel implements Observer
+{
+    private static final long serialVersionUID = 105910555885359618L;
+    private JScrollPane scrollPane = null;
+    private JTree tree = null;
+    private JPanel rightDetailPanel;
+    
+    private DefaultTreeModel model;
+    private DefaultMutableTreeNode rootNode;
+    private DefaultMutableTreeNode groupsNode;
+    private DefaultMutableTreeNode usersNode;
+    private DefaultMutableTreeNode applicationsNode;
+
+
+    /**
+     * This method initializes
+     */
+    public LeftTreeNavigation()
+    {
+        super();
+        initialize();
+    }
+
+
+    /**
+     * This method initializes this
+     */
+    private void initialize()
+    {
+        GridLayout gridLayout = new GridLayout();
+        gridLayout.setRows( 1 );
+        this.setLayout( gridLayout );
+        this.setSize( new java.awt.Dimension( 315, 497 ) );
+        this.add( getJScrollPane(), null );
+    }
+
+
+    /**
+     * This method initializes jScrollPane
+     * 
+     * @return javax.swing.JScrollPane
+     */
+    private JScrollPane getJScrollPane()
+    {
+        if ( scrollPane == null )
+        {
+            scrollPane = new JScrollPane();
+            scrollPane.setViewportView( getJTree() );
+        }
+        return scrollPane;
+    }
+
+
+    /**
+     * This method initializes jTree
+     * 
+     * @return javax.swing.JTree
+     */
+    private JTree getJTree()
+    {
+        if ( tree == null )
+        {
+            tree = new JTree();
+            tree.setShowsRootHandles( true );
+            tree.setRootVisible( true );
+            tree.putClientProperty("JTree.lineStyle", "None");
+            rootNode = new DefaultMutableTreeNode( "disconnected" );
+            tree.setCellRenderer( new LeftTreeCellRenderer( rootNode ) );
+            model = new DefaultTreeModel( rootNode );
+            tree.setModel( model );
+            usersNode = new DefaultMutableTreeNode( "Users" );
+            model.insertNodeInto( usersNode, rootNode, 0 );
+            groupsNode = new DefaultMutableTreeNode( "Groups" );
+            model.insertNodeInto( groupsNode, rootNode, 0 );
+            applicationsNode = new DefaultMutableTreeNode( "Applications" );
+            model.insertNodeInto( applicationsNode, rootNode, 0 );
+        }
+        return tree;
+    }
+
+    
+    public void addTreeSelectionListener( TreeSelectionListener listener )
+    {
+        tree.addTreeSelectionListener( listener );
+    }
+    
+    
+    public JPanel getRightDetailPanel()
+    {
+        return rightDetailPanel;
+    }
+
+    
+    public void setRightDetailPanel( JPanel rightDetailPanel )
+    {
+        this.rightDetailPanel = rightDetailPanel;
+    }
+
+
+    String realm = null;
+    TriplesecAdmin admin = null;
+    private static Logger log = LoggerFactory.getLogger( LeftTreeNavigation.class );
+    public void update( Observable o, Object arg )
+    {
+        if ( o instanceof ConnectionManager )
+        {
+            ConnectionManager connMan = ( ConnectionManager ) o;
+            if ( connMan.isConnected() )
+            {
+                admin = connMan.getTriplesecAdmin();
+                realm = connMan.getRealm();
+                try
+                {
+                    load();
+                }
+                catch ( DataAccessException e )
+                {
+                    log.error( "failed on load", e );
+                    JOptionPane.showMessageDialog( this, e.getMessage(), "Failed on load", JOptionPane.ERROR_MESSAGE );
+                }
+            }
+            else
+            {
+                realm = null;
+                admin = null;
+                clear();
+            }
+        }
+    }
+    
+    
+    private void load() throws DataAccessException
+    {
+        if ( admin == null )
+        {
+            throw new IllegalStateException( "Admin should not be null" );
+        }
+
+        rootNode.setUserObject( realm );
+
+        for ( Iterator ii = admin.groupIterator(); ii.hasNext(); /**/ )
+        {
+            model.insertNodeInto( new DefaultMutableTreeNode( ii.next() ), groupsNode, 0 );
+        }
+        
+        for ( Iterator ii = admin.userIterator(); ii.hasNext(); /**/ )
+        {
+            model.insertNodeInto( new DefaultMutableTreeNode( ii.next() ), usersNode, 0 );
+        }
+        
+        for ( Iterator ii = admin.applicationIterator(); ii.hasNext(); /**/ )
+        {
+            Application app = ( Application ) ii.next();
+            DefaultMutableTreeNode appNode = new DefaultMutableTreeNode( app );
+            model.insertNodeInto( appNode, applicationsNode, 0 );
+            
+            DefaultMutableTreeNode profilesNode = new DefaultMutableTreeNode( "Profiles" );
+            model.insertNodeInto( profilesNode, appNode, 0 );
+            for ( Iterator jj = app.profileIterator(); jj.hasNext(); /**/ )
+            {
+                model.insertNodeInto( new DefaultMutableTreeNode( jj.next() ), profilesNode, 0 );
+            }
+            
+            DefaultMutableTreeNode rolesNode = new DefaultMutableTreeNode( "Roles" );
+            model.insertNodeInto( rolesNode, appNode, 0 );
+            for ( Iterator jj = app.roleIterator(); jj.hasNext(); /**/ )
+            {
+                model.insertNodeInto( new DefaultMutableTreeNode( jj.next() ), rolesNode, 0 );
+            }
+
+            DefaultMutableTreeNode permissionsNode = new DefaultMutableTreeNode( "Permissions" );
+            model.insertNodeInto( permissionsNode, appNode, 0 );
+            for ( Iterator jj = app.permissionIterator(); jj.hasNext(); /**/ )
+            {
+                model.insertNodeInto( new DefaultMutableTreeNode( jj.next() ), permissionsNode, 0 );
+            }
+        }
+    }
+    
+    
+    void reloadApplication( DefaultMutableTreeNode appNode ) throws DataAccessException
+    {
+        // -------------------------------------------------------------------
+        // clear out the old application 
+        // -------------------------------------------------------------------
+        
+        while( appNode.children().hasMoreElements() )
+        {
+            clear( appNode );
+        }
+        
+        // -------------------------------------------------------------------
+        // load the application again
+        // -------------------------------------------------------------------
+        
+        Application app = ( Application ) appNode.getUserObject();
+        DefaultMutableTreeNode profilesNode = new DefaultMutableTreeNode( "Profiles" );
+        model.insertNodeInto( profilesNode, appNode, 0 );
+        for ( Iterator jj = app.profileIterator(); jj.hasNext(); /**/ )
+        {
+            model.insertNodeInto( new DefaultMutableTreeNode( jj.next() ), profilesNode, 0 );
+        }
+        
+        DefaultMutableTreeNode rolesNode = new DefaultMutableTreeNode( "Roles" );
+        model.insertNodeInto( rolesNode, appNode, 0 );
+        for ( Iterator jj = app.roleIterator(); jj.hasNext(); /**/ )
+        {
+            model.insertNodeInto( new DefaultMutableTreeNode( jj.next() ), rolesNode, 0 );
+        }
+
+        DefaultMutableTreeNode permissionsNode = new DefaultMutableTreeNode( "Permissions" );
+        model.insertNodeInto( permissionsNode, appNode, 0 );
+        for ( Iterator jj = app.permissionIterator(); jj.hasNext(); /**/ )
+        {
+            model.insertNodeInto( new DefaultMutableTreeNode( jj.next() ), permissionsNode, 0 );
+        }
+    }
+    
+    
+    private void clear()
+    {
+        rootNode.setUserObject( "disconnected" );
+        
+        while ( usersNode.children().hasMoreElements() )
+        {
+            clear( usersNode );
+        }
+
+        while ( groupsNode.children().hasMoreElements() )
+        {
+            clear( groupsNode );
+        }
+
+        while ( applicationsNode.children().hasMoreElements() )
+        {
+            clear( applicationsNode );
+        }
+    }
+    
+    
+    private void clear( DefaultMutableTreeNode node )
+    {
+        for ( Enumeration ii = node.children(); ii.hasMoreElements(); /**/ )
+        {
+            DefaultMutableTreeNode child = ( DefaultMutableTreeNode ) ii.nextElement();
+            clear( child );
+            model.removeNodeFromParent( child );
+        }
+    }
+
+
+    public JTree getTree()
+    {
+        return tree;
+    }
+
+
+    public void reloadGroups() throws DataAccessException
+    {
+        while ( groupsNode.children().hasMoreElements() )
+        {
+            for ( Enumeration ii = groupsNode.children(); ii.hasMoreElements(); /**/ )
+            {
+                model.removeNodeFromParent( ( DefaultMutableTreeNode ) ii.nextElement() );
+            }
+        }
+        
+        for ( Iterator ii = admin.groupIterator(); ii.hasNext(); /**/ )
+        {
+            model.insertNodeInto( new DefaultMutableTreeNode( ii.next() ), groupsNode, 0 );
+        }
+    }
+} // @jve:decl-index=0:visual-constraint="10,10"

Added: directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/LoginDialog.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/LoginDialog.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/LoginDialog.java (added)
+++ directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/LoginDialog.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,450 @@
+/*
+ *  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 javax.swing.JDialog;
+import java.awt.GridBagLayout;
+import java.awt.GridBagConstraints;
+
+import javax.swing.JOptionPane;
+import javax.swing.JTextField;
+import javax.swing.JLabel;
+import javax.swing.JPasswordField;
+import javax.swing.JComboBox;
+import javax.swing.JButton;
+
+
+/**
+ * A login dialog used to capture optional 2-factor authentication credentials
+ * as well as standard static password credentials.
+ *
+ * @author <a href="mailto:akarasulu@safehaus.org">Alex Karasulu</a>
+ * @version $Rev$
+ */
+public class LoginDialog extends JDialog
+{
+    private static final long serialVersionUID = -7314707823982966424L;
+
+    private JPanel mainPanel = null;
+    private JPanel inputPanel = null;
+    private JPanel usernamePanel = null;
+    private JLabel usernameLabel = null;
+    private JTextField usernameField = null;
+    private JPanel passwordPanel = null;
+    private JLabel passwordLabel = null;
+    private JPasswordField passwordField = null;
+    private JPanel realmPanel = null;
+    private JLabel realmLabel = null;
+    private JComboBox realmComboBox = null;
+    private JPanel passcodePanel = null;
+    private JLabel passcodeLabel = null;
+    private JPasswordField passcodeField = null;
+    private JPanel buttonPanel = null;
+    private JButton loginButton = null;
+    private JButton cancelButton = null;
+    private ConnectionInfoModifier modifier;
+    
+
+    // -----------------------------------------------------------------------
+    // Constructors and main initialization routine
+    // -----------------------------------------------------------------------
+    
+    
+    /**
+     * This is the default constructor
+     */
+    public LoginDialog()
+    {
+        super();
+        modifier = new ConnectionInfoModifier();
+        setModal( true );
+        initialize();
+    }
+
+
+    public LoginDialog( ConnectionInfoModifier modifier )
+    {
+        super();
+        this.modifier = modifier;
+        setModal( true );
+        initialize();
+    }
+
+
+    /**
+     * This method initializes this
+     * 
+     * @return void
+     */
+    private void initialize()
+    {
+        this.setSize( 325, 257 );
+        //this.setPreferredSize( new java.awt.Dimension( 400, 200 ) );
+        this.setTitle( "Login" );
+        this.setContentPane( getMainPanel() );
+    }
+
+    
+    public ConnectionInfo getConnectionInfo()
+    {
+        return modifier.getConnectionInfo();
+    }
+    
+
+    // -----------------------------------------------------------------------
+    // Individual subcomponent intialization methods 
+    // -----------------------------------------------------------------------
+    
+    
+    /**
+     * This method initializes jContentPane
+     * 
+     * @return javax.swing.JPanel
+     */
+    private JPanel getMainPanel()
+    {
+        if ( mainPanel == null )
+        {
+            GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
+            gridBagConstraints11.gridy = 6;
+            gridBagConstraints11.gridwidth = 1;
+            gridBagConstraints11.gridheight = 2;
+            gridBagConstraints11.fill = java.awt.GridBagConstraints.BOTH;
+            gridBagConstraints11.anchor = java.awt.GridBagConstraints.SOUTH;
+            gridBagConstraints11.insets = new java.awt.Insets(12,0,0,0);
+            gridBagConstraints11.gridx = 1;
+            GridBagConstraints gridBagConstraints = new GridBagConstraints();
+            gridBagConstraints.gridx = 1;
+            gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
+            gridBagConstraints.gridwidth = 1;
+            gridBagConstraints.gridheight = 5;
+            gridBagConstraints.gridy = 1;
+            mainPanel = new JPanel();
+            mainPanel.setLayout( new GridBagLayout() );
+            mainPanel.add( getInputPanel(), gridBagConstraints );
+            mainPanel.add(getJPanel15(), gridBagConstraints11);
+        }
+        return mainPanel;
+    }
+
+
+    /**
+     * This method initializes jPanel
+     * 
+     * @return javax.swing.JPanel
+     */
+    private JPanel getInputPanel()
+    {
+        if ( inputPanel == null )
+        {
+            GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
+            gridBagConstraints3.gridy = 3;
+            gridBagConstraints3.gridx = 0;
+            GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
+            gridBagConstraints2.gridy = 2;
+            gridBagConstraints2.gridx = 0;
+            GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
+            gridBagConstraints1.gridx = 0;
+            gridBagConstraints1.gridy = 1;
+            inputPanel = new JPanel();
+            inputPanel.setLayout( new GridBagLayout() );
+            inputPanel.setBorder( javax.swing.BorderFactory.createEtchedBorder( javax.swing.border.EtchedBorder.RAISED ) );
+            inputPanel.add( getJPanel1(), new GridBagConstraints() );
+            inputPanel.add( getJPanel12(), gridBagConstraints1 );
+            inputPanel.add( getJPanel13(), gridBagConstraints2 );
+            inputPanel.add( getJPanel14(), gridBagConstraints3 );
+        }
+        return inputPanel;
+    }
+
+
+    /**
+     * This method initializes jPanel1
+     * 
+     * @return javax.swing.JPanel
+     */
+    private JPanel getJPanel1()
+    {
+        if ( usernamePanel == null )
+        {
+            usernameLabel = new JLabel();
+            usernameLabel.setText( "Username:" );
+            usernamePanel = new JPanel();
+            usernamePanel.add( usernameLabel, null );
+            usernamePanel.add( getUsernameField(), null );
+        }
+        return usernamePanel;
+    }
+
+
+    /**
+     * This method initializes jTextField
+     * 
+     * @return javax.swing.JTextField
+     */
+    private JTextField getUsernameField()
+    {
+        if ( usernameField == null )
+        {
+            usernameField = new JTextField();
+            usernameField.setColumns( 12 );
+            usernameField.setText("");
+        }
+        return usernameField;
+    }
+
+
+    /**
+     * This method initializes jPanel1
+     * 
+     * @return javax.swing.JPanel
+     */
+    private JPanel getJPanel12()
+    {
+        if ( passwordPanel == null )
+        {
+            passwordLabel = new JLabel();
+            passwordLabel.setText( "Password:" );
+            passwordPanel = new JPanel();
+            passwordPanel.add( passwordLabel, null );
+            passwordPanel.add( getPasswordField(), null );
+        }
+        return passwordPanel;
+    }
+
+
+    /**
+     * This method initializes jPasswordField
+     * 
+     * @return javax.swing.JPasswordField
+     */
+    private JPasswordField getPasswordField()
+    {
+        if ( passwordField == null )
+        {
+            passwordField = new JPasswordField();
+            passwordField.setColumns( 12 );
+        }
+        return passwordField;
+    }
+
+
+    /**
+     * This method initializes jPanel1
+     * 
+     * @return javax.swing.JPanel
+     */
+    private JPanel getJPanel13()
+    {
+        if ( realmPanel == null )
+        {
+            realmLabel = new JLabel();
+            realmLabel.setText("    Realm:");
+            realmPanel = new JPanel();
+            realmPanel.add( realmLabel, null );
+            realmPanel.add( getRealmComboBox(), null );
+        }
+        return realmPanel;
+    }
+
+
+    /**
+     * This method initializes jComboBox
+     * 
+     * @return javax.swing.JComboBox
+     */
+    private JComboBox getRealmComboBox()
+    {
+        if ( realmComboBox == null )
+        {
+            realmComboBox = new JComboBox();
+            realmComboBox.setPreferredSize( new java.awt.Dimension( 132, 18 ) );
+            realmComboBox.setEditable( true );
+        }
+        return realmComboBox;
+    }
+
+
+    /**
+     * This method initializes jPanel1
+     * 
+     * @return javax.swing.JPanel
+     */
+    private JPanel getJPanel14()
+    {
+        if ( passcodePanel == null )
+        {
+            passcodeLabel = new JLabel();
+            passcodeLabel.setText( "Passcode:" );
+            passcodePanel = new JPanel();
+            passcodePanel.add( passcodeLabel, null );
+            passcodePanel.add( getPasscodeField(), null );
+        }
+        return passcodePanel;
+    }
+
+
+    /**
+     * This method initializes jPasswordField1
+     * 
+     * @return javax.swing.JPasswordField
+     */
+    private JPasswordField getPasscodeField()
+    {
+        if ( passcodeField == null )
+        {
+            passcodeField = new JPasswordField();
+            passcodeField.setColumns( 12 );
+        }
+        return passcodeField;
+    }
+
+
+    /**
+     * This method initializes jPanel1
+     * 
+     * @return javax.swing.JPanel
+     */
+    private JPanel getJPanel15()
+    {
+        if ( buttonPanel == null )
+        {
+            buttonPanel = new JPanel();
+            buttonPanel.setBorder( javax.swing.BorderFactory.createEtchedBorder( javax.swing.border.EtchedBorder.RAISED ) );
+            buttonPanel.add( getCancelButton(), null );
+            buttonPanel.add( getLoginButton(), null );
+        }
+        return buttonPanel;
+    }
+
+
+    /**
+     * This method initializes jButton
+     * 
+     * @return javax.swing.JButton
+     */
+    private JButton getLoginButton()
+    {
+        if ( loginButton == null )
+        {
+            loginButton = new JButton();
+            loginButton.setText( "Login" );
+            loginButton.addActionListener( new java.awt.event.ActionListener()
+            {
+                public void actionPerformed( java.awt.event.ActionEvent e )
+                {
+                    if ( getPassword() == null || getPassword().length == 0 )
+                    {
+                        JOptionPane.showMessageDialog( LoginDialog.this, 
+                            "Password not supplied.", "Login Failed", JOptionPane.ERROR_MESSAGE );
+                        return;
+                    }
+                    
+                    if ( getUserName() == null || getUserName().length() == 0 )
+                    {
+                        JOptionPane.showMessageDialog( LoginDialog.this, 
+                            "Username not supplied.", "Login Failed", JOptionPane.ERROR_MESSAGE );
+                        return;
+                    }
+                    
+                    if ( getRealm() == null || getRealm().length() == 0 )
+                    {
+                        JOptionPane.showMessageDialog( LoginDialog.this, 
+                            "Realm not supplied.", "Login Failed", JOptionPane.ERROR_MESSAGE );
+                        return;
+                    }
+                    
+                    modifier.setCredentials( new String( getPassword() ) );
+                    modifier.setRealm( getRealm() );
+                    modifier.setPrincipal( getUserName() );
+                    modifier.setPasscode( new String( passcodeField.getPassword() ) );
+                    LoginDialog.this.setVisible( false );
+                    LoginDialog.this.dispose();
+                    canceled = false;
+                }
+            } );
+        }
+        return loginButton;
+    }
+
+
+    /**
+     * This method initializes jButton1
+     * 
+     * @return javax.swing.JButton
+     */
+    private JButton getCancelButton()
+    {
+        if ( cancelButton == null )
+        {
+            cancelButton = new JButton();
+            cancelButton.setText( "Cancel" );
+            cancelButton.addActionListener( new java.awt.event.ActionListener()
+            {
+                public void actionPerformed( java.awt.event.ActionEvent e )
+                {
+                    LoginDialog.this.setVisible( false );
+                    LoginDialog.this.dispose();
+                    canceled = true;
+                }
+            } );
+        }
+        return cancelButton;
+    }
+
+    
+    // -----------------------------------------------------------------------
+    // Value accessors from fields in UI used by login processor
+    // -----------------------------------------------------------------------
+    
+    
+    public String getUserName()
+    {
+        return usernameField.getText();
+    }
+    
+    
+    public char[] getPassword()
+    {
+        return passwordField.getPassword();
+    }
+    
+    
+    public char[] getPasscode()
+    {
+        return passcodeField.getPassword();
+    }
+    
+    
+    public String getRealm()
+    {
+        return ( String ) realmComboBox.getSelectedItem();
+    }
+    
+    
+    boolean canceled = true;
+    public boolean isCanceled()
+    {
+        return canceled;
+    }
+
+} // @jve:decl-index=0:visual-constraint="10,10"

Added: directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/NewApplicationPanel.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/NewApplicationPanel.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/NewApplicationPanel.java (added)
+++ directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/NewApplicationPanel.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,894 @@
+/*
+ *  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 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.ApplicationModifier;
+import org.safehaus.triplesec.admin.DataAccessException;
+import org.safehaus.triplesec.admin.Permission;
+import org.safehaus.triplesec.admin.Profile;
+import org.safehaus.triplesec.admin.ProfileModifier;
+import org.safehaus.triplesec.admin.Role;
+import org.safehaus.triplesec.admin.RoleModifier;
+import org.safehaus.triplesec.admin.TriplesecAdmin;
+import javax.swing.JPasswordField;
+
+
+public class NewApplicationPanel extends JPanel
+{
+    private static final long serialVersionUID = 1L;
+    private JPanel mainPanel = null;
+    private JPanel buttonPanel = null;
+    private JButton copyButton = 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 existingAppsTable = null;
+    private TriplesecAdmin triplesecAdmin;
+    private ExistingApplicationsTableModel existingAppsTableModel = null; //  @jve:decl-index=0:visual-constraint=""
+    private JLabel jLabel = null;
+    private JTextField statusTextField = null;
+    private JLabel jLabel1 = null;
+    private JTextField applicationNameTextField = null;
+    private JLabel jLabel2 = null;
+    private JPanel jPanel1 = null;
+    private JPasswordField applicationPasswordField = null;
+    private JLabel jLabel3 = null;
+    private JPasswordField confirmPasswordField = null;
+
+
+    public void setLeftTreeNavigation( LeftTreeNavigation leftTreeNavigation )
+    {
+        this.leftTreeNavigation = leftTreeNavigation;
+    }
+
+
+    public void setTriplesecAdmin( TriplesecAdmin triplesecAdmin )
+    {
+        this.triplesecAdmin = triplesecAdmin;
+    }
+
+
+    /**
+     * This is the default constructor
+     */
+    public NewApplicationPanel()
+    {
+        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 Application",
+            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( getCopyButton(), null );
+            buttonPanel.add( getCreateButton(), null );
+        }
+        return buttonPanel;
+    }
+
+
+    /**
+     * This method initializes jButton	
+     * 	
+     * @return javax.swing.JButton	
+     */
+    private JButton getCopyButton()
+    {
+        if ( copyButton == null )
+        {
+            copyButton = new JButton();
+            copyButton.setText( "Copy" );
+            copyButton.addActionListener( new java.awt.event.ActionListener()
+            {   
+            	public void actionPerformed(java.awt.event.ActionEvent e) 
+                {
+                    try
+                    {
+                        copyAction();
+                    }
+                    catch ( DataAccessException e1 )
+                    {
+                        String msg = UiUtils.wrap( "Failed to copy application: " + e1.getMessage(), 79 );
+                        JOptionPane.showMessageDialog( NewApplicationPanel.this, msg, 
+                            "Failed to copy application!", JOptionPane.ERROR_MESSAGE );
+                    }
+            	}
+            
+            } );
+        }
+        return copyButton;
+    }
+
+    
+    public void copyAction() throws DataAccessException
+    {
+        String msg = UiUtils.wrap( "This copy operation will persist immediately replicating the entire " +
+                "application subtree.  Would you still like to continue?", 79 ); 
+        int response = JOptionPane.showOptionDialog( this, msg, "Continue?", JOptionPane.YES_NO_OPTION, 
+            JOptionPane.QUESTION_MESSAGE, null, null, null );
+        if ( response == JOptionPane.NO_OPTION )
+        {
+            return;
+        }
+        
+        // -------------------------------------------------------------------
+        // Get ahold of the application and it's node that was to 
+        // be copied with all child entities underneath it
+        // -------------------------------------------------------------------
+        
+        int index = existingAppsTable.getSelectionModel().getAnchorSelectionIndex();
+        if ( existingAppsTableModel.getRowCount() == 0 || index < 0 )
+        {
+            return;
+        }
+        Application copiedApplication = ( Application ) existingAppsTableModel.getValueAt( index, 0 );
+        DefaultMutableTreeNode copiedApplicationNode = null;
+        for ( Enumeration ii = node.children(); ii.hasMoreElements(); /**/ )
+        {
+            DefaultMutableTreeNode child = ( DefaultMutableTreeNode ) ii.nextElement();
+            if ( child.getUserObject() == copiedApplication )
+            {
+                copiedApplicationNode = child;
+            }
+        }
+        
+        // -------------------------------------------------------------------
+        // Now we create the new application and bail if it fails
+        // -------------------------------------------------------------------
+       
+        DefaultMutableTreeNode newApplicationNode = createAction();
+        if ( newApplicationNode == null )
+        {
+            return;
+        }
+        Application newApplication = ( Application ) newApplicationNode.getUserObject();
+
+        // -------------------------------------------------------------------
+        // Iterated and copy app's perms and create in new app
+        // -------------------------------------------------------------------
+        
+        DefaultMutableTreeNode permsNode = null;
+        DefaultMutableTreeNode newPermsNode = null;
+        DefaultTreeModel model = ( DefaultTreeModel ) leftTreeNavigation.getTree().getModel();
+        for ( Enumeration ii = copiedApplicationNode.children(); ii.hasMoreElements(); /**/ )
+        {
+            DefaultMutableTreeNode child = ( DefaultMutableTreeNode ) ii.nextElement();
+            if ( ( ( String ) child.getUserObject() ).equals( "Permissions" ) )
+            {
+                permsNode = child;
+            }
+        }
+        for ( Enumeration ii = newApplicationNode.children(); ii.hasMoreElements(); /**/ )
+        {
+            DefaultMutableTreeNode child = ( DefaultMutableTreeNode ) ii.nextElement();
+            if ( ( ( String ) child.getUserObject() ).equals( "Permissions" ) )
+            {
+                newPermsNode = child;
+            }
+        }
+        for ( Enumeration ii = permsNode.children(); ii.hasMoreElements(); /**/ )
+        {
+            DefaultMutableTreeNode copiedPermissionNode = ( DefaultMutableTreeNode ) ii.nextElement();
+            Permission copiedPermission = ( Permission ) copiedPermissionNode.getUserObject();
+            Permission newPermission = newApplication.modifier()
+                .newPermission( copiedPermission.getName() )
+                .setDescription( copiedPermission.getDescription() ).add();
+            model.insertNodeInto( new DefaultMutableTreeNode( newPermission ), newPermsNode, 0 );
+        }
+        
+        // -------------------------------------------------------------------
+        // Iterate and copy app's roles and create in new app
+        // -------------------------------------------------------------------
+        
+        DefaultMutableTreeNode rolesNode = null;
+        DefaultMutableTreeNode newRolesNode = null;
+        for ( Enumeration ii = copiedApplicationNode.children(); ii.hasMoreElements(); /**/ )
+        {
+            DefaultMutableTreeNode child = ( DefaultMutableTreeNode ) ii.nextElement();
+            if ( ( ( String ) child.getUserObject() ).equals( "Roles" ) )
+            {
+                rolesNode = child;
+            }
+        }
+        for ( Enumeration ii = newApplicationNode.children(); ii.hasMoreElements(); /**/ )
+        {
+            DefaultMutableTreeNode child = ( DefaultMutableTreeNode ) ii.nextElement();
+            if ( ( ( String ) child.getUserObject() ).equals( "Roles" ) )
+            {
+                newRolesNode = child;
+            }
+        }
+        for ( Enumeration ii = rolesNode.children(); ii.hasMoreElements(); /**/ )
+        {
+            DefaultMutableTreeNode copiedRoleNode = ( DefaultMutableTreeNode ) ii.nextElement();
+            Role copiedRole = ( Role ) copiedRoleNode.getUserObject();
+            RoleModifier modifier = newApplication.modifier().newRole( copiedRole.getName() )
+                .setDescription( copiedRole.getDescription() );
+            for ( Iterator jj = copiedRole.getGrants().iterator(); jj.hasNext(); /**/ )
+            {
+                modifier.addGrant( ( String ) jj.next() );
+            }
+            Role newRole = modifier.add();
+            model.insertNodeInto( new DefaultMutableTreeNode( newRole ), newRolesNode, 0 );
+        }
+        
+        // -------------------------------------------------------------------
+        // Iterate and copy app's profiles and create in new app
+        // -------------------------------------------------------------------
+        
+        DefaultMutableTreeNode profilesNode = null;
+        DefaultMutableTreeNode newProfilesNode = null;
+        for ( Enumeration ii = copiedApplicationNode.children(); ii.hasMoreElements(); /**/ )
+        {
+            DefaultMutableTreeNode child = ( DefaultMutableTreeNode ) ii.nextElement();
+            if ( ( ( String ) child.getUserObject() ).equals( "Profiles" ) )
+            {
+                profilesNode = child;
+            }
+        }
+        for ( Enumeration ii = newApplicationNode.children(); ii.hasMoreElements(); /**/ )
+        {
+            DefaultMutableTreeNode child = ( DefaultMutableTreeNode ) ii.nextElement();
+            if ( ( ( String ) child.getUserObject() ).equals( "Profiles" ) )
+            {
+                newProfilesNode = child;
+            }
+        }
+        for ( Enumeration ii = profilesNode.children(); ii.hasMoreElements(); /**/ )
+        {
+            DefaultMutableTreeNode copiedProfileNode = ( DefaultMutableTreeNode ) ii.nextElement();
+            Profile copiedProfile = ( Profile ) copiedProfileNode.getUserObject();
+            ProfileModifier modifier = newApplication.modifier()
+                .newProfile( copiedProfile.getId(), copiedProfile.getUser() )
+                .setDescription( copiedProfile.getDescription() );
+            for ( Iterator jj = copiedProfile.getGrants().iterator(); jj.hasNext(); /**/ )
+            {
+                modifier.addGrant( ( String ) jj.next() );
+            }
+            for ( Iterator jj = copiedProfile.getDenials().iterator(); jj.hasNext(); /**/ )
+            {
+                modifier.addDenial( ( String ) jj.next() );
+            }
+            for ( Iterator jj = copiedProfile.getRoles().iterator(); jj.hasNext(); /**/ )
+            {
+                modifier.addRole( ( String ) jj.next() );
+            }
+            Profile newProfile = modifier.add();
+            model.insertNodeInto( new DefaultMutableTreeNode( newProfile ), newProfilesNode, 0 );
+        }
+        
+        applicationNameTextField.setText( null );
+        statusTextField.setText( null );
+    }
+    
+
+    /**
+     * 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_application_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.gridx = 1;
+            gridBagConstraints8.insets = new java.awt.Insets(0,0,0,0);
+            gridBagConstraints8.fill = java.awt.GridBagConstraints.BOTH;
+            gridBagConstraints8.gridy = 2;
+            GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
+            gridBagConstraints7.gridx = 0;
+            gridBagConstraints7.fill = java.awt.GridBagConstraints.HORIZONTAL;
+            gridBagConstraints7.insets = new java.awt.Insets(0,0,0,5);
+            gridBagConstraints7.gridy = 2;
+            jLabel2 = new JLabel();
+            jLabel2.setText("Password:");
+            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 = 1;
+            gridBagConstraints5.weightx = 1.0;
+            gridBagConstraints5.insets = new java.awt.Insets(0,0,5,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,5,5);
+            gridBagConstraints3.gridy = 1;
+            jLabel1 = new JLabel();
+            jLabel1.setText( "Application 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(getApplicationNameTextField(), gridBagConstraints5);
+            jPanel.add(jLabel2, gridBagConstraints7);
+            jPanel.add(getJPanel1(), 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;
+        existingAppsTable.setModel( new ExistingApplicationsTableModel() );
+    }
+
+
+    public String noNull( Object obj )
+    {
+        if ( obj == null )
+        {
+            return "";
+        }
+        return obj.toString();
+    }
+
+
+    public DefaultMutableTreeNode getTreeNode()
+    {
+        return node;
+    }
+
+
+    public DefaultMutableTreeNode createAction()
+    {
+        char[] passwordChars = applicationPasswordField.getPassword();
+        char[] confirmChars = confirmPasswordField.getPassword();
+        
+        if ( passwordChars == null || confirmChars == null )
+        {
+            JOptionPane.showMessageDialog( this, "Either the password or the confirmation field is null." );
+            return null;
+        }
+        
+        String passwordStr = new String( passwordChars );
+        String confirmStr = new String( confirmChars );
+        
+        if ( ! passwordStr.equals( confirmStr ) )
+        {
+            JOptionPane.showMessageDialog( this, "Passwords do not match." );
+            return null;
+        }
+        
+        DefaultMutableTreeNode appNode;
+        Application application;
+        ApplicationModifier modifier = triplesecAdmin.newApplication( applicationNameTextField.getText() )
+            .setDescription( descriptionTextArea.getText() ).setPassword( passwordStr );
+        try
+        {
+            application = modifier.add();
+            appNode = new DefaultMutableTreeNode( application );
+            DefaultTreeModel model = ( DefaultTreeModel ) leftTreeNavigation.getTree().getModel();
+            model.insertNodeInto( appNode, node, 0 );
+            leftTreeNavigation.reloadApplication( appNode );
+            leftTreeNavigation.reloadGroups();
+            existingAppsTableModel.fireTableDataChanged();
+        }
+        catch ( DataAccessException e )
+        {
+            JOptionPane.showMessageDialog( this,
+                UiUtils.wrap( "Failed to create application:\n" + e.getMessage(), 79 ),
+                "Application creation failure!", JOptionPane.ERROR_MESSAGE );
+            return null;
+        }
+        applicationNameTextField.setText( null );
+        statusTextField.setText( null );
+        return appNode;
+    }
+
+
+    /**
+     * This method initializes jTabbedPane	
+     * 	
+     * @return javax.swing.JTabbedPane	
+     */
+    private JTabbedPane getCenterTabbedPane()
+    {
+        if ( centerTabbedPane == null )
+        {
+            centerTabbedPane = new JTabbedPane();
+            centerTabbedPane.addTab( "Existing", null, getExistingPanelTab(),
+                "Copy an application from any one of these existing applications." );
+        }
+        return centerTabbedPane;
+    }
+
+
+    /**
+     * 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( getExistingAppsTable() );
+        }
+        return jScrollPane;
+    }
+
+
+    /**
+     * This method initializes jTable	
+     * 	
+     * @return javax.swing.JTable	
+     */
+    private JTable getExistingAppsTable()
+    {
+        if ( existingAppsTable == null )
+        {
+            existingAppsTable = new JTable();
+            existingAppsTable.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
+            existingAppsTable.getSelectionModel().addListSelectionListener( new ListSelectionListener()
+            {
+                public void valueChanged( ListSelectionEvent e )
+                {
+                    int index = existingAppsTable.getSelectionModel().getAnchorSelectionIndex();
+                    if ( existingAppsTableModel.getRowCount() == 0 || index < 0 )
+                    {
+                        return;
+                    }
+                    Application application = ( Application ) existingAppsTableModel.getValueAt( index, 0 );
+                    applicationNameTextField.setText( "CopyOf" + application.getName() );
+                    descriptionTextArea.setText( application.getDescription() );
+                }
+            } );
+            existingAppsTable.setModel( getExistingAppsTableModel() );
+        }
+        return existingAppsTable;
+    }
+
+
+    /**
+     * This method initializes defaultTableModel	
+     * 	
+     * @return javax.swing.table.DefaultTableModel	
+     */
+    private ExistingApplicationsTableModel getExistingAppsTableModel()
+    {
+        if ( existingAppsTableModel == null )
+        {
+            existingAppsTableModel = new ExistingApplicationsTableModel();
+        }
+        return existingAppsTableModel;
+    }
+
+    class ExistingApplicationsTableModel 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 ( ( Application ) child.getUserObject() ).getCreatorsName();
+                case ( 2 ):
+                    return ( ( Application ) child.getUserObject() ).getCreateTimestamp().toString();
+            }
+            return child.getUserObject();
+        }
+
+    
+        public String getColumnName( int columnIndex )
+        {
+            switch ( columnIndex )
+            {
+                case ( 0 ):
+                    return "Existing Application";
+                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 getApplicationNameTextField()
+    {
+        if ( applicationNameTextField == null )
+        {
+            applicationNameTextField = new JTextField();
+        }
+        return applicationNameTextField;
+    }
+
+
+    /**
+     * This method initializes jPanel1	
+     * 	
+     * @return javax.swing.JPanel	
+     */
+    private JPanel getJPanel1()
+    {
+        if ( jPanel1 == null )
+        {
+            GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
+            gridBagConstraints11.insets = new java.awt.Insets(0,5,0,5);
+            GridBagConstraints gridBagConstraints10 = new GridBagConstraints();
+            gridBagConstraints10.fill = java.awt.GridBagConstraints.HORIZONTAL;
+            gridBagConstraints10.weightx = 1.0;
+            jLabel3 = new JLabel();
+            jLabel3.setText("Confirm");
+            GridBagConstraints gridBagConstraints9 = new GridBagConstraints();
+            gridBagConstraints9.fill = java.awt.GridBagConstraints.HORIZONTAL;
+            gridBagConstraints9.gridy = 0;
+            gridBagConstraints9.weightx = 1.0;
+            gridBagConstraints9.gridx = 0;
+            jPanel1 = new JPanel();
+            jPanel1.setLayout(new GridBagLayout());
+            jPanel1.add(getApplicationPasswordField(), gridBagConstraints9);
+            jPanel1.add(jLabel3, gridBagConstraints11);
+            jPanel1.add(getConfirmPasswordField(), gridBagConstraints10);
+        }
+        return jPanel1;
+    }
+
+
+    /**
+     * This method initializes jPasswordField	
+     * 	
+     * @return javax.swing.JPasswordField	
+     */
+    private JPasswordField getApplicationPasswordField()
+    {
+        if ( applicationPasswordField == null )
+        {
+            applicationPasswordField = new JPasswordField();
+        }
+        return applicationPasswordField;
+    }
+
+
+    /**
+     * This method initializes jPasswordField1	
+     * 	
+     * @return javax.swing.JPasswordField	
+     */
+    private JPasswordField getConfirmPasswordField()
+    {
+        if ( confirmPasswordField == null )
+        {
+            confirmPasswordField = new JPasswordField();
+        }
+        return confirmPasswordField;
+    }
+} //  @jve:decl-index=0:visual-constraint="10,10"



Mime
View raw message