Source Code Cross Referenced for DndHandler.java in  » IDE-Netbeans » visualweb.api.designer » org » netbeans » modules » visualweb » 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.designer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003:         *
0004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005:         *
0006:         * The contents of this file are subject to the terms of either the GNU
0007:         * General Public License Version 2 only ("GPL") or the Common
0008:         * Development and Distribution License("CDDL") (collectively, the
0009:         * "License"). You may not use this file except in compliance with the
0010:         * License. You can obtain a copy of the License at
0011:         * http://www.netbeans.org/cddl-gplv2.html
0012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013:         * specific language governing permissions and limitations under the
0014:         * License.  When distributing the software, include this License Header
0015:         * Notice in each file and include the License file at
0016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
0017:         * particular file as subject to the "Classpath" exception as provided
0018:         * by Sun in the GPL Version 2 section of the License file that
0019:         * accompanied this code. If applicable, add the following below the
0020:         * License Header, with the fields enclosed by brackets [] replaced by
0021:         * your own identifying information:
0022:         * "Portions Copyrighted [year] [name of copyright owner]"
0023:         *
0024:         * Contributor(s):
0025:         *
0026:         * The Original Software is NetBeans. The Initial Developer of the Original
0027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
0028:         * Microsystems, Inc. All Rights Reserved.
0029:         *
0030:         * If you wish your version of this file to be governed by only the CDDL
0031:         * or only the GPL Version 2, indicate your decision by adding
0032:         * "[Contributor] elects to include this software in this distribution
0033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034:         * single choice of license, a recipient has the option to distribute
0035:         * your version of this file under either the CDDL, the GPL Version 2 or
0036:         * to extend the choice of license to its licensees as provided above.
0037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
0038:         * Version 2 license, then the option applies only if the new code is
0039:         * made subject to such option by the copyright holder.
0040:         */
0041:        package org.netbeans.modules.visualweb.designer;
0042:
0043:        import java.awt.Dimension;
0044:        import java.awt.Point;
0045:        import java.awt.datatransfer.Transferable;
0046:        import java.lang.ref.WeakReference;
0047:        import javax.swing.JComponent;
0048:        import javax.swing.SwingUtilities;
0049:
0050:        import org.netbeans.modules.visualweb.api.designer.DomProvider;
0051:        import org.netbeans.modules.visualweb.api.designer.DomProvider.DomPosition;
0052:        import org.netbeans.modules.visualweb.css2.ModelViewMapper;
0053:        import org.netbeans.modules.visualweb.css2.CssBox;
0054:
0055:        import org.openide.awt.StatusDisplayer;
0056:        import org.openide.util.NbBundle;
0057:
0058:        import org.w3c.dom.Element;
0059:        import org.w3c.dom.Node;
0060:
0061:        /**
0062:         * The transfer handler for the designer pane
0063:         *
0064:         * @todo I need to call canCreateFacet to check if a facet drop is allowed in those
0065:         *  places where I use it
0066:         * @todo I need to call canMoveBean instead of canCreateBean for reparenting/moving
0067:         *  and of course these would need to do more specific acceptBean/child checking!
0068:         *
0069:         * @author  Tor Norbye
0070:         * @author  Carl Quinn
0071:         */
0072:        public class DndHandler /*extends TransferHandler*/{
0073:
0074:            //    /** XXX Copy from DropSupport. */
0075:            //    private static final int DROP_ABOVE  = -1;
0076:            //    private static final int DROP_CENTER = 0;
0077:            //    private static final int DROP_BELOW  = 1;
0078:
0079:            /** State indicating that a drop is not allowed */
0080:            public static final int DROP_DENIED = DomProvider.DROP_DENIED;
0081:
0082:            /** State indicating that the drop is allowed and will cause a link */
0083:            public static final int DROP_PARENTED = DomProvider.DROP_PARENTED;
0084:
0085:            //    /** Directory prefix under the project root to place the web folder */
0086:            //    private static final String WEB = "web"; // NOI18N
0087:
0088:            //    /** Directory prefix under the web folder root to place the resource files */
0089:            //    private static final String RESOURCES = "/resources/"; // NOI18N
0090:
0091:            /** State indicating that the drop is allowed and the bean will be
0092:             *  parented by one of the beans under the cursor */
0093:            public static final int DROP_LINKED = DomProvider.DROP_LINKED;
0094:
0095:            private static final transient boolean DONT_SHOW_MATCHES = System
0096:                    .getProperty("designer.dontShowDropTarget") != null;
0097:
0098:            // Current drag & drop transfer handler registry
0099:
0100:            //    /** XXX This is a hack. The designer needs access to the
0101:            //     * transferable as part of a DropTargetDragEvent notification (to
0102:            //     * for example determine whether the drop location is valid, based
0103:            //     * on the beans being dropped and the components under the
0104:            //     * cursor. For some reason, the DropTargetDragEvent does not
0105:            //     * provide any access to the transferable. So instead we provide a
0106:            //     * way for the designer to look up the most recent
0107:            //     * transferable. It's public here since there are a couple of
0108:            //     * other sources for drags (such as the document outline, and the
0109:            //     * server navigator, and rather than having the designer look in
0110:            //     * multiple places and figure out which transferable is most
0111:            //     * recent, all drag initiators will share this field.  The
0112:            //     * designer can also clear it when it knows it's done with it, to
0113:            //     * allow gc.
0114:            //     * JDK15 In JDK15 there is a new method on the drop target listener
0115:            //     * which will provide the transferable. This will allow us to rip
0116:            //     * all this out and simply obtain the transferable directly rather
0117:            //     * than relying on the drag source to set it.
0118:            //     */
0119:            //    private static transient Transferable transferable;
0120:
0121:            private transient WebForm webform;
0122:
0123:            /**
0124:             * Used during an importBean: set to the bean to select when
0125:             * we're done processing. Different methods override which
0126:             * item should be selected.
0127:             */
0128:            //    private transient DesignBean select; // have we found a target to select?
0129:            //    private MarkupDesignBean recentDropTarget;
0130:            // XXX #123995 Leaks element which document might get replaced.
0131:            //    private transient Element recentDropTargetComponentRootElement;
0132:            private transient WeakReference<Element> recentDropTargetComponentRootElementWRef = new WeakReference<Element>(
0133:                    null);
0134:            //    private transient DesignBean currentMatched;
0135:            private transient Element currentMatchedComponentRootElement;
0136:            //    private transient MarkupMouseRegion currentRegion;
0137:            private transient Element currentRegionElement;
0138:            private transient String lastMessage;
0139:            private transient Point dropPoint;
0140:            private transient Dimension dropSize;
0141:            //    private transient Position insertPos = Position.NONE;
0142:            private transient DomPosition insertPos = DomPosition.NONE;
0143:            private transient int dropAction;
0144:
0145:            public DndHandler(WebForm webform) {
0146:                this .webform = webform;
0147:                if (DesignerUtils.DEBUG) {
0148:                    DesignerUtils.debugLog(getClass().getName() + "()");
0149:                }
0150:                if (webform == null) {
0151:                    throw (new IllegalStateException("Null webform"));
0152:                }
0153:            }
0154:
0155:            //    private static final DataFlavor FLAVOR_DISPLAY_ITEM = new DataFlavor(
0156:            //            DataFlavor.javaJVMLocalObjectMimeType + "; class=" + DisplayItem.class.getName(), // NOI18N
0157:            //            "RAVE_PALETTE_ITEM"); // TODO get rid of such name.
0158:
0159:            /**
0160:             * This method causes a transfer to a component from a clipboard or a DND drop operation.  The
0161:             * Transferable represents the data to be imported into the component.
0162:             *
0163:             * @param comp The component to receive the transfer.  This argument is provided to enable
0164:             *  sharing of TransferHandlers by multiple components.
0165:             * @param t The data to import
0166:             * @return  true if the data was inserted into the component, false otherwise.
0167:             */
0168:            public boolean importData(final JComponent comp,
0169:                    final Transferable t) {
0170:                //        Object transferData = null;
0171:                //
0172:                //        try {
0173:                ////            DataFlavor importFlavor = getImportFlavor(t.getTransferDataFlavors());
0174:                //            DataFlavor importFlavor = webform.getImportFlavor(t.getTransferDataFlavors());
0175:                //
0176:                //            if (importFlavor == null) {
0177:                //                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, 
0178:                //                        new IllegalStateException("Unusable transfer flavors " + Arrays.asList(t.getTransferDataFlavors()))); // NOI18N
0179:                //
0180:                //                return false;
0181:                //            }
0182:                //
0183:                //            // XXX What was before in SelectionTopComp.
0184:                //            if (importFlavor.getMimeType().startsWith("application/x-creator-")) { // NOI18N
0185:                //                // XXX Handling of cut/copied bean. Needs to be improved/moved later.
0186:                ////                SelectionTopComp selectionTopComp;
0187:                ////                
0188:                ////                if (comp instanceof SelectionTopComp) {
0189:                ////                    selectionTopComp = (SelectionTopComp)comp;
0190:                ////                } else {
0191:                ////                    selectionTopComp = (SelectionTopComp)SwingUtilities.getAncestorOfClass(SelectionTopComp.class, comp);
0192:                ////                }
0193:                ////                
0194:                ////                if (selectionTopComp == null) {
0195:                ////                    // XXX
0196:                ////                    return false;
0197:                ////                }
0198:                ////                
0199:                //////                DesignBean parent = selectionTopComp.getPasteParent();
0200:                ////                Element parentComponentRootElement = selectionTopComp.getPasteParentComponent();
0201:                //////                MarkupPosition pos = selectionTopComp.getPasteMarkupPosition();
0202:                ////                Point location = selectionTopComp.getPastePosition();
0203:                //////                DesignBean[] beans = selectionTopComp.pasteBeans(webform, t, parent, pos, location);
0204:                //////                Element[] componentRootElements = SelectionTopComp.pasteComponents(webform, t, parentComponentRootElement, location);
0205:                ////                
0206:                ////                if (location != null) {
0207:                ////                    GridHandler gridHandler = webform.getGridHandler();
0208:                ////                    location.x = gridHandler.snapX(location.x);
0209:                ////                    location.y = gridHandler.snapY(location.y);
0210:                ////                }
0211:                ////                Element[] componentRootElements = webform.pasteComponents(t, parentComponentRootElement, location);
0212:                ////
0213:                //////                if ((beans != null) && (beans.length > 0)) {
0214:                //////                    selectionTopComp.selectBeans(beans);
0215:                //////                }
0216:                ////                if (componentRootElements.length > 0) {
0217:                ////                    selectionTopComp.selectComponents(componentRootElements);
0218:                ////                }
0219:                ////                return true;
0220:                //                return webform.tcImportComponentData(comp, t);
0221:                //            } // TEMP
0222:                //            
0223:                //            Class rc = importFlavor.getRepresentationClass();
0224:                //            
0225:                //            transferData = t.getTransferData(importFlavor);
0226:                //            
0227:                ////            if (rc == DisplayItem.class) {
0228:                ////                // Create a new type
0229:                ////                transferData = t.getTransferData(importFlavor);
0230:                ////
0231:                ////                if (!(transferData instanceof DisplayItem)) {
0232:                ////                    ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, 
0233:                ////                            new IllegalStateException("Invalid transfer data=" + transferData));
0234:                ////
0235:                ////                    return false;
0236:                ////                }
0237:                ////            } else if (rc == DesignBean.class) {
0238:                ////                transferData = t.getTransferData(importFlavor);
0239:                ////
0240:                ////                if (!(transferData instanceof DesignBean[])) {
0241:                ////                    ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, 
0242:                ////                            new IllegalStateException("Invalid transfer data=" + transferData));
0243:                ////
0244:                ////                    return false;
0245:                ////                }
0246:                ////            } else if (rc.isAssignableFrom(List.class)) {
0247:                ////                transferData = t.getTransferData(importFlavor);
0248:                ////
0249:                ////                if (!(transferData instanceof List)) {
0250:                ////                    ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, 
0251:                ////                            new IllegalStateException("Invalid transfer data=" + transferData));
0252:                ////
0253:                ////                    return false;
0254:                ////                }
0255:                ////            } else if (rc.isAssignableFrom(org.openide.nodes.Node.class)) {
0256:                ////                transferData = t.getTransferData(importFlavor);
0257:                ////
0258:                ////                if (!(transferData instanceof org.openide.nodes.Node)) {
0259:                ////                    ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, 
0260:                ////                            new IllegalStateException("Invalid transfer data=" + transferData));
0261:                ////
0262:                ////                    return false;
0263:                ////                }
0264:                ////            } else
0265:                //                
0266:                //            if (rc == String.class) {
0267:                ////                transferData = t.getTransferData(importFlavor);
0268:                //
0269:                //                // XXX #6332049 When in inline editing we shouldn't steal the paste
0270:                //                // (at least for the JTextComponent's.
0271:                //                // This is just a workaround, it shouldn't be done this way.
0272:                //                // actions should be created based on context (and inline editing
0273:                //                // context is diff from the designer pane one).
0274:                //                if(webform.getManager().isInlineEditing()) {
0275:                //                    Component focusOwner = FocusManager.getCurrentManager().getFocusOwner();
0276:                //                    if(focusOwner instanceof JTextComponent) {
0277:                //                        JTextComponent textComp = (JTextComponent)focusOwner;
0278:                //                        textComp.paste();
0279:                //                        return true;
0280:                //                    } 
0281:                //                }
0282:                //
0283:                //                // XXX Flowlayout mode?
0284:                ////                if (webform.getPane().getCaret() != null) {
0285:                //                if (webform.getPane().hasCaret()) {
0286:                ////                    webform.getPane().getCaret().replaceSelection((String)transferData);
0287:                //                    webform.getPane().replaceSelection((String)transferData);
0288:                //                    return true;
0289:                //                }
0290:                //                
0291:                ////                String s = (String)transferData;
0292:                ////
0293:                ////                File file = extractFileFromString(s);
0294:                ////                if (file != null) {
0295:                ////                    transferData = file;
0296:                ////                }
0297:                //            }
0298:                //        } catch (Exception e) {
0299:                //            ErrorManager.getDefault().notify(e);
0300:                //
0301:                //            return false;
0302:                //        }
0303:
0304:                //        // XXX
0305:                ////        if (dropPoint == null && insertPos == Position.NONE) {
0306:                //        if (dropPoint == null && insertPos == DomPosition.NONE) {
0307:                ////            DesignerTopComp designerTC;
0308:                ////            if (comp instanceof DesignerTopComp) {
0309:                ////                designerTC = (DesignerTopComp)comp;
0310:                ////            } else {
0311:                ////                designerTC = (DesignerTopComp)SwingUtilities.getAncestorOfClass(DesignerTopComp.class, comp);
0312:                ////            }
0313:                ////            
0314:                ////            if (designerTC != null) {
0315:                ////                dropPoint = designerTC.getPastePosition();
0316:                ////                // XXX #6185935 There should be always a point specified.
0317:                ////                if (dropPoint == null) {
0318:                ////                    // By default, the left upper corner.
0319:                ////                    dropPoint = new Point(0,0);
0320:                ////                }
0321:                ////            }
0322:                ////            dropPoint = webform.tcGetPastePosition();
0323:                //            dropPoint = webform.getPastePoint();
0324:                //        }
0325:
0326:                //        // Delay this operation so that the other listener, DesignerPane.
0327:                //        // DesignerDropListener, can provide a pixel position for this drop
0328:                //        // TODO Consider only doing this when in grid mode
0329:                //        // TODO Instead of creating a new runnable each time, at a minumum
0330:                //        //   keep the runnable around, or alternatively simply make this
0331:                //        //   object a Runnable and invokeLater on this.
0332:                ////        final Object transfer = transferData;
0333:                //        SwingUtilities.invokeLater(new Runnable() {
0334:                //                public void run() {
0335:                ////                    try {
0336:                ////                        importDataDelayed(comp, t, transfer);
0337:                //                        importDataDelayed(comp, t);
0338:                ////                    } catch (Exception e) {
0339:                ////                        ErrorManager.getDefault().notify(e);
0340:                ////                        return;
0341:                ////                    }
0342:                //                }
0343:                //            });
0344:                //
0345:                //        // We don't actually know if the drop succeeded since we have to defer
0346:                //        // to pick up the grid coordinate...
0347:                //        // XXX TODO Provide your own impl of DropTarget to avoid scheduling later this task.
0348:                //        return true;
0349:                // XXX #101880 Now we can do it sync (see DesignerPaneDropTarget#drop).
0350:                return importDataExt(comp, t);
0351:            }
0352:
0353:            /**
0354:             * This method causes a transfer to a component from a clipboard or a DND drop operation.  The
0355:             * Transferable represents the data to be imported into the component.
0356:             *
0357:             * @param comp The component to receive the transfer.  This argument is provided to enable
0358:             *  sharing of TransferHandlers by multiple components.
0359:             * @param t  The data to import.
0360:             * @param transferData The data to be transferred
0361:             * @return true if the data was inserted into the component, false otherwise.
0362:             * @todo XXX Passing in a transferable here is undesirable; since we'return delayed the
0363:             *   transferable may have been "released" by the system (this appears to be the
0364:             *   case on OSX. See if there's a way to factor it out. Slightly tricky because we need
0365:             *   it in a call to computeActions, and computeActions also needs the drop position which
0366:             *   depends the delay...
0367:             */
0368:            //    private void importDataDelayed(JComponent comp, Transferable t/*, Object transferData*/) {
0369:            private boolean importDataExt(JComponent comp, Transferable t) {
0370:                if (comp == null) {
0371:                    return false;
0372:                }
0373:
0374:                //        assert transferData != null;
0375:
0376:                //        assert webform.getPane() == comp;
0377:
0378:                // XXX
0379:                if (dropPoint == null && insertPos == DomPosition.NONE) {
0380:                    dropPoint = webform.getPastePoint();
0381:                }
0382:
0383:                //        InteractionManager.clearPalette(webform); // Item already in transferable
0384:                InteractionManager.stopCnCForWebForm(webform); // Item already in transferable
0385:
0386:                // Disambiguate drop position
0387:                //        if (insertPos != Position.NONE) {
0388:                if (insertPos != DomPosition.NONE) {
0389:                    //            if (insertPos.isRendered()) {
0390:                    //            if (MarkupService.isRenderedNode(insertPos.getNode())) {
0391:                    if (insertPos.isRenderedPosition()) {
0392:                        insertPos = insertPos.getSourcePosition();
0393:                    }
0394:
0395:                    //            if (insertPos != Position.NONE) {
0396:                    if (insertPos != DomPosition.NONE) {
0397:                        dropPoint = null;
0398:                    }
0399:                }
0400:
0401:                // XXX Compute location. Faking the same switch like below
0402:                //        Location location;
0403:                //        if (transferData instanceof DisplayItem) {
0404:                //            location = computeLocationForPositions(DROP_CENTER, null, getDropPoint(), insertPos, true);
0405:                //        } else if (transferData instanceof DesignBean[]) {
0406:                //            location = computeLocationForPositions(DROP_CENTER, null, getDropPoint(), insertPos, true);
0407:                //        } else if (transferData instanceof org.openide.nodes.Node) {
0408:                //            location = computeLocationForPositions(DROP_CENTER, null, getDropPoint(), insertPos, true);
0409:                //        } else if (transferData instanceof File) {
0410:                //            location = computeLocationForPositions(DROP_CENTER, null, getDropPoint(), insertPos, true);
0411:                //        } else if (transferData instanceof String) {
0412:                //            location = computeLocationForPositions(DROP_CENTER, null, getDropPoint(), insertPos, true);
0413:                //        } else if (transferData instanceof List) {
0414:                //            location = computeLocationForPositions(DROP_CENTER, null, getDropPoint(), insertPos, true);
0415:                //        } else {
0416:                //            location = null;
0417:                //        }
0418:
0419:                //        DomProvider.CoordinateTranslator coordinateTranslator = GridHandler.getInstance();
0420:                //        DomProvider.CoordinateTranslator coordinateTranslator = webform.getGridHandler();
0421:
0422:                //        DomProvider.Location location = computeLocationForPositions(DROP_CENTER, null, getDropPoint(), insertPos, true);
0423:                Point canvasPos = getDropPoint();
0424:                //        Position documentPos = insertPos;
0425:                //        Position computedDocumentPos = computeDocumentPosition(canvasPos, documentPos);
0426:                DomPosition documentPos = insertPos;
0427:                DomPosition computedDocumentPos = computeDocumentPosition(
0428:                        canvasPos, documentPos);
0429:
0430:                Node documentPosNode = computedDocumentPos.getNode();
0431:                int documentPosOffset = computedDocumentPos.getOffset();
0432:
0433:                //        CssBox box = computeDroppeeCssBox(canvasPos);
0434:                CssBox box = canvasPos == null ? null : ModelViewMapper
0435:                        .findBox(webform.getPane().getPageBox(), canvasPos.x,
0436:                                canvasPos.y);
0437:                Element droppeeElement = box == null ? null : box.getElement();
0438:                //        DesignBean droppeeBean = box == null ? null : getDroppee(box);
0439:                Element dropeeComponentRootElement = box == null ? null
0440:                        : getDropeeComponent(box);
0441:                boolean isGrid = (!webform.isGridMode() && ((box == null) || !box
0442:                        .isGrid())) ? false : true;
0443:                //        DesignBean defaultParentBean = webform.getDefaultParentBean();
0444:                //        Element defaultParentComponentRootElement = webform.getDefaultParentComponent();
0445:                //        return doComputeLocationForPositions(facet, canvasPos, documentPosNode, documentPosOffset, getDropSize(), isGrid, droppeeElement, droppeeBean, defaultParentBean);
0446:
0447:                //        Object transferData = null;
0448:                //        try {
0449:                //            DataFlavor importFlavor = webform.getImportFlavor(t.getTransferDataFlavors());
0450:                //
0451:                //            if (importFlavor == null) {
0452:                //                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, 
0453:                //                        new IllegalStateException("Unusable transfer flavors " + Arrays.asList(t.getTransferDataFlavors()))); // NOI18N
0454:                //
0455:                //                return /*false*/;
0456:                //            }
0457:                //
0458:                //            // XXX What was before in SelectionTopComp.
0459:                //            if (importFlavor.getMimeType().startsWith("application/x-creator-")) { // NOI18N
0460:                //                /*return*/ webform.tcImportComponentData(comp, t);
0461:                //            } // TEMP
0462:                //
0463:                //            Class rc = importFlavor.getRepresentationClass();
0464:                //
0465:                //            transferData = t.getTransferData(importFlavor);
0466:                //
0467:                //            if (rc == String.class) {
0468:                //                // XXX #6332049 When in inline editing we shouldn't steal the paste
0469:                //                // (at least for the JTextComponent's.
0470:                //                // This is just a workaround, it shouldn't be done this way.
0471:                //                // actions should be created based on context (and inline editing
0472:                //                // context is diff from the designer pane one).
0473:                //                if(webform.getManager().isInlineEditing()) {
0474:                //                    Component focusOwner = FocusManager.getCurrentManager().getFocusOwner();
0475:                //                    if(focusOwner instanceof JTextComponent) {
0476:                //                        JTextComponent textComp = (JTextComponent)focusOwner;
0477:                //                        textComp.paste();
0478:                //                        return /*true*/;
0479:                //                    } 
0480:                //                }
0481:                //
0482:                //                // XXX Flowlayout mode?
0483:                ////                if (webform.getPane().getCaret() != null) {
0484:                //                if (webform.getPane().hasCaret()) {
0485:                ////                    webform.getPane().getCaret().replaceSelection((String)transferData);
0486:                //                    webform.getPane().replaceSelection((String)transferData);
0487:                //                    return /*true*/;
0488:                //                }
0489:                //            }
0490:
0491:                //        DomProvider.Location location = WebForm.getDomProviderService().computeLocationForPositions(null, canvasPos, documentPosNode, documentPosOffset, getDropSize(), isGrid, droppeeElement,
0492:                //                /*droppeeBean,*/dropeeComponentRootElement, /*defaultParentBean*/defaultParentComponentRootElement);
0493:                //        doImportDataDelayed(comp, t, transferData, location/*, coordinateTranslator*/);
0494:                boolean success = webform.importData(comp, t, /*transferData,*/
0495:                        canvasPos, documentPosNode, documentPosOffset,
0496:                        getDropSize(), isGrid, droppeeElement,
0497:                        dropeeComponentRootElement, /*defaultParentComponentRootElement, coordinateTranslator,*/
0498:                        dropAction);
0499:
0500:                //        } catch (Exception e) {
0501:                //            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
0502:                ////            return /*false*/;
0503:                //        }
0504:
0505:                dropSize = null;
0506:                //        insertPos = Position.NONE;
0507:                insertPos = DomPosition.NONE;
0508:                dropPoint = null;
0509:                clearDropMatch();
0510:
0511:                return success;
0512:            }
0513:
0514:            //    private void doImportDataDelayed(JComponent comp, Transferable t, Object transferData,
0515:            //    DomProvider.Location location, DomProvider.CoordinateTranslator coordinateTranslator) {
0516:            ////        LiveUnit unit = webform.getModel().getLiveUnit();
0517:            ////        if (unit == null) {
0518:            ////            NotifyDescriptor d =
0519:            ////                new NotifyDescriptor.Message(NbBundle.getMessage(DndHandler.class, "NoHtmlDrops"),
0520:            ////                    NotifyDescriptor.WARNING_MESSAGE);
0521:            ////            DialogDisplayer.getDefault().notify(d);
0522:            //////            dropSize = null;
0523:            //////            insertPos = Position.NONE;
0524:            //////            dropPoint = null;
0525:            ////            
0526:            //////            clearDropMatch();
0527:            ////
0528:            ////            return;
0529:            ////        }
0530:            ////
0531:            ////        // wrap process in a try to allow cleanup in the finally
0532:            ////        try {
0533:            ////            comp.setCursor(org.openide.util.Utilities.createProgressCursor(comp));
0534:            ////
0535:            ////            // if we are importing to the same component that we exported from then don't actually do
0536:            ////            // anything if the drop location is inside the drag location and set shouldRemove to false
0537:            ////            // so that exportDone knows not to remove any data
0538:            ////            if (transferData instanceof DisplayItem) {
0539:            ////                // Create a new type
0540:            ////                DisplayItem item = (DisplayItem)transferData;
0541:            ////
0542:            //////                Location location = computePositions(null, DROP_CENTER, null, getDropPoint(), insertPos, true);
0543:            ////                // Todo: pass in a set instead
0544:            //////                doImportItem(item, null, DROP_CENTER, null, null, location);
0545:            ////                importBean(new DisplayItem[] {item}, null, DROP_CENTER, null, null, location, coordinateTranslator);
0546:            ////            } else if (transferData instanceof DesignBean[]) {
0547:            ////                DesignBean[] beans = (DesignBean[])transferData;
0548:            //////                Location location =
0549:            //////                    computePositions(null, DROP_CENTER, null, getDropPoint(), insertPos, true);
0550:            //////                DesignBean droppee = location.droppee;
0551:            //////
0552:            //////                if (droppee != null) {
0553:            //////                    Location location2 =
0554:            //////                        computePositions(droppee, DROP_CENTER, null, null, null, false);
0555:            //////                    doBindOrMoveItems(dropAction, beans, t, droppee, DROP_CENTER, null, location2);
0556:            //////                }
0557:            ////                DesignBean droppee = location.droppee;
0558:            ////                if (droppee != null) {
0559:            //////                    location = computePositions(droppee1, DROP_CENTER, null, null, null, false);
0560:            ////                    location = computeLocationForBean(droppee, DROP_CENTER, null, null, getDropSize(), webform.getModel());
0561:            ////                    doBindOrMoveItems(dropAction, beans, t, droppee, DROP_CENTER, null, location);
0562:            ////                }
0563:            ////            } else if (transferData instanceof org.openide.nodes.Node) {
0564:            ////                org.openide.nodes.Node node = (org.openide.nodes.Node)transferData;
0565:            ////                DataObject dobj = (DataObject)node.getCookie(DataObject.class);
0566:            ////
0567:            ////                if (dobj != null) {
0568:            ////                    FileObject fo = dobj.getPrimaryFile();
0569:            //////                    String rel = DesignerUtils.getPageRelativePath(webform, fo);
0570:            ////                    String rel = getPageRelativePath(webform.getProject(), fo);
0571:            ////                    
0572:            ////                    Project fileProject = FileOwnerQuery.getOwner(fo);
0573:            ////
0574:            ////                    if (fileProject != webform.getProject()) {
0575:            ////                        // Import file into our project first
0576:            ////                        FileObject webitem = webform.getDataObject().getPrimaryFile();
0577:            ////
0578:            ////                        try {
0579:            ////                            if (DesignerUtils.isImage(fo.getExt()) ||
0580:            ////                                    DesignerUtils.isStylesheet(fo.getExt())) {
0581:            ////                                // Import web context relative rather than file relative
0582:            ////                                DesignProject project =
0583:            ////                                    webform.getModel().getLiveUnit().getProject();
0584:            ////                                File file = FileUtil.toFile(fo);
0585:            ////                                URL url = file.toURI().toURL();
0586:            ////                                rel = RESOURCES + UrlPropertyEditor.encodeUrl(file.getName());
0587:            ////                                project.addResource(url, new URI(WEB + rel));
0588:            ////                            } else {
0589:            ////                                URL url = fo.getURL();
0590:            ////                                rel = JsfProjectUtils.addResource(webitem, url, true);
0591:            ////                            }
0592:            ////                        } catch (FileStateInvalidException fse) {
0593:            ////                            ErrorManager.getDefault().notify(fse);
0594:            ////                        }
0595:            ////                    }
0596:            ////
0597:            ////                    if (DesignerUtils.isImage(fo.getExt())) {
0598:            //////                        Location location =
0599:            //////                            computePositions(null, DROP_CENTER, null, getDropPoint(), insertPos, true);
0600:            ////                        importImage(rel, location, coordinateTranslator);
0601:            ////                    } else if (DesignerUtils.isStylesheet(fo.getExt())) {
0602:            ////                        importStylesheet(rel);
0603:            ////                    }
0604:            ////
0605:            ////                    //} else if (node instanceof org.netbeans.modules.properties.KeyNode) {
0606:            ////                    //    // Compute the value binding expression:
0607:            ////                    //    //  #{bundle.key}
0608:            ////                    //    // But I need to ensure that the bundle file is included somewhere in
0609:            ////                    //    // the page, and use the variable in the above.
0610:            ////                    //    // The key can be found from this node via a cookie, but it looks like
0611:            ////                    //    // the properties code is using old-style openide.src api calls, so
0612:            ////                    //    // I'd hate to include it.
0613:            ////                }
0614:            ////            } else if (transferData instanceof File) {
0615:            ////                File f = (File)transferData;
0616:            //////                Location location = computePositions(null, DROP_CENTER, null, getDropPoint(), insertPos, true);
0617:            ////                importFile(f, null, location, coordinateTranslator);
0618:            ////            } else if (transferData instanceof String) {
0619:            ////                String s = (String)transferData;
0620:            ////                
0621:            ////                File file = extractFileFromString(s);
0622:            ////                if (file != null) {
0623:            ////                    importFile(file, null, location, coordinateTranslator);
0624:            ////                } else {
0625:            ////                
0626:            ////                    s = DesignerUtils.truncateString(s, 600);
0627:            //////                    Location location =
0628:            //////                        computePositions(null, DROP_CENTER, null, getDropPoint(), insertPos, true);
0629:            ////                    importString(s, location, coordinateTranslator);
0630:            ////                }
0631:            ////            } else if (transferData instanceof List) {
0632:            ////                // TODO: place this under a single undo unit?
0633:            ////                List list = (List)transferData;
0634:            ////                Iterator it = list.iterator();
0635:            ////                JPanel panel = null;
0636:            ////
0637:            ////                while (it.hasNext()) {
0638:            ////                    Object o = it.next();
0639:            ////
0640:            ////                    if (o instanceof File) {
0641:            ////                        File f = (File)o;
0642:            //////                        Location location = computePositions(null, DROP_CENTER, null, getDropPoint(), insertPos, true);
0643:            ////                        panel = importFile(f, panel, location, coordinateTranslator);
0644:            ////                    }
0645:            ////                }
0646:            ////            } else {
0647:            ////                assert false : transferData;
0648:            ////            }
0649:            ////        } catch (Exception e) {
0650:            ////            ErrorManager.getDefault().notify(e);
0651:            ////
0652:            ////            return;
0653:            ////        } finally {
0654:            ////            if (comp != null) {
0655:            ////                comp.setCursor(null);
0656:            ////            }
0657:            ////
0658:            //////            dropSize = null;
0659:            //////            insertPos = Position.NONE;
0660:            //////            dropPoint = null;
0661:            //////            clearDropMatch();
0662:            ////        }
0663:            //        webform.importData(comp, t, transferData, getDropSize(), location, coordinateTranslator, dropAction);
0664:            //    }
0665:
0666:            //    private static File extractFileFromString(String string) {
0667:            //        // We don't know if the String passed in to us represents
0668:            //        // an actual String, or a pointer to an actual file
0669:            //        // on disk. (For example, some operating systems where you
0670:            //        // drag an image file from the desktop and drop it on Creator
0671:            //        // will pass in e.g.   "file:/Users/luser/foo.gif". 
0672:            //        // In this case we should detect that we're really dealing
0673:            //        // with a path, not a literal String.
0674:            //        // To do that, we do an -experimental- URL parse, and if
0675:            //        // it suceeds, we assume we're dealing with a path, otherwise
0676:            //        // it's a plain string.
0677:            //        try {
0678:            //            // Try to construct a URL; if it's a url do a file
0679:            //            // import of that file
0680:            //            String urlString = string.trim();
0681:            //            URL url = new URL(urlString);
0682:            //            urlString = url.toExternalForm();
0683:            //
0684:            //            // looks like an okay url
0685:            //            if (url.getProtocol().equals("file")) { // NOI18N
0686:            //
0687:            //                // <markup_separation>
0688:            ////                        String filename = MarkupUnit.fromURL(urlString);
0689:            //                // ====
0690:            //                String filename = InSyncService.getProvider().fromURL(urlString);
0691:            //                // </markup_separation>
0692:            //
0693:            //                if (filename != urlString) {
0694:            //                    File file = new File(filename);
0695:            //
0696:            //                    if (file.exists()) {
0697:            //                        return file;
0698:            //                    }
0699:            //
0700:            //                    // fall through for normal string handling
0701:            //                }
0702:            //            }
0703:            //        } catch (MalformedURLException mue) {
0704:            //            // It's just normal text; fall through
0705:            //            // NOTE: This is not an error condition!! We don't know that
0706:            //            // the string reprents a URL - it was just a hypothesis we're
0707:            //            // testing! When this fails we know that the hypothesis
0708:            //            // was wrong.
0709:            //        }
0710:            //        
0711:            //        return null;
0712:            //    }
0713:
0714:            //    private JPanel importFile(final File f, JPanel panel, Location location, CoordinateTranslator coordinateTranslator) {
0715:            //        if (f.exists()) {
0716:            //            String name = f.getName();
0717:            //            String extension = name.substring(name.lastIndexOf(".") + 1); // NOI18N
0718:            //            Project project = webform.getModel().getProject();
0719:            //
0720:            //            //String mime = FileUtil.getMIMEType(extension);
0721:            //            // They've only registered gif and jpg so not a big deal
0722:            //            if (DesignerUtils.isImage(extension)) {
0723:            ////                Location location =
0724:            ////                    computePositions(null, DROP_CENTER, null, getDropPoint(), insertPos, true);
0725:            //                importImage(f, location, coordinateTranslator);
0726:            //
0727:            //                return panel;
0728:            //            } else if (DesignerUtils.isStylesheet(extension)) {
0729:            //                importStylesheet(f);
0730:            //
0731:            //                return panel;
0732:            //            }
0733:            //
0734:            //// <dep> XXX Getting rid of dep on project/importpage.
0735:            //// TODO There should be a better API created.
0736:            ////            panel = PageImport.importRandomFile(project, f, extension, panel);
0737:            //// ====
0738:            //            Lookup l = Lookup.getDefault();
0739:            //            Lookup.Template template = new Lookup.Template(Importable.class);
0740:            //            Iterator it = l.lookup(template).allInstances().iterator();
0741:            //            while (it.hasNext()) {
0742:            //                Object importable = it.next();
0743:            //                if(importable instanceof Importable.PageImportable) {
0744:            //                    panel = ((Importable.PageImportable)importable).importRandomFile(project, f, extension, panel);
0745:            //                    break;
0746:            //                }
0747:            //            }
0748:            //// </dep>
0749:            //
0750:            //            if (panel == null) {
0751:            //                JsfProjectUtils.importFile(webform.getModel().getProject(), f);
0752:            //            }
0753:            //        }
0754:            //
0755:            //        return panel;
0756:            //    }
0757:
0758:            //    private void importImage(final File file, Location location, CoordinateTranslator coordinateTranslator) {
0759:            //        try {
0760:            //            URL url = file.toURI().toURL();
0761:            //
0762:            //            // Import web context relative rather than file relative
0763:            //            //FileObject webitem = webform.getDataObject().getPrimaryFile();
0764:            //            //String local = JsfProjectHelper.addResource(webitem, url, true);
0765:            //            DesignProject project = webform.getModel().getLiveUnit().getProject();
0766:            //            String local = RESOURCES + UrlPropertyEditor.encodeUrl(file.getName());
0767:            //            project.addResource(url, new URI(WEB + local));
0768:            //
0769:            //            importImage(local, location, coordinateTranslator);
0770:            //        } catch (Exception ex) {
0771:            //            ErrorManager.getDefault().notify(ex);
0772:            //        }
0773:            //    }
0774:            //
0775:            //    private void importImage(final String local, Location location, CoordinateTranslator coordinateTranslator) {
0776:            //        // Import the file.
0777:            //        // If it's an image, just create an image component for it
0778:            //        // and drop it on the page.  (If there are multiple images,
0779:            //        // don't position them. This will happen automatically
0780:            //        // because we will clear the position after the first dropped
0781:            //        // image.)
0782:            //        // If it's a stylesheet, add it as a stylesheet.
0783:            //        // Otherwise consult the import mechanism (e.g. for html,
0784:            //        // jsp, and friends).
0785:            //        // For image I still need the position, so delay slightly.
0786:            ////        Location location =
0787:            ////            computePositions(null, DROP_CENTER, null, getDropPoint(), insertPos, true);
0788:            //        DesignBean droppee = location.droppee;
0789:            ////        Document document = webform.getDocument();
0790:            //
0791:            //        String description = NbBundle.getMessage(DndHandler.class, "DropComponent"); // NOI18N
0792:            //        UndoEvent undoEvent = webform.getModel().writeLock(description);
0793:            //        try {
0794:            ////            String description = NbBundle.getMessage(DndHandler.class, "DropComponent"); // NOI18N
0795:            ////            document.writeLock(description);
0796:            //
0797:            //            String className;
0798:            //            String propertyName;
0799:            //
0800:            //            // XXX This should be decided by the parent bean.
0801:            //            // I.e. appropriate api is missing.
0802:            ////            if (DesignerUtils.isBraveheartPage(webform.getJspDom())) {
0803:            //            // XXX This shouldn't be here resolved, but in parent bean.
0804:            //            if (InSyncService.getProvider().isBraveheartPage(webform.getJspDom())) {
0805:            //                className = "com.sun.rave.web.ui.component.ImageComponent"; // NOI18N
0806:            //                propertyName = "url";
0807:            //            } else {
0808:            //                className = "javax.faces.component.html.HtmlGraphicImage"; // NOI18N
0809:            //                propertyName = "value";
0810:            //            }
0811:            //
0812:            //            DesignBean parent = findParent(className, droppee, location.pos.getUnderParent(), true);
0813:            //            DesignBean bean = createBean(className, parent, location.pos, null);
0814:            //            select = bean;
0815:            //
0816:            //            if (bean instanceof MarkupDesignBean) {
0817:            //                MarkupDesignBean mbean = (MarkupDesignBean)bean;
0818:            //                positionBean(mbean, parent, mbean.getElement(), location, coordinateTranslator);
0819:            //            }
0820:            //
0821:            ////            selectBean(select);
0822:            //            webform.getSelection().selectBean(select);
0823:            //            select = null;
0824:            //
0825:            //            DesignProperty prop = bean.getProperty(propertyName);
0826:            //
0827:            //            if (prop != null) {
0828:            //                prop.setValue(local);
0829:            //            }
0830:            //
0831:            //            //inlineEdit(beans);
0832:            //        } finally {
0833:            ////            document.writeUnlock();
0834:            //            webform.getModel().writeUnlock(undoEvent);
0835:            //        }
0836:            //    }
0837:
0838:            void importString(String string, Point point/*, DomProvider.CoordinateTranslator coordinateTranslator*/) {
0839:                setDropPoint(point);
0840:                //setInsertPosition(getPasteMarkupPosition());
0841:
0842:                //        DomProvider.Location location =
0843:                //            computeLocationForPositions(DROP_CENTER, null, getDropPoint(), insertPos, true);
0844:                Point canvasPos = getDropPoint();
0845:                //        Position documentPos = insertPos;
0846:                //        Position computedDocumentPos = computeDocumentPosition(canvasPos, documentPos);
0847:                DomPosition documentPos = insertPos;
0848:                DomPosition computedDocumentPos = computeDocumentPosition(
0849:                        canvasPos, documentPos);
0850:
0851:                Node documentPosNode = computedDocumentPos.getNode();
0852:                int documentPosOffset = computedDocumentPos.getOffset();
0853:
0854:                //        CssBox box = computeDroppeeCssBox(canvasPos);
0855:                CssBox box = canvasPos == null ? null : ModelViewMapper
0856:                        .findBox(webform.getPane().getPageBox(), canvasPos.x,
0857:                                canvasPos.y);
0858:                Element droppeeElement = box == null ? null : box.getElement();
0859:                //        DesignBean droppeeBean = box == null ? null : getDroppee(box);
0860:                Element dropeeComponentRootElement = box == null ? null
0861:                        : getDropeeComponent(box);
0862:                boolean isGrid = (!webform.isGridMode() && ((box == null) || !box
0863:                        .isGrid())) ? false : true;
0864:                //        DesignBean defaultParentBean = webform.getDefaultParentBean();
0865:                //        Element defaultParentComponentRootElement = webform.getDefaultParentComponent();
0866:                //        return doComputeLocationForPositions(facet, canvasPos, documentPosNode, documentPosOffset, getDropSize(), isGrid, droppeeElement, droppeeBean, defaultParentBean);
0867:
0868:                //        DomProvider.Location location = WebForm.getDomProviderService().computeLocationForPositions(null, canvasPos, documentPosNode, documentPosOffset, getDropSize(), isGrid, droppeeElement,
0869:                //                /*droppeeBean,*/dropeeComponentRootElement, /*defaultParentBean*/defaultParentComponentRootElement);
0870:                //        importString(string, location, coordinateTranslator);
0871:                webform
0872:                        .importString(string, canvasPos, documentPosNode,
0873:                                documentPosOffset, getDropSize(), isGrid,
0874:                                droppeeElement, dropeeComponentRootElement /*, defaultParentComponentRootElement, coordinateTranslator*/);
0875:            }
0876:
0877:            //    void importString(String string, DomProvider.Location location, DomProvider.CoordinateTranslator coordinateTranslator) {
0878:            ////        // Import the string as part of an output text component
0879:            //////        Location location =
0880:            //////            computePositions(null, DROP_CENTER, null, getDropPoint(), insertPos, true);
0881:            ////        DesignBean droppee = location.droppee;
0882:            ////
0883:            //////        Document document = webform.getDocument();
0884:            ////
0885:            ////        String description = NbBundle.getMessage(DndHandler.class, "DropComponent"); // NOI18N
0886:            ////        UndoEvent undoEvent = webform.getModel().writeLock(description);
0887:            ////        try {
0888:            //////            String description = NbBundle.getMessage(DndHandler.class, "DropComponent"); // NOI18N
0889:            //////            document.writeLock(description);
0890:            ////
0891:            ////            String className;
0892:            ////            String propertyName;
0893:            ////
0894:            ////            // XXX This should be decided by the parent bean.
0895:            ////            // I.e. appropriate api is missing.
0896:            //////            if (DesignerUtils.isBraveheartPage(webform.getJspDom())) {
0897:            ////            // XXX This shouldn't be here resolved, but in parent bean.
0898:            ////            if (InSyncService.getProvider().isBraveheartPage(webform.getJspDom())) {
0899:            ////                className = "com.sun.rave.web.ui.component.StaticText"; // NOI18N
0900:            ////                propertyName = "text";
0901:            ////            } else {
0902:            ////                className = "javax.faces.component.html.HtmlOutputText"; // NOI18N
0903:            ////                propertyName = "value";
0904:            ////            }
0905:            ////
0906:            ////            DesignBean parent = findParent(className, droppee, location.pos.getUnderParent(), true);
0907:            ////            DesignBean bean = createBean(className, parent, location.pos, null);
0908:            ////            select = bean;
0909:            ////
0910:            ////            if (bean instanceof MarkupDesignBean) {
0911:            ////                MarkupDesignBean mbean = (MarkupDesignBean)bean;
0912:            ////                positionBean(mbean, parent, mbean.getElement(), location, coordinateTranslator);
0913:            ////            }
0914:            ////
0915:            //////            selectBean(select);
0916:            ////            webform.getSelection().selectBean(select);
0917:            ////            select = null;
0918:            ////
0919:            ////            DesignProperty prop = bean.getProperty(propertyName);
0920:            ////
0921:            ////            if (prop != null) {
0922:            ////                // Clean up string a little
0923:            ////                // TODO - should I look for <HTML> markup and if so unset the escape property?
0924:            ////                string = string.replace('\n', ' ');
0925:            ////                string = string.replace('\r', ' ');
0926:            ////                prop.setValue(string);
0927:            ////            }
0928:            ////
0929:            ////            //inlineEdit(beans);
0930:            ////        } finally {
0931:            //////            document.writeUnlock();
0932:            ////            webform.getModel().writeUnlock(undoEvent);
0933:            ////        }
0934:            //        webform.importString(string, location, coordinateTranslator);
0935:            //    }
0936:
0937:            //    private void importStylesheet(final File file) {
0938:            //        try {
0939:            //            URL url = file.toURI().toURL();
0940:            //
0941:            //            // Import web context relative rather than file relative
0942:            //            //FileObject webitem = webform.getDataObject().getPrimaryFile();
0943:            //            //String local = JsfProjectHelper.addResource(webitem, url, true);
0944:            //            DesignProject project = webform.getModel().getLiveUnit().getProject();
0945:            //            String local = RESOURCES + UrlPropertyEditor.encodeUrl(file.getName());
0946:            //            project.addResource(url, new URI(WEB + local));
0947:            //
0948:            //            importStylesheet(local);
0949:            //        } catch (Exception ex) {
0950:            //            ErrorManager.getDefault().notify(ex);
0951:            //        }
0952:            //    }
0953:            //
0954:            //    private void importStylesheet(final String local) {
0955:            ////        Document document = webform.getDocument();
0956:            //
0957:            //        //ArrayList beanItems = new ArrayList();
0958:            //        String description = NbBundle.getMessage(DndHandler.class, "DropComponent"); // NOI18N
0959:            //        UndoEvent undoEvent = webform.getModel().writeLock(description);
0960:            //        try {
0961:            ////            String description = NbBundle.getMessage(DndHandler.class, "DropComponent"); // NOI18N
0962:            ////            document.writeLock(description);
0963:            //
0964:            //            // Add stylesheet link
0965:            //            org.w3c.dom.Document dom = webform.getJspDom();
0966:            //            Element root = dom.getDocumentElement();
0967:            //            MarkupUnit markup = webform.getMarkup();
0968:            //            Element html = markup.findHtmlTag(root);
0969:            //            DesignBean bean = null;
0970:            //
0971:            //            if (html == null) {
0972:            //                DesignBean uihead = null;
0973:            //                LiveUnit lu = webform.getModel().getLiveUnit();
0974:            //                DesignBean[] heads = lu.getBeansOfType(com.sun.rave.web.ui.component.Head.class);
0975:            //
0976:            //                if ((heads != null) && (heads.length > 0)) {
0977:            //                    uihead = heads[0];
0978:            //
0979:            //                    if (uihead != null) {
0980:            //                        // No stylesheet link exists - add one
0981:            //                        // XXX TODO get rid of using xhtml directly, 
0982:            //                        // it should be shielded by api.
0983:            //                        bean = lu.createBean(com.sun.rave.web.ui.component.Link.class.getName(), uihead,
0984:            //                                new Position()); // NOI18N
0985:            //                        bean.getProperty("url").setValue(local); // NOI18N
0986:            //                    }
0987:            //                }
0988:            //            } else {
0989:            //                // Gotta replace with HtmlTag.LINK.name
0990:            //                Element head = Util.findChild(HtmlTag.HEAD.name, html, false);
0991:            //                // XXX TODO get rid of using xhtml directly, 
0992:            //                // it should be shielded by api.
0993:            //                bean = webform.getDocument().createBean(org.netbeans.modules.visualweb.xhtml.Link.class.getName(), head, null);
0994:            //                bean.getProperty("href").setValue(local); // NOI18N
0995:            //            }
0996:            //
0997:            //            if (bean == null) {
0998:            //                return;
0999:            //            }
1000:            //
1001:            //            bean.getProperty("rel").setValue("stylesheet"); // NOI18N
1002:            //            bean.getProperty("type").setValue("text/css"); // NOI18N
1003:            //        } finally {
1004:            ////            document.writeUnlock();
1005:            //            webform.getModel().writeUnlock(undoEvent);
1006:            //        }
1007:            //
1008:            //        webform.refresh(true);
1009:            //    }
1010:
1011:            //    /**
1012:            //     * @return true iff the palette item was inserted successfully
1013:            //     * @param beans An empty list into which the created beans will be added, or null
1014:            //     *    if caller is not interested in the result
1015:            //     */
1016:            //    public boolean importItem(DisplayItem item, DesignBean parent, int nodePos, String facet,
1017:            //    List beans, DomProvider.CoordinateTranslator coordinateTranslator) throws IOException {
1018:            ////        Location location = computePositions(parent, nodePos, facet, getDropPoint(), insertPos, true);
1019:            //        DomProvider.Location location = computeLocationForBean(parent, nodePos, facet, getDropPoint(), getDropSize(), webform);
1020:            ////        return doImportItem(item, parent, nodePos, facet, beans, location);
1021:            //        return importBean(new DisplayItem[] {item}, parent, nodePos, facet, beans, location, coordinateTranslator);
1022:            //    }
1023:
1024:            //    private boolean doImportItem(DisplayItem item, DesignBean parent, int nodePos, String facet,
1025:            //    List beans, Location location) throws IOException {
1026:            //        if (item instanceof DisplayItem) {
1027:            //            return importBean(new DisplayItem[] { (DisplayItem)item }, parent, nodePos,
1028:            //                facet, beans, location);
1029:            //        } else {
1030:            //            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
1031:            //                    new IllegalStateException("Unable to import item=" + item)); // NOI18N
1032:            //
1033:            //            return false;
1034:            //        }
1035:            //    }
1036:
1037:            //    public void bindOrMoveItems(int dropAction, DesignBean[] beans, Transferable t,
1038:            //    DesignBean dropNode, int nodePos, String facet) {
1039:            ////        Location location = computePositions((DesignBean)dropNode, nodePos, facet, null, null, false);
1040:            //        Location location = computeLocationForBean((DesignBean)dropNode, nodePos, facet, null, getDropSize(), webform.getModel());
1041:            //        doBindOrMoveItems(dropAction, beans, t, dropNode, nodePos, facet, location);
1042:            //    }
1043:            //    
1044:            //    private void doBindOrMoveItems(int dropAction, DesignBean[] beans, Transferable t,
1045:            //    DesignBean dropNode, int nodePos, String facet, Location location) {
1046:            //        if(DesignerUtils.DEBUG) {
1047:            //            DesignerUtils.debugLog(getClass().getName() + ".bindOrMoveItems(int, DesignBean[], Transferable, DesignBean, int, String)");
1048:            //        }
1049:            //        if(t == null) {
1050:            //            throw(new IllegalArgumentException("Null transferable."));
1051:            //        }
1052:            //        if ((beans == null) || (beans.length == 0)) {
1053:            //            return;
1054:            //        }
1055:            //
1056:            //        // It's a app outline drag: either move or link. Don't involve
1057:            //        // the transfer handler.
1058:            //        int allowed = computeActions(dropNode, t, false, nodePos);
1059:            //
1060:            //        if (allowed == DnDConstants.ACTION_NONE) {
1061:            //            return;
1062:            //        }
1063:            //
1064:            //        if (dropAction == DnDConstants.ACTION_COPY) {
1065:            //            LiveUnit unit = webform.getModel().getLiveUnit();
1066:            //            Transferable newTransferable = unit.copyBeans(beans);
1067:            //
1068:            //            if (newTransferable == null) {
1069:            //                return;
1070:            //            }
1071:            //
1072:            ////            Location location =
1073:            ////                computePositions((DesignBean)dropNode, nodePos, facet, null, null, false);
1074:            //            DesignBean parent = location.droppee;
1075:            //            SelectionTopComp.pasteBeans(webform, t, parent, location.pos, null);
1076:            //
1077:            //            return;
1078:            //        } else if (nodePos != DROP_CENTER) {
1079:            //            // MOVE: fall through to handle
1080:            //        } else if ((dropAction == DnDConstants.ACTION_LINK) ||
1081:            //                ((dropAction == DnDConstants.ACTION_MOVE) &&
1082:            //                ((allowed & DnDConstants.ACTION_LINK) != 0))) {
1083:            //            // LINK
1084:            //            // (We treat a move when link is permitted as a link since move
1085:            //            // is where you haven't selected any modifier keys so
1086:            //            // it's the mode where we make a best guess as to what
1087:            //            // you want. It would be better if we had a modifier key
1088:            //            // to let the user FORCE move though. Perhaps we should rethink
1089:            //            // this since there IS a modifier key for link (ctrl-shift).
1090:            //            ArrayList list = new ArrayList(beans.length);
1091:            //
1092:            //            for (int i = 0; i < beans.length; i++) {
1093:            //                list.add(beans[i]);
1094:            //            }
1095:            //
1096:            //            assert nodePos == DROP_CENTER;
1097:            //            handleLinks((DesignBean)dropNode, list);
1098:            //
1099:            //            return;
1100:            //        } else if ((dropAction & DnDConstants.ACTION_MOVE) != 0) {
1101:            //            // MOVE: fall through to handle
1102:            //        }
1103:            //
1104:            //        // Move
1105:            ////        Location location =
1106:            ////            computePositions((DesignBean)dropNode, nodePos, facet, null, null, false);
1107:            //        DesignBean parent = location.droppee;
1108:            //        moveBeans(webform, beans, parent, location.pos);
1109:            //    }
1110:
1111:            //    /**
1112:            //     * Move the given beans to the given parent and markup position.
1113:            //     */
1114:            //    private static void moveBeans(WebForm webform, DesignBean[] beans, DesignBean parent,
1115:            //        MarkupPosition pos) {
1116:            //        if ((beans == null) || (beans.length == 0)) {
1117:            //            return;
1118:            //        }
1119:            //
1120:            ////        Document document = null;
1121:            ////
1122:            ////        if (webform != null) {
1123:            ////            // XXX what about locking on java-only buffers? (SessionBean1 etc.)
1124:            ////            document = webform.getDocument();
1125:            ////        }
1126:            //        FacesModel facesModel = webform == null ? null : webform.getModel();
1127:            //
1128:            //        LiveUnit lu = (LiveUnit)beans[0].getDesignContext();
1129:            //
1130:            //        UndoEvent undoEvent;
1131:            //        if (facesModel != null) {
1132:            //            String description =
1133:            //                NbBundle.getMessage(SelectionTopComp.class,
1134:            //                    (beans.length > 1) ? "MoveComponents" // NOI18N
1135:            //                                       : "MoveComponent"); // NOI18N
1136:            //            undoEvent = facesModel.writeLock(description);
1137:            //        } else {
1138:            //            undoEvent = null; // No undo event
1139:            //            lu.writeLock(undoEvent);
1140:            //        }
1141:            //        
1142:            //        try {
1143:            ////            if (document != null) {
1144:            ////                String description =
1145:            ////                    NbBundle.getMessage(SelectionTopComp.class,
1146:            ////                        (beans.length > 1) ? "MoveComponents" // NOI18N
1147:            ////                                           : "MoveComponent"); // NOI18N
1148:            ////                document.writeLock(description);
1149:            ////            } else {
1150:            ////                lu.writeLock(null); // No undo event
1151:            ////            }
1152:            //
1153:            //            // Decide whether we need to strip out position coordinates
1154:            //            // from the beans being moved
1155:            //            boolean stripPos = !isGridContext(parent, pos);
1156:            //
1157:            //            for (int i = 0; i < beans.length; i++) {
1158:            //                if (!(beans[i] instanceof MarkupDesignBean)) {
1159:            //                    continue;
1160:            //                }
1161:            //
1162:            //                MarkupDesignBean bean = (MarkupDesignBean)beans[i];
1163:            //
1164:            //                if (stripPos) {
1165:            //                    Element e = bean.getElement();
1166:            //
1167:            //                    try {
1168:            ////                        webform.getDomSynchronizer().setUpdatesSuspended(bean, true);
1169:            //                        webform.setUpdatesSuspended(bean, true);
1170:            ////                        CssLookup.removeLocalStyleValue(e, XhtmlCss.POSITION_INDEX);
1171:            ////                        CssLookup.removeLocalStyleValue(e, XhtmlCss.LEFT_INDEX);
1172:            ////                        CssLookup.removeLocalStyleValue(e, XhtmlCss.TOP_INDEX);
1173:            //                        CssProvider.getEngineService().removeLocalStyleValueForElement(e, XhtmlCss.POSITION_INDEX);
1174:            //                        CssProvider.getEngineService().removeLocalStyleValueForElement(e, XhtmlCss.LEFT_INDEX);
1175:            //                        CssProvider.getEngineService().removeLocalStyleValueForElement(e, XhtmlCss.TOP_INDEX);
1176:            //                    } finally {
1177:            ////                        webform.getDomSynchronizer().setUpdatesSuspended(bean, false);
1178:            //                        webform.setUpdatesSuspended(bean, false);
1179:            //                    }
1180:            //                }
1181:            //
1182:            //                lu.moveBean(bean, parent, pos);
1183:            //            }
1184:            //        } finally {
1185:            ////            if (document != null) {
1186:            ////                document.writeUnlock();
1187:            ////            } else {
1188:            ////                lu.writeUnlock(null);
1189:            ////            }
1190:            //            if (facesModel != null) {
1191:            //                facesModel.writeUnlock(undoEvent);
1192:            //            } else {
1193:            //                lu.writeUnlock(undoEvent);
1194:            //            }
1195:            //        }
1196:            //    }
1197:
1198:            //    private String[] getClasses(DisplayItem[] items) {
1199:            //        List list = new ArrayList(items.length);
1200:            //
1201:            //        for (int i = 0, n = items.length; i < n; i++) {
1202:            //            DisplayItem item = items[i];
1203:            //            if (item instanceof BeanCreateInfo) {
1204:            //                list.add(((BeanCreateInfo)item).getBeanClassName());
1205:            //            } else if (item instanceof BeanCreateInfoSet) {
1206:            //                String[] cls = ((BeanCreateInfoSet)item).getBeanClassNames();
1207:            //                for (int k = 0; k < cls.length; k++) {
1208:            //                    list.add(cls[k]);
1209:            //                }
1210:            //            } else {
1211:            //                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
1212:            //                        new IllegalStateException("Illegal item=" + item)); // NOI18N
1213:            //            }
1214:            //        }
1215:            //
1216:            //        String[] classNames = (String[])list.toArray(new String[list.size()]);
1217:            //
1218:            //        return classNames;
1219:            //    }
1220:
1221:            //    /**
1222:            //     * @param beans An empty list into which the created beans will be added, or null
1223:            //     *    if caller is not interested in the result
1224:            //     * @return true iff the bean palette item was inserted successfully
1225:            //     */
1226:            //    private boolean importBean(DisplayItem[] items, DesignBean origParent, int nodePos,
1227:            //    String facet, List createdBeans, DomProvider.Location location, DomProvider.CoordinateTranslator coordinateTranslator) throws IOException {
1228:            //        if(DesignerUtils.DEBUG) {
1229:            //            DesignerUtils.debugLog(getClass().getName() + ".importBean(DisplayItem[], DesignBean, int, String, List)");
1230:            //        }
1231:            //        if(items == null) {
1232:            //            throw(new IllegalArgumentException("Null items array."));
1233:            //        }
1234:            //        select = null;
1235:            //
1236:            ////        Location location =
1237:            ////            computePositions(origParent, nodePos, facet, getDropPoint(), insertPos, true);
1238:            //
1239:            //        // It's a app outline drag: either move or link. Don't involve
1240:            //        // the transfer handler.
1241:            //        String[] classes = getClasses(items);
1242:            //
1243:            //        if (classes != null) {
1244:            //            DesignBean[] beans = null;
1245:            //            boolean searchUp = true;
1246:            //
1247:            //            // Can always "move" from the palette - it's an implied copy.
1248:            //            // The explorer drag & drop is a bit weird about this - they
1249:            //            // only pass "move" as the valid operation, not copy.
1250:            //            int action = DnDConstants.ACTION_MOVE;
1251:            //
1252:            //            if (location.droppee == null) {
1253:            //                MarkupBean bean = webform.getModel().getFacesUnit().getDefaultParent();
1254:            //
1255:            //                if (bean != null) {
1256:            //                    location.droppee = webform.getModel().getLiveUnit().getDesignBean(bean);
1257:            //                }
1258:            //            }
1259:            //
1260:            //            int allowed =
1261:            //                computeActions(location.droppee, classes, beans, action, searchUp, nodePos);
1262:            //
1263:            //            if (allowed == DnDConstants.ACTION_NONE) {
1264:            //                return false;
1265:            //            }
1266:            //        }
1267:            //
1268:            ////        Document document = webform.getDocument();
1269:            //        List beanItems = new ArrayList(); // HACK remove after TP
1270:            //
1271:            //        String description =
1272:            //            NbBundle.getMessage(DndHandler.class,
1273:            //                (items.length > 1) ? "DropComponents" : "DropComponent"); // NOI18N
1274:            //        UndoEvent undoEvent = webform.getModel().writeLock(description);
1275:            //        
1276:            //        // Don't want BeanPaletteItem.beanCreated; only want the
1277:            //        // set operation. For now the dataconnectivity module relies on
1278:            //        // this to name the instances, so we've gotta honor it.
1279:            //        try {
1280:            ////            String description =
1281:            ////                NbBundle.getMessage(DndHandler.class,
1282:            ////                    (items.length > 1) ? "DropComponents" : "DropComponent"); // NOI18N
1283:            ////            document.writeLock(description);
1284:            //
1285:            //            List beans = createBeans(location, items, beanItems, coordinateTranslator);
1286:            //
1287:            //            if (beans.isEmpty()) {
1288:            //                return false;
1289:            //            }
1290:            //
1291:            //            if (createdBeans != null) {
1292:            //                createdBeans.addAll(beans);
1293:            //            }
1294:            //
1295:            //            beansCreated(beans, beanItems);
1296:            //
1297:            //            processLinks(location.droppeeElement, null, beans, false, true, false);
1298:            //            customizeCreation(beans);
1299:            //
1300:            ////            selectBean(select);
1301:            //            webform.getSelection().selectBean(select);
1302:            //            select = null;
1303:            //
1304:            ////            inlineEdit(beans);
1305:            //            webform.getManager().inlineEdit(beans);
1306:            //
1307:            //            // Try to activate the designer surface! requestActive() isn't
1308:            //            // enough -- gotta force the multiview container to be activated
1309:            //            // and the right tab fronted!
1310:            //        } finally {
1311:            ////            document.writeUnlock();
1312:            //            webform.getModel().writeUnlock(undoEvent);
1313:            //        }
1314:            //
1315:            //        return true;
1316:            //        return webform.importBean(items, origParent, nodePos, facet, createdBeans, location, coordinateTranslator);
1317:            //    }
1318:
1319:            //    private DesignBean getDroppee(CssBox box) {
1320:            private Element getDropeeComponent(CssBox box) {
1321:                //        DesignBean origDroppee = ModelViewMapper.findComponent(box);
1322:                //        DesignBean origDroppee = ModelViewMapper.findMarkupDesignBean(box);
1323:                Element origDropeeComponentRootElement = ModelViewMapper
1324:                        .findElement(box);
1325:
1326:                // XXX Moved to methods in DomProviderImpl.
1327:                ////        if (webform.isGridMode() && (origDroppee == null) &&
1328:                ////                (webform.getModel().getLiveUnit() != null)) {
1329:                ////            MarkupBean bean = webform.getModel().getFacesUnit().getDefaultParent();
1330:                ////
1331:                ////            if (bean != null) {
1332:                ////                origDroppee = webform.getModel().getLiveUnit().getDesignBean(bean);
1333:                ////            }
1334:                ////        }
1335:                ////        if (webform.isGridMode() && (origDroppee == null)) {
1336:                ////            origDroppee = webform.getDefaultParentBean();
1337:                ////        }
1338:                //        if (webform.isGridMode() && (origDropeeComponentRootElement == null)) {
1339:                ////            origDroppee = webform.getDefaultParentBean();
1340:                //            origDropeeComponentRootElement = webform.getDefaultParentComponent();
1341:                //        }
1342:
1343:                //        return origDroppee;
1344:                return origDropeeComponentRootElement;
1345:            }
1346:
1347:            //    private Position computeDocumentPosition(Point canvasPos, Position documentPos) {
1348:            private DomPosition computeDocumentPosition(Point canvasPos,
1349:                    DomPosition documentPos) {
1350:                //        if (canvasPos == null && documentPos == null && webform.getPane().getCaret() != null) {
1351:                if (canvasPos == null && documentPos == null
1352:                        && webform.getPane().hasCaret()) {
1353:                    // The user is trying to insert a component without
1354:                    // dropping in a particular location; use the caret
1355:                    // position
1356:                    //            DesignerCaret caret = webform.getPane().getCaret();
1357:                    //            if (!caret.isReadOnlyRegion()) {
1358:                    //                documentPos = caret.getDot();
1359:                    //            }
1360:                    DesignerPane pane = webform.getPane();
1361:                    if (!pane.isCaretReadOnlyRegion()) {
1362:                        documentPos = pane.getCaretPosition();
1363:                    }
1364:                }
1365:
1366:                Node documentPosNode;
1367:                int documentPosOffset;
1368:                //        if (documentPos != null && documentPos != Position.NONE && !Document.isReadOnlyRegion(documentPos)) {
1369:                //        if (documentPos != null && documentPos != Position.NONE && !InteractionManager.isReadOnlyRegion(documentPos)) {
1370:                if (documentPos != null && documentPos != DomPosition.NONE
1371:                        && !InteractionManager.isReadOnlyRegion(documentPos)) {
1372:                    //            documentPosNode = documentPos.getNode();
1373:                    //            documentPosOffset = documentPos.getOffset();
1374:                    return documentPos;
1375:                } else {
1376:                    //            documentPosNode = null;
1377:                    //            documentPosOffset = -1;
1378:                    //            return Position.NONE;
1379:                    return DomPosition.NONE;
1380:                }
1381:            }
1382:
1383:            //    private DomProvider.Location computeLocationForPositions(
1384:            //            int where,
1385:            //            String facet,
1386:            //            Point canvasPos,
1387:            //            Position documentPos,
1388:            //            boolean split
1389:            //    ) {
1390:            ////        return doComputePositions(bean, where, facet, canvasPos, documentPosNode, documentPosOffset, split, getDropSize(), isGrid, droppeeElement, droppeeBean, webform.getModel());
1391:            //        Position computedDocumentPos = computeDocumentPosition(canvasPos, documentPos);
1392:            //        Node documentPosNode = computedDocumentPos.getNode();
1393:            //        int documentPosOffset = computedDocumentPos.getOffset();
1394:            //
1395:            ////        CssBox box = computeDroppeeCssBox(canvasPos);
1396:            //        CssBox box = canvasPos == null ? null : ModelViewMapper.findBox(webform.getPane().getPageBox(), canvasPos.x, canvasPos.y);
1397:            //        Element droppeeElement = box == null ? null : box.getElement();
1398:            ////        DesignBean droppeeBean = box == null ? null : getDroppee(box);
1399:            //        Element dropeeComponentRootElement = box == null ? null : getDropeeComponent(box);
1400:            //        boolean isGrid = (!webform.isGridMode() && ((box == null) || !box.isGrid())) ? false : true;
1401:            ////        DesignBean defaultParentBean = webform.getDefaultParentBean();
1402:            //        Element defaultParentComponentRootElement = webform.getDefautlParentComponent();
1403:            ////        return doComputeLocationForPositions(facet, canvasPos, documentPosNode, documentPosOffset, getDropSize(), isGrid, droppeeElement, droppeeBean, defaultParentBean);
1404:            //        return WebForm.getDomProviderService().computeLocationForPositions(facet, canvasPos, documentPosNode, documentPosOffset, getDropSize(), isGrid, droppeeElement,
1405:            //                /*droppeeBean,*/dropeeComponentRootElement, /*defaultParentBean*/defaultParentComponentRootElement);
1406:            //    }
1407:
1408:            //    private static DomProvider.Location doComputeLocationForPositions(String facet, Point canvasPos, Node documentPosNode, int documentPosOffset,
1409:            //    Dimension dropSize, boolean isGrid, Element droppeeElement, DesignBean droppeeBean, /*WebForm webform*/DesignBean defaultParentBean) {
1410:            //        DomProvider.Location location = new DomProvider.Location();
1411:            //        location.facet = facet;
1412:            //        location.coordinates = canvasPos;
1413:            ////        location.size = getDropSize();
1414:            //        location.size = dropSize;
1415:            //
1416:            //        DesignBean parent = null;
1417:            //        Node under = null;
1418:            //        Node before = null;
1419:            //
1420:            //        Element element = null;
1421:            //
1422:            //        if (documentPosNode != null) {
1423:            //            // XXX TODO: split text nodes!
1424:            //            if (documentPosNode instanceof Text) {
1425:            //                if (documentPosOffset == 0) {
1426:            //                    before = documentPosNode;
1427:            //                    under = before.getParentNode();
1428:            //                } else {
1429:            //                    Text txt = (Text)documentPosNode;
1430:            //
1431:            //                    if (documentPosOffset < txt.getLength()) {
1432:            //                        before = txt.splitText(documentPosOffset);
1433:            //                        under = before.getParentNode();
1434:            //                    } else {
1435:            //                        before = txt.getNextSibling();
1436:            //                        under = txt.getParentNode();
1437:            //                    }
1438:            //                }
1439:            //            } else {
1440:            //                int offset = documentPosOffset;
1441:            //
1442:            //                if (offset < documentPosNode.getChildNodes().getLength()) {
1443:            //                    under = documentPosNode;
1444:            //                    before = under.getChildNodes().item(offset);
1445:            //                } else {
1446:            //                    // Just append - but we don't have an api for that (can only set "before")
1447:            //                    // so create a new blank text node as a hook
1448:            //                    // XXX should I really mutate the document here?
1449:            //                    // That doesn't sound right...
1450:            //                    under = documentPosNode;
1451:            //
1452:            //                    // XXX Manipulation of the doc may not be done here.
1453:            ////                        Text txt = webform.getJspDom().createTextNode(" "); // NOI18N
1454:            //                    Text txt = under.getOwnerDocument().createTextNode(" "); // NOI18N
1455:            //                    under.appendChild(txt);
1456:            //                    before = txt;
1457:            //                }
1458:            //            }
1459:            //
1460:            //            if (parent == null) {
1461:            //                Node n = under;
1462:            //
1463:            ////                    while (n instanceof RaveElement) {
1464:            ////                        RaveElement xel = (RaveElement)n;
1465:            //                while (n instanceof Element) {
1466:            //                    Element xel = (Element)n;
1467:            //
1468:            ////                        if (xel.getDesignBean() != null) {
1469:            ////                            DesignBean lbean = (DesignBean)xel.getDesignBean();
1470:            ////                    DesignBean lbean = InSyncService.getProvider().getMarkupDesignBeanForElement(xel);
1471:            //                    DesignBean lbean = WebForm.getDomProviderService().getMarkupDesignBeanForElement(xel);
1472:            //                    if (lbean != null) {
1473:            //                        if (lbean.isContainer()) {
1474:            //                            parent = lbean;
1475:            //
1476:            //                            break;
1477:            //                        }
1478:            //                    }
1479:            //
1480:            //                    n = n.getParentNode();
1481:            //                }
1482:            //            }
1483:            //
1484:            //            //!CQ: facesUnit.setInsertBefore(before);
1485:            //            // determine the integer offset of the before node within its parent
1486:            //            if ((under != null) && (under.getNodeType() == Node.ELEMENT_NODE)) {
1487:            //                location.droppeeElement = (Element)under;
1488:            //            }
1489:            //        } else if (canvasPos != null) {
1490:            //            // What position should we assign here??? For now, nothing.
1491:            //            // Let insync pick a position. The exact location in the source
1492:            //            // where the tag is inserted isn't very important since we're
1493:            //            // absolute positioning anyway.
1494:            //            under = null;
1495:            //            before = null;
1496:            //
1497:            ////                CssBox box = webform.getMapper().findBox(canvasPos.x, canvasPos.y);
1498:            ////                CssBox box = ModelViewMapper.findBox(webform.getPane().getPageBox(), canvasPos.x, canvasPos.y);
1499:            ////
1500:            ////                // In flow mode, don't do absolute positioning, ever, unless we're in
1501:            ////                // a grid positioning area
1502:            ////                if (!webform.isGridMode() && ((box == null) || !box.isGrid())) {
1503:            ////                    location.coordinates = null;
1504:            ////                }
1505:            ////
1506:            ////                location.droppeeElement = box.getElement();
1507:            ////                parent = getDroppee(box);
1508:            //            if (!isGrid) {
1509:            //                location.coordinates = null;
1510:            //            }
1511:            //            location.droppeeElement = droppeeElement;
1512:            //            parent = droppeeBean;
1513:            //        }
1514:            //
1515:            //        //            else {
1516:            //        //                // No position specified. In this case send just nulls
1517:            //        //                // to insync and let insync figure it out. It will insert
1518:            //        //                // the component most likely as a child of the form component.
1519:            //        //            }
1520:            //
1521:            //        location.droppee = parent;
1522:            //
1523:            //        // If default-positioning, try to place the component before the <br/>, if
1524:            //        // the the br is the last element under the default parent.
1525:            //        if ((under == null) && (before == null)) {
1526:            //            if (parent == null) {
1527:            ////                parent = webform.getDefaultParentBean();
1528:            //                parent = defaultParentBean;
1529:            //            }
1530:            //            location.pos = getDefaultMarkupPositionUnderParent(parent/*, webform*/);
1531:            //        } else {
1532:            //            location.pos = new MarkupPosition(under, before);
1533:            //        }
1534:            //
1535:            //        return location;
1536:            //        
1537:            //    }
1538:
1539:            //    private static DomProvider.Location computeLocationForBean(DesignBean bean, int where, String facet, Point canvasPos, Dimension dropSize, WebForm webform) {
1540:            //        if (bean == null) {
1541:            //            throw new NullPointerException("Bean can't be null!"); // NOI18N
1542:            //        }
1543:            //        
1544:            //        DomProvider.Location location = new DomProvider.Location();
1545:            //        location.facet = facet;
1546:            //        location.coordinates = canvasPos;
1547:            ////        location.size = getDropSize();
1548:            //        location.size = dropSize;
1549:            //
1550:            ////        if ((bean != null) && !LiveUnit.isCssPositionable(bean)) {
1551:            //        if (bean instanceof MarkupDesignBean && !WebForm.getDomProviderService().isCssPositionable(
1552:            //                WebForm.getDomProviderService().getComponentRootElementForMarkupDesignBean((MarkupDesignBean)bean))) {
1553:            //            location.coordinates = null;
1554:            //        }
1555:            //
1556:            //        DesignBean parent = null;
1557:            //        Node under = null;
1558:            //        Node before = null;
1559:            //
1560:            //        Element element = null;
1561:            //
1562:            //        if (bean != null) {
1563:            ////            element = FacesSupport.getElement(bean);
1564:            ////            element = Util.getElement(bean);
1565:            //            element = WebForm.getDomProviderService().getElement(bean);
1566:            //
1567:            //            // No, can still reposition these guys.
1568:            //            //if (element == null) {
1569:            //            //    bean = null;
1570:            //            //}
1571:            //            location.droppeeElement = element;
1572:            //        }
1573:            //
1574:            //        //location.droppeeChosen = true;
1575:            //        if (where == DROP_CENTER) { // child of bean
1576:            //            parent = bean;
1577:            //            under = element;
1578:            //            before = null;
1579:            //        } else if (where == DROP_ABOVE) { // before bean
1580:            //            parent = bean.getBeanParent();
1581:            //            before = element;
1582:            //
1583:            //            if (element != null) {
1584:            //                under = element.getParentNode();
1585:            //            } else { // after bean
1586:            //                under = null;
1587:            //            }
1588:            //        } else {
1589:            //            parent = bean.getBeanParent();
1590:            //            assert where == DROP_BELOW;
1591:            //            before = null;
1592:            //
1593:            //            for (int i = 0, n = parent.getChildBeanCount(); i < (n - 1); i++) {
1594:            //                if (parent.getChildBean(i) == bean) {
1595:            //                    DesignBean next = parent.getChildBean(i + 1);
1596:            ////                    Element nextElement = FacesSupport.getElement(next);
1597:            ////                    Element nextElement = Util.getElement(next);
1598:            //                    Element nextElement = WebForm.getDomProviderService().getElement(next);
1599:            //                    before = nextElement;
1600:            //
1601:            //                    break;
1602:            //                }
1603:            //            }
1604:            //
1605:            //            if (element != null) {
1606:            //                under = element.getParentNode();
1607:            //            } else { // after bean
1608:            //                under = null;
1609:            //            }
1610:            //        }
1611:            //
1612:            //        location.droppee = parent;
1613:            //
1614:            //        // If default-positioning, try to place the component before the <br/>, if
1615:            //        // the the br is the last element under the default parent.
1616:            //        if ((under == null) && (before == null)) {
1617:            //            location.pos = getDefaultMarkupPositionUnderParent(parent, webform);
1618:            //        } else {
1619:            //            location.pos = new MarkupPosition(under, before);
1620:            //        }
1621:            //
1622:            //        return location;
1623:            //    }
1624:
1625:            //    /**
1626:            //     * Compute the target markup and bean positions to be used for a
1627:            //     * component insert, reposition or live pointer feedback.  <p> Given
1628:            //     * some parameters (prechosen position in the bean hierarchy
1629:            //     * (typically when you drop on the application outline), or a mouse
1630:            //     * coordinate or caret position (typically when dropping over the
1631:            //     * design surface)) return the position to be used.  <p> If a parent
1632:            //     * bean is specified, it takes precedence over a specified insert
1633:            //     * document position, which in turn takes precedence of a specified
1634:            //     * drop point on the canvas.
1635:            //     *
1636:            //     * @param bean The bean the user has pointed to, or null. The
1637:            //     * "where" parameter will indicate if we pointed directly at, or
1638:            //     * above or below, this bean. (If you point at a bean and it's a
1639:            //     * container, it probably means that you want to drop the new
1640:            //     * component as a child of this bean; if on the other hand you
1641:            //     * pointed below it you want to insert it as its sibling,
1642:            //     * immediately following this bean.)
1643:            //     * @param where Ignored if <code>bean</code> is null. Otherwise if
1644:            //     * DROP_ABOVE, you're pointing above the bean, if
1645:            //     * DROP_CENTER, you're pointing right at the bean,
1646:            //     * and if DROP_BELOW, you're pointing below the
1647:            //     * bean. These three values mean that the target position is
1648:            //     * before, as a child of, and after the bean respectively.
1649:            //     * @param documentPos If not null, indicates a document position
1650:            //     * where the component should be inserted (flow mode).
1651:            //     * @param canvasPos If not null, indicates a position in the canvas
1652:            //     * the user has pointed (absolute positioning mode).
1653:            //     * @param split If true, split a text node if necessary such that
1654:            //     * we can potentially insert in the middle of the text. This mutates
1655:            //     * the document.
1656:            //     *
1657:            //     * @return The parent DesignBean to be used
1658:            //     */
1659:            //    private static Location doComputePositions(DesignBean bean, int where, String facet, Point canvasPos,
1660:            //    /*Position documentPos,*/ Node documentPosNode, int documentPosOffset, boolean split, Dimension dropSize,
1661:            //    boolean isGrid, Element droppeeElement, DesignBean droppeeBean, FacesModel facesModel) {
1662:            //        Location location = new Location();
1663:            //        location.facet = facet;
1664:            //        location.coordinates = canvasPos;
1665:            ////        location.size = getDropSize();
1666:            //        location.size = dropSize;
1667:            //
1668:            //        if ((bean != null) && !LiveUnit.isCssPositionable(bean)) {
1669:            //            location.coordinates = null;
1670:            //        }
1671:            //
1672:            //        DesignBean parent = null;
1673:            //        Node under = null;
1674:            //        Node before = null;
1675:            //
1676:            //        Element element = null;
1677:            //
1678:            //        if (bean != null) {
1679:            //            element = FacesSupport.getElement(bean);
1680:            //
1681:            //            // No, can still reposition these guys.
1682:            //            //if (element == null) {
1683:            //            //    bean = null;
1684:            //            //}
1685:            //            location.droppeeElement = element;
1686:            //        }
1687:            //
1688:            //        if (bean == null) {
1689:            ////            if ((canvasPos == null) && (documentPos == null) &&
1690:            ////                    (webform.getPane().getCaret() != null)) {
1691:            ////                // The user is trying to insert a component without
1692:            ////                // dropping in a particular location; use the caret
1693:            ////                // position
1694:            ////                DesignerCaret caret = webform.getPane().getCaret();
1695:            ////
1696:            ////                if (!caret.isReadOnlyRegion()) {
1697:            ////                    documentPos = caret.getDot();
1698:            ////                }
1699:            //
1700:            ////            if ((documentPos != null) && (documentPos != Position.NONE) &&
1701:            ////                    !Document.isReadOnlyRegion(documentPos)) {
1702:            ////                // XXX TODO: split text nodes!
1703:            ////                if (documentPos.getNode() instanceof Text) {
1704:            ////                    if (documentPos.getOffset() == 0) {
1705:            ////                        before = documentPos.getNode();
1706:            ////                        under = before.getParentNode();
1707:            ////                    } else {
1708:            ////                        Text txt = (Text)documentPos.getNode();
1709:            ////
1710:            ////                        if (documentPos.getOffset() < txt.getLength()) {
1711:            ////                            before = txt.splitText(documentPos.getOffset());
1712:            ////                            under = before.getParentNode();
1713:            ////                        } else {
1714:            ////                            before = txt.getNextSibling();
1715:            ////                            under = txt.getParentNode();
1716:            ////                        }
1717:            ////                    }
1718:            ////                } else {
1719:            ////                    int offset = documentPos.getOffset();
1720:            ////
1721:            ////                    if (offset < documentPos.getNode().getChildNodes().getLength()) {
1722:            ////                        under = documentPos.getNode();
1723:            ////                        before = under.getChildNodes().item(offset);
1724:            ////                    } else {
1725:            ////                        // Just append - but we don't have an api for that (can only set "before")
1726:            ////                        // so create a new blank text node as a hook
1727:            ////                        // XXX should I really mutate the document here?
1728:            ////                        // That doesn't sound right...
1729:            ////                        under = documentPos.getNode();
1730:            ////
1731:            ////                        // XXX Manipulation of the doc may not be done here.
1732:            ////                        Text txt = webform.getJspDom().createTextNode(" "); // NOI18N
1733:            ////                        under.appendChild(txt);
1734:            ////                        before = txt;
1735:            ////                    }
1736:            ////                }
1737:            //            if (documentPosNode != null) {
1738:            //                // XXX TODO: split text nodes!
1739:            //                if (documentPosNode instanceof Text) {
1740:            //                    if (documentPosOffset == 0) {
1741:            //                        before = documentPosNode;
1742:            //                        under = before.getParentNode();
1743:            //                    } else {
1744:            //                        Text txt = (Text)documentPosNode;
1745:            //
1746:            //                        if (documentPosOffset < txt.getLength()) {
1747:            //                            before = txt.splitText(documentPosOffset);
1748:            //                            under = before.getParentNode();
1749:            //                        } else {
1750:            //                            before = txt.getNextSibling();
1751:            //                            under = txt.getParentNode();
1752:            //                        }
1753:            //                    }
1754:            //                } else {
1755:            //                    int offset = documentPosOffset;
1756:            //
1757:            //                    if (offset < documentPosNode.getChildNodes().getLength()) {
1758:            //                        under = documentPosNode;
1759:            //                        before = under.getChildNodes().item(offset);
1760:            //                    } else {
1761:            //                        // Just append - but we don't have an api for that (can only set "before")
1762:            //                        // so create a new blank text node as a hook
1763:            //                        // XXX should I really mutate the document here?
1764:            //                        // That doesn't sound right...
1765:            //                        under = documentPosNode;
1766:            //
1767:            //                        // XXX Manipulation of the doc may not be done here.
1768:            ////                        Text txt = webform.getJspDom().createTextNode(" "); // NOI18N
1769:            //                        Text txt = under.getOwnerDocument().createTextNode(" "); // NOI18N
1770:            //                        under.appendChild(txt);
1771:            //                        before = txt;
1772:            //                    }
1773:            //                }
1774:            //
1775:            //                if (parent == null) {
1776:            //                    Node n = under;
1777:            //
1778:            ////                    while (n instanceof RaveElement) {
1779:            ////                        RaveElement xel = (RaveElement)n;
1780:            //                    while (n instanceof Element) {
1781:            //                        Element xel = (Element)n;
1782:            //
1783:            ////                        if (xel.getDesignBean() != null) {
1784:            ////                            DesignBean lbean = (DesignBean)xel.getDesignBean();
1785:            //                        DesignBean lbean = InSyncService.getProvider().getMarkupDesignBeanForElement(xel);
1786:            //                        if (lbean != null) {
1787:            //                            if (lbean.isContainer()) {
1788:            //                                parent = lbean;
1789:            //
1790:            //                                break;
1791:            //                            }
1792:            //                        }
1793:            //
1794:            //                        n = n.getParentNode();
1795:            //                    }
1796:            //                }
1797:            //
1798:            //                //!CQ: facesUnit.setInsertBefore(before);
1799:            //                // determine the integer offset of the before node within its parent
1800:            //                if ((under != null) && (under.getNodeType() == Node.ELEMENT_NODE)) {
1801:            //                    location.droppeeElement = (Element)under;
1802:            //                }
1803:            //            } else if (canvasPos != null) {
1804:            //                // What position should we assign here??? For now, nothing.
1805:            //                // Let insync pick a position. The exact location in the source
1806:            //                // where the tag is inserted isn't very important since we're
1807:            //                // absolute positioning anyway.
1808:            //                under = null;
1809:            //                before = null;
1810:            //
1811:            ////                CssBox box = webform.getMapper().findBox(canvasPos.x, canvasPos.y);
1812:            ////                CssBox box = ModelViewMapper.findBox(webform.getPane().getPageBox(), canvasPos.x, canvasPos.y);
1813:            ////
1814:            ////                // In flow mode, don't do absolute positioning, ever, unless we're in
1815:            ////                // a grid positioning area
1816:            ////                if (!webform.isGridMode() && ((box == null) || !box.isGrid())) {
1817:            ////                    location.coordinates = null;
1818:            ////                }
1819:            ////
1820:            ////                location.droppeeElement = box.getElement();
1821:            ////                parent = getDroppee(box);
1822:            //                if (!isGrid) {
1823:            //                    location.coordinates = null;
1824:            //                }
1825:            //                location.droppeeElement = droppeeElement;
1826:            //                parent = droppeeBean;
1827:            //            }
1828:            //
1829:            //            //            else {
1830:            //            //                // No position specified. In this case send just nulls
1831:            //            //                // to insync and let insync figure it out. It will insert
1832:            //            //                // the component most likely as a child of the form component.
1833:            //            //            }
1834:            //        } else {
1835:            //            //location.droppeeChosen = true;
1836:            //            if (where == DROP_CENTER) { // child of bean
1837:            //                parent = bean;
1838:            //                under = element;
1839:            //                before = null;
1840:            //            } else if (where == DROP_ABOVE) { // before bean
1841:            //                parent = bean.getBeanParent();
1842:            //                before = element;
1843:            //
1844:            //                if (element != null) {
1845:            //                    under = element.getParentNode();
1846:            //                } else { // after bean
1847:            //                    under = null;
1848:            //                }
1849:            //            } else {
1850:            //                parent = bean.getBeanParent();
1851:            //                assert where == DROP_BELOW;
1852:            //                before = null;
1853:            //
1854:            //                for (int i = 0, n = parent.getChildBeanCount(); i < (n - 1); i++) {
1855:            //                    if (parent.getChildBean(i) == bean) {
1856:            //                        DesignBean next = parent.getChildBean(i + 1);
1857:            //                        Element nextElement = FacesSupport.getElement(next);
1858:            //                        before = nextElement;
1859:            //
1860:            //                        break;
1861:            //                    }
1862:            //                }
1863:            //
1864:            //                if (element != null) {
1865:            //                    under = element.getParentNode();
1866:            //                } else { // after bean
1867:            //                    under = null;
1868:            //                }
1869:            //            }
1870:            //        }
1871:            //
1872:            //        location.droppee = parent;
1873:            //
1874:            //        // If default-positioning, try to place the component before the <br/>, if
1875:            //        // the the br is the last element under the default parent.
1876:            //        if ((under == null) && (before == null)) {
1877:            //            location.pos = getDefaultMarkupPositionUnderParent(parent, facesModel);
1878:            //        } else {
1879:            //            location.pos = new MarkupPosition(under, before);
1880:            //        }
1881:            //
1882:            //        return location;
1883:            //    }
1884:
1885:            //    private static MarkupPosition getDefaultMarkupPositionUnderParent(DesignBean parent/*, WebForm webform*/) {
1886:            ////        Node under = null;
1887:            ////        Node before = null;
1888:            ////        if ((parent != null) && parent instanceof MarkupDesignBean) {
1889:            ////            under = ((MarkupDesignBean)parent).getElement();
1890:            ////        }
1891:            ////
1892:            ////        if (under == null) {
1893:            //////                under = webform.getModel().getFacesUnit().getDefaultParent().getElement();
1894:            ////            under = facesModel.getFacesUnit().getDefaultParent().getElement();
1895:            ////        }
1896:            ////
1897:            ////        if (under != null) {
1898:            ////            NodeList children = under.getChildNodes();
1899:            ////
1900:            ////            if (children.getLength() > 0) {
1901:            ////                Node last = children.item(children.getLength() - 1);
1902:            ////
1903:            ////                while (last != null) {
1904:            ////                    if ((last.getNodeType() != Node.TEXT_NODE) ||
1905:            ////                            !DesignerUtils.onlyWhitespace(last.getNodeValue())) {
1906:            ////                        break;
1907:            ////                    }
1908:            ////
1909:            ////                    last = last.getPreviousSibling();
1910:            ////                }
1911:            ////
1912:            ////                if ((last != null) && (last.getNodeType() == Node.ELEMENT_NODE) &&
1913:            ////                        last.getNodeName().equals(HtmlTag.BR.name)) {
1914:            ////                    before = last;
1915:            ////                }
1916:            ////            }
1917:            ////        }
1918:            ////
1919:            ////        return new MarkupPosition(under, before);
1920:            ////        return webform.getDefaultMarkupPositionUnderParent(parent);
1921:            //        return WebForm.getDomProviderService().getDefaultMarkupPositionUnderParent(parent);
1922:            //    }
1923:
1924:            //    /** Figure out which kind of action we can do for the given
1925:            //     * transferable over the given droppee.
1926:            //     *
1927:            //     * @param droppee The target component
1928:            //     * @param transferable The transferable being considered dropped
1929:            //     *        or linked on the droppee. If it references multiple
1930:            //     *        components, it will set the allowable action union of
1931:            //     *        all the components.
1932:            //     * @param searchUp If true, you are permitted to search upwards
1933:            //     *        as well.
1934:            //     */
1935:            ////    public int computeActions(DesignBean droppee, Transferable transferable, boolean searchUp,
1936:            ////        int nodePos) {
1937:            //    public int computeActions(Element dropeeComponentRootElement, Transferable transferable, boolean searchUp,
1938:            //        int nodePos) {
1939:            ////        if(DesignerUtils.DEBUG) {
1940:            ////            DesignerUtils.debugLog(getClass().getName() + ".computeActions(DesignBean, Transferable, boolean, int)");
1941:            ////        }
1942:            ////        if(transferable == null) {
1943:            ////            throw(new IllegalArgumentException("Null transferable."));
1944:            ////        }
1945:            ////        int action = DnDConstants.ACTION_NONE;
1946:            ////        String[] classes = null;
1947:            ////        DesignBean[] beans = null;
1948:            ////        DataFlavor[] flavors = transferable.getTransferDataFlavors();
1949:            ////
1950:            ////        for (int j = 0; j < flavors.length; j++) {
1951:            ////            Class clz = flavors[j].getRepresentationClass();
1952:            ////
1953:            ////            if (clz == DisplayItem.class) {
1954:            ////                // Can always "move" from the palette - it's an implied copy.
1955:            ////                // The explorer drag & drop is a bit weird about this - they
1956:            ////                // only pass "move" as the valid operation, not copy.
1957:            ////                action |= DnDConstants.ACTION_MOVE;
1958:            ////
1959:            ////                Object data;
1960:            ////
1961:            ////                try {
1962:            ////                    data = transferable.getTransferData(flavors[j]);
1963:            ////                } catch (Exception e) {
1964:            ////                    ErrorManager.getDefault().notify(e);
1965:            ////
1966:            ////                    return action;
1967:            ////                }
1968:            ////
1969:            ////                if (!(data instanceof DisplayItem)) {
1970:            ////                    ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, 
1971:            ////                            new IllegalStateException("Invalid DisplayItem transfer data: " + data)); // NOI18N
1972:            ////
1973:            ////                    return action;
1974:            ////                }
1975:            ////
1976:            ////                List list = new ArrayList();
1977:            ////                DisplayItem item = (DisplayItem)data;
1978:            ////
1979:            ////                if (item instanceof BeanCreateInfo) {
1980:            ////                    BeanCreateInfo bci = (BeanCreateInfo)item;
1981:            ////                    classes = new String[] { bci.getBeanClassName() };
1982:            ////                } else if (item instanceof BeanCreateInfoSet) {
1983:            ////                    BeanCreateInfoSet bcis = (BeanCreateInfoSet)item;
1984:            ////                    classes = bcis.getBeanClassNames();
1985:            ////                } else {
1986:            ////                    ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
1987:            ////                            new IllegalStateException("Illegal item=" + item)); // NOI18N
1988:            ////                }
1989:            ////
1990:            ////                break;
1991:            ////            } else if (clz == DesignBean.class) {
1992:            ////                Object data;
1993:            ////
1994:            ////                try {
1995:            ////                    data = transferable.getTransferData(flavors[j]);
1996:            ////                } catch (IOException ex) {
1997:            ////                    ErrorManager.getDefault().notify(ex);
1998:            ////
1999:            ////                    return action;
2000:            ////                } catch (UnsupportedFlavorException ex) {
2001:            ////                    ErrorManager.getDefault().notify(ex);
2002:            ////
2003:            ////                    return action;
2004:            ////                }
2005:            ////
2006:            ////                if ((data != null) && data instanceof DesignBean[]) {
2007:            ////                    beans = (DesignBean[])data;
2008:            ////
2009:            ////                    if (beans == null) {
2010:            ////                        return action;
2011:            ////                    }
2012:            ////
2013:            ////                    classes = new String[beans.length];
2014:            ////
2015:            ////                    for (int i = 0; i < beans.length; i++) {
2016:            ////                        classes[i] = beans[i].getInstance().getClass().getName();
2017:            ////                    }
2018:            ////
2019:            ////                    // See if we can move these beans. We can move if the
2020:            ////                    // parent target location is not a child of any of the beans,
2021:            ////                    // or the beans themselves
2022:            ////                    boolean cannot = false;
2023:            ////
2024:            ////                    for (int i = 0; i < beans.length; i++) {
2025:            ////                        DesignBean d = droppee;
2026:            ////
2027:            ////                        while (d != null) {
2028:            ////                            if (d == beans[i]) {
2029:            ////                                cannot = true;
2030:            ////
2031:            ////                                break;
2032:            ////                            }
2033:            ////
2034:            ////                            d = d.getBeanParent();
2035:            ////                        }
2036:            ////                    }
2037:            ////
2038:            ////                    if (!cannot) {
2039:            ////                        action |= DnDConstants.ACTION_MOVE;
2040:            ////                    }
2041:            ////
2042:            ////                    break;
2043:            ////                }
2044:            ////            } else if (clz == LiveUnit.ClipImage.class) {
2045:            ////                Object data;
2046:            ////
2047:            ////                try {
2048:            ////                    data = transferable.getTransferData(flavors[j]);
2049:            ////                } catch (Exception e) {
2050:            ////                    ErrorManager.getDefault().notify(e);
2051:            ////
2052:            ////                    return action;
2053:            ////                }
2054:            ////
2055:            ////                if (!(data instanceof LiveUnit.ClipImage)) {
2056:            ////                    ErrorManager.getDefault().log("Invalid LiveUnit.ClipImage transfer data: " +
2057:            ////                        data);
2058:            ////
2059:            ////                    return action;
2060:            ////                }
2061:            ////
2062:            ////                LiveUnit.ClipImage luc = (LiveUnit.ClipImage)data;
2063:            ////                classes = luc.getTypes();
2064:            ////            }
2065:            ////        }
2066:            ////
2067:            ////        if (classes == null) {
2068:            ////            return action;
2069:            ////        }
2070:            ////
2071:            ////        return computeActions(droppee, classes, beans, action, searchUp, nodePos);
2072:            ////        return webform.computeActions(droppee, transferable, searchUp, nodePos);
2073:            //        return webform.computeActions(dropeeComponentRootElement, transferable, searchUp, nodePos);
2074:            //    }
2075:
2076:            //    private int computeActions(DesignBean origDroppee, String[] classes, DesignBean[] beans,
2077:            //        int action, boolean searchUp, int nodePos) {
2078:            //        DesignBean droppee = null;
2079:            //
2080:            //        if (nodePos == DROP_CENTER) { // Can only link if pointing at a node
2081:            //linkCheckFinished: 
2082:            //            for (int i = 0; i < classes.length; i++) {
2083:            //                try {
2084:            //                    Class clz = webform.getModel().getFacesUnit().getBeanClass(classes[i]);
2085:            //                    DesignBean lb = null;
2086:            //
2087:            //                    if (beans != null) {
2088:            //                        lb = beans[i];
2089:            //                    }
2090:            //
2091:            //                    droppee = origDroppee;
2092:            //
2093:            //                    for (droppee = origDroppee; droppee != null;
2094:            //                            droppee = droppee.getBeanParent()) {
2095:            //                        // Prevent self-linking
2096:            //                        if (beans != null) {
2097:            //                            boolean same = false;
2098:            //
2099:            //                            for (int j = 0; j < beans.length; j++) {
2100:            //                                if (droppee == beans[j]) {
2101:            //                                    same = true;
2102:            //
2103:            //                                    break;
2104:            //                                }
2105:            //                            }
2106:            //
2107:            //                            if (same) {
2108:            //                                if (!searchUp) {
2109:            //                                    break;
2110:            //                                } else {
2111:            //                                    continue;
2112:            //                                }
2113:            //                            }
2114:            //                        }
2115:            //
2116:            //                        DesignInfo dbi = droppee.getDesignInfo();
2117:            //
2118:            //                        if ((dbi != null) && dbi.acceptLink(droppee, lb, clz)) {
2119:            //                            action |= DnDConstants.ACTION_LINK;
2120:            //
2121:            //                            break linkCheckFinished;
2122:            //                        }
2123:            //
2124:            //                        if (!searchUp) {
2125:            //                            break;
2126:            //                        }
2127:            //                    }
2128:            //                } catch (Exception e) {
2129:            //                    ErrorManager.getDefault().notify(e);
2130:            //                }
2131:            //            }
2132:            //        } else {
2133:            //            // For pos=ABOVE or BELOW, the passed in node points to the specific
2134:            //            // node -sibling-, but we want the parent
2135:            //            origDroppee = origDroppee.getBeanParent();
2136:            //        }
2137:            //
2138:            //        // See if any of the droppee parents accept the new item as a
2139:            //        // child
2140:            //        for (int i = 0; i < classes.length; i++) {
2141:            //            DesignBean parent = findParent(classes[i], origDroppee, null, searchUp);
2142:            //
2143:            //            if (parent != null) {
2144:            //                action |= DnDConstants.ACTION_COPY;
2145:            //
2146:            //                break;
2147:            //            } else {
2148:            //                action &= ~DnDConstants.ACTION_MOVE;
2149:            //
2150:            //                break;
2151:            //            }
2152:            //        }
2153:            //
2154:            //        return action;
2155:            //    }
2156:
2157:            //    private List createBeans(Location location, DisplayItem[] items, List beanItems, CoordinateTranslator coordinateTranslator)
2158:            //        throws IOException {
2159:            //        DesignBean droppee = location.droppee;
2160:            //        MarkupPosition position = location.pos;
2161:            //        String facet = location.facet;
2162:            //
2163:            //        ArrayList created = new ArrayList(2 * items.length); // slop for BeanCreateInfoSets
2164:            //
2165:            //        for (int i = 0; i < items.length; i++) {
2166:            //
2167:            ////            if (!(items[i] instanceof BeanPaletteItem)) {
2168:            ////                importItem(items[i], null, DROP_CENTER, null, null);
2169:            ////
2170:            ////                continue;
2171:            ////            }
2172:            //
2173:            //            DisplayItem item = (DisplayItem)items[i];
2174:            //            
2175:            //            // <change>
2176:            //            // XXX There is a need to get class name even from the bean create info set.
2177:            ////            String className = item.getBeanClassName();
2178:            //// ====
2179:            //            String className = null;
2180:            //            // </change>
2181:            //
2182:            ////            // Customize creation if requested by the component
2183:            ////            BeanCreateInfo bci = item.getBeanCreateInfo();
2184:            ////            BeanCreateInfoSet bcis = item.getBeanCreateInfoSet();
2185:            //
2186:            ////            // At most one of the above should be set...
2187:            ////            assert !((bci != null) && (bcis != null));
2188:            //
2189:            //            String[] classes = null;
2190:            //            int current = 0;
2191:            //            int max = 0;
2192:            //
2193:            //            if (item instanceof BeanCreateInfoSet) {
2194:            //                BeanCreateInfoSet bcis = (BeanCreateInfoSet)item;
2195:            //                // Set us up for multiple bean creation
2196:            //                classes = bcis.getBeanClassNames();
2197:            //                max = classes.length;
2198:            //            } else if (item instanceof BeanCreateInfo) {
2199:            //                className = ((BeanCreateInfo)item).getBeanClassName();
2200:            //            } else {
2201:            //                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
2202:            //                        new IllegalStateException("Illegal item=" + item)); // NOI18N
2203:            //                continue;
2204:            //            }
2205:            //
2206:            //            do {
2207:            //                // If we're creating multiple beans from a BeanCreateInfoSet
2208:            //                // fetch the next class name
2209:            //                if (current < max) {
2210:            //                    className = classes[current++];
2211:            //                }
2212:            //
2213:            //                DesignBean parent = findParent(className, droppee, position.getUnderParent(), true);
2214:            //
2215:            //                if (parent != null) {
2216:            //                    boolean droppingOnFrameset = parent.getInstance() instanceof FramesetFrameset;
2217:            //                    boolean droppingOnFrame = parent.getInstance() instanceof Frame;
2218:            //
2219:            //                    if (droppingOnFrameset || droppingOnFrame) {
2220:            //                        //                if (!(droppingOnFrameset && (className.equals(HtmlBean.PACKAGE+"Frame") ||
2221:            //                        //                                             className.equals(HtmlBean.PACKAGE+"FramesetFrameset")))) { // NOI18N
2222:            //                        if (!(droppingOnFrameset &&
2223:            //                                (className.equals(Frame.class.getName()) ||
2224:            //                                className.equals(Frame.class.getName())))) {
2225:            //                            NotifyDescriptor d =
2226:            //                                new NotifyDescriptor.Message(NbBundle.getMessage(DndHandler.class,
2227:            //                                        "NoFrameDrops", item.getDisplayName()),
2228:            //                                    NotifyDescriptor.WARNING_MESSAGE);
2229:            //                            DialogDisplayer.getDefault().notify(d);
2230:            //
2231:            //                            continue;
2232:            //                        }
2233:            //                    }
2234:            //                }
2235:            //
2236:            //                // Native method - is this result cached?
2237:            //                //if (className.equals(Jsp_Directive_Include.class.getName())) {
2238:            //                String savedClass = null;
2239:            //
2240:            //                if (className.equals(HtmlBean.PACKAGE + "Jsp_Directive_Include")) { // NOI18N
2241:            //
2242:            //                    // You're dropping a jsp:directive.include box. These cannot
2243:            //                    // be CSS positioned (e.g. dropped at a particular pixel
2244:            //                    // location over a grid layout area) - because this directive
2245:            //                    // does not have a style attribute, and Jasper will scream
2246:            //                    // bloody murder if we put it in.
2247:            //                    // So instead we drop a <div>, and place the jsp directive
2248:            //                    // inside it.
2249:            //                    // I wanted to solve this more cleanly: If you're dropping
2250:            //                    // a visual component and it doesn't have a "style" property,
2251:            //                    // it doesn't support positioning, so apply the above
2252:            //                    // <div>-wrapping trick. However, while I can check if a
2253:            //                    // component about to be dropped has a style property through
2254:            //                    // the beaninfo, I can't tell if it's a visual component
2255:            //                    // or not until it's actually instantiated (via
2256:            //                    // DesignBean.isVisualBean()) - so I can't do it this way or
2257:            //                    // suddenly e.g. rowset beans would be parented by <div> since
2258:            //                    // they don't have a style attribute....   So for now
2259:            //                    // it's just a special case check for the one known visual
2260:            //                    // component that doesn't have a style attribute.
2261:            //                    //if (getDropPoint() != null && insertPos == null) {
2262:            //                    savedClass = className;
2263:            //
2264:            //                    // XXX Why not Div.class.getName() ?
2265:            //                    className = HtmlBean.PACKAGE + "Div"; // NOI18N
2266:            //
2267:            //                    //}
2268:            //                    // Comment on above: we now ALWAYS want to insert a div, since
2269:            //                    // even in flow context you want a div which specifies
2270:            //                    // "position: relative" in order to ensure that absolutely
2271:            //                    // positioned children within the fragment are relative
2272:            //                    // to the jsp's top level corner, not the current viewport
2273:            //                    // or absolutely positioned -ancestor- of the jsp include
2274:            //                    // box.
2275:            //                }
2276:            //
2277:            //                // Adjust position, in case we're default inserting it
2278:            //                // If we're default-positioin inserting into a form or body,
2279:            //                // and it ends with a <br>, insert the new component before
2280:            //                // the <br> so that it doesn't create a new line.
2281:            //                if ((parent == null) &&
2282:            //                        ((position == null) ||
2283:            //                        ((position.getUnderParent() == null) &&
2284:            //                        (position.getBeforeSibling() == null)))) {
2285:            //                    // See if I have a Br
2286:            //                    MarkupBean formBean = webform.getModel().getFacesUnit().getDefaultParent();
2287:            //
2288:            //                    if (formBean != null) {
2289:            //                        Bean[] children = formBean.getChildren();
2290:            //
2291:            //                        if ((children != null) && (children.length > 0)) {
2292:            //                            Bean b = children[children.length - 1];
2293:            //
2294:            //                            if (b instanceof MarkupBean) {
2295:            //                                MarkupBean mb = (MarkupBean)b;
2296:            //
2297:            //                                if ((mb.getElement() != null) &&
2298:            //                                        mb.getElement().getTagName().equals(HtmlTag.BR.name)) {
2299:            //                                    position =
2300:            //                                        new MarkupPosition(formBean.getElement(), mb.getElement());
2301:            //                                }
2302:            //                            }
2303:            //                        }
2304:            //                    }
2305:            //                }
2306:            //
2307:            //                DesignBean bean = createBean(className, parent, position, facet);
2308:            //                select = bean;
2309:            //
2310:            //                if (bean != null) {
2311:            //                    created.add(bean);
2312:            //                    beanItems.add(items[i]);
2313:            //                }
2314:            //
2315:            //                if (bean instanceof MarkupDesignBean) {
2316:            //                    MarkupDesignBean mbean = (MarkupDesignBean)bean;
2317:            //                    positionBean(mbean, parent, mbean.getElement(), location, coordinateTranslator);
2318:            //
2319:            //                    if ((savedClass != null) && bean.isContainer()) {
2320:            //                        DesignBean child = createBean(savedClass, bean, null, null);
2321:            //
2322:            //                        if (child != null) {
2323:            //                            created.add(child);
2324:            //
2325:            //                            // Ensure that the two lists are kept in sync
2326:            //                            beanItems.add(null);
2327:            //                        }
2328:            //
2329:            //                        // If inserted in flow, put a <div> with relative
2330:            //                        // positioning around it to ensure that absolutely
2331:            //                        // positioned children in the div are absolute relative
2332:            //                        // to the jsp box, not whatever outer container is
2333:            //                        // establishing the current absolute positions
2334:            //                        if (insertPos != Position.NONE) {
2335:            //                            DesignProperty styleProp = bean.getProperty("style"); // NOI18N
2336:            //
2337:            //                            if (styleProp != null) {
2338:            //                                String mods = "position: relative"; // NOI18N
2339:            //                                String style = (String)styleProp.getValue();
2340:            //
2341:            //                                if ((style != null) && (style.length() > 0)) {
2342:            //                                    styleProp.setValue(style + "; " + mods);
2343:            //                                } else {
2344:            //                                    styleProp.setValue(mods);
2345:            //                                }
2346:            //                            }
2347:            //                        }
2348:            //
2349:            //                        /*
2350:            //                        DesignProperty styleProp = bean.getProperty("style"); // NOI18N
2351:            //                        if (styleProp != null) {
2352:            //                            String mods = "overflow: hidden; width: 240px"; // NOI18N
2353:            //                            String style = (String)styleProp.getValue();
2354:            //                            if (style != null && style.length() > 0) {
2355:            //                                styleProp.setValue(style + "; " + mods);
2356:            //                            } else {
2357:            //                                styleProp.setValue(mods);
2358:            //                            }
2359:            //                        }
2360:            //                        */
2361:            //                    }
2362:            //                }
2363:            //            } while (current < max);
2364:            //        }
2365:            //
2366:            //        insertPos = Position.NONE;
2367:            //
2368:            //        //facesUnit.setInsertBefore(null);
2369:            //        return created;
2370:            //    }
2371:
2372:            //    private DesignBean findParent(String className, DesignBean droppee, Node parentNode, boolean searchUp) {
2373:            ////        if (webform.isGridMode() && (droppee == null) &&
2374:            ////                (webform.getModel().getLiveUnit() != null)) {
2375:            ////            MarkupBean bean = webform.getModel().getFacesUnit().getDefaultParent();
2376:            ////
2377:            ////            if (bean != null) {
2378:            ////                droppee = webform.getModel().getLiveUnit().getDesignBean(bean);
2379:            ////            }
2380:            ////        }
2381:            ////
2382:            ////        DesignBean parent = droppee;
2383:            ////
2384:            ////        if (searchUp) {
2385:            ////            for (; (parent != null) && !parent.isContainer(); parent = parent.getBeanParent()) {
2386:            ////                ;
2387:            ////            }
2388:            ////        }
2389:            ////
2390:            ////        LiveUnit unit = webform.getModel().getLiveUnit();
2391:            ////
2392:            ////        if (searchUp) {
2393:            ////            boolean isHtmlBean =
2394:            ////                className.startsWith(HtmlBean.PACKAGE) &&
2395:            ////                // f:verbatim is explicitly allowed where jsf components can go
2396:            ////                // XXX Why not F_Verbatim.class.getName() ?
2397:            ////                !(HtmlBean.PACKAGE + "F_Verbatim").equals(className); // NOI18N
2398:            ////
2399:            ////            if (isHtmlBean) {
2400:            ////                // We can't drop anywhere below a "renders children" JSF
2401:            ////                // component
2402:            ////                parent = FacesSupport.findHtmlContainer(parent);
2403:            ////            }
2404:            ////        }
2405:            ////
2406:            ////        // Validate the parent: walk up the parent chain until you find
2407:            ////        // a parent which will accept the child.
2408:            ////        for (; parent != null; parent = parent.getBeanParent()) {
2409:            ////            if (unit.canCreateBean(className, parent, null)) {
2410:            ////                // Found it
2411:            ////                break;
2412:            ////            }
2413:            ////
2414:            ////            if (!searchUp) {
2415:            ////                return null;
2416:            ////            }
2417:            ////        }
2418:            ////
2419:            ////        if ((parent == null) && (parentNode != null)) {
2420:            ////            // Adjust hierarchy: we should pass in a parent
2421:            ////            // pointer based on where we are: locate the closest
2422:            ////            // jsf parent above
2423:            ////            Node n = parentNode;
2424:            ////            MarkupBean mb = null;
2425:            ////
2426:            ////            while (n != null) {
2427:            ////                if (n instanceof Element) {
2428:            ////                    Element e = (Element)n;
2429:            //////                    mb = FacesSupport.getMarkupBean(webform.getDocument(), e);
2430:            ////                    mb = getMarkupBean(webform.getModel(), e);
2431:            ////
2432:            ////                    if (mb != null) {
2433:            ////                        break;
2434:            ////                    }
2435:            ////                }
2436:            ////
2437:            ////                n = n.getParentNode();
2438:            ////            }
2439:            ////
2440:            ////            if (mb != null) {
2441:            ////                DesignBean lmb = webform.getModel().getLiveUnit().getDesignBean(mb);
2442:            ////
2443:            ////                if (lmb.isContainer()) {
2444:            ////                    parent = lmb;
2445:            ////                }
2446:            ////            }
2447:            ////
2448:            ////            if (parent == null) {
2449:            ////                parent = webform.getModel().getRootBean();
2450:            ////            }
2451:            ////        }
2452:            ////
2453:            ////        return parent;
2454:            //        return webform.findParent(className, droppee, parentNode, searchUp);
2455:            //    }
2456:
2457:            //    /**
2458:            //     * Given an element which possibly maps to a markup bean, return the corresponding bean.
2459:            //     */
2460:            //    private static MarkupBean getMarkupBean(FacesModel model, Element elem) {
2461:            ////        FacesModel model = doc.getWebForm().getModel();
2462:            //
2463:            //        if (model == null) { // testsuite
2464:            //
2465:            //            return null;
2466:            //        }
2467:            //
2468:            //        FacesPageUnit facesunit = model.getFacesUnit();
2469:            //        MarkupBean bean = null;
2470:            //
2471:            //        if (facesunit != null) {
2472:            //            bean = facesunit.getMarkupBean(elem);
2473:            //
2474:            //            // Find component for this element:
2475:            //        }
2476:            //
2477:            //        return bean;
2478:            //    }
2479:
2480:            //    private DesignBean createBean(String className, DesignBean parent,
2481:            //        Position pos, String facet) {
2482:            //        LiveUnit unit = webform.getModel().getLiveUnit();
2483:            //
2484:            //        if (parent != null) {
2485:            //            // It's possible that we're adding to a unit other than
2486:            //            // the web form one -- such as a Session Bean unit for
2487:            //            // a rowset
2488:            //            unit = (LiveUnit)parent.getDesignContext();
2489:            //
2490:            //            // Ensure that the MarkupPosition is correct
2491:            //            if (pos instanceof MarkupPosition) {
2492:            //                MarkupPosition markupPos = (MarkupPosition)pos;
2493:            //
2494:            ////                if (markupPos.getUnderParent() instanceof RaveElement) {
2495:            ////                    RaveElement parentElement = (RaveElement)markupPos.getUnderParent();
2496:            //                if (markupPos.getUnderParent() instanceof Element) {
2497:            //                    Element parentElement = (Element)markupPos.getUnderParent();
2498:            //
2499:            ////                    while (parentElement.getDesignBean() != parent) {
2500:            //                    while (InSyncService.getProvider().getMarkupDesignBeanForElement(parentElement) != parent) {
2501:            ////                        if (parentElement.getParentNode() instanceof RaveElement) {
2502:            ////                            parentElement = (RaveElement)parentElement.getParentNode();
2503:            //                        if (parentElement.getParentNode() instanceof Element) {
2504:            //                            parentElement = (Element)parentElement.getParentNode();
2505:            //                        } else {
2506:            //                            break;
2507:            //                        }
2508:            //                    }
2509:            //
2510:            //                    if ((parentElement != null) && (parentElement != markupPos.getUnderParent())) {
2511:            //                        // The parent DesignBean is for a higher-up element. This can happen
2512:            //                        // when the acceptChild/acceptParent calls force parenting up higher
2513:            //                        // in the chain.
2514:            //                        pos = new MarkupPosition(parentElement, null);
2515:            //                    }
2516:            //                }
2517:            //            }
2518:            //        }
2519:            //
2520:            //        if (facet != null) {
2521:            //            return unit.createFacet(facet, className, parent);
2522:            //        }
2523:            //
2524:            //        return unit.createBean(className, parent, pos);
2525:            //    }
2526:
2527:            //    private void beansCreated(List beans, List beanItems) {
2528:            //        int n = beans.size();
2529:            //
2530:            //        for (int i = 0; i < n; i++) {
2531:            //            DesignBean lb = (DesignBean)beans.get(i);
2532:            //
2533:            //            try {
2534:            //                webform.getModel().beanCreated(lb);
2535:            //            } catch (Exception e) {
2536:            //                ErrorManager.getDefault().notify(e);
2537:            //            }
2538:            //        }
2539:            //
2540:            //        for (int i = 0; i < n; i++) {
2541:            //            DisplayItem item = (DisplayItem)beanItems.get(i);
2542:            //
2543:            //            if (item == null) {
2544:            //                continue;
2545:            //            }
2546:            //
2547:            ////            // Customize creation if requested by the component
2548:            ////            BeanCreateInfo bci = item.getBeanCreateInfo();
2549:            ////            BeanCreateInfoSet bcis = item.getBeanCreateInfoSet();
2550:            ////
2551:            ////            if ((bci == null) && (bcis == null)) {
2552:            ////                continue;
2553:            ////            }
2554:            ////
2555:            ////            // At most one of the above should be set...
2556:            ////            assert !((bci != null) && (bcis != null));
2557:            //
2558:            //            // Multiple beans could have been created from this item....
2559:            //            // check that and process them
2560:            //            if (item instanceof BeanCreateInfoSet) {
2561:            //                BeanCreateInfoSet bcis = (BeanCreateInfoSet)item;
2562:            //                // I don't want to rely on bcis.getBeanClassNames().length because one or more
2563:            //                // beans could have failed to have been created (missing class, or
2564:            //                // designtime canCreate returned false, etc.) - which would lead to
2565:            //                // getting out of sync.
2566:            //                // So instead I count by checking for identical BeanCreateItems
2567:            //                // in subsequent beanItems entries
2568:            //                ArrayList list = new ArrayList();
2569:            //
2570:            //                for (int j = i; j < n; j++) {
2571:            //                    if (beanItems.get(j) == item) {
2572:            //                        list.add(beans.get(j));
2573:            //                    }
2574:            //                }
2575:            //
2576:            //                if (list.size() > 0) {
2577:            //                    i += (list.size() - 1);
2578:            //
2579:            //                    DesignBean[] createdBeans =
2580:            //                        (DesignBean[])list.toArray(new DesignBean[list.size()]);
2581:            //                    Result result = bcis.beansCreatedSetup(createdBeans);
2582:            //                    ResultHandler.handleResult(result, webform.getModel());
2583:            //                }
2584:            //            } else if (item instanceof BeanCreateInfo) {
2585:            //                BeanCreateInfo bci = (BeanCreateInfo)item;
2586:            //                DesignBean bean = (DesignBean)beans.get(i);
2587:            //                Result result = bci.beanCreatedSetup(bean);
2588:            //                ResultHandler.handleResult(result, webform.getModel());
2589:            //            } else {
2590:            //                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
2591:            //                        new IllegalStateException("Invalid item=" + item)); // NOI18N
2592:            //            }
2593:            //        }
2594:            //    }
2595:
2596:            //    /** Handle links where the target is a possibly nonvisual bean so has no element */
2597:            //    public void handleLinks(DesignBean droppee, ArrayList beans) {
2598:            ////        Document document = webform.getDocument();
2599:            //
2600:            //        int n = beans.size();
2601:            //        String description =
2602:            //            NbBundle.getMessage(DndHandler.class, (n > 1) ? "LinkComponents" : "LinkComponent"); // NOI18N
2603:            //        UndoEvent undoEvent = webform.getModel().writeLock(description);
2604:            //        try {
2605:            ////            int n = beans.size();
2606:            ////            String description =
2607:            ////                NbBundle.getMessage(DndHandler.class, (n > 1) ? "LinkComponents" : "LinkComponent"); // NOI18N
2608:            ////            document.writeLock(description);
2609:            //
2610:            //            for (int i = 0; i < n; i++) {
2611:            //                DesignBean lb = (DesignBean)beans.get(i);
2612:            //
2613:            //                try {
2614:            //                    // If you drop on an existing component, see if they
2615:            //                    // can be wired together
2616:            //                    // Try to bind the two together - for example, if you
2617:            //                    // drop a RowSet on a bean that has a RowSet property,
2618:            //                    // the RowSet property is bound to this particular
2619:            //                    // RowSet.
2620:            //                    DesignInfo dbi = droppee.getDesignInfo();
2621:            //                    boolean canLink =
2622:            //                        (dbi != null) && dbi.acceptLink(droppee, lb, lb.getInstance().getClass());
2623:            //
2624:            //                    if (canLink) {
2625:            //                        MarkupDesignBean mbean = null;
2626:            //
2627:            //                        if (droppee instanceof MarkupDesignBean) {
2628:            //                            // link beans might perform lots and lots of
2629:            //                            // updates on the element - that's the case
2630:            //                            // for the data grid when you bind a table
2631:            //                            // to it for example.  So batch up all these
2632:            //                            // modifications into a single change event
2633:            //                            // on the top level element.
2634:            //                            mbean = (MarkupDesignBean)droppee;
2635:            ////                            webform.getDomSynchronizer().setUpdatesSuspended(mbean, true);
2636:            //                            webform.setUpdatesSuspended(mbean, true);
2637:            //                        }
2638:            //
2639:            //                        try {
2640:            //                            webform.getModel().linkBeans(droppee, lb);
2641:            //                        } finally {
2642:            //                            if (mbean != null) {
2643:            //                                // Process queued up changes
2644:            ////                                webform.getDomSynchronizer().setUpdatesSuspended(mbean, false);
2645:            //                                webform.setUpdatesSuspended(mbean, false);
2646:            //                            }
2647:            //                        }
2648:            //
2649:            //                        // The target bean should be selected instead of
2650:            //                        // the droppee!
2651:            //                        select = droppee;
2652:            //                    }
2653:            //                } catch (Exception e) {
2654:            //                    ErrorManager.getDefault().notify(e);
2655:            //                }
2656:            //            }
2657:            //        } finally {
2658:            ////            document.writeUnlock();
2659:            //            webform.getModel().writeUnlock(undoEvent);
2660:            //        }
2661:            //    }
2662:
2663:            //    /**
2664:            //     * Multi-function method dealing with link handling for components.
2665:            //     * I used to have separate methods which accomplished various aspects of link
2666:            //     * handling, but these would vary slightly in how they handled certain aspects
2667:            //     * and as a result inconsistent handling would result. Thus, all the logic is handled
2668:            //     * by the same method -- both "previewing" what links are available as well as actually
2669:            //     * handling the linking. The flags control the behaviors.
2670:            //     *
2671:            //     * @param origElement The first/innermost element to start with when searching
2672:            //     *    the bean hierarchy for DesignBean and MarkupMouseRegions willing to link
2673:            //     *    the given beans or bean classes.
2674:            //     * @param classes Array of classes to be checked for link eligibility. This is
2675:            //     *    separate from beans because we often want to check if linking is possible
2676:            //     *    before we actually have created beans -- such as when we're about to
2677:            //     *    drag &amp; drop. Obviously in this case we can't perform linking. This
2678:            //     *     parameter can be null but then beans must not be null.
2679:            //     * @param beans Can be null, but if not, should correspond exactly to the classes
2680:            //     *    parameter -- same length, same order, etc. This list must be specified
2681:            //     *    if handleLinks is true; you can't link on just class names.
2682:            //     * @param selectFirst If set, don't ask the user which target to use if there are multiple
2683:            //     *    possibilities; just pick the first one. If not set, all eligible link handlers
2684:            //     *    in the parent chain up from the original element will be checked, and if more than
2685:            //     *    one is willing to link, the user will be presented with a list and asked to choose.
2686:            //     * @param handleLinks If true, actually perform the linking.
2687:            //     * @param showLinkTarget If true, highlihght the link target and region. Also sets the
2688:            //     *    recentDropTarget field.
2689:            //     * @return DROP_DENIED if no beans/classes were linkable for any mouse regions or
2690:            //     *    DesignBeans; otherwise returns DROP_LINKED. If showLinkTarget is set, recentDropTarget
2691:            //     *    will be set to the most recent such eligible DesignBean.
2692:            //     */
2693:            ////    public int processLinks(Element origElement, Class[] classes, List beans,
2694:            //    public int processLinks(Element origElement, Class[] classes, Element componentRootElement,
2695:            //        boolean selectFirst, // if there are multiple hits; if not ask user
2696:            //        boolean handleLinks, // actually do linking
2697:            //        boolean showLinkTarget) {
2698:            //        
2699:            ////        ErrorManager.getDefault()
2700:            ////    .getInstance(DesignerUtils.class.getName()).isLoggable(ErrorManager.INFORMATIONAL);
2701:            ////        if(DesignerUtils.DEBUG) {
2702:            ////            DesignerUtils.debugLog(getClass().getName() + ".processLinks(Element, Class[], ArrayList, boolean, boolean, boolean)");
2703:            ////        }
2704:            ////        if((classes == null && beans == null) ||
2705:            ////                (classes != null && beans != null && beans.size() != classes.length)) {
2706:            ////            throw(new IllegalArgumentException("One of the classes array or beans list must not be null. If both are not null, than the length of them must be the same."));
2707:            ////        }
2708:            ////
2709:            ////        int dropType = DROP_DENIED;
2710:            ////        int n;
2711:            ////
2712:            ////        if (classes != null) {
2713:            ////            n = classes.length;
2714:            ////        } else {
2715:            ////            //the assert below would hide the NPE - better have NPE if not IllegalArgumentException
2716:            ////            //assert beans != null;
2717:            ////            n = beans.size();
2718:            ////        }
2719:            ////
2720:            ////        //the assertion below does not give anything (see the if above). 
2721:            ////        //assert (beans != null) || (classes != null);
2722:            ////        //the assertion below should be replaced by an if statement, so that the check happens even if
2723:            ////        //the asserions are turned off (see the if block above)
2724:            ////        //assert (beans == null) || (classes == null) || (beans.size() == classes.length);
2725:            ////
2726:            ////        for (int i = 0; i < n; i++) {
2727:            ////            ArrayList candidates = new ArrayList(n);
2728:            ////            Class clz;
2729:            ////            DesignBean lb = null;
2730:            ////
2731:            ////            if (beans != null) {
2732:            ////                lb = (DesignBean)beans.get(i);
2733:            ////            }
2734:            ////
2735:            ////            if (classes != null) {
2736:            ////                clz = classes[i];
2737:            ////            } else {
2738:            ////                clz = ((DesignBean)beans.get(i)).getInstance().getClass();
2739:            ////            }
2740:            ////
2741:            ////            try {
2742:            ////                // See if this new bean should be wired to the bean we
2743:            ////                // dropped on (or some container up the parent chain that
2744:            ////                // can handle the bean drop)
2745:            ////                DesignBean prev = null;
2746:            ////
2747:            ////                for (Element element = origElement; element != null; element = FacesSupport.getParent(element)) {
2748:            //////                    DesignBean droppee = element.getDesignBean();
2749:            ////                    DesignBean droppee = InSyncService.getProvider().getMarkupDesignBeanForElement(element);
2750:            ////
2751:            ////                    if (droppee == null) {
2752:            ////                        continue;
2753:            ////                    }
2754:            ////
2755:            //////                    MarkupMouseRegion region = element.getMarkupMouseRegion();
2756:            ////                    MarkupMouseRegion region = InSyncService.getProvider().getMarkupMouseRegionForElement(element);
2757:            ////
2758:            ////                    if ((region != null) && region.acceptLink(droppee, lb, clz)) {
2759:            ////                        if (!candidates.contains(element)) {
2760:            ////                            candidates.add(element);
2761:            ////                        }
2762:            ////                    }
2763:            ////
2764:            ////                    if (prev == droppee) {
2765:            ////                        continue;
2766:            ////                    }
2767:            ////
2768:            ////                    prev = droppee;
2769:            ////
2770:            ////                    DesignInfo dbi = droppee.getDesignInfo();
2771:            ////
2772:            ////                    if ((dbi != null) && dbi.acceptLink(droppee, lb, clz)) {
2773:            ////                        if (!candidates.contains(droppee) &&
2774:            ////                                ((beans == null) || !beans.contains(droppee))) {
2775:            ////                            candidates.add(droppee);
2776:            ////                        }
2777:            ////                    }
2778:            ////                }
2779:            ////            } catch (Exception e) {
2780:            ////                ErrorManager.getDefault().notify(e);
2781:            ////            }
2782:            ////
2783:            ////            if (candidates.size() == 0) {
2784:            ////                continue;
2785:            ////            }
2786:            ////
2787:            ////            dropType = DROP_LINKED;
2788:            ////
2789:            ////            // Store either the chosen DesignBean, or the chosen MarkupMouseRegion.
2790:            ////            // However, we'll need both the region and the corresponding bean, so
2791:            ////            // store the element instead which will point to both.
2792:            ////            Object selected = null;
2793:            ////
2794:            ////            if (selectFirst || (candidates.size() == 1)) {
2795:            ////                selected = candidates.get(0);
2796:            ////            } else {
2797:            ////                // Gotta ask the user
2798:            ////                // Code originally emitted by the form builder:
2799:            ////                JPanel panel = new JPanel(new GridBagLayout());
2800:            ////                GridBagConstraints gridBagConstraints;
2801:            ////                String labelDesc = NbBundle.getMessage(DndHandler.class, "ChooseTargetLabel"); // NOI18N
2802:            ////                JLabel label = new JLabel(labelDesc);
2803:            ////                gridBagConstraints = new GridBagConstraints();
2804:            ////                gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
2805:            ////                gridBagConstraints.insets = new Insets(12, 12, 11, 11);
2806:            ////                gridBagConstraints.anchor = GridBagConstraints.WEST;
2807:            ////                gridBagConstraints.weightx = 1.0;
2808:            ////                panel.add(label, gridBagConstraints);
2809:            ////
2810:            ////                ButtonGroup buttonGroup = new ButtonGroup();
2811:            ////
2812:            ////                // Iterate reverse order since list was generates from the leaf
2813:            ////                // up the parent chain, and I want to display outermost parents first
2814:            ////                for (int j = candidates.size() - 1; j >= 0; j--) {
2815:            ////                    String name = "";
2816:            ////                    Object next = candidates.get(j);
2817:            ////
2818:            ////                    if (next instanceof DesignBean) {
2819:            ////                        DesignBean dlb = (DesignBean)next;
2820:            ////                        name = dlb.getInstanceName();
2821:            ////
2822:            ////                        BeanInfo bi = dlb.getBeanInfo();
2823:            ////
2824:            ////                        if (bi != null) {
2825:            ////                            BeanDescriptor bd = bi.getBeanDescriptor();
2826:            ////
2827:            ////                            if (bd != null) {
2828:            ////                                String desc = bd.getShortDescription();
2829:            ////
2830:            ////                                if (desc == null) {
2831:            ////                                    desc = bd.getDisplayName();
2832:            ////
2833:            ////                                    if (desc == null) {
2834:            ////                                        desc = "";
2835:            ////                                    }
2836:            ////                                }
2837:            ////
2838:            ////                                name =
2839:            ////                                    NbBundle.getMessage(DndHandler.class, "TargetDescriptor", // NOI18N
2840:            ////                                        name, desc);
2841:            ////                            }
2842:            ////                        }
2843:            ////                    } else {
2844:            //////                        assert next instanceof RaveElement;
2845:            ////                        if (!(next instanceof Element)) {
2846:            ////                            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
2847:            ////                                    new IllegalStateException("Object is expected to be of Element type, object=" + next)); // NOI18N
2848:            ////                        }
2849:            ////
2850:            //////                        RaveElement element = (RaveElement)next;
2851:            //////                        MarkupMouseRegion region = element.getMarkupMouseRegion();
2852:            ////                        Element element = (Element)next;
2853:            ////                        MarkupMouseRegion region = InSyncService.getProvider().getMarkupMouseRegionForElement(element);
2854:            ////                        assert region != null;
2855:            ////
2856:            ////                        if ((region.getDescription() != null) &&
2857:            ////                                (region.getDescription().length() > 0)) {
2858:            ////                            name =
2859:            ////                                NbBundle.getMessage(DndHandler.class, "TargetDescriptor", // NOI18N
2860:            ////                                    region.getDisplayName(), region.getDescription());
2861:            ////                        } else {
2862:            ////                            name = region.getDisplayName();
2863:            ////                        }
2864:            ////                    }
2865:            ////
2866:            ////                    JRadioButton radioButton = new JRadioButton(name);
2867:            ////
2868:            ////                    if (j == (candidates.size() - 1)) {
2869:            ////                        radioButton.setSelected(true);
2870:            ////                    }
2871:            ////
2872:            ////                    radioButton.putClientProperty("liveBean", next); // NOI18N
2873:            ////                    buttonGroup.add(radioButton);
2874:            ////                    gridBagConstraints = new GridBagConstraints();
2875:            ////                    gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
2876:            ////                    gridBagConstraints.insets = new Insets(0, 12, 0, 11);
2877:            ////                    gridBagConstraints.anchor = GridBagConstraints.WEST;
2878:            ////                    panel.add(radioButton, gridBagConstraints);
2879:            ////                }
2880:            ////
2881:            ////                JPanel filler = new JPanel();
2882:            ////                gridBagConstraints = new GridBagConstraints();
2883:            ////                gridBagConstraints.weighty = 1.0;
2884:            ////                panel.add(filler, gridBagConstraints);
2885:            ////
2886:            ////                String title = NbBundle.getMessage(DndHandler.class, "ChooseTarget"); // NOI18N
2887:            ////                DialogDescriptor dlg =
2888:            ////                    new DialogDescriptor(panel, title, true, DialogDescriptor.OK_CANCEL_OPTION,
2889:            ////                        DialogDescriptor.OK_OPTION, DialogDescriptor.DEFAULT_ALIGN, 
2890:            ////                    // DialogDescriptor.BOTTOM_ALIGN,
2891:            ////                    null, //new HelpCtx("choose_target"), // NOI18N
2892:            ////                        null);
2893:            ////
2894:            ////                Dialog dialog = DialogDisplayer.getDefault().createDialog(dlg);
2895:            ////                dialog.show();
2896:            ////
2897:            ////                if (dlg.getValue().equals(DialogDescriptor.OK_OPTION)) {
2898:            ////                    Enumeration enm = buttonGroup.getElements();
2899:            ////
2900:            ////                    while (enm.hasMoreElements()) {
2901:            ////                        JRadioButton button = (JRadioButton)enm.nextElement();
2902:            ////
2903:            ////                        if (button.isSelected()) {
2904:            ////                            selected = button.getClientProperty("liveBean"); // NOI18N
2905:            ////
2906:            ////                            break;
2907:            ////                        }
2908:            ////                    }
2909:            ////                } // else: Cancel, or Esc: do nothing; selected will stay null
2910:            ////            }
2911:            ////
2912:            ////            if (showLinkTarget) {
2913:            ////                if (selected instanceof DesignBean) {
2914:            ////                    DesignBean droppee = (DesignBean)selected;
2915:            ////
2916:            ////                    if (droppee instanceof MarkupDesignBean) {
2917:            ////                        recentDropTarget = (MarkupDesignBean)droppee;
2918:            ////                        showDropMatch(recentDropTarget, null, DROP_LINKED);
2919:            ////                    }
2920:            ////                } else {
2921:            //////                    assert selected instanceof RaveElement;
2922:            ////                    if (!(selected instanceof Element)) {
2923:            ////                        ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
2924:            ////                                new IllegalStateException("Object is expected to be of Element type, object=" + selected)); // NOI18N
2925:            ////                    }
2926:            ////                    
2927:            ////
2928:            //////                    RaveElement element = (RaveElement)selected;
2929:            //////                    DesignBean droppee = element.getDesignBean();
2930:            ////                    Element element = (Element)selected;
2931:            ////                    DesignBean droppee = InSyncService.getProvider().getMarkupDesignBeanForElement(element);
2932:            ////
2933:            ////                    if (droppee instanceof MarkupDesignBean) {
2934:            ////                        recentDropTarget = (MarkupDesignBean)droppee;
2935:            //////                        showDropMatch(recentDropTarget, element.getMarkupMouseRegion(), DROP_LINKED);
2936:            ////                        showDropMatch(recentDropTarget,
2937:            ////                                InSyncService.getProvider().getMarkupMouseRegionForElement(element),
2938:            ////                                DROP_LINKED);
2939:            ////                    }
2940:            ////                }
2941:            ////            }
2942:            ////
2943:            ////            if ((selected == null) || !handleLinks || (beans == null)) {
2944:            ////                return dropType;
2945:            ////            }
2946:            ////
2947:            //////            Document document = webform.getDocument();
2948:            ////
2949:            ////            String description = NbBundle.getMessage(DndHandler.class, "LinkComponent"); // NOI18N
2950:            ////            UndoEvent undoEvent = webform.getModel().writeLock(description);
2951:            ////            try {
2952:            //////                String description = NbBundle.getMessage(DndHandler.class, "LinkComponent"); // NOI18N
2953:            //////                document.writeLock(description);
2954:            ////
2955:            ////                lb = (DesignBean)beans.get(i);
2956:            ////
2957:            ////                try {
2958:            ////                    // If you drop on an existing component, see if they
2959:            ////                    // can be wired together
2960:            ////                    // Try to bind the two together - for example, if you
2961:            ////                    // drop a RowSet on a bean that has a RowSet property,
2962:            ////                    // the RowSet property is bound to this particular
2963:            ////                    // RowSet.
2964:            ////                    if (selected instanceof DesignBean) {
2965:            ////                        DesignBean droppee = (DesignBean)selected;
2966:            ////                        assert droppee.getDesignInfo().acceptLink(droppee, lb,
2967:            ////                            lb.getInstance().getClass());
2968:            ////
2969:            ////                        MarkupDesignBean mbean = null;
2970:            ////
2971:            ////                        if (droppee instanceof MarkupDesignBean) {
2972:            ////                            // link beans might perform lots and lots of
2973:            ////                            // updates on the element - that's the case
2974:            ////                            // for the data grid when you bind a table
2975:            ////                            // to it for example.  So batch up all these
2976:            ////                            // modifications into a single change event
2977:            ////                            // on the top level element.
2978:            ////                            mbean = (MarkupDesignBean)droppee;
2979:            //////                            webform.getDomSynchronizer().setUpdatesSuspended(mbean, true);
2980:            ////                            webform.setUpdatesSuspended(mbean, true);
2981:            ////                        }
2982:            ////
2983:            ////                        try {
2984:            ////                            webform.getModel().linkBeans(droppee, lb);
2985:            ////                        } finally {
2986:            ////                            if (mbean != null) {
2987:            ////                                // Process queued up changes
2988:            //////                                webform.getDomSynchronizer().setUpdatesSuspended(mbean, false);
2989:            ////                                webform.setUpdatesSuspended(mbean, false);
2990:            ////                            }
2991:            ////                        }
2992:            ////
2993:            ////                        // The target bean should be selected instead of
2994:            ////                        // the droppee!
2995:            ////                        select = droppee;
2996:            ////                    } else {
2997:            //////                        assert selected instanceof RaveElement;
2998:            ////                        if (!(selected instanceof Element)) {
2999:            ////                            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
3000:            ////                                    new IllegalStateException("Object is expected to be of Element type, object=" + selected)); // NOI18N
3001:            ////                        }
3002:            ////
3003:            //////                        RaveElement element = (RaveElement)selected;
3004:            //////                        MarkupMouseRegion region = element.getMarkupMouseRegion();
3005:            ////                        Element element = (Element)selected;
3006:            ////                        MarkupMouseRegion region = InSyncService.getProvider().getMarkupMouseRegionForElement(element);
3007:            ////                        assert region != null;
3008:            ////
3009:            //////                        DesignBean droppee = element.getDesignBean();
3010:            ////                        DesignBean droppee = InSyncService.getProvider().getMarkupDesignBeanForElement(element);
3011:            ////                        assert droppee != null;
3012:            ////                        assert region.acceptLink(droppee, lb, clz);
3013:            ////
3014:            ////                        MarkupDesignBean mbean = null;
3015:            ////
3016:            ////                        if (droppee instanceof MarkupDesignBean) {
3017:            ////                            mbean = (MarkupDesignBean)droppee;
3018:            //////                            webform.getDomSynchronizer().setUpdatesSuspended(mbean, true);
3019:            ////                            webform.setUpdatesSuspended(mbean, true);
3020:            ////                        }
3021:            ////
3022:            ////                        try {
3023:            ////                            Result r = region.linkBeans(droppee, lb);
3024:            ////                            ResultHandler.handleResult(r, webform.getModel());
3025:            ////                        } finally {
3026:            ////                            if (mbean != null) {
3027:            //////                                webform.getDomSynchronizer().setUpdatesSuspended(mbean, false);
3028:            ////                                webform.setUpdatesSuspended(mbean, false);
3029:            ////                            }
3030:            ////                        }
3031:            ////                    }
3032:            ////                } catch (Exception e) {
3033:            ////                    ErrorManager.getDefault().notify(e);
3034:            ////                }
3035:            ////            } finally {
3036:            //////                document.writeUnlock();
3037:            ////                webform.getModel().writeUnlock(undoEvent);
3038:            ////            }
3039:            ////        }
3040:            ////
3041:            ////        return dropType;
3042:            //        
3043:            ////        return webform.processLinks(origElement, classes, beans, selectFirst, handleLinks, showLinkTarget);
3044:            //        return webform.processLinks(origElement, classes, componentRootElement, selectFirst, handleLinks, showLinkTarget);
3045:            //    }
3046:
3047:            //    /** Set the absolute position of the component. **/
3048:            //    private void positionBean(MarkupDesignBean lb, DesignBean origParent, Element element,
3049:            //    Location location, CoordinateTranslator coordinateTranslator) {
3050:            //        // TODO - transfer this logic to computePositions
3051:            //        if ((location.coordinates == null) || (element == null)) {
3052:            //            return;
3053:            //        }
3054:            //
3055:            //        DesignBean parent = origParent;
3056:            //
3057:            //        // Only position beans dropped on a grid area or a form
3058:            //        boolean grid = false;
3059:            //
3060:            //        // XXX TODO: transfer this logic into Utilities instead and make
3061:            //        // sure we do it the same way everywhere!
3062:            //        if (element.getParentNode() instanceof Element) {
3063:            //            Element pe = (Element)element.getParentNode();
3064:            //
3065:            //            if (pe.getTagName().equals(HtmlTag.FSUBVIEW.name) &&
3066:            //                    pe.getParentNode() instanceof Element) {
3067:            //                pe = (Element)pe.getParentNode();
3068:            //            }
3069:            //
3070:            //            // The component may -render- a -rave-layout setting,
3071:            //            // so look in the rendered HTML for the layout setting
3072:            //            // rather than in the JSP DOM
3073:            ////            RaveElement rendered = ((RaveElement)pe).getRendered();
3074:            //            Element rendered = MarkupService.getRenderedElementForElement(pe);
3075:            //            if (rendered != null) {
3076:            //                pe = rendered;
3077:            //            }
3078:            //
3079:            ////            Value val = CssLookup.getValue(pe, XhtmlCss.RAVELAYOUT_INDEX);
3080:            //            CssValue cssValue = CssProvider.getEngineService().getComputedValueForElement(pe, XhtmlCss.RAVELAYOUT_INDEX);
3081:            //
3082:            ////            if (val == CssValueConstants.GRID_VALUE) {
3083:            //            if (CssProvider.getValueService().isGridValue(cssValue)) {
3084:            //                grid = true;
3085:            //            } else if (pe.getTagName().endsWith(HtmlTag.FORM.name)) { // h:form too
3086:            //                pe = (Element)pe.getParentNode();
3087:            ////                val = CssLookup.getValue(pe, XhtmlCss.RAVELAYOUT_INDEX);
3088:            //                CssValue cssValue2 = CssProvider.getEngineService().getComputedValueForElement(pe, XhtmlCss.RAVELAYOUT_INDEX);
3089:            //
3090:            ////                if (val == CssValueConstants.GRID_VALUE) {
3091:            //                if (CssProvider.getValueService().isGridValue(cssValue2)) {
3092:            //                    grid = true;
3093:            //                }
3094:            //            }
3095:            //        }
3096:            //
3097:            //        if (((parent == null) || grid || FacesSupport.isFormBean(webform, parent))) {
3098:            ////            GridHandler gm = GridHandler.getInstance();
3099:            //            setInitialPosition(webform, lb, element, location.coordinates, location.size, coordinateTranslator);
3100:            //            select = lb;
3101:            //        }
3102:            //    }
3103:
3104:            //    /**
3105:            //     * Set the initial position for a given component.
3106:            //     * It is assumed that the bean does not already have an associated position.
3107:            //     *
3108:            //     * @param editor The designer pane containing the element
3109:            //     * @param element The element we want to set a style attribute for
3110:            //     * @param pos The point where we want the element positioned. If null,
3111:            //     *              this method has no effect.
3112:            //     * @param size The size to assign to the component. If null, don't set a
3113:            //     *              size, use the intrinsic size.
3114:            //     */
3115:            //    private static void setInitialPosition(WebForm webform, MarkupDesignBean bean, Element element, Point pos, Dimension size,
3116:            //    CoordinateTranslator coordinateTranslator) {
3117:            //        if (pos == null) {
3118:            //            return;
3119:            //        }
3120:            //
3121:            //        DesignProperty styleProp = bean.getProperty("style"); // NOI18N
3122:            //
3123:            //        if (styleProp == null) {
3124:            //            // No style property - can't set position!!
3125:            //            return;
3126:            //        }
3127:            //
3128:            //        String style = (String)styleProp.getValue();
3129:            //        StringBuffer sb = new StringBuffer();
3130:            //
3131:            //        if ((style != null) && (style.length() > 0)) {
3132:            //            sb.append(style);
3133:            //            sb.append("; ");
3134:            //        }
3135:            //
3136:            //        // Locate a grid layout parent
3137:            ////        Document doc = editor.getDocument();
3138:            ////        WebForm webform = doc.getWebForm();
3139:            ////        XhtmlCssEngine engine = webform.getMarkup().getCssEngine();
3140:            //
3141:            //        // This model should already be locked when we attempt to do this
3142:            //        assert webform.getModel().isWriteLocked();
3143:            //
3144:            //        int x = pos.x;
3145:            //        int y = pos.y;
3146:            //
3147:            ////        GridHandler gridHandler = GridHandler.getInstance();
3148:            //        // See if we should translate the coordinates
3149:            //        if (element.getParentNode() instanceof Element) {
3150:            //            Element parent = (Element)element.getParentNode();
3151:            ////            CssBox parentBox = CssBox.getBox(parent);
3152:            ////
3153:            ////            if (parentBox != null) {
3154:            ////                // Translate coordinates from absolute/viewport
3155:            ////                // to absolute coordinates relative to the target
3156:            ////                // grid container
3157:            //////                Point p = translateCoordinates(parentBox, x, y);
3158:            ////                Point p = gridHandler.translateCoordinates(parentBox, x, y);
3159:            ////                x = p.x;
3160:            ////                y = p.y;
3161:            ////            }
3162:            ////            Point point = gridHandler.translateCoordinates(parent, x, y);
3163:            //            Point point = coordinateTranslator.translateCoordinates(parent, x, y);
3164:            //            if (point != null) {
3165:            //                x = point.x;
3166:            //                y = point.y;
3167:            //            }
3168:            //        }
3169:            //
3170:            ////        x = snapX(x);
3171:            ////        y = snapY(y);
3172:            ////        x = gridHandler.snapX(x);
3173:            ////        y = gridHandler.snapY(y);
3174:            //        x = coordinateTranslator.snapX(x);
3175:            //        y = coordinateTranslator.snapY(y);
3176:            //
3177:            //        // prevent multiple updates for the same element - only need a single refresh
3178:            //        try {
3179:            ////            webform.getDomSynchronizer().setUpdatesSuspended(bean, true);
3180:            //            webform.setUpdatesSuspended(bean, true);
3181:            //
3182:            //            // TODO: Find the -rendered- element; I have to look up margins on it
3183:            //            // since it could come from style classes. For example, for a Braveheart
3184:            //            // button, if I have a CSS rule   .Btn2 { margin: 200px }  I won't find
3185:            //            // this style looking at the JSP element (ui:button) I need to do lookup
3186:            //            // on the rendered <input class="Btn2" ...> element.
3187:            //            // The "top" and "left" properties are relative to the margin edge of the
3188:            //            // component yet the position is specified relative to the border (visible) area
3189:            ////            int leftMargin = CssLookup.getLength(element, XhtmlCss.MARGIN_LEFT_INDEX);
3190:            ////            int topMargin = CssLookup.getLength(element, XhtmlCss.MARGIN_TOP_INDEX);
3191:            //            int leftMargin = CssBox.getCssLength(element, XhtmlCss.MARGIN_LEFT_INDEX);
3192:            //            int topMargin = CssBox.getCssLength(element, XhtmlCss.MARGIN_TOP_INDEX);
3193:            //            x -= leftMargin;
3194:            //            y -= topMargin;
3195:            //
3196:            //            List set = new ArrayList(5);
3197:            //            List remove = new ArrayList(3);
3198:            //
3199:            //            sb.append("position: absolute; ");
3200:            //            sb.append("left: ");
3201:            //            sb.append(Integer.toString(x));
3202:            //            sb.append("px; ");
3203:            //            sb.append("top: ");
3204:            //            sb.append(Integer.toString(y));
3205:            //            sb.append("px");
3206:            //
3207:            //            if (size != null) {
3208:            //                if (!setDesignProperty(bean, HtmlAttribute.WIDTH, size.width)) {
3209:            //                    sb.append("; width: ");
3210:            //                    sb.append(Integer.toString(size.width));
3211:            //                    sb.append("px"); // NOI18N
3212:            //                } else {
3213:            //                    // Do I need to try to delete the width from the existing value string?
3214:            //                    // The only way this could get here is if the component has had a chance
3215:            //                    // to set widths/sizes with the create customizers
3216:            //                }
3217:            //
3218:            //                if (!setDesignProperty(bean, HtmlAttribute.HEIGHT, size.height)) {
3219:            //                    sb.append("; height: ");
3220:            //                    sb.append(Integer.toString(size.height));
3221:            //                    sb.append("px"); // NOI18N
3222:            //                } else {
3223:            //                    // Do I need to try to delete the width from the existing value string?
3224:            //                    // The only way this could get here is if the component has had a chance
3225:            //                    // to set widths/sizes with the create customizers
3226:            //                }
3227:            //            }
3228:            //
3229:            //            styleProp.setValue(sb.toString());
3230:            //        } finally {
3231:            ////            webform.getDomSynchronizer().setUpdatesSuspended(bean, false);
3232:            //            webform.setUpdatesSuspended(bean, false);
3233:            //        }
3234:            //    }
3235:
3236:            //    /** Attempt to set the given attribute on the bean to the given length
3237:            //     * and return true iff it succeeds.
3238:            //     */
3239:            //    public /*private*/ static boolean setDesignProperty(DesignBean bean, String attribute, int length, WebForm webform) {
3240:            ////        DesignProperty prop = bean.getProperty(attribute);
3241:            ////
3242:            ////        if (prop != null) {
3243:            ////            PropertyDescriptor desc = prop.getPropertyDescriptor();
3244:            ////            Class clz = desc.getPropertyType();
3245:            ////
3246:            ////            // I can do == instead of isAssignableFrom because
3247:            ////            // both String and Integer are final!
3248:            ////            if (clz == String.class) {
3249:            ////                prop.setValue(Integer.toString(length));
3250:            ////
3251:            ////                return true;
3252:            ////            } else if (clz == Integer.TYPE) {
3253:            ////                prop.setValue(new Integer(length));
3254:            ////
3255:            ////                return true;
3256:            ////            }
3257:            ////        }
3258:            ////
3259:            ////        return false;
3260:            //        return Util.setDesignProperty(bean, attribute, length);
3261:            //    }
3262:
3263:            //    void customizeCreation(List beans) {
3264:            ////        int n = beans.size();
3265:            ////
3266:            ////        for (int i = 0; i < n; i++) {
3267:            ////            DesignBean lb = (DesignBean)beans.get(i);
3268:            ////            DesignInfo lbi = lb.getDesignInfo();
3269:            ////
3270:            ////            if (lbi != null) {
3271:            ////                Customizer2 customizer = null; //lbi.getCreateCustomizer(lb);
3272:            ////
3273:            ////                if (customizer != null) {
3274:            ////                    CustomizerDisplayer lcd =
3275:            ////                        new CustomizerDisplayer(lb, customizer, customizer.getHelpKey(),
3276:            ////                            webform.getModel());
3277:            ////                    lcd.show();
3278:            ////                }
3279:            ////            }
3280:            ////        }
3281:            //    }
3282:
3283:            /**
3284:             * Return the target parent or link-handler computed for the most recent
3285:             * getDropType call. Be careful. This must be called after getDropType()
3286:             * and the result will be clobbered as soon as additional getDropType
3287:             * requests come in (which they often do from the mouse motion listener!)
3288:             */
3289:            //    MarkupDesignBean getRecentDropTarget() {
3290:            //        return recentDropTarget;
3291:            Element getRecentDropTargetComponentRootElement() {
3292:                //        return recentDropTargetComponentRootElement;
3293:                return recentDropTargetComponentRootElementWRef.get();
3294:            }
3295:
3296:            /** Compute the list of class names for beans identified by the given palette item transferable */
3297:            public int getDropType(Point p, Transferable t, boolean linkOnly) {
3298:                if (t == null) {
3299:                    return DROP_DENIED;
3300:                }
3301:
3302:                CssBox box = ModelViewMapper.findBox(webform.getPane()
3303:                        .getPageBox(), p.x, p.y);
3304:                //        DesignBean origDroppee = getDroppee(box);
3305:                Element origDropeeComponentRootElement = getDropeeComponent(box);
3306:                Element droppeeElement = box == null ? null : box.getElement();
3307:
3308:                //        DataFlavor importFlavor = getImportFlavor(t.getTransferDataFlavors());
3309:                //
3310:                //        if (importFlavor == null) {
3311:                //            DataFlavor[] flavors = t.getTransferDataFlavors();
3312:                //            ErrorManager.getDefault().log("Unusable transfer, data flavors="
3313:                //                    + (flavors == null ? null : java.util.Arrays.asList(t.getTransferDataFlavors()))); // NOI18N
3314:                //
3315:                //            return DROP_DENIED;
3316:                //        }
3317:                //
3318:                //        Class rc = importFlavor.getRepresentationClass();
3319:                //
3320:                //        if (rc == DisplayItem.class) {
3321:                //            // Create a new type
3322:                //            try {
3323:                //                Object transferData = t.getTransferData(importFlavor);
3324:                //
3325:                //                if (!(transferData instanceof DisplayItem)) {
3326:                //                    ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, 
3327:                //                            new IllegalStateException("Invalid transferData=" + transferData // NOI18N
3328:                //                            + ", from transferable=" + t)); // NOI18N
3329:                //                    return DROP_DENIED;
3330:                //                }
3331:                //
3332:                //                DisplayItem item = (DisplayItem)transferData;
3333:                //
3334:                //                return getDropTypeForDisplayItem(origDroppee, droppeeElement, item, linkOnly);
3335:                //            } catch (UnsupportedFlavorException ex) {
3336:                //                ErrorManager.getDefault().notify(ex);
3337:                //
3338:                //                return DROP_DENIED;
3339:                //            } catch (java.io.IOException ex) {
3340:                //                ErrorManager.getDefault().notify(ex);
3341:                //
3342:                //                return DROP_DENIED;
3343:                //            }
3344:                //        } else if (rc == DesignBean.class) {
3345:                //            try {
3346:                //                Object transferData = t.getTransferData(importFlavor);
3347:                //
3348:                //                if (!(transferData instanceof DesignBean[])) {
3349:                //                    ErrorManager.getDefault().log("Invalid DesignBean[] transfer data: " +
3350:                //                        transferData);
3351:                //
3352:                //                    return DROP_DENIED;
3353:                //                }
3354:                //
3355:                //                DesignBean[] beans = (DesignBean[])transferData;
3356:                //
3357:                //                String[] classNames = new String[beans.length];
3358:                //
3359:                //                for (int i = 0, n = beans.length; i < n; i++) {
3360:                //                    classNames[i] = beans[i].getInstance().getClass().getName();
3361:                //                }
3362:                //
3363:                //                return getDropTypeForClassNames(origDroppee, droppeeElement, classNames, null, linkOnly);
3364:                //            } catch (UnsupportedFlavorException ex) {
3365:                //                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
3366:                //                return DROP_DENIED;
3367:                //            } catch (java.io.IOException ex) {
3368:                //                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
3369:                //                return DROP_DENIED;
3370:                //            }
3371:                //        }
3372:                //        
3373:                //        // XXX TEMP First give the chance to the provider.
3374:                //        // FIXME This shouldn't be here at all, the original transferable
3375:                //        // should contain all the needed flavors.
3376:                //        DesignTimeTransferDataCreator dataCreator = (DesignTimeTransferDataCreator)Lookup.getDefault().lookup(DesignTimeTransferDataCreator.class);
3377:                //        if (dataCreator != null) {
3378:                //            DisplayItem displayItem = dataCreator.getDisplayItem(t);
3379:                //            if (displayItem != null) {
3380:                //                return getDropTypeForDisplayItem(origDroppee, droppeeElement, displayItem, linkOnly);
3381:                //            }
3382:                //        }
3383:                //        
3384:                //        // XXX The other hacked transferables.
3385:                //        if (rc == String.class/*Linux*/ || rc == List.class/*Windows/Solaris*/) {
3386:                //            // XXX #6468896 To be able to drop files (images) from the outside world (desktop).
3387:                //           return DROP_PARENTED;
3388:                //        } else if (rc == org.openide.nodes.Node.class) {
3389:                //            // XXX #6482097 Reflecting the impl in FacesDnDSupport.
3390:                //            // FIXME Later the impl has to be improved and moved over there.
3391:                //            Object transferData;
3392:                //            try {
3393:                //                transferData = t.getTransferData(importFlavor);
3394:                //                if (transferData instanceof org.openide.nodes.Node) {
3395:                //                    org.openide.nodes.Node node = (org.openide.nodes.Node)transferData;
3396:                //                    DataObject dobj = (DataObject)node.getCookie(DataObject.class);
3397:                //
3398:                //                    if (dobj != null) {
3399:                //                        FileObject fo = dobj.getPrimaryFile();
3400:                //                        if (isImage(fo.getExt())) {
3401:                ////                            String className;
3402:                ////                            // XXX This should be decided by the parent bean.
3403:                ////                            // I.e. appropriate api is missing.
3404:                ////                            // XXX This shouldn't be here resolved, but in the parent bean.
3405:                ////                            if (webform.isBraveheartPage()) {
3406:                ////                                className = com.sun.rave.web.ui.component.ImageComponent.class.getName(); // NOI18N
3407:                ////                            } else if (webform.isWoodstockPage()) {
3408:                ////                                // Use woodstock ImageComponent component
3409:                ////                                className = com.sun.webui.jsf.component.ImageComponent.class.getName(); // NOI18N
3410:                ////                            } else {
3411:                ////                                className = javax.faces.component.html.HtmlGraphicImage.class.getName(); // NOI18N
3412:                ////                            }
3413:                //                            String className = webform.getImageComponentClassName();
3414:                //                            
3415:                //                            String[] classNames = new String[] {className};
3416:                //
3417:                //                            return getDropTypeForClassNames(origDroppee, droppeeElement, classNames, null, linkOnly);
3418:                //                        } else if (isStylesheet(fo.getExt())) {
3419:                //                            return DROP_PARENTED;
3420:                //                        }
3421:                //                    }
3422:                //                }
3423:                //            } catch (IOException ex) {
3424:                //                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
3425:                //            } catch (UnsupportedFlavorException ex) {
3426:                //                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
3427:                //            }
3428:                //            return DROP_DENIED;
3429:                //        }
3430:                //
3431:                //        return DROP_DENIED;
3432:                return webform.getDropType(
3433:                        /*origDroppee,*/origDropeeComponentRootElement,
3434:                        droppeeElement, t, linkOnly);
3435:            }
3436:
3437:            //    // XXX Also in insync/FacesDnDSupport
3438:            //    /** Return true if the extension indicates that this is an image */
3439:            //    private static boolean isImage(String extension) {
3440:            //        return (extension.equalsIgnoreCase("jpg") || // NOI18N
3441:            //                extension.equalsIgnoreCase("gif") || // NOI18N
3442:            //                extension.equalsIgnoreCase("png") || // NOI18N
3443:            //                extension.equalsIgnoreCase("jpeg")); // NOI18N
3444:            //    }
3445:
3446:            //    // XXX Also in insync/FacesDnDSupport.
3447:            //    private static boolean isStylesheet(String extension) {
3448:            //        return extension.equalsIgnoreCase("css"); // NOI18N
3449:            //    }
3450:
3451:            //    /**
3452:            //     * Decide whether or not we can drop the given palette item
3453:            //     * at the given position.
3454:            //     * XXX TODO get rid of this method from the designer, it is JSF specific..
3455:            //     */
3456:            ////    private int getDropTypeForDisplayItem(Point p, DisplayItem item, boolean linkOnly) {
3457:            //    private int getDropTypeForDisplayItem(DesignBean origDroppee, Element droppeeElement, DisplayItem item, boolean linkOnly) {
3458:            //        if(item == null) {
3459:            //            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, 
3460:            //                    new NullPointerException("Item is null")); // NOI18N
3461:            //            return DROP_DENIED;
3462:            //        } 
3463:            //        
3464:            ////        String[] classNames = getClasses(new DisplayItem[] { item });
3465:            //        String[] classNames = webform.getClassNames(new DisplayItem[] {item});
3466:            //
3467:            //        return getDropTypeForClassNames(origDroppee, droppeeElement, classNames, null, linkOnly);
3468:            //    }
3469:
3470:            /**
3471:             * We have a potential drop match on the given bean - show it as selected.
3472:             */
3473:            //    public void showDropMatch(MarkupDesignBean bean, MarkupMouseRegion region, int type) {
3474:            public void showDropMatch(Element componentRootElement,
3475:                    Element regionElement, int type) {
3476:                //        recentDropTarget = bean;
3477:                //        recentDropTargetComponentRootElement = componentRootElement;
3478:                recentDropTargetComponentRootElementWRef = new WeakReference<Element>(
3479:                        componentRootElement);
3480:
3481:                //        if (DONT_SHOW_MATCHES || ((currentMatched == bean) && (currentRegion == region))) {
3482:                if (DONT_SHOW_MATCHES
3483:                        || ((currentMatchedComponentRootElement == componentRootElement) && (currentRegionElement == regionElement))) {
3484:                    return;
3485:                }
3486:
3487:                //        currentMatched = bean;
3488:                currentMatchedComponentRootElement = componentRootElement;
3489:                //        currentRegion = region;
3490:                currentRegionElement = regionElement;
3491:
3492:                //        if (region != null) {
3493:                if (regionElement != null) {
3494:                    // Regions only support linking, not parenting
3495:                    assert type == DROP_LINKED;
3496:                    //            webform.getManager().highlight(bean, region);
3497:                    webform.getManager().highlight(componentRootElement,
3498:                            regionElement);
3499:                    //            lastMessage =
3500:                    //                NbBundle.getMessage(DndHandler.class, "LinkTarget", region.getDisplayName());
3501:                    lastMessage = NbBundle.getMessage(DndHandler.class,
3502:                            "LinkTarget", webform.getDomProviderService()
3503:                                    .getRegionDisplayName(regionElement));
3504:
3505:                    StatusDisplayer.getDefault().setStatusText(lastMessage);
3506:                    //        } else if (bean != null) {
3507:                } else if (componentRootElement != null) {
3508:                    //            FacesPageUnit facesUnit = webform.getModel().getFacesUnit();
3509:                    //
3510:                    //            if ((facesUnit == null) ||
3511:                    ////                    ((facesUnit.getDefaultParent() != FacesSupport.getMarkupBean(bean)) &&
3512:                    //                    ((facesUnit.getDefaultParent() != Util.getMarkupBean(bean)) &&
3513:                    //                    
3514:                    ////                    (bean.getElement() != webform.getBody().getSourceElement()))) {
3515:                    //                    (bean.getElement() != MarkupService.getSourceElementForElement(webform.getHtmlBody())))) {
3516:                    //            if (webform.canHighlightMarkupDesignBean(bean)) {
3517:                    //                webform.getManager().highlight(bean, null);
3518:                    if (webform
3519:                            .canHighlightComponentRootElement(componentRootElement)) {
3520:                        webform.getManager().highlight(componentRootElement,
3521:                                null);
3522:                    } else {
3523:                        webform.getManager().highlight(null, null);
3524:                    }
3525:
3526:                    if (type == DROP_LINKED) {
3527:                        lastMessage =
3528:                        //                    NbBundle.getMessage(DndHandler.class, "LinkTarget", bean.getInstanceName());
3529:                        NbBundle.getMessage(DndHandler.class, "LinkTarget",
3530:                                webform.getDomProviderService()
3531:                                        .getInstanceName(componentRootElement));
3532:                        StatusDisplayer.getDefault().setStatusText(lastMessage);
3533:                    } else if (type == DROP_PARENTED) {
3534:                        lastMessage =
3535:                        //                    NbBundle.getMessage(DndHandler.class, "ParentTarget", bean.getInstanceName());
3536:                        NbBundle.getMessage(DndHandler.class, "ParentTarget",
3537:                                webform.getDomProviderService()
3538:                                        .getInstanceName(componentRootElement));
3539:                        StatusDisplayer.getDefault().setStatusText(lastMessage);
3540:                    } else {
3541:                        assert false : type;
3542:                    }
3543:                } else {
3544:                    clearDropMatch();
3545:                }
3546:            }
3547:
3548:            public void clearDropMatch() {
3549:                //        currentMatched = null;
3550:                currentMatchedComponentRootElement = null;
3551:                webform.getManager().highlight(null, null);
3552:
3553:                if (StatusDisplayer.getDefault().getStatusText() == lastMessage) {
3554:                    StatusDisplayer.getDefault().setStatusText("");
3555:                }
3556:
3557:                lastMessage = null;
3558:            }
3559:
3560:            //    /** Get rid of this method from designer. */
3561:            //    public int getDropTypeForClassNamesEx(Point p, String[] classNames, DesignBean[] beans, boolean linkOnly) {
3562:            public int getDropTypeForComponent(Point p,
3563:                    Element componentRootElement, boolean linkOnly) {
3564:                if (p == null) {
3565:                    throw (new IllegalArgumentException("Null drop point."));
3566:                }
3567:                // No... call computePositions and use location.coordinates instead... see @todo above
3568:                //        CssBox box = webform.getMapper().findBox(p.x, p.y);
3569:                CssBox box = ModelViewMapper.findBox(webform.getPane()
3570:                        .getPageBox(), p.x, p.y);
3571:                //        DesignBean origDroppee = getDroppee(box);
3572:                Element origDropeeComponentRootElement = getDropeeComponent(box);
3573:                Element droppeeElement = box == null ? null : box.getElement();
3574:                //        return webform.getDropTypeForClassNames(origDroppee, droppeeElement, classNames, beans, linkOnly);
3575:                return webform.getDropTypeForComponent(
3576:                        /*origDroppee,*/origDropeeComponentRootElement,
3577:                        droppeeElement, componentRootElement, linkOnly);
3578:            }
3579:
3580:            //    /**
3581:            //     * Decide whether or not we can drop the given palette item at the given position.
3582:            //    * @todo implement using computeActions and computePosition instead of custom solution here... e.g.
3583:            //     <pre>
3584:            //    public int getDropType(Point p, String[] classNames, boolean linkOnly) {
3585:            //        int allowed = computeActions(dropNode, t, false, nodePos);
3586:            //        if (allowed == DnDConstants.ACTION_NONE) {
3587:            //            return;
3588:            //        }
3589:            //        if (dropAction == DnDConstants.ACTION_COPY) {
3590:            //        ... XXX call computeActions
3591:            //    }
3592:            //     </pre>
3593:            //     * XXX TODO get rid of this method from the designer, it is JSF specific.
3594:            //    */
3595:            //    private int getDropTypeForClassNames(DesignBean origDroppee, Element droppeeElement, String[] classNames, DesignBean[] beans, boolean linkOnly) {
3596:            //        if(DesignerUtils.DEBUG) {
3597:            //            DesignerUtils.debugLog(getClass().getName() + ".getDropType(Point, PaletteItem, boolean)");
3598:            //        }
3599:            ////        if(p == null) {
3600:            ////            throw(new IllegalArgumentException("Null drop point."));
3601:            ////        }
3602:            //        if(classNames == null) {
3603:            //            throw(new IllegalArgumentException("Null class names array."));
3604:            //        }
3605:            //
3606:            //        recentDropTarget = null;
3607:            //
3608:            ////        // No... call computePositions and use location.coordinates instead... see @todo above
3609:            //////        CssBox box = webform.getMapper().findBox(p.x, p.y);
3610:            ////        CssBox box = ModelViewMapper.findBox(webform.getPane().getPageBox(), p.x, p.y);
3611:            ////        DesignBean origDroppee = getDroppee(box);
3612:            //
3613:            //        if (origDroppee == null) {
3614:            //            if (linkOnly) {
3615:            //                return DROP_DENIED;
3616:            //            }
3617:            //
3618:            ////            if (origDroppee instanceof MarkupDesignBean) {
3619:            ////                recentDropTarget = (MarkupDesignBean)origDroppee;
3620:            ////            }
3621:            //
3622:            ////            LiveUnit unit = webform.getModel().getLiveUnit();
3623:            //
3624:            ////            if (unit != null) {
3625:            //                for (int i = 0; i < classNames.length; i++) {
3626:            //                    // Do anything smart about facets here? E.g. what if you
3627:            //                    // point over a facet table header? A drop in the app outline
3628:            //                    // would offer to replace it. Should the interactive link feedback
3629:            //                    // allow this too?
3630:            ////                    if (unit.canCreateBean(classNames[i], null, null)) {
3631:            //                    if (webform.canCreateBean(classNames[i], null, null)) {
3632:            //                        showDropMatch(null, null, DROP_PARENTED);
3633:            //
3634:            //                        return DROP_PARENTED;
3635:            //                    }
3636:            //                }
3637:            ////            }
3638:            //
3639:            //            clearDropMatch();
3640:            //
3641:            //            return DROP_DENIED;
3642:            //        }
3643:            //
3644:            //        // None of the droppee ancestors accepted the drop items
3645:            //        // as a potential child - but perhaps they will accept
3646:            //        // a link?
3647:            ////        Class[] classes = new Class[classNames.length];
3648:            ////        ArrayList beanList = null;
3649:            ////
3650:            ////        if (beans != null) {
3651:            ////            beanList = new ArrayList(beans.length);
3652:            ////        }
3653:            ////
3654:            ////        for (int i = 0; i < classNames.length; i++) {
3655:            ////            try {
3656:            ////                Class clz = webform.getModel().getFacesUnit().getBeanClass(classNames[i]);
3657:            ////
3658:            ////                if (clz != null) {
3659:            ////                    classes[i] = clz;
3660:            ////                }
3661:            ////
3662:            ////                if (beans != null) {
3663:            ////                    beanList.add(beans[i]);
3664:            ////                }
3665:            ////            } catch (Exception e) {
3666:            ////                ErrorManager.getDefault().notify(e);
3667:            ////            }
3668:            ////        }
3669:            ////        
3670:            ////        if (beans == null) {
3671:            ////            beanList = null;
3672:            ////        }
3673:            //        List<Class> classList = new ArrayList<Class>();
3674:            //        List<DesignBean> beanList = beans == null ? null : new ArrayList<DesignBean>();
3675:            //        for (int i = 0; i < classNames.length; i++) {
3676:            //            try {
3677:            ////                Class clazz = webform.getModel().getFacesUnit().getBeanClass(classNames[i]);
3678:            //                Class clazz = webform.getBeanClass(classNames[i]);
3679:            //                if (clazz != null) {
3680:            //                    classList.add(clazz);
3681:            //                }
3682:            //                if (beans != null) {
3683:            //                    beanList.add(beans[i]);
3684:            //                }
3685:            //            } catch (ClassNotFoundException ex) {
3686:            //                // XXX #6492649 It means the class can't be found so no drop should happen.
3687:            //                // FIXME The API should be improved and not controlled via exceptions.
3688:            //                continue;
3689:            //            } catch (Exception ex) {
3690:            //                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
3691:            //                continue;
3692:            //            }
3693:            //        }
3694:            //        Class[] classes = classList.toArray(new Class[classList.size()]);
3695:            //
3696:            ////        RaveElement droppeeElement = (RaveElement)box.getElement();
3697:            ////        Element droppeeElement = box.getElement();
3698:            //        
3699:            //        int dropType = processLinks(droppeeElement, classes, beanList, true, false, true);
3700:            //
3701:            //        if (dropType != DROP_DENIED) {
3702:            //            return dropType;
3703:            //        }
3704:            //
3705:            //        if (linkOnly) {
3706:            //            clearDropMatch();
3707:            //
3708:            //            return DROP_DENIED;
3709:            //        }
3710:            //
3711:            //        // See if any of the droppee parents accept the new item as a
3712:            //        // child
3713:            //        for (int i = 0; i < classNames.length; i++) {
3714:            //            Node parentNode = null; // XXX todo figure out better parent node
3715:            ////            DesignBean parent = findParent(classNames[i], origDroppee, parentNode, true);
3716:            //            DesignBean parent = webform.findParent(classNames[i], origDroppee, parentNode, true);
3717:            //
3718:            //            if (parent != null) {
3719:            //                if (parent instanceof MarkupDesignBean) {
3720:            //                    recentDropTarget = (MarkupDesignBean)parent;
3721:            //                    showDropMatch(recentDropTarget, null, DROP_PARENTED);
3722:            //                } else {
3723:            //                    clearDropMatch();
3724:            //                }
3725:            //
3726:            //                return DROP_PARENTED;
3727:            //            }
3728:            //        }
3729:            //
3730:            //        showDropMatch(null, null, DROP_DENIED);
3731:            //
3732:            //        return DROP_DENIED;
3733:            //    }
3734:
3735:            //    /**
3736:            //     * Try to find a flavor that can be used to import a Transferable.
3737:            //     * The set of usable flavors are tried in the following order:
3738:            //     * <ol>
3739:            //     *     <li>First, an attempt is made to find a flavor matching the content type
3740:            //     *         of the EditorKit for the component.
3741:            //     *     <li>Second, an attempt to find a text/plain flavor is made.
3742:            //     *     <li>Third, an attempt to find a flavor representing a String reference
3743:            //     *         in the same VM is made.
3744:            //     *     <li>Lastly, DataFlavor.stringFlavor is searched for.
3745:            //     * </ol>
3746:            //     */
3747:            //    public DataFlavor getImportFlavor(DataFlavor[] flavors) {
3748:            ////        DataFlavor plainFlavor = null;
3749:            ////        DataFlavor refFlavor = null;
3750:            ////        DataFlavor stringFlavor = null;
3751:            ////        DataFlavor listFlavor = null;
3752:            ////
3753:            ////        for (int i = 0; i < flavors.length; i++) {
3754:            ////            String mime = flavors[i].getMimeType();
3755:            ////            Class clz = flavors[i].getRepresentationClass();
3756:            ////
3757:            ////            if (clz.isAssignableFrom(DisplayItem.class)) {
3758:            ////                return flavors[i];
3759:            ////            }
3760:            ////
3761:            ////            if (clz == DesignBean.class) {
3762:            ////                return flavors[i];
3763:            ////            }
3764:            ////
3765:            ////            if (clz.isAssignableFrom(List.class)) {
3766:            ////                // We don't know what's in the list, and can't look until
3767:            ////                // we have a transferable... but it looks promising so
3768:            ////                // defer decision
3769:            ////                listFlavor = flavors[i];
3770:            ////            }
3771:            ////
3772:            ////            if (clz.isAssignableFrom(org.openide.nodes.Node.class)) {
3773:            ////                listFlavor = flavors[i];
3774:            ////            } // TODO: check for org.openide.util.datatransfer.MultiTransferObject
3775:            ////
3776:            ////            if ((plainFlavor == null) && mime.startsWith("text/plain")) {
3777:            ////                plainFlavor = flavors[i];
3778:            ////            } else if ((refFlavor == null) &&
3779:            ////                    mime.startsWith("application/x-java-jvm-local-objectref") &&
3780:            ////                    (flavors[i].getRepresentationClass() == java.lang.String.class)) {
3781:            ////                refFlavor = flavors[i];
3782:            ////            } else if ((stringFlavor == null) && flavors[i].equals(DataFlavor.stringFlavor)) {
3783:            ////                stringFlavor = flavors[i];
3784:            ////            }
3785:            ////        }
3786:            ////
3787:            ////        if (refFlavor != null) {
3788:            ////            return refFlavor;
3789:            ////        } else if (listFlavor != null) {
3790:            ////            return listFlavor;
3791:            ////        } else if (stringFlavor != null) {
3792:            ////            return stringFlavor;
3793:            ////        } else if (plainFlavor != null) {
3794:            ////            return plainFlavor;
3795:            ////        }
3796:            ////
3797:            ////        return null;
3798:            //        return webform.getImportFlavor(flavors);
3799:            //    }
3800:
3801:            //    /**
3802:            //     * This method indicates if a component would accept an import of the given
3803:            //     * set of data flavors prior to actually attempting to import it.
3804:            //     *
3805:            //     * @param comp  The component to receive the transfer.  This
3806:            //     *  argument is provided to enable sharing of TransferHandlers by
3807:            //     *  multiple components.
3808:            //     * @param flavors  The data formats available
3809:            //     * @return  true if the data can be inserted into the component, false otherwise.
3810:            //     */
3811:            //    public boolean canImport(JComponent comp, DataFlavor[] flavors) {
3812:            //        // TODO Moving to NB winsys
3813:            //        // Ensure that the toolbox, if in auto-hide mode, hides such that
3814:            //        // the entire drawing canvas is visible and usable as a drop location
3815:            //        //        WindowManager.getDefault().clearOverlappedWindow();
3816:            //
3817:            //        //the following assert is changed by an if statement
3818:            //        //assert comp == webform.getPane();
3819:            //        if(DesignerUtils.DEBUG) {
3820:            //            DesignerUtils.debugLog(getClass().getName() + ".canImport(JComponent, DataFlavor[])");
3821:            //        }
3822:            //        if(comp != webform.getPane()) {
3823:            //            throw(new IllegalArgumentException("Wrong component."));
3824:            //        }
3825:            //        if(flavors == null) {
3826:            //            throw(new IllegalArgumentException("Null transferable."));
3827:            //        }
3828:            //
3829:            //        // DesignerPane is always enabled and editable
3830:            //        //DesignerPane c = webform.getPane();
3831:            //        //if (!(c.isEditable() && c.isEnabled())) {
3832:            //        //    return false;
3833:            //        //}
3834:            //        boolean canImport = getImportFlavor(flavors) != null;
3835:            //
3836:            //        return canImport;
3837:            //    }
3838:
3839:            /** Get the most recent drop point that we've been notified about */
3840:            public Point getDropPoint() {
3841:                return dropPoint;
3842:            }
3843:
3844:            /** Set the most recent drop point that we've been notified about */
3845:            public void setDropPoint(Point p) {
3846:                dropPoint = p;
3847:            }
3848:
3849:            /** Get the most recent drop size that we've been notified about */
3850:            public Dimension getDropSize() {
3851:                return dropSize;
3852:            }
3853:
3854:            /** Set the most recent drop point that we've been notified about */
3855:            public void setDropSize(Dimension d) {
3856:                dropSize = d;
3857:            }
3858:
3859:            /** Set the element to insert this tag immediately preeceding
3860:             *  in the DOM */
3861:            //    public void setInsertPosition(Position insertPos) {
3862:            public void setInsertPosition(DomPosition insertPos) {
3863:                this .insertPos = insertPos;
3864:            }
3865:
3866:            /** Set the drop action in effect so the importData method knows
3867:             * how to react. */
3868:            public void setDropAction(int dropAction) {
3869:                this .dropAction = dropAction;
3870:            }
3871:
3872:            //    /** Get the currently active transferable used during drag &amp; drop. */
3873:            //    public static Transferable getActiveTransferable() {
3874:            //        return transferable;
3875:            //    }
3876:            //
3877:            //    public static void setActiveTransferable(Transferable t) {
3878:            //        transferable = t;
3879:            //    }
3880:
3881:            //    /**
3882:            //     * Report whether the given position is in grid context
3883:            //     */
3884:            //    public static boolean isGridContext(DesignBean parent, MarkupPosition pos) {
3885:            //        if (parent.getInstance() instanceof javax.faces.component.UIForm ||
3886:            //                parent.getInstance() instanceof org.netbeans.modules.visualweb.xhtml.Form) {
3887:            //            // Look at its parent
3888:            //            parent = parent.getBeanParent();
3889:            //
3890:            //            if (parent == null) {
3891:            //                return false;
3892:            //            }
3893:            //        }
3894:            //
3895:            //        Element element = FacesSupport.getElement(parent);
3896:            //
3897:            //        if (element == null) {
3898:            //            return false;
3899:            //        }
3900:            //
3901:            ////        Value val = CssLookup.getValue(element, XhtmlCss.RAVELAYOUT_INDEX);
3902:            //        CssValue cssValue = CssProvider.getEngineService().getComputedValueForElement(element, XhtmlCss.RAVELAYOUT_INDEX);
3903:            //
3904:            ////        return val == CssValueConstants.GRID_VALUE;
3905:            //        return CssProvider.getValueService().isGridValue(cssValue);
3906:            //    }
3907:
3908:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.