Thomas Vachuska | aa8b0eb | 2015-05-22 09:54:15 -0700 | [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 | package org.onosproject.ui.impl; |
| 17 | |
| 18 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 19 | import com.google.common.collect.ImmutableSet; |
| 20 | import org.onosproject.cfg.ComponentConfigService; |
| 21 | import org.onosproject.cfg.ConfigProperty; |
| 22 | import org.onosproject.ui.RequestHandler; |
| 23 | import org.onosproject.ui.UiMessageHandler; |
| 24 | import org.onosproject.ui.table.TableModel; |
| 25 | import org.onosproject.ui.table.TableRequestHandler; |
| 26 | |
| 27 | import java.util.Collection; |
| 28 | |
| 29 | /** |
| 30 | * Message handler for component configuration view related messages. |
| 31 | */ |
| 32 | public class SettingsViewMessageHandler extends UiMessageHandler { |
| 33 | |
| 34 | private static final String DATA_REQUEST = "settingDataRequest"; |
| 35 | private static final String DATA_RESPONSE = "settingDataResponse"; |
| 36 | private static final String SETTINGS = "settings"; |
| 37 | |
| 38 | private static final String COMPONENT = "component"; |
| 39 | private static final String ID = "id"; |
| 40 | private static final String TYPE = "type"; |
| 41 | private static final String VALUE = "value"; |
| 42 | private static final String DEFAULT = "defValue"; |
| 43 | private static final String DESC = "desc"; |
| 44 | |
| 45 | private static final String[] COL_IDS = { |
| 46 | COMPONENT, ID, TYPE, VALUE, DEFAULT, DESC |
| 47 | }; |
| 48 | |
| 49 | @Override |
| 50 | protected Collection<RequestHandler> createRequestHandlers() { |
| 51 | return ImmutableSet.of(new SettingsRequest()); |
| 52 | } |
| 53 | |
| 54 | // handler for host table requests |
| 55 | private final class SettingsRequest extends TableRequestHandler { |
| 56 | private SettingsRequest() { |
| 57 | super(DATA_REQUEST, DATA_RESPONSE, SETTINGS); |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | protected String[] getColumnIds() { |
| 62 | return COL_IDS; |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | protected String defaultColumnId() { |
| 67 | return COMPONENT; |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | protected TableModel createTableModel() { |
| 72 | TableModel tm = super.createTableModel(); |
| 73 | return tm; |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | protected void populateTable(TableModel tm, ObjectNode payload) { |
| 78 | ComponentConfigService ccs = get(ComponentConfigService.class); |
| 79 | for (String component : ccs.getComponentNames()) { |
| 80 | for (ConfigProperty prop : ccs.getProperties(component)) { |
| 81 | populateRow(tm.addRow(), component, prop); |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | private void populateRow(TableModel.Row row, String component, ConfigProperty prop) { |
| 87 | row.cell(COMPONENT, component) |
| 88 | .cell(ID, prop.name()) |
| 89 | .cell(TYPE, prop.type().toString().toLowerCase()) |
| 90 | .cell(VALUE, prop.value()) |
| 91 | .cell(DEFAULT, prop.defaultValue()) |
| 92 | .cell(DESC, prop.description()); |
| 93 | } |
| 94 | } |
| 95 | } |