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 /* no name given as RequireJS' documentatio says that makes modules less portable */
14 define(["datatables"], function() {
18 * <li>http://www.w3.org/TR/REC-xml-names/#NT-NCName</li>
19 * <li>http://www.w3.org/TR/REC-xml/#NT-Name</li>
22 // NameCharRange \u10000-\ueffff is not supported by Java
23 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]";
24 var NCNameChar_RegExp = NCNameStartChar_RegExp + "|[-\\.0-9\u00B7\u0300-\u036F\u203F-\u2040]";
25 var NCName_RegExp = NCNameStartChar_RegExp + "(" + NCNameChar_RegExp + ")*";
26 var QName_RegExp = "(" + NCName_RegExp + ":)?(" + NCName_RegExp + ")";
28 var NCNameStartChar_Pattern = new RegExp(NCNameStartChar_RegExp);
29 var NCNameChar_Pattern = new RegExp(NCNameChar_RegExp);
32 * Initializes a table (and updates tableInfo)
33 * * adds selection capability
35 * @param info.id: id of the table (with #)
36 * @param paramsForDataTable: additional parameters for dataTable()
37 * @param afterInit function to be called after dataTables object initalization happened
39 * @returns initialized info object
40 * * info.table is updated with a pointer to the data table
41 * * info.selectedTr is set to null
43 function initTable(info, paramsForDataTable, afterInit) {
44 paramsForDataTable = paramsForDataTable || {};
46 $(info.id).click(function(event) {
47 if (info.selectedTr != null) {
48 info.selectedTr.removeClass('row_selected');
50 var row = $(event.target.parentNode);
51 if ((info.selectedTr != null) && (info.selectedTr[0] == row[0])) {
52 // row is deselected if selected again
53 info.selectedRow = null;
54 info.selectedTr = null;
56 info.selectedTr = row;
57 info.selectedTr.addClass('row_selected');
58 info.selectedRow = event.target.parentNode;
61 info.selectedTr = null;
62 info.table = $(info.id).dataTable(paramsForDataTable);
63 if (afterInit) afterInit();
67 * Function to determine whether a data table described with the tableInfo object is empty
69 * @param tableInfo the table info object describing the table
70 * @returns true if the table is empty, false otherwise
72 function isEmptyTable(tableInfo) {
73 return tableInfo.table.children("tbody").children("tr").first().children("td").hasClass("dataTables_empty");
77 * JavaScript implementation of org.eclipse.winery.common.Util.makeNCName(String)
79 function makeNCName(text) {
80 if (!text || text == "") {
86 var start = text.substr(0, 1);
87 if (NCNameStartChar_Pattern.test(start)) {
93 for (var i=1; i<text.length; i++) {
94 var c = (text.substr(i, 1));
95 if (NCNameChar_Pattern.test(c)) {
105 initTable: initTable,
106 isEmptyTable: isEmptyTable,
107 makeNCName: makeNCName,
108 QName_RegExp: QName_RegExp