/* * AccountContentManagerApplet.java * */ import java.applet.*; import java.awt.*; import java.net.*; import java.util.*; import sunw.admin.avm.base.*; public class AccountContentManagerApplet extends Applet { TopLevelContentManager mgr; ContentManager users; Image userImg; org.omg.CORBA.ORB orb; sysagent.AccountFactory accountFactory; sysagent.Account accounts[]; Vector userVals = new Vector(); public void init() { System.err.println("Initializing applet."); // initialize the ORB System.err.print("Initializing ORB ..."); orb = org.omg.CORBA.ORB.init(this); System.err.println("o.k."); // get a reference for the account factory accountFactory = sysagent.AccountFactoryHelper.bind(orb, "AccountFactory"); accounts = accountFactory.list(); System.err.println("Bound to account factory."); for(int i=0; i < accounts.length; i++) { System.err.println("account.Login() = " + accounts[i].Login()); Vector accountVector = new Vector(); accountVector.addElement(accounts[i].Login()); accountVector.addElement(accounts[i].Password()); accountVector.addElement(new Long(accounts[i].ID()).toString()); accountVector.addElement(new Long(accounts[i].GID()).toString()); accountVector.addElement(accounts[i].Comment()); accountVector.addElement(accounts[i].Home()); accountVector.addElement(accounts[i].Shell()); userVals.addElement(accountVector); } System.err.println("Done collecting account data."); setLayout(new BorderLayout()); Context.setProperty("headerBackground", new Color(70,70,170)); Context.setProperty("headerForeground", Color.white); try { userImg = Context.getImage("images/user.gif", this); } catch (MalformedURLException e) { System.out.println("Invalid URL"); } add("Center", mgr = new TopLevelContentManager()); mgr.add("Center", users = new AccountContentMgr("Users", userImg, userVals)); users.addItemListener(mgr); mgr.select(users); } } class AccountContentMgr extends SimpleContentManager { static private Command[] listCmds = new Command[4]; static { listCmds[0] = new PropertiesCommand(); listCmds[1] = new FilterCommand(); listCmds[2] = new SortCommand(); listCmds[3] = new DisplayCommand(); } public AccountContentMgr(String title, Image img, Vector userVals) { super(title, img); // Set Table parameters Table table = getTable(); table.setNumColumns(7); table.setColumnWidthInChars(0, 8); table.setColumnWidthInChars(1, 15); table.setColumnWidthInChars(2, 5); table.setColumnWidthInChars(3, 5); table.setColumnWidthInChars(4, 20); table.setColumnWidthInChars(5, 23); table.setColumnWidthInChars(6, 15); // Set up menus setCommands(Selectable.VIEW_COMMANDS, listCmds); // Create TableData, plus Filter, Sort, and View pipes. setTableData(new TableData(userVals)); String[] cols = new String[7]; cols[0] = "Login"; cols[1] = "Password"; cols[2] = "User ID"; cols[3] = "Group ID"; cols[4] = "Comment"; cols[5] = "Home Directory"; cols[6] = "Shell"; setQuerySpace(makeQuerySpace()); setFilterPipe(new TableFilterPipe(getTableData(), cols)); setSortPipe(new TableSortPipe(getFilterPipe(), cols)); int[] wids = new int[7]; wids[0] = 8; wids[1] = 15; wids[2] = 5; wids[3] = 5; wids[4] = 20; wids[5] = 23; wids[6] = 15; setViewPipe(new TableViewPropertiesPipe(getSortPipe(), cols, wids)); getViewPipe().addObserver(this); getTableData().changed(); } private QuerySpace makeQuerySpace() { QuerySpace qs = new QuerySpace(); QueryRelation relation[] = {QueryRelation.MATCHES}; Vector values; // Login values = new Vector(); values.addElement("*"); qs.add("Account", "Login", QueryType.STRING, relation, values); //Password values = new Vector(); values.addElement("*"); qs.add("Account", "Password", QueryType.STRING, relation, values); // User ID values = new Vector(); values.addElement("*"); qs.add("Account", "User ID", QueryType.STRING, relation, values); // Group ID values = new Vector(); values.addElement("*"); qs.add("Account", "Group ID", QueryType.STRING, relation, values); // Comment values = new Vector(); values.addElement("*"); qs.add("Account", "Comment", QueryType.STRING, relation, values); // Home Directory values = new Vector(); values.addElement("*"); qs.add("Account", "Home Directory", QueryType.STRING, relation, values); // Shell values = new Vector(); values.addElement("*"); qs.add("Account", "Shell", QueryType.STRING, relation, values); return qs; } }