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 new rewrite alias replacement string.<p> 044 */ 045public class CmsRewriteAliasReplacementColumn 046extends A_CmsAliasTableColumn<CmsRewriteAliasTableRow, String, CmsRewriteAliasTable> 047implements FieldUpdater<CmsRewriteAliasTableRow, String> { 048 049 /** Comparator used 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.getReplacementString(); 056 } 057 }); 058 059 /** The table which this column belongs to. */ 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 to 066 */ 067 public CmsRewriteAliasReplacementColumn(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.messageColumnReplacement()); 083 table.setColumnWidth(this, "300px"); 084 } 085 086 /** 087 * @see com.google.gwt.user.cellview.client.Column#getValue(java.lang.Object) 088 */ 089 @Override 090 public String getValue(CmsRewriteAliasTableRow row) { 091 092 return row.getReplacementString(); 093 } 094 095 /** 096 * @see org.opencms.ade.sitemap.client.alias.A_CmsAliasTableColumn#initSortHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) 097 */ 098 @Override 099 public void initSortHandler(ListHandler<CmsRewriteAliasTableRow> sortHandler) { 100 101 sortHandler.setComparator(this, comparator); 102 } 103 104 /** 105 * @see com.google.gwt.cell.client.FieldUpdater#update(int, java.lang.Object, java.lang.Object) 106 */ 107 public void update(int index, CmsRewriteAliasTableRow object, String value) { 108 109 object.setReplacementString(value); 110 m_table.getController().editRewriteAlias(object); 111 } 112 113}