1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-21 07:55:24 +02:00

Bugzilla 272369

This commit is contained in:
Randy Rohrbach 2009-04-24 14:43:04 +00:00
parent 19caf501e5
commit 67777ab391
7 changed files with 642 additions and 88 deletions

View file

@ -34,6 +34,7 @@ public class MessagesForRegisterVM extends NLS {
public static String RegisterVMNode_Expression_column__text_format;
public static String RegisterVMNode_Type_column__text_format;
public static String RegisterVMNode_No_columns__text_format;
public static String RegisterVMNode_No_columns__text_format_with_type;
public static String RegisterVMNode_No_columns__Error__text_format;
public static String RegisterBitFieldVMNode_Name_column__text_format;
@ -42,11 +43,11 @@ public class MessagesForRegisterVM extends NLS {
public static String RegisterBitFieldVMNode_Value_column__With_mnemonic__text_format;
public static String RegisterBitFieldVMNode_Expression_column__text_format;
public static String RegisterBitFieldVMNode_No_columns__text_format;
public static String RegisterBitFieldVMNode_No_columns__text_format_with_type;
public static String RegisterBitFieldVMNode_No_columns__With_mnemonic__text_format;
public static String RegisterBitFieldVMNode_No_columns__With_mnemonic__text_format_with_type;
public static String RegisterBitFieldVMNode_No_columns__Error__text_format;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, MessagesForRegisterVM.class);

View file

@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.cdt.dsf.debug.ui.viewmodel.register;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.RejectedExecutionException;
@ -74,6 +76,7 @@ import org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.IDebugModelPresentation;
import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.debug.ui.actions.IWatchExpressionFactoryAdapter2;
import org.eclipse.jface.util.PropertyChangeEvent;
@ -88,6 +91,11 @@ import org.eclipse.swt.widgets.Composite;
public class RegisterBitFieldVMNode extends AbstractExpressionVMNode
implements IElementEditor, IElementLabelProvider, IElementMementoProvider, IElementPropertiesProvider
{
/**
* @since 2.0
*/
private static final String PROP_BITFIELD_SHOW_TYPE_NAMES = "bitfield_show_type_names"; //$NON-NLS-1$
protected class BitFieldVMC extends DMVMContext
implements IFormattedValueVMContext
{
@ -179,6 +187,26 @@ public class RegisterBitFieldVMNode extends AbstractExpressionVMNode
return "RegisterBitFieldVMNode(" + getSession().getId() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
}
private Object[] constructTypeObjects( Map<String, Object> properties ) {
int readAttr = 0;
if ( Boolean.TRUE.equals(properties.get(IRegisterVMConstants.PROP_IS_READABLE)) ) {
readAttr = 1;
} else if ( Boolean.TRUE.equals(properties.get(IRegisterVMConstants.PROP_IS_READONCE)) ) {
readAttr = 2;
}
int writeAttr = 0;
if ( Boolean.TRUE.equals(properties.get(IRegisterVMConstants.PROP_IS_WRITEABLE)) ) {
writeAttr = 1;
} else if ( Boolean.TRUE.equals(properties.get(IRegisterVMConstants.PROP_IS_WRITEONCE)) ) {
writeAttr = 2;
}
Object[] messageAttrs = new Object[] { readAttr, writeAttr };
return messageAttrs;
}
/**
* Creates the label provider delegate. This VM node will delegate label
* updates to this provider which can be created by sub-classes.
@ -220,27 +248,14 @@ public class RegisterBitFieldVMNode extends AbstractExpressionVMNode
new LabelText(
MessagesForRegisterVM.RegisterBitFieldVMNode_Type_column__text_format,
new String[] {
IRegisterVMConstants.PROP_IS_READABLE, IRegisterVMConstants.PROP_IS_READONCE,
IRegisterVMConstants.PROP_IS_WRITEABLE, IRegisterVMConstants.PROP_IS_WRITEONCE
})
IRegisterVMConstants.PROP_IS_READABLE,
IRegisterVMConstants.PROP_IS_READONCE,
IRegisterVMConstants.PROP_IS_WRITEABLE,
IRegisterVMConstants.PROP_IS_WRITEONCE})
{
@Override
public void updateAttribute(ILabelUpdate update, int columnIndex, IStatus status, Map<String, Object> properties) {
int readAttr = 0;
if ( Boolean.TRUE.equals(properties.get(IRegisterVMConstants.PROP_IS_READABLE)) ) {
readAttr = 1;
} else if ( Boolean.TRUE.equals(properties.get(IRegisterVMConstants.PROP_IS_READONCE)) ) {
readAttr = 2;
}
int writeAttr = 0;
if ( Boolean.TRUE.equals(properties.get(IRegisterVMConstants.PROP_IS_WRITEABLE)) ) {
writeAttr = 1;
} else if ( Boolean.TRUE.equals(properties.get(IRegisterVMConstants.PROP_IS_WRITEONCE)) ) {
writeAttr = 2;
}
Object[] messageAttrs = new Object[] { readAttr, writeAttr };
Object[] messageAttrs = constructTypeObjects( properties );
try {
update.setLabel(getMessageFormat().format(
messageAttrs, new StringBuffer(), null).toString(), columnIndex);
@ -325,12 +340,108 @@ public class RegisterBitFieldVMNode extends AbstractExpressionVMNode
new String[] {
PROP_NAME,
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE,
IRegisterVMConstants.PROP_CURRENT_MNEMONIC_LONG_NAME}),
IRegisterVMConstants.PROP_CURRENT_MNEMONIC_LONG_NAME})
{
@Override
public boolean isEnabled(IStatus status, Map<String, Object> properties) {
Boolean showTypeNames = (Boolean) properties.get(PROP_BITFIELD_SHOW_TYPE_NAMES);
return
showTypeNames != null &&
!showTypeNames.booleanValue() &&
super.isEnabled(status, properties);
}
},
new FormattedValueLabelText(
MessagesForRegisterVM.RegisterBitFieldVMNode_No_columns__With_mnemonic__text_format,
MessagesForRegisterVM.RegisterBitFieldVMNode_No_columns__With_mnemonic__text_format_with_type,
new String[] {
PROP_NAME,
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE}),
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE,
IRegisterVMConstants.PROP_CURRENT_MNEMONIC_LONG_NAME,
IRegisterVMConstants.PROP_IS_READABLE,
IRegisterVMConstants.PROP_IS_READONCE,
IRegisterVMConstants.PROP_IS_WRITEABLE,
IRegisterVMConstants.PROP_IS_WRITEONCE,
PROP_BITFIELD_SHOW_TYPE_NAMES})
{
@Override
public void updateAttribute(ILabelUpdate update, int columnIndex, IStatus status, Map<String, Object> properties) {
Object[] messageAttrs = constructTypeObjects( properties );
Object[] combinedAttrs = new Object[ messageAttrs.length + 3 ];
combinedAttrs[0] = super.getPropertyValue(PROP_NAME, status, properties);
combinedAttrs[1] = super.getPropertyValue(IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE, status, properties);
combinedAttrs[2] = super.getPropertyValue(IRegisterVMConstants.PROP_CURRENT_MNEMONIC_LONG_NAME, status, properties);
for ( int idx = 0 ; idx < messageAttrs.length; idx ++ ) {
combinedAttrs[ idx + 3 ] = messageAttrs[ idx ];
}
try {
update.setLabel(getMessageFormat().format(combinedAttrs, new StringBuffer(), null).toString(), columnIndex);
} catch (IllegalArgumentException e) {
update.setStatus(new Status(IStatus.ERROR, DsfUIPlugin.PLUGIN_ID, 0, "Failed formatting a message for column " + columnIndex + ", for update " + update, e)); //$NON-NLS-1$ //$NON-NLS-2$
}
}
@Override
public boolean isEnabled(IStatus status, Map<String, Object> properties) {
Boolean showTypeNames = (Boolean) properties.get(PROP_BITFIELD_SHOW_TYPE_NAMES);
return
showTypeNames != null &&
showTypeNames.booleanValue() &&
super.isEnabled(status, properties);
}
},
new FormattedValueLabelText(
MessagesForRegisterVM.RegisterBitFieldVMNode_No_columns__text_format,
new String[] {
PROP_NAME,
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE})
{
@Override
public boolean isEnabled(IStatus status, Map<String, Object> properties) {
Boolean showTypeNames = (Boolean) properties.get(PROP_BITFIELD_SHOW_TYPE_NAMES);
return
showTypeNames != null &&
!showTypeNames.booleanValue() &&
super.isEnabled(status, properties);
}
},
new FormattedValueLabelText(
MessagesForRegisterVM.RegisterBitFieldVMNode_No_columns__text_format_with_type,
new String[] {
PROP_NAME,
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE,
IRegisterVMConstants.PROP_IS_READABLE,
IRegisterVMConstants.PROP_IS_READONCE,
IRegisterVMConstants.PROP_IS_WRITEABLE,
IRegisterVMConstants.PROP_IS_WRITEONCE,
PROP_BITFIELD_SHOW_TYPE_NAMES})
{
@Override
public void updateAttribute(ILabelUpdate update, int columnIndex, IStatus status, Map<String, Object> properties) {
Object[] messageAttrs = constructTypeObjects( properties );
Object[] combinedAttrs = new Object[ messageAttrs.length + 2 ];
combinedAttrs[0] = super.getPropertyValue(PROP_NAME, status, properties);
combinedAttrs[1] = super.getPropertyValue(IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE, status, properties);
for ( int idx = 0 ; idx < messageAttrs.length; idx ++ ) {
combinedAttrs[ idx + 2 ] = messageAttrs[ idx ];
}
try {
update.setLabel(getMessageFormat().format(combinedAttrs, new StringBuffer(), null).toString(), columnIndex);
} catch (IllegalArgumentException e) {
update.setStatus(new Status(IStatus.ERROR, DsfUIPlugin.PLUGIN_ID, 0, "Failed formatting a message for column " + columnIndex + ", for update " + update, e)); //$NON-NLS-1$ //$NON-NLS-2$
}
}
@Override
public boolean isEnabled(IStatus status, Map<String, Object> properties) {
Boolean showTypeNames = (Boolean) properties.get(PROP_BITFIELD_SHOW_TYPE_NAMES);
return
showTypeNames != null &&
showTypeNames.booleanValue() &&
super.isEnabled(status, properties);
}
},
new ErrorLabelText(
MessagesForRegisterVM.RegisterBitFieldVMNode_No_columns__Error__text_format,
new String[] { PROP_NAME }),
@ -401,6 +512,93 @@ public class RegisterBitFieldVMNode extends AbstractExpressionVMNode
}
}
//
// We encapsulate the determination of the state of the "Show Type Names" ICON
// selection to this routine. This attribute information is not readily available
// from standard Interface definitions. So we use reflection to get the info. But
// in the future this will change and then we can just change this routine. This
// really should just be as simple as the code below, which could be done inline
// once it comes to pass.
//
// Boolean attribute = (Boolean) context.getProperty(IDebugModelPresentation.DISPLAY_VARIABLE_TYPE_NAMES);
// if (attribute != null) {
// return attribute;
// }
// return Boolean.FALSE;
//
// @param return-value Boolean.TRUE --> Show Types ICON is selected/depressed
// @param return-value Boolean.FALSE --> Show Types ICON is not selected/depressed
//
@SuppressWarnings("unchecked")
private Boolean getShowTypeNamesState( IPresentationContext context ) {
// This is fairly ugly stuff. It should be the case that the "getPropery()"
// method of the presentation context should contain this attribute, but it
// does not. So we have to go mining for it. As it turns out the presentation
// context is actually an implementation class DebugModelPresentationContext
// from which you can get the IDebugModelPresentation instance. In turn this
// is a DelegatingModelPresentation instance which allows you to obtain the
// current set of internal attributes, which contains the current state of
// "Show Type Names" ICON selection.
Class<? extends IPresentationContext> contextClass = context.getClass();
Method contextMethod = null;
try {
// Will return the instance of the class "DebugModelPresentationContext"
// if this is indeed the implementation we are expecting.
contextMethod = contextClass.getMethod( "getModelPresentation" , new Class[] {} ); //$NON-NLS-1$
}
catch ( Exception ex ) {}
IDebugModelPresentation debugModelPresentation = null ;
if (contextMethod != null) {
try {
// We invoke the "getModelPresntation" method to get the actual instance
// of the "DelegatingModelPresentation".
debugModelPresentation = (IDebugModelPresentation) contextMethod.invoke(context , new Object[0]);
}
catch ( Exception e ) {}
}
if (debugModelPresentation != null) {
Class<? extends IDebugModelPresentation> presentationClass = debugModelPresentation.getClass();
Method presentationMethod = null;
try {
// The "getAttributeMethod" is a public method which returns the internal
// attributes. These should be part of the Interface but they are not. So
// we get them through this available method.
presentationMethod = presentationClass.getMethod( "getAttributeMap" , new Class[] {} ); //$NON-NLS-1$
}
catch ( Exception ex ) {}
HashMap attributeMap = null;
if (presentationMethod != null) {
try {
// Now get the actual HashMap attribute list so we can see if there is
// state information about the "Show Type Names" ICON.
attributeMap = (HashMap) presentationMethod.invoke(debugModelPresentation , new Object[0]);
}
catch ( Exception e ) {}
}
if (attributeMap != null) {
// This attribute ( which is globally defined ) reflect the state of the ICON.
// If is exists is contains the current state. Non-existence would mean that
// the ICON has never been selected or changed. This is so at the very start
// when the view is first brought up.
Boolean attribute = (Boolean) attributeMap.get(IDebugModelPresentation.DISPLAY_VARIABLE_TYPE_NAMES);
if (attribute != null) {
return attribute;
}
}
}
// Could not get to the one of the methods needs to determine the state of the
// ICON or we could not get the attribute. Assume we are not showing the TYPE
// NAMES.
return Boolean.FALSE;
}
/**
* @since 2.0
*/
@ -429,6 +627,11 @@ public class RegisterBitFieldVMNode extends AbstractExpressionVMNode
update.setProperty(AbstractExpressionVMNode.PROP_ELEMENT_EXPRESSION, expression.getExpressionText());
}
// Capture the current "Show Type Names" ICON state in case there are no columns.
if (update.getProperties().contains(PROP_BITFIELD_SHOW_TYPE_NAMES)) {
update.setProperty(PROP_BITFIELD_SHOW_TYPE_NAMES, getShowTypeNamesState(update.getPresentationContext()));
}
IBitFieldDMContext dmc = findDmcInPath(update.getViewerInput(), update.getElementPath(), IBitFieldDMContext.class);
if (dmc == null || service == null) {
handleFailedUpdate(update);

View file

@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.cdt.dsf.debug.ui.viewmodel.register;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.RejectedExecutionException;
@ -71,6 +73,7 @@ import org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.IDebugModelPresentation;
import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.debug.ui.actions.IWatchExpressionFactoryAdapter2;
import org.eclipse.jface.util.PropertyChangeEvent;
@ -87,6 +90,11 @@ import org.eclipse.swt.widgets.Composite;
public class RegisterVMNode extends AbstractExpressionVMNode
implements IElementEditor, IElementLabelProvider, IElementMementoProvider, IElementPropertiesProvider
{
/**
* @since 2.0
*/
private static final String PROP_REGISTER_SHOW_TYPE_NAMES = "register_show_type_names"; //$NON-NLS-1$
protected class RegisterVMC extends DMVMContext
implements IFormattedValueVMContext
{
@ -170,6 +178,29 @@ public class RegisterVMNode extends AbstractExpressionVMNode
fLabelProvider = createLabelProvider();
}
private Object[] constructTypeObjects( Map<String, Object> properties ) {
int type = 0;
if ( Boolean.TRUE.equals(properties.get(IRegisterVMConstants.PROP_IS_FLOAT)) ) {
type = 1;
}
int readAttr = 0;
if ( Boolean.TRUE.equals(properties.get(IRegisterVMConstants.PROP_IS_READABLE)) ) {
readAttr = 1;
} else if ( Boolean.TRUE.equals(properties.get(IRegisterVMConstants.PROP_IS_READONCE)) ) {
readAttr = 2;
}
int writeAttr = 0;
if ( Boolean.TRUE.equals(properties.get(IRegisterVMConstants.PROP_IS_WRITEABLE)) ) {
writeAttr = 1;
} else if ( Boolean.TRUE.equals(properties.get(IRegisterVMConstants.PROP_IS_WRITEONCE)) ) {
writeAttr = 2;
}
Object[] messageAttrs = new Object[] { type, readAttr, writeAttr };
return messageAttrs;
}
/**
* Creates the label provider delegate. This VM node will delegate label
* updates to this provider which can be created by sub-classes.
@ -178,6 +209,7 @@ public class RegisterVMNode extends AbstractExpressionVMNode
*
* @since 2.0
*/
protected IElementLabelProvider createLabelProvider() {
PropertiesBasedLabelProvider provider = new PropertiesBasedLabelProvider();
@ -211,35 +243,18 @@ public class RegisterVMNode extends AbstractExpressionVMNode
new LabelText(
MessagesForRegisterVM.RegisterVMNode_Type_column__text_format,
new String[] {
IRegisterVMConstants.PROP_IS_FLOAT, IRegisterVMConstants.PROP_IS_READABLE, IRegisterVMConstants.PROP_IS_READONCE,
IRegisterVMConstants.PROP_IS_WRITEABLE, IRegisterVMConstants.PROP_IS_WRITEONCE
IRegisterVMConstants.PROP_IS_FLOAT,
IRegisterVMConstants.PROP_IS_READABLE,
IRegisterVMConstants.PROP_IS_READONCE,
IRegisterVMConstants.PROP_IS_WRITEABLE,
IRegisterVMConstants.PROP_IS_WRITEONCE
})
{
@Override
public void updateAttribute(ILabelUpdate update, int columnIndex, IStatus status, Map<String, Object> properties) {
int type = 0;
if ( Boolean.TRUE.equals(properties.get(IRegisterVMConstants.PROP_IS_FLOAT)) ) {
type = 1;
}
int readAttr = 0;
if ( Boolean.TRUE.equals(properties.get(IRegisterVMConstants.PROP_IS_READABLE)) ) {
readAttr = 1;
} else if ( Boolean.TRUE.equals(properties.get(IRegisterVMConstants.PROP_IS_READONCE)) ) {
readAttr = 2;
}
int writeAttr = 0;
if ( Boolean.TRUE.equals(properties.get(IRegisterVMConstants.PROP_IS_WRITEABLE)) ) {
writeAttr = 1;
} else if ( Boolean.TRUE.equals(properties.get(IRegisterVMConstants.PROP_IS_WRITEONCE)) ) {
writeAttr = 2;
}
Object[] messageAttrs = new Object[] { type, readAttr, writeAttr };
Object[] messageAttrs = constructTypeObjects( properties );
try {
update.setLabel(getMessageFormat().format(
messageAttrs, new StringBuffer(), null).toString(), columnIndex);
update.setLabel(getMessageFormat().format(messageAttrs, new StringBuffer(), null).toString(), columnIndex);
} catch (IllegalArgumentException e) {
update.setStatus(new Status(IStatus.ERROR, DsfUIPlugin.PLUGIN_ID, 0, "Failed formatting a message for column " + columnIndex + ", for update " + update, e)); //$NON-NLS-1$ //$NON-NLS-2$
}
@ -312,7 +327,54 @@ public class RegisterVMNode extends AbstractExpressionVMNode
new LabelColumnInfo(new LabelAttribute[] {
new FormattedValueLabelText(
MessagesForRegisterVM.RegisterVMNode_No_columns__text_format,
new String[] { PROP_NAME, IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE }),
new String[] { PROP_NAME,
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE})
{
@Override
public boolean isEnabled(IStatus status, Map<String, Object> properties) {
Boolean showTypeNames = (Boolean) properties.get(PROP_REGISTER_SHOW_TYPE_NAMES);
return
showTypeNames != null &&
!showTypeNames.booleanValue() &&
super.isEnabled(status, properties);
}
},
new FormattedValueLabelText(
MessagesForRegisterVM.RegisterVMNode_No_columns__text_format_with_type,
new String[] { PROP_NAME,
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE,
IRegisterVMConstants.PROP_IS_FLOAT,
IRegisterVMConstants.PROP_IS_READABLE,
IRegisterVMConstants.PROP_IS_READONCE,
IRegisterVMConstants.PROP_IS_WRITEABLE,
IRegisterVMConstants.PROP_IS_WRITEONCE,
PROP_REGISTER_SHOW_TYPE_NAMES})
{
@Override
public void updateAttribute(ILabelUpdate update, int columnIndex, IStatus status, Map<String, Object> properties) {
Object[] messageAttrs = constructTypeObjects( properties );
Object[] combinedAttrs = new Object[ messageAttrs.length + 2 ];
combinedAttrs[0] = super.getPropertyValue(PROP_NAME, status, properties);
combinedAttrs[1] = super.getPropertyValue(IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE, status, properties);
for ( int idx = 0 ; idx < messageAttrs.length; idx ++ ) {
combinedAttrs[ idx + 2 ] = messageAttrs[ idx ];
}
try {
update.setLabel(getMessageFormat().format(combinedAttrs, new StringBuffer(), null).toString(), columnIndex);
} catch (IllegalArgumentException e) {
update.setStatus(new Status(IStatus.ERROR, DsfUIPlugin.PLUGIN_ID, 0, "Failed formatting a message for column " + columnIndex + ", for update " + update, e)); //$NON-NLS-1$ //$NON-NLS-2$
}
}
@Override
public boolean isEnabled(IStatus status, Map<String, Object> properties) {
Boolean showTypeNames = (Boolean) properties.get(PROP_REGISTER_SHOW_TYPE_NAMES);
return
showTypeNames != null &&
showTypeNames.booleanValue() &&
super.isEnabled(status, properties);
}
},
new ErrorLabelText(
MessagesForRegisterVM.RegisterVMNode_No_columns__Error__text_format,
new String[] { PROP_NAME }),
@ -386,6 +448,93 @@ public class RegisterVMNode extends AbstractExpressionVMNode
}
}
//
// We encapsulate the determination of the state of the "Show Type Names" ICON
// selection to this routine. This attribute information is not readily available
// from standard Interface definitions. So we use reflection to get the info. But
// in the future this will change and then we can just change this routine. This
// really should just be as simple as the code below, which could be done inline
// once it comes to pass.
//
// Boolean attribute = (Boolean) context.getProperty(IDebugModelPresentation.DISPLAY_VARIABLE_TYPE_NAMES);
// if (attribute != null) {
// return attribute;
// }
// return Boolean.FALSE;
//
// @param return-value Boolean.TRUE --> Show Types ICON is selected/depressed
// @param return-value Boolean.FALSE --> Show Types ICON is not selected/depressed
//
@SuppressWarnings("unchecked")
private Boolean getShowTypeNamesState( IPresentationContext context ) {
// This is fairly ugly stuff. It should be the case that the "getPropery()"
// method of the presentation context should contain this attribute, but it
// does not. So we have to go mining for it. As it turns out the presentation
// context is actually an implementation class DebugModelPresentationContext
// from which you can get the IDebugModelPresentation instance. In turn this
// is a DelegatingModelPresentation instance which allows you to obtain the
// current set of internal attributes, which contains the current state of
// "Show Type Names" ICON selection.
Class<? extends IPresentationContext> contextClass = context.getClass();
Method contextMethod = null;
try {
// Will return the instance of the class "DebugModelPresentationContext"
// if this is indeed the implementation we are expecting.
contextMethod = contextClass.getMethod( "getModelPresentation" , new Class[] {} ); //$NON-NLS-1$
}
catch ( Exception ex ) {}
IDebugModelPresentation debugModelPresentation = null ;
if (contextMethod != null) {
try {
// We invoke the "getModelPresntation" method to get the actual instance
// of the "DelegatingModelPresentation".
debugModelPresentation = (IDebugModelPresentation) contextMethod.invoke(context , new Object[0]);
}
catch ( Exception e ) {}
}
if (debugModelPresentation != null) {
Class<? extends IDebugModelPresentation> presentationClass = debugModelPresentation.getClass();
Method presentationMethod = null;
try {
// The "getAttributeMethod" is a public method which returns the internal
// attributes. These should be part of the Interface but they are not. So
// we get them through this available method.
presentationMethod = presentationClass.getMethod( "getAttributeMap" , new Class[] {} ); //$NON-NLS-1$
}
catch ( Exception ex ) {}
HashMap attributeMap = null;
if (presentationMethod != null) {
try {
// Now get the actual HashMap attribute list so we can see if there is
// state information about the "Show Type Names" ICON.
attributeMap = (HashMap) presentationMethod.invoke(debugModelPresentation , new Object[0]);
}
catch ( Exception e ) {}
}
if (attributeMap != null) {
// This attribute ( which is globally defined ) reflect the state of the ICON.
// If is exists is contains the current state. Non-existence would mean that
// the ICON has never been selected or changed. This is so at the very start
// when the view is first brought up.
Boolean attribute = (Boolean) attributeMap.get(IDebugModelPresentation.DISPLAY_VARIABLE_TYPE_NAMES);
if (attribute != null) {
return attribute;
}
}
}
// Could not get to the one of the methods needs to determine the state of the
// ICON or we could not get the attribute. Assume we are not showing the TYPE
// NAMES.
return Boolean.FALSE;
}
/**
* @since 2.0
*/
@ -420,6 +569,11 @@ public class RegisterVMNode extends AbstractExpressionVMNode
continue;
}
// Capture the current "Show Type Names" ICON state in case there are no columns.
if (update.getProperties().contains(PROP_REGISTER_SHOW_TYPE_NAMES)) {
update.setProperty(PROP_REGISTER_SHOW_TYPE_NAMES, getShowTypeNamesState(update.getPresentationContext()));
}
service.getRegisterData(
dmc,
// Use the ViewerDataRequestMonitor in order to propagate the update's cancel request. Use an immediate

View file

@ -23,28 +23,35 @@ RegisterGroupVMNode_No_columns__text_format={0} - {1}
# {1} - error message
RegisterGroupVMNode_No_columns__Error__text_format={0} - Error:{1}
RegisterVMNode_Name_column__text_format={0}
RegisterVMNode_Description_column__text_format={0}
# {0} floating point, 0=integer/1=float
# {1} readability, 0=not readable/1=readable/2=readonce
# {2} write-ability, 0=not write-able/1=write-able/2=write once
# {0} - floating point, 0=integer/1=float
# {1} - readability, 0=not readable/1=readable/2=readonce
# {2} - write-ability, 0=not write-able/1=write-able/2=write once
RegisterVMNode_Type_column__text_format={0,choice,0#Unsigned|1#Floating Point} / {1,choice,0#ReadNone|1#Readable|2#ReadOnce},{2,choice,0#WriteNone|1#Writeable|2#WriteOnce}
RegisterVMNode_Expression_column__text_format={0}
# {0} - register name
# {1} - value formatted in the active format. If the preferred format was
# available, then this is just the value. Otherwise, it's the string formatted
# by the FormattedValueLabelText.
# {1} - value formatted in the active format. If the preferred format was available,
# then this is just the value. Otherwise, it's the string formatted by the
# FormattedValueLabelText and the complexly created type.
RegisterVMNode_No_columns__text_format={0} = {1}
# {0} - register name
# {1} - value formatted in the active format. If the preferred format was available,
# then this is just the value. Otherwise, it's the string formatted by the
# FormattedValueLabelText and the complexly created type.
# {2} - floating point, 0=integer/1=float
# {3} - readability, 0=not readable/1=readable/2=readonce
# {4} - write-ability, 0=not write-able/1=write-able/2=write once
RegisterVMNode_No_columns__text_format_with_type={0} = {1} (type: {2,choice,0#Unsigned|1#Floating Point} / {3,choice,0#ReadNone|1#Readable|2#ReadOnce},{4,choice,0#WriteNone|1#Writeable|2#WriteOnce})
# {0} - register name
# {1} - error message
RegisterVMNode_No_columns__Error__text_format={0} - Error:{1}
RegisterBitFieldVMNode_Name_column__text_format={0}
RegisterBitFieldVMNode_Description_column__text_format={0}
@ -53,9 +60,9 @@ RegisterBitFieldVMNode_Description_column__text_format={0}
RegisterBitFieldVMNode_Type_column__text_format={0,choice,0#ReadNone|1#Readable|2#ReadOnce},{1,choice,0#WriteNone|1#Writeable|2#WriteOnce}
# Message format for the value column text
# {0} - value formatted in the active format. If the preferred format was
# available, then this is just the value. Otherwise, it's the string formatted
# by FormattedValueLabelText.
# {0} - value formatted in the active format. If the preferred format was available,
# then this is just the value. Otherwise, it's the string formatted by the
# FormattedValueLabelText.
# {1} - bit field mnemonic
RegisterBitFieldVMNode_Value_column__With_mnemonic__text_format={0} - {1}
@ -67,9 +74,23 @@ RegisterBitFieldVMNode_No_columns__text_format={0} = {1}
# {0} - bit field name
# {1} - error message
# {2} - readability, 0=not readable/1=readable/2=readonce
# {3} - write-ability, 0=not write-able/1=write-able/2=write once
RegisterBitFieldVMNode_No_columns__text_format_with_type={0} = {1} (type: {2,choice,0#ReadNone|1#Readable|2#ReadOnce},{3,choice,0#WriteNone|1#Writeable|2#WriteOnce})
# {0} - bit field name
# {1} - bit field value
# {2} - bit field mnemonic
RegisterBitFieldVMNode_No_columns__With_mnemonic__text_format={0} = {1} - {2}
# {0} - bit field name
# {1} - bit field value
# {2} - bit field mnemonic
# {3} - readability, 0=not readable/1=readable/2=readonce
# {4} - write-ability, 0=not write-able/1=write-able/2=write once
RegisterBitFieldVMNode_No_columns__With_mnemonic__text_format_with_type={0} = {1} - {2} (type: {3,choice,0#ReadNone|1#Readable|2#ReadOnce},{4,choice,0#WriteNone|1#Writeable|2#WriteOnce})
# {0} - bit field name
# {1} - error message
RegisterBitFieldVMNode_No_columns__Error__text_format={0} - Error:{1}

View file

@ -31,6 +31,8 @@ public class MessagesForVariablesVM extends NLS {
public static String VariableVMNode_Name_column__text_format;
public static String VariableVMNode_NoColumns_column__Error__text_format;
public static String VariableVMNode_NoColumns_column__text_format;
public static String VariableVMNode_NoColumns_column__No_string__text_format_with_type;
public static String VariableVMNode_NoColumns_column__text_format_with_type;
public static String VariableVMNode_NoColumns_column__No_string__text_format;
public static String VariableVMNode_Type_column__Error__text_format;
public static String VariableVMNode_Type_column__text_format;

View file

@ -11,8 +11,10 @@
package org.eclipse.cdt.dsf.debug.ui.viewmodel.variable;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.RejectedExecutionException;
@ -83,6 +85,7 @@ import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.IDebugModelPresentation;
import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.debug.ui.actions.IWatchExpressionFactoryAdapter2;
import org.eclipse.jface.util.PropertyChangeEvent;
@ -94,6 +97,7 @@ import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IMemento;
@SuppressWarnings("restriction")
public class VariableVMNode extends AbstractExpressionVMNode
implements IElementEditor, IElementLabelProvider, IElementPropertiesProvider, IElementMementoProvider
{
@ -112,6 +116,11 @@ public class VariableVMNode extends AbstractExpressionVMNode
*/
private static final String PROP_VARIABLE_ADDRESS = "variable_address"; //$NON-NLS-1$
/**
* @since 2.0
*/
private static final String PROP_VARIABLE_SHOW_TYPE_NAMES = "variable_show_type_names"; //$NON-NLS-1$
/**
* @since 2.0
*/
@ -407,21 +416,23 @@ public class VariableVMNode extends AbstractExpressionVMNode
FormattedValueVMUtil.getPropertyForFormatId(IFormattedValues.STRING_FORMAT),
IDebugVMConstants.PROP_FORMATTED_VALUE_AVAILABLE_FORMATS,
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT,
IDebugVMConstants.PROP_FORMATTED_VALUE_FORMAT_PREFERENCE})
IDebugVMConstants.PROP_FORMATTED_VALUE_FORMAT_PREFERENCE,
PROP_VARIABLE_SHOW_TYPE_NAMES})
{
@Override
public boolean isEnabled(IStatus status, Map<String, Object> properties) {
String[] formatIds =
(String[])properties.get(IDebugVMConstants.PROP_FORMATTED_VALUE_AVAILABLE_FORMATS);
String activeFormat = (String)properties.get(IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT);
Boolean showTypeNames = (Boolean) properties.get(PROP_VARIABLE_SHOW_TYPE_NAMES);
String[] formatIds = (String[]) properties.get(IDebugVMConstants.PROP_FORMATTED_VALUE_AVAILABLE_FORMATS);
String activeFormat = (String) properties.get(IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT);
return
showTypeNames != null &&
!showTypeNames.booleanValue() &&
!IFormattedValues.STRING_FORMAT.equals(activeFormat) &&
formatIds != null &&
Arrays.asList(formatIds).contains(IFormattedValues.STRING_FORMAT) &&
super.isEnabled(status, properties);
}
},
new FormattedValueLabelText(
MessagesForVariablesVM.VariableVMNode_NoColumns_column__No_string__text_format,
new String[] {
@ -429,7 +440,64 @@ public class VariableVMNode extends AbstractExpressionVMNode
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE,
IDebugVMConstants.PROP_FORMATTED_VALUE_AVAILABLE_FORMATS,
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT,
IDebugVMConstants.PROP_FORMATTED_VALUE_FORMAT_PREFERENCE}),
IDebugVMConstants.PROP_FORMATTED_VALUE_FORMAT_PREFERENCE,
PROP_VARIABLE_SHOW_TYPE_NAMES})
{
@Override
public boolean isEnabled(IStatus status, Map<String, Object> properties) {
Boolean showTypeNames = (Boolean) properties.get(PROP_VARIABLE_SHOW_TYPE_NAMES);
return
showTypeNames != null &&
!showTypeNames.booleanValue() &&
super.isEnabled(status, properties);
}
},
new FormattedValueLabelText(
MessagesForVariablesVM.VariableVMNode_NoColumns_column__text_format_with_type,
new String[] {
PROP_NAME,
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE,
FormattedValueVMUtil.getPropertyForFormatId(IFormattedValues.STRING_FORMAT),
PROP_VARIABLE_TYPE_NAME,
IDebugVMConstants.PROP_FORMATTED_VALUE_AVAILABLE_FORMATS,
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT,
IDebugVMConstants.PROP_FORMATTED_VALUE_FORMAT_PREFERENCE,
PROP_VARIABLE_SHOW_TYPE_NAMES})
{
@Override
public boolean isEnabled(IStatus status, Map<String, Object> properties) {
Boolean showTypeNames = (Boolean) properties.get(PROP_VARIABLE_SHOW_TYPE_NAMES);
String[] formatIds = (String[]) properties.get(IDebugVMConstants.PROP_FORMATTED_VALUE_AVAILABLE_FORMATS);
String activeFormat = (String) properties.get(IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT);
return
showTypeNames != null &&
showTypeNames.booleanValue() &&
!IFormattedValues.STRING_FORMAT.equals(activeFormat) &&
formatIds != null &&
Arrays.asList(formatIds).contains(IFormattedValues.STRING_FORMAT) &&
super.isEnabled(status, properties);
}
},
new FormattedValueLabelText(
MessagesForVariablesVM.VariableVMNode_NoColumns_column__No_string__text_format_with_type,
new String[] {
PROP_NAME,
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE,
PROP_VARIABLE_TYPE_NAME,
IDebugVMConstants.PROP_FORMATTED_VALUE_AVAILABLE_FORMATS,
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT,
IDebugVMConstants.PROP_FORMATTED_VALUE_FORMAT_PREFERENCE,
PROP_VARIABLE_SHOW_TYPE_NAMES})
{
@Override
public boolean isEnabled(IStatus status, Map<String, Object> properties) {
Boolean showTypeNames = (Boolean) properties.get(PROP_VARIABLE_SHOW_TYPE_NAMES);
return
showTypeNames != null &&
showTypeNames.booleanValue() &&
super.isEnabled(status, properties);
}
},
new ErrorLabelText(
MessagesForVariablesVM.VariableVMNode_NoColumns_column__Error__text_format,
new String[] { PROP_NAME }),
@ -504,6 +572,93 @@ public class VariableVMNode extends AbstractExpressionVMNode
}
}
//
// We encapsulate the determination of the state of the "Show Type Names" ICON
// selection to this routine. This attribute information is not readily available
// from standard Interface definitions. So we use reflection to get the info. But
// in the future this will change and then we can just change this routine. This
// really should just be as simple as the code below, which could be done inline
// once it comes to pass.
//
// Boolean attribute = (Boolean) context.getProperty(IDebugModelPresentation.DISPLAY_VARIABLE_TYPE_NAMES);
// if (attribute != null) {
// return attribute;
// }
// return Boolean.FALSE;
//
// @param return-value Boolean.TRUE --> Show Types ICON is selected/depressed
// @param return-value Boolean.FALSE --> Show Types ICON is not selected/depressed
//
@SuppressWarnings("unchecked")
private Boolean getShowTypeNamesState( IPresentationContext context ) {
// This is fairly ugly stuff. It should be the case that the "getPropery()"
// method of the presentation context should contain this attribute, but it
// does not. So we have to go mining for it. As it turns out the presentation
// context is actually an implementation class DebugModelPresentationContext
// from which you can get the IDebugModelPresentation instance. In turn this
// is a DelegatingModelPresentation instance which allows you to obtain the
// current set of internal attributes, which contains the current state of
// "Show Type Names" ICON selection.
Class<? extends IPresentationContext> contextClass = context.getClass();
Method contextMethod = null;
try {
// Will return the instance of the class "DebugModelPresentationContext"
// if this is indeed the implementation we are expecting.
contextMethod = contextClass.getMethod( "getModelPresentation" , new Class[] {} ); //$NON-NLS-1$
}
catch ( Exception ex ) {}
IDebugModelPresentation debugModelPresentation = null ;
if (contextMethod != null) {
try {
// We invoke the "getModelPresntation" method to get the actual instance
// of the "DelegatingModelPresentation".
debugModelPresentation = (IDebugModelPresentation) contextMethod.invoke(context , new Object[0]);
}
catch ( Exception e ) {}
}
if (debugModelPresentation != null) {
Class<? extends IDebugModelPresentation> presentationClass = debugModelPresentation.getClass();
Method presentationMethod = null;
try {
// The "getAttributeMethod" is a public method which returns the internal
// attributes. These should be part of the Interface but they are not. So
// we get them through this available method.
presentationMethod = presentationClass.getMethod( "getAttributeMap" , new Class[] {} ); //$NON-NLS-1$
}
catch ( Exception ex ) {}
HashMap attributeMap = null;
if (presentationMethod != null) {
try {
// Now get the actual HashMap attribute list so we can see if there is
// state information about the "Show Type Names" ICON.
attributeMap = (HashMap) presentationMethod.invoke(debugModelPresentation , new Object[0]);
}
catch ( Exception e ) {}
}
if (attributeMap != null) {
// This attribute ( which is globally defined ) reflect the state of the ICON.
// If is exists is contains the current state. Non-existence would mean that
// the ICON has never been selected or changed. This is so at the very start
// when the view is first brought up.
Boolean attribute = (Boolean) attributeMap.get(IDebugModelPresentation.DISPLAY_VARIABLE_TYPE_NAMES);
if (attribute != null) {
return attribute;
}
}
}
// Could not get to the one of the methods needs to determine the state of the
// ICON or we could not get the attribute. Assume we are not showing the TYPE
// NAMES.
return Boolean.FALSE;
}
/**
* @since 2.0
*/
@ -532,6 +687,11 @@ public class VariableVMNode extends AbstractExpressionVMNode
update.setProperty(AbstractExpressionVMNode.PROP_ELEMENT_EXPRESSION, expression.getExpressionText());
}
// Capture the current "Show Type Names" ICON state in case there are no columns.
if (update.getProperties().contains(PROP_VARIABLE_SHOW_TYPE_NAMES)) {
update.setProperty(PROP_VARIABLE_SHOW_TYPE_NAMES, getShowTypeNamesState(update.getPresentationContext()));
}
IExpressionDMContext dmc = findDmcInPath(update.getViewerInput(), update.getElementPath(), IExpressions.IExpressionDMContext.class);
if ( dmc == null || service == null) {
update.setStatus(DsfUIPlugin.newErrorStatus(IDsfStatusConstants.INVALID_STATE, "Invalid context or service not available.", null)); //$NON-NLS-1$
@ -603,11 +763,11 @@ public class VariableVMNode extends AbstractExpressionVMNode
update.setProperty(PROP_VARIABLE_BASIC_TYPE, type.name());
}
/*
* If this node has an expression then it has already been filled in by the higher
* level logic. If not then we need to supply something. In the previous version
* ( pre-property based ) we supplied the name. So we will do that here also.
*/
//
// If this node has an expression then it has already been filled in by the higher
// level logic. If not then we need to supply something. In the previous version
// ( pre-property based ) we supplied the name. So we will do that here also.
//
IExpression expression = (IExpression)DebugPlugin.getAdapter(update.getElement(), IExpression.class);
if (expression == null) {
update.setProperty(AbstractExpressionVMNode.PROP_ELEMENT_EXPRESSION, data.getName());
@ -864,8 +1024,6 @@ public class VariableVMNode extends AbstractExpressionVMNode
stackFrameService.getLocals(frameDmc, rm);
}
//private final static int MAX_STRING_VALUE_LENGTH = 40;
public int getDeltaFlags(Object e) {
if ( e instanceof ISuspendedDMEvent ||
e instanceof IMemoryChangedEvent ||

View file

@ -24,23 +24,38 @@ VariableVMNode_Type_column__Error__text_format=
VariableVMNode_Type_column__text_format={0}
# Message format for the value column text
# {0} - value formatted in the active format. If the preferred format was
# available, then this is just the value. Otherwise, it's the string formatted
# by the format in VariableVMNode_Value_column__Value__text_format.
# {0} - value formatted in the active format. If the preferred format was available,
# then this is just the value. Otherwise, it's the string formatted by the
# format in VariableVMNode_Value_column__Value__text_format.
# {1} - value in STRING format.
VariableVMNode_Value_column__text_format={0} {1}
# {0} - variable name
# {1} - value formatted in the active format. If the preferred format was
# available, then this is just the value. Otherwise, it's the string formatted
# by the format in VariableVMNode_Value_column__Value__text_format.
# {1} - value formatted in the active format. If the preferred format was available,
# then this is just the value. Otherwise, it's the string formatted by the
# format in VariableVMNode_Value_column__Value__text_format.
# {2} - value in STRING format.
VariableVMNode_NoColumns_column__text_format={0} = {1} {2}
# {0} - variable name
# {1} - value formatted in the active format. If the preferred format was
# available, then this is just the value. Otherwise, it's the string formatted
# by the format in VariableVMNode_Value_column__Value__text_format.
# {1} - value formatted in the active format. If the preferred format was available,
# then this is just the value. Otherwise, it's the string formatted by the
# format in VariableVMNode_Value_column__Value__text_format.
# {2} - type of the variable being displayed
VariableVMNode_NoColumns_column__No_string__text_format_with_type={0} = {1} (type: {2})
# {0} - variable name
# {1} - value formatted in the active format. If the preferred format was available,
# then this is just the value. Otherwise, it's the string formatted by the
# format in VariableVMNode_Value_column__Value__text_format.
# {2} - value in STRING format.
# {3} - type of the variable being displayed
VariableVMNode_NoColumns_column__text_format_with_type={0} = {1} {2} (type: {3})
# {0} - variable name
# {1} - value formatted in the active format. If the preferred format was available,
# then this is just the value. Otherwise, it's the string formatted by the
# format in VariableVMNode_Value_column__Value__text_format.
VariableVMNode_NoColumns_column__No_string__text_format={0} = {1}
# {0} - variable name