List of usage examples for com.google.gwt.user.client.ui CheckBox addValueChangeHandler
@Override
public HandlerRegistration addValueChangeHandler(ValueChangeHandler<Boolean> handler)
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/*from w w w . ja va 2s . c om*/ 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.rooms.RoomEdit.java
License:Apache License
public void setProperties(RoomPropertiesInterface properties) { iProperties = properties;//from ww w . j a va2 s . co m iForm.setColSpan(iProperties.isGoogleMap() ? 3 : 2); iBuilding.getWidget().clear(); iBuilding.getWidget().addItem(MESSAGES.itemSelect(), "-1"); for (BuildingInterface building : iProperties.getBuildings()) iBuilding.getWidget().addItem(building.getAbbreviation() + " - " + building.getName(), building.getId().toString()); iCoordinatesFormat.setText(iProperties.getEllipsoid()); iExaminationRooms.clear(); iExaminationRoomsPanel.clear(); for (final ExamTypeInterface type : iProperties.getExamTypes()) { final CheckBox ch = new CheckBox(type.getLabel()); ch.addStyleName("exam"); iExaminationRooms.put(type.getId(), ch); iExaminationRoomsPanel.add(ch); ch.setValue(false); ch.addValueChangeHandler(new ValueChangeHandler<Boolean>() { @Override public void onValueChange(ValueChangeEvent<Boolean> event) { Integer row = iPeriodPreferencesRow.get(type.getId()); if (row != null) { PeriodPreferencesWidget pref = iPeriodPreferences.get(type.getId()); iForm.getRowFormatter().setVisible(row, event.getValue() && pref != null && pref.getModel() != null && !pref.getModel().getPeriods().isEmpty()); } boolean prefVisible = false; for (ExamTypeInterface t : iProperties.getExamTypes()) { if (iExaminationRooms.get(t.getId()).getValue()) { PeriodPreferencesWidget pref = iPeriodPreferences.get(t.getId()); if (pref != null && pref.getModel() != null && !pref.getModel().getPeriods().isEmpty()) { prefVisible = true; break; } } } if (iPeriodPreferencesHeaderRow > 0) iForm.getRowFormatter().setVisible(iPeriodPreferencesHeaderRow, prefVisible); if (!event.getValue()) { iExamCapacity.clearHint(); iHeader.clearMessage(); } } }); } if (iProperties.isGoogleMap() && iGoogleMap == null) { iGoogleMap = new AbsolutePanel(); iGoogleMap.setStyleName("map"); iGoogleMapControl = new AbsolutePanel(); iGoogleMapControl.setStyleName("control"); final TextBox searchBox = new TextBox(); searchBox.setStyleName("unitime-TextBox"); searchBox.addStyleName("searchBox"); searchBox.getElement().setId("mapSearchBox"); searchBox.setTabIndex(-1); iGoogleMapControl.add(searchBox); Button button = new Button(MESSAGES.buttonGeocode(), new ClickHandler() { @Override public void onClick(ClickEvent event) { geocodeAddress(); } }); button.setTabIndex(-1); searchBox.addKeyPressHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { switch (event.getNativeEvent().getKeyCode()) { case KeyCodes.KEY_ENTER: event.preventDefault(); geocodeAddress(); return; } } }); button.addStyleName("geocode"); ToolBox.setWhiteSpace(button.getElement().getStyle(), "nowrap"); Character accessKey = UniTimeHeaderPanel.guessAccessKey(MESSAGES.buttonGeocode()); if (accessKey != null) button.setAccessKey(accessKey); iGoogleMapControl.add(button); iGoogleMap.add(iGoogleMapControl); addGoogleMap(iGoogleMap.getElement(), iGoogleMapControl.getElement()); } iGroups.clear(); iGroupPanel.clear(); iGlobalGroupsPanel = null; if (!iProperties.getGroups().isEmpty()) { P groups = new P("groups"); for (GroupInterface group : iProperties.getGroups()) { CheckBox ch = new CheckBox(group.getLabel()); ch.addStyleName("group"); iGroups.put(group.getId(), ch); if (group.getDepartment() != null) { P d = iGroupPanel.get(group.getDepartment().getId()); if (d == null) { d = new P("groups"); d.setWidth("100%"); iGroupPanel.put(group.getDepartment().getId(), d); } d.add(ch); } else { groups.add(ch); } } if (groups.getWidgetCount() > 0) { iGlobalGroupsPanel = groups; } } iFeatures.clear(); if (!iProperties.getFeatures().isEmpty()) { for (FeatureInterface feature : iProperties.getFeatures()) { CheckBox ch = new CheckBox(feature.getTitle()); ch.addStyleName("feature"); iFeatures.put(feature.getId(), ch); } } iPeriodPreferences.clear(); for (ExamTypeInterface type : iProperties.getExamTypes()) { PeriodPreferencesWidget pref = new PeriodPreferencesWidget(true); iPeriodPreferences.put(type.getId(), pref); } }
From source file:org.unitime.timetable.gwt.client.rooms.RoomEdit.java
License:Apache License
public void setRoom(RoomDetailInterface room) { iRoom = room;/*w w w . j a v a2 s.c om*/ if (iRoom == null) { iRoom = new RoomDetailInterface(); iRoom.setSessionId(iProperties.getAcademicSessionId()); iRoom.setSessionName(iProperties.getAcademicSessionName()); iHeader.setEnabled("create", true); iHeader.setEnabled("update", false); iHeader.setEnabled("delete", false); } else { iHeader.setEnabled("create", false); iHeader.setEnabled("update", true); iHeader.setEnabled("delete", iRoom.isCanDelete()); } iLastControllingDept = iRoom.getControlDepartment(); iLastEventDept = iRoom.getEventDepartment(); iForm.clear(); iHeader.clearMessage(); iForm.addHeaderRow(iHeader); int firstRow = iForm.getRowCount(); if (iMode.hasSessionSelection()) { iForm.addRow(MESSAGES.propAcademicSession(), new Label( iRoom.hasSessionName() ? iRoom.getSessionName() : iProperties.getAcademicSessionName()), 1); } if (iRoom.getRoomType() == null || iRoom.isCanChangeType()) { iType.clearHint(); iType.getWidget().clear(); if (iRoom.getRoomType() == null) { iType.getWidget().addItem(MESSAGES.itemSelect(), "-1"); for (RoomTypeInterface type : iProperties.getRoomTypes()) { if (type.isRoom() && iProperties.isCanAddRoom()) iType.getWidget().addItem(type.getLabel(), type.getId().toString()); else if (!type.isRoom() && iProperties.isCanAddNonUniversity()) iType.getWidget().addItem(type.getLabel(), type.getId().toString()); } iType.getWidget().setSelectedIndex(0); } else { for (RoomTypeInterface type : iProperties.getRoomTypes()) { if (type.isRoom() && iRoom.getBuilding() != null) iType.getWidget().addItem(type.getLabel(), type.getId().toString()); else if (!type.isRoom() && iRoom.getBuilding() == null) iType.getWidget().addItem(type.getLabel(), type.getId().toString()); } for (int i = 0; i < iType.getWidget().getItemCount(); i++) { if (iType.getWidget().getValue(i).equals(iRoom.getRoomType().getId().toString())) { iType.getWidget().setSelectedIndex(i); break; } } } iForm.addRow(MESSAGES.propRoomType(), iType, 1); } else { iForm.addRow(MESSAGES.propRoomType(), new Label(iRoom.getRoomType().getLabel(), false), 1); } if (iRoom.getUniqueId() != null && iRoom.getBuilding() == null) { iBuildingRow = -1; } else if (iRoom.getUniqueId() == null || iRoom.isCanChangeRoomProperties()) { iBuilding.clearHint(); if (iRoom.getBuilding() == null) { iBuilding.getWidget().setSelectedIndex(0); } else { iBuilding.getWidget().setSelectedIndex(1 + iProperties.getBuildings().indexOf(iRoom.getBuilding())); } iBuildingRow = iForm.addRow(MESSAGES.propBuilding(), iBuilding, 1); } else { iBuildingRow = iForm.addRow(MESSAGES.propBuilding(), new Label(iRoom.getBuilding().getAbbreviation() + " - " + iRoom.getBuilding().getName()), 1); } if (iRoom.getUniqueId() == null || iRoom.isCanChangeRoomProperties()) { iName.clearHint(); iName.getWidget().setText(iRoom.getName() == null ? "" : iRoom.getName()); iForm.addRow(iNameLabel, iName, 1); } else { iForm.addRow(iNameLabel, new Label(iRoom.getName()), 1); } if (iRoom.getRoomType() == null || iRoom.isCanChangeType()) { typeChanged(); } else { if (iBuildingRow >= 0) iForm.getRowFormatter().setVisible(iBuildingRow, iRoom.getRoomType() != null && iRoom.getRoomType().isRoom()); iNameLabel .setText(iRoom.getRoomType() != null && iRoom.getRoomType().isRoom() ? MESSAGES.propRoomNumber() : MESSAGES.propRoomName()); } if (iRoom.getUniqueId() == null || iRoom.isCanChangeRoomProperties()) { iDisplayName.setText(iRoom.getDisplayName() == null ? "" : iRoom.getDisplayName()); iForm.addRow(MESSAGES.propDisplayName(), iDisplayName, 1); } else if (iRoom.hasDisplayName()) { iForm.addRow(MESSAGES.propDisplayName(), new Label(iRoom.getDisplayName()), 1); } if ((iRoom.getUniqueId() == null && iProperties.isCanChangeExternalId()) || iRoom.isCanChangeExternalId()) { iExternalId.setText(iRoom.getExternalId() == null ? "" : iRoom.getExternalId()); iForm.addRow(MESSAGES.propExternalId(), iExternalId, 1); } else if (iRoom.hasExternalId()) { iForm.addRow(MESSAGES.propExternalId(), new Label(iRoom.getExternalId()), 1); } if (iRoom.getUniqueId() == null || iRoom.isCanChangeCapacity()) { iCapacity.clearHint(); iCapacity.getWidget().setValue(iRoom.getCapacity()); iForm.addRow(MESSAGES.propCapacity(), iCapacity, 1); } else if (iRoom.getCapacity() != null) { iForm.addRow(MESSAGES.propCapacity(), new Label(iRoom.getCapacity().toString()), 1); } if ((iRoom.getUniqueId() == null && iProperties.isCanChangeControll()) || iRoom.isCanChangeControll()) { iControllingDepartment.clearHint(); iControllingDepartment.getWidget().clear(); iControllingDepartment.getWidget().addItem(MESSAGES.itemNoControlDepartment(), "-1"); for (DepartmentInterface department : iProperties.getDepartments()) iControllingDepartment.getWidget().addItem( department.getExtAbbreviationOrCode() + " - " + department.getExtLabelWhenExist(), department.getId().toString()); if (iRoom.getControlDepartment() == null) { iControllingDepartment.getWidget().setSelectedIndex(0); } else { int index = iProperties.getDepartments().indexOf(iRoom.getControlDepartment()); if (index >= 0) { iControllingDepartment.getWidget().setSelectedIndex(1 + index); } else { iControllingDepartment.getWidget().addItem( iRoom.getControlDepartment().getExtAbbreviationOrCode() + " - " + iRoom.getControlDepartment().getExtLabelWhenExist(), iRoom.getControlDepartment().getId().toString()); iControllingDepartment.getWidget() .setSelectedIndex(iControllingDepartment.getWidget().getItemCount() - 1); } } if (iRoom.getUniqueId() == null && iControllingDepartment.getWidget().getItemCount() == 2) iControllingDepartment.getWidget().setSelectedIndex(1); iForm.addRow(MESSAGES.propControllingDepartment(), iControllingDepartment, 1); /* } else if (iRoom.getUniqueId() == null) { iControllingDepartment.getWidget().clear(); for (DepartmentInterface department: iProperties.getDepartments()) iControllingDepartment.getWidget().addItem(department.getExtAbbreviationOrCode() + " - " + department.getExtLabelWhenExist(), department.getId().toString()); //TODO: guess selected department from filter iForm.addRow(MESSAGES.propDepartment(), iControllingDepartment, 1);*/ } else if (iRoom.getControlDepartment() != null && iProperties.isCanSeeCourses()) { iForm.addRow(MESSAGES.propControllingDepartment(), new Label(RoomDetail.toString(iRoom.getControlDepartment())), 1); } if (iRoom.getUniqueId() == null || iRoom.isCanChangeRoomProperties()) { iX.setValue(iRoom.getX()); iY.setValue(iRoom.getY()); iForm.addRow(MESSAGES.propCoordinates(), iCoordinates, 1); iArea.setValue(iRoom.getArea()); iAreaFormat.setText(iProperties != null && iProperties.isRoomAreaInMetricUnits() ? CONSTANTS.roomAreaMetricUnitsLong() : CONSTANTS.roomAreaUnitsLong()); iForm.addRow(MESSAGES.propRoomArea(), iAreaPanel, 1); if (iProperties.isCanSeeCourses()) { iDistanceCheck.setValue(!iRoom.isIgnoreTooFar()); distanceCheckChanged(); iForm.addRow(MESSAGES.propDistanceCheck(), iDistanceCheck, 1); } iRoomCheck.setValue(!iRoom.isIgnoreRoomCheck()); roomCheckChanged(); iForm.addRow(MESSAGES.propRoomCheck(), iRoomCheck, 1); if (iGoogleMapControl != null) iGoogleMapControl.setVisible(true); } else { if (iRoom.hasCoordinates()) if (iProperties != null && iProperties.hasEllipsoid()) iForm.addRow(MESSAGES.propCoordinates(), new HTML(MESSAGES .coordinatesWithEllipsoid(iRoom.getX(), iRoom.getY(), iProperties.getEllipsoid())), 1); else iForm.addRow(MESSAGES.propCoordinates(), new HTML(MESSAGES.coordinates(iRoom.getX(), iRoom.getY())), 1); if (iRoom.getArea() != null) iForm.addRow(MESSAGES.propRoomArea(), new HTML(MESSAGES.roomArea(iRoom.getArea()) + " " + (iProperties != null && iProperties.isRoomAreaInMetricUnits() ? CONSTANTS.roomAreaMetricUnitsShort() : CONSTANTS.roomAreaUnitsShort())), 1); if (iProperties.isCanSeeCourses()) { iForm.addRow(MESSAGES.propDistanceCheck(), new Check(!room.isIgnoreTooFar(), MESSAGES.infoDistanceCheckOn(), MESSAGES.infoDistanceCheckOff()), 1); iForm.addRow(MESSAGES.propRoomCheck(), new Check(!room.isIgnoreRoomCheck(), MESSAGES.infoRoomCheckOn(), MESSAGES.infoRoomCheckOff()), 1); } else if (iProperties.isCanSeeEvents()) { iForm.addRow(MESSAGES.propRoomCheck(), new Check(!room.isIgnoreRoomCheck(), MESSAGES.infoRoomCheckOn(), MESSAGES.infoRoomCheckOff()), 1); } if (iGoogleMapControl != null) iGoogleMapControl.setVisible(false); } if ((iRoom.getUniqueId() == null && iProperties.isCanChangeExamStatus()) || iRoom.isCanChangeExamStatus()) { for (Map.Entry<Long, CheckBox> e : iExaminationRooms.entrySet()) e.getValue().setValue(false); if (iRoom.hasExamTypes()) { for (ExamTypeInterface type : iRoom.getExamTypes()) iExaminationRooms.get(type.getId()).setValue(true); } iForm.addRow(MESSAGES.propExamRooms(), iExaminationRoomsPanel, 1); iExamCapacity.getWidget().setValue(iRoom.getExamCapacity()); iForm.addRow(MESSAGES.propExamCapacity(), iExamCapacity, 1); } else if (iProperties.isCanSeeExams() && (iRoom.getExamCapacity() != null || iRoom.hasExamTypes())) { iForm.addRow(MESSAGES.propExamCapacity(), new RoomDetail.ExamSeatingCapacityLabel(iRoom), 1); } if ((iRoom.getUniqueId() == null && iProperties.isCanChangeEventProperties()) || iRoom.isCanChangeEventProperties()) { iEventDepartment.clear(); if ((iRoom.getUniqueId() == null && iProperties.isCanChangeControll()) || (iRoom.getUniqueId() != null && (iRoom.getEventDepartment() == null || iRoom.isCanChangeControll()))) { iEventDepartment.addItem(MESSAGES.itemNoEventDepartment(), "-1"); } for (DepartmentInterface department : iProperties.getDepartments()) if (department.isEvent()) iEventDepartment.addItem(department.getDeptCode() + " - " + department.getLabel(), department.getId().toString()); if (iRoom.getEventDepartment() == null) { iEventDepartment.setSelectedIndex(0); } else { iEventDepartment.setSelectedIndex(0); for (int i = 1; i < iEventDepartment.getItemCount(); i++) { if (iEventDepartment.getValue(i).equals(iRoom.getEventDepartment().getId().toString())) { iEventDepartment.setSelectedIndex(i); break; } } if (iRoom.getEventDepartment() != null && "-1".equals(iEventDepartment.getValue(iEventDepartment.getSelectedIndex()))) { iEventDepartment.addItem( iRoom.getEventDepartment().getDeptCode() + " - " + iRoom.getEventDepartment().getLabel(), iRoom.getEventDepartment().getId().toString()); iEventDepartment.setSelectedIndex(iEventDepartment.getItemCount() + -1); } } iForm.addRow(MESSAGES.propEventDepartment(), iEventDepartment, 1); iEventStatus.getWidget() .setSelectedIndex(iRoom.getEventStatus() == null ? 0 : iRoom.getEventStatus() + 1); iEventStatus.clearHint(); iForm.addRow(MESSAGES.propEventStatus(), iEventStatus, 1); iNote.getWidget().setText(iRoom.getEventNote() == null ? "" : iRoom.getEventNote()); iForm.addRow(MESSAGES.propEventNote(), iNote, 1); iBreakTime.setValue(iRoom.getBreakTime()); iForm.addRow(MESSAGES.propBreakTime(), iBreakTimePanel, 1); } else if (iProperties.isCanSeeEvents()) { if (iRoom.getEventDepartment() != null) iForm.addRow(MESSAGES.propEventDepartment(), new Label(RoomDetail.toString(iRoom.getEventDepartment(), true)), 1); if (iRoom.getEventStatus() != null || iRoom.getDefaultEventStatus() != null) { Label status = new Label( CONSTANTS.eventStatusName()[iRoom.getEventStatus() == null ? iRoom.getDefaultEventStatus() : iRoom.getEventStatus()]); if (iRoom.getEventStatus() == null) status.addStyleName("default"); iForm.addRow(MESSAGES.propEventStatus(), status, 1); } if (iRoom.hasEventNote() || iRoom.hasDefaultEventNote()) { HTML note = new HTML(iRoom.hasEventNote() ? iRoom.getEventNote() : iRoom.getDefaultEventNote()); if (!iRoom.hasEventNote()) note.addStyleName("default"); iForm.addRow(MESSAGES.propEventNote(), note, 1); } if (iRoom.getBreakTime() != null || iRoom.getDefaultBreakTime() != null) { Label bt = new Label( (iRoom.getBreakTime() == null ? iRoom.getDefaultBreakTime() : iRoom.getBreakTime()) .toString()); if (iRoom.getBreakTime() == null) bt.addStyleName("default"); iForm.addRow(MESSAGES.propBreakTime(), bt, 1); } } if (iProperties.isGoogleMap()) { iForm.setWidget(firstRow, 2, iGoogleMap); iForm.getFlexCellFormatter().setRowSpan(firstRow, 2, iForm.getRowCount() - firstRow - 1); } if (((iRoom.getUniqueId() == null && iProperties.isCanChangeGroups()) || iRoom.isCanChangeGroups()) && !iProperties.getGroups().isEmpty()) { iForm.addHeaderRow(MESSAGES.headerRoomGroups()); for (Map.Entry<Long, CheckBox> e : iGroups.entrySet()) e.getValue().setValue(iRoom.hasGroup(e.getKey())); if (iGlobalGroupsPanel != null) { iForm.addRow(MESSAGES.propGlobalGroups(), iGlobalGroupsPanel); } else { List<GroupInterface> globalGroups = iRoom.getGlobalGroups(); if (!globalGroups.isEmpty()) iForm.addRow(MESSAGES.propGlobalGroups(), new RoomDetail.GroupsCell(globalGroups), 1); } for (DepartmentInterface dept : iProperties.getDepartments()) { P d = iGroupPanel.get(dept.getId()); if (d != null) iForm.addRow(dept.getExtLabelWhenExist() + ":", d); } } else if (iRoom.hasGroups()) { iForm.addHeaderRow(MESSAGES.headerRoomGroups()); List<GroupInterface> globalGroups = iRoom.getGlobalGroups(); if (!globalGroups.isEmpty()) iForm.addRow(MESSAGES.propGlobalGroups(), new RoomDetail.GroupsCell(globalGroups)); List<GroupInterface> departmentalGroups = iRoom.getDepartmentalGroups(null); if (!departmentalGroups.isEmpty()) iForm.addRow(MESSAGES.propDepartmenalGroups(), new RoomDetail.GroupsCell(departmentalGroups)); } if (((iRoom.getUniqueId() == null && iProperties.isCanChangeFeatures()) || iRoom.isCanChangeFeatures()) && !iProperties.getFeatures().isEmpty()) { iForm.addHeaderRow(MESSAGES.headerRoomFeatures()); for (Map.Entry<Long, CheckBox> e : iFeatures.entrySet()) e.getValue().setValue(iRoom.hasFeature(e.getKey())); P features = new P("features"); Map<Long, P> fp = new HashMap<Long, P>(); for (FeatureInterface feature : iProperties.getFeatures()) { CheckBox ch = iFeatures.get(feature.getId()); if (feature.getType() != null) { P d = fp.get(feature.getType().getId()); if (d == null) { d = new P("features"); d.setWidth("100%"); fp.put(feature.getType().getId(), d); } d.add(ch); } else { features.add(ch); } } for (FeatureInterface feature : iRoom.getFeatures()) { if (!iFeatures.containsKey(feature.getId()) && feature.getDepartment() == null) { P f = new P("feature"); f.setText(feature.getTitle()); if (feature.getType() != null) { P d = fp.get(feature.getType().getId()); if (d == null) { d = new P("features"); d.setWidth("100%"); fp.put(feature.getType().getId(), d); } d.add(f); } else { features.add(f); } } } if (features.getWidgetCount() > 0) iForm.addRow(MESSAGES.propFeatures(), features); for (FeatureTypeInterface type : iProperties.getFeatureTypes()) { P d = fp.get(type.getId()); if (d != null) iForm.addRow(type.getLabel() + ":", d); } } else if (iRoom.hasFeatures()) { iForm.addHeaderRow(MESSAGES.headerRoomFeatures()); List<FeatureInterface> features = iRoom.getFeatures((Long) null); if (!features.isEmpty()) iForm.addRow(MESSAGES.propFeatures(), new RoomDetail.FeaturesCell(features)); for (FeatureTypeInterface type : iProperties.getFeatureTypes()) { List<FeatureInterface> featuresOfType = iRoom.getFeatures(type); if (!featuresOfType.isEmpty()) iForm.addRow(type.getLabel() + ":", new RoomDetail.FeaturesCell(featuresOfType)); } } if (iRoom.hasRoomSharingModel()) { iRoomSharingHeader.clearMessage(); iRoomSharing.setEditable(iProperties.isCanEditDepartments() || (iRoom.getUniqueId() == null && iProperties.isCanChangeAvailability()) || iRoom.isCanChangeAvailability()); iRoomSharing.setModel(iRoom.getRoomSharingModel()); iRoomSharing.setVisible(true); if (iRoom.getUniqueId() == null) { iLastSelectedDepartmentId = Long.valueOf(iControllingDepartment.getWidget() .getValue(iControllingDepartment.getWidget().getSelectedIndex())); if (iLastSelectedDepartmentId > 0) iRoomSharing.addOption(iLastSelectedDepartmentId); } iForm.addHeaderRow(iRoomSharingHeader); iForm.addRow(iRoomSharing); } else if (iProperties.isCanEditDepartments() || (iRoom.getUniqueId() == null && iProperties.isCanChangeAvailability()) || iRoom.isCanChangeAvailability()) { iForm.addHeaderRow(iRoomSharingHeader); iForm.addRow(iRoomSharing); iRoomSharingHeader.showLoading(); iRoomSharing.setVisible(false); RPC.execute( RoomInterface.RoomSharingRequest.load(iRoom.getSessionId(), iRoom.getUniqueId(), false, true), new AsyncCallback<RoomSharingModel>() { @Override public void onFailure(Throwable caught) { iRoomSharingHeader .setErrorMessage(MESSAGES.failedToLoadRoomAvailability(caught.getMessage())); } @Override public void onSuccess(RoomSharingModel result) { iRoomSharingHeader.clearMessage(); iRoomSharing.setEditable(iProperties.isCanEditDepartments() || (iRoom.getUniqueId() == null && iProperties.isCanChangeAvailability()) || iRoom.isCanChangeAvailability()); iRoomSharing.setModel(result); iRoomSharing.setVisible(true); if (iRoom.getUniqueId() == null) { iLastSelectedDepartmentId = Long.valueOf(iControllingDepartment.getWidget() .getValue(iControllingDepartment.getWidget().getSelectedIndex())); if (iLastSelectedDepartmentId > 0) iRoomSharing.addOption(iLastSelectedDepartmentId); } } }); } if (iProperties.isCanEditRoomExams() || (iProperties.isCanSeeExams() && iRoom.isCanSeePeriodPreferences() && iRoom.hasExamTypes())) { iPeriodPreferencesHeaderRow = iForm.addHeaderRow(iPeriodPreferencesHeader); iForm.getRowFormatter().setVisible(iPeriodPreferencesHeaderRow, false); for (ExamTypeInterface type : iProperties.getExamTypes()) { PeriodPreferencesWidget pref = iPeriodPreferences.get(type.getId()); int row = iForm.addRow(MESSAGES.propExaminationPreferences(type.getLabel()), pref); iPeriodPreferencesRow.put(type.getId(), row); iForm.getRowFormatter().setVisible(iPeriodPreferencesRow.get(type.getId()), false); } iPeriodPreferencesHeader.clearMessage(); for (final ExamTypeInterface type : iProperties.getExamTypes()) { final PeriodPreferencesWidget pref = iPeriodPreferences.get(type.getId()); if (iRoom.hasPeriodPreferenceModel(type.getId())) { pref.setEditable(iProperties.isCanEditRoomExams()); pref.setModel(iRoom.getPeriodPreferenceModel(type.getId())); boolean visible = iExaminationRooms.get(type.getId()).getValue() && !pref.getModel().getPeriods().isEmpty(); iForm.getRowFormatter().setVisible(iPeriodPreferencesRow.get(type.getId()), visible); if (visible) iForm.getRowFormatter().setVisible(iPeriodPreferencesHeaderRow, true); } else if ((iRoom.getUniqueId() == null && iProperties.isCanChangeExamStatus()) || iRoom.isCanChangeExamStatus()) { iPeriodPreferencesHeader.showLoading(); iForm.getRowFormatter().setVisible(iPeriodPreferencesRow.get(type.getId()), false); RPC.execute(RoomInterface.PeriodPreferenceRequest.load(iRoom.getSessionId(), iRoom.getUniqueId(), type.getId()), new AsyncCallback<PeriodPreferenceModel>() { @Override public void onFailure(Throwable caught) { iPeriodPreferencesHeader.setErrorMessage( MESSAGES.failedToLoadPeriodPreferences(caught.getMessage())); } @Override public void onSuccess(PeriodPreferenceModel result) { iPeriodPreferencesHeader.clearMessage(); pref.setEditable(iProperties.isCanEditRoomExams()); pref.setModel(result); boolean visible = iExaminationRooms.get(type.getId()).getValue() && !pref.getModel().getPeriods().isEmpty(); iForm.getRowFormatter().setVisible(iPeriodPreferencesRow.get(type.getId()), visible); if (visible) iForm.getRowFormatter().setVisible(iPeriodPreferencesHeaderRow, true); } }); } else { iForm.getRowFormatter().setVisible(iPeriodPreferencesRow.get(type.getId()), false); } } } else { iPeriodPreferencesHeaderRow = -1; iPeriodPreferencesRow.clear(); } if (((iRoom.getUniqueId() == null && iProperties.isCanChangeEventAvailability()) || iRoom.isCanChangeEventAvailability()) || (iProperties.isCanSeeEvents() && iRoom.isCanSeeEventAvailability())) { iForm.addHeaderRow(iEventAvailabilityHeader); iForm.addRow(iEventAvailability); iEventAvailabilityHeader .setVisible(!"-1".equals(iEventDepartment.getValue(iEventDepartment.getSelectedIndex()))); if (iRoom.hasEventAvailabilityModel()) { iEventAvailabilityHeader.clearMessage(); iEventAvailability .setEditable((iRoom.getUniqueId() == null && iProperties.isCanChangeEventAvailability()) || iRoom.isCanChangeEventAvailability()); iEventAvailability.setModel(iRoom.getEventAvailabilityModel()); iEventAvailability .setVisible(!"-1".equals(iEventDepartment.getValue(iEventDepartment.getSelectedIndex()))); } else { iEventAvailabilityHeader.showLoading(); iEventAvailability.setVisible(false); RPC.execute(RoomInterface.RoomSharingRequest.load(iRoom.getSessionId(), iRoom.getUniqueId(), true), new AsyncCallback<RoomSharingModel>() { @Override public void onFailure(Throwable caught) { iEventAvailabilityHeader.setErrorMessage( MESSAGES.failedToLoadRoomAvailability(caught.getMessage())); } @Override public void onSuccess(RoomSharingModel result) { iEventAvailabilityHeader.clearMessage(); iEventAvailability.setEditable( (iRoom.getUniqueId() == null && iProperties.isCanChangeEventAvailability()) || iRoom.isCanChangeEventAvailability()); iEventAvailability.setModel(result); iEventAvailability.setVisible(!"-1" .equals(iEventDepartment.getValue(iEventDepartment.getSelectedIndex()))); } }); } } if (iRoom.hasPictures() || (iRoom.getUniqueId() == null && iProperties.isCanChangePicture()) || iRoom.isCanChangePicture()) { iForm.addHeaderRow(iPicturesHeader); if ((iRoom.getUniqueId() == null && iProperties.isCanChangePicture()) || iRoom.isCanChangePicture()) iForm.addRow(MESSAGES.propNewPicture(), iFileUpload); iForm.addRow(iPictures); iPictures.clearTable(1); if (iRoom.hasPictures()) { for (final RoomPictureInterface picture : iRoom.getPictures()) iPictures.addRow(picture, line(picture)); } } iForm.addBottomRow(iFooter); if (iRoom.getUniqueId() == null && iProperties.hasFutureSessions()) { int row = iForm.addHeaderRow(iApplyToHeader); iForm.getRowFormatter().addStyleName(row, "space-above"); iApplyTo.clearTable(1); long id = 0; for (AcademicSessionInterface session : iProperties.getFutureSessions()) { List<Widget> line = new ArrayList<Widget>(); CheckBox select = new CheckBox(); line.add(select); select.addValueChangeHandler(new ValueChangeHandler<Boolean>() { @Override public void onValueChange(ValueChangeEvent<Boolean> event) { futureChanged(); } }); line.add(new Label()); line.add(new Label()); line.add(new Label()); line.add(new Label()); line.add(new Label(session.getLabel())); Integer flags = RoomCookie.getInstance().getFutureFlags(session.getId()); select.setValue(flags != null); for (FutureOperation op : FutureOperation.values()) { CheckBox ch = new CheckBox(); ch.setValue(canFutureOperation(iRoom, op) && ((flags == null && op.getDefaultSelectionNewRoom()) || (flags != null && op.in(flags)))); if (op == FutureOperation.ROOM_PROPERTIES) { ch.setValue(true); ch.setEnabled(false); } line.add(ch); } FutureRoomInterface fr = new FutureRoomInterface(); fr.setSession(session); fr.setId(--id); iApplyTo.addRow(fr, line); } for (FutureOperation op : FutureOperation.values()) { iApplyTo.setColumnVisible(6 + op.ordinal(), canFutureOperation(iRoom, op)); } iApplyTo.setColumnVisible(1, false); iApplyTo.setColumnVisible(2, false); iApplyTo.setColumnVisible(3, false); iApplyTo.setColumnVisible(4, false); iForm.addRow(iApplyTo); futureChanged(); } else if (iRoom.hasFutureRooms()) { int row = iForm.addHeaderRow(iApplyToHeader); iForm.getRowFormatter().addStyleName(row, "space-above"); iApplyTo.clearTable(1); boolean hasExtId = false, hasType = false, hasCapacity = false; for (FutureRoomInterface fr : iRoom.getFutureRooms()) { List<Widget> line = new ArrayList<Widget>(); CheckBox select = new CheckBox(); line.add(select); select.addValueChangeHandler(new ValueChangeHandler<Boolean>() { @Override public void onValueChange(ValueChangeEvent<Boolean> event) { futureChanged(); } }); line.add(new FutureRoomNameCell(fr)); if (fr.hasExternalId()) hasExtId = true; line.add(new Label(fr.hasExternalId() ? fr.getExternalId() : "")); if (fr.hasType()) hasType = true; line.add(new Label(fr.hasType() ? fr.getType() : "")); if (fr.hasCapacity()) hasCapacity = true; line.add(new Label(fr.hasCapacity() ? fr.getCapacity().toString() : "")); line.add(new Label(fr.getSession().getLabel())); Integer flags = RoomCookie.getInstance().getFutureFlags(fr.getSession().getId()); select.setValue(flags != null); for (FutureOperation op : FutureOperation.values()) { CheckBox ch = new CheckBox(); ch.setValue(canFutureOperation(iRoom, op) && ((flags == null && op.getDefaultSelection()) || (flags != null && op.in(flags)))); line.add(ch); } iApplyTo.addRow(fr, line); } for (FutureOperation op : FutureOperation.values()) { iApplyTo.setColumnVisible(6 + op.ordinal(), canFutureOperation(iRoom, op)); } iApplyTo.setColumnVisible(1, true); iApplyTo.setColumnVisible(2, hasExtId); iApplyTo.setColumnVisible(3, hasType); iApplyTo.setColumnVisible(4, hasCapacity); iForm.addRow(iApplyTo); futureChanged(); } }
From source file:org.unitime.timetable.gwt.client.sectioning.SectioningStatusPage.java
License:Apache License
public void populateStudentTable(List<StudentInfo> result) { List<Widget> header = new ArrayList<Widget>(); if (iOnline && iProperties != null && iProperties.isCanSelectStudent()) { UniTimeTableHeader hSelect = new UniTimeTableHeader("⊗", HasHorizontalAlignment.ALIGN_CENTER); header.add(hSelect);/*from ww w . j a va 2 s . c o m*/ hSelect.setWidth("10px"); hSelect.addAdditionalStyleName("unitime-NoPrint"); hSelect.addOperation(new Operation() { @Override public String getName() { return MESSAGES.selectAll(); } @Override public boolean hasSeparator() { return false; } @Override public boolean isApplicable() { return iSelectedStudentIds.size() != iStudentTable.getRowCount() + 2; } @Override public void execute() { iSelectedStudentIds.clear(); for (int row = 0; row < iStudentTable.getRowCount(); row++) { StudentInfo i = iStudentTable.getData(row); if (i != null && i.getStudent() != null) { ((CheckBox) iStudentTable.getWidget(row, 0)).setValue(true); iSelectedStudentIds.add(i.getStudent().getId()); } } } }); hSelect.addOperation(new Operation() { @Override public String getName() { return MESSAGES.clearAll(); } @Override public boolean hasSeparator() { return false; } @Override public boolean isApplicable() { return iSelectedStudentIds.size() > 0; } @Override public void execute() { iSelectedStudentIds.clear(); for (int row = 0; row < iStudentTable.getRowCount(); row++) { StudentInfo i = iStudentTable.getData(row); if (i != null && i.getStudent() != null) ((CheckBox) iStudentTable.getWidget(row, 0)).setValue(false); } } }); hSelect.addOperation(new Operation() { @Override public String getName() { return MESSAGES.sendStudentEmail(); } @Override public boolean hasSeparator() { return true; } @Override public boolean isApplicable() { return iSelectedStudentIds.size() > 0 && iProperties != null && iProperties.isEmail(); } @Override public void execute() { SimpleForm sf = new SimpleForm(); final UniTimeHeaderPanel buttons = new UniTimeHeaderPanel(); sf.removeStyleName("unitime-NotPrintableBottomLine"); sf.addRow(MESSAGES.emailSubject(), iSubject); if (iSubject.getText().isEmpty() || iSubject.getText().equals(MESSAGES.defaulSubjectMassCancel())) iSubject.setText(MESSAGES.defaulSubject()); sf.addRow(MESSAGES.emailCC(), iCC); sf.addRow(MESSAGES.emailBody(), iMessage); sf.addBottomRow(buttons); final UniTimeDialogBox dialog = new UniTimeDialogBox(true, false); dialog.setWidget(sf); dialog.setText(MESSAGES.sendStudentEmail()); dialog.setEscapeToHide(true); buttons.addButton("send", MESSAGES.emailSend(), new ClickHandler() { @Override public void onClick(ClickEvent event) { List<Long> studentIds = new ArrayList<Long>(); for (int row = 0; row < iStudentTable.getRowCount(); row++) { StudentInfo i = iStudentTable.getData(row); if (i != null && i.getStudent() != null && iSelectedStudentIds.contains(i.getStudent().getId())) { studentIds.add(i.getStudent().getId()); iStudentTable.setWidget(row, iStudentTable.getCellCount(row) - 1, new Image(RESOURCES.loading_small())); } } dialog.hide(); sendEmail(studentIds.iterator(), iSubject.getText(), iMessage.getText(), iCC.getText(), 0); } }); buttons.addButton("close", MESSAGES.buttonClose(), new ClickHandler() { @Override public void onClick(ClickEvent event) { dialog.hide(); } }); dialog.center(); } }); hSelect.addOperation(new Operation() { @Override public String getName() { return MESSAGES.massCancel(); } @Override public boolean hasSeparator() { return false; } @Override public boolean isApplicable() { return iSelectedStudentIds.size() > 0 && iProperties != null && iProperties.isMassCancel(); } @Override public void execute() { SimpleForm sf = new SimpleForm(); final UniTimeHeaderPanel buttons = new UniTimeHeaderPanel(); sf.removeStyleName("unitime-NotPrintableBottomLine"); if (iSubject.getText().isEmpty() || iSubject.getText().equals(MESSAGES.defaulSubject())) iSubject.setText(MESSAGES.defaulSubjectMassCancel()); sf.addRow(MESSAGES.emailSubject(), iSubject); sf.addRow(MESSAGES.emailCC(), iCC); sf.addRow(MESSAGES.emailBody(), iMessage); sf.addRow(MESSAGES.newStatus(), iStatus); sf.addBottomRow(buttons); final UniTimeDialogBox dialog = new UniTimeDialogBox(true, false); dialog.setWidget(sf); dialog.setText(MESSAGES.massCancel()); dialog.setEscapeToHide(true); buttons.addButton("cancel", MESSAGES.buttonMassCancel(), new ClickHandler() { @Override public void onClick(ClickEvent event) { if (!Window.confirm(MESSAGES.massCancelConfirmation())) { dialog.hide(); return; } final List<Long> studentIds = new ArrayList<Long>(); for (int row = 0; row < iStudentTable.getRowCount(); row++) { StudentInfo i = iStudentTable.getData(row); if (i != null && i.getStudent() != null && iSelectedStudentIds.contains(i.getStudent().getId())) { studentIds.add(i.getStudent().getId()); iStudentTable.setWidget(row, iStudentTable.getCellCount(row) - 1, new Image(RESOURCES.loading_small())); } } dialog.hide(); LoadingWidget.getInstance().show(MESSAGES.massCanceling()); iSectioningService.massCancel(studentIds, iStatus.getWidget().getValue(iStatus.getWidget().getSelectedIndex()), iSubject.getText(), iMessage.getText(), iCC.getText(), new AsyncCallback<Boolean>() { @Override public void onFailure(Throwable caught) { LoadingWidget.getInstance().hide(); UniTimeNotifications.error(caught); for (int row = 0; row < iStudentTable.getRowCount(); row++) { StudentInfo i = iStudentTable.getData(row); if (i != null && i.getStudent() != null && studentIds.contains(i.getStudent().getId())) { HTML error = new HTML(caught.getMessage()); error.setStyleName("unitime-ErrorMessage"); iStudentTable.setWidget(row, iStudentTable.getCellCount(row) - 1, error); i.setEmailDate(null); } } } @Override public void onSuccess(Boolean result) { LoadingWidget.getInstance().hide(); loadData(); } }); } }); buttons.addButton("close", MESSAGES.buttonClose(), new ClickHandler() { @Override public void onClick(ClickEvent event) { dialog.hide(); } }); dialog.center(); } }); hSelect.addOperation(new Operation() { @Override public String getName() { return MESSAGES.requestStudentUpdate(); } @Override public boolean hasSeparator() { return true; } @Override public boolean isApplicable() { return iSelectedStudentIds.size() > 0 && iProperties != null && iProperties.isRequestUpdate(); } @Override public void execute() { List<Long> studentIds = new ArrayList<Long>(iSelectedStudentIds); LoadingWidget.getInstance().show(MESSAGES.requestingStudentUpdate()); iSectioningService.requestStudentUpdate(studentIds, new AsyncCallback<Boolean>() { @Override public void onFailure(Throwable caught) { LoadingWidget.getInstance().hide(); UniTimeNotifications.error(caught); } @Override public void onSuccess(Boolean result) { LoadingWidget.getInstance().hide(); UniTimeNotifications.info(MESSAGES.requestStudentUpdateSuccess()); } }); } }); if (iStates != null) { for (final String ref : new TreeSet<String>(iStates.keySet())) { hSelect.addOperation(new Operation() { @Override public String getName() { return MESSAGES.changeStatusTo(iStates.get(ref)); } @Override public boolean hasSeparator() { return "".equals(ref); } @Override public boolean isApplicable() { return iSelectedStudentIds.size() > 0 && iProperties != null && iProperties.isChangeStatus(); } @Override public void execute() { List<Long> studentIds = new ArrayList<Long>(iSelectedStudentIds); LoadingWidget.getInstance().show(MESSAGES.changingStatusTo(iStates.get(ref))); iSectioningService.changeStatus(studentIds, ref, new AsyncCallback<Boolean>() { @Override public void onFailure(Throwable caught) { LoadingWidget.getInstance().hide(); UniTimeNotifications.error(caught); } @Override public void onSuccess(Boolean result) { for (int row = 0; row < iStudentTable.getRowCount(); row++) { StudentInfo i = iStudentTable.getData(row); if (i != null && i.getStudent() != null && ((CheckBox) iStudentTable.getWidget(row, 0)).getValue()) { i.setStatus(ref); ((HTML) iStudentTable.getWidget(row, iStatusColumn)).setHTML(ref); } } LoadingWidget.getInstance().hide(); } }); } }); } } } boolean hasExtId = false; for (ClassAssignmentInterface.StudentInfo e : result) { if (e.getStudent() != null && e.getStudent().isCanShowExternalId()) { hasExtId = true; break; } } UniTimeTableHeader hExtId = null; if (hasExtId) { hExtId = new UniTimeTableHeader(MESSAGES.colStudentExternalId()); header.add(hExtId); addSortOperation(hExtId, StudentComparator.SortBy.EXTERNAL_ID, MESSAGES.colStudentExternalId()); } UniTimeTableHeader hStudent = new UniTimeTableHeader(MESSAGES.colStudent()); header.add(hStudent); addSortOperation(hStudent, StudentComparator.SortBy.STUDENT, MESSAGES.colStudent()); UniTimeTableHeader hTotal = new UniTimeTableHeader(" "); header.add(hTotal); boolean hasEnrollment = false, hasWaitList = false, hasArea = false, hasMajor = false, hasGroup = false, hasAcmd = false, hasReservation = false, hasRequestedDate = false, hasEnrolledDate = false, hasConsent = false, hasCredit = false; for (ClassAssignmentInterface.StudentInfo e : result) { if (e.getStudent() == null) continue; // if (e.getStatus() != null) hasStatus = true; if (e.getTotalEnrollment() != null && e.getTotalEnrollment() > 0) hasEnrollment = true; if (e.getTotalUnassigned() != null && e.getTotalUnassigned() > 0) hasWaitList = true; if (e.getStudent().hasArea()) hasArea = true; if (e.getStudent().hasMajor()) hasMajor = true; if (e.getStudent().hasGroup()) hasGroup = true; if (e.getStudent().hasAccommodation()) hasAcmd = true; if (e.getTotalReservation() != null && e.getTotalReservation() > 0) hasReservation = true; if (e.getRequestedDate() != null) hasRequestedDate = true; if (e.getEnrolledDate() != null) hasEnrolledDate = true; // if (e.getEmailDate() != null) hasEmailDate = true; if (e.getTotalConsentNeeded() != null && e.getTotalConsentNeeded() > 0) hasConsent = true; if (e.hasTotalCredit()) hasCredit = true; } UniTimeTableHeader hArea = null, hClasf = null; if (hasArea) { hArea = new UniTimeTableHeader(MESSAGES.colArea()); //hArea.setWidth("100px"); header.add(hArea); addSortOperation(hArea, StudentComparator.SortBy.AREA, MESSAGES.colArea()); hClasf = new UniTimeTableHeader(MESSAGES.colClassification()); //hClasf.setWidth("100px"); header.add(hClasf); addSortOperation(hClasf, StudentComparator.SortBy.CLASSIFICATION, MESSAGES.colClassification()); } UniTimeTableHeader hMajor = null; if (hasMajor) { hMajor = new UniTimeTableHeader(MESSAGES.colMajor()); //hMajor.setWidth("100px"); header.add(hMajor); addSortOperation(hMajor, StudentComparator.SortBy.MAJOR, MESSAGES.colMajor()); } UniTimeTableHeader hGroup = null; if (hasGroup) { hGroup = new UniTimeTableHeader(MESSAGES.colGroup()); //hGroup.setWidth("100px"); header.add(hGroup); addSortOperation(hGroup, StudentComparator.SortBy.GROUP, MESSAGES.colGroup()); } UniTimeTableHeader hAcmd = null; if (hasAcmd) { hAcmd = new UniTimeTableHeader(MESSAGES.colAccommodation()); //hGroup.setWidth("100px"); header.add(hAcmd); addSortOperation(hAcmd, StudentComparator.SortBy.ACCOMODATION, MESSAGES.colAccommodation()); } iStatusColumn = header.size() - 1; UniTimeTableHeader hStatus = new UniTimeTableHeader(MESSAGES.colStatus()); //hMajor.setWidth("100px"); header.add(hStatus); addSortOperation(hStatus, StudentComparator.SortBy.STATUS, MESSAGES.colStatus()); UniTimeTableHeader hEnrollment = null; if (hasEnrollment) { hEnrollment = new UniTimeTableHeader(MESSAGES.colEnrollment()); header.add(hEnrollment); addSortOperation(hEnrollment, StudentComparator.SortBy.ENROLLMENT, MESSAGES.colEnrollment()); } UniTimeTableHeader hWaitlist = null; if (hasWaitList) { hWaitlist = new UniTimeTableHeader(MESSAGES.colWaitListed()); header.add(hWaitlist); addSortOperation(hWaitlist, StudentComparator.SortBy.WAITLIST, MESSAGES.colWaitListed()); } UniTimeTableHeader hReservation = null; if (hasReservation) { hReservation = new UniTimeTableHeader(MESSAGES.colReservation()); header.add(hReservation); addSortOperation(hReservation, StudentComparator.SortBy.RESERVATION, MESSAGES.colReservation()); } UniTimeTableHeader hConsent = null; if (hasConsent) { hConsent = new UniTimeTableHeader(MESSAGES.colConsent()); header.add(hConsent); addSortOperation(hConsent, StudentComparator.SortBy.CONSENT, MESSAGES.colConsent()); } UniTimeTableHeader hCredit = null; if (hasCredit) { hCredit = new UniTimeTableHeader(MESSAGES.colCredit()); header.add(hCredit); addSortOperation(hCredit, StudentComparator.SortBy.CREDIT, MESSAGES.colCredit()); } UniTimeTableHeader hRequestTS = null; if (hasRequestedDate) { hRequestTS = new UniTimeTableHeader(MESSAGES.colRequestTimeStamp()); header.add(hRequestTS); addSortOperation(hRequestTS, StudentComparator.SortBy.REQUEST_TS, MESSAGES.colRequestTimeStamp()); } UniTimeTableHeader hEnrolledTS = null; if (hasEnrolledDate) { hEnrolledTS = new UniTimeTableHeader(MESSAGES.colEnrollmentTimeStamp()); header.add(hEnrolledTS); addSortOperation(hEnrolledTS, StudentComparator.SortBy.ENROLLMENT_TS, MESSAGES.colEnrollmentTimeStamp()); } UniTimeTableHeader hEmailTS = null; if (iOnline) { hEmailTS = new UniTimeTableHeader(MESSAGES.colEmailTimeStamp()); header.add(hEmailTS); addSortOperation(hEmailTS, StudentComparator.SortBy.EMAIL_TS, MESSAGES.colEmailTimeStamp()); } iStudentTable.addRow(null, header); Set<Long> newlySelected = new HashSet<Long>(); for (StudentInfo info : result) { List<Widget> line = new ArrayList<Widget>(); if (info.getStudent() != null) { if (iOnline && iProperties != null && iProperties.isCanSelectStudent()) { CheckBox ch = new CheckBox(); ch.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { event.stopPropagation(); } }); final Long sid = info.getStudent().getId(); if (iSelectedStudentIds.contains(sid)) { ch.setValue(true); newlySelected.add(sid); } ch.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { event.stopPropagation(); } }); ch.addValueChangeHandler(new ValueChangeHandler<Boolean>() { @Override public void onValueChange(ValueChangeEvent<Boolean> event) { if (event.getValue()) iSelectedStudentIds.add(sid); else iSelectedStudentIds.remove(sid); } }); line.add(ch); } if (hasExtId) { line.add(new Label( info.getStudent().isCanShowExternalId() ? info.getStudent().getExternalId() : "", false)); } line.add(new TitleCell(info.getStudent().getName())); if (hasArea) { line.add(new HTML(info.getStudent().getArea("<br>"), false)); line.add(new HTML(info.getStudent().getClassification("<br>"), false)); } if (hasMajor) line.add(new HTML(info.getStudent().getMajor("<br>"), false)); if (hasGroup) line.add(new HTML(info.getStudent().getGroup("<br>"), false)); if (hasAcmd) line.add(new HTML(info.getStudent().getAccommodation("<br>"), false)); line.add(new HTML(info.getStatus(), false)); } else { if (iOnline && iProperties != null && iProperties.isCanSelectStudent()) line.add(new HTML(" ", false)); if (hasExtId) line.add(new TitleCell(MESSAGES.total())); else line.add(new Label(MESSAGES.total())); line.add(new NumberCell(null, result.size() - 1)); if (hasArea) { line.add(new HTML(" ", false)); line.add(new HTML(" ", false)); } if (hasMajor) line.add(new HTML(" ", false)); if (hasGroup) line.add(new HTML(" ", false)); if (hasAcmd) line.add(new HTML(" ", false)); line.add(new HTML(" ", false)); } if (hasEnrollment) line.add(new NumberCell(info.getEnrollment(), info.getTotalEnrollment())); if (hasWaitList) line.add(new WaitListCell(info)); if (hasReservation) line.add(new NumberCell(info.getReservation(), info.getTotalReservation())); if (hasConsent) line.add(new NumberCell(info.getConsentNeeded(), info.getTotalConsentNeeded())); if (hasCredit) line.add(new CreditCell(info.getCredit(), info.getTotalCredit())); if (info.getStudent() != null) { if (hasRequestedDate) line.add(new HTML( info.getRequestedDate() == null ? " " : sDF.format(info.getRequestedDate()), false)); if (hasEnrolledDate) line.add(new HTML( info.getEnrolledDate() == null ? " " : sDF.format(info.getEnrolledDate()), false)); if (iOnline) line.add(new HTML(info.getEmailDate() == null ? " " : sDF.format(info.getEmailDate()), false)); } else { if (hasRequestedDate) line.add(new HTML(" ", false)); if (hasEnrolledDate) line.add(new HTML(" ", false)); if (iOnline) line.add(new HTML(" ", false)); } iStudentTable.addRow(info, line); } iSelectedStudentIds.clear(); iSelectedStudentIds.addAll(newlySelected); if (iStudentTable.getRowCount() >= 2) { for (int c = 0; c < iStudentTable.getCellCount(iStudentTable.getRowCount() - 1); c++) iStudentTable.getCellFormatter().setStyleName(iStudentTable.getRowCount() - 1, c, "unitime-TotalRow"); } iStudentTableHint.setVisible(hasWaitList); if (SectioningStatusCookie.getInstance().getSortBy(iOnline, 1) != 0) { boolean asc = (SectioningStatusCookie.getInstance().getSortBy(iOnline, 1) > 0); StudentComparator.SortBy sort = StudentComparator.SortBy .values()[Math.abs(SectioningStatusCookie.getInstance().getSortBy(iOnline, 1)) - 1]; UniTimeTableHeader h = null; switch (sort) { case ACCOMODATION: h = hAcmd; break; case AREA: h = hArea; break; case CLASSIFICATION: h = hClasf; break; case CONSENT: h = hConsent; break; case CREDIT: h = hCredit; break; case EMAIL_TS: h = hEmailTS; break; case ENROLLMENT: h = hEnrollment; break; case ENROLLMENT_TS: h = hEnrolledTS; break; case EXTERNAL_ID: h = hExtId; break; case GROUP: h = hGroup; break; case MAJOR: h = hMajor; break; case REQUEST_TS: h = hRequestTS; break; case RESERVATION: h = hReservation; break; case STATUS: h = hStatus; break; case STUDENT: h = hStudent; break; case WAITLIST: h = hWaitlist; break; } if (h != null) iStudentTable.sort(h, new StudentComparator(sort), asc); } }
From source file:org.unitime.timetable.gwt.client.solver.PageFilter.java
License:Apache License
protected Widget getWidget(final FilterParameterInterface param) { if (param.hasOptions()) { final ListBox list = new ListBox(); list.setMultipleSelect(param.isMultiSelect()); if (!param.isMultiSelect()) list.addItem(MESSAGES.itemSelect()); for (ListItem item : param.getOptions()) { list.addItem(item.getText(), item.getValue()); if (param.isMultiSelect()) list.setItemSelected(list.getItemCount() - 1, param.isDefaultItem(item)); else if (param.isDefaultItem(item)) list.setSelectedIndex(list.getItemCount() - 1); }/*from w ww . ja v a 2 s . co m*/ list.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent event) { if (param.isMultiSelect()) { String value = ""; for (int i = 0; i < list.getItemCount(); i++) if (list.isItemSelected(i)) value += (value.isEmpty() ? "" : ",") + list.getValue(i); param.setValue(value); } else { if (list.getSelectedIndex() <= 0) param.setValue(null); else param.setValue(list.getValue(list.getSelectedIndex())); } ValueChangeEvent.fire(PageFilter.this, iFilter); } }); return list; } if ("boolean".equalsIgnoreCase(param.getType())) { CheckBox ch = new CheckBox(); ch.setValue("1".equalsIgnoreCase(param.getDefaultValue())); ch.addValueChangeHandler(new ValueChangeHandler<Boolean>() { @Override public void onValueChange(ValueChangeEvent<Boolean> event) { if (event.getValue() == null) param.setValue(null); else param.setValue(event.getValue() ? "1" : "0"); ValueChangeEvent.fire(PageFilter.this, iFilter); } }); return ch; } if ("file".equalsIgnoreCase(param.getType())) { UniTimeFileUpload upload = new UniTimeFileUpload(); upload.reset(); upload.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { if (event.getValue() == null) param.setValue(null); else param.setValue(event.getValue()); ValueChangeEvent.fire(PageFilter.this, iFilter); } }); return upload; } if ("textarea".equalsIgnoreCase(param.getType())) { TextArea textarea = new TextArea(); textarea.setStyleName("unitime-TextArea"); textarea.setVisibleLines(5); textarea.setCharacterWidth(80); if (param.hasDefaultValue()) textarea.setText(param.getDefaultValue()); textarea.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { if (event.getValue() == null) param.setValue(null); else param.setValue(event.getValue()); ValueChangeEvent.fire(PageFilter.this, iFilter); } }); return textarea; } if ("integer".equalsIgnoreCase(param.getType()) || "int".equalsIgnoreCase(param.getType()) || "long".equalsIgnoreCase(param.getType()) || "short".equalsIgnoreCase(param.getType()) || "byte".equalsIgnoreCase(param.getType())) { NumberBox text = new NumberBox(); text.setDecimal(false); text.setNegative(true); if (param.hasDefaultValue()) text.setText(param.getDefaultValue()); text.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { if (event.getValue() == null) param.setValue(null); else param.setValue(event.getValue()); ValueChangeEvent.fire(PageFilter.this, iFilter); } }); return text; } if ("number".equalsIgnoreCase(param.getType()) || "float".equalsIgnoreCase(param.getType()) || "double".equalsIgnoreCase(param.getType())) { NumberBox text = new NumberBox(); text.setDecimal(true); text.setNegative(true); if (param.hasDefaultValue()) text.setText(param.getDefaultValue()); text.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { if (event.getValue() == null) param.setValue(null); else param.setValue(event.getValue()); ValueChangeEvent.fire(PageFilter.this, iFilter); } }); return text; } if ("date".equalsIgnoreCase(param.getType())) { SingleDateSelector text = new SingleDateSelector(); if (param.hasDefaultValue()) text.setText(param.getDefaultValue()); final DateTimeFormat format = DateTimeFormat.getFormat(CONSTANTS.eventDateFormat()); text.addValueChangeHandler(new ValueChangeHandler<Date>() { @Override public void onValueChange(ValueChangeEvent<Date> event) { if (event.getValue() == null) param.setValue(null); else param.setValue(format.format(event.getValue())); ValueChangeEvent.fire(PageFilter.this, iFilter); } }); return text; } TextBox text = new TextBox(); text.setStyleName("unitime-TextBox"); text.setWidth("400px"); if (param.hasDefaultValue()) text.setText(param.getDefaultValue()); text.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { if (event.getValue() == null) param.setValue(null); else param.setValue(event.getValue()); ValueChangeEvent.fire(PageFilter.this, iFilter); } }); return text; }
From source file:org.unitime.timetable.gwt.client.widgets.CourseFinderMultipleCourses.java
License:Apache License
@Override public void setValue(RequestedCourse value, final boolean fireEvents) { iCheckedCourses.clear();/* w ww. j a v a 2s . c o m*/ for (int r = 0; r < iCourses.getRowCount(); r++) { CourseAssignment ca = iCourses.getData(r); if (iCourses.getWidget(r, 0) instanceof CheckBox && ca != null) { CheckBox c = (CheckBox) iCourses.getWidget(r, 0); c.setValue(false); c.setText(""); } } String query = (value == null || !value.isCourse() ? "" : value.getCourseName()); iSelectedMethods.clear(); if (iRequired != null) iRequired.setValue(false); for (CheckBox ch : iInstructionalMethods.values()) if (ch.isEnabled()) ch.setValue(false); if (value != null && value.hasSelectedIntructionalMethods()) for (Preference id : value.getSelectedIntructionalMethods()) { iSelectedMethods.add(id); if (id.isRequired() && iRequired != null) iRequired.setValue(true); CheckBox ch = iInstructionalMethods.get(id); if (ch != null && ch.isEnabled()) ch.setValue(true); } if (iDetails != null) for (CourseFinderCourseDetails d : iDetails) d.onSetValue(value); if (query.isEmpty() && !iShowDefaultSuggestions) { iLastQuery = null; iCourses.clearTable(1); iCourses.setEmptyMessage(MESSAGES.courseSelectionNoCourseFilter()); updateCourseDetails(); } else if (!query.equals(iLastQuery)) { iLastQuery = query; iDataProvider.getData(query, new AsyncCallback<Collection<CourseAssignment>>() { public void onFailure(Throwable caught) { iCourses.clearTable(1); iCourses.setEmptyMessage(caught.getMessage()); if (isVisible()) AriaStatus.getInstance().setText(caught.getMessage()); updateCourseDetails(); ResponseEvent.fire(CourseFinderMultipleCourses.this, false); } public void onSuccess(Collection<CourseAssignment> result) { iCourses.clearTable(1); boolean hasCredit = false, hasNote = false; for (final CourseAssignment record : result) { List<Widget> line = new ArrayList<Widget>(); CheckBox ch = new CheckBox(); ch.setValue( iCheckedCourses.contains(new RequestedCourse(record, CONSTANTS.showCourseTitle()))); ch.setText(ch.getValue() ? String.valueOf(iCheckedCourses .indexOf(new RequestedCourse(record, CONSTANTS.showCourseTitle())) + 1) : ""); ch.addValueChangeHandler(new ValueChangeHandler<Boolean>() { @Override public void onValueChange(ValueChangeEvent<Boolean> event) { RequestedCourse rc = new RequestedCourse(); rc.setCourseId(record.getCourseId()); rc.setCourseName(MESSAGES.courseName(record.getSubject(), record.getCourseNbr())); if (record.hasTitle() && (!record.hasUniqueName() || iShowCourseTitles)) rc.setCourseName(MESSAGES.courseNameWithTitle(record.getSubject(), record.getCourseNbr(), record.getTitle())); rc.setCourseTitle(record.getTitle()); rc.setCredit(record.guessCreditRange()); if (event.getValue()) { iCheckedCourses.add(rc); } else { iCheckedCourses.remove(rc); } for (int r = 0; r < iCourses.getRowCount(); r++) { CourseAssignment ca = iCourses.getData(r); if (iCourses.getWidget(r, 0) instanceof CheckBox && ca != null) { CheckBox c = (CheckBox) iCourses.getWidget(r, 0); c.setText(c.getValue() ? String.valueOf(iCheckedCourses.indexOf( new RequestedCourse(ca, CONSTANTS.showCourseTitle())) + 1) : ""); } } } }); line.add(ch); line.add(new Label(record.getSubject(), false)); line.add(new Label(record.getCourseNbr(), false)); line.add(new HTML(record.getLimit() == null || record.getLimit() == 0 || record.getEnrollment() == null ? "" : record.getLimit() < 0 ? "∞" : (record.getLimit() - record.getEnrollment()) + " / " + record.getLimit(), false)); line.add(new Label(record.getTitle() == null ? "" : record.getTitle(), false)); if (record.hasCredit()) { Label credit = new Label(record.getCreditAbbv(), false); if (record.hasCredit()) credit.setTitle(record.getCreditText()); line.add(credit); hasCredit = true; } else { line.add(new Label()); } line.add(new Label(record.getNote() == null ? "" : record.getNote())); if (record.hasNote()) hasNote = true; if (record.hasTitle()) { if (record.hasNote()) { line.add(new AriaHiddenLabel( ARIA.courseFinderCourseWithTitleAndNote(record.getSubject(), record.getCourseNbr(), record.getTitle(), record.getNote()))); } else { line.add(new AriaHiddenLabel(ARIA.courseFinderCourseWithTitle(record.getSubject(), record.getCourseNbr(), record.getTitle()))); } } else { if (record.hasNote()) { line.add(new AriaHiddenLabel(ARIA.courseFinderCourseWithNote(record.getSubject(), record.getCourseNbr(), record.getNote()))); } else { line.add(new AriaHiddenLabel( ARIA.courseFinderCourse(record.getSubject(), record.getCourseNbr()))); } } int row = iCourses.addRow(record, line); if (iLastQuery .equalsIgnoreCase(MESSAGES.courseName(record.getSubject(), record.getCourseNbr())) || (record.getTitle() != null && iLastQuery.equalsIgnoreCase(MESSAGES.courseNameWithTitle( record.getSubject(), record.getCourseNbr(), record.getTitle())))) iCourses.setSelected(row, true); } iCourses.setColumnVisible(4, hasCredit); iCourses.setColumnVisible(5, hasNote); if (result.size() == 1) iCourses.setSelected(1, true); if (iCourses.getSelectedRow() >= 0) { scrollToSelectedRow(); if (fireEvents) ValueChangeEvent.fire(CourseFinderMultipleCourses.this, getValue()); } updateCourseDetails(); ResponseEvent.fire(CourseFinderMultipleCourses.this, !result.isEmpty()); } }); } if (iRequired != null) { iRequired.setEnabled(isEnabled() && (iSpecReg == null || iSpecReg.isCanRequire())); iRequired.setVisible(iSpecReg == null || iSpecReg.isCanRequire()); } }
From source file:org.unitime.timetable.gwt.client.widgets.CourseFinderMultipleCourses.java
License:Apache License
protected void updateCourseDetails() { if (iLastDetails != null) { for (RequestedCourse rc : iCheckedCourses) { if (rc.equals(iLastDetails)) { rc.clearSelection();//from ww w. ja v a 2 s .c om for (Map.Entry<Preference, CheckBox> e : iInstructionalMethods.entrySet()) if (e.getValue().isEnabled() && e.getValue().getValue()) rc.setSelectedIntructionalMethod(e.getKey(), true); if (iDetails != null) for (CourseFinderCourseDetails d : iDetails) d.onGetValue(rc); } } } int row = iCourses.getSelectedRow(); CourseAssignment record = iCourses.getData(row); iLastDetails = record; if (record == null) { if (iDetails != null) for (CourseFinderCourseDetails detail : iDetails) { detail.setValue(null); } if (isVisible() && isAttached()) AriaStatus.getInstance().setHTML(ARIA.courseFinderNoCourse()); iInstructionalMethodsPanel.clear(); iInstructionalMethods.clear(); } else { for (CourseFinderCourseDetails detail : iDetails) detail.setValue(record); if (record.hasTitle()) { if (record.hasNote()) { AriaStatus.getInstance() .setHTML(ARIA.courseFinderSelectedWithTitleAndNote(iCourses.getSelectedRow(), iCourses.getRowCount() - 1, record.getSubject(), record.getCourseNbr(), record.getTitle(), record.getNote())); } else { AriaStatus.getInstance() .setHTML(ARIA.courseFinderSelectedWithTitle(iCourses.getSelectedRow(), iCourses.getRowCount() - 1, record.getSubject(), record.getCourseNbr(), record.getTitle())); } } else { if (record.hasNote()) { AriaStatus.getInstance() .setHTML(ARIA.courseFinderSelectedWithNote(iCourses.getSelectedRow(), iCourses.getRowCount() - 1, record.getSubject(), record.getCourseNbr(), record.getNote())); } else { AriaStatus.getInstance().setHTML(ARIA.courseFinderSelected(iCourses.getSelectedRow(), iCourses.getRowCount() - 1, record.getSubject(), record.getCourseNbr())); } } iInstructionalMethodsPanel.clear(); iInstructionalMethods.clear(); if (record.hasInstructionalMethodSelection()) { P imp = new P("preference-label"); imp.setText(MESSAGES.labelInstructionalMethodPreference()); iInstructionalMethodsPanel.add(imp); for (final IdValue m : record.getInstructionalMethods()) { CheckBox ch = new CheckBox(m.getValue()); ch.setValue(isSelectedMethod(m.getId())); ch.setEnabled(isEnabled()); final Preference p = new Preference(m.getId(), m.getValue(), isSelectedMethodRequired(m.getId())); ch.addValueChangeHandler(new ValueChangeHandler<Boolean>() { @Override public void onValueChange(ValueChangeEvent<Boolean> event) { if (event.getValue()) iSelectedMethods.add(p); else iSelectedMethods.remove(p); } }); ch.addStyleName("instructional-method"); iInstructionalMethods.put(p, ch); iInstructionalMethodsPanel.add(ch); } } else if (record.hasInstructionalMethods()) { P imp = new P("preference-label"); imp.setText(MESSAGES.labelInstructionalMethodPreference()); iInstructionalMethodsPanel.add(imp); for (IdValue m : record.getInstructionalMethods()) { CheckBox ch = new CheckBox(m.getValue()); ch.addStyleName("instructional-method"); ch.setValue(true); ch.setEnabled(false); iInstructionalMethods .put(new Preference(m.getId(), m.getValue(), isSelectedMethodRequired(m.getId())), ch); iInstructionalMethodsPanel.add(ch); } } if (iRequired != null) { iInstructionalMethodsPanel.add(iRequired); } } }
From source file:org.waveprotocol.wave.client.editor.debug.DebugOptions.java
License:Apache License
private void addCheckBox(Panel panel, String caption, boolean initValue, ValueChangeHandler<Boolean> handler) { CheckBox box = new CheckBox(caption); box.setValue(initValue);/* w w w .j a va 2s . c om*/ box.addValueChangeHandler(handler); panel.add(box); }
From source file:org.waveprotocol.wave.client.editor.harness.EditorHarness.java
License:Apache License
private CheckBox createEditToggleCheckBox(final Editor editor) { CheckBox check = new CheckBox("Toggle edit"); check.addValueChangeHandler(new ValueChangeHandler<Boolean>() { @Override/* www . jav a 2 s . c om*/ public void onValueChange(ValueChangeEvent<Boolean> event) { setEditing(editor, event.getValue()); } }); return check; }