Source Code Cross Referenced for DesignerPaneOperator.java in  » IDE-Netbeans » visualweb.api.designer » org » netbeans » modules » visualweb » gravy » designer » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » visualweb.api.designer » org.netbeans.modules.visualweb.gravy.designer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.visualweb.gravy.designer;
043:
044:        import org.netbeans.modules.visualweb.css2.ModelViewMapper;
045:        import org.netbeans.modules.visualweb.designer.WebForm;
046:        import org.netbeans.modules.visualweb.gravy.Util;
047:        import org.netbeans.modules.visualweb.css2.CssBox;
048:        import org.netbeans.modules.visualweb.designer.*;
049:        import org.netbeans.modules.visualweb.designer.jsf.*;
050:        import org.netbeans.modules.visualweb.designer.jsf.ui.*;
051:        import org.netbeans.modules.visualweb.gravy.properties.*;
052:        import java.awt.*;
053:        import org.netbeans.jemmy.ComponentChooser;
054:        import org.netbeans.jemmy.operators.*;
055:        import org.netbeans.modules.visualweb.gravy.toolbox.PaletteContainerOperator;
056:        import org.netbeans.jellytools.Bundle;
057:        import org.netbeans.modules.visualweb.designer.html.HtmlAttribute;
058:        import com.sun.rave.designtime.DesignBean;
059:        import org.netbeans.modules.visualweb.gravy.RaveWindowOperator;
060:        import org.openide.windows.TopComponent;
061:        import org.netbeans.jemmy.QueueTool;
062:        import org.netbeans.modules.visualweb.api.designer.DomProvider;
063:
064:        /**
065:         * This class implements test functionality for the Design View of a project web-page.
066:         */
067:        public class DesignerPaneOperator extends JComponentOperator {
068:            private static final String DESIGNER_BUTTON_DESIGN = org.netbeans.modules.visualweb.gravy.Bundle
069:                    .getStringTrimmed(
070:                            "org.netbeans.modules.visualweb.project.jsfloader.Bundle",
071:                            "CTL_DesignerTabCaption"),//"Design"
072:                    DESIGNER_BUTTON_JSP = org.netbeans.modules.visualweb.gravy.Bundle
073:                            .getStringTrimmed(
074:                                    "org.netbeans.modules.visualweb.project.jsfloader.Bundle",
075:                                    "CTL_JspTabCaption"),//"JSP",
076:                    DESIGNER_BUTTON_JAVA = org.netbeans.modules.visualweb.gravy.Bundle
077:                            .getStringTrimmed(
078:                                    "org.netbeans.modules.visualweb.project.jsfloader.Bundle",
079:                                    "CTL_JavaTabCaption");//"Java";
080:
081:            protected static String defaultPalette = "JSFSTD";
082:            protected String currentPalette = defaultPalette;
083:
084:            /**
085:             * Creates a new instance of this class
086:             * @param cont an object ContainerOperator related to container, which 
087:             * includes window of web-page.
088:             */
089:            public DesignerPaneOperator(ContainerOperator cont) {
090:                super (cont, new DesignerPaneChooser());
091:            }
092:
093:            /**
094:             * Creates a new instance of this class
095:             * @param cont an object ContainerOperator related to container, which 
096:             * includes window of web-page.
097:             * @param index a number of desired component if container includes several
098:             * similar components
099:             */
100:            public DesignerPaneOperator(ContainerOperator cont, int index) {
101:                super (cont, new DesignerPaneChooser(), index);
102:            }
103:
104:            /**
105:             * Creates a new instance of this class
106:             */
107:            public DesignerPaneOperator() {
108:                this (RaveWindowOperator.getDefaultRave());
109:            }
110:
111:            /**
112:             * Returns a Design View of a project web-page.
113:             * @return an object ContainerOperator
114:             */
115:            public ContainerOperator getDesignerView() {
116:                return (new ContainerOperator(getContainer(new Operator.Finder(
117:                        JsfTopComponent.class))));
118:            }
119:
120:            /**
121:             * Returns a center coordinate of component, placed on Design View.
122:             * @param comp_id a component identifier
123:             * @return an object Point
124:             */
125:            public Point getComponentCenter(String comp_id) {
126:                CssBox box = getCssBox(getDesignBean(comp_id));
127:                if (box != null) {
128:                    return (new Point(box.getAbsoluteX(), box.getAbsoluteY()));
129:                }
130:                return null;
131:            }
132:
133:            /**
134:             * Returns a coordinate of component top-left corner, placed on Design View.
135:             * @param componentID a component identifier
136:             * @return an object Point
137:             */
138:            public Point getComponentLocation(String componentID) {
139:                Rectangle compRect = getComponentRectangle(componentID);
140:                if (compRect != null) {
141:                    return (compRect.getLocation());
142:                }
143:                return null;
144:            }
145:
146:            /**
147:             * Returns measurements of a component, placed on Design View.
148:             * @param componentID a component identifier
149:             * @return an object Rectangle
150:             */
151:            public Rectangle getComponentRectangle(String componentID) {
152:                CssBox box = getCssBox(getDesignBean(componentID));
153:                if (box != null) {
154:                    return (box.getExtentsRectangle());
155:                }
156:                return null;
157:            }
158:
159:            private DesignBean getDesignBean(String componentID) {
160:                if ((componentID == null) || (componentID.length() < 1))
161:                    return null;
162:
163:                DesignerPane designerPane = (DesignerPane) getSource();
164:                //        DesignBean bean =
165:                //                designerPane.getWebForm().getModel().getLiveUnit().getBeanByName(
166:                //                componentID);
167:                //        org.openide.filesystems.FileObject jspFileObject = designerPane.getWebForm().getJspDataObject().getPrimaryFile();
168:                WebForm webForm = designerPane.getWebForm();
169:                DomProvider domProvider = webForm.getDomProvider();
170:                JsfForm jsfForm = JsfForm
171:                        .findJsfFormForDomProvider(domProvider);
172:                org.openide.filesystems.FileObject jspFileObject = jsfForm
173:                        .getJspDataObject().getPrimaryFile();
174:                org.netbeans.modules.visualweb.insync.models.FacesModel facesModel = org.netbeans.modules.visualweb.insync.models.FacesModel
175:                        .getInstance(jspFileObject);
176:                DesignBean bean = facesModel.getLiveUnit().getBeanByName(
177:                        componentID);
178:                return bean;
179:            }
180:
181:            private CssBox getCssBox(DesignBean designBean) {
182:                if (designBean == null)
183:                    return null;
184:                DesignerPane designerPane = (DesignerPane) getSource();
185:                /*
186:                CssBox cssBox = ModelViewMapper.findBox(designerPane.getPageBox(), designBean); 
187:                                                      //designerPane.getWebForm().getMapper().findBox(designBean);
188:                 */
189:                WebForm webForm = designerPane.getWebForm();
190:                CssBox cssBox = ModelViewMapper.findBox(webForm.getPane()
191:                        .getPageBox(), webForm.getSelection()
192:                        .getSelectedComponentRootElements()[0]);
193:                return cssBox;
194:            }
195:
196:            /**
197:             * Invokes a popup menu, related to a component, placed on Design View.
198:             * @param comp_id a component identifier
199:             */
200:            public void clickForPopup(String comp_id) {
201:                Point p = getComponentCenter(comp_id);
202:                clickForPopup(p.x, p.y);
203:            }
204:
205:            /**
206:             * Clicks mouse on a component, placed on Design View.
207:             * @param comp_id a component identifier
208:             * @param clickCount a number of clicks
209:             */
210:            public void clickMouse(String comp_id, int clickCount) {
211:                Point p = getComponentCenter(comp_id);
212:                clickMouse(p.x, p.y, clickCount);
213:            }
214:
215:            /**
216:             * Selects a component on Design View.
217:             * @param comp_id a component identifier
218:             */
219:            public void select(String comp_id) {
220:                Point p = getComponentCenter(comp_id);
221:                clickMouse(p.x, p.y, 1);
222:            }
223:
224:            public static class DesignerPaneChooser implements  ComponentChooser {
225:                public boolean checkComponent(Component comp) {
226:                    return (comp instanceof  org.netbeans.modules.visualweb.designer.DesignerPane);
227:                }
228:
229:                public String getDescription() {
230:                    return (DesignerPane.class.getName());
231:                }
232:            }
233:
234:            /**
235:             * Adds a component on Design View.
236:             * @param component a component name
237:             * @param x coordinate x of top-left component corner on Design View
238:             * @param y coordinate y of top-left component corner on Design View
239:             */
240:            public void addComponent(String component, int x, int y) {
241:                addComponent(component, x, y, null, null);
242:            }
243:
244:            /**
245:             * Adds a component on Design View.
246:             * @param component a component name
247:             * @param x coordinate x of top-left component corner on Design View
248:             * @param y coordinate y of top-left component corner on Design View
249:             * @param id a name of modified component property
250:             * @param value a value of modified component property
251:             */
252:            public void addComponent(String component, int x, int y, String id,
253:                    String value) {
254:                addComponentFromPalette(component, x, y, id, value,
255:                        currentPalette);
256:            }
257:
258:            /**
259:             * Sets a component palette used by default.
260:             * @param palName a palette name
261:             */
262:            public static void setDefaultPalette(String palName) {
263:                defaultPalette = palName;
264:            }
265:
266:            /**
267:             * Sets a component palette "BraveHeart" as a default palette.
268:             */
269:            public static void setDefaultBraveHeartPalette() {
270:                defaultPalette = "Basic";
271:            }
272:
273:            /**
274:             * Sets a component palette "Standard" as a default palette.
275:             */
276:            public static void setDefaultStandardPalette() {
277:                defaultPalette = "JSFSTD";
278:            }
279:
280:            /**
281:             * Sets a current component palette.
282:             * @param palName a palette name
283:             */
284:            public void setPalette(String palName) {
285:                currentPalette = palName;
286:            }
287:
288:            /**
289:             * Sets a component palette "BraveHeart" as a current palette.
290:             */
291:            public void setBraveHeartPalette() {
292:                setPalette("Basic");
293:            }
294:
295:            /**
296:             * Sets a component palette "Standard" as a current palette.
297:             */
298:            public void setStandardPalette() {
299:                setPalette("JSFSTD");
300:            }
301:
302:            /**
303:             * Adds a component on Design View.
304:             * @param component a component name
305:             * @param x coordinate x of top-left component corner on Design View
306:             * @param y coordinate y of top-left component corner on Design View
307:             * @param id a name of modified component property
308:             * @param value a value of modified component property
309:             * @param palName a palette name
310:             */
311:            public void addComponentFromPalette(String component, int x, int y,
312:                    String id, String value, String palName) {
313:
314:                // Wait for the Portfolio to appear
315:                Util.wait(2000);
316:                PaletteContainerOperator palette = PaletteContainerOperator
317:                        .showPalette(Bundle.getStringTrimmed(
318:                                "com.sun.rave.toolbox.Bundle", "COMPONENTS"),
319:                                palName);
320:
321:                System.out
322:                        .println("======================================================================");
323:                System.out.println(palName + " Components");
324:                System.out
325:                        .println("======================================================================");
326:                // workaround for CR 6258411
327:                Point clickPoint = palette.getClickPoint(component);
328:                new QueueTool().waitEmpty();
329:                palette.getComponentsTree().clickMouse(clickPoint.x,
330:                        clickPoint.y, 1);
331:                Util.wait(300);
332:
333:                palette.addComponent(component, this , new Point(x, y));
334:
335:                //@todo This is temporary - remove after Rave bug will be fixed
336:                //select component
337:                //clickMouse(1,1,1);
338:                //clickMouse(x,y,1);
339:
340:                Util.wait(1000);
341:
342:                // Change properties
343:
344:                SheetTableOperator props = new SheetTableOperator();
345:                if (id != null) {
346:                    props.setTextValue("id", id);
347:                    Util.wait(1000);
348:                }
349:                if (value != null) {
350:                    props.setTextValue("value", value);
351:                    Util.wait(1000);
352:                }
353:
354:            }
355:
356:            /**
357:             * Switch to JSP Editor of web-page.
358:             */
359:            public static void switchToJSPSource() {
360:                switchToSource(DESIGNER_BUTTON_JSP);
361:            }
362:
363:            /**
364:             * Switch to Java Editor of web-page.
365:             */
366:            public static void switchToJavaSource() {
367:                switchToSource(DESIGNER_BUTTON_JAVA);
368:            }
369:
370:            /**
371:             * Switch to Design View of web-page.
372:             */
373:            public static void switchToDesignerPane() {
374:                switchToSource(DESIGNER_BUTTON_DESIGN);
375:            }
376:
377:            private static void switchToSource(String toggleButtonText) {
378:                //org.netbeans.jellytools.TopComponentOperator topComponent =
379:                //new org.netbeans.jellytools.TopComponentOperator("Page1.jsp");
380:                //    new org.netbeans.jellytools.TopComponentOperator(Util.getMainWindow());
381:                //Util.wait(1000);
382:                JToggleButtonOperator toggleButton = new JToggleButtonOperator(
383:                        Util.getMainWindow(), toggleButtonText);
384:                Util.wait(1000);
385:                toggleButton.setSelected(true);
386:                Util.wait(1000);
387:            }
388:
389:            /**
390:             * Extracts and returns a coordinate of a component from a window "Properties".
391:             * @return an object Point
392:             */
393:            public Point getCoords() {
394:
395:                PropertySheetOperator pso = new PropertySheetOperator(Util
396:                        .getMainWindow());
397:                PropertySheetTabOperator psto = new PropertySheetTabOperator(
398:                        pso);
399:                // set a new comparator which should find the required property by performing
400:                // a strictly comparison of a property name with a given pattern
401:                psto.setComparator(new Operator.DefaultStringComparator(true,
402:                        true));
403:
404:                // Name of the property is style
405:                Property pr = new Property(psto, "style" /* Bundle.getResourceString("CSS_Style") */);
406:                String propValue = pr.getValue();
407:
408:                //value of style property (example) = position: absolute; left: 288px; top: 96px
409:
410:                int xLoc = HtmlAttribute.parseInt(propValue.substring(propValue
411:                        .indexOf("left: ") + 6));
412:                int yLoc = HtmlAttribute.parseInt(propValue.substring(propValue
413:                        .indexOf("top: ") + 5));
414:                //        int xLoc =  new Integer(propValue.substring(propValue.indexOf("left: ")+6,propValue.indexOf("px;"))).intValue();
415:                //        int yLoc = new Integer(propValue.substring(propValue.indexOf("top: ")+5,propValue.indexOf("px; position:"))).intValue();
416:
417:                return new Point(xLoc, yLoc);
418:            }
419:
420:            public void makeComponentVisible() {
421:                TopComponent theComponent = (TopComponent) findContainerUnder(
422:                        getSource(), new ComponentChooser() {
423:                            public boolean checkComponent(Component comp) {
424:                                return (comp instanceof  TopComponent);
425:                            }
426:
427:                            public String getDescription() {
428:                                return ("TopComponent");
429:                            }
430:                        });
431:
432:                final TopComponent topComponent = theComponent;
433:                try {
434:                    javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
435:                        public void run() {
436:                            String topComponentString = org.openide.windows.WindowManager
437:                                    .getDefault().findTopComponentID(
438:                                            topComponent);
439:                            System.out
440:                                    .println("++++++++++++++++++++++++++++++++++++++++++++++++");
441:                            System.out.println(topComponentString);
442:                            System.out
443:                                    .println("++++++++++++++++++++++++++++++++++++++++++++++++");
444:                        }
445:                    });
446:                } catch (Exception e) {
447:                    e.printStackTrace();
448:                }
449:                new org.netbeans.jellytools.TopComponentOperator(theComponent)
450:                        .makeComponentVisible();
451:                super .makeComponentVisible();
452:            }
453:
454:            /**
455:             * Sets an image to a component via Image customizer.
456:             * @param componentID a component identifier
457:             * @param imagePath a path to an image file
458:             */
459:            public void setImage(String componentID, String imagePath) {
460:                clickForPopup(componentID); // this api not working 6/1/06
461:                Util.wait(500);
462:                new JPopupMenuOperator().pushMenuNoBlock(Bundle
463:                        .getStringTrimmed(
464:                                "org.netbeans.modules.visualweb.gravy.Bundle",
465:                                "DesignerMenuItem_SetImage"));
466:                JDialogOperator dialog = new JDialogOperator(Bundle
467:                        .getStringTrimmed(
468:                                "org.netbeans.modules.visualweb.gravy.Bundle",
469:                                "DesignerMenuItem_SetImage"));
470:                JTextFieldOperator tf_Name = new JTextFieldOperator(dialog, 0);
471:                tf_Name.setText(imagePath);
472:                Util.wait(1000);
473:                new JButtonOperator(dialog, Bundle.getStringTrimmed(
474:                        "org.netbeans.modules.visualweb.gravy.Bundle", "OK"))
475:                        .pushNoBlock();
476:                dialog.waitClosed();
477:                Util.wait(1000);
478:            }
479:
480:            /**
481:             * Sets an image to a component via Image customizer.
482:             * @param x coordinate x of top-left component corner on Design View
483:             * @param y coordinate y of top-left component corner on Design View
484:             * @param imagePath a path to an image file
485:             */
486:            public void setImage(int x, int y, String imagePath) {
487:                clickForPopup(x, y);
488:                Util.wait(500);
489:                new JPopupMenuOperator().pushMenuNoBlock(Bundle
490:                        .getStringTrimmed(
491:                                "org.netbeans.modules.visualweb.gravy.Bundle",
492:                                "DesignerMenuItem_SetImage"));
493:                JDialogOperator dialog = new JDialogOperator(Bundle
494:                        .getStringTrimmed(
495:                                "org.netbeans.modules.visualweb.gravy.Bundle",
496:                                "Dialog_ImageCustomizer"));
497:                (new JTextFieldOperator(dialog, 0)).enterText(imagePath);
498:                Util.wait(1000);
499:                new JButtonOperator(dialog, Bundle.getStringTrimmed(
500:                        "org.netbeans.modules.visualweb.gravy.Bundle",
501:                        "Button_OK")).pushNoBlock();
502:                dialog.waitClosed();
503:                Util.wait(1000);
504:            }
505:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.