All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.tidalwave.bluebill.mobile.media.impl.MediaPresentationModel Maven / Gradle / Ivy

/***********************************************************************************************************************
 *
 * blueBill Mobile - Android - open source birding
 * Copyright (C) 2009-2011 by Tidalwave s.a.s. (http://www.tidalwave.it)
 *
 ***********************************************************************************************************************
 *
 * 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.
 *
 ***********************************************************************************************************************
 *
 * WWW: http://bluebill.tidalwave.it/mobile
 * SCM: https://java.net/hg/bluebill-mobile~android-src
 *
 **********************************************************************************************************************/
package it.tidalwave.bluebill.mobile.media.impl;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import it.tidalwave.role.ui.spi.DefaultPresentationModel;
import it.tidalwave.mobile.media.Media;
import static it.tidalwave.role.Identifiable.Identifiable;
import static it.tidalwave.role.PlainTextRenderable.PlainTextRenderable;
import static it.tidalwave.mobile.util.Downloadable.*;

/***********************************************************************************************************************
 *
 * FIXME: this class only exists for the patch below.
 * 
 * @author  Fabrizio Giudici
 * @version $Id$
 *
 **********************************************************************************************************************/
/* package */ class MediaPresentationModel extends DefaultPresentationModel
  {    
    public MediaPresentationModel (final @Nonnull Media media, final @Nonnull Object ... capabilities)
      {
        // FIXME: Media doesn't expose Downloadable through its Lookup,
        // and AsLookupWithSupport doesn't include the owner Lookup when owner is Lookup.Provider.
        // So we have to explicitly expose those roles below.
        super(merged(new Object[] 
                       { 
                         media,
                         media.as(Downloadable), 
                         media.as(Identifiable), 
                         media.as(Removable),
                         media.as(PlainTextRenderable) 
                       }, 
                     capabilities));
      }
    
    @Nonnull
    private static Object[] merged (final @Nonnull Object[] a, final @Nonnull Object[] b)
      {  
        final List result = new ArrayList();
        result.addAll(Arrays.asList(a));
        result.addAll(Arrays.asList(b));
        
        return result.toArray();
      }
  }