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;
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. . .