wiki:GROUP_TEMPLATES_R1
Last modified 16 years ago Last modified on 05/25/09 18:56:49

Error: Macro BackLinksMenu(None) failed
compressed data is corrupt

Error: Macro TicketQuery(summary=GROUP_TEMPLATES_R1, format=table, col=summary|owner|status|type|component|priority|effort|importance, rows=description|analysis_owners|analysis_reviewers|analysis_score|design_owners|design_reviewers|design_score|implementation_owners|implementation_reviewers|implementation_score|test_owners|test_reviewers|test_score|) failed
current transaction is aborted, commands ignored until end of transaction block

Analysis

Overview

  • The templating library needs to be of not great complexity, so that persisting and copying is done easily.
  • The main issue is that when deriving mutable objects and then making changes to them results in derived objects with local changes, which are hard to handle.

Task requirements

  • The goal of this revision is to reduce the complexity of the templating library.
  • It should not be possible there to be a derived object with local changes.

Task result

  • The result of this task should be source code.

Implementation idea

  • The mode should be set recursively to the bottom of the tree, but the mutable objects themselves should not be derived.
  • Create an enumeration for the different modes of a templated property.

How to demo

  • Start Sophie2.
  • Create a page with some frames.
  • Add the page as a template.
  • Create another page and apply the newly created template to it.

Design

Instead of having useTemplate() and locked() properties, an enumeration TemplateMode should be introduced, with the following elements:

  • USE_TEMPLATE - the value from the template is used
  • LOCKED - the own value is used and it cannot be modified
  • CUSTOM - the own value is used and it can be modified.

When setting a value to a mutable object, for instance Frame, it should be set to all children recursevly - for example backgroundStyle(), borderStyle(), contentLocation(), etc. Setting a value to a mutable object, actually does not change its mode in its own TemplateSupport - instead it is only changed in the children. This should insure that there cannot be derived mutable objects. Here is an example of setting a mode:

  • frame.templateSupport().get().mode().set(TemplateMode.LOCKED); - this will set all properties of the frame to be in locked mode. Those include all properties of the border style, background style, shadow style, and also, the content location, content size, etc.
  • frame.backgroundStyle().get().templateSupport().get().mode().set(TemplateMode.LOCKED); - this will lock all the properties of the backgroundStyle.
  • frame.templateSupport().get().setMode(frame.backgroundStyle(), TemplateMode.LOCKED); - this does the same as above.
  • frame.templateSupport().get().setMode(frame.contentLocation(), TemplateMode.LOCKED); - this will lock only the location

Here is an example of getting a mode:

  • frame.templateSupport().get().getMode(frame.contentLocation()); - gets the mode of the location
  • frame.templateSupport().get().getMode(frame.backgroundStyle()); - get the mode of the background style. If all properties of the background style are USE_TEMPLATE (for example), then USE_TEMPLATE is returned. CUSTOM is returned otherwise.
  • frame.backgroundStyle().get().templateSupport().get().mode().get(); - some as the above.
  • frame.templateSupport().get().mode().get - will return USE_TEMPLATE if the whole frame uses the template, LOCKED if the whole frame is locked, and CUSTOM otherwise.

The following changes should be considered:

  • A new interface Templatable should be added, which contains the templateSupport() property. All classes need template support should implement this interface.
  • Class TemplateField should be rafactored in a way that the TemplateMode enumeration is used.
  • Class TemplateValueField should be refactored in the following way:
    • value() should always return ownValue() if the object is a mutable
    • derivedValue() should only return immutables
  • Class TemplateListField should be refactored in a way that either the ownList or derivedList is returned, depending on the mode.
  • Class TemplateSupport should be rafactored in a way that the TemplateMode enumeration is used.

Updated UML class diagram:

source:trunk/sophie2-platform/doc/uml-design-diagrams/TemplateR1ClassDiagram.png

The tests are in revision [2813]

Unit test for TemplateSupport: TemplateSupportTest

Unit test for TemplateMode: TemplateModeTest

Integration test: TemplateIntegrationTest

Demo: TemplateDemo

Implementation

Done according to the design. [2833], [2835] Merged into the trunk in [2846] revision.

Known bugs

  • If a page template is created and that template is applied, toggling the "use template content" button on some of the derived frames causes unnecessary frame resources to be created. For some reason, the derivedList() which contains the derived frames of the page is recomputed.

Testing

(Place the testing results here.)

Comments

(Write comments for this or later revisions here.)