1 26 package org.objectweb.util.explorer.interpreter.lib.swing; 27 28 import java.util.Map ; 29 30 import org.objectweb.util.explorer.api.Panel; 31 import org.objectweb.util.explorer.api.Table; 32 import org.objectweb.util.explorer.api.Tree; 33 import org.objectweb.util.explorer.core.code.api.Code; 34 import org.objectweb.util.explorer.core.common.api.Description; 35 import org.objectweb.util.explorer.core.panel.api.CompositePanelDescription; 36 import org.objectweb.util.explorer.core.panel.api.PanelDescription; 37 import org.objectweb.util.explorer.core.panel.api.TableDescription; 38 import org.objectweb.util.explorer.interpreter.api.DescriptionInterpreter; 39 import org.objectweb.util.explorer.interpreter.lib.AbstractDescriptionInterpreter; 40 import org.objectweb.util.explorer.resolver.api.PropertyResolver; 41 import org.objectweb.util.explorer.swing.panel.BasicCompositePanel; 42 import org.objectweb.util.explorer.swing.panel.BasicTablePanel; 43 44 52 public class PanelInterpreter 53 extends AbstractDescriptionInterpreter 54 { 55 56 62 68 74 protected Panel createPanel(TableDescription table, Map params){ 75 Code tableCode = getCodeProvider().getCode(table.getCodeDescription()); 76 if(tableCode!=null && tableCode.isInstanceOf(Table.class)){ 77 BasicTablePanel p = new BasicTablePanel(); 78 p.setTable((Table)tableCode.createInstance()); 79 p.setPropertyResolver((PropertyResolver)params.get(PropertyResolver.PROPERTY_RESOLVER)); 80 p.setDescriptionInterpreter((DescriptionInterpreter)params.get(DescriptionInterpreter.DESCRIPTION_INTERPRETER)); 81 p.setTree((Tree)params.get(Tree.TREE)); 82 return p; 83 } else { 84 getTrace().warn(tableCode + " is not assignable from Table!"); 85 return null; 86 } 87 } 88 89 protected Panel createPanel(PanelDescription panel){ 90 Code panelCode = getCodeProvider().getCode(panel.getCodeDescription()); 91 if(panelCode!=null && panelCode.isInstanceOf(Panel.class)){ 92 return (Panel)panelCode.createInstance(); 93 } else { 94 getTrace().warn(panelCode + " is not assignable from Panel!"); 95 return null; 96 } 97 } 98 99 protected Panel createPanel(CompositePanelDescription panel, Map params){ 100 BasicCompositePanel compositePanel = new BasicCompositePanel(); 101 PanelDescription[] panelDescs = panel.getPanelDescriptions(); 102 for (int i = 0; i < panelDescs.length; i++) { 103 PanelDescription panelDesc = panelDescs[i]; 104 if (PanelDescription.TABLE.equals(panelDesc.getPanelType())) { 105 compositePanel.add(createPanel((TableDescription)panelDesc, params)); 106 } else if (PanelDescription.PANEL.equals(panelDesc.getPanelType())) { 107 compositePanel.add(createPanel((PanelDescription)panelDesc)); 108 } else { 109 compositePanel.add(createPanel((CompositePanelDescription)panelDesc)); 110 } 111 } 112 return compositePanel; 113 } 114 115 121 124 public Object interprete(Description description, Object params) { 125 return createPanel((CompositePanelDescription)description, (Map )params); 126 } 127 128 } 129 | Popular Tags |