aboutsummaryrefslogtreecommitdiffstats
path: root/winery/org.eclipse.winery.repository/src/main/webapp/js
diff options
context:
space:
mode:
authorhuangjian <huang.jian12@zte.com.cn>2016-08-31 16:47:33 +0800
committerhuangjian <huang.jian12@zte.com.cn>2016-08-31 16:47:33 +0800
commitfa49e78cc199526a9e33b59c5194f8e3bf0f0952 (patch)
tree3478e867a8f304266dbceca6e992cceca410ede4 /winery/org.eclipse.winery.repository/src/main/webapp/js
parent159d40f0011559c8f82338b29dca1bffd700f2c8 (diff)
Add winery source code
Change-Id: I1c5088121d79b71098c3cba1996c6f784737532e Issue-id: TOSCA-49 Signed-off-by: huangjian <huang.jian12@zte.com.cn>
Diffstat (limited to 'winery/org.eclipse.winery.repository/src/main/webapp/js')
-rw-r--r--winery/org.eclipse.winery.repository/src/main/webapp/js/.gitignore3
-rw-r--r--winery/org.eclipse.winery.repository/src/main/webapp/js/boundaryDefinitionsXSelection.js96
-rw-r--r--winery/org.eclipse.winery.repository/src/main/webapp/js/jquery.fileupload-audio.js12
-rw-r--r--winery/org.eclipse.winery.repository/src/main/webapp/js/jquery.fileupload-image.js12
-rw-r--r--winery/org.eclipse.winery.repository/src/main/webapp/js/jquery.fileupload-validate.js12
-rw-r--r--winery/org.eclipse.winery.repository/src/main/webapp/js/jquery.fileupload-video.js12
-rw-r--r--winery/org.eclipse.winery.repository/src/main/webapp/js/nextselect.js144
-rw-r--r--winery/org.eclipse.winery.repository/src/main/webapp/js/winery-support-non-AMD.js223
-rw-r--r--winery/org.eclipse.winery.repository/src/main/webapp/js/winery-support.js112
9 files changed, 626 insertions, 0 deletions
diff --git a/winery/org.eclipse.winery.repository/src/main/webapp/js/.gitignore b/winery/org.eclipse.winery.repository/src/main/webapp/js/.gitignore
new file mode 100644
index 0000000..23c1477
--- /dev/null
+++ b/winery/org.eclipse.winery.repository/src/main/webapp/js/.gitignore
@@ -0,0 +1,3 @@
+# copied from topology modeler at mvn generate-sources
+winery-common-topologyrendering.js
+winery-support-common.js \ No newline at end of file
diff --git a/winery/org.eclipse.winery.repository/src/main/webapp/js/boundaryDefinitionsXSelection.js b/winery/org.eclipse.winery.repository/src/main/webapp/js/boundaryDefinitionsXSelection.js
new file mode 100644
index 0000000..afefc8c
--- /dev/null
+++ b/winery/org.eclipse.winery.repository/src/main/webapp/js/boundaryDefinitionsXSelection.js
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ * Tobias Binz - communication with the parent window
+ *******************************************************************************/
+
+ /**
+ * Called from the renderer as soon as the whole topology is loaded
+ */
+ function wineryViewExternalScriptOnLoad() {
+
+ function getIdOfNodeTemplateShape(element) {
+ var nodeTemplate = element.closest("div.NodeTemplateShape");
+ var id = nodeTemplate.children("div.headerContainer").children("div.id").text();
+ return id;
+ }
+
+ jsPlumb.bind("ready", function() {
+ jsPlumb.bind("click", function(conn, originalEvent) {
+ var id = winery.connections[conn.id].id;
+ var message = {
+ targetRelationshipTemplateRef: id
+ }
+ sendMessage(message);
+ });
+ });
+
+
+ $("div.NodeTemplateShape").on("click", function(e) {
+ var id = getIdOfNodeTemplateShape($(e.target));
+ // send id and empty property as no property has been clicked
+ var message = {
+ targetObjectRef: id,
+ targetPropertyRef: ""
+ };
+ sendMessage(message);
+
+ return false;
+ });
+
+ $("tr.KVProperty").on("click", function(e) {
+ var trKVProperty = $(e.target).closest("tr.KVProperty");
+ var key = trKVProperty.children("td").children("span.KVPropertyKey").text();
+
+ var content = trKVProperty.closest("div.content");
+ var elementName = content.children("span.elementName").text();
+
+ // form namespace-unaware XPath
+ var xpath = "/*[local-name()='" + elementName + "']/*[local-name()='" + key + "']";
+
+ var message = {
+ targetPropertyRef: xpath,
+ targetObjectRef: getIdOfNodeTemplateShape(trKVProperty)
+ };
+ sendMessage(message);
+
+ // do not trigger click on NodeTemplateShape -> we included both values in the message
+ return false;
+ });
+
+ $("div.requirements").on("click", function(e) {
+ var reqorcap = $(e.target).closest("div.requirements");
+ var id = reqorcap.children("div.id").text();
+
+ var message = {
+ reqRef: id
+ };
+ sendMessage(message);
+
+ return false;
+ });
+
+ $("div.capabilities").on("click", function(e) {
+ var reqorcap = $(e.target).closest("div.capabilities");
+ var id = reqorcap.children("div.id").text();
+
+ var message = {
+ capRef: id
+ };
+ sendMessage(message);
+
+ return false;
+ });
+
+ }
+
+function sendMessage(message) {
+ window.parent.postMessage(message, "*");
+}
diff --git a/winery/org.eclipse.winery.repository/src/main/webapp/js/jquery.fileupload-audio.js b/winery/org.eclipse.winery.repository/src/main/webapp/js/jquery.fileupload-audio.js
new file mode 100644
index 0000000..9b68349
--- /dev/null
+++ b/winery/org.eclipse.winery.repository/src/main/webapp/js/jquery.fileupload-audio.js
@@ -0,0 +1,12 @@
+/*******************************************************************************
+ * Copyright (c) 2012-2013 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
+ *******************************************************************************/
+// dummy as we don't need the functionality, but jquery.fileupload-ui.js requires it \ No newline at end of file
diff --git a/winery/org.eclipse.winery.repository/src/main/webapp/js/jquery.fileupload-image.js b/winery/org.eclipse.winery.repository/src/main/webapp/js/jquery.fileupload-image.js
new file mode 100644
index 0000000..9b68349
--- /dev/null
+++ b/winery/org.eclipse.winery.repository/src/main/webapp/js/jquery.fileupload-image.js
@@ -0,0 +1,12 @@
+/*******************************************************************************
+ * Copyright (c) 2012-2013 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
+ *******************************************************************************/
+// dummy as we don't need the functionality, but jquery.fileupload-ui.js requires it \ No newline at end of file
diff --git a/winery/org.eclipse.winery.repository/src/main/webapp/js/jquery.fileupload-validate.js b/winery/org.eclipse.winery.repository/src/main/webapp/js/jquery.fileupload-validate.js
new file mode 100644
index 0000000..9b68349
--- /dev/null
+++ b/winery/org.eclipse.winery.repository/src/main/webapp/js/jquery.fileupload-validate.js
@@ -0,0 +1,12 @@
+/*******************************************************************************
+ * Copyright (c) 2012-2013 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
+ *******************************************************************************/
+// dummy as we don't need the functionality, but jquery.fileupload-ui.js requires it \ No newline at end of file
diff --git a/winery/org.eclipse.winery.repository/src/main/webapp/js/jquery.fileupload-video.js b/winery/org.eclipse.winery.repository/src/main/webapp/js/jquery.fileupload-video.js
new file mode 100644
index 0000000..9b68349
--- /dev/null
+++ b/winery/org.eclipse.winery.repository/src/main/webapp/js/jquery.fileupload-video.js
@@ -0,0 +1,12 @@
+/*******************************************************************************
+ * Copyright (c) 2012-2013 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
+ *******************************************************************************/
+// dummy as we don't need the functionality, but jquery.fileupload-ui.js requires it \ No newline at end of file
diff --git a/winery/org.eclipse.winery.repository/src/main/webapp/js/nextselect.js b/winery/org.eclipse.winery.repository/src/main/webapp/js/nextselect.js
new file mode 100644
index 0000000..050fcb1
--- /dev/null
+++ b/winery/org.eclipse.winery.repository/src/main/webapp/js/nextselect.js
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * Copyright (c) 2012-2013 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
+ *******************************************************************************/
+/*
+
+Script for dependent selection boxes.
+
+One object for stating a map from value to content. The value is globally unique.
+
+Verbose example:
+<script>
+
+var WSDLoperationsData = {
+ "ns1" : {
+ "options" : ["ns1:pt11", "ns1:pt12"],
+ },
+
+ "ns2" : {
+ "options" : ["ns2:pt21"],
+ },
+
+ "ns3" : {
+ "options" : ["ns3:pt31"],
+ },
+
+ "ns1:pt11" : {
+ "label" : "PortType 1.1",
+ "options" : ["ns1:pt11:op111", "ns1:pt11:op112"]
+ },
+
+ "ns1:pt12" : {
+ "label" : "PortType 1.2",
+ "options" : ["ns1:pt12:op113", "ns1:pt11:op114"]
+ },
+
+
+ "ns2:pt21" : {
+ "label" : "PortType 2.1",
+ "options" : ["ns2:pt21:op211", "ns2:pt21:op212"]
+ },
+
+
+ "ns3:pt31" : {
+ "label" : "PortType 3.1",
+ "options" : ["ns3:pt31:op311", "ns3:pt31:op312"]
+ },
+
+
+ "ns1:pt11:op111" : {
+ "label" : "operation 1.1.1",
+ },
+
+ "ns1:pt11:op112" : {
+ "label" : "operation 1.1.2",
+ },
+
+ "ns1:pt12:op113" : {
+ "label" : "operation 1.1.3",
+ },
+
+ "ns1:pt12:op114" : {
+ "label" : "operation 1.1.4",
+ },
+
+ "ns2:pt21:op211" : {
+ "label" : "operation 2.1.1",
+ },
+
+ "ns2:pt21:op212" : {
+ "label" : "operation 2.1.2",
+ },
+
+ "ns3:pt31:op311" : {
+ "label" : "operation 3.1.1",
+ },
+
+ "ns3:pt31:op312" : {
+ "label" : "operation 3.1.2",
+ }
+}
+
+var WSDLdependendSelects = {
+ "#portTypes" : "#operations"
+}
+</script>
+
+<select size="15" onchange="updateListContent(this.value, '#portTypes', WSDLdependendSelects, WSDLoperationsData);" >
+ <option value="ns1" selected="true" >Namespace1</option>
+ <option value="ns2" >Namespace2</option>
+ <option value="ns3" >Namespace3</option>
+</select>
+
+<select id="portTypes" size="15" onchange="updateListContent(this.value, '#operations', WSDLdependendSelects, WSDLoperationsData);">
+ <option value="ns1:pt11" selected="true">PortType1.1</option>
+ <option value="ns1:pt11">PortType1.2</option>
+</select>
+
+<select id="operations" size="15">
+ <option value="ns1:pt11:op111" selected="true">op1.1.2</option>
+ <option value="ns1:pt12:op112">op1.1.2</option>
+ <option value="ns1:pt13:op113">op1.1.2</option>
+</select>
+
+ */
+
+/**
+ *
+ * @param value the current selected value
+ * @param targetElement the select to update
+ * @param dependendSelects the data structure for subsequently dependent select elements
+ * @param completeData the data structure with the complete data
+ */
+function updateListContent(value, targetElement, dependendSelects, completeData) {
+ jQuery(targetElement).empty();
+ var listData = completeData[value];
+ if (listData !== undefined) {
+ for (var i=0; i < listData.options.length; i++) {
+ var optionName = listData.options[i];
+ var label = completeData[optionName].label;
+ var selected;
+ if (i == 0) {
+ selected = ' selected="selected"';
+ } else {
+ selected = '';
+ }
+ var toAppend = '<option value="' + optionName + '"' + selected + '>' + label + '</option>';
+ jQuery(targetElement).append(toAppend);
+ }
+ nextSelect = dependendSelects[targetElement];
+ if (nextSelect !== undefined) {
+ // We assume listData is not empty
+ updateListContent(listData.options[0], nextSelect, dependendSelects, completeData);
+ }
+ }
+ jQuery(targetElement).trigger("change");
+}
diff --git a/winery/org.eclipse.winery.repository/src/main/webapp/js/winery-support-non-AMD.js b/winery/org.eclipse.winery.repository/src/main/webapp/js/winery-support-non-AMD.js
new file mode 100644
index 0000000..f1f1cfa
--- /dev/null
+++ b/winery/org.eclipse.winery.repository/src/main/webapp/js/winery-support-non-AMD.js
@@ -0,0 +1,223 @@
+/*******************************************************************************
+ * Copyright (c) 2012-2013 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
+ *******************************************************************************/
+
+function addResourceInstance() {
+ if (highlightRequiredFields()) {
+ vShowError("Please fill in all required fields");
+ return;
+ }
+
+ var dataToSend = $('#createResourceForm').serialize();
+ var cr = $('#createResource');
+ $.ajax({
+ type: "POST",
+ async: false,
+ "data": dataToSend,
+ "url": cr.data("url"),
+ dataType: "text",
+ error: function(jqXHR, textStatus, errorThrown) {
+ vShowAJAXError("Could not create resource", jqXHR, errorThrown);
+ cr.modal("hide");
+ },
+ success: function(resData, textStatus, jqXHR) {
+ cr.data("onSuccess")($('#createResourceForm').serializeArray(), resData, textStatus, jqXHR);
+ cr.modal('hide');
+ }
+ });
+}
+
+/**
+ * This function creates a dialog, where the user can add key/value pairs.
+ * These pairs are then sent to the given URL via POST.
+ *
+ * REQUIRES <script id="template-createresource" type="text/x-tmpl">
+ * Currently placed in header.jsp
+ *
+ * @param nameOfResource the name of the resource to add
+ * @param fields array of label/name/type/hint/checked values to use for the field and to pass in the AJAX call. (optional) type is in "text"/"checkbox"/... -- the values allowed for "type" attributes of <input> fields. Currently, all fields are required.
+ * @param url the URL to use. The URL is uses as unique ID. If a dialog is requested to be open with a URL and the previous dialog had the same URL, the previous dialog is opened
+ * @param onSuccess: function(serializedArray, data, textStatus, jqXHR) to call if adding has been successful. "serializedArray" contains the value of $('#formid').serializeArray()
+ */
+function createResource(nameOfResource, fields, url, onSuccess) {
+ var cr = $('#createResource');
+ if (cr.length == 1) {
+ if (cr.data("url") == url) {
+ // the same dialog has been created before. Reuse it
+ cr.modal("show");
+ return;
+ } else {
+ // remove the dialog and thus enable the creation of a new one
+ cr.remove();
+ }
+ }
+
+ var data = {
+ nameOfResource: nameOfResource,
+ fields: fields
+ };
+ require(["tmpl"], function(tmpl) {
+ var div = tmpl("template-createresource", data);
+
+ $("body").append(div);
+ cr = $('#createResource');
+ cr.on("shown.bs.modal", function() {
+ $("#createResourceForm > fieldset > div:first-child > input").focus();
+ });
+
+ cr.modal('show');
+ cr.data("url", url);
+ cr.data("onSuccess", onSuccess);
+ });
+}
+
+/**
+ *
+ * @param selection jQuery selection object (<selection>)
+ * @param value the value of the text to add
+ * @param text the text to add
+ */
+function addSortedSelectionItem(selection, value, text) {
+ var option = selection.children("option:first-child");
+ while ((option.length == 1) && (option.text() < text)) {
+ option = option.next();
+ }
+ var toAppend = '<option value="' + value + '" selected="selected">' + text + '</option>';
+ if (option.length == 0) {
+ selection.append(toAppend);
+ } else {
+ option.before(toAppend);
+ }
+}
+
+/**** begin: for datatable ****/
+
+/**
+ * Uses selected row as information for deleting on server (and on success deleting in table)
+ *
+ * the id of the thing to delete is read from the first column of the table
+ *
+ * @param tableInfo: info object about table
+ * @param nameOfThingToDelete: used at messages
+ * @param baseURL: used to form URL by baseURL+<name of thing>
+ * @param idColumn: (optional) column to look for the id. If not provided, look in the first column
+ * @param nameColumn: (optional) column to look for a name. If not provided, the id is used
+ * @param namespaceColumn: (optional) column to look for a namespace. If not provided, do not use any nameespace information
+ * @param withoutConfirmation (optional) if given, the resource is deleted without any confirmation
+*/
+function deleteOnServerAndInTable(tableInfo, nameOfThingToDelete, baseURL, idColumn, nameColumn, namespaceColumn, withoutConfirmation) {
+ if (tableInfo.selectedRow == null) {
+ vShowError("No row selected.");
+ } else {
+ idColumn = idColumn || 0; // default: first column indicates identifier
+ var id = tableInfo.table.fnGetData(tableInfo.selectedRow, idColumn);
+ var name;
+ if (typeof nameColumn === "undefined") {
+ name = id;
+ } else {
+ name = tableInfo.table.fnGetData(tableInfo.selectedRow, nameColumn);
+ }
+
+ var url = baseURL;
+ if (typeof namespaceColumn !== "undefined") {
+ var namespace = tableInfo.table.fnGetData(tableInfo.selectedRow, namespaceColumn);
+ namespace = encodeID(namespace);
+ url = url + namespace + '/';
+ }
+ // append the id
+ // we could add a "/" to be compatible with Jersey's URL rewriting
+ // However, that prevents deleting a thing being a leaf in the URL (e.g. a namespace)
+ url = url + encodeID(id);
+
+ // defined in winery-common.js
+ deleteResource(nameOfThingToDelete + " " + name, url,
+ function(data, textSTatus, jqXHR) {
+ tableInfo.table.fnDeleteRow(tableInfo.selectedRow);
+ tableInfo.selectedRow = null;
+ tableInfo.selectedTr = null;
+ }, false, false, withoutConfirmation
+ );
+ }
+}
+
+/**** end: for datatable ****/
+
+/**
+ * Uploads the content of given form to given url
+ *
+ * @param form specifies the form to read data from
+ * @param url specifies the URL to send the data to
+ * @param onSuccess: function(XMLHttpRequest) to handle result
+ */
+function uploadFile(form, url, onSuccess) {
+ var xhr = new XMLHttpRequest();
+ var fd = new FormData(form);
+ xhr.onreadystatechange = function(e) {
+ if (this.readyState == 4) {
+ if ((xhr.status != 200) && (xhr.status != 201)) {
+ alert("Upload error occurred: " + xhr.status);
+ } else {
+ onSuccess(xhr);
+ }
+ }
+ };
+ xhr.open('post', url, true);
+ xhr.send(fd);
+}
+
+/**
+ * PUTs given value to the server in the BODY
+ *
+ * @param thing the thing to send. used as URL and in the error messages
+ */
+function updateValue(thing, value) {
+ $.ajax({
+ type: "PUT",
+ async: false,
+ url: thing,
+ "data": value,
+ dataType: "text",
+ processData: false, // leads to a send in the body
+ error: function(jqXHR, textStatus, errorThrown) {
+ vShowAJAXError("Could not set " + thing, jqXHR, errorThrown);
+ },
+ success: function() {
+ vShowSuccess("Successfully updated " + thing);
+ }
+ });
+}
+
+/**
+ * Puts the color to visualappearance/{id}
+ *
+ * Required by visualappearance.jsp (node type and relation ship type)
+ *
+ * @param id
+ */
+function putColor(id, hex) {
+ var dataToSend = {
+ "color" : hex
+ };
+ $.ajax({
+ type : "PUT",
+ async : false,
+ url : "visualappearance/" + id,
+ "data" : dataToSend,
+ dataType : "text",
+ error : function(jqXHR, textStatus, errorThrown) {
+ vShowError("Could not set color " + errorThrown);
+ },
+ success: function(data, textStatus, jqXHR) {
+ vShowSuccess("Successfully updated color");
+ }
+ });
+}
+
diff --git a/winery/org.eclipse.winery.repository/src/main/webapp/js/winery-support.js b/winery/org.eclipse.winery.repository/src/main/webapp/js/winery-support.js
new file mode 100644
index 0000000..0459235
--- /dev/null
+++ b/winery/org.eclipse.winery.repository/src/main/webapp/js/winery-support.js
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * Copyright (c) 2012-2013 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
+ *******************************************************************************/
+
+/* no name given as RequireJS' documentatio says that makes modules less portable */
+define(["datatables"], function() {
+ /*
+ * Valid chars: See
+ * <ul>
+ * <li>http://www.w3.org/TR/REC-xml-names/#NT-NCName</li>
+ * <li>http://www.w3.org/TR/REC-xml/#NT-Name</li>
+ * </ul>
+ */
+ // NameCharRange \u10000-\ueffff is not supported by Java
+ var NCNameStartChar_RegExp = "[A-Z_a-z\u00c0-\u00d6\u00d8\u00f6\u00f8\u02ff\u0370\u037d\u037f-\u1fff\u200c-\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]";
+ var NCNameChar_RegExp = NCNameStartChar_RegExp + "|[-\\.0-9\u00B7\u0300-\u036F\u203F-\u2040]";
+ var NCName_RegExp = NCNameStartChar_RegExp + "(" + NCNameChar_RegExp + ")*";
+ var QName_RegExp = "(" + NCName_RegExp + ":)?(" + NCName_RegExp + ")";
+
+ var NCNameStartChar_Pattern = new RegExp(NCNameStartChar_RegExp);
+ var NCNameChar_Pattern = new RegExp(NCNameChar_RegExp);
+
+ /**
+ * Initializes a table (and updates tableInfo)
+ * * adds selection capability
+ *
+ * @param info.id: id of the table (with #)
+ * @param paramsForDataTable: additional parameters for dataTable()
+ * @param afterInit function to be called after dataTables object initalization happened
+ *
+ * @returns initialized info object
+ * * info.table is updated with a pointer to the data table
+ * * info.selectedTr is set to null
+ */
+ function initTable(info, paramsForDataTable, afterInit) {
+ paramsForDataTable = paramsForDataTable || {};
+
+ $(info.id).click(function(event) {
+ if (info.selectedTr != null) {
+ info.selectedTr.removeClass('row_selected');
+ }
+ var row = $(event.target.parentNode);
+ if ((info.selectedTr != null) && (info.selectedTr[0] == row[0])) {
+ // row is deselected if selected again
+ info.selectedRow = null;
+ info.selectedTr = null;
+ } else {
+ info.selectedTr = row;
+ info.selectedTr.addClass('row_selected');
+ info.selectedRow = event.target.parentNode;
+ }
+ });
+ info.selectedTr = null;
+ info.table = $(info.id).dataTable(paramsForDataTable);
+ if (afterInit) afterInit();
+ }
+
+ /**
+ * Function to determine whether a data table described with the tableInfo object is empty
+ *
+ * @param tableInfo the table info object describing the table
+ * @returns true if the table is empty, false otherwise
+ */
+ function isEmptyTable(tableInfo) {
+ return tableInfo.table.children("tbody").children("tr").first().children("td").hasClass("dataTables_empty");
+ }
+
+ /**
+ * JavaScript implementation of org.eclipse.winery.common.Util.makeNCName(String)
+ */
+ function makeNCName(text) {
+ if (!text || text == "") {
+ return text;
+ }
+
+ var res = "";
+
+ var start = text.substr(0, 1);
+ if (NCNameStartChar_Pattern.test(start)) {
+ res += start;
+ } else {
+ res += "_";
+ }
+
+ for (var i=1; i<text.length; i++) {
+ var c = (text.substr(i, 1));
+ if (NCNameChar_Pattern.test(c)) {
+ res += c;
+ } else {
+ res += "_";
+ }
+ }
+ return res;
+ }
+
+ var module = {
+ initTable: initTable,
+ isEmptyTable: isEmptyTable,
+ makeNCName: makeNCName,
+ QName_RegExp: QName_RegExp
+ };
+ return module;
+ }
+);