org.appng.api.support.SelectionBuilder Maven / Gradle / Ivy
/*
* Copyright 2011-2019 the original author or authors.
*
* 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 org.appng.api.support;
import java.util.Collection;
import org.appng.api.model.NameProvider;
import org.appng.api.support.OptionOwner.HitCounter;
import org.appng.api.support.OptionOwner.Selector;
import org.appng.xml.platform.Label;
import org.appng.xml.platform.Option;
import org.appng.xml.platform.OptionGroup;
import org.appng.xml.platform.SelectionType;
/**
* A builder for {@link org.appng.xml.platform.Selection}s, providing a fluent API.
* Example:
*
* Selection persons = new SelectionBuilder("persons")
* .title("persons")
* .options(Arrays.asList(a, b, c))
* .select(b)
* .disable(c)
* .type(SelectionType.SELECT_MULTIPLE)
* .build();
*
* @param
* the type to create {@link Option}s from
*/
public class SelectionBuilder extends OptionsBuilder.Selection> {
private Selection selection;
class Selection extends org.appng.xml.platform.Selection implements OptionOwner {
public void addOption(Option option) {
getOptions().add(option);
}
public Option addOption(String name, String value, boolean selected) {
Option o = new Option();
getOptions().add(o);
o.setName(name);
o.setValue(value);
o.setSelected(selected);
return o;
}
};
public SelectionBuilder(String id) {
super();
this.selection = new Selection();
selection.setId(id);
setOwner(selection);
}
/**
* Sets the title for the selection
*
* @param title
* the title
* @return this builder
*/
public SelectionBuilder title(String title) {
Label label = new Label();
label.setValue(title);
selection.setTitle(label);
return this;
}
/**
* Sets the {@link SelectionType} for the selection
*
* @param type
* the type
* @return this builder
*/
public SelectionBuilder type(SelectionType type) {
selection.setType(type);
return this;
}
/**
* Adds a {@link OptionGroup} to the selection
*
* @param group
* the group
* @return this builder
*/
public SelectionBuilder addGroup(OptionGroup group) {
this.selection.getOptionGroups().add(group);
return this;
}
public SelectionBuilder options(Iterable values) {
super.options(values);
return this;
}
public SelectionBuilder name(NameProvider nameProvider) {
super.name(nameProvider);
return this;
}
public SelectionBuilder selector(Selector selector) {
super.selector(selector);
return this;
}
public SelectionBuilder select(Collection selected) {
super.select(selected);
return this;
}
public SelectionBuilder select(T selected) {
super.select(selected);
return this;
}
public SelectionBuilder disable(Collection disabled) {
super.disable(disabled);
return this;
}
public SelectionBuilder disable(T disabled) {
super.disable(disabled);
return this;
}
public SelectionBuilder defaultOption(String name, String value) {
super.defaultOption(name, value);
return this;
}
public SelectionBuilder hitCounter(HitCounter counter) {
super.hitCounter(counter);
return this;
}
public Selection build() {
super.build();
return selection;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy