From 2cf367f1970133303c872e969861be6147196fef Mon Sep 17 00:00:00 2001 From: James Moger Date: Tue, 3 Jun 2014 09:13:58 -0400 Subject: [PATCH] Extract re-usable checkbox, choice, and text option panels --- .../wicket/pages/EditRepositoryPage.html | 33 ------- .../wicket/pages/EditRepositoryPage.java | 90 +++++-------------- .../wicket/panels/AccessPolicyPanel.html | 9 -- .../wicket/panels/AccessPolicyPanel.java | 12 +-- .../gitblit/wicket/panels/CheckboxOption.html | 17 ++++ .../gitblit/wicket/panels/CheckboxOption.java | 53 +++++++++++ .../gitblit/wicket/panels/ChoiceOption.html | 19 ++++ .../gitblit/wicket/panels/ChoiceOption.java | 51 +++++++++++ .../panels/RegistrantPermissionsPanel.html | 2 +- .../com/gitblit/wicket/panels/TextOption.html | 20 +++++ .../com/gitblit/wicket/panels/TextOption.java | 53 +++++++++++ 11 files changed, 239 insertions(+), 120 deletions(-) create mode 100644 src/main/java/com/gitblit/wicket/panels/CheckboxOption.html create mode 100644 src/main/java/com/gitblit/wicket/panels/CheckboxOption.java create mode 100644 src/main/java/com/gitblit/wicket/panels/ChoiceOption.html create mode 100644 src/main/java/com/gitblit/wicket/panels/ChoiceOption.java create mode 100644 src/main/java/com/gitblit/wicket/panels/TextOption.html create mode 100644 src/main/java/com/gitblit/wicket/panels/TextOption.java diff --git a/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.html b/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.html index b5f9528f..1e683b4f 100644 --- a/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.html +++ b/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.html @@ -189,38 +189,5 @@ - -
-
- -
- -
-
- - -
-
- -
- - -
-
- \ No newline at end of file diff --git a/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java b/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java index 16dac895..f891595c 100644 --- a/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java +++ b/src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java @@ -43,7 +43,6 @@ import org.apache.wicket.markup.html.form.TextField; import org.apache.wicket.markup.html.link.Link; import org.apache.wicket.markup.html.list.ListItem; import org.apache.wicket.markup.html.list.ListView; -import org.apache.wicket.markup.html.panel.Fragment; import org.apache.wicket.model.CompoundPropertyModel; import org.apache.wicket.model.IModel; import org.apache.wicket.model.Model; @@ -72,8 +71,11 @@ import com.gitblit.wicket.WicketUtils; import com.gitblit.wicket.panels.AccessPolicyPanel; import com.gitblit.wicket.panels.BasePanel.JavascriptEventConfirmation; import com.gitblit.wicket.panels.BulletListPanel; +import com.gitblit.wicket.panels.CheckboxOption; +import com.gitblit.wicket.panels.ChoiceOption; import com.gitblit.wicket.panels.RegistrantPermissionsPanel; import com.gitblit.wicket.panels.RepositoryNamePanel; +import com.gitblit.wicket.panels.TextOption; public class EditRepositoryPage extends RootSubPage { @@ -417,7 +419,7 @@ public class EditRepositoryPage extends RootSubPage { // XXX AccessPolicyPanel is defined later. - form.add(newChoice("head", + form.add(new ChoiceOption("head", getString("gb.headRef"), getString("gb.headRefDescription"), new PropertyModel(repositoryModel, "HEAD"), @@ -434,22 +436,22 @@ public class EditRepositoryPage extends RootSubPage { // // TICKETS // - form.add(newCheckbox("acceptNewPatchsets", + form.add(new CheckboxOption("acceptNewPatchsets", getString("gb.acceptNewPatchsets"), getString("gb.acceptNewPatchsetsDescription"), new PropertyModel(repositoryModel, "acceptNewPatchsets"))); - form.add(newCheckbox("acceptNewTickets", + form.add(new CheckboxOption("acceptNewTickets", getString("gb.acceptNewTickets"), getString("gb.acceptNewTicketsDescription"), new PropertyModel(repositoryModel, "acceptNewPatchsets"))); - form.add(newCheckbox("requireApproval", + form.add(new CheckboxOption("requireApproval", getString("gb.requireApproval"), getString("gb.requireApprovalDescription"), new PropertyModel(repositoryModel, "requireApproval"))); - form.add(newChoice("mergeTo", + form.add(new ChoiceOption("mergeTo", getString("gb.mergeTo"), getString("gb.mergeToDescription"), new PropertyModel(repositoryModel, "mergeTo"), @@ -458,22 +460,22 @@ public class EditRepositoryPage extends RootSubPage { // // RECEIVE // - form.add(newCheckbox("isFrozen", + form.add(new CheckboxOption("isFrozen", getString("gb.isFrozen"), getString("gb.isFrozenDescription"), new PropertyModel(repositoryModel, "isFrozen"))); - form.add(newCheckbox("incrementalPushTags", + form.add(new CheckboxOption("incrementalPushTags", getString("gb.enableIncrementalPushTags"), getString("gb.useIncrementalPushTagsDescription"), new PropertyModel(repositoryModel, "useIncrementalPushTags"))); final CheckBox verifyCommitter = new CheckBox("checkbox", new PropertyModel(repositoryModel, "verifyCommitter")); verifyCommitter.setOutputMarkupId(true); - form.add(newCheckbox("verifyCommitter", + form.add(new CheckboxOption("verifyCommitter", getString("gb.verifyCommitter"), - getString("gb.verifyCommitterDescription"), - verifyCommitter)); + getString("gb.verifyCommitterDescription") + "
" + getString("gb.verifyCommitterNote"), + verifyCommitter).setIsHtmlDescription(true)); form.add(preReceivePalette); form.add(new BulletListPanel("inheritedPreReceive", getString("gb.inherited"), app().repositories() @@ -496,7 +498,7 @@ public class EditRepositoryPage extends RootSubPage { federationStrategies.remove(FederationStrategy.FEDERATE_ORIGIN); } - form.add(newChoice("federationStrategy", + form.add(new ChoiceOption("federationStrategy", getString("gb.federationStrategy"), getString("gb.federationStrategyDescription"), new DropDownChoice( @@ -521,7 +523,7 @@ public class EditRepositoryPage extends RootSubPage { repositoryModel.gcPeriod = defaultGcPeriod; } List gcPeriods = Arrays.asList(1, 2, 3, 4, 5, 7, 10, 14 ); - form.add(newChoice("gcPeriod", + form.add(new ChoiceOption("gcPeriod", getString("gb.gcPeriod"), getString("gb.gcPeriodDescription"), new DropDownChoice("choice", @@ -529,7 +531,7 @@ public class EditRepositoryPage extends RootSubPage { gcPeriods, new GCPeriodRenderer())).setEnabled(gcEnabled)); - form.add(newTextfield("gcThreshold", + form.add(new TextOption("gcThreshold", getString("gb.gcThreshold"), getString("gb.gcThresholdDescription"), "span1", @@ -539,29 +541,29 @@ public class EditRepositoryPage extends RootSubPage { // MISCELLANEOUS // - form.add(newTextfield("origin", + form.add(new TextOption("origin", getString("gb.origin"), getString("gb.originDescription"), "span6", new PropertyModel(repositoryModel, "origin")).setEnabled(false)); - form.add(newCheckbox("showRemoteBranches", + form.add(new CheckboxOption("showRemoteBranches", getString("gb.showRemoteBranches"), getString("gb.showRemoteBranchesDescription"), new PropertyModel(repositoryModel, "showRemoteBranches"))); - form.add(newCheckbox("skipSizeCalculation", + form.add(new CheckboxOption("skipSizeCalculation", getString("gb.skipSizeCalculation"), getString("gb.skipSizeCalculationDescription"), new PropertyModel(repositoryModel, "skipSizeCalculation"))); - form.add(newCheckbox("skipSummaryMetrics", + form.add(new CheckboxOption("skipSummaryMetrics", getString("gb.skipSummaryMetrics"), getString("gb.skipSummaryMetricsDescription"), new PropertyModel(repositoryModel, "skipSummaryMetrics"))); List maxActivityCommits = Arrays.asList(-1, 0, 25, 50, 75, 100, 150, 200, 250, 500); - form.add(newChoice("maxActivityCommits", + form.add(new ChoiceOption("maxActivityCommits", getString("gb.maxActivityCommits"), getString("gb.maxActivityCommitsDescription"), new DropDownChoice("choice", @@ -570,7 +572,7 @@ public class EditRepositoryPage extends RootSubPage { new MaxActivityCommitsRenderer()))); List renderers = Arrays.asList(CommitMessageRenderer.values()); - form.add(newChoice("commitMessageRenderer", + form.add(new ChoiceOption("commitMessageRenderer", getString("gb.commitMessageRenderer"), getString("gb.commitMessageRendererDescription"), new DropDownChoice("choice", @@ -580,7 +582,7 @@ public class EditRepositoryPage extends RootSubPage { metricAuthorExclusions = new Model(ArrayUtils.isEmpty(repositoryModel.metricAuthorExclusions) ? "" : StringUtils.flattenStrings(repositoryModel.metricAuthorExclusions, " ")); - form.add(newTextfield("metricAuthorExclusions", + form.add(new TextOption("metricAuthorExclusions", getString("gb.metricAuthorExclusions"), getString("gb.metricAuthorExclusions"), "span6", @@ -589,7 +591,7 @@ public class EditRepositoryPage extends RootSubPage { mailingLists = new Model(ArrayUtils.isEmpty(repositoryModel.mailingLists) ? "" : StringUtils.flattenStrings(repositoryModel.mailingLists, " ")); - form.add(newTextfield("mailingLists", + form.add(new TextOption("mailingLists", getString("gb.mailingLists"), getString("gb.mailingLists"), "span6", @@ -752,50 +754,6 @@ public class EditRepositoryPage extends RootSubPage { } } - private Fragment newCheckbox(String wicketId, String title, String description, IModel model) { - Fragment fragment = new Fragment(wicketId, "checkboxOption", this); - fragment.add(new Label("name", title)); - fragment.add(new Label("description", description)); - fragment.add(new CheckBox("checkbox", model)); - return fragment; - } - - private Fragment newCheckbox(String wicketId, String title, String description, CheckBox checkbox) { - Fragment fragment = new Fragment(wicketId, "checkboxOption", this); - fragment.add(new Label("name", title)); - fragment.add(new Label("description", description)); - fragment.add(checkbox); - return fragment; - } - - private Fragment newChoice(String wicketId, String title, String description, IModel model, List choices) { - Fragment fragment = new Fragment(wicketId, "choiceOption", this); - fragment.add(new Label("name", title)); - fragment.add(new Label("description", description)); - fragment.add(new DropDownChoice<>("choice", model, choices).setEnabled(choices.size() > 0)); - return fragment; - } - - private Fragment newChoice(String wicketId, String title, String description, DropDownChoice choice) { - Fragment fragment = new Fragment(wicketId, "choiceOption", this); - fragment.add(new Label("name", title)); - fragment.add(new Label("description", description)); - fragment.add(choice.setEnabled(choice.getChoices().size() > 0)); - return fragment; - } - - private Fragment newTextfield(String wicketId, String title, String description, String css, IModel model) { - Fragment fragment = new Fragment(wicketId, "textfieldOption", this); - fragment.add(new Label("name", title)); - fragment.add(new Label("description", description)); - TextField tf = new TextField("text", model); - if (!StringUtils.isEmpty(css)) { - WicketUtils.setCssClass(tf, css); - } - fragment.add(tf); - return fragment; - } - private class FederationTypeRenderer implements IChoiceRenderer { diff --git a/src/main/java/com/gitblit/wicket/panels/AccessPolicyPanel.html b/src/main/java/com/gitblit/wicket/panels/AccessPolicyPanel.html index 965c4d51..d3c29ba7 100644 --- a/src/main/java/com/gitblit/wicket/panels/AccessPolicyPanel.html +++ b/src/main/java/com/gitblit/wicket/panels/AccessPolicyPanel.html @@ -27,15 +27,6 @@
- -
-
- -
- -
-
- \ No newline at end of file diff --git a/src/main/java/com/gitblit/wicket/panels/AccessPolicyPanel.java b/src/main/java/com/gitblit/wicket/panels/AccessPolicyPanel.java index 7aa801f4..4f234263 100644 --- a/src/main/java/com/gitblit/wicket/panels/AccessPolicyPanel.java +++ b/src/main/java/com/gitblit/wicket/panels/AccessPolicyPanel.java @@ -21,12 +21,10 @@ import java.util.List; import org.apache.wicket.ajax.form.AjaxFormChoiceComponentUpdatingBehavior; import org.apache.wicket.markup.html.basic.Label; -import org.apache.wicket.markup.html.form.CheckBox; import org.apache.wicket.markup.html.form.Radio; import org.apache.wicket.markup.html.form.RadioGroup; import org.apache.wicket.markup.html.list.ListItem; import org.apache.wicket.markup.html.list.ListView; -import org.apache.wicket.markup.html.panel.Fragment; import org.apache.wicket.model.IModel; import org.apache.wicket.model.Model; @@ -148,7 +146,7 @@ public class AccessPolicyPanel extends BasePanel { add(policiesGroup); allowForks = Model.of(true); - add(newCheckbox("allowForks", + add(new CheckboxOption("allowForks", getString("gb.allowForks"), getString("gb.allowForksDescription"), allowForks).setEnabled(app().settings().getBoolean(Keys.web.allowForking, true))); @@ -156,14 +154,6 @@ public class AccessPolicyPanel extends BasePanel { setOutputMarkupId(true); } - private Fragment newCheckbox(String wicketId, String title, String description, IModel model) { - Fragment fragment = new Fragment(wicketId, "checkboxOption", this); - fragment.add(new Label("name", title)); - fragment.add(new Label("description", description)); - fragment.add(new CheckBox("checkbox", model)); - return fragment; - } - public void updateModel(RepositoryModel repository) { AccessPolicy policy = policiesGroup.getModelObject(); repository.authorizationControl = policy.control; diff --git a/src/main/java/com/gitblit/wicket/panels/CheckboxOption.html b/src/main/java/com/gitblit/wicket/panels/CheckboxOption.html new file mode 100644 index 00000000..6684fe92 --- /dev/null +++ b/src/main/java/com/gitblit/wicket/panels/CheckboxOption.html @@ -0,0 +1,17 @@ + + + + + +
+
+ +
+ +
+
+ + \ No newline at end of file diff --git a/src/main/java/com/gitblit/wicket/panels/CheckboxOption.java b/src/main/java/com/gitblit/wicket/panels/CheckboxOption.java new file mode 100644 index 00000000..086d8ef2 --- /dev/null +++ b/src/main/java/com/gitblit/wicket/panels/CheckboxOption.java @@ -0,0 +1,53 @@ +/* + * Copyright 2014 gitblit.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gitblit.wicket.panels; + +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.form.CheckBox; +import org.apache.wicket.model.IModel; + +/** + * A re-usable checkbox option panel. + * + * [x] title + * description + * + * @author James Moger + * + */ +public class CheckboxOption extends BasePanel { + + private static final long serialVersionUID = 1L; + + public CheckboxOption(String wicketId, String title, String description, IModel model) { + super(wicketId); + add(new Label("name", title)); + add(new Label("description", description)); + add(new CheckBox("checkbox", model)); + } + + public CheckboxOption(String wicketId, String title, String description, CheckBox checkbox) { + super(wicketId); + add(new Label("name", title)); + add(new Label("description", description)); + add(checkbox.setMarkupId("checkbox")); + } + + public CheckboxOption setIsHtmlDescription(boolean val) { + ((Label) get("description")).setEscapeModelStrings(!val); + return this; + } +} diff --git a/src/main/java/com/gitblit/wicket/panels/ChoiceOption.html b/src/main/java/com/gitblit/wicket/panels/ChoiceOption.html new file mode 100644 index 00000000..8c34c819 --- /dev/null +++ b/src/main/java/com/gitblit/wicket/panels/ChoiceOption.html @@ -0,0 +1,19 @@ + + + + + +
+
+ +
+
diff --git a/src/main/java/com/gitblit/wicket/panels/TextOption.html b/src/main/java/com/gitblit/wicket/panels/TextOption.html new file mode 100644 index 00000000..ff2da78e --- /dev/null +++ b/src/main/java/com/gitblit/wicket/panels/TextOption.html @@ -0,0 +1,20 @@ + + + + + +
+
+ +
+ + +
+
+ + \ No newline at end of file diff --git a/src/main/java/com/gitblit/wicket/panels/TextOption.java b/src/main/java/com/gitblit/wicket/panels/TextOption.java new file mode 100644 index 00000000..dcd465fb --- /dev/null +++ b/src/main/java/com/gitblit/wicket/panels/TextOption.java @@ -0,0 +1,53 @@ +/* + * Copyright 2014 gitblit.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gitblit.wicket.panels; + +import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.form.TextField; +import org.apache.wicket.model.IModel; + +import com.gitblit.utils.StringUtils; +import com.gitblit.wicket.WicketUtils; + +/** + * A re-usable textfield option panel. + * + * title + * description + * [textfield] + * + * @author James Moger + * + */ +public class TextOption extends BasePanel { + + private static final long serialVersionUID = 1L; + + public TextOption(String wicketId, String title, String description, IModel model) { + this(wicketId, title, description, null, model); + } + + public TextOption(String wicketId, String title, String description, String css, IModel model) { + super(wicketId); + add(new Label("name", title)); + add(new Label("description", description)); + TextField tf = new TextField("text", model); + if (!StringUtils.isEmpty(css)) { + WicketUtils.setCssClass(tf, css); + } + add(tf); + } +} -- 2.39.5