You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by tb...@apache.org on 2006/12/12 16:24:14 UTC
svn commit: r486187 [26/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...
Added: directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/AdminFrame.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/AdminFrame.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/AdminFrame.java (added)
+++ directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/AdminFrame.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,1298 @@
+/*
+ * 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 javax.security.auth.login.LoginException;
+import javax.swing.Icon;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JFrame;
+import javax.swing.JMenuBar;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+import javax.swing.JToolBar;
+import javax.swing.JButton;
+import javax.swing.JSplitPane;
+import javax.swing.JLabel;
+
+import java.awt.GridLayout;
+import java.awt.CardLayout;
+
+import javax.swing.ImageIcon;
+import javax.swing.border.EtchedBorder;
+import javax.swing.event.TreeSelectionEvent;
+import javax.swing.event.TreeSelectionListener;
+import javax.swing.tree.DefaultMutableTreeNode;
+
+import org.safehaus.triplesec.TriplesecInstallationLayout;
+import org.safehaus.triplesec.admin.Application;
+import org.safehaus.triplesec.admin.Group;
+import org.safehaus.triplesec.admin.Permission;
+import org.safehaus.triplesec.admin.Profile;
+import org.safehaus.triplesec.admin.Role;
+import org.safehaus.triplesec.admin.User;
+import org.safehaus.triplesec.guardian.ApplicationPolicy;
+import org.safehaus.triplesec.guardian.ApplicationPolicyFactory;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.awt.event.KeyEvent;
+import java.io.File;
+import java.io.IOException;
+import java.util.Properties;
+
+
+/**
+ * The main administration swing UI frame.
+ *
+ * @author <a href="mailto:akarasulu@safehaus.org">Alex Karasulu</a>
+ * @version $Rev$
+ */
+public class AdminFrame extends JFrame implements TreeSelectionListener
+{
+ private static final long serialVersionUID = -150826562775754154L;
+
+ private static final Logger log = LoggerFactory.getLogger( AdminFrame.class );
+
+ private JPanel mainPane = null;
+ private JMenuBar mainMenuBar = null;
+ private JMenu fileMenu = null;
+ private JMenuItem openMenuItem = null;
+ private JMenuItem closeMenuItem = null;
+ private JMenuItem saveMenuItem = null;
+ private JMenuItem exitMenuItem = null;
+ private JToolBar mainToolBar = null;
+ private JButton openToolbarButton = null;
+ private JButton closeToolbarButton = null;
+ private JButton saveToolbarButton = null;
+ private JPanel statusPanel = null;
+ private JPanel mainPanel = null;
+ private JSplitPane jSplitPane = null;
+ private JLabel statusLabel = null;
+ private JPanel rightDetailPanel = null;
+ private LeftTreeNavigation leftNavigation = null;
+ private ConnectionManager connectionManager = null;
+ private ConfigurationFileManager configurationFileManager = null;
+ private CardLayout rightDetailPanelLayout;
+ private TriplesecInstallationLayout layout;
+ private JMenuItem connectMenuItem = null;
+ private JMenuItem disconnectMenuItem = null;
+ private JButton connectButton = null;
+ private JButton disconnectButton = null;
+ private JMenu connectionMenu = null;
+ private JPanel emptyPanel = null;
+ private PermissionPanel permissionPanel = null;
+ private RolePanel rolePanel;
+ private UserPanel userPanel;
+ private ProfilePanel profilePanel;
+ private ApplicationPanel applicationPanel;
+ private NewApplicationPanel newApplicationPanel;
+ private GroupPanel groupPanel;
+ private NewGroupPanel newGroupPanel;
+ private NewUserPanel newUserPanel;
+ private NewPermissionPanel newPermissionPanel;
+ private NewRolePanel newRolePanel;
+ private NewProfilePanel newProfilePanel;
+ private JMenu settingsMenu = null;
+ private JMenuItem editSettingsMenuItem = null;
+ private AdminToolSettings settings = null;
+
+ private JMenuItem loadSettingsMenuItem = null;
+
+
+ /**
+ * This is the default constructor
+ */
+ public AdminFrame()
+ {
+ super();
+// SplashScreen splashScreen = new SplashScreen( "splashscreen.png", this, 500 );
+// splashScreen.setVisible( true );
+ initialize();
+ applicationPanel.setLeftTreeNavigation( leftNavigation );
+ configurationFileManager = new ConfigurationFileManager( this );
+ connectionManager = new ConnectionManager();
+ connectionManager.addObserver( leftNavigation );
+ }
+
+
+ public AdminToolSettings getSettings()
+ {
+ return settings;
+ }
+
+
+ public ConnectionManager getConnectionManager()
+ {
+ return connectionManager;
+ }
+
+
+ public ConfigurationFileManager getConfigurationFileManager()
+ {
+ return configurationFileManager;
+ }
+
+
+ /**
+ * This method initializes this
+ *
+ * @return void
+ */
+ private void initialize()
+ {
+ this.setSize(940, 560);
+ this.setJMenuBar( getMainMenuBar() );
+ this.setContentPane( getMainPane() );
+ this.setTitle( "Triplesec Administration Tool" );
+ this.addWindowListener( new java.awt.event.WindowAdapter()
+ {
+ public void windowClosing( java.awt.event.WindowEvent e )
+ {
+ AdminFrame.this.setVisible( false );
+ AdminFrame.this.dispose();
+ System.exit( 0 );
+ }
+ } );
+ }
+
+
+ /**
+ * This method initializes jContentPane
+ *
+ * @return javax.swing.JPanel
+ */
+ private JPanel getMainPane()
+ {
+ if ( mainPane == null )
+ {
+ mainPane = new JPanel();
+ mainPane.setLayout( new BorderLayout() );
+ mainPane.add( getMainToolBar(), java.awt.BorderLayout.NORTH );
+ mainPane.add( getStatusPanel(), java.awt.BorderLayout.SOUTH );
+ mainPane.add( getMainPanel(), java.awt.BorderLayout.CENTER );
+ }
+ return mainPane;
+ }
+
+
+ /**
+ * This method initializes jJMenuBar
+ *
+ * @return javax.swing.JMenuBar
+ */
+ private JMenuBar getMainMenuBar()
+ {
+ if ( mainMenuBar == null )
+ {
+ mainMenuBar = new JMenuBar();
+ mainMenuBar.add( getFileMenu() );
+ mainMenuBar.add(getConnectionMenu());
+ mainMenuBar.add(getSettingsMenu());
+ }
+ return mainMenuBar;
+ }
+
+
+ /**
+ * This method initializes jMenu
+ *
+ * @return javax.swing.JMenu
+ */
+ private JMenu getFileMenu()
+ {
+ if ( fileMenu == null )
+ {
+ fileMenu = new JMenu();
+ fileMenu.setText( "File" );
+ fileMenu.setMnemonic( java.awt.event.KeyEvent.VK_F );
+ fileMenu.add( getOpenMenuItem() );
+ fileMenu.add( getCloseMenuItem() );
+ fileMenu.add( getSaveMenuItem() );
+ fileMenu.add( getExitMenuItem() );
+ }
+ return fileMenu;
+ }
+
+
+ /**
+ * This method initializes jMenuItem
+ *
+ * @return javax.swing.JMenuItem
+ */
+ private JMenuItem getOpenMenuItem()
+ {
+ if ( openMenuItem == null )
+ {
+ openMenuItem = new JMenuItem();
+ openMenuItem.setText( "Open" );
+ openMenuItem.setMnemonic( java.awt.event.KeyEvent.VK_O );
+ openMenuItem.setToolTipText( "Open Triplesec Configuration File" );
+ openMenuItem.addActionListener( new java.awt.event.ActionListener()
+ {
+ public void actionPerformed( java.awt.event.ActionEvent e )
+ {
+ openActionTaken();
+ }
+ } );
+ }
+ return openMenuItem;
+ }
+
+
+ /**
+ * This method initializes jMenuItem
+ *
+ * @return javax.swing.JMenuItem
+ */
+ private JMenuItem getCloseMenuItem()
+ {
+ if ( closeMenuItem == null )
+ {
+ closeMenuItem = new JMenuItem();
+ closeMenuItem.setText( "Close" );
+ closeMenuItem.setMnemonic( java.awt.event.KeyEvent.VK_C );
+ closeMenuItem.setToolTipText( "Close Triplesec Configuration File" );
+ }
+ return closeMenuItem;
+ }
+
+
+ /**
+ * This method initializes jMenuItem
+ *
+ * @return javax.swing.JMenuItem
+ */
+ private JMenuItem getSaveMenuItem()
+ {
+ if ( saveMenuItem == null )
+ {
+ saveMenuItem = new JMenuItem();
+ saveMenuItem.setText( "Save" );
+ saveMenuItem.setMnemonic( java.awt.event.KeyEvent.VK_S );
+ saveMenuItem.setToolTipText( "Save Triplesec Configuration File" );
+ }
+ return saveMenuItem;
+ }
+
+
+ /**
+ * This method initializes jMenuItem
+ *
+ * @return javax.swing.JMenuItem
+ */
+ private JMenuItem getExitMenuItem()
+ {
+ if ( exitMenuItem == null )
+ {
+ exitMenuItem = new JMenuItem();
+ exitMenuItem.setText( "Exit" );
+ exitMenuItem.setMnemonic( java.awt.event.KeyEvent.VK_X );
+ exitMenuItem.addActionListener( new java.awt.event.ActionListener()
+ {
+ public void actionPerformed( java.awt.event.ActionEvent e )
+ {
+ log.info( "Application exited." );
+ AdminFrame.this.setVisible( false );
+ AdminFrame.this.dispose();
+ System.exit( 0 );
+ }
+ } );
+ }
+ return exitMenuItem;
+ }
+
+
+ /**
+ * This method initializes jJToolBarBar
+ *
+ * @return javax.swing.JToolBar
+ */
+ private JToolBar getMainToolBar()
+ {
+ if ( mainToolBar == null )
+ {
+ mainToolBar = new JToolBar();
+ mainToolBar.add( getOpenToolbarButton() );
+ mainToolBar.add( getCloseToolbarButton() );
+ mainToolBar.add( getSaveToolbarButton() );
+ mainToolBar.add( getConnectButton() );
+ mainToolBar.add( getDisconnectButton() );
+ }
+ return mainToolBar;
+ }
+
+
+ /**
+ * This method initializes jButton
+ *
+ * @return javax.swing.JButton
+ */
+ private JButton getOpenToolbarButton()
+ {
+ if ( openToolbarButton == null )
+ {
+ openToolbarButton = new JButton();
+ openToolbarButton.setIcon( new ImageIcon( getClass().getResource(
+ "/org/safehaus/triplesec/admin/swing/fileopen_22x22.png" ) ) );
+ openToolbarButton.setBorder( new EtchedBorder() );
+ openToolbarButton.addActionListener( new java.awt.event.ActionListener()
+ {
+ public void actionPerformed( java.awt.event.ActionEvent e )
+ {
+ openActionTaken();
+ }
+ } );
+ }
+ return openToolbarButton;
+ }
+
+
+ /**
+ * This method initializes jButton1
+ *
+ * @return javax.swing.JButton
+ */
+ private JButton getCloseToolbarButton()
+ {
+ if ( closeToolbarButton == null )
+ {
+ closeToolbarButton = new JButton();
+ closeToolbarButton.setIcon( new ImageIcon( getClass().getResource(
+ "/org/safehaus/triplesec/admin/swing/fileclose_22x22.png" ) ) );
+ closeToolbarButton.setBorder( new EtchedBorder() );
+ }
+ return closeToolbarButton;
+ }
+
+
+ /**
+ * This method initializes jButton2
+ *
+ * @return javax.swing.JButton
+ */
+ private JButton getSaveToolbarButton()
+ {
+ if ( saveToolbarButton == null )
+ {
+ saveToolbarButton = new JButton();
+ saveToolbarButton.setIcon( new ImageIcon( getClass().getResource(
+ "/org/safehaus/triplesec/admin/swing/filesave_22x22.png" ) ) );
+ saveToolbarButton.setToolTipText( "Save Triplesec Configuration File" );
+ saveToolbarButton.setBorder( new EtchedBorder() );
+ }
+ return saveToolbarButton;
+ }
+
+
+ /**
+ * This method initializes jPanel
+ *
+ * @return javax.swing.JPanel
+ */
+ private JPanel getStatusPanel()
+ {
+ if ( statusPanel == null )
+ {
+ statusLabel = new JLabel();
+ statusLabel.setText( " Status: ok" );
+ statusLabel.setIcon( new ImageIcon( getClass().getResource(
+ "/org/safehaus/triplesec/admin/swing/status_ok_16x16.png" ) ) );
+ statusLabel.setPreferredSize( new java.awt.Dimension( 38, 19 ) );
+ statusPanel = new JPanel();
+ statusPanel.setLayout( new BorderLayout() );
+ statusPanel.add( statusLabel, java.awt.BorderLayout.NORTH );
+ }
+ return statusPanel;
+ }
+
+
+ /**
+ * This method initializes jPanel
+ *
+ * @return javax.swing.JPanel
+ */
+ private JPanel getMainPanel()
+ {
+ if ( mainPanel == null )
+ {
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.setRows( 1 );
+ mainPanel = new JPanel();
+ mainPanel.setLayout( gridLayout );
+ mainPanel.setBorder( javax.swing.BorderFactory.createBevelBorder( javax.swing.border.BevelBorder.LOWERED ) );
+ mainPanel.add( getJSplitPane(), null );
+ }
+ return mainPanel;
+ }
+
+
+ /**
+ * This method initializes jSplitPane
+ *
+ * @return javax.swing.JSplitPane
+ */
+ private JSplitPane getJSplitPane()
+ {
+ if ( jSplitPane == null )
+ {
+ jSplitPane = new JSplitPane();
+ jSplitPane.setDividerSize(6);
+ jSplitPane.setOneTouchExpandable(true);
+ jSplitPane.setRightComponent( getRightPanel() );
+ jSplitPane.setLeftComponent( getLeftNavigation() );
+ leftNavigation.addTreeSelectionListener( this );
+ jSplitPane.setDividerLocation(250);
+ }
+ return jSplitPane;
+ }
+
+
+ private LeftTreeNavigation getLeftNavigation()
+ {
+ if ( leftNavigation == null )
+ {
+ leftNavigation = new LeftTreeNavigation();
+ leftNavigation.setPreferredSize(new java.awt.Dimension(250,323));
+ leftNavigation.setRightDetailPanel( rightDetailPanel );
+ }
+ return leftNavigation;
+ }
+
+
+ /**
+ * This method initializes jPanel
+ *
+ * @return javax.swing.JPanel
+ */
+ private JPanel getRightPanel()
+ {
+ if ( rightDetailPanel == null )
+ {
+ rightDetailPanel = new JPanel();
+ rightDetailPanelLayout = new CardLayout();
+ rightDetailPanel.setLayout( rightDetailPanelLayout );
+ rightDetailPanel.add( getEmptyPanel(), getEmptyPanel().getName() );
+ rightDetailPanel.add( getPermissionPanel(), getPermissionPanel().getName() );
+ rightDetailPanel.add( getRolePanel(), getRolePanel().getName() );
+ rightDetailPanel.add( getProfilePanel(), getProfilePanel().getName() );
+ rightDetailPanel.add( getApplicationPanel(), getApplicationPanel().getName() );
+ rightDetailPanel.add( getGroupPanel(), getGroupPanel().getName() );
+ rightDetailPanel.add( getUserPanel(), getUserPanel().getName() );
+ rightDetailPanel.add( getNewApplicationPanel(), getNewApplicationPanel().getName() );
+ rightDetailPanel.add( getNewGroupPanel(), getNewGroupPanel().getName() );
+ rightDetailPanel.add( getNewUserPanel(), getNewUserPanel().getName() );
+ rightDetailPanel.add( getNewPermissionPanel(), getNewPermissionPanel().getName() );
+ rightDetailPanel.add( getNewRolePanel(), getNewRolePanel().getName() );
+ rightDetailPanel.add( getNewProfilePanel(), getNewProfilePanel().getName() );
+ }
+ return rightDetailPanel;
+ }
+
+
+ public void setInstallationLayout( TriplesecInstallationLayout layout )
+ {
+ this.layout = layout;
+ }
+
+
+ /**
+ * This method initializes jMenuItem
+ *
+ * @return javax.swing.JMenuItem
+ */
+ private JMenuItem getConnectMenuItem()
+ {
+ if ( connectMenuItem == null )
+ {
+ connectMenuItem = new JMenuItem();
+ connectMenuItem.setToolTipText( "Connect to Triplesec Server" );
+ connectMenuItem.setText( "Connect" );
+ connectMenuItem.setMnemonic(java.awt.event.KeyEvent.VK_C);
+ connectMenuItem.addActionListener( new java.awt.event.ActionListener()
+ {
+ public void actionPerformed( java.awt.event.ActionEvent e )
+ {
+ connectActionTaken();
+ }
+ } );
+ }
+ return connectMenuItem;
+ }
+
+
+ /**
+ * This method initializes jMenuItem1
+ *
+ * @return javax.swing.JMenuItem
+ */
+ private JMenuItem getDisconnectMenuItem()
+ {
+ if ( disconnectMenuItem == null )
+ {
+ disconnectMenuItem = new JMenuItem();
+ disconnectMenuItem.setToolTipText( "Disconnect from Triplesec Server" );
+ disconnectMenuItem.setText( "Disconnect" );
+ disconnectMenuItem.setMnemonic( KeyEvent.VK_D );
+ disconnectMenuItem.addActionListener( new java.awt.event.ActionListener()
+ {
+ public void actionPerformed( java.awt.event.ActionEvent e )
+ {
+ performDisconnect();
+ }
+ } );
+ }
+ return disconnectMenuItem;
+ }
+
+
+ private void performDisconnect()
+ {
+ if ( !connectionManager.isConnected() )
+ {
+ JOptionPane.showMessageDialog( this , "Triplesec Admin has already disconnected.",
+ "Already Disconnected", JOptionPane.INFORMATION_MESSAGE );
+ return;
+ }
+ boolean isDisconnected = connectionManager.disconnect();
+ if ( ! isDisconnected )
+ {
+ JOptionPane.showMessageDialog( this , connectionManager.getLastFailure().getMessage(),
+ "Disconnect Failure", JOptionPane.ERROR_MESSAGE );
+ }
+ rightDetailPanelLayout.show( rightDetailPanel, "emptyPanel" );
+ settings = null;
+ configurationFileManager.clear();
+ }
+
+
+ /**
+ * This method initializes jButton
+ *
+ * @return javax.swing.JButton
+ */
+ private JButton getConnectButton()
+ {
+ if ( connectButton == null )
+ {
+ connectButton = new JButton();
+ connectButton.setBorder( new EtchedBorder() );
+ connectButton.setIcon( new ImageIcon( getClass().getResource(
+ "/org/safehaus/triplesec/admin/swing/connect_22x22.png" ) ) );
+ connectButton.setToolTipText( "Connect to Triplesec Server" );
+ connectButton.addActionListener( new java.awt.event.ActionListener()
+ {
+ public void actionPerformed( java.awt.event.ActionEvent e )
+ {
+ connectActionTaken();
+ }
+ } );
+ }
+ return connectButton;
+ }
+
+
+ /**
+ * This method initializes jButton
+ *
+ * @return javax.swing.JButton
+ */
+ private JButton getDisconnectButton()
+ {
+ if ( disconnectButton == null )
+ {
+ disconnectButton = new JButton();
+ disconnectButton.setBorder( new EtchedBorder() );
+ disconnectButton.setIcon( new ImageIcon( getClass().getResource(
+ "/org/safehaus/triplesec/admin/swing/disconnect_22x22.png" ) ) );
+ disconnectButton.setToolTipText( "Disconnect from Triplesec Server" );
+ disconnectButton.addActionListener( new java.awt.event.ActionListener()
+ {
+ public void actionPerformed( java.awt.event.ActionEvent e )
+ {
+ performDisconnect();
+ }
+ } );
+ }
+ return disconnectButton;
+ }
+
+
+ /**
+ * This method initializes jMenu
+ *
+ * @return javax.swing.JMenu
+ */
+ private JMenu getConnectionMenu()
+ {
+ if ( connectionMenu == null )
+ {
+ connectionMenu = new JMenu();
+ connectionMenu.setText("Connection");
+ connectionMenu.setMnemonic(java.awt.event.KeyEvent.VK_C);
+ connectionMenu.add(getConnectMenuItem());
+ connectionMenu.add(getDisconnectMenuItem());
+ }
+ return connectionMenu;
+ }
+
+
+ /**
+ * This method initializes jPanel
+ *
+ * @return javax.swing.JPanel
+ */
+ private JPanel getEmptyPanel()
+ {
+ if ( emptyPanel == null )
+ {
+ emptyPanel = new JPanel();
+ emptyPanel.setName("emptyPanel");
+ }
+ return emptyPanel;
+ }
+
+
+ /**
+ * This method initializes jPanel
+ *
+ * @return javax.swing.JPanel
+ */
+ private PermissionPanel getPermissionPanel()
+ {
+ if ( permissionPanel == null )
+ {
+ permissionPanel = new PermissionPanel();
+ permissionPanel.setName( "permissionPanel" );
+ }
+ return permissionPanel;
+ }
+
+
+ /**
+ * This method initializes jPanel
+ *
+ * @return javax.swing.JPanel
+ */
+ private RolePanel getRolePanel()
+ {
+ if ( rolePanel == null )
+ {
+ rolePanel = new RolePanel();
+ rolePanel.setName( "rolePanel" );
+ }
+ return rolePanel;
+ }
+
+
+ /**
+ * This method initializes jPanel
+ *
+ * @return javax.swing.JPanel
+ */
+ private ProfilePanel getProfilePanel()
+ {
+ if ( profilePanel == null )
+ {
+ profilePanel = new ProfilePanel();
+ profilePanel.setName( "profilePanel" );
+ }
+ return profilePanel;
+ }
+
+
+ /**
+ * This method initializes jPanel
+ *
+ * @return javax.swing.JPanel
+ */
+ private ApplicationPanel getApplicationPanel()
+ {
+ if ( applicationPanel == null )
+ {
+ applicationPanel = new ApplicationPanel();
+ applicationPanel.setName( "applicationPanel" );
+ }
+ return applicationPanel;
+ }
+
+
+ /**
+ * This method initializes jPanel
+ *
+ * @return javax.swing.JPanel
+ */
+ private GroupPanel getGroupPanel()
+ {
+ if ( groupPanel == null )
+ {
+ groupPanel = new GroupPanel();
+ groupPanel.setName( "groupPanel" );
+ }
+ return groupPanel;
+ }
+
+
+ /**
+ * This method initializes jPanel
+ *
+ * @return javax.swing.JPanel
+ */
+ private UserPanel getUserPanel()
+ {
+ if ( userPanel == null )
+ {
+ userPanel = new UserPanel();
+ userPanel.setAdminFrame( this );
+ userPanel.setName( "userPanel" );
+ }
+ return userPanel;
+ }
+
+
+ /**
+ * This method initializes jPanel
+ *
+ * @return javax.swing.JPanel
+ */
+ private NewApplicationPanel getNewApplicationPanel()
+ {
+ if ( newApplicationPanel == null )
+ {
+ newApplicationPanel = new NewApplicationPanel();
+ newApplicationPanel.setName( "newApplicationPanel" );
+ }
+ return newApplicationPanel;
+ }
+
+
+ /**
+ * This method initializes jPanel
+ *
+ * @return javax.swing.JPanel
+ */
+ private NewGroupPanel getNewGroupPanel()
+ {
+ if ( newGroupPanel == null )
+ {
+ newGroupPanel = new NewGroupPanel();
+ newGroupPanel.setName( "newGroupPanel" );
+ }
+ return newGroupPanel;
+ }
+
+
+ /**
+ * This method initializes jPanel
+ *
+ * @return javax.swing.JPanel
+ */
+ private NewUserPanel getNewUserPanel()
+ {
+ if ( newUserPanel == null )
+ {
+ newUserPanel = new NewUserPanel();
+ newUserPanel.setName( "newUserPanel" );
+ }
+ return newUserPanel;
+ }
+
+
+ /**
+ * This method initializes jPanel
+ *
+ * @return javax.swing.JPanel
+ */
+ private NewPermissionPanel getNewPermissionPanel()
+ {
+ if ( newPermissionPanel == null )
+ {
+ newPermissionPanel = new NewPermissionPanel();
+ newPermissionPanel.setName( "newPermissionPanel" );
+ }
+ return newPermissionPanel;
+ }
+
+
+ /**
+ * This method initializes jPanel
+ *
+ * @return javax.swing.JPanel
+ */
+ private NewRolePanel getNewRolePanel()
+ {
+ if ( newRolePanel == null )
+ {
+ newRolePanel = new NewRolePanel();
+ newRolePanel.setName( "newRolePanel" );
+ }
+ return newRolePanel;
+ }
+
+
+ /**
+ * This method initializes jPanel
+ *
+ * @return javax.swing.JPanel
+ */
+ private NewProfilePanel getNewProfilePanel()
+ {
+ if ( newProfilePanel == null )
+ {
+ newProfilePanel = new NewProfilePanel();
+ newProfilePanel.setName( "newProfilePanel" );
+ }
+ return newProfilePanel;
+ }
+
+
+ public void setStatusMessage( String msg, Icon icon )
+ {
+ statusLabel.setText( " Status: " + msg );
+ statusLabel.setIcon( icon );
+ }
+
+
+ private boolean doConnectDialogs()
+ {
+ if ( SettingsUtils.isAvailableSettings() && settings == null )
+ {
+ String msg = "You have encrypted settings stored on disk. \nWould you like to use these settings?" +
+ "\nCancel to use smart defaults.";
+ int response = JOptionPane.showConfirmDialog( this, msg, "Use Discovered Settings?",
+ JOptionPane.YES_NO_OPTION );
+
+ if ( response == JOptionPane.YES_OPTION )
+ {
+ int count = 0;
+ String passphrase = null;
+ while ( ( passphrase = UiUtils.showPasswordDialog( this, "Enter passphrase for encrypted settings." ) ).length() == 0 )
+ {
+ count++;
+ if ( count == 3 )
+ {
+ JOptionPane.showMessageDialog( this, "You just can't seem to get it right - I'm aborting!" );
+ return false;
+ }
+ JOptionPane.showMessageDialog( this, "Invalid passphrase try again." );
+ }
+
+ try
+ {
+ settings = SettingsUtils.load( passphrase );
+ }
+ catch ( IOException e )
+ {
+ return false;
+ }
+ }
+ }
+
+ // -------------------------------------------------------------------
+ // Acquire Connection Info and AdminTool app's Guardian Password
+ // -------------------------------------------------------------------
+
+ ConnectionInfo connectionInfo = null;
+ String adminToolPassword = null;
+ if ( settings != null )
+ {
+ ConnectionInfoModifier modifier = new ConnectionInfoModifier( settings.getDefaultConnectionInfo() );
+ adminToolPassword = settings.getAdminToolPassword();
+ String passcode = UiUtils.showPasswordDialog( this, "If user "
+ + modifier.getConnectionInfo().getPrincipal() +
+ " requires a passcode generate and enter it now. Otherwise just continue ... " );
+ if ( passcode != null && passcode.length() > 0 )
+ {
+ modifier.setPasscode( passcode );
+ }
+ connectionInfo = modifier.getConnectionInfo();
+ }
+ else
+ {
+ ConnectionDialog connectionDialog = new ConnectionDialog();
+ connectionDialog.setModal( true );
+ connectionDialog.setLocation( UiUtils.getCenteredPosition( connectionDialog ) );
+ connectionDialog.setVisible( true );
+ if ( connectionDialog.isCanceled() )
+ {
+ return false;
+ }
+
+ ConnectionInfoModifier modifier = connectionDialog.getConnectionModifier();
+ LoginDialog loginDialog = new LoginDialog( modifier );
+ loginDialog.setModal( true );
+ loginDialog.setLocation( UiUtils.getCenteredPosition( connectionDialog ) );
+ loginDialog.setVisible( true );
+ if ( loginDialog.isCanceled() )
+ {
+ return false;
+ }
+
+ connectionInfo = modifier.getConnectionInfo();
+
+ int count = 0;
+ while ( ( adminToolPassword = UiUtils.showPasswordDialog( this, "Enter adminTool's guardian password." ) ).length() == 0 )
+ {
+ count++;
+ if ( count == 3 )
+ {
+ JOptionPane.showMessageDialog( this, "You just can't seem to get it right - I'm aborting!" );
+ return false;
+ }
+ JOptionPane.showMessageDialog( this, "Invalid guardian password for adminTool try again." );
+ }
+ }
+
+ try
+ {
+ // -------------------------------------------------------------------
+ // Need to connect to the server via guardian first
+ // -------------------------------------------------------------------
+
+ Properties props = new Properties();
+ StringBuffer buf = new StringBuffer();
+ buf.append( "appName=tsecAdminTool,ou=Applications," ).append( connectionInfo.getLdapRealmBase() );
+ props.setProperty( "applicationPrincipalDN", buf.toString() );
+ props.setProperty( "applicationCredentials", adminToolPassword );
+
+ try
+ {
+ Class.forName( "org.safehaus.triplesec.guardian.ldap.LdapConnectionDriver" );
+ }
+ catch ( ClassNotFoundException e1 )
+ {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ buf.setLength( 0 );
+ buf.append( "ldap://" ).append( connectionInfo.getHost() ).append( ":" )
+ .append( connectionInfo.getLdapPort() ).append( "/" ).append( connectionInfo.getLdapRealmBase() );
+ ApplicationPolicy policy =
+ ApplicationPolicyFactory.newInstance( buf.toString(), props );
+ return connectionManager.connect( connectionInfo, policy );
+ }
+ catch ( LoginException t )
+ {
+ log.error( "Authentication Failed", t );
+ JOptionPane.showMessageDialog( this, UiUtils.wrap( t.getMessage(), 79 ), "Connection Failed",
+ JOptionPane.ERROR_MESSAGE );
+ return false;
+ }
+ }
+
+
+ private void connectActionTaken()
+ {
+ if ( connectionManager.isConnected() )
+ {
+ JOptionPane.showMessageDialog( this, "Triplesec Admin is already connected.",
+ "Already Connected", JOptionPane.INFORMATION_MESSAGE );
+ return;
+ }
+
+ boolean isConnected = false;
+ if ( configurationFileManager.isConfigurationLoaded() )
+ {
+ isConnected = connectionManager.connect( configurationFileManager.getConfiguration(),
+ configurationFileManager.getEnvironment() );
+ }
+ else
+ {
+ isConnected = doConnectDialogs();
+ }
+
+ if ( ! isConnected )
+ {
+ if ( connectionManager.getLastFailure() == null )
+ {
+ return;
+ }
+ String msg = UiUtils.wrap( connectionManager.getLastFailure().getMessage(), 79 );
+ JOptionPane.showMessageDialog( this, msg,
+ "Connection Failed", JOptionPane.ERROR_MESSAGE );
+ }
+ else
+ {
+ JOptionPane.showMessageDialog( this, "Connected and authenticated successfully.",
+ "Success", JOptionPane.INFORMATION_MESSAGE );
+ }
+
+ newApplicationPanel.setTriplesecAdmin( connectionManager.getTriplesecAdmin() );
+ newGroupPanel.setTriplesecAdmin( connectionManager.getTriplesecAdmin() );
+ newUserPanel.setTriplesecAdmin( connectionManager.getTriplesecAdmin() );
+ }
+
+
+ public void connect( ConnectionInfo connectInfo, ApplicationPolicy policy ) throws LoginException
+ {
+ connectionManager.connect( connectInfo, policy );
+ newApplicationPanel.setTriplesecAdmin( connectionManager.getTriplesecAdmin() );
+ newGroupPanel.setTriplesecAdmin( connectionManager.getTriplesecAdmin() );
+ newUserPanel.setTriplesecAdmin( connectionManager.getTriplesecAdmin() );
+ }
+
+
+ public void openActionTaken()
+ {
+ if ( layout == null )
+ {
+ configurationFileManager.prompt( new File( System.getProperty( "user.home" ) ) );
+ }
+ else
+ {
+ configurationFileManager.prompt( this.layout.getBootstrapperConfigurationFile() );
+ }
+ }
+
+
+ public void valueChanged( TreeSelectionEvent e )
+ {
+ if ( ! connectionManager.isConnected() )
+ {
+ return;
+ }
+ DefaultMutableTreeNode node = ( DefaultMutableTreeNode ) e.getPath().getLastPathComponent();
+ if ( node == null )
+ {
+ rightDetailPanelLayout.show( rightDetailPanel, "emptyPanel" );
+ return;
+ }
+
+ Object obj = node.getUserObject();
+ if ( obj instanceof Permission )
+ {
+ permissionPanel.setTreeNode( node );
+ permissionPanel.setTree( leftNavigation.getTree() );
+ rightDetailPanelLayout.show( rightDetailPanel, "permissionPanel" );
+ }
+ else if ( obj instanceof Role )
+ {
+ rolePanel.setTreeNode( node );
+ rolePanel.setTree( leftNavigation.getTree() );
+ rightDetailPanelLayout.show( rightDetailPanel, "rolePanel" );
+ }
+ else if ( obj instanceof Profile )
+ {
+ profilePanel.setTreeNode( node );
+ profilePanel.setTree( leftNavigation.getTree() );
+ rightDetailPanelLayout.show( rightDetailPanel, "profilePanel" );
+ }
+ else if ( obj instanceof Application )
+ {
+ applicationPanel.setTreeNode( node );
+ applicationPanel.setTree( leftNavigation.getTree() );
+ rightDetailPanelLayout.show( rightDetailPanel, "applicationPanel" );
+ }
+ else if ( obj instanceof Group )
+ {
+ groupPanel.setTreeNode( node );
+ groupPanel.setTree( leftNavigation.getTree() );
+ rightDetailPanelLayout.show( rightDetailPanel, "groupPanel" );
+ }
+ else if ( obj instanceof User )
+ {
+ userPanel.setTreeNode( node );
+ userPanel.setTree( leftNavigation.getTree() );
+ rightDetailPanelLayout.show( rightDetailPanel, "userPanel" );
+ }
+ else if ( obj instanceof String )
+ {
+ if ( ( ( String ) obj ).equalsIgnoreCase( "Applications" ) )
+ {
+ newApplicationPanel.setTreeNode( node );
+ newApplicationPanel.setLeftTreeNavigation( leftNavigation );
+ rightDetailPanelLayout.show( rightDetailPanel, "newApplicationPanel" );
+ }
+ else if ( ( ( String ) obj ).equalsIgnoreCase( "Groups" ) )
+ {
+ newGroupPanel.setTreeNode( node );
+ newGroupPanel.setLeftTreeNavigation( leftNavigation );
+ rightDetailPanelLayout.show( rightDetailPanel, "newGroupPanel" );
+ }
+ else if ( ( ( String ) obj ).equalsIgnoreCase( "Users" ) )
+ {
+ newUserPanel.setTreeNode( node );
+ newUserPanel.setLeftTreeNavigation( leftNavigation );
+ rightDetailPanelLayout.show( rightDetailPanel, "newUserPanel" );
+ }
+ else if ( ( ( String ) obj ).equalsIgnoreCase( "Permissions" ) )
+ {
+ newPermissionPanel.setTreeNode( node );
+ newPermissionPanel.setLeftTreeNavigation( leftNavigation );
+ rightDetailPanelLayout.show( rightDetailPanel, "newPermissionPanel" );
+ }
+ else if ( ( ( String ) obj ).equalsIgnoreCase( "Roles" ) )
+ {
+ newRolePanel.setTreeNode( node );
+ newRolePanel.setLeftTreeNavigation( leftNavigation );
+ rightDetailPanelLayout.show( rightDetailPanel, "newRolePanel" );
+ }
+ else if ( ( ( String ) obj ).equalsIgnoreCase( "Profiles" ) )
+ {
+ newProfilePanel.setTreeNode( node );
+ newProfilePanel.setLeftTreeNavigation( leftNavigation );
+ rightDetailPanelLayout.show( rightDetailPanel, "newProfilePanel" );
+ }
+ else
+ {
+ rightDetailPanelLayout.show( rightDetailPanel, "emptyPanel" );
+ }
+ }
+ else
+ {
+ rightDetailPanelLayout.show( rightDetailPanel, "emptyPanel" );
+ }
+ }
+
+
+ /**
+ * This method initializes jMenu
+ *
+ * @return javax.swing.JMenu
+ */
+ private JMenu getSettingsMenu()
+ {
+ if ( settingsMenu == null )
+ {
+ settingsMenu = new JMenu();
+ settingsMenu.setText("Settings");
+ settingsMenu.setMnemonic(java.awt.event.KeyEvent.VK_S);
+ settingsMenu.add(getLoadSettingsMenuItem());
+ settingsMenu.add(getEditSettingsMenuItem());
+ }
+ return settingsMenu;
+ }
+
+
+ /**
+ * This method initializes jMenuItem
+ *
+ * @return javax.swing.JMenuItem
+ */
+ private JMenuItem getEditSettingsMenuItem()
+ {
+ if ( editSettingsMenuItem == null )
+ {
+ editSettingsMenuItem = new JMenuItem();
+ editSettingsMenuItem.setText("Edit");
+ editSettingsMenuItem.setMnemonic(java.awt.event.KeyEvent.VK_E);
+ editSettingsMenuItem.addActionListener( new java.awt.event.ActionListener()
+ {
+ public void actionPerformed(java.awt.event.ActionEvent e) {
+ if ( SettingsUtils.isAvailableSettings() && settings == null )
+ {
+ String passphrase = UiUtils.showPasswordDialog( AdminFrame.this,
+ "Enter passphrase to decrypt settings." );
+ try
+ {
+ settings = SettingsUtils.load( passphrase );
+ }
+ catch ( IOException e1 )
+ {
+ String msg = UiUtils.wrap( "Could load settings file: " + e1.getMessage(), 79 );
+ JOptionPane.showMessageDialog( AdminFrame.this, msg, "Load Failure!", JOptionPane.ERROR_MESSAGE );
+ return;
+ }
+ }
+
+ SettingsEditor editor = new SettingsEditor();
+ editor.setSettings( settings );
+ editor.setVisible( true );
+ }
+ } );
+ }
+ return editSettingsMenuItem;
+ }
+
+
+ public boolean doLoadSettings()
+ {
+ if ( ! SettingsUtils.isAvailableSettings() )
+ {
+ String msg = UiUtils.wrap( "No default settings file found for "
+ + System.getProperty( "user.name" ) + ". You can use Settings->Edit instead and save " +
+ "your settings after replying no to this dialog. Or select yes to import " +
+ "another non-default settings file." , 79 );
+ int response = JOptionPane.showConfirmDialog( AdminFrame.this, msg, "Import Settings File?",
+ JOptionPane.YES_NO_OPTION );
+
+ if ( response == JOptionPane.YES_OPTION )
+ {
+ // TODO add yes handling for importing non-default settings file
+ }
+ return false;
+ }
+
+ String passphrase = UiUtils.showPasswordDialog( AdminFrame.this,
+ "Enter passphrase to decrypt settings." );
+ try
+ {
+ settings = SettingsUtils.load( passphrase );
+ }
+ catch ( IOException e1 )
+ {
+ String msg = UiUtils.wrap( "Could load settings file: " + e1.getMessage(), 79 );
+ JOptionPane.showMessageDialog( AdminFrame.this, msg, "Load Failure!", JOptionPane.ERROR_MESSAGE );
+ }
+
+ return true;
+ }
+
+
+ /**
+ * This method initializes jMenuItem
+ *
+ * @return javax.swing.JMenuItem
+ */
+ private JMenuItem getLoadSettingsMenuItem()
+ {
+ if ( loadSettingsMenuItem == null )
+ {
+ loadSettingsMenuItem = new JMenuItem();
+ loadSettingsMenuItem.setText("Load");
+ loadSettingsMenuItem.setMnemonic(java.awt.event.KeyEvent.VK_L);
+ loadSettingsMenuItem.addActionListener( new java.awt.event.ActionListener()
+ {
+ public void actionPerformed( java.awt.event.ActionEvent e )
+ {
+ doLoadSettings();
+ }
+ } );
+ }
+ return loadSettingsMenuItem;
+ }
+
+
+ public static void main( String[] args )
+ {
+ AdminFrame frame = new AdminFrame();
+ if ( args.length > 0 )
+ {
+ frame.setInstallationLayout( new TriplesecInstallationLayout( args[0] ) );
+ }
+ frame.setLocation( UiUtils.getCenteredPosition( frame ) );
+ frame.setVisible( true );
+ }
+
+
+} // @jve:decl-index=0:visual-constraint="10,10"
Added: directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/AdminToolSettings.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/AdminToolSettings.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/AdminToolSettings.java (added)
+++ directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/AdminToolSettings.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,120 @@
+/*
+ * 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 org.safehaus.triplesec.configuration.SmsConfiguration;
+import org.safehaus.triplesec.configuration.SmtpConfiguration;
+
+
+public class AdminToolSettings
+{
+ private SmsConfiguration defaultSmsConfig;
+ private SmtpConfiguration defaultSmtpConfig;
+ private String adminToolPassword;
+ private ConnectionInfo defaultConnectionInfo;
+ private String settingsPassphrase;
+ private boolean passcodePromptEnabled = true;
+ private String presentationBaseUrl;
+
+
+ public void setDefaultSmsConfig( SmsConfiguration defaultSmsConfig )
+ {
+ this.defaultSmsConfig = defaultSmsConfig;
+ }
+
+
+ public SmsConfiguration getDefaultSmsConfig()
+ {
+ return defaultSmsConfig;
+ }
+
+
+ public void setDefaultSmtpConfig( SmtpConfiguration defaultSmtpConfig )
+ {
+ this.defaultSmtpConfig = defaultSmtpConfig;
+ }
+
+
+ public SmtpConfiguration getDefaultSmtpConfig()
+ {
+ return defaultSmtpConfig;
+ }
+
+
+ public void setAdminToolPassword( String adminToolPassword )
+ {
+ this.adminToolPassword = adminToolPassword;
+ }
+
+
+ public String getAdminToolPassword()
+ {
+ return adminToolPassword;
+ }
+
+
+ public void setDefaultConnectionInfo( ConnectionInfo defaultConnectionInfo )
+ {
+ this.defaultConnectionInfo = defaultConnectionInfo;
+ }
+
+
+ public ConnectionInfo getDefaultConnectionInfo()
+ {
+ return defaultConnectionInfo;
+ }
+
+
+ public void setSettingsPassphrase( String settingsPassphrase )
+ {
+ this.settingsPassphrase = settingsPassphrase;
+ }
+
+
+ public String getSettingsPassphrase()
+ {
+ return settingsPassphrase;
+ }
+
+
+ public boolean isPasscodePromptEnabled()
+ {
+ return passcodePromptEnabled;
+ }
+
+
+ public void setPasscodePromptEnabled( boolean passcodePromptEnabled )
+ {
+ this.passcodePromptEnabled = passcodePromptEnabled;
+ }
+
+
+ public void setPresentationBaseUrl( String presentationBaseUrl )
+ {
+ this.presentationBaseUrl = presentationBaseUrl;
+ }
+
+
+ public String getPresentationBaseUrl()
+ {
+ return presentationBaseUrl;
+ }
+}
Added: directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/ApplicationPanel.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/ApplicationPanel.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/ApplicationPanel.java (added)
+++ directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/ApplicationPanel.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,647 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.safehaus.triplesec.admin.swing;
+
+
+import javax.swing.JPanel;
+import java.awt.BorderLayout;
+
+import javax.swing.ImageIcon;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JTabbedPane;
+import javax.swing.JButton;
+import javax.swing.JTree;
+
+import java.awt.GridBagLayout;
+import java.awt.GridBagConstraints;
+import javax.swing.JTextField;
+import javax.swing.JTextArea;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeModel;
+import javax.swing.tree.TreePath;
+
+import org.safehaus.triplesec.admin.Application;
+import org.safehaus.triplesec.admin.ApplicationModifier;
+import org.safehaus.triplesec.admin.DataAccessException;
+import javax.swing.JPasswordField;
+
+
+public class ApplicationPanel 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 Application application = null;
+ private JTree tree = null;
+ private DefaultMutableTreeNode node = null;
+ private LeftTreeNavigation leftTreeNavigation;
+ private JLabel jLabel = null;
+ private JTextField statusTextField = null;
+ private JLabel jLabel1 = null;
+ private JTextField applicationNameTextField = null;
+ private JButton deleteButton = 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;
+ }
+
+
+ /**
+ * This is the default constructor
+ */
+ public ApplicationPanel()
+ {
+ 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 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(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 )
+ {
+ setApplicationFields();
+ }
+ } );
+ }
+ 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, getGeneralPanelTab(), 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 JPanel getGeneralPanelTab()
+ {
+ if ( generalPanel == null )
+ {
+ generalPanel = new GeneralPanel();
+ }
+ return generalPanel;
+ }
+
+
+ /**
+ * This method initializes iconLabel
+ *
+ * @return javax.swing.JLabel
+ */
+ private JLabel getIconLabel()
+ {
+ if ( iconLabel == null )
+ {
+ iconLabel = new JLabel();
+ iconLabel.setIcon( new ImageIcon( getClass().getResource(
+ "/org/safehaus/triplesec/admin/swing/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.fill = java.awt.GridBagConstraints.BOTH;
+ gridBagConstraints8.insets = new java.awt.Insets(0,0,0,5);
+ gridBagConstraints8.gridy = 2;
+ GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
+ gridBagConstraints7.fill = java.awt.GridBagConstraints.HORIZONTAL;
+ gridBagConstraints7.gridy = 2;
+ gridBagConstraints7.weightx = 1.0;
+ gridBagConstraints7.insets = new java.awt.Insets(0,0,0,5);
+ gridBagConstraints7.gridx = 1;
+ GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
+ gridBagConstraints6.gridx = 0;
+ gridBagConstraints6.fill = java.awt.GridBagConstraints.HORIZONTAL;
+ gridBagConstraints6.insets = new java.awt.Insets(0,0,0,5);
+ gridBagConstraints6.gridy = 2;
+ jLabel2 = new JLabel();
+ jLabel2.setText("Password:");
+ jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
+ GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
+ gridBagConstraints5.fill = java.awt.GridBagConstraints.HORIZONTAL;
+ gridBagConstraints5.gridy = 1;
+ gridBagConstraints5.weightx = 1.0;
+ gridBagConstraints5.insets = new java.awt.Insets(0,0,5,5);
+ gridBagConstraints5.gridx = 1;
+ GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
+ gridBagConstraints4.gridx = 0;
+ gridBagConstraints4.insets = new java.awt.Insets(0,0,5,5);
+ gridBagConstraints4.fill = java.awt.GridBagConstraints.HORIZONTAL;
+ gridBagConstraints4.gridy = 1;
+ jLabel1 = new JLabel();
+ jLabel1.setText( "Application Name:" );
+ jLabel1.setHorizontalAlignment( javax.swing.SwingConstants.RIGHT );
+ GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
+ gridBagConstraints3.fill = java.awt.GridBagConstraints.HORIZONTAL;
+ gridBagConstraints3.gridy = 0;
+ gridBagConstraints3.weightx = 1.0;
+ gridBagConstraints3.insets = new java.awt.Insets( 0, 0, 5, 5 );
+ gridBagConstraints3.gridx = 1;
+ GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
+ gridBagConstraints2.insets = new java.awt.Insets( 0, 0, 5, 5 );
+ gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
+ jLabel = new JLabel();
+ jLabel.setText( "Status:" );
+ jLabel.setHorizontalAlignment( javax.swing.SwingConstants.RIGHT );
+ jPanel = new JPanel();
+ jPanel.setLayout( new GridBagLayout() );
+ jPanel.setPreferredSize( new java.awt.Dimension( 131, 88 ) );
+ jPanel.add( jLabel, gridBagConstraints2 );
+ jPanel.add( getStatusTextField(), gridBagConstraints3 );
+ jPanel.add(jLabel1, gridBagConstraints4);
+ jPanel.add(getApplicationNameTextField(), gridBagConstraints5);
+ jPanel.add(jLabel2, gridBagConstraints6);
+ 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 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 setApplicationFields()
+ {
+ generalPanel.setFields( application );
+ applicationNameTextField.setText( application.getName() );
+ applicationPasswordField.setText( application.getPassword() );
+ confirmPasswordField.setText( application.getPassword() );
+ descriptionTextArea.setText( application.getDescription() );
+ }
+
+
+ public void setTree( JTree tree )
+ {
+ this.tree = tree;
+ }
+
+
+ public void setTreeNode( DefaultMutableTreeNode node )
+ {
+ this.node = node;
+ this.application = ( Application ) node.getUserObject();
+ setApplicationFields();
+ }
+
+
+ public String noNull( Object obj )
+ {
+ if ( obj == null )
+ {
+ return "";
+ }
+ return obj.toString();
+ }
+
+
+ public DefaultMutableTreeNode getTreeNode()
+ {
+ return node;
+ }
+
+
+ public void saveAction()
+ {
+ 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;
+ }
+
+ String passwordStr = new String( passwordChars );
+ String confirmStr = new String( confirmChars );
+
+ if ( ! passwordStr.equals( confirmStr ) )
+ {
+ JOptionPane.showMessageDialog( this, "Passwords do not match." );
+ return;
+ }
+
+ ApplicationModifier modifier = application.modifier()
+ .setDescription( descriptionTextArea.getText() )
+ .setPassword( passwordStr );
+ if ( modifier.isUpdateNeeded() )
+ {
+ try
+ {
+ application = modifier.modify();
+ }
+ catch ( DataAccessException e )
+ {
+ JOptionPane.showMessageDialog( this, UiUtils.wrap( "Failed to modify application:\n" + e.getMessage(),
+ 79 ), "Application modification failure!", JOptionPane.ERROR_MESSAGE );
+ return;
+ }
+ node.setUserObject( application );
+ }
+
+ if ( !application.getName().equals( applicationNameTextField.getText() ) )
+ {
+ try
+ {
+ application = application.modifier().rename( applicationNameTextField.getText() );
+ ( ( DefaultTreeModel ) tree.getModel() ).valueForPathChanged( new TreePath( node.getPath() ),
+ application );
+ leftTreeNavigation.reloadApplication( this.node );
+ }
+ catch ( DataAccessException e )
+ {
+ JOptionPane.showMessageDialog( this, UiUtils.wrap( "Failed to rename application:\n" + e.getMessage(),
+ 79 ), "Application rename failure!", JOptionPane.ERROR_MESSAGE );
+ return;
+ }
+ }
+
+ node.setUserObject( application );
+ setApplicationFields();
+ }
+
+
+ /**
+ * 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();
+ }
+ 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
+ {
+ application.modifier().delete();
+ DefaultMutableTreeNode parentNode = ( DefaultMutableTreeNode ) node.getParent();
+ DefaultTreeModel treeModel = ( DefaultTreeModel ) tree.getModel();
+ treeModel.removeNodeFromParent( node );
+ leftTreeNavigation.reloadGroups();
+ TreePath path = new TreePath( parentNode.getPath() );
+ tree.setSelectionPaths( new TreePath[] { path } );
+ }
+ catch ( DataAccessException e1 )
+ {
+ JOptionPane.showMessageDialog( ApplicationPanel.this,
+ "Failed to delete application: " + e1.getMessage(), "Delete Failed",
+ JOptionPane.ERROR_MESSAGE );
+ }
+ }
+ } );
+ }
+ return deleteButton;
+ }
+
+
+ /**
+ * This method initializes jPanel1
+ *
+ * @return javax.swing.JPanel
+ */
+ private JPanel getJPanel1()
+ {
+ if ( jPanel1 == null )
+ {
+ GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
+ gridBagConstraints11.fill = java.awt.GridBagConstraints.HORIZONTAL;
+ gridBagConstraints11.weightx = 1.0;
+ GridBagConstraints gridBagConstraints10 = new GridBagConstraints();
+ gridBagConstraints10.insets = new java.awt.Insets(0,5,0,5);
+ 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, gridBagConstraints10);
+ jPanel1.add(getConfirmPasswordField(), gridBagConstraints11);
+ }
+ 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"
Added: directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/Carrier.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/Carrier.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/Carrier.java (added)
+++ directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/Carrier.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,91 @@
+/*
+ * 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;
+
+
+public class Carrier
+{
+ public static final Carrier ATT = new Carrier( "AT&T", 31001 );
+ public static final Carrier CINGULAR = new Carrier( "Cingular", 31002 );
+ public static final Carrier VERIZON = new Carrier( "Verizon", 31003 );
+ public static final Carrier T_MOBILE = new Carrier( "T-Mobile", 31004 );
+ public static final Carrier SPRINT = new Carrier( "Sprint", 31005 );
+ public static final Carrier NEXTEL = new Carrier( "Nextel", 31007 );
+ public static final Carrier[] CARRIERS = { ATT, CINGULAR, VERIZON, T_MOBILE, SPRINT, NEXTEL };
+
+ private final String name;
+ private final int value;
+
+
+ private Carrier( String name, int value )
+ {
+ this.name = name;
+ this.value = value;
+ }
+
+
+ public String getName()
+ {
+ return name;
+ }
+
+
+ public int getValue()
+ {
+ return value;
+ }
+
+
+ public String toString()
+ {
+ return name;
+ }
+
+
+ public static Carrier getCarrier( String name )
+ {
+ if ( name.equalsIgnoreCase( ATT.getName() ) )
+ {
+ return ATT;
+ }
+ if ( name.equalsIgnoreCase( CINGULAR.getName() ) )
+ {
+ return CINGULAR;
+ }
+ if ( name.equalsIgnoreCase( VERIZON.getName() ) )
+ {
+ return VERIZON;
+ }
+ if ( name.equalsIgnoreCase( T_MOBILE.getName() ) )
+ {
+ return T_MOBILE;
+ }
+ if ( name.equalsIgnoreCase( SPRINT.getName() ) )
+ {
+ return SPRINT;
+ }
+ if ( name.equalsIgnoreCase( NEXTEL.getName() ) )
+ {
+ return NEXTEL;
+ }
+
+ throw new IllegalStateException( "Unknown carrier name: " + name );
+ }
+}
Added: directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/ConfigurationFileManager.java
URL: http://svn.apache.org/viewvc/directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/ConfigurationFileManager.java?view=auto&rev=486187
==============================================================================
--- directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/ConfigurationFileManager.java (added)
+++ directory/trunks/triplesec/swing-admin/src/main/java/org/safehaus/triplesec/admin/swing/ConfigurationFileManager.java Tue Dec 12 07:23:31 2006
@@ -0,0 +1,324 @@
+/*
+ * 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.Cursor;
+import java.awt.Dimension;
+import java.io.File;
+import java.io.IOException;
+import java.util.Properties;
+
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JFileChooser;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JProgressBar;
+import javax.swing.filechooser.FileFilter;
+
+import org.safehaus.triplesec.TriplesecInstallationLayout;
+import org.safehaus.triplesec.configuration.MutableTriplesecStartupConfiguration;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.FileSystemXmlApplicationContext;
+
+
+/**
+ *
+ *
+ */
+public class ConfigurationFileManager
+{
+ private static final Logger log = LoggerFactory.getLogger( ConfigurationFileManager.class );
+ private TriplesecInstallationLayout layout;
+ private MutableTriplesecStartupConfiguration configuration;
+ private Properties env;
+ private boolean isLoading = false;
+ private AdminFrame adminFrame;
+
+
+ public ConfigurationFileManager( AdminFrame adminFrame )
+ {
+ this.adminFrame = adminFrame;
+ }
+
+
+ public boolean prompt( File selectedFile )
+ {
+ if ( isConfigurationLoaded() )
+ {
+ int response = JOptionPane.showConfirmDialog( adminFrame, "Abort loaded configuration "
+ + layout.getBaseDirectory().getAbsolutePath() + "?" );
+ switch ( response )
+ {
+ case ( JOptionPane.NO_OPTION ):
+ case ( JOptionPane.CANCEL_OPTION ):
+ return false;
+ }
+ }
+
+ log.info( "Prompting for configuration file selection." );
+ JFileChooser fileChooser = new JFileChooser();
+ fileChooser.setDialogTitle( "Open Triplesec Configuration File" );
+ fileChooser.setLocation( UiUtils.getCenteredPosition( fileChooser ) );
+ fileChooser.setFileFilter( new FileFilter()
+ {
+ public boolean accept( File f )
+ {
+ return f.getAbsolutePath().endsWith( "server.xml" );
+ }
+
+
+ public String getDescription()
+ {
+ return "Triplesec Server Configuration File";
+ }
+ } );
+ if ( selectedFile != null )
+ {
+ fileChooser.setSelectedFile( selectedFile );
+ }
+
+ int returnValue = fileChooser.showOpenDialog( this.adminFrame );
+ if ( returnValue == JFileChooser.APPROVE_OPTION )
+ {
+ log.info( "Opening file: " + fileChooser.getSelectedFile().getAbsolutePath() );
+ layout = new TriplesecInstallationLayout( fileChooser.getSelectedFile().getParentFile().getParentFile() );
+ isLoading = true;
+ LoadProgress progress = new LoadProgress();
+ progress.setLocation( UiUtils.getCenteredPosition( progress ) );
+ progress.setVisible( true );
+ Thread progressThread = new Thread( progress );
+ progressThread.start();
+
+ Loader loader = new Loader();
+ Thread loaderThread = new Thread( loader );
+ loaderThread.start();
+ return true;
+ }
+ return false;
+ }
+
+
+ public void save() throws IOException
+ {
+ throw new RuntimeException( "Not implemented yet" );
+ }
+
+
+ public void clear()
+ {
+ layout = null;
+ configuration = null;
+ env = null;
+ }
+
+
+ public boolean isConfigurationLoaded()
+ {
+ return configuration != null && env != null;
+ }
+
+
+ public MutableTriplesecStartupConfiguration getConfiguration()
+ {
+ return configuration;
+ }
+
+
+ public Properties getEnvironment()
+ {
+ return env;
+ }
+
+
+ public TriplesecInstallationLayout getLayout()
+ {
+ return layout;
+ }
+
+ public class Loader implements Runnable
+ {
+ public void run()
+ {
+ try
+ {
+ isLoading = true;
+ adminFrame.setStatusMessage( "Opening " + layout.getConfigurationFile(), new ImageIcon( getClass()
+ .getResource( "/org/safehaus/triplesec/admin/swing/fileopen_16x16.png" ) ) );
+ ApplicationContext factory = new FileSystemXmlApplicationContext( layout.getConfigurationFile().toURL()
+ .toString() );
+ configuration = ( MutableTriplesecStartupConfiguration ) factory.getBean( "configuration" );
+ env = ( Properties ) factory.getBean( "environment" );
+ isLoading = false;
+ adminFrame.setStatusMessage( "ok", new ImageIcon( getClass().getResource(
+ "/org/safehaus/triplesec/admin/swing/status_ok_16x16.png" ) ) );
+ }
+ catch ( Exception e )
+ {
+ isLoading = false;
+ String msg = "Failed to open " + layout.getConfigurationFile();
+ adminFrame.setStatusMessage( msg, new ImageIcon( getClass().getResource(
+ "/org/safehaus/triplesec/admin/swing/error_16x16.png" ) ) );
+ log.error( msg, e );
+ JOptionPane.showMessageDialog( adminFrame, msg, "Failed to load.", JOptionPane.ERROR_MESSAGE );
+ }
+ }
+ }
+
+ public class LoadProgress extends JDialog implements Runnable
+ {
+ private static final long serialVersionUID = 1L;
+ private JPanel jContentPane = null;
+ private JPanel jPanel = null;
+ private JButton jButton = null;
+ private JProgressBar jProgressBar = null;
+ private boolean bypass = false;
+
+
+ public void run()
+ {
+ setCursor( Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR ) );
+ jProgressBar.setEnabled( true );
+ jProgressBar.setMinimum( 0 );
+ jProgressBar.setMaximum( 10 );
+ jProgressBar.setPreferredSize( new Dimension( 100, 10 ) );
+ jProgressBar.setIndeterminate( true );
+ while ( !bypass && isLoading )
+ {
+ try
+ {
+ Thread.sleep( 50 );
+ }
+ catch ( InterruptedException e )
+ {
+ e.printStackTrace();
+ }
+ jProgressBar.setValue( jProgressBar.getValue() + 2 );
+ this.repaint();
+ }
+
+ setCursor( null );
+ setVisible( false );
+ dispose();
+ }
+
+
+ /**
+ * This is the default constructor
+ */
+ public LoadProgress()
+ {
+ super();
+ initialize();
+ }
+
+
+ /**
+ * This method initializes this
+ *
+ * @return void
+ */
+ private void initialize()
+ {
+ this.setSize( 300, 104 );
+ this.setContentPane( getJContentPane() );
+ }
+
+
+ /**
+ * This method initializes jContentPane
+ *
+ * @return javax.swing.JPanel
+ */
+ private JPanel getJContentPane()
+ {
+ if ( jContentPane == null )
+ {
+ jContentPane = new JPanel();
+ jContentPane.setLayout( new BorderLayout() );
+ jContentPane.add( getJPanel(), java.awt.BorderLayout.SOUTH );
+ jContentPane.add( getJProgressBar(), java.awt.BorderLayout.CENTER );
+ }
+ return jContentPane;
+ }
+
+
+ /**
+ * This method initializes jPanel
+ *
+ * @return javax.swing.JPanel
+ */
+ private JPanel getJPanel()
+ {
+ if ( jPanel == null )
+ {
+ jPanel = new JPanel();
+ jPanel.add( getJButton(), null );
+ }
+ return jPanel;
+ }
+
+
+ /**
+ * This method initializes jButton
+ *
+ * @return javax.swing.JButton
+ */
+ private JButton getJButton()
+ {
+ if ( jButton == null )
+ {
+ jButton = new JButton();
+ jButton.setText( "Close" );
+ jButton.addActionListener( new java.awt.event.ActionListener()
+ {
+ public void actionPerformed( java.awt.event.ActionEvent e )
+ {
+ bypass = true;
+ }
+ } );
+ }
+ return jButton;
+ }
+
+
+ /**
+ * This method initializes jProgressBar
+ *
+ * @return javax.swing.JProgressBar
+ */
+ private JProgressBar getJProgressBar()
+ {
+ if ( jProgressBar == null )
+ {
+ jProgressBar = new JProgressBar();
+ }
+ return jProgressBar;
+ }
+
+ } // @jve:decl-index=0:visual-constraint="10,10"
+}