Changeset 2928
- Timestamp:
- Nov 16, 2006, 5:38:55 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/net/sf/basedb/core/Project.java
r2906 r2928 33 33 34 34 import java.util.ArrayList; 35 import java.util.HashMap; 35 36 import java.util.HashSet; 36 37 import java.util.List; … … 86 87 public static final Item TYPE = Item.PROJECT; 87 88 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 // 100 105 /** 101 106 This filter will limit a query to only return projects … … 464 469 465 470 /** 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. 468 472 469 473 @param dc The <code>DbControl</code> which will be used for 470 474 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(); 477 480 if (defaultItem == null) 478 481 { 479 AnyToAny.unlinkFrom(dc, this, linkName);482 AnyToAny.unlinkFrom(dc, this, defaultType.getName()); 480 483 } 481 484 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) 490 488 { 491 489 dc.saveItem(defaultLink); 492 490 } 493 } 491 } 494 492 } 495 493 … … 504 502 @return A BasicItem or null if no item of <code>itemType. 505 503 */ 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 } 521 520 522 521 /** … … 588 587 } 589 588 } 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 } 590 676 } 591 677 678 679 -
trunk/src/test/TestProject.java
r2906 r2928 97 97 try 98 98 { 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); 103 102 Project p = Project.getById(dc, id); 104 103 105 p.setDefaultItem(dc, prt, Project.DEFAULT_POOLING_PROTOCOL);104 p.setDefaultItem(dc, ad, Project.Default.ARRAYDESIGN); 106 105 dc.commit(); 107 106 write("--Set default item OK"); 108 107 dc = TestUtil.getDbControl(); 109 Protocol testPrt = (Protocol)p.getDefaultItem(dc, Protocol.TYPE, Project.DEFAULT_POOLING_PROTOCOL);110 if (test Prt.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()); 111 110 write("--Get default item OK"); 112 111 if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter(); 113 p.setDefaultItem(dc, null, Project.D EFAULT_POOLING_PROTOCOL);112 p.setDefaultItem(dc, null, Project.Default.ARRAYDESIGN); 114 113 dc.commit(); 115 114 dc = TestUtil.getDbControl(); 116 115 try 117 116 { 118 test Prt = (Protocol)p.getDefaultItem(dc, Protocol.TYPE, Project.DEFAULT_POOLING_PROTOCOL);117 testAD = (ArrayDesign)p.getDefaultItem(dc, Project.Default.ARRAYDESIGN); 119 118 } 120 119 catch(ItemNotFoundException ex) 121 120 { 122 121 write("--Reset default item OK"); 123 } 124 125 TestProtocol.test_delete(pId); 126 TestProtocolType.test_delete(pTypeId); 122 } 123 TestArrayDesign.test_delete(adId); 127 124 } 128 125 catch(Throwable ex) -
trunk/www/my_base/projects/edit_project.jsp
r2916 r2928 28 28 <%@ page 29 29 import="net.sf.basedb.core.SessionControl" 30 import="net.sf.basedb.core.BasicItem" 30 31 import="net.sf.basedb.core.DbControl" 31 32 import="net.sf.basedb.core.Item" … … 111 112 throw new PermissionDeniedException(Permission.WRITE, itemType.toString()); 112 113 } 114 final StringBuilder sb = new StringBuilder(); 115 113 116 final String clazz = "class=\"text\""; 114 117 final String requiredClazz = "class=\"text required\""; … … 116 119 117 120 <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"> 119 122 <script language="JavaScript"> 120 123 // Validate the "Project" tab … … 160 163 %> 161 164 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 %> 162 195 } 163 196 function initMembers() … … 194 227 %> 195 228 } 196 229 var oldValueDiv; 230 function defaultItemOnClick(defaultname) 231 { 232 233 } 197 234 function correctPermissions(checked) 198 235 { … … 400 437 </table> 401 438 </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> 402 456 </t:tabcontrol> 403 457
Note: See TracChangeset
for help on using the changeset viewer.