KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > adminGui > feature > account > groups > WorkGroupDialog


1 //// You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
package org.ozoneDB.adminGui.feature.account.groups;
8
9 import java.awt.BorderLayout JavaDoc;
10 import java.util.Vector JavaDoc;
11 import javax.swing.JDialog JavaDoc;
12
13 import org.ozoneDB.adminGui.widget.AssignmentPanel;
14 import org.ozoneDB.adminGui.widget.ButtonPanel;
15 import org.ozoneDB.adminGui.widget.ButtonPanelListener;
16 import org.ozoneDB.adminGui.main.AdminGui;
17
18
19 //#############################################################################
20
/**
21  * This class gets a new group name to be created.
22  *
23  * @author <p align=center>Ibsen Ramos-Bonilla
24  * <br>Copyright &copy 1997-@year@ by SMB GmbH. All Rights Reserved.</p>
25  *
26  * @version 1.0
27  */

28 //#############################################################################
29

30 public class WorkGroupDialog extends JDialog JavaDoc implements ButtonPanelListener {
31
32     /** Group calling the work dialog. */
33     private String JavaDoc group = null;
34     /** A list of account names. */
35     private Vector JavaDoc userNames = null;
36     /** A list of assigned account names. */
37     private Vector JavaDoc assignedUserNames = null;
38     /** Panel used to get the group name. */
39     private WorkGroupPanel groupPane = null;
40     /** Panel used to assign users at time of group creation. */
41     private AssignmentPanel assignPane = null;
42     /** List of buttons for the button panel. */
43     private String JavaDoc[] button = {"OK", "Cancel"};
44     /** Flag to monitor if the ok buttons was clicked. */
45     private boolean ok = false;
46
47
48     /**
49      * Overloaded constructor creates the work group dialog from a new group.
50      *
51      * @param userNames - the list of names available for use.
52      */

53     public WorkGroupDialog(Vector JavaDoc userNames) {
54         super(AdminGui.instance(), "Create Group", true);
55         this.userNames = userNames;
56
57         try {
58             init();
59             this.setSize(390, 290);
60         } catch (Exception JavaDoc e) {
61             e.printStackTrace();
62         }
63     }
64
65     /**
66      * Overloaded constructor creates the work group dialog from an existing
67      * group.
68      *
69      * @param group - the group name.
70      * @param userNames - the list of names available for use.
71      * @param assignedUserNames - the list of assigned users already in the group.
72      */

73     public WorkGroupDialog(String JavaDoc group, Vector JavaDoc userNames,
74                            Vector JavaDoc assignedUserNames) {
75         super(AdminGui.instance(), "Create Group", true);
76         this.group = group;
77         this.userNames = userNames;
78         this.assignedUserNames = assignedUserNames;
79
80         try {
81             init();
82             this.setSize(390, 290);
83         } catch (Exception JavaDoc e) {
84             e.printStackTrace();
85         }
86     }
87
88     /**
89      * This method initializes the dialog.
90      */

91     private void init() throws Exception JavaDoc {
92         //set dialog attributes
93
this.setResizable(false);
94         this.setLocationRelativeTo(AdminGui.instance());
95         this.getContentPane().setLayout(new BorderLayout JavaDoc());
96
97         //create panels
98
groupPane = new WorkGroupPanel(group);
99         assignPane = new AssignmentPanel("Users", userNames, assignedUserNames);
100
101         ButtonPanel buttonPane = new ButtonPanel(this.button);
102         buttonPane.addConnectionListener(this);
103
104         //add the dialog components
105
this.getContentPane().add(groupPane, BorderLayout.NORTH);
106         this.getContentPane().add(assignPane, BorderLayout.CENTER);
107         this.getContentPane().add(buttonPane, BorderLayout.SOUTH);
108     }
109
110     /**
111      * This method handles the button clicks..
112      *
113      * @param buttonName - name of the button pressed.
114      */

115     public void buttonExecute(String JavaDoc buttonName) {
116         //ok
117
if (button[0].equals(buttonName))
118             collectGroupInfo();
119
120         //cancel
121
else
122             this.hide();
123     }
124
125     /**
126      * This method is called when the ok button is clicked.
127      */

128     private void collectGroupInfo() {
129         this.assignedUserNames = this.assignPane.getAssignedValues();
130         String JavaDoc name = this.groupPane.getGroup().trim();
131
132         //verify that we have a valid entry
133
if (name.equals("") | name == null)
134             this.ok = false;
135         else
136             this.ok = true;
137
138         this.hide();
139     }
140
141     /**
142      * This method returns the group name.
143      *
144      * @return String - the new group name.
145      */

146     public String JavaDoc getName() {
147         return this.groupPane.getGroup();
148     }
149
150     /**
151      * This method denotes if the ok button was pushed.
152      *
153      * @return boolean - TRUE = OK button pushed.
154      * FALSE = Cancel button pushed.
155      */

156     public boolean isOK() {
157         return this.ok;
158     }
159
160     /**
161      * This method returns a list of the names selected in the Users list.
162      *
163      * @return Vector - a list of assigned account names.
164      */

165     public Vector JavaDoc getUsers() {
166         return this.assignedUserNames;
167     }
168
169 } //--------------------------------- E O F -----------------------------------
170
Popular Tags