Example #1
0
  public void refresh() {
    model.refresh();

    if (model.getEventList().size() > 0 && contacts.getSelectedIndex() == -1) {
      contacts.setSelectedIndex(0);
    }
  }
Example #2
0
  public void notifyTransactions(Iterable<TransactionDomainEvents> transactions) {
    if (Events.matches(
        Events.withNames("changedStatus", "addedContact", "deletedContact", "updatedContact"),
        transactions)) {
      refresh();

      if (Events.matches(Events.withNames("addedContact"), transactions)) {
        contacts.setSelectedIndex(contacts.getModel().getSize() - 1);
      } else if (Events.matches(Events.withNames("updatedContact"), transactions)) {
        model
            .getCurrentContact()
            .setContact(
                model.createInitialValues(model.getEventList().get(contacts.getSelectedIndex())));
      } else if (Events.matches(Events.withNames("deletedContact"), transactions)) {
        if (model.getEventList().size() >= 0) {
          contacts.setSelectedIndex(0);
        }
      }
    }
  }
Example #3
0
  public ContactsView(@Service ApplicationContext context, @Uses ContactsModel model) {
    super(new BorderLayout());

    this.model = model;

    ActionMap am = context.getActionMap(this);
    setActionMap(am);
    setPreferredSize(new Dimension(200, 0));

    this.setBorder(Borders.createEmptyBorder("2dlu, 2dlu, 2dlu, 2dlu"));

    contacts = new JList(new EventListModel<ContactDTO>(model.getEventList()));
    contacts.setPreferredSize(new Dimension(200, 1000));
    contacts.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JScrollPane contactsScrollPane = new JScrollPane();
    contactsScrollPane.setViewportView(contacts);
    contacts.setCellRenderer(
        new DefaultListCellRenderer() {

          @Override
          public Component getListCellRendererComponent(
              JList jList, Object o, int i, boolean b, boolean b1) {
            ContactDTO contact = (ContactDTO) o;
            if ("".equals(contact.name().get())) {
              Component cell =
                  super.getListCellRendererComponent(
                      jList, i18n.text(WorkspaceResources.name_label), i, b, b1);
              cell.setForeground(Color.GRAY);
              return cell;
            }

            String text = contact.name().get();

            return super.getListCellRendererComponent(jList, text, i, b, b1);
          }
        });
    add(contactsScrollPane, BorderLayout.CENTER);

    JPanel toolbar = new JPanel();
    toolbar.add(new StreamflowButton(am.get("add")));
    toolbar.add(new StreamflowButton(am.get("remove")));
    add(toolbar, BorderLayout.SOUTH);

    model.addObserver(new RefreshComponents().visibleOn("add", toolbar));

    contacts
        .getSelectionModel()
        .addListSelectionListener(new SelectionActionEnabler(am.get("remove")));

    /*
          setFocusTraversalPolicy( new LayoutFocusTraversalPolicy() );
          setFocusCycleRoot( true );
          setFocusable( true );
          addFocusListener( new FocusListener()
          {
             public void focusGained( FocusEvent e )
             {
                Component defaultComp = getFocusTraversalPolicy().getDefaultComponent( contactView );
                if (defaultComp != null)
                {
                   defaultComp.requestFocusInWindow();
                }
             }

             public void focusLost( FocusEvent e )
             {
             }
          } );
    */

    new RefreshWhenShowing(this, this);
  }