View Javadoc

1   /*
2    * $Id: WarningNode.java,v 1.14 2007/07/04 19:42:48 edankert Exp $
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.bounce.util.URIUtils;
33  import org.xmlhammer.model.project.Warning;
34  
35  /***
36   * The node for a warning.
37   *
38   * @version	$Revision: 1.14 $, $Date: 2007/07/04 19:42:48 $
39   * @author Edwin Dankert <edankert@gmail.com>
40   */
41  public class WarningNode extends ResultNode {
42  	private static final long serialVersionUID = 926492815637254913L;
43  
44      private static final ImageIcon ICON = ImageLoader.get().getImage( "/org/xmlhammer/gui/icons/obj16/warning.gif");
45      private static ExceptionDetailsDialog dialog = null;
46  
47  	private Warning warning = null;
48      private URI uri = null;
49  	
50  	public WarningNode(URI uri, Warning warning) {
51  		this.warning = warning;
52          this.uri = uri;
53  	}
54  	
55  	public String getName() {
56  		return getValue();
57  	}
58  	
59      public String getValue() {
60          StringBuilder builder = new StringBuilder();
61          
62          if (warning.getSystemId() != null) {
63              URI systemId = URIUtils.createURI(warning.getSystemId());
64              
65              if (uri.compareTo(systemId) != 0) {
66                  builder.append(URIUtils.getName(systemId));
67                  builder.append(" - ");
68              }
69          }
70          
71          builder.append("[");
72          builder.append(getNumber(warning.getLine()));
73          builder.append(":");
74          builder.append(getNumber(warning.getColumn()));
75          builder.append("] ");
76          builder.append(warning.getLocalizedMessage());
77          
78          return builder.toString();
79      }
80  
81  	public String getDescription() {
82  		return getValue();
83  	}
84  	
85  	public ImageIcon getIcon() {
86  		return ICON;
87  	}
88  
89      public String getContext() {
90          return "";
91      }
92      
93      @Override
94      public JPopupMenu getPopupMenu(JFrame parent) {
95          JPopupMenu popup = new JPopupMenu();
96          popup.add(getOpenURIAction(getOpenableURI(), getNumber(warning.getLine()), getNumber(warning.getColumn())));
97          popup.add(getEditURIAction(getOpenableURI(), getNumber(warning.getLine()), getNumber(warning.getColumn())));
98          popup.addSeparator();
99          popup.add(getCopyAction());
100         popup.addSeparator();
101         popup.add(getPropertiesAction(getDialog(parent)));
102         
103         MenuUtilities.alignMenu(popup);
104 
105         return popup;
106     }
107     
108     @Override
109     public RunnableAction getDefaultAction(JFrame parent) {
110         return getPropertiesAction(getDialog(parent));
111     }
112     
113     private ExceptionDetailsDialog getDialog(JFrame parent) {
114         if (dialog == null) {
115             dialog = new ExceptionDetailsDialog(parent, "Warning Details");
116         }
117         
118         dialog.setException(warning, uri, ICON);
119 
120         return dialog;
121     }
122 
123     private static int getNumber(Integer integer) {
124         if (integer != null) {
125             return integer;
126         } 
127         
128         return -1;
129     }
130     
131     public String getCopyValue() {
132         return "[warning] "+getValue();
133     }
134     
135     private URI getOpenableURI() {
136         if (warning.getSystemId() != null) {
137             return URIUtils.createURI(warning.getSystemId());
138         }
139         
140         return uri;
141     }
142 }