Source Code Cross Referenced for Folder.java in  » IDE-Netbeans » cnd » org » netbeans » modules » cnd » makeproject » api » configurations » 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 » cnd » org.netbeans.modules.cnd.makeproject.api.configurations 
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.cnd.makeproject.api.configurations;
043:
044:        import java.util.ArrayList;
045:        import java.util.Collection;
046:        import java.util.HashSet;
047:        import java.util.Iterator;
048:        import java.util.LinkedHashSet;
049:        import java.util.List;
050:        import java.util.Set;
051:        import java.util.Vector;
052:        import javax.swing.event.ChangeEvent;
053:        import javax.swing.event.ChangeListener;
054:        import org.netbeans.api.project.Project;
055:        import org.netbeans.modules.cnd.api.project.NativeFileItem;
056:        import org.netbeans.modules.cnd.api.project.NativeFileItemSet;
057:        import org.netbeans.modules.cnd.loaders.CndDataObject;
058:        import org.openide.filesystems.FileObject;
059:        import org.openide.loaders.DataObject;
060:        import org.openide.util.NbBundle;
061:
062:        public class Folder {
063:            public static final String DEFAULT_FOLDER_NAME = "f"; // NOI18N
064:            public static final String DEFAULT_FOLDER_DISPLAY_NAME = getString("NewFolderName");
065:
066:            private ConfigurationDescriptor configurationDescriptor;
067:            private final String name;
068:            private String displayName;
069:            private String sortName;
070:            private final Folder parent;
071:            private Vector items = null; // Folder or Item
072:            private Set<ChangeListener> changeListenerList = new HashSet<ChangeListener>();
073:            private final boolean projectFiles;
074:            private String id = null;
075:
076:            public Folder(ConfigurationDescriptor configurationDescriptor,
077:                    Folder parent, String name, String displayName,
078:                    boolean projectFiles) {
079:                this .configurationDescriptor = configurationDescriptor;
080:                this .parent = parent;
081:                this .name = name;
082:                this .displayName = displayName;
083:                this .projectFiles = projectFiles;
084:                this .items = new Vector();
085:                this .sortName = displayName.toLowerCase();
086:            }
087:
088:            public int size() {
089:                return items.size();
090:            }
091:
092:            public Folder getParent() {
093:                return parent;
094:            }
095:
096:            public Project getProject() {
097:                return ((MakeConfigurationDescriptor) getConfigurationDescriptor())
098:                        .getProject();
099:            }
100:
101:            public String getName() {
102:                return name;
103:            }
104:
105:            public String getSortName() {
106:                return sortName;
107:            }
108:
109:            public String getPath() {
110:                //        StringBuilder builder = new StringBuilder(getName());
111:                //        Folder parent = getParent();
112:                //        while (parent != null) {
113:                //            if (parent.getParent() != null) {
114:                //                builder.insert(0, '/'); // NOI18N
115:                //                builder.insert(0, parent.getName());
116:                //            }
117:                //            parent = parent.getParent();
118:                //        };
119:                //        return builder.toString();
120:                StringBuilder builder2 = new StringBuilder(32);
121:                reversePath(this , builder2);
122:                return builder2.toString();
123:            }
124:
125:            private void reversePath(Folder folder, StringBuilder builder) {
126:                Folder parent = folder.getParent();
127:                if (parent != null && parent.getParent() != null) {
128:                    reversePath(parent, builder);
129:                    builder.append('/'); // NOI18N
130:                }
131:                builder.append(folder.getName());
132:            }
133:
134:            public String getDisplayName() {
135:                return displayName;
136:            }
137:
138:            public void setDisplayName(String displayName) {
139:                this .displayName = displayName;
140:                configurationDescriptor.setModified();
141:                sortName = displayName.toLowerCase();
142:                getParent().reInsertElement(this );
143:            }
144:
145:            public ConfigurationDescriptor getConfigurationDescriptor() {
146:                return configurationDescriptor;
147:            }
148:
149:            public void setConfigurationDescriptor(
150:                    ConfigurationDescriptor configurationDescriptor) {
151:                this .configurationDescriptor = configurationDescriptor;
152:            }
153:
154:            public boolean isProjectFiles() {
155:                return projectFiles;
156:            }
157:
158:            public Vector getElements() {
159:                return items;
160:            }
161:
162:            public void reInsertElement(Object element) {
163:                int index = items.indexOf(element);
164:                if (index < 0)
165:                    return;
166:                items.remove(element);
167:                if (element instanceof  Folder)
168:                    insertFolderElement((Folder) element);
169:                else if (element instanceof  Item)
170:                    insertItemElement((Item) element);
171:                else
172:                    assert false;
173:                fireChangeEvent();
174:            }
175:
176:            private void insertFolderElement(Folder element) {
177:                if (!element.isProjectFiles()) {
178:                    // Insert last
179:                    items.add(element);
180:                    return;
181:                }
182:                String name1 = element.getSortName();
183:                int indexAt = items.size() - 1;
184:                while (indexAt >= 0) {
185:                    Object o = items.elementAt(indexAt);
186:                    if (!(o instanceof  Folder)) {
187:                        indexAt--;
188:                        continue;
189:                    }
190:                    if (!((Folder) o).isProjectFiles()) {
191:                        indexAt--;
192:                        continue;
193:                    }
194:                    String name2 = ((Folder) o).getSortName();
195:                    int compareRes = name1.compareTo(name2);
196:                    if (compareRes < 0) {
197:                        indexAt--;
198:                        continue;
199:                    }
200:                    break;
201:                }
202:                items.add(indexAt + 1, element);
203:            }
204:
205:            private void insertItemElement(Item element) {
206:                String name1 = ((Item) element).getSortName();
207:                int indexAt = items.size() - 1;
208:                while (indexAt >= 0) {
209:                    Object o = items.elementAt(indexAt);
210:                    if (!(o instanceof  Item)) {
211:                        //indexAt--;
212:                        break;
213:                    }
214:                    String name2 = ((Item) o).getSortName();
215:                    int compareRes = name1.compareTo(name2);
216:                    if (compareRes < 0) {
217:                        indexAt--;
218:                        continue;
219:                    }
220:                    break;
221:                }
222:                items.add(indexAt + 1, element);
223:            }
224:
225:            public void addElement(Object element) { // FIXUP: shopuld be private
226:                // Always keep the vector sorted
227:                int indexAt = -1;
228:                if (element instanceof  Item) {
229:                    insertItemElement((Item) element);
230:                } else if (element instanceof  Folder) {
231:                    insertFolderElement((Folder) element);
232:                } else {
233:                    assert false;
234:                }
235:                fireChangeEvent();
236:            }
237:
238:            public Item addItemAction(Item item) {
239:                if (addItem(item) == null) {
240:                    return null; // Nothing added
241:                }
242:                ArrayList list = new ArrayList(1);
243:                list.add(item);
244:                ((MakeConfigurationDescriptor) configurationDescriptor)
245:                        .fireFilesAdded(list);
246:                return item;
247:            }
248:
249:            public Item addItem(Item item) {
250:                if (item == null)
251:                    return null;
252:                // Check if already in project. Refresh if it's there.
253:                Item existingItem;
254:                if (isProjectFiles()
255:                        && (existingItem = ((MakeConfigurationDescriptor) configurationDescriptor)
256:                                .findProjectItemByPath(item.getPath())) != null) {
257:                    //System.err.println("Folder - addItem - item ignored, already added: " + item); // NOI18N  // FIXUP: correct?
258:                    refresh(existingItem);
259:                    return null; // Nothing added
260:                }
261:                // Add it to the folder
262:                item.setFolder(this );
263:                addElement(item);
264:
265:                // Add item to the dataObject's lookup
266:                if (isProjectFiles()) {
267:                    // item.getLastDataObject() should be inited in method item.setFolder(this);
268:                    if (item.getLastDataObject() instanceof  CndDataObject) {
269:                        CndDataObject dataObject = (CndDataObject) item
270:                                .getLastDataObject();
271:                        MyNativeFileItemSet myNativeFileItemSet = (MyNativeFileItemSet) dataObject
272:                                .getCookie(MyNativeFileItemSet.class);
273:                        if (myNativeFileItemSet == null) {
274:                            myNativeFileItemSet = new MyNativeFileItemSet();
275:                            dataObject.addCookie(myNativeFileItemSet);
276:                        }
277:                        myNativeFileItemSet.add(item);
278:                    }
279:                }
280:
281:                // Add it to project Items
282:                if (isProjectFiles()) {
283:                    ((MakeConfigurationDescriptor) configurationDescriptor)
284:                            .addProjectItem(item);
285:                    // Add configuration to all configurations
286:                    if (configurationDescriptor.getConfs() == null)
287:                        return item;
288:                    Configuration[] configurations = configurationDescriptor
289:                            .getConfs().getConfs();
290:                    for (int i = 0; i < configurations.length; i++) {
291:                        FolderConfiguration folderConfiguration = getFolderConfiguration(configurations[i]);
292:                        configurations[i].addAuxObject(new ItemConfiguration(
293:                                configurations[i], item));
294:                    }
295:                }
296:
297:                return item;
298:            }
299:
300:            public void addFolder(Folder folder) {
301:                addElement(folder);
302:                if (isProjectFiles()) {
303:                    // Add configuration to all configurations
304:                    if (configurationDescriptor.getConfs() == null)
305:                        return;
306:                    Configuration[] configurations = configurationDescriptor
307:                            .getConfs().getConfs();
308:                    for (int i = 0; i < configurations.length; i++) {
309:                        folder.getFolderConfiguration(configurations[i]);
310:                    }
311:                }
312:            }
313:
314:            /**
315:             * Returns an unique id (String) used to retrive this object from the
316:             * pool of aux objects
317:             */
318:            public String getId() {
319:                if (id == null) {
320:                    id = "f-" + getPath(); // NOI18N
321:                }
322:                return id;
323:            }
324:
325:            public FolderConfiguration getFolderConfiguration(
326:                    Configuration configuration) {
327:                FolderConfiguration folderConfiguration = null;
328:                if (isProjectFiles()) {
329:                    String id = getId();
330:                    folderConfiguration = (FolderConfiguration) configuration
331:                            .getAuxObject(getId());
332:                    if (folderConfiguration == null) {
333:                        CCompilerConfiguration parentCCompilerConfiguration;
334:                        CCCompilerConfiguration parentCCCompilerConfiguration;
335:                        FolderConfiguration parentFolderConfiguration = null;
336:                        if (getParent() != null)
337:                            parentFolderConfiguration = getParent()
338:                                    .getFolderConfiguration(configuration);
339:                        if (parentFolderConfiguration != null) {
340:                            parentCCompilerConfiguration = parentFolderConfiguration
341:                                    .getCCompilerConfiguration();
342:                            parentCCCompilerConfiguration = parentFolderConfiguration
343:                                    .getCCCompilerConfiguration();
344:                        } else {
345:                            parentCCompilerConfiguration = ((MakeConfiguration) configuration)
346:                                    .getCCompilerConfiguration();
347:                            parentCCCompilerConfiguration = ((MakeConfiguration) configuration)
348:                                    .getCCCompilerConfiguration();
349:                        }
350:                        folderConfiguration = new FolderConfiguration(
351:                                configuration, parentCCompilerConfiguration,
352:                                parentCCCompilerConfiguration, this );
353:                        configuration.addAuxObject(folderConfiguration);
354:                    }
355:                }
356:                return folderConfiguration;
357:            }
358:
359:            public Folder addNewFolder(boolean projectFiles) {
360:                String name;
361:                String displayName;
362:                for (int i = 1;; i++) {
363:                    name = DEFAULT_FOLDER_NAME + i;
364:                    displayName = DEFAULT_FOLDER_DISPLAY_NAME + " " + i; // NOI18N
365:                    if (findFolderByName(name) == null)
366:                        break;
367:                }
368:                return addNewFolder(name, displayName, projectFiles); // NOI18N
369:            }
370:
371:            public Folder addNewFolder(String name, String displayName,
372:                    boolean projectFiles) {
373:                Folder newFolder = new Folder(getConfigurationDescriptor(),
374:                        this , name, displayName, projectFiles);
375:                addFolder(newFolder);
376:                return newFolder;
377:            }
378:
379:            public boolean removeItemAction(Item item) {
380:                ArrayList list = new ArrayList(1);
381:                list.add(item);
382:                if (isProjectFiles())
383:                    ((MakeConfigurationDescriptor) configurationDescriptor)
384:                            .fireFilesRemoved(list);
385:                return removeItem(item);
386:            }
387:
388:            public void renameItemAction(String oldPath, Item newItem) {
389:                ((MakeConfigurationDescriptor) configurationDescriptor)
390:                        .fireFileRenamed(oldPath, newItem);
391:            }
392:
393:            public boolean removeItem(Item item) {
394:                boolean ret = false;
395:                if (item == null)
396:                    return false;
397:                // Remove it from folder
398:                ret = items.removeElement(item);
399:                if (!ret)
400:                    return ret;
401:
402:                // Remove item from the dataObject's lookup
403:                if (isProjectFiles()) {
404:                    DataObject dataObject = item.getDataObject();
405:                    if (dataObject == null) {
406:                        // try to use last Data Object (getDataObject() cannot find renamed data object)
407:                        dataObject = item.getLastDataObject();
408:                    }
409:                    if (dataObject instanceof  CndDataObject) {
410:                        CndDataObject cndDataObject = (CndDataObject) dataObject;
411:                        MyNativeFileItemSet myNativeFileItemSet = (MyNativeFileItemSet) cndDataObject
412:                                .getCookie(MyNativeFileItemSet.class);
413:                        if (myNativeFileItemSet != null) {
414:                            myNativeFileItemSet.remove(item);
415:                            if (myNativeFileItemSet.isEmpty())
416:                                cndDataObject.removeCookie(myNativeFileItemSet);
417:                        }
418:                    }
419:                }
420:
421:                //	item.setFolder(null);
422:                if (isProjectFiles()) {
423:                    // Remove it from project Items
424:                    ((MakeConfigurationDescriptor) configurationDescriptor)
425:                            .removeProjectItem(item);
426:                    // Remove it form all configurations
427:                    Configuration[] configurations = configurationDescriptor
428:                            .getConfs().getConfs();
429:                    for (int i = 0; i < configurations.length; i++)
430:                        configurations[i]
431:                                .removeAuxObject(item.getId()/*ItemConfiguration.getId(item.getPath())*/);
432:                }
433:                item.removePropertyChangeListener();
434:                item.setFolder(null);
435:                fireChangeEvent();
436:                return ret;
437:            }
438:
439:            public boolean removeItemByPath(String path) {
440:                boolean ret = false;
441:                Item item = findItemByPath(path);
442:                return removeItem(item);
443:            }
444:
445:            public boolean removeFolderAction(Folder folder) {
446:                ((MakeConfigurationDescriptor) configurationDescriptor)
447:                        .fireFilesRemoved(folder.getAllItemsAsList());
448:                return removeFolder(folder);
449:            }
450:
451:            public boolean removeFolder(Folder folder) {
452:                boolean ret = false;
453:                if (folder != null) {
454:                    folder.removeAll();
455:                    ret = items.removeElement(folder);
456:                    if (isProjectFiles()) {
457:                        // Remove it form all configurations
458:                        Configuration[] configurations = configurationDescriptor
459:                                .getConfs().getConfs();
460:                        for (int i = 0; i < configurations.length; i++)
461:                            configurations[i].removeAuxObject(folder.getId());
462:                    }
463:                }
464:                if (ret)
465:                    fireChangeEvent();
466:                return ret;
467:            }
468:
469:            /**
470:             * Remove all items and folders recursively
471:             */
472:            public void removeAll() {
473:                Item[] itemsToRemove = getItemsAsArray();
474:                Folder[] foldersToRemove = getFoldersAsArray();
475:                for (int i = 0; i < itemsToRemove.length; i++)
476:                    removeItem(itemsToRemove[i]);
477:                for (int i = 0; i < foldersToRemove.length; i++)
478:                    removeFolder(foldersToRemove[i]);
479:            }
480:
481:            public void reset() {
482:                items = new Vector();
483:                fireChangeEvent();
484:            }
485:
486:            public Item findItemByPath(String path) {
487:                if (path == null)
488:                    return null;
489:                Item[] items = getItemsAsArray();
490:                for (int i = 0; i < items.length; i++) {
491:                    if (path.equals(items[i].getPath()))
492:                        return items[i];
493:                }
494:                return null;
495:            }
496:
497:            public Folder findFolderByName(String name) {
498:                if (name == null)
499:                    return null;
500:                Folder[] folders = getFoldersAsArray();
501:                for (int i = 0; i < folders.length; i++) {
502:                    if (name.equals(folders[i].getName()))
503:                        return folders[i];
504:                }
505:                return null;
506:            }
507:
508:            public Folder findFolderByDisplayName(String name) {
509:                if (name == null)
510:                    return null;
511:                Folder[] folders = getFoldersAsArray();
512:                for (int i = 0; i < folders.length; i++) {
513:                    if (name.equals(folders[i].getDisplayName()))
514:                        return folders[i];
515:                }
516:                return null;
517:            }
518:
519:            public Folder findFolderByPath(String path) {
520:                int i = path.indexOf('/');
521:                if (i >= 0) {
522:                    String name = path.substring(0, i);
523:                    Folder folder = findFolderByName(name);
524:                    if (folder == null)
525:                        return null;
526:                    return folder.findFolderByPath(path.substring(i + 1));
527:                } else
528:                    return findFolderByName(path);
529:            }
530:
531:            public Item[] getItemsAsArray() {
532:                Vector found = new Vector();
533:                Iterator iter = new ArrayList(getElements()).iterator();
534:                while (iter.hasNext()) {
535:                    Object o = iter.next();
536:                    if (o instanceof  Item)
537:                        found.add(o);
538:                }
539:                return (Item[]) found.toArray(new Item[found.size()]);
540:            }
541:
542:            public List getAllItemsAsList() {
543:                ArrayList found = new ArrayList();
544:                Iterator iter = new ArrayList(getElements()).iterator();
545:                while (iter.hasNext()) {
546:                    Object o = iter.next();
547:                    if (o instanceof  Item)
548:                        found.add(o);
549:                    if (o instanceof  Folder) {
550:                        List items = ((Folder) o).getAllItemsAsList();
551:                        found.addAll(items);
552:                    }
553:                }
554:                return found;
555:            }
556:
557:            public Item[] getAllItemsAsArray() {
558:                List list = getAllItemsAsList();
559:                return (Item[]) list.toArray(new Item[list.size()]);
560:            }
561:
562:            /*
563:             * Returns a set of all files in this logical folder as FileObjetc's
564:             */
565:            public Set/*<FileObject>*/getItemsAsFileObjectSet() {
566:                Vector files = new Vector();
567:                Iterator iter = new ArrayList(getElements()).iterator();
568:                while (iter.hasNext()) {
569:                    Item item = (Item) iter.next();
570:                    if (item instanceof  Item) {
571:                        FileObject fo = item.getFileObject();
572:                        if (fo != null)
573:                            files.add(fo);
574:                    }
575:                }
576:                return new LinkedHashSet(files);
577:            }
578:
579:            /*
580:             * Returns a set of all files in this logical folder and subfolders as FileObjetc's
581:             */
582:            public Set/*<FileObject>*/getAllItemsAsFileObjectSet(
583:                    boolean projectFilesOnly) {
584:                Vector files = new Vector();
585:
586:                if (!projectFilesOnly || isProjectFiles()) {
587:                    Iterator iter = new ArrayList(getElements()).iterator();
588:                    while (iter.hasNext()) {
589:                        Object item = iter.next();
590:                        if (item instanceof  Item) {
591:                            FileObject fo = ((Item) item).getFileObject();
592:                            if (fo != null)
593:                                files.add(fo);
594:                        }
595:                        if (item instanceof  Folder) {
596:                            files
597:                                    .addAll(((Folder) item)
598:                                            .getAllItemsAsFileObjectSet(projectFilesOnly));
599:                        }
600:                    }
601:                }
602:
603:                return new LinkedHashSet(files);
604:            }
605:
606:            /*
607:             * Returns a set of all files in this logical folder as FileObjetc's
608:             */
609:            public Set/*<DataObject>*/getItemsAsDataObjectSet(
610:                    String MIMETypeFilter) {
611:                Vector files = new Vector();
612:                Iterator iter = new ArrayList(getElements()).iterator();
613:                while (iter.hasNext()) {
614:                    Item item = (Item) iter.next();
615:                    if (item instanceof  Item) {
616:                        DataObject da = item.getDataObject();
617:                        if (da != null
618:                                && (MIMETypeFilter == null || da
619:                                        .getPrimaryFile().getMIMEType()
620:                                        .contains(MIMETypeFilter)))
621:                            files.add(da);
622:                    }
623:                }
624:                return new LinkedHashSet(files);
625:            }
626:
627:            /*
628:             * Returns a set of all files in this logical folder and subfolders as FileObjetc's
629:             */
630:            public Set/*<DataObject>*/getAllItemsAsDataObjectSet(
631:                    boolean projectFilesOnly, String MIMETypeFilter) {
632:                Vector files = new Vector();
633:
634:                if (!projectFilesOnly || isProjectFiles()) {
635:                    Iterator iter = new ArrayList(getElements()).iterator();
636:                    while (iter.hasNext()) {
637:                        Object item = iter.next();
638:                        if (item instanceof  Item) {
639:                            DataObject da = ((Item) item).getDataObject();
640:                            if (da != null
641:                                    && (MIMETypeFilter == null || da
642:                                            .getPrimaryFile().getMIMEType()
643:                                            .contains(MIMETypeFilter)))
644:                                files.add(da);
645:                        }
646:                        if (item instanceof  Folder) {
647:                            files.addAll(((Folder) item)
648:                                    .getAllItemsAsDataObjectSet(
649:                                            projectFilesOnly, MIMETypeFilter));
650:                        }
651:                    }
652:                }
653:
654:                return new LinkedHashSet(files);
655:            }
656:
657:            public String[] getItemNamesAsArray() {
658:                Item[] items = getItemsAsArray();
659:                String[] names = new String[items.length];
660:                for (int i = 0; i < items.length; i++)
661:                    names[i] = items[i].getPath();
662:                return names;
663:            }
664:
665:            /*
666:             * Returns a set of all logical folder in this folder as an array
667:             */
668:            public Folder[] getFoldersAsArray() {
669:                Vector folders = getFolders();
670:                return (Folder[]) folders.toArray(new Folder[folders.size()]);
671:            }
672:
673:            /*
674:             * Returns a set of all logical folder in this folder
675:             */
676:            public Vector getFolders() {
677:                Vector folders = new Vector();
678:                Iterator iter = new ArrayList(getElements()).iterator();
679:                while (iter.hasNext()) {
680:                    Object item = iter.next();
681:                    if (item instanceof  Folder) {
682:                        folders.add(item);
683:                    }
684:                }
685:                return folders;
686:            }
687:
688:            /*
689:             * Returns a set of all logical folder and subfolders in this folder
690:             */
691:            public Vector getAllFolders(boolean projectFilesOnly) {
692:                Vector folders = new Vector();
693:
694:                if (!projectFilesOnly || isProjectFiles()) {
695:                    Iterator iter = new ArrayList(getElements()).iterator();
696:                    while (iter.hasNext()) {
697:                        Object item = iter.next();
698:                        if (item instanceof  Folder) {
699:                            if (!projectFilesOnly
700:                                    || ((Folder) item).isProjectFiles()) {
701:                                folders.add(item);
702:                                folders.addAll(((Folder) item)
703:                                        .getAllFolders(projectFilesOnly));
704:                            }
705:                        }
706:                    }
707:                }
708:
709:                return folders;
710:            }
711:
712:            public String[] getFolderNamesAsArray() {
713:                Folder[] items = getFoldersAsArray();
714:                String[] names = new String[items.length];
715:                for (int i = 0; i < items.length; i++)
716:                    names[i] = items[i].getName();
717:                return names;
718:            }
719:
720:            public void addChangeListener(ChangeListener cl) {
721:                synchronized (changeListenerList) {
722:                    changeListenerList.add(cl);
723:                }
724:            }
725:
726:            public void removeChangeListener(ChangeListener cl) {
727:                synchronized (changeListenerList) {
728:                    changeListenerList.remove(cl);
729:                }
730:            }
731:
732:            public void refresh() {
733:                fireChangeEvent(this );
734:            }
735:
736:            public void refresh(Object source) {
737:                fireChangeEvent(source);
738:            }
739:
740:            public void fireChangeEvent() {
741:                fireChangeEvent(this );
742:            }
743:
744:            public void fireChangeEvent(Object source) {
745:                Iterator it;
746:
747:                synchronized (changeListenerList) {
748:                    it = new HashSet(changeListenerList).iterator();
749:                }
750:                ChangeEvent ev = new ChangeEvent(source);
751:                while (it.hasNext()) {
752:                    ((ChangeListener) it.next()).stateChanged(ev);
753:                }
754:                configurationDescriptor.setModified();
755:            }
756:
757:            static private class MyNativeFileItemSet implements 
758:                    NativeFileItemSet {
759:                private List<NativeFileItem> items = new ArrayList<NativeFileItem>(
760:                        1);
761:
762:                public synchronized Collection<NativeFileItem> getItems() {
763:                    return new ArrayList<NativeFileItem>(items);
764:                }
765:
766:                public synchronized void add(NativeFileItem item) {
767:                    if (!items.contains(item)) {
768:                        items.add(item);
769:                    }
770:                }
771:
772:                public synchronized void remove(NativeFileItem item) {
773:                    items.remove(item);
774:                }
775:
776:                public boolean isEmpty() {
777:                    return items.isEmpty();
778:                }
779:            }
780:
781:            /** Look up i18n strings here */
782:            private static String getString(String s) {
783:                return NbBundle.getMessage(Folder.class, s);
784:            }
785:        }
w__ww_.__ja__v_a___2s_.__co___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.