Source Code Cross Referenced for ProjectsRootNode.java in  » IDE-Netbeans » collab » org » netbeans » modules » collab » channel » filesharing » ui » 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 » collab » org.netbeans.modules.collab.channel.filesharing.ui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003:         *
0004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005:         *
0006:         * The contents of this file are subject to the terms of either the GNU
0007:         * General Public License Version 2 only ("GPL") or the Common
0008:         * Development and Distribution License("CDDL") (collectively, the
0009:         * "License"). You may not use this file except in compliance with the
0010:         * License. You can obtain a copy of the License at
0011:         * http://www.netbeans.org/cddl-gplv2.html
0012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013:         * specific language governing permissions and limitations under the
0014:         * License.  When distributing the software, include this License Header
0015:         * Notice in each file and include the License file at
0016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
0017:         * particular file as subject to the "Classpath" exception as provided
0018:         * by Sun in the GPL Version 2 section of the License file that
0019:         * accompanied this code. If applicable, add the following below the
0020:         * License Header, with the fields enclosed by brackets [] replaced by
0021:         * your own identifying information:
0022:         * "Portions Copyrighted [year] [name of copyright owner]"
0023:         *
0024:         * Contributor(s):
0025:         *
0026:         * The Original Software is NetBeans. The Initial Developer of the Original
0027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
0028:         * Microsystems, Inc. All Rights Reserved.
0029:         *
0030:         * If you wish your version of this file to be governed by only the CDDL
0031:         * or only the GPL Version 2, indicate your decision by adding
0032:         * "[Contributor] elects to include this software in this distribution
0033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034:         * single choice of license, a recipient has the option to distribute
0035:         * your version of this file under either the CDDL, the GPL Version 2 or
0036:         * to extend the choice of license to its licensees as provided above.
0037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
0038:         * Version 2 license, then the option applies only if the new code is
0039:         * made subject to such option by the copyright holder.
0040:         */
0041:        package org.netbeans.modules.collab.channel.filesharing.ui;
0042:
0043:        import com.sun.collablet.CollabException;
0044:        import com.sun.collablet.Conversation;
0045:        import java.lang.reflect.InvocationTargetException;
0046:
0047:        import org.openide.DialogDisplayer;
0048:        import org.openide.ErrorManager;
0049:        import org.openide.NotifyDescriptor;
0050:        import org.openide.actions.PasteAction;
0051:        import org.openide.filesystems.*;
0052:        import org.openide.loaders.*;
0053:        import org.openide.nodes.AbstractNode;
0054:        import org.openide.nodes.Children;
0055:        import org.openide.nodes.FilterNode;
0056:        import org.openide.nodes.Index;
0057:        import org.openide.nodes.Node;
0058:        import org.openide.nodes.NodeTransfer;
0059:        import org.openide.util.*;
0060:        import org.openide.util.Utilities;
0061:        import org.openide.util.actions.SystemAction;
0062:        import org.openide.util.datatransfer.PasteType;
0063:        import org.openide.xml.XMLUtil;
0064:
0065:        import java.awt.Cursor;
0066:        import java.awt.Image;
0067:        import java.awt.datatransfer.Transferable;
0068:
0069:        import java.beans.*;
0070:
0071:        import java.io.*;
0072:
0073:        import java.util.ArrayList;
0074:        import java.util.HashMap;
0075:        import java.util.List;
0076:
0077:        import javax.swing.Action;
0078:        import javax.swing.SwingUtilities;
0079:
0080:        import org.netbeans.api.java.project.JavaProjectConstants;
0081:
0082:        import org.netbeans.api.project.FileOwnerQuery;
0083:        import org.netbeans.api.project.Project;
0084:        import org.netbeans.api.project.ProjectInformation;
0085:        import org.netbeans.api.project.ProjectManager;
0086:        import org.netbeans.api.project.ProjectUtils;
0087:        import org.netbeans.api.project.SourceGroup;
0088:        import org.netbeans.api.project.Sources;
0089:        import org.netbeans.api.project.ui.OpenProjects;
0090:
0091:        import org.netbeans.modules.collab.channel.filesharing.FilesharingCollablet;
0092:        import org.netbeans.modules.collab.channel.filesharing.FilesharingConstants;
0093:        import org.netbeans.modules.collab.channel.filesharing.FilesharingContext;
0094:        import org.netbeans.modules.collab.channel.filesharing.FilesharingEventNotifierFactory;
0095:        import org.netbeans.modules.collab.channel.filesharing.FilesharingEventProcessorFactory;
0096:        import org.netbeans.modules.collab.channel.filesharing.context.ProjectContext;
0097:        import org.netbeans.modules.collab.channel.filesharing.event.DeleteFileEvent;
0098:        import org.netbeans.modules.collab.channel.filesharing.event.ProjectActionListEvent;
0099:        import org.netbeans.modules.collab.channel.filesharing.event.RenameFileEvent;
0100:        import org.netbeans.modules.collab.channel.filesharing.eventlistener.FilesharingTimerTask;
0101:        import org.netbeans.modules.collab.channel.filesharing.eventlistener.ProjectActionListTimerTask;
0102:        import org.netbeans.modules.collab.channel.filesharing.filehandler.CollabFileHandler;
0103:        import org.netbeans.modules.collab.channel.filesharing.filesystem.CollabFilesystem;
0104:        import org.netbeans.modules.collab.channel.filesharing.mdc.CollabEvent;
0105:        import org.netbeans.modules.collab.channel.filesharing.mdc.EventContext;
0106:        import org.netbeans.modules.collab.channel.filesharing.mdc.EventNotifier;
0107:        import org.netbeans.modules.collab.channel.filesharing.mdc.EventProcessor;
0108:        import org.netbeans.modules.collab.channel.filesharing.projecthandler.SharedProject;
0109:        import org.netbeans.modules.collab.channel.filesharing.projecthandler.SharedProjectFactory;
0110:        import org.netbeans.modules.collab.channel.filesharing.ui.actions.CollabProjectAction;
0111:        import org.netbeans.modules.collab.channel.filesharing.ui.actions.CreateNonProjectAction;
0112:        import org.netbeans.modules.collab.channel.filesharing.ui.actions.ProjectAction;
0113:        import org.netbeans.modules.collab.channel.filesharing.util.FileshareUtil;
0114:        import org.netbeans.modules.collab.core.Debug;
0115:
0116:        import org.netbeans.spi.project.ui.LogicalViewProvider;
0117:
0118:        /**
0119:         *
0120:         * @author  Ayub Khan, ayub.khan@sun.com
0121:         */
0122:        public class ProjectsRootNode extends AbstractNode implements 
0123:                FilesharingConstants {
0124:            ////////////////////////////////////////////////////////////////////////////
0125:            // Class variables
0126:            ////////////////////////////////////////////////////////////////////////////
0127:            public static final String URL_SHARE_JAVA_NET = "share.java.net:5222"; //NoI18n
0128:            public static final Image PROJECTS_ROOT_BADGE = Utilities
0129:                    .loadImage(
0130:                            "org/netbeans/modules/collab/channel/filesharing/resources/project_png.gif",
0131:                            true); // NOI18N
0132:            public static final Image GROUP_BADGE = Utilities.loadImage(
0133:                    "org/netbeans/modules/collab/ui/resources/group_png.gif",
0134:                    true); // NOI18N
0135:            public static final List NON_SHAREABLE_NODE_PATTERNS = new ArrayList();
0136:
0137:            static {
0138:                NON_SHAREABLE_NODE_PATTERNS.add("jar:file:/");
0139:            }
0140:
0141:            ////////////////////////////////////////////////////////////////////////////
0142:            // Instance variables
0143:            ////////////////////////////////////////////////////////////////////////////
0144:            FileSystem n_filesystem;
0145:            FileObject rootFile;
0146:            String loginUser = null;
0147:            FilesharingContext context;
0148:
0149:            public ProjectsRootNode(FileSystem filesystem) {
0150:                super (new Index.ArrayChildren());
0151:
0152:                String name = NbBundle.getMessage(ProjectsRootNode.class,
0153:                        "LBL_ProjectsRootNode_DisplayName");
0154:                setName(name);
0155:                setDisplayName(name);
0156:                n_filesystem = filesystem;
0157:                this .context = ((CollabFilesystem) n_filesystem).getContext();
0158:                loginUser = getContext().getLoginUser();
0159:            }
0160:
0161:            public Action[] getActions(boolean context) {
0162:                if (getContext().isReadOnlyConversation()) {
0163:                    return new SystemAction[] {};
0164:                } else {
0165:                    return new SystemAction[] {
0166:                            new CreateNonProjectAction(getContext(), this ),
0167:                            null, SystemAction.get(PasteAction.class) };
0168:                }
0169:            }
0170:
0171:            public Image getIcon(int type) {
0172:                return computeIcon(false, type);
0173:            }
0174:
0175:            public Image getOpenedIcon(int type) {
0176:                return computeIcon(true, type);
0177:            }
0178:
0179:            private Image computeIcon(boolean opened, int type) {
0180:                //return Utilities.mergeImages(PROJECTS_ROOT_BADGE, GROUP_BADGE, 7, 7);
0181:                //New icons for filesharing
0182:                Image image = Utilities
0183:                        .loadImage(
0184:                                "org/netbeans/modules/collab/channel/filesharing/resources/filesharing_png.gif",
0185:                                true); // NOI18N
0186:
0187:                return image;
0188:            }
0189:
0190:            private FilesharingContext getContext() {
0191:                return this .context;
0192:            }
0193:
0194:            private static boolean strContains(String str, String pattern) {
0195:                return str.indexOf(pattern) != -1;
0196:            }
0197:
0198:            private DataObject[] getDragDataObjects(Node[] dragNodes,
0199:                    List dragDataObjects) {
0200:                boolean skipProjectFolder = false;
0201:
0202:                if ((dragNodes != null) && (dragNodes.length == 1)) {
0203:                    DataObject d = (DataObject) dragNodes[0]
0204:                            .getCookie(DataObject.class);
0205:
0206:                    if ((d != null)
0207:                            && (d.getPrimaryFile() != null)
0208:                            && d.getPrimaryFile().isFolder()
0209:                            && ProjectManager.getDefault().isProject(
0210:                                    d.getPrimaryFile())) {
0211:                        skipProjectFolder = true;
0212:                    }
0213:                }
0214:
0215:                return getDragDataObjects(dragNodes, dragDataObjects,
0216:                        skipProjectFolder);
0217:            }
0218:
0219:            private DataObject[] getDragDataObjects(Node[] dragNodes,
0220:                    List dragDataObjects, boolean skipProjectFolder) {
0221:                Debug.out.println("ProjectsRootNode, getDragDataObjects: "
0222:                        + dragNodes.length);
0223:
0224:                if (dragNodes != null) {
0225:                    if ((dragNodes.length == 1) && !skipNode(dragNodes[0])) //now find all dataobject, including sub dataobjects
0226:                    {
0227:                        if (dragNodes[0].isLeaf()
0228:                                || (dragNodes[0].getCookie(DataObject.class) != null)) {
0229:                            Debug.out
0230:                                    .println("leaf: " + dragNodes[0].getName());
0231:
0232:                            DataObject d = (DataObject) dragNodes[0]
0233:                                    .getCookie(DataObject.class);
0234:
0235:                            if ((d != null) && (d.getPrimaryFile() != null)) //a file or folder
0236:                            {
0237:                                Debug.out.println("leaf a file/folder: "
0238:                                        + d.getName());
0239:
0240:                                if (d.getPrimaryFile().isData()
0241:                                        || strContains(dragNodes[0].getName(),
0242:                                                "jar:file:/")) { //a file
0243:                                    Debug.out.println("leaf a file: "
0244:                                            + d.getName());
0245:
0246:                                    if (!dragDataObjects.contains(d)) {
0247:                                        dragDataObjects.add(d);
0248:                                    }
0249:                                } else //a folder
0250:                                {
0251:                                    Debug.out.println("leaf a folder: "
0252:                                            + d.getName());
0253:                                    getChildren(d.getPrimaryFile(),
0254:                                            dragDataObjects, skipProjectFolder);
0255:                                }
0256:                            } else {
0257:                                Debug.out.println("leaf not a file/folder: "
0258:                                        + d);
0259:                            }
0260:                        } else {
0261:                            Debug.out.println("non leaf: "
0262:                                    + dragNodes[0].getName());
0263:                            getDragDataObjects(dragNodes[0].getChildren()
0264:                                    .getNodes(), dragDataObjects,
0265:                                    skipProjectFolder);
0266:                        }
0267:                    } else {
0268:                        //find atleast a node that has a dataobject in the dragnodes
0269:                        for (int i = 0; i < dragNodes.length; i++) {
0270:                            Debug.out.println("a folder: "
0271:                                    + dragNodes[i].getName());
0272:
0273:                            if (!(skipNode(dragNodes[i]) || dragNodes[i]
0274:                                    .getName().equals("important.files"))) {
0275:                                getDragDataObjects(new Node[] { dragNodes[i] },
0276:                                        dragDataObjects, skipProjectFolder);
0277:                            }
0278:                        }
0279:                    }
0280:                }
0281:
0282:                return (DataObject[]) dragDataObjects
0283:                        .toArray(new DataObject[0]);
0284:            }
0285:
0286:            private void getChildren(FileObject fObj, List dragDataObjects,
0287:                    boolean skipProjectFolder) {
0288:                Debug.out.println("In getChildren: ");
0289:
0290:                FileObject[] childs = fObj.getChildren();
0291:
0292:                for (int i = 0; i < childs.length; i++) {
0293:                    if (isVCSFile(childs[i]) || //skip VCS files
0294:                            childs[i].getNameExt().startsWith(".")) { //skip hidden files
0295:
0296:                        continue;
0297:                    }
0298:
0299:                    Debug.out.println("getChildren: [" + childs[i].getNameExt()
0300:                            + "] a file: " + childs[i].isData());
0301:
0302:                    if (childs[i].isData()) {
0303:                        try {
0304:                            DataObject d = DataObject.find(childs[i]);
0305:
0306:                            if (d.getPrimaryFile().isData()) { //a file
0307:
0308:                                if (!dragDataObjects.contains(d)) {
0309:                                    dragDataObjects.add(d);
0310:                                }
0311:                            }
0312:                        } catch (DataObjectNotFoundException ddnf) {
0313:                        }
0314:                    } else {
0315:                        if (skipProjectFolder
0316:                                && (ProjectManager.getDefault().isProject(
0317:                                        childs[i])
0318:                                        || childs[i].getNameExt().equals(
0319:                                                "build.xml")
0320:                                        || //NoI18n
0321:                                        childs[i].getNameExt().equals("build")
0322:                                        || //NoI18n
0323:                                        childs[i].getNameExt().equals("dist") || //NoI18n
0324:                                        childs[i].getNameExt().equals("arch") || //NoI18n
0325:                                childs[i].getNameExt().equals("nbproject")) //NoI18n
0326:                        ) {
0327:                            continue;
0328:                        }
0329:
0330:                        getChildren(childs[i], dragDataObjects,
0331:                                skipProjectFolder);
0332:                    }
0333:                }
0334:            }
0335:
0336:            private boolean isVCSFile(FileObject fObj) {
0337:                String VSS_IGNORE_FILE = "vssver.scc"; //defined in org.netbeans.modules.vcs.profiles.vss.list.VssListCommand.IGNORED_FILE
0338:                String CVS_IGNORE_FILE = "CVS";
0339:                String SCCS_IGNORE_FILE = "SCCS";
0340:                String RCS_IGNORE_FILE = "RCS";
0341:                String fileName = fObj.getNameExt();
0342:
0343:                if (CVS_IGNORE_FILE.equalsIgnoreCase(fileName)
0344:                        || VSS_IGNORE_FILE.equalsIgnoreCase(fileName)
0345:                        || SCCS_IGNORE_FILE.equalsIgnoreCase(fileName)
0346:                        || RCS_IGNORE_FILE.equalsIgnoreCase(fileName)) {
0347:                    return true;
0348:                } else {
0349:                    return false;
0350:                }
0351:            }
0352:
0353:            private Project findShareableProject(FileObject file) {
0354:                Project[] projects = OpenProjects.getDefault()
0355:                        .getOpenProjects();
0356:
0357:                for (int i = 0; i < projects.length; i++) {
0358:                    Project project = projects[i];
0359:                    Debug.log("ProjectsRootNode", "ProjectsRootNode, projects["
0360:                            + i + "]: " + project);
0361:
0362:                    Project prj = FileOwnerQuery.getOwner(file);
0363:
0364:                    if ((prj != null)
0365:                            && prj.getProjectDirectory().getPath().equals(
0366:                                    project.getProjectDirectory().getPath())) {
0367:                        return project; //match found
0368:                    }
0369:                }
0370:
0371:                return null;
0372:            }
0373:
0374:            private String getProjectName(Project project) {
0375:                String projectName = null;
0376:
0377:                if (project != null) {
0378:                    ProjectInformation info = ProjectUtils
0379:                            .getInformation(project);
0380:                    projectName = info.getDisplayName();
0381:                    Debug.log("ProjectsRootNode",
0382:                            "ProjectsRootNode, Project name: "
0383:                                    + info.getDisplayName());
0384:                    Debug.log("ProjectsRootNode",
0385:                            "ProjectsRootNode, Project id: " + info.getName());
0386:                }
0387:
0388:                return projectName;
0389:            }
0390:
0391:            /*
0392:             * createProjectNode
0393:             *
0394:             * @param nodes
0395:             */
0396:            public void createProjectNode(Node[] nue) throws CollabException {
0397:                setVisibleWaitCursor(true);
0398:
0399:                //do actual work here
0400:                doCreateProjectNode(nue, null, null);
0401:
0402:                setVisibleWaitCursor(false);
0403:            }
0404:
0405:            private void setVisibleWaitCursor(boolean visible) {
0406:                Debug.out.println("In setVisibleWaitCursor: " + visible);
0407:
0408:                FilesystemExplorerPanel panel = getContext()
0409:                        .getFilesystemExplorer();
0410:
0411:                if (panel != null) {
0412:                    if (visible) {
0413:                        String message = NbBundle.getMessage(
0414:                                FilesystemExplorerPanel.class,
0415:                                "LBL_FilesystemExplorerPanel_PauseMessage");
0416:                        PropertyChangeEvent event = new PropertyChangeEvent(
0417:                                this , FS_STATUS_CHANGE, message, message);
0418:                        panel.propertyChange(event);
0419:                        Debug.out.println("setting wait cursor");
0420:
0421:                        try {
0422:                            panel.setCursor(Cursor
0423:                                    .getPredefinedCursor(Cursor.WAIT_CURSOR));
0424:                        } catch (Throwable th) {
0425:                            th.printStackTrace(Debug.out);
0426:                        }
0427:                    } else {
0428:                        PropertyChangeEvent event = new PropertyChangeEvent(
0429:                                this , FS_STATUS_CHANGE, "", "");
0430:                        panel.propertyChange(event);
0431:                        Debug.out.println("unsetting wait cursor");
0432:                        panel.setCursor(null);
0433:                    }
0434:                }
0435:            }
0436:
0437:            private void doCreateProjectNode(final Node[] nue,
0438:                    String projectName, Project fromProject)
0439:                    throws CollabException {
0440:                //return if not shareable
0441:                if (checkNonShareableNodes(nue)) {
0442:                    Debug.out.println("skip node: " + nue[0].getName());
0443:
0444:                    return;
0445:                }
0446:
0447:                //find atleast a node that has a dataobject in the dragnodes
0448:                List ddList = new ArrayList();
0449:
0450:                if ((nue != null) && (nue.length == 1) && !(skipNode(nue[0]))) //process project node
0451:                {
0452:                    Project p = null;
0453:                    DataObject d1 = (DataObject) nue[0]
0454:                            .getCookie(DataObject.class);
0455:
0456:                    if ((d1 != null) && (d1.getPrimaryFile() != null)) {
0457:                        p = findShareableProject(d1.getPrimaryFile());
0458:
0459:                        if ((p == null)
0460:                                || !p.getProjectDirectory().getPath().equals(
0461:                                        d1.getPrimaryFile().getPath())) {
0462:                            p = null;
0463:                        }
0464:                    } else {
0465:                        Debug.out.println("node may not be a project");
0466:                    }
0467:
0468:                    if (p != null) {
0469:                        fromProject = p;
0470:                    }
0471:
0472:                    if (fromProject != null) {
0473:                        Debug.out.println("check sgs: ");
0474:
0475:                        Sources s = ProjectUtils.getSources(fromProject);
0476:                        SourceGroup[] sgs = s
0477:                                .getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
0478:
0479:                        for (int i = 0; i < sgs.length; i++) {
0480:                            Debug.out.println(" sgs: " + sgs[i].getName());
0481:                            Debug.out
0482:                                    .println(" sgs: " + sgs[i].getRootFolder());
0483:
0484:                            DataObject d = null;
0485:
0486:                            try {
0487:                                d = DataObject.find(sgs[i].getRootFolder());
0488:                            } catch (DataObjectNotFoundException ddnf) {
0489:                                ddnf.printStackTrace(Debug.out);
0490:                            }
0491:
0492:                            if (d != null) {
0493:                                getChildren(d.getPrimaryFile(), ddList, true);
0494:                            }
0495:                        }
0496:
0497:                        if ((ddList.size() == 0) && (d1 != null)) { //try using nodes
0498:                            ddList.add(d1);
0499:                        }
0500:                    } else { //not a project node
0501:                        getDragDataObjects(nue, ddList);
0502:                    }
0503:                } else { //nodes
0504:                    getDragDataObjects(nue, ddList);
0505:                }
0506:
0507:                final DataObject[] dragDataObjects = (DataObject[]) ddList
0508:                        .toArray(new DataObject[0]);
0509:                Debug.out.println("getDragDataObjects return length: "
0510:                        + dragDataObjects.length);
0511:
0512:                if (dragDataObjects.length == 0) {
0513:                    return;
0514:                }
0515:
0516:                //return if atleast a dataobject exceed 1MB limit for share.java.net
0517:                //this check is commented out for now
0518:
0519:                /*String serverURL=URL_SHARE_JAVA_NET;// NOI18N
0520:                Debug.out.println("serverURL: "+serverURL);
0521:                String userID=context.getConversation().getCollabSession().
0522:                                        getUserPrincipal().getIdentifier();
0523:                String userIDServerInfo=userID.split("@")[1];
0524:                Debug.out.println("userIDServerInfo: "+userIDServerInfo);
0525:                for(int i=0;i<dragDataObjects.length;i++)
0526:                {
0527:                        if(isExceedShareableSizeLimit(new DataObject[]{dragDataObjects[i]}) &&
0528:                                userIDServerInfo!=null &&
0529:                                        userIDServerInfo.contains(serverURL.split(":")[0]))//NoI18n
0530:                        {
0531:                                return;
0532:                        }
0533:                }*/
0534:                if (projectName == null) {
0535:                    projectName = SHARED_COMMON_DIR;
0536:                    fromProject = findShareableProject(dragDataObjects[0]
0537:                            .getPrimaryFile());
0538:
0539:                    if (fromProject != null) {
0540:                        projectName = getProjectName(fromProject);
0541:
0542:                        //return if project already shared
0543:                        if (!isProjectShared(fromProject)) {
0544:                            return;
0545:                        }
0546:                    }
0547:
0548:                    SharedProject sharedProject = SharedProjectFactory
0549:                            .createSharedProject(projectName, loginUser,
0550:                                    fromProject, getContext()
0551:                                            .getSharedProjectManager());
0552:                    getContext().getSharedProjectManager().addSharedProject(
0553:                            loginUser, projectName, sharedProject);
0554:                }
0555:
0556:                //now add dragnodes
0557:                final String projectNodeName = projectName;
0558:                final Project prj = fromProject;
0559:
0560:                try {
0561:                    n_filesystem.runAtomicAction(new FileSystem.AtomicAction() {
0562:                        public void run() throws IOException {
0563:                            Debug.log("ProjectsRootNode", "ProjectsRootNode, "
0564:                                    + "doAddChildren:: projectName: "
0565:                                    + projectNodeName);
0566:                            doCreateProjectNode(loginUser, projectNodeName,
0567:                                    dragDataObjects, prj);
0568:                            setVisibleWaitCursor(false);
0569:                        }
0570:                    });
0571:                } catch (IOException iox) {
0572:                    Debug.log("ProjectsRootNode",
0573:                            "ProjectsRootNode, PasteType::ex: " + iox);
0574:                    iox.printStackTrace(Debug.out);
0575:                } catch (Throwable th) {
0576:                    Debug.log("ProjectsRootNode",
0577:                            "ProjectsRootNode, PasteType::ex: " + th);
0578:                    th.printStackTrace(Debug.out);
0579:                }
0580:            }
0581:
0582:            private void showMessage(String message) {
0583:                final NotifyDescriptor descriptor = new NotifyDescriptor.Message(
0584:                        message);
0585:                SwingUtilities.invokeLater(new Runnable() {
0586:                    public void run() {
0587:                        DialogDisplayer.getDefault().notify(descriptor);
0588:                    }
0589:                });
0590:            }
0591:
0592:            private boolean checkNonShareableNodes(Node[] dragNodes) {
0593:                Debug.out.println("In checkNonShareableNodes");
0594:
0595:                List checkNodes = NON_SHAREABLE_NODE_PATTERNS;
0596:
0597:                for (int i = 0; i < dragNodes.length; i++) {
0598:                    DataObject d1 = (DataObject) dragNodes[i]
0599:                            .getCookie(DataObject.class);
0600:
0601:                    if (d1 != null) {
0602:                        String fPath = d1.getPrimaryFile().getPath();
0603:                        String rPath = getRootDir().getPath().replace('\\',
0604:                                FILE_SEPERATOR_CHAR);
0605:                        Debug.out.println("path: " + fPath);
0606:                        Debug.out.println("rpath: " + rPath);
0607:
0608:                        if (strContains(fPath, rPath)) {
0609:                            return true; //skip copy share file/folder to share area
0610:                        }
0611:                    }
0612:
0613:                    for (int j = 0; j < checkNodes.size(); j++) {
0614:                        String pattern = (String) checkNodes.get(j);
0615:
0616:                        if ((dragNodes[i] != null)
0617:                                && (dragNodes[i].getName() != null)
0618:                                && strContains(dragNodes[i].getName(), pattern)) {
0619:                            String message = NbBundle.getMessage(
0620:                                    ProjectsRootNode.class,
0621:                                    "MSG_ProjectsRootNode_CannotShareNode",
0622:                                    dragNodes[i].getDisplayName());
0623:                            showMessage(message);
0624:
0625:                            return true;
0626:                        }
0627:                    }
0628:                }
0629:
0630:                return false;
0631:            }
0632:
0633:            private boolean isExceedShareableSizeLimit(
0634:                    DataObject[] dragDataObjects) {
0635:                long totalSize = calculateSize(dragDataObjects);
0636:
0637:                if (totalSize > SHAREABLE_LIMIT) {
0638:                    String message = NbBundle.getMessage(
0639:                            ProjectsRootNode.class,
0640:                            "MSG_ProjectsRootNode_SharedFilesExceedLimit",
0641:                            dragDataObjects[0].getPrimaryFile().getNameExt(),
0642:                            URL_SHARE_JAVA_NET);
0643:                    showMessage(message);
0644:
0645:                    return true;
0646:                }
0647:
0648:                return false;
0649:            }
0650:
0651:            private long calculateSize(DataObject[] dragDataObjects) {
0652:                long totalSize = 0;
0653:
0654:                for (int i = 0; i < dragDataObjects.length; i++) {
0655:                    FileObject[] fileObjects = (FileObject[]) dragDataObjects[i]
0656:                            .files().toArray(new FileObject[0]);
0657:
0658:                    for (int j = 0; j < fileObjects.length; j++) {
0659:                        long fileSize = fileObjects[j].getSize();
0660:                        Debug.log("ProjectsRootNode",
0661:                                "ProjectsRootNode, file: "
0662:                                        + fileObjects[j].getNameExt()
0663:                                        + " size: " + fileSize);
0664:
0665:                        if ((totalSize + fileSize) >= Long.MAX_VALUE) {
0666:                            return Long.MAX_VALUE;
0667:                        }
0668:
0669:                        totalSize += fileSize;
0670:                        Debug.log("ProjectsRootNode",
0671:                                "ProjectsRootNode, totalSize: " + totalSize);
0672:                    }
0673:                }
0674:
0675:                Debug.log("ProjectsRootNode",
0676:                        "ProjectsRootNode, final totalSize: " + totalSize);
0677:
0678:                return totalSize;
0679:            }
0680:
0681:            private boolean isProjectShared(Project project) {
0682:                Conversation[] conv = FilesharingCollablet
0683:                        .getConversations(project);
0684:                boolean checkShareable = ((conv == null) || (conv.length == 0) || ((conv.length == 1) && conv[0]
0685:                        .getDisplayName().equals(
0686:                                getContext().getChannel().getConversation()
0687:                                        .getDisplayName()))) ? true : false;
0688:
0689:                if (!checkShareable) {
0690:                    String sharedConvName = ((conv != null) && (conv[0] != null)) ? conv[0]
0691:                            .getDisplayName()
0692:                            : "";
0693:                    String message = NbBundle.getMessage(
0694:                            ProjectsRootNode.class,
0695:                            "MSG_ProjectsRootNode_ProjectAlreadyShared",
0696:                            sharedConvName);
0697:                    showMessage(message);
0698:                }
0699:
0700:                return checkShareable;
0701:            }
0702:
0703:            protected void createPasteTypes(Transferable t, List ls) {
0704:                if (getContext().isReadOnlyConversation()) {
0705:                    return;
0706:                }
0707:
0708:                final Node[] ns = NodeTransfer.nodes(t, NodeTransfer.DND_COPY);
0709:
0710:                if (ns != null) {
0711:                    ls.add(new PasteType() {
0712:                        public Transferable paste() throws IOException {
0713:                            final Node[] nue = new Node[ns.length];
0714:
0715:                            for (int i = 0; i < nue.length; i++) {
0716:                                nue[i] = ns[i].cloneNode();
0717:                            }
0718:
0719:                            RequestProcessor.getDefault().post(new Runnable() {
0720:                                public void run() {
0721:                                    try {
0722:                                        createProjectNode(nue);
0723:                                    } catch (CollabException ce) {
0724:                                    }
0725:                                }
0726:                            });
0727:
0728:                            return null;
0729:                        }
0730:                    });
0731:                }
0732:
0733:                // Also try superclass, but give it lower priority:
0734:                super .createPasteTypes(t, ls);
0735:            }
0736:
0737:            /*
0738:             * init
0739:             *
0740:             */
0741:            public void init() {
0742:                Debug.out.println("PSRN init");
0743:
0744:                SharedProject[] sharedProjects = getContext()
0745:                        .getSharedProjectManager().getAllSharedProjects();
0746:
0747:                for (int i = 0; i < sharedProjects.length; i++) {
0748:                    String projectOwner = sharedProjects[i].getProjectOwner();
0749:                    String projectName = sharedProjects[i].getName();
0750:
0751:                    try {
0752:                        final Node projectNode = createProjectNode(
0753:                                projectOwner, projectName);
0754:                        final FileObject projectFolder = ((ProjectNode) projectNode)
0755:                                .getProjectDir();
0756:
0757:                        //init all child nodes
0758:                        FileSystem fs = getContext().getCollabFilesystem();
0759:                        fs.runAtomicAction(new FileSystem.AtomicAction() {
0760:                            public void run() throws IOException {
0761:                                //find atleast a node that has a dataobject in the dragnodes
0762:                                List ddList = new ArrayList();
0763:                                getChildren(projectFolder, ddList, true);
0764:
0765:                                DataObject[] dd = (DataObject[]) ddList
0766:                                        .toArray(new DataObject[0]);
0767:                                Debug.out
0768:                                        .println("getDragDataObjects return length: "
0769:                                                + dd.length);
0770:                                processPaste(projectNode, dd, null, false);
0771:                            }
0772:                        });
0773:                    } catch (IOException iox) {
0774:                        //ignore
0775:                    }
0776:                }
0777:            }
0778:
0779:            /*
0780:             * createProjectNode
0781:             *
0782:             * @param userName
0783:             * @param projectName
0784:             * @return projectNode
0785:             */
0786:            public Node createProjectNode(final String userName,
0787:                    final String projectName) throws IOException {
0788:                return doCreateProjectNode(userName, projectName, null, null);
0789:            }
0790:
0791:            /*
0792:             * doCreateProjectNode
0793:             *
0794:             * @param userName
0795:             * @param projectName
0796:             * @param dragDataObjects
0797:             * @return projectNode
0798:             */
0799:            private Node doCreateProjectNode(final String userName,
0800:                    final String projectName, DataObject[] dragDataObjects,
0801:                    Project fromProject) throws IOException {
0802:                Debug.log("ProjectsRootNode",
0803:                        "ProjectsRootNode, \n\nADDCHILD userNode(loginUser name): "
0804:                                + userName);
0805:
0806:                SharedProject sharedProject = getContext()
0807:                        .getSharedProjectManager().getSharedProject(userName,
0808:                                projectName);
0809:
0810:                if (sharedProject != null) {
0811:                    Debug.log("ProjectsRootNode",
0812:                            "ProjectsRootNode, found project: " + projectName);
0813:                } else {
0814:                    Debug.log("ProjectsRootNode",
0815:                            "ProjectsRootNode, createSharedProject: "
0816:                                    + projectName);
0817:                    sharedProject = SharedProjectFactory.createSharedProject(
0818:                            projectName, userName, null, getContext()
0819:                                    .getSharedProjectManager());
0820:                    getContext().getSharedProjectManager().addSharedProject(
0821:                            userName, projectName, sharedProject);
0822:                }
0823:
0824:                Node userNode = createUserNode(userName);
0825:
0826:                if (userNode == null) {
0827:                    Debug.log("ProjectsRootNode",
0828:                            "ProjectsRootNode, ADDCHILD:: find userNode null");
0829:
0830:                    return null;
0831:                }
0832:
0833:                //add project nodes to the userNode now
0834:                Node projectNode = addProjectNodes(userNode, projectName,
0835:                        fromProject);
0836:
0837:                if ((projectNode != null) && (dragDataObjects != null)) {
0838:                    processPaste(projectNode, dragDataObjects, fromProject,
0839:                            true);
0840:                }
0841:
0842:                return projectNode;
0843:            }
0844:
0845:            /*
0846:             * add project nodes to the userNode
0847:             *
0848:             * @param userName
0849:             */
0850:            private Node addProjectNodes(Node userNode, String projectName,
0851:                    final Project fromProject) throws IOException {
0852:                final String userName = userNode.getName();
0853:                Children children = userNode.getChildren();
0854:
0855:                if (projectName == null) {
0856:                    projectName = SHARED_COMMON_DIR;
0857:                }
0858:
0859:                if (fromProject != null) {
0860:                    LogicalViewProvider lvp = (LogicalViewProvider) fromProject
0861:                            .getLookup().lookup(LogicalViewProvider.class);
0862:                    Node[] nodes = new Node[] { lvp.createLogicalView() };
0863:                    Debug.log("ProjectsRootNode",
0864:                            "ProjectsRootNode, PRN createNodes length: "
0865:                                    + nodes.length);
0866:
0867:                    if (nodes[0].getLookup().lookup(Project.class) != fromProject) {
0868:                        // Various actions, badging, etc. are not going to work.
0869:                        ErrorManager
0870:                                .getDefault()
0871:                                .log(
0872:                                        ErrorManager.WARNING,
0873:                                        "Warning - project1 "
0874:                                                + ProjectUtils.getInformation(
0875:                                                        fromProject).getName()
0876:                                                + " failed to supply itself in the lookup of the "
0877:                                                + "root node of its own logical view"); // NOI18N
0878:                    }
0879:
0880:                    projectName = nodes[0].getDisplayName();
0881:                }
0882:
0883:                Node projectNode = children.findChild(projectName);
0884:
0885:                if (projectNode == null) {
0886:                    projectNode = new ProjectNode(projectName, userNode,
0887:                            fromProject, null);
0888:                    Debug.out
0889:                            .println("ProjectsRootNode, Created project node: "
0890:                                    + projectName);
0891:                    children.add(new Node[] { projectNode });
0892:
0893:                    final Node pNode = projectNode;
0894:                    final String pName = projectName;
0895:
0896:                    Runnable run = new Runnable() {
0897:                        public void run() {
0898:                            //get Actions from original project
0899:                            if (fromProject != null) {
0900:                                processActionsFromSharedProject(pNode,
0901:                                        fromProject);
0902:                            } else {
0903:                                SharedProject sharedProject = getContext()
0904:                                        .getSharedProjectManager()
0905:                                        .getSharedProject(userName, pName);
0906:                                processActions(pNode, sharedProject);
0907:                            }
0908:                        }
0909:                    };
0910:                    if (SwingUtilities.isEventDispatchThread()) {
0911:                        run.run();
0912:                    } else {
0913:                        try {
0914:                            SwingUtilities.invokeAndWait(run);
0915:                        } catch (InterruptedException ie) {
0916:                            // ignore
0917:                        } catch (InvocationTargetException ite) {
0918:                            ErrorManager.getDefault().notify(ite);
0919:                        }
0920:                    }
0921:                }
0922:
0923:                //create original files folder for owner
0924:                Children projectChildren = projectNode.getChildren();
0925:
0926:                if (!projectName.equals(SHARED_COMMON_DIR) && //skip creating for non project
0927:                        loginUser.equals(userName) && //skip creating for non project owner
0928:                        (projectChildren.findChild(ARCHIVE_DIR) == null)) {
0929:                    ((ProjectNode) projectNode).getChildNode(ARCHIVE_DIR);
0930:                }
0931:
0932:                return projectNode;
0933:            }
0934:
0935:            private boolean skipNode(Node childNode) {
0936:                if ((childNode == null) || (childNode.getName() == null)
0937:                        || childNode.getName().equals(LIBRARY_NODE)
0938:                        || childNode.getName().equals(TEST_LIBRARY_NODE)) {
0939:                    return true;
0940:                }
0941:
0942:                return false;
0943:            }
0944:
0945:            private FileObject getRootDir() {
0946:                if (rootFile == null) {
0947:                    rootFile = FileUtil
0948:                            .toFileObject(((CollabFilesystem) n_filesystem)
0949:                                    .getCollabRoot());
0950:                }
0951:
0952:                return rootFile;
0953:            }
0954:
0955:            private Node createUserNode(String userName) {
0956:                Node userNode = new UserNode(userName);
0957:                Debug.log("ProjectsRootNode",
0958:                        "ProjectsRootNode, Created user node: "
0959:                                + userNode.getName());
0960:
0961:                Children userNodes = getChildren();
0962:
0963:                if (userNodes.findChild(userName) == null) {
0964:                    userNodes.add(new Node[] { userNode });
0965:                }
0966:
0967:                userNodes = getChildren();
0968:                userNode = userNodes.findChild(userName);
0969:
0970:                return userNode;
0971:            }
0972:
0973:            private void processActionsFromSharedProject(Node projectNode,
0974:                    Project fromProject) {
0975:                HashMap actionMap = new HashMap();
0976:                LogicalViewProvider lvp_fromProject = (LogicalViewProvider) fromProject
0977:                        .getLookup().lookup(LogicalViewProvider.class);
0978:                Node[] nodes_fromProject = new Node[] { lvp_fromProject
0979:                        .createLogicalView() };
0980:                Debug.log("ProjectsRootNode",
0981:                        "ProjectsRootNode, PRN createNodes length: "
0982:                                + nodes_fromProject.length);
0983:
0984:                if (nodes_fromProject[0].getLookup().lookup(Project.class) != fromProject) {
0985:                    // Various actions, badging, etc. are not going to work.
0986:                    ErrorManager
0987:                            .getDefault()
0988:                            .log(
0989:                                    ErrorManager.WARNING,
0990:                                    "Warning - project1 "
0991:                                            + ProjectUtils.getInformation(
0992:                                                    fromProject).getName()
0993:                                            + " failed to supply itself in the lookup of the "
0994:                                            + "root node of its own logical view"); // NOI18N
0995:                }
0996:
0997:                Node[] badgedNodes_fromProject = new Node[nodes_fromProject.length];
0998:
0999:                for (int j = 0; j < nodes_fromProject.length; j++) {
1000:                    badgedNodes_fromProject[j] = new BadgingNode(
1001:                            nodes_fromProject[j]);
1002:                }
1003:
1004:                Object[] actions = badgedNodes_fromProject[0].getActions(false);
1005:
1006:                for (int j = 0; j < actions.length; j++) {
1007:                    if (actions[j] instanceof  Action) {
1008:                        Action action = (Action) actions[j];
1009:                        Debug.out.println("ProjectsRootNode"
1010:                                + "ProjectsRootNode, Swg action: "
1011:                                + action.toString());
1012:
1013:                        String actionValue = (String) action
1014:                                .getValue(Action.NAME);
1015:                        Debug.out.println("ProjectsRootNode"
1016:                                + "ProjectsRootNode, getValue" + actionValue);
1017:                        actionMap.put(actionValue, action);
1018:                    }
1019:                }
1020:
1021:                SharedProject sharedProject = getContext()
1022:                        .getSharedProjectManager().getSharedProject(loginUser,
1023:                                projectNode.getName());
1024:
1025:                if (sharedProject != null) {
1026:                    sharedProject.setProjectActions((Action[]) actionMap
1027:                            .values().toArray(new Action[0]));
1028:                }
1029:
1030:                SystemAction[] pNodeactions = processActions(projectNode,
1031:                        sharedProject);
1032:
1033:                //Send Action List
1034:                EventContext evContext = new ProjectContext(
1035:                        ProjectActionListEvent.getEventID(), sharedProject
1036:                                .getProjectOwner(), projectNode.getName(),
1037:                        pNodeactions);
1038:                final CollabEvent ce = new ProjectActionListEvent(evContext);
1039:
1040:                /* send projectActionList message after a delay */
1041:                ProjectActionListTimerTask sendProjectActionListTimerTask = new ProjectActionListTimerTask(
1042:                        getContext().getChannelEventNotifier(),
1043:                        new ProjectActionListEvent(evContext), getContext());
1044:                getContext().addTimerTask(SEND_PROJECTACTIONLIST_TIMER_TASK,
1045:                        projectNode.getName(), sendProjectActionListTimerTask);
1046:                sendProjectActionListTimerTask
1047:                        .schedule(FilesharingTimerTask.PERIOD * 3);
1048:            }
1049:
1050:            private SystemAction[] processActions(Node projectNode,
1051:                    SharedProject sharedProject) {
1052:                Action[] nodeActions = sharedProject.getProjectActions();
1053:                Project fromProject = sharedProject.getOriginalProject();
1054:                SystemAction[] pNodeactions = FileshareUtil.setProjectActions(
1055:                        projectNode, nodeActions, fromProject, getContext());
1056:
1057:                return pNodeactions;
1058:            }
1059:
1060:            public void processPaste(Node projectNode,
1061:                    DataObject[] dragDataObjects, Project fromProject,
1062:                    boolean performPaste) throws IOException,
1063:                    DataObjectNotFoundException {
1064:                Debug.out.println("In PSRN processPaste");
1065:
1066:                for (int i = 0; i < dragDataObjects.length; i++) {
1067:                    if (dragDataObjects[i] == null) {
1068:                        continue;
1069:                    }
1070:
1071:                    DataObject dragDataObject = dragDataObjects[i];
1072:
1073:                    if ((dragDataObject == null)
1074:                            || (dragDataObject.getPrimaryFile() == null)
1075:                            || dragDataObject.getPrimaryFile().isFolder()) { //not a file
1076:
1077:                        continue;
1078:                    }
1079:
1080:                    try {
1081:                        if (performPaste
1082:                                && getContext()
1083:                                        .getSharedFileGroupManager()
1084:                                        .isShared(
1085:                                                dragDataObject.getPrimaryFile())) {
1086:                            Debug.out
1087:                                    .println("Skip paste, file already shared: "
1088:                                            + dragDataObject.getPrimaryFile()
1089:                                                    .getPath());
1090:
1091:                            continue; //skip if file already shared
1092:                        }
1093:                    } catch (Throwable th) {
1094:                        th.printStackTrace(Debug.out);
1095:                    }
1096:
1097:                    String dragNodePath = dragDataObject.getPrimaryFile()
1098:                            .getPath();
1099:                    Debug.out.println("PSRN, dragDataObject: " + dragNodePath);
1100:
1101:                    String uri = null;
1102:
1103:                    if (projectNode.getParentNode().getName().equals(loginUser)) { //perform for project owner
1104:
1105:                        if (!performPaste && //Create new file/folder to Shared Common root
1106:                                projectNode.getName().equals(SHARED_COMMON_DIR)) //DnD to Shared Common from Shared Common
1107:                        { //truncate path for New Shared Common files
1108:                            uri = getRelativePath(((ProjectNode) projectNode)
1109:                                    .getProjectDir().getPath(), dragNodePath);
1110:                        } else {
1111:                            if (fromProject != null) { //dragging to a SharedProjectNode
1112:
1113:                                //uri="src/japp/Main.java" if dragNodePath is "C:/test/javaapp/src/japp/Main.java", 
1114:                                //project path is "C:/test/javaapp"
1115:                                //uri=dragNodePath.substring(fromProject.getProjectDirectory().getPath().length()+1);
1116:                                uri = getRelativePath(fromProject
1117:                                        .getProjectDirectory().getPath(),
1118:                                        dragNodePath);
1119:                            } else { //dragging to a SharedNonProjectNode
1120:
1121:                                //uri="myfolder/myfile.txt" if dragNodePath is "C:/myfolder/myfile.txt"
1122:                                uri = dragNodePath.substring(dragNodePath
1123:                                        .indexOf(FILE_SEPERATOR) + 1);
1124:                            }
1125:                        }
1126:                    } else { //remote user
1127:
1128:                        //uri="src/japp/Main.java" if dragNodePath is "C:/test/javaapp/src/japp/Main.java", 
1129:                        //project path is "C:/test/javaapp"
1130:                        //uri=dragNodePath.substring(((ProjectNode)projectNode).getProjectDir().getPath().length()+1);	
1131:                        uri = getRelativePath(((ProjectNode) projectNode)
1132:                                .getProjectDir().getPath(), dragNodePath);
1133:
1134:                        if (uri.startsWith("/") || uri.startsWith("\\")) {
1135:                            uri = uri.substring(1);
1136:                        }
1137:                    }
1138:
1139:                    Debug.log("ProjectsRootNode",
1140:                            "ProjectsRootNode, uri full: " + uri);
1141:
1142:                    int firstindex = uri.indexOf(FILE_SEPERATOR);
1143:                    int lastindex = uri.lastIndexOf(FILE_SEPERATOR);
1144:                    String destFolderPath = null;
1145:                    String destFldr = null;
1146:
1147:                    if (firstindex != -1) {
1148:                        //find the corresponding node src for src, web for web etc
1149:                        ((CollabFilesystem) n_filesystem).refresh(false);
1150:
1151:                        Node tmpNode = ((ProjectNode) projectNode)
1152:                                .getChildNode(uri.substring(0, firstindex));
1153:                        Debug.log("ProjectsRootNode",
1154:                                "ProjectsRootNode, uri short: "
1155:                                        + uri.substring(0, firstindex));
1156:
1157:                        if (tmpNode != null) //if folder exist
1158:                        {
1159:                            if ((firstindex != -1) && (lastindex != -1)
1160:                                    && (firstindex < lastindex)) {
1161:                                //"japp"
1162:                                destFolderPath = uri.substring(firstindex + 1,
1163:                                        lastindex);
1164:                            }
1165:                        } else //drop the file into collab directory with its structure 
1166:                        {
1167:                            //"src/japp"
1168:                            destFolderPath = uri.substring(0, lastindex);
1169:                        }
1170:
1171:                        destFldr = uri.substring(0, firstindex);
1172:                    } else //drop the file into collab directory with its structure 
1173:                    {
1174:                        destFldr = null;
1175:                    }
1176:
1177:                    Node dragNode = null;
1178:                    DataFolder leafFldr = null;
1179:
1180:                    //make actual paste here
1181:                    if (performPaste) {
1182:                        if (destFldr == null) {
1183:                            leafFldr = DataFolder
1184:                                    .findFolder(((ProjectNode) projectNode)
1185:                                            .getProjectDir());
1186:                        } else {
1187:                            leafFldr = DataFolder
1188:                                    .findFolder(((ProjectNode) projectNode)
1189:                                            .getProjectDir().getFileObject(
1190:                                                    destFldr));
1191:                        }
1192:
1193:                        Debug.log("ProjectsRootNode", "PRN, leafFldr : "
1194:                                + leafFldr.getPrimaryFile().getPath());
1195:                        Debug.log("ProjectsRootNode", "PRN, destFolderPath : "
1196:                                + destFolderPath);
1197:
1198:                        if ((destFolderPath != null)
1199:                                && !destFolderPath.equals("")) {
1200:                            leafFldr = replicateFolderStructure(leafFldr
1201:                                    .getPrimaryFile(), destFolderPath);
1202:                        }
1203:
1204:                        Debug.log("ProjectsRootNode", "PRN, leafFldr : "
1205:                                + leafFldr.getPrimaryFile().getPath());
1206:
1207:                        DataObject dd = null;
1208:
1209:                        if (fromProject != null) {
1210:                            dd = dragDataObject.createShadow(leafFldr);
1211:                        } else {
1212:                            dd = dragDataObject.copy(leafFldr);
1213:                        }
1214:
1215:                        ((CollabFilesystem) n_filesystem).refresh(false);
1216:                        dragNode = dd.getNodeDelegate();
1217:                    } else {
1218:                        leafFldr = DataFolder
1219:                                .findFolder(((ProjectNode) projectNode)
1220:                                        .getProjectDir());
1221:                        dragNode = dragDataObject.getNodeDelegate();
1222:                    }
1223:
1224:                    boolean isLocal = loginUser.equals(projectNode
1225:                            .getParentNode().getName());
1226:
1227:                    //Now create filter node of the dragDataObject
1228:                    if (projectNode.getName().equals(SHARED_COMMON_DIR)) {
1229:                        dragNode = new SharedNonProjectNode(dragDataObject
1230:                                .getPrimaryFile().getNameExt(), dragNode,
1231:                                isLocal, getContext());
1232:                    } else {
1233:                        dragNode = new SharedProjectNode(dragDataObject
1234:                                .getNodeDelegate(), isLocal, getContext(),
1235:                                false);
1236:                    }
1237:
1238:                    Node destNode = ((ProjectNode) projectNode)
1239:                            .getChildNode(destFldr);
1240:
1241:                    if (destNode != null) {
1242:                        if (destNode instanceof  PackagesNode) {
1243:                            String pkgName = DEFAULT_PKG;
1244:
1245:                            if (destFolderPath != null) {
1246:                                pkgName = destFolderPath;
1247:                            }
1248:
1249:                            Debug.log("ProjectsRootNode", "PRN, pkg 1: "
1250:                                    + pkgName);
1251:
1252:                            //Seperate conf files, usually in WebApps have src/conf/MANIFEST.mf
1253:                            if (pkgName.equals(CONF_NODE)) {
1254:                                //fix bug#6284927
1255:                                //destNode = ((ProjectNode) projectNode).getChildNode(CONF_NODE);
1256:                                //if (destNode.getChildren().findChild(dragNode.getName()) == null) {
1257:                                //    destNode.getChildren().add(new Node[] { dragNode });
1258:                                //}
1259:                            } else {
1260:                                if (pkgName.startsWith(JAVA_PKG)) {
1261:                                    if (pkgName.length() == 4) {
1262:                                        pkgName = DEFAULT_PKG;
1263:                                    } else if (pkgName.startsWith(JAVA_PKG
1264:                                            + FILE_SEPERATOR)) {
1265:                                        pkgName = pkgName.substring(5);
1266:                                    }
1267:                                }
1268:
1269:                                PackagesNode.PackagesNodeChildren pkgs = ((PackagesNode) destNode)
1270:                                        .getPackagesNodeChildren();
1271:
1272:                                if (pkgs.findChild(pkgName) == null) {
1273:                                    pkgs.add(pkgName, new Node[] { dragNode });
1274:                                } else {
1275:                                    pkgs.findChild(pkgName).getChildren().add(
1276:                                            new Node[] { dragNode });
1277:                                }
1278:                            }
1279:
1280:                            Debug.log("ProjectsRootNode", "PRN, pkg 2: "
1281:                                    + pkgName);
1282:                        } else {
1283:                        } //nothing to do
1284:                    } else {
1285:                        if (projectNode.getChildren().findChild(
1286:                                dragNode.getName()) == null) {
1287:                            projectNode.getChildren().add(
1288:                                    new Node[] { dragNode });
1289:                        }
1290:                    }
1291:
1292:                    //expand node
1293:                    FilesystemExplorerPanel panel = getContext()
1294:                            .getFilesystemExplorer();
1295:
1296:                    if (panel != null) {
1297:                        if (destFolderPath != null) {
1298:                            panel.expandTreeNode(dragNode, destFolderPath);
1299:                        } else {
1300:                            panel.expandTreeNode(dragNode.getParentNode(),
1301:                                    destFolderPath);
1302:                        }
1303:                    }
1304:
1305:                    //now send file
1306:                    if (performPaste) {
1307:                        getContext().getSharedFileGroupManager()
1308:                                .sendDataObject(loginUser,
1309:                                        projectNode.getName(), leafFldr,
1310:                                        dragDataObject);
1311:                    }
1312:
1313:                    if ((fromProject != null) && performPaste) {
1314:                        //save a copy of the original file of project
1315:                        leafFldr = DataFolder
1316:                                .findFolder(((ProjectNode) projectNode)
1317:                                        .getProjectDir().getFileObject(
1318:                                                ARCHIVE_DIR));
1319:                        destFolderPath = null;
1320:
1321:                        if (lastindex != -1) {
1322:                            destFolderPath = uri.substring(0, lastindex); //"src/japp"	
1323:                        }
1324:
1325:                        if ((destFolderPath != null)
1326:                                && !destFolderPath.equals("")) {
1327:                            leafFldr = replicateFolderStructure(leafFldr
1328:                                    .getPrimaryFile(), destFolderPath);
1329:                            ((CollabFilesystem) n_filesystem).refresh(false);
1330:                        }
1331:
1332:                        dragDataObject.copy(leafFldr);
1333:                    }
1334:                }
1335:            }
1336:
1337:            private String getRelativePath(String folderPath, String path) {
1338:                Debug.out.println("In getRelativePath for loginUser: "
1339:                        + loginUser);
1340:                Debug.out.println("folderPath: " + folderPath + " path: "
1341:                        + path);
1342:
1343:                if (path.startsWith("/") || path.startsWith("\\")) {
1344:                    path = path.substring(1);
1345:                }
1346:
1347:                if (folderPath.startsWith("/") || folderPath.startsWith("\\")) {
1348:                    folderPath = folderPath.substring(1);
1349:                }
1350:
1351:                if (path.length() > folderPath.length()) {
1352:                    return path.substring(folderPath.length() + 1);
1353:                } else {
1354:                    return folderPath;
1355:                }
1356:            }
1357:
1358:            protected DataFolder replicateFolderStructure(FileObject dropRoot,
1359:                    String dragParentPath) throws IOException,
1360:                    DataObjectNotFoundException {
1361:                Debug.out.println("In replicateFolderStructure for: "
1362:                        + dragParentPath);
1363:
1364:                DataObject d = DataObject.find(FileUtil.createFolder(dropRoot,
1365:                        dragParentPath));
1366:
1367:                return (DataFolder) d.getCookie(DataFolder.class);
1368:            }
1369:
1370:            private boolean isExist(String name, File[] userDirs) {
1371:                for (int i = 0; i < userDirs.length; i++) {
1372:                    if (userDirs[i].getName().equals(name)) {
1373:                        Debug.log("ProjectsRootNode",
1374:                                "ProjectsRootNode, found name: " + name);
1375:
1376:                        return true;
1377:                    }
1378:                }
1379:
1380:                return false;
1381:            }
1382:
1383:            class UserNode extends AbstractNode {
1384:                ////////////////////////////////////////////////////////////////////////////
1385:                // Instance variables
1386:                ////////////////////////////////////////////////////////////////////////////
1387:                private FileObject userFolder = null;
1388:                private Image USER_BADGE = Utilities
1389:                        .loadImage(
1390:                                "org/netbeans/modules/collab/core/resources/account_png.gif",
1391:                                true); // NOI18N		
1392:
1393:                public UserNode(String name) {
1394:                    super (new Index.ArrayChildren());
1395:                    Debug.log("ProjectsRootNode", "ProjectsRootNode, UNuser: "
1396:                            + name);
1397:                    setName(name);
1398:                    setDisplayName(getContext().getPrincipal(name)
1399:                            .getDisplayName());
1400:                }
1401:
1402:                public Action[] getActions(boolean context) {
1403:                    return new SystemAction[] {};
1404:                }
1405:
1406:                public Image getIcon(int type) {
1407:                    return computeIcon(false, type);
1408:                }
1409:
1410:                public Image getOpenedIcon(int type) {
1411:                    return computeIcon(true, type);
1412:                }
1413:
1414:                private Image computeIcon(boolean opened, int type) {
1415:                    return USER_BADGE;
1416:                }
1417:
1418:                /**
1419:                 *
1420:                 *
1421:                 */
1422:                public boolean canCut() {
1423:                    return false;
1424:                }
1425:
1426:                /**
1427:                 *
1428:                 *
1429:                 */
1430:                public boolean canCopy() {
1431:                    return false;
1432:                }
1433:
1434:                /**
1435:                 *
1436:                 *
1437:                 */
1438:                public boolean canDestroy() {
1439:                    return false;
1440:                }
1441:
1442:                /**
1443:                 *
1444:                 *
1445:                 */
1446:                public boolean canRename() {
1447:                    return false;
1448:                }
1449:
1450:                private FileObject getUserDir() {
1451:                    if (userFolder != null) {
1452:                        return userFolder;
1453:                    }
1454:
1455:                    FileObject rootFile = FileUtil
1456:                            .toFileObject(((CollabFilesystem) n_filesystem)
1457:                                    .getCollabRoot());
1458:
1459:                    if (rootFile == null) {
1460:                        return null;
1461:                    }
1462:
1463:                    userFolder = rootFile.getFileObject(getName());
1464:
1465:                    try {
1466:                        if (userFolder == null) {
1467:                            userFolder = rootFile.createFolder(getName());
1468:                        }
1469:                    } catch (IOException iox) {
1470:                        iox.printStackTrace(Debug.out);
1471:                    }
1472:
1473:                    return userFolder;
1474:                }
1475:            }
1476:
1477:            public class ProjectNode extends AbstractNode {
1478:                ////////////////////////////////////////////////////////////////////////////
1479:                // Instance variables
1480:                ////////////////////////////////////////////////////////////////////////////
1481:                private Image PROJECT_BADGE = PROJECTS_ROOT_BADGE;
1482:                private SystemAction[] actions = null;
1483:                private HashMap actionMap = new HashMap();
1484:                private String parentNodeName;
1485:                private Project fromProject;
1486:                private FileObject projectFolder;
1487:                private boolean isLocal = false;
1488:
1489:                public ProjectNode(final String name, Node userNode,
1490:                        Project fromProject, SystemAction[] actions) {
1491:                    super (new Index.ArrayChildren());
1492:                    Debug.log("ProjectsRootNode", "ProjectsNode: " + name);
1493:                    setName(name);
1494:
1495:                    if (name.equals(SHARED_COMMON_DIR)) {
1496:                        setDisplayName(COLLAB_NON_PROJECT_FOLDER_NAME);
1497:                    } else {
1498:                        setDisplayName(name);
1499:                    }
1500:
1501:                    this .parentNodeName = userNode.getName();
1502:                    this .fromProject = fromProject;
1503:                    setActions(actions);
1504:
1505:                    FileObject userFolder = ((UserNode) userNode).getUserDir();
1506:                    projectFolder = userFolder.getFileObject(name);
1507:
1508:                    try {
1509:                        if (projectFolder == null) {
1510:                            projectFolder = userFolder.createFolder(name);
1511:                        }
1512:                    } catch (IOException iox) {
1513:                        iox.printStackTrace(Debug.out);
1514:
1515:                        return;
1516:                    }
1517:
1518:                    Debug.out.println("ProjectsRootNode, projectDir: "
1519:                            + projectFolder.getPath());
1520:                    Debug.out.println("SharedProject pDir: " + getProjectDir());
1521:                    this .isLocal = loginUser.equals(this .parentNodeName);
1522:                    init();
1523:                }
1524:
1525:                public Image getIcon(int type) {
1526:                    return computeIcon(false, type);
1527:                }
1528:
1529:                public Image getOpenedIcon(int type) {
1530:                    return computeIcon(true, type);
1531:                }
1532:
1533:                private Image computeIcon(boolean opened, int type) {
1534:                    return PROJECT_BADGE;
1535:                }
1536:
1537:                public Action[] getActions(boolean context) {
1538:                    return (actions == null) ? new SystemAction[] {} : actions;
1539:                }
1540:
1541:                /**
1542:                 *
1543:                 *
1544:                 */
1545:                public boolean canCut() {
1546:                    return false;
1547:                }
1548:
1549:                /**
1550:                 *
1551:                 *
1552:                 */
1553:                public boolean canCopy() {
1554:                    return false;
1555:                }
1556:
1557:                /**
1558:                 *
1559:                 *
1560:                 */
1561:                public boolean canDestroy() {
1562:                    return false;
1563:                }
1564:
1565:                /**
1566:                 *
1567:                 *
1568:                 */
1569:                public boolean canRename() {
1570:                    return false;
1571:                }
1572:
1573:                public void setActions(SystemAction[] actions) {
1574:                    int size;
1575:
1576:                    if (actions == null) {
1577:                        size = 0;
1578:                    } else {
1579:                        size = actions.length;
1580:                    }
1581:
1582:                    this .actions = new SystemAction[(size * 2) + 3];
1583:
1584:                    int index = 0;
1585:
1586:                    if (loginUser.equals(parentNodeName)) {
1587:                        if (!getContext().isReadOnlyConversation()) {
1588:                            if (this .getName().equals(SHARED_COMMON_DIR)) {
1589:                                this .actions[index++] = new CreateNonProjectAction(
1590:                                        getContext(), this );
1591:                            }
1592:
1593:                            this .actions[index++] = SystemAction
1594:                                    .get(PasteAction.class);
1595:                        }
1596:                    }
1597:
1598:                    this .actions[index++] = null;
1599:                    actionMap.clear();
1600:
1601:                    for (int i = 0; i < size; i++) {
1602:                        //this.actions[index+i]=actions[i];
1603:                        if (actions[i] != null) {
1604:                            actionMap.put(((ProjectAction) actions[i]).getID(),
1605:                                    actions[i]);
1606:                        }
1607:                    }
1608:
1609:                    //re-order actions
1610:                    if (actionMap.get(CollabProjectAction.COMMAND_BUILD) != null) {
1611:                        this .actions[index++] = (SystemAction) actionMap
1612:                                .get(CollabProjectAction.COMMAND_BUILD);
1613:                    }
1614:
1615:                    if (actionMap.get(CollabProjectAction.COMMAND_REBUILD) != null) {
1616:                        this .actions[index++] = (SystemAction) actionMap
1617:                                .get(CollabProjectAction.COMMAND_REBUILD);
1618:                        this .actions[index++] = null;
1619:                    }
1620:
1621:                    if (actionMap.get(CollabProjectAction.COMMAND_RUN) != null) {
1622:                        this .actions[index++] = (SystemAction) actionMap
1623:                                .get(CollabProjectAction.COMMAND_RUN);
1624:                        this .actions[index++] = null;
1625:                    }
1626:
1627:                    if (actionMap.get(CollabProjectAction.COMMAND_INSTALL) != null) {
1628:                        this .actions[index++] = (SystemAction) actionMap
1629:                                .get(CollabProjectAction.COMMAND_INSTALL);
1630:                        this .actions[index++] = null;
1631:                    }
1632:                }
1633:
1634:                public SystemAction getAction(String name) {
1635:                    Debug.out
1636:                            .println("ProjectsRootNode, ProjectsRootNode, actionMap: "
1637:                                    + actionMap);
1638:
1639:                    return (SystemAction) actionMap.get(name);
1640:                }
1641:
1642:                protected void createPasteTypes(Transferable t, List ls) {
1643:                    if (getContext().isReadOnlyConversation()) {
1644:                        return;
1645:                    }
1646:
1647:                    final Node[] ns = NodeTransfer.nodes(t,
1648:                            NodeTransfer.DND_COPY);
1649:                    final String projectNodeName = this .getName();
1650:
1651:                    if (ns != null) {
1652:                        ls.add(new PasteType() {
1653:                            public Transferable paste() throws IOException {
1654:                                //return if not the owner of this project
1655:                                if (!loginUser.equals(parentNodeName)) {
1656:                                    return null;
1657:                                }
1658:
1659:                                Node[] nue = new Node[ns.length];
1660:
1661:                                for (int i = 0; i < nue.length; i++) {
1662:                                    nue[i] = ns[i].cloneNode();
1663:                                }
1664:
1665:                                try {
1666:                                    createProjectNode(nue);
1667:                                } catch (CollabException ce) {
1668:                                    //ignore
1669:                                }
1670:
1671:                                return null;
1672:                            }
1673:                        });
1674:                    }
1675:
1676:                    // Also try superclass, but give it lower priority:
1677:                    super .createPasteTypes(t, ls);
1678:                }
1679:
1680:                public Node getChildNode(String childName)
1681:                        throws DataObjectNotFoundException {
1682:                    if (childName == null) {
1683:                        return null;
1684:                    }
1685:
1686:                    Children projectChildren = getChildren();
1687:                    String projectName = getName();
1688:                    String userName = getParentNode().getName();
1689:                    Node childNode = null;
1690:
1691:                    if (getName().equals(SHARED_COMMON_DIR)) {
1692:                        childNode = projectChildren.findChild(childName); //NoI18n		
1693:
1694:                        if (childNode == null) {
1695:                            FileObject pChildFolder = getProjectDir()
1696:                                    .getFileObject(childName);
1697:
1698:                            try {
1699:                                if (pChildFolder == null) {
1700:                                    pChildFolder = getProjectDir()
1701:                                            .createFolder(childName);
1702:                                }
1703:
1704:                                projectChildren
1705:                                        .add(new Node[] { new SharedNonProjectNode(
1706:                                                childName,
1707:                                                DataObject.find(pChildFolder)
1708:                                                        .getNodeDelegate(),
1709:                                                loginUser
1710:                                                        .equals(parentNodeName),
1711:                                                getContext()) });
1712:                            } catch (IOException iox) {
1713:                                iox.printStackTrace(Debug.out);
1714:                            }
1715:                        }
1716:                    }
1717:
1718:                    if (childName.equals(SRC_DIR) || childName.equals(TEST_DIR)
1719:                            || childName.equals(JAVAHELP_DIR)) {
1720:                        String displayName = childName;
1721:
1722:                        if (childName.equals(SRC_DIR)) {
1723:                            childNode = (projectChildren.findChild(SRC_DIR) != null) ? projectChildren
1724:                                    .findChild(SRC_DIR)
1725:                                    : projectChildren.findChild(SRC_NODE); //NoI18n
1726:                            displayName = SRC_FOLDER_NAME;
1727:                        } else if (childName.equals(TEST_DIR)) {
1728:                            childNode = (projectChildren.findChild(TEST_DIR) != null) ? projectChildren
1729:                                    .findChild(TEST_DIR)
1730:                                    : projectChildren.findChild(TEST_NODE); //NoI18n
1731:                            displayName = TEST_FOLDER_NAME;
1732:                        } else if (childName.equals(JAVAHELP_DIR)) {
1733:                            childNode = (projectChildren
1734:                                    .findChild(JAVAHELP_DIR) != null) ? projectChildren
1735:                                    .findChild(JAVAHELP_DIR)
1736:                                    : projectChildren.findChild(JAVAHELP_NODE); //NoI18n
1737:                            displayName = JAVAHELP_FOLDER_NAME;
1738:                        }
1739:
1740:                        if (childNode == null) {
1741:                            FileObject pChildFolder = getProjectDir()
1742:                                    .getFileObject(childName);
1743:
1744:                            try {
1745:                                if (pChildFolder == null) {
1746:                                    pChildFolder = getProjectDir()
1747:                                            .createFolder(childName);
1748:                                }
1749:
1750:                                if (projectChildren.findChild(childName) == null) {
1751:                                    if (displayName == null) {
1752:                                        displayName = childName;
1753:                                    }
1754:
1755:                                    String packageRootPath = pChildFolder
1756:                                            .getPath();
1757:                                    projectChildren
1758:                                            .add(new Node[] { new PackagesNode(
1759:                                                    displayName,
1760:                                                    packageRootPath, DataObject
1761:                                                            .find(pChildFolder)
1762:                                                            .getNodeDelegate(),
1763:                                                    isLocal, getContext()) });
1764:                                }
1765:                            } catch (IOException iox) {
1766:                                iox.printStackTrace(Debug.out);
1767:                            }
1768:                        }
1769:                    } else if (childName.equals(WEB_DIR)) //NoI18n
1770:                    {
1771:                        childNode = projectChildren.findChild(WEB_DIR); //NoI18n		
1772:
1773:                        if (childNode == null) {
1774:                            FileObject pChildFolder = getProjectDir()
1775:                                    .getFileObject(childName);
1776:
1777:                            try {
1778:                                if (pChildFolder == null) {
1779:                                    pChildFolder = getProjectDir()
1780:                                            .createFolder(childName);
1781:                                }
1782:
1783:                                projectChildren
1784:                                        .add(new Node[] { new SharedProjectNode(
1785:                                                WEB_FOLDER_NAME, DataObject
1786:                                                        .find(pChildFolder)
1787:                                                        .getNodeDelegate(),
1788:                                                isLocal, getContext()) });
1789:                            } catch (IOException iox) {
1790:                                iox.printStackTrace(Debug.out);
1791:                            }
1792:                        }
1793:                    } else if (childName.equals(CONF_NODE)) {
1794:                        childNode = projectChildren.findChild(CONF_NODE); //NoI18n		
1795:
1796:                        if (childNode == null) {
1797:                            FileObject pChildFolder = getProjectDir()
1798:                                    .getFileObject(CONF_DIR);
1799:
1800:                            try {
1801:                                if (pChildFolder == null) {
1802:                                    pChildFolder = getProjectDir()
1803:                                            .createFolder(CONF_DIR);
1804:                                }
1805:
1806:                                projectChildren
1807:                                        .add(new Node[] { new SharedProjectNode(
1808:                                                CONF_FOLDER_NAME, DataObject
1809:                                                        .find(pChildFolder)
1810:                                                        .getNodeDelegate(),
1811:                                                isLocal, getContext()) });
1812:                            } catch (IOException iox) {
1813:                                iox.printStackTrace(Debug.out);
1814:                            }
1815:                        }
1816:                    } else if (childName.equals(ARCHIVE_DIR)) {
1817:                        FileObject pChildFolder = getProjectDir()
1818:                                .getFileObject(ARCHIVE_DIR);
1819:
1820:                        try {
1821:                            if (pChildFolder == null) {
1822:                                pChildFolder = getProjectDir().createFolder(
1823:                                        ARCHIVE_DIR);
1824:                            }
1825:                        } catch (IOException iox) {
1826:                            iox.printStackTrace(Debug.out);
1827:                        }
1828:                    } else {
1829:                        childNode = projectChildren.findChild(childName);
1830:
1831:                        if (childNode == null) {
1832:                            FileObject pChildFolder = getProjectDir()
1833:                                    .getFileObject(childName);
1834:
1835:                            try {
1836:                                if (pChildFolder == null) {
1837:                                    pChildFolder = getProjectDir()
1838:                                            .createFolder(childName);
1839:                                }
1840:
1841:                                projectChildren
1842:                                        .add(new Node[] { new SharedProjectNode(
1843:                                                childName, DataObject.find(
1844:                                                        pChildFolder)
1845:                                                        .getNodeDelegate(),
1846:                                                isLocal, getContext()) });
1847:                            } catch (IOException iox) {
1848:                                iox.printStackTrace(Debug.out);
1849:                            }
1850:                        }
1851:                    }
1852:
1853:                    return projectChildren.findChild(childName);
1854:                }
1855:
1856:                public FileObject getProjectDir() {
1857:                    return this .projectFolder;
1858:                }
1859:
1860:                public String getParentName() {
1861:                    return this .parentNodeName;
1862:                }
1863:
1864:                private void init() {
1865:                    if (getName().equals(SHARED_COMMON_DIR)) {
1866:                        FileSystem fs = null;
1867:
1868:                        try {
1869:                            fs = getProjectDir().getFileSystem();
1870:                        } catch (Exception e) {
1871:                            Debug.out
1872:                                    .println("SharedProject getFileSystem() failed"
1873:                                            + e);
1874:                            e.printStackTrace(Debug.out);
1875:                        }
1876:
1877:                        FileChangeListener scfl = new SharedCommonFileListener(
1878:                                this , parentNodeName);
1879:
1880:                        if (fs != null) {
1881:                            fs.addFileChangeListener(scfl);
1882:                            getContext().setSharedCommonFileListener(fs, scfl);
1883:                        }
1884:                    }
1885:                }
1886:            }
1887:
1888:            public class SharedCommonFileListener extends FileChangeAdapter {
1889:                private ProjectNode pNode;
1890:                private String userNodeName;
1891:                private String ppath;
1892:                private EventNotifier fileChangeNotifier = null;
1893:
1894:                public SharedCommonFileListener(ProjectNode node,
1895:                        String userNodeName) {
1896:                    this .pNode = node;
1897:                    this .userNodeName = userNodeName;
1898:                    this .ppath = node.getProjectDir().getPath();
1899:                    Debug.out.println("In scfl() for loginUser: " + loginUser);
1900:                    Debug.out.println("projectDir: " + ppath);
1901:
1902:                    //create a notifer first
1903:                    try {
1904:                        EventProcessor ep = FilesharingEventProcessorFactory
1905:                                .getDefault().createEventProcessor(
1906:                                        getContext().getProcessorConfig(),
1907:                                        getContext());
1908:                        fileChangeNotifier = FilesharingEventNotifierFactory
1909:                                .getDefault().createEventNotifier(
1910:                                        getContext().getNotifierConfig(), ep);
1911:                    } catch (CollabException e) {
1912:                        e.printStackTrace(Debug.out);
1913:                    }
1914:                }
1915:
1916:                public void fileDataCreated(FileEvent e) {
1917:                    if (!isShared(e)) {
1918:                        return;
1919:                    }
1920:
1921:                    FileObject fObj = e.getFile();
1922:                    Debug.out.println("FileDataCreated: " + fObj.getNameExt());
1923:
1924:                    String fileName = fObj.getNameExt();
1925:
1926:                    if (!(fileName.equals(".nbattrs") || (fileName
1927:                            .startsWith(".LCK") && fileName.endsWith("~")))) {
1928:                        if (getRelativePath(fObj.getPath()).equals(
1929:                                fObj.getNameExt())) {
1930:                            addNode(e);
1931:                        }
1932:
1933:                        try {
1934:                            Debug.out.println("fileDataCreated: " + fileName);
1935:
1936:                            DataObject folder = (DataObject) DataObject
1937:                                    .find(fObj.getParent());
1938:                            DataFolder leafFldr = (DataFolder) folder
1939:                                    .getCookie(DataFolder.class);
1940:
1941:                            if (userNodeName.equals(loginUser)) {
1942:                                DataObject d = DataObject.find(fObj);
1943:                                context.getSharedFileGroupManager()
1944:                                        .sendDataObject(loginUser, getName(),
1945:                                                leafFldr, d);
1946:                            }
1947:                        } catch (DataObjectNotFoundException ddnf) {
1948:                            //ignore
1949:                        }
1950:                    }
1951:                }
1952:
1953:                public void fileFolderCreated(FileEvent e) {
1954:                    if (!isShared(e)) {
1955:                        return;
1956:                    }
1957:
1958:                    FileObject fObj = e.getFile();
1959:                    Debug.out
1960:                            .println("FileFolderCreated: " + fObj.getNameExt());
1961:
1962:                    if (getRelativePath(fObj.getPath()).equals(
1963:                            fObj.getNameExt())) {
1964:                        addNode(e);
1965:                    }
1966:                }
1967:
1968:                public void fileDeleted(FileEvent fe) {
1969:                    if (!isShared(fe)) {
1970:                        return;
1971:                    }
1972:
1973:                    FileObject fObj = fe.getFile();
1974:                    Debug.out.println("File Delete: " + fObj.getNameExt());
1975:
1976:                    if (fileChangeNotifier == null) {
1977:                        return;
1978:                    }
1979:
1980:                    try {
1981:                        if (userNodeName.equals(loginUser)) //send if owner
1982:                        {
1983:                            if (!getContext().getSharedFileGroupManager()
1984:                                    .isShared(fObj)) {
1985:                                return;
1986:                            }
1987:
1988:                            CollabFileHandler fh = getContext()
1989:                                    .getSharedFileGroupManager()
1990:                                    .getFileHandler(fObj);
1991:                            EventContext evContext = new EventContext(
1992:                                    DeleteFileEvent.getEventID(), fh);
1993:                            CollabEvent ce = new DeleteFileEvent(evContext);
1994:                            fileChangeNotifier.notify(ce);
1995:                        }
1996:                    } catch (Exception e) {
1997:                        Debug.out.println("Exception sendDelete: " + e);
1998:                        e.printStackTrace(Debug.out);
1999:                    }
2000:                }
2001:
2002:                public void fileRenamed(FileRenameEvent fre) {
2003:                    if (!isShared(fre)) {
2004:                        return;
2005:                    }
2006:
2007:                    FileObject fObj = fre.getFile();
2008:                    String origName = fre.getName();
2009:                    String origExt = fre.getExt();
2010:
2011:                    if ((origExt != null) && !origExt.equals("")) {
2012:                        origName = origName + "." + origExt;
2013:                    }
2014:
2015:                    Debug.out.println("File Rename from: " + origName);
2016:                    Debug.out.println("File Rename to: " + fObj.getNameExt());
2017:
2018:                    if (fileChangeNotifier == null) {
2019:                        return;
2020:                    }
2021:
2022:                    try {
2023:                        if (getRelativePath(fObj.getPath()).equals(
2024:                                fObj.getNameExt())) {
2025:                            Node node = pNode.getChildren().findChild(
2026:                                    fObj.getNameExt());
2027:
2028:                            if (node == null) {
2029:                                node = pNode.getChildren().findChild(origName);
2030:                            }
2031:
2032:                            if (node != null) {
2033:                                Debug.out.println("removing node: " + origName);
2034:                                pNode.getChildren().remove(new Node[] { node });
2035:                                Debug.out.println("adding node: "
2036:                                        + fObj.getNameExt());
2037:                                addNode(fre);
2038:                            } else {
2039:                                Debug.out.println("node null for: "
2040:                                        + fObj.getNameExt());
2041:                            }
2042:                        }
2043:
2044:                        if (userNodeName.equals(loginUser)) //send if owner
2045:                        {
2046:                            Debug.out.println("check isShared: "
2047:                                    + fObj.getNameExt());
2048:
2049:                            if (!getContext().getSharedFileGroupManager()
2050:                                    .isShared(fObj)) {
2051:                                return;
2052:                            }
2053:
2054:                            CollabFileHandler fh = getContext()
2055:                                    .getSharedFileGroupManager()
2056:                                    .getFileHandler(fObj);
2057:                            String fileName = fh.getName();
2058:                            Debug.out.println("shared: " + fileName);
2059:
2060:                            EventContext evContext = new EventContext(
2061:                                    RenameFileEvent.getEventID(), fh);
2062:                            CollabEvent ce = new RenameFileEvent(evContext);
2063:                            fileChangeNotifier.notify(ce);
2064:                        }
2065:                    } catch (Exception e) {
2066:                        Debug.out.println("Exception sendRename: " + e);
2067:                        e.printStackTrace(Debug.out);
2068:                    }
2069:                }
2070:
2071:                /*
2072:                 * check if operation belongs to this right shared folder
2073:                 */
2074:                private boolean isShared(FileEvent e) {
2075:                    FileObject fObj = e.getFile();
2076:                    String fPath = fObj.getPath();
2077:                    String rPath = ppath.replace('\\', FILE_SEPERATOR_CHAR);
2078:                    Debug.out.println("path: " + fPath);
2079:                    Debug.out.println("rpath: " + rPath);
2080:
2081:                    if (strContains(fPath, rPath)) {
2082:                        return true; //a shared file
2083:                    }
2084:
2085:                    return false;
2086:                }
2087:
2088:                private void addNode(FileEvent e) {
2089:                    FileObject fObj = e.getFile();
2090:                    Debug.out.println("ProjectsRootNode fileadded: "
2091:                            + fObj.getPath());
2092:
2093:                    try {
2094:                        DataObject d = DataObject.find(fObj);
2095:
2096:                        if (fObj.isData()) {
2097:                            ProjectsRootNode.this .processPaste(pNode,
2098:                                    new DataObject[] { d }, null, false);
2099:                        } else {
2100:                            if (pNode.getChildren().findChild(fObj.getName()) == null) {
2101:                                pNode.getChildren().add(
2102:                                        new Node[] { new SharedNonProjectNode(d
2103:                                                .getNodeDelegate(), pNode
2104:                                                .getParentName().equals(
2105:                                                        loginUser),
2106:                                                getContext()) });
2107:                            }
2108:                        }
2109:                    } catch (DataObjectNotFoundException dne) {
2110:                        dne.printStackTrace(Debug.out);
2111:                    } catch (IOException iox) {
2112:                        iox.printStackTrace(Debug.out);
2113:                    }
2114:                }
2115:
2116:                private String getRelativePath(String path) {
2117:                    return ProjectsRootNode.this .getRelativePath(ppath, path);
2118:                }
2119:            }
2120:
2121:            private static final class BadgingNode extends FilterNode implements 
2122:                    PropertyChangeListener {
2123:                public BadgingNode(Node n) {
2124:                    super (n, null, //default children
2125:                            n.getLookup());
2126:                }
2127:
2128:                public String getDisplayName() {
2129:                    String original = super .getDisplayName();
2130:
2131:                    return original;
2132:                }
2133:
2134:                public String getHtmlDisplayName() {
2135:                    String htmlName = getOriginal().getHtmlDisplayName();
2136:                    String dispName = null;
2137:
2138:                    if (htmlName == null) {
2139:                        dispName = super .getDisplayName();
2140:
2141:                        try {
2142:                            dispName = XMLUtil.toElementContent(dispName);
2143:                        } catch (CharConversionException ex) {
2144:                            // ignore
2145:                        }
2146:                    }
2147:
2148:                    return htmlName; //NOI18N
2149:                }
2150:
2151:                public void propertyChange(PropertyChangeEvent e) {
2152:                }
2153:            }
2154:        }
w___w_w_._j___a__va__2__s_._c___om_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.