Changeset 2928


Ignore:
Timestamp:
Nov 16, 2006, 5:38:55 PM (16 years ago)
Author:
Martin Svensson
Message:

References #334. Updated the functions in core.
Not completely implemented in web

Location:
trunk
Files:
3 edited

Legend:

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

    r2906 r2928  
    3333
    3434import java.util.ArrayList;
     35import java.util.HashMap;
    3536import java.util.HashSet;
    3637import java.util.List;
     
    8687  public static final Item TYPE = Item.PROJECT;
    8788 
    88   public static final String DEFAULT_SCANNING_PROTOCOL = "default_scanning_protocol";
    89   public static final String DEFAULT_SAMPLING_PROTOCOL = "default_sampling_protocol";
    90   public static final String DEFAULT_EXTRACTING_PROTOCOL = "default_extracting_protocol";
    91   public static final String DEFAULT_LABELING_PROTOCOL = "default_labeling_protocol";
    92   public static final String DEFAULT_HYBRIDIZATION_PROTOCOL = "default_hybridization_protocol";
    93   public static final String DEFAULT_FEATURE_EXTRACTION_PROTOCOL = "default_feature_extraction_protocol";
    94   public static final String DEFAULT_POOLING_PROTOCOL = "default_pooling_protocol";
    95   public static final String DEFAULT_PRINTING_PROTOCOL = "default_printing_protocol";
    96   public static final String DEFAULT_SOFTWARE = "default_software";
    97   public static final String DEFAULT_ARRAYDESIGN = "default_arraydesign";
    98   public static final String DEFAULT_HARDWARE = "default_hardware";
    99    
     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// 
    100105  /**
    101106    This filter will limit a query to only return projects
     
    464469
    465470  /**
    466       Sets the default item and give it a specific <code>linkName</code>
    467       The default item will be removed if <code>defaultItem</code> is null.
     471      Sets default item.       
    468472     
    469473      @param dc The <code>DbControl</code> which will be used for
    470474      permission checking and database access.
    471       @param defaultItem The {@linknet.sf.basedb.core.BaseItem} to set as default.
    472       @param linkName The link name that the default item shall get.
    473   */
    474   public void setDefaultItem(DbControl dc, BasicItem defaultItem, String linkName)
    475   {
    476     if (linkName == null)throw new InvalidUseOfNullException("linkName");   
     475      @param defaultItem The {@link net.sf.basedb.core.BasicItem} to set as default.   
     476  */
     477  public void setDefaultItem(DbControl dc, BasicItem defaultItem, Default defaultType)
     478  {
     479    String lnkName = defaultType.getName();
    477480    if (defaultItem == null)
    478481    {
    479       AnyToAny.unlinkFrom(dc, this, linkName);
     482      AnyToAny.unlinkFrom(dc, this, defaultType.getName());
    480483    }
    481484    else
    482     {
    483      
    484       AnyToAny defaultLink = AnyToAny.getNewOrExisting(dc, this, linkName, defaultItem, false);
    485       if (defaultLink.getId() != 0)
    486       {
    487         defaultLink.setTo(defaultItem);
    488       }
    489       else
     485    {
     486      AnyToAny defaultLink = AnyToAny.getNewOrExisting(dc, this, lnkName, defaultItem, false);
     487      if (defaultLink.getId() == 0)     
    490488      {
    491489        dc.saveItem(defaultLink);
    492490      }
    493     }   
     491    }    
    494492  }
    495493 
     
    504502      @return A BasicItem or null if no item of <code>itemType.
    505503  */
    506   public BasicItem getDefaultItem(DbControl dc, Item itemType, String linkName)
    507   {
    508     if (itemType == null) throw new InvalidUseOfNullException("itemType");
    509     BasicItem defaultItem = null;
    510     AnyToAny ata = AnyToAny.getByName(dc, this, linkName);
    511     defaultItem = ata.getTo();
    512     if (defaultItem.getType() == itemType)
    513     {
    514       return defaultItem;
    515     }
    516     else
    517     {
    518       return null;
    519     }
    520   }
     504  public BasicItem getDefaultItem(DbControl dc, Default defaultType)
     505  {
     506    if (defaultType == null) throw new InvalidUseOfNullException("defaultType");   
     507    BasicItem defaultItem = null;   
     508    AnyToAny ata;   
     509    try
     510    {
     511      ata = AnyToAny.getByName(dc, this, defaultType.getName());
     512      defaultItem = ata.getTo();
     513    }
     514    catch (ItemNotFoundException ex)
     515    {
     516      defaultItem = null;
     517    }   
     518    return defaultItem;
     519  }
    521520 
    522521  /**
     
    588587    }
    589588  }
     589 
     590  public enum Default
     591  {
     592    SCANNING_PROTOCOL("default_scanning_protocol", "Scanning protocol", Item.PROTOCOL, ProtocolType.SCANNING),
     593    SAMPLING_PROTOCOL("default_sampling_protocol", "Sampling protocol", Item.PROTOCOL, ProtocolType.SAMPLING),
     594    EXTRACTING_PROTOCOL("default_extracting_protocol", "Extracting protocol", Item.PROTOCOL, ProtocolType.EXTRACTION),   
     595    LABELING_PROTOCOL("default_labeling_protocol", "Labeling protocol", Item.PROTOCOL, ProtocolType.LABELING),
     596    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),
     598    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);
     605   
     606    private String name;
     607    private String shortName;
     608    private Item itemType;
     609    private String type;
     610   
     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   
     632    private Default(String name, String shortName, Item itemType, String type)
     633    {
     634      this.name = name;
     635      this.shortName = shortName;
     636      this.itemType = itemType;
     637      this.type = type;
     638    }
     639   
     640    public String getName()
     641    {
     642      return name;
     643    }
     644   
     645    public String getShortName()
     646    {
     647      return shortName;
     648    }
     649   
     650    public Item getItemType()
     651    {
     652      return itemType;
     653    }
     654   
     655    public String getType()
     656    {
     657      return type;
     658    }
     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//    }
     675  }
    590676}
    591677
     678
     679
  • trunk/src/test/TestProject.java

    r2906 r2928  
    9797    try
    9898    {     
    99       dc = TestUtil.getDbControl();
    100       int pTypeId = TestProtocolType.test_create(true);
    101       int pId = TestProtocol.test_create(pTypeId, true);     
    102       Protocol prt = Protocol.getById(dc, pId);
     99      dc = TestUtil.getDbControl();     
     100      int adId = TestArrayDesign.test_create(false, false);     
     101      ArrayDesign ad = ArrayDesign.getById(dc, adId);
    103102      Project p = Project.getById(dc, id);
    104103     
    105       p.setDefaultItem(dc, prt, Project.DEFAULT_POOLING_PROTOCOL);
     104      p.setDefaultItem(dc, ad, Project.Default.ARRAYDESIGN);
    106105      dc.commit();
    107106      write("--Set default item OK");
    108107      dc = TestUtil.getDbControl();
    109       Protocol testPrt = (Protocol)p.getDefaultItem(dc, Protocol.TYPE, Project.DEFAULT_POOLING_PROTOCOL);
    110       if (testPrt.getId() != pId) throw new BaseException("Expected " + pId + " but got " + testPrt.getId());
     108      ArrayDesign testAD = (ArrayDesign)p.getDefaultItem(dc, Project.Default.ARRAYDESIGN);
     109      if (testAD.getId() != adId) throw new BaseException("Expected " + adId + " but got " + testAD.getId());
    111110      write("--Get default item OK");
    112111      if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter();
    113       p.setDefaultItem(dc, null, Project.DEFAULT_POOLING_PROTOCOL);
     112      p.setDefaultItem(dc, null, Project.Default.ARRAYDESIGN);
    114113      dc.commit();   
    115114      dc = TestUtil.getDbControl();
    116115      try
    117116      {
    118         testPrt = (Protocol)p.getDefaultItem(dc, Protocol.TYPE, Project.DEFAULT_POOLING_PROTOCOL);
     117        testAD = (ArrayDesign)p.getDefaultItem(dc, Project.Default.ARRAYDESIGN);
    119118      }
    120119      catch(ItemNotFoundException ex)
    121120      {
    122121        write("--Reset default item OK");
    123       }
    124      
    125       TestProtocol.test_delete(pId);
    126       TestProtocolType.test_delete(pTypeId);
     122      }     
     123      TestArrayDesign.test_delete(adId);     
    127124    }
    128125    catch(Throwable ex)
  • trunk/www/my_base/projects/edit_project.jsp

    r2916 r2928  
    2828<%@ page
    2929  import="net.sf.basedb.core.SessionControl"
     30  import="net.sf.basedb.core.BasicItem"
    3031  import="net.sf.basedb.core.DbControl"
    3132  import="net.sf.basedb.core.Item"
     
    111112    throw new PermissionDeniedException(Permission.WRITE, itemType.toString());
    112113  }
     114  final StringBuilder sb = new StringBuilder();
     115 
    113116  final String clazz = "class=\"text\"";
    114117  final String requiredClazz = "class=\"text required\"";
     
    116119
    117120  <base:page type="popup" title="<%=title%>">
    118   <base:head scripts="tabcontrol.js,linkitems.js" styles="tabcontrol.css">
     121  <base:head scripts="tabcontrol.js,linkitems.js" styles="tabcontrol.css,parameters.css">
    119122    <script language="JavaScript">
    120123    // Validate the "Project" tab
     
    160163      %>
    161164      initMembers();
     165      initDefaults();
     166    }
     167    function initDefaults()
     168    {
     169      <%
     170      for (Project.Default d : Project.Default.values())
     171      {
     172        String icon = "";
     173        if (project != null)
     174        {
     175          BasicItem defaultValue = project.getDefaultItem(dc, d);
     176          if (defaultValue != null)
     177          {
     178            icon = "notrequired_values.gif";
     179          }
     180          else
     181          {
     182            icon = "notrequired_novalues.gif";
     183          }
     184        }
     185        else
     186        {
     187          icon = "notrequired_novalues.gif";
     188        }
     189        icon = "<span class=\"icon\"><img id=\"icon_"+d.getName()+"\" src=\"../../images/"+icon+"\"></span>";
     190        sb.append("<div class=\"param\" id=\"prompt_"+d.getName()+"\" onclick=\"defaultItemOnClick('"+d.getName()+"')\"");
     191        sb.append(" onmouseover=\"Main.addClass(this, 'hover')\" onmouseout=\"Main.removeClass(this, 'hover')\" title=\""+d.getShortName()+"\">");
     192        sb.append(icon+"<span class=\"label\">"+d.getShortName()+"</span></div>\n");       
     193      }
     194      %>
    162195    }
    163196    function initMembers()
     
    194227      %>
    195228    }
    196    
     229    var oldValueDiv;
     230    function defaultItemOnClick(defaultname)
     231    {
     232     
     233    }   
    197234    function correctPermissions(checked)
    198235    {
     
    400437    </table>
    401438    </t:tab>
     439   
     440    <t:tab id="defaults" title="Defaults"  helpid="project.edit.defaults">
     441      <table class="form" cellspacing="2" border="0" cellpadding="0" width="100%">       
     442        <tr valign="top">
     443          <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
     449          </td>
     450          <td width="50%">
     451
     452          </td>
     453        </tr>
     454      </table>
     455    </t:tab>
    402456    </t:tabcontrol>
    403457
Note: See TracChangeset for help on using the changeset viewer.