public ListBoxModel doFillUnstableAsItems() { ListBoxModel items = new ListBoxModel(); GHCommitState[] results = new GHCommitState[] {GHCommitState.SUCCESS, GHCommitState.ERROR, GHCommitState.FAILURE}; for (GHCommitState nextResult : results) { String text = StringUtils.capitalize(nextResult.toString().toLowerCase()); items.add(text, nextResult.toString()); if (unstableAs.toString().equals(nextResult.toString())) { items.get(items.size() - 1).selected = true; } } return items; }
public ListBoxModel doFillResultItems(@QueryParameter String result) { ListBoxModel items = new ListBoxModel(); GHCommitState[] results = new GHCommitState[] {GHCommitState.SUCCESS, GHCommitState.ERROR, GHCommitState.FAILURE}; for (GHCommitState nextResult : results) { items.add(nextResult.toString(), nextResult.toString()); if (result.equals(nextResult.toString())) { items.get(items.size() - 1).selected = true; } } return items; } }
public ListBoxModel doFillStateItems(@QueryParameter("state") String state) { ListBoxModel items = new ListBoxModel(); for (GHCommitState commitState : GHCommitState.values()) { items.add(commitState.toString(), commitState.toString()); if (state.equals(commitState.toString())) { items.get(items.size() - 1).selected = true; } } return items; } }
@NonNull public static ListBoxModel doFillFileItems(@Nullable final String currentValue) { ListBoxModel m = new ListBoxModel(); m.add("- none -", ""); for (ConfigProvider p : ConfigProvider.all()) { ConfigSuitableFor a = p.getClass().getAnnotation(ConfigSuitableFor.class); if (null != a && a.target() == UserData.class) { for (Config cfg : p.getAllConfigs()) { String label = p.getDisplayName() + " " + cfg.name; if (cfg.comment != null && !cfg.comment.isEmpty()) { label += String.format(" [%s]", cfg.comment); } m.add(label, cfg.id); if (cfg.id.equals(currentValue)) { m.get(m.size() - 1).selected = true; } } } } return m; } }
/** * For UI. */ @SuppressWarnings({"UnusedDeclaration", "JavaDoc"}) public void doComputerNameValues(StaplerRequest req, StaplerResponse resp, @QueryParameter("hostName") String hostName) throws IOException, ServletException { ListBoxModel m = new ListBoxModel(); List<VirtualBoxMachine> virtualMachines = getDefinedVirtualMachines(hostName); if (virtualMachines != null && virtualMachines.size() > 0) { for (VirtualBoxMachine vm : virtualMachines) { m.add(new ListBoxModel.Option(vm.getName(), vm.getName())); } m.get(0).selected = true; } m.writeTo(req, resp); }
/** * Set the selected server. * * @param name the name of the newly selected server. * */ @DataBoundSetter public void setServerName(String name) { this.serverName = name; if (this.notificationLevel == null) { ListBoxModel options = ((DescriptorImpl)getDescriptor()).doFillNotificationLevelItems(this.serverName); if (!options.isEmpty()) { notificationLevel = options.get(0).value; } } }
ListBoxModel options = descriptor.doFillNotificationLevelItems(this.serverName); if (!options.isEmpty()) { this.notificationLevel = options.get(0).value;
@Override public void run() { ListBoxModel options = r.jenkins.getDescriptorByType(MercurialSCM.DescriptorImpl.class).doFillCredentialsIdItems(null, "http://nowhere.net/"); assertEquals(CredentialsNameProvider.name(c), options.get(1).name); } });
@Test public void credentialsListableAtFolderScope() throws Exception { Folder f = createFolder(); ListBoxModel asGroup = CredentialsProvider.listCredentials(StandardUsernamePasswordCredentials.class, (ItemGroup) f, ACL.SYSTEM, Collections.emptyList(), CredentialsMatchers.always()); ListBoxModel asItem = CredentialsProvider.listCredentials(StandardUsernamePasswordCredentials.class, (Item) f, ACL.SYSTEM, Collections.emptyList(), CredentialsMatchers.always()); assertThat(asGroup, is(asItem)); assertThat(asGroup.size(), is(0)); assertThat(asItem.size(), is(0)); CredentialsStore folderStore = getFolderStore(f); UsernamePasswordCredentialsImpl credentials = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "test-id", "description", "test-user", "secret"); folderStore.addCredentials(Domain.global(), credentials); asGroup = CredentialsProvider.listCredentials(StandardUsernamePasswordCredentials.class, (ItemGroup) f, ACL.SYSTEM, Collections.emptyList(), CredentialsMatchers.always()); asItem = CredentialsProvider.listCredentials(StandardUsernamePasswordCredentials.class, (Item) f, ACL.SYSTEM, Collections.emptyList(), CredentialsMatchers.always()); assertThat(asGroup.size(), is(1)); assertThat(asGroup.get(0).value, is("test-id")); assertThat(asItem.size(), is(1)); assertThat(asItem.get(0).value, is("test-id")); }