Commits

Kevin Poalses  committed a89bd07

QUALIMP: The view persons tool command is now almost useful ;-)

  • Participants
  • Parent commits e5efd7e
  • Branches editing

Comments (0)

Files changed (6)

 
 ### Prerequisites
 
-#### Java 7 SE JDK
+#### Java 7 SE JDK (update 6 or later)
 
 Download and install the [Java 7 SE JDK](http://www.oracle.com/technetwork/java/javase/downloads/index.html)
 
 Runtime Requirements
 --------------------
 
-- [Java 7 SE](http://www.oracle.com/technetwork/java/javase/downloads/index.html)
+- [Java 7 SE update 6 or later](http://www.oracle.com/technetwork/java/javase/downloads/index.html)
 
 ***
 Licensing

File src/main/java/net/poalsoft/dossier/contacts/tool/internal/ViewPersonsApplication.java

     public void start(Stage stage) throws Exception {
 
         Scene scene = new Scene(new Group());
-        stage.setTitle("Person View Sample");
-        stage.setWidth(850);
-        stage.setHeight(500);
+        stage.setTitle("Viewing Persons");
+        stage.setWidth(1280);
+        stage.setHeight(600);
 
         final Label label = new Label("Persons");
         label.setFont(new Font("Arial", 20));

File src/main/java/net/poalsoft/dossier/contacts/tool/internal/ViewPersonsModel.java

         visualPersonProxyBuilder.withVisualType(VisualPerson.class);
 
         for (Person person : this.personRepository.findAll()) {
-            logger.trace("Adding person [{}] to visual persons list",
-                         person.getDerivedDisplayName());
-            persons.add(visualPersonProxyBuilder
-                                .withWrappedEntity(person)
-                                .<VisualPerson>build());
+            if (!person.getDerivedDisplayName().isEmpty()) {
+                logger.trace("Adding person [{}] to visual persons list",
+                             person.getDerivedDisplayName());
+                persons.add(visualPersonProxyBuilder
+                                    .withWrappedEntity(person)
+                                    .<VisualPerson>build());
+            }
         }
 
         return persons;

File src/main/java/net/poalsoft/dossier/contacts/ui/view/internal/AbstractVisualContactTableViewBuilder.java

 
 package net.poalsoft.dossier.contacts.ui.view.internal;
 
+import javafx.beans.property.ReadOnlyStringWrapper;
+import javafx.beans.value.ObservableValue;
 import javafx.scene.control.TableColumn;
 import javafx.scene.control.TableColumnBuilder;
 import javafx.scene.control.cell.PropertyValueFactoryBuilder;
+import javafx.util.Callback;
+import net.poalsoft.dossier.contacts.base.EmailAddress;
 import net.poalsoft.dossier.contacts.base.Geolocation;
+import net.poalsoft.dossier.contacts.ui.model.VisualContact;
 import net.poalsoft.dossier.contacts.ui.view.VisualEntityTableViewBuilder;
 
 import javax.annotation.concurrent.ThreadSafe;
+import java.util.Iterator;
 
 /**
  * An abstract visual contact table view builder.
  * @author Kevin Poalses
  */
 @ThreadSafe
-public abstract class AbstractVisualContactTableViewBuilder<VisualContactEntity> extends
-                                                                                 AbstractVisualEntityTableViewBuilder<VisualContactEntity> {
+public abstract class AbstractVisualContactTableViewBuilder<VisualContactEntity extends VisualContact> extends
+                                                                                                       AbstractVisualEntityTableViewBuilder<VisualContactEntity> {
 
     public AbstractVisualContactTableViewBuilder() {
         super();
                         .build();
         withDefaultTableColumn(displayNameCol);
 
+        TableColumn<VisualContactEntity, String> emailAddressesCol =
+                TableColumnBuilder
+                        .<VisualContactEntity, String>create()
+                        .text("Email")
+                        .cellValueFactory(
+                                new ContactEmailAddressesCellValueFactoryCallback<VisualContactEntity>())
+                        .build();
+        withDefaultTableColumn(emailAddressesCol);
+
         return this;
     }
 
 
         return this;
     }
+
+    private static class ContactEmailAddressesCellValueFactoryCallback<VisualContactEntity extends VisualContact> implements
+                                                                                                                  Callback<TableColumn.CellDataFeatures<VisualContactEntity, String>, ObservableValue<String>> {
+        @Override
+        public ObservableValue<String> call(TableColumn.CellDataFeatures<VisualContactEntity, String> cellDataFeatures) {
+            Iterator<EmailAddress> emailAddressIterator =
+                    cellDataFeatures.getValue()
+                                    .getEmailAddresses()
+                                    .iterator();
+            StringBuilder sb = new StringBuilder();
+            if (emailAddressIterator.hasNext()) {
+                sb.append(emailAddressIterator.next()
+                                              .getEmailURI()
+                                              .getSchemeSpecificPart());
+                while (emailAddressIterator.hasNext()) {
+                    sb.append(", ")
+                      .append(emailAddressIterator.next()
+                                                  .getEmailURI()
+                                                  .getSchemeSpecificPart());
+                }
+            }
+            return new ReadOnlyStringWrapper(sb.toString());
+        }
+    }
 }

File src/main/java/net/poalsoft/dossier/contacts/ui/view/internal/VisualPersonTableViewBuilderImpl.java

     @Override
     public VisualEntityTableViewBuilder<VisualPerson> withDefaultColumns() {
 
-        super.withDefaultColumns();
-
         TableColumn<VisualPerson, String> firstNameCol =
                 TableColumnBuilder
                         .<VisualPerson, String>create()
                         .build();
         withDefaultTableColumn(lastNameCol);
 
+        super.withDefaultColumns();
+
+        return this;
+    }
+
+    @Override
+    public VisualEntityTableViewBuilder<VisualPerson> withExtraColumns() {
+
+        super.withExtraColumns();
+
         TableColumn<VisualPerson, String> nickNameCol =
                 TableColumnBuilder
                         .<VisualPerson, String>create()
                                                                      .property("nickName")
                                                                      .build())
                         .build();
-        withDefaultTableColumn(nickNameCol);
-
-        return this;
-    }
-
-    @Override
-    public VisualEntityTableViewBuilder<VisualPerson> withExtraColumns() {
-
-        super.withExtraColumns();
+        withExtraTableColumn(nickNameCol);
 
         TableColumn<VisualPerson, PersonGender> genderCol =
                 TableColumnBuilder
 
     @Override
     public VisualEntityTableViewBuilder<VisualPerson> withDefaultPreferredWidth() {
-        return withPreferredWidth(800);
+        return withPreferredWidth(1200);
     }
 
 }

File src/test/java/net/poalsoft/dossier/contacts/ui/demo/ShowPersons.java

 
         Scene scene = new Scene(new Group());
         stage.setTitle("Person View Sample");
-        stage.setWidth(850);
+        stage.setWidth(800);
         stage.setHeight(500);
 
         final Label label = new Label("Persons");