Jelly Config Expand Elements - java

I have a quick question. In jenkins when making the jelly config file for the gui, you can have a radio button expand and show more elements, can this be done with a drop down list as well? If so, does anyone have an example please? I know how to do it with radio buttons but i don't want radio buttons, I need the content to be dependant on the choice.
Edit: Currently I have the following:
<f:entry title="${%Authentication}" field="authMode">
<f:select />
</f:entry>
and in the java file:
public ListBoxModel doFillAuthModeItems() {
ListBoxModel items = new ListBoxModel();
items.add("None");
items.add("Form Based Authentication");
items.add("Script Based Authentication");
return items;
}
This creates a drop down list of 3 elements, i just need to show different content based on the selection, for example. None would have no new content, Form Based would show a username and a password textfield.

What you need to research is the hetero-list jelly tag. There is a good page on it from cloud bees their code is closed though
I put an open source one together for the selenium-axis-plugin but this is in groovy and using groovy forms
namespace(lib.FormTagLib).with {
entry(title: _("Name"), field:"name") {
textbox( default:"label")
}
block{
entry(field:"seleniumCapabilities") {
hetero_list( name: "seleniumCapabilities",
hasHeader: true,
descriptors:descriptor.axisItemTypes(),
items: instance?
instance.getSeleniumCapabilities():
descriptor.loadDefaultItems())
}
}
}
source
How it works is that there a method on the top level descriptor which returns all the descriptors which can be used
List<ItemDescriptor> axisItemTypes() {
def ait = Jenkins.instance.<Item,ItemDescriptor>getDescriptorList(Item)
def ret = []
for (int i = 0; i < ait.size(); i++) {
/*code removed*/
ret.add(ait.get(i))
}
ret
}
source
All of the nested items have to have their own descriptors and also a #DataBoundConstructor

Related

Angular Local Storage Delete Not Removing item

Hello I am learning angular and I'm working on a todo app that stores to local storage. Getting the local storage to remove a single item as well as editing an item has been a challenge and I've not found many good resources.
Right now it looks like its removing the entire array and I'm not sure why. Hopefully Ive included the proper details.
This is is my delete/remove in the CRUD task
deleteTask(task : Task) {
localStorage.removeItem(this.taskKey)
}
This is the delete task in the componant
deleteTask(idx: number) {
this.taskService.deleteTask(new Task(this.addTaskValue))
if( idx >= 0) {
this.taskArr.splice(idx, 1);
}
}
Other Details from the componant
taskArr: Task[];
public addTaskValue: string = '';
constructor(private taskService: TaskService) {}
ngOnInit(): void {
this.addTaskValue = '';
this.taskArr = this.taskService.getAllTasks();
}
Local Storage Image
I've tried to just use the splice out in the deleteTask but that only removed it from the screen and not the local storage. Ive tried a bunch of other things as well but cant recall them all in detail.
In the above code, you provided. I don't see a logic where the taskKey is even being set. I would add some console statements to see if you're even getting the right string in this.taskKey.
deleteTask(task : Task) {
console.log(this.taskKey); // check if this value is "tasks"
localStorage.removeItem(this.taskKey)
}
Essentially it needs to boil down to this.
localstorage.removeItem('tasks').

How to force combobox to render autocomplete options?

This is my zul code:
<combobox id="digitalPublisherCombobox" value="#load(ivm.inventory.digitalPublisherName)"
onOK="#command('setDigitalPublisher', digitalPublisherBox = self)"
onSelect="#command('setDigitalPublisher', digitalPublisherBox = self)"
onChanging="#command('setupQuicksearchByEvent', searchlayout = event, prefix = 'PUB', tags = 'PublisherName, PublisherNameTranslit')"
mold="rounded" hflex="1" buttonVisible="false" autodrop="true">
<comboitem self="#{each=entry}" value="#{entry.key}" label="#{entry.value}"/>
</combobox>
And this is QuickSearch implementations:
#Command
public void setupQuicksearchByEvent(#BindingParam("searchlayout")Event event, #BindingParam("prefix") String prefix, #BindingParam("tags") String tags) throws WrongValueException, SearchException, IOException
{
if(event instanceof InputEvent)
{
InputEvent inputEvent = (InputEvent) event;
String inputText = inputEvent.getValue();
List<String> searchFields = Arrays.asList(tags.split(","));
ListModel model = new ListModelMap(ZKLogic.findDocsStartingWith(prefix, searchFields, "proxy", inputText), true);
ListModel subModel = ListModels.toListSubModel(model, Autocompleter.MAP_VALUE_CONTAINS_COMPARATOR, 10);
Combobox searchBox = (Combobox) event.getTarget();
searchBox.setModel(subModel);
searchBox.setItemRenderer(new ComboitemRenderer()
{
#Override
public void render( Comboitem item, Object data, int pos ) throws Exception
{
String publisherString = data.toString();
UID key = getUidFromPublisherString(publisherString);
int startIndex = publisherString.indexOf('=') + 1;
String publisher = publisherString.substring(startIndex);
item.setLabel(publisher);
item.setValue(key);
}
});
}
}
ZKLogic.findDocsStartingWith return map with UID-key and String-value.
With code above I achieved to get dropdown list when I switch to another window. I need to type something, then select another browser or notepad window - and comboitems will be displayed immediately.
So, my question still need answer, is there are any techniques to reproduce this windows switching in code? Or maybe I should do something with autocomplete, because I've got some ac working with preloaded lists, but this thing should return only 10 records from db, instead of all 70000 entries, every time when user type something in the field.
Edit 20/09/2013: Problem still exist. Rename question a bit, because thing that I need is to call render option by force in code. Is there is any way to do it? Code hasn't changed a lot, but print option in render method said, that method can miss two or more onChange events and suddenly render text for one variant.
Maybe you know another autocomplete options in zk framework where database participating? I'm ready to change implementation, if there is a guide with working implementation of it.
Ok I see two problems, you should solve first.
Setting the Renderer in every call of setupQuicksearchByEvent(...).
that is not logical, cos it is the same every time.
Add to the zul combobox tag something like
itemRenderer="#load(ivm.myRenderer)" ....
If you want just 10 items, do not let the db-request return more then 10.
If you use JPA klick here or for sql here or just google a bit.
After you fixed this two issues, we can exclude these as a reason of the unexpected behavior and fix it, if it is still present.
Edit
Ok, I have two possible ways to fix it.
Call Combobox#invalidate()
This schould force zk to rerender the Combobox, but could
lead to low performance and I would not prefer this.
Use Listbox with the select mold instead of Combobox.
To force the rerender, use Listbox#renderAll()
Try setting the selected item on your combobox or throw its related event
Solution is simple. Really. Nothing is better then brute-force, but I think I tried to avoid it and use it in despair.
#Command
public void setupQuicksearchByEvent(#BindingParam("searchlayout")Event event, #BindingParam("prefix") String prefix, #BindingParam("tags") String tags) throws WrongValueException, SearchException, IOException
{
if(event instanceof InputEvent)
{
InputEvent inputEvent = (InputEvent) event;
String inputText = inputEvent.getValue();
List<String> searchFields = Arrays.asList(tags.split(","));
Map<UID, String> publishers = ZKLogic.findDocsStartingWith(prefix, searchFields, "proxy", inputText);
Combobox searchBox = (Combobox) event.getTarget();
searchBox.getChildren().clear();
for (Map.Entry<UID, String > entry : publishers.entrySet())
{
Comboitem item = new Comboitem();
item.setLabel(entry.getValue());
item.setValue(entry.getKey());
searchBox.appendChild(item);
}
}
}

How can I (un)hide a SWT TableItem?

I am trying to allow my user to search through a table of information, dynamically hiding/showing results that contain the search. I have the hiding part down, and it works well, but I'm having trouble showing the table item again once the search criteria is changed.
Here is my hide code:
searchField.addModifyListener(new ModifyListener() {
#Override
public void modifyText(ModifyEvent arg0) {
modified = true;
for (int i = 0; i < table.getItems().length; i++) {
if (!(table.getItem(i).getText(2)
.contains(searchField.getText()))) {
table.getItem(i).dispose();
}
}
if ("".equals(searchField.getText())) {
modified = false;
//where I would want to un-hide items
}
}
});
Looking at your code, it seems you try to hide the item by calling dispose(). If you dispose a widget, it is gone for good. You cannot get it back.
If you want to unhide it again, will have to create a new item at the position of the previously hidden one with the same content.
Isn't it better to actually operate with some kind of a table model and JFace bindings, rather, then do it like that? And yes, disposing is not hiding. You should probably remove the item from the table.
You have probably to save the data from TableItem into collection before you call dispose. Then when you search again you could check that collection and if matches are found, then insert back into Table by creating new TableItem.

Removing filtered text programmatically?

I am using GXT's filtered grid(http://www.sencha.com/examples-2/#filtergrid). once the filter is applied i need to remove filtered text whatever user has entered.
is it possible to remove "abc" text programatically without user intervention?
Thanks!
Please try the below code. I have not tested this.
new StringFilter("someValue") {
#Override
protected void fireUpdate() {
super.fireUpdate();
List<Component> items = menu.getItems();
if (!items.isEmpty()) {
((Field) items.get(0)).setValue("");
}
// Not tested this. If the above code is not working try to get the
textfield instance somehow from the menu and clear it
}
};
If you want to clear the value only on user's key enter and not on programmatic filter (via setValue()), then the above will not work. You have to override the onFieldKeyUp method and clear it using some scheduler.

Hierarchical Vaadin Tree from XML(MSDL)

im tryind to build an Vaadin tree from an XML file(MSDL), im stuck at adding child items to my tree. So far i can read from my XML file and display the the tags/info i want but i cant make an Hierarchical strukture out of it , e.g :
i have an XML file with some information about Planets and their moons and the galaxy they are in :
Milky Way
-Sunsystem
-Earth
-"Moon"
-Mars
-Phobos
-Deimos
-Saturn
-Titan
-Tethys
Pinwheel Galaxy
-somesystem
-weirdPlanet1
-moon1
-moon2
-weirdPlanet2
-moon1
-moon2
now i want to have the same strukture in my vaadin tree. i have tryed lots of things but the result was always the same : some null values where added to the tree of i could see only the galaxys but i couldnt expand them or i could see a tree with all the infos but there whee no strukture at all all planets / moons where just listed :/
I'm pretty sure this doesn't have anything to do with the Tree itself. Instead of adding the data directly to the Tree, you can try this:
Parse the XML data into a HierarchicalContainer
Iterate through the HierarchicalContainer with the sample code below and verify that it's identical to your XML file structure
Bind the data container to the tree by calling Tree.setContainerDataSource(Container)
Sample code to iterate through a HierarchicalContainer:
void iterateContainer() {
for(Object rootItemId : myContainer.rootItemIds()) {
Item rootItem = myContainer.getItem(rootItemId);
System.out.println(rootItem.getItemProperty(myLabelProperty).getValue());
iterateChildren(rootItemId, 1);
}
}
void iterateChildren(Object parentItemId, int indent) {
for(Object childItemId : myContainer.getChildren(parentItemId)) {
Item childItem = myContainer.getItem(childItemId);
for(int i = 0; i < indent; i++) {
System.out.print(" ");
}
System.out.println(childItem.getItemProperty(myLabelProperty).getValue());
if(myContainer.hasChildren(childItemId)) {
iterateChildren(childItemId, indent+1);
}
}
}
This is just some untested QnD code, but this should help you to iterate through the container.
edit: Just noticed that my answer could have been (partially) a stupid solution, since Tree already utilizes HierarchicalContainer. You can initialize myContainer HierarchicalContainer myContainer = (HierarchicalContainer) myTree.getContainerDataSource(); and use the code above.
edit2: And if the structure isn't identical, see where it goes wrong and let the debugger do the rest .. :)

Categories

Resources