harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjanu...@apache.org
Subject svn commit: r687695 - in /harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool: control/ model/ view/
Date Thu, 21 Aug 2008 10:27:55 GMT
Author: sjanuary
Date: Thu Aug 21 03:27:53 2008
New Revision: 687695

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

Added:
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/WarningLogDialog.java
  (with props)
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/apache.gif
  (with props)
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/control/PolicyTextParser.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/view/BaseFormDialog.java
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/EditorPanel.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/LAEFormDialog.java
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/MainFrame.java
    harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/PermissionEditFormDialog.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=687695&r1=687694&r2=687695&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
Thu Aug 21 03:27:53 2008
@@ -31,6 +31,7 @@
 import org.apache.harmony.tools.policytool.view.EditorPanel;
 import org.apache.harmony.tools.policytool.view.GraphicalEditorPanel;
 import org.apache.harmony.tools.policytool.view.MainFrame;
+import org.apache.harmony.tools.policytool.view.WarningLogDialog;
 import org.apache.harmony.tools.policytool.view.MainFrame.MenuItemEnum;
 
 /**
@@ -38,6 +39,9 @@
  */
 public class Controller implements ChangeListener, ActionListener{
 
+    /** Thee warning log dialog. */
+    private static WarningLogDialog warningLogDialog;
+
     /** Reference to the main frame.              */
     private final MainFrame     mainFrame;
     /** Array of the editor panels.               */
@@ -52,6 +56,22 @@
     private File                editedPolicyFile;
 
     /**
+     * Logs an error message to the warning/error log.
+     * @param errorMessage error message to be logged
+     */
+    public static void logError( final String errorMessage ) {
+        warningLogDialog.addMessage( "Error: " + errorMessage );
+    }
+
+    /**
+     * Logs a warning message to the warning/error log.
+     * @param warningMessage warning message to be logged
+     */
+    public static void logWarning( final String warningMessage ) {
+        warningLogDialog.addMessage( "Warning: " + warningMessage );
+    }
+
+    /**
      * Creates a new Controller.
      * @param mainFrame reference to the main frame
      * @param editorPanels array of the editor panels
@@ -60,6 +80,7 @@
     public Controller( final MainFrame mainFrame, final EditorPanel[] editorPanels, final
String policyFileName ) {
         this.mainFrame    = mainFrame;
         this.editorPanels = editorPanels;
+        warningLogDialog  = new WarningLogDialog( mainFrame );
         activeEditorPanel = editorPanels[ 0 ];
 
         PolicyFileHandler.setDialogParentComponent( mainFrame );
@@ -101,7 +122,7 @@
      * Determines if a dirty sensitive operation is allowed to be executed.<br>
      * There are operation which will throw away the edited policy text currently hold in
the active editor
      * (for example exit or load a file, or start a new).<br>
-     * This method checks whether there are unsaved changes, and if so, ask confirmation
on what to do with them.<br>
+     * This method checks whether there are unsaved changes, and if so, asks 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.
      * 
@@ -186,7 +207,7 @@
 
         case NEW :
             if ( allowedDirtySensitiveOperation( "starting new file" ) ) {
-                activeEditorPanel.loadPolicyText( null );
+                activeEditorPanel.loadPolicyText( "" );
                 setEditedPolicyFile( null );
             }
             break;
@@ -221,6 +242,7 @@
             break;
 
         case VIEW_WARNING_LOG :
+            warningLogDialog.setVisible( true );
             break;
 
         case EXIT :

Modified: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/PolicyTextParser.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/PolicyTextParser.java?rev=687695&r1=687694&r2=687695&view=diff
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/PolicyTextParser.java
(original)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/control/PolicyTextParser.java
Thu Aug 21 03:27:53 2008
@@ -363,7 +363,7 @@
                         if ( peekNextNonWhiteSpaceChar( signedByIndices[ 1 ] ) != PolicyEntry.TERMINATOR_CHAR
)
                             throw new InvalidPolicyTextException( "Was expecting semicolon
but found something else!" );
                         else
-                            newIndex = skipWhiteSpaces( newIndex ) + 1;
+                            newIndex = skipWhiteSpaces( signedByIndices[ 1 ] ) + 1;
                     }
                     else
                         newIndex = skipWhiteSpaces( newIndex ) + 1;

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=687695&r1=687694&r2=687695&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
Thu Aug 21 03:27:53 2008
@@ -113,7 +113,7 @@
         if ( actions != null && actions.length() > 0 )
             stringBuilder.append( ", \"" ).append( actions ).append( '"');
         if ( signedBy != null && signedBy.length() > 0 )
-            stringBuilder.append( "," ).append( signedByPartPrefix ).append( "signedBy \""
).append( signedBy ).append( '"' );
+            stringBuilder.append( ", " ).append( signedByPartPrefix ).append( "signedBy \""
).append( signedBy ).append( '"' );
 
         return stringBuilder.toString();
     }

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=687695&r1=687694&r2=687695&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
Thu Aug 21 03:27:53 2008
@@ -33,6 +33,9 @@
  */
 public abstract class BaseFormDialog extends JDialog implements ActionListener {
 
+    /** Error message for not allowed quotation marks. */
+    public static final String NOT_ALLOWED_QUOTATION_MARKS_MESSAGE = "The following fields
may not contain quotation marks: ";
+
     /** Reference to the owner window.    */
     protected final Window      ownerWindow;
 
@@ -130,7 +133,7 @@
     }
 
     /**
-     * Handles the action events of the dialog's ok and cancel button.
+     * Handles the action events of the dialog's ok and cancel buttons.
      */
     public void actionPerformed( final ActionEvent ae ) {
         if ( ae.getSource() == okButton )

Modified: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/EditorPanel.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/EditorPanel.java?rev=687695&r1=687694&r2=687695&view=diff
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/EditorPanel.java
(original)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/EditorPanel.java
Thu Aug 21 03:27:53 2008
@@ -43,7 +43,6 @@
      * @param mainFrame reference to the main frame
      * @param panelTitle the title of the panel
      * @param layoutManager layout manager to be used
-     * @param supportsGraphicalKeystoreEdit true if this editor panel supports graphical
keystore edit; false otherwise
      */
     public EditorPanel( final MainFrame mainFrame, final String panelTitle, final LayoutManager
layoutManager ) {
         this( mainFrame, panelTitle, layoutManager, false );

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=687695&r1=687694&r2=687695&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
Thu Aug 21 03:27:53 2008
@@ -20,14 +20,18 @@
 import java.awt.BorderLayout;
 import java.awt.Dimension;
 import java.awt.Frame;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
 
 import javax.swing.Box;
 import javax.swing.JLabel;
+import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JTextField;
 
+import org.apache.harmony.tools.policytool.control.Controller;
 import org.apache.harmony.tools.policytool.model.GrantEntry;
 import org.apache.harmony.tools.policytool.model.Permission;
 import org.apache.harmony.tools.policytool.model.PolicyEntry;
@@ -173,7 +177,34 @@
 
     @Override
     public void onOkButtonPressed() {
-        // TODO: validation
+        // validation
+        final StringBuilder errorStringBuilder = new StringBuilder( NOT_ALLOWED_QUOTATION_MARKS_MESSAGE
);
+        boolean validationFails = false;
+        if ( codeBaseTextField.getText().indexOf( '"' ) >= 0 ) {
+            validationFails = true;
+            errorStringBuilder.append( "codeBase" );
+        }
+        if ( signedByTextField.getText().indexOf( '"' ) >= 0 ) {
+            validationFails = true;
+            errorStringBuilder.append( validationFails ? ", signedBy" : "signedBy" );
+        }
+
+        if ( !validationFails && codeBaseTextField.getText().length() > 0 ) {
+            try {
+                new URL( codeBaseTextField.getText() );
+            } catch ( final MalformedURLException mue ) {
+                validationFails = true;
+                errorStringBuilder.setLength( 0 );
+                errorStringBuilder.append( "CodeBase contains a malformed URL: " + mue.getMessage()
);
+            }
+        }
+
+        if ( validationFails ) {
+            Controller.logError( errorStringBuilder.toString() );
+            JOptionPane.showMessageDialog( this, errorStringBuilder.toString(), "Error!",
JOptionPane.ERROR_MESSAGE );
+            return;
+        }
+        // validation end
 
         final GrantEntry grantEntry = initialGrantEntry == null ? newGrantEntry : initialGrantEntry;
 

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=687695&r1=687694&r2=687695&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
Thu Aug 21 03:27:53 2008
@@ -24,6 +24,7 @@
 import javax.swing.JOptionPane;
 
 import org.apache.harmony.tools.policytool.Consts;
+import org.apache.harmony.tools.policytool.control.Controller;
 import org.apache.harmony.tools.policytool.control.InvalidPolicyTextException;
 import org.apache.harmony.tools.policytool.control.PolicyTextParser;
 import org.apache.harmony.tools.policytool.model.GrantEntry;
@@ -93,6 +94,7 @@
             policyEntryList   = PolicyTextParser.parsePolicyText( policyText );
 
         } catch ( final InvalidPolicyTextException ipte ) {
+            Controller.logError( ipte.getMessage() );
             JOptionPane.showMessageDialog( this, new String[] { ipte.getMessage(), " ", "Graphical
editor is disabled, correct the error in the direct editor or load a valid policy file." },
"Parse error!", JOptionPane.ERROR_MESSAGE );
             invalidPolicyText = policyText;
             policyEntryList   = new ArrayList< PolicyEntry >();

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=687695&r1=687694&r2=687695&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
Thu Aug 21 03:27:53 2008
@@ -20,13 +20,17 @@
 import java.awt.BorderLayout;
 import java.awt.Frame;
 import java.awt.GridLayout;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.List;
 
 import javax.swing.JLabel;
+import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.JTextField;
 
+import org.apache.harmony.tools.policytool.control.Controller;
 import org.apache.harmony.tools.policytool.model.CommentEntry;
 import org.apache.harmony.tools.policytool.model.KeystoreEntry;
 import org.apache.harmony.tools.policytool.model.KeystorePasswordURLEntry;
@@ -104,7 +108,52 @@
 
     @Override
     public void onOkButtonPressed() {
-        // TODO: validation
+        // validation
+        final StringBuilder errorStringBuilder = new StringBuilder( NOT_ALLOWED_QUOTATION_MARKS_MESSAGE
);
+        boolean validationFails = false;
+        if ( keystoreURLTextField.getText().indexOf( '"' ) >= 0 ) {
+            validationFails = true;
+            errorStringBuilder.append( "Keystore URL" );
+        }
+        if ( keystoreTypeTextField.getText().indexOf( '"' ) >= 0 ) {
+            errorStringBuilder.append( validationFails ? ", Keystore Type" : "Keystore Type"
);
+            validationFails = true;
+        }
+        if ( keystoreProviderTextField.getText().indexOf( '"' ) >= 0 ) {
+            errorStringBuilder.append( validationFails ? ", Keystore Provider" : "Keystore
Provider" );
+            validationFails = true;
+        }
+        if ( keystorePasswordURLTextField.getText().indexOf( '"' ) >= 0 ) {
+            errorStringBuilder.append( validationFails ? ", Keystore Password URL" : "Keystore
Password URL" );
+            validationFails = true;
+        }
+
+        if ( !validationFails && keystoreURLTextField.getText().length() > 0 )
{
+            try {
+                new URL( keystoreURLTextField.getText() );
+            } catch ( final MalformedURLException mue ) {
+                validationFails = true;
+                errorStringBuilder.setLength( 0 );
+                errorStringBuilder.append( "Keystore URL contains a malformed URL: " + mue.getMessage()
);
+            }
+        }
+
+        if ( !validationFails && keystorePasswordURLTextField.getText().length()
> 0 ) {
+            try {
+                new URL( keystorePasswordURLTextField.getText() );
+            } catch ( final MalformedURLException mue ) {
+                validationFails = true;
+                errorStringBuilder.setLength( 0 );
+                errorStringBuilder.append( "Keystore Password URL contains a malformed URL:
" + mue.getMessage() );
+            }
+        }
+
+        if ( validationFails ) {
+            Controller.logError( errorStringBuilder.toString() );
+            JOptionPane.showMessageDialog( this, errorStringBuilder.toString(), "Error!",
JOptionPane.ERROR_MESSAGE );
+            return;
+        }
+        // validation end
 
         final KeystoreEntry keystoreEntry = initialKeystoreEntry == null ? new KeystoreEntry()
: initialKeystoreEntry;
 

Modified: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/LAEFormDialog.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/LAEFormDialog.java?rev=687695&r1=687694&r2=687695&view=diff
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/LAEFormDialog.java
(original)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/LAEFormDialog.java
Thu Aug 21 03:27:53 2008
@@ -75,8 +75,12 @@
      * Should be called if the entities of the list might have changed but the list model
was not modified.
      */
     public void refreshVisualizationList() {
-        visualizationJListforLAE.revalidate();
-        visualizationJListforLAE.repaint();
+        final Object newTempItem = new String();
+        // There is a bug if we edit an item, we change it in a way that its toString() method
will return a very long string
+        // (long as it won't fit in the displayed width), its string will be truncated (ended
with "..."), and no scrollbars will be displayed
+        // The addElement() operation causes to recalculate the viewport size.
+        listModel.addElement   ( newTempItem );
+        listModel.removeElement( newTempItem );
     }
 
 }

Modified: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/MainFrame.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/MainFrame.java?rev=687695&r1=687694&r2=687695&view=diff
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/MainFrame.java
(original)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/MainFrame.java
Thu Aug 21 03:27:53 2008
@@ -22,7 +22,9 @@
 import java.awt.event.WindowEvent;
 import java.io.File;
 import java.io.IOException;
+import java.net.URL;
 
+import javax.swing.ImageIcon;
 import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JMenu;
@@ -57,6 +59,12 @@
     public MainFrame( final String policyFileName ) {
         super( Consts.APPLICATION_NAME );
 
+        // I set icon image before controller, because controller creates WarningLogDialog
passign main frame as owner,
+        // and icon image is inherited. This way Warning Log Dialog will have the same icon.
+        final URL apahceIconURL = MainFrame.class.getResource( "apache.gif" );
+        if ( apahceIconURL != null )
+            setIconImage( new ImageIcon( apahceIconURL ).getImage() );
+
         final EditorPanel[] editorPanels = new EditorPanel[] { new GraphicalEditorPanel(
this ), new DirectTextEditorPanel( this ) };
         final Controller    controller   = new Controller( this, editorPanels, policyFileName
);
 

Modified: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/PermissionEditFormDialog.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/PermissionEditFormDialog.java?rev=687695&r1=687694&r2=687695&view=diff
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/PermissionEditFormDialog.java
(original)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/PermissionEditFormDialog.java
Thu Aug 21 03:27:53 2008
@@ -34,6 +34,7 @@
 import javax.swing.JScrollPane;
 import javax.swing.JTextField;
 
+import org.apache.harmony.tools.policytool.control.Controller;
 import org.apache.harmony.tools.policytool.model.Permission;
 
 /**
@@ -230,11 +231,35 @@
 
     @Override
     public void onOkButtonPressed() {
-        // TODO: validation
-        if ( permissionTypeTextField.getText().length() == 0 || targetNameTextField.isEnabled()
&& targetNameTextField.getText().length() == 0 ) {
-            JOptionPane.showMessageDialog( this, "Permission and target name must have a
value!", "Error", JOptionPane.ERROR_MESSAGE );
+        // validation
+        final StringBuilder errorStringBuilder = new StringBuilder( NOT_ALLOWED_QUOTATION_MARKS_MESSAGE
);
+        boolean validationFails = false;
+        if ( targetNameTextField.getText().indexOf( '"' ) >= 0 ) {
+            validationFails = true;
+            errorStringBuilder.append( "Target Name" );
+        }
+        if ( actionsTextField.getText().indexOf( '"' ) >= 0 ) {
+            errorStringBuilder.append( validationFails ? ", Actions" : "Actions" );
+            validationFails = true;
+        }
+        if ( signedByTextField.getText().indexOf( '"' ) >= 0 ) {
+            errorStringBuilder.append( validationFails ? ", Signed By" : "Signed By" );
+            validationFails = true;
+        }
+
+        if ( !validationFails )
+            if ( permissionTypeTextField.getText().length() == 0 || targetNameTextField.isEnabled()
&& targetNameTextField.getText().length() == 0 ) {
+                validationFails = true;
+                errorStringBuilder.setLength( 0 );
+                errorStringBuilder.append( "Permission and target name must have a value!"
);
+            }
+
+        if ( validationFails ) {
+            Controller.logError( errorStringBuilder.toString() );
+            JOptionPane.showMessageDialog( this, errorStringBuilder.toString(), "Error!",
JOptionPane.ERROR_MESSAGE );
             return;
         }
+        // validation end
 
         final Permission permission = initialPermission == null ? new Permission() : initialPermission;
 

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=687695&r1=687694&r2=687695&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
Thu Aug 21 03:27:53 2008
@@ -26,10 +26,12 @@
 
 import javax.swing.JComboBox;
 import javax.swing.JLabel;
+import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.JTextField;
 
+import org.apache.harmony.tools.policytool.control.Controller;
 import org.apache.harmony.tools.policytool.model.Principal;
 
 /**
@@ -108,8 +110,27 @@
 
     @Override
     public void onOkButtonPressed() {
-        // TODO: validation
-        // Class name and target name are mandatory!
+        // validation
+        final StringBuilder errorStringBuilder = new StringBuilder( NOT_ALLOWED_QUOTATION_MARKS_MESSAGE
);
+        boolean validationFails = false;
+        if ( principalNameTextField.getText().indexOf( '"' ) >= 0 ) {
+            validationFails = true;
+            errorStringBuilder.append( "Principal Name" );
+        }
+
+        if ( !validationFails )
+            if ( principalTypeTextField.getText().length() == 0 || principalNameTextField.getText().length()
== 0 ) {
+                validationFails = true;
+                errorStringBuilder.setLength( 0 );
+                errorStringBuilder.append( "Principal Type and Principal Name must have a
value!" );
+            }
+
+        if ( validationFails ) {
+            Controller.logError( errorStringBuilder.toString() );
+            JOptionPane.showMessageDialog( this, errorStringBuilder.toString(), "Error!",
JOptionPane.ERROR_MESSAGE );
+            return;
+        }
+        // validation end
 
         final Principal principal = initialPrincipal == null ? new Principal() : initialPrincipal;
 

Added: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/WarningLogDialog.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/WarningLogDialog.java?rev=687695&view=auto
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/WarningLogDialog.java
(added)
+++ harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/WarningLogDialog.java
Thu Aug 21 03:27:53 2008
@@ -0,0 +1,96 @@
+/*
+ * 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.apache.harmony.tools.policytool.view;
+
+import java.awt.BorderLayout;
+import java.awt.Frame;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+
+import org.apache.harmony.tools.policytool.Consts;
+
+/**
+ * Dialog to view the warning and error logs.
+ */
+public class WarningLogDialog extends JDialog implements ActionListener {
+
+    /** Text area to store and display the log. */
+    private final JTextArea logTextArea; 
+    /** Reference to the owner frame.           */
+    private final Frame     ownerFrame;
+    
+    /**
+     * Creates a new WarningLogDialog.
+     * @param ownerFrame reference to the owner frame
+     */
+    public WarningLogDialog( final Frame ownerFrame ) {
+        super( ownerFrame, "Warning log", false );
+        this.ownerFrame = ownerFrame;
+        setDefaultCloseOperation( HIDE_ON_CLOSE );
+
+        logTextArea = new JTextArea( 15, 50 );
+        logTextArea.setEditable( false );
+        add( new JScrollPane( logTextArea ), BorderLayout.CENTER );
+
+        final JPanel  panel       = new JPanel();
+
+        final JButton closeButton = new JButton( "Close" );
+        closeButton.setMnemonic( closeButton.getText().charAt( 0 ) );
+        closeButton.addActionListener( this );
+        panel.add( closeButton );
+
+        add( panel, BorderLayout.SOUTH );
+
+        pack();
+    }
+
+    /**
+     * If parameter <code>visibility</code> is true, first centers the dialog.
Calls <code>super.setVisible()</code> afterwards.
+     */
+    @Override
+    public void setVisible( final boolean visibility ) {
+        if ( visibility )
+            setLocation( ownerFrame.getX() + ownerFrame.getWidth () / 2 - getWidth () / 2,
+                         ownerFrame.getY() + ownerFrame.getHeight() / 2 - getHeight() / 2
);
+        super.setVisible( visibility );
+    }
+
+    /**
+     * Adds a message to the log.
+     * @param message message to be added
+     */
+    public void addMessage( final String message ) {
+        logTextArea.append( message );
+        logTextArea.append( Consts.NEW_LINE_STRING );
+        logTextArea.setCaretPosition( logTextArea.getDocument().getLength() );
+    }
+
+    /**
+     * Handles the action events of the close button.
+     */
+    public void actionPerformed( final ActionEvent ae ) {
+        setVisible( false );
+    }
+
+}

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/WarningLogDialog.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/WarningLogDialog.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/apache.gif
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/apache.gif?rev=687695&view=auto
==============================================================================
Binary file - no diff available.

Propchange: harmony/enhanced/jdktools/trunk/modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/apache.gif
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message