1 19 20 package org.netbeans.modules.debugger.ui.models; 21 22 import java.beans.PropertyEditor ; 23 import java.beans.PropertyEditorSupport ; 24 import org.netbeans.api.debugger.Properties; 25 import org.netbeans.api.debugger.Session; 26 import org.netbeans.spi.debugger.ui.Constants; 27 import org.netbeans.spi.viewmodel.ColumnModel; 28 import org.openide.ErrorManager; 29 import org.openide.util.NbBundle; 30 31 32 39 public class ColumnModels { 40 41 46 private static class AbstractColumn extends ColumnModel { 47 48 private String id; 49 private String displayName; 50 private String shortDescription; 51 private Class type; 52 private boolean defaultVisible; 53 private PropertyEditor propertyEditor; 54 55 Properties properties = Properties.getDefault (). 56 getProperties ("debugger").getProperties ("views"); 57 58 public AbstractColumn(String id, String displayName, String shortDescription, 59 Class type) { 60 this(id, displayName, shortDescription, type, true); 61 } 62 63 public AbstractColumn(String id, String displayName, String shortDescription, 64 Class type, boolean defaultVisible) { 65 this(id, displayName, shortDescription, type, defaultVisible, null); 66 } 67 68 public AbstractColumn(String id, String displayName, String shortDescription, 69 Class type, boolean defaultVisible, 70 PropertyEditor propertyEditor) { 71 this.id = id; 72 this.displayName = displayName; 73 this.shortDescription = shortDescription; 74 this.type = type; 75 this.defaultVisible = defaultVisible; 76 this.propertyEditor = propertyEditor; 77 } 78 79 public String getID() { 80 return id; 81 } 82 83 public String getDisplayName() { 84 return NbBundle.getBundle (ColumnModels.class).getString(displayName); 85 } 86 87 public Character getDisplayedMnemonic() { 88 return new Character (NbBundle.getBundle(ColumnModels.class). 89 getString(displayName+"_Mnc").charAt(0)); } 91 92 public String getShortDescription() { 93 return NbBundle.getBundle (ColumnModels.class).getString(shortDescription); 94 } 95 96 public Class getType() { 97 return type; 98 } 99 100 105 public void setVisible (boolean visible) { 106 properties.setBoolean (getID () + ".visible", visible); 107 } 108 109 114 public void setSorted (boolean sorted) { 115 properties.setBoolean (getID () + ".sorted", sorted); 116 } 117 118 124 public void setSortedDescending (boolean sortedDescending) { 125 properties.setBoolean ( 126 getID () + ".sortedDescending", 127 sortedDescending 128 ); 129 } 130 131 136 public int getCurrentOrderNumber () { 137 return properties.getInt (getID () + ".currentOrderNumber", -1); 138 } 139 140 145 public void setCurrentOrderNumber (int newOrderNumber) { 146 properties.setInt ( 147 getID () + ".currentOrderNumber", 148 newOrderNumber 149 ); 150 } 151 152 157 public int getColumnWidth () { 158 return properties.getInt (getID () + ".columnWidth", 150); 159 } 160 161 166 public void setColumnWidth (int newColumnWidth) { 167 properties.setInt (getID () + ".columnWidth", newColumnWidth); 168 } 169 170 175 public boolean isVisible () { 176 return properties.getBoolean (getID () + ".visible", defaultVisible); 177 } 178 179 184 public boolean isSorted () { 185 return properties.getBoolean (getID () + ".sorted", false); 186 } 187 188 194 public boolean isSortedDescending () { 195 return properties.getBoolean ( 196 getID () + ".sortedDescending", 197 false 198 ); 199 } 200 201 209 public PropertyEditor getPropertyEditor() { 210 return propertyEditor; 211 } 212 } 213 214 219 public static ColumnModel createDefaultBreakpointsColumn() { 220 return new AbstractColumn("DefaultBreakpointColumn", 221 "CTL_BreakpointView_Column_Name_Name", 222 "CTL_BreakpointView_Column_Name_Desc", 223 null); 224 } 225 226 231 public static ColumnModel createBreakpointEnabledColumn() { 232 return new AbstractColumn(Constants.BREAKPOINT_ENABLED_COLUMN_ID, 233 "CTL_BreakpointView_Column_Enabled_Name", 234 "CTL_BreakpointView_Column_Enabled_Desc", 235 Boolean.TYPE); 236 } 237 238 243 public static ColumnModel createDefaultCallStackColumn() { 244 return new AbstractColumn("DefaultCallStackColumn", 245 "CTL_CallstackView_Column_Name_Name", 246 "CTL_CallstackView_Column_Name_Desc", 247 null); 248 } 249 250 255 public static ColumnModel createCallStackLocationColumn() { 256 return new AbstractColumn(Constants.CALL_STACK_FRAME_LOCATION_COLUMN_ID, 257 "CTL_CallstackView_Column_Location_Name", 258 "CTL_CallstackView_Column_Location_Desc", 259 String .class, 260 false); 261 } 262 263 268 public static ColumnModel createDefaultLocalsColumn() { 269 return new AbstractColumn("DefaultLocalsColumn", 270 "CTL_LocalsView_Column_Name_Name", 271 "CTL_LocalsView_Column_Name_Desc", 272 null); 273 } 274 275 280 public static ColumnModel createLocalsToStringColumn() { 281 return new AbstractColumn(Constants.LOCALS_TO_STRING_COLUMN_ID, 282 "CTL_LocalsView_Column_ToString_Name", 283 "CTL_LocalsView_Column_ToString_Desc", 284 String .class, 285 false); 286 } 287 288 293 public static ColumnModel createLocalsTypeColumn() { 294 return new AbstractColumn(Constants.LOCALS_TYPE_COLUMN_ID, 295 "CTL_LocalsView_Column_Type_Name", 296 "CTL_LocalsView_Column_Type_Desc", 297 String .class, 298 true); 299 } 300 305 public static ColumnModel createLocalsValueColumn() { 306 return new AbstractColumn(Constants.LOCALS_VALUE_COLUMN_ID, 307 "CTL_LocalsView_Column_Value_Name", 308 "CTL_LocalsView_Column_Value_Desc", 309 String .class, 310 true); 311 } 312 317 public static ColumnModel createDefaultSessionColumn() { 318 return new AbstractColumn("DefaultSessionColumn", 319 "CTL_SessionsView_Column_Name_Name", 320 "CTL_SessionsView_Column_Name_Desc", 321 null); 322 } 323 324 329 public static ColumnModel createSessionHostNameColumn() { 330 return new AbstractColumn(Constants.SESSION_HOST_NAME_COLUMN_ID, 331 "CTL_SessionsView_Column_HostName_Name", 332 "CTL_SessionsView_Column_HostName_Desc", 333 String .class, 334 false); 335 } 336 337 342 public static ColumnModel createSessionStateColumn () { 343 return new AbstractColumn(Constants.SESSION_STATE_COLUMN_ID, 344 "CTL_SessionsView_Column_State_Name", 345 "CTL_SessionsView_Column_State_Desc", 346 String .class, 347 true); 348 } 349 350 355 public static ColumnModel createSessionLanguageColumn () { 356 return new AbstractColumn(Constants.SESSION_LANGUAGE_COLUMN_ID, 357 "CTL_SessionsView_Column_Language_Name", 358 "CTL_SessionsView_Column_Language_Desc", 359 Session.class, 360 true, 361 new LanguagePropertyEditor ()); 362 } 363 364 369 public static ColumnModel createDefaultThreadColumn() { 370 return new AbstractColumn("DefaultThreadColumn", 371 "CTL_ThreadsView_Column_Name_Name", 372 "CTL_ThreadsView_Column_Name_Desc", 373 null); 374 } 375 376 381 public static ColumnModel createThreadStateColumn() { 382 return new AbstractColumn(Constants.THREAD_STATE_COLUMN_ID, 383 "CTL_ThreadsView_Column_State_Name", 384 "CTL_ThreadsView_Column_State_Desc", 385 String .class, 386 true); 387 } 388 389 394 public static ColumnModel createThreadSuspendedColumn() { 395 return new AbstractColumn(Constants.THREAD_SUSPENDED_COLUMN_ID, 396 "CTL_ThreadsView_Column_Suspended_Name", 397 "CTL_ThreadsView_Column_Suspended_Desc", 398 Boolean.TYPE, 399 false); 400 } 401 402 407 public static ColumnModel createDefaultWatchesColumn() { 408 return new AbstractColumn("DefaultWatchesColumn", 409 "CTL_WatchesView_Column_Name_Name", 410 "CTL_WatchesView_Column_Name_Desc", 411 null); 412 } 413 414 419 public static ColumnModel createWatchToStringColumn() { 420 return new AbstractColumn(Constants.WATCH_TO_STRING_COLUMN_ID, 421 "CTL_WatchesView_Column_ToString_Name", 422 "CTL_WatchesView_Column_ToString_Desc", 423 String .class, 424 false); 425 } 426 427 432 public static ColumnModel createWatchTypeColumn() { 433 return new AbstractColumn(Constants.WATCH_TYPE_COLUMN_ID, 434 "CTL_WatchesView_Column_Type_Name", 435 "CTL_WatchesView_Column_Type_Desc", 436 String .class, 437 true); 438 } 439 440 445 public static ColumnModel createWatchValueColumn() { 446 return new AbstractColumn(Constants.WATCH_VALUE_COLUMN_ID, 447 "CTL_WatchesView_Column_Value_Name", 448 "CTL_WatchesView_Column_Value_Desc", 449 String .class, 450 true); 451 } 452 453 private static class LanguagePropertyEditor extends PropertyEditorSupport { 454 455 public void setValue(Object value) { 456 if (value != null && !(value instanceof Session)) { 457 ErrorManager.getDefault().notify( 458 new IllegalArgumentException ("Value "+value+" is not an instance of Session!")); 459 } 460 super.setValue(value); 461 } 462 463 public String [] getTags () { 464 if (getValue () == null) return new String [0]; 465 String [] s = ((Session) getValue ()).getSupportedLanguages (); 466 return s; 467 } 468 469 public String getAsText () { 470 String s = ((Session) getValue ()).getCurrentLanguage (); 471 return s; 472 } 473 474 public void setAsText (String text) { 475 ((Session) getValue ()).setCurrentLanguage (text); 476 } 477 } 478 } 479 | Popular Tags |