Advertisement
Guest User

Untitled

a guest
Jun 25th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.21 KB | None | 0 0
  1. import java.util.Vector;
  2.  
  3. import com.google.gwt.event.dom.client.ClickEvent;
  4. import com.google.gwt.event.dom.client.ClickHandler;
  5. import com.google.gwt.user.client.rpc.AsyncCallback;
  6. import com.google.gwt.user.client.ui.Button;
  7. import com.google.gwt.user.client.ui.FlexTable;
  8. import com.google.gwt.user.client.ui.Label;
  9. import com.google.gwt.user.client.ui.RootPanel;
  10.  
  11. import de.hdm.datingservice.client.ClientsideSettings;
  12. import de.hdm.datingservice.client.login.LoginInfo;
  13. import de.hdm.datingservice.shared.DatingServiceAdministrationAsync;
  14. import de.hdm.datingservice.shared.bo.UserProfile;
  15.  
  16. /**
  17.  * Dies Klasse stellt dem Benutzer die blockierten Profile der Blockliste in
  18.  * einer Tabelle dar. Ueber den Zeige Profil-Button kann der Benutzer sich das
  19.  * andere Profil anzeigen lassen.
  20.  *
  21.  * @author simon
  22.  */
  23. public class BlocklistView {
  24.  
  25.     private DatingServiceAdministrationAsync datingServiceAdministration = ClientsideSettings
  26.             .getDatingServiceAdministration();
  27.    
  28.     private LoginInfo loginInfo = null;
  29.     private String userEmail;
  30.     private Label lbl;
  31.     private Button showOtherProfileButton;
  32.     private int blocklistCounter = 1;
  33.     private FlexTable blocklistTable = new FlexTable();
  34.     private Button backToBlocklistButton;
  35.  
  36.     /**
  37.      * *************************************************************************
  38.      * *********** Konstruktor
  39.      * *************************************************************************
  40.      * ***********
  41.      */
  42.     /**
  43.      * Der Konstruktor laedt vorerst den aktuellen Benutzer ueber die
  44.      * Email-Adresse. Wenn dies erfolgreich ist, wird ueber die Methode
  45.      * createBlocklistTable() der Benutzer uebergeben, damit im Folgenden alle
  46.      * blockierten Profile der Blockliste geladen werden koennen.
  47.      *
  48.      * @param loginInfo
  49.      * @author marc
  50.      */
  51.     public BlocklistView(LoginInfo loginInfo) {
  52.  
  53.         // Content wird geloescht
  54.         RootPanel.get("Content").clear();
  55.         RootPanel.get("Subnav").clear();
  56.  
  57.         // LoginInfo wird Klassenvariable zugewiesen
  58.         this.loginInfo = loginInfo;
  59.  
  60.         // UserEmail wird ausgelesen
  61.         userEmail = loginInfo.getEmailAddress();
  62.  
  63.         // Profil der zugehoerigen E-Mail wird ausgelesen
  64.         AsyncCallback<UserProfile> getProfileCallback = new AsyncCallback<UserProfile>() {
  65.             public void onFailure(Throwable caught) {
  66.                 ClientsideSettings.getLogger().severe("Profil konnte nicht geladen werden");
  67.             }
  68.  
  69.             public void onSuccess(UserProfile user) {
  70.                 lbl = new Label("Dies sind die gesperrten Profile von: " + user.getNickname());
  71.                 RootPanel.get("Content").add(lbl);
  72.                 lbl.addStyleName("headline");
  73.                 createBlocklistTable(user);
  74.             }
  75.         };
  76.         datingServiceAdministration.getUserProfileByEmail(userEmail, getProfileCallback);
  77.     }
  78.  
  79.     /**
  80.      * *************************************************************************
  81.      * *********** Methoden
  82.      * *************************************************************************
  83.      * ***********
  84.      */
  85.     /**
  86.      * Diese Methode laedt ueber die asynchrone Methode
  87.      * getBlocklistByUserProfile alle blockierten Profile. Der Ergebnisvektor
  88.      * mit allen blockierten Profilen wird mit einer Schleife ausgelesen und in
  89.      * einer Tabelle eingetragen.
  90.      *
  91.      * @param user
  92.      * @author marc
  93.      */
  94.     public void createBlocklistTable(UserProfile user) {
  95.         AsyncCallback<Vector<UserProfile>> getBlocksCallback = new AsyncCallback<Vector<UserProfile>>() {
  96.             public void onFailure(Throwable caught) {
  97.                 ClientsideSettings.getLogger().severe("Blockliste konnten nicht geladen werden");
  98.             }
  99.  
  100.             @Override
  101.             public void onSuccess(Vector<UserProfile> result) {
  102.                 for (UserProfile otherUser : result) {
  103.                     showOtherProfileButton = new Button("");
  104.                     showOtherProfileButton.setStyleName("profilButton");
  105.                     showOtherProfileButton.addClickHandler(new showOtherProfileClickHandler(otherUser));
  106.  
  107.                     blocklistTable.setText(0, 0, "Vorname");
  108.                     blocklistTable.setText(0, 1, "Nachname");
  109.                     blocklistTable.setText(0, 2, "Geburtstag");
  110.                     blocklistTable.setText(0, 3, "Profil anzeigen");
  111.  
  112.                     blocklistTable.getCellFormatter().addStyleName(0, 0, "flexTableColumns");
  113.                     blocklistTable.getCellFormatter().addStyleName(0, 1, "flexTableColumns");
  114.                     blocklistTable.getCellFormatter().addStyleName(0, 2, "flexTableColumns");
  115.                     blocklistTable.getCellFormatter().addStyleName(0, 3, "flexTableColumns");
  116.  
  117.                     blocklistTable.addStyleName("flexTable");
  118.                     blocklistTable.getRowFormatter().addStyleName(0, "flexTableHeader");
  119.  
  120.                     blocklistTable.setText(blocklistCounter, 0, otherUser.getFirstName());
  121.                     blocklistTable.setText(blocklistCounter, 1, otherUser.getLastName());
  122.                     blocklistTable.setText(blocklistCounter, 2, otherUser.getBirthday().toString());
  123.                     blocklistTable.setWidget(blocklistCounter, 3, showOtherProfileButton);
  124.  
  125.                     if (blocklistCounter % 2 == 0) {
  126.                         blocklistTable.getRowFormatter().addStyleName(blocklistCounter, "flexTableRow0");
  127.                     } else {
  128.                         blocklistTable.getRowFormatter().addStyleName(blocklistCounter, "flexTableRow1");
  129.                     }
  130.  
  131.                     blocklistCounter++;
  132.                 }
  133.  
  134.             }
  135.         };
  136.         datingServiceAdministration.getBlocksByUserProfile(user, getBlocksCallback);
  137.  
  138.         RootPanel.get("Content").add(blocklistTable);
  139.     }
  140.  
  141.     /**
  142.      * *************************************************************************
  143.      * *********** CLICK HANDLER
  144.      * *************************************************************************
  145.      * ***********
  146.      */
  147.     /**
  148.      * Dies ist der Click Handler fuer die Weiterleitung auf das jeweilig andere
  149.      * Profil. Im ersten Schritt wird ueber den Konstruktor das zu besuchende
  150.      * Profil uebergeben und ein neues UserProfile erzeugt. Beim Klick wird die
  151.      * asnychrone Methode getUserProfileByEmail() aufgerufen, mit welcher erneut
  152.      * der Benutzer/Eigentuemer des Merkzettels geladen wird. Bei Erfolg wird
  153.      * eine neue Klasse (OtherProfileView) instanziiert. Hier wird das
  154.      * LoginInfo-Objekt und das UserProfile-Objekt des Eigentuemers, sowie das
  155.      * gemerkte Benutzerprofil uebergeben
  156.      *
  157.      * @author marc
  158.      */
  159.     class showOtherProfileClickHandler implements ClickHandler {
  160.         UserProfile otherUser;
  161.  
  162.         public showOtherProfileClickHandler(UserProfile otherUser) {
  163.             this.otherUser = otherUser;
  164.         }
  165.  
  166.         public void onClick(ClickEvent event) {
  167.             // Zurueck Button
  168.             backToBlocklistButton = new Button("Zurück");
  169.             backToBlocklistButton.setStyleName("menubutton");
  170.             backToBlocklistButton.addClickHandler(new BackToBlocklistButtonClickHandler());
  171.             RootPanel.get("Subnav").add(backToBlocklistButton);
  172.  
  173.             AsyncCallback<UserProfile> getProfileCallback = new AsyncCallback<UserProfile>() {
  174.                 public void onFailure(Throwable caught) {
  175.                     ClientsideSettings.getLogger().severe("Profil konnte nicht geladen werden");
  176.                 }
  177.  
  178.                 public void onSuccess(UserProfile user) {
  179.                     OtherProfileView otherProfileView = new OtherProfileView(loginInfo, user, otherUser);
  180.                 }
  181.             };
  182.             datingServiceAdministration.getUserProfileByEmail(userEmail, getProfileCallback);
  183.         }
  184.     }
  185.  
  186.     /**
  187.      * Dieser Click Handler leitet den Benutzer zurueck zu der Ansicht des
  188.      * Merkzettels.
  189.      *
  190.      * @author simon
  191.      */
  192.     class BackToBlocklistButtonClickHandler implements ClickHandler {
  193.         public void onClick(ClickEvent event) {
  194.             BlocklistView blocklistView = new BlocklistView(loginInfo);
  195.         }
  196.     }
  197. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement