ETLayoutItemGroup

Authors

Quentin Mathe (qmathe@club-internet.fr)
A layout item tree node which can contain arbitrary ETLayoutItem subclass instances.

Copyright: (C) 2007 Quentin Mathe


Contents -

  1. Software documentation for the ETLayoutItemGroup class
  2. Software documentation for the NSObject(ETLayoutItemGroupDelegate) informal protocol
  3. Software documentation for the NSObject(ETLayoutItemGroupIndexSource) informal protocol
  4. Software documentation for the NSObject(ETLayoutItemGroupSource) informal protocol
  5. ETLayoutItemGroup constants

Software documentation for the ETLayoutItemGroup class

ETLayoutItemGroup : ETLayoutItem

Declared in:
ETLayoutItemGroup.h
Conforms to:
ETLayoutingContext
ETWidgetLayoutingContext
ETItemSelection
ETCollection
ETCollectionMutation

You must never subclass ETLayoutItemGroup.

Method summary

acceptsActionsForItemsOutsideOfFrame 

- (BOOL) acceptsActionsForItemsOutsideOfFrame;
An empty method provided for subclasses to override.

Returns whether the tools should hit test the children which intersect the area that lies outside the receiver frame but inside its bounding box.

By default, returns NO.

You can override this method to implement control points external to the receiver area as ETHandleGroup do.


addItem: 

- (void) addItem: (ETLayoutItem*)item;

@taskunit Accessing and Mutating Items

Adds the given item to the receiver children.

Adds the given item to the receiver children.


addItems: 

- (void) addItems: (NSArray*)items;

Adds the given the items to the receiver children.


allDescendantItems 

- (NSArray*) allDescendantItems;

Returns all descendant items of the receiver, including immediate children.

This method collects every item in the layout item subtree (excluding the receiver) by doing a preorder traversal, the resulting collection is a flat list of every item in the tree.

If you are interested in collecting descendant items in another traversal order, you have to implement your own version of this method.


arrangedItems 

- (NSArray*) arrangedItems;

Returns an array with the child items currently sorted and filtered, otherwise returns an array identical to -items .

If the receiver has not been sorted or filtered yet, returns a nil array.


canReload 

- (BOOL) canReload;

@taskunit Framework Private

Returns whether the receiver can be reloaded presently with -reload .

Returns whether the receiver can be reloaded presently with -reload .


containsItem: 

- (BOOL) containsItem: (ETLayoutItem*)item;

Returns whether the given item is a receiver child or not.


controller 

- (ETController*) controller;

Returns the controller which allows to customize the overall UI interaction with the receiver item tree.

When the controller is not nil, the receiver is both a base item and the controller content.


delegate 

- (id) delegate;

@taskunit Controller and Delegate

Returns the delegate associated with the receiver.

See also -setDelegate: .

Returns the delegate associated with the receiver.

See also -setDelegate: .


descendantItemsSharingSameBaseItem 

- (NSArray*) descendantItemsSharingSameBaseItem;

@taskunit Accessing Descendant Items

Returns the descendant items, including the immediate children, that share the same base item than the receiver.

An item is said to be under the control of an item group, when you can traverse the branch leading to the item without crossing a base item. An item group becomes a base item when a represented path base is set, in other words when -representedPathBase doesn't return nil. See also -isBaseItem .

This method collects every item in the layout item subtree (excluding the receiver) by doing a preorder traversal, the resulting collection is a flat list of every item in the tree.

If you are interested by collecting descendant items in another traversal order, you have to implement your own version of this method.

Returns the descendant items, including the immediate children, that share the same base item than the receiver.

An item is said to be under the control of an item group, when you can traverse the branch leading to the item without crossing a base item. An item group becomes a base item when a represented path base is set, in other words when -representedPathBase doesn't return nil. See also -isBaseItem .

This method collects every item in the layout item subtree (excluding the receiver) by doing a preorder traversal, the resulting collection is a flat list of every item in the tree.

If you are interested by collecting descendant items in another traversal order, you have to implement your own version of this method.


descriptionWithProperty: arranged: 

- (NSString*) descriptionWithProperty: (NSString*)aProperty arranged: (BOOL)usesArrangedItems;

@taskunit Debugging

Returns an indented tree description by traversing the tree with -arrangedItems to get the children if usesArrangedItems is YES, otherwise with -items .

When aProperty is a valid property name, each item description includes the value bound to this property.

See also -[NSObject descriptionWithOptions:].

Returns an indented tree description by traversing the tree with -arrangedItems to get the children if usesArrangedItems is YES, otherwise with -items .

When aProperty is a valid property name, each item description includes the value bound to this property.

See also -[NSObject descriptionWithOptions:].


didChangeSelection 

- (void) didChangeSelection;

Tells the receiver the selection has been changed and it should post ETItemGroupSelectionDidChangeNotification.

You should never use this method when you use -setSelected: on descendant items rather than setSelectionXXX: methods on the receiver.


doubleAction 

- (SEL) doubleAction;

Sets the action that can be sent by the action handler, typically on a double click within the receiver area.

See also -setDoubleAction: .


doubleClickedItem 

- (ETLayoutItem*) doubleClickedItem;

Returns the last child item on which a double click occurs.


filterWithPredicate: recursively: 

- (void) filterWithPredicate: (NSPredicate*)predicate recursively: (BOOL)recursively;
Description forthcoming.

firstItem 

- (ETLayoutItem*) firstItem;

Returns the first receiver child item.

Shortcut method equivalent to [self itemAtIndex: 0].

Similar to -firstObject method for collections (see ETCollection).


handleAttachItem: 

- (void) handleAttachItem: (ETLayoutItem*)item;
An empty method provided for subclasses to override.

Handles any necessary adjustments to be done right before item is made a child item of the receiver. This method is available to be overriden in subclasses that want to extend or modify the item insertion behavior.

The default implementation takes to care to remove item from any existing parent item, then updates the parent item reference to be the receiver.
You must always call the superclass implementation.

Symetric method to -handleDetachItem:


handleAttachViewOfItem: 

- (void) handleAttachViewOfItem: (ETLayoutItem*)item;

Inserts the display view of the given item into the receiver view.

This method is used by -setVisibleItems: to manage view insertion. See also -handleDetachViewOfItem: and -[ETUItem displayView].


handleDetachItem: 

- (void) handleDetachItem: (ETLayoutItem*)item;
An empty method provided for subclasses to override.

Handles any necessary adjustments to be done right before item is removed as a child item from the receiver. This method is available to be overriden in subclasses that want to extend or modify the item removal behavior.

The default implementation only updates the parent item reference to be nil.
You must always call the superclass implementation.

Symetric method to -handleAttachItem:


handleDetachViewOfItem: 

- (void) handleDetachViewOfItem: (ETLayoutItem*)item;

Removes the display view of the given view from the receiver view.

This method is used by -setVisibleItems: to manage view removal. See also -handleAttachViewOfItem: and -[ETUIItem displayView].


indexOfItem: 

- (NSInteger) indexOfItem: (id)item;

Returns the index of the given child item in the receiver children.


initAsLayerItemWithObjectGraphContext: 

- (id) initAsLayerItemWithObjectGraphContext: (COObjectGraphContext*)aContext;

Initializes and returns a layer item to be encaspulated in a layout.

You should never need to use this method.

See also -isLayerItem .


insertItem: atIndex: 

- (void) insertItem: (ETLayoutItem*)item atIndex: (NSUInteger)index;

Inserts the given item in the receiver children at a precise index.


insertObject: atIndex: hint: boxingForced: 

- (ETLayoutItem*) insertObject: (id)object atIndex: (NSUInteger)index hint: (id)hint boxingForced: (BOOL)boxingForced;

@taskunit Additions to ETCollectionMutation


isChangingSelection 

- (BOOL) isChangingSelection;

Returns YES when a selection change initiated by -setSelectionIndex: , -setSelectionIndexes: or -setSelectionIndexPaths: is underway, otherwise returns NO.

During ETItemGroupSelectionDidChangeNotification and -[ETLayout didChangeSelectionInLayoutContext] will return YES.

You can use this method in ETLayout subclasses to prevent loops while synchronizing the selection between a widget and the item tree.
See -[ETWidgetLayout didChangeSelectionInLayoutView].
e.g. Just put a guard clause at the beginning of -didChangeSelectionInLayoutView

if ([layoutContext isChangingSelection])
	return;

isDescendantItem: 

- (BOOL) isDescendantItem: (ETLayoutItem*)anItem;

Returns whether the item is a receiver descendant item.

This method is a lot more efficient than using -allDescendantItems e.g. [[self allDescendantItems] containsItem: anItem] .


isFiltered 

- (BOOL) isFiltered;

Returns whether -arrangedItems are filtered or not.

See also -filterWithPredicate:recursively: .


isLayerItem 

- (BOOL) isLayerItem;

Returns whether the receiver is a layer item encaspulated in a layout and invisible in the main layout item tree.


isSorted 

- (BOOL) isSorted;

Returns whether -arrangedItems are sorted or not.

See also -sortWithSortDescriptors:recursively: .


itemAtIndex: 

- (ETLayoutItem*) itemAtIndex: (NSInteger)index;

Returns the child item at the given index in the receiver children.


itemAtIndexPath: 

- (ETLayoutItem*) itemAtIndexPath: (NSIndexPath*)path;

@taskunit Traversing the Layout Item Tree

Returns the layout item child identified by the index path parameter interpreted as relative to the receiver.

For an empty path, returns self.
For a nil path, returns nil.

Returns the layout item child identified by the index path parameter interpreted as relative to the receiver.

For an empty path, returns self.
For a nil path, returns nil.


itemForIdentifier: 

- (ETLayoutItem*) itemForIdentifier: (NSString*)anId;

Returns the first layout item descendant on which the identifier is set.

The descendant items are retrieved with -allDescendantItems , this results in a pre-order traversal.
Use this method cautiously when the item tree is big (e.g. more than 10 000 items).

See also -identifier .


itemScaleFactor 

- (CGFloat) itemScaleFactor;

@taskunit Item Scaling

Returns the scale factor applied to each item when the layout supports it.

See also -setItemScaleFactor: .

Returns the scale factor applied to each item when the layout supports it.

See also -setItemScaleFactor: .


items 

- (NSArray*) items;

Returns an autoreleased array which contains the receiver child items.


lastItem 

- (ETLayoutItem*) lastItem;

Returns the last receiver child item.

Shortcut method equivalent to [self itemAtIndex: [self numberOfItems] - 1].

Similar to -lastObject method for collections (see ETCollection).


layout 

- (id) layout;

@taskunit Layout

Returns the layout associated with the receiver to present its content.

Returns the layout associated with the receiver to present its content.


numberOfItems 

- (NSInteger) numberOfItems;

Returns how many child items the receiver includes.


reload 

- (void) reload;

Reloads the content by removing all existing childrens and requesting all the receiver immediate children to the base item source.

Will cancel any any sorting and/or filtering currently done on the receiver. Which means -isFiltered and -isSorted will both return NO.

Marks the receiver as needing a layout update.


reloadAndUpdateLayout 

- (void) reloadAndUpdateLayout;

@taskunit Deprecated

Attempts to reload the children items from the source and updates the layout by asking the first ancestor item with an opaque layout to do so.

Attempts to reload the children items from the source and updates the layout by asking the first ancestor item with an opaque layout to do so.


reloadIfNeeded 

- (void) reloadIfNeeded;

@@taskunit Reloading Items from Represented Object or Source

Tries to reload the content of the receiver, but only if it can be reloaded.

Won't reload when the receiver is currently sorted and/or filtered. See -isSorted and -isFiltered .

This method can be safely called even if the receiver has no source or doesn't inherit a source from a base item.

Marks the receiver as needing a layout update, if a reload occurs.

See also -reload .

Tries to reload the content of the receiver, but only if it can be reloaded.

Won't reload when the receiver is currently sorted and/or filtered. See -isSorted and -isFiltered .

This method can be safely called even if the receiver has no source or doesn't inherit a source from a base item.

Marks the receiver as needing a layout update, if a reload occurs.

See also -reload .


removeAllItems 

- (void) removeAllItems;

Removes all the receiver child items.


removeItem: 

- (void) removeItem: (ETLayoutItem*)item;

Removes the given item from the receiver children.


removeItemAtIndex: 

- (void) removeItemAtIndex: (NSUInteger)index;

Removes the child item at the given index in the receiver children.


removeItems: 

- (void) removeItems: (NSArray*)items;

Removes the given child items from the receiver children.


render: dirtyRect: inContext: 

- (void) render: (NSMutableDictionary*)inputValues dirtyRect: (NSRect)dirtyRect inContext: (id)ctxt;

@taskunit Drawing

See -[ETLayoutItem render:dirtyRect:inContext:]. The most important addition of this method is to manage the drawing of children items by calling this method recursively on them. The supervisor view or parent item intersects the dirty rect against the receiver drawing box just before calling -render:dirtyRect:inContext: . Which means the dirty rect needs no adjustments.

See -[ETLayoutItem render:dirtyRect:inContext:]. The most important addition of this method is to manage the drawing of children items by calling this method recursively on them. The supervisor view or parent item intersects the dirty rect against the receiver drawing box just before calling -render:dirtyRect:inContext: . Which means the dirty rect needs no adjustments.


selectedItems 

- (NSArray*) selectedItems;

Returns the selected child items belonging to the receiver.

The returned collection only includes immediate children, other selected descendant items below these childrens in the layout item subtree are excluded.


selectedItemsInLayout 

- (NSArray*) selectedItemsInLayout;

Returns selected descendant items reported by the active layout through -[ETLayout selectedItems].

You should call this method to obtain the selection in most cases and not -selectedItems .


selectionIndex 

- (NSUInteger) selectionIndex;

@taskunit Selection

Returns the index of the first selected item which is an immediate child of the receiver. If there is none, returns NSNotFound.

Calling this method is equivalent to [[self selectionIndexes] firstIndex].

Take note that -selectionIndexPaths may return one or multiple values when this method returns NSNotFound. See -selectionIndexes also.

Returns the index of the first selected item which is an immediate child of the receiver. If there is none, returns NSNotFound.

Calling this method is equivalent to [[self selectionIndexes] firstIndex].

Take note that -selectionIndexPaths may return one or multiple values when this method returns NSNotFound. See -selectionIndexes also.


selectionIndexPaths 

- (NSArray*) selectionIndexPaths;

Returns the index paths of selected items in layout item subtree of the the receiver.


selectionIndexes 

- (NSMutableIndexSet*) selectionIndexes;

Returns all indexes matching selected items which are immediate children of the receiver.

Put in another way, the method returns the first index of all index paths with a length equal one.


setController: 

- (void) setController: (ETController*)aController;

Sets the controller which allows to customize the overall UI interaction with the receiver item tree.

When the given controller is not nil, it is inserted as the next responder and the receiver becomes both a base item and the controller content.

See also -setSource: , -isBaseItem and -nextResponder .


setDelegate: 

- (void) setDelegate: (id)delegate;

Sets the delegate associated with the receiver.

A delegate is only useful if the receiver is a base item, otherwise it will be ignored.

The delegate is retained, unlike what Cocoa/GNUstep usually do.
The delegate is owned by the item and treated as a pluggable aspect to be released when the item is deallocated.


setDoubleAction: 

- (void) setDoubleAction: (SEL)selector;

@taskunit Actions

Returns the action that can be sent by the action handler, typically on a double click within the receiver area.

For a double action, the sender will be the receiver. The double clicked item can be retrieved by calling -doubleClickedItem on the sender in your action method.

Returns the action that can be sent by the action handler, typically on a double click within the receiver area.

For a double action, the sender will be the receiver. The double clicked item can be retrieved by calling -doubleClickedItem on the sender in your action method.


setItemScaleFactor: 

- (void) setItemScaleFactor: (CGFloat)aFactor;

Sets the scale factor applied to each item when the layout supports it.

This scale factor only applies to the immediate children.

Updates the layout immediately unlike most methods.

See -[ETLayout setItemSizeConstraintStyle:] and -[ETLayout setConstrainedItemSize:] to control more precisely how the items get resized per layout.


setLayout: 

- (void) setLayout: (ETLayout*)layout;

Sets the layout associated with the receiver to present its content.


setLayoutView: 

- (void) setLayoutView: (NSView*)aView;

@taskunit Layouting Context Protocol

Inserts the given layout view into the supervisor view.

Inserts the given layout view into the supervisor view.


setSelectedItems: 

- (void) setSelectedItems: (NSArray*)items;

Sets the selected items in the layout item subtree attached to the receiver.

Posts an ETItemGroupSelectionDidChangeNotification and marks the receiver to be redisplayed.


setSelectionIndex: 

- (void) setSelectionIndex: (NSUInteger)index;

Sets the selected item identified by index in the receiver and discards any existing selection index paths previously set.

Posts an ETItemGroupSelectionDidChangeNotification.


setSelectionIndexPaths: 

- (void) setSelectionIndexPaths: (NSArray*)indexPaths;

Sets the selected items in the layout item subtree attached to the receiver.

Posts an ETItemGroupSelectionDidChangeNotification and marks the receiver to be redisplayed.


setSelectionIndexes: 

- (void) setSelectionIndexes: (NSIndexSet*)indexes;

Sets the selected items identified by indexes in the receiver and discards any existing selection index paths previously set.

Posts an ETItemGroupSelectionDidChangeNotification.


setShouldMutateRepresentedObject: 

- (void) setShouldMutateRepresentedObject: (BOOL)flag;

Sets whether the layout item tree mutation are propagated to the represented object or not.

The value set is meaningful only if the receiver is a base item, otherwise the value is simply ignored.


setSource: 

- (void) setSource: (id)source;

Sets the source which provides the content displayed by the receiver. A source can be any objects conforming to ETIndexSource or ETPathSource protocol.

So you can write you own data source object by implementing either:

    • -numberOfItemsInItemGroup:
    • -itemGroup:itemAtIndex:
    • -itemGroup:numberOfItemsAtPath:
    • -itemGroup:itemAtPath:

Another common solution is to use the receiver itself as a source, in that case -usesRepresentedObjectAsProvider returns YES. And the receiver will generate the layout item tree bound to it by retrieving any child objects of the represented object (through ETCollection protocol) and wrapping them into ETLayoutItem or ETLayoutItemGroup objects based on whether these childs implements ETCollection or not.

You can also combine these abilities with an off-the-shelf controller object like ETController. See -setController to do so. This brings extra flexibility such as:

  • template item and item group for the generated layout items
  • easy to use add, insert and remove actions with template model object and model group for the represented objects to insert wrapped in layout items
  • sorting
  • searching

Finally when -source returns nil, it's always possible to build and manage a layout item tree structure in a static fashion by yourself.

When the new source is set, the content is immediately reloaded, and the layout updated unless the autolayout is disabled. Finally an ETSourceDidUpdateNotification is posted.

By setting a source, the receiver represented path base is automatically set to '/' unless another path was set previously. If you pass nil to get rid of a source, the represented path base isn't reset to nil but keeps its actual value in order to maintain it as a base item and avoid unpredictable changes to the event handling logic.

Marks the receiver as needing a layout update.


setVisibleItems: 

- (void) setVisibleItems: (NSArray*)visibleItems;

Sets the receiver visible child items, and mutates the view hierarchy when some items use a view. Views are inserted or removed to match the item visibility.

This method is invoked by the receiver layout just before -[ETLayout renderWithItems:isNewContent:] returns, to adjust the visibility of views and update each item visible property.
You shouldn't need to call this method by yourself.


shouldMutateRepresentedObject 

- (BOOL) shouldMutateRepresentedObject;

@taskunit Controlling Content Mutation and Item Providing

Returns YES when the item tree mutation are propagated to the represented object, otherwise returns NO if it's up to you to reflect structural changes of the layout item tree onto the model object graph. By default, this method returns YES.

Mutations are triggered by calling children or collection related methods like -addItem: , -insertItem:atIndex: , removeItem:, addObject: etc.

The returned value is meaningful only if the receiver is a base item. In this case, the value applies to all related descendant items (by being looked up by descendant items).

Returns YES when the item tree mutation are propagated to the represented object, otherwise returns NO if it's up to you to reflect structural changes of the layout item tree onto the model object graph. By default, this method returns YES.

Mutations are triggered by calling children or collection related methods like -addItem: , -insertItem:atIndex: , removeItem:, addObject: etc.

The returned value is meaningful only if the receiver is a base item. In this case, the value applies to all related descendant items (by being looked up by descendant items).


sortWithSortDescriptors: recursively: 

- (void) sortWithSortDescriptors: (NSArray*)sortDescriptors recursively: (BOOL)recursively;

@taskunit Sorting and Filtering


source 

- (id) source;

Returns the source which provides the content presented by the receiver.

A source implements either ETIndexSource or ETPathSource protocols. If the receiver handles the layout item tree directly without the help of a source object, then this method returns nil.


updateLayout 

- (void) updateLayout;

Updates recursively each layout in the item tree owned by the receiver.

See -updateLayoutRecursively: .


updateLayoutRecursively: 

- (void) updateLayoutRecursively: (BOOL)recursively;

Updates each layout in the immediate children ( recursively is NO) or in the whole item subtree (recursively is YES) owned by the receiver.

When recursively is YES, does a bottom-up layout update, by propagating it first downwards.
Layout updates start on the terminal descendant items, then are carried upwards through the tree structure back to the receiver, whose layout is the last updated.
A bottom-up update is used because a parent layout computation might depend on child item properties. For example, an item can use a layout which touches its frame (see -usesFlexibleLayoutFrame).


usesRepresentedObjectAsProvider 

- (BOOL) usesRepresentedObjectAsProvider;

Returns YES when the child items are automatically generated by wrapping the elements of the represented object collection into ETLayoutItem or ETLayoutItemGroup instances.

To use represented objects as providers in the layout item tree connected to the receiver, you have to set the source of the receiver to be the receiver itself. The code would be something like

[itemGroupsetSource: itemGroup]
.

visibleContentSize 

- (NSSize) visibleContentSize;
Description forthcoming.

visibleItems 

- (NSArray*) visibleItems;

Returns the receiver visible child items.


Software documentation for the NSObject(ETLayoutItemGroupDelegate) informal protocol

NSObject(ETLayoutItemGroupDelegate)

Declared in:
ETLayoutItemGroup.h

Informal delegate protocol that can be implemented by the object set with -[ETLayoutItemGroup setDelegate:].

Method summary

itemGroupSelectionDidChange: 

- (void) itemGroupSelectionDidChange: (NSNotification*)notif;

Delegate method that corresponds to ETItemGroupSelectionDidChangeNotification.


provideWindowItemForItemGroup: 

- (ETWindowItem*) provideWindowItemForItemGroup: (ETLayoutItemGroup*)itemGroup;
Description forthcoming.

Software documentation for the NSObject(ETLayoutItemGroupIndexSource) informal protocol

NSObject(ETLayoutItemGroupIndexSource)

Declared in:
ETLayoutItemGroup.h

Informal source protocol based on child index, which can be implemented by the source object set with -[ETLayoutItemGroup setSource:].

Method summary

baseItem: itemAtIndex: inItemGroup: 

- (ETLayoutItem*) baseItem: (ETLayoutItemGroup*)baseItem itemAtIndex: (NSUInteger)index inItemGroup: (ETLayoutItemGroup*)itemGroup;
Description forthcoming.

baseItem: numberOfItemsInItemGroup: 

- (int) baseItem: (ETLayoutItemGroup*)baseItem numberOfItemsInItemGroup: (ETLayoutItemGroup*)itemGroup;
Description forthcoming.

Software documentation for the NSObject(ETLayoutItemGroupSource) informal protocol

NSObject(ETLayoutItemGroupSource)

Declared in:
ETLayoutItemGroup.h

Additional methods that makes up the informal source protocol.

Method summary

displayedItemPropertiesInItemGroup: 

- (NSArray*) displayedItemPropertiesInItemGroup: (ETLayoutItemGroup*)itemGroup;
Description forthcoming.

ETLayoutItemGroup constants

ETItemGroupSelectionDidChangeNotification

NSString* const ETItemGroupSelectionDidChangeNotification;

Notification posted by ETLayoutItemGroup and subclasses in reply to selection change in the layout item tree connected to the poster object. The poster object is always an item group and can be retrieved through -[NSNotification object].

This notification is posted when a selection related method such as -setSelectionIndexPaths: has been called on the object associated with the notification, or when the selection is modified by the user, in this last case the poster object will always be a base item.


ETSourceDidUpdateNotification

NSString* const ETSourceDidUpdateNotification;

Notification observed by ETLayoutItemGroup and other classes on which a source can be set. When the notification is received, the layout item tree that belongs to the receiver is automatically reloaded.

This notification is only delivered when the poster is equal to the source object of the observer.

You can use this method to trigger the reloading everywhere the poster object is used as source, without having to know the involved objects directly and explicitly invoke -reload on each object.