MPS 2025.1 Logical View: how to replace TREE_NODE

We used to have code like this in our project in MPS 2023.2:

...
action context parameters:
  TreeNode treeNode key: TREE_NODE required

...

if (this.treeNode instanceof ProjectSolutionTreeNode) { 
  SModule module = ((ProjectSolutionTreeNode) this.treeNode).getModule(); 
  searchScope = new  ModulesScope(module); 
} else if (this.treeNode instanceof SModelTreeNode) { 
  SModel model = ((SModelTreeNode) this.treeNode).getModel(); 
  searchScope = new  ModelsScope(model); 
} else if (this.treeNode instanceof PackageNode) { 
  PackageNode packageNode = ((PackageNode) this.treeNode); 
  SModel model = packageNode.getModelReference().resolve(this.mpsProject.getRepository()); 
  searchScope = new  ModelsScope(model); 
  nodesInPackageScope = packageNode.getNodesUnderPackage(); 
} else { 
  searchScope = new  ProjectScope(this.mpsProject); 
}

Now we’re migrating to 2025.1 and the TREE_NODE data key no longer works. I see that there are new VALUE and USER_OBJECT keys that appear to be the replacement of TREE_NODE. How would I use them to write code above? I.e. to figure out what kind of entity is currently selected?

In MPS 2025.1 the Project pane stopped providing the Swing tree node itself via MPSCommonDataKeys.TREE_NODE. Instead, it now exposes:

  • MPSCommonDataKeys.VALUE: the semantic value of the selected item (e.g., SModule, SModel, SNode, or a VirtualFolder like VirtualFolder.Nodes for a package folder).
  • MPSCommonDataKeys.USER_OBJECT: the “node presentation object” that may implement helper interfaces (e.g., ContextValueProvider, StereotypeProvider, DiscoveryValueProvider) to get contextual information.

This means you should not rely on Swing’s TreeNode type anymore to decide what is selected. Use VALUE to detect semantics and USER_OBJECT only when you need extra context.

You can also use MPSCommonDataKeys.VALUES / USER_OBJECTS for multi-selection.

Quick mapping from old to new:

  • ProjectSolutionTreeNode → VALUE instanceof SModule (Solution)
  • SModelTreeNode → VALUE instanceof SModel
  • PackageNode (namespace under a model) → VALUE instanceof VirtualFolder.Nodes
    and USER_OBJECT implements ContextValueProvider → get SModel: contextValueOfType(SModel.class)
    and USER_OBJECT implements DiscoveryValueProvider → get package contents: discoverValuesOfType(SNode.class)

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.