Source Code Cross Referenced for InspectorWrapperTree.java in  » IDE-Netbeans » vmd.analyzer » org » netbeans » modules » vmd » inspector » 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 » vmd.analyzer » org.netbeans.modules.vmd.inspector 
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-2006 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.vmd.inspector;
043:
044:        import org.netbeans.modules.vmd.api.inspector.*;
045:        import org.netbeans.modules.vmd.api.model.DesignComponent;
046:        import org.netbeans.modules.vmd.api.model.DesignDocument;
047:        import org.netbeans.modules.vmd.api.model.DesignEvent;
048:        import org.netbeans.modules.vmd.api.model.TypeID;
049:        import org.netbeans.modules.vmd.api.model.presenters.InfoPresenter;
050:        import org.openide.nodes.Node;
051:        import org.openide.util.WeakSet;
052:        import org.openide.util.datatransfer.NewType;
053:
054:        import javax.swing.*;
055:        import java.awt.*;
056:        import java.awt.image.ImageObserver;
057:        import java.awt.image.ImageProducer;
058:        import java.util.ArrayList;
059:        import java.util.Collection;
060:        import java.util.HashSet;
061:        import java.util.List;
062:
063:        /**
064:         *
065:         * @author Karol Harezlak
066:         */
067:        public final class InspectorWrapperTree implements 
068:                FolderRegistry.Listener {
069:
070:            private Collection<InspectorFolder> globalFolders;
071:            private FolderRegistry registry;
072:            private DesignDocument document;
073:            private InspectorFolderWrapper rootFolderWrapper;
074:            private WeakSet<DesignComponent> componentsToDelete;
075:            private WeakSet<DesignComponent> componentsToAdd;
076:            private WeakSet<DesignComponent> componentsToUndo;
077:            private WeakSet<InspectorFolderWrapper> foldersToUpdate;
078:            private WeakSet<DesignComponent> deletedComponentsCash;
079:            private WeakSet<InspectorFolderWrapper> foldersToExtend;
080:            private boolean lock = true;
081:            private InspectorUI ui;
082:
083:            InspectorWrapperTree(DesignDocument document, InspectorUI ui) {
084:                foldersToExtend = new WeakSet<InspectorFolderWrapper>();
085:                foldersToUpdate = new WeakSet<InspectorFolderWrapper>();
086:                componentsToAdd = new WeakSet<DesignComponent>();
087:                componentsToDelete = new WeakSet<DesignComponent>();
088:                componentsToUndo = new WeakSet<DesignComponent>();
089:                this .document = document;
090:                rootFolderWrapper = new InspectorFolderWrapper(document,
091:                        new RootFolder());
092:                rootFolderWrapper.resolveFolder(document);
093:                this .ui = ui;
094:            }
095:
096:            synchronized void buildTree(final DesignEvent event) {
097:                lock = true;
098:                document.getTransactionManager().readAccess(new Runnable() {
099:                    public void run() {
100:                        if (rootFolderWrapper.getChildren() != null
101:                                && event != null) {
102:                            if (event.getFullyAffectedComponents() != null
103:                                    && !event.getFullyAffectedComponents()
104:                                            .isEmpty()) {
105:                                addFoldersToUpdate(event
106:                                        .getFullyAffectedComponents(),
107:                                        rootFolderWrapper);
108:                            }
109:                            updateChangedDescriptors(event
110:                                    .getCreatedComponents(), event
111:                                    .getFullyAffectedComponents());
112:                            dive(InspectorFolderPath.createInspectorPath().add(
113:                                    rootFolderWrapper.getFolder()),
114:                                    rootFolderWrapper);
115:                            updateTreeStructureView();
116:                            ui.expandNodes(foldersToExtend);
117:                        } else {
118:                            updateChangedDescriptors(
119:                                    markAllComponentsAsToAdd(), null);
120:                            dive(InspectorFolderPath.createInspectorPath().add(
121:                                    rootFolderWrapper.getFolder()),
122:                                    rootFolderWrapper);
123:                            updateTreeStructureView();
124:                            Collection<InspectorFolderWrapper> foldersToExpand = rootFolderWrapper
125:                                    .getChildren();
126:                            if (foldersToExpand != null) {
127:                                ui.expandNodes(foldersToExpand);
128:                            }
129:                        }
130:                    }
131:                });
132:                // cleaning up
133:                foldersToUpdate.clear();
134:                foldersToExtend.clear();
135:                componentsToAdd.clear();
136:                componentsToDelete.clear();
137:                componentsToUndo.clear();
138:                lock = false;
139:            }
140:
141:            private void addFoldersToUpdate(
142:                    Collection<DesignComponent> fullyAffected,
143:                    InspectorFolderWrapper parentWrapper) {
144:                if (parentWrapper.getChildren() == null) {
145:                    return;
146:                }
147:                for (InspectorFolderWrapper wrapper : parentWrapper
148:                        .getChildren()) {
149:                    addFoldersToUpdate(fullyAffected, wrapper);
150:                    if (fullyAffected.contains(wrapper.getComponent())) {
151:                        foldersToUpdate.add(wrapper);
152:                    }
153:                }
154:            }
155:
156:            boolean isLocked() {
157:                return lock;
158:            }
159:
160:            //------------------ bulid tree algorithm
161:            private void dive(InspectorFolderPath path,
162:                    InspectorFolderWrapper parentWrapper) {
163:                List<InspectorFolderWrapper> wrapperChildren;
164:                if (parentWrapper.getFolder() instanceof  RootFolder) {
165:                    wrapperChildren = componentsRecursion(path, parentWrapper,
166:                            document.getRootComponent());
167:                } else {
168:                    wrapperChildren = componentsChildrenDive(path,
169:                            parentWrapper, document.getRootComponent());
170:                }
171:                if (wrapperChildren == null) {
172:                    wrapperChildren = registryDescriptorsDive(path,
173:                            parentWrapper);
174:                } else {
175:                    List<InspectorFolderWrapper> registryWrapperChildren = registryDescriptorsDive(
176:                            path, parentWrapper);
177:                    if (registryWrapperChildren != null) {
178:                        wrapperChildren.addAll(registryWrapperChildren);
179:                    }
180:                }
181:
182:                if (wrapperChildren == null) {
183:                    wrapperChildren = parentWrapper.getChildren();
184:                } else {
185:                    foldersToUpdate.add(parentWrapper);
186:                    List<InspectorFolderWrapper> parentWrapperChildren = parentWrapper
187:                            .getChildren();
188:                    if (parentWrapperChildren != null) {
189:                        wrapperChildren.addAll(parentWrapperChildren);
190:                    }
191:                }
192:
193:                if (wrapperChildren != null) {
194:                    WeakSet<InspectorFolderWrapper> wrappersToDelete = null;
195:                    for (InspectorFolderWrapper folder : wrapperChildren) {
196:                        if (componentsToDelete != null
197:                                && folder.getFolder().getComponentID() != null) {
198:                            for (DesignComponent component : componentsToDelete) {
199:                                if (folder.getFolder().getComponentID().equals(
200:                                        component.getComponentID())) {
201:                                    if (wrappersToDelete == null) {
202:                                        wrappersToDelete = new WeakSet<InspectorFolderWrapper>();
203:                                    }
204:                                    wrappersToDelete.add(folder);
205:                                    if (deletedComponentsCash == null) {
206:                                        deletedComponentsCash = new WeakSet<DesignComponent>();
207:                                    }
208:                                    deletedComponentsCash.add(document
209:                                            .getComponentByUID(component
210:                                                    .getComponentID()));
211:                                    foldersToUpdate.add(parentWrapper);
212:                                }
213:                            }
214:                        }
215:                        path.add(folder.getFolder());
216:                        dive(path, folder);
217:                        path.remove(folder.getFolder());
218:                    }
219:                    if (wrappersToDelete != null) {
220:                        wrapperChildren.removeAll(wrappersToDelete);
221:                        for (InspectorFolderWrapper wrapperToDelete : wrappersToDelete) {
222:                            wrapperToDelete.terminate();
223:                        }
224:                    }
225:                    parentWrapper.setChildren(wrapperChildren);
226:                }
227:            }
228:
229:            private List<InspectorFolderWrapper> componentsChildrenDive(
230:                    InspectorFolderPath path,
231:                    InspectorFolderWrapper parentWrapper,
232:                    DesignComponent parentComponent) {
233:                List<InspectorFolderWrapper> wrapperChildren = null;
234:
235:                for (DesignComponent component : parentComponent
236:                        .getComponents()) {
237:                    if (componentsToAdd.contains(component)
238:                            || componentsToUndo.contains(component)) {
239:                        List<InspectorFolderWrapper> tempWrapperChildren = componentsRecursion(
240:                                path, parentWrapper, component);
241:                        if (wrapperChildren == null) {
242:                            wrapperChildren = tempWrapperChildren;
243:                        } else if (tempWrapperChildren != null) {
244:                            wrapperChildren.addAll(tempWrapperChildren);
245:                        }
246:                    }
247:                    if ((!InspectorRegistry.getInstance(document)
248:                            .getComponentsToUpdate().isEmpty())
249:                            && InspectorRegistry.getInstance(document)
250:                                    .getComponentsToUpdate()
251:                                    .contains(component)) {
252:                        if (wrapperChildren == null) {
253:                            wrapperChildren = changedComponentsRecursion(path,
254:                                    parentWrapper, component);
255:                        } else {
256:                            List<InspectorFolderWrapper> changedComponentsRecursionChildren = changedComponentsRecursion(
257:                                    path, parentWrapper, component);
258:                            if (changedComponentsRecursionChildren != null) {
259:                                wrapperChildren
260:                                        .addAll(changedComponentsRecursionChildren);
261:                            }
262:                        }
263:                    }
264:                    if (wrapperChildren == null) {
265:                        wrapperChildren = componentsChildrenDive(path,
266:                                parentWrapper, component);
267:                    } else {
268:                        List<InspectorFolderWrapper> componentsChildren = componentsChildrenDive(
269:                                path, parentWrapper, component);
270:                        if (componentsChildren != null) {
271:                            wrapperChildren.addAll(componentsChildren);
272:                        }
273:                    }
274:                }
275:                return wrapperChildren;
276:            }
277:
278:            private List<InspectorFolderWrapper> componentsRecursion(
279:                    InspectorFolderPath path,
280:                    InspectorFolderWrapper parentWrapper,
281:                    DesignComponent component) {
282:                List<InspectorFolderWrapper> wrapperChildren = null;
283:
284:                for (DesignComponent componentToAdd : componentsToAdd) {
285:                    if (componentToAdd.getComponentID() != component
286:                            .getComponentID()) {
287:                        continue;
288:                    }
289:                    for (InspectorFolderPresenter presenter : componentToAdd
290:                            .getPresenters(InspectorFolderPresenter.class)) {
291:                        if (presenter != null
292:                                && presenter.getFolder().isInside(path,
293:                                        presenter.getFolder(), componentToAdd)) {
294:                            if (presenter.getFolder().getComponentID() != null
295:                                    && (parentWrapper.getChildrenFolders() == null || (!parentWrapper
296:                                            .getChildrenFolders().contains(
297:                                                    presenter.getFolder())))) {
298:                                if (wrapperChildren == null) {
299:                                    wrapperChildren = new ArrayList<InspectorFolderWrapper>();
300:                                }
301:                                InspectorFolderWrapper wrapper = new InspectorFolderWrapper(
302:                                        document, presenter.getFolder());
303:                                wrapperChildren.add(wrapper);
304:                                foldersToUpdate.add(parentWrapper);
305:                                foldersToExtend.add(parentWrapper);
306:                            }
307:                        }
308:                    }
309:                }
310:
311:                for (DesignComponent componentToUndo : componentsToUndo) {
312:                    if (componentToUndo.getComponentID() != component
313:                            .getComponentID()) {
314:                        continue;
315:                    }
316:                    for (InspectorFolderPresenter presenter : componentToUndo
317:                            .getPresenters(InspectorFolderPresenter.class)) {
318:                        if (presenter != null
319:                                && presenter.getFolder().isInside(path,
320:                                        presenter.getFolder(), componentToUndo)) {
321:                            if (presenter.getFolder().getComponentID() != null) {
322:                                if (wrapperChildren == null) {
323:                                    wrapperChildren = new ArrayList<InspectorFolderWrapper>();
324:                                }
325:                                InspectorFolderWrapper wrapper = new InspectorFolderWrapper(
326:                                        document, presenter.getFolder());
327:                                wrapperChildren.add(wrapper);
328:                                foldersToUpdate.add(parentWrapper);
329:                                foldersToExtend.add(parentWrapper);
330:                                deletedComponentsCash.remove(componentToUndo);
331:                            }
332:                        }
333:                    }
334:                }
335:                return wrapperChildren;
336:            }
337:
338:            private List<InspectorFolderWrapper> changedComponentsRecursion(
339:                    InspectorFolderPath path,
340:                    InspectorFolderWrapper parentWrapper,
341:                    DesignComponent component) {
342:                List<InspectorFolderWrapper> wrapperChildren = null;
343:
344:                for (InspectorFolderPresenter presenter : component
345:                        .getPresenters(InspectorFolderPresenter.class)) {
346:                    if (presenter != null
347:                            && presenter.getFolder().isInside(path,
348:                                    presenter.getFolder(), component)) {
349:                        if (presenter.getFolder().getComponentID() != null) {
350:                            if (!parentWrapper.removeChild(presenter
351:                                    .getFolder())) {
352:                                continue;
353:                            }
354:                            if (wrapperChildren == null) {
355:                                wrapperChildren = new ArrayList<InspectorFolderWrapper>();
356:                            }
357:                            InspectorFolderWrapper wrapper = new InspectorFolderWrapper(
358:                                    document, presenter.getFolder());
359:                            wrapperChildren.add(wrapper);
360:                            path.add(wrapper.getFolder());
361:                            rebulidDive(path, wrapper);
362:                            path.remove(wrapper.getFolder());
363:                            foldersToUpdate.add(parentWrapper);
364:                        } else {
365:                            throw new IllegalArgumentException(
366:                                    "Argument ComponentID is null: component: "
367:                                            + component); //NOI18N
368:                        }
369:                    }
370:                }
371:                return wrapperChildren;
372:            }
373:
374:            private List<InspectorFolderWrapper> registryDescriptorsDive(
375:                    InspectorFolderPath path,
376:                    InspectorFolderWrapper parentWrapper) {
377:                List<InspectorFolderWrapper> wrapperChildren = null;
378:
379:                if (globalFolders == null) {
380:                    return null;
381:                }
382:                for (InspectorFolder folder : globalFolders) {
383:                    if (folder.isInside(path, folder, null)) {
384:                        if (parentWrapper.getChildrenFolders() != null
385:                                && parentWrapper.getChildrenFolders().contains(
386:                                        folder)) {
387:                            continue;
388:                        }
389:                        if (wrapperChildren == null) {
390:                            wrapperChildren = new ArrayList<InspectorFolderWrapper>();
391:                        }
392:                        InspectorFolderWrapper wrapper = new InspectorFolderWrapper(
393:                                document, folder);
394:                        wrapperChildren.add(wrapper);
395:                    }
396:                }
397:                return wrapperChildren;
398:            }
399:
400:            //------------------ change tree algorithm
401:            private void rebulidDive(InspectorFolderPath path,
402:                    InspectorFolderWrapper parentWrapper) {
403:                List<InspectorFolderWrapper> wrapperChildren;
404:
405:                if (parentWrapper.getFolder() instanceof  RootFolder) {
406:                    wrapperChildren = rebulidComponentsRecursion(path,
407:                            parentWrapper, document.getRootComponent());
408:                } else {
409:                    wrapperChildren = rebulidComponentsChildrenDive(path,
410:                            parentWrapper, document.getRootComponent());
411:                }
412:                if (wrapperChildren == null) {
413:                    wrapperChildren = registryDescriptorsDive(path,
414:                            parentWrapper);
415:                } else {
416:                    List<InspectorFolderWrapper> registryChildren = registryDescriptorsDive(
417:                            path, parentWrapper);
418:                    if (registryChildren != null) {
419:                        wrapperChildren.addAll(registryChildren);
420:                    }
421:                }
422:                if (wrapperChildren == null) {
423:                    wrapperChildren = parentWrapper.getChildren();
424:                } else {
425:                    List<InspectorFolderWrapper> parentChildren = parentWrapper
426:                            .getChildren();
427:                    if (parentChildren != null) {
428:                        wrapperChildren.addAll(parentChildren);
429:                    }
430:                }
431:                if (wrapperChildren != null) {
432:                    for (InspectorFolderWrapper folder : wrapperChildren) {
433:                        path.add(folder.getFolder());
434:                        rebulidDive(path, folder);
435:                        path.remove(folder.getFolder());
436:                    }
437:                    parentWrapper.setChildren(wrapperChildren);
438:                }
439:            }
440:
441:            private List<InspectorFolderWrapper> rebulidComponentsChildrenDive(
442:                    InspectorFolderPath path,
443:                    InspectorFolderWrapper parentWrapper,
444:                    DesignComponent parentComponent) {
445:                List<InspectorFolderWrapper> wrapperChildren = null;
446:
447:                for (DesignComponent component : parentComponent
448:                        .getComponents()) {
449:                    List<InspectorFolderWrapper> tempWrapperChildren = rebulidComponentsRecursion(
450:                            path, parentWrapper, component);
451:
452:                    if (wrapperChildren == null) {
453:                        wrapperChildren = tempWrapperChildren;
454:                    } else if (tempWrapperChildren != null) {
455:                        wrapperChildren.addAll(tempWrapperChildren);
456:                    }
457:                    if (wrapperChildren == null) {
458:                        wrapperChildren = rebulidComponentsChildrenDive(path,
459:                                parentWrapper, component);
460:                    } else {
461:                        List<InspectorFolderWrapper> componentsChildren = rebulidComponentsChildrenDive(
462:                                path, parentWrapper, component);
463:                        if (componentsChildren != null) {
464:                            wrapperChildren.addAll(componentsChildren);
465:                        }
466:                    }
467:                }
468:                return wrapperChildren;
469:            }
470:
471:            private List<InspectorFolderWrapper> rebulidComponentsRecursion(
472:                    InspectorFolderPath path,
473:                    InspectorFolderWrapper parentWrapper,
474:                    DesignComponent component) {
475:                List<InspectorFolderWrapper> childrenWrapper = null;
476:                for (InspectorFolderPresenter presenter : component
477:                        .getPresenters(InspectorFolderPresenter.class)) {
478:                    if (presenter != null
479:                            && presenter.getFolder().isInside(path,
480:                                    presenter.getFolder(), component)) {
481:                        if (presenter.getFolder().getComponentID() != null
482:                                && (parentWrapper.getChildrenFolders() == null || (!parentWrapper
483:                                        .getChildrenFolders().contains(
484:                                                presenter.getFolder())))) {
485:                            if (childrenWrapper == null) {
486:                                childrenWrapper = new ArrayList<InspectorFolderWrapper>();
487:                            }
488:                            InspectorFolderWrapper wrapper = new InspectorFolderWrapper(
489:                                    document, presenter.getFolder());
490:                            childrenWrapper.add(wrapper);
491:                            foldersToUpdate.add(parentWrapper);
492:                            foldersToExtend.add(parentWrapper);
493:                        }
494:                    }
495:                }
496:                return childrenWrapper;
497:            }
498:
499:            // ---------- Existing tree update
500:            private void updateChangedDescriptors(
501:                    final Collection<DesignComponent> createdComponents,
502:                    final Collection<DesignComponent> affectedComponents) {
503:                if (createdComponents != null) {
504:                    for (DesignComponent component : createdComponents) {
505:                        if (!component.getPresenters(
506:                                InspectorFolderPresenter.class).isEmpty()) {
507:                            componentsToAdd.add(component);
508:                        }
509:                    }
510:                }
511:                if (affectedComponents != null) {
512:                    for (DesignComponent component : affectedComponents) {
513:                        if (deletedComponentsCash != null
514:                                && deletedComponentsCash.contains(component)) {
515:                            componentsToUndo.add(component);
516:                        }
517:                        if (component == null
518:                                || component.getParentComponent() != null) {
519:                            continue;
520:                        }
521:                        componentsToDelete.add(component);
522:                    }
523:                }
524:
525:                InspectorRegistry.getInstance(document).remove(componentsToAdd);
526:                InspectorRegistry.getInstance(document).remove(
527:                        componentsToDelete);
528:            }
529:
530:            private void updateTreeStructureView() {
531:                updateTreeStructureView(rootFolderWrapper);
532:                rootFolderWrapper.resolveFolder(document);
533:                warmUp(rootFolderWrapper.getNode());
534:            }
535:
536:            private void updateTreeStructureView(
537:                    InspectorFolderWrapper parentWrapper) {
538:                if (parentWrapper.getChildren() != null) {
539:                    for (InspectorFolderWrapper wrapper : parentWrapper
540:                            .getChildren()) {
541:                        updateTreeStructureView(wrapper);
542:                        if (foldersToUpdate.contains(wrapper)) {
543:                            wrapper.resolveFolder(document);
544:                        }
545:                    }
546:                }
547:                if (parentWrapper.getChildren() == null
548:                        || parentWrapper.getChildren().isEmpty()) {
549:                    parentWrapper.resolveFolder(document);
550:                }
551:            }
552:
553:            private void warmUp(Node node) {
554:                for (Node child : node.getChildren().getNodes()) {
555:                    warmUp(child);
556:                }
557:            }
558:
559:            private void updateRegistredFolders() {
560:                if (registry == null) {
561:                    return;
562:                }
563:                registry.readAccess(new Runnable() {
564:
565:                    public void run() {
566:                        globalFolders = registry.getFolders();
567:                    }
568:                });
569:            }
570:
571:            InspectorFolderWrapper getRootWrapperFolder() {
572:                return rootFolderWrapper;
573:            }
574:
575:            public void notifyRegistryContentChange() {
576:                updateRegistredFolders();
577:            }
578:
579:            Collection<Node> getSelectedNodes() {
580:                return getSelectedNodes(rootFolderWrapper);
581:            }
582:
583:            private Collection<Node> getSelectedNodes(
584:                    final InspectorFolderWrapper parentFolder) {
585:                if (parentFolder == null || parentFolder.getChildren() == null) {
586:                    return null;
587:                }
588:                final Collection<Node> selectedNodes = new HashSet<Node>();
589:
590:                if (document.getSelectedComponents().isEmpty()) {
591:                    return selectedNodes;
592:                }
593:                for (InspectorFolderWrapper folder : parentFolder.getChildren()) {
594:                    if (folder.getChildren() != null) {
595:                        selectedNodes.addAll(getSelectedNodes(folder));
596:                    }
597:                    //TODO Selection based on the ComponentID and Display Name could be not enough it better to create smarter algorithm
598:                    for (DesignComponent component : document
599:                            .getSelectedComponents()) {
600:                        Long componentID = folder.getFolder().getComponentID();
601:                        if (componentID == null
602:                                || componentID != component.getComponentID()) {
603:                            continue;
604:                        }
605:                        if (folder.getFolder().getDisplayName().equals(
606:                                InfoPresenter.getDisplayName(component))) {
607:                            selectedNodes.add(folder.getNode());
608:                        }
609:                    }
610:                }
611:                return selectedNodes;
612:            }
613:
614:            private Collection<DesignComponent> markAllComponentsAsToAdd() {
615:                Collection<DesignComponent> componentsToAdd = new HashSet<DesignComponent>();
616:                if (document.getRootComponent() != null)
617:                    markAllComponentsAsToAdd(componentsToAdd, document
618:                            .getRootComponent());
619:                return componentsToAdd;
620:            }
621:
622:            private Collection<DesignComponent> markAllComponentsAsToAdd(
623:                    Collection<DesignComponent> componentsToAdd,
624:                    DesignComponent parentComponent) {
625:                componentsToAdd.add(parentComponent);
626:                for (DesignComponent component : parentComponent
627:                        .getComponents())
628:                    markAllComponentsAsToAdd(componentsToAdd, component);
629:                return componentsToAdd;
630:            }
631:
632:            void terminate() {
633:                if (rootFolderWrapper != null) {
634:                    terminateChildern(rootFolderWrapper);
635:                    globalFolders = null;
636:                    registry = null;
637:                    document = null;
638:                    componentsToDelete = null;
639:                    componentsToAdd = null;
640:                    componentsToUndo = null;
641:                    foldersToUpdate = null;
642:                    deletedComponentsCash = null;
643:                    foldersToExtend = null;
644:                    rootFolderWrapper = null;
645:                    ui = null;
646:                    lock = false;
647:                }
648:            }
649:
650:            private void terminateChildern(InspectorFolderWrapper fw) {
651:                if (fw.getChildren() != null) {
652:                    for (InspectorFolderWrapper child : fw.getChildren()) {
653:                        terminateChildern(child);
654:                    }
655:                }
656:                fw.terminate();
657:            }
658:
659:            private class RootFolder extends InspectorFolder {
660:
661:                public TypeID getTypeID() {
662:                    return new TypeID(TypeID.Kind.PRIMITIVE, ""); //NOI18N
663:                }
664:
665:                public Long getComponentID() {
666:                    return null;
667:                }
668:
669:                public Image getIcon() {
670:                    return new Image() {
671:
672:                        public void flush() {
673:                        }
674:
675:                        public Graphics getGraphics() {
676:                            return null;
677:                        }
678:
679:                        public int getHeight(ImageObserver observer) {
680:                            return 0;
681:                        }
682:
683:                        public Object getProperty(String name,
684:                                ImageObserver observer) {
685:                            return null;
686:                        }
687:
688:                        public ImageProducer getSource() {
689:                            return null;
690:                        }
691:
692:                        public int getWidth(ImageObserver observer) {
693:                            return 0;
694:                        }
695:                    };
696:                }
697:
698:                public String getDisplayName() {
699:                    return "ROOT FOLDER - SHOULD BE HIDDEN"; //NOI18N
700:                }
701:
702:                public Action[] getActions() {
703:                    return null;
704:                }
705:
706:                public NewType[] getNewTypes() {
707:                    return null;
708:                }
709:
710:                public boolean canRename() {
711:                    return false;
712:                }
713:
714:                public boolean isInside(InspectorFolderPath path,
715:                        InspectorFolder folder, DesignComponent component) {
716:                    return false;
717:                }
718:
719:                public String getName() {
720:                    return "ROOT FOLDER - SHOULD BE HIDDEN"; //NOI18N
721:                }
722:
723:                public InspectorOrderingController[] getOrderingControllers() {
724:                    return null;
725:                }
726:
727:                public String getHtmlDisplayName() {
728:                    return "ROOT FOLDER - SHOULD BE HIDDEN"; //NOI18N
729:                }
730:            }
731:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.