Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/GrantEntry.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/GrantEntry.java (revision 676240) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/GrantEntry.java (working copy) @@ -113,4 +113,19 @@ // TODO Auto-generated method stub } + @Override + public String toString() { + final StringBuilder stringBuilder = new StringBuilder(); + + if ( codeBase != null ) + stringBuilder.append( "CodeBase \"" ).append( codeBase ).append( '"'); + if ( signedBy != null ) + stringBuilder.append( stringBuilder.length() > 0 ? ", " : "" ).append( "SignedBy \"" ).append( signedBy ).append( '"' ); + + for ( final Principal principal : principalList ) + stringBuilder.append( stringBuilder.length() > 0 ? ", " : "" ).append( principal ); + + return stringBuilder.toString(); + } + } Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/Principal.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/Principal.java (revision 676240) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/model/Principal.java (working copy) @@ -59,4 +59,9 @@ this.name = name; } + @Override + public String toString() { + return "Principal " + type + " \"" + name + '"'; + } + } Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/BaseFormDialog.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/BaseFormDialog.java (revision 676240) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/BaseFormDialog.java (working copy) @@ -18,7 +18,9 @@ package org.apache.harmony.tools.policytool.view; import java.awt.BorderLayout; +import java.awt.Dialog; import java.awt.Frame; +import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -31,13 +33,13 @@ */ public abstract class BaseFormDialog extends JDialog implements ActionListener { - /** Reference to the owner frame. */ - private final Frame ownerFrame; + /** Reference to the owner window. */ + protected final Window ownerWindow; /** Ok button of the form dialog. */ - private final JButton okButton = new JButton( "OK" ); + private final JButton okButton = new JButton( "OK" ); /** Cancel button of the form dialog. */ - private final JButton cancelButton = new JButton( "Cancel" ); + private final JButton cancelButton = new JButton( "Cancel" ); /** Reference to the owner editor panel. This reference can (will) be used to indicate new data/dirty state. */ protected final EditorPanel ownerEditorPanel; @@ -51,11 +53,38 @@ public BaseFormDialog( final Frame ownerFrame, final String title, final EditorPanel ownerEditorPanel ) { super( ownerFrame, title, true ); - this.ownerFrame = ownerFrame; + this.ownerWindow = ownerFrame; + this.ownerEditorPanel = ownerEditorPanel; + + initialize(); + } + + /** + * Creates a new BaseFormDialog. + * @param ownerDialog owner dialog of the dialog + * @param title title of the dialog + * @param ownerEditorPanel reference to the owner editor panel + */ + public BaseFormDialog( final Dialog ownerDialog, final String title, final EditorPanel ownerEditorPanel ) { + super( ownerDialog, title, true ); + + this.ownerWindow = ownerDialog; this.ownerEditorPanel = ownerEditorPanel; + initialize(); + } + + /** + * Initializes the dialog.
+ * Part of the constructor. + */ + private void initialize() { + setDefaultCloseOperation( DISPOSE_ON_CLOSE ); + buildBaseGUI(); - setDefaultCloseOperation( DISPOSE_ON_CLOSE ); + + // We cannot call or perform the prepareForDisplay() operation here, + // because the actual GUI might require fields initialized after this constructor. } /** @@ -77,11 +106,27 @@ } /** + * Builds the GUI of the dialog. + */ + protected abstract void buildGUI(); + + /** + * Prepares the dialog for displaying.
+ * This includes finishing building the gui and sizing and positioning it. + */ + protected void prepareForDisplay() { + buildGUI(); + + pack(); + center(); + } + + /** * Centers the dialog to its owner frame. */ public void center() { - setLocation( ownerFrame.getX() + ownerFrame.getWidth () / 2 - getWidth () / 2, - ownerFrame.getY() + ownerFrame.getHeight() / 2 - getHeight() / 2 ); + setLocation( ownerWindow.getX() + ownerWindow.getWidth () / 2 - getWidth () / 2, + ownerWindow.getY() + ownerWindow.getHeight() / 2 - getHeight() / 2 ); } /** @@ -100,6 +145,14 @@ public abstract void onOkButtonPressed(); /** + * Finishes a successful edit action. + */ + protected void finishSuccessfulEdit() { + ownerEditorPanel.setHasDirty( true ); + dispose(); + } + + /** * Called when the cancel button of the dialog is pressed.
* Simply disposes the dialog. */ Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/GraphicalEditorPanel.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/GraphicalEditorPanel.java (revision 676240) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/GraphicalEditorPanel.java (working copy) @@ -46,11 +46,18 @@ super( mainFrame, "Graphical editing", new BorderLayout(), true ); // buildGUI: - add( new ListAndEditPanel< PolicyEntry >( "Policy Entry", policyEntryList, new ListAndEditPanel.Filter< PolicyEntry > () { - public boolean includeEntity( final PolicyEntry entity ) { - return entity instanceof GrantEntry; + add( new ListAndEditPanel< PolicyEntry >( "Policy entries:", "Policy Entry", policyEntryList, + new ListAndEditPanel.Filter< PolicyEntry > () { + public boolean includeEntity( final PolicyEntry entity ) { + return entity instanceof GrantEntry; + } + }, + new ListAndEditPanel.LAEFormDialogFactory< PolicyEntry > () { + public LAEFormDialog createFactoryForAddOrEdit( final PolicyEntry selectedEntity ) { + return new GrantEntryEditFormDialog( mainFrame, GraphicalEditorPanel.this, (GrantEntry) selectedEntity, policyEntryList ); + } } - } ), BorderLayout.CENTER ); + ), BorderLayout.CENTER ); } @Override Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/PrincipalEditFormDialog.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/PrincipalEditFormDialog.java (revision 0) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/PrincipalEditFormDialog.java (revision 0) @@ -0,0 +1,127 @@ +/* + * 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.Dialog; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.List; + +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextField; + +import org.apache.harmony.tools.policytool.model.Principal; + +/** + * Form dialog to view and edit the principals of a grant entry. + */ +public class PrincipalEditFormDialog extends LAEFormDialog { + + /** Names of the principal types. */ + private static final String[] DEFAULT_PRINCIPAL_TYPE_NAMES = + new String[] { "Principal Type:", "KerberosPrincipal" , "X500Principal" }; + /** Default names of the principal type classes to be set when chosen. Null value means not to change it. */ + private static final String[] DEFAULT_PRINCIPAL_TYPE_CLASS_NAMES = + new String[] { null , "javax.security.auth.kerberos.KerberosPrincipal", "javax.security.auth.x500.X500Principal" }; + + /** Reference to the initial editable principal or null, if we are creating a new one. */ + private final Principal initialPrincipal; + /** List of principals where to store if new principal is to be created. */ + private final List< Principal > principalList; + + /** Combo box to view and choose the principal type. */ + private final JComboBox principalTypeComboBox = new JComboBox( DEFAULT_PRINCIPAL_TYPE_NAMES ); + /** Text field to view and edit the principal type (the class name). */ + private final JTextField principalTypeTextField = new JTextField( 20 ); + /** Text field to view and edit the principal name. */ + private final JTextField principalNameTextField = new JTextField( 20 ); + + /** + * Creates a new PrincipalEditFormDialog. + * @param ownerDialog reference to the owner dialog + * @param ownerEditorPanel reference to the owner editor panel + * @param principal reference to the editable principal or null, if we are creating a new one + * @param principalList list of principals where to store if new principal is to be created + */ + public PrincipalEditFormDialog( final Dialog ownerDialog, final EditorPanel ownerEditorPanel, final Principal principal, final List< Principal > principalList ) { + super( ownerDialog, "Principal", ownerEditorPanel ); + + this.initialPrincipal = principal; + this.principalList = principalList; + + prepareForDisplay(); + } + + @Override + protected void buildGUI() { + final JPanel panel = new JPanel( new GridLayout( 2, 2, 5, 10 ) ); + + principalTypeComboBox.addActionListener( new ActionListener() { + public void actionPerformed( final ActionEvent ae ) { + final String classNameForSelectedType = DEFAULT_PRINCIPAL_TYPE_CLASS_NAMES[ principalTypeComboBox.getSelectedIndex() ]; + if ( classNameForSelectedType != null ) + principalTypeTextField.setText( classNameForSelectedType ); + } + } ); + panel.add( principalTypeComboBox ); + panel.add( principalTypeTextField ); + + panel.add( new JLabel( "Principal Name:" ) ); + panel.add( principalNameTextField ); + + if ( initialPrincipal != null ) { + // Should we choose anything in the principal type combo box? + 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 ); + break; + } + principalTypeTextField.setText( initialPrincipal.getType() ); + principalNameTextField.setText( initialPrincipal.getName() ); + } + + final JPanel flowPanel = new JPanel(); + flowPanel.add( panel ); + add( new JScrollPane( flowPanel ), BorderLayout.CENTER ); + } + + @Override + public void onOkButtonPressed() { + // TODO: validation + + final Principal principal = initialPrincipal == null ? new Principal() : initialPrincipal; + + principal.setType( principalTypeTextField.getText() ); + principal.setName( principalNameTextField.getText() ); + + if ( initialPrincipal == null ) { + principalList.add( principal ); + listModel.addElement( principal ); + } else + refreshVisualizationList(); + + finishSuccessfulEdit(); + } + +} Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/GrantEntryEditFormDialog.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/GrantEntryEditFormDialog.java (revision 0) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/GrantEntryEditFormDialog.java (revision 0) @@ -0,0 +1,146 @@ +/* + * 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.Dimension; +import java.awt.Frame; +import java.util.List; + +import javax.swing.Box; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; + +import org.apache.harmony.tools.policytool.model.GrantEntry; +import org.apache.harmony.tools.policytool.model.Permission; +import org.apache.harmony.tools.policytool.model.PolicyEntry; +import org.apache.harmony.tools.policytool.model.Principal; + +/** + * Form dialog to view and edit the grant entries. + */ +public class GrantEntryEditFormDialog extends LAEFormDialog { + + /** Reference to the initial editable grant entry or null, if we are creating a new one. */ + 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; + + /** 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. */ + private final JTextField signedByTextField = new JTextField(); + + /** + * Creates a new GrantEntryEditFormDialog. + * @param ownerFrame reference to the owner frame + * @param ownerEditorPanel reference to the owner editor panel + * @param grantEntry reference to the editable grant entry or null, if we are creating a new one + * @param policyEntryList list of policy entries where to store if new entry is to be created + */ + public GrantEntryEditFormDialog( final Frame ownerFrame, final EditorPanel ownerEditorPanel, final GrantEntry grantEntry, final List< PolicyEntry > policyEntryList ) { + super( ownerFrame, "Policy Entry", ownerEditorPanel ); + + this.initialGrantEntry = grantEntry; + this.policyEntryList = policyEntryList; + + newGrantEntry = initialGrantEntry == null ? new GrantEntry() : null; + + prepareForDisplay(); + } + + @Override + protected void buildGUI() { + final JPanel panel = new JPanel( new BorderLayout( 2,15 ) ); + + final Box verticalBox = Box.createVerticalBox(); + + verticalBox.add( Box.createVerticalStrut( 10 ) ); + + Box hBox = Box.createHorizontalBox(); + JLabel label = new JLabel( "CodeBase: ", JLabel.RIGHT ); + label.setPreferredSize( new Dimension( 80, 20 ) ); + hBox.add( label ); + hBox.add( codeBaseTextField ); + verticalBox.add( hBox ); + + verticalBox.add( Box.createVerticalStrut( 5 ) ); + + hBox = Box.createHorizontalBox(); + label = new JLabel( "SignedBy: ", JLabel.RIGHT ); + label.setPreferredSize( new Dimension( 80, 20 ) ); + hBox.add( label ); + hBox.add( signedByTextField ); + verticalBox.add( hBox ); + + if ( initialGrantEntry != null ) { + codeBaseTextField.setText( initialGrantEntry.getCodeBase() ); + signedByTextField.setText( initialGrantEntry.getSignedBy() ); + } + + panel.add( verticalBox, BorderLayout.NORTH ); + + // ListAndEdit component for Principals + panel.add( new ListAndEditPanel< Principal >( "Principals:", "Principal", ( initialGrantEntry == null ? newGrantEntry : initialGrantEntry ).getPrincipalList(), + new ListAndEditPanel.LAEFormDialogFactory< Principal > () { + public LAEFormDialog createFactoryForAddOrEdit( final Principal selectedEntity ) { + return new PrincipalEditFormDialog( GrantEntryEditFormDialog.this, ownerEditorPanel, selectedEntity, ( initialGrantEntry == null ? newGrantEntry : initialGrantEntry ).getPrincipalList() ); + } + } + ), BorderLayout.CENTER ); + + panel.add( new JLabel(), BorderLayout.SOUTH ); // To make some space between the 2 ListAndEdit components (vertical gap of the BorderLayout of the panel will be used) + + add( panel, BorderLayout.NORTH ); + + // ListAndEdit component for Permissions + final ListAndEditPanel< Permission > permissionsLAE = + new ListAndEditPanel< Permission >( "Permissions:", "Permission", ( initialGrantEntry == null ? newGrantEntry : initialGrantEntry ).getPermissionList(), + new ListAndEditPanel.LAEFormDialogFactory< Permission > () { + public LAEFormDialog createFactoryForAddOrEdit( final Permission selectedEntity ) { + return null; + } + } + ); + permissionsLAE.overrideMnemonics( 'd', 't', 'v' ); + add( permissionsLAE, BorderLayout.CENTER ); + } + + @Override + public void onOkButtonPressed() { + // TODO: validation + + final GrantEntry grantEntry = initialGrantEntry == null ? newGrantEntry : initialGrantEntry; + + grantEntry.setCodeBase( codeBaseTextField.getText() ); + grantEntry.setSignedBy( signedByTextField.getText() ); + + if ( initialGrantEntry == null ) { + policyEntryList.add( grantEntry ); + listModel.addElement( grantEntry ); + } else + refreshVisualizationList(); + + finishSuccessfulEdit(); + } + +} Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/ListAndEditPanel.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/ListAndEditPanel.java (revision 676240) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/ListAndEditPanel.java (working copy) @@ -22,6 +22,7 @@ import java.awt.event.ActionListener; import java.util.List; +import javax.swing.BorderFactory; import javax.swing.DefaultListModel; import javax.swing.JButton; import javax.swing.JList; @@ -35,18 +36,23 @@ */ public class ListAndEditPanel< EntityType > extends JPanel implements ActionListener { + /** Model of the list component displaying the entities. */ + private final DefaultListModel listModel = new DefaultListModel(); /** The component to list he entities. */ - private final JList entityListComponent = new JList(); + private final JList entityListComponent = new JList( listModel ); /** Add new entity button. */ - private final JButton addButton = new JButton(); + private final JButton addButton = new JButton(); /** Edit selected entity button. */ - private final JButton editButton = new JButton(); + private final JButton editButton = new JButton(); /** Remove selected entity button. */ - private final JButton removeButton = new JButton(); + private final JButton removeButton = new JButton(); /** Reference to the list whose elements are to be listed and edited, and where to put new entities. */ - private final List< ? > entityList; + private final List< ? > entityList; + + /** Reference to the base form dialog factory. */ + private final LAEFormDialogFactory< EntityType > baseFormDialogFactory; /** * Can be used to filter the input entity list, hide elements from displaying. @@ -62,13 +68,29 @@ } /** + * Factory instance to be used to acuire a base form dialog which will handle the add/edit action of the selected entity. + * @param type of the entities which is (listed and edited and) passed by by this ListAndEditPanel + */ + public interface LAEFormDialogFactory< EntityType > { + /** + * Creates a LAEFormDialog which will handle the add/edit action of the passed selected entity. + * @param selectedEntity selected entity to be edited or null if a new one should be created and added + * @return a reference to the created BaseFormDialog + */ + LAEFormDialog createFactoryForAddOrEdit( final EntityType selectedEntity ); + } + + + /** * Creates a new ListAndEditPanel.
* Sets a BorderLayout for ourselves. + * @param panelTitle title of the list and edit panel * @param entityName name of the listed and edited entity (this will be displayed on the buttons) * @param entityList reference to the list whose elements are to be listed and edited, and where to put new entities + * @param baseFormDialogFactory reference to a base form dialog factory */ - public ListAndEditPanel( final String entityName, final List< EntityType > entityList ) { - this( entityName, entityList, null ); + public ListAndEditPanel( final String panelTitle, final String entityName, final List< EntityType > entityList, final LAEFormDialogFactory< EntityType > baseFormDialogFactory ) { + this( panelTitle, entityName, entityList, null, baseFormDialogFactory ); } /** @@ -74,16 +96,18 @@ /** * Creates a new ListAndEditPanel.
* Sets a BorderLayout for ourselves. + * @param panelTitle title of the list and edit panel * @param entityName name of the listed and edited entity (this will be displayed on the buttons) * @param entityList reference to the list whose elements are to be listed and edited, and where to put new entities * @param entityFilter filter to be used when listing the entities + * @param baseFormDialogFactory reference to a base form dialog factory */ - public ListAndEditPanel( final String entityName, final List< EntityType > entityList, final Filter< EntityType > entityFilter ) { + public ListAndEditPanel( final String panelTitle, final String entityName, final List< EntityType > entityList, final Filter< EntityType > entityFilter, final LAEFormDialogFactory< EntityType > baseFormDialogFactory ) { super( new BorderLayout() ); - this.entityList = entityList; + this.entityList = entityList; + this.baseFormDialogFactory = baseFormDialogFactory; - final DefaultListModel listModel = new DefaultListModel(); for ( final EntityType entity : entityList ) if ( entityFilter == null || entityFilter.includeEntity( entity ) ) listModel.addElement( entity ); @@ -88,9 +112,7 @@ if ( entityFilter == null || entityFilter.includeEntity( entity ) ) listModel.addElement( entity ); - entityListComponent.setModel( listModel ); - - buildGUI( entityName ); + buildGUI( panelTitle, entityName ); } /** @@ -95,9 +117,10 @@ /** * Builds the graphical user interface of the panel. + * @param panelTitle title of the list and edit panel * @param entityName name of the listed and edited entity (this will be displayed on the buttons) */ - private void buildGUI( final String entityName ) { + private void buildGUI( final String panelTitle, final String entityName ) { final JPanel buttonsPanel = new JPanel(); addButton .setText ( "Add " + entityName ); @@ -118,6 +141,26 @@ add( buttonsPanel, BorderLayout.NORTH ); add( new JScrollPane( entityListComponent ), BorderLayout.CENTER ); + + setBorder( BorderFactory.createTitledBorder( panelTitle ) ); + } + + /** + * Overrides default mnemonic keys for the add, edit and remove buttons.
+ * If null value is passed as a mnemonic, the mnemonic for that button will not be changed. + * @param addButtonMnemonic new mnemonic for the add button + * @param editButtonMnemonic new mnemonic for the edit button + * @param removeButtonMnemonic new mnemonic for the remove button + */ + public void overrideMnemonics( final Character addButtonMnemonic, final Character editButtonMnemonic, final Character removeButtonMnemonic ) { + if ( addButtonMnemonic != null ) + addButton .setMnemonic( addButtonMnemonic ); + + if ( editButtonMnemonic != null ) + editButton .setMnemonic( editButtonMnemonic ); + + if ( removeButtonMnemonic != null ) + removeButton.setMnemonic( removeButtonMnemonic ); } /** @@ -124,7 +167,25 @@ * Handles the action events of the buttons for adding new, editing and removing entities. * @param ae details of the action event */ + @SuppressWarnings("unchecked") public void actionPerformed( final ActionEvent ae ) { + if ( ae.getSource() == addButton ) { + final LAEFormDialog laeFormDialog = baseFormDialogFactory.createFactoryForAddOrEdit( null ); + laeFormDialog.setVisualizationListForLAE( entityListComponent, listModel ); + laeFormDialog.setVisible( true ); + } else if ( ae.getSource() == editButton ) { + final EntityType selectedEntity = (EntityType) entityListComponent.getSelectedValue(); + if ( selectedEntity != null ) { + final LAEFormDialog laeFormDialog = baseFormDialogFactory.createFactoryForAddOrEdit( selectedEntity ); + laeFormDialog.setVisualizationListForLAE( entityListComponent, listModel ); + laeFormDialog.setVisible( true ); + } + } else if ( ae.getSource() == removeButton ) { + for ( final Object selectedEntityObject : entityListComponent.getSelectedValues() ) { + listModel .removeElement( selectedEntityObject ); + entityList.remove ( selectedEntityObject ); + } + } } } Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/MainFrame.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/MainFrame.java (revision 676240) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/MainFrame.java (working copy) @@ -63,7 +63,7 @@ buildGUI( controller ); setLocation( Consts.MAIN_FRAME_START_POS_X, Consts.MAIN_FRAME_START_POS_X ); - setSize( 500, 500 ); + setSize( Consts.MAIN_FRAME_WIDTH, Consts.MAIN_FRAME_HEIGHT ); setDefaultCloseOperation( DO_NOTHING_ON_CLOSE ); addWindowListener( new WindowAdapter() { public void windowClosing( final WindowEvent we ) { Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/KeystoreEntryEditFormDialog.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/KeystoreEntryEditFormDialog.java (revision 676240) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/KeystoreEntryEditFormDialog.java (working copy) @@ -37,21 +37,21 @@ */ public class KeystoreEntryEditFormDialog extends BaseFormDialog { - /** Reference to the initial editable keystore entry. */ + /** Reference to the initial editable keystore entry or null, if we are creating a new one. */ private final KeystoreEntry initialKeystoreEntry; - /** Reference to the initial editable keystore password URL entry. */ + /** Reference to the initial editable keystore password URL entry. */ private final KeystorePasswordURLEntry initialKeystorePasswordURLEntry; - /** List of policy entries where to store if new entries are to be created. */ + /** List of policy entries where to store if new entry is to be created. */ private final List< PolicyEntry > policyEntryList; - /** Text field to view and edit the value of keystore URL. */ - private final JTextField keystoreURLTextField = new JTextField( 10 ); - /** Text field to view and edit the value of keystore type. */ - private final JTextField keystoreTypeTextField = new JTextField( 10 ); - /** Text field to view and edit the value of keystore provider. */ - private final JTextField keystoreProviderTextField = new JTextField( 10 ); + /** Text field to view and edit the value of keystore URL. */ + private final JTextField keystoreURLTextField = new JTextField( 20 ); + /** Text field to view and edit the value of keystore type. */ + private final JTextField keystoreTypeTextField = new JTextField( 20 ); + /** Text field to view and edit the value of keystore provider. */ + private final JTextField keystoreProviderTextField = new JTextField( 20 ); /** Text field to view and edit the value of keystore password URL. */ - private final JTextField keystorePasswordURLTextField = new JTextField( 10 ); + private final JTextField keystorePasswordURLTextField = new JTextField( 20 ); /** * Creates a new KeystoreEntryEditFormDialog. @@ -57,7 +57,7 @@ * Creates a new KeystoreEntryEditFormDialog. * @param ownerFrame reference to the owner frame * @param ownerEditorPanel reference to the owner editor panel - * @param keystoreEntry reference to the editable keystore entry + * @param keystoreEntry reference to the editable keystore entry or null, if we are creating a new one * @param keystorePasswordURLEntry reference to the editable password URL entry * @param policyEntryList list of policy entries where to store if new entries are to be created */ @@ -68,15 +68,11 @@ this.initialKeystorePasswordURLEntry = keystorePasswordURLEntry; this.policyEntryList = policyEntryList; - buildGUI(); - pack(); - center(); + prepareForDisplay(); } - /** - * Builds the GUI of the dialog. - */ - private void buildGUI() { + @Override + protected void buildGUI() { final JPanel panel = new JPanel( new GridLayout( 4, 2, 5, 10 ) ); panel.add( new JLabel( "KeyStore URL:" ) ); @@ -153,9 +149,7 @@ } } - ownerEditorPanel.setHasDirty( true ); - - dispose(); + finishSuccessfulEdit(); } } Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/LAEFormDialog.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/LAEFormDialog.java (revision 0) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/view/LAEFormDialog.java (revision 0) @@ -0,0 +1,76 @@ +/* + * 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.Dialog; +import java.awt.Frame; + +import javax.swing.DefaultListModel; +import javax.swing.JList; + +/** + * An extended form dialog which is tied to a ListAndEdit component.
+ * The form is destined to view and edit the entities of a ListAndEdit component. + */ +public abstract class LAEFormDialog extends BaseFormDialog { + + /** Reference to the visualization list component of the tied ListAndEdit component. */ + protected JList visualizationJListforLAE; + /** Reference to the model of the visualization list as DefaultListModel. */ + protected DefaultListModel listModel; + + /** + * A delegator constructor toward the ancestor's constructor. + * @param ownerFrame reference to the owner frame + * @param title title of the dialog + * @param ownerEditorPanel reference to the owner editor panel + */ + public LAEFormDialog( final Frame ownerFrame, final String title, final EditorPanel ownerEditorPanel ) { + super( ownerFrame, title, ownerEditorPanel ); + } + + /** + * A delegator constructor toward the ancestor's constructor. + * @param ownerDialog reference to the owner dialog + * @param title title of the dialog + * @param ownerEditorPanel reference to the owner editor panel + */ + public LAEFormDialog( final Dialog ownerDialog, final String title, final EditorPanel ownerEditorPanel ) { + super( ownerDialog, title, ownerEditorPanel ); + } + + /** + * Sets the visualization list component and its list model of the tied ListAndEdit component. + * @param visualizationJListforLAE visualization list component of the tied ListAndEdit component + * @param listModel list model of the visualization list component + */ + public void setVisualizationListForLAE( final JList visualizationJListforLAE, final DefaultListModel listModel ) { + this.visualizationJListforLAE = visualizationJListforLAE; + this.listModel = listModel; + } + + /** + * Refreshes the visualization list.
+ * 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(); + } + +} Index: modules/tools/src/main/java/org/apache/harmony/tools/policytool/Consts.java =================================================================== --- modules/tools/src/main/java/org/apache/harmony/tools/policytool/Consts.java (revision 676240) +++ modules/tools/src/main/java/org/apache/harmony/tools/policytool/Consts.java (working copy) @@ -29,6 +29,10 @@ public static final int MAIN_FRAME_START_POS_X = 200; /** Y coordinate of the main frame on startup. */ public static final int MAIN_FRAME_START_POS_Y = 100; + /** Width of the main frame. */ + public static final int MAIN_FRAME_WIDTH = 600; + /** Height of the main frame. */ + public static final int MAIN_FRAME_HEIGHT = 600; /** Font size in the direct editing panel. */ public static final int DIRECT_EDITING_FONT_SIZE = 13;