1 4 package com.tc.admin.dso; 5 6 import com.tc.admin.AdminClient; 7 import com.tc.admin.AdminClientContext; 8 import com.tc.admin.ConnectionContext; 9 import com.tc.admin.common.ObjectNameTreeNode; 10 import com.tc.admin.common.XAbstractAction; 11 import com.tc.admin.common.XTreeModel; 12 import com.tc.admin.common.XTreeNode; 13 14 import java.awt.event.ActionEvent ; 15 import java.awt.event.KeyEvent ; 16 import java.awt.event.MouseEvent ; 17 import java.util.Vector ; 18 19 import javax.swing.Icon ; 20 import javax.swing.JPopupMenu ; 21 import javax.swing.KeyStroke ; 22 import javax.swing.SwingUtilities ; 23 import javax.swing.tree.TreeNode ; 24 25 public class RootTreeNode extends ObjectNameTreeNode implements DSOObjectTreeNode { 26 private ConnectionContext m_cc; 27 private DSORoot m_root; 28 private JPopupMenu m_popupMenu; 29 private MoreAction m_moreAction; 30 private LessAction m_lessAction; 31 private int m_batchSize; 32 private RefreshAction m_refreshAction; 33 34 private static final String REFRESH_ACTION = "RefreshAction"; 35 36 public RootTreeNode(ConnectionContext cc, DSORoot root) { 37 super(root.getObjectName()); 38 39 m_cc = cc; 40 m_root = root; 41 m_batchSize = ConnectionContext.DSO_SMALL_BATCH_SIZE; 42 43 initMenu(); 44 init(); 45 } 46 47 public DSOObject getDSOObject() { 48 return getDSORoot(); 49 } 50 51 public DSORoot getDSORoot() { 52 return m_root; 53 } 54 55 private void init() { 56 int count = m_root.getFieldCount(); 57 58 if(count > 0) { 59 if(children == null) { 60 children = new Vector (); 61 } 62 children.setSize(count); 63 } 64 } 65 66 private void initMenu() { 67 m_refreshAction = new RefreshAction(); 68 69 m_popupMenu = new JPopupMenu ("Root Actions"); 70 m_popupMenu.add(m_refreshAction); 71 72 if(m_root.isArray() || m_root.isCollection()) { 73 m_popupMenu.add(m_moreAction = new MoreAction()); 74 m_popupMenu.add(m_lessAction = new LessAction()); 75 } 76 77 addActionBinding(REFRESH_ACTION, m_refreshAction); 78 } 79 80 public JPopupMenu getPopupMenu() { 81 return m_popupMenu; 82 } 83 84 private void fillInChildren() { 85 int childCount = getChildCount(); 86 boolean nso = false; 87 88 for(int i = 0; i < childCount; i++) { 89 DSOObject field = m_root.getField(i); 90 XTreeNode child = createFieldNode(field); 91 92 children.setElementAt(child, i); 93 child.setParent(this); 94 95 if(field == null) { 96 nso = true; 97 } 98 } 99 100 if(nso) { 101 SwingUtilities.invokeLater(new ChildReaper()); 102 } 103 } 104 105 class ChildReaper implements Runnable { 106 public void run() { 107 refresh(); 108 } 109 } 110 111 public TreeNode getChildAt(int index) { 112 if(children != null && children.elementAt(index) == null) { 113 AdminClientContext acc = AdminClient.getContext(); 114 115 acc.controller.block(); 116 fillInChildren(); 117 acc.controller.unblock(); 118 } 119 120 return super.getChildAt(index); 121 } 122 123 private XTreeNode createFieldNode(DSOObject field) { 124 return RootsHelper.getHelper().createFieldNode(m_cc, field); 125 } 126 127 public int getChildCount() { 128 return m_root != null ? m_root.getFieldCount() : 0; 129 } 130 131 public String toString() { 132 return m_root.toString(); 133 } 134 135 public Icon getIcon() { 136 return RootsHelper.getHelper().getRootIcon(); 137 } 138 139 public void refresh() { 140 AdminClientContext acc = AdminClient.getContext(); 141 boolean expanded = acc.controller.isExpanded(this); 142 XTreeModel model = getModel(); 143 XTreeNode node; 144 145 for(int i = getChildCount()-1; i >= 0; i--) { 146 node = (XTreeNode)getChildAt(i); 147 node.tearDown(); 148 model.removeNodeFromParent(node); 149 } 150 151 m_root.refresh(); 152 153 init(); 154 155 model.nodeStructureChanged(RootTreeNode.this); 156 if(expanded) { 157 acc.controller.expand(this); 158 } 159 } 160 161 private class RefreshAction extends XAbstractAction { 162 private RefreshAction() { 163 super("Refresh", RootsHelper.getHelper().getRefreshIcon()); 164 setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0, true)); 165 } 166 167 public void actionPerformed(ActionEvent ae) { 168 AdminClientContext acc = AdminClient.getContext(); 169 String name = m_root.getName(); 170 171 acc.controller.setStatus("Refreshing root " + name + "..."); 172 acc.controller.block(); 173 174 refresh(); 175 176 acc.controller.clearStatus(); 177 acc.controller.unblock(); 178 } 179 } 180 181 public void nodeClicked(MouseEvent me) { 182 m_refreshAction.actionPerformed(null); 183 } 184 185 private class MoreAction extends XAbstractAction { 186 private MoreAction() { 187 super("More"); 188 } 189 190 public void actionPerformed(ActionEvent ae) { 191 AdminClientContext acc = AdminClient.getContext(); 192 String name = m_root.getName(); 193 194 if(incrementDSOBatchSize() == ConnectionContext.DSO_MAX_BATCH_SIZE) { 195 setEnabled(false); 196 } 197 m_lessAction.setEnabled(true); 198 m_root.setBatchSize(m_batchSize); 199 200 acc.controller.setStatus("Refreshing root " + name + "..."); 201 acc.controller.block(); 202 203 refresh(); 204 205 acc.controller.clearStatus(); 206 acc.controller.unblock(); 207 } 208 } 209 210 private class LessAction extends XAbstractAction { 211 private LessAction() { 212 super("Less"); 213 setEnabled(false); 214 } 215 216 public void actionPerformed(ActionEvent ae) { 217 AdminClientContext acc = AdminClient.getContext(); 218 String name = m_root.getName(); 219 220 if(decrementDSOBatchSize() == ConnectionContext.DSO_SMALL_BATCH_SIZE) { 221 setEnabled(false); 222 } 223 m_moreAction.setEnabled(true); 224 m_root.setBatchSize(m_batchSize); 225 226 acc.controller.setStatus("Refreshing root " + name + "..."); 227 acc.controller.block(); 228 229 refresh(); 230 231 acc.controller.clearStatus(); 232 acc.controller.unblock(); 233 } 234 } 235 236 int incrementDSOBatchSize() { 237 switch(m_batchSize) { 238 case ConnectionContext.DSO_SMALL_BATCH_SIZE: 239 m_batchSize = ConnectionContext.DSO_MEDIUM_BATCH_SIZE; 240 break; 241 case ConnectionContext.DSO_MEDIUM_BATCH_SIZE: 242 m_batchSize = ConnectionContext.DSO_LARGE_BATCH_SIZE; 243 break; 244 case ConnectionContext.DSO_LARGE_BATCH_SIZE: 245 m_batchSize = ConnectionContext.DSO_MAX_BATCH_SIZE; 246 break; 247 } 248 249 return m_batchSize; 250 } 251 252 int decrementDSOBatchSize() { 253 switch(m_batchSize) { 254 case ConnectionContext.DSO_MEDIUM_BATCH_SIZE: 255 m_batchSize = ConnectionContext.DSO_SMALL_BATCH_SIZE; 256 break; 257 case ConnectionContext.DSO_LARGE_BATCH_SIZE: 258 m_batchSize = ConnectionContext.DSO_MEDIUM_BATCH_SIZE; 259 break; 260 case ConnectionContext.DSO_MAX_BATCH_SIZE: 261 m_batchSize = ConnectionContext.DSO_LARGE_BATCH_SIZE; 262 break; 263 } 264 265 return m_batchSize; 266 } 267 268 public int resetDSOBatchSize() { 269 return m_batchSize = ConnectionContext.DSO_SMALL_BATCH_SIZE; 270 } 271 272 273 public void tearDown() { 274 super.tearDown(); 275 276 m_cc = null; 277 m_root = null; 278 m_popupMenu = null; 279 } 280 } 281 | Popular Tags |