harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From odea...@apache.org
Subject svn commit: r682413 - in /harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool: control/ model/ view/
Date Mon, 04 Aug 2008 14:57:13 GMT
Author: odeakin
Date: Mon Aug  4 07:57:13 2008
New Revision: 682413

URL: http://svn.apache.org/viewvc?rev=682413&view=rev
Log:
Apply patch for HARMONY-5927 (Progress on policytool)

Modified:
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/Controller.java
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/Permission.java
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/Principal.java
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/BaseFormDialog.java
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/GrantEntryEditFormDialog.java
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/GraphicalEditorPanel.java
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/KeystoreEntryEditFormDialog.java
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/ListAndEditPanel.java
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/PrincipalEditFormDialog.java

Modified: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/Controller.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/Controller.java?rev=682413&r1=682412&r2=682413&view=diff
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/Controller.java
(original)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/Controller.java
Mon Aug  4 07:57:13 2008
@@ -104,7 +104,7 @@
      * This method checks whether there are unsaved changes, and if so, ask confirmation
on what to do with them.<br>
      * Finally returns true, if the dirty data can be thrown away or has been saved successfully.
      * Returns false, if the effect of the operation (throwing away unsaved changes) is unwanted
and therefore the operation is disallowed.
-     *
+     * 
      * @param operationName name of the operation which will be included in the confirmation
messages
      * @return true, if the operation now can be performed safely; false otherwise
      */
@@ -163,7 +163,7 @@
      */
     public void stateChanged( final ChangeEvent ce ) {
         final EditorPanel newActiveEditorPanel = (EditorPanel) ( (JTabbedPane) ce.getSource()
).getSelectedComponent();
-
+        
         newActiveEditorPanel.loadPolicyText( activeEditorPanel.getPolicyText() );
         newActiveEditorPanel.setHasDirty   ( activeEditorPanel.getHasDirty  () );
         activeEditorPanel = newActiveEditorPanel;

Modified: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/Permission.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/Permission.java?rev=682413&r1=682412&r2=682413&view=diff
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/Permission.java
(original)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/Permission.java
Mon Aug  4 07:57:13 2008
@@ -20,7 +20,7 @@
 /**
  * Represents a principal for the grant entries.
  */
-public class Permission {
+public class Permission implements Cloneable {
 
     /** Name of the class of the permission.                   */
     private String className;
@@ -95,4 +95,15 @@
         this.signedBy = signedBy;
     }
 
+    @Override
+    public Object clone() {
+        try {
+            return super.clone();
+        } catch ( final CloneNotSupportedException cnse ) {
+            // This never gonna happen.
+            cnse.printStackTrace();
+            return null;
+        }
+    }
+
 }

Modified: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/Principal.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/Principal.java?rev=682413&r1=682412&r2=682413&view=diff
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/Principal.java
(original)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/Principal.java
Mon Aug  4 07:57:13 2008
@@ -20,7 +20,7 @@
 /**
  * Represents a principal for the grant entries.
  */
-public class Principal {
+public class Principal implements Cloneable {
 
     /** Type of the principal. */
     private String type;
@@ -64,4 +64,15 @@
         return "Principal " + type + " \"" + name + '"';
     }
 
+    @Override
+    public Object clone() {
+        try {
+            return super.clone();
+        } catch ( final CloneNotSupportedException cnse ) {
+            // This never gonna happen.
+            cnse.printStackTrace();
+            return null;
+        }
+    }
+
 }

Modified: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/BaseFormDialog.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/BaseFormDialog.java?rev=682413&r1=682412&r2=682413&view=diff
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/BaseFormDialog.java
(original)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/BaseFormDialog.java
Mon Aug  4 07:57:13 2008
@@ -148,7 +148,16 @@
      * Finishes a successful edit action.
      */
     protected void finishSuccessfulEdit() {
-        ownerEditorPanel.setHasDirty( true );
+        finishSuccessfulEdit( true );
+    }
+
+    /**
+     * Finishes a successful edit action.
+     * @param setDirtyFlag tells whether dirty flag has to be set (to true)
+     */
+    protected void finishSuccessfulEdit( final boolean setDirtyFlag ) {
+        if ( setDirtyFlag )
+            ownerEditorPanel.setHasDirty( true );
         dispose();
     }
 

Modified: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/GrantEntryEditFormDialog.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/GrantEntryEditFormDialog.java?rev=682413&r1=682412&r2=682413&view=diff
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/GrantEntryEditFormDialog.java
(original)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/GrantEntryEditFormDialog.java
Mon Aug  4 07:57:13 2008
@@ -20,6 +20,7 @@
 import java.awt.BorderLayout;
 import java.awt.Dimension;
 import java.awt.Frame;
+import java.util.ArrayList;
 import java.util.List;
 
 import javax.swing.Box;
@@ -41,10 +42,21 @@
     private final GrantEntry          initialGrantEntry;
     /** List of policy entries where to store if new entry is to be created.            
    */
     private final List< PolicyEntry > policyEntryList;
-
+    
     /** Holds the reference to the new granty entry in case of we are creating a new one.
   */
     private final GrantEntry          newGrantEntry;
 
+    /** A deep clone of the edited grant entry's principal list.<br>
+     * This is necessary because we have to be able to restore the original principal list
+     * (which are edited by another instance of LAEFormDialog)
+     * if cancel action is performed here on the grant entry's LAEFormDialog.           
    */
+    private final List< Principal >   tempPrincipalList;
+    /** A deep clone of the edited grant entry's permission list.<br>
+     * This is necessary because we have to be able to restore the original permission list
+     * (which are edited by another instance of LAEFormDialog)
+     * if cancel action is performed here on the grant entry's LAEFormDialog.           
    */
+    private final List< Permission >  tempPermissionList;
+
     /** Text field to view and edit the value of code base. */
     private final JTextField codeBaseTextField = new JTextField();
     /** Text field to view and edit the value of signed by. */
@@ -64,10 +76,44 @@
         this.policyEntryList   = policyEntryList;
 
         newGrantEntry = initialGrantEntry == null ? new GrantEntry() : null;
+        tempPrincipalList  = deepclonePrincipalList ( ( initialGrantEntry == null ? newGrantEntry
: initialGrantEntry ).getPrincipalList () );
+        tempPermissionList = deepclonePermissionList( ( initialGrantEntry == null ? newGrantEntry
: initialGrantEntry ).getPermissionList() );
 
         prepareForDisplay();
     }
 
+    /**
+     * Deepclones a principal list and returns it.<br>
+     * This method uses the <code>Object.clone()</code> clone the elements.
+     * 
+     * @param principalList principal list to be deepcloned
+     * @return a deepcloned principal list
+     */
+    private static List< Principal > deepclonePrincipalList( final List< Principal
> principalList ) {
+        final List< Principal > deepclonedPrincipalList = new ArrayList< Principal
>( principalList.size() );
+
+        for ( final Principal principal : principalList )
+            deepclonedPrincipalList.add( (Principal) principal.clone() );
+
+        return deepclonedPrincipalList;
+    }
+
+    /**
+     * Deepclones a permission list and returns it.<br>
+     * This method uses the <code>Object.clone()</code> clone the elements.
+     * 
+     * @param permissionList permission list to be deepcloned
+     * @return a deepcloned permission list
+     */
+    private static List< Permission > deepclonePermissionList( final List< Permission
> permissionList ) {
+        final List< Permission > deepclonedPermissionList = new ArrayList< Permission
>( permissionList.size() );
+
+        for ( final Permission permission : permissionList )
+            deepclonedPermissionList.add( (Permission) permission.clone() );
+
+        return deepclonedPermissionList;
+    }
+
     @Override
     protected void buildGUI() {
         final JPanel panel = new JPanel( new BorderLayout( 2,15 ) );
@@ -100,10 +146,10 @@
         panel.add( verticalBox, BorderLayout.NORTH );
 
         // ListAndEdit component for Principals
-        panel.add( new ListAndEditPanel< Principal >( "Principals:", "Principal", (
initialGrantEntry == null ? newGrantEntry : initialGrantEntry ).getPrincipalList(),
+        panel.add( new ListAndEditPanel< Principal >( "Principals:", "Principal", tempPrincipalList,
                 new ListAndEditPanel.LAEFormDialogFactory< Principal > () {
                     public LAEFormDialog createFactoryForAddOrEdit( final Principal selectedEntity
) {
-                        return new PrincipalEditFormDialog( GrantEntryEditFormDialog.this,
ownerEditorPanel, selectedEntity, ( initialGrantEntry == null ? newGrantEntry : initialGrantEntry
).getPrincipalList() );
+                        return new PrincipalEditFormDialog( GrantEntryEditFormDialog.this,
ownerEditorPanel, selectedEntity, tempPrincipalList );
                     }
                 }
             ), BorderLayout.CENTER );
@@ -114,10 +160,10 @@
 
         // ListAndEdit component for Permissions
         final ListAndEditPanel< Permission > permissionsLAE =
-            new ListAndEditPanel< Permission >( "Permissions:", "Permission", ( initialGrantEntry
== null ? newGrantEntry : initialGrantEntry ).getPermissionList(),
+            new ListAndEditPanel< Permission >( "Permissions:", "Permission", tempPermissionList,
                 new ListAndEditPanel.LAEFormDialogFactory< Permission > () {
                     public LAEFormDialog createFactoryForAddOrEdit( final Permission selectedEntity
) {
-                        return null;
+                        return new PermissionEditFormDialog( GrantEntryEditFormDialog.this,
ownerEditorPanel, selectedEntity, tempPermissionList );
                     }
                 }
             );
@@ -131,8 +177,10 @@
 
         final GrantEntry grantEntry = initialGrantEntry == null ? newGrantEntry : initialGrantEntry;
 
-        grantEntry.setCodeBase( codeBaseTextField.getText() );
-        grantEntry.setSignedBy( signedByTextField.getText() );
+        grantEntry.setCodeBase      ( codeBaseTextField.getText() );
+        grantEntry.setSignedBy      ( signedByTextField.getText() );
+        grantEntry.setPrincipalList ( tempPrincipalList           );
+        grantEntry.setPermissionList( tempPermissionList          );
 
         if ( initialGrantEntry == null ) {
             policyEntryList.add( grantEntry );

Modified: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/GraphicalEditorPanel.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/GraphicalEditorPanel.java?rev=682413&r1=682412&r2=682413&view=diff
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/GraphicalEditorPanel.java
(original)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/GraphicalEditorPanel.java
Mon Aug  4 07:57:13 2008
@@ -32,11 +32,13 @@
 public class GraphicalEditorPanel extends EditorPanel {
 
     /** Holds the invalid policy text or null if the loaded policy text is valid.       
*/
-    private String              invalidPolicyText;
+    private String                          invalidPolicyText;
 
     /** The list of the policy text's entries or null if invalid policy text was loaded.
*/
-    private List< PolicyEntry > policyEntryList = new ArrayList< PolicyEntry >();
+    private List< PolicyEntry >             policyEntryList = new ArrayList< PolicyEntry
>();
 
+    /** ListAndEditPanel for handling the grant entries.                                
*/
+    private ListAndEditPanel< PolicyEntry > grantEntryLAEPanel;
     /**
      * Creates a new GraphicalEditorPanel.<br>
      * Sets a BorderLayout as the layout manager.
@@ -45,8 +47,18 @@
     public GraphicalEditorPanel( final MainFrame mainFrame ) {
         super( mainFrame, "Graphical editing", new BorderLayout(), true );
 
-        // buildGUI:
-        add( new ListAndEditPanel< PolicyEntry >( "Policy entries:", "Policy Entry",
policyEntryList,
+        buildGUI();
+    }
+
+    /**
+     * Builds the graphical user interface.<br>
+     * Creates and adds a new LAE panel to this editor panel which will be responsible to
handle the grant entries.
+     */
+    private void buildGUI() {
+        if ( grantEntryLAEPanel != null )
+            remove( grantEntryLAEPanel );
+
+        grantEntryLAEPanel = new ListAndEditPanel< PolicyEntry >( "Policy entries:",
"Policy Entry", policyEntryList,
             new ListAndEditPanel.Filter< PolicyEntry > () {
                 public boolean includeEntity( final PolicyEntry entity ) {
                     return entity instanceof GrantEntry;
@@ -57,7 +69,9 @@
                     return new GrantEntryEditFormDialog( mainFrame, GraphicalEditorPanel.this,
(GrantEntry) selectedEntity, policyEntryList );
                 }
             }
-        ), BorderLayout.CENTER );
+        );
+
+        add( grantEntryLAEPanel, BorderLayout.CENTER );
     }
 
     @Override
@@ -66,6 +80,9 @@
 
         policyEntryList = new ArrayList< PolicyEntry >();
 
+        //TODO: uncomment when loadPolicyText() is implemented 
+        //buildGUI();
+
         return true;
     }
 

Modified: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/KeystoreEntryEditFormDialog.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/KeystoreEntryEditFormDialog.java?rev=682413&r1=682412&r2=682413&view=diff
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/KeystoreEntryEditFormDialog.java
(original)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/KeystoreEntryEditFormDialog.java
Mon Aug  4 07:57:13 2008
@@ -94,7 +94,7 @@
         }
 
         if ( initialKeystorePasswordURLEntry != null ) {
-            keystorePasswordURLTextField.setText( initialKeystorePasswordURLEntry.getUrl()
);
+            keystorePasswordURLTextField.setText( initialKeystorePasswordURLEntry.getUrl()
); 
         }
 
         final JPanel flowPanel = new JPanel();

Modified: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/ListAndEditPanel.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/ListAndEditPanel.java?rev=682413&r1=682412&r2=682413&view=diff
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/ListAndEditPanel.java
(original)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/ListAndEditPanel.java
Mon Aug  4 07:57:13 2008
@@ -31,7 +31,7 @@
 
 /**
  * The abstraction of a panel which can list entities and provide GUI components to offer
and handle certain actions on the entities.<br>
- * The entities are listed in a listbox,
+ * The entities are listed in a listbox.
  * @param <EntityType> type of the entities listed on and edited by this panel
  */
 public class ListAndEditPanel< EntityType > extends JPanel implements ActionListener
{

Modified: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/PrincipalEditFormDialog.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/PrincipalEditFormDialog.java?rev=682413&r1=682412&r2=682413&view=diff
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/PrincipalEditFormDialog.java
(original)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/PrincipalEditFormDialog.java
Mon Aug  4 07:57:13 2008
@@ -94,11 +94,11 @@
             if ( initialPrincipal.getType() != null )
                 for ( int i = 0; i < DEFAULT_PRINCIPAL_TYPE_CLASS_NAMES.length; i++ )
                     if ( DEFAULT_PRINCIPAL_TYPE_CLASS_NAMES[ i ] != null && DEFAULT_PRINCIPAL_TYPE_CLASS_NAMES[
i ].equals( initialPrincipal.getType() ) ) {
-                        principalTypeComboBox .setSelectedIndex( i );
+                        principalTypeComboBox.setSelectedIndex( i );
                         break;
                     }
-            principalTypeTextField.setText( initialPrincipal.getType() );
-            principalNameTextField.setText( initialPrincipal.getName() );
+            principalTypeTextField.setText( initialPrincipal.getType() ); 
+            principalNameTextField.setText( initialPrincipal.getName() ); 
         }
 
         final JPanel flowPanel = new JPanel();
@@ -121,7 +121,7 @@
         } else
             refreshVisualizationList();
 
-        finishSuccessfulEdit();
+        finishSuccessfulEdit( false );
     }
 
 }



Mime
View raw message