package votorola.s.gwt.stage.talk; // Copyright 2012, Christian Weilbach. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE. import votorola.a.web.gwt.App; import votorola.g.lang.Warning; import votorola.g.web.gwt.GWTX; import votorola.g.web.gwt.event.Change; import votorola.s.gwt.stage.Stage; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.MouseOutEvent; import com.google.gwt.event.dom.client.MouseOutHandler; import com.google.gwt.event.dom.client.MouseOverEvent; import com.google.gwt.event.dom.client.MouseOverHandler; import com.google.gwt.uibinder.client.UiConstructor; import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.Panel; import com.google.gwt.user.client.ui.PopupPanel; import com.google.gwt.user.client.ui.ScrollPanel; import com.google.gwt.user.client.ui.VerticalPanel; @Warning("non-Api") /** * A button triggering a dialog through the forum update process. * */ class UpdateButton extends Image implements MouseOverHandler, MouseOutHandler, ClickHandler { /** * @param talkTrackV parent view */ @Warning("non-Api") @UiConstructor UpdateButton(TalkTrackV talkTrackV) { this.talkTrackV = talkTrackV; setUrl(App.getServletContextLocation() + "/stage/talk/plus.png"); setAltText("Update forums"); setTitle("Update forums"); addClickHandler(this); addMouseOverHandler(this); addMouseOutHandler(this); } /** * Called from {@linkplain TalkTrackV} when new data is loaded in the view. * @param success Whether new posts have arrived. */ public void update(final boolean success) { if(clicked) { updateFinished(success); } else { reset(); } } /** * Reset the state of the dialog and button. */ public void reset() { final String actorName = Stage.i().getActorName(); if (actorName != null && Stage.i().getPollName() != null) { clicked = false; updateDialogInformation("Kick an update on all forums linked on position of " + actorName, true); } else { updateDialogInformation(needsActor, false); } } //// P r i v a t e /////////////////////////////////////////////////////////////////////// private final TalkTrackV talkTrackV; private boolean clicked = false; private void updateFinished(final boolean success) { if(success){ updateDialogInformation("New posts fetched!", false); } else { updateDialogInformation("No new posts fetched.", false); } } // - U I ------------------------------------------------------------------------------ private final VerticalPanel popupPanel = new VerticalPanel(); { popupPanel.setStyleName("popupPanel"); } private final Button closeButton = new Button("x"); { closeButton.setStyleName("closeButton"); closeButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { popup.hide(); } }); } // - D i a l o g ---------------------------------------------------------------------- private final String needsActor = "You need to select an actor first."; private final Label infoLabel = new Label(needsActor); private final ScrollPanel scrollPanel = new ScrollPanel(infoLabel); { scrollPanel.setWidth("200px"); scrollPanel.setHeight("50px"); } private void updateDialogInformation(final String text, boolean isEnabled) { infoLabel.setText(text); dialogButton.setEnabled(isEnabled); dialogButton.setStyleDependentName("disabled", !isEnabled); } private final Button dialogButton = new Button("kick update"); { dialogButton.setStyleName("updateButton"); dialogButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { updateDialogInformation("Waiting for freshly harvested posts ...", false); GWTX.i().bus().fireEventFromSource(new Change(), talkTrackV); clicked = true; } }); popupPanel.add(closeButton); popupPanel.setCellHorizontalAlignment(closeButton,VerticalPanel.ALIGN_RIGHT); popupPanel.add(scrollPanel); popupPanel.add(dialogButton); popupPanel.setCellHorizontalAlignment(dialogButton,VerticalPanel.ALIGN_CENTER); } private final PopupPanel popup = new PopupPanel(); { popup.add(popupPanel); } // - C l i c k - H a n d l e r ------------------------------------------------- @Override public void onClick( ClickEvent e ) { popup.show(); popup.setPopupPosition(e.getClientX()-popupPanel.getOffsetWidth(), e.getClientY()); } // - M o u s e - O v e r - H a n d l e r ------------------------------------------ @Override public void onMouseOver( MouseOverEvent e ) { setStyleDependentName("hover", true); } // - M o u s e - O u t - H a n d l e r ------------------------------------------ @Override public void onMouseOut(MouseOutEvent e) { setStyleDependentName("hover", false); } }