/** * Gets the visible item ids. In Select, this returns list of all item ids, * but can be overridden in subclasses if they paint only part of the items * to the terminal or null if no items is visible. */ public Collection<?> getVisibleItemIds() { return getItemIds(); }
/** * Writes the data source items to a design. Hierarchical select components * should override this method to only write the root items. * * @since 7.5.0 * @param design * the element into which to insert the items * @param context * the DesignContext instance used in writing */ protected void writeItems(Element design, DesignContext context) { for (Object itemId : getItemIds()) { writeItem(design, itemId, context); } }
@Test public void createFieldSelectsFirstOptionIfItemIsNew() throws Exception { // GIVEN definition.setSortOptions(false); baseItem = new JcrNewNodeAdapter(baseNode, baseNode.getPrimaryNodeType().getName()); initializeSelectFieldFactory(); // WHEN AbstractSelect field = (AbstractSelect) dialogSelect.createField(); // THEN Collection<String> items = (Collection<String>) field.getItemIds(); assertThat(items, contains("1", "2", "3")); assertThat(field.getValue().toString(), is("1")); }
@Test public void createFieldDoesntSortOptionsIfSpecified() throws Exception { // GIVEN ArrayList<SelectFieldOptionDefinition> options = new ArrayList<SelectFieldOptionDefinition>(); SelectFieldOptionDefinition option1 = new SelectFieldOptionDefinition(); option1.setLabel("bb"); option1.setValue("1"); options.add(option1); SelectFieldOptionDefinition option2 = new SelectFieldOptionDefinition(); option2.setLabel("AA"); option2.setValue("2"); options.add(option2); SelectFieldOptionDefinition option3 = new SelectFieldOptionDefinition(); option3.setLabel("cc"); option3.setValue("3"); options.add(option3); definition.setOptions(options); definition.setSortOptions(false); initializeSelectFieldFactory(); // WHEN AbstractSelect field = (AbstractSelect) dialogSelect.createField(); // THEN Collection<String> items = (Collection<String>) field.getItemIds(); assertThat(items, contains("1", "2", "3")); assertThat(field.getValue(), is(nullValue())); assertThat(items.iterator().next(), is("1")); }
@Test public void remoteOptionsGetRebuiltUponFieldRecreation() throws Exception { // GIVEN // Initialize a Options node. initRemoteOptionsNode(); // Set remote Options in configuration definition.setOptions(Collections.<SelectFieldOptionDefinition>emptyList()); definition.setPath(remoteSelectOptionsNode.getPath()); definition.setRepository(workspaceName); baseItem = new JcrNewNodeAdapter(baseNode, baseNode.getPrimaryNodeType().getName()); initializeSelectFieldFactory(); // WHEN we initially create a select field AbstractSelect field = (AbstractSelect) dialogSelect.createField(); // THEN initially pre-created options from the remote location are present assertThat(field.getItemIds(), Matchers.<Object>contains("en", "fr")); // WHEN we add another 'remote' option and re-create a field addRemoteSelectOption("Qux", "qux"); initializeSelectFieldFactory(); field = (AbstractSelect) dialogSelect.createField(); // THEN initially pre-created options from the remote location are present assertThat(field.getItemIds(), Matchers.<Object>contains("en", "fr", "qux")); }
@Test public void createFieldSortsOptionsByNullSafeLabelComparator() throws Exception { // GIVEN ArrayList<SelectFieldOptionDefinition> options = new ArrayList<>(); SelectFieldOptionDefinition nullOption = new SelectFieldOptionDefinition(); nullOption.setLabel(null); nullOption.setValue("1"); options.add(nullOption); SelectFieldOptionDefinition emptyOption = new SelectFieldOptionDefinition(); emptyOption.setLabel(""); emptyOption.setValue("2"); options.add(emptyOption); SelectFieldOptionDefinition blankOption = new SelectFieldOptionDefinition(); blankOption.setLabel(" "); blankOption.setValue("3"); options.add(blankOption); definition.setOptions(options); initializeSelectFieldFactory(); // WHEN AbstractSelect field = (AbstractSelect) dialogSelect.createField(); // THEN Collection<String> items = (Collection<String>) field.getItemIds(); assertThat(items, contains("1", "2", "3")); assertThat(field.getValue(), is(nullValue())); }
@Test public void createFieldSortsOptionsAlphabeticallyAscendingByDefault() throws Exception { // GIVEN ArrayList<SelectFieldOptionDefinition> options = new ArrayList<SelectFieldOptionDefinition>(); SelectFieldOptionDefinition option1 = new SelectFieldOptionDefinition(); option1.setLabel("bb"); option1.setValue("1"); options.add(option1); SelectFieldOptionDefinition option2 = new SelectFieldOptionDefinition(); option2.setLabel("AA"); option2.setValue("2"); options.add(option2); SelectFieldOptionDefinition option3 = new SelectFieldOptionDefinition(); option3.setLabel("cc"); option3.setValue("3"); options.add(option3); definition.setOptions(options); initializeSelectFieldFactory(); // WHEN AbstractSelect field = (AbstractSelect) dialogSelect.createField(); // THEN Collection<String> items = (Collection<String>) field.getItemIds(); assertThat(items, contains("2", "1", "3")); }
Collection<String> items = (Collection<String>) field.getItemIds(); assertThat(items, contains("1", "6", "2", "5", "3", "4")); assertThat(field.getValue(), is(nullValue()));
int keyIndex = 0; final Collection<?> ids = getItemIds(); if (isNullSelectionAllowed() && getNullSelectionItemId() != null && !ids.contains(getNullSelectionItemId())) { for (final Object id : getItemIds()) {