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.runtime.userprofile; 021 022import java.util.List; 023 024import com.google.common.collect.Lists; 025 026import org.apache.isis.core.metamodel.adapter.ObjectAdapter; 027 028public class PerspectiveEntry { 029 030 public PerspectiveEntry() { 031 } 032 033 // /////////////////////////////////////////////////////// 034 // Name & Title 035 // /////////////////////////////////////////////////////// 036 037 private String name; 038 039 public String getName() { 040 return name; 041 } 042 043 public void setName(final String name) { 044 this.name = name; 045 } 046 047 public String getTitle() { 048 return name + " (" + services.size() + " classes)"; 049 } 050 051 // /////////////////////////////////////////////////////// 052 // Objects, save 053 // /////////////////////////////////////////////////////// 054 055 private final List<Object> objects = Lists.newArrayList(); 056 057 // REVIEW should this deal with Isis, and the services with IDs (or Isis) 058 public List<Object> getObjects() { 059 return objects; 060 } 061 062 public void addToObjects(final Object obj) { 063 if (!objects.contains(obj)) { 064 objects.add(obj); 065 } 066 } 067 068 public void removeFromObjects(final Object obj) { 069 objects.remove(obj); 070 } 071 072 public void save(final List<ObjectAdapter> adapters) { 073 this.objects.clear(); 074 for (final ObjectAdapter adapter : adapters) { 075 addToObjects(adapter.getObject()); 076 } 077 } 078 079 // /////////////////////////////////////////////////////// 080 // Services 081 // /////////////////////////////////////////////////////// 082 083 private final List<Object> services = Lists.newArrayList(); 084 085 public List<Object> getServices() { 086 return services; 087 } 088 089 public void addToServices(final Object service) { 090 if (service != null && !services.contains(service)) { 091 services.add(service); 092 } 093 } 094 095 public void removeFromServices(final Object service) { 096 if (service != null && services.contains(service)) { 097 services.remove(service); 098 } 099 } 100 101 // /////////////////////////////////////////////////////// 102 // copy 103 // /////////////////////////////////////////////////////// 104 105 public void copy(final PerspectiveEntry template) { 106 name = template.getName(); 107 for (final Object service : template.getServices()) { 108 addToServices(service); 109 } 110 for (final Object obj : template.getObjects()) { 111 addToObjects(obj); 112 } 113 } 114 115}