1 26 27 package org.objectweb.util.browser.gui.lib; 28 29 import java.awt.Dimension ; 30 31 import javax.swing.Box ; 32 import javax.swing.JScrollPane ; 33 34 import org.objectweb.util.browser.api.Entry; 35 import org.objectweb.util.browser.api.Wrapper; 36 import org.objectweb.util.browser.gui.api.ValidateReport; 37 import org.objectweb.util.browser.core.common.DynamicTree; 38 39 46 public class TreeBox 47 extends AbstractElementBox { 48 49 55 56 protected DynamicTree tree_; 57 58 59 protected JScrollPane scrollPane_; 60 61 67 71 public TreeBox(DynamicTree tree) { 72 this(tree,true); 73 } 74 75 80 public TreeBox(DynamicTree tree, boolean isMandatory) { 81 super(isMandatory); 82 tree_ = tree; 83 scrollPane_ = new JScrollPane (tree_); 84 add(scrollPane_); 85 } 86 87 90 public void preInitialize(){ 91 if(tree_!=null){ 92 tree_.setPopupEnabled(false); 93 tree_.setDragAndDropEnabled(false); 94 } 95 } 96 97 100 public void postInitialize(){ 101 if(tree_!=null){ 102 tree_.setPopupEnabled(true); 103 tree_.setDragAndDropEnabled(true); 104 } 105 } 106 107 113 119 123 public ValidateReport validateBox(){ 124 if(isMandatory_){ 125 if(getObject()==null) 126 return new DefaultValidateReport(false,"You must select a component"); 127 } 128 return new DefaultValidateReport(); 129 } 130 131 135 public Box getBox(){ 136 return this; 137 } 138 139 145 146 public Object getObject(){ 147 Object o = null; 148 Entry entry = tree_.getSelectedEntry(); 149 if (entry != null) { 150 o = entry.getValue(); 151 if (o!=null && Wrapper.class.isAssignableFrom(o.getClass())) 152 return ((Wrapper)o).getWrapped(); 153 } 154 return o; 155 } 156 157 161 public void setPreferredSize(Dimension d){ 162 scrollPane_.setPreferredSize(d); 163 } 164 165 } | Popular Tags |