Moved YANG GUI up the source tree.

Change-Id: I0398f9a0b963942b011acbd74478b053ddad703a
diff --git a/apps/yang-gui/src/main/java/org/onosproject/yang/gui/YangModelMessageHandler.java b/apps/yang-gui/src/main/java/org/onosproject/yang/gui/YangModelMessageHandler.java
new file mode 100644
index 0000000..475b105
--- /dev/null
+++ b/apps/yang-gui/src/main/java/org/onosproject/yang/gui/YangModelMessageHandler.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.gui;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.ImmutableSet;
+import org.onlab.osgi.ServiceDirectory;
+import org.onosproject.ui.RequestHandler;
+import org.onosproject.ui.UiConnection;
+import org.onosproject.ui.UiMessageHandler;
+import org.onosproject.ui.table.TableModel;
+import org.onosproject.ui.table.TableRequestHandler;
+import org.onosproject.yang.model.YangModel;
+import org.onosproject.yang.runtime.YangModelRegistry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+
+/**
+ * ONOS UI YANG Models message handler.
+ */
+public class YangModelMessageHandler extends UiMessageHandler {
+
+    private static final String TABLE_REQ = "yangModelDataRequest";
+    private static final String TABLE_RESP = "yangModelDataResponse";
+    private static final String MODELS = "yangModels";
+
+    private static final String DETAILS_REQ = "yangModelDetailsRequest";
+    private static final String DETAILS_RESP = "yangModelDetailsResponse";
+    private static final String DETAILS = "details";
+
+    // Table Column IDs
+    private static final String ID = "id";
+    private static final String TYPE = "type";
+    // TODO: fill out table columns as needed
+
+    private static final String[] COL_IDS = {
+            ID, TYPE
+    };
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private YangModelRegistry modelRegistry;
+    // TODO: fill out other fields as necessary
+
+
+    // ===============-=-=-=-=-=-==================-=-=-=-=-=-=-===========
+
+    @Override
+    public void init(UiConnection connection, ServiceDirectory directory) {
+        super.init(connection, directory);
+        modelRegistry = directory.get(YangModelRegistry.class);
+        // TODO: addListeners(); ???
+    }
+
+    @Override
+    public void destroy() {
+        // TODO: removeListeners(); ???
+        super.destroy();
+        // NOTE: if no listeners are required, this method can be removed
+    }
+
+    @Override
+    protected Collection<RequestHandler> createRequestHandlers() {
+        return ImmutableSet.of(
+                new TableDataHandler(),
+                new DetailRequestHandler()
+        );
+    }
+
+
+    // Handler for table requests
+    private final class TableDataHandler extends TableRequestHandler {
+        private static final String NO_ROWS_MESSAGE = "No YANG Models found";
+
+        private TableDataHandler() {
+            super(TABLE_REQ, TABLE_RESP, MODELS);
+        }
+
+        @Override
+        protected String[] getColumnIds() {
+            return COL_IDS;
+        }
+
+        @Override
+        protected String noRowsMessage(ObjectNode payload) {
+            return NO_ROWS_MESSAGE;
+        }
+
+        @Override
+        protected void populateTable(TableModel tm, ObjectNode payload) {
+            for (YangModel model : modelRegistry.getModels()) {
+                populateRow(tm.addRow(), model.getYangModulesId().toString());
+            }
+        }
+
+        // TODO: obviously, this should be adapted to arrange YANG model data
+        //       into the appropriate table columns
+        private void populateRow(TableModel.Row row, String k) {
+            row.cell(ID, k).cell(TYPE, k);
+        }
+    }
+
+
+    // handler for selected model detail requests (selected table row)
+    private final class DetailRequestHandler extends RequestHandler {
+        private DetailRequestHandler() {
+            super(DETAILS_REQ);
+        }
+
+        @Override
+        public void process(ObjectNode payload) {
+            String id = string(payload, ID);
+
+            // TODO: retrieve the appropriate model from ymsService and create
+            //       a detail record to send back to the client.
+
+            ObjectNode data = objectNode();
+
+            data.put(ID, id);
+            data.put(TYPE, "some-type");
+            data.put("todo", "fill out with appropriate date attributes");
+
+            ObjectNode rootNode = objectNode();
+            rootNode.set(DETAILS, data);
+
+            sendMessage(DETAILS_RESP, rootNode);
+        }
+    }
+}
diff --git a/apps/yang-gui/src/main/java/org/onosproject/yang/gui/YangModelUiComponent.java b/apps/yang-gui/src/main/java/org/onosproject/yang/gui/YangModelUiComponent.java
new file mode 100644
index 0000000..b4d9697
--- /dev/null
+++ b/apps/yang-gui/src/main/java/org/onosproject/yang/gui/YangModelUiComponent.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.gui;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onosproject.ui.UiExtension;
+import org.onosproject.ui.UiExtensionService;
+import org.onosproject.ui.UiMessageHandlerFactory;
+import org.onosproject.ui.UiView;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+
+import static org.onosproject.ui.UiView.Category;
+
+/**
+ * ONOS UI component for the Yang Models table view.
+ */
+@Component(immediate = true)
+public class YangModelUiComponent {
+
+    private static final ClassLoader CL =
+            YangModelUiComponent.class.getClassLoader();
+    private static final String VIEW_ID = "yangModel";
+    private static final String NAV_LABEL = "YANG Models";
+    private static final String NAV_ICON = "nav_yang";
+    private static final String HELP_URL =
+            "https://wiki.onosproject.org/display/ONOS/YANG+Models+in+ONOS";
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected UiExtensionService uiExtensionService;
+
+    // List of application views
+    private final List<UiView> uiViews = ImmutableList.of(
+            new UiView(Category.PLATFORM, VIEW_ID, NAV_LABEL, NAV_ICON, HELP_URL)
+    );
+
+    // Factory for UI message handlers
+    private final UiMessageHandlerFactory msgHandlerFactory =
+            () -> ImmutableList.of(
+                    new YangModelMessageHandler()
+            );
+
+    // Application UI Extension
+    private UiExtension extension =
+            new UiExtension.Builder(CL, uiViews)
+                    .resourcePath(VIEW_ID)
+                    .messageHandlerFactory(msgHandlerFactory)
+                    .build();
+
+    @Activate
+    protected void activate() {
+        uiExtensionService.register(extension);
+        log.info("Started");
+    }
+
+    @Deactivate
+    protected void deactivate() {
+        uiExtensionService.unregister(extension);
+        log.info("Stopped");
+    }
+
+}
diff --git a/apps/yang-gui/src/main/java/org/onosproject/yang/gui/package-info.java b/apps/yang-gui/src/main/java/org/onosproject/yang/gui/package-info.java
new file mode 100644
index 0000000..e7f96ab
--- /dev/null
+++ b/apps/yang-gui/src/main/java/org/onosproject/yang/gui/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * GUI elements for YANG Runtime &amp; Live YANG Compiler subsystem.
+ */
+package org.onosproject.yang.gui;
\ No newline at end of file
diff --git a/apps/yang-gui/src/main/resources/app/view/yangModel/yangModel-theme.css b/apps/yang-gui/src/main/resources/app/view/yangModel/yangModel-theme.css
new file mode 100644
index 0000000..afeb601
--- /dev/null
+++ b/apps/yang-gui/src/main/resources/app/view/yangModel/yangModel-theme.css
@@ -0,0 +1,16 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
diff --git a/apps/yang-gui/src/main/resources/app/view/yangModel/yangModel.css b/apps/yang-gui/src/main/resources/app/view/yangModel/yangModel.css
new file mode 100644
index 0000000..f8e9d01
--- /dev/null
+++ b/apps/yang-gui/src/main/resources/app/view/yangModel/yangModel.css
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ov-yang-model h2 {
+    display: inline-block;
+}
+
+#ov-yang-model div.ctrl-btns {
+}
+
+
+
+#yang-model-details-panel.floatpanel {
+    z-index: 0;
+}
+
+
+#yang-model-details-panel .container {
+    padding: 8px 12px;
+}
+
+#yang-model-details-panel .close-btn {
+    position: absolute;
+    right: 12px;
+    top: 12px;
+    cursor: pointer;
+}
+
+#yang-model-details-panel h2 {
+    display: inline-block;
+    margin: 8px 0;
+}
+
+
+#yang-model-details-panel .data {
+    font-size: 12pt;
+}
+
diff --git a/apps/yang-gui/src/main/resources/app/view/yangModel/yangModel.html b/apps/yang-gui/src/main/resources/app/view/yangModel/yangModel.html
new file mode 100644
index 0000000..2e1171d
--- /dev/null
+++ b/apps/yang-gui/src/main/resources/app/view/yangModel/yangModel.html
@@ -0,0 +1,48 @@
+<!-- YANG Model partial HTML -->
+<div id="ov-yang-model">
+
+    <div class="tabular-header">
+        <h2>YANG Models ({{tableData.length}} total)</h2>
+        <div class="ctrl-btns">
+            <div class="refresh" ng-class="{active: autoRefresh}"
+                 icon icon-id="refresh" icon-size="42"
+                 tooltip tt-msg="autoRefreshTip"
+                 ng-click="toggleRefresh()"></div>
+        </div>
+    </div>
+
+    <div class="summary-list" onos-table-resize>
+        <div class="table-header" onos-sortable-header>
+            <table>
+                <tr>
+                    <td colId="id" col-width="130px" sortable>ID</td>
+                    <td colId="type" sortable>Type</td>
+                    <!-- TODO: More columns to be added -->
+                </tr>
+            </table>
+        </div>
+
+        <div class="table-body">
+            <table id-prop="id">
+                <tr ng-if="!tableData.length" class="no-data">
+                    <!-- TODO: set colspan to the final number of columns -->
+                    <td colspan="2">
+                        {{annots.no_rows_msg}}
+                    </td>
+                </tr>
+
+                <tr ng-repeat="ymodel in tableData track by $index"
+                    ng-click="selectCallback($event, ymodel)"
+                    ng-class="{selected: ymodel.id === selId}"
+                    ng-repeat-complete row-id="{{ymodel.id}}">
+                    <td>{{ymodel.id}}</td>
+                    <td>{{ymodel.type}}</td>
+                    <!-- TODO: add more columns here -->
+                </tr>
+            </table>
+        </div>
+    </div>
+
+    <yang-model-details-panel></yang-model-details-panel>
+
+</div>
diff --git a/apps/yang-gui/src/main/resources/app/view/yangModel/yangModel.js b/apps/yang-gui/src/main/resources/app/view/yangModel/yangModel.js
new file mode 100644
index 0000000..930dc6d
--- /dev/null
+++ b/apps/yang-gui/src/main/resources/app/view/yangModel/yangModel.js
@@ -0,0 +1,234 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+  ONOS GUI -- YANG Model table view
+ */
+
+(function () {
+    'use strict';
+
+    // injected refs
+    var $log, $scope, fs, mast, ps, wss, is;
+
+    // constants
+    var topPdg = 28,
+        pWidth = 800;
+
+    // internal state
+    var detailsPanel,
+        ymodel,
+        pStartY,
+        pHeight,
+        wSize,
+        top,
+        iconDiv;
+
+    // constants
+    var pName = 'yang-model-details-panel',
+        detailsReq = 'yangModelDetailsRequest',
+        detailsResp = 'yangModelDetailsResponse';
+
+
+
+    function createDetailsPanel() {
+        detailsPanel = ps.createPanel(pName, {
+            width: pWidth,
+            margin: 0,
+            hideMargin: 0
+        });
+        $scope.hidePanel = function () { detailsPanel.hide(); };
+        detailsPanel.hide();
+    }
+
+    function populateDetails(details) {
+        var topData;
+
+        setUpPanel();
+        topData = top.select('.top-data');
+        populateTop(topData, details);
+        detailsPanel.height(pHeight);
+    }
+
+    function setUpPanel() {
+        var container, closeBtn, dataDiv;
+        detailsPanel.empty();
+
+        container = detailsPanel.append('div').classed('container', true);
+
+        top = container.append('div').classed('top', true);
+        closeBtn = top.append('div').classed('close-btn', true);
+        addCloseBtn(closeBtn);
+        iconDiv = top.append('div').classed('dev-icon', true);
+        top.append('h2');
+
+        dataDiv = top.append('div').classed('top-data', true);
+        dataDiv.append('p').text('fill out properties here');
+    }
+
+    function populateTop(dataDiv, details) {
+        top.select('h2').html('ID:' + details.id);
+        // TODO: format data from 'details' into the dataDiv
+        dataDiv.append('p').html('type: ' + details.type);
+
+    }
+
+    function closePanel() {
+        if (detailsPanel.isVisible()) {
+            $scope.selId = null;
+            detailsPanel.hide();
+            return true;
+        }
+        return false;
+    }
+
+    function addCloseBtn(div) {
+        is.loadEmbeddedIcon(div, 'close', 20);
+        div.on('click', closePanel);
+    }
+
+
+    // callback invoked when data from a details request returns from server
+    function respDetailsCb(data) {
+        $scope.panelData = data.details;
+        ymodel = data.yangModel;
+        $scope.$apply();
+        // TODO: complete the detail panel directive.
+        $log.debug('YANG_MODEL>', detailsResp, data);
+    }
+
+    function handleEscape() {
+        return closePanel();
+    }
+
+
+    // defines view controller
+    angular.module('ovYangModel', [])
+    .controller('OvYangModelCtrl', [
+        '$log', '$scope', 'TableBuilderService', 'TableDetailService',
+        'FnService', 'MastService', 'PanelService', 'WebSocketService',
+        'IconService',
+
+        function (_$log_, _$scope_, tbs, tds, _fs_, _mast_, _ps_, _wss_, _is_) {
+            var handlers = {};
+
+            $log = _$log_;
+            $scope = _$scope_;
+            fs = _fs_;
+            mast = _mast_;
+            ps = _ps_;
+            wss = _wss_;
+            is = _is_;
+
+            $scope.panelData = {};
+
+            // register response handler
+            handlers[detailsResp] = respDetailsCb;
+            wss.bindHandlers(handlers);
+
+            // row selection callback
+            function selCb($event, row) {
+                if ($scope.selId) {
+                    wss.sendEvent(detailsReq, { id: row.id });
+                } else {
+                    $scope.hidePanel();
+                }
+                $log.debug('Got a click on:', row);
+            }
+
+            tbs.buildTable({
+                scope: $scope,
+                tag: 'yangModel',
+                selCb: selCb
+            });
+
+            $scope.$on('$destroy', function () {
+                wss.unbindHandlers(handlers);
+            });
+
+            $log.log('OvYangModelCtrl has been created');
+        }
+    ])
+
+    .directive('yangModelDetailsPanel', [
+        '$rootScope', '$window', '$timeout', 'KeyService',
+
+    function ($rootScope, $window, $timeout, ks) {
+        return function (scope) {
+            var unbindWatch;
+
+            function heightCalc() {
+                pStartY = fs.noPxStyle(d3.select('.tabular-header'), 'height')
+                        + mast.mastHeight() + topPdg;
+                wSize = fs.windowSize(pStartY);
+                pHeight = wSize.height;
+            }
+
+            function initPanel() {
+                heightCalc();
+                createDetailsPanel();
+            }
+
+            // Safari has a bug where it renders the fixed-layout table wrong
+            // if you ask for the window's size too early
+            if (scope.onos.browser === 'safari') {
+                $timeout(initPanel);
+            } else {
+                initPanel();
+            }
+
+            // create key bindings to handle panel
+            ks.keyBindings({
+                esc: [handleEscape, 'Close the details panel'],
+                _helpFormat: ['esc']
+            });
+            ks.gestureNotes([
+                ['click', 'Select a row to show YANG model details'],
+                ['scroll down', 'See more models']
+            ]);
+
+            // if the panelData changes
+            scope.$watch('panelData', function () {
+                if (!fs.isEmptyObject(scope.panelData)) {
+                    populateDetails(scope.panelData);
+                    detailsPanel.show();
+                }
+            });
+
+            // if the window size changes
+            unbindWatch = $rootScope.$watchCollection(
+                function () {
+                    return {
+                        h: $window.innerHeight,
+                        w: $window.innerWidth
+                    };
+                }, function () {
+                    if (!fs.isEmptyObject(scope.panelData)) {
+                        heightCalc();
+                        populateDetails(scope.panelData);
+                    }
+                }
+            );
+
+            scope.$on('$destroy', function () {
+                unbindWatch();
+                ks.unbindKeys();
+                ps.destroyPanel(pName);
+            });
+        };
+    }]);
+
+}());
\ No newline at end of file
diff --git a/apps/yang-gui/src/main/resources/yangModel/css.html b/apps/yang-gui/src/main/resources/yangModel/css.html
new file mode 100644
index 0000000..b6762b6
--- /dev/null
+++ b/apps/yang-gui/src/main/resources/yangModel/css.html
@@ -0,0 +1,2 @@
+<link rel="stylesheet" href="app/view/yangModel/yangModel.css">
+<link rel="stylesheet" href="app/view/yangModel/yangModel-theme.css">
\ No newline at end of file
diff --git a/apps/yang-gui/src/main/resources/yangModel/js.html b/apps/yang-gui/src/main/resources/yangModel/js.html
new file mode 100644
index 0000000..ff52ac3
--- /dev/null
+++ b/apps/yang-gui/src/main/resources/yangModel/js.html
@@ -0,0 +1 @@
+<script src="app/view/yangModel/yangModel.js"></script>