chengfan | b466a7e | 2015-08-21 09:59:29 -0500 | [diff] [blame] | 1 | package org.onosproject.ui.impl; |
| 2 | |
| 3 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 4 | import com.google.common.collect.ImmutableSet; |
| 5 | import org.onosproject.incubator.net.tunnel.Tunnel; |
chengfan | 392e8f9 | 2015-08-21 13:20:02 -0500 | [diff] [blame] | 6 | import org.onosproject.incubator.net.tunnel.TunnelEndPointFormatter; |
chengfan | b466a7e | 2015-08-21 09:59:29 -0500 | [diff] [blame] | 7 | import org.onosproject.incubator.net.tunnel.TunnelService; |
| 8 | import org.onosproject.ui.RequestHandler; |
| 9 | import org.onosproject.ui.UiMessageHandler; |
| 10 | import org.onosproject.ui.table.TableModel; |
| 11 | import org.onosproject.ui.table.TableRequestHandler; |
| 12 | import org.onosproject.ui.table.cell.EnumFormatter; |
| 13 | |
| 14 | import java.util.Collection; |
| 15 | |
| 16 | public class TunnelViewMessageHandler extends UiMessageHandler { |
| 17 | private static final String TUNNEL_DATA_REQ = "tunnelDataRequest"; |
| 18 | private static final String TUNNEL_DATA_RESP = "tunnelDataResponse"; |
| 19 | private static final String TUNNELS = "tunnels"; |
| 20 | private static final String ID = "id"; |
| 21 | private static final String NAME = "name"; |
| 22 | private static final String ONE = "one"; |
| 23 | private static final String TWO = "two"; |
| 24 | private static final String TYPE = "type"; |
| 25 | private static final String GROUP_ID = "group_id"; |
| 26 | |
| 27 | private static final String BANDWIDTH = "bandwidth"; |
| 28 | private static final String PATH = "path"; |
| 29 | |
| 30 | |
| 31 | private static final String[] COL_IDS = { |
| 32 | ID, NAME, ONE, TWO, TYPE, GROUP_ID, |
| 33 | BANDWIDTH, PATH |
| 34 | }; |
| 35 | |
| 36 | @Override |
| 37 | protected Collection<RequestHandler> createRequestHandlers() { |
| 38 | return ImmutableSet.of(new TunnelDataRequestHandler()); |
| 39 | } |
| 40 | |
| 41 | private final class TunnelDataRequestHandler extends TableRequestHandler { |
| 42 | |
| 43 | public TunnelDataRequestHandler() { |
| 44 | super(TUNNEL_DATA_REQ, TUNNEL_DATA_RESP, TUNNELS); |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | protected String[] getColumnIds() { |
| 49 | return COL_IDS; |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | protected TableModel createTableModel() { |
| 54 | TableModel tm = super.createTableModel(); |
| 55 | //TODO add more formater class so that we can get a more readable table |
chengfan | 392e8f9 | 2015-08-21 13:20:02 -0500 | [diff] [blame] | 56 | tm.setFormatter(ONE, TunnelEndPointFormatter.INSTANCE); |
| 57 | tm.setFormatter(TWO, TunnelEndPointFormatter.INSTANCE); |
chengfan | b466a7e | 2015-08-21 09:59:29 -0500 | [diff] [blame] | 58 | tm.setFormatter(TYPE, EnumFormatter.INSTANCE); |
| 59 | return tm; |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | protected void populateTable(TableModel tm, ObjectNode payload) { |
| 64 | TunnelService ts = get(TunnelService.class); |
chengfan | 392e8f9 | 2015-08-21 13:20:02 -0500 | [diff] [blame] | 65 | ts.queryAllTunnels().forEach(tunnel -> populateRow(tm.addRow(), tunnel)); |
chengfan | b466a7e | 2015-08-21 09:59:29 -0500 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | } |
| 69 | |
| 70 | private void populateRow(TableModel.Row row, Tunnel tunnel) { |
| 71 | row.cell(ID, tunnel.tunnelId().id()) |
| 72 | .cell(NAME, tunnel.tunnelName().value()) |
| 73 | .cell(ONE, tunnel.src()) |
| 74 | .cell(TWO, tunnel.dst()) |
| 75 | .cell(TYPE, tunnel.type()) |
| 76 | .cell(GROUP_ID, tunnel.groupId().id()) |
| 77 | .cell(BANDWIDTH, tunnel.annotations().value(BANDWIDTH)) |
| 78 | .cell(PATH, tunnel.path()); |
| 79 | } |
| 80 | } |