Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.cdlflex.ui.markup.html.badge.notifybar;
 
 import java.util.List;
 
A Component that dynamically populates a org.cdlflex.ui.markup.html.badge.BadgeList with components provided by a INotifyBarComponentProvider.

Its purpose is to bridge the gap between the org.cdlflex.ui.markup.html.badge.BadgeList and OSGi service-based design. In an OSGi use-case, one would implement an INotifyBarComponentProvider as a service aggregator, which allows INotifyBarComponents to be provided from different bundles.

 
 public class NotifyBar extends Panel {
     private static final long serialVersionUID = 1L;
 
     private static final Logger LOG = LoggerFactory.getLogger(NotifyBar.class);
 
 
     public NotifyBar(String idINotifyBarComponentProvider componentProvider) {
         super(id);
         this. = componentProvider;
     }
 
         return ;
     }
 
     public void setComponentProvider(INotifyBarComponentProvider componentProvider) {
         this. = componentProvider;
     }
 
     @Override
     protected void onInitialize() {
         super.onInitialize();
 
         add(newBadgeList("badge-list"));
     }

    
Factory method that creates the BadgeList to be displayed.

Parameters:
id the component id
Returns:
a new BadgeList
 
     protected Component newBadgeList(String id) {
         return new BadgeList(idnew BadgeItemProvidingModel());
     }
 
     @Override
     protected void onComponentTag(ComponentTag tag) {
         super.onComponentTag(tag);
         CssClassNameAppender.append(tag"notifybar");
     }

    
Model that provides BadgeListItems from the INotifyBarComponentProvider of this NotifyBar instance.
 
     protected class BadgeItemProvidingModel extends AbstractReadOnlyModel<List<? extends BadgeListItem>> {
         private static final long serialVersionUID = 1L;
 
         @Override
         public List<? extends BadgeListItemgetObject() {
             INotifyBarComponentProvider provider = getComponentProvider();
             if (provider == null) {
                 .warn("INotifyBarComponentProvider is null, can not populate NotifyBar");
                 return Collections.emptyList();
             }
 
             List<INotifyBarComponentcomponents = new ArrayList<>(provider.getComponents());
             Collections.retain(componentsnew VisibilityFilter()); // remove all components that are not visible
             Collections.sort(componentsnew ComponentPriorityComparator()); // sort them by priority
            return Collections.map(componentsnew BadgeListItemFactory()); // create the BadgeListItems
        }
    }

    
A Comparator that compares INotifyBarComponent elements based on their priority.
    private static class ComponentPriorityComparator implements Comparator<INotifyBarComponent> {
        @Override
        public int compare(INotifyBarComponent o1INotifyBarComponent o2) {
            return Integer.compare(o1.getPriority(), o2.getPriority());
        }
    }

    
Callback that creates BadgeListItemAdapter instances from INotifyBarComponent.
    private static class BadgeListItemFactory implements Collections.Callback<INotifyBarComponentBadgeListItem> {
        @Override
        public BadgeListItem call(INotifyBarComponent component) {
            return new BadgeListItemAdapter(component);
        }
    }

    
Predicate that delegates access to INotifyBarComponent.isVisible().
    private static class VisibilityFilter implements Collections.Predicate<INotifyBarComponent> {
        @Override
        public Boolean call(INotifyBarComponent object) {
            return object.isVisible();
        }
    }
New to GrepCode? Check out our FAQ X