Changeset 2210


Ignore:
Timestamp:
May 3, 2006, 3:42:21 PM (17 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #163: The tree of bioassay sets in the analysis should include
transformations as separate items

Location:
trunk
Files:
4 added
3 edited

Legend:

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

    r2199 r2210  
    309309      sc.getCurrentContext(Item.DIRECTORY, subContext) : null; // Used in special case for file manager
    310310   
     311    ItemContext transformationContext = itemType == Item.BIOASSAYSET ?
     312      sc.getCurrentContext(Item.TRANSFORMATION, subContext) : null; // Used in special case for analysis tree
     313     
    311314    // Detect if active project has changed and then set the include option
    312315    int projectId = sc.getActiveProjectId();
     
    395398        cc.getSelected().clear();
    396399        if (dirContext != null) dirContext.getSelected().clear();
     400        if (transformationContext != null) transformationContext.getSelected().clear();
    397401        while (names.hasMoreElements())
    398402        {
     
    466470            }
    467471          }
    468           else if (name.startsWith("D:") && dirContext != null)
     472          else if (dirContext != null && name.startsWith("D:"))
    469473          {
    470474            // Special case for file manager which lists both files and directories in the
     
    472476            int id = Values.getInt(name.substring(2), -1);
    473477            if (id != -1) dirContext.getSelected().add(id);
     478          }
     479          else if (transformationContext != null && name.startsWith("T:"))
     480          {
     481            // Special case for analysis tree which lists both bioassay sets and
     482            // transformations in the same list
     483            int id = Values.getInt(name.substring(2), -1);
     484            if (id != -1) transformationContext.getSelected().add(id);
    474485          }
    475486          else
  • trunk/www/views/experiments/bioassaysets/index.jsp

    r2200 r2210  
    7171  private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,transformation,spots,reporters,date,tools");
    7272  private static final Item itemType = Item.BIOASSAYSET;
     73 
     74 
     75  private void setClosed(HttpServletRequest request, ItemContext cc)
     76  {
     77    String closed = request.getParameter("closed");
     78    if (closed != null)
     79    {
     80      cc.setObject("closed", new HashSet<String>(Arrays.asList(closed.split(","))));
     81    }
     82  }
    7383%>
    7484<%
     
    111121    // Display the list page after updating the current context from the request parameters
    112122    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
    113     String closed = request.getParameter("closed");
    114     if (closed != null)
    115     {
    116       cc.setObject("closed", new HashSet<Integer>(Arrays.asList(Values.getInt(closed.split(",")))));
    117     }
     123    setClosed(request, cc);
    118124    redirect = listPage;
    119125  }
     
    180186    dc = sc.newDbControl();
    181187    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
    182     int numTotal = cc.getSelected().size();
     188    ItemContext tc = sc.getCurrentContext(Item.TRANSFORMATION);
     189    setClosed(request, cc);
     190
     191    int numTotal = cc.getSelected().size()+tc.getSelected().size();
    183192    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), true);
     193    numRemoved += RemovableUtil.setRemoved(dc, Item.TRANSFORMATION, tc.getSelected(), true);
    184194    dc.commit();
    185195    if (numTotal != numRemoved)
     
    203213    dc = sc.newDbControl();
    204214    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
    205     int numTotal = cc.getSelected().size();
     215    ItemContext tc = sc.getCurrentContext(Item.TRANSFORMATION);
     216    setClosed(request, cc);
     217
     218    int numTotal = cc.getSelected().size()+tc.getSelected().size();
    206219    int numRemoved = RemovableUtil.setRemoved(dc, itemType, cc.getSelected(), false);
     220    numRemoved += RemovableUtil.setRemoved(dc, Item.TRANSFORMATION, tc.getSelected(), false);
    207221    dc.commit();
    208222    if (numTotal != numRemoved)
     
    216230    // Run an export plugin in a list context
    217231    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
     232    setClosed(request, cc);
    218233    dc = sc.newDbControl();
    219234    final Experiment experiment = Experiment.getById(dc, experimentId);
     
    234249    // Run an import plugin in a list context
    235250    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
     251    setClosed(request, cc);
    236252    dc = sc.newDbControl();
    237253    final Experiment experiment = Experiment.getById(dc, experimentId);
     
    252268    // Run another plugin in a list context
    253269    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
     270    setClosed(request, cc);
    254271    dc = sc.newDbControl();
    255272    final Experiment experiment = Experiment.getById(dc, experimentId);
  • trunk/www/views/experiments/bioassaysets/list_bioassaysets.jsp

    r2173 r2210  
    3131  import="net.sf.basedb.core.Item"
    3232  import="net.sf.basedb.core.ItemContext"
     33  import="net.sf.basedb.core.BasicItem"
    3334  import="net.sf.basedb.core.Experiment"
    3435  import="net.sf.basedb.core.BioAssaySet"
     36  import="net.sf.basedb.core.Transformation"
    3537  import="net.sf.basedb.core.ItemQuery"
     38  import="net.sf.basedb.core.Nameable"
    3639  import="net.sf.basedb.core.ItemResultIterator"
    3740  import="net.sf.basedb.core.ItemResultList"
     
    4346  import="net.sf.basedb.core.query.Orders"
    4447  import="net.sf.basedb.core.query.Hql"
     48  import="net.sf.basedb.core.query.Restrictions"
    4549  import="net.sf.basedb.core.plugin.GuiContext"
    4650  import="net.sf.basedb.core.plugin.Plugin"
     
    5155  import="net.sf.basedb.clients.web.util.Values"
    5256  import="java.util.List"
     57  import="java.util.ArrayList"
    5358  import="java.util.LinkedList"
    5459  import="java.util.Map"
     
    6772<%!
    6873
    69 private static void addToTree(Tree<BioAssaySet> tree, BioAssaySet bas)
     74private static void addToTree(Tree<BasicItem> tree, BioAssaySet bas)
    7075{
    7176  if (!tree.contains(bas))
    7277  {
    73     BioAssaySet source = bas.getTransformation().getSource();
    74     Tree.Entry<BioAssaySet> parent = tree.getEntry(source);
     78    Transformation transformation = bas.getTransformation();
     79    Tree.Entry<BasicItem> parent = tree.getEntry(transformation);
    7580    if (parent == null)
    7681    {
    77       addToTree(tree, source);
    78       parent = tree.getEntry(source);
     82      addToTree(tree, transformation);
     83      parent = tree.getEntry(transformation);
    7984    }
    8085    parent.addChild(bas);
     
    8287}
    8388
    84 private static Tree<BioAssaySet> getBioAssaySetTree(DbControl dc, ItemQuery<BioAssaySet> query)
     89private static void addToTree(Tree<BasicItem> tree, Transformation transformation)
    8590{
    86   Tree<BioAssaySet> tree = new Tree<BioAssaySet>(null);
    87   ItemResultList<BioAssaySet> allBioAssaySets = query.list(dc);
     91  if (!tree.contains(transformation))
     92  {
     93    BioAssaySet source = transformation.getSource();
     94    Tree.Entry<BasicItem> parent = tree.getEntry(source);
     95    if (parent == null)
     96    {
     97      addToTree(tree, source);
     98      parent = tree.getEntry(source);
     99    }
     100    parent.addChild(transformation);
     101  }
     102}
     103
     104private static Tree<BasicItem> getAnalysisTree(DbControl dc, ItemQuery<BioAssaySet> bioAssaySetQuery, ItemQuery<Transformation> transformationQuery)
     105{
     106  Tree<BasicItem> tree = new Tree<BasicItem>(null);
     107  ItemResultList<BioAssaySet> allBioAssaySets = bioAssaySetQuery.list(dc);
     108  List<Integer> ids = new ArrayList<Integer>(allBioAssaySets.size());
     109 
    88110  for (BioAssaySet bas : allBioAssaySets)
    89111  {
    90112    addToTree(tree, bas);
     113    ids.add(bas.getId());
     114  }
     115 
     116  transformationQuery.restrict(
     117    Restrictions.in(
     118      Hql.property("source.id"),
     119      Expressions.parameter("bioAssaySets", ids)
     120    )
     121  );
     122  ItemResultList<Transformation> allTransformations = transformationQuery.list(dc);
     123  for (Transformation t: allTransformations)
     124  {
     125    addToTree(tree, t);
    91126  }
    92127  return tree;
    93128}
    94 String generateTree(Tree<BioAssaySet> tree, BioAssaySet root, Collection<Integer> closed)
     129String generateTree(Tree<BasicItem> tree, BasicItem root, Collection<String> closed)
    95130{
    96131  StringBuilder sb = new StringBuilder();
    97   Tree.Entry<BioAssaySet> rootEntry = tree.getEntry(root);
     132  Tree.Entry<BasicItem> rootEntry = tree.getEntry(root);
    98133  if (rootEntry == null) return "";
    99134 
    100   List<Tree.Entry<BioAssaySet>> children = rootEntry.getChildren();
     135  List<Tree.Entry<BasicItem>> children = rootEntry.getChildren();
    101136  if (children != null)
    102137  {
    103     for (Tree.Entry<BioAssaySet> child : children)
    104     {
    105       String folderIcon = "BioAssaySet";
    106       BioAssaySet childBa = child.getNode();
    107       sb.append("var ba").append(childBa.getId());
     138    for (Tree.Entry<BasicItem> child : children)
     139    {
     140      BasicItem node = child.getNode();
     141      int id = node.getId();
     142      String var = node.getType().name() + "_" + id;
     143      String name = ((Nameable)node).getName();
     144     
     145      String folderIcon = node.getType() == Item.BIOASSAYSET ?
     146        "BioAssaySet" : "Transformation";
     147      sb.append("var ").append(var);
    108148      if (root == null)
    109149      {
     
    112152      else
    113153      {
    114         sb.append(" = JoustMenu.addChildItem(ba" + root.getId());
     154        String rootVar = root.getType().name() + "_" + root.getId();
     155        sb.append(" = JoustMenu.addChildItem(").append(rootVar);
    115156      }
    116157      sb.append(",'").append(folderIcon).append("'");
    117       sb.append(",'").append(HTML.javaScriptEncode(childBa.getName())).append("'");
    118       sb.append(", 'itemOnClick(event, ").append(childBa.getId()).append(")', '', '").append(childBa.getId()).append("');\n");
    119       if ((closed == null || !closed.contains(childBa.getId())) && child.getNumChildren() > 0)
    120       {
    121         sb.append("JoustMenu.menuItems[ba").append(childBa.getId()).append("].isOpen = true;\n");
    122       }
    123       sb.append(generateTree(tree, childBa, closed));
     158      sb.append(",'").append(HTML.javaScriptEncode(name)).append("'");
     159      sb.append(", 'itemOnClick(event, ").append(id).append(")', '', '").append(var).append("');\n");
     160      if ((closed == null || !closed.contains(var)) && child.getNumChildren() > 0)
     161      {
     162        sb.append("JoustMenu.menuItems[").append(var).append("].isOpen = true;\n");
     163      }
     164      sb.append(generateTree(tree, node, closed));
    124165    }
    125166  }
     
    132173final String ID = sc.getId();
    133174final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
     175final ItemContext tc = sc.getCurrentContext(Item.TRANSFORMATION);
    134176
    135177final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
     
    137179final String title = mode.generateTitle("bioassay set", "bioassay sets");
    138180final DbControl dc = sc.newDbControl();
    139 Tree<BioAssaySet> bioAssaySets = null;
     181Tree<BasicItem> analysisTree = null;
    140182try
    141183{
     
    146188
    147189  final ItemQuery<BioAssaySet> query = Base.getConfiguredQuery(cc, true, experiment.getBioAssaySets());
     190  final ItemQuery<Transformation> transformationQuery = experiment.getTransformations();
    148191  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
    149192  try
    150193  {
    151     bioAssaySets = getBioAssaySetTree(dc, query);
     194    analysisTree = getAnalysisTree(dc, query, transformationQuery);
    152195  }
    153196  catch (Throwable t)
     
    156199  }
    157200  // Contains the ID:s of the bioassaysets that are closed in the tree
    158   Collection<Integer> closed = (Collection<Integer>)cc.getObject("closed");
     201  Collection<String> closed = (Collection<String>)cc.getObject("closed");
    159202  int numListed = 0;
    160203  %>
     
    168211      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=NewItem&experiment_id=<%=experimentId%>', 'NewBioAssaySet', 740, 540);
    169212    }
    170     function editItem(itemId)
     213    function editBioAssaySet(itemId)
    171214    {
    172215      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=EditItem&experiment_id=<%=experimentId%>&item_id='+itemId, 'EditBioAssaySet', 500, 300);
    173216    }
    174     function viewItem(itemId)
     217    function viewBioAssaySet(itemId)
    175218    {
    176219      location.href = 'index.jsp?ID=<%=ID%>&cmd=ViewItem&experiment_id=<%=experimentId%>&item_id='+itemId;
    177220    }
    178     function itemOnClick(evt, itemId)
    179     {
    180       Table.itemOnClick(formId, evt, itemId, '<%=mode.getName()%>', viewItem, editItem, returnSelected);
     221    function bioAssaySetOnClick(evt, itemId)
     222    {
     223      Table.itemOnClick(formId, evt, itemId, '<%=mode.getName()%>', viewBioAssaySet, editBioAssaySet, returnSelected);
     224    }
     225    function viewTransformation(itemId)
     226    {
     227      location.href = '../transformations/index.jsp?ID=<%=ID%>&cmd=ViewItem&experiment_id=<%=experimentId%>&item_id='+itemId;
     228    }
     229    function transformationOnClick(evt, itemId)
     230    {
     231      viewTransformation(itemId);
    181232    }
    182233    function deleteItems()
     
    258309          frm.closed.value += menuItem.externalId+',';
    259310        }
    260 //        alert(document.forms[formId].closed.value);
     311        // alert(document.forms[formId].closed.value);
    261312        this.updateIconsAndText(menuItemIndex);
    262313      }
     
    324375      }
    325376
    326       <%=generateTree(bioAssaySets, null, closed)%>
     377      <%=analysisTree == null ? "" : generateTree(analysisTree, null, closed)%>
    327378      JoustMenu.draw('joust');
    328379     
     
    404455        datatype="int"
    405456        title="Reporters"
    406         sortable="true"
    407         filterable="true"
    408         exportable="true"
    409       />
    410       <tbl:columndef
    411         id="transformation"
    412         property="transformation.name"
    413         datatype="string"
    414         title="Transformation"
    415457        sortable="true"
    416458        filterable="true"
     
    537579          int index = cc.getPage()*cc.getRowsPerPage();
    538580          int selectedItemId = cc.getId();
    539           if (bioAssaySets != null)
     581          if (analysisTree != null)
    540582          {
    541             Iterator<Tree.Entry<BioAssaySet>> baas = bioAssaySets.entryIterator();
     583            Iterator<Tree.Entry<BasicItem>> baas = analysisTree.entryIterator();
    542584            while (baas.hasNext())
    543585            {
    544               Tree.Entry<BioAssaySet> entry = baas.next();
    545               BioAssaySet item = entry.getNode();
     586              Tree.Entry<BasicItem> entry = baas.next();
     587              BasicItem item = entry.getNode();
    546588              if (item != null)
    547589              {
    548               int level = entry.getDepth() - 1;
    549               int itemId = item.getId();
    550               String name = HTML.encodeTags(item.getName());
    551               index++;
    552               numListed++;
    553               boolean hasChildren = entry.getNumChildren() > 0;
    554               boolean isFirstChild = entry.getParent().isFirstChild(item);
    555               boolean isLastChild = entry.getParent().isLastChild(item);
    556               String outlineIcon = "";
    557               String docIcon = "";
    558               if (hasChildren)
    559               {
    560                 docIcon = "folderopen.gif";
    561                 outlineIcon = "minus";
    562                 if (isFirstChild && isLastChild)
     590                int level = entry.getDepth() - 1;
     591                int itemId = item.getId();
     592                String joustId = item.getType().name() + "_" + itemId;
     593                String name = HTML.encodeTags(((Nameable)item).getName());
     594                String description = HTML.encodeTags(((Nameable)item).getDescription());
     595                boolean removed = false;
     596                Transformation t = null;
     597                BioAssaySet bas = null;
     598                String prefix = "";
     599                ItemContext ccc = null;
     600                String view = "";
     601                String onClick = "";
     602                if (item.getType() == Item.TRANSFORMATION)
    563603                {
    564                   outlineIcon += "only.gif";
    565                 }
    566                 else if (isFirstChild)
    567                 {
    568                   outlineIcon += "top.gif";
    569                 }
    570                 else if (isLastChild)
    571                 {
    572                   outlineIcon += "bottom.gif";
     604                  t = (Transformation)item;
     605                  removed = t.isRemoved();
     606                  prefix = "T:";
     607                  ccc = tc;
     608                  view = "View this transformation (use CTRL, ALT or SHIFT to edit)";
     609                  onClick = "transformationOnClick";
    573610                }
    574611                else
    575612                {
    576                   outlineIcon += ".gif";
     613                  bas = (BioAssaySet)item;
     614                  removed = bas.isRemoved();
     615                  ccc = cc;
     616                  view = "View this bioassay set (use CTRL, ALT or SHIFT to edit)";
     617                  onClick = "bioAssaySetOnClick";
    577618                }
    578               }
    579               else
    580               {
    581                 docIcon = "folderclosed.gif";
    582                 outlineIcon = "join";
    583                 if (isLastChild)
    584                 {
    585                   outlineIcon += "bottom.gif";
    586                 }
    587                 else if (isFirstChild)
    588                 {
    589                   outlineIcon += "top.gif";
    590                 }
    591                 else
    592                 {
    593                   outlineIcon += ".gif";
    594                 }
    595               }
    596               %>
    597               <tbl:row
    598                 id="<%="row."+itemId%>"
    599                 >
    600                 <tbl:header
    601                   clazz="index"
    602                   ><%=index%></tbl:header>
    603                 <tbl:header
    604                   clazz="check"
    605                   visible="<%=mode.hasCheck()%>"
    606                   ><input
    607                       type="checkbox"
    608                       name="<%=itemId%>"
    609                       value="<%=itemId%>"
    610                       title="<%=name%>"
    611                       <%=cc.getSelected().contains(itemId) ? "checked" : ""%>
    612                     ></tbl:header>
    613                 <tbl:header
    614                   clazz="check"
    615                   visible="<%=mode.hasRadio()%>"
    616                   ><input
    617                       type="radio"
    618                       name="item_id"
    619                       value="<%=itemId%>"
    620                       title="<%=name%>"
    621                       <%=selectedItemId == itemId ? "checked" : ""%>
    622                     ></tbl:header>
    623                 <tbl:header
    624                   clazz="icons"
    625                   visible="<%=mode.hasIcons()%>"
    626                   ><base:icon
    627                     image="deleted.gif"
    628                     tooltip="This item has been scheduled for deletion"
    629                     visible="<%=item.isRemoved()%>"
    630                   />&nbsp;</tbl:header>
    631619               
    632                 <tbl:cell clazz="joustcell" column="name">
    633                   <div id="tree.<%=itemId%>" class="link" onclick="itemOnClick(event, <%=itemId%>)" title="View this bioassay set (use CTRL, ALT or SHIFT to edit)">
    634                     <img src="../../../images/joust/blank.gif" width="<%=level*18%>" height="1">
    635                     <img src="../../../images/joust/<%=outlineIcon%>">
    636                     <img src="../../../images/joust/<%=docIcon%>">
    637                     <%=name%>
    638                   </div>
    639                 </tbl:cell>
    640                 <tbl:cell column="spots"><%=item.getNumSpots()%></tbl:cell>
    641                 <tbl:cell column="reporters"><%=item.getNumReporters()%></tbl:cell>
    642                 <tbl:cell column="transformation"><base:propertyvalue item="<%=item%>" property="transformation.name" /></tbl:cell>
    643                 <tbl:cell column="date"><base:propertyvalue item="<%=item%>" property="transformation.job.ended" /></tbl:cell>
    644                 <tbl:cell column="plugin"><base:propertyvalue item="<%=item%>" property="transformation.job.pluginDefinition.name" /></tbl:cell>
    645                 <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
    646                 <tbl:cell column="tools">TODO</tbl:cell>
    647               </tbl:row>
    648               <%
     620                index++;
     621                numListed++;
     622
     623                %>
     624                <tbl:row
     625                  id="<%="row."+joustId%>"
     626                  >
     627                  <tbl:header
     628                    clazz="index"
     629                    ><%=index%></tbl:header>
     630                  <tbl:header
     631                    clazz="check"
     632                    visible="<%=mode.hasCheck()%>"
     633                    ><input
     634                        type="checkbox"
     635                        name="<%=prefix+itemId%>"
     636                        value="<%=itemId%>"
     637                        title="<%=name%>"
     638                        <%=ccc.getSelected().contains(itemId) ? "checked" : ""%>
     639                      ></tbl:header>
     640                  <tbl:header
     641                    clazz="check"
     642                    visible="<%=mode.hasRadio()%>"
     643                    ><input
     644                        type="radio"
     645                        name="item_id"
     646                        value="<%=itemId%>"
     647                        title="<%=name%>"
     648                        <%=selectedItemId == itemId ? "checked" : ""%>
     649                      ></tbl:header>
     650                  <tbl:header
     651                    clazz="icons"
     652                    visible="<%=mode.hasIcons()%>"
     653                    ><base:icon
     654                      image="deleted.gif"
     655                      tooltip="This item has been scheduled for deletion"
     656                      visible="<%=removed%>"
     657                    />&nbsp;</tbl:header>
     658                 
     659                  <tbl:cell clazz="joustcell" column="name">
     660                    <div id="tree.<%=joustId%>" class="link" onclick="<%=onClick%>(event, <%=itemId%>)" title="<%=view%>">
     661                      <%=name%>
     662                    </div>
     663                  </tbl:cell>
     664                  <tbl:cell column="spots"><%=bas == null ? "" : bas.getNumSpots()%></tbl:cell>
     665                  <tbl:cell column="reporters"><%=bas == null ? "" : bas.getNumReporters()%></tbl:cell>
     666                  <%
     667                  if (t != null)
     668                  {
     669                    %>
     670                    <tbl:cell column="date"><base:propertyvalue item="<%=t%>" property="job.ended" /></tbl:cell>
     671                    <tbl:cell column="plugin"><base:propertyvalue item="<%=t%>" property="job.pluginDefinition.name" /></tbl:cell>
     672                    <%
     673                  }
     674                  else
     675                  {
     676                    %>
     677                    <tbl:cell column="date">&nbsp;</tbl:cell>
     678                    <tbl:cell column="plugin">&nbsp;</tbl:cell>
     679                    <%
     680                  }
     681                  %>
     682                  <tbl:cell column="description"><%=description%></tbl:cell>
     683                  <tbl:cell column="tools">TODO</tbl:cell>
     684                </tbl:row>
     685                <%
    649686              }
    650687            }
Note: See TracChangeset for help on using the changeset viewer.