1 26 27 package org.objectweb.util.explorer.swing.gui.lib; 28 29 import java.awt.Dimension ; 30 31 import javax.swing.Box ; 32 import javax.swing.JScrollPane ; 33 34 import org.objectweb.fractal.api.Component; 35 import org.objectweb.fractal.api.NoSuchInterfaceException; 36 import org.objectweb.util.explorer.api.Entry; 37 import org.objectweb.util.explorer.api.Tree; 38 import org.objectweb.util.explorer.swing.api.Explorer; 39 import org.objectweb.util.explorer.swing.gui.api.ValidateReport; 40 41 48 public class TreeBox 49 extends AbstractElementBox { 50 51 57 58 protected Component component_; 59 60 61 protected Tree treeItf_; 62 63 64 protected Explorer explorerItf_; 65 66 67 protected JScrollPane scrollPane_; 68 69 75 79 public TreeBox(Component treeComponent) { 80 this(treeComponent,true); 81 } 82 83 88 public TreeBox(Component treeComponent, boolean isMandatory) { 89 super(isMandatory); 90 initAttributes(treeComponent); 91 scrollPane_ = new JScrollPane (explorerItf_.getTree()); 92 add(scrollPane_); 93 } 94 95 98 public void preInitialize(){ 99 if(explorerItf_!=null){ 100 explorerItf_.setPopupEnabled(false); 101 explorerItf_.setDragAndDropEnabled(false); 102 } 103 } 104 105 108 public void postInitialize(){ 109 if(explorerItf_!=null){ 110 explorerItf_.setPopupEnabled(true); 111 explorerItf_.setDragAndDropEnabled(true); 112 } 113 } 114 115 121 protected void initAttributes(org.objectweb.fractal.api.Component treeComponent){ 122 component_ = treeComponent; 123 if(component_!=null){ 124 try { 125 treeItf_ = (Tree)component_.getFcInterface(Tree.TREE); 126 explorerItf_ = (Explorer)component_.getFcInterface(Explorer.EXPLORER); 127 } catch (NoSuchInterfaceException e) { 128 e.printStackTrace(); 129 } 130 } 131 } 132 133 139 143 public ValidateReport validateBox(){ 144 if(isMandatory_){ 145 if(getObject()==null) 146 return new DefaultValidateReport(false,"You must select a component"); 147 } 148 return new DefaultValidateReport(); 149 } 150 151 155 public Box getBox(){ 156 return this; 157 } 158 159 165 166 public Object getObject(){ 167 Object o = null; 168 Entry entry = treeItf_.getSelectedEntry(); 169 if (entry != null) { 170 o = entry.getValue(); 171 } 172 return o; 173 } 174 175 179 public void setPreferredSize(Dimension d){ 180 scrollPane_.setPreferredSize(d); 181 } 182 183 } | Popular Tags |