blob: 423657a1bcc9662d2ff1be25f85ae4dc15108732 [file] [log] [blame]
Bri Prebilic Cole468bc1d2015-02-12 12:11:13 -08001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.gui;
18
Bri Prebilic Cole468bc1d2015-02-12 12:11:13 -080019import org.onosproject.net.Device;
20import org.onosproject.net.device.DeviceService;
21
Bri Prebilic Coledea09742015-02-12 15:33:50 -080022/**
23 * TableRow implementation for {@link Device devices}.
24 */
25public class DeviceTableRow extends AbstractTableRow {
Bri Prebilic Cole468bc1d2015-02-12 12:11:13 -080026
27 private static final String ID = "id";
28 private static final String AVAILABLE = "available";
29 private static final String AVAILABLE_IID = "_iconid_available";
Bri Prebilic Coledea09742015-02-12 15:33:50 -080030 private static final String TYPE_IID = "_iconid_type";
31 private static final String DEV_ICON_PREFIX = "devIcon_";
Bri Prebilic Cole468bc1d2015-02-12 12:11:13 -080032 private static final String ROLE = "role";
33 private static final String MFR = "mfr";
34 private static final String HW = "hw";
35 private static final String SW = "sw";
36 private static final String SERIAL = "serial";
37 private static final String PROTOCOL = "protocol";
Bri Prebilic Coledea09742015-02-12 15:33:50 -080038 private static final String CHASSISID = "chassisid";
39
40 private static final String[] COL_IDS = {
41 ID, AVAILABLE, AVAILABLE_IID, TYPE_IID, ROLE,
42 MFR, HW, SW, SERIAL, PROTOCOL, CHASSISID
43 };
Bri Prebilic Cole468bc1d2015-02-12 12:11:13 -080044
45 private static final String ICON_ID_ONLINE = "deviceOnline";
46 private static final String ICON_ID_OFFLINE = "deviceOffline";
47
Bri Prebilic Cole468bc1d2015-02-12 12:11:13 -080048 public DeviceTableRow(DeviceService service, Device d) {
49 boolean available = service.isAvailable(d.id());
50 String iconId = available ? ICON_ID_ONLINE : ICON_ID_OFFLINE;
51
Bri Prebilic Coledea09742015-02-12 15:33:50 -080052 add(ID, d.id().toString());
53 add(AVAILABLE, Boolean.toString(available));
54 add(AVAILABLE_IID, iconId);
55 add(TYPE_IID, getTypeIconId(d));
56 add(ROLE, service.getRole(d.id()).toString());
57 add(MFR, d.manufacturer());
58 add(HW, d.hwVersion());
59 add(SW, d.swVersion());
60 add(SERIAL, d.serialNumber());
61 add(PROTOCOL, d.annotations().value(PROTOCOL));
62 add(CHASSISID, d.chassisId().toString());
63 }
64
65 private String getTypeIconId(Device d) {
66 return DEV_ICON_PREFIX + d.type().toString();
Bri Prebilic Cole468bc1d2015-02-12 12:11:13 -080067 }
68
69 @Override
Bri Prebilic Coledea09742015-02-12 15:33:50 -080070 protected String[] columnIds() {
71 return COL_IDS;
Bri Prebilic Cole468bc1d2015-02-12 12:11:13 -080072 }
73}