KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > piagetproject > PiagetProject


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * PovProject.java
21  *
22  * Created on February 16, 2005, 3:43 PM
23  */

24
25 package org.netbeans.modules.piagetproject;
26 import java.beans.PropertyChangeListener JavaDoc;
27 import java.io.File JavaDoc;
28 import java.io.IOException JavaDoc;
29 import java.util.Properties JavaDoc;
30 import javax.swing.Icon JavaDoc;
31 import javax.swing.ImageIcon JavaDoc;
32 import org.netbeans.api.project.Project;
33 import org.netbeans.api.project.ProjectInformation;
34 import org.netbeans.spi.project.ProjectState;
35 import org.openide.ErrorManager;
36 import org.openide.filesystems.FileObject;
37 import org.openide.filesystems.FileUtil;
38 import org.openide.loaders.DataFolder;
39 import org.openide.util.Lookup;
40 import org.openide.util.Utilities;
41 import org.openide.util.lookup.Lookups;
42 import org.openide.nodes.Node;
43
44
45
46 public final class PiagetProject implements Project {
47     
48     
49     private final FileObject projectFileObject;
50     private final Node projectNode;
51     public static String JavaDoc workPath;
52     private final ProjectState state;
53     
54     public PiagetProject(FileObject projectDir, ProjectState state) {
55         this.projectFileObject = projectDir;
56         DataFolder data = DataFolder.findFolder(projectDir);
57         this.projectNode = data.getNodeDelegate();
58         this.state = state;
59         structure();
60     }
61     
62     public FileObject getProjectDirectory() {
63         return projectFileObject;
64     }
65     
66   
67     
68     
69     
70     public Lookup getLookup() {
71         return Lookups.fixed(new Object JavaDoc[] {
72             this, //project docs require a project be in its lookup
73
state,
74                     new Info(), //Project information implementation
75
new PiagetLogicalView(this), //Logical view of project implementation
76
});
77     }
78     
79     /**
80      * Fetches the scenes folder, creating it if necessary.
81      */

82     void structure() {
83        
84         /*String[] dirNames = new String[]{PiagetProjectFactory.LEVEL1, PiagetProjectFactory.LEVEL2, PiagetProjectFactory.LEVEL3};
85         for(int i=0;i<dirNames.length;i++){
86             FileObject dir = projectFileObject.getFileObject(dirNames[i]);
87             if (dir == null) {
88                 try {
89                     projectFileObject.createFolder(dirNames[i]);
90                 } catch (IOException ioe) {
91                     ErrorManager.getDefault().notify(ioe);
92                 }
93             }
94         }*/

95         
96         String JavaDoc [] dirNames = new String JavaDoc[]{PiagetProjectFactory.ORIGINALS_DIR, PiagetProjectFactory.PARSED_DIR};
97         FileObject repository = projectFileObject.getFileObject(PiagetProjectFactory.PROJECT_DIR);
98         for(int i=0;i<dirNames.length;i++){
99             FileObject dir = repository.getFileObject(dirNames[i]);
100             if (dir == null) {
101                 try {
102                     repository.createFolder(dirNames[i]);
103                 } catch (IOException JavaDoc ioe) {
104                     ErrorManager.getDefault().notify(ioe);
105                 }
106             }
107         }
108         
109         FileObject workDir = repository.getFileObject(PiagetProjectFactory.PARSED_DIR);
110         File JavaDoc f = FileUtil.toFile(workDir);
111         this.workPath = f.getAbsolutePath();
112         
113         /*FileObject repFO = projectFileObject.getFileObject(PiagetProjectFactory.PROJECT_DIR);
114         FileObject parsedFO = repFO.getFileObject(PiagetProjectFactory.PARSED_DIR);
115         if (parsedFO == null) {
116             try {
117                 parsedFO = repFO.createFolder(PiagetProjectFactory.PARSED_DIR);
118             } catch (IOException ioe) {
119                 ErrorManager.getDefault().notify(ioe);
120             }
121         }
122         */

123     }
124     
125     
126     /** Implementation of project system's ProjectInformation class */
127     private final class Info implements ProjectInformation {
128         public Icon JavaDoc getIcon() {
129             return new ImageIcon JavaDoc(Utilities.loadImage(
130                     "org/netbeans/modules/piagetproject/resources/project.png"));
131         }
132         
133         public String JavaDoc getName() {
134             return getProjectDirectory().getName();
135         }
136         
137         public String JavaDoc getDisplayName() {
138             return getName();
139         }
140         
141         public void addPropertyChangeListener(PropertyChangeListener JavaDoc pcl) {
142             //do nothing, won't change
143
}
144         
145         public void removePropertyChangeListener(PropertyChangeListener JavaDoc pcl) {
146             //do nothing, won't change
147
}
148         
149         public Project getProject() {
150             return PiagetProject.this;
151         }
152     }
153     
154 }
155
Popular Tags