package jalview.urls;
+import jalview.util.MessageManager;
+import jalview.util.UrlLink;
+
+import java.util.ArrayList;
+import java.util.List;
/**
* UrlLink table row definition
public class UrlLinkDisplay
{
- private String id; // id is not supplied to display, but used to identify
- // entries when saved
+ // column positions
+ public static final int DATABASE = 0;
- private String name;
+ public static final int NAME = 1;
- private String url;
+ public static final int URL = 2;
- private boolean isDefault;
+ public static final int SELECTED = 3;
- private boolean isSelected;
+ public static final int PRIMARY = 4;
- public final static int ID = 4;
+ public static final int ID = 5;
- public final static int URL = 1;
+ // Headers for columns in table
+ @SuppressWarnings("serial")
+ private static final List<String> COLNAMES = new ArrayList<String>()
+ {
+ {
+ add(MessageManager.formatMessage("label.database"));
+ add(MessageManager.formatMessage("label.name"));
+ add(MessageManager.formatMessage("label.url"));
+ add(MessageManager.formatMessage("label.inmenu"));
+ add(MessageManager.formatMessage("label.primary"));
+ add(MessageManager.formatMessage("label.id"));
+ }
+ };
- public final static int SELECTED = 2;
+ private String id; // id is not supplied to display, but used to identify
+ // entries when saved
- public final static int DEFAULT = 3;
+ private boolean isPrimary;
- public final static int NAME = 0;
+ private boolean isSelected;
+
+ private UrlLink link;
- public UrlLinkDisplay(String rowId, String rowName, String rowUrl,
- boolean rowSelected, boolean rowDefault)
+ public UrlLinkDisplay(String rowId, UrlLink rowLink, boolean rowSelected,
+ boolean rowDefault)
{
id = rowId;
- name = rowName;
- url = rowUrl;
- isDefault = rowDefault;
+ isPrimary = rowDefault;
isSelected = rowSelected;
+
+ link = rowLink;
}
+ // getters/setters
public String getId()
{
return id;
}
- public String getName()
+ public String getDescription()
+ {
+ return link.getLabel();
+ }
+
+ public String getDBName()
{
- return name;
+ return link.getTarget();
}
public String getUrl()
{
- return url;
+ return link.getUrlWithToken();
}
- public boolean getIsDefault()
+ public boolean getIsPrimary()
{
- return isDefault;
+ return isPrimary;
}
public boolean getIsSelected()
return isSelected;
}
+ public void setDBName(String name)
+ {
+ link.setTarget(name);
+ }
+
public void setUrl(String rowUrl)
{
- url = rowUrl;
+ link = new UrlLink(getDescription(), rowUrl, getDBName());
+ }
+
+ public void setDescription(String desc)
+ {
+ link.setLabel(desc);
}
public void setIsDefault(boolean rowDefault)
{
- isDefault = rowDefault;
+ isPrimary = rowDefault;
}
public void setIsSelected(boolean rowSelected)
case ID:
return id;
case URL:
- return url;
- case DEFAULT:
- return isDefault;
+ return getUrl();
+ case PRIMARY:
+ return isPrimary;
case SELECTED:
return isSelected;
case NAME:
- return name;
+ return getDescription();
+ case DATABASE:
+ return getDBName();
default:
- return null; // TODO
+ return null;
}
}
id = (String) value;
break;
case URL:
- url = (String) value;
+ setUrl((String) value);
break;
- case DEFAULT:
- isDefault = (boolean) value;
+ case PRIMARY:
+ isPrimary = (boolean) value;
break;
case SELECTED:
isSelected = (boolean) value;
break;
case NAME:
- name = (String) value;
+ setDescription((String) value);
+ // deliberate fall through
+ case DATABASE:
+ setDBName((String) value);
break;
default:
- // TODO
+ // do nothing
}
}
+ /**
+ * Identify editable columns
+ *
+ * @param index
+ * index of column
+ * @return whether column can be edited in table
+ */
public boolean isEditable(int index)
{
- return ((index == DEFAULT) || (index == SELECTED));
+ if (index == PRIMARY)
+ {
+ // primary link must not be a $DB_ACCESSION$ link
+ // so only allow editing if it is not
+ return (!link.usesDBAccession());
+ }
+ else
+ {
+ return index == SELECTED;
+ }
+ }
+
+ /**
+ * Get list of column names to display in UI
+ *
+ * @return column names
+ */
+ public static List<String> getDisplayColumnNames()
+ {
+ // Display names between DESCRIPTION and ID (excludes ID)
+ return COLNAMES.subList(DATABASE, ID);
}
}