private void setSelectItemEvents(final boolean async, final ObjectNameIdResolver resolver) { final ListModel model = listModel; model .getItemsChangedEvent() .addListener( new ChangedModelItemEventHandler(this, model) { public String getItemName(Object o) { return resolver.getItemName(o); } public String getItemId(Object o) { return resolver.getItemId(o); } }); model .getSelectedItemChangedEvent() .addListener( new IEventListener() { @Override public void eventRaised(Event ev, Object sender, EventArgs args) { if (async && getForm() == null) return; GWT.log("Item changed: " + getTitle() + " Changed to: " + model.getSelectedItem()); if (model.getSelectedItem() != null) setValue(resolver.getItemId(model.getSelectedItem())); else if (getDisplayValue() != null) setValue((String) null); // Clear the selected item } }); addChangedHandler( new BoxSelectItemChanged(model) { String getItemId(Object o) { return resolver.getItemId(o); } }); model .getPropertyChangedEvent() .addListener( new IEventListener() { @Override public void eventRaised(Event ev, Object sender, EventArgs args) { if (async && getForm() == null) return; String property = ((PropertyChangedEventArgs) args).PropertyName; if (property.equals("IsChangable")) { if (!model.getIsChangable()) { setShowDisabled(true); setDisabled(true); } else { setDisabled(false); } } else if (property.equals("IsAvailable")) { if (!model.getIsAvailable()) { hide(); } else { show(); } } else if (property.equals("IsValid")) { if (!listModel.getIsValid()) { setTextBoxStyle("selectBoxInvalid"); if (listModel.getInvalidityReasons() != null && listModel.getInvalidityReasons().size() > 0) { setTooltip( "<nobr>" + listModel.getInvalidityReasons().iterator().next() + "</nobr>"); setHoverStyle("gridToolTipStyle"); setHoverWidth(1); setHoverDelay(100); } } else { setTextBoxStyle("engineSelectItem"); setTooltip(""); } } } }); if (!async) { model.getItemsChangedEvent().raise(model, EventArgs.Empty); model.getSelectedItemChangedEvent().raise(model, EventArgs.Empty); } }
public ItemRemoveModalPanel( String title, String itemsString, final ListModel model, ObjectNameResolver nameResolver, final GridController gridController) { super(panelWidth, panelHeight, title); this.model = model; VLayout inPanel = new VLayout(); inPanel.setHeight100(); inPanel.setWidth100(); Label message = new Label("Are you sure you want to remove the following " + itemsString + "?"); message.setStyleName("removePanelLabel"); message.setAutoHeight(); inPanel.addMember(message); for (Object item : model.getSelectedItems()) { Label l = new Label("- " + nameResolver.getItemName(item)); l.setStyleName("removePanelItems"); l.setAutoHeight(); l.setValign(VerticalAlignment.TOP); inPanel.addMember(l); } model .getPropertyChangedEvent() .addListener( new IEventListener() { @Override public void eventRaised(Event ev, Object sender, EventArgs args) { String propertyName = ((PropertyChangedEventArgs) args).PropertyName; GWT.log("DERBA: " + propertyName); if (propertyName.equals("Window") || propertyName.equals("ConfirmationModel")) { destroy(); model.getPropertyChangedEvent().removeListener(this); if (gridController != null) gridController.gridChangePerformed(); } } }); Button okButton = new Button("OK"); okButton.addClickHandler( new ClickHandler() { @Override public void onClick(ClickEvent event) { model.ExecuteCommand(new UICommand("OnRemove", model)); } }); Button cancelButton = new Button("Cancel"); cancelButton.addClickHandler( new ClickHandler() { @Override public void onClick(ClickEvent event) { onClose(); } }); setFooterButtons(Alignment.RIGHT, okButton, cancelButton); addItem(inPanel); }