001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2008-2010 Sun Microsystems, Inc. 015 * Portions Copyright 2014 ForgeRock AS. 016 */ 017 018package org.opends.guitools.controlpanel.datamodel; 019 020 021import static com.forgerock.opendj.cli.Utils.wrapText; 022 023import javax.swing.table.AbstractTableModel; 024 025import org.opends.guitools.controlpanel.ui.ColorAndFontConstants; 026import org.opends.guitools.controlpanel.util.Utilities; 027import org.forgerock.i18n.LocalizableMessage; 028import org.opends.server.util.ServerConstants; 029 030/** 031 * A generic interface that must implement table models that are sortable. 032 */ 033public abstract class SortableTableModel extends AbstractTableModel 034{ 035 private static final long serialVersionUID = 123129879083L; 036 037 /** 038 * Returns whether the sort is ascending or descending. 039 * @return <CODE>true</CODE> if the sort is ascending and <CODE>false</CODE> 040 * otherwise. 041 */ 042 public abstract boolean isSortAscending(); 043 044 /** 045 * Sets whether to sort ascending of descending. 046 * @param sortAscending whether to sort ascending or descending. 047 */ 048 public abstract void setSortAscending(boolean sortAscending); 049 050 /** 051 * Returns the column index used to sort. 052 * @return the column index used to sort. 053 */ 054 public abstract int getSortColumn(); 055 056 /** 057 * Sets the column index used to sort. 058 * @param sortColumn column index used to sort.. 059 */ 060 public abstract void setSortColumn(int sortColumn); 061 062 /** 063 * Updates the table model contents and sorts its contents depending on the 064 * sort options set by the user. 065 */ 066 public abstract void forceResort(); 067 068 069 /** 070 * Returns the header wrapped with the default line width. 071 * @param msg the header message value (with no HTML formatting). 072 * @return the header wrapped with the default line width. 073 */ 074 protected String getHeader(LocalizableMessage msg) 075 { 076 return getHeader(msg, 15); 077 } 078 079 /** 080 * Returns the header wrapped with a certain line width. 081 * @param msg the header message value (with no HTML formatting). 082 * @param wrap the maximum line width before wrapping. 083 * @return the header wrapped with the specified line width. 084 */ 085 protected String getHeader(LocalizableMessage msg, int wrap) 086 { 087 String text = msg.toString(); 088 String wrappedText = wrapText(text, wrap); 089 wrappedText = wrappedText.replaceAll(ServerConstants.EOL, "<br>"); 090 return "<html>"+Utilities.applyFont(wrappedText, 091 ColorAndFontConstants.headerFont); 092 } 093}