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.gwt.shared.alias.CmsRewriteAliasTableRow;
033
034import java.util.Comparator;
035
036import com.google.common.base.Function;
037import com.google.common.collect.Ordering;
038import com.google.gwt.cell.client.EditTextCell;
039import com.google.gwt.cell.client.FieldUpdater;
040import com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler;
041
042/**
043 * Column class for entering a rewrite alias pattern.<p>
044 */
045public class CmsRewriteAliasPatternColumn
046extends A_CmsAliasTableColumn<CmsRewriteAliasTableRow, String, CmsRewriteAliasTable>
047implements FieldUpdater<CmsRewriteAliasTableRow, String> {
048
049    /** Comparator for sorting this column. */
050    private static Comparator<CmsRewriteAliasTableRow> comparator = Ordering.natural().onResultOf(
051        new Function<CmsRewriteAliasTableRow, String>() {
052
053            public String apply(CmsRewriteAliasTableRow row) {
054
055                return row.getPatternString();
056            }
057        });
058
059    /** The cell table to which this column belongs. */
060    private CmsRewriteAliasTable m_table;
061
062    /**
063     * Creates a new column instance.<p>
064     *
065     * @param table the table to which this column belongs
066     */
067    public CmsRewriteAliasPatternColumn(CmsRewriteAliasTable table) {
068
069        super(new EditTextCell());
070        m_table = table;
071        setFieldUpdater(this);
072        setSortable(true);
073
074    }
075
076    /**
077     * @see org.opencms.ade.sitemap.client.alias.A_CmsAliasTableColumn#addToTable(com.google.gwt.user.cellview.client.CellTable)
078     */
079    @Override
080    public void addToTable(CmsRewriteAliasTable table) {
081
082        table.addColumn(this, CmsAliasMessages.messageColumnPattern());
083        table.setColumnWidth(this, "300px");
084
085    }
086
087    /**
088     * @see com.google.gwt.user.cellview.client.Column#getValue(java.lang.Object)
089     */
090    @Override
091    public String getValue(CmsRewriteAliasTableRow row) {
092
093        return row.getPatternString();
094    }
095
096    /**
097     * @see org.opencms.ade.sitemap.client.alias.A_CmsAliasTableColumn#initSortHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler)
098     */
099    @Override
100    public void initSortHandler(ListHandler<CmsRewriteAliasTableRow> sortHandler) {
101
102        sortHandler.setComparator(this, comparator);
103    }
104
105    /**
106     * @see com.google.gwt.cell.client.FieldUpdater#update(int, java.lang.Object, java.lang.Object)
107     */
108    public void update(int index, CmsRewriteAliasTableRow object, String value) {
109
110        object.setPatternString(value);
111        m_table.getController().editRewriteAlias(object);
112    }
113
114}