Hello,
I am new to SmartGwt though I did a little work on the client side in GWT.
I am trying to explore the use of the TreeGrid component so that I can select treenodes and display information of a particular node in a form, edit it in the form and send it back to the TreeGrid data.
First issue that I am having (been working on this for the whole of yesterday and day before ) is to try to give it a good look and feel and to display the intended information.
My desire is to get it to look something like
http://www.java2s.com/Code/Java/GWT/TreewithMultipleColumnsSampleSmartGWT.htm
I have been trying various methods of the TreeGrid but I am getting a very drab looking interface with empty check boxes. I am unable to give the Grid a good border, the header fields are not being displayed the way I wanted it, the Look and feel is very bad, the nodeicon images are not showing, etc. Pl find below the code that I am playing with. I started with the class LocalDataSample.java that came with the installation.
Any tips on how I can resolve this would be very welcome.
I have a feeling that for some reason the images, style in the smartgwt-skins.jar file are not getting reflected...not sure.... I have kept this jar file and the other gwt and smartgwt jar files in the WEB-INF/lib directory. Hope it is correct
I have tried this both on Unix and windows but have not been able to get a good L and F
I then want to make the nodes selectable so that I can capture info of the node. This I have not tried but some advance tips on this would be helpful.
Regards
package com.app.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.user.client.ui.RootPanel;
import com.smartgwt.client.widgets.tree.TreeGrid;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class SmartGwtTest implements EntryPoint {
/**
* The message displayed to the user when the server cannot be reached or
* returns an error.
*/
private static final String SERVER_ERROR = "An error occurred while "
+ "attempting to contact the server. Please check your network "
+ "connection and try again.";
/**
* Create a remote service proxy to talk to the server-side Greeting service.
*/
private final GreetingServiceAsync greetingService = GWT.create(GreetingService.class);
/**
* This is the entry point method.
*/
public void onModuleLoad() {
final LocalDataTreeSample localDataTreeSample = new LocalDataTreeSample();
final TreeGrid treeGrid= localDataTreeSample.getTreeGrid();
// Add the nameField and sendButton to the RootPanel
// Use RootPanel.get() to get the entire body element
RootPanel.get("nameFieldContainer").add(treeGrid);
// Create a handler for the sendButton and nameField
class MyHandler implements ClickHandler, KeyUpHandler {
/**
* Fired when the user clicks on the sendButton.
*/
public void onClick(ClickEvent event) {
//sendNameToServer();
}
/**
* Fired when the user types in the nameField.
*/
public void onKeyUp(KeyUpEvent event) {
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
//sendNameToServer();
}
}
}
// Add a handler to send the name to the server
MyHandler handler = new MyHandler();
//treeGrid.addCickHandler(handler);
}
}
package com.app.client;
import com.smartgwt.client.types.ExpansionMode;
import com.smartgwt.client.types.SelectionAppearance;
import com.smartgwt.client.types.TreeModelType;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.tree.Tree;
import com.smartgwt.client.widgets.tree.TreeGrid;
import com.smartgwt.client.widgets.tree.TreeGridField;
import com.smartgwt.client.widgets.tree.TreeNode;
//import com.smartgwt.sample.showcase.client.PanelFactory;
//import com.smartgwt.sample.showcase.client.ShowcasePanel;
//public class LocalDataTreeSample extends ShowcasePanel {
public class LocalDataTreeSample {
private static final String DESCRIPTION = "Load tree data from a collection of local beans.";
/***
// public static class Factory implements PanelFactory {
public static class Factory {
private String id;
public Canvas create() {
LocalDataTreeSample panel = new LocalDataTreeSample();
id = panel.getID();
return panel;
}
public String getID() {
return id;
}
public String getDescription() {
return DESCRIPTION;
}
}
***/
public TreeGrid getTreeGrid() {
TreeGrid treeGrid = new TreeGrid();
treeGrid.setWidth(600);
treeGrid.setHeight(400);
treeGrid.setBorder("4px");
//treeGrid.addStyleName("treeGrid");
treeGrid.setStyleName("treeGrid");
//treeGrid.setIconSize(14);
treeGrid.setShowAllColumns(Boolean.TRUE);
treeGrid.setExpansionMode(ExpansionMode.DETAILS);
//treeGrid.setImage("collapsedImage", "icons/16/person.png");
treeGrid.setNodeIcon( "http:/localhost:8080/SmartGwtTest/icons/person.png");
treeGrid.setFolderIcon( "icons/16/person.png");
treeGrid.setSelectionAppearance(SelectionAppearance.ROW_STYLE);
//treeGrid.setBackgroundColor("grey");
TreeGridField field = new TreeGridField("Name", "Tree from local data");
field.setCanSort(false);
treeGrid.setFields(field);
treeGrid.show();
///**
Tree tree = new Tree();
tree.setModelType(TreeModelType.PARENT);
//tree.setRootValue("1");
tree.setNameProperty("Name");
tree.setIdField("EmployeeId");
tree.setParentIdField("ReportsTo");
tree.setShowRoot(true);
System.out.println("11111");
EmployeeTreeNode root = new EmployeeTreeNode("4", "1", "Charles-or Madigen");
EmployeeTreeNode node2 = new EmployeeTreeNode("188", "4", "Rogine Leger");
EmployeeTreeNode node3 = new EmployeeTreeNode("189", "4", "Gene Porter");
EmployeeTreeNode node4 = new EmployeeTreeNode("265", "189", "Olivier Doucet");
EmployeeTreeNode node5 = new EmployeeTreeNode("264", "189", "Cheryl Pearson");
//tree.setRoot(rootNode);
tree.setData(new TreeNode[]{root, node2, node3, node4, node5});
//tree.setData(new TreeNode[]{rootNode});
//tree.setRoot(root);
treeGrid.setData(tree);
System.out.println("2223333");
return treeGrid;
}
public static class EmployeeTreeNode extends TreeNode {
public EmployeeTreeNode(String employeeId, String reportsTo, String name) {
setEmployeeId(employeeId);
setReportsTo(reportsTo);
System.out.println(" in constructor 11");
setIcon("icons/16/person.png");
setName(name);
}
public void setEmployeeId(String value) {
setAttribute("EmployeeId", value);
}
public void setReportsTo(String value) {
setAttribute("ReportsTo", value);
}
public void setName(String name) {
setAttribute("Name", name);
}
}
public String getIntro() {
return DESCRIPTION;
}
}
smartgwttest.gwt.xml
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='smartgwttest'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User'/>
<inherits name="com.smartgwt.SmartGwt"/>
<inherits name="com.google.gwt.core.Core"/>
<inherits name="com.google.gwt.user.History"/>
<inherits name="com.smartgwt.SmartGwtNoScript"/>
<inherits name="com.smartgwt.tools.SmartGwtTools"/>
<inherits name="com.smartclient.theme.enterprise.EnterpriseResources"/>
<inherits name="com.smartclient.theme.enterpriseblue.EnterpriseBlueResources"/>
<inherits name="com.smartclient.theme.graphite.GraphiteResources"/>
<!-- Inherit the default GWT style sheet. You can change -->
<!-- the theme of your GWT application by uncommenting -->
<!-- any one of the following lines. -->
<inherits name='com.google.gwt.user.theme.standard.Standard'/>
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
<!-- Other module inherits -->
<!-- Specify the app entry point class. -->
<entry-point class='com.app.client.SmartGwtTest'/>
<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>
</module>
I am new to SmartGwt though I did a little work on the client side in GWT.
I am trying to explore the use of the TreeGrid component so that I can select treenodes and display information of a particular node in a form, edit it in the form and send it back to the TreeGrid data.
First issue that I am having (been working on this for the whole of yesterday and day before ) is to try to give it a good look and feel and to display the intended information.
My desire is to get it to look something like
http://www.java2s.com/Code/Java/GWT/TreewithMultipleColumnsSampleSmartGWT.htm
I have been trying various methods of the TreeGrid but I am getting a very drab looking interface with empty check boxes. I am unable to give the Grid a good border, the header fields are not being displayed the way I wanted it, the Look and feel is very bad, the nodeicon images are not showing, etc. Pl find below the code that I am playing with. I started with the class LocalDataSample.java that came with the installation.
Any tips on how I can resolve this would be very welcome.
I have a feeling that for some reason the images, style in the smartgwt-skins.jar file are not getting reflected...not sure.... I have kept this jar file and the other gwt and smartgwt jar files in the WEB-INF/lib directory. Hope it is correct
I have tried this both on Unix and windows but have not been able to get a good L and F
I then want to make the nodes selectable so that I can capture info of the node. This I have not tried but some advance tips on this would be helpful.
Regards
package com.app.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.user.client.ui.RootPanel;
import com.smartgwt.client.widgets.tree.TreeGrid;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class SmartGwtTest implements EntryPoint {
/**
* The message displayed to the user when the server cannot be reached or
* returns an error.
*/
private static final String SERVER_ERROR = "An error occurred while "
+ "attempting to contact the server. Please check your network "
+ "connection and try again.";
/**
* Create a remote service proxy to talk to the server-side Greeting service.
*/
private final GreetingServiceAsync greetingService = GWT.create(GreetingService.class);
/**
* This is the entry point method.
*/
public void onModuleLoad() {
final LocalDataTreeSample localDataTreeSample = new LocalDataTreeSample();
final TreeGrid treeGrid= localDataTreeSample.getTreeGrid();
// Add the nameField and sendButton to the RootPanel
// Use RootPanel.get() to get the entire body element
RootPanel.get("nameFieldContainer").add(treeGrid);
// Create a handler for the sendButton and nameField
class MyHandler implements ClickHandler, KeyUpHandler {
/**
* Fired when the user clicks on the sendButton.
*/
public void onClick(ClickEvent event) {
//sendNameToServer();
}
/**
* Fired when the user types in the nameField.
*/
public void onKeyUp(KeyUpEvent event) {
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
//sendNameToServer();
}
}
}
// Add a handler to send the name to the server
MyHandler handler = new MyHandler();
//treeGrid.addCickHandler(handler);
}
}
package com.app.client;
import com.smartgwt.client.types.ExpansionMode;
import com.smartgwt.client.types.SelectionAppearance;
import com.smartgwt.client.types.TreeModelType;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.tree.Tree;
import com.smartgwt.client.widgets.tree.TreeGrid;
import com.smartgwt.client.widgets.tree.TreeGridField;
import com.smartgwt.client.widgets.tree.TreeNode;
//import com.smartgwt.sample.showcase.client.PanelFactory;
//import com.smartgwt.sample.showcase.client.ShowcasePanel;
//public class LocalDataTreeSample extends ShowcasePanel {
public class LocalDataTreeSample {
private static final String DESCRIPTION = "Load tree data from a collection of local beans.";
/***
// public static class Factory implements PanelFactory {
public static class Factory {
private String id;
public Canvas create() {
LocalDataTreeSample panel = new LocalDataTreeSample();
id = panel.getID();
return panel;
}
public String getID() {
return id;
}
public String getDescription() {
return DESCRIPTION;
}
}
***/
public TreeGrid getTreeGrid() {
TreeGrid treeGrid = new TreeGrid();
treeGrid.setWidth(600);
treeGrid.setHeight(400);
treeGrid.setBorder("4px");
//treeGrid.addStyleName("treeGrid");
treeGrid.setStyleName("treeGrid");
//treeGrid.setIconSize(14);
treeGrid.setShowAllColumns(Boolean.TRUE);
treeGrid.setExpansionMode(ExpansionMode.DETAILS);
//treeGrid.setImage("collapsedImage", "icons/16/person.png");
treeGrid.setNodeIcon( "http:/localhost:8080/SmartGwtTest/icons/person.png");
treeGrid.setFolderIcon( "icons/16/person.png");
treeGrid.setSelectionAppearance(SelectionAppearance.ROW_STYLE);
//treeGrid.setBackgroundColor("grey");
TreeGridField field = new TreeGridField("Name", "Tree from local data");
field.setCanSort(false);
treeGrid.setFields(field);
treeGrid.show();
///**
Tree tree = new Tree();
tree.setModelType(TreeModelType.PARENT);
//tree.setRootValue("1");
tree.setNameProperty("Name");
tree.setIdField("EmployeeId");
tree.setParentIdField("ReportsTo");
tree.setShowRoot(true);
System.out.println("11111");
EmployeeTreeNode root = new EmployeeTreeNode("4", "1", "Charles-or Madigen");
EmployeeTreeNode node2 = new EmployeeTreeNode("188", "4", "Rogine Leger");
EmployeeTreeNode node3 = new EmployeeTreeNode("189", "4", "Gene Porter");
EmployeeTreeNode node4 = new EmployeeTreeNode("265", "189", "Olivier Doucet");
EmployeeTreeNode node5 = new EmployeeTreeNode("264", "189", "Cheryl Pearson");
//tree.setRoot(rootNode);
tree.setData(new TreeNode[]{root, node2, node3, node4, node5});
//tree.setData(new TreeNode[]{rootNode});
//tree.setRoot(root);
treeGrid.setData(tree);
System.out.println("2223333");
return treeGrid;
}
public static class EmployeeTreeNode extends TreeNode {
public EmployeeTreeNode(String employeeId, String reportsTo, String name) {
setEmployeeId(employeeId);
setReportsTo(reportsTo);
System.out.println(" in constructor 11");
setIcon("icons/16/person.png");
setName(name);
}
public void setEmployeeId(String value) {
setAttribute("EmployeeId", value);
}
public void setReportsTo(String value) {
setAttribute("ReportsTo", value);
}
public void setName(String name) {
setAttribute("Name", name);
}
}
public String getIntro() {
return DESCRIPTION;
}
}
smartgwttest.gwt.xml
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='smartgwttest'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User'/>
<inherits name="com.smartgwt.SmartGwt"/>
<inherits name="com.google.gwt.core.Core"/>
<inherits name="com.google.gwt.user.History"/>
<inherits name="com.smartgwt.SmartGwtNoScript"/>
<inherits name="com.smartgwt.tools.SmartGwtTools"/>
<inherits name="com.smartclient.theme.enterprise.EnterpriseResources"/>
<inherits name="com.smartclient.theme.enterpriseblue.EnterpriseBlueResources"/>
<inherits name="com.smartclient.theme.graphite.GraphiteResources"/>
<!-- Inherit the default GWT style sheet. You can change -->
<!-- the theme of your GWT application by uncommenting -->
<!-- any one of the following lines. -->
<inherits name='com.google.gwt.user.theme.standard.Standard'/>
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
<!-- Other module inherits -->
<!-- Specify the app entry point class. -->
<entry-point class='com.app.client.SmartGwtTest'/>
<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>
</module>
Comment