Skip to content

Commit 27dd7d7

Browse files
Merge pull request #1734 from JohnMcGuinness/ensure-consistent-usage-of-HeadingLevel
Ensure consistent usage of HeadingLevel
2 parents c5c8efe + 3b5e449 commit 27dd7d7

28 files changed

+111
-71
lines changed

wcomponents-core/src/main/java/com/github/bordertech/wcomponents/WColumnLayout.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public WColumnLayout() {
4040
* @param heading the heading text.
4141
*/
4242
public WColumnLayout(final String heading) {
43-
this(new WHeading(WHeading.SECTION, heading));
43+
this(new WHeading(HeadingLevel.H3, heading));
4444
}
4545

4646
/**
@@ -80,7 +80,7 @@ public void setLeftColumn(final WComponent content) {
8080
* @param content the content.
8181
*/
8282
public void setLeftColumn(final String heading, final WComponent content) {
83-
setLeftColumn(new WHeading(WHeading.MINOR, heading), content);
83+
setLeftColumn(new WHeading(HeadingLevel.H4, heading), content);
8484
}
8585

8686
/**
@@ -109,7 +109,7 @@ public void setRightColumn(final WComponent content) {
109109
* @param content the content.
110110
*/
111111
public void setRightColumn(final String heading, final WComponent content) {
112-
setRightColumn(new WHeading(WHeading.MINOR, heading), content);
112+
setRightColumn(new WHeading(HeadingLevel.H4, heading), content);
113113
}
114114

115115
/**

wcomponents-core/src/test/java/com/github/bordertech/wcomponents/WColumnLayout_Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void testSetLeftColumn() {
3636
WColumnLayout col = new WColumnLayout();
3737
WLabel label = new WLabel("leftLabel");
3838
String headingText = "leftHeading";
39-
WHeading heading = new WHeading(WHeading.MINOR, headingText);
39+
WHeading heading = new WHeading(HeadingLevel.H4, headingText);
4040

4141
Assert.assertFalse("Should not have any content by default", col.hasLeftContent());
4242
col.setLeftColumn(label);
@@ -68,7 +68,7 @@ public void testSetRightColumn() {
6868
WColumnLayout col = new WColumnLayout();
6969
WLabel label = new WLabel("rightLabel");
7070
String headingText = "rightHeading";
71-
WHeading heading = new WHeading(WHeading.MINOR, headingText);
71+
WHeading heading = new WHeading(HeadingLevel.H4, headingText);
7272

7373
Assert.assertFalse("Should not have any content by default", col.hasRightContent());
7474
col.setRightColumn(label);

wcomponents-core/src/test/java/com/github/bordertech/wcomponents/WHeading_Test.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,20 @@ public void testHeadingLevelAccessors() {
6969
HeadingLevel.H1, HeadingLevel.H2, HeadingLevel.H3);
7070
}
7171

72+
@Test
73+
public void testHeadingTypeToHeadingLevelConversion() {
74+
75+
testHeadingLevelConversion(WHeading.TITLE, HeadingLevel.H1);
76+
testHeadingLevelConversion(WHeading.MAJOR, HeadingLevel.H2);
77+
testHeadingLevelConversion(WHeading.SECTION, HeadingLevel.H3);
78+
testHeadingLevelConversion(WHeading.MINOR, HeadingLevel.H4);
79+
testHeadingLevelConversion(WHeading.SUB_HEADING, HeadingLevel.H5);
80+
testHeadingLevelConversion(WHeading.SUB_SUB_HEADING, HeadingLevel.H6);
81+
}
82+
83+
private void testHeadingLevelConversion(int type, HeadingLevel headingLevel) {
84+
WHeading heading = new WHeading(type, "dummy");
85+
Assert.assertEquals("WHeading type conversion to HeadingLevel failed",
86+
headingLevel, heading.getHeadingLevel());
87+
}
7288
}

wcomponents-core/src/test/java/com/github/bordertech/wcomponents/render/webxml/WHeadingRenderer_Test.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.bordertech.wcomponents.render.webxml;
22

3+
import com.github.bordertech.wcomponents.HeadingLevel;
34
import com.github.bordertech.wcomponents.Margin;
45
import com.github.bordertech.wcomponents.Size;
56
import com.github.bordertech.wcomponents.WDecoratedLabel;
@@ -21,7 +22,7 @@ public class WHeadingRenderer_Test extends AbstractWebXmlRendererTestCase {
2122

2223
@Test
2324
public void testRendererCorrectlyConfigured() {
24-
WHeading component = new WHeading(WHeading.TITLE, "");
25+
WHeading component = new WHeading(HeadingLevel.H1, "");
2526
Assert.assertTrue("Incorrect renderer supplied",
2627
getWebXmlRenderer(component) instanceof WHeadingRenderer);
2728
}
@@ -30,27 +31,27 @@ public void testRendererCorrectlyConfigured() {
3031
public void testPaint() throws IOException, SAXException, XpathException {
3132
final String text = "WHeading_Test.testPaint.heading";
3233

33-
WHeading heading = new WHeading(WHeading.TITLE, text);
34+
WHeading heading = new WHeading(HeadingLevel.H1, text);
3435
assertSchemaMatch(heading);
3536
assertXpathEvaluatesTo(text, "//ui:heading[@level=1]", heading);
3637

37-
heading = new WHeading(WHeading.MAJOR, text);
38+
heading = new WHeading(HeadingLevel.H2, text);
3839
assertSchemaMatch(heading);
3940
assertXpathEvaluatesTo(text, "//ui:heading[@level=2]", heading);
4041

41-
heading = new WHeading(WHeading.SECTION, text);
42+
heading = new WHeading(HeadingLevel.H3, text);
4243
assertSchemaMatch(heading);
4344
assertXpathEvaluatesTo(text, "//ui:heading[@level=3]", heading);
4445

45-
heading = new WHeading(WHeading.MINOR, text);
46+
heading = new WHeading(HeadingLevel.H4, text);
4647
assertSchemaMatch(heading);
4748
assertXpathEvaluatesTo(text, "//ui:heading[@level=4]", heading);
4849

49-
heading = new WHeading(WHeading.SUB_HEADING, text);
50+
heading = new WHeading(HeadingLevel.H5, text);
5051
assertSchemaMatch(heading);
5152
assertXpathEvaluatesTo(text, "//ui:heading[@level=5]", heading);
5253

53-
heading = new WHeading(WHeading.SUB_SUB_HEADING, text);
54+
heading = new WHeading(HeadingLevel.H6, text);
5455
assertSchemaMatch(heading);
5556
assertXpathEvaluatesTo(text, "//ui:heading[@level=6]", heading);
5657

@@ -67,7 +68,7 @@ public void testPaintWithDecoratedLabel() throws IOException, SAXException, Xpat
6768
final String text1 = "WHeading_Test.testPaintWithDecoratedLabel.text1";
6869
final String text2 = "WHeading_Test.testPaintWithDecoratedLabel.text2";
6970

70-
WHeading heading = new WHeading(WHeading.TITLE, new WDecoratedLabel(new WText(text1)));
71+
WHeading heading = new WHeading(HeadingLevel.H1, new WDecoratedLabel(new WText(text1)));
7172
assertSchemaMatch(heading);
7273

7374
assertXpathEvaluatesTo(text1, "//ui:heading[@level=1]/ui:decoratedlabel/ui:labelbody/text()",
@@ -81,7 +82,7 @@ public void testPaintWithDecoratedLabel() throws IOException, SAXException, Xpat
8182

8283
@Test
8384
public void testRenderedWithMargins() throws IOException, SAXException, XpathException {
84-
WHeading heading = new WHeading(WHeading.TITLE, "test");
85+
WHeading heading = new WHeading(HeadingLevel.H1, "test");
8586
assertXpathNotExists("//ui:heading/ui:margin", heading);
8687

8788
Margin margin = new Margin(0);
@@ -109,7 +110,7 @@ public void testRenderedWithMargins() throws IOException, SAXException, XpathExc
109110

110111
@Test
111112
public void testXssEscaping() throws IOException, SAXException, XpathException {
112-
WHeading heading = new WHeading(WHeading.TITLE, new WDecoratedLabel(new WText("dummy")));
113+
WHeading heading = new WHeading(HeadingLevel.H1, new WDecoratedLabel(new WText("dummy")));
113114

114115
assertSafeContent(heading);
115116

wcomponents-core/src/test/java/com/github/bordertech/wcomponents/testapp/BigPanel.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.github.bordertech.wcomponents.Action;
44
import com.github.bordertech.wcomponents.ActionEvent;
5+
import com.github.bordertech.wcomponents.HeadingLevel;
56
import com.github.bordertech.wcomponents.RadioButtonGroup;
67
import com.github.bordertech.wcomponents.TestLookupTable;
78
import com.github.bordertech.wcomponents.WButton;
@@ -47,7 +48,7 @@ public BigPanel() {
4748

4849
List<String> progTypeList = getProgrammerTypeList();
4950

50-
add(new WHeading(WHeading.MAJOR, "Programmer social network"));
51+
add(new WHeading(HeadingLevel.H2, "Programmer social network"));
5152
leftColumn.addField("Name", new WTextField());
5253
leftColumn.addField("Date Of birth", new WDateField());
5354
leftColumn.addField("Day of week", new WDropdown(TestLookupTable.DayOfWeekTable.class));

wcomponents-core/src/test/java/com/github/bordertech/wcomponents/testapp/DetailsPage.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.github.bordertech.wcomponents.Action;
44
import com.github.bordertech.wcomponents.ActionEvent;
5+
import com.github.bordertech.wcomponents.HeadingLevel;
56
import com.github.bordertech.wcomponents.RadioButtonGroup;
67
import com.github.bordertech.wcomponents.TestLookupTable;
78
import com.github.bordertech.wcomponents.WButton;
@@ -34,7 +35,7 @@ public class DetailsPage extends WContainer {
3435
* Creates a DetailsPage.
3536
*/
3637
public DetailsPage() {
37-
add(new WHeading(WHeading.MAJOR, "Details"));
38+
add(new WHeading(HeadingLevel.H2, "Details"));
3839
// core input fields, tabs, collapsible, menu
3940

4041
WTabSet tabs = new WTabSet();

wcomponents-examples/src/main/java/com/github/bordertech/wcomponents/examples/KitchenSink.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.github.bordertech.wcomponents.Action;
44
import com.github.bordertech.wcomponents.ActionEvent;
5+
import com.github.bordertech.wcomponents.HeadingLevel;
56
import com.github.bordertech.wcomponents.Request;
67
import com.github.bordertech.wcomponents.WButton;
78
import com.github.bordertech.wcomponents.WContainer;
@@ -55,7 +56,7 @@ public void execute(final ActionEvent event) {
5556
tabs.addTab(new DuplicatorGroup(), "Dynamic Additions", WTabSet.TAB_MODE_CLIENT);
5657
tabs.addTab(new TextDuplicator(), "Text Duplicator", WTabSet.TAB_MODE_CLIENT);
5758

58-
add(new WHeading(WHeading.MAJOR, "Selection of tests"));
59+
add(new WHeading(HeadingLevel.H2, "Selection of tests"));
5960
add(tabs);
6061
}
6162

wcomponents-examples/src/main/java/com/github/bordertech/wcomponents/examples/LoadAjaxControlsExample.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.bordertech.wcomponents.examples;
22

3+
import com.github.bordertech.wcomponents.HeadingLevel;
34
import com.github.bordertech.wcomponents.WCollapsible;
45
import com.github.bordertech.wcomponents.WCollapsible.CollapsibleMode;
56
import com.github.bordertech.wcomponents.WContainer;
@@ -42,61 +43,61 @@ public LoadAjaxControlsExample() {
4243
CollapsibleMode.DYNAMIC);
4344
add(collapse);
4445

45-
content.add(new WHeading(WHeading.SECTION, "Lists using datalist"));
46+
content.add(new WHeading(HeadingLevel.H3, "Lists using datalist"));
4647

4748
WFieldLayout layout = new WFieldLayout();
4849
createFields(layout, "icao");
4950
content.add(layout);
5051

5152
content.add(new WHorizontalRule());
52-
content.add(new WHeading(WHeading.SECTION, "Lists using different datalist"));
53+
content.add(new WHeading(HeadingLevel.H3, "Lists using different datalist"));
5354

5455
WFieldLayout layout2 = new WFieldLayout();
5556
createFields(layout2, new TableWithNullOption("icao"));
5657
content.add(layout2);
5758

5859
content.add(new WHorizontalRule());
59-
content.add(new WHeading(WHeading.SECTION, "Eager Panel"));
60+
content.add(new WHeading(HeadingLevel.H3, "Eager Panel"));
6061

6162
WPanel eager = new WPanel(WPanel.Type.BOX);
6263
eager.setMode(PanelMode.EAGER);
6364
eager.add(new WText("Eager panel content loaded via ajax."));
6465
content.add(eager);
6566

6667
content.add(new WHorizontalRule());
67-
content.add(new WHeading(WHeading.SECTION, "Ajax - Button"));
68+
content.add(new WHeading(HeadingLevel.H3, "Ajax - Button"));
6869
content.add(new AjaxWButtonExample());
6970

7071
content.add(new WHorizontalRule());
71-
content.add(new WHeading(WHeading.SECTION, "Ajax - CheckBox"));
72+
content.add(new WHeading(HeadingLevel.H3, "Ajax - CheckBox"));
7273
content.add(new AjaxWCheckboxExample());
7374

7475
content.add(new WHorizontalRule());
75-
content.add(new WHeading(WHeading.SECTION, "Ajax - Dropdown"));
76+
content.add(new WHeading(HeadingLevel.H3, "Ajax - Dropdown"));
7677
content.add(new AjaxWDropdownExample());
7778

7879
content.add(new WHorizontalRule());
79-
content.add(new WHeading(WHeading.SECTION, "Ajax - Table"));
80+
content.add(new WHeading(HeadingLevel.H3, "Ajax - Table"));
8081
content.add(new TreeTableExample());
8182

8283
content.add(new WHorizontalRule());
83-
content.add(new WHeading(WHeading.SECTION, "Ajax - Polling"));
84+
content.add(new WHeading(HeadingLevel.H3, "Ajax - Polling"));
8485
content.add(new AjaxPollingWButtonExample());
8586

8687
content.add(new WHorizontalRule());
87-
content.add(new WHeading(WHeading.SECTION, "Ajax - Lazy Panel"));
88+
content.add(new WHeading(HeadingLevel.H3, "Ajax - Lazy Panel"));
8889
content.add(new AjaxWPanelExample());
8990

9091
content.add(new WHorizontalRule());
91-
content.add(new WHeading(WHeading.SECTION, "Ajax - RadioButtonSelect"));
92+
content.add(new WHeading(HeadingLevel.H3, "Ajax - RadioButtonSelect"));
9293
content.add(new AjaxWRadioButtonSelectExample());
9394

9495
content.add(new WHorizontalRule());
95-
content.add(new WHeading(WHeading.SECTION, "Dialog"));
96+
content.add(new WHeading(HeadingLevel.H3, "Dialog"));
9697
content.add(new WDialogExample());
9798

9899
content.add(new WHorizontalRule());
99-
content.add(new WHeading(WHeading.SECTION, "Tab Modes"));
100+
content.add(new WHeading(HeadingLevel.H3, "Tab Modes"));
100101
WTabSet tabset1 = new WTabSet();
101102
tabset1.
102103
addTab(new DateText("Tab Content 1"), "Tab 1 (client)", WTabSet.TAB_MODE_CLIENT, '1');
@@ -111,7 +112,7 @@ public LoadAjaxControlsExample() {
111112
content.add(tabset1);
112113

113114
content.add(new WHorizontalRule());
114-
content.add(new WHeading(WHeading.SECTION, "Collapsibles"));
115+
content.add(new WHeading(HeadingLevel.H3, "Collapsibles"));
115116
content.add(new WCollapsible(new DateText("Eager Collapsible Content"), "Eager Mode",
116117
CollapsibleMode.EAGER));
117118
content.add(new WCollapsible(new DateText("Lazy Collapsible Content"), "Lazy Mode",

wcomponents-examples/src/main/java/com/github/bordertech/wcomponents/examples/TextFieldExample.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.github.bordertech.wcomponents.Action;
44
import com.github.bordertech.wcomponents.ActionEvent;
5+
import com.github.bordertech.wcomponents.HeadingLevel;
56
import com.github.bordertech.wcomponents.Request;
67
import com.github.bordertech.wcomponents.WButton;
78
import com.github.bordertech.wcomponents.WDefinitionList;
@@ -126,7 +127,7 @@ public void execute(final ActionEvent event) {
126127
fieldLayout.addField("Ten column field", tf5);
127128

128129
add(new WHorizontalRule());
129-
WHeading heading = new WHeading(WHeading.MAJOR, "Values read from fields");
130+
WHeading heading = new WHeading(HeadingLevel.H2, "Values read from fields");
130131
add(heading);
131132
WDefinitionList defList = new WDefinitionList(WDefinitionList.Type.COLUMN);
132133
defList.addTerm(tf1.getLabel().getText(), plain);

wcomponents-examples/src/main/java/com/github/bordertech/wcomponents/examples/WDataListServletExample.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.bordertech.wcomponents.examples;
22

3+
import com.github.bordertech.wcomponents.HeadingLevel;
34
import com.github.bordertech.wcomponents.Request;
45
import com.github.bordertech.wcomponents.WButton;
56
import com.github.bordertech.wcomponents.WComponent;
@@ -53,7 +54,7 @@ public class WDataListServletExample extends WContainer {
5354
* Construct the example.
5455
*/
5556
public WDataListServletExample() {
56-
add(new WHeading(WHeading.SECTION,
57+
add(new WHeading(HeadingLevel.H3,
5758
"Example of components using cached lists (WDataListServlet)"));
5859

5960
add(layout);

wcomponents-examples/src/main/java/com/github/bordertech/wcomponents/examples/WDefinitionListExample.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.bordertech.wcomponents.examples;
22

3+
import com.github.bordertech.wcomponents.HeadingLevel;
34
import com.github.bordertech.wcomponents.WContainer;
45
import com.github.bordertech.wcomponents.WDefinitionList;
56
import com.github.bordertech.wcomponents.WHeading;
@@ -17,22 +18,22 @@ public class WDefinitionListExample extends WContainer {
1718
* Creates a WDefinitionListExample.
1819
*/
1920
public WDefinitionListExample() {
20-
add(new WHeading(WHeading.SECTION, "Normal layout"));
21+
add(new WHeading(HeadingLevel.H3, "Normal layout"));
2122
WDefinitionList list = new WDefinitionList();
2223
addListItems(list);
2324
add(list);
2425

25-
add(new WHeading(WHeading.SECTION, "Flat layout"));
26+
add(new WHeading(HeadingLevel.H3, "Flat layout"));
2627
list = new WDefinitionList(WDefinitionList.Type.FLAT);
2728
addListItems(list);
2829
add(list);
2930

30-
add(new WHeading(WHeading.SECTION, "Stacked layout"));
31+
add(new WHeading(HeadingLevel.H3, "Stacked layout"));
3132
list = new WDefinitionList(WDefinitionList.Type.STACKED);
3233
addListItems(list);
3334
add(list);
3435

35-
add(new WHeading(WHeading.SECTION, "Column layout"));
36+
add(new WHeading(HeadingLevel.H3, "Column layout"));
3637
list = new WDefinitionList(WDefinitionList.Type.COLUMN);
3738
addListItems(list);
3839
add(list);

wcomponents-examples/src/main/java/com/github/bordertech/wcomponents/examples/WDialogExample.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,13 @@ public void execute(final ActionEvent event) {
251251
add(dialogWithHeight2);
252252
add(dialogWithMode);
253253

254-
add(new WHeading(WHeading.MAJOR, "Dialogs which open without page reload"));
254+
add(new WHeading(HeadingLevel.H2, "Dialogs which open without page reload"));
255255
//remember the button of an immediate is part of the dialog: it will be place into the UI wherever the dialog is placed
256256
add(nonModalDialog);
257257
add(modalDialog);
258258
// for buttons which will result in a dialog on reload the button is added to the UI explicitly
259259

260-
add(new WHeading(WHeading.MAJOR, "Dialogs which open after page reload"));
260+
add(new WHeading(HeadingLevel.H2, "Dialogs which open after page reload"));
261261
add(dialogButton1);
262262
add(dialogButton2);
263263

wcomponents-examples/src/main/java/com/github/bordertech/wcomponents/examples/WPanelExample.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.bordertech.wcomponents.examples;
22

3+
import com.github.bordertech.wcomponents.HeadingLevel;
34
import com.github.bordertech.wcomponents.WButton;
45
import com.github.bordertech.wcomponents.WContainer;
56
import com.github.bordertech.wcomponents.WHeading;
@@ -26,7 +27,7 @@ public WPanelExample() {
2627
add(new WHorizontalRule());
2728
}
2829

29-
add(new WHeading(WHeading.SECTION, panelType.toString()));
30+
add(new WHeading(HeadingLevel.H3, panelType.toString()));
3031

3132
WPanel panel = new WPanel(panelType);
3233
panel.setTitleText("Panel title");

wcomponents-examples/src/main/java/com/github/bordertech/wcomponents/examples/WShufflerExample.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.bordertech.wcomponents.examples;
22

3+
import com.github.bordertech.wcomponents.HeadingLevel;
34
import com.github.bordertech.wcomponents.Request;
45
import com.github.bordertech.wcomponents.WButton;
56
import com.github.bordertech.wcomponents.WContainer;
@@ -30,7 +31,7 @@ public class WShufflerExample extends WContainer {
3031
* Construct the example.
3132
*/
3233
public WShufflerExample() {
33-
add(new WHeading(WHeading.SECTION, "WShuffler examples"));
34+
add(new WHeading(HeadingLevel.H3, "WShuffler examples"));
3435

3536
WFieldLayout layout = new WFieldLayout();
3637
add(layout);

0 commit comments

Comments
 (0)