Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Vector;
- import com.google.gwt.event.dom.client.ClickEvent;
- import com.google.gwt.event.dom.client.ClickHandler;
- import com.google.gwt.user.client.rpc.AsyncCallback;
- import com.google.gwt.user.client.ui.Button;
- import com.google.gwt.user.client.ui.FlexTable;
- import com.google.gwt.user.client.ui.Label;
- import com.google.gwt.user.client.ui.RootPanel;
- import de.hdm.datingservice.client.ClientsideSettings;
- import de.hdm.datingservice.client.login.LoginInfo;
- import de.hdm.datingservice.shared.DatingServiceAdministrationAsync;
- import de.hdm.datingservice.shared.bo.UserProfile;
- /**
- * Dies Klasse stellt dem Benutzer die blockierten Profile der Blockliste in
- * einer Tabelle dar. Ueber den Zeige Profil-Button kann der Benutzer sich das
- * andere Profil anzeigen lassen.
- *
- * @author simon
- */
- public class BlocklistView {
- private DatingServiceAdministrationAsync datingServiceAdministration = ClientsideSettings
- .getDatingServiceAdministration();
- private LoginInfo loginInfo = null;
- private String userEmail;
- private Label lbl;
- private Button showOtherProfileButton;
- private int blocklistCounter = 1;
- private FlexTable blocklistTable = new FlexTable();
- private Button backToBlocklistButton;
- /**
- * *************************************************************************
- * *********** Konstruktor
- * *************************************************************************
- * ***********
- */
- /**
- * Der Konstruktor laedt vorerst den aktuellen Benutzer ueber die
- * Email-Adresse. Wenn dies erfolgreich ist, wird ueber die Methode
- * createBlocklistTable() der Benutzer uebergeben, damit im Folgenden alle
- * blockierten Profile der Blockliste geladen werden koennen.
- *
- * @param loginInfo
- * @author marc
- */
- public BlocklistView(LoginInfo loginInfo) {
- // Content wird geloescht
- RootPanel.get("Content").clear();
- RootPanel.get("Subnav").clear();
- // LoginInfo wird Klassenvariable zugewiesen
- this.loginInfo = loginInfo;
- // UserEmail wird ausgelesen
- userEmail = loginInfo.getEmailAddress();
- // Profil der zugehoerigen E-Mail wird ausgelesen
- AsyncCallback<UserProfile> getProfileCallback = new AsyncCallback<UserProfile>() {
- public void onFailure(Throwable caught) {
- ClientsideSettings.getLogger().severe("Profil konnte nicht geladen werden");
- }
- public void onSuccess(UserProfile user) {
- lbl = new Label("Dies sind die gesperrten Profile von: " + user.getNickname());
- RootPanel.get("Content").add(lbl);
- lbl.addStyleName("headline");
- createBlocklistTable(user);
- }
- };
- datingServiceAdministration.getUserProfileByEmail(userEmail, getProfileCallback);
- }
- /**
- * *************************************************************************
- * *********** Methoden
- * *************************************************************************
- * ***********
- */
- /**
- * Diese Methode laedt ueber die asynchrone Methode
- * getBlocklistByUserProfile alle blockierten Profile. Der Ergebnisvektor
- * mit allen blockierten Profilen wird mit einer Schleife ausgelesen und in
- * einer Tabelle eingetragen.
- *
- * @param user
- * @author marc
- */
- public void createBlocklistTable(UserProfile user) {
- AsyncCallback<Vector<UserProfile>> getBlocksCallback = new AsyncCallback<Vector<UserProfile>>() {
- public void onFailure(Throwable caught) {
- ClientsideSettings.getLogger().severe("Blockliste konnten nicht geladen werden");
- }
- @Override
- public void onSuccess(Vector<UserProfile> result) {
- for (UserProfile otherUser : result) {
- showOtherProfileButton = new Button("");
- showOtherProfileButton.setStyleName("profilButton");
- showOtherProfileButton.addClickHandler(new showOtherProfileClickHandler(otherUser));
- blocklistTable.setText(0, 0, "Vorname");
- blocklistTable.setText(0, 1, "Nachname");
- blocklistTable.setText(0, 2, "Geburtstag");
- blocklistTable.setText(0, 3, "Profil anzeigen");
- blocklistTable.getCellFormatter().addStyleName(0, 0, "flexTableColumns");
- blocklistTable.getCellFormatter().addStyleName(0, 1, "flexTableColumns");
- blocklistTable.getCellFormatter().addStyleName(0, 2, "flexTableColumns");
- blocklistTable.getCellFormatter().addStyleName(0, 3, "flexTableColumns");
- blocklistTable.addStyleName("flexTable");
- blocklistTable.getRowFormatter().addStyleName(0, "flexTableHeader");
- blocklistTable.setText(blocklistCounter, 0, otherUser.getFirstName());
- blocklistTable.setText(blocklistCounter, 1, otherUser.getLastName());
- blocklistTable.setText(blocklistCounter, 2, otherUser.getBirthday().toString());
- blocklistTable.setWidget(blocklistCounter, 3, showOtherProfileButton);
- if (blocklistCounter % 2 == 0) {
- blocklistTable.getRowFormatter().addStyleName(blocklistCounter, "flexTableRow0");
- } else {
- blocklistTable.getRowFormatter().addStyleName(blocklistCounter, "flexTableRow1");
- }
- blocklistCounter++;
- }
- }
- };
- datingServiceAdministration.getBlocksByUserProfile(user, getBlocksCallback);
- RootPanel.get("Content").add(blocklistTable);
- }
- /**
- * *************************************************************************
- * *********** CLICK HANDLER
- * *************************************************************************
- * ***********
- */
- /**
- * Dies ist der Click Handler fuer die Weiterleitung auf das jeweilig andere
- * Profil. Im ersten Schritt wird ueber den Konstruktor das zu besuchende
- * Profil uebergeben und ein neues UserProfile erzeugt. Beim Klick wird die
- * asnychrone Methode getUserProfileByEmail() aufgerufen, mit welcher erneut
- * der Benutzer/Eigentuemer des Merkzettels geladen wird. Bei Erfolg wird
- * eine neue Klasse (OtherProfileView) instanziiert. Hier wird das
- * LoginInfo-Objekt und das UserProfile-Objekt des Eigentuemers, sowie das
- * gemerkte Benutzerprofil uebergeben
- *
- * @author marc
- */
- class showOtherProfileClickHandler implements ClickHandler {
- UserProfile otherUser;
- public showOtherProfileClickHandler(UserProfile otherUser) {
- this.otherUser = otherUser;
- }
- public void onClick(ClickEvent event) {
- // Zurueck Button
- backToBlocklistButton = new Button("Zurück");
- backToBlocklistButton.setStyleName("menubutton");
- backToBlocklistButton.addClickHandler(new BackToBlocklistButtonClickHandler());
- RootPanel.get("Subnav").add(backToBlocklistButton);
- AsyncCallback<UserProfile> getProfileCallback = new AsyncCallback<UserProfile>() {
- public void onFailure(Throwable caught) {
- ClientsideSettings.getLogger().severe("Profil konnte nicht geladen werden");
- }
- public void onSuccess(UserProfile user) {
- OtherProfileView otherProfileView = new OtherProfileView(loginInfo, user, otherUser);
- }
- };
- datingServiceAdministration.getUserProfileByEmail(userEmail, getProfileCallback);
- }
- }
- /**
- * Dieser Click Handler leitet den Benutzer zurueck zu der Ansicht des
- * Merkzettels.
- *
- * @author simon
- */
- class BackToBlocklistButtonClickHandler implements ClickHandler {
- public void onClick(ClickEvent event) {
- BlocklistView blocklistView = new BlocklistView(loginInfo);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement