1 19 20 package org.netbeans.modules.debugger.ui.views; 21 22 import java.awt.BorderLayout ; 23 import java.io.Externalizable ; 24 import java.io.IOException ; 25 import java.io.ObjectInput ; 26 import java.io.ObjectOutput ; 27 import javax.swing.JComponent ; 28 import org.netbeans.spi.viewmodel.Models; 29 30 import org.netbeans.modules.debugger.ui.Utils; 31 32 import org.openide.util.NbBundle; 33 import org.openide.windows.TopComponent; 34 35 36 public class View extends TopComponent implements org.openide.util.HelpCtx.Provider { 41 43 public static final String BREAKPOINTS_VIEW_NAME = "BreakpointsView"; 44 public static final String CALLSTACK_VIEW_NAME = "CallStackView"; 45 public static final String LOCALS_VIEW_NAME = "LocalsView"; 46 public static final String SESSIONS_VIEW_NAME = "SessionsView"; 47 public static final String THREADS_VIEW_NAME = "ThreadsView"; 48 public static final String WATCHES_VIEW_NAME = "WatchesView"; 49 50 private transient JComponent tree; 51 private transient ViewModelListener viewModelListener; 52 private String name; private transient String helpID; 54 private transient String propertiesHelpID; 55 private transient String displayNameResource; 56 private transient String toolTipResource; 57 58 private View (String icon, String name, String helpID, String propertiesHelpID, 59 String displayNameResource, String toolTipResource) { 60 setIcon (Utils.getIcon(icon).getImage()); 61 this.name = name; 62 this.helpID = helpID; 63 this.propertiesHelpID = propertiesHelpID; 64 this.displayNameResource = displayNameResource; 65 this.toolTipResource = toolTipResource; 66 } 67 68 protected String preferredID() { 69 return this.getClass().getPackage().getName() + "." + name; 70 } 71 72 protected void componentShowing () { 73 super.componentShowing (); 74 if (viewModelListener != null) { 75 viewModelListener.setUp(); 76 return ; 77 } 78 if (tree == null) { 79 setLayout (new BorderLayout ()); 80 tree = Models.createView (Models.EMPTY_MODEL); 81 tree.setName (NbBundle.getMessage (View.class, toolTipResource)); 82 add (tree, "Center"); } 84 viewModelListener = new ViewModelListener ( 93 name, 94 tree, 95 propertiesHelpID 96 ); 97 } 99 100 protected void componentHidden () { 101 super.componentHidden (); 102 if (viewModelListener != null) { 103 viewModelListener.destroy (); 104 } 105 } 106 107 public org.openide.util.HelpCtx getHelpCtx() { 110 return new org.openide.util.HelpCtx(helpID); 111 } 112 114 public int getPersistenceType () { 115 return PERSISTENCE_ALWAYS; 116 } 117 118 public boolean requestFocusInWindow () { 119 super.requestFocusInWindow (); 120 if (tree == null) return false; 121 return tree.requestFocusInWindow (); 122 } 123 124 public void requestActive() { 125 super.requestActive(); 126 if (tree != null) { 127 tree.requestFocusInWindow (); 128 } 129 } 130 131 public String getName () { 132 return NbBundle.getMessage (View.class, displayNameResource); 133 } 134 135 public String getToolTipText () { 136 return NbBundle.getMessage (View.class, toolTipResource); } 138 139 public Object writeReplace() { 140 return new ResolvableHelper(name); 141 } 142 143 144 145 148 private static final class ResolvableHelper implements Externalizable { 149 150 private String name; 151 152 private static final long serialVersionUID = 1L; 153 154 public ResolvableHelper(String name) { 155 this.name = name; 156 } 157 158 public ResolvableHelper() { 159 } 161 162 public void writeExternal(ObjectOutput out) throws IOException { 163 out.writeObject(name); 164 } 165 166 public void readExternal(ObjectInput in) throws IOException , ClassNotFoundException { 167 name = (String ) in.readObject(); 168 } 169 170 public Object readResolve() { 171 return View.getView(name); 172 } 173 } 174 175 176 179 public static synchronized TopComponent getBreakpointsView() { 180 return new View( 181 "org/netbeans/modules/debugger/resources/breakpointsView/Breakpoint", 182 BREAKPOINTS_VIEW_NAME, 183 "NetbeansDebuggerBreakpointNode", 184 null, 185 "CTL_Breakpoints_view", 186 "CTL_Breakpoints_view_tooltip" 187 ); 188 } 189 190 193 public static synchronized TopComponent getCallStackView() { 194 return new View( 195 "org/netbeans/modules/debugger/resources/allInOneView/CallStack", 196 CALLSTACK_VIEW_NAME, 197 "NetbeansDebuggerCallStackNode", 198 null, 199 "CTL_Call_stack_view", 200 "CTL_Call_stack_view_tooltip" 201 ); 202 } 203 204 207 public static synchronized TopComponent getLocalsView() { 208 return new View( 209 "org/netbeans/modules/debugger/resources/localsView/LocalVariable", 210 LOCALS_VIEW_NAME, 211 "NetbeansDebuggerVariableNode", 212 null, 213 "CTL_Variables_view", 214 "CTL_Locals_view_tooltip" 215 ); 216 } 217 218 221 public static synchronized TopComponent getSessionsView() { 222 return new View( 223 "org/netbeans/modules/debugger/resources/sessionsView/Session", 224 SESSIONS_VIEW_NAME, 225 "NetbeansDebuggerSessionNode", 226 "NetbeansDebuggerSessionsPropertiesSheet", 227 "CTL_Sessions_view", 228 "CTL_Sessions_view_tooltip" 229 ); 230 } 231 232 235 public static synchronized TopComponent getThreadsView() { 236 return new View( 237 "org/netbeans/modules/debugger/resources/threadsView/RunningThread", 238 THREADS_VIEW_NAME, 239 "NetbeansDebuggerThreadNode", 240 "NetbeansDebuggerThreadsPropertiesSheet", 241 "CTL_Threads_view", 242 "CTL_Threads_view_tooltip" 243 ); 244 } 245 246 249 public static synchronized TopComponent getWatchesView() { 250 return new View( 251 "org/netbeans/modules/debugger/resources/watchesView/Watch", 252 WATCHES_VIEW_NAME, 253 "NetbeansDebuggerWatchNode", 254 null, 255 "CTL_Watches_view", 256 "CTL_Watches_view_tooltip" 257 ); 258 } 259 260 private static TopComponent getView(String viewName) { 261 if (viewName.equals(BREAKPOINTS_VIEW_NAME)) { 262 return getBreakpointsView(); 263 } 264 if (viewName.equals(CALLSTACK_VIEW_NAME)) { 265 return getCallStackView(); 266 } 267 if (viewName.equals(LOCALS_VIEW_NAME)) { 268 return getLocalsView(); 269 } 270 if (viewName.equals(SESSIONS_VIEW_NAME)) { 271 return getSessionsView(); 272 } 273 if (viewName.equals(THREADS_VIEW_NAME)) { 274 return getThreadsView(); 275 } 276 if (viewName.equals(WATCHES_VIEW_NAME)) { 277 return getWatchesView(); 278 } 279 throw new IllegalArgumentException (viewName); 280 } 281 282 } 283 | Popular Tags |