How to set the checkbox selected in the first record on the Listgrid? - smartgwt

my ListGrid already set .setSelectionType(SelectionStyle.SIMPLE) and .setSelectionAppearance(SelectionAppearance.CHECKBOX),but now I want to set the checkbox of the first record true when loaded some records.So,how can I code it ?

Try the following:
listGrid.addDataArrivedHandler(new DataArrivedHandler() {
#Override
void onDataArrived(DataArrivedEvent event) {
listGrid.selectRecord(0);
}
});

Related

Remove value change listener

I am facing problem in value change listener.
I have added value change listener in vaadin option group which has six checkboxes.
optionGroup.addValueChangeListener(this :: optionGroupValueChanged);
//..
private void optionGroupValueChanged(ValueChangeEvent valueChangeEvent) {
//...
}
Now I have one another checkbox which selects all the checkboxes of the option group (because it's multiselect). I want to avoid call of value change listener for individual checkboxes so that I first removed the value change listener and added after selecting all as stated below.
selectAllCheckBox.addValueChangeListener(this :: selectAllChecked);
//...
private void selectAllChecked(ValueChangeEvent valueChangeEvent) {
final boolean isChecked = (boolean) valueChangeEvent.getProperty().getValue();
//Following line does not remove the value change listener
optionGroup.removeValueChangeListener(this :: optionGroupValueChanged);
if(isChecked) {
//So here it will call value change of option group six time
optionGroup.getItemIds().stream().forEach( itemId -> optionGroup.select(itemId));
} else {
optionGroup.setValue(null);
}
optionGroup.addValueChangeListener(this :: optionGroupValueChanged);
}
I have checked code of vaadin removeValueChangeListener method it contains markAsDirty(); method. What is the reason of this behavior ? Is there any other alternative solution for my problem ?
Note : Version of vaadin is 7.5.0
That's because this :: optionGroupValueChanged creates each time new instance of ValueChangeListener. You don't want this, you want to remove very specific instance of ValueChangeListener. The solution is to remember (in private field in example) the reference to the listener and pass it in your add and remove ValueChangeListener calls.
optionGroupListener = this :: optionGroupValueChanged;
optionGroup.addValueChangeListener(optionGroupListener);
private void selectAllChecked(ValueChangeEvent valueChangeEvent) {
final boolean isChecked = (boolean) valueChangeEvent.getProperty().getValue();
//change here
optionGroup.removeValueChangeListener(optionGroupListener );
if(isChecked) {
optionGroup.getItemIds().stream().forEach( itemId -> optionGroup.select(itemId));
} else {
optionGroup.setValue(null);
}
//and here
optionGroup.addValueChangeListener(optionGroupListener );
}

unable to Validate Custom components in SmartGWT

I am unable to get my custom compoenent to be validated in the dynamic form. I tried many versions but it is not working as expected. For e.g. either the label is not showing in BOLD to indicate the field is mandatory and it aloows to save the form without entering anything in the field. Only when the user enters something in the field and deletes it, then the red icon is displayed to the user that the field is mandatory.I dont know what i am missing. please help. code is below
telnumber = new CustomTelephoneTextItem();
telnumber.setName("tel");
telnumber.setTitle("Tel");
telnumber.setTitle(nerpweb.clientFactory.getMessages().tel());
Below is my Custom TextItem which i am using in the above class
public class CustomTelephoneTextItem extends CanvasItem
{
textField_value = new CustomIntegerItem();
textField_value.setShowTitle(false);
textField_value.setWidth(100);
textField_value.setRequired(true);
form.setItems(textField_value, textField_code);
form.validate();
setWrapTitle(false);
this.setCanvas(form);
First, if you want to item title showin bold, you must call item's setRequired(true).
in your code is telnumber.setRequired(true);
Second, if you want to validate item on form.validate(), you must override validate() function in your item and write validation code in this function.
in your code is call form.validate() in CustomTelephoneTextItem validate() function
Here is the code to be implemented to validate custom component
This code will go in your Custom component which you will implement
#Override
public Object getValue()
{
if (validate() && textField_value.getValue() != null)
return textField_value.getValue();
return null;
}
#Override
public void setRequired(Boolean required) {
super.setRequired(true);
}
#Override
public Boolean validate() {
return super.validate();
}
#Override
public void setValidators(Validator... validators) {
textField_value.setValidators(validators);
}
Then in the class where you will create the custom component you will call the setRequired() method,like so
telnumber.setRequired(true);

Get changed unsaved property value of a node in content tab, after clicking save button and before saving the changes. Umbraco

Update:
I want to get a node's property value that has been changed after clicking save button and before saving the changes programmatically, on content tab in BackOffice.
The node could contain many properties. When the save button is clicked, I want to first get the new changed value for the node's properties. I think Umbraco should have APIs to get those in server side.
Any idea would be very much appreciated.
You want to wire into the Document.BeforeSave method in an IApplicationEventHandler class. Like so (assuming you're changing bodyText from "apple" to "orange"):
using umbraco.cms.businesslogic.web;
using Umbraco.Core;
using Umbraco.Web;
namespace ClassLibrary1
{
public class Class1 : IApplicationEventHandler
{
public void OnApplicationStarted(UmbracoApplication httpApplication, ApplicationContext applicationContext)
{
Document.BeforeSave += new Document.SaveEventHandler(Document_BeforeSave);
Document.AfterSave += new Document.SaveEventHandler(Document_AfterSave);
}
void Document_BeforeSave(Document sender, umbraco.cms.businesslogic.SaveEventArgs e)
{
// your code goes here!
sender.getProperty("bodyText").Value // returns apple
}
void Document_AfterSave(Document sender, umbraco.cms.businesslogic.SaveEventArgs e)
{
// your code goes here!
sender.getProperty("bodyText").Value // returns orange
}
public void OnApplicationStarting(UmbracoApplication httpApplication, ApplicationContext applicationContext)
{
// unused
}
public void OnApplicationInitialized(UmbracoApplication httpApplication, ApplicationContext applicationContext)
{
// unused
}
}
}
I tested this in Umbraco 4.11
Cheers
Jonathan
What you could do is use a jquery event handler, that is targeted at the field in the umbraco admin you want to check for changes. This example will work by finding the label of the umbraco field you want to monitor and then adding a jquery event handler that will fire when the field that is the sibling to the label is changed - this example will work for any changes to the 'Name' field that is on every node's 'properties' tab. Different field types will hold the value differently, so $(this).val() should usually work for most - but not all field types.
Drop this into the end of \umbraco\editcontent.aspx
<script type="text/javascript">
$(document).ready(function () {
$("div.propertyItemheader:contains('Name') + div.propertyItemContent").keyup(function () {
alert("field changed");
});
});
</script>

smartgwt listgrid set cursor to hand over an icon field

I've been working on this problem for quite a while but have not been able to solve it.
I have a listgrid with a field type icon. I would like to change the cursor to "hand" over the icon.
I've been searching the web and saw that a couple of solutions existed.
One of them is using addCellOverHandler for the list grid. But I don't understand how you can change the cursor for the specified field of the listgrid.
this.addCellOverHandler(new CellOverHandler() {
#Override
public void onCellOver(CellOverEvent event) {
// not able to get the field and setCursor()
}
});
My field in the listgrid is defined as:
ListGridField iconField = new ListGridField("icon");
iconField.setAlign(Alignment.CENTER);
iconField.setType(ListGridFieldType.ICON);
iconField.setIcon("icons/icon.gif");
Like someone pointed out on the forum, a setCursor() method exist for the listgrid, but not for the field only...
If anybody has a clue...
Thanks
After some more (a lot more...) googling, I found this:
http://forums.smartclient.com/showthread.php?t=15748
The thing is to Override the getCellStyle method in the listgrid.
Here is the code I use:
#Override
protected String getCellStyle(ListGridRecord record, int rowNum, int colNum) {
if (colNum==6){
return "EC_pointer";
}
return super.getCellStyle(record, rowNum, colNum);
}
and in my CSS file:
.EC_pointer {
cursor: pointer;
}
The major fallout is that you have to know in advance the column number of the field.
Further to my comment and adding information from here I tested the following code which works with SmartGwt2.4 under Firefox 5.0.
demandesGrid.setCanHover(true);
demandesGrid.setShowHover(false);
demandesGrid.addCellHoverHandler(new CellHoverHandler() {
#Override
public void onCellHover(CellHoverEvent event) {
if (event.getColNum() == demandesGrid.getFieldNum("icon")) {
// SC.say(demandesGrid.getChildren()[3].toString());
demandesGrid.getChildren()[3].setCursor(Cursor.POINTER);
} else {
demandesGrid.getChildren()[3].setCursor(Cursor.DEFAULT);
}
}
});
I don't know if the index of the ListGridBody is constant; I found it with the SC.say line.
How about
grid.addCellOverHandler(new CellOverHandler() {
#Override
public void onCellOver(CellOverEvent event) {
//cellOver event to get field and refresh the cell
//grid.refreshCell(i, j);
}
});
The best approach is fully demonstrated here (take a look at how "comments/stats" field is being initialized).
In short, u have to extend ListGrid and override createRecordComponent method. In this method you can make any custom component you like and it will be show in grid cell.
Also ListGrid should be initialized with:
listGrid.setShowRecordComponents(true);
listGrid.setShowRecordComponentsByCell(true);

How to add tooltip for a item or cell of a vaadin table

I noticed that vaadin 6.7.0 beta1 supports to add tooltip for row/cell of a table. However, I did not find any example how to add it.
Is there anybody who can provide some sample?
Use code as below:
table.setItemDescriptionGenerator(new ItemDescriptionGenerator() {
public String generateDescription(Component source, Object itemId, Object propertyId) {
if(propertyId == null){
return "Row description "+ itemId;
} else if(propertyId == COLUMN1_PROPERTY_ID) {
return "Cell description " + itemId +","+propertyId;
}
return null;
}}
You could accomplish this by setting a formfieldfactory. Here you could return a button that only loooks like text with styling CSS. This will let you set a caption on the button. This is obviously a ugly hack. More info about buttons and links in vaadin.
table.setTableFieldFactory(new TableFieldFactory() {
// container is the datasource
// item is the row
// property is the column
//
#Override
public Field createField(Container container, Object itemId, Object propertyId, Component uiContext) {
})
You can't add tooltpis (setDescription) to a row/cell nativly - not yet!
It is already in there issue tracker but don't know when they will implement this feature

Resources