1 /*
2 * Metis: Java Data Framework
3 * Copyright 2012-2026. Tony Washer
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6 * use this file except in compliance with the License. You may obtain a copy
7 * of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17 package io.github.tonywasher.joceanus.metis.help;
18
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import io.github.tonywasher.joceanus.metis.help.MetisHelpModule.MetisHelpId;
23
24 /**
25 * Help Entry class. This class provides structure to the help system, providing parent child
26 * relationships to implement chapters and also providing maps between the name of a help page and
27 * the file that holds the HTML for the page
28 */
29 public class MetisHelpEntry {
30 /**
31 * Title of the entry.
32 */
33 private final String theTitle;
34
35 /**
36 * Name of the entry.
37 */
38 private final String theName;
39
40 /**
41 * HelpId of the entry.
42 */
43 private final MetisHelpId theId;
44
45 /**
46 * Children of the entry.
47 */
48 private List<MetisHelpEntry> theChildren;
49
50 /**
51 * HTML.
52 */
53 private String theHtml;
54
55 /**
56 * Constructor for an HTML element.
57 *
58 * @param <K> the key type
59 * @param pName the name by which this entry is referenced
60 * @param pTitle the title for this page in the table of contents
61 * @param pHelpId the helpId representing the HTML for this entry
62 */
63 public <K extends Enum<K> & MetisHelpId> MetisHelpEntry(final String pName,
64 final String pTitle,
65 final K pHelpId) {
66 theName = pName;
67 theTitle = pTitle;
68 theId = pHelpId;
69 }
70
71 /**
72 * Constructor for a table of contents element.
73 *
74 * @param pName the name by which this entry is referenced
75 * @param pTitle the title for this page in the table of contents
76 */
77 public MetisHelpEntry(final String pName,
78 final String pTitle) {
79 theName = pName;
80 theTitle = pTitle;
81 theId = null;
82 }
83
84 /**
85 * Add child entry.
86 *
87 * @param pChild the child
88 * @return the HelpEntry
89 */
90 public MetisHelpEntry addChildEntry(final MetisHelpEntry pChild) {
91 if (theChildren == null) {
92 theChildren = new ArrayList<>();
93 }
94 theChildren.add(pChild);
95 return pChild;
96 }
97
98 /**
99 * Obtain the title.
100 *
101 * @return the title
102 */
103 public String getTitle() {
104 return theTitle;
105 }
106
107 /**
108 * Obtain the name.
109 *
110 * @return the name
111 */
112 public String getName() {
113 return theName;
114 }
115
116 /**
117 * Obtain the helpId.
118 *
119 * @return the id
120 */
121 public MetisHelpId getHelpId() {
122 return theId;
123 }
124
125 /**
126 * Obtain the children.
127 *
128 * @return the children
129 */
130 public List<MetisHelpEntry> getChildren() {
131 return theChildren;
132 }
133
134 /**
135 * Obtain the HTML.
136 *
137 * @return the HTML
138 */
139 public String getHtml() {
140 return theHtml;
141 }
142
143 /**
144 * Set the HTML.
145 *
146 * @param pHtml the HTML
147 */
148 protected void setHtml(final String pHtml) {
149 theHtml = pHtml;
150 }
151
152 @Override
153 public String toString() {
154 return getTitle();
155 }
156 }