001: // UsersHelper.java
002: // $Id: UsersHelper.java,v 1.8 2000/08/16 21:37:28 ylafon Exp $
003: // (c) COPYRIGHT MIT and INRIA, 1997.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005:
006: package org.w3c.jigadm.editors;
007:
008: import java.awt.BorderLayout;
009: import java.awt.Button;
010: import java.awt.Component;
011: import java.awt.Container;
012: import java.awt.GridBagConstraints;
013: import java.awt.GridBagLayout;
014: import java.awt.Label;
015: import java.awt.Panel;
016: import java.awt.TextComponent;
017: import java.awt.TextField;
018:
019: import java.awt.event.ActionEvent;
020: import java.awt.event.ActionListener;
021:
022: import java.util.Properties;
023:
024: import org.w3c.jigadm.RemoteResourceWrapper;
025:
026: import org.w3c.jigsaw.admin.RemoteAccessException;
027: import org.w3c.jigsaw.admin.RemoteResource;
028:
029: import org.w3c.tools.resources.Attribute;
030:
031: public class UsersHelper extends ResourceHelper {
032:
033: class AddUserListener implements ActionListener {
034:
035: public void actionPerformed(ActionEvent ae) {
036: addUser();
037: }
038: }
039:
040: RemoteResourceWrapper rrw = null;
041: RemoteResource rr = null;
042: private boolean initialized = false;
043: TextField tf;
044: Panel widget;
045:
046: protected void addUser() {
047: if (tf.getText().length() > 0) {
048: RemoteResource nrr;
049: try {
050: nrr = rrw.getResource().registerResource(tf.getText(),
051: "org.w3c.jigsaw.auth.AuthUser");
052: } catch (RemoteAccessException ex) {
053: errorPopup("RemoteAccessException", ex);
054: return;
055: }
056: RemoteResourceWrapper nrrw;
057: nrrw = new RemoteResourceWrapper(rrw, nrr, rrw.getBrowser());
058: rrw.getBrowser().insertNode(rrw, nrrw, tf.getText());
059: }
060: }
061:
062: protected RemoteResourceWrapper getWrapper() {
063: return rrw;
064: }
065:
066: public Component getComponent() {
067: return widget;
068: }
069:
070: public void commitChanges() {
071: }
072:
073: public boolean hasChanged() {
074: return false;
075: }
076:
077: public void resetChanges() {
078: }
079:
080: public void clearChanged() {
081: }
082:
083: public final String getTitle() {
084: return "Users";
085: }
086:
087: public UsersHelper() {
088: widget = new Panel();
089: }
090:
091: protected void initAddPanel() {
092: GridBagLayout gbl = new GridBagLayout();
093: GridBagConstraints gbc = new GridBagConstraints();
094: AddUserListener aul = new AddUserListener();
095: Panel p = new Panel(gbl);
096: Label l;
097: gbc.fill = GridBagConstraints.HORIZONTAL;
098: gbc.weightx = 0;
099: gbc.weighty = 0;
100: tf = new TextField(15);
101: tf.addActionListener(aul);
102: l = new Label("User name", Label.RIGHT);
103: gbc.gridwidth = 1;
104: gbl.setConstraints(l, gbc);
105: p.add(l);
106: gbc.gridwidth = GridBagConstraints.REMAINDER;
107: gbl.setConstraints(tf, gbc);
108: p.add(tf);
109: widget.add("Center", p);
110: Button newb = new Button("Add User");
111: newb.addActionListener(aul);
112: widget.add("South", newb);
113: }
114:
115: /**
116: * initialize this helper
117: * @param rrw The RemoteResourceWrapper
118: * @param pr The properties
119: * @exception RemoteAccessException if a remote access error occurs.
120: */
121: public void initialize(RemoteResourceWrapper rrw, Properties pr)
122: throws RemoteAccessException {
123: if (!initialized)
124: initialized = true;
125: else
126: return;
127:
128: this .rrw = rrw;
129: rr = rrw.getResource();
130:
131: if (rr.isContainer()) {
132: widget.setLayout(new BorderLayout());
133: initAddPanel();
134: }
135: }
136: }
|