Update Center issue: How to hide/remove items from the Available Plugins tab

"jhuber" <[email protected]>
Newsgroups gmane.comp.java.netbeans.modules.openide.devel
Message-ID <[email protected]>
In case anyone is interested, I finally got back to this issue after being shuffled around between projects and came up with a solution.  

This involves patching the Auto Update UI platform module.  I'm working with NB platform 8.0.2.

In org.netbeans.modules.autoupdate.ui.api, which is a public package, I added a new class UpdateUnitListModifier, which very simply is


Code:
[...]
package org.netbeans.modules.autoupdate.ui.api;

import java.util.List;
import org.netbeans.api.autoupdate.UpdateUnit;

/** <code>UpdateUnitListModifier</code> modifies a list of {@link org.netbeans.api.autoupdate.UpdateUnit} items. 
 * After {@link org.netbeans.modules.autoupdate.ui.PluginManagerUI} creates the list, 
 * it looks for providers of this service registered in the global lookup, and calls them to modify the list.
 *
 * @author jhuber
 */
public interface UpdateUnitListModifier {
    public List<UpdateUnit> modifyList(List<UpdateUnit> uList);
}



Then, in org.netbeans.modules.autoupdate.ui, I modified PuginManagerUI.java by adding code noted below to initialize() after line 251:


Code:
[...]
private void initialize () {
        try {
            final List<UpdateUnit> uu = UpdateManager.getDefault().getUpdateUnits(Utilities.getUnitTypes());
//            List<UnitCategory> precompute1 = Utilities.makeUpdateCategories (uu, false);
            if (localTable != null) {
                final List<UpdateUnit> nbms = new ArrayList<UpdateUnit>(((LocallyDownloadedTableModel) localTable.getModel()).getLocalDownloadSupport().getUpdateUnits());
                List<UnitCategory> precompute2 = Utilities.makeUpdateCategories (nbms, true);
            }

//new code            
            Collection<?> col1 = Lookup.getDefault().lookupAll(UpdateUnitListModifier.class);
            if (!col1.isEmpty()) {
                for (Object k1 : col1) {
                    ((UpdateUnitListModifier)k1).modifyList(uu);
                }
            }            
//end new code
            
            // postpone later
            refreshUnitsInBackground(uu);
[...]




Finally in my application, I have an UpdateUnitListModifier service provider to manipulate the UpdateUnit list.


Code:
[...]
@ServiceProvider(service=UpdateUnitListModifier.class)
public class UpdateModifier implements UpdateUnitListModifier {

    @Override
    public List<UpdateUnit> modifyList(List<UpdateUnit> uList) {      
          Iterator<UpdateUnit> it1 = uList.iterator();
          while (it1.hasNext()) {
                UpdateUnit u1 = it1.next();            
                String s1 = "com.dont.show.this.in.update.tab";
                if ((u1.getInstalled() == null) && u1.getCodeName().contentEquals(s1)) {
                   System.out.println ("This module should be removed from the list: " + u1.getCodeName());            
                   it1.remove();                
            }
        }
        return uList;
    }    
}




When one selects Tools>Plugins, PluginManagerUI goes about figuring out what is installed, what needs to be updated, and creates an UpdateUnit list with these items. Per the above modification, after this list is created and before the default Plugins window is displayed, PluginManagerUI now looks for service providers to modify this list.  The service provider(s) can go through the list and remove items from (or add items to) the list.  PluginManagerUI then goes on to process the list normally and display it in the various tabs of the Plugins window.

I've done some limited testing, but it seems to work as planned.  My next challenge is to figure out how to distribute the modified Auto Update UI platform module through my app's update center.  Not much out there about how to do that.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.