1 /*
2 * Copyright 2003 - 2013 The eFaps Team
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 * Revision: $Rev$
17 * Last Changed: $Date$
18 * Last Changed By: $Author$
19 */
20
21 package org.efaps.update.schema.ui;
22
23 import java.net.URL;
24 import java.util.HashSet;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.Set;
28
29 import org.efaps.update.LinkInstance;
30 import org.efaps.util.EFapsException;
31
32 /**
33 * @author The eFaps Team
34 * @version $Id$
35 */
36 public class MenuUpdate
37 extends CommandUpdate
38 {
39 /**
40 * The links for the Menu to be updated.
41 */
42 protected static final Set<Link> ALLLINKS = new HashSet<Link>();
43
44 /** Link from menu to child command / menu. */
45 private static final Link LINK2CHILD = new OrderedLink("Admin_UI_Menu2Command",
46 "FromMenu",
47 "Admin_UI_Command", "ToCommand").setIncludeChildTypes(true);
48
49 /** Link from menu to type as type tree menu. */
50 private static final Link LINK2TYPE = new UniqueLink("Admin_UI_LinkIsTypeTreeFor", "From",
51 "Admin_DataModel_Type", "To");
52
53 static {
54 MenuUpdate.ALLLINKS.add(MenuUpdate.LINK2CHILD);
55 MenuUpdate.ALLLINKS.add(MenuUpdate.LINK2TYPE);
56 MenuUpdate.ALLLINKS.addAll(CommandUpdate.ALLLINKS);
57 }
58
59 /**
60 * @param _url URL to the Configuration Item.
61 */
62 public MenuUpdate(final URL _url)
63 {
64 super(_url, "Admin_UI_Menu", MenuUpdate.ALLLINKS);
65 }
66
67 /**
68 *
69 * @param _url URL to the Configuration Item.
70 * @param _typeName Name of the type
71 * @param _allLinks link definitions
72 */
73 protected MenuUpdate(final URL _url,
74 final String _typeName,
75 final Set<Link> _allLinks)
76 {
77 super(_url, _typeName, _allLinks);
78 }
79
80 /**
81 * Creates new instance of class {@link MenuDefinition}.
82 *
83 * @return new definition instance
84 * @see MenuDefinition
85 */
86 @Override
87 protected AbstractDefinition newDefinition()
88 {
89 return new MenuDefinition();
90 }
91
92 /**
93 *
94 */
95 protected class MenuDefinition
96 extends CommandDefinition
97 {
98 @Override
99 protected void readXML(final List<String> _tags,
100 final Map<String, String> _attributes,
101 final String _text)
102 throws EFapsException
103 {
104 final String value = _tags.get(0);
105 if ("childs".equals(value)) {
106 if (_tags.size() > 1) {
107 final String subValue = _tags.get(1);
108 if ("child".equals(subValue)) {
109 final LinkInstance child = new LinkInstance(_text);
110 addLink(MenuUpdate.LINK2CHILD, child);
111 } else {
112 super.readXML(_tags, _attributes, _text);
113 }
114 }
115 } else if ("type".equals(value)) {
116 // assigns a type the menu for which this menu instance is the type
117 // tree menu
118 addLink(MenuUpdate.LINK2TYPE, new LinkInstance(_text));
119 } else {
120 super.readXML(_tags, _attributes, _text);
121 }
122 }
123 }
124 }