View Javadoc
1   /*
2    * Copyright (C) 2013 4th Line GmbH, Switzerland
3    *
4    * The contents of this file are subject to the terms of either the GNU
5    * Lesser General Public License Version 2 or later ("LGPL") or the
6    * Common Development and Distribution License Version 1 or later
7    * ("CDDL") (collectively, the "License"). You may not use this file
8    * except in compliance with the License. See LICENSE.txt for more
9    * information.
10   *
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14   */
15  
16  package org.fourthline.cling.support.shared.log.impl;
17  
18  import org.fourthline.cling.support.shared.TextExpand;
19  import org.fourthline.cling.support.shared.log.LogView;
20  import org.seamless.swing.logging.LogMessage;
21  
22  import javax.annotation.PreDestroy;
23  import javax.enterprise.context.ApplicationScoped;
24  import javax.enterprise.event.Event;
25  import javax.inject.Inject;
26  import javax.swing.SwingUtilities;
27  
28  /**
29   * @author Christian Bauer
30   */
31  @ApplicationScoped
32  public class LogPresenter implements LogView.Presenter {
33  
34      @Inject
35      protected LogView view;
36  
37      @Inject
38      protected Event<TextExpand> textExpandEvent;
39  
40      public void init() {
41          view.setPresenter(this);
42      }
43  
44      @Override
45      public void onExpand(LogMessage logMessage) {
46          textExpandEvent.fire(new TextExpand(logMessage.getMessage()));
47      }
48  
49      @PreDestroy
50      public void destroy() {
51          SwingUtilities.invokeLater(new Runnable() {
52              public void run() {
53                  view.dispose();
54              }
55          });
56      }
57  
58      @Override
59      public void pushMessage(final LogMessage message) {
60          SwingUtilities.invokeLater(new Runnable() {
61              public void run() {
62                  view.pushMessage(message);
63              }
64          });
65      }
66  
67  }