View Javadoc

1   /*
2    * $Id$
3    *
4    * The contents of this file are subject to the Mozilla Public License 
5    * Version 1.1 (the "License"); you may not use this file except in 
6    * compliance with the License. You may obtain a copy of the License at 
7    * http://www.mozilla.org/MPL/ 
8    *
9    * Software distributed under the License is distributed on an "AS IS" basis, 
10   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
11   * for the specific language governing rights and limitations under the License.
12   *
13   * The Original Code is XML Hammer code. (org.xmlhammer.*)
14   *
15   * The Initial Developer of the Original Code is Edwin Dankert. Portions created 
16   * by the Initial Developer are Copyright (C) 2005 - 2006 the Initial Developer. 
17   * All Rights Reserved.
18   *
19   * Contributor(s): Edwin Dankert <edankert@gmail.com>
20   */
21  package org.xmlhammer.gui.output;
22  
23  import java.net.URI;
24  
25  import javax.swing.ImageIcon;
26  import javax.swing.JFrame;
27  import javax.swing.JPopupMenu;
28  
29  import org.bounce.RunnableAction;
30  import org.bounce.MenuUtilities;
31  import org.bounce.image.ImageLoader;
32  import org.xmlhammer.model.project.Message;
33  
34  /***
35   * The node for the XML Comment.
36   *
37   * @version	$Revision$, $Date$
38   * @author Edwin Dankert <edankert@gmail.com>
39   */
40  public class MessageNode extends ResultNode {
41  	private static final long serialVersionUID = 5817597938649902807L;
42  
43      private static final ImageIcon ICON_OUT = ImageLoader.get().getImage( "/org/xmlhammer/gui/icons/obj16/message_out.gif");
44      private static final ImageIcon ICON_ERR = ImageLoader.get().getImage( "/org/xmlhammer/gui/icons/obj16/message_err.gif");
45  
46      private static MessageDetailsDialog dialog = null;
47  
48      private Message message = null;
49      private String value = null;
50      private URI uri = null;
51  
52      public MessageNode(URI uri, Message message) {
53  		this.message = message;
54          this.uri = uri;
55  	}
56  	
57  	public String getName() {
58  		return "";
59  	}
60  	
61  	public String getValue() {
62          if ( value == null) {
63              value = getFirstLine(message.getValue());
64          }
65  
66          return value;
67  	}
68  	
69  	public String getDescription() {
70  		return getValue();
71  	}
72  	
73  	public ImageIcon getIcon() {
74          if ("err".equals(message.getType())) {
75              return ICON_ERR;
76          }
77  		return ICON_OUT;
78  	}
79  
80      @Override
81      public JPopupMenu getPopupMenu(JFrame parent) {
82          JPopupMenu popup = new JPopupMenu();
83          popup.add(getOpenURIAction(uri, 0, 0));
84          popup.add(getEditURIAction(uri, 0, 0));
85          popup.addSeparator();
86          popup.add(getCopyAction());
87          popup.addSeparator();
88          popup.add(getPropertiesAction(getDialog(parent)));
89          
90          MenuUtilities.alignMenu(popup);
91  
92          return popup;
93      }
94      
95      @Override
96      public RunnableAction getDefaultAction(JFrame parent) {
97          return getPropertiesAction(getDialog(parent));
98      }
99      
100     private MessageDetailsDialog getDialog(JFrame parent) {
101         if (dialog == null) {
102             dialog = new MessageDetailsDialog(parent);
103         }
104         
105         dialog.setMessage(message);
106 
107         return dialog;
108     }
109     
110     public String getCopyValue() {
111         return message.getValue();
112     }
113 }