001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (C) Alkacon Software (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.ade.sitemap.client.alias.rewrite;
029
030import org.opencms.ade.sitemap.client.alias.A_CmsAliasTableColumn;
031import org.opencms.ade.sitemap.client.alias.CmsAliasMessages;
032import org.opencms.ade.sitemap.client.alias.CmsCellTableUtil;
033import org.opencms.gwt.client.ui.css.I_CmsCellTableResources;
034import org.opencms.gwt.shared.alias.CmsRewriteAliasTableRow;
035
036import java.util.Comparator;
037
038import com.google.common.base.Function;
039import com.google.common.collect.Ordering;
040import com.google.gwt.cell.client.SafeHtmlCell;
041import com.google.gwt.safehtml.shared.SafeHtml;
042import com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler;
043
044/**
045 * Column for displaying errors in the rewrite table.<p>
046 */
047public class CmsRewriteAliasErrorColumn
048extends A_CmsAliasTableColumn<CmsRewriteAliasTableRow, SafeHtml, CmsRewriteAliasTable> {
049
050    /** Comparator used for sorting this column. */
051    private static Comparator<CmsRewriteAliasTableRow> comparator = Ordering.natural().onResultOf(
052        new Function<CmsRewriteAliasTableRow, String>() {
053
054            public String apply(CmsRewriteAliasTableRow row) {
055
056                return row.getError() == null ? "" : row.getError();
057            }
058        });
059
060    /**
061     * Creates a new column instance.<p>
062     */
063    public CmsRewriteAliasErrorColumn() {
064
065        super(new SafeHtmlCell());
066        setSortable(true);
067    }
068
069    /**
070     * @see org.opencms.ade.sitemap.client.alias.A_CmsAliasTableColumn#addToTable(com.google.gwt.user.cellview.client.CellTable)
071     */
072    @Override
073    public void addToTable(CmsRewriteAliasTable table) {
074
075        table.addColumn(this, CmsAliasMessages.messageColumnError());
076    }
077
078    /**
079     * @see com.google.gwt.user.cellview.client.Column#getCellStyleNames(com.google.gwt.cell.client.Cell.Context, java.lang.Object)
080     */
081    @Override
082    public String getCellStyleNames(com.google.gwt.cell.client.Cell.Context context, CmsRewriteAliasTableRow object) {
083
084        String result = super.getCellStyleNames(context, object);
085        if (object.getError() != null) {
086            result += " " + I_CmsCellTableResources.INSTANCE.cellTableStyle().cmsCellError();
087        }
088        return result;
089    }
090
091    /**
092     * @see com.google.gwt.user.cellview.client.Column#getValue(java.lang.Object)
093     */
094    @Override
095    public SafeHtml getValue(CmsRewriteAliasTableRow object) {
096
097        return CmsCellTableUtil.formatErrorHtml(object.getError());
098    }
099
100    /**
101     * @see org.opencms.ade.sitemap.client.alias.A_CmsAliasTableColumn#initSortHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)
102     */
103    @Override
104    public void initSortHandler(ListHandler<CmsRewriteAliasTableRow> sortHandler) {
105
106        sortHandler.setComparator(this, comparator);
107    }
108
109}