source: trunk/www/common/anytoany/list_anytoany.jsp @ 7604

Last change on this file since 7604 was 7604, checked in by Nicklas Nordborg, 4 years ago

References #2151: Pre-compile all JSP pages before releases

Getting rid of rawtypes warnings. Most of them are relatively simple by adding a type parameter.

Utility functions that are used with generics are typically a bit harder.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 8.6 KB
Line 
1<%-- $Id: list_anytoany.jsp 7604 2019-02-25 12:19:50Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Nicklas Nordborg
4
5  This file is part of BASE - BioArray Software Environment.
6  Available at http://base.thep.lu.se/
7
8  BASE is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License
10  as published by the Free Software Foundation; either version 3
11  of the License, or (at your option) any later version.
12
13  BASE is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with BASE. If not, see <http://www.gnu.org/licenses/>.
20  ------------------------------------------------------------------
21
22  @author Nicklas
23  @version 2.0
24--%>
25<%@ page pageEncoding="UTF-8" session="false"
26  import="net.sf.basedb.core.SessionControl"
27  import="net.sf.basedb.core.DbControl"
28  import="net.sf.basedb.core.Item"
29  import="net.sf.basedb.core.Permission"
30  import="net.sf.basedb.core.BasicItem"
31  import="net.sf.basedb.core.AnyToAny"
32  import="net.sf.basedb.core.Nameable"
33  import="net.sf.basedb.core.ItemSubtype"
34  import="net.sf.basedb.core.Subtypable"
35  import="net.sf.basedb.core.Removable"
36  import="net.sf.basedb.core.File"
37  import="net.sf.basedb.core.ItemQuery"
38  import="net.sf.basedb.core.ItemContext"
39  import="net.sf.basedb.core.ItemResultList"
40  import="net.sf.basedb.core.PermissionDeniedException"
41  import="net.sf.basedb.core.ItemNotFoundException"
42  import="net.sf.basedb.core.query.Orders"
43  import="net.sf.basedb.core.query.Hql"
44  import="net.sf.basedb.core.plugin.GuiContext"
45  import="net.sf.basedb.util.Values"
46  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
47  import="net.sf.basedb.clients.web.Base"
48  import="net.sf.basedb.clients.web.util.HTML"
49  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
50  import="net.sf.basedb.clients.web.extensions.JspContext"
51  import="net.sf.basedb.clients.web.extensions.toolbar.ButtonAction" 
52  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
53  import="net.sf.basedb.clients.web.extensions.list.ListColumnAction"
54  import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil"
55  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
56  import="java.util.List"
57%>
58<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
59<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
60<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
61<%
62String root = request.getContextPath() + "/";
63final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
64final String ID = sc.getId();
65final Item itemType = Item.valueOf(request.getParameter("item_type"));
66final int itemId = Values.getInt(request.getParameter("item_id"));
67final float scale = Base.getScale(sc);
68final DbControl dc = sc.newDbControl();
69final ItemContext cc = sc.getCurrentContext(itemType);
70String title = Values.getString(request.getParameter("title"), "Related items");
71
72try
73{
74  final BasicItem item = itemType.getById(dc, itemId);
75  final boolean createPermission = item.hasPermission(Permission.WRITE);
76  final boolean deletePermission = createPermission;
77 
78  ItemQuery<AnyToAny> query = AnyToAny.getLinksFrom(item);
79  query.order(Orders.asc(Hql.property("name")));
80  ItemResultList<AnyToAny> links = query.list(dc);
81  long count = links.getTotalCount();
82 
83  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, new GuiContext(Item.ANYTOANY, GuiContext.Type.LIST), item);
84  ExtensionsInvoker<ButtonAction> invoker = ToolbarUtil.useExtensions(jspContext);
85  ExtensionsInvoker<ListColumnAction<AnyToAny,?>> columnsInvoker = ListColumnUtil.useExtensions(jspContext);
86  %>
87  <base:page type="include">
88  <base:head scripts="/common/anytoany/list.js" />
89  <base:body>
90    <base:section 
91      id="anytoany" 
92      title="<%=title + " (" + (count) +")"%>"
93      context="<%=cc%>">
94
95        <tbl:table
96          id="links"
97          columns="all"
98          sc="<%=sc%>"
99          action="<%=root + "common/anytoany/index.jsp"%>"
100          >
101          <tbl:columndef 
102            id="name"
103            title="Name"
104          />
105          <tbl:columndef 
106            id="item"
107            title="Item"
108          />
109          <tbl:columndef 
110            id="description"
111            title="Description"
112          />
113          <tbl:columndef 
114            id="xt-columns" 
115            extensions="<%=columnsInvoker%>" 
116            jspcontext="<%=jspContext%>" 
117          />
118          <tbl:toolbar
119            subclass="topborder leftborder rightborder bg-filled-50"
120            >
121            <tbl:button 
122              id="btnNewLink"
123              disabled="<%=!createPermission%>" 
124              image="add.png" 
125              title="Add link&hellip;" 
126              tooltip="<%=createPermission ? "Create new link" : "You do not have permission to create links"%>" 
127              data-item-type="ANYTOANY"
128              data-extra-url="<%="&from_type="+itemType.name() + "&from_id="+itemId %>"
129            />
130            <tbl:button 
131              id="btnUnlinkItems"
132              image="delete_permanently.png"
133              title="Unlink&hellip;" 
134              tooltip="Unlink the selected items"
135              visible="<%=count > 0 %>"
136              disabled="<%=!deletePermission%>"
137            />
138            <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
139              wrapper="<%=new PrefixSuffixRenderer<ButtonAction>(jspContext, "<td>", "</td>") %>"/>
140          </tbl:toolbar>
141          <tbl:data>
142            <tbl:headers style="<%=links.size() == 0 ? "display: none;" : "" %>">
143              <tbl:headerrow>
144              <tbl:header subclass="index" />
145              <tbl:header 
146                subclass="check"
147                ><base:icon 
148                  subclass="link table-check"
149                  image="check_uncheck.png" 
150                  tooltip="Toggle all (use CTRL, ALT or SHIFT to check/uncheck)" 
151                /></tbl:header>
152                <tbl:columnheaders />
153              </tbl:headerrow>
154            </tbl:headers>
155            <tbl:rows>
156            <%
157            int index = 0;
158            for (AnyToAny ata : links)
159            {
160              index++;
161              String name = HTML.encodeTags(ata.getName());
162              int ataId = ata.getId();
163              BasicItem to = null;
164              String subtype = ata.getToType().toString();
165              boolean readTo = true;
166              boolean missingTo = false;
167              try
168              {
169                to = ata.getTo();
170              }
171              catch (PermissionDeniedException ex)
172              {
173                readTo = false;
174              }
175              catch (ItemNotFoundException ex)
176              {
177                missingTo = true;
178              }
179             
180              String toLink = "";
181              if (to instanceof File)
182              {
183                File toFile = (File)to;
184                toLink = Base.getLinkedFile(ID, toFile, false, true, true, root);
185              }
186              else if (to instanceof Nameable)
187              {
188                Nameable nameable = (Nameable)to;
189                toLink = Base.getLinkedName(ID, nameable, false, true);
190              }
191              else if (!readTo)
192              {
193                toLink = "<i>- denied -</i>";
194              }
195              else if (missingTo)
196              {
197                toLink = "<i>- missing -</i> (" + ata.getToType().toString() + "; id=" + ata.getToId() + ")";
198              }
199              else if (to == null)
200              {
201                toLink = "<i>- none -</i>";
202              }
203              else
204              {
205                toLink = Base.getLink(ID, to.toString(), to.getType(), to.getId(), true);
206              }
207              if (to instanceof Subtypable)
208              {
209                try
210                {
211                  ItemSubtype st = ((Subtypable)to).getItemSubtype();
212                  if (st != null) subtype = st.getName();
213                }
214                catch (RuntimeException ex)
215                {}
216              }
217              boolean isRemoved = false;
218              if (to instanceof Removable)
219              {
220                isRemoved = ((Removable)to).isRemoved();
221              }
222              toLink += " <span class=\"itemsubtype\">("+HTML.encodeTags(subtype)+")</span>";
223              %>
224              <tbl:row>
225                <tbl:header 
226                  clazz="index"
227                  ><%=index%></tbl:header>
228                <tbl:header 
229                  clazz="check" 
230                  ><input 
231                    type="checkbox" 
232                    name="<%=ataId%>" 
233                    value="<%=ataId%>" 
234                    title="<%=name%>"
235                  ></tbl:header>
236                <tbl:cell column="name"><%=Base.getLinkedName(ID, ata, false, true)%></tbl:cell>
237                <tbl:cell column="item"><base:icon image="deleted.png"
238                  tooltip="This item has been scheduled for deletion"
239                  visible="<%=isRemoved%>" />
240                  <%=toLink%></tbl:cell>
241                <tbl:cell column="description"><%=HTML.niceFormat(ata.getDescription())%></tbl:cell>
242                <tbl:xt-cells dc="<%=dc%>" item="<%=ata%>">
243                  <tbl:cell column="xt-columns" />
244                </tbl:xt-cells>
245              </tbl:row>
246              <%
247            }
248            if (count == 0)
249            {
250              %>
251              <tbl:panel>
252                There are no other items related to this
253                <%=itemType.toString().toLowerCase() %>.
254              </tbl:panel>
255              <%
256            }
257            %>
258            </tbl:rows>
259          </tbl:data>
260        </tbl:table>
261    </base:section>
262  </base:body>
263  </base:page>
264  <%
265}
266finally
267{
268  if (dc != null) dc.close();
269}
270
271%>
Note: See TracBrowser for help on using the repository browser.