1 /*******************************************************************************
2 * Copyright (c) 2012-2013 University of Stuttgart.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * and the Apache License 2.0 which both accompany this distribution,
6 * and are available at http://www.eclipse.org/legal/epl-v10.html
7 * and http://www.apache.org/licenses/LICENSE-2.0
10 * Oliver Kopp - initial API and implementation and/or initial documentation
11 *******************************************************************************/
13 * This file contains supporting functions for the rendering a topology template
16 ["jsplumb", "winery-support-common"],
17 function (globdefa, wsc) {
21 initNodeTemplate: initNodeTemplate,
22 handleConnectionCreated: handleConnectionCreated,
23 imageError: imageError,
24 setReadOnly: setReadOnly
30 * @param nodeTemplateShape the set of node template shapes to initialize
31 * @param makeDraggable true if the nodeTemplates should be made draggable
33 function initNodeTemplate(nodeTemplateShapeSet, makeDraggable) {
35 jsPlumb.draggable(nodeTemplateShapeSet);
37 jsPlumb.makeTarget(nodeTemplateShapeSet, {
42 // this function is defined in index.jsp via jsp functions
43 // as it depends on the available relationship types
44 createConnectorEndpoints(nodeTemplateShapeSet);
46 nodeTemplateShapeSet.addClass("layoutableComponent");
48 nodeTemplateShapeSet.each(function(idx, s) {
51 var id = shape.attr("id");
54 var props = shape.children(".propertiesContainer")
59 props.find(".KVPropertyValue").editable();
62 // Deployment Artifacts
63 var fu = shape.children(".deploymentArtifactsContainer")
65 .children(".addnewartifacttemplate")
66 .children(".fileupload");
67 fu.attr("data-url", "nodetemplates/" + wsc.encodeId(id) + "/deploymentartifacts/");
70 // nodeTemplateShapeSet.children(".deploymentArtifactsContainer").children(".content").children(".deploymentArtifact").each(function(index, e) {
71 // addnewfileoverlay could be added here
77 * Handles the creation of connections by jsPlumb
79 * Also called if connection is created during loading
81 function handleConnectionCreated(data) {
82 // might be called directly from here or by the event
83 // if called by jsPlumb infrastructure, we have to get rid of the surrounding element
85 if (data.connection) {
86 conn = data.connection;
90 winery.debugConnData = conn;
93 winery.connections[id] = {
94 // we store the id to have a default for the id
96 // and use it also as starting point of a name
98 // we do NOT copy the plain type here
99 // type is stored in the connection
100 // type: .getType()[0]
101 // BUT: we copy the detailed ns and id
102 nsAndLocalName: wsc.getNamespaceAndLocalNameFromQName(conn.getType()[0])
104 putToolTipInfo(conn);
106 // we have to manually show and hide the tooltips as Bootstrap's tooltip plugin does not work after a connection was highlighted.
107 conn.bind("mouseenter", function(conn,e) {
108 putToolTipInfo(conn);
110 conn.bind("mouseexit", function(conn,e) {
111 $("div.tooltip").remove();
112 // we have to replace the tooltip as
113 putToolTipInfo(conn);
117 function putToolTipInfo(conn) {
118 // add tooltip showing the relationship type
119 var svgElement = $(conn.canvas);
120 // the title attribute is shown in the tooltip
121 // set the relationship type as tooltip
122 // we show the localname only
123 var nsAndLocalName = winery.connections[conn.id].nsAndLocalName;
124 // Vino4TOSCA: type in brackets
125 var title = "(" + nsAndLocalName.localname + ")";
126 svgElement.tooltip({title: title});
130 * Removes the image from the display. Used at images which could not be loaded
132 * Used via {@code <img onerror="imageError(this);" ... />}
134 function imageError(image) {
136 image.style.visibility = "hidden";
139 function setReadOnly() {