blob: 8665a4e644fc070d9bd29972fe5bc879408005bc [file] [log] [blame]
Thomas Vachuskaeb851cd2016-07-21 15:41:05 -07001/*
Brian O'Connor0a4e6742016-09-15 23:03:10 -07002 * Copyright 2016-present Open Networking Laboratory
Thomas Vachuskaeb851cd2016-07-21 15:41:05 -07003 *
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.cli.net;
17
18import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
20import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.net.region.Region;
22import org.onosproject.net.region.RegionService;
23import org.onosproject.ui.UiTopoLayoutService;
24import org.onosproject.ui.model.topo.UiTopoLayout;
25import org.onosproject.ui.model.topo.UiTopoLayoutId;
26
27import static org.onosproject.net.region.RegionId.regionId;
28import static org.onosproject.ui.model.topo.UiTopoLayoutId.layoutId;
29
30/**
31 * Creates a new UI layout.
32 */
33@Command(scope = "onos", name = "layout-add",
34 description = "Creates a new UI layout")
35public class LayoutAddCommand extends AbstractShellCommand {
36
37 private static final String FMT = "id=%s, name=%s, type=%s";
38 private static final String FMT_MASTER = " master=%s";
39
40 @Argument(index = 0, name = "id", description = "Layout ID",
41 required = true, multiValued = false)
42 String id = null;
43
44 @Argument(index = 1, name = "id", description = "Region ID (optional)",
45 required = false, multiValued = false)
46 String regionId = null;
47
48 @Argument(index = 2, name = "id", description = "Parent layout ID (optional)",
49 required = false, multiValued = false)
50 String parentId = null;
51
52 private RegionService regionService;
53
54 @Override
55 protected void execute() {
56 UiTopoLayoutService service = get(UiTopoLayoutService.class);
57 RegionService regionService = get(RegionService.class);
58
59 Region region = regionId == null ? null : regionService.getRegion(regionId(regionId));
60 UiTopoLayoutId pid = parentId == null ? UiTopoLayoutId.DEFAULT_ID : layoutId(parentId);
61
Simon Huntd0fa2842016-10-24 18:04:05 -070062 UiTopoLayout layout = new UiTopoLayout(layoutId(id)).region(region).parent(pid);
Thomas Vachuskaeb851cd2016-07-21 15:41:05 -070063 service.addLayout(layout);
64 }
65}