Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jdt-debug-dev] extending JDIModelPresentation

Hi everyone,

in my current project we work with a lot of date variables as long unix
timestamp values.
This makes debugging very difficult, cause we are not taff enough to
interpret this dates in the variables view or the inspect popup.

Therefore i implemented a very small plugin to display long values
formatted as Date. I have done this by extending JDIModelPresentation:

------------
public class JDILongAsDateModelPresentation extends JDIModelPresentation
{
  public static final long MIN_DATE = -62135773200000L; //1.1.0000
  public static final long MAX_DATE = 253402210800000L; //31.12.9999
  public static final String LONG_NAME = "long";
  public static final String PREFIX = " (as date=";
  public static final String SUFIX = ")";


  /* (non-Javadoc)
   * @see
org.eclipse.jdt.internal.debug.ui.JDIModelPresentation#getValueText(org.eclipse.jdt.debug.core.IJavaValue)
   */
  protected String getValueText( IJavaValue pIJavaValue ) throws
DebugException
  {
    StringBuffer rText = new StringBuffer( super.getValueText( pIJavaValue
) );
    try
    {
      if ( pIJavaValue != null
          && pIJavaValue instanceof JDIPrimitiveValue )
      {
        JDIPrimitiveValue tJDIPrimitiveValue =
(JDIPrimitiveValue)pIJavaValue;
        if ( LONG_NAME.equals( tJDIPrimitiveValue.getJavaType().getName() ) )
        {
          long tTime = tJDIPrimitiveValue.getLongValue();

          if ( tTime >= MIN_DATE && tTime <= MAX_DATE )
          {
            Date tDate = new Date( tTime );
            rText.append( PREFIX );
            rText.append( getDateFormat().format( tDate ) );
            rText.append( SUFIX );
          }
        }
      }
    }
    catch ( Throwable t )
    {
      //not that important!
    }

    return rText.toString();
  }

  private SimpleDateFormat getDateFormat()
  {
    return new SimpleDateFormat(
WVKEclipseUtilsPlugin.getDefault().getPreferenceStore().getString(
PreferenceConstants.DATE_FORMAT_PREF ) );
  }
}

------------
<extension point="org.eclipse.debug.ui.debugModelPresentations">
         <debugModelPresentation
             class="somepackage.eclipse.JDILongAsDateModelPresentation"
             id="org.eclipse.jdt.debug"
             detailsViewerConfiguration="org.eclipse.jdt.internal.debug.ui.display.DetailsViewerConfiguration">
	    </debugModelPresentation>
	</extension>
------------

This worked very well with eclipse 3.1.0. Now i wanted to upgrade to
3.2.1, but my plugin does not work any more. I get a lot of discouraged
access warnings and my class is never used/called. Is there a way to get
it to work in 3.2.1 or a better/right way to extend the variables view ?

thanks a lot

David

Attachment: debug.PNG
Description: PNG image


Back to the top