Define a UserFilter
Description:
Once you have a huge amount of registered Users in your application, you may want to display only a certain
amount of them. This can be accomplished by the UserFilter.
UserFilter is an interface, but don't worry, there's not much to implement. You only have to define the method
match(User user), which shall return true when the User matches the criteria you want
him to be displayed for.
Used classes:
Related topics:
ToDo:
-
Create a class implementing
UserFilter. -
Add the constructor and invoke the
superconstructor. -
Implement the
public boolean match(User user)method.
Therein decide which user shall be filtered and which not.
Example Source Code:
1 public class DisplayUserFilter implements UserFilter { 2 public DisplayUserFilter() { super(); } 3 public boolean match(User user) { return user.getCapability("AdminRights").isGranted(); } }
Back to:
Display Users in a JUserList
Description:
Like TableFormSheets display the content of CountingStocks or Catalogs, a
JUserList displays the Users managed by a UserManager.
The JUserList is a JComponent and thereby can easily be displayed by a FormSheet. In
this example we do not only display the Users, but use the method User.getCapabilityCheckBox(), too,
so we can also edit the Capabilities of a User.
With the UserManager determined as the GlobalUM, the JUserList can be initialized with
its default constructor and will use the GlobalUM. Otherwise you have to initialize it with the
UserManager you want to display the content of.
The JUserList being a JComponent makes it possible to add other components to it, like in this case
the JCheckBox. It is disabled at first, because initially no User is being selected in the
JUserList.
In order to enable the CheckBox after a selection, we added a ListSelectionListener to the
JUserList and let the valueChanged(ListSelectionEvent) method update the CheckBox.
In this example we put all this into a SaleProcess, which is the easiest way, but not the only one. Be careful to
initialize the UIGate with the new FormSheet and then add the JComponent to the
Formsheet, otherwise the Gate won't display the JUserList.
For more information about processes, please refer to the section Processes.
Used classes:
Related topics:
ToDo:
-
Add a
JUserListto the attributes of theSaleProcessin order to make it available all over the process. Do the same for aJCheckBox,TransitionandUIGate. All four will be needed. -
In your
Gateinitialize theJUserList. The default constructor will do, because we use only oneUserManagerand declared itGlobalUMin theShopinstance. -
Before we add the
JCheckBoxthat later on will be theCapabilityCheckBox, we set the Layout of theJUserListand after that add the blankJCheckBox. -
In order to update the state of the
JCheckBox, add aListSelectionListenerto theJUserList. This will enable theJCheckBoxas soon as aUseris selected in the List and even update the value of theJCheckBoxreferring to the selectedUser. -
Create a
FormSheet(with buttons and so on, set byFormSheetContentCreator) where theJUserListwill be displayed in. -
Create a new
UIGatecontaining thatFormSheet. -
Call
FormSheet.setComponentat theFormSheetabove to display theJUserListand theUIGateis ready to be displayed. -
Instantiate the
Transitionthat updates theJCheckbox. Therein remove the old Box, create a new from theJUserList, add it to theJUserListand return theUIGatefrom theperformmethod.
The order of the last two steps is quite important, because the other way around (first setting the Component to
the FormSheet and then adding it to the UIGate), the Gate won't display the
JUserList!
Example Source Code:
public class DisplaySaleProcess extends SaleProcess
{
1
private JUserList userList;
private JCheckBox checkBox;
private Transition transitionSelect;
private UIGate uig_user;
public Gate getUserGate()
{
2
userList = new JUserList();
3
userList.setLayout(new GridLayout());
checkBox = new JCheckBox();
userList.add(checkBox);
4
userList.addListSelectionListener(new ListSelectionListener()
{
public void valueChanged(ListSelectionEvent listSelectionEvent)
{
uig_user.setNextTransition((Transition) transitionSelect);
}
}
);
5
FormSheet formSheet = new FormSheet("UserEditor", null);
formSheet.addContentCreator(
new DisplayFormSheetContentCreator());
6
uig_user = new UIGate(formSheet, null);
7
formSheet.setComponent(userList);
8
transitionSelect = new Transition()
{
public Gate perform(SaleProcess process, User user)
{
userList.remove(checkBox);
checkBox = userList.getSelectedUser().getCapabilityCheckBox("Office");
userList.add(checkBox);
return uig_user;
}
};
return uig_user;
}
}
Back to:
Define a User's Capability
Description:
To display the status of a user's Capability, the class User has the method
getCapabilityCheckBox(String nameOfCap). This will return a JCheckBox with the DisplayName of the
Capability on it and it will be checked or not, depending on wether the user is granted that capability.
The tricky thing about this is the CapabilityDisplayName which is used as the caption of the
JCheckBox. You have to extend the java.util.ResourceBundle at first and put the DisplayName (the +
caption matching to the locale) into the keyList. For more information on ResourceBundles go to
ResourceBundle of the Java
API and
setDisplayNameResourceBundleName
of the Framework API.
For the complete example refer to Display Users in a JUserList.
Used classes:
Related topics:
ToDo:
-
Resolve the
Useryou want to display theCapabilityof and call thegetCapabilityCheckBox(String nameOfCap)method in order to get theJCheckBox. -
Add the
JCheckBoxto theContaineryou want it to be displayed in.
You don't have to take care about any action triggered by the CheckBox. The status of the Capability will be updated automatically at the User by the Framework, so it can also be used to edit the Capabilites.
Example Source Code:
1
checkBox = userList.getSelectedUser().getCapabilityCheckBox("Office");
2
userList.add(checkBox);
Back to:
Use a LogOnForm
Description:
A LogOnForm is a special FormSheet with a ComboBox and an optional PasswordField.
It can be used where ever you want a User to be identified. The ComboBox will show the Users stored
in the UserManager and in the PasswordField you can enter the password.
If the identification has been successful, the LogOnForm will return the User that was identified,
otherwise null.
Used classes:
Related topics:
- none
ToDo:
-
Instantiate the
LogOnFormwith- its title
- the prompt of the ComboBox
- the prompt of the PasswordField
- boolean wether password is needed or not
-
the
UserManagerstoring the User to be identified -
a
Comparatorfor the appearance of theUsers.
(null ->Userswill be ordered by their names) -
a
Filterin order to display only certainUsers.
(null -> allUserswill be displayed)
-
Display the
FormSheet.
The method getResult() will return the User if the identification was successful, else null.
Example Source Code:
1
LogOnForm formLogOn = new LogOnForm(
"Please identify yourself",
"Username: ",
"Password: ",
true,
UserManager.getGlobalUM(),
null,
null);
2
uig_logon.setFormSheet(formLogOn);
Back to:
Display: LogFile Management | Display: Tables ![]() |
Display: LogFile Management