001: // ControlServerHelper.java
002: // $Id: ControlServerHelper.java,v 1.12 2000/08/16 21:37:30 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 javax.swing.JPanel;
009:
010: import java.awt.Component;
011: import java.awt.Cursor;
012:
013: import java.awt.event.ActionEvent;
014: import java.awt.event.ActionListener;
015:
016: import javax.swing.ImageIcon;
017: import javax.swing.JToolBar;
018: import javax.swing.JButton;
019:
020: import java.util.Properties;
021: import java.util.Vector;
022:
023: import org.w3c.jigadmin.RemoteResourceWrapper;
024: import org.w3c.jigadmin.gui.Message;
025: import org.w3c.jigadmin.events.ResourceActionEvent;
026: import org.w3c.jigadmin.events.ResourceActionSource;
027: import org.w3c.jigadmin.events.ResourceActionListener;
028: import org.w3c.jigadmin.widgets.Icons;
029:
030: import org.w3c.jigsaw.admin.RemoteAccessException;
031:
032: import org.w3c.tools.widgets.Utilities;
033:
034: /**
035: * The server helper for the control resource.
036: * @version $Revision: 1.12 $
037: * @author Benoît Mahé (bmahe@w3.org)
038: */
039: public class ControlServerHelper extends JToolBar implements
040: ServerHelperInterface, ResourceActionSource {
041: protected RemoteResourceWrapper control = null;
042:
043: protected Vector listeners = null;
044:
045: protected String name = null;
046: protected String tooltip = null;
047:
048: protected final static String SAVE_A = "save";
049: protected final static String STOP_A = "stop";
050: protected final static String HELP_A = "help";
051: protected final static String DELE_A = "del";
052: protected final static String ADD_A = "add";
053: protected final static String REIN_A = "reindx";
054: protected final static String REFE_A = "reference";
055: protected final static String EDIT_A = "edit";
056:
057: protected String saveBTT = null;
058: protected String stopBTT = null;
059: protected String helpBTT = null;
060: protected String deleBTT = null;
061: protected String addBTT = null;
062: protected String reinBTT = null;
063: protected String refeBTT = null;
064: protected String editBTT = null;
065:
066: boolean res_op_enabled = true;
067: boolean built = false;
068:
069: /**
070: * Our internal ActionListener.
071: */
072: ActionListener al = new ActionListener() {
073: public void actionPerformed(ActionEvent ae) {
074: String command = ae.getActionCommand();
075: control.getServerBrowser().setCursor(Cursor.WAIT_CURSOR);
076: if (command.equals(HELP_A)) {
077: try {
078: String url = (String) control.getResource()
079: .getValue("help-url");
080: MiniBrowser.showDocumentationURL(url,
081: "Documentation");
082: } catch (RemoteAccessException ex) {
083: ex.printStackTrace();
084: } catch (Exception ex) {
085: }
086: } else if (command.equals(DELE_A)) {
087: fireResourceEvent(ResourceActionEvent.DELETE_EVENT);
088: } else if (command.equals(ADD_A)) {
089: fireResourceEvent(ResourceActionEvent.ADD_EVENT);
090: } else if (command.equals(STOP_A)) {
091: fireResourceEvent(ResourceActionEvent.STOP_EVENT);
092: try {
093: control.getChildResource(ae.getActionCommand());
094: } catch (RemoteAccessException ex) {
095: Message.showErrorMessage(ControlServerHelper.this ,
096: ex);
097: }
098: } else if (command.equals(SAVE_A)) {
099: fireResourceEvent(ResourceActionEvent.SAVE_EVENT);
100: try {
101: control.getChildResource(ae.getActionCommand());
102: } catch (RemoteAccessException ex) {
103: Message.showErrorMessage(ControlServerHelper.this ,
104: ex);
105: }
106: } else if (command.equals(REIN_A)) {
107: fireResourceEvent(ResourceActionEvent.REINDEX_EVENT);
108: } else if (command.equals(REFE_A)) {
109: fireResourceEvent(ResourceActionEvent.REFERENCE_EVENT);
110: } else if (command.equals(EDIT_A)) {
111: fireResourceEvent(ResourceActionEvent.EDIT_EVENT);
112: }
113: control.getServerBrowser().setCursor(Cursor.DEFAULT_CURSOR);
114: }
115: };
116:
117: /**
118: * Add a ResourceActionListener.
119: * @param listener the ResourceActionListener to add
120: */
121: public void addResourceActionListener(
122: ResourceActionListener listener) {
123: if (listeners == null)
124: listeners = new Vector(1);
125: listeners.addElement(listener);
126: }
127:
128: /**
129: * Remove a ResourceActionListener.
130: * @param listener the ResourceActionListener to remove
131: */
132: public void removeResourceActionListener(
133: ResourceActionListener listener) {
134: if (listeners == null)
135: return;
136: listeners.removeElement(listener);
137: }
138:
139: /**
140: * Fire a resource event.
141: * @param type the resource event type
142: * @see org.w3c.jigadmin.event.ResourceActionEvent
143: */
144: protected void fireResourceEvent(int type) {
145: if (listeners == null)
146: return;
147: ResourceActionEvent ev = new ResourceActionEvent(this , type);
148: for (int i = 0; i < listeners.size(); i++)
149: ((ResourceActionListener) listeners.elementAt(i))
150: .resourceActionPerformed(ev);
151: }
152:
153: /**
154: * Enable or disable the resource operations.
155: * @param onoff a boolean.
156: */
157: public void setResOpEnabled(boolean onoff) {
158: res_op_enabled = onoff;
159: }
160:
161: /**
162: * Set the tooltip for the save button.
163: * @param tooltip the tooltip
164: */
165: public void setSaveToolTipText(String tooltip) {
166: saveBTT = tooltip;
167: }
168:
169: /**
170: * Set the tooltip for the stop button.
171: * @param tooltip the tooltip
172: */
173: public void setStopToolTipText(String tooltip) {
174: stopBTT = tooltip;
175: }
176:
177: /**
178: * Set the tooltip for the help button.
179: * @param tooltip the tooltip
180: */
181: public void setHelpToolTipText(String tooltip) {
182: helpBTT = tooltip;
183: }
184:
185: /**
186: * Set the tooltip for the delete button.
187: * @param tooltip the tooltip
188: */
189: public void setDeleteToolTipText(String tooltip) {
190: deleBTT = tooltip;
191: }
192:
193: /**
194: * Set the tooltip for the add button.
195: * @param tooltip the tooltip
196: */
197: public void setAddToolTipText(String tooltip) {
198: addBTT = tooltip;
199: }
200:
201: /**
202: * Set the tooltip for the reindex button.
203: * @param tooltip the tooltip
204: */
205: public void setReindexToolTipText(String tooltip) {
206: reinBTT = tooltip;
207: }
208:
209: /**
210: * Set the tooltip for the information button.
211: * @param tooltip the tooltip
212: */
213: public void setReferenceToolTipText(String tooltip) {
214: refeBTT = tooltip;
215: }
216:
217: /**
218: * Set the tooltip for the edit button.
219: * @param tooltip the tooltip
220: */
221: public void setEditToolTipText(String tooltip) {
222: editBTT = tooltip;
223: }
224:
225: /**
226: * Initialize this editor.
227: * @param name the editor name
228: * @param rrw the RemoteResourceWrapper wrapping the editor node.
229: * @param p the editor properties
230: */
231: public void initialize(String name, RemoteResourceWrapper rrw,
232: Properties p) {
233: this .control = rrw;
234: this .name = name;
235: this .tooltip = (String) p.get(TOOLTIP_P);
236: }
237:
238: /**
239: * Build the interface.
240: */
241: protected void build() {
242: JButton saveB = (JButton) add(new JButton(Icons.saveIcon));
243: if (saveBTT == null)
244: saveBTT = "Save the configuration";
245: saveB.setToolTipText(saveBTT);
246: saveB.setMargin(Utilities.insets0);
247: saveB.setActionCommand(SAVE_A);
248: saveB.addActionListener(al);
249:
250: addSeparator(Utilities.dim3_3);
251:
252: JButton stopB = (JButton) add(new JButton(Icons.stopIcon));
253: if (stopBTT == null)
254: stopBTT = "Stop the server";
255: stopB.setToolTipText(stopBTT);
256: stopB.setMargin(Utilities.insets0);
257: stopB.setActionCommand(STOP_A);
258: stopB.addActionListener(al);
259:
260: if (res_op_enabled) {
261: addSeparator(Utilities.dim10_10);
262: JButton reinB = (JButton) add(new JButton(Icons.reindexIcon));
263: if (reinBTT == null)
264: reinBTT = "Reindex children of selected Container(s)";
265: reinB.setToolTipText(reinBTT);
266: reinB.setMargin(Utilities.insets0);
267: reinB.setActionCommand(REIN_A);
268: reinB.addActionListener(al);
269:
270: addSeparator(Utilities.dim3_3);
271:
272: JButton addB = (JButton) add(new JButton(Icons.addIcon));
273: if (addBTT == null)
274: addBTT = "Add a resource to the selected Container";
275: addB.setToolTipText(addBTT);
276: addB.setMargin(Utilities.insets0);
277: addB.setActionCommand(ADD_A);
278: addB.addActionListener(al);
279:
280: addSeparator(Utilities.dim3_3);
281:
282: JButton deleB = (JButton) add(new JButton(Icons.deleteIcon));
283: if (deleBTT == null)
284: deleBTT = "Delete selected resources";
285: deleB.setToolTipText(deleBTT);
286: deleB.setMargin(Utilities.insets0);
287: deleB.setActionCommand(DELE_A);
288: deleB.addActionListener(al);
289:
290: addSeparator(Utilities.dim3_3);
291:
292: JButton editB = (JButton) add(new JButton(Icons.editIcon));
293: if (editBTT == null)
294: editBTT = "Edit selected resource";
295: editB.setToolTipText(editBTT);
296: editB.setMargin(Utilities.insets0);
297: editB.setActionCommand(EDIT_A);
298: editB.addActionListener(al);
299:
300: addSeparator(Utilities.dim10_10);
301:
302: JButton refeB = (JButton) add(new JButton(Icons.infoIcon));
303: if (refeBTT == null)
304: refeBTT = "Show reference documentation of selected resource";
305: refeB.setToolTipText(refeBTT);
306: refeB.setMargin(Utilities.insets0);
307: refeB.setActionCommand(REFE_A);
308: refeB.addActionListener(al);
309:
310: addSeparator(Utilities.dim3_3);
311:
312: JButton helpB = (JButton) add(new JButton(Icons.helpIcon));
313: if (helpBTT == null)
314: helpBTT = "Show documentation";
315: helpB.setToolTipText(helpBTT);
316: helpB.setMargin(Utilities.insets0);
317: helpB.setActionCommand(HELP_A);
318: helpB.addActionListener(al);
319: }
320:
321: putClientProperty("JToolBar.isRollover", Boolean.FALSE);
322: built = true;
323: }
324:
325: /**
326: * Get the helper name.
327: * @return a String instance
328: */
329: public String getName() {
330: return name;
331: }
332:
333: /**
334: * Get the helper tooltip
335: * @return a String
336: */
337: public String getToolTip() {
338: return tooltip;
339: }
340:
341: /**
342: * Get the helper Component
343: * @return a Component instance
344: */
345: public Component getComponent() {
346: if (!built)
347: build();
348: return this ;
349: }
350:
351: /**
352: * Constructor.
353: */
354: public ControlServerHelper() {
355: super (HORIZONTAL);
356: //new instance
357: }
358:
359: }
|