File: DefaultNutUtilitiesImpl.mesa
CreatedBy: Butler on June 18, 1984 9:25:04 am PDT
Last Edited By:
Butler on June 27, 1984 3:52:35 pm PDT
Widom on June 18, 1984 9:25:39 am PDT
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. . .