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;
}
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);
}
}
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);
}
Aggregations