1 4 package com.tc.admin.dso; 5 6 import org.dijon.Component; 7 8 import com.tc.admin.AdminClient; 9 import com.tc.admin.AdminClientContext; 10 import com.tc.admin.ConnectionContext; 11 import com.tc.admin.common.ComponentNode; 12 import com.tc.admin.common.XAbstractAction; 13 14 import java.awt.event.ActionEvent ; 15 import java.awt.event.KeyEvent ; 16 import java.awt.event.MouseEvent ; 17 18 import javax.swing.Icon ; 19 import javax.swing.JPopupMenu ; 20 import javax.swing.KeyStroke ; 21 22 public class RootNode extends ComponentNode { 23 private ConnectionContext m_cc; 24 private DSORoot m_root; 25 private RootsPanel m_rootsPanel; 26 private MoreAction m_moreAction; 27 private LessAction m_lessAction; 28 private JPopupMenu m_popupMenu; 29 private int m_batchSize; 30 private RefreshAction m_refreshAction; 31 32 private static final String REFRESH_ACTION = "RefreshAction"; 33 34 public RootNode(ConnectionContext cc, DSORoot root) { 35 super(); 36 37 m_cc = cc; 38 m_root = root; 39 m_batchSize = ConnectionContext.DSO_SMALL_BATCH_SIZE; 40 41 initMenu(); 42 43 setLabel(root.toString()); 44 } 45 46 public Component getComponent() { 47 if(m_rootsPanel == null) { 48 m_rootsPanel = new RootsPanel(m_cc, new DSORoot[] {m_root}); 49 m_rootsPanel.setNode(this); 50 } 51 52 return m_rootsPanel; 53 } 54 55 private void initMenu() { 56 m_refreshAction = new RefreshAction(); 57 58 m_popupMenu = new JPopupMenu ("Root Actions"); 59 m_popupMenu.add(m_refreshAction); 60 61 if(m_root.isArray() || m_root.isCollection()) { 62 m_popupMenu.add(m_moreAction = new MoreAction()); 63 m_popupMenu.add(m_lessAction = new LessAction()); 64 } 65 66 addActionBinding(REFRESH_ACTION, m_refreshAction); 67 } 68 69 public JPopupMenu getPopupMenu() { 70 return m_popupMenu; 71 } 72 73 public Icon getIcon() { 74 return RootsHelper.getHelper().getRootIcon(); 75 } 76 77 private void refresh() { 78 ((RootsPanel)getComponent()).refresh(); 79 setLabel(m_root.toString()); 80 nodeChanged(); 81 } 82 83 private class RefreshAction extends XAbstractAction { 84 private RefreshAction() { 85 super("Refresh", RootsHelper.getHelper().getRefreshIcon()); 86 setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0, true)); 87 } 88 89 public void actionPerformed(ActionEvent ae) { 90 AdminClientContext acc = AdminClient.getContext(); 91 String name = m_root.getName(); 92 93 acc.controller.setStatus("Refreshing root " + name + "..."); 94 acc.controller.block(); 95 96 refresh(); 97 98 acc.controller.clearStatus(); 99 acc.controller.unblock(); 100 } 101 } 102 103 public void nodeClicked(MouseEvent me) { 104 m_refreshAction.actionPerformed(null); 105 } 106 107 private class MoreAction extends XAbstractAction { 108 private MoreAction() { 109 super("More"); 110 } 111 112 public void actionPerformed(ActionEvent ae) { 113 AdminClientContext acc = AdminClient.getContext(); 114 String name = m_root.getName(); 115 116 if(incrementDSOBatchSize() == ConnectionContext.DSO_MAX_BATCH_SIZE) { 117 setEnabled(false); 118 } 119 m_lessAction.setEnabled(true); 120 m_root.setBatchSize(m_batchSize); 121 122 acc.controller.setStatus("Refreshing root " + name + "..."); 123 acc.controller.block(); 124 125 refresh(); 126 127 acc.controller.clearStatus(); 128 acc.controller.unblock(); 129 } 130 } 131 132 private class LessAction extends XAbstractAction { 133 private LessAction() { 134 super("Less"); 135 setEnabled(false); 136 } 137 138 public void actionPerformed(ActionEvent ae) { 139 AdminClientContext acc = AdminClient.getContext(); 140 String name = m_root.getName(); 141 142 if(decrementDSOBatchSize() == ConnectionContext.DSO_SMALL_BATCH_SIZE) { 143 setEnabled(false); 144 } 145 m_moreAction.setEnabled(true); 146 m_root.setBatchSize(m_batchSize); 147 148 acc.controller.setStatus("Refreshing root " + name + "..."); 149 acc.controller.block(); 150 151 refresh(); 152 153 acc.controller.clearStatus(); 154 acc.controller.unblock(); 155 } 156 } 157 158 int incrementDSOBatchSize() { 159 switch(m_batchSize) { 160 case ConnectionContext.DSO_SMALL_BATCH_SIZE: 161 m_batchSize = ConnectionContext.DSO_MEDIUM_BATCH_SIZE; 162 break; 163 case ConnectionContext.DSO_MEDIUM_BATCH_SIZE: 164 m_batchSize = ConnectionContext.DSO_LARGE_BATCH_SIZE; 165 break; 166 case ConnectionContext.DSO_LARGE_BATCH_SIZE: 167 m_batchSize = ConnectionContext.DSO_MAX_BATCH_SIZE; 168 break; 169 } 170 171 return m_batchSize; 172 } 173 174 int decrementDSOBatchSize() { 175 switch(m_batchSize) { 176 case ConnectionContext.DSO_MEDIUM_BATCH_SIZE: 177 m_batchSize = ConnectionContext.DSO_SMALL_BATCH_SIZE; 178 break; 179 case ConnectionContext.DSO_LARGE_BATCH_SIZE: 180 m_batchSize = ConnectionContext.DSO_MEDIUM_BATCH_SIZE; 181 break; 182 case ConnectionContext.DSO_MAX_BATCH_SIZE: 183 m_batchSize = ConnectionContext.DSO_LARGE_BATCH_SIZE; 184 break; 185 } 186 187 return m_batchSize; 188 } 189 190 public int resetDSOBatchSize() { 191 return m_batchSize = ConnectionContext.DSO_SMALL_BATCH_SIZE; 192 } 193 194 public void tearDown() { 195 super.tearDown(); 196 197 m_popupMenu = null; 198 m_moreAction = null; 199 m_lessAction = null; 200 } 201 } 202 | Popular Tags |