From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4506 invoked by alias); 9 Jun 2004 05:58:03 -0000 Mailing-List: contact rhdb-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Post: List-Help: , Sender: rhdb-owner@sources.redhat.com Received: (qmail 4498 invoked from network); 9 Jun 2004 05:58:01 -0000 Received: from unknown (HELO web61104.mail.yahoo.com) (216.155.196.106) by sourceware.org with SMTP; 9 Jun 2004 05:58:01 -0000 Message-ID: <20040609055801.86333.qmail@web61104.mail.yahoo.com> Received: from [66.185.84.73] by web61104.mail.yahoo.com via HTTP; Wed, 09 Jun 2004 01:58:01 EDT Date: Wed, 09 Jun 2004 05:58:00 -0000 From: Deepak B Subject: Re: Final set of changes to Administrator 2.0 (Java) for PostgreSQL 7.4 series. To: rhdb@sources.redhat.com MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="0-1098252433-1086760681=:85636" X-SW-Source: 2004-q2/txt/msg00003.txt.bz2 --0-1098252433-1086760681=:85636 Content-Type: text/plain; charset=us-ascii Content-Id: Content-Disposition: inline Content-length: 503 --- Deepak B wrote: > A bit late, but better than never :) > > This patch brings Administrator up to speed with > 7.4.x. All privileges items have been fixed to allow Sorry, the PrivilegesCheckBoxPanel.java file was badly intended.. didn't notice it till I saw the mail. Attaching a correctly indented version with this e-mail. Deepak B ______________________________________________________________________ Post your free ad now! http://personals.yahoo.ca --0-1098252433-1086760681=:85636 Content-Type: text/x-java; name="PrivilegesCheckBoxPanel.java" Content-Description: PrivilegesCheckBoxPanel.java Content-Disposition: inline; filename="PrivilegesCheckBoxPanel.java" Content-length: 15572 /* * Copyright (c) 2004 Red Hat, Inc. All rights reserved. * * This software may be freely redistributed under the terms of the * GNU General Public License. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Component of: Administrator GUI tool for PostgreSQL - Red Hat Edition */ package com.redhat.rhdb.admin; /** * A Check Box panel specifically for privileges. *

* Based on com.redhat.rhdb.admin.CheckBoxPanel by Brian Booth * * @author Deepak Bhole * */ public class PrivilegesCheckBoxPanel extends javax.swing.JPanel implements java.awt.event.ActionListener { /** Creates a new instance of PrivilegesCheckBoxPanel */ /** * Creates a CheckBoxPanel with a title * * @param names An array of names associated with the CheckBoxes * @param layout the layout of the panel. Must be either CheckBoxPanel.HORIZONTAL or CheckBoxPanel.VERTICAL * @param title the title of the panel * */ public PrivilegesCheckBoxPanel(String[] names, String title, String secondaryCheckBoxTitle) { jchButtons = new javax.swing.JCheckBox[names.length]; jchSecondaryButtons = new javax.swing.JCheckBox[names.length]; hasChanged = new boolean[names.length]; hasSecondaryChanged = new boolean[names.length]; hasSecondaryCBEnabled = true; hasSecondaryCB = !secondaryCheckBoxTitle.equals(""); java.awt.GridLayout gl; setLayout(new java.awt.GridBagLayout()); java.awt.GridBagConstraints gridBagConstraints; for (int i = 0; i < names.length; i++) { gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 0); gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.gridx = 0; gridBagConstraints.gridy = i; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; jchButtons[i] = new javax.swing.JCheckBox(names[i]); jchButtons[i].setEnabled(false); add(jchButtons[i], gridBagConstraints); hasChanged[i] = false; jchButtons[i].addActionListener(this); if (hasSecondaryCB) { jchSecondaryButtons[i] = new javax.swing.JCheckBox(secondaryCheckBoxTitle); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = i; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; hasSecondaryChanged[i] = false; jchSecondaryButtons[i].setEnabled(false); add(jchSecondaryButtons[i], gridBagConstraints); jchSecondaryButtons[i].addActionListener(this); } } setBorder(new javax.swing.border.TitledBorder(title)); } /**. * For IDE Use. */ public PrivilegesCheckBoxPanel() { super(); } /** * Enables or disables the CheckBoxes * * @param enabled true if the CheckBoxes are enabled, false otherwise. * */ public void setEnabled(boolean enabled) { for (int i = 0; i < jchButtons.length; i++) { jchButtons[i].setEnabled(enabled); if (hasSecondaryCB && jchButtons[i].isSelected()) jchSecondaryButtons[i].setEnabled(hasSecondaryCBEnabled && enabled); } super.setEnabled(enabled); } /** * Deselects all checkboxes and clears history * */ public void reset() { for (int i = 0; i < jchButtons.length; i++) { jchButtons[i].setSelected(false); if (hasSecondaryCB) { jchSecondaryButtons[i].setSelected(false); jchSecondaryButtons[i].setEnabled(false); } hasChanged[i] = false; hasSecondaryChanged[i] = false; } } /** * Gets the text of the selected CheckBoxes * * @return the text associated with the selected CheckBoxes * */ public String[] getSelectedBoxes() { int size = 0; for (int i = 0; i < jchButtons.length; i++) if (jchButtons[i].isSelected()) size++; String[] names = new String[size]; int index = 0; for (int i = 0; i < jchButtons.length; i++) if (jchButtons[i].isSelected()) { names[index] = jchButtons[i].getText(); index++; } return names; } /** * Gets the text of the selected CheckBoxes * * @return the text associated with the selected CheckBoxes * */ public String[] getPrimaryOnlySelectedBoxes() { int size = 0; for (int i = 0; i < jchButtons.length; i++) if (jchButtons[i].isSelected() && !(hasSecondaryCB && jchSecondaryButtons[i].isSelected())) size++; String[] names = new String[size]; int index = 0; for (int i = 0; i < jchButtons.length; i++) if (jchButtons[i].isSelected() && !(hasSecondaryCB && jchSecondaryButtons[i].isSelected())) { names[index] = jchButtons[i].getText(); index++; } return names; } /** * Gets the text of the selected secondary CheckBoxes * * @return the text associated with the selected secondary CheckBoxes * */ public String[] getSelectedSecondaryBoxes() { int size = 0; for (int i = 0; i < jchButtons.length; i++) if (hasSecondaryCB && jchButtons[i].isSelected() && jchSecondaryButtons[i].isSelected()) size++; String[] names = new String[size]; int index = 0; for (int i = 0; i < jchButtons.length; i++) if (hasSecondaryCB && jchButtons[i].isSelected() && jchSecondaryButtons[i].isSelected()) { names[index] = jchButtons[i].getText(); index++; } return names; } /** * Gets the indexes of the selected CheckBoxes * * @return the indexes associated with the selected CheckBoxes * */ public int[] getSelectedIndexes() { int size = 0; for (int i = 0; i < jchButtons.length; i++) if (jchButtons[i].isSelected()) size++; int[] indexes = new int[size]; int index = 0; for (int i = 0; i < jchButtons.length; i++) if (jchButtons[i].isSelected()) { indexes[index] = i; index++; } return indexes; } /** * Gets the indexes of the selected and enabled secondary CheckBoxes * * @return the indexes associated with the selected and enabled secondary CheckBoxes */ public int[] getSelectedSecondaryIndexes() { int size = 0; for (int i = 0; i < jchButtons.length; i++) if (hasSecondaryCB && jchButtons[i].isSelected() && jchSecondaryButtons[i].isSelected()) size++; int[] indexes = new int[size]; int index = 0; for (int i = 0; i < jchButtons.length; i++) if (hasSecondaryCB && jchButtons[i].isSelected() && jchSecondaryButtons[i].isSelected()) { indexes[index] = i; index++; } return indexes; } /** * Checks if the chechbox is selected at the given index * * @return Returns true if the checkbox at 'index' is selected and * false otherwise * */ public boolean isSelected(int index) { return jchButtons[index].isSelected(); } /** * Checks if the secondary chechbox is selected at the given index * * @return Returns true if the checkbox at 'index' is selected and * false otherwise * */ public boolean isSecondarySelected(int index) { if (hasSecondaryCB) return jchSecondaryButtons[index].isSelected(); else return false; } /** * Sets the Selection mode of the CheckBox at the given index * * @param index the index of the RadioButton you want to select * @param isSelect true if the CheckBox is selected, false otherwise * */ public void setSelectedBox(int index, boolean isSelect) { jchButtons[index].setSelected(isSelect); if (isSelect) jchSecondaryButtons[index].setEnabled(true); } /** * Sets the Selection mode of the secondary CheckBox at the given index * * @param index the index of the RadioButton you want to select * @param isSelect true if the CheckBox is selected, false otherwise * */ public void setSelectedSecondaryBox(int index, boolean isSelect) { if (hasSecondaryCB) jchButtons[index].setSelected(isSelect); } /** * Sets the Selection mode of the CheckBoxes at the given indexes * * @param indexes the indexes of the CheckBoxes you want to select * @param isSelect true if the CheckBoxes are selected, false otherwise * */ public void setSelectedBoxes(int[] indexes, boolean isSelect) { for (int i = 0; i < indexes.length; i++) { jchButtons[indexes[i]].setSelected(isSelect); if (hasSecondaryCB && isSelect) jchSecondaryButtons[indexes[i]].setEnabled(hasSecondaryCBEnabled && true); } } /** * Sets the Selection mode of the Secondary CheckBoxes at the given indexes. * Secondary CB's can be selected iff the primary is selected. * * * @param indexes the indexes of the CheckBoxes you want to select * @param isSelect true if the CheckBoxes are selected, false otherwise * */ public void setSelectedSecondaryBoxes(int[] indexes, boolean isSelect) { if (!hasSecondaryCB) return; for (int i = 0; i < indexes.length; i++) { if (jchButtons[indexes[i]].isSelected()) jchSecondaryButtons[indexes[i]].setSelected(isSelect); } } /** * Sets the Selection mode of the first CheckBox with the given text * * @param str the text associated with the CheckBox you want to select * @param isSelect true if the CheckBox is selected, false otherwise * */ public void setSelectedBox(String str, boolean isSelect) { for (int i = 0; i < jchButtons.length; i++) if (str.equals(jchButtons[i].getText())) { jchButtons[i].setSelected(isSelect); if (hasSecondaryCB && isSelect) jchSecondaryButtons[i].setEnabled(hasSecondaryCBEnabled && true); } } /** * Sets the Selection mode of the first secondary CheckBox with the given text (for the primary) * * @param str the text associated with the CheckBox whose secondary you want to select * @param isSelect true if the CheckBox is selected, false otherwise * */ public void setSelectedSecondaryBox(String str, boolean isSelect) { for (int i = 0; i < jchButtons.length; i++) if (hasSecondaryCB && str.equals(jchButtons[i].getText()) && jchButtons[i].isSelected()) jchSecondaryButtons[i].setSelected(isSelect); } /** * Sets the Selection mode of the CheckBoxes that have the given text * * @param str the text associated with the CheckBoxes you want to select * @param isSelect true if the CheckBoxes are selected, false otherwise * */ public void setSelectedBoxes(String[] str, boolean isSelect) { for (int i = 0; i < jchButtons.length; i++) for (int j = 0; j < str.length; j++) if (str[j].equals(jchButtons[i].getText())) { jchSecondaryButtons[i].setSelected(isSelect); if (hasSecondaryCB && isSelect) jchSecondaryButtons[i].setEnabled(hasSecondaryCBEnabled && true); } } /** * Sets the Selection mode of the secondary CheckBoxes whose primary have the given text * * @param str the text associated with the CheckBoxes whose secondary you want to select * @param isSelect true if the CheckBoxes are selected, false otherwise * */ public void setSelectedSecondaryBoxes(String[] str, boolean isSelect) { for (int i = 0; i < jchButtons.length; i++) for (int j = 0; j < str.length; j++) if (hasSecondaryCB && str[j].equals(jchButtons[i].getText()) && jchButtons[i].isSelected()) jchSecondaryButtons[i].setSelected(isSelect); } /** * Gets the indexes of the CheckBoxes whose values have changed (Primary or Secondary). * * @return the indexes associated with the CheckBoxes whose values have changed. * */ public int[] getChangedIndexes() { int size = 0; for (int i = 0; i < hasChanged.length; i++) { if (hasChanged[i] || (hasSecondaryCB && hasSecondaryChanged[i])) size++; } int[] toReturn = new int[size]; int index = 0; for (int i = 0; i < hasChanged.length; i++) if (hasChanged[i] || (hasSecondaryCB && hasSecondaryChanged[i])) { toReturn[index] = i; index++; } return toReturn; } /** * Gets the indexes of the primary CheckBoxes whose values have changed. * * @return the indexes associated with the CheckBoxes whose values have changed. * */ public int[] getChangedPrimaryIndexes() { int size = 0; for (int i = 0; i < hasChanged.length; i++) if (hasChanged[i]) size++; int[] toReturn = new int[size]; int index = 0; for (int i = 0; i < hasChanged.length; i++) if (hasChanged[i]) { toReturn[index] = i; index++; } return toReturn; } /** * Gets the indexes of the secondary CheckBoxes whose values have changed. * * @return the indexes associated with the CheckBoxes whose values have changed. * */ public int[] getChangedSecondaryIndexes() { if (!hasSecondaryCB) { return new int[0]; } int size = 0; for (int i = 0; i < hasChanged.length; i++) if (hasChanged[i]) size++; int[] toReturn = new int[size]; int index = 0; for (int i = 0; i < hasChanged.length; i++) if (hasChanged[i]) { toReturn[index] = i; index++; } return toReturn; } /** * Gets the text of the CheckBoxes whose values have changed. * * @return the text associated with the CheckBoxes whose values have changed. * */ public String[] getChangedStrings() { int size = 0; for (int i = 0; i < hasChanged.length; i++) if (hasChanged[i] || (hasSecondaryCB && hasSecondaryChanged[i])) size++; String[] toReturn = new String[size]; int index = 0; for (int i = 0; i < hasChanged.length; i++) if (hasChanged[i] || (hasSecondaryCB && hasSecondaryChanged[i])) { toReturn[index] = jchButtons[i].getText(); index++; } return toReturn; } /** * Set all secondary checkboxes to given state (selected items are unselected). * * @param enabled The state to set the boxes to. */ public void setSecondaryCBEnabled(boolean enabled) { if (!hasSecondaryCB) return; hasSecondaryCBEnabled = enabled; for (int i=0; i < jchSecondaryButtons.length; i++) { jchSecondaryButtons[i].setSelected(false); jchSecondaryButtons[i].setEnabled(enabled); } } /** * Run whenever a CheckBoxes value changes. Fires a PropertyChangedEvent * * @param evt the selection or de-selection of a CheckBox * */ public void actionPerformed(java.awt.event.ActionEvent evt) { for (int i = 0; i < jchButtons.length; i++) { if (evt.getSource() == jchButtons[i]) hasChanged[i] = !hasChanged[i]; if (hasSecondaryCB && evt.getSource() == jchSecondaryButtons[i]) { hasSecondaryChanged[i] = !hasSecondaryChanged[i]; } if (evt.getSource() == jchButtons[i]) { if (jchButtons[i].isSelected()) { if (hasSecondaryCB) jchSecondaryButtons[i].setEnabled(hasSecondaryCBEnabled && true); } else { if (hasSecondaryCB) jchSecondaryButtons[i].setEnabled(false); } } } firePropertyChange(SELECTION_MADE, !hasChanged[0], hasChanged[0]); } protected javax.swing.JCheckBox[] jchButtons = new javax.swing.JCheckBox[0]; protected javax.swing.JCheckBox[] jchSecondaryButtons = new javax.swing.JCheckBox[0]; protected boolean[] hasChanged = new boolean[0]; protected boolean[] hasSecondaryChanged = new boolean[0]; private boolean hasSecondaryCB = false; private boolean hasSecondaryCBEnabled = true; /** Name of the PropertyChangeEvent */ public static final String SELECTION_MADE = "Check Box Selected"; } --0-1098252433-1086760681=:85636--