GWTP: Troubles to display a CellTable - celltable

Hi I'm new to GWT and so, to GWTP too.
I try to play with CellTables and I decided to begin by building a simple one following GWT documentation at developers.google.com/web-toolkit/doc/2.4/DevGuideUiCellWidgets#celltable
I adapted few things to match GWTP MVP design.
First, I created my Celltable on my View.ui.xml file:
xmlns:c="urn:import:com.google.gwt.user.cellview.client">
<g:HTMLPanel>
<c:CellTable pageSize='15' ui:field='cellTable' />
</g:HTMLPanel>
Then, I created a class Contact:
public class Contact {
private final String address;
private final String name;
public Contact(String name, String address) {
this.name = name;
this.address = address;
}
public String getAddress() {
return address;
}
public String getName() {
return name;
}
}
in my View.java file:
#UiField(provided=true) CellTable<Contact> cellTable = new CellTable<Contact>();
public CellTable<Contact> getCellTable() {
return cellTable;
}
Finally in my Presenter.java file:
public interface MyView extends View {
CellTable<Contact> getCellTable();
}
#Override
protected void onReset() {
super.onReset();
// Create name column.
TextColumn<Contact> nameColumn = new TextColumn<Contact>() {
#Override
public String getValue(Contact contact) {
return contact.getName();
}
};
// Create address column.
TextColumn<Contact> addressColumn = new TextColumn<Contact>() {
#Override
public String getValue(Contact contact) {
return contact.getAddress();
}
};
// Add the columns.
getView().getCellTable().addColumn(nameColumn, "Name");
getView().getCellTable().addColumn(addressColumn, "Address");
// Set the total row count.
getView().getCellTable().setRowCount(CONTACTS.size(), true);
// Push the data into the widget.
getView().getCellTable().setRowData(0, CONTACTS);
}
Everything seems good to me but there is no CellTable displayed when I try this code...And I get no errors...
Thanks in advance for your Help!

It looks like you do not use/have DataProvider registered for your CellTable. GWT CellWidgets are based on DataProvider/DIsplay pattern. So CellTable is just a Display for your DataProvider. One DataProvider could have multiple displays.
You do not need to write:
// Set the total row count.
getView().getCellTable().setRowCount(CONTACTS.size(), true);
// Push the data into the widget.
getView().getCellTable().setRowData(0, CONTACTS);
You need to register your CellTable as a Display for your DataProvider (eg ListDataProvider) and than call refresh method when you update DataProvider with new data.

Related

My RecyclerView is duplicated every time I open activity

I have some problem with my project, and I will be very glad if anyone of you helps me. There is an activity in my app, where the only view is RecyclerView and everytime I open this activity, I need fill it, I do it like that:
RecyclerView templatesRecycler;
private MyRecyclerViewAdapter myRecyclerViewAdapter;
int numberOfColumns = 2;
//
templatesRecycler = (RecyclerView) findViewById(R.id.templatesListView);
updateRecyclerView(MyCollections.getTemplatesTitles());
public void updateRecyclerView(ArrayList<MyTemplate> myTemplates){
templatesRecycler.setHasFixedSize(true);
templatesRecycler.setLayoutManager(new GridLayoutManager(this, numberOfColumns));
myRecyclerViewAdapter = new MyRecyclerViewAdapter(this, myTemplates, this);
templatesRecycler.setAdapter(myRecyclerViewAdapter);
}
I want to use class MyCollections, because there are a lot of RecyclerViews in my app, but I dont want to fill it myself everytime, so I create class MyCollections:
public class MyCollections {
public static ArrayList<MyTemplate> templatesTitles = new ArrayList<>();
public MyCollections(){
templatesTitles.add(new MyTemplate("Люди", R.drawable.ic_people));
templatesTitles.add(new MyTemplate("Транспорт", R.drawable.ic_car));
templatesTitles.add(new MyTemplate("Мебель", R.drawable.ic_furniture));
templatesTitles.add(new MyTemplate("Фоны", R.drawable.ic_background));
templatesTitles.add(new MyTemplate("Предметы", R.drawable.ic_tools));
templatesTitles.add(new MyTemplate("Животные", R.drawable.ic_animal));
templatesTitles.add(new MyTemplate("Природа", R.drawable.ic_nature));
templatesTitles.add(new MyTemplate("Разметка листа", R.drawable.ic_sections));
templatesTitles.add(new MyTemplate("Другое", R.drawable.ic_others));
}
public static ArrayList<MyTemplate> getTemplatesTitles() {
return templatesTitles;
}
}
By the way, here is my MyTemplate class:
public class MyTemplate {
public String titleTemplate;
public int drawableID;
public String getTitleTemplate() {
return titleTemplate;
}
public void setTitleTemplate(String titleTemplate) {
this.titleTemplate = titleTemplate;
}
public int getDrawableID() {
return drawableID;
}
public void setDrawableID(int drawableID) {
this.drawableID = drawableID;
}
public MyTemplate(String titleTemplate, int drawableID){
this.titleTemplate = titleTemplate;
this.drawableID = drawableID;
}
public MyTemplate(){}
}
But here is the problem. Every time I open activity, my RecyclerView duplicates his elements, before I filled RecyclerView myself, and there wasnt such a problem. Please, help me, I am just beginner, so I dont know how I can fix this problem. Thanks!

Problem returning data from Search Query in ASP.Net

I'm learning ASP.NET Core MVC development. I'm trying to create a search query that returns the book if author name or the book title matches from a dummy database.
This is my BookRepository (data source):
public class BookRepository
{
public List<BookModel> SearchBook(string title, string authorName)
{
return DataSource().Where(x => x.Title.Contains(title) || x.Author.Contains(authorName)).ToList();
}
private List<BookModel> DataSource()
{
return new List<BookModel>
{
new BookModel(){Id=1, Author="Einstein", Title="The Grand Design"},
new BookModel(){Id=2, Author="Author", Title="ASP.Net"},
new BookModel(){Id=3, Author="Author1", Title="Visual Studio"}
};
}
}
My BookController class is:
using Book_Store.Repository;
namespace Book_Store.Controllers
{
public class BookController : Controller
{
private readonly BookRepository bookRepository = null;
public BookController()
{
bookRepository = new BookRepository();
}
public List<BookModel> SearchBook(string bookName, string authorName)
{
return bookRepository.SearchBook(bookName, authorName);
}
}
}
The problem is this query is returning a null array every time. I'm executing the command like this:
Can someone please identify the problem in this rather simple program?
Thanks!

How to see arguments when creating a new class?

When creating a new class or method I used to be able to see the parameters needed. But, now they don't come up anymore. How do I view parameters when creating a class?
Running the latest windows version.
public class Main {
public static void main(String args[]) {
Case theCase = new Case("Default", "Corsair", "500W");
}
}
public class Case {
private String model;
private String manufacturer;
private String powerSupply;
public Case(String model, String manufacturer, String powerSupply,) {
this.model = model;
this.manufacturer = manufacturer;
this.powerSupply = powerSupply;
}
public void pressPowerButton() {
System.out.println("Power button pressed");
}
public String getModel() {
return model;
}
public String getManufacturer() {
return manufacturer;
}
public String getPowerSupply() {
return powerSupply;
}
}
When making theCase I can't see what my parameters are and have to move to the "Case" class back and forth
You can explicitly call Parameter Info action which is usually mapped to Ctrl/(Cmd) - p.
Nevermind in order to see the parameters as you type you must type them while in the editor without moving your cursor.

Dynamically update title of Design Support TabLayout

is there a way to dynamically update the title of a tab in a Design Support TabLayout? I tried adding a method in the Adapter which changes the contents of the ArrayList which holds the titles of the tabs and notify the adapter but the tab titles don't change to the new title.
Adapter:
public class TabAdapter extends FragmentPagerAdapter {
private final List<Fragment> fragments = new ArrayList<>();
private final List<String> fragmentTiles = new ArrayList<>();
public TabAdapter(FragmentManager fm) {
super(fm);
}
public void addFragment(Fragment fragment, String title) {
fragments.add(fragment);
fragmentTiles.add(title);
}
#Override
public Fragment getItem(int position) {
return fragments.get(position);
}
#Override
public int getCount() {
return fragments.size();
}
#Override
public CharSequence getPageTitle(int position) {
return fragmentTiles.get(position);
}
public void setFragmentTiles(int index, String title) {
fragmentTiles.set(index, title);
Log.e("ARRAY", fragmentTiles.toString());
}
}
I am changing the content of the title ArrayList like this:
adapter.setFragmentTiles("New title 1");
adapter.setFragmentTiles("New title 2");
adapter.notifyDataSetChanged();
But this doesn't work. Do I have to update the ViewPager or the TabLayout as well?
What's worked for me is to use the setText method on the Tab:
i.e. tab.setText(...); // where ... is CharSequence or resId
Looking at the methods available to the TabLayout you can get the desired Tab instance of an index/position:
e.g. tabLayout.getTabAt(...); // where ... is int.
As far as I can tell, calling notifyDataSetChanged() on the adapter just calls the getCount() of the adapter as opposed to what one might expect of refreshing the title.
Hopefully that helps or at least points you in the right direction.

Returning Dataset to controller in asp.net MVC

In Data access layer I have method to retrieve all the table values. How can I return it into the controller in asp.net MVC. can anyone help me?
Thanks in advance.
public static Dataset GetMembers()
{
//sql steps to retrieve records and fill it in dataset
}
Controller code:
{
var members = class.GetMembers()
return View(members);
}
You'll need to modify your GetMembers method (or implement another one that returns IEnumerable<YourType>. In this example (since you don't provide any additional data), I'll return a list of MyType, which I'll assume looks like:
public class MyType
{
public int ID { get; set; }
public string Name { get; set; }
}
And then populate a List<MyType> inside GetMembers
public static IEnumerable<MyType> GetMembers()
{
List<MyType> list = new List<MyType>();
using(SqlConnection db = new SqlConnection(connectionString))
{
DataSet ds = new DataSet();
// get a DataSet as normal
foreach (DataRow dr in ds.Tables[0].Rows)
{
list.Add(new MyType()
{
ID = Convert.ToInt32(dr["ID"].ToString()),
Name = dr["Name"].ToString())
});
}
}
return list;
}
This is a basic example of how you could return IEnumerable (of which List<T> implements) from your method.