Filtering table from another table in vaadin - filtering

I was wondering how to filter one table based on what I click on in another table. For example if I click on Russia in the country table it should filter all the people from Russia in the name table. I would like to know how to do this using vaadin. I added some relevant code below. The country table is suppose to filter the name table when I click on a country.
Here is my filter method:
public class CountryFilter implements Filter {
public String needle;
public CountryFilter(String needle) {
this.needle = needle;
}
public boolean appliesToProperty(Object id) {
return true;
}
public boolean passesFilter(Object itemId, Item item) {
String haystack = ("" + item.getItemProperty(Name) +
item.getItemProperty(Country)).toLowerCase();
return haystack.contains(needle);
}
}
Here is my search method that uses the filter
public void initCountrySearch() {
country.setSelectable(true);
country.setImmediate(true);
name.setVisibleColumns(new String[] {"name"});
country.setVisibleColumns(new String[] {"country"});
country.addValueChangeListener(new Property.ValueChangeListener() {
public void valueChange(ValueChangeEvent event) {
// TODO Auto-generated method stub
data.name.removeAllContainerFilters();
data.name.addContainerFilter(new CountryFilter(event.getProperty().getValue().toString()));
}
});
}

You could set a ValueChangeListener on your selection criteria table which informs you about, well, a value change. In the value change method you can get the selected item and according to this item you do a loading on your target table.

Related

How to instantiate children of a custom element in UI Builder using a script?

Basically, I'd like to make a simple non-scrollable list containing other VisualElements. In order to simplify workflow and allow reusability, I want to make a custom element where I could input an integer for the number of entries in said list in inspector inside UI Builder and have it instantiate rows in the list.
I've written the code for the custom element and the integer in the inspector is showing up correctly.
public class ListElement : VisualElement {
public new class UxmlFactory : UxmlFactory<ListElement, UxmlTraits> { }
public new class UxmlTraits : VisualElement.UxmlTraits {
UxmlIntAttributeDescription _numberOfEntries = new UxmlIntAttributeDescription { name = "Number of entries", defaultValue = 2 };
public override IEnumerable<UxmlChildElementDescription> uxmlChildElementsDescription {
get { yield break; }
}
public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc) {
base.Init(ve, bag, cc);
var ate = ve as ListElement;
ate.numberOfEntries = _numberOfEntries.GetValueFromBag(bag, cc);
}
}
public int numberOfEntries { get; set; }
}
Now the thing is, I have absolutely no clue how to instantiate the child VisualElements in order for them to show up in the UI Builder.
Here is a mockup of what I'd like to achieve.

How can i design a Model of a document contains more than one collection in Mongodb

I am novice in mongodb.
I have a mongodb and i have a table / document(Ex: sampleTable).
I know how to retrieve data from this single table.
I used below code to retrieve data and working fine.
#Document(collection="sampleTable")
public class sampleMapping {
private String id;
private String strClassName;
public sampleMapping () {}
public sampleMapping (String strClassName) {
super();
this.strClassName = strClassName;
}
public String getStrClassName() {
return strClassName;
}
public void setStrClassName(String strClassName) {
this.strClassName = strClassName;
}
}
But now, i wanted to retrieve data from more than one table. How can i do that?
Say, i need to retrieve table1 and table2.
How can i update the above code to get data from multiple collections?

How to pass filters to Wicket Data Provider based on user choise

I have created a DataView backed by a Data provider. I am attempting to find out how are we suppose to have the data provider filter the data coming from the database based on a filter set by the user. The user is able to select many options that will then be used to filter the data in the database, however, how is this usually done when the dataview is backed by a data provider? Do I pass in the filter to the data provider? Should I run the query first, store it in an ArrayList and then pass in the list to the data provider?
The wicket examples have a contact data provider, but it does not show how it would filter the data based on users input. Any ideas?
Let me know if I need to clarify the question.
Usually I have some sort of criteria object:
FooCriteria {
String bar;
boolean baz;
}
... that is configured in a matching panel:
FooCriteriaPanel(String id, IModel<FooCriteria> criteria) {
super(new CompoundPropertyModel<>(criteria);
add(new TextField("bar"));
add(new Checkbox("baz"));
}
... and passed to the results panel:
FooResultsPanel(String id, IModel<FooCriteria> criteria) {
super(id);
add(new DataTable("table", new FooProvider(criteria)));
}
private class FooProvider implements IDataProvider {
private IModel<FooCriteria> criteria;
public FooProvider(IModel<FooCriteria> criteria) {
this.criteria = criteria;
}
public void detach() {
this.criteria.detach();
}
public Iterator<Foo> iterator(long first, long count) {
service.getFoos(criteria.getObject(), first, count);
}
...
}

Represent a single-rowed table in EF?

I have a configuration table in my database and it contains exactly one row.
ConfirmedScheduleColor | OverlappedScheduleColor | ColN
Currently, I'm retrieving the configuration like this:
var db = new SchedulingDbContext();
var config = db.Configurations.FirstOrDefault();
It's currently working fine and I can access my configurations and all. The thing is, the code looks awkward since I'm accessing the Configurations DbSet as if it contains many records (FirstOrDefault()); although actually, it contains only one record. I want to access my configurations like I'm accessing a static object. How to do that in EF?
You could simply add a property to your DbContext that returns Configurations.FirstOrDefault() and privatize the DbSet:
public class SchedulingDbContext : DbContext
{
private DbSet<Configuration> Configurations { get; set; }
public Configuration Configuration
{
get
{
return Configurations.FirstOrDefault();
}
}
}
I have a class in my project that has static methods to retrieve config settings. I use the ConfigurationManager rather than the database, but you could adapt it to get the setting from wherever you are storing the value.
In my example I have written a GetFromDb method for you that takes a key as parameter but that is because if I was storing my config settings in the database I wouldn't want to add a column every time I needed a new config setting. I would have a table with Key/Value columns. If you are wedded to the single row table then you might want to do without such a method.
public class Config
{
private _ConfirmedScheduleColor;
public static string ConfirmedScheduleColor
{
get
{
if(_ConfirmedScheduleColor == null)
_ConfirmedScheduleColor = GetFromDb("ConfirmedScheduleColor");
return _ConfirmedScheduleColor;
}
}
public static string OverlappedScheduleColor
{
get { return GetValue("OverlappedScheduleColor", "Pink"); }
}
public static int ColN
{
get { return GetValue("ColN", 2); }
}
private static string GetFromDb(string key)
{
if(key == "ConfirmedScheduleColor")
{
var config = db.Configurations.FirstOrDefault();
return config.ConfirmedScheduleColor;
}
}
private static string GetValue(string key, string defaultValue)
{
return ConfigurationManager.AppSettings[key] ?? defaultValue;
}
private static string GetValue(string key, int defaultValue)
{
int i;
if(int.TryParse(ConfigurationManager.AppSettings[key], out i))
return i;
return defaultValue;
}
}
In EF Core you can set the check constraint for the primary key. It enforces that column Id must have value that is equal to 1 which means only one record can exist in table if you have the primary key.
modelBuilder.Entity<YourTable>(e =>
{
e.HasCheckConstraint("CK_Table_Column", "[Id] = 1");
e.HasData(...) //optionally add some initial date for Id = 1
});

SmartGWT Object binding without specifying object's fields

I am just wondering if it's possible to create some sort of binding without explicitly specifying all of the fields that need to be mapped to some widget(i.e. ListGrid).
Currently I do the following: First I read all the JSON objects fields and put these fields into CategoryRecord object like this:
public class CategoryRecord extends Record {
public CategoryRecord(String displayName, String id) {
setDisplayName(displayName);
setId(id);
}
private void setId(String id) {
setAttribute("id", id);
}
public String getId() {
return getAttributeAsString("id");
}
private void setDisplayName(String displayName) {
setAttribute("displayName", displayName);
}
public String getDisplayName() {
return getAttributeAsString("displayName");
}
}
Then I return a CategoryRecord[] object and put it into a ListGrid. But what if application developers decide to change the "id" field to "categoryId" or completely remove it. Do I have to manually change my code each time something like this happens? Or is there a way to get the whole JSON object, get it's fields and put it wherever I want, without specifying their names.
Thanks in advance!
Just iterate over the properties of the JSON object and create ListGridField objects for each one.