KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ddloaders > web > test > util > Helper


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.ddloaders.web.test.util;
21
22 import java.io.File JavaDoc;
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 /**
34  *
35  * @author Milan Kuchtiak
36  */

37 public class Helper {
38
39     public static File JavaDoc getDDFile(File JavaDoc dataDir) {
40         String JavaDoc result = dataDir.getAbsolutePath() + "/projects/webapp/web/WEB-INF/web.xml";
41         return new File JavaDoc(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 JavaDoc {
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 JavaDoc {
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 JavaDoc 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 JavaDoc() {
93             public void run() {
94                 finished[0] = true;
95             }
96         });
97         new StepIterator() {
98             public boolean step() throws Exception JavaDoc {
99                 return finished[0];
100             }
101         };
102     }
103 }
Popular Tags