ref = pgdef.getComponentDefinition(cls, true); if (ref == null) //return null if not found ref = Components.getDefinitionByDeviceType(langdef.getDeviceType(), cls);
/** Returns the component definition of the specified class, or null * if not found. */ /*package*/ static ComponentDefinition getDefinition(Execution exec, Class<? extends Component> cls) { if (exec != null) { final ExecutionCtrl execCtrl = (ExecutionCtrl) exec; final PageDefinition pgdef = execCtrl.getCurrentPageDefinition(); final Page page = execCtrl.getCurrentPage(); final ComponentDefinition compdef = pgdef != null ? pgdef.getComponentDefinition(cls, true) : page != null ? page.getComponentDefinition(cls, true) : null; if (compdef != null && compdef.getLanguageDefinition() != null) return compdef; //already from langdef (not from pgdef) final ComponentDefinition compdef2 = Components.getDefinitionByDeviceType(exec.getDesktop().getDeviceType(), cls); return compdef != null && (compdef2 == null || !Objects.equals(compdef.getImplementationClass(), compdef2.getImplementationClass())) ? compdef : compdef2; //Feature 2816083: use compdef2 if same class } for (String deviceType : LanguageDefinition.getDeviceTypes()) { final ComponentDefinition compdef = Components.getDefinitionByDeviceType(deviceType, cls); if (compdef != null) return compdef; } return null; }
public void setDefinition(String name) { final Execution exec = Executions.getCurrent(); if (exec != null) { final ExecutionCtrl execCtrl = (ExecutionCtrl) exec; final PageDefinition pgdef = execCtrl.getCurrentPageDefinition(); final Page page = execCtrl.getCurrentPage(); ComponentDefinition compdef = pgdef != null ? pgdef.getComponentDefinition(name, true) : page != null ? page.getComponentDefinition(name, true) : null; if (compdef == null) compdef = Impls.getDefinitionByDeviceType(this, exec.getDesktop().getDeviceType(), name); if (compdef != null) { setDefinition(compdef); return; } } else { for (String deviceType : LanguageDefinition.getDeviceTypes()) { final ComponentDefinition compdef = Impls.getDefinitionByDeviceType(this, deviceType, name); if (compdef != null) { setDefinition(compdef); return; } } } throw new ComponentNotFoundException(name + " not found"); }