Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Java question regarding Anonymous Class-Widget creation and Handler registration

    Hi all,

    I'm using a lot of anonymous class code like this in order to keep my code more readable (Java 1.6, SmartGWT 2.5, Eclipse Indigo)
    Code:
    		final DateChooser dateChooser = new DateChooser() {
    			{
    				Calendar today = Calendar.getInstance();
    
    				setStartYear(today.get(Calendar.YEAR) - 1);
    				setEndYear(today.get(Calendar.YEAR) + 1);
    				setFirstDayOfWeek(1);
    				setWidth(100);
    				setTodayButtonTitle("Heute");
    			}
    		};
    I'd like to do the same with handlers, eg this handler:
    Code:
    dateChooser.addDataChangedHandler(new DataChangedHandler() {
    			@Override
    			public void onDataChanged(DataChangedEvent event) {
    				checkWholeDate(dateChooser, timeItem, blurbItem);
    			}
    		});
    where checkWholeDate a method and timeItem, blurbItem other final widgets.

    I can't do it like this:
    Code:
    		final DateChooser dateChooser = new DateChooser() {
    			{
    				Calendar today = Calendar.getInstance();
    
    				setStartYear(today.get(Calendar.YEAR) - 1);
    				setEndYear(today.get(Calendar.YEAR) + 1);
    				setFirstDayOfWeek(1);
    				setWidth(100);
    				setTodayButtonTitle("Heute");
    				addDataChangedHandler(new DataChangedHandler() {
    					@Override
    					public void onDataChanged(DataChangedEvent event) {
    						checkWholeDate(dateChooser, timeItem, blurbItem);
    					}
    				});
    			}
    		};
    because the "dateChooser" method parameter is not available in the inner handler anonymous class.

    Do you have an idea how I could also move the handler to the widget anonymous class?

    Thanks,
    Blama
Working...
X