1 17 18 package org.objectweb.jac.aspects.gui.web; 19 20 import java.io.IOException ; 21 import java.io.PrintWriter ; 22 import java.util.Iterator ; 23 import java.util.Vector ; 24 import org.apache.log4j.Logger; 25 import org.objectweb.jac.aspects.gui.*; 26 import org.objectweb.jac.aspects.gui.web.html.*; 27 28 31 public class Tabs extends AbstractCompositeView 32 implements TabsListener, TabsView 33 { 34 static Logger logger = Logger.getLogger("gui.web"); 35 static Logger loggerEditor = Logger.getLogger("gui.editor"); 36 37 38 Vector tabs = new Vector (); 39 40 41 Vector icons = new Vector (); 42 43 44 View selected; 45 46 public Tabs() { 47 } 48 49 54 public void addView(View view, Object extraInfos) { 55 logger.debug("TabbedPane.addView("+view+","+extraInfos+")"); 56 add(view); 57 tabs.add((String )extraInfos); 58 icons.add(""); 59 if (selected==null) { 60 setSelected(view); 61 } 62 } 63 64 public void addTab(View component, String category, String icon) { 65 logger.debug("TabbedPane.addView("+component+","+category+")"); 66 67 add(component); 68 tabs.add((String ) category); 69 icons.add(icon); 70 if (selected==null) { 71 setSelected(component); 72 } 73 } 74 75 public View getView(Object id) { 76 if (id instanceof String ) 77 try { 78 return (View)components.get(Integer.parseInt((String )id)); 79 } catch (NumberFormatException e) { 80 return getTab((String )id); 81 } 82 else if (id instanceof Integer ) 83 return (View)components.get(((Integer )id).intValue()); 84 else 85 throw new RuntimeException ("getView(): bad id "+id); 86 } 87 88 public void select(String tab) { 89 setSelected(getTab(tab)); 90 } 91 92 95 protected void setSelected(View selected) { 96 this.selected = selected; 97 loggerEditor.debug("setSelected "+selected); 98 Iterator it = context.getEditors().iterator(); 99 while (it.hasNext()) { 100 Object view = it.next(); 101 if (view instanceof FieldEditor) { 102 FieldEditor editor = (FieldEditor)view; 103 if (((View)editor).isDescendantOf(selected)) 104 editor.setEnabled(true); 105 else 106 editor.setEnabled(false); 107 } 108 } 109 } 110 111 115 public View getTab(String tab) { 116 return getView(new Integer (tabs.indexOf(tab))); 117 } 118 119 121 public void genHTML(PrintWriter out) throws IOException { 122 Iterator i = tabs.iterator(); 123 Iterator j = icons.iterator(); 124 int index = 0; 125 126 if (tabs.size() != icons.size()) 127 throw new RuntimeException ("Number of tabs and number" + 128 " of icons are different"); 129 130 out.println("<div class=\""+type+"\">"); 131 JacRequest request=WebDisplay.getRequest(); 132 if (request.isIEUserAgent()) { 133 out.println(" <table class=\"ieheader\"><tr>"); 135 } else { 136 out.println(" <div class=\"header\">"); 137 } 138 139 while (i.hasNext()) { 140 String icon = (String ) j.next(); 141 String label = (String )i.next(); 142 String str; 143 if (icon != null) 144 str = iconElement(icon, "") + label; 145 else 146 str = label; 147 Element element = (Element)eventURL(str, "onSelect", 148 "&index=" + index); 149 if (selected==components.get(index)) { 150 element.cssClass("selected"); 151 } 152 try { 153 if (request.isIEUserAgent()) { 154 if (selected==components.get(index)) 155 out.println("<td class=\"td-selected\">"); 156 else 157 out.println("<td class=\"td\">"); 158 } 159 element.write(out); 160 if (request.isIEUserAgent()) { 161 out.println("</td>"); 162 if (i.hasNext()) { 163 out.println("<td> </td>"); 164 } 165 } 166 } catch(Exception e) { 167 e.printStackTrace(); 168 } 169 index++; 170 } 171 if (request.isIEUserAgent()) { 172 out.println(" </tr></table>"); 173 } else { 174 out.println(" </div>"); 175 } 176 out.println(" <div class=\"body\">"); 177 if (selected!=null) 178 ((HTMLViewer)selected).genHTML(out); 179 out.println(" </div>"); 180 out.println("</div>"); 181 } 182 183 185 public void onSelect(int index) { 186 try { 187 setSelected((View)components.get(index)); 188 } finally { 189 context.getDisplay().refresh(); 190 } 191 } 192 } 193 | Popular Tags |