--- /dev/null
+// PropertiesServerHelper.java\r
+// $Id: PropertiesServerHelper.java,v 1.1 2010/06/15 12:25:51 smhuang Exp $\r
+// (c) COPYRIGHT MIT and INRIA, 1998.\r
+// Please first read the full copyright statement in file COPYRIGHT.html\r
+\r
+package org.w3c.jigadmin.editors;\r
+\r
+import java.awt.Insets;\r
+import java.awt.GridLayout;\r
+import java.awt.BorderLayout;\r
+import java.awt.CardLayout;\r
+import java.awt.Cursor;\r
+import java.awt.Component;\r
+import java.awt.event.ActionListener;\r
+import java.awt.event.ActionEvent;\r
+\r
+import javax.swing.JPanel;\r
+import javax.swing.JButton;\r
+import javax.swing.AbstractButton;\r
+import javax.swing.BorderFactory;\r
+import javax.swing.JTabbedPane;\r
+import javax.swing.border.TitledBorder;\r
+import javax.swing.event.ChangeListener;\r
+import javax.swing.event.ChangeEvent;\r
+\r
+import java.util.Properties;\r
+import java.util.Hashtable;\r
+\r
+import org.w3c.jigadmin.RemoteResourceWrapper;\r
+import org.w3c.jigadmin.PropertyManager;\r
+import org.w3c.jigadmin.gui.Message;\r
+\r
+import org.w3c.jigsaw.admin.RemoteAccessException;\r
+\r
+import org.w3c.tools.widgets.Utilities;\r
+import org.w3c.tools.sorter.Sorter;\r
+\r
+/**\r
+ * The server helper dedicated to the properties.\r
+ * @version $Revision: 1.1 $\r
+ * @author Benoît Mahé (bmahe@w3.org)\r
+ */\r
+public class PropertiesServerHelper extends JPanel \r
+ implements ServerHelperInterface, ChangeListener\r
+{\r
+ protected String name = null;\r
+ protected String tooltip = null;\r
+ protected RemoteResourceWrapper root = null;\r
+ protected String properties[] = null;\r
+ protected JPanel cards = null;\r
+ protected Hashtable helpers = null;\r
+ protected String selected = null;\r
+\r
+ /**\r
+ * Initialize this editor.\r
+ * @param name the editor name\r
+ * @param rrw the RemoteResourceWrapper wrapping the editor node.\r
+ * @param p the editor properties\r
+ */ \r
+ public void initialize(String name, \r
+ RemoteResourceWrapper rrw, \r
+ Properties p)\r
+ {\r
+ this.name = name;\r
+ this.root = rrw;\r
+ this.tooltip = (String) p.get(TOOLTIP_P);\r
+ build();\r
+ }\r
+\r
+ /**\r
+ * ChangeListener implementation.\r
+ * @param e a ChangeEvent\r
+ */\r
+ public void stateChanged(ChangeEvent e) {\r
+ Object source = e.getSource();\r
+ if (source instanceof JTabbedPane) {\r
+ JTabbedPane pane = (JTabbedPane) source;\r
+ if (pane.getSelectedComponent() == this) {\r
+ removeAll();\r
+ invalidate();\r
+ build();\r
+ if (selected != null)\r
+ select(selected);\r
+ validate();\r
+ }\r
+ }\r
+ \r
+ }\r
+\r
+ /**\r
+ * Build the interface.\r
+ */\r
+ protected void build() {\r
+ int len = 0;\r
+ JButton b = null;\r
+\r
+ helpers = new Hashtable();\r
+\r
+ try {\r
+ properties = root.getResource().enumerateResourceIdentifiers();\r
+ Sorter.sortStringArray(properties, true);\r
+ } catch (RemoteAccessException ex) {\r
+ Message.showErrorMessage(this, ex);\r
+ }\r
+ if (properties == null)\r
+ return;\r
+\r
+ setLayout(new BorderLayout());\r
+ len = properties.length;\r
+ JPanel buttons = new JPanel(new GridLayout(len, 1));\r
+ cards = new JPanel(new CardLayout()); \r
+\r
+ ActionListener listener = new ActionListener() {\r
+ public void actionPerformed(ActionEvent e) {\r
+ root.getServerBrowser().setCursor(Cursor.WAIT_CURSOR);\r
+ String property = e.getActionCommand();\r
+ select(property);\r
+ root.getServerBrowser().setCursor(Cursor.DEFAULT_CURSOR);\r
+ }\r
+ };\r
+\r
+ for (int i = 0 ; i < len ; i++) {\r
+ String name = properties[i];\r
+ //button\r
+ b = new JButton(name);\r
+ b.setVerticalTextPosition(AbstractButton.CENTER);\r
+ b.setHorizontalTextPosition(AbstractButton.CENTER);\r
+ b.setActionCommand(name);\r
+ b.addActionListener(listener);\r
+ b.setMargin(Utilities.insets2);\r
+ buttons.add(b);\r
+ //attribute helper\r
+ JPanel p1 = new JPanel(new GridLayout(1,1));\r
+ p1.setBorder(BorderFactory.createTitledBorder(name));\r
+ helpers.put(name, p1);\r
+ cards.add(name, p1);\r
+ }\r
+ JPanel p1 = new JPanel(new BorderLayout());\r
+ p1.add(buttons, BorderLayout.NORTH);\r
+ p1.setBorder(BorderFactory.createTitledBorder("Properties"));\r
+ add(p1, BorderLayout.WEST);\r
+ add(cards, BorderLayout.CENTER);\r
+ }\r
+\r
+ protected void select(String name) {\r
+ selected = name;\r
+ JPanel p1 = (JPanel)helpers.get(name);\r
+ p1.removeAll();\r
+ try {\r
+ RemoteResourceWrapper rrw = root.getChildResource(name);\r
+ AttributesHelper helper = new AttributesHelper();\r
+ PropertyManager pm = PropertyManager.getPropertyManager();\r
+ Properties props = pm.getEditorProperties(rrw);\r
+ helper.initialize(rrw, props);\r
+ p1.add(helper.getComponent());\r
+ p1.invalidate();\r
+ p1.validate();\r
+ } catch (RemoteAccessException ex) {\r
+ Message.showErrorMessage(this, ex);\r
+ }\r
+ ((CardLayout)cards.getLayout()).show(cards, name);\r
+ }\r
+\r
+ /**\r
+ * Get the helper name.\r
+ * @return a String instance\r
+ */\r
+ public String getName() {\r
+ return name;\r
+ }\r
+\r
+ /**\r
+ * Get the helper tooltip\r
+ * @return a String\r
+ */\r
+ public String getToolTip() {\r
+ return tooltip;\r
+ }\r
+\r
+ /**\r
+ * Get the Component.\r
+ * @return a Component instance\r
+ */\r
+ public Component getComponent() {\r
+ return this;\r
+ }\r
+\r
+ /**\r
+ * Constructor.\r
+ */\r
+ public PropertiesServerHelper() {\r
+ //new instance\r
+ }\r
+\r
+}\r