001package 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. 002 003import votorola.a.web.gwt.App; 004import votorola.g.lang.Warning; 005import votorola.g.web.gwt.GWTX; 006import votorola.g.web.gwt.event.Change; 007import votorola.s.gwt.stage.Stage; 008 009import com.google.gwt.event.dom.client.ClickEvent; 010import com.google.gwt.event.dom.client.ClickHandler; 011import com.google.gwt.event.dom.client.MouseOutEvent; 012import com.google.gwt.event.dom.client.MouseOutHandler; 013import com.google.gwt.event.dom.client.MouseOverEvent; 014import com.google.gwt.event.dom.client.MouseOverHandler; 015import com.google.gwt.uibinder.client.UiConstructor; 016import com.google.gwt.user.client.ui.Button; 017import com.google.gwt.user.client.ui.Image; 018import com.google.gwt.user.client.ui.Label; 019import com.google.gwt.user.client.ui.Panel; 020import com.google.gwt.user.client.ui.PopupPanel; 021import com.google.gwt.user.client.ui.ScrollPanel; 022import com.google.gwt.user.client.ui.VerticalPanel; 023 024@Warning("non-Api") 025/** 026 * A button triggering a dialog through the forum update process. 027 * 028 */ 029class UpdateButton extends Image implements MouseOverHandler, MouseOutHandler, ClickHandler { 030 031 032 /** 033 * @param talkTrackV parent view 034 */ 035 @Warning("non-Api") 036 @UiConstructor UpdateButton(TalkTrackV talkTrackV) 037 { 038 this.talkTrackV = talkTrackV; 039 setUrl(App.getServletContextLocation() + "/stage/talk/plus.png"); 040 setAltText("Update forums"); 041 setTitle("Update forums"); 042 addClickHandler(this); 043 addMouseOverHandler(this); 044 addMouseOutHandler(this); 045 } 046 047 048 /** 049 * Called from {@linkplain TalkTrackV} when new data is loaded in the view. 050 * @param success Whether new posts have arrived. 051 */ 052 public void update(final boolean success) 053 { 054 if(clicked) { updateFinished(success); } 055 else { reset(); } 056 } 057 058 059 060 /** 061 * Reset the state of the dialog and button. 062 */ 063 public void reset() 064 { 065 final String actorName = Stage.i().getActorName(); 066 if (actorName != null 067 && Stage.i().getPollName() != null) 068 { 069 clicked = false; 070 updateDialogInformation("Kick an update on all forums linked on position of " + actorName, true); 071 072 } else { updateDialogInformation(needsActor, false); } 073 } 074 075 076 077//// P r i v a t e /////////////////////////////////////////////////////////////////////// 078 079 080 private final TalkTrackV talkTrackV; 081 082 083 084 private boolean clicked = false; 085 086 087 088 private void updateFinished(final boolean success) 089 { 090 if(success){ updateDialogInformation("New posts fetched!", false); } 091 else { updateDialogInformation("No new posts fetched.", false); } 092 } 093 094 095 096 097 // - U I ------------------------------------------------------------------------------ 098 099 100 private final VerticalPanel popupPanel = new VerticalPanel(); 101 { popupPanel.setStyleName("popupPanel"); } 102 103 private final Button closeButton = new Button("x"); 104 { 105 closeButton.setStyleName("closeButton"); 106 closeButton.addClickHandler(new ClickHandler() { 107 108 @Override 109 public void onClick(ClickEvent event) { 110 popup.hide(); 111 } 112 }); 113 } 114 115 116 // - D i a l o g ---------------------------------------------------------------------- 117 118 119 private final String needsActor = "You need to select an actor first."; 120 121 122 private final Label infoLabel = new Label(needsActor); 123 124 125 private final ScrollPanel scrollPanel = new ScrollPanel(infoLabel); 126 { 127 scrollPanel.setWidth("200px"); 128 scrollPanel.setHeight("50px"); 129 } 130 131 132 private void updateDialogInformation(final String text, boolean isEnabled) { 133 infoLabel.setText(text); 134 dialogButton.setEnabled(isEnabled); 135 dialogButton.setStyleDependentName("disabled", !isEnabled); 136 } 137 138 139 private final Button dialogButton = new Button("kick update"); 140 { 141 dialogButton.setStyleName("updateButton"); 142 dialogButton.addClickHandler(new ClickHandler() { 143 144 @Override 145 public void onClick(ClickEvent event) { 146 updateDialogInformation("Waiting for freshly harvested posts ...", false); 147 GWTX.i().bus().fireEventFromSource(new Change(), talkTrackV); 148 clicked = true; 149 } 150 151 }); 152 popupPanel.add(closeButton); 153 popupPanel.setCellHorizontalAlignment(closeButton,VerticalPanel.ALIGN_RIGHT); 154 popupPanel.add(scrollPanel); 155 popupPanel.add(dialogButton); 156 popupPanel.setCellHorizontalAlignment(dialogButton,VerticalPanel.ALIGN_CENTER); 157 } 158 159 160 private final PopupPanel popup = new PopupPanel(); 161 162 { popup.add(popupPanel); } 163 164 165 // - C l i c k - H a n d l e r ------------------------------------------------- 166 167 168 @Override 169 public void onClick( ClickEvent e ) { 170 popup.show(); 171 popup.setPopupPosition(e.getClientX()-popupPanel.getOffsetWidth(), e.getClientY()); 172 } 173 174 175 176 // - M o u s e - O v e r - H a n d l e r ------------------------------------------ 177 178 179 @Override 180 public void onMouseOver( MouseOverEvent e ) { setStyleDependentName("hover", true); } 181 182 183 184 // - M o u s e - O u t - H a n d l e r ------------------------------------------ 185 186 187 @Override 188 public void onMouseOut(MouseOutEvent e) { setStyleDependentName("hover", false); } 189 190 191}