View Javadoc
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 io.github.tonywasher.joceanus.oceanus.resource.OceanusResourceId;
20  
21  import java.util.ArrayList;
22  import java.util.List;
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       * HelpId.
32       */
33      public interface MetisHelpId extends OceanusResourceId {
34      }
35  
36      /**
37       * Title of the entry.
38       */
39      private final String theTitle;
40  
41      /**
42       * Name of the entry.
43       */
44      private final String theName;
45  
46      /**
47       * HelpId of the entry.
48       */
49      private final MetisHelpId theId;
50  
51      /**
52       * Children of the entry.
53       */
54      private List<MetisHelpEntry> theChildren;
55  
56      /**
57       * HTML.
58       */
59      private String theHtml;
60  
61      /**
62       * Constructor for an HTML element.
63       *
64       * @param <K>     the key type
65       * @param pName   the name by which this entry is referenced
66       * @param pTitle  the title for this page in the table of contents
67       * @param pHelpId the helpId representing the HTML for this entry
68       */
69      public <K extends Enum<K> & MetisHelpId> MetisHelpEntry(final String pName,
70                                                              final String pTitle,
71                                                              final K pHelpId) {
72          theName = pName;
73          theTitle = pTitle;
74          theId = pHelpId;
75      }
76  
77      /**
78       * Constructor for a table of contents element.
79       *
80       * @param pName  the name by which this entry is referenced
81       * @param pTitle the title for this page in the table of contents
82       */
83      public MetisHelpEntry(final String pName,
84                            final String pTitle) {
85          theName = pName;
86          theTitle = pTitle;
87          theId = null;
88      }
89  
90      /**
91       * Add child entry.
92       *
93       * @param pChild the child
94       * @return the HelpEntry
95       */
96      public MetisHelpEntry addChildEntry(final MetisHelpEntry pChild) {
97          if (theChildren == null) {
98              theChildren = new ArrayList<>();
99          }
100         theChildren.add(pChild);
101         return pChild;
102     }
103 
104     /**
105      * Obtain the title.
106      *
107      * @return the title
108      */
109     public String getTitle() {
110         return theTitle;
111     }
112 
113     /**
114      * Obtain the name.
115      *
116      * @return the name
117      */
118     public String getName() {
119         return theName;
120     }
121 
122     /**
123      * Obtain the helpId.
124      *
125      * @return the id
126      */
127     public MetisHelpId getHelpId() {
128         return theId;
129     }
130 
131     /**
132      * Obtain the children.
133      *
134      * @return the children
135      */
136     public List<MetisHelpEntry> getChildren() {
137         return theChildren;
138     }
139 
140     /**
141      * Obtain the HTML.
142      *
143      * @return the HTML
144      */
145     public String getHtml() {
146         return theHtml;
147     }
148 
149     /**
150      * Set the HTML.
151      *
152      * @param pHtml the HTML
153      */
154     protected void setHtml(final String pHtml) {
155         theHtml = pHtml;
156     }
157 
158     @Override
159     public String toString() {
160         return getTitle();
161     }
162 }