LINKS_HUD_UI_MANAGING_LINKS: linksHud-implementation.patch

File linksHud-implementation.patch, 21.3 KB (added by pap, 15 years ago)
  • modules/org.sophie2.main.func.links/src/main/java/org/sophie2/main/func/links/LinksHudLogic.java

    ### Eclipse Workspace Patch 1.0
    #P sophie
     
    11package org.sophie2.main.func.links; 
    22 
     3import javax.swing.SwingUtilities; 
     4 
    35import org.sophie2.base.bound.BoundControl; 
    46import org.sophie2.base.bound.ComboInput; 
    57import org.sophie2.base.commons.util.ImmList; 
     
    1719import org.sophie2.core.mvc.OperationDef; 
    1820import org.sophie2.core.mvc.events.EventR3; 
    1921import org.sophie2.main.app.commons.links.LinkHolder; 
    20 import org.sophie2.main.func.links.LinksHud.AddRule; 
    2122import org.sophie2.main.func.links.LinksHud.AvailableActions; 
    2223import org.sophie2.main.func.links.LinksHud.AvailableTriggers; 
    2324import org.sophie2.main.func.links.LinksHud.CurrentRule; 
     
    2829 * Logic, related to the {@link LinksHud}. It handles events fired from there. 
    2930 *  
    3031 * @author kyli 
     32 * @author pap 
    3133 */ 
    3234public enum LinksHudLogic implements OperationDef { 
    3335 
     
    4951 
    5052                        LinksHud hud = control.findParentElement(LinksHud.class); 
    5153 
    52                         if (input.getSelectedItem() != null &&  
    53                                         hud != null &&  
    54                                         input.getSelectedItem() != null) { 
    55                                 hud.currentRule().set(input.getSelectedItem()); 
     54                        if (hud != null ) { 
     55                                hud.wantedRule().set(input.getSelectedItem()); 
    5656                        } 
    5757 
    5858                        return true; 
     
    7878                                        BoundControl.EventIds.INPUT_PARAM_INDEX, ComboInput.class); 
    7979 
    8080                        LinksHud hud = control.findParentElement(LinksHud.class); 
    81                         if (hud != null && hud.currentRule().get() != null && input.getSelectedItem() != null) { 
    82  
     81                        if (hud != null && input.getSelectedItem() != null) { 
    8382                                LinkHolder holder = hud.holder().get(); 
    8483 
     84                                if (hud.currentRule().get() == LinksHud.EMPTY_RULE) { 
     85                                        LinkRule newRule = new LinkRule(null, null); 
     86                                        ImmList<LinkRule> rules = holder.getLink().getRules(); 
     87                                        final Link newLink = new Link(rules.add(newRule)); 
     88                                         
     89                                        LogicR3.fire(hud, control, null, event, EventIds.SET_LINK,  
     90                                                        newLink, "Add link rule"); 
     91                                         
     92                                        assert holder.getLink().getRules().asList().indexOf(newRule) >= 0 : 
     93                                                "The rule could not be added!";  
     94                                        hud.wantedRule().set(newRule); 
     95                                } 
     96 
     97                                 
     98 
    8599                                LinkTrigger newTrigger = input.getSelectedItem(); 
    86100 
    87101                                LinkRule newRule = new LinkRule(newTrigger,  
     
    102116                                LogicR3.fire(hud, control, null, event, EventIds.SET_LINK,  
    103117                                                newLink, "Change link trigger"); 
    104118 
    105                                 hud.currentRule().set(newRule); 
     119                                hud.wantedRule().set(newRule); 
    106120                        } 
    107121                        return true; 
    108122                } 
     
    121135 
    122136                @SuppressWarnings("unchecked") 
    123137                public boolean handle(EventR3 event) { 
    124                         AvailableActions control = event.getSource(AvailableActions.class); 
     138                        final AvailableActions control = event.getSource(AvailableActions.class); 
    125139                        ComboInput<LinkActionProvider> input = event.getEventParam( 
    126140                                        BoundControl.EventIds.INPUT_PARAM_INDEX, ComboInput.class); 
    127141 
     
    149163                                LogicR3.fire(hud, control, null, event, EventIds.SET_LINK,  
    150164                                                newLink, "Change link action"); 
    151165                                 
    152                                 hud.currentRule().set(newRule); 
     166                                hud.wantedRule().set(newRule); 
     167                                SwingUtilities.invokeLater(new Runnable() { 
     168                                         
     169                                        public void run() { 
     170                                                Boolean  value = control.actionUpdateForcer().get(); 
     171                                                control.actionUpdateForcer().set(!value); 
     172                                        } 
     173                                }); 
    153174                        } 
    154175                        return true; 
    155176                } 
     
    188209                        LogicR3.fire(hud, control, null, event, EventIds.SET_LINK,  
    189210                                        newLink, "Remove link rule"); 
    190211                         
    191                         if (newLink.getRules().size() > 0) { 
    192                                 hud.currentRule().set(newLink.getRules().get(0)); 
    193                         } else { 
    194                                 hud.currentRule().set(null); 
    195                         } 
    196                         return true; 
    197                 } 
    198         },  
    199          
    200         /** 
    201          *      A new {@link LinkRule} should be added to the {@link Link}. 
    202          */ 
    203         ON_ADD_RULE { 
    204  
    205                 public void defineFilter(EventFilterBuilder filter) { 
    206                         filter.setSourceClass(AddRule.class); 
    207                         filter.setEventId(LinkActionIds.ADD_RULE); 
    208                 } 
    209  
    210                 public boolean handle(EventR3 event) { 
    211                         AddRule control = event.getSource(AddRule.class); 
    212                         LinksHud hud = control.findParentElement(LinksHud.class); 
    213                          
    214                         if (hud == null) { 
    215                                 throw new RuntimeException("Hud not found!"); 
    216                         } 
    217                         LinkHolder holder = hud.holder().get(); 
    218  
    219                         LinkRule newRule = new LinkRule(null, null); 
    220                         ImmList<LinkRule> rules = holder.getLink().getRules(); 
    221                         final Link newLink = new Link(rules.add(newRule)); 
    222                          
    223                         LogicR3.fire(hud, control, null, event, EventIds.SET_LINK,  
    224                                         newLink, "Add link rule"); 
    225                          
    226                         assert holder.getLink().getRules().asList().indexOf(newRule) >= 0 : 
    227                                 "The rule could not be added!";  
    228                          
    229                         hud.currentRule().set(newRule); 
     212                        hud.wantedRule().set(null); 
    230213                        return true; 
    231214                } 
    232215        },  
  • modules/org.sophie2.main.func.links/src/main/java/org/sophie2/main/func/links/LinksHud.java

     
    22 
    33import java.awt.Font; 
    44import java.util.ArrayList; 
    5 import java.util.Collections; 
     5import java.util.LinkedList; 
    66import java.util.List; 
    77 
    88import javax.swing.JPanel; 
     
    2626import org.sophie2.base.model.book.links.LinkActionProvider; 
    2727import org.sophie2.base.model.book.links.LinkRule; 
    2828import org.sophie2.base.model.book.links.LinkTrigger; 
     29import org.sophie2.base.skins.Skin; 
    2930import org.sophie2.base.skins.SkinElementId; 
     31import org.sophie2.base.skins.SkinManager; 
     32import org.sophie2.base.skins.SkinUtil; 
    3033import org.sophie2.base.visual.BaseSwingVisualElement; 
    3134import org.sophie2.base.visual.skins.ElementSkinPart; 
    3235import org.sophie2.base.visual.skins.RelatedChildren; 
     
    3740import org.sophie2.core.mvc.events.EventR3; 
    3841import org.sophie2.core.prolib.annot.Own; 
    3942import org.sophie2.core.prolib.impl.AutoListProperty; 
     43import org.sophie2.core.prolib.impl.AutoProperty; 
    4044import org.sophie2.core.prolib.impl.ResourceProperty; 
    4145import org.sophie2.core.prolib.interfaces.ListProp; 
    4246import org.sophie2.core.prolib.interfaces.Prop; 
     
    5054 * look for attached rules and configuration panels. 
    5155 *  
    5256 * @author kyli 
     57 * @author pap 
    5358 */ 
    5459public abstract class LinksHud extends HudDialog { 
    5560 
     61        /** 
     62         * The {@link Skin} property id of the title of the {@link #EMPTY_RULE} item. 
     63         */ 
     64        public static final String EMPTY_RULE_TITLE_PROP_ID = null; 
     65 
    5666        @SuppressWarnings("unused") 
    5767        @SkinPartDef 
    5868        private static void defineSkin(ElementSkinPart part) { 
    5969                part.add(TOOL_TIP_PROP_ID, "Manage links."); 
     70                part.add(EMPTY_RULE_TITLE_PROP_ID, "New Rule"); 
    6071        } 
    6172 
    6273        /** 
     
    7687                        part.add(FONT_ID, new Font("Arial", Font.BOLD, 12)); 
    7788                        part.add(FONT_COLOR_ID, new ImmColor(0.17578125f, 0.26171875f, 0.6875f)); 
    7889                } 
    79                  
     90 
    8091                /** 
    8192                 * The button that closes the links hud. 
    8293                 *  
     
    95106                } 
    96107 
    97108        } 
    98          
    99          
     109 
     110 
    100111        /** 
    101112         * The "current rule" comboBox. 
     113         *  
     114         * @author pap 
    102115         */ 
    103116        @VisualElementDef(parent = LinksHud.class, sortKey = "aaa-current-rule") 
    104117        public static class CurrentRule extends BoundComboBox<LinkRule> { 
     
    118131                protected ComboState<LinkRule> computeModelData() { 
    119132                        LinksHud hud = this.findParentElement(LinksHud.class); 
    120133                        if (hud != null && hud.holder().get() != null) { 
    121                                 return new ComboState<LinkRule>("",  
    122                                                 hud.holder().get().getLink().getRules().asList(), hud.currentRule().get()); 
     134                                List<LinkRule> rules = new ArrayList<LinkRule>(); 
     135                                rules.add(EMPTY_RULE); 
     136                                rules.addAll(hud.holder().get().getLink().getRules().asList()); 
     137                                LinkRule rule = hud.currentRule().get(); 
     138                                rule = rule == null ? EMPTY_RULE : rule ; 
    123139 
     140                                return new ComboState<LinkRule>("", rules, rule); 
    124141                        } 
    125142                        // else, return empty DropDownList 
    126                         return new ComboState<LinkRule>("", Collections.<LinkRule> emptyList(), null); 
     143                        return ComboState.<LinkRule>empty(); 
    127144                } 
    128145 
    129146                @Override 
    130147                protected BoundValidation validate(ComboInput<LinkRule> inputData) { 
    131148                        return BoundValidation.SUCCESS; 
    132149                } 
    133                  
     150 
    134151        } 
    135152 
    136153        /** 
     
    139156        @VisualElementDef(parent = LinksHud.class, sortKey = "ddd-available-triggers") 
    140157        public static class AvailableTriggers extends BoundComboBox<LinkTrigger> { 
    141158 
     159                /** 
     160                 * The {@link Skin} property id of the title of the {@link #SELECT_TRIGGER_ITEM}. 
     161                 */ 
     162                public static final String SELECT_TRIGGER_TITLE_PROP_ID = null; 
     163                 
     164                /** 
     165                 * A special {@link LinkTrigger} to denote a "New rule" item in the combo. 
     166                 */ 
     167                public static final LinkTrigger SELECT_TRIGGER_ITEM = new LinkTrigger() { 
     168 
     169                        public String getDescription() { 
     170                                String elemId = SkinUtil.getElementId(AvailableTriggers.class); 
     171                                return SkinManager.get().currentSkin().get().getValue(elemId, SELECT_TRIGGER_TITLE_PROP_ID, String.class); 
     172                        } 
     173 
     174                        @Override 
     175                        public String toString() { 
     176                                return getDescription(); 
     177                        } 
     178                }; 
     179 
    142180                @SuppressWarnings("unused") 
    143181                @SkinPartDef 
    144182                private static void fillSkinParts(ElementSkinPart part) { 
     
    148186                        part.add(FIELD_EDITABLE_PROP_ID, Boolean.FALSE); 
    149187                        part.add(COMBO_SIZE_PROP_ID, new ImmSize(220, 20)); 
    150188                        part.add(VALIDATION_VISIBLE_ID, false); 
     189                        part.add(SELECT_TRIGGER_TITLE_PROP_ID, "choose trigger"); 
    151190                } 
    152191 
    153192                @Override 
     
    158197                        if (hud != null && hud.holder().get() != null) { 
    159198 
    160199                                // if the holder is a page, get the rule's set trigger. 
    161                                         if (hud.currentRule().get() != null) { 
    162                                                 trigger = hud.currentRule().get().getTrigger(); 
    163                                         } else { 
    164                                                 trigger = null; 
    165                                         } 
    166                                         return new ComboState<LinkTrigger>("",  
    167                                                         hud.holder().get().getTriggers(), trigger); 
     200                                LinkRule currentRule = hud.currentRule().get(); 
     201                                if (currentRule != null && currentRule != EMPTY_RULE) { 
     202                                        trigger = currentRule.getTrigger(); 
     203                                } else { 
     204                                        trigger = SELECT_TRIGGER_ITEM; 
     205                                } 
     206                                return new ComboState<LinkTrigger>("",  
     207                                                hud.holder().get().getTriggers(), trigger); 
    168208                        } 
    169209                        // else, return empty DropDownList 
    170                         return new ComboState<LinkTrigger>("", Collections.<LinkTrigger> emptyList(), null); 
     210                        return ComboState.<LinkTrigger>empty(); 
    171211                } 
    172212 
    173213                @Override 
    174214                protected BoundValidation validate(ComboInput<LinkTrigger> inputData) { 
    175215                        return BoundValidation.SUCCESS; 
    176216                } 
    177                  
    178                 @Override 
    179                 public boolean computeEnabled() { 
    180                         LinksHud hud = findParentElement(LinksHud.class); 
    181                         return hud != null && hud.currentRule().get() != null; 
    182                 } 
     217 
    183218        } 
    184219 
    185220        /** 
     
    187222         */ 
    188223        @VisualElementDef(parent = LinksHud.class, sortKey = "eee-available-actions") 
    189224        public static class AvailableActions extends BoundComboBox<LinkActionProvider> { 
     225                 
     226                /** 
     227                 * The {@link Skin} property id of the title of the {@link #SELECT_ACTION_ITEM}. 
     228                 */ 
     229                public static final String SELECT_ACTION_TITLE_PROP_ID = "select-action-item"; 
     230 
     231                /** 
     232                 * A special item which purpose is to prompt the user to select an action for the link. 
     233                 */ 
     234                public static final LinkActionProvider SELECT_ACTION_ITEM = new LinkActionProvider() { 
     235 
     236                        public Class<? extends LinkAction> getProvidedClass() { 
     237                                return null; 
     238                        } 
     239 
     240                        public String getDescription() { 
     241                                String elemId = SkinUtil.getElementId(AvailableActions.class); 
     242                                return SkinManager.get().currentSkin().get().getValue(elemId, SELECT_ACTION_TITLE_PROP_ID, String.class); 
     243                        } 
     244 
     245                        @Override 
     246                        public String toString() { 
     247                                return getDescription(); 
     248                        } 
     249 
     250                        public LinkAction create() { 
     251                                return null; 
     252                        } 
     253                };  
    190254 
    191255                @SuppressWarnings("unused") 
    192256                @SkinPartDef 
     
    197261                        part.add(FIELD_EDITABLE_PROP_ID, Boolean.FALSE); 
    198262                        part.add(COMBO_SIZE_PROP_ID, new ImmSize(220, 20)); 
    199263                        part.add(VALIDATION_VISIBLE_ID, false); 
     264                        part.add(SELECT_ACTION_TITLE_PROP_ID, "choose action"); 
    200265                } 
    201266 
    202267                private ListProp<LinkActionProvider> actionProviders() { 
     
    208273 
    209274                                                @Override 
    210275                                                protected List<? extends LinkActionProvider> computeData() { 
     276                                                        List<LinkActionProvider> res = new ArrayList<LinkActionProvider>(); 
    211277                                                        ProList<SophieExtension<LinkActionProvider>> extensions =  
    212278                                                                BaseModelBookModule.get().getLinkActionPoint().extensions().get(); 
    213                                                         List<LinkActionProvider> res = new ArrayList<LinkActionProvider>(); 
    214279                                                        for (int i = 0; i < extensions.size(); i++) { 
    215280                                                                res.add(extensions.get(i).getObject()); 
    216281                                                        } 
     
    221286                        } 
    222287                        return getBean().makeProp(actionProviders.class); 
    223288                } 
     289                 
     290                /** 
     291                 * A property used to make the {@link AvailableActions} control update itself and 
     292                 * remove the "choose action" item when an action is chosen for the first time.  
     293                 *  
     294                 * @return 
     295                 *                      Property. 
     296                 */ 
     297                RwProp<Boolean> actionUpdateForcer() { 
     298                        return getBean().makeValueProp("actionUpdateForcer", Boolean.class, true); 
     299                } 
    224300 
    225301                @Override 
    226302                protected ComboState<LinkActionProvider> computeModelData() { 
    227                         LinksHud hud = this.findParentElement(LinksHud.class); 
     303                        LinksHud hud = findParentElement(LinksHud.class); 
    228304                        LinkActionProvider selectedProvider = null; 
     305                        List<LinkActionProvider> items = new LinkedList<LinkActionProvider>(actionProviders().get());  
    229306 
    230                         if (hud != null && hud.currentRule().get() != null) { 
    231                                 LinkAction action = hud.currentRule().get().getAction(); 
    232                                 for (LinkActionProvider prov : actionProviders().get()) { 
    233                                         if (action != null && prov.getProvidedClass().equals(action.getClass())) { 
    234                                                 selectedProvider = prov; 
    235                                                 break; 
     307                        if (hud != null) { 
     308                                actionUpdateForcer().get(); 
     309                                LinkRule currentRule = hud.currentRule().get(); 
     310                                if (currentRule == null || currentRule == EMPTY_RULE || currentRule.getAction() == null) { 
     311                                        items.add(0, SELECT_ACTION_ITEM); 
     312                                        selectedProvider = SELECT_ACTION_ITEM; 
     313                                } else { 
     314                                        LinkAction action = hud.currentRule().get().getAction(); 
     315                                        for (LinkActionProvider prov : actionProviders().get()) { 
     316                                                if (action != null && prov.getProvidedClass().equals(action.getClass())) { 
     317                                                        selectedProvider = prov; 
     318                                                        break; 
     319                                                } 
    236320                                        } 
    237                                 } 
    238321 
     322                                }  
    239323                        } 
    240                                 return new ComboState<LinkActionProvider>("", actionProviders().get(), 
    241                                                 selectedProvider); 
     324                        return new ComboState<LinkActionProvider>("", items, selectedProvider); 
    242325                } 
    243326 
    244327                @Override 
    245328                protected BoundValidation validate(ComboInput<LinkActionProvider> inputData) { 
    246329                        return BoundValidation.SUCCESS; 
    247330                } 
    248                  
     331 
    249332                @Override 
    250333                public boolean computeEnabled() { 
    251334                        LinksHud hud = findParentElement(LinksHud.class); 
    252335                        return hud != null &&  
    253                                 hud.currentRule().get() != null &&  
    254                                 hud.currentRule().get().getTrigger() != null; 
    255                 } 
    256         } 
    257  
    258         /** 
    259          * The "add rule" button. 
    260          */ 
    261         @VisualElementDef(parent = LinksHud.class, sortKey = "bbb-add-rule") 
    262         public static class AddRule extends LogicR3Button { 
    263  
    264                 @SuppressWarnings("unused") 
    265                 @SkinPartDef 
    266                 private static void fillSkinParts(ElementSkinPart part) { 
    267                         part.add(TOOL_TIP_PROP_ID, "Add new rule"); 
    268                         part.add(SIZE_PROP_ID, new ImmSize(26, 26)); 
    269                         part.add(ICON_PROP_ID, ImageUtil.loadIcon("plus.png")); 
    270                 } 
    271                  
    272                 @Override 
    273                 protected ImmList<EventR3> computeEvents() { 
    274                         return ImmTreeList.<EventR3>create(new EventR3(this, null, null,null, LinkActionIds.ADD_RULE)); 
     336                        hud.currentRule().get() != null &&  
     337                        hud.currentRule().get().getTrigger() != null; 
    275338                } 
    276  
    277 //              public Prop<JButton> swingComponent() { 
    278 //                      class swingComponent extends ResourceProperty<JButton> { 
    279 // 
    280 //                              @Override 
    281 //                              protected JButton create() { 
    282 //                                      JButton res =null; 
    283 //                                      res.setName("emptyBackgroundButton"); 
    284 //                                       
    285 //                                      return res; 
    286 //                              } 
    287 // 
    288 //                              @Override 
    289 //                              protected void destroy(JButton res) { 
    290 //                                      // nothing 
    291 //                              } 
    292 // 
    293 //                              @Override 
    294 //                              protected void setup(JButton res) { 
    295 //                                      res.setMargin(new Insets(0, 0, 0, 0)); 
    296 //                              } 
    297 //                      } 
    298 //                      return getBean().makeProp(swingComponent.class); 
    299 //              } 
    300339        } 
    301340 
    302341        /** 
     
    312351                        part.add(SIZE_PROP_ID, new ImmSize(26, 26)); 
    313352                        part.add(ICON_PROP_ID, ImageUtil.loadIcon("minus.png")); 
    314353                } 
    315                  
     354 
    316355                @Override 
    317356                protected ImmList<EventR3> computeEvents() { 
    318357                        return ImmTreeList.create(new EventR3(this, null, null,null, LinkActionIds.REMOVE_RULE)); 
    319358                } 
    320  
    321 //              public Prop<JButton> swingComponent() { 
    322 //                      class swingComponent extends ResourceProperty<JButton> { 
    323 // 
    324 //                              @Override 
    325 //                              protected JButton create() { 
    326 //                                      JButton res =  
    327 //                                              new LogicR3Button("",  
    328 //                                                      ); 
    329 //                                      res.setName("emptyBackgroundButton"); 
    330 //                                       
    331 //                                      return res; 
    332 //                              } 
    333 // 
    334 //                              @Override 
    335 //                              protected void destroy(JButton res) { 
    336 //                                      // nothing 
    337 //                              } 
    338 // 
    339 //                              @Override 
    340 //                              protected void setup(JButton res) { 
    341 //                                       
    342 //                                      res.setToolTipText("Remove currently selected rule"); 
    343 //                                      res.setMargin(new Insets(0, 0, 0, 0)); 
    344 //                              } 
    345 //                      } 
    346 //                      return getBean().makeProp(swingComponent.class); 
    347 //              } 
     359                 
     360                @Override 
     361                protected boolean computeEnabled() { 
     362                        LinksHud hud = findParentElement(LinksHud.class); 
     363                        return hud != null && hud.currentRule().get() != null 
     364                                && hud.currentRule().get() != LinksHud.EMPTY_RULE; 
     365                } 
    348366        } 
    349367 
    350368        /** 
     
    352370         */ 
    353371        @VisualElementDef(parent = LinksHud.class, sortKey = "fff-configuration-panel") 
    354372        public static class ConfigPanel extends BaseSwingVisualElement { 
    355                  
     373 
    356374                @SkinPartDef 
    357375                @SuppressWarnings("unused") 
    358376                private static void initSkin(ElementSkinPart part) { 
     
    380398 
    381399                public Prop<JPanel> swingComponent() { 
    382400                        class swingComponent extends ResourceProperty<JPanel> { 
    383                                  
     401 
    384402                                private ActionConfigurationPanel currentPanel = null; 
    385403 
    386404                                @Override 
     
    455473                        @Override 
    456474                        protected void setup(Object res) { 
    457475                                holder().get(); 
    458                                 currentRule().set(null); 
     476                                wantedRule().set(null); 
    459477                        } 
    460478                } 
    461479                return getBean().makeProp(currentRuleSync.class); 
    462480        } 
    463481 
    464482        /** 
     483         * A special {@link LinkRule} denoting that a new rule should be created when the user selects a trigger. 
     484         */ 
     485        public static final LinkRule EMPTY_RULE = new LinkRule(null, null) { 
     486 
     487                @Override 
     488                public String toString() { 
     489                        String elemId = SkinUtil.getElementId(LinksHud.class); 
     490                        return SkinManager.get().currentSkin().get().getValue(elemId, EMPTY_RULE_TITLE_PROP_ID, String.class); 
     491                } 
     492        };  
     493 
     494        /** 
     495         * The rule that the user has explicitly set as the one to be edited. 
     496         *  
     497         * @return 
     498         *                      Property. 
     499         */ 
     500        public RwProp<LinkRule> wantedRule() { 
     501                return getBean().makeValueProp("wantedRule", LinkRule.class, null); 
     502        }  
     503 
     504        /** 
    465505         * The rule which is currently selected in the hud. 
    466506         *  
    467507         * @return the property 
    468508         */ 
    469         public RwProp<LinkRule> currentRule() { 
    470                 return getBean().makeValueProp("currentRule", LinkRule.class, null); 
     509        public Prop<LinkRule> currentRule() { 
     510                class currentRule extends AutoProperty<LinkRule> { 
     511 
     512                        @Override 
     513                        protected LinkRule compute() { 
     514                                if (wantedRule().get() != null) { 
     515                                        return wantedRule().get(); 
     516                                } 
     517 
     518                                LinkRule selected = null; 
     519                                if (holder().get() != null && holder().get().getLink() != null) { 
     520                                        ImmList<LinkRule> rules = holder().get().getLink().getRules(); 
     521                                        if (!rules.isEmpty()) { 
     522                                                selected = rules.get(rules.size() - 1); 
     523                                        } else { 
     524                                                selected = EMPTY_RULE; 
     525                                        } 
     526                                } 
     527                                return selected; 
     528                        } 
     529 
     530                } 
     531                return getBean().makeProp(currentRule.class); 
    471532        } 
    472533 
    473534        /** 
     
    477538         *              The {@link LinkHolder} to use. 
    478539         */ 
    479540        public abstract Prop<? extends LinkHolder> holder(); 
    480          
     541 
    481542        /** 
    482          *      The Ids of the events, fired by the "add" and "remove" buttons. 
     543         *      The Ids of the events, fired by LinksHud elements. 
    483544         */ 
    484545        public enum LinkActionIds { 
    485                 /** 
    486                  * A bew {@link LinkRule} should be added to the current link. 
    487                  */ 
    488                 @EventParams({}) 
    489                 ADD_RULE, 
    490                  
     546 
    491547                /** 
    492548                 * The currently selected {@link LinkRule} should be removed from the model.  
    493549                 */ 
  • modules/org.sophie2.main.func.links/src/main/java/org/sophie2/main/func/links/LinksUtil.java

     
    4545                LogicR3.fire(hud, null, null, null, EventIds.SET_LINK,  
    4646                                newLink, "Change link action settings"); 
    4747                 
    48                 hud.currentRule().set(newRule); 
     48                hud.wantedRule().set(newRule); 
    4949        } 
    5050 
    5151        /** 
  • modules/org.sophie2.main.func.links/src/main/java/org/sophie2/main/func/links/ElementLinksHud.java

     
    1616 */ 
    1717@SkinElementId("main.func.links.element-links-hud") 
    1818@RelatedChildren( {  
    19         LinksHud.CurrentRule.class, LinksHud.AddRule.class,  
    20         LinksHud.RemoveRule.class, LinksHud.AvailableTriggers.class,  
    21         LinksHud.AvailableActions.class, LinksHud.ConfigPanel.class, 
    22         LinksHud.LinksHudTitleBar.class}) 
     19        LinksHud.CurrentRule.class,  
     20        LinksHud.RemoveRule.class,  
     21        LinksHud.AvailableTriggers.class,  
     22        LinksHud.AvailableActions.class,  
     23        LinksHud.ConfigPanel.class, 
     24        LinksHud.LinksHudTitleBar.class 
     25        }) 
    2326@VisualElementDef(parent = ElementLinksHaloButton.class, sortKey = "kkk-element-links-hud") 
    2427public class ElementLinksHud extends LinksHud { 
    2528