Bri Prebilic Cole | 468bc1d | 2015-02-12 12:11:13 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.gui; |
| 18 | |
Bri Prebilic Cole | 468bc1d | 2015-02-12 12:11:13 -0800 | [diff] [blame] | 19 | import org.onosproject.net.Device; |
| 20 | import org.onosproject.net.device.DeviceService; |
| 21 | |
Bri Prebilic Cole | dea0974 | 2015-02-12 15:33:50 -0800 | [diff] [blame] | 22 | /** |
| 23 | * TableRow implementation for {@link Device devices}. |
| 24 | */ |
| 25 | public class DeviceTableRow extends AbstractTableRow { |
Bri Prebilic Cole | 468bc1d | 2015-02-12 12:11:13 -0800 | [diff] [blame] | 26 | |
| 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 Cole | dea0974 | 2015-02-12 15:33:50 -0800 | [diff] [blame] | 30 | private static final String TYPE_IID = "_iconid_type"; |
| 31 | private static final String DEV_ICON_PREFIX = "devIcon_"; |
Bri Prebilic Cole | 468bc1d | 2015-02-12 12:11:13 -0800 | [diff] [blame] | 32 | 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 Cole | dea0974 | 2015-02-12 15:33:50 -0800 | [diff] [blame] | 38 | 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 Cole | 468bc1d | 2015-02-12 12:11:13 -0800 | [diff] [blame] | 44 | |
| 45 | private static final String ICON_ID_ONLINE = "deviceOnline"; |
| 46 | private static final String ICON_ID_OFFLINE = "deviceOffline"; |
| 47 | |
Bri Prebilic Cole | 468bc1d | 2015-02-12 12:11:13 -0800 | [diff] [blame] | 48 | 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 Cole | dea0974 | 2015-02-12 15:33:50 -0800 | [diff] [blame] | 52 | 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 Cole | 468bc1d | 2015-02-12 12:11:13 -0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | @Override |
Bri Prebilic Cole | dea0974 | 2015-02-12 15:33:50 -0800 | [diff] [blame] | 70 | protected String[] columnIds() { |
| 71 | return COL_IDS; |
Bri Prebilic Cole | 468bc1d | 2015-02-12 12:11:13 -0800 | [diff] [blame] | 72 | } |
| 73 | } |