Changeset 2939


Ignore:
Timestamp:
Nov 20, 2006, 4:23:40 PM (16 years ago)
Author:
Martin Svensson
Message:

References #334. Set default values for some BasicItems? in a project.

Location:
trunk
Files:
4 edited

Legend:

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

    r2928 r2939  
    3333
    3434import java.util.ArrayList;
    35 import java.util.HashMap;
    3635import java.util.HashSet;
    3736import java.util.List;
    38 import java.util.Map;
    3937import java.util.Set;
    4038import java.util.Collections;
     
    8684  */
    8785  public static final Item TYPE = Item.PROJECT;
    88  
    89 //  public static final String DEFAULT_SCANNING_PROTOCOL = "default_scanning_protocol";
    90 //  public static final String DEFAULT_SAMPLING_PROTOCOL = "default_sampling_protocol";
    91 //  public static final String DEFAULT_EXTRACTING_PROTOCOL = "default_extracting_protocol";
    92 //  public static final String DEFAULT_LABELING_PROTOCOL = "default_labeling_protocol";
    93 //  public static final String DEFAULT_HYBRIDIZATION_PROTOCOL = "default_hybridization_protocol";
    94 //  public static final String DEFAULT_FEATURE_EXTRACTION_PROTOCOL = "default_feature_extraction_protocol";
    95 //  public static final String DEFAULT_POOLING_PROTOCOL = "default_pooling_protocol";
    96 //  public static final String DEFAULT_PRINTING_PROTOCOL = "default_printing_protocol";
    97 //  public static final String DEFAULT_SOFTWARE = "default_software";
    98 //  public static final String DEFAULT_ARRAYDESIGN = "default_arraydesign";
    99 //  public static final String DEFAULT_HYBRIDIZATION_HARDWARE = "default_hybridization_hardware";
    100 //  public static final String DEFAULT_SCANNER_HARDWARE = "default_scanner_hardware";
    101 //  public static final String DEFAULT_PRINTROBOT_HARDWARE = "default_print_robot_hardware";
    102 //   
    103 //  private static final List<String> defaultNames = null;
    104 // 
     86
    10587  /**
    10688    This filter will limit a query to only return projects
     
    469451
    470452  /**
    471       Sets default item.       
     453      Sets item as default for project.
    472454     
    473455      @param dc The <code>DbControl</code> which will be used for
    474456      permission checking and database access.
    475       @param defaultItem The {@link net.sf.basedb.core.BasicItem} to set as default.   
     457      @param defaultItem The {@link net.sf.basedb.core.BasicItem} to set as default.
     458        Use null when to remove a default value.
     459      @param defaultType The {@link Default} to be set.
    476460  */
    477461  public void setDefaultItem(DbControl dc, BasicItem defaultItem, Default defaultType)
     
    480464    if (defaultItem == null)
    481465    {
    482       AnyToAny.unlinkFrom(dc, this, defaultType.getName());
     466      AnyToAny.unlinkFrom(dc, this, lnkName);
    483467    }
    484468    else
     
    493477 
    494478  /**
    495       Gets the project's default item of a certain <code>itemType</code>.
     479      Gets the project's default item of a certain itemType defined in <code>defaultType</code>.
    496480      If no item of the specified type is found this will return Null
    497481     
    498482      @param dc The <code>DbControl</code> which will be used for
    499483      permission checking and database access.
    500       @param itemType The {@linknet.sf.basedb.core.Item} type is expected to be..
    501       @param linkName The link name that the default item has been saved as.
    502       @return A BasicItem or null if no item of <code>itemType.
     484      @param defaultType The project's <code>Default</code> to get.
     485      @return A BasicItem or null if no item was found.
    503486  */
    504487  public BasicItem getDefaultItem(DbControl dc, Default defaultType)
     
    589572 
    590573  public enum Default
    591   {
     574  {   
     575    SOFTWARE("default_software", "Software", Item.SOFTWARE, null),
     576    ARRAYDESIGN("default_arraydesign", "Array design", Item.ARRAYDESIGN, null),
     577    HYBRIDIZATION_HARDWARE("default_hybridization_hardware", "Hybridization station", Item.HARDWARE, HardwareType.HYBRIDIZATION_STATION),
     578    SCANNER_HARDWARE("default_scanner_hardware", "Scanner", Item.HARDWARE, HardwareType.SCANNER),
     579    PRINTROBOT_HARDWARE("default_print_robot_hardware", "Print robot", Item.HARDWARE, HardwareType.PRINT_ROBOT),
    592580    SCANNING_PROTOCOL("default_scanning_protocol", "Scanning protocol", Item.PROTOCOL, ProtocolType.SCANNING),
    593581    SAMPLING_PROTOCOL("default_sampling_protocol", "Sampling protocol", Item.PROTOCOL, ProtocolType.SAMPLING),
     
    595583    LABELING_PROTOCOL("default_labeling_protocol", "Labeling protocol", Item.PROTOCOL, ProtocolType.LABELING),
    596584    HYBRIDIZATION_PROTOCOL("default_hybridization_protocol", "Hybridization protocol", Item.PROTOCOL, ProtocolType.HYBRIDIZATION),
    597     FEATURE_EXTRACTION_PROTOCOL("default_feature_extraction_protocol", "Feature extraction protocol", Item.PROTOCOL, ProtocolType.FEATURE_EXTRACTION),
     585    FEATURE_EXTRACTION_PROTOCOL("default_feature_extraction_protocol", "Feat. extraction protocol", Item.PROTOCOL, ProtocolType.FEATURE_EXTRACTION),
    598586    POOLING_PROTOCOL("default_pooling_protocol", "Pooling protocol", Item.PROTOCOL, ProtocolType.POOLING),
    599     PRINTING_PROTOCOL("default_printing_protocol", "Printing protocol", Item.PROTOCOL, ProtocolType.PRINTING),
    600     SOFTWARE("default_software", "Software", Item.SOFTWARE, null),
    601     ARRAYDESIGN("default_arraydesign", "Array design", Item.ARRAYDESIGN, null),
    602     HYBRIDIZATION_HARDWARE("default_hybridization_hardware", "Hybridization station", Item.HARDWARE, HardwareType.HYBRIDIZATION_STATION),
    603     SCANNER_HARDWARE("default_scanner_hardware", "Scanner", Item.HARDWARE, HardwareType.SCANNER),
    604     PRINTROBOT_HARDWARE("default_print_robot_hardware", "Print robot", Item.HARDWARE, HardwareType.PRINT_ROBOT);
     587    PRINTING_PROTOCOL("default_printing_protocol", "Printing protocol", Item.PROTOCOL, ProtocolType.PRINTING);
    605588   
    606589    private String name;
     
    609592    private String type;
    610593   
    611 //    private static final Map<String, String>typeMapping = new HashMap<String, String>();
    612 //    private static final Map<Item, String>itemMapping = new HashMap<Item, String>();
    613    
    614 //    static
    615 //    {
    616 //      for (Default d : Default.values())
    617 //      {
    618 //        String s = null;
    619 //        if (d.getType() != null)
    620 //        {
    621 //          s = typeMapping.put(d.getType(), d.getName());
    622 //          assert s == null : "Another name for type "+d.getType()+" already exists: " + s;
    623 //        }
    624 //        if (d.getItemType() != null)
    625 //        {
    626 //          s = itemMapping.put(d.getItemType(), d.getName());
    627 //          assert s == null : "Another name for item "+d.getItemType()+" already exists: " + s;
    628 //        }
    629 //      }
    630 //    }
    631    
    632594    private Default(String name, String shortName, Item itemType, String type)
    633595    {
     
    657619      return type;
    658620    }
    659 //   
    660 //    public static String fromType(String type)
    661 //    {
    662 //      String s;
    663 //      s = typeMapping.get(type);
    664 //      assert s != null : "name == null for type " + type;
    665 //      return s;
    666 //    }
    667 //   
    668 //    public static String fromItem(Item itemType)
    669 //    {
    670 //      String s;
    671 //      s = itemMapping.get(itemType);
    672 //      assert s != null : "name == null for item " + itemType.toString();
    673 //      return s;
    674 //    }
    675621  }
    676622}
  • trunk/www/include/scripts/main.js

    r2907 r2939  
    369369    this.controllers['BIOSOURCE'] = { url:'biomaterials/biosources/index.jsp', width:800, height:500 };
    370370    this.controllers['MESSAGE'] = { url:'my_base/messages/index.jsp', width:600, height:420, popup:true, edit:false };
    371     this.controllers['PROJECT'] = { url:'my_base/projects/index.jsp', width:540, height:400 };
     371    this.controllers['PROJECT'] = { url:'my_base/projects/index.jsp', width:570, height:400 };
    372372    this.controllers['FILE'] = { url:'filemanager/index.jsp', width:500, height:360 };
    373373    this.controllers['DIRECTORY'] = { url:'filemanager/directories/index.jsp', width:450, height:340, xpopup:true };
  • trunk/www/my_base/projects/edit_project.jsp

    r2928 r2939  
    2727--%>
    2828<%@ page
     29  import="net.sf.basedb.core.ArrayDesign"
    2930  import="net.sf.basedb.core.SessionControl"
    3031  import="net.sf.basedb.core.BasicItem"
    3132  import="net.sf.basedb.core.DbControl"
     33  import="net.sf.basedb.core.Hardware"
    3234  import="net.sf.basedb.core.Item"
    3335  import="net.sf.basedb.core.ItemContext"
     
    3537  import="net.sf.basedb.core.Permission"
    3638  import="net.sf.basedb.core.Project"
     39  import="net.sf.basedb.core.Protocol"
    3740  import="net.sf.basedb.core.User"
    3841  import="net.sf.basedb.core.Group"
     
    4043  import="net.sf.basedb.core.ItemResultList"
    4144  import="net.sf.basedb.core.PermissionDeniedException"
     45  import="net.sf.basedb.core.Software"
    4246  import="net.sf.basedb.core.BaseException"
    4347  import="net.sf.basedb.core.query.Orders"
     
    9195  // Query to retrieve user members
    9296  ItemQuery<User> userQuery = null;
     97 
     98  // Load recently used items
     99  List<Protocol> recentProtocol = (List<Protocol>)cc.getRecent(dc, Item.PROTOCOL);
     100  List<Software> recentSoftware = (List<Software>)cc.getRecent(dc, Item.SOFTWARE);
     101  List<Hardware> recentHardware = (List<Hardware>)cc.getRecent(dc, Item.HARDWARE);
     102  List<ArrayDesign> recentArrayDesign = (List<ArrayDesign>)cc.getRecent(dc, Item.ARRAYDESIGN);
     103 
    93104 
    94105  if (itemId == 0)
     
    119130
    120131  <base:page type="popup" title="<%=title%>">
    121   <base:head scripts="tabcontrol.js,linkitems.js" styles="tabcontrol.css,parameters.css">
     132  <base:head scripts="tabcontrol.js,linkitems.js,parameters.js" styles="tabcontrol.css,parameters.css">
    122133    <script language="JavaScript">
    123134    // Validate the "Project" tab
     
    170181      for (Project.Default d : Project.Default.values())
    171182      {
     183        BasicItem defaultValue = null;
     184        int valueId = 0;
    172185        String icon = "";
    173186        if (project != null)
    174187        {
    175           BasicItem defaultValue = project.getDefaultItem(dc, d);
     188          defaultValue = project.getDefaultItem(dc, d);
    176189          if (defaultValue != null)
    177190          {
     191            valueId = defaultValue.getId();
    178192            icon = "notrequired_values.gif";
    179193          }
     
    191205        sb.append(" onmouseover=\"Main.addClass(this, 'hover')\" onmouseout=\"Main.removeClass(this, 'hover')\" title=\""+d.getShortName()+"\">");
    192206        sb.append(icon+"<span class=\"label\">"+d.getShortName()+"</span></div>\n");       
    193       }
     207        %>
     208        var values = new Array();
     209        values[values.length] = <%=valueId%>;
     210        var di = new Parameter('<%=d.getName()%>', '<%=HTML.javaScriptEncode(d.getShortName())%>', 1, false, false, values);
     211        <%
     212      }
     213      // TODO Set default RawDataType
    194214      %>
    195215    }
     
    226246      }
    227247      %>
    228     }
    229     var oldValueDiv;
    230     function defaultItemOnClick(defaultname)
    231     {
    232      
    233     }   
     248    }     
    234249    function correctPermissions(checked)
    235250    {
     
    357372      Link.addItem(document.forms['project'].members, item);
    358373    }
     374    var oldValueDiv;
     375    function defaultItemOnClick(defaultName)
     376    {
     377      var frm = document.forms['project'];
     378      if (oldValueDiv) Main.hide(oldValueDiv);
     379     
     380      var pp = Parameters.allParameters['ID'+defaultName];   
     381      setSelectedParameter(pp, defaultName);
     382      oldValueDiv = 'value_'+pp.name+'_div';
     383      Main.show(oldValueDiv);
     384     
     385      var valueElement = frm['value_'+pp.name];
     386      if (valueElement.focus) valueElement.focus();
     387     
     388     
     389    }
     390    var selectedParameter = null;
     391    var selectedParameterName = null;
     392    function getSelectedParameter()
     393    {
     394      return selectedParameter;
     395    }   
     396    function setSelectedParameter(parameter, name)
     397    {
     398      if (selectedParameter != null)
     399      {
     400        Main.removeClass(document.getElementById('prompt_'+selectedParameter.name), 'selected');
     401      }
     402      selectedParameter = parameter;
     403      selectedParameterName = name;
     404      if (selectedParameter != null)
     405      {
     406        Main.addClass(document.getElementById('prompt_'+selectedParameter.name), 'selected');
     407      }
     408    }
     409    function updateSelectedStyle()
     410    {
     411      var pp = getSelectedParameter();
     412      var icon = document.getElementById('icon_'+pp.name);
     413      var gif = getRoot()+'images/';
     414      if (pp.values[0] == 0)
     415      {
     416        gif += 'notrequired_novalues.gif';
     417      }
     418      else
     419      {
     420        gif += 'notrequired_values.gif';
     421      }
     422      icon.src = gif;   
     423    }
     424    function defaultItemOnChange(value)
     425    {
     426      var pp = getSelectedParameter();
     427      if (value == null || value == '')
     428      {
     429        pp.removeValue(0);
     430      }
     431      else
     432      {
     433        pp.updateValue(0, value);
     434      }
     435      updateSelectedStyle();   
     436    }
     437    function selectDefaultItemOnClick(url)
     438    {
     439      var frm = document.forms['project'];           
     440      var select_id = 'value_' + getSelectedParameter().name;
     441      var selectlist = frm[select_id];
     442      if (selectlist.length > 1)
     443      {
     444        var id = Math.abs(parseInt(selectlist[1].value));       
     445        url += '&item_id='+id;
     446      }
     447      Main.openPopup(url, 'SelectDefaultItem', 1000, 700);
     448    }
     449    function setDefaultItemCallback(id, name)
     450    {
     451      var frm = document.forms['project'];
     452      var select_id = 'value_' + getSelectedParameter().name;
     453      var selectlist = frm[select_id];
     454      if (selectlist.length < 2)
     455      {
     456        Forms.addListOption(selectlist, 1, new Option());
     457      }
     458      selectlist[1].value = id;
     459      selectlist[1].text = name;
     460      selectlist.selectedIndex = 1;
     461      defaultItemOnChange(selectlist[1].value);   
     462    }       
    359463    function removeOnClick()
    360464    {
     
    442546        <tr valign="top">
    443547          <td width="50%">
    444           <b>Values</b><br>
    445           <div class="parameterlist" style="height: <%=(int)(scale*230)%>px; margin-top: 4px;">
    446             <%=sb.toString()%>
    447           </div>
    448           <base:icon image="hasvalues.gif" /> = Has value
     548            <b>Project default items</b><br>
     549            <div class="parameterlist" style="height: <%=(int)(scale*230)%>px; margin-top: 4px;">
     550              <%=sb.toString()%>
     551            </div>
     552            <base:icon image="hasvalues.gif" /> = Has value
    449553          </td>
    450554          <td width="50%">
    451 
     555            <br>
     556            <%
     557            for (Project.Default d : Project.Default.values())
     558            {
     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>
     600                   
     601                    <tr>
     602                    <td>
     603                      <base:select
     604                        id="<%=inputName%>"
     605                        clazz="selectionlist"
     606                        required="false"
     607                        current="<%=currentItem%>"
     608                        denied="<%=!readCurrentItem%>"
     609                        recent="<%=recentItems%>"
     610                        newitem="<%=project == null%>"
     611                        onselect="<%=selectDefaultItemOnClick%>"
     612                        onchange = 'defaultItemOnChange(this[this.selectedIndex].value)'
     613                      />
     614                    </td>
     615                    </tr>
     616                  </table>                   
     617                </div>
     618              <%
     619              }
     620            }
     621            %>           
    452622          </td>
    453623        </tr>
  • trunk/www/my_base/projects/index.jsp

    r2918 r2939  
    2626--%>
    2727<%@ page
     28  import="net.sf.basedb.core.BasicItem"
    2829  import="net.sf.basedb.core.SessionControl"
    2930  import="net.sf.basedb.core.DbControl"
     
    166167      }
    167168    }
     169   
     170    // Default tab
     171    for (Project.Default d : Project.Default.values())
     172    {
     173      String selectDefault = "value_"+d.getName();
     174      int selectId = Values.getInt(request.getParameter(selectDefault), -1);     
     175      if (selectId >= 0)
     176      {
     177        BasicItem item = null;
     178        item = selectId == 0 ? null : d.getItemType().getById(dc, selectId);
     179        project.setDefaultItem(dc, item, d);
     180      }
     181    }
    168182
    169183    dc.commit();
Note: See TracChangeset for help on using the changeset viewer.