I'm trying to create a mechanism to track changes to Vision Windows in a specific project from within a module.
The SDK Programmer's Guide says:
Modules can add a
ProjectListener
to theProjectManager
in order to be notified when a project is added, removed, or modified. It is important to remember that the listener will be notified for all projects, and that the Project object provided will only be the difference between the last project state and the new one. If the full project is required, for example to resolve full folder paths of resources, you should retrieve it from the ProjectManager using the id provided by the supplied project.
However, the ProjectListener interface appears to only define signatures that provide a string with the name of the project that was added, modified or deleted, and I have not been able to figure out what has changed.
Browsing the JavaDocs, I saw the ProjectResourceListener interface, which seemed to be exactly what I was looking for.
Within my GatewayHook's setup method, I obtained a reference to the project I want to monitor and attempted to add a ProjectResourceListener to it, but the events never seem to fire. I get nothing in the logs and breakpoints never hit with remote debugging.
Can anyone see what I'm doing wrong or point me in a better direction?
Here is the ProjectResourceListener implementation I tried to define and the relevant portion of the code I used to try to hook it up.
public class GatewayHook extends AbstractGatewayModuleHook {
private final Logger logger = LoggerFactory.getLogger(getClass());
private MyProjectResourceListener myProjectResourceListener = new MyProjectResourceListener();
@Override
public void setup(GatewayContext gatewayContext)
{
var myProject = gatewayContext.getProjectManager().getProject("MyProject");
if (myProject.isPresent()) {
myProject.get().addProjectResourceListener(myProjectResourceListener);
} else {
logger.warn("My project not found");
}
}
}
public class MyProjectResourceListener implements ProjectResourceListener {
private static Logger logger = LoggerFactory.getLogger(MyProjectResourceListener.class);
@Override
public void onBeforeChanges() {
ProjectResourceListener.super.onBeforeChanges();
}
@Override
public void onAfterChanges() {
ProjectResourceListener.super.onAfterChanges();
}
@Override
public void manifestChanged(String projectName, List<ChangeOperation.ManifestChangeOperation> operation) {
ProjectResourceListener.super.manifestChanged(projectName, operation);
}
@Override
public void resourcesCreated(String s, List<ChangeOperation.CreateResourceOperation> list) {
logger.info("Resources created: " + s);
}
@Override
public void resourcesModified(String s, List<ChangeOperation.ModifyResourceOperation> list) {
logger.info("Resources modified: " + s);
}
@Override
public void resourcesDeleted(String s, List<ChangeOperation.DeleteResourceOperation> list) {
logger.info("Resources deleted: " + s);
}
@Override
public ResourceFilter getResourceFilter() {
return ProjectResourceListener.super.getResourceFilter();
}
}