List of usage examples for com.google.gwt.event.dom.client FocusHandler FocusHandler
FocusHandler
From source file:org.unitime.timetable.gwt.client.aria.AriaButton.java
License:Apache License
public AriaButton(ImageResource image, String html) { super(html);/* ww w . ja v a 2 s.c o m*/ super.setHTML("<img src='" + image.getSafeUri().asString() + "' class='gwt-Image'></img><span class='gwt-Label' style='padding-left: 5px;'>" + html + "</span>"); addStyleName("unitime-ImageButton"); setAriaLabel(UniTimeHeaderPanel.stripAccessKey(html)); Character accessKey = UniTimeHeaderPanel.guessAccessKey(html); if (accessKey != null) setAccessKey(accessKey); ToolBox.setMinWidth(getElement().getStyle(), "75px"); addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { iFocused = true; } }); addBlurHandler(new BlurHandler() { @Override public void onBlur(BlurEvent event) { iFocused = false; } }); }
From source file:org.unitime.timetable.gwt.client.aria.AriaButton.java
License:Apache License
public AriaButton(String html, ImageResource image) { super(html);/* w ww. j a va 2 s .c o m*/ super.setHTML("<span class='gwt-Label' style='padding-right: 5px;'>" + html + "</span><img src='" + image.getSafeUri().asString() + "' class='gwt-Image'></img>"); addStyleName("unitime-ImageButton"); setAriaLabel(UniTimeHeaderPanel.stripAccessKey(html)); Character accessKey = UniTimeHeaderPanel.guessAccessKey(html); if (accessKey != null) setAccessKey(accessKey); ToolBox.setMinWidth(getElement().getStyle(), "75px"); addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { iFocused = true; } }); addBlurHandler(new BlurHandler() { @Override public void onBlur(BlurEvent event) { iFocused = false; } }); }
From source file:org.unitime.timetable.gwt.client.events.AcademicSessionSelectionBox.java
License:Apache License
public AcademicSessionSelectionBox(String term, String source) { super(false); setHint(MESSAGES.waitLoadingSessions()); RPC.execute(new ListAcademicSessions(term, source), new AsyncCallback<GwtRpcResponseList<AcademicSession>>() { @Override//from www. j a v a 2 s. c o m public void onFailure(Throwable caught) { setErrorHint(caught.getMessage()); ToolBox.checkAccess(caught); onInitializationFailure(caught); } @Override public void onSuccess(GwtRpcResponseList<AcademicSession> result) { clearHint(); iAllSessions = result; setValues(result); onInitializationSuccess(result); } }); addValueChangeHandler(new ValueChangeHandler<Interval>() { @Override public void onValueChange(ValueChangeEvent<Interval> event) { fireAcademicSessionChanged(); setAriaLabel(ARIA.academicSession(toAriaString())); } }); addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { setAriaLabel(ARIA.academicSession(toAriaString())); } }); }
From source file:org.unitime.timetable.gwt.client.events.AddMeetingsDialog.java
License:Apache License
public AddMeetingsDialog(AcademicSessionProvider session, EventPropertiesProvider propeties, AsyncCallback<List<MeetingInterface>> callback) { super(true, true); setAnimationEnabled(false);/*from w ww .j a va 2 s . co m*/ iCallback = callback; iSession = session; iProperties = propeties; setText(MESSAGES.dialogAddMeetings()); setEscapeToHide(true); iDatesForm = new SimpleForm(); iDatesHeader = new UniTimeHeaderPanel(); iDatesHeader.setRotateFocus(true); iDatesHeader.addButton("next", MESSAGES.buttonNext(), 75, new ClickHandler() { @Override public void onClick(ClickEvent event) { if (iDates.getSelectedDaysCount() == 0) { iDatesHeader.setErrorMessage(MESSAGES.errorNoDateSelected()); AriaStatus.getInstance().setText(MESSAGES.errorNoDateSelected()); return; } else if (getStartSlot() == null) { iDatesHeader.setErrorMessage(MESSAGES.errorNoStartTime()); AriaStatus.getInstance().setText(MESSAGES.errorNoStartTime()); return; } else if (getEndSlot() == null) { iDatesHeader.setErrorMessage(MESSAGES.errorNoEndTime()); AriaStatus.getInstance().setText(MESSAGES.errorNoEndTime()); return; } LoadingWidget.getInstance().show(MESSAGES.waitCheckingRoomAvailability()); iRooms.getElements(new AsyncCallback<List<Entity>>() { @Override public void onFailure(Throwable caught) { LoadingWidget.getInstance().hide(); iDatesHeader.setErrorMessage(caught.getMessage()); AriaStatus.getInstance().setText(caught.getMessage()); } @Override public void onSuccess(List<Entity> result) { iMatchingRooms = result; if (result == null || result.isEmpty()) { LoadingWidget.getInstance().hide(); iDatesHeader.setErrorMessage(MESSAGES.errorNoMatchingRooms()); AriaStatus.getInstance().setText(MESSAGES.errorNoMatchingRooms()); } else if (iDates.getSelectedDaysCount() > 0) { iDatesHeader.clearMessage(); if (iProperties != null && iProperties.isTooEarly(getStartSlot(), getEndSlot())) { iAvailabilityHeader.setWarningMessage( MESSAGES.warnMeetingTooEarly(TimeUtils.slot2time(getStartSlot()) + " - " + TimeUtils.slot2time(getEndSlot()))); AriaStatus.getInstance() .setText(MESSAGES.warnMeetingTooEarly(TimeUtils.slot2aria(getStartSlot()) + " - " + TimeUtils.slot2aria(getEndSlot()))); } else { iAvailabilityHeader.clearMessage(); } RPC.execute( EventRoomAvailabilityRpcRequest.checkAvailability(getStartSlot(), getEndSlot(), getDates(), getRooms(), iEventId, iSession.getAcademicSessionId()), new AsyncCallback<EventRoomAvailabilityRpcResponse>() { @Override public void onFailure(Throwable caught) { LoadingWidget.getInstance().hide(); iDatesHeader.setErrorMessage(caught.getMessage()); AriaStatus.getInstance().setText(caught.getMessage()); } @Override public void onSuccess(EventRoomAvailabilityRpcResponse result) { LoadingWidget.getInstance().hide(); iResponse = result; populate(0, EventCookie.getInstance().getRoomsSortBy()); setWidget(iAvailabilityForm); recenter(); iText.setFocus(true); } }); } } }); } }); iDatesForm.addHeaderRow(iDatesHeader); SimpleForm form = new SimpleForm(); form.removeStyleName("unitime-NotPrintableBottomLine"); iDates = new SessionDatesSelector(session); form.addRow(MESSAGES.propDates(), iDates); iTimes = new StartEndTimeSelector(); form.addRow(MESSAGES.propTimes(), iTimes); iRooms = new RoomFilterBox(session); form.addRow(MESSAGES.propLocations(), iRooms); iScrollDates = new ScrollPanel(form); iScrollDates.setStyleName("unitime-VerticalScrollPanel"); iDatesForm.addRow(iScrollDates); iDatesForm.addBottomRow(iDatesHeader.clonePanel()); iAvailabilityForm = new SimpleForm(); iAvailabilityHeader = new UniTimeHeaderPanel(); iAvailabilityHeader.setRotateFocus(true); iAvailabilityHeader.addButton("dates", MESSAGES.buttonPrevious(), 75, new ClickHandler() { @Override public void onClick(ClickEvent event) { setWidget(iDatesForm); recenter(); iResponse = null; Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { iDates.setFocus(true); } }); } }); iAvailabilityHeader.addButton("prev", MESSAGES.buttonLeft(), new ClickHandler() { @Override public void onClick(ClickEvent event) { populate(iIndex - iStep, null); recenter(); } }); iAvailabilityHeader.addButton("next", MESSAGES.buttonRight(), new ClickHandler() { @Override public void onClick(ClickEvent event) { populate(iIndex + iStep, null); recenter(); } }); iAvailabilityHeader.addButton("more", MESSAGES.buttonMoreOperations(), 75, new ClickHandler() { @Override public void onClick(ClickEvent event) { final PopupPanel popup = new PopupPanel(true); MenuBar menu = new MenuBar(true); for (final SortRoomsBy sortBy : SortRoomsBy.values()) { if (sortBy == SortRoomsBy.DISTANCE && !iRooms.hasChip(new Chip("flag", "Nearby"))) continue; MenuItem item = new MenuItem( (sortBy.ordinal() == EventCookie.getInstance().getRoomsSortBy() ? "↑ " : (sortBy.ordinal() + SortRoomsBy.values().length == EventCookie.getInstance() .getRoomsSortBy()) ? "↓ " : "") + MESSAGES.opSortBy(getSortRoomsByName(sortBy)), true, new Command() { @Override public void execute() { popup.hide(); if (sortBy.ordinal() == EventCookie.getInstance().getRoomsSortBy()) { EventCookie.getInstance() .setSortRoomsBy(SortRoomsBy.values().length + sortBy.ordinal()); } else { EventCookie.getInstance().setSortRoomsBy(sortBy.ordinal()); } populate(0, EventCookie.getInstance().getRoomsSortBy()); recenter(); } }); item.getElement().getStyle().setCursor(Cursor.POINTER); menu.addItem(item); } menu.addSeparator(); MenuItem swapItem = new MenuItem(MESSAGES.opSwapAxes(), true, new Command() { @Override public void execute() { popup.hide(); EventCookie.getInstance() .setRoomsHorizontal(!EventCookie.getInstance().areRoomsHorizontal()); populate(0, EventCookie.getInstance().getRoomsSortBy()); recenter(); } }); swapItem.getElement().getStyle().setCursor(Cursor.POINTER); menu.addItem(swapItem); MenuItem expandOrCollapseAll = new MenuItem( EventCookie.getInstance().isExpandRoomConflicts() ? MESSAGES.opCollapseAll() : MESSAGES.opExpandAll(), true, new Command() { @Override public void execute() { popup.hide(); EventCookie.getInstance() .setExpandRoomConflicts(!EventCookie.getInstance().isExpandRoomConflicts()); populate(iIndex, EventCookie.getInstance().getRoomsSortBy()); recenter(); } }); expandOrCollapseAll.getElement().getStyle().setCursor(Cursor.POINTER); menu.addItem(expandOrCollapseAll); menu.setVisible(true); menu.setFocusOnHoverEnabled(true); popup.add(menu); popup.showRelativeTo((UIObject) event.getSource()); if (event.getSource() instanceof Focusable) { final Focusable focusable = (Focusable) event.getSource(); popup.addCloseHandler(new CloseHandler<PopupPanel>() { @Override public void onClose(CloseEvent<PopupPanel> event) { focusable.setFocus(true); } }); } menu.focus(); } }); iAvailabilityHeader.addButton("select", MESSAGES.buttonSelect(), 75, new ClickHandler() { @Override public void onClick(ClickEvent event) { hide(); List<MeetingInterface> meetings = new ArrayList<MeetingInterface>(); for (Integer date : getDates()) { for (Entity room : getRooms()) { if (isSelected(date, room)) { MeetingInterface meeting = new MeetingInterface(); meeting.setDayOfYear(date); meeting.setStartSlot(getStartSlot()); meeting.setEndSlot(getEndSlot()); meeting.setStartOffset(0); meeting.setEndOffset(-Integer.parseInt(room.getProperty("breakTime", "0"))); meeting.setLocation(new ResourceInterface(room)); meeting.setConflicts(getConflicts(date, room)); meetings.add(meeting); } } } iCallback.onSuccess(meetings); } }); iAvailabilityForm.addHeaderRow(iAvailabilityHeader); iRoomAvailability = new P("unitime-MeetingSelection"); iText = new AriaTextBox(); iText.setStyleName("text"); iScrollRooms = new ScrollPanel(iRoomAvailability); iAvailabilityForm.addRow(iScrollRooms); iAvailabilityForm.addNotPrintableBottomRow(iAvailabilityHeader.clonePanel()); setWidget(iDatesForm); addCloseHandler(new CloseHandler<PopupPanel>() { @Override public void onClose(CloseEvent<PopupPanel> event) { RootPanel.getBodyElement().getStyle().setOverflow(Overflow.AUTO); } }); iText.addKeyUpHandler(new KeyUpHandler() { @Override public void onKeyUp(KeyUpEvent event) { if (iResponse == null) return; if (EventCookie.getInstance().areRoomsHorizontal()) { int min = iIndex, max = Math.min(iIndex + iStep, getRooms().size()) - 1; switch (event.getNativeKeyCode()) { case KeyCodes.KEY_DOWN: if (iHoverDate != null && iHoverLoc != null) { iPanels.get(iHoverDate + ":" + iHoverLoc.getUniqueId()).removeStyleName("hover"); int idx = Math.min(Math.max(0, getDates().indexOf(iHoverDate) + 1), getDates().size() - 1); iHoverDate = getDates().get(idx); iPanels.get(iHoverDate + ":" + iHoverLoc.getUniqueId()).addStyleName("hover"); } else { iHoverDate = getDates().get(0); iHoverLoc = getRooms().get(min); iPanels.get(iHoverDate + ":" + iHoverLoc.getUniqueId()).addStyleName("hover"); } iScrollRooms.ensureVisible(iPanels.get(iHoverDate + ":" + iHoverLoc.getUniqueId())); break; case KeyCodes.KEY_UP: if (iHoverDate != null && iHoverLoc != null) { iPanels.get(iHoverDate + ":" + iHoverLoc.getUniqueId()).removeStyleName("hover"); int idx = Math.min(Math.max(0, getDates().indexOf(iHoverDate) - 1), getDates().size() - 1); iHoverDate = getDates().get(idx); iPanels.get(iHoverDate + ":" + iHoverLoc.getUniqueId()).addStyleName("hover"); } else { iHoverDate = getDates().get(getDates().size() - 1); iHoverLoc = getRooms().get(min); iPanels.get(iHoverDate + ":" + iHoverLoc.getUniqueId()).addStyleName("hover"); } iScrollDates.ensureVisible(iPanels.get(iHoverDate + ":" + iHoverLoc.getUniqueId())); break; case KeyCodes.KEY_RIGHT: if (iHoverDate != null && iHoverLoc != null) { iPanels.get(iHoverDate + ":" + iHoverLoc.getUniqueId()).removeStyleName("hover"); int idx = Math.min(Math.max(min, getRooms().indexOf(iHoverLoc) + 1), max); iHoverLoc = getRooms().get(idx); iPanels.get(iHoverDate + ":" + iHoverLoc.getUniqueId()).addStyleName("hover"); } else { iHoverDate = getDates().get(0); iHoverLoc = getRooms().get(min); iPanels.get(iHoverDate + ":" + iHoverLoc.getUniqueId()).addStyleName("hover"); } break; case KeyCodes.KEY_LEFT: if (iHoverDate != null && iHoverLoc != null) { iPanels.get(iHoverDate + ":" + iHoverLoc.getUniqueId()).removeStyleName("hover"); int idx = Math.min(Math.max(min, getRooms().indexOf(iHoverLoc) - 1), max); iHoverLoc = getRooms().get(idx); iPanels.get(iHoverDate + ":" + iHoverLoc.getUniqueId()).addStyleName("hover"); } else { iHoverDate = getDates().get(0); iHoverLoc = getRooms().get(max); iPanels.get(iHoverDate + ":" + iHoverLoc.getUniqueId()).addStyleName("hover"); } break; case KeyCodes.KEY_PAGEDOWN: if (iIndex + iStep < getRooms().size()) populate(iIndex + iStep, null); break; case KeyCodes.KEY_PAGEUP: if (iIndex > 0) populate(iIndex - iStep, null); break; case 32: case KeyCodes.KEY_ENTER: if (iHoverDate != null && iHoverLoc != null) { setSelected(iHoverDate, iHoverLoc, !isSelected(iHoverDate, iHoverLoc)); } break; } } else { int min = iIndex, max = Math.min(iIndex + iStep, getDates().size()) - 1; switch (event.getNativeKeyCode()) { case KeyCodes.KEY_RIGHT: if (iHoverDate != null && iHoverLoc != null) { iPanels.get(iHoverDate + ":" + iHoverLoc.getUniqueId()).removeStyleName("hover"); int idx = Math.min(Math.max(min, getDates().indexOf(iHoverDate) + 1), max); iHoverDate = getDates().get(idx); iPanels.get(iHoverDate + ":" + iHoverLoc.getUniqueId()).addStyleName("hover"); } else { iHoverDate = getDates().get(min); iHoverLoc = getRooms().get(0); iPanels.get(iHoverDate + ":" + iHoverLoc.getUniqueId()).addStyleName("hover"); } iScrollRooms.ensureVisible(iPanels.get(iHoverDate + ":" + iHoverLoc.getUniqueId())); break; case KeyCodes.KEY_LEFT: if (iHoverDate != null && iHoverLoc != null) { iPanels.get(iHoverDate + ":" + iHoverLoc.getUniqueId()).removeStyleName("hover"); int idx = Math.min(Math.max(min, getDates().indexOf(iHoverDate) - 1), max); iHoverDate = getDates().get(idx); iPanels.get(iHoverDate + ":" + iHoverLoc.getUniqueId()).addStyleName("hover"); } else { iHoverDate = getDates().get(max); iHoverLoc = getRooms().get(0); iPanels.get(iHoverDate + ":" + iHoverLoc.getUniqueId()).addStyleName("hover"); } iScrollDates.ensureVisible(iPanels.get(iHoverDate + ":" + iHoverLoc.getUniqueId())); break; case KeyCodes.KEY_DOWN: if (iHoverDate != null && iHoverLoc != null) { iPanels.get(iHoverDate + ":" + iHoverLoc.getUniqueId()).removeStyleName("hover"); int idx = Math.min(Math.max(0, getRooms().indexOf(iHoverLoc) + 1), getRooms().size() - 1); iHoverLoc = getRooms().get(idx); iPanels.get(iHoverDate + ":" + iHoverLoc.getUniqueId()).addStyleName("hover"); } else { iHoverDate = getDates().get(min); iHoverLoc = getRooms().get(0); iPanels.get(iHoverDate + ":" + iHoverLoc.getUniqueId()).addStyleName("hover"); } break; case KeyCodes.KEY_UP: if (iHoverDate != null && iHoverLoc != null) { iPanels.get(iHoverDate + ":" + iHoverLoc.getUniqueId()).removeStyleName("hover"); int idx = Math.min(Math.max(0, getRooms().indexOf(iHoverLoc) - 1), getRooms().size() - 1); iHoverLoc = getRooms().get(idx); iPanels.get(iHoverDate + ":" + iHoverLoc.getUniqueId()).addStyleName("hover"); } else { iHoverDate = getDates().get(min); iHoverLoc = getRooms().get(getRooms().size() - 1); iPanels.get(iHoverDate + ":" + iHoverLoc.getUniqueId()).addStyleName("hover"); } break; case KeyCodes.KEY_PAGEDOWN: if (iIndex + iStep < getDates().size()) populate(iIndex + iStep, null); break; case KeyCodes.KEY_PAGEUP: if (iIndex > 0) populate(iIndex - iStep, null); break; case 32: case KeyCodes.KEY_ENTER: if (iHoverDate != null && iHoverLoc != null) { setSelected(iHoverDate, iHoverLoc, !isSelected(iHoverDate, iHoverLoc)); } break; } } iText.setAriaLabel(toAriaLabel(true, true, false)); } }); iText.addKeyDownHandler(new KeyDownHandler() { @Override public void onKeyDown(KeyDownEvent event) { switch (event.getNativeEvent().getKeyCode()) { case KeyCodes.KEY_RIGHT: case KeyCodes.KEY_LEFT: case KeyCodes.KEY_UP: case KeyCodes.KEY_DOWN: case KeyCodes.KEY_PAGEDOWN: case KeyCodes.KEY_PAGEUP: event.preventDefault(); } } }); iText.addKeyPressHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { switch (event.getNativeEvent().getKeyCode()) { case 32: if (iText.getValue().isEmpty()) event.preventDefault(); return; case KeyCodes.KEY_ENTER: event.preventDefault(); return; } } }); iText.addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { if (iHoverDate != null && iHoverLoc != null) iPanels.get(iHoverDate + ":" + iHoverLoc.getUniqueId()).addStyleName("hover"); iText.setAriaLabel(toAriaLabel(true, true, false)); } }); iText.addBlurHandler(new BlurHandler() { @Override public void onBlur(BlurEvent event) { if (iHoverDate != null && iHoverLoc != null) { iPanels.get(iHoverDate + ":" + iHoverLoc.getUniqueId()).removeStyleName("hover"); } } }); }
From source file:org.unitime.timetable.gwt.client.events.EventFilterBox.java
License:Apache License
public EventFilterBox(AcademicSessionProvider session) { super(session); addFilter(new FilterBox.StaticSimpleFilter("type", MESSAGES.tagEventType()) { @Override/*from w w w . jav a 2 s. co m*/ public void validate(String text, AsyncCallback<Chip> callback) { String translatedValue = null; if ("class".equalsIgnoreCase(text)) translatedValue = CONSTANTS.eventTypeShort()[0]; else if ("final exam".equalsIgnoreCase(text)) translatedValue = CONSTANTS.eventTypeShort()[1]; else if ("midterm exam".equalsIgnoreCase(text)) translatedValue = CONSTANTS.eventTypeShort()[2]; else if ("course".equalsIgnoreCase(text)) translatedValue = CONSTANTS.eventTypeShort()[3]; else if ("special".equalsIgnoreCase(text)) translatedValue = CONSTANTS.eventTypeShort()[4]; else if ("not available".equalsIgnoreCase(text)) translatedValue = CONSTANTS.eventTypeShort()[5]; callback.onSuccess(new Chip(getCommand(), text).withTranslatedCommand(getLabel()) .withTranslatedValue(translatedValue)); } }); iSponsors = new ListBox(); iSponsors.setMultipleSelect(true); iSponsors.setWidth("100%"); iSponsors.setVisibleItemCount(3); addFilter(new FilterBox.CustomFilter("sponsor", MESSAGES.tagSponsor(), iSponsors) { @Override public void getSuggestions(List<Chip> chips, String text, AsyncCallback<Collection<Suggestion>> callback) { if (text.isEmpty()) { callback.onSuccess(null); } else { List<Suggestion> suggestions = new ArrayList<Suggestion>(); for (int i = 0; i < iSponsors.getItemCount(); i++) { Chip chip = new Chip("sponsor", iSponsors.getValue(i)) .withTranslatedCommand(MESSAGES.tagSponsor()); String name = iSponsors.getItemText(i); if (iSponsors.getValue(i).toLowerCase().startsWith(text.toLowerCase())) { suggestions.add(new Suggestion(name, chip)); } else if (text.length() > 2 && name.toLowerCase().contains(" " + text.toLowerCase())) { suggestions.add(new Suggestion(name, chip)); } } callback.onSuccess(suggestions); } } @Override public boolean isVisible() { return iSponsors.getItemCount() > 0; } }); iSponsors.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent event) { boolean changed = false; for (int i = 0; i < iSponsors.getItemCount(); i++) { Chip chip = new Chip("sponsor", iSponsors.getValue(i)) .withTranslatedCommand(MESSAGES.tagSponsor()); if (iSponsors.isItemSelected(i)) { if (!hasChip(chip)) { addChip(chip, false); changed = true; } } else { if (hasChip(chip)) { removeChip(chip, false); changed = true; } } } if (changed) fireValueChangeEvent(); } }); FilterBox.StaticSimpleFilter mode = new FilterBox.StaticSimpleFilter("mode", MESSAGES.tagEventMode()) { @Override public void validate(String text, AsyncCallback<Chip> callback) { String translatedValue = null; if ("all".equalsIgnoreCase(text)) translatedValue = CONSTANTS.eventModeAbbv()[0]; else if ("my".equalsIgnoreCase(text)) translatedValue = CONSTANTS.eventModeAbbv()[1]; else if ("approved".equalsIgnoreCase(text)) translatedValue = CONSTANTS.eventModeAbbv()[2]; else if ("unapproved".equalsIgnoreCase(text)) translatedValue = CONSTANTS.eventModeAbbv()[3]; else if ("awaiting".equalsIgnoreCase(text)) translatedValue = CONSTANTS.eventModeAbbv()[4]; else if ("conflicting".equalsIgnoreCase(text)) translatedValue = CONSTANTS.eventModeAbbv()[5]; else if ("my awaiting".equalsIgnoreCase(text)) translatedValue = CONSTANTS.eventModeAbbv()[6]; else if ("cancelled".equalsIgnoreCase(text)) translatedValue = CONSTANTS.eventModeAbbv()[7]; else if ("expiring".equalsIgnoreCase(text)) translatedValue = CONSTANTS.eventModeAbbv()[8]; callback.onSuccess(new Chip(getCommand(), text).withTranslatedCommand(getLabel()) .withTranslatedValue(translatedValue)); } }; mode.setMultipleSelection(false); addFilter(mode); addFilter(new FilterBox.StaticSimpleFilter("role", MESSAGES.tagEventRole()) { @Override public void getPopupWidget(final FilterBox box, final AsyncCallback<Widget> callback) { callback.onSuccess(null); } @Override public void validate(String text, AsyncCallback<Chip> callback) { String translatedValue = null; if ("all".equalsIgnoreCase(text)) translatedValue = CONSTANTS.eventRole()[0]; else if ("student".equalsIgnoreCase(text)) translatedValue = CONSTANTS.eventRole()[1]; else if ("instructor".equalsIgnoreCase(text)) translatedValue = CONSTANTS.eventRole()[2]; else if ("coordinator".equalsIgnoreCase(text)) translatedValue = CONSTANTS.eventRole()[3]; else if ("contact".equalsIgnoreCase(text)) translatedValue = CONSTANTS.eventRole()[4]; callback.onSuccess(new Chip(getCommand(), text).withTranslatedCommand(getLabel()) .withTranslatedValue(translatedValue)); } }); Label reqLab = new Label(MESSAGES.propRequestedBy()); iRequested = new AriaSuggestBox(new RequestedByOracle()); iRequested.setStyleName("unitime-TextArea"); iRequested.setWidth("200px"); final CheckBox conflicts = new CheckBox(MESSAGES.checkDisplayConflicts()); conflicts.getElement().getStyle().setMarginLeft(10, Unit.PX); final CheckBox sessions = new CheckBox(MESSAGES.checkSpanMultipleSessions()); sessions.getElement().getStyle().setMarginLeft(10, Unit.PX); iOther = new FilterBox.CustomFilter("other", MESSAGES.tagOther(), reqLab, iRequested, conflicts, sessions) { @Override public void getSuggestions(final List<Chip> chips, final String text, AsyncCallback<Collection<FilterBox.Suggestion>> callback) { if (text.isEmpty()) { callback.onSuccess(null); } else { List<FilterBox.Suggestion> suggestions = new ArrayList<FilterBox.Suggestion>(); if ("conflicts".startsWith(text.toLowerCase()) || MESSAGES.checkDisplayConflicts().toLowerCase().startsWith(text.toLowerCase())) { suggestions.add(new Suggestion(MESSAGES.checkDisplayConflicts(), new Chip("flag", "Conflicts").withTranslatedCommand(MESSAGES.tagEventFlag()) .withTranslatedValue(MESSAGES.attrFlagShowConflicts()))); } if ("sessinons".startsWith(text.toLowerCase()) || MESSAGES.checkSpanMultipleSessions().toLowerCase().startsWith(text.toLowerCase())) { suggestions.add(new Suggestion(MESSAGES.checkSpanMultipleSessions(), new Chip("flag", "All Sessions").withTranslatedCommand(MESSAGES.tagEventFlag()) .withTranslatedValue(MESSAGES.attrFlagAllSessions()))); } callback.onSuccess(suggestions); } } }; addFilter(iOther); addFilter(new FilterBox.StaticSimpleFilter("requested", MESSAGES.tagRequested())); addFilter(new FilterBox.StaticSimpleFilter("flag", MESSAGES.tagEventFlag()) { @Override public void validate(String text, AsyncCallback<Chip> callback) { String translatedValue = null; if ("conflicts".equalsIgnoreCase(text)) translatedValue = MESSAGES.attrFlagShowConflicts(); else if ("all sessions".equalsIgnoreCase(text)) translatedValue = MESSAGES.attrFlagAllSessions(); callback.onSuccess(new Chip(getCommand(), text).withTranslatedCommand(getLabel()) .withTranslatedValue(translatedValue)); } }); iRequested.getValueBox().addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent event) { requestedChanged(true); } }); iRequested.getValueBox().addKeyPressHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { requestedChanged(false); } }); } }); iRequested.getValueBox().addKeyUpHandler(new KeyUpHandler() { @Override public void onKeyUp(KeyUpEvent event) { if (event.getNativeKeyCode() == KeyCodes.KEY_BACKSPACE) Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { requestedChanged(false); } }); } }); iRequested.getValueBox().addBlurHandler(new BlurHandler() { @Override public void onBlur(BlurEvent event) { requestedChanged(true); } }); iRequested.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() { @Override public void onSelection(SelectionEvent<com.google.gwt.user.client.ui.SuggestOracle.Suggestion> event) { requestedChanged(true); } }); conflicts.addValueChangeHandler(new ValueChangeHandler<Boolean>() { @Override public void onValueChange(ValueChangeEvent<Boolean> event) { Chip chip = new Chip("flag", "Conflicts").withTranslatedCommand(MESSAGES.tagEventFlag()) .withTranslatedValue(MESSAGES.attrFlagShowConflicts()); if (event.getValue()) { if (!hasChip(chip)) addChip(chip, true); } else { if (hasChip(chip)) removeChip(chip, true); } } }); conflicts.addMouseDownHandler(new MouseDownHandler() { @Override public void onMouseDown(MouseDownEvent event) { event.getNativeEvent().stopPropagation(); event.getNativeEvent().preventDefault(); } }); sessions.addValueChangeHandler(new ValueChangeHandler<Boolean>() { @Override public void onValueChange(ValueChangeEvent<Boolean> event) { Chip chip = new Chip("flag", "All Sessions").withTranslatedCommand(MESSAGES.tagEventFlag()) .withTranslatedValue(MESSAGES.attrFlagAllSessions()); if (event.getValue()) { if (!hasChip(chip)) addChip(chip, true); } else { if (hasChip(chip)) removeChip(chip, true); } } }); sessions.addMouseDownHandler(new MouseDownHandler() { @Override public void onMouseDown(MouseDownEvent event) { event.getNativeEvent().stopPropagation(); event.getNativeEvent().preventDefault(); } }); AbsolutePanel m = new AbsolutePanel(); m.setStyleName("unitime-DateSelector"); final SingleDateSelector.SingleMonth m1 = new SingleDateSelector.SingleMonth(MESSAGES.tagDateFrom()); m1.setAllowDeselect(true); m.add(m1); final SingleDateSelector.SingleMonth m2 = new SingleDateSelector.SingleMonth(MESSAGES.tagDateTo()); m2.setAllowDeselect(true); m.add(m2); addFilter(new FilterBox.CustomFilter("date", MESSAGES.tagDate(), m) { @Override public void getSuggestions(List<Chip> chips, String text, AsyncCallback<Collection<Suggestion>> callback) { List<FilterBox.Suggestion> suggestions = new ArrayList<FilterBox.Suggestion>(); Chip chFrom = null, chTo = null; for (Chip c : chips) { if (c.getCommand().equals("from")) chFrom = c; if (c.getCommand().equals("to")) chTo = c; } try { Date date = DateTimeFormat.getFormat("MM/dd").parse(text); suggestions.add(new FilterBox.Suggestion( new Chip("from", sDateFormat.format(date)).withTranslatedCommand(MESSAGES.tagDateFrom()) .withTranslatedValue(sLocalDateFormat.format(date)), chFrom)); suggestions.add(new FilterBox.Suggestion( new Chip("to", sDateFormat.format(date)).withTranslatedCommand(MESSAGES.tagDateTo()) .withTranslatedValue(sLocalDateFormat.format(date)), chTo)); } catch (Exception e) { } try { Date date = DateTimeFormat.getFormat("dd.MM").parse(text); suggestions.add(new FilterBox.Suggestion( new Chip("from", sDateFormat.format(date)).withTranslatedCommand(MESSAGES.tagDateFrom()) .withTranslatedValue(sLocalDateFormat.format(date)), chFrom)); suggestions.add(new FilterBox.Suggestion( new Chip("to", sDateFormat.format(date)).withTranslatedCommand(MESSAGES.tagDateTo()) .withTranslatedValue(sLocalDateFormat.format(date)), chTo)); } catch (Exception e) { } try { Date date = DateTimeFormat.getFormat("MM/dd/yy").parse(text); suggestions.add(new FilterBox.Suggestion( new Chip("from", sDateFormat.format(date)).withTranslatedCommand(MESSAGES.tagDateFrom()) .withTranslatedValue(sLocalDateFormat.format(date)), chFrom)); suggestions.add(new FilterBox.Suggestion( new Chip("to", sDateFormat.format(date)).withTranslatedCommand(MESSAGES.tagDateTo()) .withTranslatedValue(sLocalDateFormat.format(date)), chTo)); } catch (Exception e) { } try { Date date = DateTimeFormat.getFormat("dd.MM.yy").parse(text); suggestions.add(new FilterBox.Suggestion( new Chip("from", sDateFormat.format(date)).withTranslatedCommand(MESSAGES.tagDateFrom()) .withTranslatedValue(sLocalDateFormat.format(date)), chFrom)); suggestions.add(new FilterBox.Suggestion( new Chip("to", sDateFormat.format(date)).withTranslatedCommand(MESSAGES.tagDateTo()) .withTranslatedValue(sLocalDateFormat.format(date)), chTo)); } catch (Exception e) { } try { Date date = DateTimeFormat.getFormat("MMM dd").parse(text); suggestions.add(new FilterBox.Suggestion( new Chip("from", sDateFormat.format(date)).withTranslatedCommand(MESSAGES.tagDateFrom()) .withTranslatedValue(sLocalDateFormat.format(date)), chFrom)); suggestions.add(new FilterBox.Suggestion( new Chip("to", sDateFormat.format(date)).withTranslatedCommand(MESSAGES.tagDateTo()) .withTranslatedValue(sLocalDateFormat.format(date)), chTo)); } catch (Exception e) { } try { Date date = DateTimeFormat.getFormat("MMM dd yy").parse(text); suggestions.add(new FilterBox.Suggestion( new Chip("from", sDateFormat.format(date)).withTranslatedCommand(MESSAGES.tagDateFrom()) .withTranslatedValue(sLocalDateFormat.format(date)), chFrom)); suggestions.add(new FilterBox.Suggestion( new Chip("to", sDateFormat.format(date)).withTranslatedCommand(MESSAGES.tagDateTo()) .withTranslatedValue(sLocalDateFormat.format(date)), chTo)); } catch (Exception e) { } callback.onSuccess(suggestions); } }); addFilter(new FilterBox.StaticSimpleFilter("from", MESSAGES.tagDateFrom()) { @Override public void validate(String value, AsyncCallback<Chip> callback) { String translatedValue = null; try { translatedValue = sLocalDateFormat.format(sDateFormat.parse(value)); } catch (IllegalArgumentException e) { } callback.onSuccess(new Chip(getCommand(), value).withTranslatedCommand(getLabel()) .withTranslatedValue(translatedValue)); } }); addFilter(new FilterBox.StaticSimpleFilter("to", MESSAGES.tagDateTo()) { @Override public void validate(String value, AsyncCallback<Chip> callback) { String translatedValue = null; try { translatedValue = sLocalDateFormat.format(sDateFormat.parse(value)); } catch (IllegalArgumentException e) { } callback.onSuccess(new Chip(getCommand(), value).withTranslatedCommand(getLabel()) .withTranslatedValue(translatedValue)); } }); session.addAcademicSessionChangeHandler(new AcademicSessionChangeHandler() { @Override public void onAcademicSessionChange(AcademicSessionChangeEvent event) { if (event.isChanged() && event.getNewAcademicSessionId() != null) { RPC.execute(new RequestSessionDetails(event.getNewAcademicSessionId()), new AsyncCallback<GwtRpcResponseList<SessionMonth>>() { @Override public void onFailure(Throwable caught) { } @Override public void onSuccess(GwtRpcResponseList<SessionMonth> result) { m1.setMonths(result); m2.setMonths(result); } }); } } }); m1.addValueChangeHandler(new ValueChangeHandler<Date>() { @Override public void onValueChange(ValueChangeEvent<Date> event) { Chip ch = getChip("from"); Date value = event.getValue(); if (value == null) { if (ch != null) removeChip(ch, true); } else { if (ch != null) { if (ch.getValue().equals(sDateFormat.format(value))) return; removeChip(ch, false); } addChip(new Chip("from", sDateFormat.format(value)) .withTranslatedCommand(MESSAGES.tagDateFrom()) .withTranslatedValue(sLocalDateFormat.format(value)), true); } } }); m2.addValueChangeHandler(new ValueChangeHandler<Date>() { @Override public void onValueChange(ValueChangeEvent<Date> event) { Chip ch = getChip("to"); Date value = event.getValue(); if (value == null) { if (ch != null) removeChip(ch, true); } else { if (ch != null) { if (ch.getValue().equals(sDateFormat.format(value))) return; removeChip(ch, false); } addChip(new Chip("to", sDateFormat.format(value)).withTranslatedCommand(MESSAGES.tagDateTo()) .withTranslatedValue(sLocalDateFormat.format(value)), true); } } }); List<Chip> days = new ArrayList<Chip>(); days.add(new Chip("day", "Monday").withTranslatedCommand(MESSAGES.tagDayOfWeek()) .withTranslatedValue(CONSTANTS.longDays()[0])); days.add(new Chip("day", "Tuesday").withTranslatedCommand(MESSAGES.tagDayOfWeek()) .withTranslatedValue(CONSTANTS.longDays()[1])); days.add(new Chip("day", "Wednesday").withTranslatedCommand(MESSAGES.tagDayOfWeek()) .withTranslatedValue(CONSTANTS.longDays()[2])); days.add(new Chip("day", "Thursday").withTranslatedCommand(MESSAGES.tagDayOfWeek()) .withTranslatedValue(CONSTANTS.longDays()[3])); days.add(new Chip("day", "Friday").withTranslatedCommand(MESSAGES.tagDayOfWeek()) .withTranslatedValue(CONSTANTS.longDays()[4])); days.add(new Chip("day", "Saturday").withTranslatedCommand(MESSAGES.tagDayOfWeek()) .withTranslatedValue(CONSTANTS.longDays()[5])); days.add(new Chip("day", "Sunday").withTranslatedCommand(MESSAGES.tagDayOfWeek()) .withTranslatedValue(CONSTANTS.longDays()[6])); addFilter(new FilterBox.StaticSimpleFilter("day", MESSAGES.tagDayOfWeek(), days)); final TimeSelector st = new TimeSelector(null); final TimeSelector et = new TimeSelector(st); st.setStyleName("unitime-TextArea"); st.addStyleName("unitime-TimeSelector"); et.setStyleName("unitime-TextArea"); et.addStyleName("unitime-TimeSelector"); addFilter(new FilterBox.CustomFilter("time", MESSAGES.tagTime(), new Label(MESSAGES.propAfter()), st, new Label(" " + MESSAGES.propBefore()), et) { @Override public void getSuggestions(List<Chip> chips, String text, AsyncCallback<Collection<Suggestion>> callback) { List<FilterBox.Suggestion> suggestions = new ArrayList<FilterBox.Suggestion>(); Chip chStart = null, chStop = null; for (Chip c : chips) { if (c.getCommand().equals("after")) chStart = c; if (c.getCommand().equals("before")) chStop = c; } Integer start = TimeSelector.TimeUtils.parseTime(CONSTANTS, text, null); Integer stop = TimeSelector.TimeUtils.parseTime(CONSTANTS, text, chStart == null ? null : TimeSelector.TimeUtils.parseMilitary(chStart.getValue())); if (chStart == null) { if (start != null) { suggestions.add(new FilterBox.Suggestion(new Chip("after", TimeUtils.slot2military(start)) .withTranslatedCommand(MESSAGES.tagTimeAfter()) .withTranslatedValue(TimeUtils.slot2time(start)), chStart)); suggestions .add(new FilterBox.Suggestion(new Chip("after", TimeUtils.slot2military(start + 3)) .withTranslatedCommand(MESSAGES.tagTimeAfter()) .withTranslatedValue(TimeUtils.slot2time(start + 3)), chStart)); suggestions .add(new FilterBox.Suggestion(new Chip("after", TimeUtils.slot2military(start + 6)) .withTranslatedCommand(MESSAGES.tagTimeAfter()) .withTranslatedValue(TimeUtils.slot2time(start + 6)), chStart)); suggestions .add(new FilterBox.Suggestion(new Chip("after", TimeUtils.slot2military(start + 9)) .withTranslatedCommand(MESSAGES.tagTimeAfter()) .withTranslatedValue(TimeUtils.slot2time(start + 9)), chStart)); } if (stop != null) { suggestions.add(new FilterBox.Suggestion(new Chip("before", TimeUtils.slot2military(stop)) .withTranslatedCommand(MESSAGES.tagTimeBefore()) .withTranslatedValue(TimeUtils.slot2time(stop)), chStop)); suggestions .add(new FilterBox.Suggestion(new Chip("before", TimeUtils.slot2military(stop + 3)) .withTranslatedCommand(MESSAGES.tagTimeBefore()) .withTranslatedValue(TimeUtils.slot2time(stop + 3)), chStop)); suggestions .add(new FilterBox.Suggestion(new Chip("before", TimeUtils.slot2military(stop + 6)) .withTranslatedCommand(MESSAGES.tagTimeBefore()) .withTranslatedValue(TimeUtils.slot2time(stop + 6)), chStop)); suggestions .add(new FilterBox.Suggestion(new Chip("before", TimeUtils.slot2military(stop + 9)) .withTranslatedCommand(MESSAGES.tagTimeBefore()) .withTranslatedValue(TimeUtils.slot2time(stop + 9)), chStop)); } } else { if (stop != null) { suggestions.add(new FilterBox.Suggestion(new Chip("before", TimeUtils.slot2military(stop)) .withTranslatedCommand(MESSAGES.tagTimeBefore()) .withTranslatedValue(TimeUtils.slot2time(stop)), chStop)); suggestions .add(new FilterBox.Suggestion(new Chip("before", TimeUtils.slot2military(stop + 3)) .withTranslatedCommand(MESSAGES.tagTimeBefore()) .withTranslatedValue(TimeUtils.slot2time(stop + 3)), chStop)); suggestions .add(new FilterBox.Suggestion(new Chip("before", TimeUtils.slot2military(stop + 6)) .withTranslatedCommand(MESSAGES.tagTimeBefore()) .withTranslatedValue(TimeUtils.slot2time(stop + 6)), chStop)); suggestions .add(new FilterBox.Suggestion(new Chip("before", TimeUtils.slot2military(stop + 9)) .withTranslatedCommand(MESSAGES.tagTimeBefore()) .withTranslatedValue(TimeUtils.slot2time(stop + 9)), chStop)); } if (start != null) { suggestions.add(new FilterBox.Suggestion(new Chip("after", TimeUtils.slot2military(start)) .withTranslatedCommand(MESSAGES.tagTimeAfter()) .withTranslatedValue(TimeUtils.slot2time(start)), chStart)); suggestions .add(new FilterBox.Suggestion(new Chip("after", TimeUtils.slot2military(start + 3)) .withTranslatedCommand(MESSAGES.tagTimeAfter()) .withTranslatedValue(TimeUtils.slot2time(start + 3)), chStart)); suggestions .add(new FilterBox.Suggestion(new Chip("after", TimeUtils.slot2military(start + 6)) .withTranslatedCommand(MESSAGES.tagTimeAfter()) .withTranslatedValue(TimeUtils.slot2time(start + 6)), chStart)); suggestions .add(new FilterBox.Suggestion(new Chip("after", TimeUtils.slot2military(start + 9)) .withTranslatedCommand(MESSAGES.tagTimeAfter()) .withTranslatedValue(TimeUtils.slot2time(start + 9)), chStart)); } } callback.onSuccess(suggestions); } }); st.addValueChangeHandler(new ValueChangeHandler<Integer>() { @Override public void onValueChange(ValueChangeEvent<Integer> event) { Chip ch = getChip("after"); Integer start = event.getValue(); if (start == null) { if (ch != null) removeChip(ch, true); } else { if (ch != null) { if (ch.getCommand().equals(TimeUtils.slot2military(start))) return; removeChip(ch, false); } addChip(new Chip("after", TimeUtils.slot2military(start)) .withTranslatedCommand(MESSAGES.tagTimeAfter()) .withTranslatedValue(TimeUtils.slot2time(start)), true); } Chip ch2 = getChip("before"); Integer stop = et.getValue(); if (stop == null) { if (ch2 != null) removeChip(ch2, true); } else { if (ch2 != null) { if (ch2.getCommand().equals(TimeUtils.slot2military(stop))) return; removeChip(ch2, false); } addChip(new Chip("before", TimeUtils.slot2military(stop)) .withTranslatedCommand(MESSAGES.tagTimeBefore()) .withTranslatedValue(TimeUtils.slot2time(stop)), true); } } }); et.addValueChangeHandler(new ValueChangeHandler<Integer>() { @Override public void onValueChange(ValueChangeEvent<Integer> event) { Chip ch = getChip("before"); Integer stop = event.getValue(); if (stop == null) { if (ch != null) removeChip(ch, true); } else { if (ch != null) { if (ch.getCommand().equals(TimeUtils.slot2military(stop))) return; removeChip(ch, false); } addChip(new Chip("before", TimeUtils.slot2military(stop)) .withTranslatedCommand(MESSAGES.tagTimeBefore()) .withTranslatedValue(TimeUtils.slot2time(stop)), true); } } }); addFilter(new FilterBox.StaticSimpleFilter("after", MESSAGES.tagTimeAfter()) { @Override public void validate(String text, AsyncCallback<Chip> callback) { String translatedValue = null; Integer slot = TimeUtils.parseTime2(CONSTANTS, text, null); if (slot != null) translatedValue = TimeUtils.slot2time(slot); callback.onSuccess(new Chip(getCommand(), text).withTranslatedCommand(getLabel()) .withTranslatedValue(translatedValue)); } }); addFilter(new FilterBox.StaticSimpleFilter("before", MESSAGES.tagTimeBefore()) { @Override public void validate(String text, AsyncCallback<Chip> callback) { String translatedValue = null; Integer slot = TimeUtils.parseTime2(CONSTANTS, text, null); if (slot != null) translatedValue = TimeUtils.slot2time(slot); callback.onSuccess(new Chip(getCommand(), text).withTranslatedCommand(getLabel()) .withTranslatedValue(translatedValue)); } }); addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { iLastRequested = getChip("requested"); if (!isFilterPopupShowing()) { conflicts.setValue(hasChip(new Chip("flag", "Conflicts"))); sessions.setValue(hasChip(new Chip("flag", "All Sessions"))); Chip req = getChip("requested"); if (req == null) iRequested.setText(""); else iRequested.setText(req.getValue()); for (int i = 0; i < iSponsors.getItemCount(); i++) { String value = iSponsors.getValue(i); iSponsors.setItemSelected(i, hasChip(new Chip("sponsor", value))); } Chip chFrom = getChip("from"); if (chFrom != null) m1.setDate(sDateFormat.parse(chFrom.getValue())); else m1.clearSelection(); Chip chTo = getChip("to"); if (chTo != null) m2.setDate(sDateFormat.parse(chTo.getValue())); else m2.clearSelection(); Chip chStart = getChip("after"); if (chStart != null) st.setValue(TimeSelector.TimeUtils.parseMilitary(chStart.getValue())); else st.setValue(null); Chip chStop = getChip("before"); if (chStop != null) et.setValue(TimeSelector.TimeUtils.parseMilitary(chStop.getValue())); else et.setValue(null); } if (getAcademicSessionId() != null) init(false, getAcademicSessionId(), new Command() { @Override public void execute() { if (isFilterPopupShowing()) showFilterPopup(); } }); setAriaLabel(ARIA.eventFilter(toAriaString())); } }); addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { setAriaLabel(ARIA.eventFilter(toAriaString())); } }); }
From source file:org.unitime.timetable.gwt.client.events.EventResourceTimetable.java
License:Apache License
public EventResourceTimetable(PageType type) { iHistoryToken = new HistoryToken(type); iType = type;/* w w w .ja v a 2s .c o m*/ iFilter = new SimpleForm(2); iFilter.removeStyleName("unitime-NotPrintableBottomLine"); iFilter.getColumnFormatter().setWidth(0, "120px"); iFilterHeader = new UniTimeHeaderPanel(MESSAGES.sectFilter()); iLookup = new Lookup(); iLookup.setOptions("mustHaveExternalId"); iLookup.addValueChangeHandler(new ValueChangeHandler<PersonInterface>() { @Override public void onValueChange(ValueChangeEvent<PersonInterface> event) { if (event.getValue() != null) { iResources.setText(event.getValue().getId()); resourceTypeChanged(true); } } }); iFilterHeader.addButton("lookup", MESSAGES.buttonLookup(), 75, new ClickHandler() { @Override public void onClick(ClickEvent event) { iLookup.center(); } }); iFilterHeader.setEnabled("lookup", false); iFilterHeader.addButton("add", MESSAGES.buttonAddEvent(), 75, new ClickHandler() { @Override public void onClick(ClickEvent event) { iEventAdd.setEvent(null); iEventAdd.show(); } }); iFilterHeader.setEnabled("add", false); iFilter.addHeaderRow(iFilterHeader); iFilterHeader.addButton("clear", MESSAGES.buttonClear(), 75, new ClickHandler() { @Override public void onClick(ClickEvent event) { // Event filter iEvents.setValue(iHistoryToken.getDefaultParameter("events", ""), true); // Room filter iRooms.setValue(iHistoryToken.getDefaultParameter("rooms", ""), true); // Resource type if (!"true".equals(iHistoryToken.getParameter("fixedType", "false"))) { String typeString = iHistoryToken.getDefaultParameter("type", "room"); if (typeString != null) for (int idx = 0; idx < iResourceTypes.getItemCount(); idx++) { if (iResourceTypes.getValue(idx).equalsIgnoreCase(typeString)) { iResourceTypes.setSelectedIndex(idx); } } } // Subject, curriculum, department, etc. iResources.setValue(iHistoryToken.getDefaultParameter("name", "")); // Room selection iLocRoom = iHistoryToken.getDefaultParameter("room", ""); // Week selection iLocDate = iHistoryToken.getDefaultParameter("date", ""); hideResults(); changeUrl(); UniTimePageLabel.getInstance().setPageName(getPageName()); resourceTypeChanged(false); } }); iFilterHeader.setEnabled("clear", "true".equals(iHistoryToken.getParameter("showClear", "true"))); iFilterHeader.addButton("search", MESSAGES.buttonSearch(), 75, new ClickHandler() { @Override public void onClick(ClickEvent event) { resourceTypeChanged(true); } }); iSession = new AcademicSessionSelectionBox(iHistoryToken.getParameter("term"), "Events") { @Override protected void onInitializationSuccess(List<AcademicSession> sessions) { iFilter.setVisible(sessions != null && !sessions.isEmpty()); UniTimePageHeader.getInstance().getRight().setVisible(false); UniTimePageHeader.getInstance().getRight().setPreventDefault(true); } @Override protected void onInitializationFailure(Throwable caught) { UniTimeNotifications.error(MESSAGES.failedLoadSessions(caught.getMessage()), caught); } }; iSession.setFilter(this); iSessionRow = iFilter.addRow(MESSAGES.propAcademicSession(), iSession); iEvents = new EventFilterBox(iSession); if ("true".equals(iHistoryToken.getParameter("showFilter", "true"))) iFilter.addRow(MESSAGES.propEventFilter(), iEvents); iRooms = new RoomFilterBox(iSession); if ("true".equals(iHistoryToken.getParameter("showFilter", "true"))) iFilter.addRow(MESSAGES.propRoomFilter(), iRooms); iResourceTypes = new ListBox(); for (ResourceType resource : ResourceType.values()) { if (resource.isVisible()) iResourceTypes.addItem(resource.getResourceType(CONSTANTS), resource.name()); } iResourceTypes.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent event) { iResources.setText(""); UniTimePageLabel.getInstance().setPageName(getPageName()); hideResults(); if (iProperties != null) resourceTypeChanged(isShowingResults()); } }); int row = iFilter.addRow(MESSAGES.propResourceType(), iResourceTypes); if ("true".equals(iHistoryToken.getParameter("fixedType", "false"))) iFilter.getRowFormatter().setVisible(row, false); iResources = new SuggestBox(new SuggestOracle() { @Override public void requestDefaultSuggestions(Request request, Callback callback) { requestSuggestions(request, callback); } @Override public void requestSuggestions(final Request request, final Callback callback) { if (iSession.getAcademicSessionId() != null) { RPC.execute( ResourceLookupRpcRequest.findResources(iSession.getAcademicSessionId(), ResourceType .valueOf(iResourceTypes.getValue(iResourceTypes.getSelectedIndex())), request.getQuery(), request.getLimit()), new AsyncCallback<GwtRpcResponseList<ResourceInterface>>() { @Override public void onFailure(final Throwable caught) { ArrayList<Suggestion> suggestions = new ArrayList<Suggestion>(); suggestions.add(new Suggestion() { @Override public String getDisplayString() { return "<font color='red'>" + caught.getMessage() + "</font>"; } @Override public String getReplacementString() { return ""; } }); callback.onSuggestionsReady(request, new Response(suggestions)); ToolBox.checkAccess(caught); } @Override public void onSuccess(GwtRpcResponseList<ResourceInterface> result) { ArrayList<Suggestion> suggestions = new ArrayList<Suggestion>(); for (ResourceInterface resource : result) { suggestions.add(new ResourceSuggestion(resource)); } callback.onSuggestionsReady(request, new Response(suggestions)); } }); } } @Override public boolean isDisplayStringHTML() { return true; } }); iResources.getValueBox().addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { iResources.showSuggestionList(); } }); iResourcesRow = iFilter.addRow(MESSAGES.propResource(), iResources); iResources.addSelectionHandler(new SelectionHandler<Suggestion>() { public void onSelection(SelectionEvent<Suggestion> event) { if (event.getSelectedItem() instanceof ResourceSuggestion) { resourceChanged(((ResourceSuggestion) event.getSelectedItem()).getResource()); } } }); iFilter.getRowFormatter().setVisible(iResourcesRow, false); iResourceTypes.setSelectedIndex(ResourceType.ROOM.ordinal()); iPanel = new SimpleForm(2); iPanel.removeStyleName("unitime-NotPrintableBottomLine"); iPanel.addRow(iFilter); iHeader = new UniTimeHeaderPanel(); iPanel.addHeaderRow(iHeader); iWeekPanel = new WeekSelector(iSession); iWeekPanel.addValueChangeHandler(new ValueChangeHandler<WeekSelector.Interval>() { @Override public void onValueChange(ValueChangeEvent<WeekSelector.Interval> e) { iLocDate = iWeekPanel.getSelection(); tabOrDataChanged(true); } }); iWeekPanel.setFilter(new WeekSelector.Filter<WeekInterface>() { @Override public boolean filter(WeekInterface week) { return !iMatchingWeeks.contains(week.getDayOfYear()); } @Override public boolean isEmpty() { return iMatchingRooms.isEmpty(); } }); iRoomPanel = new RoomSelector(); iRoomPanel.setFilter(new WeekSelector.Filter<ResourceInterface>() { @Override public boolean filter(ResourceInterface room) { return !iMatchingRooms.contains(room.getId()); } @Override public boolean isEmpty() { return iMatchingRooms.isEmpty(); } }); iTabBar = new AriaTabBar(); iTabBar.addTab(MESSAGES.tabGrid(), true); iTabBar.addTab(MESSAGES.tabEventTable(), true); iTabBar.addTab(MESSAGES.tabMeetingTable(), true); iTabBar.addSelectionHandler(new SelectionHandler<Integer>() { @Override public void onSelection(SelectionEvent<Integer> event) { tabOrDataChanged(true); } }); iGridOrTablePanel = new SimplePanel(); iGridOrTablePanel.setStyleName("unitime-TabPanel"); final Character gridAccessKey = UniTimeHeaderPanel.guessAccessKey(MESSAGES.tabGrid()); final Character eventsAccessKey = UniTimeHeaderPanel.guessAccessKey(MESSAGES.tabEventTable()); final Character meetingsAccessKey = UniTimeHeaderPanel.guessAccessKey(MESSAGES.tabMeetingTable()); if (gridAccessKey != null || eventsAccessKey != null || meetingsAccessKey != null) { RootPanel.get().addDomHandler(new KeyUpHandler() { @Override public void onKeyUp(KeyUpEvent event) { if (!iRootPanel.getWidget().equals(iPanel)) return; int tab = -1; if (gridAccessKey != null && event.getNativeEvent().getCtrlKey() && (event.getNativeKeyCode() == gridAccessKey || event.getNativeKeyCode() == Character.toUpperCase(gridAccessKey))) { tab = 0; } if (eventsAccessKey != null && event.getNativeEvent().getCtrlKey() && (event.getNativeKeyCode() == eventsAccessKey || event.getNativeKeyCode() == Character.toUpperCase(eventsAccessKey))) { tab = 1; } if (meetingsAccessKey != null && event.getNativeEvent().getCtrlKey() && (event.getNativeKeyCode() == meetingsAccessKey || event.getNativeKeyCode() == Character.toUpperCase(meetingsAccessKey))) { tab = 2; } if (tab >= 0) { iTabBar.selectTab(tab); event.preventDefault(); } } }, KeyUpEvent.getType()); } iDockPanel = new DockPanel(); iDockPanel.setStyleName("unitime-EventResults"); iDockPanel.setSpacing(0); iDockPanel.add(iGridOrTablePanel, DockPanel.SOUTH); iDockPanel.add(iRoomPanel, DockPanel.WEST); iDockPanel.setCellHorizontalAlignment(iRoomPanel, HasHorizontalAlignment.ALIGN_LEFT); iDockPanel.add(iTabBar, DockPanel.CENTER); iDockPanel.setCellVerticalAlignment(iTabBar, HasVerticalAlignment.ALIGN_BOTTOM); iDockPanel.setCellHorizontalAlignment(iTabBar, HasHorizontalAlignment.ALIGN_CENTER); iDockPanel.add(iWeekPanel, DockPanel.EAST); iDockPanel.setCellHorizontalAlignment(iWeekPanel, HasHorizontalAlignment.ALIGN_RIGHT); Roles.getTabpanelRole().set(iDockPanel.getElement()); Roles.getTabpanelRole().setAriaOwnsProperty(iDockPanel.getElement(), Id.of(iTabBar.getElement())); iPanel.addRow(iDockPanel); hideResults(); iFooter = iHeader.clonePanel(); iPanel.addRow(iFooter); iRootPanel = new SimplePanel(iPanel); initWidget(iRootPanel); iRoomPanel.addValueChangeHandler(new ValueChangeHandler<IntervalSelector<ResourceInterface>.Interval>() { @Override public void onValueChange(ValueChangeEvent<IntervalSelector<ResourceInterface>.Interval> e) { iLocRoom = iRoomPanel.getSelection(); tabOrDataChanged(true); } }); for (int i = 1; i < iPanel.getRowCount(); i++) iPanel.getRowFormatter().setVisible(i, false); iHeader.addButton("add", MESSAGES.buttonAddEvent(), 75, new ClickHandler() { @Override public void onClick(ClickEvent event) { iEventAdd.setEvent(null); iEventAdd.show(); } }); iHeader.setEnabled("add", false); iHeader.addButton("print", MESSAGES.buttonPrint(), 75, new ClickHandler() { @Override public void onClick(ClickEvent clickEvent) { final EventMeetingTable table = new EventMeetingTable( getSelectedTab() <= 1 ? EventMeetingTable.Mode.ListOfEvents : EventMeetingTable.Mode.ListOfMeetings, false, EventResourceTimetable.this); table.setMeetingFilter(EventResourceTimetable.this); table.setShowMainContact(iProperties != null && iProperties.isCanLookupMainContact()); table.setEvents(iData); table.setSortBy(iTable.getSortBy()); table.getElement().getStyle().setWidth(1040, Unit.PX); int firstSlot = 84, lastSlot = 216; boolean skipDays = iEvents.hasChip(new FilterBox.Chip("day", null)); boolean hasDay[] = new boolean[] { !skipDays || iEvents.hasChip(new FilterBox.Chip("day", CONSTANTS.longDays()[0])), !skipDays || iEvents.hasChip(new FilterBox.Chip("day", CONSTANTS.longDays()[1])), !skipDays || iEvents.hasChip(new FilterBox.Chip("day", CONSTANTS.longDays()[2])), !skipDays || iEvents.hasChip(new FilterBox.Chip("day", CONSTANTS.longDays()[3])), !skipDays || iEvents.hasChip(new FilterBox.Chip("day", CONSTANTS.longDays()[4])), iEvents.hasChip(new FilterBox.Chip("day", CONSTANTS.longDays()[5])), iEvents.hasChip(new FilterBox.Chip("day", CONSTANTS.longDays()[6])) }; for (EventInterface event : iData) { if (event.getType() == EventType.Unavailabile && !iEvents.hasChip(new Chip("type", "Not Available"))) continue; for (MeetingInterface meeting : event.getMeetings()) { if (filterEvent(event, meeting)) continue; if (meeting.getApprovalStatus() != ApprovalStatus.Pending && meeting.getApprovalStatus() != ApprovalStatus.Approved) continue; if (firstSlot > meeting.getStartSlot()) firstSlot = meeting.getStartSlot(); if (lastSlot < meeting.getEndSlot()) lastSlot = meeting.getEndSlot(); hasDay[meeting.getDayOfWeek()] = true; } } Chip after = iEvents.getChip("after"); if (after != null) { Integer slot = TimeUtils.parseTime(CONSTANTS, after.getValue(), null); if (slot != null && firstSlot > slot) firstSlot = slot; } Chip before = iEvents.getChip("before"); if (before != null) { Integer slot = TimeUtils.parseTime(CONSTANTS, before.getValue(), firstSlot); if (slot != null && lastSlot < slot) lastSlot = slot; } int nrDays = 0; for (boolean d : hasDay) if (d) nrDays++; int days[] = new int[nrDays]; int d = 0; for (int i = 0; i < 7; i++) if (hasDay[i]) days[d++] = i; int firstHour = firstSlot / 12; int lastHour = 1 + (lastSlot - 1) / 12; if (firstHour <= 7 && firstHour > 0 && ((firstSlot % 12) <= 6)) firstHour--; HashMap<Long, String> colors = new HashMap<Long, String>(); final TimeGrid tg = new TimeGrid(colors, days, (int) (1000 / nrDays), 55, true, false, (firstHour < 7 ? firstHour : 7), (lastHour > 18 ? lastHour : 18), EventResourceTimetable.this); tg.setResourceType(getResourceType()); tg.setSelectedWeeks(iWeekPanel.getSelected()); tg.setRoomResources(iRoomPanel.getSelected()); tg.setMode(gridMode()); tg.showVerticalSplit(); for (EventInterface event : sortedEvents()) { List<MeetingInterface> meetings = new ArrayList<MeetingInterface>(); for (MeetingInterface meeting : event.getMeetings()) { if (meeting.getApprovalStatus() != ApprovalStatus.Pending && meeting.getApprovalStatus() != ApprovalStatus.Approved) continue; if (meeting.getMeetingDate() != null && !filterEvent(event, meeting)) meetings.add(meeting); } if (!meetings.isEmpty()) tg.addEvent(event, meetings); } if (iWeekPanel.getValue() != null) tg.labelDays(iWeekPanel.getValue().getFirst(), iWeekPanel.getValue().getLast()); // Move header row to thead Element headerRow = table.getRowFormatter().getElement(0); Element tableElement = table.getElement(); Element thead = DOM.createTHead(); tableElement.insertFirst(thead); headerRow.getParentElement().removeChild(headerRow); thead.appendChild(headerRow); ToolBox.print(new ToolBox.Page() { @Override public String getName() { return iHeader.getHeaderTitle(); } @Override public String getUser() { return iRoomPanel.getValue().toString(); } @Override public String getSession() { return iWeekPanel.getValue().toString(); } @Override public Element getBody() { return tg.getElement(); } }, new ToolBox.Page() { @Override public String getName() { return iHeader.getHeaderTitle(); } @Override public String getUser() { return iRoomPanel.getValue().toString(); } @Override public String getSession() { return iWeekPanel.getValue().toString(); } @Override public Element getBody() { return table.getElement(); } }); } }); iHeader.addButton("export", MESSAGES.buttonExport(), 75, new ClickHandler() { @Override public void onClick(ClickEvent clickEvent) { if (iProperties != null && iProperties.isCanExportCSV()) { final PopupPanel popup = new PopupPanel(true); MenuBar menu = new MenuBar(true); MenuItem exportPdf = new MenuItem(MESSAGES.opExportPDF(), true, new Command() { @Override public void execute() { popup.hide(); export("output=" + (getSelectedTab() <= 1 ? "events" : "meetings") + ".pdf&flags=" + EventCookie.getInstance().getFlags(), true); } }); exportPdf.getElement().getStyle().setCursor(Cursor.POINTER); menu.addItem(exportPdf); MenuItem exportCsv = new MenuItem(MESSAGES.opExportCSV(), true, new Command() { @Override public void execute() { popup.hide(); export("output=" + (getSelectedTab() <= 1 ? "events" : "meetings") + ".csv&flags=" + EventCookie.getInstance().getFlags(), true); } }); exportCsv.getElement().getStyle().setCursor(Cursor.POINTER); menu.addItem(exportCsv); MenuItem exportIcs = new MenuItem(MESSAGES.opExportICalendar(), true, new Command() { @Override public void execute() { popup.hide(); copyToClipboard( "output=events.ics" + (iType == PageType.Personal ? "&e:flag=All+Sessions" : ""), iType == PageType.Personal); } }); exportIcs.getElement().getStyle().setCursor(Cursor.POINTER); menu.addItem(exportIcs); popup.add(menu); popup.showRelativeTo((UIObject) clickEvent.getSource()); menu.focus(); } else { export("output=events.ics", false); } } }); iHeader.addButton("operations", MESSAGES.buttonMoreOperations(), 75, new ClickHandler() { @Override public void onClick(ClickEvent event) { final PopupPanel popup = new PopupPanel(true); iTable.getHeader(0).setMenu(popup); popup.showRelativeTo((UIObject) event.getSource()); ((MenuBar) popup.getWidget()).focus(); } }); iHeader.setEnabled("print", false); iHeader.setEnabled("export", false); iHeader.setEnabled("operations", false); iSession.addAcademicSessionChangeHandler(new AcademicSessionChangeHandler() { @Override public void onAcademicSessionChange(AcademicSessionChangeEvent event) { loadProperties(new AsyncCallback<EventPropertiesRpcResponse>() { @Override public void onFailure(Throwable caught) { } @Override public void onSuccess(EventPropertiesRpcResponse result) { if (!iInitialized) setup(true); else resourceTypeChanged(isShowingResults()); } }); } }); iEventDetail = new EventDetail(this) { @Override protected void onHide() { iRootPanel.setWidget(iPanel); UniTimePageLabel.getInstance().setPageName(getPageName()); if (!isShowingResults()) resourceTypeChanged(true); changeUrl(); } @Override protected void onShow() { iBack.clear(); if (iTable != null) iTable.clearHover(); iRootPanel.setWidget(iEventDetail); changeUrl(); } @Override protected void edit() { super.hide(); iEventAdd.setEvent(getEvent()); iEventAdd.show(); } @Override protected EventInterface getPrevious(Long eventId) { return iTable.previous(eventId); } @Override protected EventInterface getNext(Long eventId) { return iTable.next(eventId); } @Override protected void previous(final EventInterface event) { iBack.add(getEvent()); LoadingWidget.execute( EventDetailRpcRequest.requestEventDetails(iSession.getAcademicSessionId(), event.getId()), new AsyncCallback<EventInterface>() { @Override public void onFailure(Throwable caught) { UniTimeNotifications .error(MESSAGES.failedLoad(event.getName(), caught.getMessage()), caught); } @Override public void onSuccess(EventInterface result) { LoadingWidget.getInstance().hide(); setEvent(result); changeUrl(); } }, MESSAGES.waitLoading(event.getName())); } @Override protected void next(final EventInterface event) { previous(event); } @Override public void hide() { if (!iBack.isEmpty()) { EventInterface last = iBack.remove(iBack.size() - 1); setEvent(last); } else { super.hide(); } } @Override protected void onApprovalOrReject(Long eventId, EventInterface event) { if (iData != null) populate(tinker(new GwtRpcResponseList<EventInterface>(iData), eventId, event)); } }; iEventAdd = new EventAdd(iSession, this) { @Override protected void onHide() { iSession.setFilter(EventResourceTimetable.this); iFilter.setWidget(iSessionRow, 1, iSession); final EventInterface modified = iEventAdd.getEvent(), detail = iEventDetail.getEvent(), saved = iEventAdd.getSavedEvent(); if (saved != null) { if (iData != null) populate(tinker(new GwtRpcResponseList<EventInterface>(iData), (saved.getId() == null ? modified.getId() : saved.getId()), saved)); if (saved.getId() != null) { iEventDetail.setEvent(saved); iEventDetail.show(); } else { iRootPanel.setWidget(iPanel); UniTimePageLabel.getInstance().setPageName(getPageName()); } } else if (modified != null && detail != null && detail.getId().equals(modified.getId())) { LoadingWidget.execute(EventDetailRpcRequest.requestEventDetails(iSession.getAcademicSessionId(), modified.getId()), new AsyncCallback<EventInterface>() { @Override public void onFailure(Throwable caught) { UniTimeNotifications.error( MESSAGES.failedLoad(detail.getName(), caught.getMessage()), caught); } @Override public void onSuccess(EventInterface result) { LoadingWidget.getInstance().hide(); if (result == null) { iRootPanel.setWidget(iPanel); UniTimePageLabel.getInstance().setPageName(getPageName()); } else { iEventDetail.setEvent(result); iEventDetail.show(); } } }, MESSAGES.waitLoading(detail.getName())); } else { iRootPanel.setWidget(iPanel); UniTimePageLabel.getInstance().setPageName(getPageName()); } changeUrl(); } @Override protected void onShow() { if (iTable != null) iTable.clearHover(); iRootPanel.setWidget(iEventAdd); changeUrl(); } }; iMeetingClickHandler = new MeetingClickHandler() { @Override public void onMeetingClick(final MeetingClickEvent event) { if (!event.getEvent().isCanView()) return; LoadingWidget.execute(EventDetailRpcRequest.requestEventDetails(iSession.getAcademicSessionId(), event.getEvent().getId()), new AsyncCallback<EventInterface>() { @Override public void onFailure(Throwable caught) { UniTimeNotifications.error( MESSAGES.failedLoad(event.getEvent().getName(), caught.getMessage()), caught); } @Override public void onSuccess(EventInterface result) { LoadingWidget.getInstance().hide(); iEventDetail.setEvent(result); iEventDetail.show(); } }, MESSAGES.waitLoading(event.getEvent().getName())); } }; iTable = new EventMeetingTable(EventMeetingTable.Mode.ListOfEvents, true, this) { @Override protected void onSortByChanded(EventComparator.EventMeetingSortBy sortBy, boolean asc) { changeUrl(); } @Override protected void onColumnShownOrHid(int eventCookieFlags) { changeUrl(); } }; iTable.setMeetingFilter(this); iTable.addMouseClickListener(new MouseClickListener<EventMeetingRow>() { @Override public void onMouseClick(final TableEvent<EventMeetingRow> event) { if (event.getData() == null) return; final EventInterface e = event.getData().getEvent(); if (e == null || !e.isCanView()) return; LoadingWidget.execute( EventDetailRpcRequest.requestEventDetails(iSession.getAcademicSessionId(), e.getId()), new AsyncCallback<EventInterface>() { @Override public void onFailure(Throwable caught) { UniTimeNotifications.error(MESSAGES.failedLoad(e.getName(), caught.getMessage()), caught); } @Override public void onSuccess(EventInterface result) { LoadingWidget.getInstance().hide(); iEventDetail.setEvent(result); iEventDetail.show(); } }, MESSAGES.waitLoading(e.getName())); } }); iApproveDialog = new ApproveDialog(this) { @Override protected void onSubmit(ApproveEventRpcRequest.Operation operation, List<EventMeetingRow> data, String message, boolean emailConfirmation) { Map<EventInterface, List<MeetingInterface>> event2meetings = new HashMap<EventInterface, List<MeetingInterface>>(); List<EventInterface> events = new ArrayList<EventInterface>(); for (EventMeetingRow row : data) { if (row.getMeeting() != null) { List<MeetingInterface> meetings = event2meetings.get(row.getEvent()); if (meetings == null) { meetings = new ArrayList<EventInterface.MeetingInterface>(); event2meetings.put(row.getEvent(), meetings); events.add(row.getEvent()); } meetings.add(row.getMeeting()); } else { events.add(row.getEvent()); } } onSubmit(operation, events.iterator(), event2meetings, message, emailConfirmation, new GwtRpcResponseList<EventInterface>(iData)); } protected void onSubmit(final ApproveEventRpcRequest.Operation operation, final Iterator<EventInterface> events, final Map<EventInterface, List<MeetingInterface>> event2meetings, final String message, final boolean emailConfirmation, final GwtRpcResponseList<EventInterface> data) { if (events.hasNext()) { final EventInterface event = events.next(); List<MeetingInterface> meetings = event2meetings.get(event); if (meetings == null) { meetings = new ArrayList<MeetingInterface>(); for (MeetingInterface meeting : event.getMeetings()) { switch (operation) { case APPROVE: case REJECT: if (meeting.isCanApprove() && !filter(event, meeting)) meetings.add(meeting); break; case CANCEL: if (meeting.isCanCancel() && !filter(event, meeting)) meetings.add(meeting); break; case INQUIRE: if (meeting.isCanInquire() && !filter(event, meeting)) meetings.add(meeting); break; } } } if (meetings.isEmpty()) { onSubmit(operation, events, event2meetings, message, emailConfirmation, data); } else { switch (operation) { case APPROVE: LoadingWidget.getInstance().show(MESSAGES.waitForApproval(event.getName())); break; case INQUIRE: LoadingWidget.getInstance().show(MESSAGES.waitForInquiry(event.getName())); break; case REJECT: LoadingWidget.getInstance().show(MESSAGES.waitForRejection(event.getName())); break; case CANCEL: LoadingWidget.getInstance().show(MESSAGES.waitForCancellation(event.getName())); break; } RPC.execute( ApproveEventRpcRequest.createRequest(operation, iSession.getAcademicSessionId(), event, meetings, message, emailConfirmation), new AsyncCallback<SaveOrApproveEventRpcResponse>() { @Override public void onFailure(Throwable caught) { LoadingWidget.getInstance().hide(); UniTimeNotifications.error(caught); onSubmit(operation, events, event2meetings, message, emailConfirmation, data); } @Override public void onSuccess(SaveOrApproveEventRpcResponse result) { LoadingWidget.getInstance().hide(); if (result.hasMessages()) for (MessageInterface m : result.getMessages()) { if (m.isError()) UniTimeNotifications.warn(m.getMessage()); else if (m.isWarning()) UniTimeNotifications.error(m.getMessage()); else UniTimeNotifications.info(m.getMessage()); } switch (operation) { case APPROVE: case REJECT: case CANCEL: tinker(data, event.getId(), result.getEvent()); } onSubmit(operation, events, event2meetings, message, emailConfirmation, data); } }); } } else { LoadingWidget.getInstance().hide(); populate(data); } } }; iTable.setOperation(EventMeetingTable.OperationType.Approve, iApproveDialog); iTable.setOperation(EventMeetingTable.OperationType.Reject, iApproveDialog); iTable.setOperation(EventMeetingTable.OperationType.Inquire, iApproveDialog); iTable.setOperation(EventMeetingTable.OperationType.Cancel, iApproveDialog); History.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { if (iInitialized) { if ("event=add".equals(event.getValue())) iHistoryToken.parse(event.getValue()); else iHistoryToken.reset(event.getValue()); setup(false); if (LoadingWidget.getInstance().isShowing()) LoadingWidget.getInstance().hide(); } } }); }
From source file:org.unitime.timetable.gwt.client.events.RoomFilterBox.java
License:Apache License
public RoomFilterBox(AcademicSessionProvider session) { super(session); iDepartments = new ListBox(); iDepartments.setMultipleSelect(false); iDepartments.setWidth("100%"); iDepartmentFilter = new FilterBox.CustomFilter("department", MESSAGES.tagDepartment(), iDepartments) { @Override/*w w w .ja v a 2 s . c o m*/ public void getSuggestions(List<Chip> chips, String text, AsyncCallback<Collection<Suggestion>> callback) { if (text.isEmpty()) { callback.onSuccess(null); } else { Chip oldChip = getChip("department"); List<Suggestion> suggestions = new ArrayList<Suggestion>(); for (int i = 0; i < iDepartments.getItemCount(); i++) { Chip chip = new Chip("department", iDepartments.getValue(i)) .withTranslatedCommand(MESSAGES.tagDepartment()); String name = iDepartments.getItemText(i); if (iDepartments.getValue(i).toLowerCase().startsWith(text.toLowerCase())) { suggestions.add(new Suggestion(name, chip, oldChip)); } else if (text.length() > 2 && (name.toLowerCase().contains(" " + text.toLowerCase()) || name.toLowerCase().contains(" (" + text.toLowerCase()))) { suggestions.add(new Suggestion(name, chip, oldChip)); } } if ("department".startsWith(text.toLowerCase()) && text.toLowerCase().length() >= 5) { for (int i = 0; i < iDepartments.getItemCount(); i++) { Chip chip = new Chip("department", iDepartments.getValue(i)) .withTranslatedCommand(MESSAGES.tagDepartment()); String name = iDepartments.getItemText(i); if (!chip.equals(oldChip)) suggestions.add(new Suggestion(name, chip, oldChip)); } } callback.onSuccess(suggestions); } } @Override public void validate(String value, AsyncCallback<Chip> callback) { String translatedValue = null; if ("managed".equalsIgnoreCase(value)) translatedValue = MESSAGES.attrDepartmentManagedRooms(); callback.onSuccess(new Chip(getCommand(), value).withTranslatedCommand(getLabel()) .withTranslatedValue(translatedValue)); } }; iDepartmentFilter.setVisible(false); addFilter(iDepartmentFilter); iDepartments.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent event) { Chip oldChip = getChip("department"); Chip newChip = (iDepartments.getSelectedIndex() <= 0 ? null : new Chip("department", iDepartments.getValue(iDepartments.getSelectedIndex())) .withTranslatedCommand(MESSAGES.tagDepartment())); if (oldChip != null) { if (newChip == null) { removeChip(oldChip, true); } else { if (!oldChip.getValue().equals(newChip.getValue())) { removeChip(oldChip, false); addChip(newChip, true); } } } else { if (newChip != null) addChip(newChip, true); } } }); addFilter(new FilterBox.StaticSimpleFilter("type", MESSAGES.tagRoomType())); addFilter(new FilterBox.StaticSimpleFilter("feature", MESSAGES.tagRoomFeature())); addFilter(new FilterBox.StaticSimpleFilter("group", MESSAGES.tagRoomGroup())); addFilter(new FilterBox.StaticSimpleFilter("size", MESSAGES.tagRoomSize())); addFilter(new FilterBox.StaticSimpleFilter("flag", MESSAGES.tagRoomFlag()) { @Override public void validate(String text, AsyncCallback<Chip> callback) { String translatedValue = null; if ("all".equalsIgnoreCase(text)) translatedValue = MESSAGES.attrFlagAllRooms(); else if ("event".equalsIgnoreCase(text)) translatedValue = MESSAGES.attrFlagEventRooms(); else if ("nearby".equalsIgnoreCase(text)) translatedValue = MESSAGES.attrFlagNearbyRooms(); callback.onSuccess(new Chip(getCommand(), text).withTranslatedCommand(getLabel()) .withTranslatedValue(translatedValue)); } }); iBuildings = new ListBox(); iBuildings.setMultipleSelect(true); iBuildings.setWidth("100%"); iBuildings.setVisibleItemCount(3); addFilter(new FilterBox.CustomFilter("building", MESSAGES.tagBuilding(), iBuildings) { @Override public void getSuggestions(List<Chip> chips, String text, AsyncCallback<Collection<Suggestion>> callback) { if (text.isEmpty()) { callback.onSuccess(null); } else { List<Suggestion> suggestions = new ArrayList<Suggestion>(); for (int i = 0; i < iBuildings.getItemCount(); i++) { Chip chip = new Chip("building", iBuildings.getValue(i)) .withTranslatedCommand(MESSAGES.tagBuilding()); String name = iBuildings.getItemText(i); if (iBuildings.getValue(i).toLowerCase().startsWith(text.toLowerCase())) { suggestions.add(new Suggestion(name, chip)); } else if (text.length() > 2 && name.toLowerCase().contains(" " + text.toLowerCase())) { suggestions.add(new Suggestion(name, chip)); } } if ("building".startsWith(text.toLowerCase()) && text.toLowerCase().length() >= 5) { for (int i = 0; i < iBuildings.getItemCount(); i++) { Chip chip = new Chip("building", iBuildings.getValue(i)) .withTranslatedCommand(MESSAGES.tagBuilding()); String name = iBuildings.getItemText(i); suggestions.add(new Suggestion(name, chip)); } } callback.onSuccess(suggestions); } } @Override public boolean isVisible() { return iBuildings.getItemCount() > 0; } }); iBuildings.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent event) { boolean changed = false; for (int i = 0; i < iBuildings.getItemCount(); i++) { Chip chip = new Chip("building", iBuildings.getValue(i)) .withTranslatedCommand(MESSAGES.tagBuilding()); if (iBuildings.isItemSelected(i)) { if (!hasChip(chip)) { addChip(chip, false); changed = true; } } else { if (hasChip(chip)) { removeChip(chip, false); changed = true; } } } if (changed) fireValueChangeEvent(); } }); Label l1 = new Label(MESSAGES.propMin()); iMin = new TextBox(); iMin.setStyleName("unitime-TextArea"); iMin.setMaxLength(10); iMin.getElement().getStyle().setWidth(50, Unit.PX); Label l2 = new Label(MESSAGES.propMax()); l2.getElement().getStyle().setMarginLeft(10, Unit.PX); iMax = new TextBox(); iMax.setMaxLength(10); iMax.getElement().getStyle().setWidth(50, Unit.PX); iMax.setStyleName("unitime-TextArea"); final CheckBox events = new CheckBox(MESSAGES.checkOnlyEventLocations()); events.getElement().getStyle().setMarginLeft(10, Unit.PX); final CheckBox nearby = new CheckBox(MESSAGES.checkIncludeNearby()); nearby.getElement().getStyle().setMarginLeft(10, Unit.PX); addFilter(new FilterBox.CustomFilter("other", MESSAGES.tagOther(), l1, iMin, l2, iMax, events, nearby) { @Override public void getSuggestions(final List<Chip> chips, final String text, AsyncCallback<Collection<FilterBox.Suggestion>> callback) { if (text.isEmpty()) { callback.onSuccess(null); } else { List<FilterBox.Suggestion> suggestions = new ArrayList<FilterBox.Suggestion>(); if (MESSAGES.attrFlagNearbyRooms().toLowerCase().startsWith(text.toLowerCase()) || "nearby".startsWith(text.toLowerCase()) || MESSAGES.checkIncludeNearby().toLowerCase().startsWith(text.toLowerCase())) { suggestions.add(new Suggestion(MESSAGES.checkIncludeNearby(), new Chip("flag", "Nearby").withTranslatedCommand(MESSAGES.tagRoomFlag()) .withTranslatedValue(MESSAGES.attrFlagNearbyRooms()))); } else if (MESSAGES.attrFlagAllRooms().toLowerCase().startsWith(text.toLowerCase()) || "all".startsWith(text.toLowerCase()) || MESSAGES.checkAllLocations().toLowerCase().startsWith(text.toLowerCase())) { suggestions.add(new Suggestion(MESSAGES.checkAllLocations(), new Chip("flag", "All").withTranslatedCommand(MESSAGES.tagRoomFlag()) .withTranslatedValue(MESSAGES.attrFlagAllRooms()), new Chip("flag", "Event").withTranslatedCommand(MESSAGES.tagRoomFlag()) .withTranslatedValue(MESSAGES.attrFlagEventRooms()))); } else if (MESSAGES.attrFlagEventRooms().toLowerCase().startsWith(text.toLowerCase()) || "event".startsWith(text.toLowerCase()) || MESSAGES.checkOnlyEventLocations().toLowerCase().startsWith(text.toLowerCase())) { suggestions.add(new Suggestion(MESSAGES.checkOnlyEventLocations(), new Chip("flag", "Event").withTranslatedCommand(MESSAGES.tagRoomFlag()) .withTranslatedValue(MESSAGES.attrFlagEventRooms()), new Chip("flag", "All").withTranslatedCommand(MESSAGES.tagRoomFlag()) .withTranslatedValue(MESSAGES.attrFlagAllRooms()))); } else { Chip old = null; for (Chip c : chips) { if (c.getCommand().equals("size")) { old = c; break; } } try { String number = text; String prefix = ""; if (text.startsWith("<=") || text.startsWith(">=")) { number = number.substring(2); prefix = text.substring(0, 2); } else if (text.startsWith("<") || text.startsWith(">")) { number = number.substring(1); prefix = text.substring(0, 1); } Integer.parseInt(number); suggestions.add(new Suggestion( new Chip("size", text).withTranslatedCommand(MESSAGES.tagRoomSize()), old)); if (prefix.isEmpty()) { suggestions.add(new Suggestion( new Chip("size", "<=" + text).withTranslatedCommand(MESSAGES.tagRoomSize()), old)); suggestions.add(new Suggestion( new Chip("size", ">=" + text).withTranslatedCommand(MESSAGES.tagRoomSize()), old)); } } catch (Exception e) { } if (text.contains("..")) { try { String first = text.substring(0, text.indexOf('.')); String second = text.substring(text.indexOf("..") + 2); Integer.parseInt(first); Integer.parseInt(second); suggestions.add(new Suggestion( new Chip("size", text).withTranslatedCommand(MESSAGES.tagRoomSize()), old)); } catch (Exception e) { } } } callback.onSuccess(suggestions); } } }); iMin.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent event) { sizeChanged(true); } }); iMax.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent event) { sizeChanged(true); } }); iMin.addKeyPressHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { sizeChanged(false); } }); } }); iMax.addKeyPressHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { sizeChanged(false); } }); } }); iMin.addKeyUpHandler(new KeyUpHandler() { @Override public void onKeyUp(KeyUpEvent event) { if (event.getNativeKeyCode() == KeyCodes.KEY_BACKSPACE) Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { sizeChanged(false); } }); } }); iMax.addKeyUpHandler(new KeyUpHandler() { @Override public void onKeyUp(KeyUpEvent event) { if (event.getNativeKeyCode() == KeyCodes.KEY_BACKSPACE) Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { sizeChanged(false); } }); } }); iMin.addBlurHandler(new BlurHandler() { @Override public void onBlur(BlurEvent event) { sizeChanged(true); } }); iMax.addBlurHandler(new BlurHandler() { @Override public void onBlur(BlurEvent event) { sizeChanged(true); } }); nearby.addValueChangeHandler(new ValueChangeHandler<Boolean>() { @Override public void onValueChange(ValueChangeEvent<Boolean> event) { Chip chip = new Chip("flag", "Nearby").withTranslatedCommand(MESSAGES.tagRoomFlag()) .withTranslatedValue(MESSAGES.attrFlagNearbyRooms()); if (event.getValue()) { if (!hasChip(chip)) addChip(chip, true); } else { if (hasChip(chip)) removeChip(chip, true); } } }); nearby.addMouseDownHandler(new MouseDownHandler() { @Override public void onMouseDown(MouseDownEvent event) { event.getNativeEvent().stopPropagation(); event.getNativeEvent().preventDefault(); } }); events.addValueChangeHandler(new ValueChangeHandler<Boolean>() { @Override public void onValueChange(ValueChangeEvent<Boolean> event) { Chip eventChip = new Chip("flag", "Event").withTranslatedCommand(MESSAGES.tagRoomFlag()) .withTranslatedValue(MESSAGES.attrFlagEventRooms()); Chip allChip = new Chip("flag", "All").withTranslatedCommand(MESSAGES.tagRoomFlag()) .withTranslatedValue(MESSAGES.attrFlagAllRooms()); if (event.getValue()) { if (!hasChip(eventChip)) addChip(eventChip, true); if (hasChip(allChip)) removeChip(allChip, true); } else { if (hasChip(eventChip)) removeChip(eventChip, true); if (!hasChip(allChip)) addChip(allChip, true); } } }); events.addMouseDownHandler(new MouseDownHandler() { @Override public void onMouseDown(MouseDownEvent event) { event.getNativeEvent().stopPropagation(); event.getNativeEvent().preventDefault(); } }); addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { iLastSize = getChip("size"); if (!isFilterPopupShowing()) { nearby.setValue(hasChip(new Chip("flag", "Nearby").withTranslatedCommand(MESSAGES.tagRoomFlag()) .withTranslatedValue(MESSAGES.attrFlagNearbyRooms()))); events.setValue(hasChip(new Chip("flag", "Event").withTranslatedCommand(MESSAGES.tagRoomFlag()) .withTranslatedValue(MESSAGES.attrFlagEventRooms()))); Chip size = getChip("size"); if (size != null) { if (size.getValue().startsWith("<=")) { iMin.setText(""); iMax.setText(size.getValue().substring(2)); } else if (size.getValue().startsWith("<")) { try { iMax.setText(String.valueOf(Integer.parseInt(size.getValue().substring(1)) - 1)); iMin.setText(""); } catch (Exception e) { } } else if (size.getValue().startsWith(">=")) { iMin.setText(size.getValue().substring(2)); iMax.setText(""); } else if (size.getValue().startsWith(">")) { try { iMin.setText(String.valueOf(Integer.parseInt(size.getValue().substring(1)) + 1)); iMax.setText(""); } catch (Exception e) { } } else if (size.getValue().contains("..")) { iMin.setText(size.getValue().substring(0, size.getValue().indexOf(".."))); iMax.setText(size.getValue().substring(size.getValue().indexOf("..") + 2)); } else { iMin.setText(size.getValue()); iMax.setText(size.getValue()); } } else { iMin.setText(""); iMax.setText(""); } for (int i = 0; i < iBuildings.getItemCount(); i++) { String value = iBuildings.getValue(i); iBuildings.setItemSelected(i, hasChip(new Chip("building", value).withTranslatedCommand(MESSAGES.tagBuilding()))); } iDepartments.setSelectedIndex(0); for (int i = 1; i < iDepartments.getItemCount(); i++) { String value = iDepartments.getValue(i); if (hasChip( new Chip("department", value).withTranslatedCommand(MESSAGES.tagDepartment()))) { iDepartments.setSelectedIndex(i); break; } } } if (getAcademicSessionId() != null) init(false, getAcademicSessionId(), new Command() { @Override public void execute() { if (isFilterPopupShowing()) showFilterPopup(); } }); setAriaLabel(ARIA.roomFilter(toAriaString())); } }); addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { setAriaLabel(ARIA.roomFilter(toAriaString())); } }); }
From source file:org.unitime.timetable.gwt.client.events.SingleDateSelector.java
License:Apache License
private SingleDateSelector(AriaTextBox text, AcademicSessionProvider session, boolean hint) { super(text);// ww w. ja v a 2s . c om iPicker = getWidget(); iAcademicSession = session; iHint = hint; if (iHint) setHint(iFormat.getPattern().toUpperCase()); iPicker.setStyleName("gwt-SuggestBox"); iPicker.addStyleName("unitime-DateSelectionBox"); iPicker.setAriaLabel(null); iMonth = new SingleMonth(new Date()) { @Override protected void init() { super.init(); if (iPopup != null && iPopup.isShowing() && getValue() != null) { AriaStatus.getInstance().setText(ARIA.singleDateCursor( DateTimeFormat.getFormat(CONSTANTS.singleDateSelectionFormat()).format(getValue()))); } } }; AbsolutePanel panel = new AbsolutePanel(); panel.setStyleName("unitime-DateSelector"); panel.add(iMonth); iPopup = new PopupPanel(true, false); iPopup.setPreviewingAllNativeEvents(true); iPopup.setStyleName("unitime-DateSelectionBoxPopup"); iPopup.setWidget(panel); iPicker.addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { iPopup.showRelativeTo(iPicker); } }); iPicker.addBlurHandler(new BlurHandler() { @Override public void onBlur(BlurEvent event) { if (iPopup.isShowing()) iPopup.hide(); } }); iPicker.addKeyDownHandler(new KeyDownHandler() { @Override public void onKeyDown(KeyDownEvent event) { if (iPopup.isShowing()) { switch (event.getNativeEvent().getKeyCode()) { case KeyCodes.KEY_UP: iMonth.addDays(-7); event.preventDefault(); event.stopPropagation(); break; case KeyCodes.KEY_DOWN: iMonth.addDays(+7); event.preventDefault(); event.stopPropagation(); break; case KeyCodes.KEY_RIGHT: if (iPicker.getCursorPos() == iPicker.getText().length()) { iMonth.addDays(+1); event.preventDefault(); event.stopPropagation(); } break; case KeyCodes.KEY_LEFT: if (iPicker.getCursorPos() == 0) { iMonth.addDays(-1); event.preventDefault(); event.stopPropagation(); } break; case KeyCodes.KEY_PAGEUP: iMonth.addMonths(-1); event.preventDefault(); event.stopPropagation(); break; case KeyCodes.KEY_PAGEDOWN: iMonth.addMonths(+1); event.preventDefault(); event.stopPropagation(); break; case KeyCodes.KEY_ESCAPE: event.preventDefault(); event.stopPropagation(); iPopup.hide(); break; case KeyCodes.KEY_ENTER: if (iMonth.getValue() != null) { iPicker.setText(iFormat.format(iMonth.getValue())); ValueChangeEvent.fire(SingleDateSelector.this, getValue()); AriaStatus.getInstance().setText(ARIA.singleDateSelected(DateTimeFormat .getFormat(CONSTANTS.singleDateSelectionFormat()).format(getValue()))); } event.preventDefault(); event.stopPropagation(); iPopup.hide(); break; } } else { if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_DOWN && (event.getNativeEvent().getAltKey() || iPicker.getCursorPos() == iPicker.getText().length())) { try { iMonth.setValue(iFormat.parse(iPicker.getText())); } catch (Exception e) { } iPopup.showRelativeTo(iPicker); if (iMonth.getValue() != null) { AriaStatus.getInstance() .setText(ARIA.singleDatePopupOpenedDateSelected(ARIA.singleDateCursor( DateTimeFormat.getFormat(CONSTANTS.singleDateSelectionFormat()) .format(iMonth.getValue())))); } else { AriaStatus.getInstance() .setText(ARIA.singleDatePopupOpenedNoDateSelected(iMonth.getCalendarTitle())); } event.preventDefault(); event.stopPropagation(); } } } }); iMonth.addValueChangeHandler(new ValueChangeHandler<Date>() { @Override public void onValueChange(ValueChangeEvent<Date> event) { if (event.getValue() != null) { iPicker.setText(iFormat.format(iMonth.getValue())); if (iPopup.isShowing()) iPopup.hide(); ValueChangeEvent.fire(SingleDateSelector.this, event.getValue()); } } }); iPicker.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent event) { MatchResult match = iRegExp[0].exec(iPicker.getText()); int month = -1, day = -1, year = -1; if (match != null) { month = Integer.parseInt(match.getGroup(1)); day = (match.getGroup(2).isEmpty() ? 1 : Integer.parseInt(match.getGroup(2))); year = (match.getGroup(3).isEmpty() ? -1 : Integer.parseInt(match.getGroup(3))); } else { match = iRegExp[1].exec(iPicker.getText()); if (match != null) { day = Integer.parseInt(match.getGroup(1)); month = (match.getGroup(2).isEmpty() ? -1 : Integer.parseInt(match.getGroup(2))); year = (match.getGroup(3).isEmpty() ? -1 : Integer.parseInt(match.getGroup(3))); } } if (year <= 99 && month >= 0 && iMonth.getMonths() != null) { for (SessionMonth m : iMonth.getMonths()) { if (m.getMonth() + 1 == month) { if (year < 0 || year == m.getYear() + 1900 || year == m.getYear() + 2000) { year = m.getYear(); } } } } if (year < 0) { year = Integer.parseInt(DateTimeFormat.getFormat("yyyy").format(new Date())); } else if (year <= 99) { year += 2000; } if (year >= 0 && month >= 1 && month <= 12 && day >= 1) { iMonth.setDate(year, month, day); setValue(iMonth.getValue()); ValueChangeEvent.fire(SingleDateSelector.this, getValue()); return; } Date date = null; try { date = iFormat.parse(iPicker.getText()); } catch (Exception e) { } iMonth.setValue(date); setValue(date == null ? null : iMonth.getValue()); ValueChangeEvent.fire(SingleDateSelector.this, getValue()); } }); if (iAcademicSession != null) { iAcademicSession.addAcademicSessionChangeHandler(new AcademicSessionChangeHandler() { @Override public void onAcademicSessionChange(AcademicSessionChangeEvent event) { if (event.isChanged()) init(event.getNewAcademicSessionId()); } }); Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { init(iAcademicSession.getAcademicSessionId()); } }); } }
From source file:org.unitime.timetable.gwt.client.widgets.CourseRequestBox.java
License:Apache License
public CourseRequestBox(boolean showCourses, SpecialRegistrationContext specreg) { super("unitime-CourseRequestBox"); iShowCourses = showCourses;//from www. j a v a 2s .c o m iSpecReg = specreg; iFilter = new CourseRequestFilterBox(new ClickHandler() { @Override public void onClick(ClickEvent event) { // if (isEnabled()) openDialogAsync(); } }) { @Override protected void applySuggestion(Suggestion suggestion) { if (suggestion instanceof CourseSuggestion) { CourseRequestBox.this.setValue(((CourseSuggestion) suggestion).getRequestedCourse()); } else { super.applySuggestion(suggestion); } } }; add(iFilter); iFilter.addFilter(new FilterBox.StaticSimpleFilter("method", MESSAGES.tagInstructionalMethod())); iFilter.addFilter(new FilterBox.StaticSimpleFilter("section", MESSAGES.tagSection())); iFilter.setSuggestionsProvider(new SuggestionsProvider() { @Override public void getSuggestions(List<Chip> chips, final String text, final AsyncCallback<Collection<Suggestion>> callback) { if (text.equals(getHint())) return; if (iLastCourse != null && iLastCourse.isCourse() && text.startsWith(iLastCourse.getCourseName() + " ") && iValidCourseNames.containsKey(iLastCourse.getCourseName().toLowerCase())) { final CourseAssignment course = iValidCourseNames .get(iLastCourse.getCourseName().toLowerCase()); final String query = text.substring(iLastCourse.getCourseName().length() + 1).trim(); iSectionProvider.getData(course, new AsyncCallback<Collection<ClassAssignment>>() { @Override public void onFailure(Throwable caught) { callback.onFailure(caught); } @Override public void onSuccess(Collection<ClassAssignment> result) { List<Suggestion> suggestions = new ArrayList<Suggestion>(); if (course.hasInstructionalMethods()) { for (IdValue im : course.getInstructionalMethods()) { if (im.getValue().toLowerCase().startsWith(query.toLowerCase())) { suggestions.add(new CourseSuggestion(course, im, false)); if (iSpecReg == null || iSpecReg.isCanRequire()) suggestions.add(new CourseSuggestion(course, im, true)); } else if ((im.getValue() + "!").equalsIgnoreCase(query) && (iSpecReg == null || iSpecReg.isCanRequire())) { suggestions.add(new CourseSuggestion(course, im, true)); } } } for (ClassAssignment clazz : result) { if (clazz.isCancelled() || (!clazz.isSaved() && !clazz.isAvailable() && !isSpecialRegistration())) continue; if (clazz.getSection().equalsIgnoreCase(query) || clazz.getSelection().getText().equalsIgnoreCase(query)) { suggestions.add(new CourseSuggestion(course, clazz, false)); if (iSpecReg == null || iSpecReg.isCanRequire()) suggestions.add(new CourseSuggestion(course, clazz, true)); } else if (((clazz.getSection() + "!").equalsIgnoreCase(query) || (clazz.getSelection().getText() + "!").equalsIgnoreCase(query)) && (iSpecReg == null || iSpecReg.isCanRequire())) { suggestions.add(new CourseSuggestion(course, clazz, true)); } else if (clazz.getSection().toLowerCase().startsWith(query.toLowerCase()) || clazz .getSelection().getText().toLowerCase().startsWith(query.toLowerCase())) { suggestions.add(new CourseSuggestion(course, clazz, false)); } else if (clazz .getTimeString(CONSTANTS.shortDays(), CONSTANTS.useAmPm(), MESSAGES.arrangeHours()) .toLowerCase().startsWith(query.toLowerCase())) suggestions.add(new CourseSuggestion(course, clazz, false)); else if (clazz.hasInstructors()) for (String instructor : clazz.getInstructors()) if (instructor.toLowerCase().startsWith(query.toLowerCase())) { suggestions.add(new CourseSuggestion(course, clazz, false)); break; } } callback.onSuccess(suggestions); } }); return; } iDataProvider.getData(text, new AsyncCallback<Collection<CourseAssignment>>() { @Override public void onFailure(Throwable caught) { iValidCourseNames.clear(); if (iFreeTimeParser != null) { iFreeTimeParser.getData(text, new AsyncCallback<List<FreeTime>>() { @Override public void onFailure(Throwable e) { callback.onFailure(e); } @Override public void onSuccess(List<FreeTime> freeTimes) { String ft = iFreeTimeParser.freeTimesToString(freeTimes); List<Suggestion> suggestions = new ArrayList<Suggestion>(); Suggestion suggestion = new Suggestion(ft, ft, MESSAGES.hintFreeTimeRequest()); suggestions.add(suggestion); callback.onSuccess(suggestions); } }); } else { callback.onFailure(caught); } } @Override public void onSuccess(Collection<CourseAssignment> result) { iValidCourseNames.clear(); List<Suggestion> suggestions = new ArrayList<Suggestion>(); if (result != null) for (CourseAssignment course : result) { Suggestion suggestion = new CourseSuggestion(course); suggestions.add(suggestion); iValidCourseNames.put(suggestion.getReplacementString().toLowerCase(), course); if (course.getClassAssignments() != null) { for (ClassAssignment clazz : course.getClassAssignments()) suggestions.add(new CourseSuggestion(course, clazz, false)); } if (result.size() <= 5 && course.hasInstructionalMethodSelection()) { for (IdValue im : course.getInstructionalMethods()) { suggestions.add(new CourseSuggestion(course, im, false)); } } } callback.onSuccess(suggestions); } }); } }); iError = new HTML(); iError.setStyleName("unitime-ErrorHint"); iError.setVisible(false); Roles.getPresentationRole().setAriaHiddenState(iError.getElement(), true); add(iError); iFilter.getValueBox().addBlurHandler(new BlurHandler() { public void onBlur(BlurEvent event) { if (getText().isEmpty() && iError.isVisible()) iError.setVisible(false); } }); iFilter.getValueBox().addFocusHandler(new FocusHandler() { public void onFocus(FocusEvent event) { if (iError.isVisible() && !iError.getText().isEmpty()) AriaStatus.getInstance().setText(iError.getText()); } }); iFilter.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { String value = iFilter.getText(); if (iLastCourse == null || !iLastCourse.isCourse() || !value.startsWith(iLastCourse.getCourseName())) { iFilter.removeAllChips(); } else if (!value.equals(iLastCourse.getCourseName())) { iFilter.setText(iLastCourse.getCourseName()); } iFilter.resizeFilterIfNeeded(); CourseSelectionEvent.fire(CourseRequestBox.this, getValue()); } }); iFilter.addSelectionHandler(new SelectionHandler<FilterBox.Suggestion>() { @Override public void onSelection(SelectionEvent<Suggestion> event) { iLastCourse = getValue(); } }); }
From source file:org.unitime.timetable.gwt.client.widgets.CourseSelectionSuggestBox.java
License:Apache License
public CourseSelectionSuggestBox(boolean showCourses, boolean showDefaultSuggestions) { iShowCourses = showCourses;//w ww . j a v a 2s .c o m iShowDefaultSuggestions = showDefaultSuggestions; SuggestOracle courseOfferingOracle = new SuggestOracle() { public void requestSuggestions(Request request, Callback callback) { if (request.getQuery().equals(iHint)) return; iDataProvider.getData(request.getQuery(), new SuggestCallback(request, callback)); } public void requestDefaultSuggestions(Request request, Callback callback) { if (iShowDefaultSuggestions) iDataProvider.getData("", new SuggestCallback(request, callback)); else super.requestDefaultSuggestions(request, callback); } public boolean isDisplayStringHTML() { return true; } }; iSuggest = new AriaSuggestBox(courseOfferingOracle); iSuggest.setStyleName("unitime-TextBoxHint"); iFinderButton = new ImageButton(RESOURCES.search_picker(), RESOURCES.search_picker_Down(), RESOURCES.search_picker_Over(), RESOURCES.search_picker_Disabled()); iFinderButton.setTabIndex(-1); iVPanel = new VerticalPanel(); iHPanel = new HorizontalPanel(); iHPanel.add(iSuggest); iHPanel.add(iFinderButton); iVPanel.add(iHPanel); iError = new Label(); iError.setStyleName("unitime-ErrorHint"); iError.setVisible(false); Roles.getPresentationRole().setAriaHiddenState(iError.getElement(), true); iVPanel.add(iError); iFinderButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { if (iSuggest.isEnabled()) { openDialogAsync(); } } }); iSuggest.addSelectionHandler(new SelectionHandler<Suggestion>() { public void onSelection(SelectionEvent<Suggestion> event) { String text = event.getSelectedItem().getReplacementString(); iLastSuggestion = text; CourseSelectionEvent.fire(CourseSelectionSuggestBox.this, text, !text.isEmpty()); } }); iSuggest.getValueBox().addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { boolean valid = false; String text = iSuggest.getText(); if (text.equalsIgnoreCase(iLastSuggestion)) valid = true; else for (String course : iValidCourseNames) { if (course.equalsIgnoreCase(text)) { valid = true; break; } } CourseSelectionEvent.fire(CourseSelectionSuggestBox.this, text, valid); } }); iSuggest.getValueBox().addKeyDownHandler(new KeyDownHandler() { public void onKeyDown(KeyDownEvent event) { if (!iSuggest.isEnabled()) return; if ((event.getNativeEvent().getKeyCode() == 'F' || event.getNativeEvent().getKeyCode() == 'f') && (event.isControlKeyDown() || event.isAltKeyDown())) { iSuggest.hideSuggestionList(); openDialogAsync(); } if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) { iSuggest.hideSuggestionList(); } if ((event.getNativeEvent().getKeyCode() == 'L' || event.getNativeEvent().getKeyCode() == 'l') && (event.isControlKeyDown() || event.isAltKeyDown())) { iSuggest.showSuggestionList(); } } }); iSuggest.getValueBox().addBlurHandler(new BlurHandler() { public void onBlur(BlurEvent event) { if (iSuggest.getText().isEmpty()) { if (iError.isVisible()) iError.setVisible(false); if (!iHint.isEmpty()) { iSuggest.setText(iHint); iSuggest.setStyleName("unitime-TextBoxHint"); } } } }); iSuggest.getValueBox().addFocusHandler(new FocusHandler() { public void onFocus(FocusEvent event) { iSuggest.setStyleName("gwt-SuggestBox"); if (!iHint.isEmpty() && iSuggest.getText().equals(iHint)) iSuggest.setText(""); if (!iError.getText().isEmpty()) AriaStatus.getInstance().setText(iError.getText()); } }); initWidget(iVPanel); }