Changeset 5687
- Timestamp:
- Aug 9, 2011, 1:39:40 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/clients/web/net/sf/basedb/clients/web/taglib/Select.java
r5663 r5687 22 22 package net.sf.basedb.clients.web.taglib; 23 23 24 import java.util.Collections; 24 25 import java.util.List; 25 26 … … 315 316 316 317 /** 317 The project default value 318 */ 319 private transient BasicItem defaultitem;318 The project default values. 319 */ 320 private transient List<? extends BasicItem> defaultItems; 320 321 321 322 /** … … 481 482 public void setDefaultitem(BasicItem defaultitem) 482 483 { 483 this.defaultitem = defaultitem; 484 } 485 public BasicItem getDefaultitem() 486 { 487 return defaultitem; 484 this.defaultItems = defaultitem == null ? null : Collections.singletonList(defaultitem); 485 } 486 487 public void setDefaultitems(List<? extends BasicItem> defaultItems) 488 { 489 this.defaultItems = defaultItems; 488 490 } 489 491 … … 584 586 sb.append("<option value=\"0\">").append(getUnselectedtext()).append("\n"); 585 587 } 588 boolean hasSelected = false; 586 589 if (current != null) 587 590 { … … 589 592 sb.append(current.getId() * (isNewitem() ? 1 : -1)); 590 593 sb.append("\" selected>"); 594 hasSelected = true; 591 595 String name = getName(current); 592 596 sb.append(HTML.encodeTags(name)).append("\n"); … … 607 611 sb.append("<option value=\"").append(item.getId()).append("\""); 608 612 sb.append(" class=\"").append(clazz).append("\""); 609 if ( i == 1 && current == null&& isNewitem() && getSelectrecent())613 if (!hasSelected && isNewitem() && getSelectrecent()) 610 614 { 611 615 sb.append(" selected"); 616 hasSelected = true; 612 617 } 613 618 sb.append(">").append(i).append(". ").append(name).append("\n"); … … 615 620 } 616 621 } 617 if (defaultitem != null) 618 { 619 sb.append("<option value=\"0\" disabled=\"true\" class=\"defaultheader\">- default -\n"); 620 String name = getName(defaultitem); 621 String clazz = "default"; 622 623 sb.append("<option value=\"").append(defaultitem.getId()).append("\""); 624 sb.append(" class=\"").append(clazz).append("\""); 625 if ( current == null && 626 (recent != null && recent.isEmpty()) && 627 isNewitem() && 628 getSelectdefault() ) 629 { 630 sb.append(" selected"); 622 if (defaultItems != null && defaultItems.size() > 0) 623 { 624 sb.append("<option value=\"0\" disabled=\"true\" class=\"defaultheader\">- project default -\n"); 625 for (BasicItem defaultitem : defaultItems) 626 { 627 String name = getName(defaultitem); 628 629 sb.append("<option value=\"").append(defaultitem.getId()).append("\""); 630 sb.append(" class=\"default\""); 631 if (!hasSelected && isNewitem() && getSelectdefault()) 632 { 633 sb.append(" selected"); 634 hasSelected = true; 635 } 636 sb.append(">").append(name).append("\n"); 631 637 } 632 sb.append(">").append(name).append("\n");633 638 } 634 639 } -
trunk/src/core/net/sf/basedb/core/Project.java
r5652 r5687 39 39 import net.sf.basedb.info.ProjectInfo; 40 40 import net.sf.basedb.info.ToTransferable; 41 import net.sf.basedb.util.EqualsHelper; 41 42 42 43 import java.util.ArrayList; … … 674 675 675 676 /** 676 Find a default item of the given item type. If the project contains 677 more than one default item, the first one found is selected. 677 Find the default items of the given item type. If the strict parameter 678 is true, the search will only match items without a subtype. If strict 679 is false, the search ignore the subtype. 680 678 681 @param dc A DbControl for database access 679 682 @param itemType The type of item to find 680 @return The item that was found, or null683 @return A list with the items that was found (empty if no item was found) 681 684 @since 3.0 682 685 */ 683 public BasicItem findDefaultItem(DbControl dc, Item itemType)686 public List<? extends BasicItem> findDefaultItems(DbControl dc, Item itemType, boolean strict) 684 687 { 685 688 if (itemType == null) throw new InvalidUseOfNullException("itemType"); 686 BasicData defaultData = findDefaultData(itemType, null, false); 687 return dc.getItem(BasicItem.class, defaultData); 688 } 689 690 /** 691 Find a default (subtypable) item that has the given subtype. If the 689 List<BasicData> defaultData = findAllDefaultData(itemType, null, strict); 690 List<BasicItem> defaultItems = new ArrayList<BasicItem>(defaultData.size()); 691 for (BasicData data : defaultData) 692 { 693 defaultItems.add(dc.getItem(BasicItem.class, data)); 694 } 695 return defaultItems; 696 } 697 698 /** 699 Find the default (subtypable) items that has the given subtype. If the 692 700 strict parameter is true, an exact match must be found, otherwise 693 701 the search is repeated to find an item without a subtype. The search … … 698 706 @param strict TRUE to strictly match the subtype, FALSE to also 699 707 search for items without subtype 700 @return The item that was found, or null708 @return A list with the items that was found (empty if no item was found) 701 709 @since 3.0 702 710 */ 703 public BasicItem findDefaultItem(DbControl dc, ItemSubtype subtype, boolean strict)711 public List<? extends BasicItem> findDefaultItems(DbControl dc, ItemSubtype subtype, boolean strict) 704 712 { 705 713 if (subtype == null) throw new InvalidUseOfNullException("subtype"); 706 BasicData defaultData = findDefaultData(subtype.getMainItemType(), subtype.getData(), strict); 707 return dc.getItem(BasicItem.class, defaultData); 714 List<BasicData> defaultData = findAllDefaultData(subtype.getMainItemType(), subtype.getData(), strict); 715 List<BasicItem> defaultItems = new ArrayList<BasicItem>(defaultData.size()); 716 for (BasicData data : defaultData) 717 { 718 defaultItems.add(dc.getItem(BasicItem.class, data)); 719 } 720 return defaultItems; 721 } 722 723 /** 724 Utility method for finding default items of the given relatedType. 725 If a subtype is given this method first try to find the related 726 subtype for the given relatedType. If no subtype is given or if no 727 related subtype is found, this method behaves as if {@link #findDefaultItems(DbControl, Item, boolean)} 728 was called with strict=true (eg. it will only find items that doesn't have a subtype). 729 If a related subtype is found this method behaves as if 730 {@link #findDefaultItems(DbControl, ItemSubtype, boolean)} 731 was called with the related subtype and strict=false. 732 733 @param dc A DbControl for database access 734 @param subtype The main subtype 735 @param relatedType The related item type that we are interested in 736 @return A list with the items that was found (empty if no item was found) 737 @since 3.0 738 */ 739 public List<? extends BasicItem> findDefaultItemsOfRelatedSubtype(DbControl dc, ItemSubtype subtype, Item relatedType) 740 { 741 ItemSubtype related = subtype == null ? null : subtype.getRelatedSubtype(relatedType); 742 if (related == null) 743 { 744 return findDefaultItems(dc, relatedType, true); 745 } 746 else 747 { 748 return findDefaultItems(dc, related, false); 749 } 708 750 } 709 751 … … 788 830 /** 789 831 Find a default item in this project of the given item type (required) 790 and subtype (optional). If a subtype is given, this method first try to 791 match exactly. If no item is found, and strict is false, a second attempt 792 is made to match against items WITHOUT subtype (items with a different 793 subtype are never matched). If more than one item matches the critera, 794 the first one found is returned. 832 and subtype (optional). This method will first try to locate an 833 exact match for the given item type and subtype. If no items are found 834 and strict is false, a second attempt is made to match items as follows: 835 If a subtype is given it will match items WITHOUT a subtype (items with 836 a different subtype are not matched). If no subtype is given, the search 837 ignore the subtype on the other items. 838 839 <p> 840 If more than one item matches the critera, the first one found is returned. 795 841 796 842 @param itemType The main item type of the item we are looking for … … 811 857 if (dataClass.isInstance(data)) 812 858 { 813 // If no subtype is given we have found a match 814 if (subtype == null) 859 // Found an item of the correct item type... get it's subtype 860 ItemSubtypeData otherSubtype = null; 861 if (data instanceof SubtypableData) 862 { 863 otherSubtype = ((SubtypableData)data).getItemSubtype(); 864 } 865 866 // If the subtypes are null or equal we have found a match 867 if (EqualsHelper.equals(subtype, otherSubtype)) 815 868 { 816 869 bestMatch = data; … … 818 871 } 819 872 820 // Check the subtype 821 if (data instanceof SubtypableData) 822 { 823 ItemSubtypeData otherSubtype = ((SubtypableData)data).getItemSubtype(); 824 if (subtype.equals(otherSubtype)) 825 { 826 // Found an exact match 827 bestMatch = data; 828 break; 829 } 830 831 // This is a possible (non-strict) match -- do not update if already set 832 if (!strict && otherSubtype == null && bestMatch == null) 873 if (!strict && bestMatch == null) 874 { 875 // Is this maybe the first non-strict match? 876 if (subtype == null || otherSubtype == null) 833 877 { 834 878 bestMatch = data; 835 879 } 836 880 } 837 838 881 } 839 882 } 840 883 return bestMatch; 884 } 885 886 /** 887 Find all default items in this project of the given item type (required) 888 and subtype (optional). If a subtype is given, this method first try to 889 match exactly. If no item is found, and strict is false, a second attempt 890 is made to match against items WITHOUT subtype (items with a different 891 subtype are never matched). 892 893 @param itemType The main item type of the item we are looking for 894 @param subtype The subtype of the item we are looking for (optional) 895 @param strict TRUE if the subtype must match 896 @since 3.0 897 */ 898 List<BasicData> findAllDefaultData(Item itemType, ItemSubtypeData subtype, boolean strict) 899 { 900 ItemParameterValueData defaultItems = getData().getDefaultItems(); 901 if (defaultItems == null) return null; 902 903 List<BasicData> result = new ArrayList<BasicData>(); 904 List<BasicData> nonStrictMatches = strict ? null : new ArrayList<BasicData>(); 905 906 Class dataClass = itemType.getDataClass(); 907 for (BasicData data : defaultItems.getValues()) 908 { 909 if (dataClass.isInstance(data)) 910 { 911 // Found an item of the correct item type... get it's subtype 912 ItemSubtypeData otherSubtype = null; 913 if (data instanceof SubtypableData) 914 { 915 otherSubtype = ((SubtypableData)data).getItemSubtype(); 916 } 917 918 // If the subtypes are null or equal we have found a match 919 if (EqualsHelper.equals(subtype, otherSubtype)) 920 { 921 result.add(data); 922 } 923 else if (!strict) 924 { 925 // Non-strict matches 926 if (subtype == null || otherSubtype == null) 927 { 928 nonStrictMatches.add(data); 929 } 930 } 931 } 932 } 933 if (result.size() == 0 && !strict) result.addAll(nonStrictMatches); 934 return result; 841 935 } 842 936 -
trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/AbstractItemImporter.java
r5661 r5687 1285 1285 } 1286 1286 /** 1287 Get the default platform of the currently active project. 1287 Get the default platform of the currently active project. If there 1288 is more than one default platform, the first one is selected. 1288 1289 @return The active platform, or null if no project is active or 1289 1290 the project doesn't specify a platform … … 1294 1295 if (sc.getActiveProjectId() == 0) return null; 1295 1296 Project activeProject = Project.getById(dc, sc.getActiveProjectId()); 1296 return (Platform)activeProject.findDefaultItem(dc, Item.PLATFORM); 1297 List<? extends BasicItem> platforms = activeProject.findDefaultItems(dc, Item.PLATFORM, true); 1298 return platforms == null || platforms.size() == 0 ? null : (Platform)platforms.get(0); 1297 1299 } 1298 1300 … … 1307 1309 if (sc.getActiveProjectId() == 0) return null; 1308 1310 Project activeProject = Project.getById(dc, sc.getActiveProjectId()); 1309 return (PlatformVariant)activeProject.findDefaultItem(dc, Item.PLATFORMVARIANT); 1311 List<? extends BasicItem> platforms = activeProject.findDefaultItems(dc, Item.PLATFORMVARIANT, true); 1312 return platforms == null || platforms.size() == 0 ? null : (PlatformVariant)platforms.get(0); 1310 1313 } 1311 1314 -
trunk/src/test/TestProject.java
r5653 r5687 139 139 Project p = Project.getById(dc, project_id); 140 140 141 BasicItemfound = null;141 List<? extends BasicItem> found = null; 142 142 if (subtypeId == 0) 143 143 { 144 found = p.findDefaultItem (dc, defaultType);144 found = p.findDefaultItems(dc, defaultType, true); 145 145 } 146 146 else 147 147 { 148 148 ItemSubtype subtype = ItemSubtype.getById(dc, subtypeId); 149 found = p.findDefaultItem (dc, subtype, true);149 found = p.findDefaultItems(dc, subtype, true); 150 150 } 151 151 152 if (found == null )152 if (found == null || found.size() == 0) 153 153 { 154 154 throw new ItemNotFoundException("Default " + defaultType + " for project: " + p); 155 155 } 156 else if (found.get Id() != expectedId)156 else if (found.get(0).getId() != expectedId) 157 157 { 158 158 throw new RuntimeException("Found " + found); -
trunk/www/WEB-INF/base.tld
r5663 r5687 433 433 </attribute> 434 434 <attribute> 435 <name>defaultitems</name> 436 <required>false</required> 437 <rtexprvalue>true</rtexprvalue> 438 </attribute> 439 <attribute> 435 440 <name>selectdefault</name> 436 441 <required>false</required> -
trunk/www/admin/itemsubtypes/ajax.jsp
r5686 r5687 27 27 import="net.sf.basedb.core.Item" 28 28 import="net.sf.basedb.core.ItemContext" 29 import="net.sf.basedb.core.Project" 29 30 import="net.sf.basedb.core.ItemSubtype" 30 31 import="net.sf.basedb.core.Subtypable" 31 32 import="net.sf.basedb.core.BasicItem" 32 33 import="net.sf.basedb.core.Nameable" 34 import="net.sf.basedb.core.SystemItems" 35 import="net.sf.basedb.core.Protocol" 36 import="net.sf.basedb.core.Hardware" 37 import="net.sf.basedb.core.Software" 33 38 import="net.sf.basedb.core.InvalidDataException" 34 39 import="net.sf.basedb.util.Values" … … 91 96 dc = sc.newDbControl(); 92 97 98 // The main item's subtype 93 99 ItemSubtype subtype = itemId == 0 ? null : ItemSubtype.getById(dc, itemId); 94 Item mainItemType = subtype == null ? Item.valueOf(request.getParameter("itemType")) : subtype.getMainItemType(); 95 ItemContext cc = sc.getCurrentContext(mainItemType); 96 100 Item mainItemType = null; 97 101 if (subtype != null) 98 102 { 103 mainItemType = subtype.getMainItemType(); 99 104 json.put("id", subtype.getId()); 100 105 json.put("name", subtype.getName()); 101 106 } 107 else 108 { 109 mainItemType = Item.valueOf(request.getParameter("itemType")); 110 } 111 112 // Current context for the main item 113 ItemContext cc = sc.getCurrentContext(mainItemType); 114 115 // Active project 116 Project activeProject = sc.getActiveProjectId() > 0 ? Project.getById(dc, sc.getActiveProjectId()) : null; 102 117 118 // Related item types 103 119 for (String relatedType : request.getParameterValues("relatedType")) 104 120 { … … 107 123 108 124 // Load the related subtype 125 ItemSubtype relatedSubtype = null; 109 126 if (subtype != null) 110 127 { 111 ItemSubtyperelatedSubtype = subtype.getRelatedSubtype(relatedItem);128 relatedSubtype = subtype.getRelatedSubtype(relatedItem); 112 129 if (relatedSubtype != null) 113 130 { … … 119 136 } 120 137 138 if (relatedSubtype == null) 139 { 140 // Find a default related subtype 141 String systemId = null; 142 if (relatedItem == Item.PROTOCOL) 143 { 144 systemId = Protocol.getDefaultSystemId(mainItemType); 145 } 146 else if (relatedItem == Item.HARDWARE) 147 { 148 systemId = Hardware.getDefaultSystemId(mainItemType); 149 } 150 else if (relatedItem == Item.SOFTWARE) 151 { 152 systemId = Software.getDefaultSystemId(mainItemType); 153 } 154 if (systemId != null) 155 { 156 relatedSubtype = ItemSubtype.getById(dc, SystemItems.getId(systemId)); 157 } 158 } 159 121 160 // Load the most recently used items 122 161 List<? extends BasicItem> recentItems = cc.getRecent(dc, relatedItem, subtype); … … 133 172 jsonITEM.put("recent", jsonRecent); 134 173 } 174 175 // Load project default items 176 if (activeProject != null) 177 { 178 List<? extends BasicItem> defaultItems = relatedSubtype != null ? 179 activeProject.findDefaultItems(dc, relatedSubtype, false) : activeProject.findDefaultItems(dc, relatedItem, true); 180 181 JSONArray jsonDefault = new JSONArray(); 182 for (BasicItem defaultItem : defaultItems) 183 { 184 JSONObject jsonDefaultItem = new JSONObject(); 185 jsonDefaultItem.put("id", defaultItem.getId()); 186 jsonDefaultItem.put("name", ((Nameable)defaultItem).getName()); 187 jsonDefault.add(jsonDefaultItem); 188 } 189 jsonITEM.put("default", jsonDefault); 190 } 191 135 192 json.put(relatedType, jsonITEM); 136 193 } -
trunk/www/biomaterials/extracts/edit_extract.jsp
r5665 r5687 54 54 import="net.sf.basedb.clients.web.util.HTML" 55 55 import="net.sf.basedb.util.Values" 56 import="net.sf.basedb.util.ListUtil" 56 57 import="net.sf.basedb.util.formatter.Formatter" 57 58 import="net.sf.basedb.util.formatter.WellCoordinateFormatter" … … 67 68 import="java.util.HashSet" 68 69 import="java.util.Date" 70 import="java.util.Collections" 69 71 %> 70 72 <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> … … 91 93 92 94 boolean readCurrentSubtype = true; 93 int currentSubtypeId = 0;95 ItemSubtype currentSubtype = null; 94 96 boolean readCurrentProtocol = true; 95 97 Protocol currentProtocol = null; 96 Protocol defaultProtocol = null;97 98 boolean readCurrentTag = true; 98 99 Tag currentTag = null; … … 108 109 BioPlate currentBioPlate = null; 109 110 110 // Load recently used items111 List<Protocol> recentProtocols = (List<Protocol>)cc.getRecent(dc, Item.PROTOCOL);112 List<Sample> recentSamples = (List<Sample>)cc.getRecent(dc, Item.SAMPLE);113 List<BioPlate> recentBioPlates = (List<BioPlate>)cc.getRecent(dc, Item.BIOPLATE);114 List<Tag> recentTags = (List<Tag>)cc.getRecent(dc, Item.TAG);115 116 int activeProjectId = sc.getActiveProjectId();117 if (activeProjectId > 0)118 {119 Project activeProject = Project.getById(dc, activeProjectId);120 try121 {122 defaultProtocol = (Protocol)activeProject.findDefaultItem(dc,123 ItemSubtype.getById(dc, SystemItems.getId(Protocol.EXTRACTION)), false);124 }125 catch(PermissionDeniedException pdex)126 {127 defaultProtocol = null;128 }129 }130 111 if (itemId == 0) 131 112 { … … 140 121 currentTag = Base.getFirstMatching(dc, Tag.getQuery(), "name", cc.getPropertyFilter("tag.name")); 141 122 } 142 currentSubtypeId = Values.getInt(request.getParameter("subtype_id")); 143 if (currentSubtypeId == 0) 144 { 145 int recentSubtypeId = Values.getInt(cc.getRecent(Item.ITEMSUBTYPE.name(), 0)); 146 currentSubtypeId = Values.getInt(cc.getPropertyValue("itemSubtype"), recentSubtypeId); 147 } 123 int currentSubtypeId = Values.getInt(request.getParameter("subtype_id")); 124 List<ItemSubtype> relatedToParent = Collections.emptyList(); 148 125 int sampleId = Values.getInt(request.getParameter("sample_id")); 149 126 int extractId = Values.getInt(request.getParameter("extract_id")); 127 150 128 if (sampleId != 0) 151 129 { … … 153 131 parentType = Item.SAMPLE; 154 132 name = currentSample.getName() + ".e" + (currentSample.countExtracts() + 1); 133 if (currentSubtypeId == 0) 134 { 135 relatedToParent = ItemSubtype.getParentSubtypes(dc, currentSample, Item.EXTRACT); 136 } 155 137 } 156 138 else if (extractId != 0) … … 161 143 extractsQuery = Extract.getQuery(); 162 144 extractsQuery.restrict(Restrictions.eq(Hql.property("id"), Expressions.integer(extractId))); 145 if (currentSubtypeId == 0) 146 { 147 relatedToParent = ItemSubtype.getParentSubtypes(dc, e, Item.EXTRACT); 148 } 163 149 } 164 150 else if (Values.getBoolean(request.getParameter("pooled"))) … … 173 159 { 174 160 name = Values.getString(cc.getPropertyValue("name"), "New extract"); 161 } 162 if (currentSubtypeId == 0) 163 { 164 if (relatedToParent.size() > 0) 165 { 166 // Find most recently used related subtype 167 List<ItemSubtype> recentSubtypes = (List<ItemSubtype>)cc.getRecent(dc, Item.ITEMSUBTYPE); 168 currentSubtype = ListUtil.findFirstCommon(recentSubtypes, relatedToParent, relatedToParent.get(0)); 169 } 170 else 171 { 172 int recentSubtypeId = Values.getInt(cc.getRecent(Item.ITEMSUBTYPE.name(), 0)); 173 currentSubtypeId = Values.getInt(cc.getPropertyValue("itemSubtype"), recentSubtypeId); 174 if (currentSubtypeId > 0) currentSubtype = ItemSubtype.getById(dc, currentSubtypeId); 175 } 175 176 } 176 177 eventDate = (Date)cc.getPropertyObject("creationEvent.eventDate"); … … 191 192 try 192 193 { 193 ItemSubtype subtype = extract.getItemSubtype(); 194 if (subtype != null) currentSubtypeId = subtype.getId(); 194 currentSubtype = extract.getItemSubtype(); 195 195 } 196 196 catch (PermissionDeniedException ex) … … 253 253 } 254 254 } 255 256 // Default items 257 int activeProjectId = sc.getActiveProjectId(); 258 List<Protocol> defaultProtocols = null; 259 if (activeProjectId > 0) 260 { 261 Project activeProject = Project.getById(dc, activeProjectId); 262 ItemSubtype protocolSubtype = currentSubtype == null ? null : currentSubtype.getRelatedSubtype(Item.PROTOCOL); 263 if (protocolSubtype == null) protocolSubtype = ItemSubtype.getById(dc, SystemItems.getId(Protocol.EXTRACTION)); 264 defaultProtocols = (List<Protocol>)activeProject.findDefaultItems(dc, protocolSubtype, false); 265 } 266 267 // Load recently used items 268 List<Protocol> recentProtocols = (List<Protocol>)cc.getRecent(dc, Item.PROTOCOL, currentSubtype); 269 List<Sample> recentSamples = (List<Sample>)cc.getRecent(dc, Item.SAMPLE); 270 List<BioPlate> recentBioPlates = (List<BioPlate>)cc.getRecent(dc, Item.BIOPLATE, currentSubtype); 271 List<Tag> recentTags = (List<Tag>)cc.getRecent(dc, Item.TAG, currentSubtype); 255 272 256 273 // Query to retrieve item types … … 363 380 } 364 381 return parents; 382 } 383 384 function subtypeOnChange() 385 { 386 var frm = document.forms['extract']; 387 var subtypeId = ItemSubtype.getSubtypeId('extract'); 388 var recentInfo = ItemSubtype.getRecentAndRelatedInfo(subtypeId, 'EXTRACT', ['PROTOCOL', 'BIOPLATE', 'TAG', 'SAMPLE', 'EXTRACT']); 389 protocolChanged = ItemSubtype.updateRecentItemsInList(frm.protocol_id, recentInfo.PROTOCOL['recent']); 390 ItemSubtype.updateDefaultItemsInList(frm.protocol_id, recentInfo.PROTOCOL['default']); 391 ItemSubtype.updateRecentItemsInList(frm.tag_id, recentInfo.TAG['recent']); 392 ItemSubtype.updateRecentItemsInList(frm.bioplate_id, recentInfo.BIOPLATE['recent']); 365 393 } 366 394 … … 688 716 <td colspan="2"> 689 717 <select name="subtype_id" 690 <%=!readCurrentSubtype ? "disabled readonly class=\"disabled selectionlist\"" : "class=\"selectionlist\""%>> 718 <%=!readCurrentSubtype ? "disabled readonly class=\"disabled selectionlist\"" : "class=\"selectionlist\""%> 719 onchange="subtypeOnChange()" 720 > 691 721 <% 692 722 if (!readCurrentSubtype) … … 701 731 <option value="0">-none- 702 732 <% 733 int currentSubtypeId = currentSubtype == null ? 0 : currentSubtype.getId(); 703 734 for (ItemSubtype subtype : subtypesQuery.list(dc)) 704 735 { … … 782 813 denied="<%=!readCurrentProtocol%>" 783 814 recent="<%=recentProtocols%>" 784 defaultitem ="<%=defaultProtocol%>"815 defaultitems="<%=defaultProtocols%>" 785 816 newitem="<%=extract == null%>" 786 817 onselect="selectProtocolOnClick()" -
trunk/www/biomaterials/extracts/index.jsp
r5664 r5687 233 233 extract.setOriginalQuantity(Values.getFloat(request.getParameter("original_quantity"), null)); 234 234 235 int subtypeId = Values.getInt(request.getParameter("subtype_id"), -1); 236 ItemSubtype subtype = null; 237 if (subtypeId >= 0) // < 0 = denied or unchanged 238 { 239 if (subtypeId > 0) subtype = ItemSubtype.getById(dc, subtypeId); 240 extract.setItemSubtype(subtype); 241 if (subtype != null) cc.setRecent(subtype, maxRecent); 242 } 243 235 244 BioMaterialEvent creationEvent = extract.getCreationEvent(); 236 245 if (creationEvent.hasPermission(Permission.WRITE)) … … 243 252 Protocol pt = protocolId == 0 ? null : Protocol.getById(dc, protocolId); 244 253 creationEvent.setProtocol(pt); 245 if (pt != null) cc.setRecent(pt, maxRecent);254 if (pt != null) cc.setRecent(pt, subtype, maxRecent); 246 255 } 247 }248 249 int subtypeId = Values.getInt(request.getParameter("subtype_id"), -1);250 if (subtypeId >= 0) // < 0 = denied or unchanged251 {252 ItemSubtype subtype = subtypeId == 0 ? null : ItemSubtype.getById(dc, subtypeId);253 extract.setItemSubtype(subtype);254 if (subtype != null) cc.setRecent(subtype, maxRecent);255 256 } 256 257 … … 260 261 Tag tag = tagId == 0 ? null : Tag.getById(dc, tagId); 261 262 extract.setTag(tag); 262 if (tag != null) cc.setRecent(tag, maxRecent);263 if (tag != null) cc.setRecent(tag, subtype, maxRecent); 263 264 } 264 265 … … 274 275 } 275 276 extract.setBioWell(bw); 276 if (bw != null) cc.setRecent(bw.getPlate(), maxRecent);277 if (bw != null) cc.setRecent(bw.getPlate(), subtype, maxRecent); 277 278 } 278 279 -
trunk/www/biomaterials/samples/edit_sample.jsp
r5686 r5687 94 94 boolean readCurrentProtocol = true; 95 95 Protocol currentProtocol = null; 96 Protocol defaultProtocol = null;97 96 boolean readCurrentBioSource = true; 98 97 BioSource currentBioSource = null; … … 107 106 WellCoordinateFormatter columnFormatter = new WellCoordinateFormatter(false); 108 107 109 int activeProjectId = sc.getActiveProjectId();110 if (activeProjectId > 0)111 {112 Project activeProject = Project.getById(dc, activeProjectId);113 try114 {115 defaultProtocol = (Protocol)activeProject.findDefaultItem(dc,116 ItemSubtype.getById(dc, SystemItems.getId(Protocol.SAMPLING)), false);117 }118 catch(PermissionDeniedException pdex)119 {120 defaultProtocol = null;121 }122 }123 124 108 if (itemId == 0) 125 109 { … … 250 234 } 251 235 236 // Default items 237 int activeProjectId = sc.getActiveProjectId(); 238 List<Protocol> defaultProtocols = null; 239 if (activeProjectId > 0) 240 { 241 Project activeProject = Project.getById(dc, activeProjectId); 242 ItemSubtype protocolSubtype = currentSubtype == null ? null : currentSubtype.getRelatedSubtype(Item.PROTOCOL); 243 if (protocolSubtype == null) protocolSubtype = ItemSubtype.getById(dc, SystemItems.getId(Protocol.SAMPLING)); 244 defaultProtocols = (List<Protocol>)activeProject.findDefaultItems(dc, protocolSubtype, false); 245 } 246 252 247 // Load recently used items 253 248 List<Protocol> recentProtocols = (List<Protocol>)cc.getRecent(dc, Item.PROTOCOL, currentSubtype); 254 249 List<BioSource> recentBioSources = (List<BioSource>)cc.getRecent(dc, Item.BIOSOURCE); 255 List<BioPlate> recentBioPlates = (List<BioPlate>)cc.getRecent(dc, Item.BIOPLATE );250 List<BioPlate> recentBioPlates = (List<BioPlate>)cc.getRecent(dc, Item.BIOPLATE, currentSubtype); 256 251 257 252 // Query to retrieve item types … … 370 365 var frm = document.forms['sample']; 371 366 var subtypeId = ItemSubtype.getSubtypeId('sample'); 372 var recentInfo = ItemSubtype.getRecentAndRelatedInfo(subtypeId, 'SAMPLE', ['PROTOCOL', 'BIOSOURCE', 'SAMPLE']); 373 protocolChanged = ItemSubtype.updateRecentItemsInList(frm.protocol_id, recentInfo.PROTOCOL.recent); 367 var recentInfo = ItemSubtype.getRecentAndRelatedInfo(subtypeId, 'SAMPLE', ['PROTOCOL', 'BIOPLATE', 'BIOSOURCE', 'SAMPLE']); 368 protocolChanged = ItemSubtype.updateRecentItemsInList(frm.protocol_id, recentInfo.PROTOCOL['recent']); 369 ItemSubtype.updateDefaultItemsInList(frm.protocol_id, recentInfo.PROTOCOL['default']); 370 ItemSubtype.updateRecentItemsInList(frm.bioplate_id, recentInfo.BIOPLATE['recent']); 374 371 } 375 372 … … 742 739 denied="<%=!readCurrentProtocol%>" 743 740 recent="<%=recentProtocols%>" 744 defaultitem ="<%=defaultProtocol%>"741 defaultitems="<%=defaultProtocols%>" 745 742 newitem="<%=sample == null%>" 746 743 onselect="selectProtocolOnClick()" -
trunk/www/biomaterials/samples/index.jsp
r5686 r5687 263 263 } 264 264 sample.setBioWell(bw); 265 if (bw != null) cc.setRecent(bw.getPlate(), maxRecent);265 if (bw != null) cc.setRecent(bw.getPlate(), subtype, maxRecent); 266 266 } 267 267 -
trunk/www/include/scripts/subtypes.js
r5686 r5687 159 159 this.updateRecentItemsInList = function(list, recentItems, noNoneOption) 160 160 { 161 if (!list || !recentItems ) return;161 if (!list || !recentItems || !recentItems.length) return; 162 162 163 163 var oldSelectedValue = list.selectedIndex >= 0 ? list[list.selectedIndex].value : 0; … … 211 211 } 212 212 213 this.updateDefaultItemsInList = function(list, defaultItems, noNoneOption) 214 { 215 if (!list || !defaultItems || !defaultItems.length) return; 216 var defaultHeader = new Option('- project default -', 0); 217 defaultHeader.className = 'defaultheader'; 218 defaultHeader.disabled = true; 219 list[list.length] = defaultHeader; 220 // Add the new items to the end of the list 221 for (var i = 0; i < defaultItems.length; i++) 222 { 223 list[list.length] = new Option(defaultItems[i].name, defaultItems[i].id); 224 } 225 } 213 226 } 214 227 -
trunk/www/lims/arraybatches/edit_batch.jsp
r5650 r5687 74 74 boolean readCurrentArrayDesign = true; 75 75 ArrayDesign currentArrayDesign = null; 76 ArrayDesign defaultArrayDesign= null;76 List<ArrayDesign> defaultArrayDesigns = null; 77 77 boolean readCurrentProtocol = true; 78 78 Protocol currentProtocol = null; 79 Protocol defaultProtocol= null;79 List<Protocol> defaultProtocols = null; 80 80 boolean readCurrentPrintRobot = true; 81 81 Hardware currentPrintRobot = null; 82 Hardware defaultPrintRobot= null;82 List<Hardware> defaultPrintRobots = null; 83 83 84 84 // Load recently used items … … 93 93 try 94 94 { 95 defaultArrayDesign = (ArrayDesign)activeProject.findDefaultItem(dc, Item.ARRAYDESIGN);95 defaultArrayDesigns = (List<ArrayDesign>)activeProject.findDefaultItems(dc, Item.ARRAYDESIGN, true); 96 96 } 97 97 catch (PermissionDeniedException pdex) 98 { 99 defaultArrayDesign = null; 100 } 101 try 102 { 103 defaultProtocol = (Protocol)activeProject.findDefaultItem(dc, 98 {} 99 try 100 { 101 defaultProtocols = (List<Protocol>)activeProject.findDefaultItems(dc, 104 102 ItemSubtype.getById(dc, SystemItems.getId(Protocol.PRINTING)), false); 105 103 } 106 104 catch (PermissionDeniedException pdex) 107 { 108 defaultProtocol = null; 109 } 110 try 111 { 112 defaultPrintRobot = (Hardware)activeProject.findDefaultItem(dc, 105 {} 106 try 107 { 108 defaultPrintRobots = (List<Hardware>)activeProject.findDefaultItems(dc, 113 109 ItemSubtype.getById(dc, SystemItems.getId(Hardware.PRINT_ROBOT)), false); 114 110 } 115 111 catch (PermissionDeniedException pdex) 116 { 117 defaultPrintRobot = null; 118 } 112 {} 119 113 } 120 114 if (itemId == 0) … … 404 398 denied="<%=!readCurrentArrayDesign%>" 405 399 recent="<%=recentArrayDesigns%>" 406 defaultitem ="<%=defaultArrayDesign%>"400 defaultitems="<%=defaultArrayDesigns%>" 407 401 newitem="true" 408 402 onselect="selectArrayDesignOnClick()" … … 424 418 denied="<%=!readCurrentPrintRobot%>" 425 419 recent="<%=recentPrintRobots%>" 426 defaultitem ="<%=defaultPrintRobot%>"420 defaultitems="<%=defaultPrintRobots%>" 427 421 newitem="<%=batch == null%>" 428 422 onselect="selectPrintRobotOnClick()" … … 440 434 denied="<%=!readCurrentProtocol%>" 441 435 recent="<%=recentProtocols%>" 442 defaultitem ="<%=defaultProtocol%>"436 defaultitems="<%=defaultProtocols%>" 443 437 newitem="<%=batch == null%>" 444 438 onselect="selectProtocolOnClick()" -
trunk/www/lims/arraydesigns/edit_design.jsp
r5650 r5687 75 75 Platform currentPlatform = null; 76 76 PlatformVariant currentVariant = null; 77 Platform defaultPlatform= null;78 PlatformVariant defaultVariant= null;77 List<Platform> defaultPlatforms = null; 78 List<PlatformVariant> defaultVariants = null; 79 79 80 80 int activeProjectId = sc.getActiveProjectId(); … … 84 84 try 85 85 { 86 defaultPlatform = (Platform)activeProject.findDefaultItem(dc, Item.PLATFORM);86 defaultPlatforms = (List<Platform>)activeProject.findDefaultItems(dc, Item.PLATFORM, true); 87 87 } 88 88 catch (PermissionDeniedException pdex) … … 90 90 try 91 91 { 92 defaultVariant = (PlatformVariant)activeProject.findDefaultItem(dc, Item.PLATFORMVARIANT);92 defaultVariants = (List<PlatformVariant>)activeProject.findDefaultItems(dc, Item.PLATFORMVARIANT, true); 93 93 } 94 94 catch (PermissionDeniedException pdex) … … 109 109 catch (Throwable t) 110 110 {} 111 if (currentPlatform == null) currentPlatform = defaultPlatform; 112 if (currentVariant == null) currentVariant = defaultVariant; 111 if (currentPlatform == null && defaultPlatforms.size() > 0) 112 { 113 currentPlatform = defaultPlatforms.get(0); 114 } 115 if (currentVariant == null && defaultVariants.size() > 0) 116 { 117 currentVariant = defaultVariants.get(0); 118 } 113 119 } 114 120 else -
trunk/www/views/derivedbioassays/edit_bioassay.jsp
r5685 r5687 30 30 import="net.sf.basedb.core.Hardware" 31 31 import="net.sf.basedb.core.Software" 32 import="net.sf.basedb.core.Project" 32 33 import="net.sf.basedb.core.Item" 33 34 import="net.sf.basedb.core.ItemContext" … … 43 44 import="net.sf.basedb.clients.web.util.HTML" 44 45 import="net.sf.basedb.util.Values" 46 import="net.sf.basedb.util.ListUtil" 45 47 import="net.sf.basedb.core.plugin.GuiContext" 46 48 import="net.sf.basedb.clients.web.extensions.ExtensionsControl" … … 50 52 import="java.util.Date" 51 53 import="java.util.List" 54 import="java.util.Collections" 52 55 %> 53 56 <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> … … 67 70 68 71 boolean readCurrentSubtype = true; 69 int currentSubtypeId = 0;72 ItemSubtype currentSubtype = null; 70 73 71 74 boolean readCurrentPhysicalBioAssay = true; … … 80 83 boolean readCurrentProtocol = true; 81 84 Protocol currentProtocol = null; 82 Protocol defaultProtocol = null;83 85 84 86 boolean readCurrentHardware = true; 85 87 Hardware currentHardware = null; 86 Hardware defaultHardware = null;87 88 88 89 boolean readCurrentSoftware = true; 89 90 Software currentSoftware = null; 90 Software defaultSoftware = null;91 92 // Load recently used items93 List<PhysicalBioAssay> recentPhysicalBioAssays = (List<PhysicalBioAssay>)cc.getRecent(dc, Item.PHYSICALBIOASSAY);94 List<DerivedBioAssay> recentParentBioAssays = (List<DerivedBioAssay>)cc.getRecent(dc, Item.DERIVEDBIOASSAY);95 List<Protocol> recentProtocols = (List<Protocol>)cc.getRecent(dc, Item.PROTOCOL);96 List<Hardware> recentHardware = (List<Hardware>)cc.getRecent(dc, Item.HARDWARE);97 List<Software> recentSoftware = (List<Software>)cc.getRecent(dc, Item.SOFTWARE);98 91 99 92 if (itemId == 0) … … 101 94 title = "New derived bioassay"; 102 95 cc.removeObject("item"); 103 currentSubtypeId = Values.getInt(request.getParameter("subtype_id")); 104 if (currentSubtypeId == 0) 105 { 106 int recentSubtypeId = Values.getInt(cc.getRecent(Item.ITEMSUBTYPE.name(), 0)); 107 currentSubtypeId = Values.getInt(cc.getPropertyValue("itemSubtype"), recentSubtypeId); 108 } 109 96 int currentSubtypeId = Values.getInt(request.getParameter("subtype_id")); 97 List<ItemSubtype> relatedToParent = Collections.emptyList(); 110 98 int parentId = Values.getInt(request.getParameter("parent_id")); 111 99 if (parentId != 0) 112 100 { 113 101 currentParentBioAssay = DerivedBioAssay.getById(dc, parentId); 102 if (currentSubtypeId == 0) 103 { 104 relatedToParent = ItemSubtype.getParentSubtypes(dc, currentParentBioAssay, Item.DERIVEDBIOASSAY); 105 } 114 106 try 115 107 { … … 133 125 { 134 126 currentPhysicalBioAssay = PhysicalBioAssay.getById(dc, physicalBioAssayId); 135 } 136 } 137 127 if (currentSubtypeId == 0) 128 { 129 relatedToParent = ItemSubtype.getParentSubtypes(dc, currentPhysicalBioAssay, Item.DERIVEDBIOASSAY); 130 } 131 } 132 } 133 if (currentSubtypeId == 0) 134 { 135 if (relatedToParent.size() > 0) 136 { 137 // Find most recently used related subtype 138 List<ItemSubtype> recentSubtypes = (List<ItemSubtype>)cc.getRecent(dc, Item.ITEMSUBTYPE); 139 currentSubtype = ListUtil.findFirstCommon(recentSubtypes, relatedToParent, relatedToParent.get(0)); 140 } 141 else 142 { 143 int recentSubtypeId = Values.getInt(cc.getRecent(Item.ITEMSUBTYPE.name(), 0)); 144 currentSubtypeId = Values.getInt(cc.getPropertyValue("itemSubtype"), recentSubtypeId); 145 if (currentSubtypeId > 0) currentSubtype = ItemSubtype.getById(dc, currentSubtypeId); 146 } 147 } 138 148 } 139 149 else … … 146 156 try 147 157 { 148 ItemSubtype subtype = bioAssay.getItemSubtype(); 149 if (subtype != null) currentSubtypeId = subtype.getId(); 158 currentSubtype = bioAssay.getItemSubtype(); 150 159 } 151 160 catch (PermissionDeniedException ex) … … 202 211 } 203 212 } 213 214 // Default items 215 int activeProjectId = sc.getActiveProjectId(); 216 List<Protocol> defaultProtocols = null; 217 List<Hardware> defaultHardware = null; 218 List<Software> defaultSoftware = null; 219 if (activeProjectId > 0) 220 { 221 Project activeProject = Project.getById(dc, activeProjectId); 222 defaultProtocols = (List<Protocol>)activeProject.findDefaultItemsOfRelatedSubtype(dc, currentSubtype, Item.PROTOCOL); 223 defaultHardware = (List<Hardware>)activeProject.findDefaultItemsOfRelatedSubtype(dc, currentSubtype, Item.HARDWARE); 224 defaultSoftware = (List<Software>)activeProject.findDefaultItemsOfRelatedSubtype(dc, currentSubtype, Item.SOFTWARE); 225 } 226 227 // Load recently used items 228 List<PhysicalBioAssay> recentPhysicalBioAssays = (List<PhysicalBioAssay>)cc.getRecent(dc, Item.PHYSICALBIOASSAY); 229 List<DerivedBioAssay> recentParentBioAssays = (List<DerivedBioAssay>)cc.getRecent(dc, Item.DERIVEDBIOASSAY); 230 List<Protocol> recentProtocols = (List<Protocol>)cc.getRecent(dc, Item.PROTOCOL, currentSubtype); 231 List<Hardware> recentHardware = (List<Hardware>)cc.getRecent(dc, Item.HARDWARE, currentSubtype); 232 List<Software> recentSoftware = (List<Software>)cc.getRecent(dc, Item.SOFTWARE, currentSubtype); 233 204 234 // Query to retrieve item types 205 235 final ItemQuery<ItemSubtype> subtypesQuery = Base.getSubtypesQuery(itemType); … … 346 376 } 347 377 378 function subtypeOnChange() 379 { 380 var frm = document.forms['bioAssay']; 381 var subtypeId = ItemSubtype.getSubtypeId('bioAssay'); 382 var recentInfo = ItemSubtype.getRecentAndRelatedInfo(subtypeId, 'BIOASSAY', ['PROTOCOL', 'HARDWARE', 'SOFTWARE']); 383 protocolChanged = ItemSubtype.updateRecentItemsInList(frm.protocol_id, recentInfo.PROTOCOL['recent']); 384 ItemSubtype.updateDefaultItemsInList(frm.protocol_id, recentInfo.PROTOCOL['default']); 385 ItemSubtype.updateRecentItemsInList(frm.hardware_id, recentInfo.HARDWARE['recent']); 386 ItemSubtype.updateDefaultItemsInList(frm.hardware_id, recentInfo.HARDWARE['default']); 387 ItemSubtype.updateRecentItemsInList(frm.software_id, recentInfo.SOFTWARE['recent']); 388 ItemSubtype.updateDefaultItemsInList(frm.software_id, recentInfo.SOFTWARE['default']); 389 } 390 391 348 392 function selectProtocolOnClick() 349 393 { 350 394 var frm = document.forms['bioAssay']; 351 var url = '../../ ../admin/protocols/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone';395 var url = '../../admin/protocols/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone'; 352 396 url += '&callback=setProtocolCallback&resetTemporary=1'; 353 397 url += ItemSubtype.createRelatedFilter('bioAssay', 'PROTOCOL'); … … 444 488 { 445 489 var frm = document.forms['bioAssay']; 446 var url = '../../ ../admin/hardware/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone';490 var url = '../../admin/hardware/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone'; 447 491 url += '&callback=setHardwareCallback&resetTemporary=1'; 448 492 url += ItemSubtype.createRelatedFilter('bioAssay', 'HARDWARE'); … … 469 513 { 470 514 var frm = document.forms['bioAssay']; 471 var url = '../../ ../admin/software/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone';515 var url = '../../admin/software/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone'; 472 516 url += '&callback=setSoftwareCallback&resetTemporary=1'; 473 517 url += ItemSubtype.createRelatedFilter('bioAssay', 'SOFTWARE'); … … 647 691 <td colspan="2"> 648 692 <select name="subtype_id" 649 <%=!readCurrentSubtype ? "disabled readonly class=\"disabled selectionlist\"" : "class=\"selectionlist\""%>> 693 <%=!readCurrentSubtype ? "disabled readonly class=\"disabled selectionlist\"" : "class=\"selectionlist\""%> 694 onchange="subtypeOnChange()" 695 > 650 696 <% 651 697 if (!readCurrentSubtype) … … 660 706 <option value="0">-none- 661 707 <% 708 int currentSubtypeId = currentSubtype == null ? 0 : currentSubtype.getId(); 662 709 for (ItemSubtype subtype : subtypesQuery.list(dc)) 663 710 { … … 740 787 denied="<%=!readCurrentProtocol%>" 741 788 recent="<%=recentProtocols%>" 742 defaultitem ="<%=defaultProtocol%>"789 defaultitems="<%=defaultProtocols%>" 743 790 newitem="<%=bioAssay == null%>" 744 791 onselect="selectProtocolOnClick()" … … 757 804 denied="<%=!readCurrentHardware%>" 758 805 recent="<%=recentHardware%>" 759 defaultitem ="<%=defaultHardware%>"806 defaultitems="<%=defaultHardware%>" 760 807 newitem="<%=bioAssay == null%>" 761 808 onselect="selectHardwareOnClick()" … … 773 820 denied="<%=!readCurrentSoftware%>" 774 821 recent="<%=recentSoftware%>" 775 defaultitem ="<%=defaultSoftware%>"822 defaultitems="<%=defaultSoftware%>" 776 823 newitem="<%=bioAssay == null%>" 777 824 onselect="selectSoftwareOnClick()" -
trunk/www/views/derivedbioassays/index.jsp
r5685 r5687 208 208 209 209 int subtypeId = Values.getInt(request.getParameter("subtype_id"), -1); 210 ItemSubtype subtype = null; 210 211 if (subtypeId >= 0) // < 0 = denied or unchanged 211 212 { 212 ItemSubtypesubtype = subtypeId == 0 ? null : ItemSubtype.getById(dc, subtypeId);213 subtype = subtypeId == 0 ? null : ItemSubtype.getById(dc, subtypeId); 213 214 bas.setItemSubtype(subtype); 214 215 if (subtype != null) cc.setRecent(subtype, maxRecent); … … 227 228 Protocol pt = protocolId == 0 ? null : Protocol.getById(dc, protocolId); 228 229 bas.setProtocol(pt); 229 if (pt != null) cc.setRecent(pt, maxRecent);230 if (pt != null) cc.setRecent(pt, subtype, maxRecent); 230 231 } 231 232 … … 235 236 Hardware hw = hardwareId == 0 ? null : Hardware.getById(dc, hardwareId); 236 237 bas.setHardware(hw); 237 if (hw != null) cc.setRecent(hw, maxRecent);238 if (hw != null) cc.setRecent(hw, subtype, maxRecent); 238 239 } 239 240 … … 243 244 Software sw = softwareId == 0 ? null : Software.getById(dc, softwareId); 244 245 bas.setSoftware(sw); 245 if (sw != null) cc.setRecent(sw, maxRecent);246 if (sw != null) cc.setRecent(sw, subtype, maxRecent); 246 247 } 247 248 -
trunk/www/views/physicalbioassays/edit_bioassay.jsp
r5662 r5687 53 53 import="net.sf.basedb.clients.web.util.HTML" 54 54 import="net.sf.basedb.util.Values" 55 import="net.sf.basedb.util.ListUtil" 55 56 import="net.sf.basedb.util.formatter.Formatter" 56 57 import="net.sf.basedb.clients.web.formatter.FormatterFactory" … … 65 66 import="java.util.HashSet" 66 67 import="java.util.Date" 68 import="java.util.Collections" 67 69 %> 68 70 <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> … … 83 85 BioMaterialEvent creationEvent = null; 84 86 Date eventDate = null; 85 ItemQuery<Extract> extractsQuery= null;87 List<Extract> parentExtracts = null; 86 88 87 89 boolean readCurrentSubtype = true; 88 int currentSubtypeId = 0;90 ItemSubtype currentSubtype = null; 89 91 boolean readCurrentArraySlide = true; 90 92 ArraySlide currentArraySlide = null; … … 92 94 boolean readCurrentProtocol = true; 93 95 Protocol currentProtocol = null; 94 Protocol defaultProtocol = null;95 96 96 97 boolean readCurrentHardware = true; 97 98 Hardware currentHardware = null; 98 Hardware defaultHardware = null; 99 100 // Load recently used items 101 List<Protocol> recentProtocols = (List<Protocol>)cc.getRecent(dc, Item.PROTOCOL); 102 List<Hardware> recentHardware = (List<Hardware>)cc.getRecent(dc, Item.HARDWARE); 103 104 int activeProjectId = sc.getActiveProjectId(); 105 if (activeProjectId > 0) 106 { 107 Project activeProject = Project.getById(dc, activeProjectId); 108 try 109 { 110 defaultProtocol = (Protocol)activeProject.findDefaultItem(dc, 111 ItemSubtype.getById(dc, SystemItems.getId(Protocol.HYBRIDIZATION)), false); 112 } 113 catch (PermissionDeniedException pdex) 114 { 115 defaultProtocol = null; 116 } 117 try 118 { 119 defaultHardware = (Hardware)activeProject.findDefaultItem(dc, 120 ItemSubtype.getById(dc, SystemItems.getId(Hardware.HYBRIDIZATION_STATION)), false); 121 } 122 catch (PermissionDeniedException pdex) 123 { 124 defaultHardware = null; 125 } 126 } 99 127 100 if (itemId == 0) 128 101 { 129 102 title = "Create physical bioassay"; 130 103 cc.removeObject("item"); 131 currentSubtypeId = Values.getInt(request.getParameter("subtype_id"));132 if (currentSubtypeId == 0)133 {134 int recentSubtypeId = Values.getInt(cc.getRecent(Item.ITEMSUBTYPE.name(), 0));135 currentSubtypeId = Values.getInt(cc.getPropertyValue("itemSubtype"), recentSubtypeId);136 }137 104 if (cc.getPropertyFilter("creationEvent.protocol.name") != null) 138 105 { … … 150 117 eventDate = (Date)cc.getPropertyObject("creationEvent.eventDate"); 151 118 119 int currentSubtypeId = Values.getInt(request.getParameter("subtype_id")); 120 List<ItemSubtype> relatedToParent = Collections.emptyList(); 121 ItemQuery<Extract> extractsQuery = null; 152 122 if (Values.getBoolean(request.getParameter("useParents"))) 153 123 { … … 169 139 extractsQuery.restrict(Restrictions.eq(Hql.property("id"), 170 140 Expressions.integer(leId))); 141 } 142 143 if (extractsQuery != null) 144 { 145 parentExtracts = extractsQuery.list(dc); 146 if (currentSubtypeId == 0 && parentExtracts.size() > 0) 147 { 148 relatedToParent = ItemSubtype.getParentSubtypes(dc, parentExtracts.get(0), Item.PHYSICALBIOASSAY); 149 } 150 } 151 152 if (currentSubtypeId == 0) 153 { 154 if (relatedToParent.size() > 0) 155 { 156 // Find most recently used related subtype 157 List<ItemSubtype> recentSubtypes = (List<ItemSubtype>)cc.getRecent(dc, Item.ITEMSUBTYPE); 158 currentSubtype = ListUtil.findFirstCommon(recentSubtypes, relatedToParent, relatedToParent.get(0)); 159 } 160 else 161 { 162 int recentSubtypeId = Values.getInt(cc.getRecent(Item.ITEMSUBTYPE.name(), 0)); 163 currentSubtypeId = Values.getInt(cc.getPropertyValue("itemSubtype"), recentSubtypeId); 164 if (currentSubtypeId > 0) currentSubtype = ItemSubtype.getById(dc, currentSubtypeId); 165 } 171 166 } 172 167 } … … 183 178 try 184 179 { 185 ItemSubtype subtype = pba.getItemSubtype(); 186 if (subtype != null) currentSubtypeId = subtype.getId(); 180 currentSubtype = pba.getItemSubtype(); 187 181 } 188 182 catch (PermissionDeniedException ex) … … 217 211 218 212 // Query to retrieve source extracts 219 extractsQuery = (ItemQuery<Extract>)creationEvent.getSources();213 ItemQuery<Extract> extractsQuery = (ItemQuery<Extract>)creationEvent.getSources(); 220 214 extractsQuery.include(Include.ALL); 221 215 extractsQuery.order(Orders.asc(Hql.property("name"))); 216 parentExtracts = extractsQuery.list(dc); 222 217 223 218 } 219 220 // Default items 221 int activeProjectId = sc.getActiveProjectId(); 222 List<Protocol> defaultProtocols = null; 223 List<Hardware> defaultHardware = null; 224 if (activeProjectId > 0) 225 { 226 Project activeProject = Project.getById(dc, activeProjectId); 227 defaultProtocols = (List<Protocol>)activeProject.findDefaultItemsOfRelatedSubtype(dc, currentSubtype, Item.PROTOCOL); 228 defaultHardware = (List<Hardware>)activeProject.findDefaultItemsOfRelatedSubtype(dc, currentSubtype, Item.HARDWARE); 229 } 230 231 // Load recently used items 232 List<Protocol> recentProtocols = (List<Protocol>)cc.getRecent(dc, Item.PROTOCOL, currentSubtype); 233 List<Hardware> recentHardware = (List<Hardware>)cc.getRecent(dc, Item.HARDWARE, currentSubtype); 234 224 235 // Query to retrieve item types 225 236 final ItemQuery<ItemSubtype> subtypesQuery = Base.getSubtypesQuery(itemType); … … 319 330 return protocolId; 320 331 } 321 332 322 333 function getParents() 323 334 { … … 336 347 } 337 348 349 function subtypeOnChange() 350 { 351 var frm = document.forms['bioassay']; 352 var subtypeId = ItemSubtype.getSubtypeId('bioassay'); 353 var recentInfo = ItemSubtype.getRecentAndRelatedInfo(subtypeId, 'BIOASSAY', ['PROTOCOL', 'HARDWARE']); 354 protocolChanged = ItemSubtype.updateRecentItemsInList(frm.protocol_id, recentInfo.PROTOCOL['recent']); 355 ItemSubtype.updateDefaultItemsInList(frm.protocol_id, recentInfo.PROTOCOL['default']); 356 ItemSubtype.updateRecentItemsInList(frm.hardware_id, recentInfo.HARDWARE['recent']); 357 ItemSubtype.updateDefaultItemsInList(frm.hardware_id, recentInfo.HARDWARE['default']); 358 } 359 338 360 function selectProtocolOnClick() 339 361 { … … 541 563 <% 542 564 } 543 if (extractsQuery != null) 544 { 545 ItemResultList<Extract> extracts = extractsQuery.list(dc); 546 for (Extract extract : extracts) 565 if (parentExtracts != null) 566 { 567 for (Extract extract : parentExtracts) 547 568 { 548 569 if (pba == null) … … 590 611 <td colspan="2"> 591 612 <select name="subtype_id" 592 <%=!readCurrentSubtype ? "disabled readonly class=\"disabled selectionlist\"" : "class=\"selectionlist\""%>> 613 <%=!readCurrentSubtype ? "disabled readonly class=\"disabled selectionlist\"" : "class=\"selectionlist\""%> 614 onchange="subtypeOnChange()" 615 > 593 616 <% 594 617 if (!readCurrentSubtype) … … 600 623 else 601 624 { 625 int currentSubtypeId = currentSubtype == null ? 0 : currentSubtype.getId(); 602 626 %> 603 627 <option value="0">-none- … … 662 686 denied="<%=!readCurrentProtocol%>" 663 687 recent="<%=recentProtocols%>" 664 defaultitem ="<%=defaultProtocol%>"688 defaultitems="<%=defaultProtocols%>" 665 689 newitem="<%=pba == null%>" 666 690 onselect="selectProtocolOnClick()" … … 679 703 denied="<%=!readCurrentHardware%>" 680 704 recent="<%=recentHardware%>" 681 defaultitem ="<%=defaultHardware%>"705 defaultitems="<%=defaultHardware%>" 682 706 newitem="<%=pba == null%>" 683 707 onselect="selectHardwareOnClick()" -
trunk/www/views/physicalbioassays/index.jsp
r5685 r5687 198 198 pba.setDescription(Values.getStringOrNull(request.getParameter("description"))); 199 199 pba.setSize(Values.getInt(request.getParameter("size"), 1)); 200 201 int subtypeId = Values.getInt(request.getParameter("subtype_id"), -1); 202 ItemSubtype subtype = null; 203 if (subtypeId >= 0) // < 0 = denied or unchanged 204 { 205 if (subtypeId > 0) subtype = ItemSubtype.getById(dc, subtypeId); 206 pba.setItemSubtype(subtype); 207 if (subtype != null) cc.setRecent(subtype, maxRecent); 208 } 200 209 201 210 int arraySlideId = Values.getInt(request.getParameter("arrayslide_id"), -1); … … 212 221 Protocol pt = protocolId == 0 ? null : Protocol.getById(dc, protocolId); 213 222 creationEvent.setProtocol(pt); 214 if (pt != null) cc.setRecent(pt, maxRecent);223 if (pt != null) cc.setRecent(pt, subtype, maxRecent); 215 224 } 216 225 217 int subtypeId = Values.getInt(request.getParameter("subtype_id"), -1);218 if (subtypeId >= 0) // < 0 = denied or unchanged219 {220 ItemSubtype subtype = subtypeId == 0 ? null : ItemSubtype.getById(dc, subtypeId);221 pba.setItemSubtype(subtype);222 if (subtype != null) cc.setRecent(subtype, maxRecent);223 }224 225 226 //Hardware 226 227 int hardwareId = Values.getInt(request.getParameter("hardware_id"), -1); … … 229 230 Hardware hw = hardwareId == 0 ? null : Hardware.getById(dc, hardwareId); 230 231 creationEvent.setHardware(hw); 231 if (hw != null) cc.setRecent(hw, maxRecent);232 if (hw != null) cc.setRecent(hw, subtype, maxRecent); 232 233 } 233 234 -
trunk/www/views/rawbioassays/edit_rawbioassay.jsp
r5685 r5687 85 85 boolean deniedPlatform = false; 86 86 Platform currentPlatform = null; 87 Platform defaultPlatform= null;87 List<Platform> defaultPlatforms = null; 88 88 PlatformVariant currentVariant = null; 89 PlatformVariant defaultVariant= null;89 List<PlatformVariant> defaultVariants = null; 90 90 91 91 boolean readCurrentBioAssay = true; … … 95 95 boolean readCurrentProtocol = true; 96 96 Protocol currentProtocol = null; 97 Protocol defaultProtocol= null;97 List<Protocol> defaultProtocols = null; 98 98 boolean readCurrentSoftware = true; 99 99 Software currentSoftware = null; 100 SoftwaredefaultSoftware = null;100 List<Software> defaultSoftware = null; 101 101 boolean readCurrentArrayDesign = true; 102 102 ArrayDesign currentArrayDesign = null; 103 ArrayDesign defaultArrayDesign= null;103 List<ArrayDesign> defaultArrayDesigns = null; 104 104 RawDataType currentRawDataType = null; 105 105 RawDataType defaultRawDataType = null; … … 119 119 try 120 120 { 121 defaultProtocol = (Protocol)activeProject.findDefaultItem(dc,121 defaultProtocols = (List<Protocol>)activeProject.findDefaultItems(dc, 122 122 ItemSubtype.getById(dc, SystemItems.getId(Protocol.FEATURE_EXTRACTION)), false); 123 }124 catch (PermissionDeniedException pdex)125 {126 defaultProtocol = null;127 }128 try129 {130 defaultSoftware = (Software)activeProject.findDefaultItem(dc,131 ItemSubtype.getById(dc, SystemItems.getId(Software.FEATURE_EXTRACTION)), false);132 }133 catch (PermissionDeniedException pdex)134 {135 defaultSoftware = null;136 }137 try138 {139 defaultArrayDesign = (ArrayDesign)activeProject.findDefaultItem(dc, Item.ARRAYDESIGN);140 }141 catch (PermissionDeniedException pdex)142 {143 defaultArrayDesign = null;144 }145 try146 {147 defaultPlatform = (Platform)activeProject.findDefaultItem(dc, Item.PLATFORM);148 123 } 149 124 catch (PermissionDeniedException pdex) … … 151 126 try 152 127 { 153 defaultVariant = (PlatformVariant)activeProject.findDefaultItem(dc, Item.PLATFORMVARIANT); 128 defaultSoftware = (List<Software>)activeProject.findDefaultItems(dc, 129 ItemSubtype.getById(dc, SystemItems.getId(Software.FEATURE_EXTRACTION)), false); 130 } 131 catch (PermissionDeniedException pdex) 132 {} 133 try 134 { 135 defaultArrayDesigns = (List<ArrayDesign>)activeProject.findDefaultItems(dc, Item.ARRAYDESIGN, true); 136 } 137 catch (PermissionDeniedException pdex) 138 {} 139 try 140 { 141 defaultPlatforms = (List<Platform>)activeProject.findDefaultItems(dc, Item.PLATFORM, true); 142 } 143 catch (PermissionDeniedException pdex) 144 {} 145 try 146 { 147 defaultVariants = (List<PlatformVariant>)activeProject.findDefaultItems(dc, Item.PLATFORMVARIANT, true); 154 148 } 155 149 catch (PermissionDeniedException pdex) … … 176 170 catch (Throwable t) 177 171 {} 178 if (currentPlatform == null) currentPlatform = defaultPlatform; 179 if (currentVariant == null) currentVariant = defaultVariant; 172 if (currentPlatform == null && defaultPlatforms.size() > 0) 173 { 174 currentPlatform = defaultPlatforms.get(0); 175 } 176 if (currentVariant == null && defaultVariants.size() > 0) 177 { 178 currentVariant = defaultVariants.get(0); 179 } 180 180 181 181 currentRawDataType = RawDataTypes.getRawDataType(cc.getPropertyValue("rawDataType")); … … 772 772 denied="<%=!readCurrentArrayDesign%>" 773 773 recent="<%=recentArrayDesigns%>" 774 defaultitem ="<%=defaultArrayDesign%>"774 defaultitems="<%=defaultArrayDesigns%>" 775 775 newitem="<%=rawBioAssay == null%>" 776 776 onselect="selectArrayDesignOnClick()" … … 804 804 denied="<%=!readCurrentProtocol%>" 805 805 recent="<%=recentProtocols%>" 806 defaultitem ="<%=defaultProtocol%>"806 defaultitems="<%=defaultProtocols%>" 807 807 newitem="<%=rawBioAssay == null%>" 808 808 onselect="selectProtocolOnClick()" … … 821 821 denied="<%=!readCurrentSoftware%>" 822 822 recent="<%=recentSoftware%>" 823 defaultitem ="<%=defaultSoftware%>"823 defaultitems="<%=defaultSoftware%>" 824 824 newitem="<%=rawBioAssay == null%>" 825 825 onselect="selectSoftwareOnClick()"
Note: See TracChangeset
for help on using the changeset viewer.