001/*
002 * (C) Copyright 2010 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Anahide Tchertchian
016 */
017package org.nuxeo.ecm.platform.contentview.jsf;
018
019import java.io.Serializable;
020
021/**
022 * Holds needed information about a content view to select it from UI, or to selected one of its result layouts from UI
023 *
024 * @author Anahide Tchertchian
025 * @since 5.4
026 */
027public class ContentViewHeader implements Serializable, Comparable<ContentViewHeader> {
028
029    private static final long serialVersionUID = 1L;
030
031    protected String name;
032
033    protected String title;
034
035    protected boolean translateTitle;
036
037    protected String iconPath;
038
039    public ContentViewHeader(String name, String title, boolean translateTitle, String iconPath) {
040        this.name = name;
041        this.title = title;
042        this.translateTitle = translateTitle;
043        this.iconPath = iconPath;
044    }
045
046    public String getName() {
047        return name;
048    }
049
050    /**
051     * Returns the title or the name if title is empty.
052     */
053    public String getTitle() {
054        if (title == null || title.trim().isEmpty()) {
055            return name;
056        }
057        return title;
058    }
059
060    public boolean isTranslateTitle() {
061        return translateTitle;
062    }
063
064    public String getIconPath() {
065        return iconPath;
066    }
067
068    @Override
069    public boolean equals(Object other) {
070        if (other == this) {
071            return true;
072        }
073        if (other == null) {
074            return false;
075        }
076        if (!(other instanceof ContentViewHeader)) {
077            return false;
078        }
079
080        ContentViewHeader otherContentViewHeader = (ContentViewHeader) other;
081        return name == null ? otherContentViewHeader.name == null : name.equals(otherContentViewHeader.name);
082    }
083
084    @Override
085    public int hashCode() {
086        return name.hashCode();
087    }
088
089    @Override
090    public int compareTo(ContentViewHeader o) {
091        if (o == null) {
092            return 1;
093        }
094        String name1 = name;
095        String name2 = o.name;
096        if (name1 == null && name2 == null) {
097            return 0;
098        }
099        if (name1 == null) {
100            return -1;
101        }
102        if (name2 == null) {
103            return 1;
104        }
105        return name1.compareTo(name2);
106    }
107
108    @Override
109    public String toString() {
110        return String.format("ContentViewHeader [name=%s, title=%s, " + "translateTitle=%s, iconPath=%s]", name, title,
111                Boolean.valueOf(translateTitle), iconPath);
112    }
113
114}