PDA

View Full Version : store as interface



Stephan St├╝ckmann
29 Jan 2010, 12:46 AM
Why is it not possible to create an own store by using a store interface, like the mdel interface? We have own objects which already extends from another object. So we are not able to implement models in an easy way. But its essential to use the existing binding.
Does anyone know if it will be a part within a future release?

terciofilho
29 Jan 2010, 12:54 PM
I agree with you about the interface, "Program to Interface not to Implementation" :-P

But, there is always a but, ModelData is a central interface in GXT, it's used everywhere.

Arno.Nyhm
29 Jan 2010, 12:55 PM
but note: some widgets need a liststore.

i think it is more easy to make a proxy class "CustomModelData implements ModelData" which holds a reference your external object and implement the needed methods. thats more easys than to implement the full store.

Stephan St├╝ckmann
1 Feb 2010, 8:51 AM
This is the solution which has been implemented yet. But the proxy class could not be used directly as binding object for such as a grid.
I want to declare once an object which has our own class hierarchy and implements a store interface. So i can use this object directly for such as a grid binding.

terciofilho
1 Feb 2010, 9:05 AM
Well, I had the same problem.

My solution is something like Composite or Adapter Pattern. I have an object that implements an interface that has a "public Store asStore();" method. To bind the Grid to my object I do something like: "new Grid(myObject.asStore());"

The way GXT is implemented, it doesn't allow you to "program to interface not to implementation", this causes problems for injection, for example.

Arno.Nyhm
2 Feb 2010, 4:29 AM
My solution is something like Composite or Adapter Pattern. I have an object that implements an interface that has a "public Store asStore();" method. To bind the Grid to my object I do something like: "new Grid(myObject.asStore());"


it is possible to show example code how you done this asStore?

terciofilho
2 Feb 2010, 4:46 AM
My code actually is a bit different cause I use GIN, I just have more interfaces, but basically this is it:



public interface GxtStoreMarker
{
public <T extends ModelData> ListStore<T> asStore();

// I usually add some helper methods, so I can access a Store properties directly
public int getCount();
}

public class SomeObject extends SomeOtherObject implements GxtStoreMarker
{
protected ListStore<ModelData> innerStore;

public SomeObject()
{
this.innerStore = new ListStore<ModelData>(/* You can provide a Loader here */)
{
// Some overriden methods or some customization.

// If you add some method here you must externalize
// this implementation to a Inner Class or something.
};
}

public <T extends ModelData> ListStore<T> asStore()
{
return this.innerStore;
}

// Helper method
public int getCount()
{
return this.innerStore.getCount();
}
}