X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Furls%2FUrlLinkDisplay.java;h=0eabff7292076a4f45a6c50e51c909837d6c1942;hb=ff8c06845590fd9fd423aa59809dcce9610ab295;hp=9afe6d34b665d1c061af49656e8d2e971fff2bb8;hpb=c25a5c7301fa43bec8da032f93898d6133391f8a;p=jalview.git diff --git a/src/jalview/urls/UrlLinkDisplay.java b/src/jalview/urls/UrlLinkDisplay.java index 9afe6d3..0eabff7 100644 --- a/src/jalview/urls/UrlLinkDisplay.java +++ b/src/jalview/urls/UrlLinkDisplay.java @@ -21,6 +21,11 @@ package jalview.urls; +import jalview.util.MessageManager; +import jalview.util.UrlLink; + +import java.util.ArrayList; +import java.util.List; /** * UrlLink table row definition @@ -34,52 +39,72 @@ public class UrlLinkDisplay private String id; // id is not supplied to display, but used to identify // entries when saved - private String name; + private boolean isPrimary; - private String url; + private boolean isSelected; - private boolean isDefault; + private UrlLink link; - private boolean isSelected; + // Headers for columns in table + private final static List colNames = new ArrayList() + { + { + 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")); + } + }; + + // column positions + public final static int DATABASE = 0; - public final static int ID = 4; + public final static int NAME = 1; - public final static int URL = 1; + public final static int URL = 2; - public final static int SELECTED = 2; + public final static int SELECTED = 3; - public final static int DEFAULT = 3; + public final static int PRIMARY = 4; - public final static int NAME = 0; + public final static int ID = 5; - public UrlLinkDisplay(String rowId, String rowName, String rowUrl, + 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() @@ -87,14 +112,24 @@ public class UrlLinkDisplay 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) @@ -109,15 +144,17 @@ public class UrlLinkDisplay 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; } } @@ -129,24 +166,57 @@ public class UrlLinkDisplay 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); + 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 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 DESCRIPTION and ID (excludes ID) + return colNames.subList(DATABASE, ID); } }