Changeset 5687


Ignore:
Timestamp:
Aug 9, 2011, 1:39:40 PM (10 years ago)
Author:
Nicklas Nordborg
Message:

References #1597: Subtypes of items

Smarter selection of default subtypes and related items (protocols, etc) have now been implemented in the other important edit dialogs.

Added support for also loading and displaying project default items dynamically based on the selected subtype.

Location:
trunk
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/clients/web/net/sf/basedb/clients/web/taglib/Select.java

    r5663 r5687  
    2222package net.sf.basedb.clients.web.taglib;
    2323
     24import java.util.Collections;
    2425import java.util.List;
    2526
     
    315316 
    316317  /**
    317       The project default value
    318   */
    319   private transient BasicItem defaultitem;
     318      The project default values.
     319  */
     320  private transient List<? extends BasicItem> defaultItems;
    320321 
    321322  /**
     
    481482  public void setDefaultitem(BasicItem defaultitem)
    482483  {
    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;
    488490  }
    489491 
     
    584586        sb.append("<option value=\"0\">").append(getUnselectedtext()).append("\n");
    585587      }
     588      boolean hasSelected = false;
    586589      if (current != null)
    587590      {
     
    589592        sb.append(current.getId() * (isNewitem() ? 1 : -1));
    590593        sb.append("\" selected>");
     594        hasSelected = true;
    591595        String name = getName(current);
    592596        sb.append(HTML.encodeTags(name)).append("\n");
     
    607611          sb.append("<option value=\"").append(item.getId()).append("\"");
    608612          sb.append(" class=\"").append(clazz).append("\"");
    609           if (i == 1 && current == null && isNewitem() && getSelectrecent())
     613          if (!hasSelected && isNewitem() && getSelectrecent())
    610614          {
    611615            sb.append(" selected");
     616            hasSelected = true;
    612617          }
    613618          sb.append(">").append(i).append(". ").append(name).append("\n");
     
    615620        }
    616621      }
    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");
    631637        }
    632         sb.append(">").append(name).append("\n");
    633638      }
    634639    }
  • trunk/src/core/net/sf/basedb/core/Project.java

    r5652 r5687  
    3939import net.sf.basedb.info.ProjectInfo;
    4040import net.sf.basedb.info.ToTransferable;
     41import net.sf.basedb.util.EqualsHelper;
    4142
    4243import java.util.ArrayList;
     
    674675 
    675676  /**
    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   
    678681    @param dc A DbControl for database access
    679682    @param itemType The type of item to find
    680     @return The item that was found, or null
     683    @return A list with the items that was found (empty if no item was found)
    681684    @since 3.0
    682685  */
    683   public BasicItem findDefaultItem(DbControl dc, Item itemType)
     686  public List<? extends BasicItem> findDefaultItems(DbControl dc, Item itemType, boolean strict)
    684687  {
    685688    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
    692700    strict parameter is true, an exact match must be found, otherwise
    693701    the search is repeated to find an item without a subtype. The search
     
    698706    @param strict TRUE to strictly match the subtype, FALSE to also
    699707      search for items without subtype
    700     @return The item that was found, or null
     708    @return A list with the items that was found (empty if no item was found)
    701709    @since 3.0
    702710  */
    703   public BasicItem findDefaultItem(DbControl dc, ItemSubtype subtype, boolean strict)
     711  public List<? extends BasicItem> findDefaultItems(DbControl dc, ItemSubtype subtype, boolean strict)
    704712  {
    705713    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    }
    708750  }
    709751 
     
    788830  /**
    789831    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.
    795841   
    796842      @param itemType The main item type of the item we are looking for
     
    811857      if (dataClass.isInstance(data))
    812858      {
    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))
    815868        {
    816869          bestMatch = data;
     
    818871        }
    819872       
    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)
    833877          {
    834878            bestMatch = data;
    835879          }
    836880        }
    837        
    838881      }
    839882    }
    840883    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;
    841935  }
    842936
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/AbstractItemImporter.java

    r5661 r5687  
    12851285  }
    12861286  /**
    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.
    12881289    @return The active platform, or null if no project is active or
    12891290      the project doesn't specify a platform
     
    12941295    if (sc.getActiveProjectId() == 0) return null;
    12951296    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);
    12971299  }
    12981300 
     
    13071309    if (sc.getActiveProjectId() == 0) return null;
    13081310    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);
    13101313  }
    13111314 
  • trunk/src/test/TestProject.java

    r5653 r5687  
    139139      Project p = Project.getById(dc, project_id);
    140140     
    141       BasicItem found = null;
     141      List<? extends BasicItem> found = null;
    142142      if (subtypeId == 0)
    143143      {
    144         found = p.findDefaultItem(dc, defaultType);
     144        found = p.findDefaultItems(dc, defaultType, true);
    145145      }
    146146      else
    147147      {
    148148        ItemSubtype subtype = ItemSubtype.getById(dc, subtypeId);
    149         found = p.findDefaultItem(dc, subtype, true);
     149        found = p.findDefaultItems(dc, subtype, true);
    150150      }
    151151     
    152       if (found == null)
     152      if (found == null || found.size() == 0)
    153153      {
    154154        throw new ItemNotFoundException("Default " + defaultType + " for project: " + p);
    155155      }
    156       else if (found.getId() != expectedId)
     156      else if (found.get(0).getId() != expectedId)
    157157      {
    158158        throw new RuntimeException("Found " + found);
  • trunk/www/WEB-INF/base.tld

    r5663 r5687  
    433433    </attribute>
    434434    <attribute>
     435      <name>defaultitems</name>
     436      <required>false</required>
     437      <rtexprvalue>true</rtexprvalue>
     438    </attribute>
     439    <attribute>
    435440      <name>selectdefault</name>
    436441      <required>false</required>
  • trunk/www/admin/itemsubtypes/ajax.jsp

    r5686 r5687  
    2727  import="net.sf.basedb.core.Item"
    2828  import="net.sf.basedb.core.ItemContext"
     29  import="net.sf.basedb.core.Project"
    2930  import="net.sf.basedb.core.ItemSubtype"
    3031  import="net.sf.basedb.core.Subtypable"
    3132  import="net.sf.basedb.core.BasicItem"
    3233  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"
    3338  import="net.sf.basedb.core.InvalidDataException"
    3439  import="net.sf.basedb.util.Values"
     
    9196    dc = sc.newDbControl();
    9297
     98    // The main item's subtype
    9399    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;
    97101    if (subtype != null)
    98102    {
     103      mainItemType = subtype.getMainItemType();
    99104      json.put("id", subtype.getId());
    100105      json.put("name", subtype.getName());
    101106    }
     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;
    102117   
     118    // Related item types
    103119    for (String relatedType : request.getParameterValues("relatedType"))
    104120    {
     
    107123     
    108124      // Load the related subtype
     125      ItemSubtype relatedSubtype = null;
    109126      if (subtype != null)
    110127      {
    111         ItemSubtype relatedSubtype = subtype.getRelatedSubtype(relatedItem);
     128        relatedSubtype = subtype.getRelatedSubtype(relatedItem);
    112129        if (relatedSubtype != null)
    113130        {
     
    119136      }
    120137     
     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     
    121160      // Load the most recently used items
    122161      List<? extends BasicItem> recentItems = cc.getRecent(dc, relatedItem, subtype);
     
    133172        jsonITEM.put("recent", jsonRecent);
    134173      }
     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     
    135192      json.put(relatedType, jsonITEM);
    136193    }
  • trunk/www/biomaterials/extracts/edit_extract.jsp

    r5665 r5687  
    5454  import="net.sf.basedb.clients.web.util.HTML"
    5555  import="net.sf.basedb.util.Values"
     56  import="net.sf.basedb.util.ListUtil"
    5657  import="net.sf.basedb.util.formatter.Formatter"
    5758  import="net.sf.basedb.util.formatter.WellCoordinateFormatter"
     
    6768  import="java.util.HashSet"
    6869  import="java.util.Date"
     70  import="java.util.Collections"
    6971%>
    7072<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
     
    9193
    9294  boolean readCurrentSubtype = true;
    93   int currentSubtypeId = 0;
     95  ItemSubtype currentSubtype = null;
    9496  boolean readCurrentProtocol = true;
    9597  Protocol currentProtocol = null;
    96   Protocol defaultProtocol = null;
    9798  boolean readCurrentTag = true;
    9899  Tag currentTag = null;
     
    108109  BioPlate currentBioPlate = null;
    109110 
    110   // Load recently used items
    111   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     try
    121     {
    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   }
    130111  if (itemId == 0)
    131112  {
     
    140121      currentTag = Base.getFirstMatching(dc, Tag.getQuery(), "name", cc.getPropertyFilter("tag.name"));
    141122    }
    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();
    148125    int sampleId = Values.getInt(request.getParameter("sample_id"));
    149126    int extractId = Values.getInt(request.getParameter("extract_id"));
     127
    150128    if (sampleId != 0)
    151129    {
     
    153131      parentType = Item.SAMPLE;
    154132      name = currentSample.getName() + ".e" + (currentSample.countExtracts() + 1);     
     133      if (currentSubtypeId == 0)
     134      {
     135        relatedToParent = ItemSubtype.getParentSubtypes(dc, currentSample, Item.EXTRACT);
     136      }
    155137    }
    156138    else if (extractId != 0)
     
    161143      extractsQuery = Extract.getQuery();
    162144      extractsQuery.restrict(Restrictions.eq(Hql.property("id"), Expressions.integer(extractId)));
     145      if (currentSubtypeId == 0)
     146      {
     147        relatedToParent = ItemSubtype.getParentSubtypes(dc, e, Item.EXTRACT);
     148      }
    163149    }
    164150    else if (Values.getBoolean(request.getParameter("pooled")))
     
    173159    {
    174160      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      }
    175176    }
    176177    eventDate = (Date)cc.getPropertyObject("creationEvent.eventDate");   
     
    191192    try
    192193    {
    193       ItemSubtype subtype = extract.getItemSubtype();
    194       if (subtype != null) currentSubtypeId = subtype.getId();
     194      currentSubtype = extract.getItemSubtype();
    195195    }
    196196    catch (PermissionDeniedException ex)
     
    253253    }
    254254  }
     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);
    255272 
    256273  // Query to retrieve item types
     
    363380      }
    364381      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']);
    365393    }
    366394   
     
    688716        <td colspan="2">
    689717          <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            >
    691721          <%
    692722          if (!readCurrentSubtype)
     
    701731            <option value="0">-none-
    702732            <%
     733            int currentSubtypeId = currentSubtype == null ? 0 : currentSubtype.getId();
    703734            for (ItemSubtype subtype : subtypesQuery.list(dc))
    704735            {
     
    782813            denied="<%=!readCurrentProtocol%>"
    783814            recent="<%=recentProtocols%>"
    784             defaultitem="<%=defaultProtocol%>"
     815            defaultitems="<%=defaultProtocols%>"
    785816            newitem="<%=extract == null%>"
    786817            onselect="selectProtocolOnClick()"
  • trunk/www/biomaterials/extracts/index.jsp

    r5664 r5687  
    233233      extract.setOriginalQuantity(Values.getFloat(request.getParameter("original_quantity"), null));
    234234     
     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     
    235244      BioMaterialEvent creationEvent = extract.getCreationEvent();
    236245      if (creationEvent.hasPermission(Permission.WRITE))
     
    243252          Protocol pt = protocolId == 0 ? null : Protocol.getById(dc, protocolId);
    244253          creationEvent.setProtocol(pt);
    245           if (pt != null) cc.setRecent(pt, maxRecent);
     254          if (pt != null) cc.setRecent(pt, subtype, maxRecent);
    246255        }
    247       }
    248      
    249       int subtypeId = Values.getInt(request.getParameter("subtype_id"), -1);
    250       if (subtypeId >= 0) // < 0 = denied or unchanged
    251       {
    252         ItemSubtype subtype = subtypeId == 0 ? null : ItemSubtype.getById(dc, subtypeId);
    253         extract.setItemSubtype(subtype);
    254         if (subtype != null) cc.setRecent(subtype, maxRecent);
    255256      }
    256257     
     
    260261        Tag tag = tagId == 0 ? null : Tag.getById(dc, tagId);
    261262        extract.setTag(tag);
    262         if (tag != null) cc.setRecent(tag, maxRecent);
     263        if (tag != null) cc.setRecent(tag, subtype, maxRecent);
    263264      }
    264265
     
    274275        }
    275276        extract.setBioWell(bw);
    276         if (bw != null) cc.setRecent(bw.getPlate(), maxRecent);
     277        if (bw != null) cc.setRecent(bw.getPlate(), subtype, maxRecent);
    277278      }
    278279 
  • trunk/www/biomaterials/samples/edit_sample.jsp

    r5686 r5687  
    9494  boolean readCurrentProtocol = true;
    9595  Protocol currentProtocol = null;
    96   Protocol defaultProtocol = null;
    9796  boolean readCurrentBioSource = true;
    9897  BioSource currentBioSource = null;
     
    107106  WellCoordinateFormatter columnFormatter = new WellCoordinateFormatter(false);
    108107 
    109   int activeProjectId = sc.getActiveProjectId();
    110   if (activeProjectId > 0)
    111   {
    112     Project activeProject = Project.getById(dc, activeProjectId);
    113     try
    114     {
    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 
    124108  if (itemId == 0)
    125109  {
     
    250234  }
    251235 
     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 
    252247  // Load recently used items
    253248  List<Protocol> recentProtocols = (List<Protocol>)cc.getRecent(dc, Item.PROTOCOL, currentSubtype);
    254249  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);
    256251 
    257252  // Query to retrieve item types
     
    370365      var frm = document.forms['sample'];
    371366      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']);
    374371    }
    375372   
     
    742739            denied="<%=!readCurrentProtocol%>"
    743740            recent="<%=recentProtocols%>"
    744             defaultitem="<%=defaultProtocol%>"
     741            defaultitems="<%=defaultProtocols%>"
    745742            newitem="<%=sample == null%>"
    746743            onselect="selectProtocolOnClick()"
  • trunk/www/biomaterials/samples/index.jsp

    r5686 r5687  
    263263        }
    264264        sample.setBioWell(bw);
    265         if (bw != null) cc.setRecent(bw.getPlate(), maxRecent);
     265        if (bw != null) cc.setRecent(bw.getPlate(), subtype, maxRecent);
    266266      }
    267267 
  • trunk/www/include/scripts/subtypes.js

    r5686 r5687  
    159159  this.updateRecentItemsInList = function(list, recentItems, noNoneOption)
    160160  {
    161     if (!list || !recentItems) return;
     161    if (!list || !recentItems || !recentItems.length) return;
    162162   
    163163    var oldSelectedValue = list.selectedIndex >= 0 ? list[list.selectedIndex].value : 0;
     
    211211  }
    212212 
     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  }
    213226}
    214227
  • trunk/www/lims/arraybatches/edit_batch.jsp

    r5650 r5687  
    7474  boolean readCurrentArrayDesign = true;
    7575  ArrayDesign currentArrayDesign = null;
    76   ArrayDesign defaultArrayDesign = null;
     76  List<ArrayDesign> defaultArrayDesigns = null;
    7777  boolean readCurrentProtocol = true;
    7878  Protocol currentProtocol = null;
    79   Protocol defaultProtocol = null;
     79  List<Protocol> defaultProtocols = null;
    8080  boolean readCurrentPrintRobot = true;
    8181  Hardware currentPrintRobot = null;
    82   Hardware defaultPrintRobot = null;
     82  List<Hardware> defaultPrintRobots = null;
    8383
    8484  // Load recently used items
     
    9393    try
    9494    {
    95       defaultArrayDesign = (ArrayDesign)activeProject.findDefaultItem(dc, Item.ARRAYDESIGN);
     95      defaultArrayDesigns = (List<ArrayDesign>)activeProject.findDefaultItems(dc, Item.ARRAYDESIGN, true);
    9696    }
    9797    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,
    104102          ItemSubtype.getById(dc, SystemItems.getId(Protocol.PRINTING)), false);
    105103    }
    106104    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,
    113109          ItemSubtype.getById(dc, SystemItems.getId(Hardware.PRINT_ROBOT)), false);
    114110    }
    115111    catch (PermissionDeniedException pdex)
    116     {
    117       defaultPrintRobot = null;
    118     }
     112    {}
    119113  }
    120114  if (itemId == 0)
     
    404398              denied="<%=!readCurrentArrayDesign%>"
    405399              recent="<%=recentArrayDesigns%>"
    406               defaultitem="<%=defaultArrayDesign%>"
     400              defaultitems="<%=defaultArrayDesigns%>"
    407401              newitem="true"
    408402              onselect="selectArrayDesignOnClick()"
     
    424418            denied="<%=!readCurrentPrintRobot%>"
    425419            recent="<%=recentPrintRobots%>"
    426             defaultitem="<%=defaultPrintRobot%>"
     420            defaultitems="<%=defaultPrintRobots%>"
    427421            newitem="<%=batch == null%>"
    428422            onselect="selectPrintRobotOnClick()"
     
    440434            denied="<%=!readCurrentProtocol%>"
    441435            recent="<%=recentProtocols%>"
    442             defaultitem="<%=defaultProtocol%>"
     436            defaultitems="<%=defaultProtocols%>"
    443437            newitem="<%=batch == null%>"
    444438            onselect="selectProtocolOnClick()"
  • trunk/www/lims/arraydesigns/edit_design.jsp

    r5650 r5687  
    7575  Platform currentPlatform = null;
    7676  PlatformVariant currentVariant = null;
    77   Platform defaultPlatform = null;
    78   PlatformVariant defaultVariant = null;
     77  List<Platform> defaultPlatforms = null;
     78  List<PlatformVariant> defaultVariants = null;
    7979 
    8080  int activeProjectId = sc.getActiveProjectId();
     
    8484    try
    8585    {
    86       defaultPlatform = (Platform)activeProject.findDefaultItem(dc, Item.PLATFORM);
     86      defaultPlatforms = (List<Platform>)activeProject.findDefaultItems(dc, Item.PLATFORM, true);
    8787    }
    8888    catch (PermissionDeniedException pdex)
     
    9090    try
    9191    {
    92       defaultVariant = (PlatformVariant)activeProject.findDefaultItem(dc, Item.PLATFORMVARIANT);
     92      defaultVariants = (List<PlatformVariant>)activeProject.findDefaultItems(dc, Item.PLATFORMVARIANT, true);
    9393    }
    9494    catch (PermissionDeniedException pdex)
     
    109109    catch (Throwable t)
    110110    {}
    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    }
    113119  }
    114120  else
  • trunk/www/views/derivedbioassays/edit_bioassay.jsp

    r5685 r5687  
    3030  import="net.sf.basedb.core.Hardware"
    3131  import="net.sf.basedb.core.Software"
     32  import="net.sf.basedb.core.Project"
    3233  import="net.sf.basedb.core.Item"
    3334  import="net.sf.basedb.core.ItemContext"
     
    4344  import="net.sf.basedb.clients.web.util.HTML"
    4445  import="net.sf.basedb.util.Values"
     46  import="net.sf.basedb.util.ListUtil"
    4547  import="net.sf.basedb.core.plugin.GuiContext"
    4648  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
     
    5052  import="java.util.Date"
    5153  import="java.util.List"
     54  import="java.util.Collections"
    5255%>
    5356<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
     
    6770 
    6871  boolean readCurrentSubtype = true;
    69   int currentSubtypeId = 0;
     72  ItemSubtype currentSubtype = null;
    7073
    7174  boolean readCurrentPhysicalBioAssay = true;
     
    8083  boolean readCurrentProtocol = true;
    8184  Protocol currentProtocol = null;
    82   Protocol defaultProtocol = null;
    8385 
    8486  boolean readCurrentHardware = true;
    8587  Hardware currentHardware = null;
    86   Hardware defaultHardware = null;
    8788 
    8889  boolean readCurrentSoftware = true;
    8990  Software currentSoftware = null;
    90   Software defaultSoftware = null;
    91 
    92   // Load recently used items
    93   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);
    9891
    9992  if (itemId == 0)
     
    10194    title = "New derived bioassay";
    10295    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();
    11098    int parentId = Values.getInt(request.getParameter("parent_id"));
    11199    if (parentId != 0)
    112100    {
    113101      currentParentBioAssay = DerivedBioAssay.getById(dc, parentId);
     102      if (currentSubtypeId == 0)
     103      {
     104        relatedToParent = ItemSubtype.getParentSubtypes(dc, currentParentBioAssay, Item.DERIVEDBIOASSAY);
     105      }
    114106      try
    115107      {
     
    133125      {
    134126        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    }
    138148  }
    139149  else
     
    146156    try
    147157    {
    148       ItemSubtype subtype = bioAssay.getItemSubtype();
    149       if (subtype != null) currentSubtypeId = subtype.getId();
     158      currentSubtype = bioAssay.getItemSubtype();
    150159    }
    151160    catch (PermissionDeniedException ex)
     
    202211    }
    203212  }
     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 
    204234  // Query to retrieve item types
    205235  final ItemQuery<ItemSubtype> subtypesQuery = Base.getSubtypesQuery(itemType);
     
    346376    }
    347377   
     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   
    348392    function selectProtocolOnClick()
    349393    {
    350394      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';
    352396      url += '&callback=setProtocolCallback&resetTemporary=1';
    353397      url += ItemSubtype.createRelatedFilter('bioAssay', 'PROTOCOL');
     
    444488    {
    445489      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';
    447491      url += '&callback=setHardwareCallback&resetTemporary=1';
    448492      url += ItemSubtype.createRelatedFilter('bioAssay', 'HARDWARE');
     
    469513    {
    470514      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';
    472516      url += '&callback=setSoftwareCallback&resetTemporary=1';
    473517      url += ItemSubtype.createRelatedFilter('bioAssay', 'SOFTWARE');
     
    647691        <td colspan="2">
    648692          <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            >
    650696          <%
    651697          if (!readCurrentSubtype)
     
    660706            <option value="0">-none-
    661707            <%
     708            int currentSubtypeId = currentSubtype == null ? 0 : currentSubtype.getId();
    662709            for (ItemSubtype subtype : subtypesQuery.list(dc))
    663710            {
     
    740787            denied="<%=!readCurrentProtocol%>"
    741788            recent="<%=recentProtocols%>"
    742             defaultitem="<%=defaultProtocol%>"
     789            defaultitems="<%=defaultProtocols%>"
    743790            newitem="<%=bioAssay == null%>"
    744791            onselect="selectProtocolOnClick()"
     
    757804            denied="<%=!readCurrentHardware%>"
    758805            recent="<%=recentHardware%>"
    759             defaultitem="<%=defaultHardware%>"
     806            defaultitems="<%=defaultHardware%>"
    760807            newitem="<%=bioAssay == null%>"
    761808            onselect="selectHardwareOnClick()"
     
    773820            denied="<%=!readCurrentSoftware%>"
    774821            recent="<%=recentSoftware%>"
    775             defaultitem="<%=defaultSoftware%>"
     822            defaultitems="<%=defaultSoftware%>"
    776823            newitem="<%=bioAssay == null%>"
    777824            onselect="selectSoftwareOnClick()"
  • trunk/www/views/derivedbioassays/index.jsp

    r5685 r5687  
    208208 
    209209      int subtypeId = Values.getInt(request.getParameter("subtype_id"), -1);
     210      ItemSubtype subtype = null;
    210211      if (subtypeId >= 0) // < 0 = denied or unchanged
    211212      {
    212         ItemSubtype subtype = subtypeId == 0 ? null : ItemSubtype.getById(dc, subtypeId);
     213        subtype = subtypeId == 0 ? null : ItemSubtype.getById(dc, subtypeId);
    213214        bas.setItemSubtype(subtype);
    214215        if (subtype != null) cc.setRecent(subtype, maxRecent);
     
    227228        Protocol pt = protocolId == 0 ? null : Protocol.getById(dc, protocolId);
    228229        bas.setProtocol(pt);
    229         if (pt != null) cc.setRecent(pt, maxRecent);
     230        if (pt != null) cc.setRecent(pt, subtype, maxRecent);
    230231      }
    231232     
     
    235236        Hardware hw = hardwareId == 0 ? null : Hardware.getById(dc, hardwareId);
    236237        bas.setHardware(hw);
    237         if (hw != null) cc.setRecent(hw, maxRecent);
     238        if (hw != null) cc.setRecent(hw, subtype, maxRecent);
    238239      }
    239240
     
    243244        Software sw = softwareId == 0 ? null : Software.getById(dc, softwareId);
    244245        bas.setSoftware(sw);
    245         if (sw != null) cc.setRecent(sw, maxRecent);
     246        if (sw != null) cc.setRecent(sw, subtype, maxRecent);
    246247      }
    247248     
  • trunk/www/views/physicalbioassays/edit_bioassay.jsp

    r5662 r5687  
    5353  import="net.sf.basedb.clients.web.util.HTML"
    5454  import="net.sf.basedb.util.Values"
     55  import="net.sf.basedb.util.ListUtil"
    5556  import="net.sf.basedb.util.formatter.Formatter"
    5657  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
     
    6566  import="java.util.HashSet"
    6667  import="java.util.Date"
     68  import="java.util.Collections"
    6769%>
    6870<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
     
    8385  BioMaterialEvent creationEvent = null;
    8486  Date eventDate = null;
    85   ItemQuery<Extract> extractsQuery = null;
     87  List<Extract> parentExtracts = null;
    8688 
    8789  boolean readCurrentSubtype = true;
    88   int currentSubtypeId = 0;
     90  ItemSubtype currentSubtype = null;
    8991  boolean readCurrentArraySlide = true;
    9092  ArraySlide currentArraySlide = null;
     
    9294  boolean readCurrentProtocol = true;
    9395  Protocol currentProtocol = null;
    94   Protocol defaultProtocol = null;
    9596 
    9697  boolean readCurrentHardware = true;
    9798  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
    127100  if (itemId == 0)
    128101  {
    129102    title = "Create physical bioassay";
    130103    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     }
    137104    if (cc.getPropertyFilter("creationEvent.protocol.name") != null)
    138105    {
     
    150117    eventDate = (Date)cc.getPropertyObject("creationEvent.eventDate");
    151118   
     119    int currentSubtypeId = Values.getInt(request.getParameter("subtype_id"));
     120    List<ItemSubtype> relatedToParent = Collections.emptyList();
     121    ItemQuery<Extract> extractsQuery = null;
    152122    if (Values.getBoolean(request.getParameter("useParents")))
    153123    {
     
    169139      extractsQuery.restrict(Restrictions.eq(Hql.property("id"),
    170140        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      }
    171166    }
    172167  }
     
    183178    try
    184179    {
    185       ItemSubtype subtype = pba.getItemSubtype();
    186       if (subtype != null) currentSubtypeId = subtype.getId();
     180      currentSubtype = pba.getItemSubtype();
    187181    }
    188182    catch (PermissionDeniedException ex)
     
    217211   
    218212    // Query to retrieve source extracts
    219     extractsQuery = (ItemQuery<Extract>)creationEvent.getSources();
     213    ItemQuery<Extract> extractsQuery = (ItemQuery<Extract>)creationEvent.getSources();
    220214    extractsQuery.include(Include.ALL);
    221215    extractsQuery.order(Orders.asc(Hql.property("name")));
     216    parentExtracts = extractsQuery.list(dc);
    222217   
    223218  }
     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 
    224235  // Query to retrieve item types
    225236  final ItemQuery<ItemSubtype> subtypesQuery = Base.getSubtypesQuery(itemType);
     
    319330      return protocolId;
    320331    }
    321 
     332   
    322333    function getParents()
    323334    {
     
    336347    }
    337348
     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   
    338360    function selectProtocolOnClick()
    339361    {
     
    541563        <%
    542564      }
    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)
    547568        {
    548569          if (pba == null)
     
    590611        <td colspan="2">
    591612          <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            >
    593616          <%
    594617          if (!readCurrentSubtype)
     
    600623          else
    601624          {
     625            int currentSubtypeId = currentSubtype == null ? 0 : currentSubtype.getId();
    602626            %>
    603627            <option value="0">-none-
     
    662686            denied="<%=!readCurrentProtocol%>"
    663687            recent="<%=recentProtocols%>"
    664             defaultitem="<%=defaultProtocol%>"
     688            defaultitems="<%=defaultProtocols%>"
    665689            newitem="<%=pba == null%>"
    666690            onselect="selectProtocolOnClick()"
     
    679703            denied="<%=!readCurrentHardware%>"
    680704            recent="<%=recentHardware%>"
    681             defaultitem="<%=defaultHardware%>"
     705            defaultitems="<%=defaultHardware%>"
    682706            newitem="<%=pba == null%>"
    683707            onselect="selectHardwareOnClick()"
  • trunk/www/views/physicalbioassays/index.jsp

    r5685 r5687  
    198198      pba.setDescription(Values.getStringOrNull(request.getParameter("description")));
    199199      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      }
    200209     
    201210      int arraySlideId = Values.getInt(request.getParameter("arrayslide_id"), -1);
     
    212221        Protocol pt = protocolId == 0 ? null : Protocol.getById(dc, protocolId);
    213222        creationEvent.setProtocol(pt);
    214         if (pt != null) cc.setRecent(pt, maxRecent);
     223        if (pt != null) cc.setRecent(pt, subtype, maxRecent);
    215224      }
    216225     
    217       int subtypeId = Values.getInt(request.getParameter("subtype_id"), -1);
    218       if (subtypeId >= 0) // < 0 = denied or unchanged
    219       {
    220         ItemSubtype subtype = subtypeId == 0 ? null : ItemSubtype.getById(dc, subtypeId);
    221         pba.setItemSubtype(subtype);
    222         if (subtype != null) cc.setRecent(subtype, maxRecent);
    223       }
    224 
    225226      //Hardware
    226227      int hardwareId = Values.getInt(request.getParameter("hardware_id"), -1);
     
    229230        Hardware hw = hardwareId == 0 ? null : Hardware.getById(dc, hardwareId);
    230231        creationEvent.setHardware(hw);
    231         if (hw != null) cc.setRecent(hw, maxRecent);
     232        if (hw != null) cc.setRecent(hw, subtype, maxRecent);
    232233      }
    233234     
  • trunk/www/views/rawbioassays/edit_rawbioassay.jsp

    r5685 r5687  
    8585  boolean deniedPlatform = false;
    8686  Platform currentPlatform = null;
    87   Platform defaultPlatform = null;
     87  List<Platform> defaultPlatforms = null;
    8888  PlatformVariant currentVariant = null;
    89   PlatformVariant defaultVariant = null;
     89  List<PlatformVariant> defaultVariants = null;
    9090 
    9191  boolean readCurrentBioAssay = true;
     
    9595  boolean readCurrentProtocol = true;
    9696  Protocol currentProtocol = null;
    97   Protocol defaultProtocol = null;
     97  List<Protocol> defaultProtocols = null;
    9898  boolean readCurrentSoftware = true;
    9999  Software currentSoftware = null;
    100   Software defaultSoftware = null;
     100  List<Software> defaultSoftware = null;
    101101  boolean readCurrentArrayDesign = true;
    102102  ArrayDesign currentArrayDesign = null;
    103   ArrayDesign defaultArrayDesign = null;
     103  List<ArrayDesign> defaultArrayDesigns = null;
    104104  RawDataType currentRawDataType = null;
    105105  RawDataType defaultRawDataType = null;
     
    119119    try
    120120    {
    121       defaultProtocol = (Protocol)activeProject.findDefaultItem(dc,
     121      defaultProtocols = (List<Protocol>)activeProject.findDefaultItems(dc,
    122122          ItemSubtype.getById(dc, SystemItems.getId(Protocol.FEATURE_EXTRACTION)), false);
    123     }
    124     catch (PermissionDeniedException pdex)
    125     {
    126       defaultProtocol = null;
    127     }
    128     try
    129     {
    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     try
    138     {
    139       defaultArrayDesign = (ArrayDesign)activeProject.findDefaultItem(dc, Item.ARRAYDESIGN);
    140     }
    141     catch (PermissionDeniedException pdex)
    142     {
    143       defaultArrayDesign = null;
    144     }
    145     try
    146     {
    147       defaultPlatform = (Platform)activeProject.findDefaultItem(dc, Item.PLATFORM);
    148123    }
    149124    catch (PermissionDeniedException pdex)
     
    151126    try
    152127    {
    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);
    154148    }
    155149    catch (PermissionDeniedException pdex)
     
    176170    catch (Throwable t)
    177171    {}
    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    }
    180180   
    181181    currentRawDataType = RawDataTypes.getRawDataType(cc.getPropertyValue("rawDataType"));
     
    772772            denied="<%=!readCurrentArrayDesign%>"
    773773            recent="<%=recentArrayDesigns%>"
    774             defaultitem="<%=defaultArrayDesign%>"
     774            defaultitems="<%=defaultArrayDesigns%>"
    775775            newitem="<%=rawBioAssay == null%>"
    776776            onselect="selectArrayDesignOnClick()"
     
    804804            denied="<%=!readCurrentProtocol%>"
    805805            recent="<%=recentProtocols%>"
    806             defaultitem="<%=defaultProtocol%>"
     806            defaultitems="<%=defaultProtocols%>"
    807807            newitem="<%=rawBioAssay == null%>"
    808808            onselect="selectProtocolOnClick()"
     
    821821            denied="<%=!readCurrentSoftware%>"
    822822            recent="<%=recentSoftware%>"
    823             defaultitem="<%=defaultSoftware%>"
     823            defaultitems="<%=defaultSoftware%>"
    824824            newitem="<%=rawBioAssay == null%>"
    825825            onselect="selectSoftwareOnClick()"
Note: See TracChangeset for help on using the changeset viewer.