Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / jigsaw / src / org / w3c / jigadm / editors / ResourcesHelper.java
diff --git a/JMCR-Stable/real-world application/jigsaw/src/org/w3c/jigadm/editors/ResourcesHelper.java b/JMCR-Stable/real-world application/jigsaw/src/org/w3c/jigadm/editors/ResourcesHelper.java
new file mode 100644 (file)
index 0000000..8e9faa5
--- /dev/null
@@ -0,0 +1,171 @@
+// ResourcesHelper.java\r
+// $Id: ResourcesHelper.java,v 1.1 2010/06/15 12:22:40 smhuang Exp $\r
+// (c) COPYRIGHT MIT and INRIA, 1997.\r
+// Please first read the full copyright statement in file COPYRIGHT.html\r
+\r
+package org.w3c.jigadm.editors ;\r
+\r
+import java.awt.BorderLayout;\r
+import java.awt.Button;\r
+import java.awt.Component;\r
+import java.awt.Container;\r
+import java.awt.GridBagConstraints;\r
+import java.awt.GridBagLayout;\r
+import java.awt.GridLayout;\r
+import java.awt.Label;\r
+import java.awt.Panel;\r
+import java.awt.ScrollPane;\r
+import java.awt.TextComponent;\r
+import java.awt.TextField;\r
+\r
+import java.awt.event.ActionEvent;\r
+import java.awt.event.ActionListener;\r
+\r
+import java.util.Hashtable;\r
+import java.util.Properties;\r
+import java.util.StringTokenizer;\r
+\r
+import org.w3c.jigsaw.admin.RemoteAccessException;\r
+import org.w3c.jigsaw.admin.RemoteResource;\r
+\r
+import org.w3c.jigadm.PropertyManager;\r
+import org.w3c.jigadm.RemoteResourceWrapper;\r
+\r
+import org.w3c.tools.resources.Attribute;\r
+\r
+import org.w3c.tools.widgets.FakeComboBox;\r
+\r
+public class ResourcesHelper extends ResourceHelper {\r
+\r
+    class AddResourceListener implements ActionListener {\r
+\r
+        public void actionPerformed(ActionEvent ae) {\r
+           addResource();\r
+       }\r
+    }\r
+\r
+    RemoteResourceWrapper   rrw = null;\r
+    RemoteResource rr = null;\r
+    RemoteResource[] child = null;\r
+    private boolean initialized = false;\r
+    Properties prop;\r
+    FakeComboBox combo;\r
+    TextField tf;\r
+    Panel widget;\r
+    Panel addPanel = null;\r
+\r
+    protected void addResource() {\r
+       if(tf.getText().length() > 0) {\r
+           RemoteResource nrr;\r
+           String selected = combo.getText();\r
+           if (selected != null)\r
+             if (selected.length() > 0) {\r
+               try {\r
+                   nrr = rrw.getResource().\r
+                                     registerResource(tf.getText(),\r
+                                                      selected);\r
+               } catch (RemoteAccessException ex) {\r
+                   // Add a fancy error\r
+                   return;\r
+               }\r
+               RemoteResourceWrapper nrrw;\r
+               nrrw = new RemoteResourceWrapper(rrw, nrr, rrw.getBrowser());\r
+               rrw.getBrowser().insertNode(rrw, nrrw, tf.getText());\r
+           }\r
+       }\r
+    }\r
+\r
+    protected RemoteResourceWrapper getWrapper() {\r
+       return rrw;\r
+    }\r
+\r
+    public Component getComponent() {\r
+       return widget;\r
+    }\r
+\r
+    /**\r
+     * commit changes (if any)\r
+     * @exception RemoteAccessException if a remote access error occurs.\r
+     */\r
+    public void commitChanges()\r
+       throws RemoteAccessException\r
+    {\r
+       if(!initialized)\r
+           return;\r
+       return;\r
+    }\r
+\r
+    public boolean hasChanged() {    \r
+       return false;\r
+    }\r
+\r
+    public void resetChanges() {\r
+    }\r
+\r
+    public void clearChanged() {\r
+    }\r
+\r
+    public final String getTitle () {\r
+       return "Resources";\r
+    }\r
+\r
+    public ResourcesHelper() {\r
+       widget = new Panel();\r
+    }\r
+\r
+    protected void initAddPanel(Properties config) {\r
+       if(addPanel == null) {\r
+           Panel tfp;\r
+           addPanel = new Panel(new BorderLayout());\r
+       \r
+           String af = (String) config.get(\r
+               "org.w3c.jigadm.editors.resource.resources");\r
+           if ( af == null )\r
+               return;\r
+           StringTokenizer st = new StringTokenizer(af, "|");\r
+           ScrollPane fsp = new ScrollPane();\r
+           GridBagLayout fgbl = new GridBagLayout();\r
+           GridBagConstraints fgbc = new GridBagConstraints();\r
+           Panel fspp = new Panel (fgbl);\r
+           fsp.add(fspp);\r
+           PropertyManager pm = PropertyManager.getPropertyManager();\r
+           String downPath = pm.getIconLocation("down");\r
+           String leftPath = pm.getIconLocation("left");\r
+           combo = new FakeComboBox(35,7,true,downPath,leftPath); \r
+           while(st.hasMoreTokens())\r
+             combo.add(st.nextToken().trim());\r
+           fspp.add(combo);\r
+           addPanel.add("Center", fsp);\r
+           Button newb     = new Button("Add Resource");\r
+           newb.addActionListener(new AddResourceListener());\r
+           addPanel.add("South", newb);\r
+           tfp = new Panel(new GridLayout(1, 2));\r
+           tf = new TextField();\r
+           tfp.add(new Label("identifier"));\r
+           tfp.add(tf);\r
+           addPanel.add("North", tfp);\r
+       }\r
+       widget.add("Center", addPanel);\r
+       \r
+    }\r
+\r
+    /**\r
+     * initialize this helper\r
+     * @param rrw The RemoteResourceWrapper\r
+     * @param pr The properties\r
+     * @exception RemoteAccessException if a remote access error occurs.\r
+     */\r
+    public void initialize(RemoteResourceWrapper rrw, Properties pr)\r
+       throws RemoteAccessException\r
+    {\r
+       if(!initialized)\r
+           initialized = true;\r
+       else\r
+           return;     \r
+       \r
+       this.rrw = rrw;\r
+       rr = rrw.getResource();\r
+       widget.setLayout(new BorderLayout());\r
+       initAddPanel(pr);\r
+    }\r
+}\r