aboutsummaryrefslogtreecommitdiffstats
path: root/winery/org.eclipse.winery.topologymodeler/src/main/webapp/WEB-INF/tags/templates/relationshiptemplates/propertiesOfOneRelationshipTemplate.tag
blob: 8c63dcac81a0e69e23bbb2c2d2ba680edc9db1c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<%--
/*******************************************************************************
 * Copyright (c) 2012-2014 University of Stuttgart.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and the Apache License 2.0 which both accompany this distribution,
 * and are available at http://www.eclipse.org/legal/epl-v10.html
 * and http://www.apache.org/licenses/LICENSE-2.0
 *
 * Contributors:
 *    Oliver Kopp - initial API and implementation and/or initial documentation
 *******************************************************************************/
--%>
<%@tag language="java" pageEncoding="UTF-8" description="Renders the properies of one relationship tempate on the right"%>

<%@attribute name="relationshipTypes" required="true" type="java.util.Collection" %>
<%@attribute name="repositoryURL" required="true" type="java.lang.String" description="The repository URL"%>

<link rel="stylesheet" href="css/propertiesview.css" />

<%@taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="props" tagdir="/WEB-INF/tags/common/templates" %>
<%@taglib prefix="wc" uri="http://www.eclipse.org/winery/functions" %>

<div id="RTPropertiesView" class="propertiesView" style="display: none;">

	<div id="relationshipTemplateInformationSection">
		<fieldset>
			<div class="form-group">
				<label for="relationshiptemplateid">Id</label>
				<input id="relationshiptemplateid" disabled="disabled" class="form-control"></input>
			</div>
			<div class="form-group">
				<label for="relationshiptemplatename" class="control-label">Name</label>
				<a href="#" id="relationshiptemplatename" data-title="Name" data-type="text" class="form-control"></a>
			</div>
			<div class="form-group">
				<label for="relationshipType">Type</label>
				<%-- filled by showRTViewOnTheRight --%>
				<a id="relationshipType" target="_blank" href="#" class="form-control"></a>
			</div>
			<div class="form-group">
				<label for="RTreq" class="control-label">Requirement</label>
				<select id="RTreq" class="form-control">
				</select>
			</div>
			<div class="form-group">
				<label for="RTcap" class="control-label">Capability</label>
				<select id="RTcap" class="form-control">
				</select>
			</div>
		</fieldset>
	</div>

</div>

<script>

	var currentlySelectedConn = null;

	/**
	 * Fills the requirement and capabilities dropdowns with the available reqs and caps (which are defined at the source/target node template)
	 *
	 * @param conn the connection itself
	 * @param dataField = "req"|"cap"
	 * @param sourceDivClass = requirementsContainer | capabilitiesContainer
	 */
	function fillReqOrCap(conn, dataField, nodetemplateId, sourceDivClass, targetSelect) {
		var nt = $("#" + nodetemplateId);
		var reqsOrCaps = nt.children("." + sourceDivClass).children(".content").children(".reqorcap");
		var connReqCap = winery.connections[conn.id][dataField];

		targetSelect.empty();

		var optData = {
			value: "__NONE__",
			text: "(none)"
		};
		if (!connReqCap) {
			selected: true
		}
		require(["tmpl"], function(tmpl) {
			var newOption = tmpl("tmpl-option", optData);
			targetSelect.append(newOption);

			reqsOrCaps.each(function(i,e) {
				optData.value = $(e).children(".id").children("span.id").text();
				optData.text = $(e).children(".name").children("span.name").text();
				optData.selected = (optData.value == connReqCap);
				newOption = tmpl("tmpl-option", optData);
				targetSelect.append(newOption);
			});
		});

		targetSelect.off("change");
		targetSelect.on("change", function(e) {
			var val = targetSelect.val();
			if (val == "__NONE__") {
				delete(winery.connections[conn.id][dataField]);
			} else {
				winery.connections[conn.id][dataField] = val;
			}
		});
	}

	function fillType(nsAndLocalName) {
		require(["winery-support-common"], function(wsc) {
			var href = wsc.makeRelationshipTypeURLFromNSAndLocalName("${repositoryURL}", nsAndLocalName);
			// localname is always the name of the relationship type because the specification requires a "name" attribute only and does not foresee an "id" attribute
			$("#relationshipType").attr("href", href).text(nsAndLocalName.localname);
		})
	}

	function displayProperties(connData) {
		$("#RTPropertiesView").append(connData.propertiesContainer);
	}

	/**
	 * @param conn the jsPlumb connection
	 */
	function showRTViewOnTheRight(conn) {
		currentlySelectedConn = conn;

		$("#RTPropertiesView").fadeIn();

		$("#relationshiptemplateid").val(winery.connections[conn.id].id);
		$("#relationshiptemplatename").editable('setValue', winery.connections[conn.id].name);
		fillReqOrCap(conn, "req", conn.sourceId, "requirementsContainer", $("#RTreq"));
		fillReqOrCap(conn, "cap", conn.targetId, "capabilitiesContainer", $("#RTcap"));
		fillType(winery.connections[conn.id].nsAndLocalName);
		displayProperties(winery.connections[conn.id]);
	}

	function hideRTViewOnTheRight() {
		if (currentlySelectedConn == null) {
			// nothing to do if no relationship template is selected
			return;
		}

		$("#RTPropertiesView").fadeOut();

		// user will see some flickering here, but we don't want to set timers -> could lead to race conditions
		$("#skelettonContainerForRelationshipTemplates").append(winery.connections[currentlySelectedConn.id].propertiesContainer);
		currentlySelectedConn = null;
	}

	function storeUpdatedName(newName) {
		currentlySelectedConn.name = newName;
	}

	$(function() {
		$("#relationshiptemplatename").editable({
			success: function(response, newValue) {
				currentlySelectedConn.name = newValue;
			}
		});
	});

	function unselectAllConnections() {
		jsPlumb.select().each(function(connection) {
			connection.removeType("selected");
		});
	}

	winery.events.register(
		winery.events.name.SELECTION_CHANGED,
		function() {
			var nodeTemplate = $("div.NodeTemplateShape.selected");
			var numSelected = nodeTemplate.length;
			if (numSelected != 0) {
				// if node templates are selected, no RT properties should be shown
				hideRTViewOnTheRight();

				unselectAllConnections();
			}
		}
	);

</script>