Search in sources :

Example 31 with ModuleInfo

use of org.openide.modules.ModuleInfo in project netbeans-rcp-lite by outersky.

the class DataLoaderPool method getPreferredLoader.

/**
 * Get the preferred loader for a file.
 * @param fo the file to get loader from
 * @return the loader or null if there is no particular preferred loader
 */
public static DataLoader getPreferredLoader(FileObject fo) {
    String assignedLoaderName = (String) fo.getAttribute(DataObject.EA_ASSIGNED_LOADER);
    if (assignedLoaderName != null) {
        // First check to see if it comes from an uninstalled module.
        String modulename = (String) fo.getAttribute(DataObject.EA_ASSIGNED_LOADER_MODULE);
        if (modulename != null) {
            // [PENDING] in the future a more efficient API may be introduced
            // (actually currently you can look up with a template giving the name
            // as part of the lookup item ID but this is not an official API)
            Iterator modules = Lookup.getDefault().lookupAll(ModuleInfo.class).iterator();
            boolean ok = false;
            while (modules.hasNext()) {
                ModuleInfo module = (ModuleInfo) modules.next();
                if (module.getCodeNameBase().equals(modulename)) {
                    if (module.isEnabled()) {
                        // Carry on.
                        ok = true;
                        break;
                    } else {
                        // Uninstalled module.
                        return null;
                    }
                }
            }
            if (!ok) {
                // Unknown module.
                return null;
            }
        }
        // else don't worry about it (compatibility)
        try {
            ClassLoader load = Lookup.getDefault().lookup(ClassLoader.class);
            if (load == null) {
                load = DataLoaderPool.class.getClassLoader();
            }
            return DataLoader.getLoader(Class.forName(assignedLoaderName, true, load).asSubclass(DataLoader.class));
        } catch (Exception ex) {
            Logger.getLogger(DataLoaderPool.class.getName()).log(Level.WARNING, null, ex);
        }
    }
    return null;
}
Also used : ModuleInfo(org.openide.modules.ModuleInfo)

Example 32 with ModuleInfo

use of org.openide.modules.ModuleInfo in project netbeans-rcp-lite by outersky.

the class DataLoaderPool method setPreferredLoader.

/**
 * Utility method to mark a file as belonging to a loader.
 * When the file is to be recognized this loader will be used first.
 *
 * @param fo file to mark
 * @param loader the loader to assign to the file or null if previous
 *    association should be cleared
 * @exception IOException if setting the file's attribute failed
 */
public static void setPreferredLoader(FileObject fo, DataLoader loader) throws IOException {
    DataLoader prev = getPreferredLoader(fo);
    if (prev == loader) {
        return;
    }
    if (loader == null) {
        fo.setAttribute(DataObject.EA_ASSIGNED_LOADER, null);
    } else {
        Class c = loader.getClass();
        fo.setAttribute(DataObject.EA_ASSIGNED_LOADER, c.getName());
        ModuleInfo module = Modules.getDefault().ownerOf(c);
        if (module != null) {
            fo.setAttribute(DataObject.EA_ASSIGNED_LOADER_MODULE, module.getCodeNameBase());
        }
    }
    Set<FileObject> one = new HashSet<FileObject>();
    one.add(fo);
    if (!DataObjectPool.getPOOL().revalidate(one).isEmpty()) {
        // NOI18N
        DataObject.LOG.log(Level.FINE, "It was not possible to invalidate data object: {0}", fo);
    }
}
Also used : ModuleInfo(org.openide.modules.ModuleInfo)

Example 33 with ModuleInfo

use of org.openide.modules.ModuleInfo in project constellation by constellation-app.

the class MostRecentModuleAction method actionPerformed.

@Override
public void actionPerformed(final ActionEvent e) {
    final List<ModuleInfo> moduleList = MostRecentModules.getModules();
    final StringBuilder sb = new StringBuilder();
    moduleList.stream().forEach(mi -> sb.append(String.format("%-40s %20s\n", mi.getDisplayName(), mi.getSpecificationVersion())));
    final InfoTextPanel itp = new InfoTextPanel(sb.toString());
    final NotifyDescriptor.Message msg = new NotifyDescriptor.Message(itp);
    msg.setTitle(Bundle.CTL_MostRecentModuleAction());
    DialogDisplayer.getDefault().notify(msg);
}
Also used : NotifyDescriptor(org.openide.NotifyDescriptor) ModuleInfo(org.openide.modules.ModuleInfo) InfoTextPanel(au.gov.asd.tac.constellation.utilities.gui.InfoTextPanel)

Aggregations

ModuleInfo (org.openide.modules.ModuleInfo)33 HashSet (java.util.HashSet)8 SpecificationVersion (org.openide.modules.SpecificationVersion)7 HashMap (java.util.HashMap)6 UpdateUnit (org.netbeans.api.autoupdate.UpdateUnit)5 UpdateElement (org.netbeans.api.autoupdate.UpdateElement)4 IOException (java.io.IOException)3 Module (org.netbeans.Module)3 Dependency (org.openide.modules.Dependency)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 UpdateItem (org.netbeans.spi.autoupdate.UpdateItem)2 DataLoader (org.openide.loaders.DataLoader)2 Lookup (org.openide.util.Lookup)2 NbMarshalledObject (org.openide.util.io.NbMarshalledObject)2 InfoTextPanel (au.gov.asd.tac.constellation.utilities.gui.InfoTextPanel)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Enumeration (java.util.Enumeration)1