While using Vaadin 7.1.12, I am having problems styling the mouse cursor. The following demo code works just fine:
// List all the pointer types in CSS
String pointers[] = {"auto", "crosshair", "default", "help", "move", "pointer", "progress",
"text", "wait", "inherit"};
for (int i=0; i<pointers.length; i++)
select.addItem(pointers[i]
);
select.addListener(new Property.ValueChangeListener() {
public void valueChange(ValueChangeEvent event) {
// Set the style for the root component
System.out.println("setting cursor to select-"+(String) select.getValue());
getParent().getUI().setStyleName("select-" +
(String) select.getValue());
}
});
select.setImmediate(true);
layout.addComponent(select);
And I have the following stylesheet changes:
.select-pointer {cursor: auto;}
.select-crosshair {cursor: crosshair;}
.select-default {cursor: default;}
.select-help {cursor: help;}
.select-move {cursor: move;}
.select-pointer {cursor: pointer;}
.select-progress {cursor: progress;}
.select-text {cursor: text;}
.select-wait {cursor: wait;}
.select-inherit {cursor: inherit;}
However, when I am adding lots and lots of items to my tree on a node expand, the following code will not work.
[code]
@Override
public void nodeExpand(ExpandEvent event) {
final Item i = theTree.getItem(event.getItemId());
if (!theTree.hasChildren(event.getItemId())){
String fileName = (String)i.getItemProperty(ReportTree.FILENAME).getValue();
populateNode(fileName, event.getItemId());
}
}
@SuppressWarnings("unchecked")
private void populateNode(String directoryName, Object parentId) {
...
final File[] files = subdir.listFiles();
Arrays.sort(files);
// set wait cursor if necessary
boolean useWaitCursor = false;
if (files.length > BIG_DIR_SIZE){
useWaitCursor = true;
getParent().getUI().setStyleName(WAIT_CURSOR_STYLE); // this is just "select-wait"
// trying to force an update for the client's cursor
if (pushMode == true){
logger.info("setting up server push");
// not a good name because it is really generic
BrowserHistoryButtonThread t = new BrowserHistoryButtonThread(parms omitted for clarity);
ui.access(t);
}
}
for (int x = 0; x < files.length; x++) {
try {
// add new file item to tree
String fullName = files[x]
.getCanonicalPath().toString();
fullName=unDOSify(fullName);
fullName = fullName.replaceAll(“\\”,“/”); // ensure all stored entries are in *nix format
final String name = files
.getName().toString();
String urlPortion = fullName.substring(filePrefix.length()); // NPE here due to filePrefix not set above
Object id = treeContainer.addItem(); // for this tree/container, the id is an Integer
treeContainer.setParent(id, parentId);
treeContainer.getContainerProperty(id, ReportTree.CAPTION).setValue(name);
treeContainer.getContainerProperty(id, ReportTree.FILENAME).setValue(fullName);
String url = urlPrefix+urlPortion;
//logger.info("url to decorate with is "+url);
treeContainer.getContainerProperty(id, ReportTree.FILE_URL).setValue(url);
if (files
.isDirectory()){
treeContainer.setChildrenAllowed(id, true);
}else{
treeContainer.setChildrenAllowed(id, false);
}
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
// set cursor back if necessary
if (useWaitCursor == true){
logger.info(“removing wait style”);
getParent().getUI().removeStyleName(WAIT_CURSOR_STYLE);
}
}
[/code]
The code is being run when opening a big subdirectory, but the cursor does not change. You will notice a server push in there. Server push works for me elsewhere, because I use it to update some gui buttons at certain times.
In my tests for this, I am opening a subdirectory with ~2000 files in it, and the code for setting and unsetting the cursor, including the server push, spans about 2 seconds.
Am I going about this the wrong way?