Eclipse: Tree View And Table View - eclipse

I want to know if it's possible to use the same content and label providers for Tree and Table in Eclipse views or they must have separate content and label providers. I am trying to use the content and label providers i wrote for the tree for the table as well but i see nothing on the table view.
Thanks.

You CAN use the same Label provider.
You CAN'T use the same content provider since the tree content provider must implement ITreeContentProvider which is not "compatible" with the IStructuredContentProvider interface that must be implemented by table content provider.
By not "compatible" I mean that the implementation of IStructuredContentProvider.getElements(Object inputElement) method in TreeContentProvider must return only the "roots" objects whereas it must return all the objects for a list content provider.

You can share the providers. Your ContentProvider will have to implement both IStructuredContentProvider and ITreeContentProvider. I guess that normally you will want to have separate content providers.
In the example the Tree will show only one level with the elements (all elements are roots). The Table will show only one row.
Example:
//ContentProvider for Tree and Table
public static class CommonContentProvider extends ArrayContentProvider
implements ITreeContentProvider {
#Override
public Object[] getChildren(final Object arg0) {
return null;
}
#Override
public Object getParent(final Object arg0) {
return null;
}
#Override
public boolean hasChildren(final Object arg0) {
return false;
}
}
public static void testCommonProviderTreeTable(final Composite c) {
final Collection<String> input = Arrays.asList(new String[] { "hi",
"hola" });
final IContentProvider contentProvider = new CommonContentProvider();
final IBaseLabelProvider labelProvider = new LabelProvider() {
#Override
public String getText(final Object element) {
return element.toString();
}
};
final TreeViewer tree = new TreeViewer(c, SWT.NONE);
tree.setContentProvider(contentProvider);
tree.setLabelProvider(labelProvider);
tree.setInput(input);
final TableViewer table = new TableViewer(c, SWT.NONE);
table.setContentProvider(contentProvider);
table.setLabelProvider(labelProvider);
table.setInput(input);
}

Related

Wicket 7 - Select, SelectOptions and pre-set

Im using Select instead of DropDownChoice to use OPTGROUP.
Select<Role> roleInput = new Select<Role>("role", new PropertyModel<Role>(this,"selectedRole"));
The two list of Role are:
SelectOptions<Role> fedOptions = new SelectOptions<Role>("federazione",federationRoleList,new RoleRenderer());
SelectOptions<Role> eOptions = new SelectOptions<Role>("enti",eRoleList,new RoleRenderer());
Its working well when submitting and also applying a AjaxFormComponentUpdatingBehavior on roleInput, I have my PropertyModel dynamically modified.
Unfortunally I have a problem with pre-set.
I tried to set selectedRole with a specific Role but the Select always start with the first element of the first list.
DropDownChoice works perfectly pre-setting the model but not Select.
I've tried with
roleInput.setModelObject(selectedRole);
but its not working.
I thinks the problem is with this component that has to manage two or more Repeaters instead of a single list.
Any clue?
Thanks
EDIT:
Implementation of RoleRenderer
public class RoleRenderer implements IChoiceRenderer<Role>,Serializable{
private static final long serialVersionUID = 1L;
#Override
public Object getDisplayValue(Role object) {
return object.getName();
}
#Override
public String getIdValue(Role object, int index) {
return object.getId().toString();
}
#Override
public Role getObject(String id, IModel<? extends List<? extends Role>> choices) {
return getObjectFromId(id);
}
public Role getObjectFromId(String id){
return null;
};
}
NOTE: getObjectFromId require access to Manager so will be overrided outside.
Put a breakpoint at org.apache.wicket.extensions.markup.html.form.select.SelectOption#onComponentTag() and see what is returned by select.isSelected(this) for the SelectionOption that matches the default model (object).
It might be that your #equals() implementation is not correct.

GWT: Showing a String list in DataGrid

i got a Presenter that is supposed to present a popup window what contains a DataGrip to show log file entries from a String list. I try to set the appropriate settings, but the number of log file lines that are displayed do not match the String list. I tried to enhance the data assignment, resulting in the Presenter not being shown any more.
Could you please give me a hint what i am doing wrong?
The parts of my presenter related to the DataGrid are:
// Create a list data provider.
final ListDataProvider<String> dataProvider = new ListDataProvider<String>();
public interface MyView extends PopupView, HasUiHandlers<DeviceLogfileUiHandlers> {
DataGrid<String> getDataGrid();
}
#Inject
DeviceLogfilePresenterWidget(final EventBus eventBus, final MyView view) {
super(eventBus, view);
getView().setUiHandlers(this);
}
protected void onBind() {
super.onBind();
// Add the cellList to the dataProvider.
dataProvider.addDataDisplay(getView().getDataGrid());
TextColumn<String> stringColumn = new TextColumn<String>() {
#Override
public String getValue(String s) {
return s;
}
};
getView().getDataGrid().addColumn(stringColumn);
}
#Override
protected void onReveal() {
super.onReveal();
}
public void setDeviceLog(List<String> logEntries) {
getView().getDataGrid().setRowData(0, logEntries);
//These entries make the presenter not show up any more:
dataProvider.addDataDisplay(getView().getDataGrid());
dataProvider.setList(logEntries);
getView().getDataGrid().setRowCount(logEntries.size(), true);
getView().getDataGrid().setVisibleRange(0, logEntries.size());
getView().getDataGrid().setPageSize(logEntries.size());
getView().getDataGrid().redraw();
}

How to bind a list of objects to ListBox in GWT?

I want to bind my services to ListBox but I can't bind it.
//Service class
public class Service {
private String serviceName;
public Service(String serviceName) {
this.serviceName = serviceName;
}
public String getServiceName() {
return serviceName;
}
public void setServiceName(String serviceName) {
this.serviceName = serviceName;
}
}
// SignUpBean class
public class SignUpBean {
private List<Service> services;
public List<Service> getServices() {
return services;
}
public void setServices(List<Service> services) {
this.services = services;
}
}
The following is my Main Editor
public class SignUpEditor extends SimplePanelimplements Editor<SignUpBean> {
public ListBox services;
public void SignUpEditor (){
services.addItem("Service1");
services.addItem("Service2");
setWidget(services);
}
}
I am not getting any error but I think I have to use ListEditor or CompositeEditor. But i don't know about it. Can anyone suggest how to bind Service to ListBox
ListBox suppose to be a LeafValueEditor. Conceptually we don't edit the list in the ListBox. Rather We select a value from the list which will be displayed in the selection. So, ListBox holds only one value and thus ListBox must be leaf value Editor.
Currently there is no GWT support to directly bind the list to ListBox. We have to write an adapter which extends ListEditor ( Refer HasDataEditor class for more detail ). This approach is strange.
Simple approach is to write an adapter which implements LeafValueEditor< List < String > >. In adapter's setValue method we should iterate over the list and call listBox.addItem for each value in the list.
I don't recommend either approaches simply because ListBox's LIST is NON EDITABLE and only VALUE is EDITABLE. I recommend doing addItems manually without using Editors.
UPDATED : HasDataAdapter is an example ListEditor. Refer that implementation. You may get some idea.

GWT Editor and GXT Grid Not Sending Newly Created Proxy Entities, Only NULL Values

Does anybody have a solution to why I would be saving nulls to a OneToMany List on a server entity through a GXT Grid that contains a ListStoreEditor sub-editor?
I've followed the Sencha Example, GridBindingExample to a tee.
http://www.sencha.com/examples/#ExamplePlace:gridbinding
public class MyEditor implements IsWidget, Editor<FooProxy> {
interface Binder extends UiBinder<Widget, MyEditor> {}
private static Binder uiBinder = GWT.create(Binder.class);
public interface Driver extends SimpleBeanEditorDriver<MyProxy, MyEditor> {}
private Driver driver = GWT.create(Driver.class);
private ListStore<BarProxy> store;
ListStoreEditor<BarProxy> items;
#Ignore
#UiField(provided = true)
Grid<BarProxy> grid;
#Ignore
#UiField
ChildEditor childEditor;
#Override
public Widget asWidget() {
MyProperties props = GWT.create(MyProperties.class);
this.store = new ListStore<BarProxy>(props.key());
List<ColumnConfig<BarProxy, ?>> columns = new ArrayList<ColumnConfig<BarProxy, ?>>();
columns.add(new ColumnConfig<BarProxy, String>(props.itemName(), 300, "MyColumn"));
this.grid = new Grid<BarProxy>(store,new ColumnModel<BarProxy>(columns));
items = new ListStoreEditor<BarProxy>(store);
Widget widget = uiBinder.createAndBindUi(this);
driver.initialize(childEditor);
childEditor.getCreateButton().addSelectHandler(new SelectHandler() {
#Override
public void onSelect(SelectEvent event) {
RequestContext context = factoryProvider.get().barRequest();
BarProxy entity = context.create(BarProxy.class);
entity.setName("Eugene Qtest");
entity.setAge(45);
driver.edit(entity);
store.add(driver.flush());
}
});
return widget;
}
}
public class ChildEditor implements IsWidget, Editor<BarProxy> {
interface Binder extends UiBinder<Widget, ChildEditor> {}
private static Binder uiBinder = GWT.create(Binder.class);
#UiField
TextButton createButton;
#Override
public Widget asWidget() {
return uiBinder.createAndBindUi(this);
}
public TextButton getCreateButton() {
return createButton;
}
}
On an upper level presenter in my code, I am calling:
RequestContext req = editorPresenter.getDriver().flush();
req.fire();
This does save all data elements that the GWT Editor captures. In my database it does create the row for the grid in the above code, but all the values are null, so when the RequestContext fires, the persist brings back an empty row within the grid. So there is no foreign key to associate the entity in the OneToMany relationship back to its parent entity.
Also, I've looked at the JSON request and response to the server and it doesn't look like any of the values are being sent in the entity. It may be obfuscated, but it looks as though the other values are in plain text, so I don't think the proxy entity values are even being passed.
Any help would be great! Thanks
driver.edit(entity);
store.add(driver.flush());
These lines are saying "Draw the new object in the editor-- okay, take whatever value was put in there and add it to the store". I'm not sure this is what you intend.
Later, you reference an editorPresenter, but that doesn't seem to be in your code, and it isn't clear when you do that flush (or even the preliminary edit() call) and fire. You also make an Editor<BarProxy>, but there are no subeditors in that type to allow editing.
In the example you link to, there are two different drivers in the mix. The first takes care of the entire list, by passing it into the ListStore - this wasn't actually needed for the sake of an example, but is there to help explain how you might tie this into a bigger case, like the http://www.sencha.com/examples/#ExamplePlace:listpropertybinding example. The example should really be treated as two different editors, with two different drivers - doubly so when testing. First make sure one works, and returns the right values after driver.flush(), then the other.
As I started with, I think that your invocation of driver.flush() immediately after the edit call is almost certainly not what you want, (since the driver will have had no effect), so starting there would be good. Then, if that is what you want, test that when you receive the call on the server, you are getting the model object with all of its values.
This took me days to figure out, with the help of Colin in the above comments, Thanks!
The reason the grid was populating, but when you flushed the main editor on save, the values disappeared and a blank row was inserted into the grid, was because you have to implement the HasRequestContext interface on the editor to maintain the same RequestContext session. Below is my amended code.
public class MyEditor implements IsWidget, Editor<FooProxy>, HasRequestContext<FooProxy> {
interface Binder extends UiBinder<Widget, MyEditor> {}
private static Binder uiBinder = GWT.create(Binder.class);
private RequestContext ctx;
private ListStore<BarProxy> store;
ListStoreEditor<BarProxy> items;
#Ignore
#UiField(provided = true)
Grid<BarProxy> grid;
#Ignore
#UiField
ChildEditor childEditor;
#Override
public Widget asWidget() {
MyProperties props = GWT.create(MyProperties.class);
this.store = new ListStore<BarProxy>(props.key());
List<ColumnConfig<BarProxy, ?>> columns = new ArrayList<ColumnConfig<BarProxy, ?>>();
columns.add(new ColumnConfig<BarProxy, String>(props.itemName(), 300, "MyColumn"));
this.grid = new Grid<BarProxy>(store,new ColumnModel<BarProxy>(columns));
items = new ListStoreEditor<BarProxy>(store);
Widget widget = uiBinder.createAndBindUi(this);
driver.initialize(childEditor);
childEditor.getCreateButton().addSelectHandler(new SelectHandler() {
#Override
public void onSelect(SelectEvent event) {
RequestContext context = ctx.barRequest();
BarProxy entity = context.create(BarProxy.class);
entity.setName("Eugene Qtest");
entity.setAge(45);
ctx.edit(entity);
store.add(entity);
}
});
return widget;
}
#Override
public void setRequestContext(RequestContext ctx) {
this.ctx = ctx;
}
}

GWT CellTree Selection of Parent nodes

I'm trying to use the GWT CellTree to display a heterogeneous, hierarchical data model. I need to be able to a single selection, but be able to select Parent nodes as well as child nodes. For example, if you look at GWT's own example, you'll see that they only provide one selection model for the leave nodes.
I tried to extend their example by providing one selection model for all nodes. However, that seems impossible. So what I ended up with where 3 SelectionModels one for each node type (Composer, PlayList, Song).
What am I missing?
Thanks in advance.
In the getNodeInfo function of your TreeViewModel you have to pass the selectionModel to each new DefaultNodeInfo instance at each level.
return new DefaultNodeInfo<MyDTO>(dataProvider,new MyDTOCell(),selectionModel,null);
and then in the SelectionChangeEventHandler you have do something like this:
selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
#Override
public void onSelectionChange(SelectionChangeEvent event) {
Object object = selectionModel.getSelectedObject();
if (object instanceof MyRootDTO)
{
// DO SOMETHING with root level selected node
}
else if (object instanceof MySecondLevelDTO) {
// DO SOMETHING WITH 2. level selected node
}
// additional levels
});
Update:
In order to get around the typing problem, you can define an abstract base class which is extended by all your DTO's.
public abstract class BaseModel {
public static final ProvidesKey<BaseModel> KEY_PROVIDER = new ProvidesKey<BaseModel>() {
public Object getKey(BaseModel item) {
return item == null ? null : item.getId();
}
};
public abstract Object getId();
}
In your DTO's you extend the BaseModel and implement the abstract getId() method:
public class MyDTO extends BaseModel {
#Override
public Object getId() {
//return unique ID (i.e. MyDTO_1)
}
}