View Javadoc

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