4cc6f0ae9cc05b53e2290cde327fce388b3ce3f1
[vfc/nfvo/wfengine.git] / winery / org.eclipse.winery.topologymodeler / src / main / webapp / WEB-INF / tags / common / templates / properties.tag
1 <%--
2 /*******************************************************************************
3  * Copyright (c) 2012-2013 University of Stuttgart.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * and the Apache License 2.0 which both accompany this distribution,
7  * and are available at http://www.eclipse.org/legal/epl-v10.html
8  * and http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Contributors:
11  *    Oliver Kopp - initial API and implementation and/or initial documentation
12  *******************************************************************************/
13 --%>
14 <%@tag description="Rendering for properties. A separate CSS has to be provided to style the content. Thus, this tag is reusable both in the topology modeler and in the management UI. Requires global javaScript function editPropertiesXML(visualElementId)" pageEncoding="UTF-8"%>
15 <%@taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core"%>
16
17 <%@attribute name="propertiesDefinition" required="true" type="org.eclipse.winery.model.tosca.TEntityType.PropertiesDefinition" description="The TOSCA-conforming properties definition. May be null."%>
18 <%@attribute name="wpd" required="true" type="org.eclipse.winery.common.propertydefinitionkv.WinerysPropertiesDefinition" description="Winery's K/V properties definition. May be null"%>
19 <%@attribute name="template" required="true" type="org.eclipse.winery.model.tosca.TEntityTemplate" description="The template to display properties. Has to be null in case of the palette mode of the topology modeler"%>
20 <%@attribute name="pathToImages" required="true" description="The path (URI path) to the image/ url, where xml.png is available. Has to end with '/'"%>
21
22 <%@tag import="org.eclipse.winery.common.ModelUtilities"%>
23 <%@tag import="org.eclipse.winery.common.propertydefinitionkv.WinerysPropertiesDefinition"%>
24 <%@tag import="org.eclipse.winery.common.propertydefinitionkv.PropertyDefinitionKV"%>
25 <%@tag import="org.eclipse.winery.common.propertydefinitionkv.PropertyDefinitionKVList"%>
26
27 <%
28 if ((propertiesDefinition != null) || (wpd != null)) {
29 // properties exist
30 %>
31         <div class="propertiesContainer">
32                 <div class="header">Properties</div>
33                 <div class="content">
34                         <%
35                         if (wpd == null) {
36                                 // no winery's special properties definition, but "normal" TOSCA properties definition
37
38                                 if (propertiesDefinition.getType() != null) {
39                         %>
40                                         <span class="properties_type">XSD Type: <%=propertiesDefinition.getType()%></span>
41                                 <%
42                                 } else {
43                                 %>
44                                         <span class="properties_element">XSD Element: <%=propertiesDefinition.getElement()%></span>
45                                 <%
46                                 }
47                                 %>
48                                 <textarea class="properties_xml"><%
49                                 if (template != null) {
50                                 %><%=org.eclipse.winery.common.Util.getXMLAsString(org.eclipse.winery.model.tosca.TEntityTemplate.Properties.class, template.getProperties())%><%
51                                 }
52                                 %></textarea>
53                                 <%-- We have to do use $(this).parent().parent().parent().attr('id') instead of <%=visualElementId%> as on drag'n'drop from the palette, this binding is NOT changed, but the Id changes --> the user does NOT want to edit the properties from the palette entry, but from the node template --%>
54                                 <button class="btn btn-default" onclick="editPropertiesXML($(this).parent().parent().parent().attr('id'));"><img src="${pathToImages}xml.png"></img>View</button>
55                         <%
56                         } else {
57                                 // Winery special mode
58                                 java.util.Properties props;
59                                 if (template == null) {
60                                         // setting null only because of dump compiler.
61                                         // We never read props if in paletteMode
62                                         props = null;
63                                 } else {
64                                         props = ModelUtilities.getPropertiesKV(template);
65                                 }
66                         %>
67                                 <%-- stores wrapper element name and namespace to ease serialization--%>
68                                 <span class="elementName"><%=wpd.getElementName()%></span>
69                                 <span class="namespace"><%=wpd.getNamespace()%></span>
70                                 <table>
71                                 <%
72                                 PropertyDefinitionKVList list = wpd.getPropertyDefinitionKVList();
73                                 if (list != null) {
74                                         // iterate on all defined properties
75                                         for (PropertyDefinitionKV propdef: list) {
76                                                 String key = propdef.getKey();
77                                                 String value;
78                                                 if (template == null) {
79                                                         value = "";
80                                                 } else {
81                                                         // assign value, but change "null" to "" if no property is defined
82                                                         if ((value = props.getProperty(key)) == null) {
83                                                                 value = "";
84                                                         }
85                                                 }
86                                 %>
87                                                 <tr class="KVProperty">
88                                                         <td><span class="<%= key %> KVPropertyKey"><%= key %></span></td>
89                                                         <td><a class="KVPropertyValue" href="#" data-type="text" data-title="Enter <%= key %>"><%=value %></a></td>
90                                                 </tr>
91                                 <%
92                                         }
93                                 }
94                                 %>
95                                 </table>
96                         <%
97                         }
98                         %>
99                 </div>
100         </div>
101 <%
102 }
103 %>