1 26 package org.objectweb.util.explorer.swing.lib; 27 28 import java.awt.Dimension ; 29 import java.awt.GridLayout ; 30 import java.util.HashMap ; 31 import java.util.Map ; 32 33 import javax.swing.JPanel ; 34 import javax.swing.JScrollPane ; 35 36 import org.objectweb.fractal.api.NoSuchInterfaceException; 37 import org.objectweb.util.explorer.api.Panel; 38 import org.objectweb.util.explorer.api.Tree; 39 import org.objectweb.util.explorer.api.TreeView; 40 import org.objectweb.util.explorer.core.common.api.Description; 41 import org.objectweb.util.explorer.core.common.api.ExplorerConstants; 42 import org.objectweb.util.explorer.core.common.api.Synchronization; 43 import org.objectweb.util.explorer.core.common.lib.BindingFeature; 44 import org.objectweb.util.explorer.interpreter.api.DescriptionInterpreter; 45 import org.objectweb.util.explorer.resolver.api.PropertyResolver; 46 import org.objectweb.util.explorer.swing.api.ViewPanel; 47 import org.objectweb.util.explorer.swing.panel.WhitePanel; 48 49 57 public class DefaultViewPanel 58 extends BindingFeature 59 implements Synchronization, ViewPanel 60 { 61 62 68 protected JPanel viewPanel_ = null; 69 protected Panel userPanel_ = null; 70 protected Panel whitePanel_ = null; 71 protected TreeView currentTreeView_ = null; 72 73 79 public DefaultViewPanel(){ 80 whitePanel_ = new WhitePanel(); 81 viewPanel_ = new JPanel (); 82 viewPanel_.setLayout(new GridLayout (1, 0)); 83 viewPanel_.setPreferredSize(new Dimension (400, 500)); 84 viewPanel_.add((JPanel )whitePanel_.getPanel()); 86 } 87 88 94 97 protected PropertyResolver getPropertyResolver() { 98 try { 99 return (PropertyResolver)lookupFc(PropertyResolver.PROPERTY_RESOLVER); 100 } catch (NoSuchInterfaceException e) { 101 getTrace().warn(PropertyResolver.PROPERTY_RESOLVER + ": interface not found!"); 102 return null; 103 } 104 } 105 106 109 protected DescriptionInterpreter getDescriptionInterpreter() { 110 try { 111 return (DescriptionInterpreter)lookupFc(DescriptionInterpreter.DESCRIPTION_INTERPRETER); 112 } catch (NoSuchInterfaceException e) { 113 getTrace().warn(DescriptionInterpreter.DESCRIPTION_INTERPRETER + ": interface not found!"); 114 return null; 115 } 116 } 117 118 121 protected Tree getTree() { 122 try { 123 return (Tree)lookupFc(Tree.TREE); 124 } catch (NoSuchInterfaceException e) { 125 getTrace().warn(Tree.TREE + ": interface not found!"); 126 return null; 127 } 128 } 129 130 133 protected void setViewPanel(Panel newPanel) { 134 viewPanel_.removeAll(); 135 userPanel_ = newPanel; 136 viewPanel_.add(new JScrollPane ((JPanel )userPanel_.getPanel())); 137 viewPanel_.revalidate(); 138 } 139 140 146 149 public String [] clientFc() { 150 return new String []{Tree.TREE, PropertyResolver.PROPERTY_RESOLVER,DescriptionInterpreter.DESCRIPTION_INTERPRETER}; 151 } 152 153 159 162 public void refresh(TreeView treeView) { 163 if(userPanel_!=null && currentTreeView_!=null){ 164 userPanel_.unselected(currentTreeView_); 165 } 166 if(treeView!=null){ 167 Description desc = getPropertyResolver().resolve(ExplorerConstants.PANEL_PROPERTY, treeView.getSelectedEntry()); 168 Map map = new HashMap (); 170 map.put(PropertyResolver.PROPERTY_RESOLVER, getPropertyResolver()); 171 map.put(DescriptionInterpreter.DESCRIPTION_INTERPRETER, getDescriptionInterpreter()); 172 map.put(Tree.TREE, getTree()); 173 Panel p = (Panel )getDescriptionInterpreter().interprete(desc, map); 174 if(p!=null){ 175 currentTreeView_ = treeView; 176 p.selected(treeView); 177 setViewPanel(p); 178 } else { 179 userPanel_ = null; 180 setViewPanel(whitePanel_); 181 } 182 } 183 } 184 185 191 195 public JPanel getViewPanel(){ 196 return viewPanel_; 197 } 198 199 } 200 201 | Popular Tags |