1 package org.enhydra.kelp.ant.deployer; 2 3 11 12 import org.enhydra.tool.ToolBoxInfo; 14 import org.enhydra.tool.common.DataValidationException; 15 import org.enhydra.tool.common.SwingUtil; 16 17 import org.enhydra.kelp.KelpInfo; 19 import org.enhydra.kelp.common.Constants; 20 import org.enhydra.kelp.common.event.WriteEvent; 21 import org.enhydra.kelp.common.event.WriteListener; 22 import org.enhydra.kelp.common.node.OtterProject; 23 import org.enhydra.kelp.common.node.OtterFileNode; 24 import org.enhydra.kelp.common.node.OtterNode; 25 import org.enhydra.kelp.common.swing.AddinInnerPanel; 26 import org.enhydra.kelp.common.swing.FileNodeSelectionPanel; 27 import org.enhydra.kelp.ant.swing.AntOutputPanel; 28 29 30 import java.util.ArrayList ; 32 import java.util.Arrays ; 33 import java.util.ResourceBundle ; 34 import java.awt.*; 35 import java.beans.*; 36 import javax.swing.*; 37 import org.enhydra.tool.common.ButtonPanel; 38 import org.enhydra.tool.swing.layout.*; 39 41 public class AntDeployInnerPanel extends AddinInnerPanel { 43 44 static ResourceBundle res = 46 ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); 48 50 private boolean standalone = false; 51 private GridBagLayout layoutMain = null; 55 private AntOutputPanel outputPanel = null; 58 private AntDeployGeneralPanel generalPanel = null; 59 private AntDeployInputPanel inputPanel = null; 60 private AntDeployContentPanel contentPanel = null; 61 private JTabbedPane tab = null; 62 private WriteListener[] writeListeners = new WriteListener[0]; 63 private String progressTitle = new String (); 64 XYLayout xYLayout1 = new XYLayout(); 65 66 public static AntDeployInnerPanel XMLCfindAncestor(Component comp) { 67 Component found = null; 68 AntDeployInnerPanel ancestor = null; 69 70 found = AddinInnerPanel.findAncestor(comp); 71 if (found == null) {} 72 else if (found instanceof AntDeployInnerPanel) { 73 ancestor = (AntDeployInnerPanel) found; 74 } 75 return ancestor; 76 } 77 78 public AntDeployInnerPanel() { 79 try { 80 jbInit(); 81 pmInit(); 82 } catch (Exception ex) { 83 ex.printStackTrace(); 84 } 85 } 86 87 public void initPreferredSize() { 89 Dimension d = new Dimension(); 90 91 d.height = 425; 92 d.width = 550; 93 setPreferredSize(d); 94 } 95 96 public void clearAll() { 98 super.clearAll(); 99 layoutMain = null; 100 writeListeners = new WriteListener[0]; 101 } 102 protected void setNodes(OtterFileNode[] n) { 119 inputPanel.setNodes(n); 120 } 121 122 public void selectOutputTab() { 123 selectTab(outputPanel); 124 } 125 126 130 public synchronized WriteListener[] getWriteListeners() { 131 return writeListeners; 132 } 133 134 public synchronized void addWriteListener(WriteListener l) { 135 ArrayList list = null; 136 list = new ArrayList (Arrays.asList(writeListeners)); 137 if (!list.contains(l)) { 138 list.add(l); 139 list.trimToSize(); 140 writeListeners = new WriteListener[list.size()]; 141 writeListeners = (WriteListener[]) list.toArray(writeListeners); 142 } 143 list.clear(); 144 } 145 146 public synchronized void removeWriteListener(WriteListener l) { 147 ArrayList list = null; 148 list = new ArrayList (Arrays.asList(writeListeners)); 149 if (list.contains(l)) { 150 list.remove(l); 151 list.trimToSize(); 152 writeListeners = new WriteListener[list.size()]; 153 writeListeners = (WriteListener[]) list.toArray(writeListeners); 154 } 155 list.clear(); 156 } 157 158 159 public void read(OtterNode node) { 161 super.read(node); 162 generalPanel.setProject(getProject()); 163 outputPanel.setProject(getProject()); 164 inputPanel.setProject(getProject()); 165 contentPanel.setProject(getProject()); 166 } 167 168 public void write(OtterNode node) throws DataValidationException { 170 super.write(node); 171 if (getProject() == null) { 172 System.err.println("AntDeployInnerPanel.write(OtterProject p) : no project set"); 173 } else { 174 outputPanel.setProject(getProject()); 175 } 176 } 177 178 protected Component[] getFirstFocusComponents() { 180 Component[] comps = new Component[1]; 181 182 comps[0] = tab; 183 return comps; 184 } 185 186 public void save() { 191 super.save(); 192 } 194 public void clearOutput() { 197 outputPanel.clearOutput(); 199 } 200 201 protected void back() { 202 int index = tab.getSelectedIndex(); 203 int indexNew =0; 204 if (index > 0) { 205 indexNew = --index; 206 tab.setSelectedIndex(indexNew); 207 } 208 refresh(); 209 } 210 211 protected void next() { 212 int index = tab.getSelectedIndex(); 213 int indexNew =0; 214 if (index < tab.getTabCount()) { 215 indexNew = ++index; 216 tab.setSelectedIndex(indexNew); 217 } 218 refresh(); 219 } 220 private void refresh() { 224 Component back = null; 225 Component next = null; 226 boolean backEnable = true; 227 boolean nextEnable = true; 228 229 back = getBack(); 230 next = getNext(); 231 int index = tab.getSelectedIndex(); 232 233 if (index == 0) { 234 backEnable = false; 235 } else if (index == (tab.getTabCount() - 1)) { 236 nextEnable = false; 237 } 238 if (back != null) { 239 back.setEnabled(backEnable); 240 } 241 if (next != null) { 242 next.setEnabled(nextEnable); 243 } 244 } 246 247 private Component getNext() { 248 Component comp = ButtonPanel.findButton(getTopLevelAncestor(), 249 ButtonPanel.COMMAND_NEXT); 250 return comp; 251 } 252 253 private Component getBack() { 254 Component comp = ButtonPanel.findButton(getTopLevelAncestor(), 255 ButtonPanel.COMMAND_BACK); 256 return comp; 257 } 258 private void selectTab(final JPanel goPanel) { 259 SelectTab runSwing = null; 260 261 runSwing = new SelectTab(tab, goPanel); 262 try { 263 if (SwingUtilities.isEventDispatchThread()) { 264 runSwing.run(); 265 } else { 266 SwingUtilities.invokeAndWait(runSwing); 267 } 268 } catch (Exception e) { 269 e.printStackTrace(); 270 } 271 try { 272 Thread.sleep(500); 273 } catch (InterruptedException e) { 274 275 } 277 } 278 279 283 private void pmInit() { 284 tab.add(res.getString("General"), generalPanel); 285 tab.add(res.getString("Input"), inputPanel); 286 tab.add(res.getString("Content"), contentPanel); 287 tab.add(res.getString("Output"), outputPanel); 288 addWriteListener(outputPanel); 289 } 290 291 295 private void jbInit() throws Exception { 296 layoutMain = 297 (GridBagLayout) Beans.instantiate(getClass().getClassLoader(), 298 GridBagLayout.class.getName()); 299 300 outputPanel = 301 (AntOutputPanel) Beans.instantiate(getClass().getClassLoader(), 302 AntOutputPanel.class.getName()); 303 304 generalPanel = 305 (AntDeployGeneralPanel) Beans.instantiate(getClass().getClassLoader(), 306 AntDeployGeneralPanel.class.getName()); 307 308 inputPanel = 309 (AntDeployInputPanel) Beans.instantiate(getClass().getClassLoader(), 310 AntDeployInputPanel.class.getName()); 311 312 contentPanel = 313 (AntDeployContentPanel) Beans.instantiate(getClass().getClassLoader(), 314 AntDeployContentPanel.class.getName()); 315 316 tab = (JTabbedPane) Beans.instantiate(getClass().getClassLoader(), 317 JTabbedPane.class.getName()); 318 319 this.setLayout(layoutMain); 320 this.setMinimumSize(new Dimension(20, 20)); 321 this.setPreferredSize(new Dimension(20, 20)); 322 this.add(tab, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0 323 ,GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, -1, 6, 9), 5, 5)); 324 } 325 326 private class SelectTab implements Runnable { 327 private JTabbedPane tp = null; 328 private JPanel go = null; 329 330 protected SelectTab(JTabbedPane t, JPanel g) { 331 tp = t; 332 go = g; 333 } 334 335 synchronized public void run() { 336 tp.setSelectedComponent(go); 337 try { 338 SwingUtilities.windowForComponent(tp).repaint(); 339 } catch (NullPointerException e) { 340 341 } 343 } 344 345 } 346 347 } 348 349 | Popular Tags |