blob: 76171c06b527b7b6b59c822ec22904083d0a81f8 [file] [log] [blame]
Thomas Vachuskaaa8b0eb2015-05-22 09:54:15 -07001/*
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 */
16package org.onosproject.ui.impl;
17
18import com.fasterxml.jackson.databind.node.ObjectNode;
19import com.google.common.collect.ImmutableSet;
20import org.onosproject.cfg.ComponentConfigService;
21import org.onosproject.cfg.ConfigProperty;
22import org.onosproject.ui.RequestHandler;
23import org.onosproject.ui.UiMessageHandler;
24import org.onosproject.ui.table.TableModel;
25import org.onosproject.ui.table.TableRequestHandler;
26
27import java.util.Collection;
28
29/**
30 * Message handler for component configuration view related messages.
31 */
32public 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 {
Jian Li69f66632016-01-15 12:27:42 -080056 private static final String NO_ROWS_MESSAGE = "No settings found";
57
Thomas Vachuskaaa8b0eb2015-05-22 09:54:15 -070058 private SettingsRequest() {
59 super(DATA_REQUEST, DATA_RESPONSE, SETTINGS);
60 }
61
62 @Override
63 protected String[] getColumnIds() {
64 return COL_IDS;
65 }
66
67 @Override
Jian Li69f66632016-01-15 12:27:42 -080068 protected String noRowsMessage() {
69 return NO_ROWS_MESSAGE;
70 }
71
72 @Override
Thomas Vachuskaaa8b0eb2015-05-22 09:54:15 -070073 protected String defaultColumnId() {
74 return COMPONENT;
75 }
76
77 @Override
78 protected TableModel createTableModel() {
79 TableModel tm = super.createTableModel();
80 return tm;
81 }
82
83 @Override
84 protected void populateTable(TableModel tm, ObjectNode payload) {
85 ComponentConfigService ccs = get(ComponentConfigService.class);
86 for (String component : ccs.getComponentNames()) {
87 for (ConfigProperty prop : ccs.getProperties(component)) {
88 populateRow(tm.addRow(), component, prop);
89 }
90 }
91 }
92
93 private void populateRow(TableModel.Row row, String component, ConfigProperty prop) {
94 row.cell(COMPONENT, component)
95 .cell(ID, prop.name())
96 .cell(TYPE, prop.type().toString().toLowerCase())
97 .cell(VALUE, prop.value())
98 .cell(DEFAULT, prop.defaultValue())
99 .cell(DESC, prop.description());
100 }
101 }
102}