📄 adminsample.java
字号:
/*
* @author Reghu
* @version 1.0
*
* Development Environment : Oracle9i JDeveloper
* Name of the Application : AdminSample.java
* Creation/Modification History :
*
* Reghu 30-Dec-2002 Created
*
*/
package oracle.otnsamples.vsm.client;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.ArrayList;
import oracle.otnsamples.util.ServiceLocator;
import oracle.otnsamples.vsm.services.Administration;
import oracle.otnsamples.vsm.services.AdministrationHome;
import oracle.otnsamples.vsm.services.MallNavigation;
import oracle.otnsamples.vsm.services.MallNavigationHome;
import oracle.otnsamples.vsm.services.ProfileManagement;
import oracle.otnsamples.vsm.services.ProfileManagementHome;
import oracle.otnsamples.vsm.services.data.Category;
import oracle.otnsamples.vsm.services.data.Country;
import oracle.otnsamples.vsm.services.data.Guestbook;
import oracle.otnsamples.vsm.services.data.Profile;
import oracle.otnsamples.vsm.services.data.Shop;
/**
* This java file contains the business logic of the admin utility of VSM
* application. The business logic includes managing the categories of the
* mall, Approving/rejecting the new shop requests, managing the guest book
* entries etc. The GUI for this sample is handled in AdminFrame.java
*
* @author Reghu
* @version 1.0
*/
public class AdminSample {
AdminFrame gui;
private ArrayList countryList = new ArrayList();
/**
* Constructor , instantiates GUI.
*/
public AdminSample() {
gui = new AdminFrame(this); // Instantiate GUI
// Diplay the frame in the center of screen
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = gui.getSize();
if(frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if(frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
gui.setLocation(
(screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
gui.setVisible(true);
}
/**
* Main entry point for the class which instantiates the AdminSample
*/
public static void init() {
AdminSample adm = new AdminSample(); // Instantiate DMLSample class
adm.displayCategories();
adm.displayGuestBook();
adm.displayShops();
adm.getUserData("admin");
}
/**
* This method fetches the user details from the database and populates the
* corresponding UI. In this scenario it fetches the use details of the mall
* administrator and populate the Swing UI.
*
* @param userName Name of the user
*/
protected void getUserData(String userName) {
ProfileManagement profRemote = null;
MallNavigation mallRemote = null;
try {
// Get the EJB Home
ProfileManagementHome profHome =
(ProfileManagementHome) ServiceLocator.getLocator().getService("ProfileManagement");
// Get Remote Interface
profRemote = profHome.create();
Profile prof = profRemote.getProfile(userName);
// Get the EJB Home
MallNavigationHome mallHome =
(MallNavigationHome) ServiceLocator.getLocator().getService("MallNavigation");
// Get Remote Interface
mallRemote = mallHome.create();
if(countryList.isEmpty()) {
Country[] cntry = mallRemote.getCountries();
for(int i = 0; i < cntry.length; i++) {
countryList.add(cntry [ i ]);
}
}
// Get the values from the bean and set with the UI
gui.fname.setText(prof.getFirstName());
gui.lname.setText(prof.getLastName());
gui.address.setText(prof.getAddress());
gui.zip.setText(prof.getZip().toString());
gui.email.setText(prof.getEmail());
gui.city.setText(prof.getCity());
gui.state.setText(prof.getState());
int selectedIndex = -1;
for(int i = 0; i < countryList.size(); i++) {
Country country = (Country) countryList.get(i);
gui.country.insertItemAt(country.getCountryName(), i);
if(country.getCountryID().equals(prof.getCountryID())) {
selectedIndex = i;
}
}
gui.country.setSelectedIndex(selectedIndex);
gui.phone.setText(prof.getPhone());
gui.password.setText(prof.getPassword());
gui.provider.setText(prof.getCardProvider());
gui.expDate.setText(prof.getCardExpiryDate().toString());
gui.cardNumb.setText(prof.getCardNumber());
} catch(Exception e) {
gui.putStatus("Error in fetching the user details:" + e.getMessage());
} finally {
try {
if(profRemote != null) {
profRemote.remove();
}
if(mallRemote != null) {
mallRemote.remove();
}
} catch(Exception ex) {
// do nothing
}
}
}
/**
* This method updates the user details in the database with the updated
* values in the SWING UI. In this scenario it updates the user details of
* the mall administrator.
*
* @param userName Name of the user
* @param role Role of the user
*/
protected void updateProfile(String userName, String role) {
ProfileManagement profRemote = null;
try {
Profile prof =
new Profile(
userName, gui.fname.getText(), gui.lname.getText(),
gui.email.getText(), gui.address.getText(),
gui.city.getText(), gui.state.getText(),
((Country) countryList.get(gui.country.getSelectedIndex())).getCountryID(),
gui.zip.getText(), gui.phone.getText(), role,
new String(gui.password.getPassword()),
gui.provider.getText(), gui.cardNumb.getText(),
gui.expDate.getText());
// Get the EJB Home
ProfileManagementHome profHome =
(ProfileManagementHome) ServiceLocator.getLocator().getService("ProfileManagement");
// Get Remote Interface
profRemote = profHome.create();
// Execute the method to get the user profile.
profRemote.updateProfile(prof);
gui.putStatus("Successfully updated the user profile");
} catch(Exception e) {
gui.putStatus("Error in updating the user profile:" + e.getMessage());
} finally {
try {
if(profRemote != null) {
profRemote.remove();
}
} catch(Exception ex) {
// do nothing
}
}
}
/**
* This method fetches the guestbook details from the database and populates
* the corresponding UI. The mall admin is having the privileges to manage
* the guestbook entries.
*/
protected void displayGuestBook() {
Administration adminRemote = null;
try {
// Get the EJB Home
AdministrationHome adminHome =
(AdministrationHome) ServiceLocator.getLocator().getService("Administration");
// Get Remote Interface
adminRemote = adminHome.create();
// Execute the method to get the user profile.
Guestbook[] guest = adminRemote.viewGuestbookEntries("en");
// Populate the guestbook data in the arraylist
String rating = "Excellent";
gui.guestmodel.clearTable();
for(int i = 0; i < guest.length; i++) {
ArrayList guestData = new ArrayList();
guestData.add(guest [ i ].getUserName());
guestData.add(guest [ i ].getEmail());
guestData.add(guest [ i ].getCommentDate());
if("1".equalsIgnoreCase(guest [ i ].getRating())) {
rating = "Poor";
} else if("2".equalsIgnoreCase(guest [ i ].getRating())) {
rating = " Good";
} else {
rating = "Excellent";
}
guestData.add(guest [ i ].getComments());
guestData.add(rating);
guestData.add(guest [ i ].getId());
gui.guestmodel.insertRow(guestData); // Insert the data in the table
gui.guestTable.repaint();
}
} catch(Exception e) {
gui.putStatus("Error in fetching the guestbook data: " + e.getMessage());
} finally {
try {
if(adminRemote != null) {
adminRemote.remove();
}
} catch(Exception ex) {
// do nothing
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -