001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019 020package org.apache.isis.core.progmodel.facets.object.membergroups; 021 022import java.util.Properties; 023 024import com.google.common.base.Splitter; 025import com.google.common.collect.Iterables; 026 027import org.apache.isis.applib.annotation.MemberGroupLayout.ColumnSpans; 028import org.apache.isis.core.commons.lang.StringFunctions; 029import org.apache.isis.core.commons.lang.StringPredicates; 030import org.apache.isis.core.metamodel.facetapi.FacetHolder; 031 032public class MemberGroupLayoutFacetProperties extends MemberGroupLayoutFacetAbstract { 033 034 public MemberGroupLayoutFacetProperties( 035 final Properties properties, 036 FacetHolder holder) { 037 super(asColumnSpans(properties), 038 asListWithDefaultGroup(asGroupList(properties, "left")), 039 asList(asGroupList(properties, "middle")), 040 asList(asGroupList(properties, "right")), 041 holder); 042 } 043 044 static ColumnSpans asColumnSpans(Properties properties) { 045 String columnSpansStr = properties.getProperty("columnSpans"); 046 047 if(columnSpansStr == null) { 048 return null; 049 } 050 try { 051 return ColumnSpans.valueOf(columnSpansStr.trim()); 052 } catch(IllegalArgumentException ex) { 053 return null; 054 } 055 } 056 057 static String[] asGroupList(Properties properties, final String key) { 058 final String property = properties.getProperty(key); 059 if(property == null) { 060 return new String[0]; 061 } 062 final Iterable<String> split = Splitter.on(',').split(property); 063 return Iterables.toArray( 064 Iterables.filter( 065 Iterables.transform(split,StringFunctions.TRIM), 066 StringPredicates.NOT_EMPTY), 067 String.class); 068 } 069}