Package com.toedter.gwt.demo.contacts.shared

Examples of com.toedter.gwt.demo.contacts.shared.Contact


    contactsRepository.saveContact(contact);
    contacts = contactsRepository.getAllContacts();
  }

  public void deleteContact(Contact contact) {
    Contact originalContact = getContactByFileName(contact.getFileName());
    if (originalContact != null) {
      contactsRepository.removeContact(originalContact);
      contacts = contactsRepository.getAllContacts();
    }
  }
View Full Code Here


  public VCardContactsRepository() {
    contacts = new ArrayList<Contact>();
    try {
      for (File file : getContacts()) {
        Contact contact = readFromVCard(file.getAbsolutePath());
        contact.setFileName(file.getAbsolutePath());
        contacts.add(contact);
      }
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
View Full Code Here

   * @param fileName
   *            the vcard file
   * @return the created Contact
   */
  public Contact readFromVCard(String fileName) {
    Contact contact = new Contact();
    BufferedReader bufferedReader = null;
    String charSet = "Cp1252";

    // parse the vCard
    try {
      InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(fileName), charSet);
      bufferedReader = new BufferedReader(inputStreamReader);
      String line;
      String value;
      while ((line = bufferedReader.readLine()) != null) {
        value = getVCardValue(line, "N");
        if (value != null) {
          String[] result = value.split(";");

          if (result.length > 0) {
            contact.setLastName(result[0]);
          }
          if (result.length > 1) {
            contact.setFirstName(result[1]);
          }
          if (result.length > 2) {
            contact.setMiddleName(result[2]);
          }
          if (result.length > 3) {
            contact.setTitle(result[3]);
          }
          continue;
        }
        value = getVCardValue(line, "TEL;WORK");
        if (value != null) {
          contact.setPhone(value);
          continue;
        }
        value = getVCardValue(line, "TEL;CELL");
        if (value != null) {
          contact.setMobile(value);
          continue;
        }
        value = getVCardValue(line, "ADR;WORK");
        if (value != null) {
          String[] result = value.split(";");

          if (result.length > 2) {
            contact.setStreet(result[2]);
          }
          if (result.length > 3) {
            contact.setCity(result[3]);
          }
          if (result.length > 4) {
            contact.setState(result[4]);
          }
          if (result.length > 5) {
            contact.setZip(result[5]);
          }
          if (result.length > 6) {
            contact.setCountry(result[6]);
          }
          continue;
        }
        value = getVCardValue(line, "EMAIL;PREF;INTERNET");
        if (value != null) {
          contact.setEmail(value);
          continue;
        }
        value = getVCardValue(line, "URL;WORK");
        if (value != null) {
          contact.setWebPage(value);
          continue;
        }
        value = getVCardValue(line, "ORG");
        if (value != null) {
          contact.setCompany(value);
          continue;
        }
        value = getVCardValue(line, "TITLE");
        if (value != null) {
          contact.setJobTitle(value);
          continue;
        }
        value = getVCardValue(line, "NOTE");
        if (value != null) {
          contact.setNote(value);
          continue;
        }
        value = getVCardValue(line, "PHOTO;TYPE=JPEG;ENCODING=BASE64");
        if (value != null) {
          line = bufferedReader.readLine();
          StringBuilder builder = new StringBuilder();
          while (line != null && line.length() > 0 && line.charAt(0) == ' ') {
            builder.append(line.trim());
            line = bufferedReader.readLine();
          }
          String jpegString = builder.toString();

          String base64 = "data:image/png;base64," + jpegString;
          contact.setJpegString(base64);
          continue;
        }
      }
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
View Full Code Here

      if (fileName == null || fileName.trim().length() == 0) {
        String dir = getVCardsDir();
        fileName = dir + "/" + contact.getFirstName() + " " + contact.getLastName() + ".vcf";
        contact.setFileName(fileName);
      } else {
        Contact oldContact = getContactByFileName(fileName);
        if (oldContact != null) {
          contacts.remove(oldContact);
        }
      }
      contacts.add(contact);
View Full Code Here

    Answer<Void> answer = new Answer<Void>() {
      @Override
      public Void answer(InvocationOnMock invocation) {
        Object[] args = invocation.getArguments();
        AsyncCallback<List<Contact>> asyncCallback = (AsyncCallback<List<Contact>>) args[0];
        contact1 = new Contact();
        contact1.setFirstName("Kai");
        contact1.setLastName("Toedter");
        contact1.setEmail("kai@toedter.com");
        contact2 = new Contact();
        contact2.setFirstName("Kai2");
        contact2.setLastName("Toedter2");
        contact2.setEmail("kai2@toedter.com");
        final List<Contact> contacts2 = new ArrayList<Contact>();
        contacts2.add(contact1);
View Full Code Here

  @Override
  public void saveContact() {
    System.out.println("ToolBarActivity.saveContact()");
    ContactDetailsActivity contactDetailsActivity = ActivityRegistry.getContactDetailsActivity();
    if (contactDetailsActivity != null) {
      final Contact contact = contactDetailsActivity.getContact();
      IContactServiceAsync contactService = clientFactory.getContactService();
      contactService.saveContact(contact, new AsyncCallback<Void>() {

        @Override
        public void onSuccess(Void result) {
          System.out.println("Contact saved");
          clientFactory.setContacts(null);
          clientFactory.getPlaceController().goTo(new ContactPlace(contact.getEmail()));
        }

        @Override
        public void onFailure(Throwable caught) {
          System.err.println("Cannot save contact: " + contact);
View Full Code Here

  @Override
  public void deleteContact() {
    System.out.println("ToolBarActivity.deleteContact()");
    ContactDetailsActivity contactDetailsActivity = ActivityRegistry.getContactDetailsActivity();
    if (contactDetailsActivity != null) {
      final Contact contact = contactDetailsActivity.getContact();
      IContactServiceAsync contactService = clientFactory.getContactService();
      contactService.deleteContact(contact, new AsyncCallback<Void>() {

        @Override
        public void onSuccess(Void result) {
View Full Code Here

  public void goTo(Place place) {
    clientFactory.getPlaceController().goTo(place);
  }

  public void selectInitialContact(String email) {
    Contact contact = getContact(email);
    if (contact != null) {
      contactListView.selectInitialContact(contact);
      eventBus.fireEvent(new ContactViewEvent(contact));
    }
  }
View Full Code Here

  }

  @Override
  public void select(int index) {
    System.out.println("ContactListActivity.select(): " + index);
    Contact contact = clientFactory.getContacts().get(index);
    eventBus.fireEvent(new ContactViewEvent(contact));
    goTo(new ContactPlace(contact.getEmail()));
  }
View Full Code Here

  }

  @Override
  public Contact getContact() {
    if (contact == null) {
      contact = new Contact();
    }

    contact.setTitle(title.getText());
    String[] names = name.getText().split(" ");
    if (names.length > 0) {
View Full Code Here

TOP

Related Classes of com.toedter.gwt.demo.contacts.shared.Contact

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.