final ValueEditorHierarchyManager valueEditorHierarchyManager = gemCutter.getValueEditorHierarchyManager();
ValueEditorManager valueEditorManager = valueEditorHierarchyManager.getValueEditorManager();
ValueNode valueNode = valueGem.getValueNode();
// Create the value entry panel.
final ValueEntryPanel valueEntryPanel =
(ValueEntryPanel)valueEditorManager.getValueEditorDirector().getRootValueEditor(valueEditorHierarchyManager,
valueNode, null, 0, null);
// Add it to the map.
valueGemPanelMap.put(valueGem, valueEntryPanel);
// add a listener to propagate changes in the value gem to the VEP.
valueGem.addValueChangeListener(new ValueGemChangeListener() {
public void valueChanged(ValueGemChangeEvent e) {
ValueGem valueGem = (ValueGem)e.getSource();
valueEditorHierarchyManager.collapseHierarchy(valueEntryPanel, false);
valueEntryPanel.changeOwnerValue(valueGem.getValueNode());
valueEntryPanel.setSize(valueEntryPanel.getPreferredSize());
valueEntryPanel.revalidate();
}
});
// Set size of the panel.
valueEntryPanel.setSize(valueEntryPanel.getPreferredSize());
// Add a listener to propagate changes in the VEP to the value gem.
valueEntryPanel.addValueEditorListener(new ValueEditorAdapter() {
public void valueCommitted(ValueEditorEvent evt) {
ValueNode oldValue = evt.getOldValue();
ValueNode newValue = ((ValueEntryPanel)evt.getSource()).getValueNode();
if (!oldValue.sameValue(newValue)) {
valueGem.changeValue(newValue);
}
}
});
// Add a listener so that a change in the size of the VEP will trigger a change the size of the displayed gem.
valueEntryPanel.addComponentListener(new ComponentAdapter() {
// change the size of the displayed value gem if the VEP is resized
public void componentResized(ComponentEvent e) {
tableTop.getDisplayedGem(valueGem).sizeChanged();
}
// Re-position displayed gem if the VEP moves
// This will happen if the VEP size changes (as a result of a type change), and its size is clamped to the parent's bounds.
// eg. stick a new VEP on the right edge of the TableTop, and change its type to String.
public void componentMoved(ComponentEvent e) {
Point vepLocation = valueEntryPanel.getLocation();
int newX = vepLocation.x - DisplayConstants.BEVEL_WIDTH_X - 1;
int newY = vepLocation.y - DisplayConstants.BEVEL_WIDTH_Y - 1;
Point newPoint = new Point(newX, newY);
tableTop.getDisplayedGem(valueGem).setLocation(newPoint);
}
});
// Set the vep's context for type switching.
valueEntryPanel.setContext(new ValueEditorContext() {
public TypeExpr getLeastConstrainedTypeExpr() {
return tableTop.getGemGraph().getLeastConstrainedValueType(valueGem, tableTop.getTypeCheckInfo());
}
});
// Set it up so that VEP commits are handled as user edits.
valueEntryPanel.addValueEditorListener(new ValueEditorAdapter() {
public void valueCommitted(ValueEditorEvent evt) {
tableTop.handleValueGemCommitted(valueGem, evt.getOldValue(), valueEntryPanel.getValueNode());
}
});
}
return valueGemPanelMap.get(valueGem);