Java Code Examples for org.netbeans.modules.maven.api.NbMavenProject#addPropertyChangeListener()

The following examples show how to use org.netbeans.modules.maven.api.NbMavenProject#addPropertyChangeListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MavenPersistenceProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new instance of MavenPersistenceProvider
 */
public MavenPersistenceProvider(Project proj, Lookup lkp)
{
    NbMavenProject watcher = lkp.lookup(NbMavenProject.class);
    locProvider    = new PersistenceLocationProviderImpl(proj, watcher);
    scopeProvider  = new PersistenceScopeProviderImpl(locProvider, proj);
    scopesProvider = new PersistenceScopesProviderImpl(scopeProvider);
    
    propChangeSupport.addPropertyChangeListener(locProvider);
    propChangeSupport.addPropertyChangeListener(scopesProvider);
            
    //TODO add FileChangeListener on persistence.xml
    watcher.addWatchedPath(PersistenceLocationProviderImpl.DEF_PERSISTENCE);
    watcher.addWatchedPath(PersistenceLocationProviderImpl.ALT_PERSISTENCE);
    watcher.addPropertyChangeListener(WeakListeners.propertyChange(res, watcher));
}
 
Example 2
Source File: DependenciesNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")       
DependenciesSet(NbMavenProjectImpl project, DependencyType type) {
    this.project = project;
    this.type = type;
    ModuleInfoSupport mis = null;
    switch (type) {   
        case COMPILE:
        case TEST:
            try {
                mis = new ModuleInfoSupport(project, type);
                break;
            } catch (LinkageError err) {
                LOG.log(Level.INFO, "Can't initialize dependencies", err);
                // fallthrough
            }
        default:
    }
    this.moduleInfoSupport = mis;
    
    NbMavenProject nbmp = project.getProjectWatcher();
    nbmp.addPropertyChangeListener(WeakListeners.propertyChange(this, nbmp));
}
 
Example 3
Source File: ModulesNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
ModulesChildFactory(NbMavenProjectImpl proj) {
    project = proj;
    NbMavenProject watcher = project.getProjectWatcher();
    listener = new PropertyChangeListener() {
                               @Override
                               public void propertyChange(PropertyChangeEvent evt) {
                                   if (NbMavenProject.PROP_PROJECT.equals(evt.getPropertyName())) {
                                       refresh(false);
                                   }
                               }
                           };
     
    watcher.addPropertyChangeListener(WeakListeners.propertyChange(listener, watcher));                       
    
 
}
 
Example 4
Source File: NbMavenProjectImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("LeakingThisInConstructor")
PackagingTypeDependentLookup(NbMavenProject watcher) {
    this.watcherRef = new WeakReference<NbMavenProject>(watcher);
    //needs to be kept around to prevent recreating instances
    general = Lookups.forPath("Projects/org-netbeans-modules-maven/Lookup"); //NOI18N
    check();
    watcher.addPropertyChangeListener(WeakListeners.propertyChange(this, watcher));
}
 
Example 5
Source File: AbstractProjectClassPathImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected AbstractProjectClassPathImpl(NbMavenProjectImpl proj) {
        project = proj;
        //TODO make weak or remove the listeners as well??
        NbMavenProject.addPropertyChangeListener(proj, new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                //explicitly listing both RESOURCE and PROJECT properties, it's unclear if both are required but since some other places call addWatchedPath but don't listen it's likely required
                if (NbMavenProject.PROP_RESOURCE.equals(evt.getPropertyName()) || NbMavenProject.PROP_PROJECT.equals(evt.getPropertyName())) {
                    if (project.getProjectWatcher().isUnloadable()) {
                        return; //let's just continue with the old value, stripping classpath for broken project and re-creating it later serves no greater good.
                    }
                    List<PathResourceImplementation> newValues = getPath();
                    List<PathResourceImplementation> oldvalue;
                    boolean hasChanged;
                    synchronized (AbstractProjectClassPathImpl.this) {
                        oldvalue = resources;
                        hasChanged = hasChanged(oldvalue, newValues);
//                        System.out.println("checking=" + AbstractProjectClassPathImpl.this.getClass());
                        if (hasChanged) {
                            resources = newValues;
//                            System.out.println("old=" + oldvalue);
//                            System.out.println("new=" + newValues);
//                            System.out.println("firing change=" + AbstractProjectClassPathImpl.this.getClass());
                        }
                    }
                    if (hasChanged) {
                        support.firePropertyChange(ClassPathImplementation.PROP_RESOURCES, oldvalue, newValues);
                    }
                }
            }
        });
    }
 
Example 6
Source File: AuxPropsImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public AuxPropsImpl(Project prj) {
    this.project = prj;
    defaults.add("config/sun_checks.xml");
    defaults.add("config/maven_checks.xml");
    defaults.add("config/avalon_checks.xml");
    defaults.add("config/turbine_checks.xml");
    NbMavenProject.addPropertyChangeListener(prj, this);
}
 
Example 7
Source File: J2eeMavenSourcesImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void addChangeListener(ChangeListener changeListener) {
    // If no listener were registered until now, start listening at project changes
    if (!cs.hasListeners()) {
        NbMavenProject.addPropertyChangeListener(project, pcl);
    }
    cs.addChangeListener(changeListener);
}
 
Example 8
Source File: GroovySourcesNodeFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void addNotify() {
    NbMavenProject watch = project.getLookup().lookup(NbMavenProject.class);
    watch.addPropertyChangeListener(this);
    watch.addWatchedPath(MAIN_GROOVY);
    watch.addWatchedPath(TEST_GROOVY);
    checkFileObject(MAIN_GROOVY);
    checkFileObject(TEST_GROOVY);
}
 
Example 9
Source File: MavenFileLocator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public MavenFileLocator(Project project) {
    this.project = project;
    NbMavenProject.addPropertyChangeListener(project, new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
             //explicitly listing both RESOURCE and PROJECT properties, it's unclear if both are required but since some other places call addWatchedPath but don't listen it's likely required
            if (NbMavenProject.PROP_RESOURCE.equals(evt.getPropertyName()) || NbMavenProject.PROP_PROJECT.equals(evt.getPropertyName())) {
                synchronized (LOCK) {
                    classpath = null;
                }
            }
        }
    });
}
 
Example 10
Source File: MavenForBinaryQueryImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public MavenForBinaryQueryImpl(Project proj) {
    p = proj;
    map = new HashMap<String, BinResult>();
    NbMavenProject.addPropertyChangeListener(proj, new PropertyChangeListener() {
        public @Override void propertyChange(PropertyChangeEvent event) {
            if (NbMavenProject.PROP_PROJECT.equals(event.getPropertyName())) {
                if (p.getLookup().lookup(NbMavenProject.class).isUnloadable()) {
                    return; //let's just continue with the old value, reloading classpath for broken project and re-creating it later serves no greater good.
                }
                ForeignClassBundler bundler = p.getLookup().lookup(ForeignClassBundler.class);
                boolean oldprefer = bundler.preferSources();
                bundler.resetCachedValue();
                boolean preferChanged = oldprefer != bundler.preferSources();
                synchronized (map) {
                    for (BinResult res : map.values()) {
                        FileObject[] cached = res.getCached();
                        res.cached = null; // force refresh to see if we have to fire changes
                        FileObject[] current = res.getRoots();
                        if (preferChanged || !Arrays.equals(cached, current)) {
                            LOGGER.log(Level.FINE, "SFBQ.Result changed from {0} to {1}", new Object[]{Arrays.toString(cached), Arrays.toString(current)});
                            res.fireChanged();
                        }
                    }
                }
            }
        }
    });
}
 
Example 11
Source File: DependenciesNodeFactory.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void addNotify() {
    NbMavenProject.addPropertyChangeListener(project, this);
}
 
Example 12
Source File: DependencyNode.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public DependencyNode(
        NbMavenProjectImpl project,
        final Artifact art,
        final FileObject fo,
        boolean isLongLiving,
        Node nodeDelegate, 
        Supplier<Boolean> canAddToModuleInfo) {
    super(createChildren(nodeDelegate), createLookup(project, art, nodeDelegate, canAddToModuleInfo));
    this.data = getLookup().lookup(Data.class);
    data.fileObject.set(fo);
    longLiving = isLongLiving;

    if (longLiving) {
        listener = new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                if (NbMavenProject.PROP_PROJECT.equals(evt.getPropertyName())) {
                    refreshNode();
                }
            }
        };
        NbMavenProject.addPropertyChangeListener(project, WeakListeners.propertyChange(listener, project.getProjectWatcher()));
        listener2 = new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent event) {
                if (event instanceof MavenFileOwnerQueryImpl.GAVCHangeEvent) {
                    MavenFileOwnerQueryImpl.GAVCHangeEvent ev = (MavenFileOwnerQueryImpl.GAVCHangeEvent) event;
                    if (ev.matches(art)) {
                        refreshNode();
                    }
                } else {
                    refreshNode();
                }
            }
        };
        //TODO check if this one is a performance bottleneck.
        MavenFileOwnerQueryImpl.getInstance().addChangeListener(
                WeakListeners.change(listener2,
                MavenFileOwnerQueryImpl.getInstance()));
        DependenciesNode.prefs().addPreferenceChangeListener(WeakListeners.create(PreferenceChangeListener.class, this, DependenciesNode.prefs()));
    }
    setDisplayName(createName(false));
    setIconBase(false);
    if (longLiving) {
        RP.post(new Runnable() {
            @Override
            public void run() {
                refreshNode();
            }
        });
    }
    data.setNode(this);
}
 
Example 13
Source File: ModulesNodeFactory.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void addNotify() {
    NbMavenProject.addPropertyChangeListener(project, this);
}
 
Example 14
Source File: SiteDocsNodeFactory.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void addNotify() {
    NbMavenProject.addPropertyChangeListener(project, this);
    FileUtil.addFileChangeListener(this, Utilities.toFile(project.getSiteDirectory()));
}
 
Example 15
Source File: GenSourcesNodeFactory.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void addNotify() {
    NbMavenProject.addPropertyChangeListener(project, this);
}
 
Example 16
Source File: OthersRootChildren.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
protected void addNotify() {
    super.addNotify();
    NbMavenProject.addPropertyChangeListener(project, changeListener);
    regenerateKeys();
}
 
Example 17
Source File: WebPagesNodeFactory.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void addNotify() {
    NbMavenProject.addPropertyChangeListener(project, this);
}
 
Example 18
Source File: MavenSourcesImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public @Override void addChangeListener(ChangeListener changeListener) {
    if (!cs.hasListeners()) {
        NbMavenProject.addPropertyChangeListener(project(), pcl);
    }
    cs.addChangeListener(changeListener);
}
 
Example 19
Source File: DependencyPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@NbBundle.Messages("TAB_Tree=Tree")
public static MultiViewElement forPOM(final Lookup editor) {
    class L extends ProxyLookup implements PropertyChangeListener {
        Project p;
        L() {
            FileObject pom = editor.lookup(FileObject.class);
            if (pom != null) {
                p = FileOwnerQuery.getOwner(pom);
                if (p != null) {
                    NbMavenProject nbmp = p.getLookup().lookup(NbMavenProject.class);
                    if (nbmp != null) {
                        nbmp.addPropertyChangeListener(WeakListeners.propertyChange(this, nbmp));
                        reset();
                    } else {
                        LOG.log(Level.WARNING, "not a Maven project: {0}", p);
                    }
                } else {
                    LOG.log(Level.WARNING, "no owner of {0}", pom);
                }
            } else {
                LOG.log(Level.WARNING, "no FileObject in {0}", editor);
            }
        }
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (NbMavenProject.PROP_PROJECT.equals(evt.getPropertyName())) {
                reset();
            }
        }
        private void reset() {
            ArtifactViewerFactory avf = Lookup.getDefault().lookup(ArtifactViewerFactory.class);
            if (avf != null) {
                Lookup l = avf.createLookup(p);
                if (l != null) {
                    setLookups(l);
                } else {
                    LOG.log(Level.WARNING, "no artifact lookup for {0}", p);
                }
            } else {
                LOG.warning("no ArtifactViewerFactory found");
            }
        }
    }
    return new DependencyPanel(new L(), false);
}
 
Example 20
Source File: DependencyGraphTopComponent.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@MultiViewElement.Registration(
    displayName="#TAB_Graph",
    iconBase=IconResources.ICON_DEPENDENCY_JAR,
    persistenceType=TopComponent.PERSISTENCE_NEVER,
    preferredID=ArtifactViewer.HINT_GRAPH,
    mimeType=Constants.POM_MIME_TYPE,
    position=100
)
@Messages("TAB_Graph=Graph")
public static MultiViewElement forPOM(final Lookup editor) {
    class L extends ProxyLookup implements PropertyChangeListener {
        Project p;
        L() {
            FileObject pom = editor.lookup(FileObject.class);
            if (pom != null) {
                p = FileOwnerQuery.getOwner(pom);
                if (p != null) {
                    NbMavenProject nbmp = p.getLookup().lookup(NbMavenProject.class);
                    if (nbmp != null) {
                        nbmp.addPropertyChangeListener(WeakListeners.propertyChange(this, nbmp));
                        reset();
                    } else {
                        LOG.log(Level.WARNING, "not a Maven project: {0}", p);
                    }
                } else {
                    LOG.log(Level.WARNING, "no owner of {0}", pom);
                }
            } else {
                LOG.log(Level.WARNING, "no FileObject in {0}", editor);
            }
        }
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (NbMavenProject.PROP_PROJECT.equals(evt.getPropertyName())) {
                reset();
            }
        }
        private void reset() {
            ArtifactViewerFactory avf = Lookup.getDefault().lookup(ArtifactViewerFactory.class);
            if (avf != null) {
                Lookup l = null;
                try {
                    l = avf.createLookup(p);
                } catch (InvalidArtifactRTException e) {
                    // issue #258898 
                    LOG.log(Level.WARNING, "problems while creating lookup for {"  + p + "} : " + e.getMessage(), e);
                }
                if (l != null) {
                    setLookups(l);
                } else {
                    LOG.log(Level.WARNING, "no artifact lookup for {0}", p);
                }
            } else {
                LOG.warning("no ArtifactViewerFactory found");
            }
        }
    }
    return new DependencyGraphTopComponent(new L());
}