JaroslavTulach commented on code in PR #9636:
URL: https://github.com/apache/netbeans/pull/9636#discussion_r4133540976
##########
ergonomics/ide.ergonomics/src/org/netbeans/modules/ide/ergonomics/fod/FeatureProjectFactory.java:
##########
@@ -635,6 +640,38 @@ public Node findPath(Node root, Object target) {
}
return null;
}
+
+ @NbBundle.Messages({
+ "MSG_OnMissingSourceGroup=Project initialization requested",
+ "# {0} - name of the project",
+ "MSG_FullyInitializeProject=Should we open the {0} project and
initialize it fully?",
+ })
+ @Override
+ public SourceGroup[] getSourceGroups(String type) {
+ var src = delegate.lookup(Sources.class);
+ if (src != null && src != this) {
+ return src.getSourceGroups(type);
+ }
+ Project prj = getLookup().lookup(Project.class);
+ if (prj != null && openingPrj == null) {
+ openingPrj = NotificationDisplayer.getDefault().notify(
+ Bundle.MSG_OnMissingSourceGroup(), loadIcon(),
+ Bundle.MSG_FullyInitializeProject(getDisplayName()),
+ (ev) -> {
+ OpenProjects.getDefault().open(new Project[] { prj },
false);
+ }
+ );
+ }
+ return new SourceGroup[0];
Review Comment:
@MartinBalin told me there are two problems:
- original code had `GenericSources.genericOnly(project)` for
`Sources.TYPE_GENERIC`
- listeners aren't implemented. They should as after `associate()` the old
`Sources` impl starts to return new values without firing any event
```java
public class Test {
static int notifications, cleared;
public static class Services extends ProxyLookup {
public Services() { super(Lookups.fixed(new Displayer(),
(ProjectInformationProvider) p ->
p.getLookup().lookup(ProjectInformation.class))); }
}
static class Displayer extends NotificationDisplayer {
public Notification notify(String t, Icon i, String d,
ActionListener a, Priority p) {
notifications++;
return new Notification() { public void clear() { cleared++; } };
}
public Notification notify(String t, Icon i, JComponent b,
JComponent d, Priority p) { throw new AssertionError(); }
}
static class RealProject implements Project, Sources {
final FileObject dir;
final ChangeSupport changes = new ChangeSupport(this);
final SourceGroup group;
RealProject(FileObject dir) {
this.dir = dir;
this.group = GenericSources.group(this, dir, "generic", "real",
null, null);
}
public FileObject getProjectDirectory() { return dir; }
public Lookup getLookup() { return Lookups.singleton(this); }
public SourceGroup[] getSourceGroups(String type) { return new
SourceGroup[]{ group }; }
public void addChangeListener(ChangeListener l) {
changes.addChangeListener(l); }
public void removeChangeListener(ChangeListener l) {
changes.removeChangeListener(l); }
}
public static void main(String[] args) throws Exception {
var dir =
FileUtil.createMemoryFileSystem().getRoot().createFolder("project");
Class<?> clazz =
Class.forName("org.netbeans.modules.ide.ergonomics.fod.FeatureProjectFactory$FeatureNonProject");
var ctor = clazz.getDeclaredConstructors()[0];
ctor.setAccessible(true);
Project p = (Project)ctor.newInstance(dir, null, null,
Collections.emptyList());
Sources s = ProjectUtils.getSources(p);
System.out.println("generic roots: " +
s.getSourceGroups(Sources.TYPE_GENERIC).length);
System.out.println("notifications for generic query: " +
notifications);
if (!(s instanceof Lookup.Provider)) return; // baseline has generic
fallback
int[] events = { 0 };
s.addChangeListener(e -> events[0]++);
RealProject real = new RealProject(dir);
var associate = s.getClass().getDeclaredMethod("associate",
Project.class); associate.setAccessible(true);
associate.invoke(s, real);
System.out.println("roots after association: " +
s.getSourceGroups(Sources.TYPE_GENERIC).length);
System.out.println("events after association: " + events[0]);
real.changes.fireChange();
System.out.println("events after delegate change: " + events[0]);
System.out.println("notifications cleared after association: " +
cleared);
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists