001/* 002 * (C) Copyright 2010 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Anahide Tchertchian 018 */ 019package org.nuxeo.ecm.platform.contentview.jsf; 020 021import java.io.Serializable; 022 023/** 024 * Holds needed information about a content view to select it from UI, or to selected one of its result layouts from UI 025 * 026 * @author Anahide Tchertchian 027 * @since 5.4 028 */ 029public class ContentViewHeader implements Serializable, Comparable<ContentViewHeader> { 030 031 private static final long serialVersionUID = 1L; 032 033 protected String name; 034 035 protected String title; 036 037 protected boolean translateTitle; 038 039 protected String iconPath; 040 041 public ContentViewHeader(String name, String title, boolean translateTitle, String iconPath) { 042 this.name = name; 043 this.title = title; 044 this.translateTitle = translateTitle; 045 this.iconPath = iconPath; 046 } 047 048 public String getName() { 049 return name; 050 } 051 052 /** 053 * Returns the title or the name if title is empty. 054 */ 055 public String getTitle() { 056 if (title == null || title.trim().isEmpty()) { 057 return name; 058 } 059 return title; 060 } 061 062 public boolean isTranslateTitle() { 063 return translateTitle; 064 } 065 066 public String getIconPath() { 067 return iconPath; 068 } 069 070 @Override 071 public boolean equals(Object other) { 072 if (other == this) { 073 return true; 074 } 075 if (other == null) { 076 return false; 077 } 078 if (!(other instanceof ContentViewHeader)) { 079 return false; 080 } 081 082 ContentViewHeader otherContentViewHeader = (ContentViewHeader) other; 083 return name == null ? otherContentViewHeader.name == null : name.equals(otherContentViewHeader.name); 084 } 085 086 @Override 087 public int hashCode() { 088 return name.hashCode(); 089 } 090 091 @Override 092 public int compareTo(ContentViewHeader o) { 093 if (o == null) { 094 return 1; 095 } 096 String name1 = name; 097 String name2 = o.name; 098 if (name1 == null && name2 == null) { 099 return 0; 100 } 101 if (name1 == null) { 102 return -1; 103 } 104 if (name2 == null) { 105 return 1; 106 } 107 return name1.compareTo(name2); 108 } 109 110 @Override 111 public String toString() { 112 final StringBuilder buf = new StringBuilder(); 113 buf.append("ContentViewHeader") 114 .append(" {") 115 .append(" name=") 116 .append(name) 117 .append(", title=") 118 .append(title) 119 .append(", translateTitle=") 120 .append(translateTitle) 121 .append(", iconPath=") 122 .append(iconPath) 123 .append('}'); 124 return buf.toString(); 125 } 126 127}