001: // ServerEditor.java
002: // $Id: ServerEditor.java,v 1.15 2000/08/16 21:37:31 ylafon Exp $
003: // (c) COPYRIGHT MIT and INRIA, 1998.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005:
006: package org.w3c.jigadmin.editors;
007:
008: import java.awt.GridLayout;
009: import java.awt.Font;
010: import java.awt.Component;
011: import java.awt.BorderLayout;
012:
013: import javax.swing.JPanel;
014: import javax.swing.JLabel;
015: import javax.swing.BorderFactory;
016: import javax.swing.JTabbedPane;
017: import javax.swing.border.TitledBorder;
018: import javax.swing.event.ChangeListener;
019:
020: import java.util.Properties;
021:
022: import org.w3c.jigadmin.RemoteResourceWrapper;
023: import org.w3c.jigadmin.widgets.DnDTabbedPane;
024: import org.w3c.jigadmin.events.ResourceActionSource;
025: import org.w3c.jigadmin.events.ResourceActionListener;
026:
027: import org.w3c.jigsaw.admin.RemoteResource;
028: import org.w3c.jigsaw.admin.RemoteAccessException;
029:
030: import org.w3c.tools.widgets.Utilities;
031: import org.w3c.tools.sorter.Sorter;
032:
033: /**
034: * The server editor.
035: * @version $Revision: 1.15 $
036: * @author Benoît Mahé (bmahe@w3.org)
037: */
038: public class ServerEditor extends JPanel implements
039: ServerEditorInterface {
040:
041: private class Retryer extends Thread {
042:
043: RemoteAccessException ex = null;
044:
045: public void run() {
046: while (server.getServerBrowser().shouldRetry(ex)) {
047: try {
048: initializeServerHelpers();
049: break;
050: } catch (RemoteAccessException ex2) {
051: ex = ex2;
052: }
053: }
054: build();
055: }
056:
057: private Retryer(RemoteAccessException ex) {
058: this .ex = ex;
059: }
060: }
061:
062: protected RemoteResourceWrapper server = null;
063: protected String name = null;
064: protected ServerHelperInterface shelpers[] = null;
065:
066: /**
067: * Reload the server configuration.
068: * @param server the new server wrapper
069: */
070: public void setServer(RemoteResourceWrapper server) {
071: this .server = server;
072: try {
073: initializeServerHelpers();
074: build();
075: } catch (RemoteAccessException ex) {
076: (new Retryer(ex)).start();
077: }
078: }
079:
080: /**
081: * Get the component.
082: * @return a Component
083: */
084: public Component getComponent() {
085: return this ;
086: }
087:
088: /**
089: * initialize the server helpers.
090: * @exception RemoteAccessException if a remote error occurs
091: */
092: protected void initializeServerHelpers()
093: throws RemoteAccessException {
094: shelpers = null;
095: //use ServerHelperFactory....
096: RemoteResource rr = server.getResource();
097: String names[] = rr.enumerateResourceIdentifiers();
098: Sorter.sortStringArray(names, true);
099: shelpers = new ServerHelperInterface[names.length];
100: for (int i = 0; i < names.length; i++) {
101: RemoteResourceWrapper rrw = server
102: .getChildResource(names[i]);
103: shelpers[i] = ServerHelperFactory.getServerHelper(names[i],
104: rrw);
105: }
106:
107: for (int i = 0; i < shelpers.length; i++) {
108: if (shelpers[i] instanceof ResourceActionSource) {
109: ResourceActionSource source = (ResourceActionSource) shelpers[i];
110: for (int j = 0; j < shelpers.length; j++) {
111: if (j != i) {
112: if (shelpers[j] instanceof ResourceActionListener) {
113: ResourceActionListener listener = (ResourceActionListener) shelpers[j];
114: source.addResourceActionListener(listener);
115: }
116: }
117: }
118: }
119: }
120: }
121:
122: /**
123: * Build the interface.
124: */
125: protected void build() {
126: removeAll();
127: invalidate();
128: setLayout(new BorderLayout());
129: TitledBorder border = BorderFactory.createTitledBorder(name);
130: border.setTitleFont(Utilities.reallyBigBoldFont);
131: setBorder(border);
132: //tabbedpane
133: JTabbedPane tabbedPane = new DnDTabbedPane();
134: if (shelpers == null)
135: return;
136:
137: for (int i = 0; i < shelpers.length; i++) {
138: if (shelpers[i] instanceof ChangeListener)
139: tabbedPane
140: .addChangeListener((ChangeListener) shelpers[i]);
141:
142: if (shelpers[i] instanceof ControlServerHelper) {
143: //add it on top of the panel
144: add(shelpers[i].getComponent(), BorderLayout.NORTH);
145: } else {
146: String name = shelpers[i].getName().replace('_', ' ');
147: char chars[] = name.toCharArray();
148: chars[0] = Character.toUpperCase(chars[0]);
149: String helperName = new String(chars);
150: tabbedPane.addTab(helperName, null, shelpers[i]
151: .getComponent(), shelpers[i].getToolTip());
152: }
153: }
154: tabbedPane.setSelectedIndex(0);
155: add(tabbedPane, BorderLayout.CENTER);
156: validate();
157: }
158:
159: /**
160: * Initialize this editor.
161: * @param name the editor name
162: * @param rrw the RemoteResourceWrapper wrapping the editor node.
163: * @param p the editor properties
164: */
165: public void initialize(String name, RemoteResourceWrapper rrw,
166: Properties p) {
167: this .server = rrw;
168: this .name = name;
169: }
170:
171: public ServerEditor() {
172: //for new Isntance
173: }
174:
175: }
|