/*
* Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
* Copyright (C) $$Year-Rel$$ The Jalview Authors
*
* This file is part of Jalview.
*
* Jalview is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* Jalview is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Jalview. If not, see .
* The Jalview Authors are detailed in the 'AUTHORS' file.
*/
package jalview.urls;
import jalview.util.MessageManager;
import jalview.util.UrlLink;
import java.util.ArrayList;
import java.util.List;
/**
* UrlLink table row definition
*
* @author $author$
* @version $Revision$
*/
public class UrlLinkDisplay
{
private String id; // id is not supplied to display, but used to identify
// entries when saved
private boolean isDefault;
private boolean isSelected;
private UrlLink link;
// Headers for columns in table
private final static List colNames = new ArrayList()
{
{
add(MessageManager.formatMessage("label.name"));
add(MessageManager.formatMessage("label.url"));
add(MessageManager.formatMessage("label.inmenu"));
add(MessageManager.formatMessage("label.default"));
add(MessageManager.formatMessage("label.id"));
}
};
// column positions
public final static int NAME = 0;
public final static int URL = 1;
public final static int SELECTED = 2;
public final static int DEFAULT = 3;
public final static int ID = 4;
public UrlLinkDisplay(String rowId, UrlLink rowLink,
boolean rowSelected, boolean rowDefault)
{
id = rowId;
isDefault = rowDefault;
isSelected = rowSelected;
link = rowLink;
}
// getters/setters
public String getId()
{
return id;
}
public String getName()
{
return link.getLabel();
}
public String getUrl()
{
return link.getUrlWithToken();
}
public boolean getIsDefault()
{
return isDefault;
}
public boolean getIsSelected()
{
return isSelected;
}
public void setName(String name)
{
link.setLabel(name);
}
public void setUrl(String rowUrl)
{
link = new UrlLink(getName(), rowUrl);
}
public void setIsDefault(boolean rowDefault)
{
isDefault = rowDefault;
}
public void setIsSelected(boolean rowSelected)
{
isSelected = rowSelected;
}
public Object getValue(int index)
{
switch (index)
{
case ID:
return id;
case URL:
return getUrl();
case DEFAULT:
return isDefault;
case SELECTED:
return isSelected;
case NAME:
return getName();
default:
return null;
}
}
public void setValue(int index, Object value)
{
switch (index)
{
case ID:
id = (String) value;
break;
case URL:
setUrl((String) value);
break;
case DEFAULT:
isDefault = (boolean) value;
break;
case SELECTED:
isSelected = (boolean) value;
break;
case NAME:
setName((String) value);
break;
default:
// do nothing
}
}
/**
* Identify editable columns
*
* @param index
* index of column
* @return whether column can be edited in table
*/
public boolean isEditable(int index)
{
if (index == DEFAULT)
{
// default link must not be a $DB_ACCESSION$ link
// so only allow editing if it is not
return (!link.usesDBAccession());
}
else if (index == SELECTED)
{
return true;
}
else
{
return false;
}
}
/**
* Get list of column names to display in UI
*
* @return column names
*/
public static List getDisplayColumnNames()
{
// Display names between NAME and ID (excludes ID)
return colNames.subList(NAME, ID);
}
}