<> <> <> <> <> <<>> <<>> DIRECTORY DB, DefaultNutUtilities, IO, InputFocus, Nut, NutOps, NutViewer, ViewerOps, Buttons; DefaultNutUtilitiesImpl: CEDAR PROGRAM IMPORTS DB, Nut, NutOps, NutViewer, InputFocus, ViewerOps EXPORTS DefaultNutUtilities = BEGIN OPEN DB, NutViewer; FieldHandle: PUBLIC TYPE = REF FieldObject; FieldObject: PUBLIC TYPE = RECORD[ tuple: Relship, attribute: Attribute ]; ProcessSelection: PUBLIC Buttons.ButtonProc = -- A standard ButtonProc that assumes the button's REF ANY data is the FieldHandle above. -- Insures attribute of tuple is entity-valued and non-NIL, then calls Nut.Display on it. BEGIN OPEN DB; otherEntity: Entity; fd: FieldHandle_ NARROW[clientData]; viewer: Viewer_ NARROW[parent]; IF fd.attribute=NIL THEN -- it was the relation itself { newV: Viewer; otherEntity _ RelationOf[fd.tuple]; newV _ NutViewer.SpawnViewer[e: otherEntity, seg: NutOps.SafeSegmentOf[otherEntity], parent: viewer.parent]; Nut.Display[e: otherEntity, newV: newV, seg: NutOps.SafeSegmentOf[otherEntity]] } ELSE IF NutOps.EntityValued[fd.attribute] THEN -- attribute refs another entity IF Null[fd.tuple] THEN Message[viewer, "That relationship has been deleted!"] ELSE IF Null[otherEntity_V2E[GetF[fd.tuple, fd.attribute]]] THEN Message[viewer, "That entity has been deleted!"] ELSE { newV: Viewer; otherEntity _ V2E[GetF[fd.tuple, fd.attribute]]; newV _ NutViewer.SpawnViewer[e: otherEntity, seg: NutOps.SafeSegmentOf[otherEntity], parent: viewer.parent]; Nut.Display[e: otherEntity, newV: newV, seg: NutOps.SafeSegmentOf[otherEntity]] } ELSE -- attribute is a string or number Message[viewer, "Not an entity-valued field"]; END; Reset: PUBLIC PROC[eName: ROPE, d: DB.Domain, seg: DB.Segment, parent: Viewer] = BEGIN -- Resets contents of editor to its statebefore edits started. e: DB.Entity; e _ DB.FetchEntity[d, eName, seg ! DB.Error => { e _ NIL; CONTINUE } ]; InputFocus.SetInputFocus[]; -- kill the caret parent.child _ NIL; ViewerOps.PaintViewer[parent, $client]; Nut.Edit[e: e, eName: eName, d: d, seg: seg, newV: parent] ; END; Edit: PUBLIC PROC[eName: ROPE, d: DB.Domain, seg: DB.Segment, parent: Viewer] = BEGIN -- Invoked when hit the "Edit" button on the default displayer. -- Should replace the displayer viewer with an editor viewer. e: Entity _ FetchEntity[d: d, name: eName]; newV: Viewer; InputFocus.SetInputFocus[]; IF NutOps.IsSystemEntity[e] THEN BEGIN [] _ NutViewer.Message[NIL, eName, " is a system entity. You may not edit it."]; RETURN; END; newV _ NutViewer.ReplaceViewer[ e: e, eName: eName, d: d, seg: seg, parent: parent]; Nut.Edit[ e: e, eName: eName, d: d, seg: seg, newV: newV]; END; GetTopLevel: PUBLIC PROCEDURE [v: Viewer] RETURNS [ancestor: Viewer] = { FOR ancestor _ v, ancestor.parent UNTIL ancestor.parent=NIL DO ENDLOOP; }; END. . .