2 /*******************************************************************************
3 * Copyright (c) 2013 Pascal Hirmer.
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
11 * Pascal Hirmer - initial API and implementation
12 *******************************************************************************/
15 <%@tag language="java" pageEncoding="UTF-8" description="This tag is used to render Relationship Templates for selection in a dialog."%>
17 <%-- attributes for the topology selection --%>
18 <%@attribute name="templateURL" type="java.lang.String"%>
19 <%@attribute name="topologyName" type="java.lang.String"%>
20 <%@attribute name="topologyNamespace" type="java.lang.String"%>
21 <%@attribute name="repositoryURL" type="java.lang.String" %>
22 <%@attribute name="stName" type="java.lang.String" %>
23 <%@attribute name="choices" type="java.util.List<org.eclipse.winery.model.tosca.TEntityTemplate>"%>
25 <%@tag import="java.util.ArrayList"%>
26 <%@tag import="java.util.HashMap"%>
27 <%@tag import="java.util.List"%>
28 <%@tag import="java.util.Map"%>
29 <%@tag import="java.util.UUID"%>
30 <%@tag import="javax.xml.namespace.QName"%>
31 <%@tag import="org.eclipse.winery.model.tosca.TEntityTemplate"%>
32 <%@tag import="org.eclipse.winery.model.tosca.TNodeTemplate"%>
33 <%@tag import="org.eclipse.winery.model.tosca.TRelationshipTemplate"%>
34 <%@tag import="org.eclipse.winery.model.tosca.TRelationshipType"%>
35 <%@tag import="org.eclipse.winery.repository.client.WineryRepositoryClientFactory"%>
36 <%@tag import="org.eclipse.winery.repository.client.IWineryRepositoryClient"%>
37 <%@tag import="org.eclipse.winery.common.Util"%>
39 <%@taglib prefix="ntrq" tagdir="/WEB-INF/tags/common/templates/nodetemplates/reqscaps" %>
40 <%@taglib prefix="nt" tagdir="/WEB-INF/tags/common/templates/nodetemplates" %>
41 <%@taglib prefix="tc" tagdir="/WEB-INF/tags/common/topologycompletion"%>
43 <div id="relationshipTemplateSelector">
44 <p> There are several possible Relationship Templates for a connection. <br> Please select your desired connection(s): </p>
46 // save all created connections in an array to be able to detach them after the selection
47 Connections = new Array();
50 // the pixel distance between the displayed NodeTemplates
51 final int NODE_TEMPLATE_DISTANCE = 150;
53 IWineryRepositoryClient client = WineryRepositoryClientFactory.getWineryRepositoryClient();
54 client.addRepository(repositoryURL);
56 Map<String, String> idMap = new HashMap<String, String>();
60 // used for the position of the NodeTemplate in the EditorArea
63 List<TRelationshipTemplate> possibleConnections = new ArrayList<TRelationshipTemplate>();
65 for (TEntityTemplate choice: choices) {
66 if (choice instanceof TRelationshipTemplate) {
67 possibleConnections.add((TRelationshipTemplate) choice);
70 for (TRelationshipTemplate connector: possibleConnections) { %>
71 <div id="proposalEditorArea">
72 <div id="proposaldrawingarea">
73 <div id="allRelationships">
77 for (TEntityTemplate choice: choices) {
78 if (choice instanceof TNodeTemplate) {
79 TNodeTemplate nodeTemplate = (TNodeTemplate) choice;
81 topCounter = topCounter + NODE_TEMPLATE_DISTANCE;
83 <nt:nodeTemplateRenderer client="<%=client%>" relationshipTypes="<%=client.getAllTypes(TRelationshipType.class)%>" repositoryURL='<%=repositoryURL%>' nodeTemplate="<%=nodeTemplate%>" top="<%=Integer.toString(topCounter)%>" left='<%="0"%>'/>
87 String randomId = UUID.randomUUID().toString();
89 document.getElementById("<%=nodeTemplate.getId()%>").id = "<%=randomId%>";
91 idMap.put(nodeTemplate.getId(), randomId);
98 sourceId = ((TNodeTemplate) connector.getSourceElement().getRef()).getId();
99 String targetId = ((TNodeTemplate) connector.getTargetElement().getRef()).getId();
100 QName type = connector.getType();
102 String visualSourceId = idMap.get(sourceId);
103 String visualTargetId = idMap.get(targetId);
106 // connect the rendered NodeTemplates
107 require(["winery-common-topologyrendering"], function(wct) {
108 wct.initNodeTemplate(jsPlumb.getSelector(".NodeTemplateShape:not('.hidden')"), true);
111 require(["jsplumb"], function(_jsPlumb) {
112 _jsPlumb.ready(function() {
113 c = _jsPlumb.connect({
114 source:"<%=visualSourceId%>",
115 target:"<%=visualTargetId%>",
126 <input id="<%=id%>" name="<%=id%>" type="checkbox" value="<%=connector.getName()%>"> <%=connector.getName()%> <br>
129 <button type="button" class="btn btn-primary btn-default" id="btnUseSelection" onclick="useRelationshipTemplateSelection()">Use Selection</button>
131 function useRelationshipTemplateSelection() {
132 // add the selected RelationshipTemplates to the topology and restart the completion
133 SelectedItems = new Array();
134 for (var i= 0; i < document.getElementById("rtchoices").children[0].choice.length; i++) {
135 if (document.getElementById("rtchoices").children[0].choice[i].checked == true) {
136 SelectedItems.push(document.getElementById("rtchoices").children[0].choice[i].value);
140 if (SelectedItems.length == 0) {
141 vShowError("Please selected at least one Relationship Template.");
143 $('#chooseRelationshipTemplateDiag').modal('hide');
144 var selectedRelationshipTemplates = JSON.stringify(SelectedItems);
145 // add selected RelationshipTemplate(s) to the topology
146 $.post("jsp/topologyCompletion/selectionHandler.jsp", {topology: topology, allChoices: choices, selectedRelationshipTemplates: selectedRelationshipTemplates},
148 require(["winery-topologycompletion"], function(completer) {
149 completer.restartCompletion(data, document.getElementById('overwriteTopology').checked,document.getElementById('openInNewWindow').checked,
150 topologyName, topologyNamespace, true, "<%=stName%>",
151 "<%=templateURL%>", "<%=repositoryURL%>");