Changeset 2941


Ignore:
Timestamp:
Nov 22, 2006, 12:11:18 PM (16 years ago)
Author:
Martin Svensson
Message:

References #334. All default values can now be set when creating/editing a project.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/Install.java

    r2933 r2941  
    102102    method.
    103103  */
    104   public static final int NEW_SCHEMA_VERSION = 26;
     104  public static final int NEW_SCHEMA_VERSION = 27;
    105105
    106106  public static synchronized void createTables(boolean update, final ProgressReporter progress)
  • trunk/src/core/net/sf/basedb/core/Project.java

    r2939 r2941  
    9191  */
    9292  private static final QueryRuntimeFilter RUNTIME_FILTER = new QueryRuntimeFilterImpl();
    93 
     93 
    9494  /**
    9595    Create a new <code>Project</code> item.
     
    501501    return defaultItem;
    502502  }
     503 
     504  /**
     505    Gets the default raw data type for this project.
     506    If no default value has been set for raw data type this will return Null.
     507   
     508      @return A {@link net.sf.basedb.core.RawDataType} object
     509  */
     510  public RawDataType getDefaultRawDataType()
     511  {
     512    RawDataType rdt = null;
     513    String id = getData().getProjectDefaults().get("raw_data_type");
     514    rdt = RawDataTypes.getRawDataType(id);   
     515    return rdt;
     516  }
     517 
     518  /**
     519      Sets a raw data type to be used as default for a project.
     520      The default value will be reset if <code>rawDataType</code> is Null
     521     
     522      @param rawDataType the {@link net.sf.basedb.core.RawDataType} to use as default.
     523  */
     524  public void setDefaultRawDataType(RawDataType rawDataType)
     525  {
     526    checkPermission(Permission.WRITE);
     527    if (rawDataType == null)
     528    {
     529      getData().getProjectDefaults().remove("raw_data_type");
     530    }
     531    else
     532    {   
     533      getData().getProjectDefaults().put("raw_data_type", rawDataType.getId());
     534    }
     535  }
    503536 
    504537  /**
     
    585618    FEATURE_EXTRACTION_PROTOCOL("default_feature_extraction_protocol", "Feat. extraction protocol", Item.PROTOCOL, ProtocolType.FEATURE_EXTRACTION),
    586619    POOLING_PROTOCOL("default_pooling_protocol", "Pooling protocol", Item.PROTOCOL, ProtocolType.POOLING),
    587     PRINTING_PROTOCOL("default_printing_protocol", "Printing protocol", Item.PROTOCOL, ProtocolType.PRINTING);
     620    PRINTING_PROTOCOL("default_printing_protocol", "Printing protocol", Item.PROTOCOL, ProtocolType.PRINTING),
     621    RAW_DATA_TYPE("default_raw_data_type", "Raw data type", null, null);
    588622   
    589623    private String name;
  • trunk/src/core/net/sf/basedb/core/Update.java

    r2933 r2941  
    316316      <ul>
    317317      <li>Added {@link net.sf.basedb.core.data.AnnotationTypeData#getExternalId()}.
     318      </ul>
     319    </td>
     320  </tr>
     321 
     322  <tr>
     323    <td>27</td>
     324    <td>
     325      <ul>
     326      <li>Added {@link net.sf.basedb.core.data.ProjectData#getProjectDefaults()}.
    318327      </ul>
    319328    </td>
     
    458467        schemaVersion = setSchemaVersionInTransaction(session, 26);
    459468      }
    460 
    461       /*
     469     
    462470      if (schemaVersion < 27)
    463471      {
    464472        if (progress != null) progress.display((int)(26*progress_factor), "--Updating schema version: " + schemaVersion + " -> 27...");
    465473        schemaVersion = setSchemaVersionInTransaction(session, 27);
     474      }
     475     
     476      /*
     477      if (schemaVersion < 28)
     478      {
     479        if (progress != null) progress.display((int)(27*progress_factor), "--Updating schema version: " + schemaVersion + " -> 28...");
     480        schemaVersion = setSchemaVersionInTransaction(session, 28);
    466481        - or -
    467         schemaVersion = updateToSchemaVersion27(session);
     482        schemaVersion = updateToSchemaVersion28(session);
    468483      }
    469484      ... etc...
  • trunk/src/core/net/sf/basedb/core/data/ProjectData.java

    r2304 r2941  
    138138    this.projectKeys = projectKeys;
    139139  }
     140 
     141  private Map<String, String> projectDefaults;
     142  /**
     143      Gets the default values
     144      @hibernate.map table="`ProjectDefaults`" lazy="true"
     145      @hibernate.collection-key column="`project_id`"
     146      @hibernate.collection-index column="`name`" type="string" length="255" not-null="true"
     147      @hibernate.collection-element column="`value`" type="string" length="255" not-null="true"
     148  */
     149  public Map<String, String> getProjectDefaults()
     150  {
     151    if (projectDefaults == null)projectDefaults = new HashMap<String,String>();
     152    return projectDefaults;
     153  }
     154  void setProjectDefaults(Map<String, String> projectDefaults)
     155  {
     156    this.projectDefaults = projectDefaults;
     157  }
    140158}
  • trunk/www/my_base/projects/edit_project.jsp

    r2939 r2941  
    4343  import="net.sf.basedb.core.ItemResultList"
    4444  import="net.sf.basedb.core.PermissionDeniedException"
     45  import="net.sf.basedb.core.RawDataType"
     46  import="net.sf.basedb.core.RawDataTypes"
    4547  import="net.sf.basedb.core.Software"
    4648  import="net.sf.basedb.core.BaseException"
     
    181183      for (Project.Default d : Project.Default.values())
    182184      {
    183         BasicItem defaultValue = null;
    184         int valueId = 0;
     185        %>
     186        var values = new Array();
     187        <%
    185188        String icon = "";
    186189        if (project != null)
    187190        {
    188           defaultValue = project.getDefaultItem(dc, d);
    189           if (defaultValue != null)
     191          if (d.getItemType() != null)
    190192          {
    191             valueId = defaultValue.getId();
    192             icon = "notrequired_values.gif";
     193            BasicItem defaultValue = project.getDefaultItem(dc, d);
     194            int valueId = 0;
     195            if (defaultValue != null)
     196            {
     197              valueId = defaultValue.getId();
     198              icon = "notrequired_values.gif";
     199            }
     200            else
     201            {
     202              icon = "notrequired_novalues.gif";
     203            }
     204            %>
     205            values[values.length] = <%=valueId%>;
     206            <%
    193207          }
    194           else
     208          else if (d == Project.Default.RAW_DATA_TYPE)
    195209          {
    196             icon = "notrequired_novalues.gif";
     210            RawDataType rdt = project.getDefaultRawDataType();
     211            String strValueId = "0";
     212            if (rdt != null)
     213            {
     214              strValueId = rdt.getId();
     215              icon = "notrequired_values.gif";
     216            }
     217            else
     218            {
     219              icon = "notrequired_novalues.gif";
     220            }
     221            %>
     222            values[values.length] = '<%=strValueId%>';
     223            <%
    197224          }
    198225        }
     
    206233        sb.append(icon+"<span class=\"label\">"+d.getShortName()+"</span></div>\n");       
    207234        %>
    208         var values = new Array();
    209         values[values.length] = <%=valueId%>;
    210235        var di = new Parameter('<%=d.getName()%>', '<%=HTML.javaScriptEncode(d.getShortName())%>', 1, false, false, values);
    211236        <%
    212237      }
    213       // TODO Set default RawDataType
    214238      %>
    215239    }
     
    422446      icon.src = gif;   
    423447    }
    424     function defaultItemOnChange(value)
     448    function defaultValueOnChange(value)
    425449    {
    426450      var pp = getSelectedParameter();
     
    434458      }
    435459      updateSelectedStyle();   
    436     }
     460    }   
    437461    function selectDefaultItemOnClick(url)
    438462    {
     
    459483      selectlist[1].text = name;
    460484      selectlist.selectedIndex = 1;
    461       defaultItemOnChange(selectlist[1].value);   
     485      defaultValueOnChange(selectlist[1].value);   
    462486    }       
    463487    function removeOnClick()
     
    545569      <table class="form" cellspacing="2" border="0" cellpadding="0" width="100%">       
    546570        <tr valign="top">
    547           <td width="50%">
    548             <b>Project default items</b><br>
    549             <div class="parameterlist" style="height: <%=(int)(scale*230)%>px; margin-top: 4px;">
     571          <td width="40%">
     572            <b>Project defaults</b><br>
     573            <div class="parameterlist" style="height: <%=(int)(scale*230)%>px; width:<%=(int)(scale*200)%>px; margin-top: 4px;">
    550574              <%=sb.toString()%>
    551575            </div>
    552576            <base:icon image="hasvalues.gif" /> = Has value
    553577          </td>
    554           <td width="50%">
     578          <td width="60%">
    555579            <br>
    556580            <%
    557581            for (Project.Default d : Project.Default.values())
    558582            {
    559               String inputName = "value_" + d.getName();             
    560               if (d.getItemType() != null)
    561               {
    562                 String selectDefaultItemOnClick = "";
    563                 String defaultItemOnChange = ""; 
    564                 List recentItems = null;
    565                 BasicItem currentItem = project != null ? project.getDefaultItem(dc, d) : null;
    566                 boolean readCurrentItem = sc.hasPermission(Permission.READ, d.getItemType());                             
    567                 if (d.getItemType() == Item.PROTOCOL)
    568                 {
    569                   int typeId = SystemItems.getId(d.getType());
    570                   String url = "'../../admin/protocols/index.jsp?ID=" + ID +
    571                       "&cmd=UpdateContext&mode=selectone&callback=setDefaultItemCallback&filter:INT:protocolType=" + typeId + "'";
    572                   selectDefaultItemOnClick = "selectDefaultItemOnClick(" + url + ")";
    573                   recentItems = recentProtocol;
    574                 }
    575                 else if (d.getItemType() == Item.HARDWARE)
    576                 {
    577                   int typeId = SystemItems.getId(d.getType());
    578                   String url = "'../../admin/hardware/index.jsp?ID=" + ID +
    579                       "&cmd=UpdateContext&mode=selectone&callback=setDefaultItemCallback&filter:INT:hardwareType=" + typeId + "'";
    580                   selectDefaultItemOnClick = "selectDefaultItemOnClick(" + url + ")";
    581                 }
    582                 else if (d.getItemType() == Item.SOFTWARE)
    583                 {
    584                   String url = "'../../admin/software/index.jsp?ID=" + ID +
    585                       "&cmd=UpdateContext&mode=selectone&callback=setDefaultItemCallback'";
    586                   selectDefaultItemOnClick = "selectDefaultItemOnClick(" + url + ")";
    587                 }
    588                 else if (d.getItemType() == Item.ARRAYDESIGN)
    589                 {
    590                   String url = "'../../lims/arraydesigns/index.jsp?ID=" + ID +
    591                       "&mode=selectone&callback=setDefaultItemCallback'";
    592                   selectDefaultItemOnClick = "selectDefaultItemOnClick(" + url + ")";                 
    593                 }               
    594                 %>
    595                 <div id="<%=inputName%>_div" style="display: none;">
    596                   <table>
    597                     <tr>
    598                     <td class="prompt"><%=d.getShortName()%></td>
    599                     </tr>
     583              String inputName = "value_" + d.getName(); 
     584              %>
     585              <div id="<%=inputName%>_div" style="display: none;">
     586                <table>
     587                  <tr>
     588                  <td class="prompt"><%=d.getShortName()%></td>
     589                  </tr>
     590                  <%
     591                  if (d.getItemType() != null)
     592                  {
     593                    String selectDefaultItemOnClick = "";
     594                    String defaultItemOnChange = ""; 
     595                    List recentItems = null;
     596                    boolean readCurrentItem = true;
     597                    BasicItem currentItem = null;
     598                    try
     599                    {
     600                      currentItem = project != null ? project.getDefaultItem(dc, d) : null;
     601                    }
     602                    catch (PermissionDeniedException ex)
     603                    {
     604                      readCurrentItem = false;
     605                    }
    600606                   
     607                    if (d.getItemType() == Item.PROTOCOL)
     608                    {
     609                      int typeId = SystemItems.getId(d.getType());
     610                      String url = "'../../admin/protocols/index.jsp?ID=" + ID +
     611                          "&cmd=UpdateContext&mode=selectone&callback=setDefaultItemCallback&filter:INT:protocolType=" + typeId + "'";
     612                      selectDefaultItemOnClick = "selectDefaultItemOnClick(" + url + ")";
     613                      recentItems = recentProtocol;
     614                    }
     615                    else if (d.getItemType() == Item.HARDWARE)
     616                    {
     617                      int typeId = SystemItems.getId(d.getType());
     618                      String url = "'../../admin/hardware/index.jsp?ID=" + ID +
     619                          "&cmd=UpdateContext&mode=selectone&callback=setDefaultItemCallback&filter:INT:hardwareType=" + typeId + "'";
     620                      selectDefaultItemOnClick = "selectDefaultItemOnClick(" + url + ")";
     621                      recentItems = recentHardware;
     622                    }
     623                    else if (d.getItemType() == Item.SOFTWARE)
     624                    {
     625                      String url = "'../../admin/software/index.jsp?ID=" + ID +
     626                          "&cmd=UpdateContext&mode=selectone&callback=setDefaultItemCallback'";
     627                      selectDefaultItemOnClick = "selectDefaultItemOnClick(" + url + ")";
     628                      recentItems = recentSoftware;
     629                    }
     630                    else if (d.getItemType() == Item.ARRAYDESIGN)
     631                    {
     632                      String url = "'../../lims/arraydesigns/index.jsp?ID=" + ID +
     633                          "&mode=selectone&callback=setDefaultItemCallback'";
     634                      selectDefaultItemOnClick = "selectDefaultItemOnClick(" + url + ")";                 
     635                      recentItems = recentArrayDesign;
     636                    }               
     637                    %>   
    601638                    <tr>
    602639                    <td>
     
    610647                        newitem="<%=project == null%>"
    611648                        onselect="<%=selectDefaultItemOnClick%>"
    612                         onchange = 'defaultItemOnChange(this[this.selectedIndex].value)'
     649                        onchange = 'defaultValueOnChange(this[this.selectedIndex].value)'
    613650                      />
    614651                    </td>
     652                    </tr>                 
     653                  <%
     654                  }
     655                  else if (d == Project.Default.RAW_DATA_TYPE)
     656                  {
     657                    RawDataType currentDefaultRawDataType = project != null ? project.getDefaultRawDataType() : null;
     658                    %>
     659                    <tr>
     660                    <td>
     661                      <div id="<%=inputName%>" class="selectionlist">
     662                        <table border="0" cellspacing="0" cellpadding="0">
     663                        <tr><td>
     664                        <select name="<%=inputName%>" onchange="defaultValueOnChange(this[this.selectedIndex].value)">
     665                          <option value="0">- none -</option>
     666                          <%
     667                          for (RawDataType rdt : RawDataTypes.getRawDataTypes())
     668                          {
     669                            String selected = rdt.equals(currentDefaultRawDataType) ? "selected" : "";
     670                            %>
     671                            <option value="<%=rdt.getId()%>" <%=selected%>><%=rdt.getName()%></option>
     672                            <%
     673                          }
     674                          %>
     675                        </select>
     676                        </td></tr>
     677                        </table>
     678                      </div>
     679                    </td>
    615680                    </tr>
    616                   </table>                   
    617                 </div>
     681                    <%
     682                  }
     683                  %>
     684                </table>                   
     685              </div>
    618686              <%
    619               }
    620687            }
    621688            %>           
  • trunk/www/my_base/projects/index.jsp

    r2939 r2941  
    4141  import="net.sf.basedb.core.PermissionDeniedException"
    4242  import="net.sf.basedb.core.ItemAlreadyExistsException"
     43  import="net.sf.basedb.core.RawDataType"
     44  import="net.sf.basedb.core.RawDataTypes"
    4345  import="net.sf.basedb.util.RemovableUtil"
    4446  import="net.sf.basedb.util.OwnableUtil"
     
    172174    {
    173175      String selectDefault = "value_"+d.getName();
    174       int selectId = Values.getInt(request.getParameter(selectDefault), -1);     
    175       if (selectId >= 0)
     176      if (d.getItemType() != null)
    176177      {
    177         BasicItem item = null;
    178         item = selectId == 0 ? null : d.getItemType().getById(dc, selectId);
    179         project.setDefaultItem(dc, item, d);
     178        int selectId = Values.getInt(request.getParameter(selectDefault), -1);     
     179        if (selectId >= 0)
     180        {
     181          BasicItem item = selectId == 0 ? null : d.getItemType().getById(dc, selectId);
     182          project.setDefaultItem(dc, item, d);
     183        }
     184      }
     185      else if (d == Project.Default.RAW_DATA_TYPE)
     186      {
     187        String selectId = request.getParameter(selectDefault);
     188        if (selectId != null && selectId.length() > 0)
     189        {
     190          RawDataType rdt = selectId.equals("0") ? null :RawDataTypes.getRawDataType(selectId);
     191          project.setDefaultRawDataType(rdt);
     192        }
    180193      }
    181194    }
Note: See TracChangeset for help on using the changeset viewer.