public void run(IAction action) {
IStructuredSelection selection = getCurrentSelection();
if (selection instanceof TextSelection) {
TextSelection textSelection = (TextSelection) selection;
IExpressionManager expressionManager = DebugPlugin.getDefault()
.getExpressionManager();
IDOMNode domNode = (IDOMNode) selection.getFirstElement();
String expression;
try {
expression = domNode.getFirstStructuredDocumentRegion()
.getParentDocument().get(textSelection.getOffset(),
textSelection.getLength());
// create the new watch expression
IWatchExpression watchExpression = expressionManager
.newWatchExpression(expression.trim());
expressionManager.addExpression(watchExpression);
// refresh and re-evaluate
watchExpression.setExpressionContext(getContext());
} catch (Exception e) {
Logger.logException(e);
}