1 19 20 package org.netbeans.modules.j2ee.ddloaders.web.test.util; 21 22 import java.io.File ; 23 import java.awt.*; 24 25 import org.netbeans.modules.xml.multiview.ToolBarMultiViewElement; 26 import org.netbeans.modules.xml.multiview.ui.DefaultTablePanel; 27 import org.netbeans.modules.xml.multiview.ui.SectionPanel; 28 import org.netbeans.modules.j2ee.ddloaders.web.DDDataObject; 29 import org.netbeans.modules.j2ee.ddloaders.web.multiview.DDBeanTableModel; 30 31 import javax.swing.*; 32 33 37 public class Helper { 38 39 public static File getDDFile(File dataDir) { 40 String result = dataDir.getAbsolutePath() + "/projects/webapp/web/WEB-INF/web.xml"; 41 return new File (result); 42 } 43 44 public static DDBeanTableModel getContextParamsTableModel(final DDDataObject dObj) { 45 final ToolBarMultiViewElement multiViewElement = getMultiViewElement(dObj); 46 JPanel sectionPanel = getSectionPanel(multiViewElement); 47 Component[] children = sectionPanel.getComponents(); 48 DefaultTablePanel tablePanel = null; 49 for (int i = 0; i < children.length; i++) { 50 if (children[i] instanceof DefaultTablePanel) { 51 tablePanel = (DefaultTablePanel) children[i]; 52 break; 53 } 54 } 55 return (DDBeanTableModel) tablePanel.getModel(); 56 } 57 58 private static JPanel getSectionPanel(final ToolBarMultiViewElement multiViewElement) { 59 return new StepIterator() { 60 JPanel sectionPanel; 61 62 public boolean step() throws Exception { 63 SectionPanel outerPanel = multiViewElement.getSectionView().findSectionPanel("context_params"); 64 sectionPanel = outerPanel == null ? null : outerPanel.getInnerPanel(); 65 return sectionPanel != null; 66 } 67 }.sectionPanel; 68 } 69 70 public static ToolBarMultiViewElement getMultiViewElement(final DDDataObject dObj) { 71 return new StepIterator() { 72 ToolBarMultiViewElement multiViewElement; 73 74 public boolean step() throws Exception { 75 multiViewElement = dObj.getActiveMVElement(); 76 return multiViewElement != null; 77 } 78 }.multiViewElement; 79 } 80 81 public static void sleep(int ms) { 82 try { 83 Thread.sleep(ms); 84 } catch (InterruptedException ex){} 85 } 86 87 public static void waitForDispatchThread() { 88 if (SwingUtilities.isEventDispatchThread()) { 89 return; 90 } 91 final boolean[] finished = new boolean[]{false}; 92 SwingUtilities.invokeLater(new Runnable () { 93 public void run() { 94 finished[0] = true; 95 } 96 }); 97 new StepIterator() { 98 public boolean step() throws Exception { 99 return finished[0]; 100 } 101 }; 102 } 103 } | Popular Tags |