Java Code Examples for org.openide.modules.ModuleInfo#addPropertyChangeListener()

The following examples show how to use org.openide.modules.ModuleInfo#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: HpiPluginWarning.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Messages({
    "HpiPluginWarning_problem_displayName=Missing Hudson/Jenkins plugin support",
    "HpiPluginWarning_problem_description=Hudson/Jenkins plugin development support was removed from NetBeans 7.3. Install https://github.com/stapler/netbeans-stapler-plugin (available from Plugin Portal).",
    "HpiPluginWarning_unresolved=Automated installation from Plugin Portal not yet implemented; install the “Jenkins Plugin Support” and “Stapler Support” plugins."
})
@Override public Collection<? extends ProjectProblem> getProblems() {
    for (ModuleInfo mi : modules.allInstances()) {
        if (mi.getCodeNameBase().equals("org.kohsuke.stapler.netbeans.jenkinsdev")) {
            if (mi.isEnabled()) {
                return Collections.emptySet();
            } else {
                mi.addPropertyChangeListener(WeakListeners.propertyChange(this, mi));
                // XXX better to display a specialized warning
                continue;
            }
        }
    }
    return Collections.singleton(ProjectProblem.createWarning(HpiPluginWarning_problem_displayName(), HpiPluginWarning_problem_description(), new ProjectProblemResolverImpl()));
}
 
Example 2
Source File: FeatureManager.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void resultChanged(LookupEvent ev) {
    for (ModuleInfo m : result.allInstances()) {
        m.removePropertyChangeListener(this);
        m.addPropertyChangeListener(this);
    }
    Set<String> tmp = new HashSet<String>();
    for (ModuleInfo mi : result.allInstances()) {
        if (mi.isEnabled()) {
            tmp.add(mi.getCodeNameBase());
        }
    }
    enabledCnbs = tmp;
    if (ev != null) {
        fireChange();
    }
}
 
Example 3
Source File: Lookup.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void listenOn(ClassLoader cl) {
    boolean doesNotContainCl = false;
    synchronized(moduleChangeListeners) {
        if (!moduleChangeListeners.containsKey(cl)) {
            doesNotContainCl = true;
        }
    }
    if (doesNotContainCl) {
        Collection<? extends ModuleInfo> allInstances = moduleLookupResult.allInstances();
        synchronized (moduleChangeListeners) {
            if (!moduleChangeListeners.containsKey(cl)) { // Still does not contain
                for (ModuleInfo mi : allInstances) {
                    if (mi.isEnabled() && mi.getClassLoader() == cl) {
                        ModuleChangeListener l = new ModuleChangeListener(cl);
                        mi.addPropertyChangeListener(WeakListeners.propertyChange(l, mi));
                        moduleChangeListeners.put(cl, l);
                    }
                }
            }
        }
    }
}
 
Example 4
Source File: ModuleCache.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void resultChanged(LookupEvent ev) {
    for (ModuleInfo m : result.allInstances()) {
        m.removePropertyChangeListener(this);
        m.addPropertyChangeListener(this);
    }
    Map<String,ModuleInfo> tmp = new HashMap<String,ModuleInfo>();
    for (ModuleInfo mi : result.allInstances()) {
        tmp.put(mi.getCodeNameBase(), mi);
    }
    infos = tmp;
    if (ev != null) {
        fireChange();
    }
}
 
Example 5
Source File: ModuleInfoManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** replace an old module info with a new one */
void setModuleInfo(ModuleInfo mi) {
    this.mi.removePropertyChangeListener(this);
    aModuleHasBeenChanged = true;
    this.mi = mi;
    mi.addPropertyChangeListener(this);
}
 
Example 6
Source File: Lookup.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void listenOnDisabledModules() {
    Collection<? extends ModuleInfo> allInstances = moduleLookupResult.allInstances();
    synchronized (moduleChangeListeners) {
        for (ModuleInfo mi : allInstances) {
            if (!mi.isEnabled() && !disabledModuleChangeListeners.containsKey(mi)) {
                ModuleChangeListener l = new ModuleChangeListener(null);
                mi.addPropertyChangeListener(WeakListeners.propertyChange(l, mi));
                disabledModuleChangeListeners.put(mi, l);
            }
        }
    }
}
 
Example 7
Source File: ModuleInfoManager.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public PCL(ModuleInfo mi) {
    this.mi = mi;
    wasModuleEnabled = mi.isEnabled();
    mi.addPropertyChangeListener(this);
}
 
Example 8
Source File: AbstractTestUtil.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
     * Enbles <code>enable = true</code>  or disables <code>enable = false</code> the module.
     */
    public static void switchModule(String codeName, boolean enable) throws Exception {
        String statusFile = "Modules/" + codeName.replace('.', '-') + ".xml";
        ModuleInfo mi = getModuleInfo(codeName);
/*
        FileObject fo = findFileObject(statusFile);
        Document document = XMLUtil.parse(new InputSource(fo.getInputStream()), false, false, null, EntityCatalog.getDefault());
        //Document document = XMLUtil.parse(new InputSource(data.getPrimaryFile().getInputStream()), false, false, null, EntityCatalog.getDefault());
        NodeList list = document.getElementsByTagName("param");
 
        for (int i = 0; i < list.getLength(); i++) {
            Element ele = (Element) list.item(i);
            if (ele.getAttribute("name").equals("enabled")) {
                ele.getFirstChild().setNodeValue(enable ? "true" : "false");
                break;
            }
        }
 
        FileLock lock = fo.lock();
        OutputStream os = fo.getOutputStream(lock);
        XMLUtil.write(document, os, "UTF-8");
        lock.releaseLock();
        os.close();
 */
        
        // module is switched
        if (mi.isEnabled() == enable) {
            return;
        }
        
        DataObject data = findDataObject(statusFile);
        EditorCookie ec = (EditorCookie) data.getCookie(EditorCookie.class);
        StyledDocument doc = ec.openDocument();
        
        // Change parametr enabled
        String stag = "<param name=\"enabled\">";
        String etag = "</param>";
        String enabled = enable ? "true" : "false";
        String result;
        
        String str = doc.getText(0,doc.getLength());
        int sindex = str.indexOf(stag);
        int eindex = str.indexOf(etag, sindex);
        if (sindex > -1 && eindex > sindex) {
            result = str.substring(0, sindex + stag.length()) + enabled + str.substring(eindex);
            //System.err.println(result);
        } else {
            //throw new IllegalStateException("Invalid format of: " + statusFile + ", missing parametr 'enabled'");
            // Probably autoload module
            return;
        }
        
        // prepare synchronization and register listener
        final Waiter waiter = new Waiter();
        final PropertyChangeListener pcl = new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
                if (evt.getPropertyName().equals("enabled")) {
                    waiter.notifyFinished();
                }
            }
        };
        mi.addPropertyChangeListener(pcl);
        
        // save document
        doc.remove(0,doc.getLength());
        doc.insertString(0,result,null);
        ec.saveDocument();
        
        // wait for enabled propety change and remove listener
        waiter.waitFinished();
        mi.removePropertyChangeListener(pcl);
    }