@Override
 public void set(Input value) {
   List<Input> binds = Lists.newArrayList(config.getBinds(bindUri));
   if (value == null) {
     if (position < binds.size()) {
       binds.remove(position);
     }
   } else {
     if (position < binds.size()) {
       binds.set(position, value);
     } else {
       binds.add(value);
     }
   }
   config.setBinds(bindUri, binds);
 }
Ejemplo n.º 2
0
 /**
  * @return A new BindsConfig, with inputs set from the DefaultBinding annotations on bind classes
  */
 public static BindsConfig createDefault(Context context) {
   ModuleManager moduleManager = context.get(ModuleManager.class);
   BindsConfig config = new BindsConfig();
   DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
   for (Name moduleId : moduleManager.getRegistry().getModuleIds()) {
     if (moduleManager.getRegistry().getLatestModuleVersion(moduleId).isCodeModule()) {
       ResolutionResult result = resolver.resolve(moduleId);
       if (result.isSuccess()) {
         try (ModuleEnvironment environment =
             moduleManager.loadEnvironment(result.getModules(), false)) {
           config.addDefaultsFor(
               moduleId,
               environment.getTypesAnnotatedWith(
                   RegisterBindButton.class, new FromModule(environment, moduleId)));
         }
       }
     }
   }
   return config;
 }
 @Override
 public Input get() {
   return Iterators.get(config.getBinds(bindUri).iterator(), position, null);
 }