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.simple; 029 030import org.opencms.ade.sitemap.client.alias.A_CmsAliasTableColumn; 031import org.opencms.ade.sitemap.client.alias.CmsAliasMessages; 032import org.opencms.gwt.client.ui.css.I_CmsCellTableResources; 033import org.opencms.gwt.shared.alias.CmsAliasTableRow; 034 035import java.util.Comparator; 036 037import com.google.gwt.cell.client.EditTextCell; 038import com.google.gwt.cell.client.FieldUpdater; 039import com.google.gwt.dom.client.Style.Unit; 040import com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler; 041 042/** 043 * The table column for editing/displaying the alias path.<p> 044 */ 045public class CmsAliasPathColumn extends A_CmsAliasTableColumn<CmsAliasTableRow, String, CmsAliasCellTable> { 046 047 /** The cell in which this column is used. */ 048 CmsAliasCellTable m_table; 049 050 /** 051 * Creates a new column instance.<p> 052 * 053 * @param table the table in which this column is used 054 */ 055 public CmsAliasPathColumn(CmsAliasCellTable table) { 056 057 super(new EditTextCell()); 058 m_table = table; 059 FieldUpdater<CmsAliasTableRow, String> updater = new FieldUpdater<CmsAliasTableRow, String>() { 060 061 public void update(int index, CmsAliasTableRow object, String value) { 062 063 m_table.getController().editAliasPath(object, value); 064 } 065 }; 066 setFieldUpdater(updater); 067 setSortable(true); 068 } 069 070 /** 071 * Gets the comparator used for this column.<p> 072 * 073 * @return the comparator to use for this row 074 */ 075 public static Comparator<CmsAliasTableRow> getComparator() { 076 077 return new Comparator<CmsAliasTableRow>() { 078 079 public int compare(CmsAliasTableRow o1, CmsAliasTableRow o2) { 080 081 return o1.getAliasPath().toString().compareTo(o2.getAliasPath().toString()); 082 } 083 }; 084 } 085 086 /** 087 * @see org.opencms.ade.sitemap.client.alias.A_CmsAliasTableColumn#addToTable(com.google.gwt.user.cellview.client.CellTable) 088 */ 089 @Override 090 public void addToTable(CmsAliasCellTable table) { 091 092 table.addColumn(this, CmsAliasMessages.messageColumnAlias()); 093 table.setColumnWidth(this, 300, Unit.PX); 094 } 095 096 /** 097 * @see com.google.gwt.user.cellview.client.Column#getCellStyleNames(com.google.gwt.cell.client.Cell.Context, java.lang.Object) 098 */ 099 @Override 100 public String getCellStyleNames(com.google.gwt.cell.client.Cell.Context context, CmsAliasTableRow object) { 101 102 if (object.getAliasError() != null) { 103 return super.getCellStyleNames(context, object) 104 + " " 105 + I_CmsCellTableResources.INSTANCE.cellTableStyle().cmsCellError(); 106 } else { 107 return super.getCellStyleNames(context, object); 108 } 109 } 110 111 /** 112 * @see com.google.gwt.user.cellview.client.Column#getValue(java.lang.Object) 113 */ 114 @Override 115 public String getValue(CmsAliasTableRow row) { 116 117 return row.getAliasPath(); 118 } 119 120 /** 121 * @see org.opencms.ade.sitemap.client.alias.A_CmsAliasTableColumn#initSortHandler(com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler) 122 */ 123 @Override 124 public void initSortHandler(ListHandler<CmsAliasTableRow> sortHandler) { 125 126 sortHandler.setComparator(this, getComparator()); 127 } 128}