@Override public void setTabs(CourseFinderTab... tabs) { iTabs = tabs; if (iTabs.length == 1) { if (iTabs[0].asWidget() instanceof VerticalPanel) { VerticalPanel vp = (VerticalPanel) iTabs[0].asWidget(); while (vp.getWidgetCount() > 0) { Widget w = vp.getWidget(0); vp.remove(w); iDialogPanel.add(w); } } else { iDialogPanel.add(iTabs[0].asWidget()); } } else { iTabPanel = new UniTimeTabPanel(); int tabIndex = 0; for (CourseFinderTab tab : iTabs) { iTabPanel.add(tab.asWidget(), tab.getName(), true); Character ch = UniTimeHeaderPanel.guessAccessKey(tab.getName()); if (ch != null) iTabAccessKeys.put(ch, tabIndex); tabIndex++; } iTabPanel.selectTab(0); iDialogPanel.add(iTabPanel); } for (final CourseFinderTab tab : iTabs) { tab.addValueChangeHandler( new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { if (event.getSource().equals(tab)) selectTab(tab); else tab.setValue(event.getValue()); iFilter.setValue(event.getValue()); } }); tab.addSelectionHandler( new SelectionHandler<String>() { @Override public void onSelection(SelectionEvent<String> event) { iFilter.setValue(event.getSelectedItem()); hide(); SelectionEvent.fire(CourseFinderDialog.this, getValue()); } }); tab.addResponseHandler( new ResponseHandler() { @Override public void onResponse(ResponseEvent event) { if (event.isValid()) { CourseFinderTab selected = getSelectedTab(); if (selected != null && selected.isCourseSelection() && selected.getValue() != null) return; selectTab(tab); } } }); } }
@Override public void findCourse() { iFilter.setAriaLabel( isAllowFreeTime() ? ARIA.courseFinderFilterAllowsFreeTime() : ARIA.courseFinderFilter()); AriaStatus.getInstance().setText(ARIA.courseFinderDialogOpened()); if (iTabs != null) for (CourseFinderTab tab : iTabs) tab.changeTip(); center(); RootPanel.getBodyElement().getStyle().setOverflow(Overflow.HIDDEN); Scheduler.get() .scheduleDeferred( new ScheduledCommand() { public void execute() { iFilter.setFocus(true); } }); }
protected void selectTab(CourseFinderTab tab) { if (iTabs != null && iTabs.length > 1) { for (int i = 0; i < iTabs.length; i++) { if (tab.equals(iTabs[i])) { iTabPanel.selectTab(i); break; } } } }
protected boolean isAllowFreeTime() { if (iTabs == null) return false; for (CourseFinderTab tab : iTabs) if (!tab.isCourseSelection()) return true; return false; }