<> <> <> <> <> <<>> <<>> 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; SpawnParent: PROC[v: Viewer] RETURNS [parent: Viewer] = { parent _ v; WHILE parent.parent # NIL DO parent _ parent.parent ENDLOOP }; 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: DefaultNutUtilities.FieldHandle_ NARROW[clientData]; viewer: Viewer_ NARROW[parent]; IF fd.attribute=NIL THEN -- it was the relation itself { otherEntity _ RelationOf[fd.tuple]; IF NOT DB.Null[otherEntity] THEN [] _ Nut.Display[eName: DB.NameOf[otherEntity], domain: "RelationDomain", parent: SpawnParent[viewer], segment: DB.SegmentOf[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 { otherEntity _ V2E[GetF[fd.tuple, fd.attribute]]; [] _ Nut.Display[eName: DB.NameOf[otherEntity], domain: DB.NameOf[DB.DomainOf[otherEntity]], parent: SpawnParent[viewer], segment: DB.SegmentOf[otherEntity]] } ELSE -- attribute is a string or number Message[viewer, "Not an entity-valued field"]; END; Reset: PUBLIC PROC[eName, domain: ROPE, seg: DB.Segment, viewer: Viewer] = BEGIN -- Resets contents of editor to its statebefore edits started. InputFocus.SetInputFocus[]; -- kill the caret viewer.child _ NIL; ViewerOps.PaintViewer[viewer, client]; [] _ Nut.Edit[eName: eName, domain: domain, segment: seg, parent: viewer] ; END; Edit: PUBLIC PROC[eName, domain: ROPE, 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. InputFocus.SetInputFocus[]; IF NutOps.IsSystemEntity[eName] THEN BEGIN [] _ NutViewer.Message[NIL, eName, " is a system entity. You may not edit it."]; RETURN; END; [] _ Nut.Edit[ eName: eName, domain: domain, segment: seg, parent: parent]; END; END. . .