11/*
2- * Copyright 2022 ebres .
2+ * Copyright 2022 Eric Bresie and friends. All rights reserved .
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1515 */
1616package org .apache .netbeans .modules .python4nb .project ;
1717
18- /**
19- *
20- * @author ebres
21- */
2218import java .awt .Image ;
2319import java .beans .PropertyChangeListener ;
20+ import java .io .File ;
21+ import java .util .Map ;
2422import javax .swing .Action ;
2523import javax .swing .Icon ;
2624import javax .swing .ImageIcon ;
25+ import org .apache .netbeans .modules .python4nb .project .PythonSources ;
2726import org .netbeans .api .annotations .common .StaticResource ;
2827import org .netbeans .api .project .Project ;
2928import org .netbeans .api .project .ProjectInformation ;
29+ import org .netbeans .spi .project .AuxiliaryConfiguration ;
3030import org .netbeans .spi .project .ProjectState ;
3131import org .netbeans .spi .project .support .ant .AntProjectHelper ;
3232import org .netbeans .spi .project .support .ant .PropertyEvaluator ;
33+ import org .netbeans .spi .project .support .ant .ReferenceHelper ;
3334import org .netbeans .spi .project .ui .LogicalViewProvider ;
3435import org .netbeans .spi .project .ui .support .CommonProjectActions ;
3536import org .openide .filesystems .FileObject ;
37+ import org .openide .filesystems .FileUtil ;
3638import org .openide .loaders .DataFolder ;
3739import org .openide .loaders .DataObjectNotFoundException ;
3840import org .openide .nodes .AbstractNode ;
4547import org .openide .util .lookup .Lookups ;
4648import org .openide .util .lookup .ProxyLookup ;
4749
50+ // Portions of this code are based on nbPython Code.
51+
52+ /**
53+ * This class is to reflect details and applicable attributes
54+ * about a given Python Project for use in NetBeans IDE.
55+ */
4856public class PythonProject implements Project {
4957
58+ public static final String SOURCES_TYPE_PYTHON = "python" ; //NOI18N
59+
5060 private final FileObject projectDir ;
51- private final ProjectState state ;
5261 protected SourceRoots sourceRoots ;
5362 protected SourceRoots testRoots ;
54- private Lookup lkp ;
55-
56- protected PropertyEvaluator evaluator ;
57- protected AntProjectHelper helper ;
63+ protected Lookup lkp ;
64+ protected PythonProjectProperties properties ;
65+ //TODO Determine if needed for future enhancements; remove if not needed
66+ // private final ProjectState state; // XXX May need
67+ // protected AntProjectHelper helper; // XXX May need some form of Helper
68+ // protected UpdateHelper updateHelper;
69+ // protected LogicalViewProvider logicalView = new PythonLogicalView(this);
70+ // protected PropertyEvaluator evaluator;
71+ // protected ReferenceHelper refHelper;
72+ // protected AuxiliaryConfiguration aux;
5873
5974 @ StaticResource ()
6075 public static final String PYTHON_PROJECT_ICON = "org/apache/netbeans/modules/python4nb/editor/py_module.png" ;
6176 PythonProject (FileObject dir , ProjectState state ) {
6277 this .projectDir = dir ;
63- this .state = state ;
78+ this .lkp = getLookup ();
79+ this .sourceRoots = getSourceRoots ();
80+ this .properties = getProperties ();
81+ // this.state = state;
82+ }
83+
84+ PythonProject (File dir ) {
85+ this .projectDir = FileUtil .toFileObject (dir );
86+ this .lkp = getLookup (); //createLookup();
87+ this .sourceRoots = getSourceRoots ();
88+ // this.state = ProjectState.state;
6489 }
6590
6691 @ Override
@@ -75,7 +100,9 @@ public Lookup getLookup() {
75100 this ,
76101 new PythonActionProvider (this ),
77102 new PythonInfo (),
78- new PythonProjectLogicalView (this )
103+ new PythonProjectLogicalView (this ),
104+ new PythonSources (this )
105+ //TODO Determine if needed for future enhancements; remove if not needed
79106// , new CustomizerProvider() {
80107// @Override
81108// public void showCustomizer() {
@@ -85,34 +112,68 @@ public Lookup getLookup() {
85112// getProjectDirectory().getName());
86113// }
87114// }
115+ // new ClassPathProviderImpl(this),
116+ // new Info(), // Project information Implementation
117+ // logicalView, // Logical view if project implementation
118+ // new PythonOpenedHook(), //Called by project framework when project is opened (closed)
119+ // new PythonProjectXmlSavedHook(), //Called when project.xml changes
120+ // new PythonSources(this, helper, evaluator, sourceRoots, testRoots), //Python source grops - used by package view, factories, refactoring, ...
121+ // new PythonProjectOperations(this), //move, rename, copy of project
122+ // new RecommendedTemplatesImpl(this.updateHelper), // Recommended Templates
123+ // new PythonCustomizerProvider(this), //Project custmoizer
124+ // new PythonFileEncodingQuery(),
125+ // new PythonProjectTemplateAttributesProvider(getEvaluator()),
126+ // new PythonSharabilityQuery(helper, getEvaluator(), getSourceRoots(), getTestRoots()), //Sharabilit info - used by VCS
127+ // helper.createCacheDirectoryProvider(), //Cache provider
128+ // helper.createAuxiliaryProperties(), // AuxiliaryConfiguraion provider - used by bookmarks, project Preferences, etc
129+ // new PythonPlatformProvider(getEvaluator()),
130+ // new PythonCoverageProvider(this),
131+ // new PythonProjectSourceLevelQuery(evaluator, "")
88132 });
89133 }
90134 return lkp ;
91135 }
92136
93- public PropertyEvaluator getEvaluator () {
94- return evaluator ;
137+ public SourceRoots getSourceRoots () {
138+ // if source root has not been established yet, try to set based on project directory
139+ if (this .sourceRoots == null ) {
140+ this .sourceRoots = SourceRoots .create (this );
141+ }
142+ return this .sourceRoots ;
143+ }
144+
145+ public SourceRoots getTestRoots () {
146+ return this .testRoots ;
95147 }
96148
97- AntProjectHelper getHelper () {
98- return this . helper ;
149+ public FileObject [] getSourceRootFiles () {
150+ return getSourceRoots (). getRoots () ;
99151 }
100152
101- public SourceRoots getSourceRoots () {
102- return this . sourceRoots ;
153+ public FileObject [] getTestSourceRootFiles () {
154+ return getTestRoots (). getRoots () ;
103155 }
156+
157+ public Object getName () {
158+ PythonInfo pi = lkp .lookup (PythonInfo .class );
159+ return pi .getName ();
160+ }
161+
162+ public PythonProjectProperties getProperties () {
163+ if (this .properties == null ) {
164+ this .properties = new PythonProjectProperties (this );
165+ this .properties .loadProperties ();
166+ }
167+ return properties ;
168+ }
104169
105170
106171
107172 private final class PythonInfo implements ProjectInformation {
108173
109- //@StaticResource()
110- // public static final String PYTHON_ICON = "org/apache/netbeans/modules/python4nb/editor/py.png";
111-
112174 @ Override
113175 public Icon getIcon () {
114176 return new ImageIcon (ImageUtilities .loadImage (PYTHON_PROJECT_ICON ));
115- // return new ImageIcon(ImageUtilities.loadImage(PYTHON_ICON));
116177 }
117178
118179 @ Override
@@ -143,12 +204,6 @@ public Project getProject() {
143204
144205 class PythonProjectLogicalView implements LogicalViewProvider {
145206
146- // @StaticResource()
147- // public static final String PYTHON_ICON = "org/apache/netbeans/modules/python4nb/editor/py.png";
148- //
149- // @StaticResource()
150- // public static final String PYTHON_PROJECT_ICON = "org/apache/netbeans/modules/python4nb/editor/py_module.png";
151-
152207 private final PythonProject project ;
153208
154209 public PythonProjectLogicalView (PythonProject project ) {
@@ -203,7 +258,6 @@ public Action[] getActions(boolean arg0) {
203258
204259 @ Override
205260 public Image getIcon (int type ) {
206- // return ImageUtilities.loadImage(PYTHON_ICON);
207261 return ImageUtilities .loadImage (PYTHON_PROJECT_ICON );
208262 }
209263
0 commit comments