[[BackLinksMenu]] [[TicketQuery(summary=UNPLANNED_LOGIC_REFACTORING_R0, 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|)]] = Analysis = == Overview == This task is about refactoring the logic operations in the application. The problems related to that include (but are not limited to): * There are operations that do not use R3 logic. * There is code duplication (especially in the menu items and bound controls in HUDs). * There is no convention on naming the events and handlers. * There is no convention on placing (and grouping) the logic classes. After this iteration there should be a convention for placing, grouping and naming events and handlers. All existing R3 logics should follow that convention. A lot of the code smells should be eliminated. All old logics will be replaced by new ones. This task is with a bigger scope and might not be finished in one week. == Task requirements == * Create a convention for naming, placing and grouping EventIds, OperationDefs and entries in OperationDefs, apply it and start following it. * Describe the convention in the [wiki:UNPLANNED_LOGIC_REFACTORING_R0#Design] section of this page. * Identify and remove duplicate code. * Refactor old logic classes to use LogicR3. * Use LogicR3 handling instead of direct method invocation. * All buttons, menu items and bound controls should fire an event. * Use AutoActions when you want to change the model. They should perform a single ModelChange and have a good description. == Task result == * Convention for Logics, described in the design section of this page. * Source code == Implementation idea == * It seems sensible that all nested ids for events should be named EventIds. Since they are accessed by the wrapper class, it is clear what event they are for. E.g. MenuItem.EventIds.CLICKED. * OperationDef members that handle an event might be named starting with ON_ (e.g. ON_SET_SCREEN_MODE). * In the MenuItem there is code duplication on the clicked method. It should become final and fire a CLICKED event. == Related == [wiki:UNPLANNED_MAIN_WINDOW_REFACTORING_R0][[BR]] [wiki:GROUP_BOOK_MODEL_REDESIGN_R0] == How to demo == * Show the convention to everyone. * Show the code and demonstrate that there are no old logics left. * Run the available tests. = Design = * For the align buttons: * Create two abstract methods in AlignElementsButton: * {{{float calculateAlignValue(List selected)}}} - for a given list of element views calculates some align value, for example, the Y-axis of the top-most element. * {{{ImmPoint calculateNewLocation(ImmRect bounds, float alignValue)}}} - calculates a new location for a single element, given the old bounds and the align value, returned from the above method. * Replace the {{{clicked}}} method in all align buttons with the above methods. * Create {{{AlignElementsLogic}}} with a single handler - {{{ON_ALIGN}}}, which listens for {{{CLICKED}}} from {{{AlignElementsButton}}}. * Calculates the align value * Creates an immutable list of new locations * Creates an immutable list of references to elements. Only elements of type {{{MemberElement}}} are collected. * Creates a new {{{AutoAction}}} that iterates over all references and changes {{{MemberElement.KEY_LOCATION}}} with the newly calculated location. = Implementation = Changesets: [5628], [5641] = Testing = ^(Place the testing results here.)^ = Comments = ^(Write comments for this or later revisions here.)