James Moger
2014-06-03 2cf367f1970133303c872e969861be6147196fef
Extract re-usable checkbox, choice, and text option panels
6 files added
5 files modified
359 ■■■■■ changed files
src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.html 33 ●●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java 90 ●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/wicket/panels/AccessPolicyPanel.html 9 ●●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/wicket/panels/AccessPolicyPanel.java 12 ●●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/wicket/panels/CheckboxOption.html 17 ●●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/wicket/panels/CheckboxOption.java 53 ●●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/wicket/panels/ChoiceOption.html 19 ●●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/wicket/panels/ChoiceOption.java 51 ●●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/wicket/panels/RegistrantPermissionsPanel.html 2 ●●● patch | view | raw | blame | history
src/main/java/com/gitblit/wicket/panels/TextOption.html 20 ●●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/wicket/panels/TextOption.java 53 ●●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.html
@@ -189,38 +189,5 @@
</form>    
</body>
<wicket:fragment wicket:id="checkboxOption">
    <div style="padding-top:4px;">
        <div>
            <label style="font-weight:bold;" class="checkbox"><input type="checkbox" wicket:id="checkbox" /> <span wicket:id="name"></span></label>
        </div>
        <label class="checkbox" style="color:#777;" wicket:id="description"></label>
    </div>
</wicket:fragment>
<wicket:fragment wicket:id="choiceOption">
    <div style="padding-top:4px;">
        <div>
            <b><span wicket:id="name"></span></b>
        </div>
        <label class="checkbox" style="color:#777;"> <span wicket:id="description"></span>
        <p style="padding-top:5px;"><select class="span2" wicket:id="choice" /></p>
        </label>
    </div>
</wicket:fragment>
<wicket:fragment wicket:id="textfieldOption">
    <div style="padding-top:4px;">
        <div>
            <b><span wicket:id="name"></span></b>
        </div>
        <label class="checkbox" style="color:#777;"> <span wicket:id="description"></span>
        <p style="padding-top:5px;"><input class="span2" type="text" wicket:id="text" /></p>
        </label>
    </div>
</wicket:fragment>
</wicket:extend>
</html>
src/main/java/com/gitblit/wicket/pages/EditRepositoryPage.java
@@ -43,7 +43,6 @@
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.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 @@
        // XXX AccessPolicyPanel is defined later.
        form.add(newChoice("head",
        form.add(new ChoiceOption<String>("head",
                getString("gb.headRef"),
                getString("gb.headRefDescription"),
                new PropertyModel<String>(repositoryModel, "HEAD"),
@@ -434,22 +436,22 @@
        //
        // TICKETS
        //
        form.add(newCheckbox("acceptNewPatchsets",
        form.add(new CheckboxOption("acceptNewPatchsets",
                getString("gb.acceptNewPatchsets"),
                getString("gb.acceptNewPatchsetsDescription"),
                new PropertyModel<Boolean>(repositoryModel, "acceptNewPatchsets")));
        form.add(newCheckbox("acceptNewTickets",
        form.add(new CheckboxOption("acceptNewTickets",
                getString("gb.acceptNewTickets"),
                getString("gb.acceptNewTicketsDescription"),
                new PropertyModel<Boolean>(repositoryModel, "acceptNewPatchsets")));
        form.add(newCheckbox("requireApproval",
        form.add(new CheckboxOption("requireApproval",
                getString("gb.requireApproval"),
                getString("gb.requireApprovalDescription"),
                new PropertyModel<Boolean>(repositoryModel, "requireApproval")));
        form.add(newChoice("mergeTo",
        form.add(new ChoiceOption<String>("mergeTo",
                getString("gb.mergeTo"),
                getString("gb.mergeToDescription"),
                new PropertyModel<String>(repositoryModel, "mergeTo"),
@@ -458,22 +460,22 @@
        //
        // RECEIVE
        //
        form.add(newCheckbox("isFrozen",
        form.add(new CheckboxOption("isFrozen",
                getString("gb.isFrozen"),
                getString("gb.isFrozenDescription"),
                new PropertyModel<Boolean>(repositoryModel, "isFrozen")));
        form.add(newCheckbox("incrementalPushTags",
        form.add(new CheckboxOption("incrementalPushTags",
                getString("gb.enableIncrementalPushTags"),
                getString("gb.useIncrementalPushTagsDescription"),
                new PropertyModel<Boolean>(repositoryModel, "useIncrementalPushTags")));
        final CheckBox verifyCommitter = new CheckBox("checkbox", new PropertyModel<Boolean>(repositoryModel, "verifyCommitter"));
        verifyCommitter.setOutputMarkupId(true);
        form.add(newCheckbox("verifyCommitter",
        form.add(new CheckboxOption("verifyCommitter",
                getString("gb.verifyCommitter"),
                getString("gb.verifyCommitterDescription"),
                verifyCommitter));
                getString("gb.verifyCommitterDescription") + "<br/>" + getString("gb.verifyCommitterNote"),
                verifyCommitter).setIsHtmlDescription(true));
        form.add(preReceivePalette);
        form.add(new BulletListPanel("inheritedPreReceive", getString("gb.inherited"), app().repositories()
@@ -496,7 +498,7 @@
            federationStrategies.remove(FederationStrategy.FEDERATE_ORIGIN);
        }
        form.add(newChoice("federationStrategy",
        form.add(new ChoiceOption<FederationStrategy>("federationStrategy",
                getString("gb.federationStrategy"),
                getString("gb.federationStrategyDescription"),
                new DropDownChoice<FederationStrategy>(
@@ -521,7 +523,7 @@
            repositoryModel.gcPeriod = defaultGcPeriod;
        }
        List<Integer> gcPeriods = Arrays.asList(1, 2, 3, 4, 5, 7, 10, 14 );
        form.add(newChoice("gcPeriod",
        form.add(new ChoiceOption<Integer>("gcPeriod",
                getString("gb.gcPeriod"),
                getString("gb.gcPeriodDescription"),
                new DropDownChoice<Integer>("choice",
@@ -529,7 +531,7 @@
                        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 @@
        // MISCELLANEOUS
        //
        form.add(newTextfield("origin",
        form.add(new TextOption("origin",
                getString("gb.origin"),
                getString("gb.originDescription"),
                "span6",
                new PropertyModel<String>(repositoryModel, "origin")).setEnabled(false));
        form.add(newCheckbox("showRemoteBranches",
        form.add(new CheckboxOption("showRemoteBranches",
                getString("gb.showRemoteBranches"),
                getString("gb.showRemoteBranchesDescription"),
                new PropertyModel<Boolean>(repositoryModel, "showRemoteBranches")));
        form.add(newCheckbox("skipSizeCalculation",
        form.add(new CheckboxOption("skipSizeCalculation",
                getString("gb.skipSizeCalculation"),
                getString("gb.skipSizeCalculationDescription"),
                new PropertyModel<Boolean>(repositoryModel, "skipSizeCalculation")));
        form.add(newCheckbox("skipSummaryMetrics",
        form.add(new CheckboxOption("skipSummaryMetrics",
                getString("gb.skipSummaryMetrics"),
                getString("gb.skipSummaryMetricsDescription"),
                new PropertyModel<Boolean>(repositoryModel, "skipSummaryMetrics")));
        List<Integer> maxActivityCommits  = Arrays.asList(-1, 0, 25, 50, 75, 100, 150, 200, 250, 500);
        form.add(newChoice("maxActivityCommits",
        form.add(new ChoiceOption<Integer>("maxActivityCommits",
                getString("gb.maxActivityCommits"),
                getString("gb.maxActivityCommitsDescription"),
                new DropDownChoice<Integer>("choice",
@@ -570,7 +572,7 @@
                        new MaxActivityCommitsRenderer())));
        List<CommitMessageRenderer> renderers = Arrays.asList(CommitMessageRenderer.values());
        form.add(newChoice("commitMessageRenderer",
        form.add(new ChoiceOption<CommitMessageRenderer>("commitMessageRenderer",
                getString("gb.commitMessageRenderer"),
                getString("gb.commitMessageRendererDescription"),
                new DropDownChoice<CommitMessageRenderer>("choice",
@@ -580,7 +582,7 @@
        metricAuthorExclusions = new Model<String>(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 @@
        mailingLists = new Model<String>(ArrayUtils.isEmpty(repositoryModel.mailingLists) ? ""
                : StringUtils.flattenStrings(repositoryModel.mailingLists, " "));
        form.add(newTextfield("mailingLists",
        form.add(new TextOption("mailingLists",
                getString("gb.mailingLists"),
                getString("gb.mailingLists"),
                "span6",
@@ -750,50 +752,6 @@
            // No Administration Permitted
            error(getString("gb.errorAdministrationDisabled"), true);
        }
    }
    private Fragment newCheckbox(String wicketId, String title, String description, IModel<Boolean> 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 <T> Fragment newChoice(String wicketId, String title, String description, IModel<T> model, List<T> 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 <T> 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<String> model) {
        Fragment fragment = new Fragment(wicketId, "textfieldOption", this);
        fragment.add(new Label("name", title));
        fragment.add(new Label("description", description));
        TextField<String> tf = new TextField<String>("text", model);
        if (!StringUtils.isEmpty(css)) {
            WicketUtils.setCssClass(tf, css);
        }
        fragment.add(tf);
        return fragment;
    }
src/main/java/com/gitblit/wicket/panels/AccessPolicyPanel.html
@@ -27,15 +27,6 @@
    
    <div wicket:id="allowForks"></div>
    
<wicket:fragment wicket:id="checkboxOption">
    <div style="padding-top:4px;">
        <div>
            <label style="font-weight:bold;" class="checkbox"><input type="checkbox" wicket:id="checkbox" /> <span wicket:id="name"></span></label>
        </div>
        <label class="checkbox" style="color:#777;" wicket:id="description"></label>
    </div>
</wicket:fragment>
</wicket:panel>
</body>
</html>
src/main/java/com/gitblit/wicket/panels/AccessPolicyPanel.java
@@ -21,12 +21,10 @@
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,20 +146,12 @@
        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)));
        setOutputMarkupId(true);
    }
    private Fragment newCheckbox(String wicketId, String title, String description, IModel<Boolean> 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) {
src/main/java/com/gitblit/wicket/panels/CheckboxOption.html
New file
@@ -0,0 +1,17 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd"
      xml:lang="en"
      lang="en">
<body>
<wicket:panel>
    <div style="padding-top:4px;">
        <div>
            <label style="font-weight:bold;" class="checkbox"><input type="checkbox" wicket:id="checkbox" /> <span wicket:id="name"></span></label>
        </div>
        <label class="checkbox" style="color:#777;" wicket:id="description"></label>
    </div>
</wicket:panel>
</body>
</html>
src/main/java/com/gitblit/wicket/panels/CheckboxOption.java
New file
@@ -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<Boolean> 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;
    }
}
src/main/java/com/gitblit/wicket/panels/ChoiceOption.html
New file
@@ -0,0 +1,19 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd"
      xml:lang="en"
      lang="en">
<body>
<wicket:panel>
    <div style="padding-top:4px;">
        <div>
            <b><span wicket:id="name"></span></b>
        </div>
        <label class="checkbox" style="color:#777;"> <span wicket:id="description"></span>
        <p style="padding-top:5px;"><select class="span3" wicket:id="choice" /></p>
        </label>
    </div>
</wicket:panel>
</body>
</html>
src/main/java/com/gitblit/wicket/panels/ChoiceOption.java
New file
@@ -0,0 +1,51 @@
/*
 * 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 java.util.List;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.model.IModel;
/**
 * A re-usable choice option panel.
 *
 * title
 *     description
 *     [choices]
 *
 * @author James Moger
 *
 */
public class ChoiceOption<T> extends BasePanel {
    private static final long serialVersionUID = 1L;
    public ChoiceOption(String wicketId, String title, String description, IModel<T> model, List<T> choices) {
        super(wicketId);
        add(new Label("name", title));
        add(new Label("description", description));
        add(new DropDownChoice<>("choice", model, choices).setEnabled(choices.size() > 0));
    }
    public ChoiceOption(String wicketId, String title, String description, DropDownChoice<?> choice) {
        super(wicketId);
        add(new Label("name", title));
        add(new Label("description", description));
        add(choice.setMarkupId("choice").setEnabled(choice.getChoices().size() > 0));
    }
}
src/main/java/com/gitblit/wicket/panels/RegistrantPermissionsPanel.html
@@ -16,7 +16,7 @@
    </form>
    
    <div style="clear:both;" wicket:id="permissionRow">
        <div style="padding-top:10px;border-left:1px solid #ccc;border-right:1px solid #ccc;" class="row-fluid">
        <div style="padding-top:10px;" class="row-fluid">
            <div style="padding-top:5px;padding-left:5px" class="span6"><span wicket:id="registrant"></span></div><div style="padding-top:5px;padding-right:5px;text-align:right;" class="span3"><span class="label" wicket:id="pType">[permission type]</span></div> <select class="input-medium" wicket:id="permission"></select>
        </div>
    </div>
src/main/java/com/gitblit/wicket/panels/TextOption.html
New file
@@ -0,0 +1,20 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd"
      xml:lang="en"
      lang="en">
<body>
<wicket:panel>
    <div style="padding-top:4px;">
        <div>
            <b><span wicket:id="name"></span></b>
        </div>
        <label class="checkbox" style="color:#777;"> <span wicket:id="description"></span>
        <p style="padding-top:5px;"><input class="span2" type="text" wicket:id="text" /></p>
        </label>
    </div>
</wicket:panel>
</body>
</html>
src/main/java/com/gitblit/wicket/panels/TextOption.java
New file
@@ -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<String> model) {
        this(wicketId, title, description, null, model);
    }
    public TextOption(String wicketId, String title, String description, String css, IModel<String> model) {
        super(wicketId);
        add(new Label("name", title));
        add(new Label("description", description));
        TextField<String> tf = new TextField<String>("text", model);
        if (!StringUtils.isEmpty(css)) {
            WicketUtils.setCssClass(tf, css);
        }
        add(tf);
    }
}