I have a grid like this one . The default behavior of this widget is to sort the column when clicking on the header. I want to disable that, and leave only the options in the context menu.
grid.addHeaderClickHandler(new HeaderClickHandler() {
#Override
public void onHeaderClick(HeaderClickEvent event) {
event.getEvent().cancelBubble(true);
event.getEvent().preventDefault();
event.getEvent().stopPropagation();
Window.alert("Event caught");
}
});
The alert gets displayed before the sorting. But when clicking Ok the default behavior kicks in.
Do you have any suggestions on how to accomplish this?
A solution that might work is to use the NativePreviewHandler, something similar to
Event.addNativePreviewHandler(new NativePreviewHandler()
{
#Override
public void onPreviewNativeEvent(final NativePreviewEvent event)
{
if (event.getTypeInt() == Event.ONCLICK)
{
Element targetElement = Element.as(event.getNativeEvent().getEventTarget());
if (!tableHeader.asWidget().getElement().isOrHasChild(targetElement))
{
event.getNativeEvent().stopPropagation();
}
}
}
});
In order to disable sorting you have to configure the column(s) to forbid sorting.
E.g. if you create a column like this (based on the source code from http://www.sencha.com/examples/#ExamplePlace:basicgrid)
ColumnConfig<Stock, String> symbolCol = new ColumnConfig<Stock, String>(props.symbol(), 100, "Symbol");
disable sorting by adding
symbolCol.setSortable(false);
See http://dev.sencha.com/deploy/gxt-3.0.0/javadoc/gxt/com/sencha/gxt/widget/core/client/grid/ColumnConfig.html#setSortable%28boolean%29 for documentation (and other options).
Ok I found it grid.getView().setSortingEnabled(false);. This will disable the sorting when clicking on the header, but keep the menu items in place.
Related
I'm using a tabcontainer in my webpage. In one of the tabpages, I'm adding some data to a table. In another tabpage I'm dynamically generating buttons according to same table. However, the inserted or deleted changes are not shown in that page; there are no new buttons for new values or disappeared buttons for deleted records. I'm using Vaadin Push both as an annotation and as manually. I'm also refilling the table on tabpage change:
public MainTabContainer(){
//...
tabshtMain.addSelectedTabChangeListener(new SelectedTabChangeListener() {
#Override
public void selectedTabChange(SelectedTabChangeEvent event) {
event.getTabSheet().getSelectedTab().setEnabled(true);
event.getTabSheet().getSelectedTab().requestRepaintAll();
if (event.getTabSheet().getSelectedTab() == steril) {
steril.fillTables();
tabshtMain.markAsDirty();
steril.markAsDirty();
getUI().push();
}
});
}
}
And here is the code sample where I generate buttons for the records in class of tabpage:
private MHorizontalLayout buildMHorizontalLayout_3() {
horizontalLayout_3 = new MHorizontalLayout();
horizontalLayout_3.setImmediate(true);
horizontalLayout_3.setWidth("100.0%");
horizontalLayout_3.setHeight("-1px");
horizontalLayout_3.setMargin(false);
for (StrMachine strMchn : listGrp.keySet()) {
MButton btnMakine = new MButton();
btnMchn.setImmediate(true);
btnMchn.setWidth("80px");
btnMchn.setHeight("80px");
btnMchn.setCaption(Icon.CREDIT_CARD.variant(IconVariant.SIZE_4X));
btnMchn.setHtmlContentAllowed(true);
btnMchn.setId(strMchn.getCode());
btnMchn.addClickListener(btnMchnClickListener);
horizontalLayout_3.addComponent(btnMchn);
horizontalLayout_3.setComponentAlignment(btnMakine, new Alignment(48));
}
return horizontalLayout_3;
}
To solve the issue I've made controls 'immediate' and called requestRepaintAll() bu they didn't help. Only refreshing page is working though.
Sorry for my language and missing jargons of sof. If you have any solutions or suggestions for the problem, please advise me.
Thanks
See below for code sample, the method handleMouseDoubleClick method will take seconds to run and open another layout screen containing buttons and links. End users may click many times on one listed item in the table control and create flood of mouse events, how can I handle the last mouse event only?
Table tableControl = (Table) control;
tableControl.addMouseListener(new MouseAdapter()
{
public void mouseDown(MouseEvent e)
{
handleMouseDown(e);
}
public void mouseUp(MouseEvent e)
{
handleMouseUp(e);
}
public void mouseDoubleClick(MouseEvent e)
{
handleMouseDoubleClick(e);
}
}
Create a flag field. Set it to true when handler was called. Initialize it with false.
You just need to check whether your screen is already initialized or not before creating another one.
Set the cursor to hourglass and/or disable the table, resetting these after the new "layout screen" is closed...
Is there a way to disable the Back button in a browser (basically clearing the History token stack) in GWT? Once I browse to a certain page in my application I want to make sure that the user can't use the back button to go back, but only be able to use links on the page to navigate the site.
You cannot disable a button just intercept it and change its return to something the browser does not understand.
This removes the history:
Window.addWindowClosingHandler(new ClosingHandler() {
#Override
public void onWindowClosing(ClosingEvent event) {
event.setMessage("My program");
}
});
To understand it see: http://groups.google.com/group/google-web-toolkit/browse_thread/thread/8b2a7ddad5a47af8/154ec7934eb6be42?lnk=gst&q=disable+back+button#154ec7934eb6be42
However, I would recommend not doing this because your it goes against good UI practices. Instead you should figure out a way that the back button does not cause a problem with your code.
Call the method below in the onModuleLoad().
private void setupHistory() {
final String initToken = History.getToken();
if (initToken.length() == 0) {
History.newItem("main");
}
// Add history listener
HandlerRegistration historyHandlerRegistration = History.addValueChangeHandler(new ValueChangeHandler() {
#Override
public void onValueChange(ValueChangeEvent event) {
String token = event.getValue();
if (initToken.equals(token)) {
History.newItem(initToken);
}
}
});
// Now that we've setup our listener, fire the initial history state.
History.fireCurrentHistoryState();
Window.addWindowClosingHandler(new ClosingHandler() {
boolean reloading = false;
#Override
public void onWindowClosing(ClosingEvent event) {
if (!reloading) {
String userAgent = Window.Navigator.getUserAgent();
if (userAgent.contains("MSIE")) {
if (!Window.confirm("Do you really want to exit?")) {
reloading = true;
Window.Location.reload(); // For IE
}
}
else {
event.setMessage("My App"); // For other browser
}
}
}
});
}
I found a way to make GWT ignore the back-button: Just add historyitem x if no historyitem was set and do nothing on x.
set a historyitem on startup
History.newItem("x")
in the ValueChangeHandler of History add the following:
String historyToken = event.getValue();
if (!historyToken.equals("x"))
History.newItem("x");
Window.addWindowClosingHandler(new ClosingHandler() {
#Override
public void onWindowClosing(ClosingEvent event) {
event.setMessage("My program");
}
});
That is not a fool proof solution. In fire fox I can press the back button and the onWindowClosing method is never invoked. The reason is that I have used History.newItem() and since history exists the back button or backspace buttons simply navigate through the browser history.
So....fix that :)
Put this in your index.html file:
window.open('html page(For example trial.html)', 'Name of the desired site', width='whatever you want',height='whatever you want', centerscreen=yes, menubar=no,toolbar=no,location=no,
personalbar=no, directories=no,status=no, resizable=yes, dependent=no, titlebar=no,dialog=no');
I have 2 inputs. When I press a button(AjaxFallbackButton), those inputs are saved into database.
If one of the input is greater than 10, when I press the button, I want to show a modal panel, for asking the user if is the sure about his option. But the modal component is not appearing. Any thoughts?
#Override
public void onSubmit(AjaxRequestTarget target) {
if (input < 10) { //save to database
} else {
AskingDialogPanel panel = new AskingDialogPanel("content",
new ResourceModel("asking.title"),
new ResourceModel("asking.message")) {
#Override
public void onOkClick(AjaxRequestTarget target) {
super.onOkClick(target);
//save to database
modalWindow.close(target);
}
#Override
public void onCancelClick(AjaxRequestTarget target) {
super.onCancelClick(target);
modalWindow.close(target);
}
};
panel.setOutputMarkupId(true);
target.addComponent(panel);
modalWindow.setContent(panel);
modalWindow.show(target);
}
Have a look at the documentation for the AjaxRequestTarget.
A component whose markup needs to be
updated should be added to this target
via
AjaxRequestTarget#addComponent(Component)
method. Its body will be rendered and
added to the envelope when the target
is processed, and refreshed on the
client side when the ajax response is
received.
I'm not sure if I remember this correctly (I've had trouble implementing the correct refresh behavior previously), but I believe you could only addComponent components that were previously added to the page, but not rendered / invisible. These will than be updated and/or their visibility re-evaluated.
I could be wrong however.. Does the above work if you substitute a normal Label for the AskingDialogPanel? (Just to verify I'm talking out the wrong end ;))
I am writing a Java Application for Data Entry using Eclipse and SWT. Naturally it has a great many Text objects.
What I would like to happen is that when user enters something into one field focus automatically changes to the next field.
Thanks in advance
final Text textBox = new Text(shell, SWT.NONE);
textBox.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (x.getText().length() == 1); {
x.traverse(SWT.TRAVERSE_TAB_NEXT);
}
}
});
final Text textBox = new Text(shell, SWT.NONE);
textBox.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent arg0) {
if (textBox.getText().equals("") == false) {
textBox.traverse(SWT.TRAVERSE_TAB_NEXT);
}
}});
You may also want to have a look at the VerifyListener interface. See this interesting blog post for a caveat though: http://eclipsenuggets.blogspot.com/2008/10/eclipse-bug-patterns-selfish-validation.html
I assume you want to change the focus after the field has been filled. I suggest using a DocumentListener (or whatever SWT calls it) to be notified of changes to the field's content: if it has the right number of characters, jump to the next field.