i working on project need use swt datespinner on rap application webpage. brought entire datespinner api project , have made changes accommodate in application. trying dispose calendar widget when user clicks anywhere on page outside bounds of calendar dropdown.
to accomplish tried adding focus listener widget , actual date spinner onfocuslost() method never executed whenever datespinner or calendar composite lose focus. tried add mouse event listener try dispose widget if mouse down event occurs outside calendar composite bounds doesn't executed either. showcalendar() method shown:
private void showcalendar() { if (calendardropdown != null && !calendardropdown.isdisposed()) { calendardropdown.dispose(); } calendardropdown = new dropdown(this); calendardropdown.setusingrelativecontrolwidth(false); composite composite = calendardropdown.getdropdown(); composite.setlayout(new filllayout()); composite.setdata(calendartoggle); calendar c = calendar.getinstance(); date date = this.getdate(); // current date in control if (date != null) { c.settime(this.getdate()); } calendarcomposite calendarwidget = new calendarcomposite(composite, c); calendarwidget.setnoneenabled(this.allownulldate); calendarwidget.setminimumdate(datetocalendar(getminimum())); calendarwidget.setmaximumdate(datetocalendar(getmaximum())); // background match calendar composite.setbackground(calendarwidget.getbackground()); calendardropdown.show(true, composite.computesize(swt.default, swt.default)); text.addfocuslistener(new focuslistener() { @override public void focuslost(focusevent event) { dispose(); } @override public void focusgained(focusevent event) { // todo auto-generated method stub } }); calendarwidget.addmaincalendarlistener(new calendarlisteneradapter() { @override public void datechanged(calendar date) { dosetdate(date != null ? date.gettime() : null, false, true); } @override public void popupclosed() { calendardropdown.dispose(); } }); } and show method of dropdown
if ((autohide && !dropdownshell.isvisible())){ dropdownshell.addmouselistener(new mouselistener() { @override public void mouseup(mouseevent e) { // todo auto-generated method stub } @override public void mousedown(mouseevent e) { if (!isinside(e.x, e.y, dropdownshell.getdisplay().getbounds())) { dispose(); } } @override public void mousedoubleclick(mouseevent e) { // todo auto-generated method stub } }); please let me know can make calendarwidget dispose on losing focus.
i think if widget focus in shell focused widget (your text), may not focuslost event because each shell can have it's own focused widget. happens shell text in gets deactivated, can notified using shelllistener.
Comments
Post a Comment