Changeset 5643


Ignore:
Timestamp:
May 26, 2011, 1:19:32 PM (12 years ago)
Author:
Nicklas Nordborg
Message:

References #1597: Subtypes of items

Cleanup code and JSP pages. Added some utility functions to make it easier to load and use subtypes. Added subtype functionality to BioSource.

Location:
trunk
Files:
34 edited

Legend:

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

    r5623 r5643  
    3333import net.sf.basedb.core.FileSet;
    3434import net.sf.basedb.core.FileStoreEnabled;
     35import net.sf.basedb.core.ItemSubtype;
    3536import net.sf.basedb.core.Location;
    3637import net.sf.basedb.core.Path;
     
    10041005
    10051006  /**
     1007    Get a query that returns all subtypes for the given main item type.
     1008    @param itemType The main item type
     1009    @return An <code>ItemQuery</code> object
     1010    @since 3.0
     1011  */
     1012  public static ItemQuery<ItemSubtype> getSubtypesQuery(Item itemType)
     1013  {
     1014    ItemQuery<ItemSubtype> query = ItemSubtype.getQuery(itemType);
     1015    query.order(Orders.asc(Hql.property("name")));
     1016    query.setCacheResult(true);
     1017    return query;
     1018  }
     1019
     1020 
     1021  /**
    10061022    Get a query that returns all annotation types defined for a
    10071023    {@link AnnotatableProxy} item.
  • trunk/src/clients/web/net/sf/basedb/clients/web/servlet/Upload.java

    r5630 r5643  
    118118        compress = Values.getBoolean(upload.getParameter("compressed"));
    119119      }
    120       int fileTypeId = Values.getInt(upload.getParameter("filetype_id"));
     120      int subtypeId = Values.getInt(upload.getParameter("subtype_id"));
    121121      String description = Values.getStringOrNull(upload.getParameter("description"));
    122122      String characterSet = Values.getStringOrNull(upload.getParameter("characterSet"));
     
    187187          String browserMimeType = uploadedFile.getMimeType();
    188188          f.setMimeTypeAuto(serverMimeType != null ? serverMimeType : browserMimeType, null);
    189           if (fileTypeId >= 0) // < 0 = denied or unchanged
    190           {
    191             ItemSubtype ft = fileTypeId == 0 ? null : ItemSubtype.getById(dc, fileTypeId);
    192             f.setItemSubtype(ft);
    193             if (ft != null) cc.setRecent(ft, maxRecent);
     189          if (subtypeId >= 0) // < 0 = denied or unchanged
     190          {
     191            ItemSubtype subtype = subtypeId == 0 ? null : ItemSubtype.getById(dc, subtypeId);
     192            f.setItemSubtype(subtype);
     193            if (subtype != null) cc.setRecent(subtype, maxRecent);
    194194          }
    195195          f.setDescription(description);
  • trunk/src/clients/web/net/sf/basedb/clients/web/taglib/table/ColumnDef.java

    r5450 r5643  
    379379  /**
    380380    Options for enum.
    381   */
    382   private String jsEnum = null;
    383  
     381  */ 
    384382  private Enumeration<String, String> enumeration;
    385383 
     
    535533  }
    536534
    537   public void setEnum(String jsEnum)
    538   {
    539     this.jsEnum = jsEnum;
    540   }
    541   public String getEnum()
    542   {
    543     return jsEnum;
    544   }
    545  
    546535  public void setEnumeration(Enumeration<String, String> enumeration)
    547536  {
  • trunk/src/clients/web/net/sf/basedb/clients/web/taglib/table/Table.java

    r5474 r5643  
    423423    script.append(cd.isFilterable() ? ",true" : ",false");
    424424    script.append(cd.isExportable() ? ",true" : ",false");
    425     script.append(cd.getEnum() != null ? ","+cd.getEnum() : ",null");
    426425    script.append("));\n");
    427426  }
  • trunk/src/core/net/sf/basedb/core/BioMaterial.java

    r5535 r5643  
    2828
    2929/**
    30   This is the base class for for the four types of biomaterials:
    31   {@link BioSource}, {@link Sample}, {@link Extract}
    32   and {@link LabeledExtract}.
     30  This is the base class for for the three types of biomaterials:
     31  {@link BioSource}, {@link Sample} and {@link Extract}.
    3332
    3433  @author Nicklas
     
    3837public abstract class BioMaterial<D extends BioMaterialData>
    3938  extends AnnotatedItem<D>
     39  implements Subtypable
    4040{
    4141
     
    4343    Get a biomaterial item when you know the id. This method can return any
    4444    of the subclasses of {@link BioMaterial}. Eg. {@link BioSource},
    45     {@link Sample}, {@link Extract} or {@link LabeledExtract}.
     45    {@link Sample} or {@link Extract}.
    4646   
    4747    @param dc The <code>DbControl</code> which will be used for
     
    6363  }
    6464 
    65   BioMaterial(D bioMaterialData)
    66   {
    67     super(bioMaterialData);
    68   }
    69 
    7065  /**
    7166    The maximum length of the external id that can be stored in the database.
     
    7469  public static final int MAX_EXTERNAL_ID_LENGTH = BioMaterialData.MAX_EXTERNAL_ID_LENGTH;
    7570
     71  BioMaterial(D bioMaterialData)
     72  {
     73    super(bioMaterialData);
     74  }
    7675 
     76  /*
     77    From the Subtypable interface
     78    -----------------------------
     79  */
     80  @Override
     81  public ItemSubtype getItemSubtype()
     82  {
     83    return getDbControl().getItem(ItemSubtype.class, getData().getItemSubtype());
     84  }
     85  @Override
     86  public void setItemSubtype(ItemSubtype subtype)
     87  {
     88    checkPermission(Permission.WRITE);
     89    if (subtype != null)
     90    {
     91      subtype.setOnItem(this);
     92    }
     93    else
     94    {
     95      getData().setItemSubtype(null);
     96    }
     97  }
     98  // -------------------------------------------
     99
     100  /*
     101    From the BasicItem class
     102    ------------------------
     103   */
    77104  /**
    78105    On delete action: issue an update to decrease the size of all
     
    103130    }
    104131  }
     132  // ------------------------------------
     133 
    105134  /**
    106135    Get the external id of the biomaterial. This value can be used to link
  • trunk/src/core/net/sf/basedb/core/Extract.java

    r5642 r5643  
    179179  */
    180180  @Override
    181   @SubtypableRelatedItems({Item.PROTOCOL, Item.HARDWARE, Item.TAG})
     181  @SubtypableRelatedItems({Item.PROTOCOL, Item.HARDWARE, Item.TAG, Item.SAMPLE, Item.EXTRACT})
    182182  public ItemSubtype getItemSubtype()
    183183  {
  • trunk/src/core/net/sf/basedb/core/MeasuredBioMaterial.java

    r5631 r5643  
    5555public abstract class MeasuredBioMaterial<D extends MeasuredBioMaterialData>
    5656  extends BioMaterial<D>
    57   implements Registered, Subtypable
     57  implements Registered
    5858{
    5959
     
    180180  public ItemSubtype getItemSubtype()
    181181  {
    182     return getDbControl().getItem(ItemSubtype.class, getData().getItemSubtype());
    183   }
    184   @Override
    185   public void setItemSubtype(ItemSubtype subtype)
    186   {
    187     checkPermission(Permission.WRITE);
    188     if (subtype != null)
    189     {
    190       subtype.setOnItem(this);
    191     }
    192     else
    193     {
    194       getData().setItemSubtype(null);
    195     }
    196   }
    197  
     182    return super.getItemSubtype();
     183  }
    198184  // -------------------------------------------
    199185 
  • trunk/src/core/net/sf/basedb/core/Sample.java

    r5523 r5643  
    161161  }
    162162  // -------------------------------------------
     163  /*
     164    From the Subtypable interface
     165    -----------------------------
     166  */
     167  @Override
     168  @SubtypableRelatedItems({Item.PROTOCOL, Item.HARDWARE, Item.BIOSOURCE, Item.SAMPLE})
     169  public ItemSubtype getItemSubtype()
     170  {
     171    return super.getItemSubtype();
     172  }
     173  // -------------------------------------------
    163174
    164175  /*
  • trunk/src/core/net/sf/basedb/core/data/BioMaterialData.java

    r4889 r5643  
    3838public abstract class BioMaterialData
    3939  extends AnnotatedData
     40  implements SubtypableData
    4041{
    4142
    4243  public BioMaterialData()
    4344  {}
     45 
     46  /*
     47    From the SubtypableData interface
     48    ----------------------------------
     49  */
     50  private ItemSubtypeData subtype;
     51  @Override
     52  public ItemSubtypeData getItemSubtype()
     53  {
     54     return subtype;
     55  }
     56  @Override
     57  public void setItemSubtype(ItemSubtypeData subtype)
     58  {
     59     this.subtype = subtype;
     60  }
     61  // ------------------------------
     62
    4463 
    4564  /**
  • trunk/src/core/net/sf/basedb/core/data/MeasuredBioMaterialData.java

    r5630 r5643  
    3838public abstract class MeasuredBioMaterialData
    3939  extends BioMaterialData
    40   implements SubtypableData
    4140{
    4241
    4342  public MeasuredBioMaterialData()
    4443  {}
    45  
    46   /*
    47     From the SubtypableData interface
    48     ----------------------------------
    49   */
    50   private ItemSubtypeData subtype;
    51   @Override
    52   public ItemSubtypeData getItemSubtype()
    53   {
    54      return subtype;
    55   }
    56   @Override
    57   public void setItemSubtype(ItemSubtypeData subtype)
    58   {
    59      this.subtype = subtype;
    60   }
    61   // ------------------------------
    62 
    6344 
    6445  private BioMaterialData parent;
  • trunk/src/core/net/sf/basedb/util/Enumeration.java

    r5384 r5643  
    2525
    2626import java.io.Serializable;
     27import java.util.Collection;
    2728import java.util.Collections;
    2829import java.util.Comparator;
    2930import java.util.List;
    3031import java.util.LinkedList;
     32
     33import net.sf.basedb.core.Nameable;
    3134
    3235/**
     
    4144
    4245  private static final long serialVersionUID = 1222952912319368574L;
     46
     47  /**
     48    Create a new enumeration from a list of basic items.
     49    The key of the enumeration is the id of each item
     50    and the value is the name.
     51    @param items A collection with items
     52    @param noneOption If not null, this options will be inserted first in the
     53      enumeration with an empty string as the key
     54  */
     55  public static Enumeration<String, String> fromItems(Collection<? extends Nameable> items, String noneOption)
     56  {
     57    Enumeration<String, String> e = new Enumeration<String, String>();
     58    if (noneOption != null)
     59    {
     60      e.add("", noneOption);
     61    }
     62    for (Nameable item : items)
     63    {
     64      e.add(Integer.toString(item.getId()), ((Nameable)item).getName());
     65    }
     66    e.lock();
     67    return e;
     68  }
     69
     70 
    4371  private final List<Entry<K, V>> entries;
    4472  private boolean locked;
     
    90118  public void remove(int index)
    91119  {
    92     if (locked) throw new UnsupportedOperationException("add; The enumeration has been locked for modifications.");
     120    if (locked) throw new UnsupportedOperationException("remove; The enumeration has been locked for modifications.");
    93121    entries.remove(index);
    94122  }
  • trunk/www/WEB-INF/table.tld

    r5186 r5643  
    188188    </attribute>
    189189    <attribute>
    190       <name>enum</name>
    191       <required>false</required>
    192       <rtexprvalue>true</rtexprvalue>
    193     </attribute>
    194     <attribute>
    195190      <name>enumeration</name>
    196191      <required>false</required>
  • trunk/www/admin/hardware/edit_hardware.jsp

    r5630 r5643  
    3434  import="net.sf.basedb.core.ItemSubtype"
    3535  import="net.sf.basedb.core.ItemQuery"
     36  import="net.sf.basedb.core.Include"
    3637  import="net.sf.basedb.core.ItemResultList"
    3738  import="net.sf.basedb.core.PermissionDeniedException"
     
    6162  String title = null;
    6263  Hardware hardware = null;
    63   boolean readCurrentHardwareType = true;
    64   int currentHardwareTypeId = 0;
     64  boolean readCurrentSubtype = true;
     65  int currentSubtypeId = 0;
    6566
    6667  if (itemId == 0)
     
    6869    title = "Create hardware";
    6970    cc.removeObject("item");
    70     currentHardwareTypeId = Values.getInt(request.getParameter("hardwaretype_id"));
    71     if (currentHardwareTypeId == 0)
    72     {
    73       int recentHardwareTypeId = Values.getInt(cc.getRecent(Item.ITEMSUBTYPE.name(), 0));
    74       currentHardwareTypeId = Values.getInt(cc.getPropertyValue("itemSubtype"), recentHardwareTypeId);
     71    currentSubtypeId = Values.getInt(request.getParameter("subtype_id"));
     72    if (currentSubtypeId == 0)
     73    {
     74      int recentSubtypeId = Values.getInt(cc.getRecent(Item.ITEMSUBTYPE.name(), 0));
     75      currentSubtypeId = Values.getInt(cc.getPropertyValue("itemSubtype"), recentSubtypeId);
    7576    }
    7677  }
     
    7879  {
    7980    hardware = Hardware.getById(dc, itemId);
     81    hardware.checkPermission(Permission.WRITE);
    8082    cc.setObject("item", hardware);
    8183    title = "Edit hardware -- " + HTML.encodeTags(hardware.getName());
    8284    try
    8385    {
    84       ItemSubtype ht = hardware.getItemSubtype();
    85       if (ht != null) currentHardwareTypeId = ht.getId();
     86      ItemSubtype subtype = hardware.getItemSubtype();
     87      if (subtype != null) currentSubtypeId = subtype.getId();
    8688    }
    8789    catch (PermissionDeniedException ex)
    8890    {
    89       readCurrentHardwareType = false;
    90     }
    91   }
    92   if (hardware != null && !hardware.hasPermission(Permission.WRITE))
    93   {
    94     throw new PermissionDeniedException(Permission.WRITE, itemType.toString());
     91      readCurrentSubtype = false;
     92    }
    9593  }
    9694 
    9795  // Query to retrieve file types
    98   final ItemQuery<ItemSubtype> hardwareTypeQuery = ItemSubtype.getQuery(itemType);
    99   hardwareTypeQuery.order(Orders.asc(Hql.property("name")));
     96  final ItemQuery<ItemSubtype> subtypesQuery = Base.getSubtypesQuery(itemType);
     97  subtypesQuery.include(Include.ALL);
    10098 
    10199  final String clazz = "class=\"text\"";
     
    164162          size="40" maxlength="<%=Hardware.MAX_NAME_LENGTH%>"></td>
    165163      </tr>
    166       <tr>
    167         <td class="prompt">Version</td>
    168         <td><input <%=clazz%> type="text" name="version"
    169           value="<%=HTML.encodeTags(hardware == null ? cc.getPropertyValue("versionString") : hardware.getVersionString())%>"
    170           size="40" maxlength="<%=Hardware.MAX_VERSIONSTRING_LENGTH%>"></td>
    171       </tr>
    172164      <tr valign="top">
    173165        <td class="prompt">Type</td>
    174166        <td colspan="2">
    175           <select name="hardwaretype_id"
    176             <%=!readCurrentHardwareType ? "disabled readonly class=\"disabled\"" : "class=\"required\""%>>
     167          <select name="subtype_id"
     168            <%=!readCurrentSubtype ? "disabled readonly class=\"disabled selectionlist\"" : "class=\"selectionlist\""%>>
    177169          <%
    178           if (!readCurrentHardwareType)
     170          if (!readCurrentSubtype)
    179171          {
    180172            %>
     
    184176          else
    185177          {
    186             for (ItemSubtype hardwareType : hardwareTypeQuery.list(dc))
     178            %>
     179            <option value="0">-none-
     180            <%
     181            for (ItemSubtype subtype : subtypesQuery.list(dc))
    187182            {
    188               int id = hardwareType.getId();
     183              int id = subtype.getId();
     184              if (id != currentSubtypeId && subtype.isRemoved()) continue;
    189185              %>
    190               <option value="<%=id == currentHardwareTypeId && hardware != null ? -id : id%>"
    191                 <%=id == currentHardwareTypeId ? "selected" : ""%>
    192                 ><%=HTML.encodeTags(hardwareType.getName())%>
     186              <option value="<%=id == currentSubtypeId && hardware != null ? -id : id%>"
     187                <%=id == currentSubtypeId ? "selected" : ""%>
     188                title="<%=HTML.encodeTags(subtype.getDescription()) %>"
     189                ><%=HTML.encodeTags(subtype.getName())%>
    193190              <%
    194191            }
     
    198195        </td>
    199196      </tr>
    200  
     197      <tr>
     198        <td class="prompt">Version</td>
     199        <td><input <%=clazz%> type="text" name="version"
     200          value="<%=HTML.encodeTags(hardware == null ? cc.getPropertyValue("versionString") : hardware.getVersionString())%>"
     201          size="40" maxlength="<%=Hardware.MAX_VERSIONSTRING_LENGTH%>"></td>
     202      </tr>
    201203      <tr valign=top>
    202204        <td class="prompt">Description</td>
  • trunk/www/admin/hardware/index.jsp

    r5630 r5643  
    6060<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
    6161<%!
    62   private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,version,itemSubtype,description");
     62  private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,itemSubtype,version,description");
    6363  private static final Item itemType = Item.HARDWARE;
    6464%>
     
    153153      hardware.setVersionString(Values.getStringOrNull(request.getParameter("version")));
    154154      hardware.setDescription(Values.getStringOrNull(request.getParameter("description")));
    155       int hardwareTypeId = Values.getInt(request.getParameter("hardwaretype_id"), -1);
    156       if (hardwareTypeId >= 0) // < 0 = denied or unchanged
     155
     156      int subtypeId = Values.getInt(request.getParameter("subtype_id"), -1);
     157      if (subtypeId >= 0) // < 0 = denied or unchanged
    157158      {
    158         ItemSubtype hwt = hardwareTypeId == 0 ? null : ItemSubtype.getById(dc, hardwareTypeId);
    159         hardware.setItemSubtype(hwt);
    160         if (hwt != null) cc.setRecent(hwt, maxRecent);
     159        ItemSubtype subtype = subtypeId == 0 ? null : ItemSubtype.getById(dc, subtypeId);
     160        hardware.setItemSubtype(subtype);
     161        if (subtype != null) cc.setRecent(subtype, maxRecent);
    161162      }
    162163     
  • trunk/www/admin/hardware/list_hardware.jsp

    r5630 r5643  
    8282{
    8383  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
    84 
    85   final ItemQuery<ItemSubtype> typeQuery = ItemSubtype.getQuery(Item.HARDWARE);
    86   typeQuery.order(Orders.asc(Hql.property("name")));
    87   typeQuery.setCacheResult(true);
     84  final ItemQuery<ItemSubtype> subtypesQuery = Base.getSubtypesQuery(itemType);
    8885
    8986  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
     
    253250        exportable="true"
    254251      />
    255       <%
    256       Enumeration<String, String> hardwareTypes = new Enumeration<String, String>();
    257       for (ItemSubtype st : typeQuery.list(dc))
    258       {
    259         hardwareTypes.add(Integer.toString(st.getId()), HTML.encodeTags(st.getName()));
    260       }
    261       %>
    262252      <tbl:columndef
    263253        id="itemSubtype"
     
    266256        exportproperty="itemSubtype.name"
    267257        datatype="int"
    268         enumeration="<%=hardwareTypes%>"
     258        enumeration="<%=Enumeration.fromItems(subtypesQuery.list(dc), "-none-")%>"
    269259        title="Type"
    270260        sortable="true"
  • trunk/www/admin/hardware/view_hardware.jsp

    r5630 r5643  
    242242      </tr>
    243243      <tr>
     244        <td class="prompt">Type</td>
     245        <td><base:propertyvalue item="<%=hardware%>" property="itemSubtype" /></td>
     246      </tr>
     247      <tr>
    244248        <td class="prompt">Registered</td>
    245249        <td><%=dateFormatter.format(hardware.getEntryDate())%></td>
    246       </tr>
    247       <tr>
    248         <td class="prompt">Type</td>
    249         <td><base:propertyvalue item="<%=hardware%>" property="itemSubtype" /></td>
    250250      </tr>
    251251      <tr>
  • trunk/www/admin/itemsubtypes/edit_subtype.jsp

    r5631 r5643  
    160160      }
    161161      %>
     162      Main.showHide('section.none', related[mainType] == '')
    162163    }
    163164   
     
    248249      <tr>
    249250        <td class="prompt">Related subtypes</td>
    250         <td></td>
     251        <td><div id="section.none" style="display: none;"><i>- none -</i></div></td>
    251252      </tr>
    252253      <%
  • trunk/www/admin/protocols/edit_protocol.jsp

    r5631 r5643  
    6666  String title = null;
    6767  Protocol protocol = null;
    68   boolean readCurrentProtocolType = true;
    69   int currentProtocolTypeId = 0;
     68  boolean readCurrentSubtype = true;
     69  int currentSubtypeId = 0;
    7070  boolean readCurrentFile = true;
    7171  File currentFile = null;
     
    7979    title = "Create protocol";
    8080
    81     currentProtocolTypeId = Values.getInt(request.getParameter("protocoltype_id"));
    82     if (currentProtocolTypeId == 0)
    83     {
    84       int recentProtocolTypeId = Values.getInt(cc.getRecent(Item.ITEMSUBTYPE.name(), 0));
    85       currentProtocolTypeId = Values.getInt(cc.getPropertyValue("itemSubtype"), recentProtocolTypeId);
     81    currentSubtypeId = Values.getInt(request.getParameter("subtype_id"));
     82    if (currentSubtypeId == 0)
     83    {
     84      int recentSubtypeId = Values.getInt(cc.getRecent(Item.ITEMSUBTYPE.name(), 0));
     85      currentSubtypeId = Values.getInt(cc.getPropertyValue("itemSubtype"), recentSubtypeId);
    8686    }
    8787    cc.removeObject("item");
     
    9090  {
    9191    protocol = Protocol.getById(dc, itemId);
     92    protocol.checkPermission(Permission.WRITE);
     93   
    9294    parameterQuery = protocol.getParameters();
    9395    cc.setObject("item", protocol);
     
    9597    try
    9698    {
    97       ItemSubtype pt = protocol.getItemSubtype();
    98       if (pt != null) currentProtocolTypeId = pt.getId();
     99      ItemSubtype subtype = protocol.getItemSubtype();
     100      if (subtype != null) currentSubtypeId = subtype.getId();
    99101    }
    100102    catch (PermissionDeniedException ex)
    101103    {
    102       readCurrentProtocolType = false;
     104      readCurrentSubtype = false;
    103105    }
    104106    try
     
    110112      readCurrentFile = false;
    111113    }
    112   }
    113   if (protocol != null && !protocol.hasPermission(Permission.WRITE))
    114   {
    115     throw new PermissionDeniedException(Permission.WRITE, itemType.toString());
    116114  }
    117115 
    118116  // Query to retrieve protocol types
    119   final ItemQuery<ItemSubtype> protocolTypeQuery = ItemSubtype.getQuery(itemType);
    120   protocolTypeQuery.include(Include.ALL);
    121   protocolTypeQuery.order(Orders.asc(Hql.property("name")));
     117  final ItemQuery<ItemSubtype> subtypesQuery = Base.getSubtypesQuery(itemType);
     118  subtypesQuery.include(Include.ALL);
    122119 
    123120  final String clazz = "class=\"text\"";
     
    182179    {
    183180      var frm = document.forms['protocol'];
    184       var protocolType = Math.abs(frm.protocoltype_id[frm.protocoltype_id.selectedIndex].value);
    185       var relatedFileSubtype = ItemSubtype.getRelatedSubtype(protocolType, 'FILE', <%=SystemItems.getId(File.PROTOCOL)%>);
    186       var url = '../../filemanager/index.jsp?ID=<%=ID%>&cmd=SelectOne&title=Select+protocol&callback=setFileCallback';
     181      var subtype = Math.abs(frm.subtype_id[frm.subtype_id.selectedIndex].value);
     182      var relatedFileSubtype = ItemSubtype.getRelatedSubtype(subtype, 'FILE', <%=SystemItems.getId(File.PROTOCOL)%>);
     183      var url = '../../filemanager/index.jsp?ID=<%=ID%>&cmd=SelectOne&title=Select+protocol+file&callback=setFileCallback';
    187184      url += '&resetTemporary=1&tmpfilter:INT:itemSubtype=' + relatedFileSubtype.id;
    188185      if (frm.file_id.length > 1)
    189186      {
    190         var id = Math.abs(parseInt(frm.file_id[1].value));       
     187        var id = Math.abs(parseInt(frm.file_id[1].value));
    191188        url += '&item_id='+id;
    192189      }
     
    276273        <td class="prompt">Type</td>
    277274        <td colspan="2">
    278           <select name="protocoltype_id"
    279             <%=!readCurrentProtocolType ? "disabled readonly class=\"disabled\"" : "class=\"required\""%>>
     275          <select name="subtype_id"
     276            <%=!readCurrentSubtype ? "disabled readonly class=\"disabled selectionlist\"" : "class=\"selectionlist\""%>>
    280277          <%
    281           if (!readCurrentProtocolType)
     278          if (!readCurrentSubtype)
    282279          {
    283280            %>
     
    287284          else
    288285          {
    289             for (ItemSubtype protocolType : protocolTypeQuery.list(dc))
     286            %>
     287            <option value="0">-none-
     288            <%
     289            for (ItemSubtype subtype : subtypesQuery.list(dc))
    290290            {
    291               int id = protocolType.getId();
    292               if (id != currentProtocolTypeId && protocolType.isRemoved()) continue;
     291              int id = subtype.getId();
     292              if (id != currentSubtypeId && subtype.isRemoved()) continue;
    293293              %>
    294               <option value="<%=id == currentProtocolTypeId && protocol != null ? -id : id%>"
    295                 <%=id == currentProtocolTypeId ? "selected" : ""%>
    296                 ><%=HTML.encodeTags(protocolType.getName())%>
     294              <option value="<%=id == currentSubtypeId && protocol != null ? -id : id%>"
     295                <%=id == currentSubtypeId ? "selected" : ""%>
     296                title="<%=HTML.encodeTags(subtype.getDescription()) %>"
     297                ><%=HTML.encodeTags(subtype.getName())%>
    297298              <%
    298299            }
  • trunk/www/admin/protocols/index.jsp

    r5630 r5643  
    155155      protocol.setDescription(Values.getStringOrNull(request.getParameter("description")));
    156156      protocol.setExternalId(Values.getStringOrNull(request.getParameter("external_id")));
    157       int protocolTypeId = Values.getInt(request.getParameter("protocoltype_id"), -1);
    158       if (protocolTypeId >= 0) // < 0 = denied or unchanged
     157      int subtypeId = Values.getInt(request.getParameter("subtype_id"), -1);
     158      if (subtypeId >= 0) // < 0 = denied or unchanged
    159159      {
    160         ItemSubtype pt = protocolTypeId == 0 ? null : ItemSubtype.getById(dc, protocolTypeId);
    161         protocol.setItemSubtype(pt);
    162         if (pt != null) cc.setRecent(pt, maxRecent);
     160        ItemSubtype subtype = subtypeId == 0 ? null : ItemSubtype.getById(dc, subtypeId);
     161        protocol.setItemSubtype(subtype);
     162        if (subtype != null) cc.setRecent(subtype, maxRecent);
    163163      }
    164164      int fileId = Values.getInt(request.getParameter("file_id"), -1);
  • trunk/www/admin/protocols/list_protocol.jsp

    r5630 r5643  
    8686{
    8787  final ItemQuery<AnnotationType> annotationTypeQuery = Base.getAnnotationTypesQuery(itemType);
     88  final ItemQuery<ItemSubtype> subtypesQuery = Base.getSubtypesQuery(itemType);
    8889  annotationTypes = annotationTypeQuery.list(dc);
    8990 
    9091  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
    9192  final ItemQuery<Protocol> query = Base.getConfiguredQuery(dc, cc, true, Protocol.getQuery(), mode);
    92 
    93   final ItemQuery<ItemSubtype> typeQuery = ItemSubtype.getQuery(itemType);
    94   typeQuery.order(Orders.asc(Hql.property("name")));
    95   typeQuery.setCacheResult(true);
    9693
    9794  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
     
    251248        formatter="<%=dateFormatter%>"
    252249      />
    253       <%
    254       Enumeration<String, String> protocolTypes = new Enumeration<String, String>();
    255       for (ItemSubtype pt : typeQuery.list(dc))
    256       {
    257         protocolTypes.add(Integer.toString(pt.getId()), HTML.encodeTags(pt.getName()));
    258       }
    259       %>
    260250      <tbl:columndef
    261251        id="externalId"
     
    273263        exportproperty="itemSubtype.name"
    274264        datatype="int"
    275         enumeration="<%=protocolTypes%>"
     265        enumeration="<%=Enumeration.fromItems(subtypesQuery.list(dc), "-none-")%>"
    276266        title="Type"
    277267        sortable="true"
  • trunk/www/admin/software/edit_software.jsp

    r5630 r5643  
    3434  import="net.sf.basedb.core.ItemSubtype"
    3535  import="net.sf.basedb.core.ItemQuery"
     36  import="net.sf.basedb.core.Include"
    3637  import="net.sf.basedb.core.ItemResultList"
    3738  import="net.sf.basedb.core.PermissionDeniedException"
     
    6162  String title = null;
    6263  Software software = null;
    63   boolean readCurrentSoftwareType = true;
    64   int currentSoftwareTypeId = 0;
     64  boolean readCurrentSubtype = true;
     65  int currentSubtypeId = 0;
    6566
    6667  if (itemId == 0)
     
    6869    title = "Create software";
    6970    cc.removeObject("item");
    70     currentSoftwareTypeId = Values.getInt(request.getParameter("softwaretype_id"));
    71     if (currentSoftwareTypeId == 0)
    72     {
    73       int recentSoftwareTypeId = Values.getInt(cc.getRecent(Item.ITEMSUBTYPE.name(), 0));
    74       currentSoftwareTypeId = Values.getInt(cc.getPropertyValue("itemSubtype"), recentSoftwareTypeId);
     71    currentSubtypeId = Values.getInt(request.getParameter("subtype_id"));
     72    if (currentSubtypeId == 0)
     73    {
     74      int recentSubtypeId = Values.getInt(cc.getRecent(Item.ITEMSUBTYPE.name(), 0));
     75      currentSubtypeId = Values.getInt(cc.getPropertyValue("itemSubtype"), recentSubtypeId);
    7576    }
    7677  }
     
    7879  {
    7980    software = Software.getById(dc, itemId);
     81    software.checkPermission(Permission.WRITE);
    8082    cc.setObject("item", software);
    8183    title = "Edit software -- " + HTML.encodeTags(software.getName());
    8284    try
    8385    {
    84       ItemSubtype st = software.getItemSubtype();
    85       if (st != null) currentSoftwareTypeId = st.getId();
     86      ItemSubtype subtype = software.getItemSubtype();
     87      if (subtype != null) currentSubtypeId = subtype.getId();
    8688    }
    8789    catch (PermissionDeniedException ex)
    8890    {
    89       readCurrentSoftwareType = false;
    90     }
    91   }
    92   if (software != null && !software.hasPermission(Permission.WRITE))
    93   {
    94     throw new PermissionDeniedException(Permission.WRITE, itemType.toString());
     91      readCurrentSubtype = false;
     92    }
    9593  }
    9694 
    9795  // Query to retrieve file types
    98   final ItemQuery<ItemSubtype> softwareTypeQuery = ItemSubtype.getQuery(itemType);
    99   softwareTypeQuery.order(Orders.asc(Hql.property("name"))); 
     96  final ItemQuery<ItemSubtype> subtypesQuery = Base.getSubtypesQuery(itemType);
     97  subtypesQuery.include(Include.ALL);
     98
    10099  final String clazz = "class=\"text\"";
    101100  final String requiredClazz = "class=\"text required\"";
     
    163162          size="40" maxlength="<%=Software.MAX_NAME_LENGTH%>"></td>
    164163      </tr>
    165       <tr>
    166         <td class="prompt">Version</td>
    167         <td><input <%=clazz%> type="text" name="version"
    168           value="<%=HTML.encodeTags(software == null ? cc.getPropertyValue("versionString") : software.getVersionString())%>"
    169           size="40" maxlength="<%=Software.MAX_VERSIONSTRING_LENGTH%>"></td>
    170       </tr>
    171164      <tr valign="top">
    172165        <td class="prompt">Type</td>
    173166        <td colspan="2">
    174           <select name="softwaretype_id"
    175             <%=!readCurrentSoftwareType ? "disabled readonly class=\"disabled\"" : "class=\"required\""%>>
     167          <select name="subtype_id"
     168            <%=!readCurrentSubtype ? "disabled readonly class=\"disabled selectionlist\"" : "class=\"selectionlist\""%>>
    176169          <%
    177           if (!readCurrentSoftwareType)
     170          if (!readCurrentSubtype)
    178171          {
    179172            %>
     
    183176          else
    184177          {
    185             for (ItemSubtype softwareType : softwareTypeQuery.list(dc))
     178            %>
     179            <option value="0">-none-
     180            <%
     181            for (ItemSubtype subtype : subtypesQuery.list(dc))
    186182            {
    187               int id = softwareType.getId();
     183              int id = subtype.getId();
     184              if (id != currentSubtypeId && subtype.isRemoved()) continue;
    188185              %>
    189               <option value="<%=id == currentSoftwareTypeId && software != null ? -id : id%>"
    190                 <%=softwareType.getId() == currentSoftwareTypeId ? "selected" : ""%>
    191                 ><%=HTML.encodeTags(softwareType.getName())%>
     186              <option value="<%=id == currentSubtypeId && software != null ? -id : id%>"
     187                <%=id == currentSubtypeId ? "selected" : ""%>
     188                title="<%=HTML.encodeTags(subtype.getDescription()) %>"
     189                ><%=HTML.encodeTags(subtype.getName())%>
    192190              <%
    193191            }
     
    196194          </select>
    197195        </td>
     196      </tr>
     197      <tr>
     198        <td class="prompt">Version</td>
     199        <td><input <%=clazz%> type="text" name="version"
     200          value="<%=HTML.encodeTags(software == null ? cc.getPropertyValue("versionString") : software.getVersionString())%>"
     201          size="40" maxlength="<%=Software.MAX_VERSIONSTRING_LENGTH%>"></td>
    198202      </tr>
    199203 
  • trunk/www/admin/software/index.jsp

    r5630 r5643  
    6060<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
    6161<%!
    62   private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,version,itemSubtype,description");
     62  private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,itemSubtype,version,description");
    6363  private static final Item itemType = Item.SOFTWARE;
    6464%>
     
    153153      software.setVersionString(Values.getStringOrNull(request.getParameter("version")));
    154154      software.setDescription(Values.getStringOrNull(request.getParameter("description")));
    155       int softwareTypeId = Values.getInt(request.getParameter("softwaretype_id"), -1);
    156       if (softwareTypeId >= 0) // < 0 = denied or unchanged
     155
     156      int subtypeId = Values.getInt(request.getParameter("subtype_id"), -1);
     157      if (subtypeId >= 0) // < 0 = denied or unchanged
    157158      {
    158         ItemSubtype swt = softwareTypeId == 0 ? null : ItemSubtype.getById(dc, softwareTypeId);
    159         software.setItemSubtype(swt);
    160         if (swt != null) cc.setRecent(swt, maxRecent);
     159        ItemSubtype subtype = subtypeId == 0 ? null : ItemSubtype.getById(dc, subtypeId);
     160        software.setItemSubtype(subtype);
     161        if (subtype != null) cc.setRecent(subtype, maxRecent);
    161162      }
    162163     
  • trunk/www/admin/software/list_software.jsp

    r5630 r5643  
    8282{
    8383  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
    84 
    85   final ItemQuery<ItemSubtype> typeQuery = ItemSubtype.getQuery(itemType);
    86   typeQuery.order(Orders.asc(Hql.property("name")));
    87   typeQuery.setCacheResult(true);
     84  final ItemQuery<ItemSubtype> subtypesQuery = Base.getSubtypesQuery(itemType);
    8885
    8986  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
     
    253250        exportable="true"
    254251      />
    255       <%
    256       Enumeration<String, String> softwareTypes = new Enumeration<String, String>();
    257       for (ItemSubtype st : typeQuery.list(dc))
    258       {
    259         softwareTypes.add(Integer.toString(st.getId()), HTML.encodeTags(st.getName()));
    260       }
    261       %>
    262252      <tbl:columndef
    263253        id="itemSubtype"
     
    266256        exportproperty="itemSubtype.name"
    267257        datatype="int"
    268         enumeration="<%=softwareTypes%>"
     258        enumeration="<%=Enumeration.fromItems(subtypesQuery.list(dc), "-none-")%>"
    269259        title="Type"
    270260        sortable="true"
  • trunk/www/admin/software/view_software.jsp

    r5630 r5643  
    241241      </tr>
    242242      <tr>
     243        <td class="prompt">Type</td>
     244        <td><base:propertyvalue item="<%=software%>" property="itemSubtype" /></td>
     245      </tr>
     246      <tr>
    243247        <td class="prompt">Registered</td>
    244248        <td><%=dateFormatter.format(software.getEntryDate())%></td>
    245       </tr>
    246       <tr>
    247         <td class="prompt">Type</td>
    248         <td><base:propertyvalue item="<%=software%>" property="itemSubtype" /></td>
    249249      </tr>
    250250      <tr>
  • trunk/www/biomaterials/biosources/edit_biosource.jsp

    r5492 r5643  
    3333  import="net.sf.basedb.core.Permission"
    3434  import="net.sf.basedb.core.BioSource"
     35  import="net.sf.basedb.core.ItemSubtype"
     36  import="net.sf.basedb.core.ItemQuery"
     37  import="net.sf.basedb.core.Include"
    3538  import="net.sf.basedb.core.PermissionDeniedException"
    3639  import="net.sf.basedb.core.BaseException"
     
    6164  String title = null;
    6265  BioSource bioSource = null;
     66  boolean readCurrentSubtype = true;
     67  int currentSubtypeId = 0;
    6368
    6469  if (itemId == 0)
     
    6671    title = "Create biosource";
    6772    cc.removeObject("item");
     73   
     74    currentSubtypeId = Values.getInt(request.getParameter("subtype_id"));
     75    if (currentSubtypeId == 0)
     76    {
     77      int recentSubtypeId = Values.getInt(cc.getRecent(Item.ITEMSUBTYPE.name(), 0));
     78      currentSubtypeId = Values.getInt(cc.getPropertyValue("itemSubtype"), recentSubtypeId);
     79    }
    6880  }
    6981  else
    7082  {
    7183    bioSource = BioSource.getById(dc, itemId);
     84    bioSource.checkPermission(Permission.WRITE);
     85   
    7286    cc.setObject("item", bioSource);
    7387    title = "Edit biosource -- " + HTML.encodeTags(bioSource.getName());
     88
     89    try
     90    {
     91      ItemSubtype subtype = bioSource.getItemSubtype();
     92      if (subtype != null) currentSubtypeId = subtype.getId();
     93    }
     94    catch (PermissionDeniedException ex)
     95    {
     96      readCurrentSubtype = false;
     97    }
     98
    7499  }
    75   if (bioSource != null && !bioSource.hasPermission(Permission.WRITE))
    76   {
    77     throw new PermissionDeniedException(Permission.WRITE, itemType.toString());
    78   }
     100 
     101  // Query to retrieve item types
     102  final ItemQuery<ItemSubtype> subtypesQuery = Base.getSubtypesQuery(itemType);
     103  subtypesQuery.include(Include.ALL);
     104 
    79105  final String clazz = "class=\"text\"";
    80106  final String requiredClazz = "class=\"text required\"";
     
    158184          value="<%=HTML.encodeTags(bioSource == null ? Values.getString(cc.getPropertyValue("name"), "New biosource") : bioSource.getName())%>"
    159185          size="40" maxlength="<%=BioSource.MAX_NAME_LENGTH%>"></td>
     186      </tr>
     187      <tr valign="top">
     188        <td class="prompt">Type</td>
     189        <td colspan="2">
     190          <select name="subtype_id"
     191            <%=!readCurrentSubtype ? "disabled readonly class=\"disabled selectionlist\"" : "class=\"selectionlist\""%>>
     192          <%
     193          if (!readCurrentSubtype)
     194          {
     195            %>
     196            <option value="-1">- denied -
     197            <%
     198          }
     199          else
     200          {
     201            %>
     202            <option value="0">-none-
     203            <%
     204            for (ItemSubtype subtype : subtypesQuery.list(dc))
     205            {
     206              int id = subtype.getId();
     207              if (id != currentSubtypeId && subtype.isRemoved()) continue;
     208              %>
     209              <option value="<%=id == currentSubtypeId && bioSource != null ? -id : id%>"
     210                <%=id == currentSubtypeId ? "selected" : ""%>
     211                title="<%=HTML.encodeTags(subtype.getDescription()) %>"
     212                ><%=HTML.encodeTags(subtype.getName())%>
     213              <%
     214            }
     215          }
     216          %>
     217          </select>
     218        </td>
    160219      </tr>
    161220      <tr>
  • trunk/www/biomaterials/biosources/index.jsp

    r5590 r5643  
    3030  import="net.sf.basedb.core.Include"
    3131  import="net.sf.basedb.core.BioSource"
     32  import="net.sf.basedb.core.ItemSubtype"
    3233  import="net.sf.basedb.core.ItemQuery"
    3334  import="net.sf.basedb.core.ItemResultIterator"
     
    6768<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
    6869<%!
    69   private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,samples,description");
     70  private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,itemSubtype,samples,description");
    7071  private static final Item itemType = Item.BIOSOURCE;
    7172 
     
    153154    // Update the properties on an item (will close the popup)
    154155    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
     156    final int maxRecent = Base.getMaxRecent(sc);
    155157    dc = sc.newDbControl();
    156158    BioSource bioSource = (BioSource)cc.getObject("item");
     
    173175      bioSource.setDescription(Values.getStringOrNull(request.getParameter("description")));
    174176      bioSource.setExternalId(Values.getStringOrNull(request.getParameter("external_id")));
     177     
     178      int subtypeId = Values.getInt(request.getParameter("subtype_id"), -1);
     179      if (subtypeId >= 0) // < 0 = denied or unchanged
     180      {
     181        ItemSubtype subtype = subtypeId == 0 ? null : ItemSubtype.getById(dc, subtypeId);
     182        bioSource.setItemSubtype(subtype);
     183        if (subtype != null) cc.setRecent(subtype, maxRecent);
     184      }
    175185     
    176186      // Annotations tab
  • trunk/www/biomaterials/biosources/list_biosources.jsp

    r5426 r5643  
    3131  import="net.sf.basedb.core.Sample"
    3232  import="net.sf.basedb.core.AnnotationType"
     33  import="net.sf.basedb.core.ItemSubtype"
    3334  import="net.sf.basedb.core.AnnotationSet"
    3435  import="net.sf.basedb.core.Annotation"
     
    8990{
    9091  final ItemQuery<AnnotationType> annotationTypeQuery = Base.getAnnotationTypesQuery(itemType);
     92  final ItemQuery<ItemSubtype> subtypesQuery = Base.getSubtypesQuery(itemType);
     93
    9194  final ItemQuery<Sample> sampleQuery = Sample.getQuery();
    9295  sampleQuery.include(cc.getInclude());
     
    243246        exportable="true"
    244247        show="always"
     248      />
     249      <tbl:columndef
     250        id="itemSubtype"
     251        property="itemSubtype"
     252        sortproperty="itemSubtype.name"
     253        exportproperty="itemSubtype.name"
     254        datatype="int"
     255        enumeration="<%=Enumeration.fromItems(subtypesQuery.list(dc), "-none-")%>"
     256        title="Type"
     257        sortable="true"
     258        filterable="true"
     259        exportable="true"
    245260      />
    246261      <tbl:columndef
     
    524539                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
    525540                <tbl:cell column="id"><%=item.getId()%></tbl:cell>
     541                <tbl:cell column="itemSubtype"><base:propertyvalue
     542                    item="<%=item%>"
     543                    property="itemSubtype"
     544                    enableEditLink="<%=mode.hasEditLink()%>"
     545                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
     546                  /></tbl:cell>
    526547                <tbl:cell column="externalId"><%=HTML.encodeTags(item.getExternalId())%></tbl:cell>
    527548                <tbl:cell column="samples">
  • trunk/www/biomaterials/biosources/view_biosource.jsp

    r5496 r5643  
    276276        <td class="prompt">Name</td>
    277277        <td><%=HTML.encodeTags(bioSource.getName())%></td>
     278      </tr>
     279      <tr>
     280        <td class="prompt">Type</td>
     281        <td><base:propertyvalue item="<%=bioSource%>" property="itemSubtype" /></td>
    278282      </tr>
    279283      <tr>
  • trunk/www/filemanager/files/edit_file.jsp

    r5630 r5643  
    3939  import="net.sf.basedb.core.Location"
    4040  import="net.sf.basedb.core.ItemQuery"
     41  import="net.sf.basedb.core.Include"
    4142  import="net.sf.basedb.core.ItemResultList"
    4243  import="net.sf.basedb.core.PermissionDeniedException"
     
    7273  File file = null;
    7374  Directory directory = null;
    74   boolean readCurrentFileType = true;
    75   int currentFileTypeId = 0;
     75  boolean readCurrentSubtype = true;
     76  int currentSubtypeId = 0;
    7677  boolean readCurrentFileServer = true;
    7778  FileServer currentFileServer = null;
     
    8182  {
    8283    title = "Create file";
    83     currentFileTypeId = Values.getInt(cc.getPropertyValue("itemSubtype"), 0);
    84     if (currentFileTypeId == 0)
    85     {
    86       currentFileTypeId = Values.getInt(cc.getRecent(Item.ITEMSUBTYPE.name(), 0), 0);
     84    currentSubtypeId = Values.getInt(request.getParameter("subtype_id"));
     85    if (currentSubtypeId == 0)
     86    {
     87      int recentSubtypeId = Values.getInt(cc.getRecent(Item.ITEMSUBTYPE.name(), 0));
     88      currentSubtypeId = Values.getInt(cc.getPropertyValue("itemSubtype"), recentSubtypeId);
    8789    }
    8890    if (cc.getPropertyFilter("fileServer.name") != null)
     
    9799  {
    98100    file = File.getById(dc, itemId);
     101    file.checkPermission(Permission.WRITE);
     102   
    99103    directory = file.getDirectory();
    100104    cc.setObject("item", file);
     
    102106    try
    103107    {
    104       ItemSubtype ft = file.getItemSubtype();
    105       if (ft != null) currentFileTypeId = ft.getId();
     108      ItemSubtype subtype = file.getItemSubtype();
     109      if (subtype != null) currentSubtypeId = subtype.getId();
    106110    }
    107111    catch (PermissionDeniedException ex)
    108112    {
    109       readCurrentFileType = false;
     113      readCurrentSubtype = false;
    110114    }
    111115    try
     
    117121      readCurrentFileServer = false;
    118122    }
    119   }
    120   if (file != null && !file.hasPermission(Permission.WRITE))
    121   {
    122     throw new PermissionDeniedException(Permission.WRITE, itemType.toString());
    123123  }
    124124 
    125125  // Query to retrieve file types
    126   final ItemQuery<ItemSubtype> fileTypeQuery = ItemSubtype.getQuery(itemType);
    127   fileTypeQuery.order(Orders.asc(Hql.property("name")));
    128   fileTypeQuery.setCacheResult(true);
     126  final ItemQuery<ItemSubtype> subtypesQuery = Base.getSubtypesQuery(itemType);
     127  subtypesQuery.include(Include.ALL);
    129128 
    130129  final String clazz = "class=\"text\"";
     
    292291        <td class="prompt">Type</td>
    293292        <td colspan="2">
    294           <select name="filetype_id" <%=!readCurrentFileType ? "disabled readonly class=\"disabled\"" : ""%>>
     293          <select name="subtype_id"
     294            <%=!readCurrentSubtype ? "disabled readonly class=\"disabled selectionlist\"" : "class=\"selectionlist\""%>>
    295295          <%
    296           if (!readCurrentFileType)
     296          if (!readCurrentSubtype)
    297297          {
    298298            %>
     
    303303          {
    304304            %>
    305             <option value="0">- none -
     305            <option value="0">-none-
    306306            <%
    307             ItemResultList<ItemSubtype> fileTypes = fileTypeQuery.list(dc);
    308             for (ItemSubtype fileType : fileTypes)
     307            for (ItemSubtype subtype : subtypesQuery.list(dc))
    309308            {
    310               int id = fileType.getId();
     309              int id = subtype.getId();
     310              if (id != currentSubtypeId && subtype.isRemoved()) continue;
    311311              %>
    312               <option
    313                 value="<%=file != null && id == currentFileTypeId ? -id : id%>"
    314                 <%=id == currentFileTypeId ? "selected" : ""%>
    315                 ><%=HTML.encodeTags(fileType.getName())%>
     312              <option value="<%=id == currentSubtypeId && file != null ? -id : id%>"
     313                <%=id == currentSubtypeId ? "selected" : ""%>
     314                title="<%=HTML.encodeTags(subtype.getDescription()) %>"
     315                ><%=HTML.encodeTags(subtype.getName())%>
    316316              <%
    317317            }
  • trunk/www/filemanager/files/index.jsp

    r5630 r5643  
    197197      file.setCharacterSet(Values.getStringOrNull(request.getParameter("characterSet")));
    198198      file.setWriteProtected(Values.getBoolean(request.getParameter("write_protected"), false));
    199       int fileTypeId = Values.getInt(request.getParameter("filetype_id"), -1);
    200       if (fileTypeId >= 0) // < 0 = denied or unchanged
    201       {
    202         ItemSubtype ft = fileTypeId == 0 ? null : ItemSubtype.getById(dc, fileTypeId);
    203         file.setItemSubtype(ft);
    204         if (ft != null) cc.setRecent(ft, maxRecent);
    205       }
    206199      file.setDescription(Values.getStringOrNull(request.getParameter("description")));
     200     
     201      int subtypeId = Values.getInt(request.getParameter("subtype_id"), -1);
     202      if (subtypeId >= 0) // < 0 = denied or unchanged
     203      {
     204        ItemSubtype subtype = subtypeId == 0 ? null : ItemSubtype.getById(dc, subtypeId);
     205        file.setItemSubtype(subtype);
     206        if (subtype != null) cc.setRecent(subtype, maxRecent);
     207      }
     208
    207209      if (file.getLocation() == Location.EXTERNAL)
    208210      {
  • trunk/www/filemanager/files/list_files.jsp

    r5630 r5643  
    106106
    107107  // Get all file types
    108   final ItemQuery<ItemSubtype> typeQuery = ItemSubtype.getQuery(itemType);
    109   typeQuery.order(Orders.asc(Hql.property("name")));
    110   typeQuery.setCacheResult(true);
     108  final ItemQuery<ItemSubtype> subtypesQuery = Base.getSubtypesQuery(itemType);
    111109
    112110  // Create directory query
     
    584582        exportable="true"
    585583      />
    586       <%
    587       Enumeration<String, String> fileTypes = new Enumeration<String, String>();
    588       fileTypes.add("", "- none -");
    589       for (ItemSubtype ft : typeQuery.list(dc))
    590       {
    591         fileTypes.add(Integer.toString(ft.getId()), ft.getName());
    592       }
    593       %>
    594584      <tbl:columndef
    595585        id="itemSubtype"
     
    598588        exportproperty="itemSubtype.name"
    599589        datatype="int"
    600         enumeration="<%=fileTypes%>"
     590        enumeration="<%=Enumeration.fromItems(subtypesQuery.list(dc), "-none-")%>"
    601591        title="Type"
    602592        sortable="true"
  • trunk/www/filemanager/upload/select.jsp

    r5630 r5643  
    7575  File file = null;
    7676  Directory directory = null;
    77   boolean readCurrentFileType = true;
    78   int currentFileTypeId = 0;
     77  boolean readCurrentSubtype = true;
     78  int currentSubtypeId = 0;
    7979  Boolean compress = Application.autoCompressionEnabled() ? null : false; // null == auto
    8080
     
    8282  {
    8383    title = "Upload new file";
    84     currentFileTypeId = Values.getInt(cc.getPropertyValue("itemSubtype"), 0);
    85     if (currentFileTypeId == 0)
    86     {
    87       currentFileTypeId = Values.getInt(cc.getRecent(Item.ITEMSUBTYPE.name(), 0), 0);
     84    currentSubtypeId = Values.getInt(cc.getPropertyValue("itemSubtype"), 0);
     85    if (currentSubtypeId == 0)
     86    {
     87      currentSubtypeId = Values.getInt(cc.getRecent(Item.ITEMSUBTYPE.name(), 0), 0);
    8888    }
    8989    directory = Directory.getById(dc, Values.getInt(request.getParameter("directory_id"), SystemItems.getId(Directory.ROOT)));
     
    9494  {
    9595    file = File.getById(dc, itemId);
     96    file.checkPermission(Permission.WRITE);
     97   
    9698    directory = file.getDirectory();
    9799    cc.setObject("item", file);
     
    99101    try
    100102    {
    101       ItemSubtype ft = file.getItemSubtype();
    102       if (ft != null) currentFileTypeId = ft.getId();
     103      ItemSubtype subtype = file.getItemSubtype();
     104      if (subtype != null) currentSubtypeId = subtype.getId();
    103105    }
    104106    catch (PermissionDeniedException ex)
    105107    {
    106       readCurrentFileType = false;
    107     }
    108   }
    109   if (file != null && !file.hasPermission(Permission.WRITE))
    110   {
    111     throw new PermissionDeniedException(Permission.WRITE, itemType.toString());
     108      readCurrentSubtype = false;
     109    }
    112110  }
    113111 
     
    128126 
    129127  // Query to retrieve file types
    130   final ItemQuery<ItemSubtype> fileTypeQuery = ItemSubtype.getQuery(itemType);
    131   fileTypeQuery.order(Orders.asc(Hql.property("name")));
    132   fileTypeQuery.setCacheResult(true);
     128  final ItemQuery<ItemSubtype> subtypesQuery = Base.getSubtypesQuery(itemType);
     129  subtypesQuery.include(Include.ALL);
    133130 
    134131  // Query to retreive FileUnpacker plugins
     
    183180        }
    184181        frm.characterSet.value = frm.temp_charset[frm.temp_charset.selectedIndex].value;
    185         frm.filetype_id.value = frm.temp_filetype_id[frm.temp_filetype_id.selectedIndex].value;
     182        frm.subtype_id.value = frm.temp_subtype_id[frm.temp_subtype_id.selectedIndex].value;
    186183        frm.description.value = frm.temp_description.value;
    187184        frm.submit();
     
    378375    <input type="hidden" name="zip_overwrite" value="0">
    379376    <input type="hidden" name="zip_keep" value="1">
    380     <input type="hidden" name="filetype_id" value="">
     377    <input type="hidden" name="subtype_id" value="">
    381378    <input type="hidden" name="description" value="">
    382379    <input type="hidden" name="characterSet" value="">
     
    450447        <td class="prompt">Type</td>
    451448        <td colspan="2">
    452           <select name="temp_filetype_id" <%=!readCurrentFileType ? "disabled readonly class=\"disabled\"" : ""%>>
     449          <select name="temp_subtype_id"
     450            <%=!readCurrentSubtype ? "disabled readonly class=\"disabled selectionlist\"" : "class=\"selectionlist\""%>>
    453451          <%
    454           if (!readCurrentFileType)
     452          if (!readCurrentSubtype)
    455453          {
    456454            %>
     
    463461            <option value="0">- none -
    464462            <%
    465             ItemResultList<ItemSubtype> fileTypes = fileTypeQuery.list(dc);
    466             for (ItemSubtype fileType : fileTypes)
     463            for (ItemSubtype subtype : subtypesQuery.list(dc))
    467464            {
    468               int id = fileType.getId();
    469               boolean current = id == currentFileTypeId;
     465              int id = subtype.getId();
     466              boolean current = id == currentSubtypeId;
    470467              %>
    471468              <option
    472469                value="<%=current && file != null ? -id : id%>"
    473470                <%=current ? "selected" : ""%>
    474                 ><%=HTML.encodeTags(fileType.getName())%>
     471                title="<%=HTML.encodeTags(subtype.getDescription())%>"
     472                ><%=HTML.encodeTags(subtype.getName())%>
    475473              <%
    476474            }
  • trunk/www/include/scripts/table.js

    r5111 r5643  
    411411  }
    412412 
    413   /**
    414     Initialise the columns list of the quick filter
    415     @param tableId The ID attribute of the table tag
    416     @param property The filter property value of the currently selected column
    417     @param value The current filter value
    418   */
    419   this.initQuickFilter = function(tableId, property, value)
    420   {
    421     var frm = document.forms[tableId];
    422     var quickcolumn = frm.quickcolumn;
    423     var selectedIndex = 0;
    424     frm.quickvalue.value = value;
    425     for (var i = 0; i < this.columns.length; i++)
    426     {
    427       var col = this.columns[i];
    428       if (col.dataType && col.visible)
    429       {
    430         selectedIndex = col.filterProperty == property ? quickcolumn.length : selectedIndex;
    431         quickcolumn[quickcolumn.length] = new Option(col.title, col.filterProperty, false, false);
    432       }
    433     }
    434     quickcolumn.selectedIndex = selectedIndex;
    435     if (!this.columns['prop'+property] && quickcolumn.length > 0) property = quickcolumn[0].value;
    436     this.quickColumnOnChange(tableId, property, value);
    437   }
    438  
    439   var oldType;
    440   // Update the displayed filter depending on the dataType of the selected column
    441   this.quickColumnOnChange = function(tableId, property, value)
    442   {
    443     var column = this.columns['prop'+property];
    444     var dataType = column.dataType;
    445     var frm = document.forms[tableId];
    446     frm.quickcolumn_type.value = dataType;
    447     frm.quickcolumn_collection.value = column.isCollection ? 1 : 0;
    448     if (oldType) Main.hide(oldType);
    449     if (column.enumeration)
    450     {
    451       frm.quickvalue_enum.length = 0;
    452       frm.quickvalue_enum[frm.quickvalue_enum.length] = new Option();
    453       for (var i = 0; i < column.enumeration.length; i++) // >
    454       {
    455         frm.quickvalue_enum[frm.quickvalue_enum.length] = new Option(column.enumeration[i].text, column.enumeration[i].value);
    456       }
    457       if (value != undefined) Forms.selectListOption(frm.quickvalue_enum, value);
    458       oldType = 'enum';
    459     }
    460     else
    461     {
    462       if (dataType == 'string')
    463       {
    464         oldType = 'string';
    465         if (value != undefined) frm.quickvalue_string.value = value;
    466       }
    467       else if (dataType == 'int')
    468       {
    469         oldType = 'int';
    470         if (value != undefined) frm.quickvalue_int.value = value;
    471       }
    472       else if (dataType == 'long')
    473       {
    474         oldType = 'long';
    475         if (value != undefined) frm.quickvalue_long.value = value;
    476       }
    477       else if (dataType == 'float')
    478       {
    479         oldType = 'float';
    480         if (value != undefined) frm.quickvalue_float.value = value;
    481       }
    482       else if (dataType == 'double')
    483       {
    484         oldType = 'double';
    485         if (value != undefined) frm.quickvalue_double.value = value;
    486       }
    487       else if (dataType == 'date')
    488       {
    489         oldType = 'date';
    490         if (value != undefined) frm.quickvalue_date.value = value;
    491       }
    492       else if (dataType == 'boolean')
    493       {
    494         oldType = 'boolean';
    495         Forms.checkRadio(frm.quickvalue_boolean, value);
    496       }
    497     }
    498     Main.showInline(oldType);
    499   }
    500  
    501   this.setQuickValue = function(frm, value)
    502   {
    503     frm.quickvalue.value = value;
    504     frm.submit();
    505   }
    506413 
    507414  this.itemOnClick = function(tableId, evt, itemId, mode, viewFunction, editFunction, returnFunction)
     
    545452}
    546453
    547 function Column(id, title, property, sortProperty, filterProperty, exportProperty, dataType, isCollection, isAnnotation, visible, alwaysShow, alwaysHide, sortable, filterable, exportable, enumeration)
     454function Column(id, title, property, sortProperty, filterProperty, exportProperty, dataType, isCollection, isAnnotation, visible, alwaysShow, alwaysHide, sortable, filterable, exportable)
    548455{
    549456  this.id = id;
     
    562469  this.filterable = filterable;
    563470  this.exportable = exportable;
    564   this.enumeration = enumeration;
    565471}
    566472
  • trunk/www/include/styles/main.css

    r5599 r5643  
    203203}
    204204
    205 .selectionlist select {
     205.selectionlist select, select.selectionlist {
    206206  width: 20em;
    207207}
Note: See TracChangeset for help on using the changeset viewer.