Source Code Cross Referenced for PartnerScene.java in  » IDE-Netbeans » xml » org » netbeans » modules » xml » wsdl » ui » view » grapheditor » widget » 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 » xml » org.netbeans.modules.xml.wsdl.ui.view.grapheditor.widget 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.xml.wsdl.ui.view.grapheditor.widget;
043:
044:        import java.awt.Font;
045:        import java.awt.Point;
046:        import java.awt.Rectangle;
047:        import java.awt.datatransfer.Transferable;
048:        import java.beans.PropertyChangeEvent;
049:        import java.beans.PropertyChangeListener;
050:        import java.io.IOException;
051:        import java.util.ArrayList;
052:        import java.util.Collections;
053:        import java.util.List;
054:        import java.util.Set;
055:
056:        import javax.swing.JLabel;
057:
058:        import org.netbeans.api.visual.action.ActionFactory;
059:        import org.netbeans.api.visual.action.CycleFocusProvider;
060:        import org.netbeans.api.visual.action.SelectProvider;
061:        import org.netbeans.api.visual.action.WidgetAction;
062:        import org.netbeans.api.visual.action.WidgetAction.WidgetDropTargetDragEvent;
063:        import org.netbeans.api.visual.action.WidgetAction.WidgetDropTargetDropEvent;
064:        import org.netbeans.api.visual.model.ObjectScene;
065:        import org.netbeans.api.visual.model.ObjectSceneEvent;
066:        import org.netbeans.api.visual.model.ObjectSceneEventType;
067:        import org.netbeans.api.visual.model.ObjectSceneListener;
068:        import org.netbeans.api.visual.model.ObjectState;
069:        import org.netbeans.api.visual.widget.EventProcessingType;
070:        import org.netbeans.api.visual.widget.Scene;
071:        import org.netbeans.api.visual.widget.Widget;
072:        import org.netbeans.modules.xml.schema.model.SchemaModel;
073:        import org.netbeans.modules.xml.schema.ui.basic.SchemaModelCookie;
074:        import org.netbeans.modules.xml.wsdl.model.Definitions;
075:        import org.netbeans.modules.xml.wsdl.model.WSDLModel;
076:        import org.netbeans.modules.xml.wsdl.ui.netbeans.module.Utility;
077:        import org.netbeans.modules.xml.wsdl.ui.netbeans.module.WSDLDataObject;
078:        import org.netbeans.modules.xml.wsdl.ui.netbeans.module.WSDLModelCookie;
079:        import org.netbeans.modules.xml.wsdl.ui.view.grapheditor.DragOverSceneLayer;
080:        import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.pastetype.SchemaImportPasteType;
081:        import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.pastetype.WSDLImportPasteType;
082:        import org.netbeans.modules.xml.xam.ComponentEvent;
083:        import org.netbeans.modules.xml.xam.ComponentListener;
084:        import org.openide.filesystems.FileUtil;
085:        import org.openide.loaders.DataObject;
086:        import org.openide.nodes.Node;
087:        import org.openide.util.WeakListeners;
088:        import org.openide.util.datatransfer.PasteType;
089:
090:        /**
091:         *
092:         * @author anjeleevich
093:         */
094:        public class PartnerScene extends ObjectScene implements 
095:                ComponentListener, DnDHandler, PropertyChangeListener {
096:            private ButtonAction buttonAction;
097:            private WidgetAction selectAction;
098:            private DnDAction dndAction;
099:            private WidgetAction focusAction;
100:
101:            private final WSDLModel model;
102:            private MessagesWidget messagesWidget;
103:            private CollaborationsWidget collaborationsWidget;
104:            private DragOverSceneLayer dragOverLayer;
105:            private Font defaultFont = new JLabel().getFont();
106:            private SelectProvider selectProvider;
107:            private PartnerSceneCycleFocusProviderAndSceneListener cycleFocusProviderAndSceneListener;
108:            private PartnerSceneCycleFocusProvider mycycleFocusProvider;
109:            private List<Widget> selectedWidgets;
110:            private PropertyChangeListener weakModelListener;
111:            private ComponentListener weakComponentListener;
112:
113:            public PartnerScene(WSDLModel model) {
114:                super ();
115:
116:                this .model = model;
117:                setKeyEventProcessingType(EventProcessingType.FOCUSED_WIDGET_AND_ITS_CHILDREN_AND_ITS_PARENTS);
118:                cycleFocusProviderAndSceneListener = new PartnerSceneCycleFocusProviderAndSceneListener();
119:
120:                mycycleFocusProvider = new PartnerSceneCycleFocusProvider();
121:                buttonAction = new ButtonAction();
122:                selectProvider = new ObjectSelectProvider();
123:                selectAction = ActionFactory.createSelectAction(selectProvider);
124:                dndAction = new DnDAction();
125:                focusAction = ActionFactory
126:                        .createCycleFocusAction(mycycleFocusProvider);
127:
128:                //IZ 93508 fixes mouse wheel scroll.
129:                getActions().addAction(ActionFactory.createWheelPanAction());
130:
131:                getPriorActions().addAction(focusAction);
132:
133:                //Add a scene select action, which brings focus to the graph component.
134:                getActions().addAction(
135:                        ActionFactory.createSelectAction(new SelectProvider() {
136:
137:                            public void select(Widget widget,
138:                                    Point localLocation, boolean invertSelection) {
139:                                getView().requestFocusInWindow();
140:                            }
141:
142:                            public boolean isSelectionAllowed(Widget widget,
143:                                    Point localLocation, boolean invertSelection) {
144:                                return true;
145:                            }
146:
147:                            public boolean isAimingAllowed(Widget widget,
148:                                    Point localLocation, boolean invertSelection) {
149:                                return true;
150:                            }
151:
152:                        }));
153:                getActions().addAction(buttonAction);
154:                getActions().addAction(dndAction);
155:
156:                this .addObjectSceneListener(cycleFocusProviderAndSceneListener,
157:                        ObjectSceneEventType.OBJECT_FOCUS_CHANGED,
158:                        ObjectSceneEventType.OBJECT_SELECTION_CHANGED);
159:                selectedWidgets = new ArrayList<Widget>();
160:                dndAction.addPriorHandler(new FileDropDnDHandler());
161:            }
162:
163:            @Override
164:            protected void notifyAdded() {
165:                super .notifyAdded();
166:                weakModelListener = WeakListeners.propertyChange(this , model);
167:                model.addPropertyChangeListener(weakModelListener);
168:                weakComponentListener = WeakListeners.create(
169:                        ComponentListener.class, this , model);
170:                model.addComponentListener(weakComponentListener);
171:            }
172:
173:            @Override
174:            protected void notifyRemoved() {
175:                super .notifyRemoved();
176:                if (weakModelListener != null) {
177:                    model.removePropertyChangeListener(weakModelListener);
178:                    weakModelListener = null;
179:                }
180:
181:                if (weakComponentListener != null) {
182:                    model.removeComponentListener(weakComponentListener);
183:                    weakComponentListener = null;
184:                }
185:            }
186:
187:            /*private Logger mLogger = Logger.getLogger(PartnerScene.class.getName());
188:            protected void printFocusCycle(Widget widget, String indent, boolean onlyFocusables, boolean onlyFocusableTrue) {
189:                for (Widget w : widget.getChildren()) {
190:                    if (w instanceof FocusableWidget) {
191:                        if (!onlyFocusableTrue) {
192:                            mLogger.log(Level.SEVERE, indent + w + ": Focusable : " + ((FocusableWidget)w).isFocusable());
193:                        } else if (((FocusableWidget)w).isFocusable()){
194:                            mLogger.log(Level.SEVERE, indent + w + ": Focusable : "); 
195:                        }
196:                    } else if (!onlyFocusables){
197:                        mLogger.log(Level.SEVERE, indent + w.toString());
198:                    }
199:                    printFocusCycle(w, indent  + "--", onlyFocusables, onlyFocusableTrue);
200:                }
201:            }*/
202:
203:            public WSDLModel getModel() {
204:                return model;
205:            }
206:
207:            /**
208:             * Return the provider for performing widget selections.
209:             *
210:             * @return  selection provider.
211:             */
212:            public SelectProvider getSelectProvider() {
213:                return selectProvider;
214:            }
215:
216:            public ButtonAction getButtonAction() {
217:                return buttonAction;
218:            }
219:
220:            public WidgetAction getSelectAction() {
221:                return selectAction;
222:            }
223:
224:            public WidgetAction getDnDAction() {
225:                return dndAction;
226:            }
227:
228:            public MessagesWidget getMessagesWidget() {
229:                if (messagesWidget == null) {
230:                    messagesWidget = new MessagesWidget(this , model);
231:                }
232:
233:                return messagesWidget;
234:            }
235:
236:            public CollaborationsWidget getCollaborationsWidget() {
237:                if (collaborationsWidget == null) {
238:                    collaborationsWidget = new CollaborationsWidget(this , model);
239:                }
240:
241:                return collaborationsWidget;
242:            }
243:
244:            public DragOverSceneLayer getDragOverLayer() {
245:                if (dragOverLayer == null) {
246:                    dragOverLayer = new DragOverSceneLayer(this );
247:                }
248:                return dragOverLayer;
249:            }
250:
251:            public void childrenAdded(ComponentEvent componentEvent) {
252:                //do nothing
253:            }
254:
255:            public void childrenDeleted(ComponentEvent componentEvent) {
256:                //do nothing, handled by property change
257:            }
258:
259:            public void valueChanged(ComponentEvent componentEvent) {
260:                //do nothing.
261:            }
262:
263:            public void propertyChange(PropertyChangeEvent evt) {
264:                if (evt.getSource() == model.getDefinitions()) {
265:                    if (evt.getPropertyName().equals(
266:                            Definitions.MESSAGE_PROPERTY)) {
267:                        getMessagesWidget().updateContent(evt);
268:                    } else if (evt.getPropertyName().equals(
269:                            Definitions.EXTENSIBILITY_ELEMENT_PROPERTY)) {
270:                        getCollaborationsWidget().updateContent(evt);
271:                    }
272:                }
273:            }
274:
275:            @Override
276:            public Font getDefaultFont() {
277:                return defaultFont;
278:            }
279:
280:            private class ObjectSelectProvider implements  SelectProvider {
281:                public boolean isAimingAllowed(Widget widget,
282:                        Point localLocation, boolean invertSelection) {
283:                    return false;
284:                }
285:
286:                public boolean isSelectionAllowed(Widget widget,
287:                        Point localLocation, boolean invertSelection) {
288:                    return true;
289:                }
290:
291:                public void select(Widget widget, Point localLocation,
292:                        boolean invertSelection) {
293:                    getView().requestFocusInWindow();
294:                    Object object = findObject(widget);
295:
296:                    if (object != null) {
297:                        if (!findWidgets(object).contains(widget)) {
298:                            return;
299:                        }
300:                        if (getSelectedObjects().contains(object)) {
301:                            return;
302:                        }
303:                        userSelectionSuggested(Collections.singleton(object),
304:                                invertSelection);
305:                        //Expand all the widgets before it.
306:                        Widget parent = widget.getParentWidget();
307:                        while (parent != null) {
308:                            if (parent instanceof  ExpandableWidget) {
309:                                ExpandableWidget.class.cast(parent)
310:                                        .expandWidget();
311:                                //There are only two expandable widgets, Partnerlinktype and Message widgets.
312:                                //so break the loop, once any one is found.
313:                                break;
314:                            }
315:                            parent = parent.getParentWidget();
316:                        }
317:                        //Make the parents visible so that this widget can be seen. 
318:                        WidgetHelper.makeWidgetVisible(widget);
319:                        setFocusedObject(object);
320:                        setFocusedWidget(widget);
321:                        Rectangle bounds = widget.getClientArea();
322:                        if (bounds != null) {
323:                            bounds = widget.getScene().convertSceneToView(
324:                                    widget.convertLocalToScene(bounds));
325:                            widget.getScene().getView().scrollRectToVisible(
326:                                    bounds);
327:                        }
328:                    } else {
329:                        userSelectionSuggested(Collections.emptySet(),
330:                                invertSelection);
331:                        widget.setState(widget.getState().deriveSelected(true));
332:                        getSelectedWidgets().add(widget);
333:                    }
334:
335:                }
336:            }
337:
338:            public void dragExit() {
339:                collaborationsWidget.dragExit();
340:                messagesWidget.dragExit();
341:            }
342:
343:            public boolean dragOver(Point scenePoint,
344:                    WidgetDropTargetDragEvent event) {
345:                boolean messageVisible = messagesWidget != null
346:                        && messagesWidget.isVisible();
347:                boolean collabVisible = collaborationsWidget != null
348:                        && collaborationsWidget.isVisible();
349:
350:                if (messageVisible && collabVisible) {
351:
352:                    boolean collaborationsHit = collaborationsWidget
353:                            .isHitAt(collaborationsWidget
354:                                    .convertSceneToLocal(new Point(100,
355:                                            scenePoint.y)));
356:
357:                    if (collaborationsHit) {
358:                        return collaborationsWidget.dragOver(scenePoint, event);
359:                    }
360:                    return messagesWidget.dragOver(scenePoint, event);
361:
362:                } else if (messageVisible) {
363:                    return messagesWidget.dragOver(scenePoint, event);
364:                } else if (collabVisible) {
365:                    return collaborationsWidget.dragOver(scenePoint, event);
366:                }
367:                return false;
368:            }
369:
370:            public boolean drop(Point scenePoint,
371:                    WidgetDropTargetDropEvent event) {
372:                boolean messageVisible = messagesWidget != null
373:                        && messagesWidget.isVisible();
374:                boolean collabVisible = collaborationsWidget != null
375:                        && collaborationsWidget.isVisible();
376:
377:                if (messageVisible && collabVisible) {
378:
379:                    boolean collaborationsHit = collaborationsWidget
380:                            .isHitAt(collaborationsWidget
381:                                    .convertSceneToLocal(new Point(100,
382:                                            scenePoint.y)));
383:
384:                    if (collaborationsHit) {
385:                        return collaborationsWidget.drop(scenePoint, event);
386:                    }
387:                    return messagesWidget.drop(scenePoint, event);
388:
389:                } else if (messageVisible) {
390:                    return messagesWidget.drop(scenePoint, event);
391:                } else if (collabVisible) {
392:                    return collaborationsWidget.drop(scenePoint, event);
393:                }
394:                return false;
395:            }
396:
397:            public void expandForDragAndDrop() {
398:                messagesWidget.expandForDragAndDrop();
399:                collaborationsWidget.expandForDragAndDrop();
400:            }
401:
402:            public boolean isCollapsed() {
403:                return messagesWidget.isCollapsed()
404:                        || collaborationsWidget.isCollapsed();
405:            }
406:
407:            @Override
408:            public void userSelectionSuggested(Set<?> suggestedSelectedObjects,
409:                    boolean invertSelection) {
410:                boolean unRecognizedObjectsPresent = false;
411:                for (Object obj : suggestedSelectedObjects) {
412:                    if (!isObject(obj)) {
413:                        unRecognizedObjectsPresent = true;
414:                    }
415:                }
416:                if (!unRecognizedObjectsPresent) {
417:                    super .userSelectionSuggested(suggestedSelectedObjects,
418:                            invertSelection);
419:                }
420:                for (Widget w : getSelectedWidgets()) {
421:                    w.setState(w.getState().deriveSelected(false));
422:                }
423:                getSelectedWidgets().clear();
424:                validate();
425:            }
426:
427:            protected List<Widget> getSelectedWidgets() {
428:                return selectedWidgets;
429:            }
430:
431:            static public class PartnerSceneCycleFocusProvider implements 
432:                    CycleFocusProvider {
433:
434:                public boolean switchPreviousFocus(Widget widget) {
435:                    Scene scene = widget.getScene();
436:                    return scene instanceof  PartnerScene
437:                            && switchFocus((PartnerScene) scene, false);
438:                }
439:
440:                public boolean switchNextFocus(Widget widget) {
441:                    Scene scene = widget.getScene();
442:                    return scene instanceof  PartnerScene
443:                            && switchFocus((PartnerScene) scene, true);
444:                }
445:
446:                private boolean switchFocus(PartnerScene scene,
447:                        boolean forwardDirection) {
448:                    //Object object = scene.getFocusedObject();
449:                    Widget widget = scene.getFocusedWidget();
450:                    Widget next = null;
451:
452:                    if (forwardDirection) {
453:                        if (widget == null) {
454:                            next = getFirstFocusableWidget(scene);
455:                        } else {
456:                            next = getNextFocusableWidget(widget);
457:                            if (next == null) {
458:                                next = getFirstFocusableWidget(scene);
459:                            }
460:                        }
461:                    } else {
462:                        if (widget == null) {
463:                            next = getLastFocusableWidget(scene);
464:                        } else {
465:                            next = getPreviousFocusableWidget(widget);
466:                            if (next == null) {
467:                                next = getLastFocusableWidget(scene);
468:                            }
469:                        }
470:                    }
471:                    if (next != null) {
472:                        scene.setFocusedWidget(next);
473:                        Object obj = scene.findObject(next);
474:                        if (obj != null
475:                                && scene.findWidgets(obj).contains(next)) {
476:                            scene.setFocusedObject(obj);
477:                        } else {
478:                            scene.userSelectionSuggested(
479:                                    Collections.emptySet(), false);
480:                            next.setState(next.getState().deriveSelected(true));
481:                            scene.getSelectedWidgets().add(next);
482:                            scene.setFocusedObject(null);
483:                            scene.setFocusedWidget(next);
484:                        }
485:
486:                        return true;
487:                    }
488:
489:                    return false;
490:                }
491:
492:                private Widget getFirstFocusableWidget(PartnerScene scene) {
493:                    return getNextFocusableWidgetInChildren(scene);
494:                }
495:
496:                private Widget getNextFocusableWidget(Widget widget) {
497:                    Widget next = getNextFocusableWidgetInChildren(widget);
498:                    if (next == null) {
499:                        next = getNextFocusableWidgetInSiblings(widget);
500:                    }
501:                    if (next != null)
502:                        return next;
503:
504:                    return null;
505:                }
506:
507:                private Widget getPreviousFocusableWidget(Widget widget) {
508:                    return getPreviousFocusableWidgetInSiblings(widget);
509:                }
510:
511:                private Widget getNextFocusableWidgetInSiblings(Widget widget) {
512:                    if (widget == null)
513:                        return null;
514:
515:                    Widget next = null;
516:                    Widget parent = widget.getParentWidget();
517:                    if (parent != null) {
518:                        List<Widget> siblings = parent.getChildren();
519:                        int index = siblings.indexOf(widget);
520:                        for (int i = index + 1; i < siblings.size(); i++) {
521:                            Widget s = siblings.get(i);
522:                            if (s instanceof  FocusableWidget) {
523:                                if (((FocusableWidget) s).isFocusable()) {
524:                                    return s;
525:                                }
526:                            } else {
527:                                next = getNextFocusableWidget(siblings.get(i));
528:                                if (next != null) {
529:                                    break;
530:                                }
531:                            }
532:                        }
533:                    }
534:                    if (next == null) {
535:                        return getNextFocusableWidgetInSiblings(parent);
536:                    }
537:
538:                    return next;
539:                }
540:
541:                private Widget getNextFocusableWidgetInChildren(Widget widget) {
542:                    for (Widget w : widget.getChildren()) {
543:                        if (w instanceof  FocusableWidget) {
544:                            FocusableWidget fw = (FocusableWidget) w;
545:                            if (fw.isFocusable()) {
546:                                return w;
547:                            }
548:                        }
549:                        Widget next = getNextFocusableWidgetInChildren(w);
550:                        if (next != null) {
551:                            return next;
552:                        }
553:                    }
554:                    return null;
555:                }
556:
557:                private Widget getLastFocusableWidget(PartnerScene scene) {
558:                    return getPreviousFocusableWidgetInChildren(scene);
559:                }
560:
561:                private Widget getPreviousFocusableWidgetInSiblings(
562:                        Widget widget) {
563:                    Widget parent = widget.getParentWidget();
564:                    Widget next = null;
565:                    if (parent != null) {
566:                        List<Widget> siblings = parent.getChildren();
567:                        int index = siblings.indexOf(widget);
568:                        for (int i = index - 1; i >= 0; i--) {
569:                            next = getPreviousFocusableWidgetInChildren(siblings
570:                                    .get(i));
571:                            if (next != null)
572:                                return next;
573:                        }
574:                        if (parent instanceof  FocusableWidget
575:                                && (((FocusableWidget) parent).isFocusable())) {
576:                            return parent;
577:                        }
578:                        next = getPreviousFocusableWidgetInSiblings(parent);
579:                        if (next != null)
580:                            return next;
581:                    }
582:                    return null;
583:                }
584:
585:                private Widget getPreviousFocusableWidgetInChildren(
586:                        Widget widget) {
587:                    if (widget == null)
588:                        return null;
589:                    Widget next = null;
590:                    List<Widget> children = widget.getChildren();
591:                    for (int i = children.size() - 1; i >= 0; i--) {
592:                        Widget w = children.get(i);
593:                        next = getPreviousFocusableWidgetInChildren(w);
594:                        if (next != null)
595:                            return next;
596:
597:                        if (w instanceof  FocusableWidget) {
598:                            if (((FocusableWidget) w).isFocusable()) {
599:                                return w;
600:                            }
601:                        }
602:                    }
603:                    if (widget instanceof  FocusableWidget
604:                            && (((FocusableWidget) widget).isFocusable())) {
605:                        return widget;
606:                    }
607:                    return null;
608:                }
609:            }
610:
611:            static public class PartnerSceneCycleFocusProviderAndSceneListener
612:                    implements  ObjectSceneListener {
613:
614:                public void focusChanged(ObjectSceneEvent event,
615:                        Object previousFocusedObject, Object newFocusedObject) {
616:                    if (newFocusedObject == null)
617:                        return;
618:                    ObjectScene scene = event.getObjectScene();
619:                    if (scene instanceof  PartnerScene) {
620:                        PartnerScene partnerScene = (PartnerScene) scene;
621:                        List<Widget> widgets = scene
622:                                .findWidgets(newFocusedObject);
623:
624:                        Widget fw = scene.getFocusedWidget();
625:                        if (fw != null) {
626:                            if (widgets.contains(fw)) {
627:                                Rectangle bounds = fw.getClientArea();
628:                                if (bounds != null) {
629:                                    bounds = partnerScene.convertSceneToView(fw
630:                                            .convertLocalToScene(bounds));
631:                                    partnerScene.getView().scrollRectToVisible(
632:                                            bounds);
633:                                }
634:                            }
635:                            if (!scene.getSelectedObjects().contains(
636:                                    newFocusedObject)) {
637:                                scene.userSelectionSuggested(Collections
638:                                        .singleton(newFocusedObject), false);
639:                            }
640:                        }
641:                    }
642:                }
643:
644:                public void objectAdded(ObjectSceneEvent event,
645:                        Object addedObject) {
646:                    // do nothing
647:                }
648:
649:                public void objectRemoved(ObjectSceneEvent event,
650:                        Object removedObject) {
651:                    // do nothing
652:                }
653:
654:                public void highlightingChanged(ObjectSceneEvent event,
655:                        Set<Object> previousHighlighting,
656:                        Set<Object> newHighlighting) {
657:                    // do nothing
658:                }
659:
660:                public void hoverChanged(ObjectSceneEvent event,
661:                        Object previousHoveredObject, Object newHoveredObject) {
662:                    // do nothing
663:                }
664:
665:                public void objectStateChanged(ObjectSceneEvent event,
666:                        Object changedObject, ObjectState previousState,
667:                        ObjectState newState) {
668:                    // do nothing
669:                }
670:
671:                public void selectionChanged(ObjectSceneEvent event,
672:                        Set<Object> previousSelection, Set<Object> newSelection) {
673:                    ObjectScene scene = event.getObjectScene();
674:                    Widget w = scene.getFocusedWidget();
675:                    Object focusedObject = scene.getFocusedObject();
676:                    if (w != null && w != scene.findObject(w)) { // in case of button widgets
677:                        if (!newSelection.isEmpty()) {
678:                            Object obj = newSelection.iterator().next();
679:                            Widget newWidget = scene.findWidget(obj);
680:                            if (newWidget != null) {
681:                                WidgetHelper.makeWidgetVisible(newWidget);
682:                            }
683:                            scene.setFocusedWidget(newWidget);
684:                            scene.setFocusedObject(obj);
685:                        }
686:                    } else {
687:                        if (!newSelection.isEmpty()
688:                                && !newSelection.contains(focusedObject)) {
689:                            scene.setFocusedObject(newSelection.iterator()
690:                                    .next());
691:                        }
692:                    }
693:                }
694:            }
695:
696:            private class FileDropDnDHandler implements  DnDHandler {
697:
698:                public FileDropDnDHandler() {
699:                    //default constructor.
700:                }
701:
702:                public boolean dragOver(Point scenePoint,
703:                        WidgetDropTargetDragEvent event) {
704:                    Transferable t = event.getTransferable();
705:                    if (t != null) {
706:                        Node[] nodes = Utility.getNodes(t);
707:                        if (nodes.length == 1) {
708:                            Node node = nodes[0];
709:                            DataObject dObj = node.getLookup().lookup(
710:                                    DataObject.class);
711:                            if (dObj.getNodeDelegate().equals(node)) {
712:                                PasteType p = Utility.getWSDLOrSchemaPasteType(
713:                                        dObj, model, true, true);
714:                                if (p != null) {
715:                                    return true;
716:                                }
717:                            }
718:                        }
719:                    }
720:                    return false;
721:                }
722:
723:                public boolean drop(Point scenePoint,
724:                        WidgetDropTargetDropEvent event) {
725:                    Transferable t = event.getTransferable();
726:                    if (t != null) {
727:                        Node[] nodes = Utility.getNodes(t);
728:                        if (nodes.length == 1) {
729:                            Node node = nodes[0];
730:                            DataObject dObj = node.getLookup().lookup(
731:                                    DataObject.class);
732:                            if (dObj.getNodeDelegate().equals(node)) {
733:                                PasteType p = Utility.getWSDLOrSchemaPasteType(
734:                                        dObj, model, true, true);
735:                                if (p != null) {
736:                                    try {
737:                                        p.paste();
738:                                    } catch (IOException e) {
739:                                        //ignore
740:                                    }
741:                                    return true;
742:                                }
743:                            }
744:                        }
745:                    }
746:                    return false;
747:                }
748:
749:                public void dragExit() {
750:                    //do nothing
751:                }
752:
753:                public void expandForDragAndDrop() {
754:                    //do nothing
755:                }
756:
757:                public boolean isCollapsed() {
758:                    return false;
759:                }
760:            }
761:        }
w_w___w_._ja___v___a_2_s_.___c___o___m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.