Ticket #2427: 2427_all_in_one.patch

File 2427_all_in_one.patch, 64.4 KB (added by meddle, 15 years ago)

All in one patch

  • modules/org.sophie2.main.func.resources/src/test/java/org/sophie2/main/func/resources/imports/ResourceImportUtilTest.java

    ### Eclipse Workspace Patch 1.0
    #P sophie
     
    88 
    99import org.junit.Before; 
    1010import org.junit.Test; 
     11import org.sophie2.base.bound.BoundModule; 
    1112import org.sophie2.base.commons.BaseCommonsModule; 
    1213import org.sophie2.base.commons.util.position.ImmPoint; 
     14import org.sophie2.base.config.BaseConfigModule; 
    1315import org.sophie2.base.dialogs.BaseDialogsModule; 
    1416import org.sophie2.base.dialogs.TestingDialogManager; 
    1517import org.sophie2.base.dnd.DndData; 
     
    2830import org.sophie2.base.model.resources.r4.immutables.SubEntryNames; 
    2931import org.sophie2.base.model.resources.r4.resources.ResourceH; 
    3032import org.sophie2.base.model.resources.r4.resources.ResourceR4; 
     33import org.sophie2.base.persistence.BasePersistenceModule; 
    3134import org.sophie2.base.skins.BaseSkinsModule; 
    3235import org.sophie2.base.skins.Message; 
    3336import org.sophie2.base.visual.BaseVisualModule; 
     
    4144import org.sophie2.main.dialogs.input.file.FileDialogInput; 
    4245import org.sophie2.main.dialogs.input.file.FileFilterInfo; 
    4346import org.sophie2.main.func.file.FileFunctionalityModule; 
     47import org.sophie2.main.func.resources.actions.CreateColdTextAction; 
    4448import org.sophie2.main.func.resources.dummy.ColdTextData; 
    4549import org.sophie2.main.func.resources.dummy.ColdTextFrame; 
    4650import org.sophie2.main.func.resources.dummy.ColdTextImportManager; 
     
    117121        protected List<Class<? extends SophieModule>> fillDependencies() { 
    118122                return Arrays.asList(BaseModelResourcesR4Module.class, 
    119123                                BaseVisualModule.class, BaseMediaModule.class, 
    120                                 BaseCommonsModule.class, MainMediaNatlibModule.class, 
    121                                 BaseDialogsModule.class, BaseSkinsModule.class, 
    122                                 BaseModelBookModule.class, FileFunctionalityModule.class, 
    123                                 MainAppModule.class, 
     124                                BaseConfigModule.class, BasePersistenceModule.class, 
     125                                BaseCommonsModule.class, BoundModule.class,  
     126                                MainMediaNatlibModule.class, BaseDialogsModule.class,  
     127                                BaseSkinsModule.class, BaseModelBookModule.class,  
     128                                FileFunctionalityModule.class, MainAppModule.class, 
    124129                                ColdTextModule.class); 
    125130        } 
    126131         
     
    275280                        ResourceRefR4.generateRandomSub(ColdTextResource.DEFAULT_TITLE); 
    276281                final String text = "My text"; 
    277282                 
    278                 new AutoAction(Message.create(CREATING_COLD_TEXT), true) { 
    279                         @Override 
    280                         public void performAuto() { 
    281                                 ColdTextResourceHelper.createColdText(getChanger(), 
    282                                                 coldRef, text); 
    283                          
    284                         } 
    285                 }.register(bookAccess); 
     283                Message description = Message.create(CREATING_COLD_TEXT); 
     284                AutoAction action = new CreateColdTextAction(description, true, text, coldRef); 
     285                action.register(bookAccess); 
    286286                 
    287287                // text and page: 
    288288                assertEquals(2, book.getChildren().size()); 
  • modules/org.sophie2.extra.func.annotations/src/main/java/org/sophie2/extra/func/annotations/actions/DeleteStickyAction.java

     
     1package org.sophie2.extra.func.annotations.actions; 
     2 
     3import org.sophie2.base.commons.util.ImmList; 
     4import org.sophie2.base.model.book.interfaces.CompositeElement; 
     5import org.sophie2.base.model.book.timelines.ActivationChannel; 
     6import org.sophie2.base.model.resources.r4.ResourceRefR4; 
     7import org.sophie2.base.model.resources.r4.changes.AutoAction; 
     8import org.sophie2.base.skins.Message; 
     9 
     10/** 
     11 * {@link AutoAction} that deletes a sticky. 
     12 *  
     13 * @author mitex 
     14 */ 
     15public class DeleteStickyAction extends AutoAction { 
     16         
     17        private final ImmList<ActivationChannel> channels; 
     18        private final ActivationChannel channel; 
     19        private final ResourceRefR4 stickyRef; 
     20 
     21        /** 
     22         * Creates the action with all the needed data to remove the sticky. 
     23         *  
     24         * @param description  
     25         *                      Description of the action.  
     26         * @param significant  
     27         *                      Significance of the action.  
     28         * @param channels 
     29         *                      The channels of the page extra containing the sticky. 
     30         * @param channel 
     31         *                      The exact channel corresponding to the sticky. 
     32         * @param stickyRef 
     33         *                      The {@link ResourceRefR4} to the sticky. 
     34         */ 
     35        public DeleteStickyAction(Message description, boolean significant, 
     36                        ImmList<ActivationChannel> channels, ActivationChannel channel, 
     37                        ResourceRefR4 stickyRef) { 
     38                super(description, significant); 
     39                 
     40                this.channels = channels; 
     41                this.channel = channel; 
     42                this.stickyRef = stickyRef; 
     43        } 
     44 
     45        @Override 
     46        public void performAuto() { 
     47                getChanger().removeResource(this.stickyRef); 
     48                getChanger().setRaw( 
     49                                CompositeElement.KEY_SUB_ELEMENTS, this.channels.remove(this.channel)); 
     50        } 
     51} 
  • modules/org.sophie2.main.func.resources/src/test/java/org/sophie2/main/func/resources/imports/ResourceImportManagerTest.java

     
    66 
    77import org.junit.Before; 
    88import org.junit.Test; 
     9import org.sophie2.base.bound.BoundModule; 
    910import org.sophie2.base.commons.BaseCommonsModule; 
    1011import org.sophie2.base.commons.structures.ImmTreeList; 
    1112import org.sophie2.base.commons.util.ImmList; 
    12 import org.sophie2.base.commons.util.position.ImmPoint; 
     13import org.sophie2.base.config.BaseConfigModule; 
    1314import org.sophie2.base.dialogs.BaseDialogsModule; 
    1415import org.sophie2.base.dialogs.TestingDialogManager; 
    1516import org.sophie2.base.media.BaseMediaModule; 
    1617import org.sophie2.base.model.book.BaseModelBookModule; 
    1718import org.sophie2.base.model.book.FrameH; 
    18 import org.sophie2.base.model.book.frame.FrameR4; 
    1919import org.sophie2.base.model.book.interfaces.ResourceFrame; 
    2020import org.sophie2.base.model.book.resource.r4.BookR4; 
    2121import org.sophie2.base.model.book.timelines.ActivationChannel; 
     
    2828import org.sophie2.base.model.resources.r4.keys.ChildrenKey; 
    2929import org.sophie2.base.model.resources.r4.keys.TemplatedKey; 
    3030import org.sophie2.base.model.resources.r4.resources.ResourceR4; 
     31import org.sophie2.base.persistence.BasePersistenceModule; 
    3132import org.sophie2.base.skins.BaseSkinsModule; 
    3233import org.sophie2.base.skins.Message; 
    3334import org.sophie2.base.visual.BaseVisualModule; 
     
    4041import org.sophie2.main.dialogs.input.file.FileDialogInput; 
    4142import org.sophie2.main.dialogs.input.file.FileFilterInfo; 
    4243import org.sophie2.main.func.file.FileFunctionalityModule; 
     44import org.sophie2.main.func.resources.actions.CreateColdTextAction; 
     45import org.sophie2.main.func.resources.actions.InsertTextFrameAction; 
    4346import org.sophie2.main.func.resources.dummy.ColdTextImportManager; 
    4447import org.sophie2.main.func.resources.dummy.ColdTextModule; 
    4548import org.sophie2.main.func.resources.dummy.ColdTextResource; 
     
    8083        protected List<Class<? extends SophieModule>> fillDependencies() { 
    8184                return Arrays.asList(BaseModelResourcesR4Module.class, 
    8285                                BaseVisualModule.class, BaseMediaModule.class, 
     86                                BaseConfigModule.class, BasePersistenceModule.class, 
    8387                                BaseCommonsModule.class, MainMediaNatlibModule.class, 
    84                                 BaseDialogsModule.class, BaseSkinsModule.class, 
     88                                BaseDialogsModule.class, BoundModule.class, BaseSkinsModule.class, 
    8589                                BaseModelBookModule.class, FileFunctionalityModule.class, 
    8690                                MainAppModule.class, 
    8791                                ColdTextModule.class); 
     
    183187                        ResourceRefR4.generateRandomSub(ColdTextResource.DEFAULT_TITLE); 
    184188                final String text = "Some text"; 
    185189                 
    186                 new AutoAction(Message.create(CREATING_COLD_TEXT), true) { 
    187                         @Override 
    188                         public void performAuto() { 
    189                                 ColdTextResourceHelper.createColdText( 
    190                                                 getChanger(), coldRef, text); 
    191                         } 
    192                 }.register(bookAccess); 
     190                Message description = Message.create(CREATING_COLD_TEXT); 
     191                AutoAction action = new CreateColdTextAction(description, true, text, coldRef); 
     192                action.register(bookAccess); 
    193193                 
    194194                SubEntryNames children = ResourceR4.KEY_CHILDREN.get(bookAccess); 
    195195                 
     
    207207                        ResourceRefR4.generateRandomSub(FrameH.NAME_PREFIX); 
    208208                final ImmList<ActivationChannel> elements = ImmTreeList.empty(); 
    209209                 
    210                 new AutoAction(Message.create(INSERT_THE_FRAME), true) { 
    211                         @Override 
    212                         public void performAuto() { 
    213                                 manager.insertFrame(getChanger().getSub(parentRef), 
    214                                                 parentRef, frameRef, coldRef, 
    215                                                 "Bau", elements, 
    216                                                 ImmPoint.ZERO, 
    217                                                 FrameR4.DEFAULT_FRAME_SIZE); 
    218                         } 
    219                          
    220                 }.register(bookAccess); 
     210                description = Message.create(INSERT_THE_FRAME); 
     211                action = new InsertTextFrameAction(description, true, manager, frameRef, 
     212                                parentRef, elements, coldRef); 
     213                action.register(bookAccess); 
    221214                 
    222215                ChildrenKey pageChildrenKey =  
    223216                        ResourceR4.KEY_CHILDREN.sub(parentRef).sub(ResourceR4.KEY_CHILDREN); 
  • modules/org.sophie2.main.func.resources/src/main/java/org/sophie2/main/func/resources/logic/ResourceDeleteLogic.java

     
    2323import org.sophie2.main.app.commons.util.AppViewUtil; 
    2424import org.sophie2.main.dialogs.input.ConfirmDialogInput; 
    2525import org.sophie2.main.dialogs.input.DialogUtils; 
     26import org.sophie2.main.func.resources.actions.RemoveResourceAction; 
     27import org.sophie2.main.func.resources.actions.RemoveTemplateAction; 
    2628import org.sophie2.main.func.resources.view.ResourceDetailsPalette; 
    2729import org.sophie2.main.func.resources.view.ResourceDetailsPalette.DeleteResourceButton; 
    2830import org.sophie2.main.func.resources.view.ResourcesPalette.ResourceItem; 
     
    8385                        return true; 
    8486                } 
    8587        }; 
    86          
     88 
    8789        /** 
    8890         * Constant created for removing template. 
    8991         * Constant created to be a parameter of a message of an {@link AutoAction}.  
     
    121123 
    122124                final ResourceRefR4 resourceRef = ResourceRefR4.getRelativeRef( 
    123125                                bookAccess.getRef(), resource.getRef()); 
    124                 new AutoAction(Message.create(REMOVE_RESOURCE), true) { 
    125                         @Override 
    126                         public void performAuto() { 
    127                                 getChanger().removeResource(resourceRef); 
    128                         } 
    129  
    130                 }.register(bookAccess); 
     126                 
     127                Message description = Message.create(REMOVE_RESOURCE); 
     128                AutoAction action = new RemoveResourceAction(description, true, resourceRef); 
     129                action.register(bookAccess); 
    131130 
    132131                return true; 
    133132        } 
     
    205204                ResourceAccess bookAccess = bookView.getAccess(); 
    206205                final ResourceRefList templates = key.get(bookAccess); 
    207206                if (templates.contains(ref)) { 
    208                         new AutoAction(Message.create(REMOVE_TEMPLATE), true) { 
    209                                 @Override 
    210                                 public void performAuto() { 
    211                                         getChanger().removeResource(ref); 
    212                                         getChanger().setRaw(key, templates.remove(ref)); 
    213                                 } 
    214  
    215                         }.register(bookAccess); 
     207                        Message description = Message.create(REMOVE_TEMPLATE); 
     208                        AutoAction action = new RemoveTemplateAction(description, true, templates, key, ref); 
     209                        action.register(bookAccess); 
    216210                         
    217211                        return true; 
    218212                } 
  • modules/org.sophie2.main.func.resources/src/test/java/org/sophie2/main/func/resources/actions/InsertTextFrameAction.java

     
     1package org.sophie2.main.func.resources.actions; 
     2 
     3import org.sophie2.base.commons.util.ImmList; 
     4import org.sophie2.base.commons.util.position.ImmPoint; 
     5import org.sophie2.base.model.book.frame.FrameR4; 
     6import org.sophie2.base.model.book.timelines.ActivationChannel; 
     7import org.sophie2.base.model.resources.r4.ResourceRefR4; 
     8import org.sophie2.base.model.resources.r4.changes.AutoAction; 
     9import org.sophie2.base.skins.Message; 
     10import org.sophie2.main.func.resources.dummy.ColdTextImportManager; 
     11 
     12/** 
     13 * {@link AutoAction} for inserting test frame with text. 
     14 *  
     15 * @author meddle 
     16 */ 
     17public class InsertTextFrameAction extends AutoAction { 
     18         
     19        private final ColdTextImportManager manager; 
     20        private final ResourceRefR4 frameRef; 
     21        private final ResourceRefR4 parentRef; 
     22        private final ImmList<ActivationChannel> elements; 
     23        private final ResourceRefR4 coldRef; 
     24 
     25        /** 
     26         * Creates the action with all needed information to insert the frame. 
     27         *  
     28         * @param description  
     29         *                      Description of the action.  
     30         * @param significant  
     31         *                      Significance of the action. 
     32         * @param manager 
     33         *                      The import manager to insert the frame. 
     34         * @param frameRef 
     35         *                      The reference to the frame. 
     36         * @param parentRef 
     37         *                      The parent of the frame. 
     38         * @param elements 
     39         *                      The current elements of the parent element. 
     40         * @param coldRef 
     41         *                      The reference to the main resource of the frame to insert 
     42         */ 
     43        public InsertTextFrameAction(Message description, boolean significant, 
     44                        ColdTextImportManager manager, ResourceRefR4 frameRef, 
     45                        ResourceRefR4 parentRef, ImmList<ActivationChannel> elements, 
     46                        ResourceRefR4 coldRef) { 
     47                super(description, significant); 
     48                 
     49                this.manager = manager; 
     50                this.frameRef = frameRef; 
     51                this.parentRef = parentRef; 
     52                this.elements = elements; 
     53                this.coldRef = coldRef; 
     54        } 
     55 
     56        @Override 
     57        public void performAuto() { 
     58                this.manager.insertFrame(getChanger().getSub(this.parentRef), 
     59                                this.parentRef, this.frameRef, this.coldRef, 
     60                                "Bau", this.elements, 
     61                                ImmPoint.ZERO, 
     62                                FrameR4.DEFAULT_FRAME_SIZE); 
     63        } 
     64} 
  • modules/org.sophie2.extra.func.annotations/src/main/java/org/sophie2/extra/func/annotations/actions/CreateStickyInExtraAction.java

     
     1package org.sophie2.extra.func.annotations.actions; 
     2 
     3import org.sophie2.base.commons.util.ImmList; 
     4import org.sophie2.base.commons.util.NaiveImmList; 
     5import org.sophie2.base.commons.util.position.ImmPoint; 
     6import org.sophie2.base.model.book.PageExtraH; 
     7import org.sophie2.base.model.book.resource.r4.PageExtraR4; 
     8import org.sophie2.base.model.book.timelines.ActivationChannel; 
     9import org.sophie2.base.model.resources.r4.ResourceRefList; 
     10import org.sophie2.base.model.resources.r4.ResourceRefR4; 
     11import org.sophie2.base.model.resources.r4.changes.AutoAction; 
     12import org.sophie2.base.skins.Message; 
     13import org.sophie2.extra.func.annotations.model.StickyH; 
     14 
     15/** 
     16 * {@link AutoAction} for creating a sticky in a {@link PageExtraR4}. 
     17 *  
     18 * @author mitex 
     19 */ 
     20public class CreateStickyInExtraAction extends AutoAction { 
     21         
     22        private final String textTitle; 
     23        private final ResourceRefR4 curPageRef; 
     24        private final ResourceRefR4 pageExtraRef; 
     25        private final ImmList<ActivationChannel> channels; 
     26        private final ResourceRefList pageExtras; 
     27        private final ImmPoint location; 
     28 
     29        /** 
     30         * Constructs the action with all the needed data for creation of page extra with sticky. 
     31         *  
     32         * @param description  
     33         *                      Description of the action.  
     34         * @param significant  
     35         *                      Significance of the action.  
     36         * @param textTitle 
     37         *                      Title of the new sticky. 
     38         * @param curPageRef 
     39         *                      Reference to the current page. 
     40         * @param pageExtraRef 
     41         *                      Reference to the {@link PageExtraR4} to be created. 
     42         * @param channels 
     43         *                      The channels of the current page. 
     44         * @param pageExtras 
     45         *                      The page extras of the current page. 
     46         * @param location 
     47         *                      The location of the sticky. 
     48         */ 
     49        public CreateStickyInExtraAction(Message description, 
     50                        boolean significant, String textTitle, 
     51                        ResourceRefR4 curPageRef, ResourceRefR4 pageExtraRef, 
     52                        ImmList<ActivationChannel> channels, 
     53                        ResourceRefList pageExtras, ImmPoint location) { 
     54                super(description, significant); 
     55                 
     56                this.textTitle = textTitle; 
     57                this.curPageRef = curPageRef; 
     58                this.pageExtraRef = pageExtraRef; 
     59                this.channels = channels; 
     60                this.pageExtras = pageExtras; 
     61                this.location = location; 
     62        } 
     63 
     64        @Override 
     65        public void performAuto() {  
     66                PageExtraH.create(getChanger(), this.pageExtraRef, 
     67                                this.curPageRef, this.channels, this.pageExtras); 
     68 
     69                StickyH.create(getChanger().getSub(this.pageExtraRef), this.textTitle, 
     70                                this.location, NaiveImmList.<ActivationChannel>getEmpty()); 
     71        } 
     72} 
     73 
  • modules/org.sophie2.main.func.resources/src/test/java/org/sophie2/main/func/resources/SophiePackageFormatTest.java

     
    22 
    33import java.io.File; 
    44import java.net.URL; 
     5import java.util.Arrays; 
    56import java.util.Collection; 
    67import java.util.Collections; 
    78import java.util.List; 
     
    1112import org.junit.Test; 
    1213import org.sophie2.base.commons.util.bindata.BinData; 
    1314import org.sophie2.base.commons.util.bindata.RawBinData; 
     15import org.sophie2.base.config.BaseConfigModule; 
    1416import org.sophie2.base.model.book.BaseModelBookModule; 
    1517import org.sophie2.base.model.book.BookH; 
    1618import org.sophie2.base.model.book.resource.r4.BookR4; 
    1719import org.sophie2.base.model.book.testing.ModelTestBase; 
     20import org.sophie2.base.model.resources.r4.BaseModelResourcesR4Module; 
    1821import org.sophie2.base.model.resources.r4.ResourceRefR4; 
    1922import org.sophie2.base.model.resources.r4.access.ResourceAccess; 
    2023import org.sophie2.base.model.resources.r4.immutables.SubEntryNames; 
     
    5053 
    5154        private File exportOtputFile = null; 
    5255 
     56        @SuppressWarnings("unchecked") 
    5357        @Override 
    5458        protected List<Class<? extends SophieModule>> fillDependencies() { 
    55                 List<Class<? extends SophieModule>> modules = super.fillDependencies();  
    56  
    57                 modules.add(CoreModularityModule.class); 
    58                 modules.add(BasePersistenceModule.class); 
    59                 modules.add(BaseModelBookModule.class); 
    60                 modules.add(MainFuncResourcesModule.class); 
    61  
    62                 return modules; 
    63         } 
     59                return Arrays.asList( 
     60                                CoreModularityModule.class, 
     61                                BaseConfigModule.class, 
     62                                BasePersistenceModule.class, 
     63                                BaseModelResourcesR4Module.class, 
     64                                BaseModelBookModule.class, 
     65                                MainFuncResourcesModule.class);  
     66                } 
    6467 
    6568        @Override 
    6669        @Before 
  • modules/org.sophie2.main.func.resources/src/main/java/org/sophie2/main/func/resources/actions/RemoveTemplateAction.java

     
     1package org.sophie2.main.func.resources.actions; 
     2 
     3import org.sophie2.base.model.resources.r4.ResourceRefList; 
     4import org.sophie2.base.model.resources.r4.ResourceRefR4; 
     5import org.sophie2.base.model.resources.r4.changes.AutoAction; 
     6import org.sophie2.base.model.resources.r4.keys.Key; 
     7import org.sophie2.base.skins.Message; 
     8 
     9/** 
     10 * {@link AutoAction} for removing a template. 
     11 *  
     12 * @author diana 
     13 */ 
     14public class RemoveTemplateAction extends AutoAction { 
     15         
     16        private final ResourceRefList templates; 
     17        private final Key<ResourceRefList> key; 
     18        private final ResourceRefR4 ref; 
     19 
     20        /** 
     21         * Creates the action with all the needed data for template removal. 
     22         *  
     23         * @param description  
     24         *                      Description of the action.  
     25         * @param significant  
     26         *                      Significance of the action. 
     27         * @param templates 
     28         *                      The current list with the templates. 
     29         * @param key 
     30         *                      The key containing the templates. 
     31         * @param ref 
     32         *                      The reference to the template to remove. 
     33         */ 
     34        public RemoveTemplateAction(Message description, boolean significant, 
     35                        ResourceRefList templates, Key<ResourceRefList> key, 
     36                        ResourceRefR4 ref) { 
     37                super(description, significant); 
     38                 
     39                this.templates = templates; 
     40                this.key = key; 
     41                this.ref = ref; 
     42        } 
     43 
     44        @Override 
     45        public void performAuto() { 
     46                getChanger().removeResource(this.ref); 
     47                getChanger().setRaw(this.key, this.templates.remove(this.ref)); 
     48        } 
     49} 
  • modules/org.sophie2.main.func.resources/src/main/java/org/sophie2/main/func/resources/actions/InsertFrameAction.java

     
     1package org.sophie2.main.func.resources.actions; 
     2 
     3import org.sophie2.base.commons.util.ImmList; 
     4import org.sophie2.base.commons.util.position.ImmPoint; 
     5import org.sophie2.base.commons.util.position.ImmSize; 
     6import org.sophie2.base.model.book.timelines.ActivationChannel; 
     7import org.sophie2.base.model.resources.r4.ResourceRefR4; 
     8import org.sophie2.base.model.resources.r4.changes.AutoAction; 
     9import org.sophie2.base.model.resources.r4.changes.ResourceChanger; 
     10import org.sophie2.base.skins.Message; 
     11import org.sophie2.main.func.resources.imports.ResourceImportInfo; 
     12import org.sophie2.main.func.resources.imports.ResourceImportManager; 
     13 
     14/** 
     15 * {@link AutoAction} for inserting a frame for given resource. 
     16 * It makes resource if the resource is not created and inserts frame for it. 
     17 *  
     18 * @author meddle 
     19 * 
     20 * @param <D> 
     21 *                              The type of the resource data to insert frame for. 
     22 */ 
     23public class InsertFrameAction<D> extends AutoAction { 
     24         
     25        private final ResourceImportInfo<D> importInfo; 
     26        private final ResourceRefR4 frameRef; 
     27        private final ImmPoint pos; 
     28        private final ImmSize frameSize; 
     29        private final ImmList<ActivationChannel> elements; 
     30        private final ResourceRefR4 parentRef; 
     31        private final ResourceImportManager<D> importManager; 
     32        private final boolean linked; 
     33        private final ResourceRefR4 resourceRef; 
     34        private final String frameTitle; 
     35 
     36        /** 
     37         * Creates the action with all needed data to insert a frame for a resource. 
     38         *  
     39         * @param description  
     40         *                      Description of the action.  
     41         * @param significant  
     42         *                      Significance of the action.  
     43         * @param importInfo 
     44         *                      The {@link ResourceImportInfo} needed for the resource contained 
     45         *                      in the frame. 
     46         * @param frameRef 
     47         *                      The {@link ResourceRefR4} for the new frame. 
     48         * @param pos 
     49         *                      The position of the new frame. 
     50         * @param frameSize 
     51         *                      The size of the new frame. 
     52         * @param elements 
     53         *                      The current sub-elements of the parent element of the new frame. 
     54         * @param parentRef 
     55         *                      The {@link ResourceRefR4} pointing to the parent of the new frame. 
     56         * @param importManager 
     57         *                      The {@link ResourceImportManager} responsible for creating resource 
     58         *                      for the frame and creating the frame. 
     59         * @param linked 
     60         *                      If the resource in the frame is linked (i.e. already created). 
     61         * @param resourceRef 
     62         *                      The reference to the resource the new frame shows. 
     63         * @param frameTitle 
     64         *                      The title of the new frame. 
     65         */ 
     66        public InsertFrameAction(Message description, boolean significant, 
     67                        ResourceImportInfo<D> importInfo, ResourceRefR4 frameRef, 
     68                        ImmPoint pos, ImmSize frameSize, 
     69                        ImmList<ActivationChannel> elements, ResourceRefR4 parentRef, 
     70                        ResourceImportManager<D> importManager, boolean linked, 
     71                        ResourceRefR4 resourceRef, String frameTitle) { 
     72                super(description, significant); 
     73                 
     74                this.importInfo = importInfo; 
     75                this.frameRef = frameRef; 
     76                this.pos = pos; 
     77                this.frameSize = frameSize; 
     78                this.elements = elements; 
     79                this.parentRef = parentRef; 
     80                this.importManager = importManager; 
     81                this.linked = linked; 
     82                this.resourceRef = resourceRef; 
     83                this.frameTitle = frameTitle; 
     84        } 
     85 
     86        @Override 
     87        public void performAuto() { 
     88                ResourceChanger changer = getChanger(); 
     89                if (!this.linked) { 
     90                        this.importManager.makeResource(changer, this.resourceRef, this.importInfo); 
     91                } 
     92 
     93                this.importManager.insertFrame(changer.getSub(this.parentRef), 
     94                                this.parentRef, this.frameRef, this.resourceRef, this.frameTitle, 
     95                                this.elements, this.pos, this.frameSize); 
     96 
     97        } 
     98} 
  • modules/org.sophie2.main.func.resources/src/main/java/org/sophie2/main/func/resources/actions/RemoveResourceAction.java

     
     1package org.sophie2.main.func.resources.actions; 
     2 
     3import org.sophie2.base.model.resources.r4.ResourceRefR4; 
     4import org.sophie2.base.model.resources.r4.changes.AutoAction; 
     5import org.sophie2.base.skins.Message; 
     6 
     7/** 
     8 * {@link AutoAction} for deleting a resource. 
     9 *  
     10 * @author diana 
     11 */ 
     12public class RemoveResourceAction extends AutoAction { 
     13         
     14        private final ResourceRefR4 resourceRef; 
     15 
     16        /** 
     17         * Creates the action with the reference to the resource to delete. 
     18         *  
     19         * @param description  
     20         *                      Description of the action.  
     21         * @param significant  
     22         *                      Significance of the action.  
     23         * @param resourceRef 
     24         *                      {@link ResourceRefR4} pointing to the resource to delete. 
     25         */ 
     26        public RemoveResourceAction(Message description, boolean significant, 
     27                        ResourceRefR4 resourceRef) { 
     28                super(description, significant); 
     29                 
     30                this.resourceRef = resourceRef; 
     31        } 
     32 
     33        @Override 
     34        public void performAuto() { 
     35                getChanger().removeResource(this.resourceRef); 
     36        } 
     37} 
  • modules/org.sophie2.main.func.resources/src/main/java/org/sophie2/main/func/resources/actions/ApplyTemplateAction.java

     
     1package org.sophie2.main.func.resources.actions; 
     2 
     3import org.sophie2.base.commons.util.NaiveImmList; 
     4import org.sophie2.base.model.resources.r4.ResourceRefR4; 
     5import org.sophie2.base.model.resources.r4.changes.AutoAction; 
     6import org.sophie2.base.model.resources.r4.keys.TemplatedKey; 
     7import org.sophie2.base.skins.Message; 
     8import org.sophie2.main.app.commons.util.TemplateUtil; 
     9 
     10/** 
     11 * {@link AutoAction} for applying a template to a resource. 
     12 *  
     13 * @author deni 
     14 */ 
     15public class ApplyTemplateAction extends AutoAction { 
     16         
     17        private final NaiveImmList<TemplatedKey<?>> immKeys; 
     18        private final ResourceRefR4 templateRef; 
     19        private final String kind; 
     20 
     21        /** 
     22         * Creates the action with all the needed information for applying a 
     23         * template to a resource. 
     24         *  
     25         * @param description  
     26         *                      Description of the action.  
     27         * @param significant  
     28         *                      Significance of the action.  
     29         * @param immKeys 
     30         *                      The templated keys of the resource. 
     31         * @param templateRef 
     32         *                      The reference to the template to apply. 
     33         * @param kind 
     34         *                      The kind of the template. 
     35         */ 
     36        public ApplyTemplateAction(Message description, boolean significant, 
     37                        NaiveImmList<TemplatedKey<?>> immKeys, 
     38                        ResourceRefR4 templateRef, String kind) { 
     39                super(description, significant); 
     40                 
     41                this.immKeys = immKeys; 
     42                this.templateRef = templateRef; 
     43                this.kind = kind; 
     44        } 
     45 
     46        @Override 
     47        public void performAuto() { 
     48                TemplateUtil.applyFrameTemplate(getChanger(),  
     49                                this.immKeys.asList(),  
     50                                this.templateRef, false, this.kind, true); 
     51 
     52        } 
     53} 
  • modules/org.sophie2.extra.func.annotations/src/main/java/org/sophie2/extra/func/annotations/actions/MoveStickyAction.java

     
     1package org.sophie2.extra.func.annotations.actions; 
     2 
     3import org.sophie2.base.commons.util.position.ImmPoint; 
     4import org.sophie2.base.model.book.interfaces.MemberElement; 
     5import org.sophie2.base.model.book.timelines.LocationChannel; 
     6import org.sophie2.base.model.resources.r4.changes.AutoAction; 
     7import org.sophie2.base.skins.Message; 
     8import org.sophie2.extra.func.annotations.model.StickyR4; 
     9 
     10/** 
     11 * {@link AutoAction} that moves a {@link StickyR4} from given location 
     12 * to another location. 
     13 *  
     14 * @author mitex 
     15 */ 
     16public class MoveStickyAction extends AutoAction { 
     17         
     18        private final LocationChannel locationChannel; 
     19        private final ImmPoint newlocation; 
     20 
     21        /** 
     22         * Crates the action with the {@link LocationChannel} of the sticky and its new 
     23         * location. 
     24         *  
     25         * @param description  
     26         *                      Description of the action. 
     27         * @param significant  
     28         *                      Significance of the action. 
     29         * @param locationChannel 
     30         *                      The {@link LocationChannel} of the sticky to move. 
     31         * @param newlocation 
     32         *                      The new location. 
     33         */ 
     34        public MoveStickyAction(Message description, boolean significant, 
     35                        LocationChannel locationChannel, ImmPoint newlocation) { 
     36                super(description, significant); 
     37                 
     38                this.locationChannel = locationChannel; 
     39                this.newlocation = newlocation; 
     40        } 
     41 
     42        @Override 
     43        public void performAuto() { 
     44                getChanger().setRaw(MemberElement.KEY_LOCATION, 
     45                                this.locationChannel.setAll(this.newlocation)); 
     46        } 
     47} 
     48 No newline at end of file 
  • modules/org.sophie2.extra.func.annotations/src/main/java/org/sophie2/extra/func/annotations/view/halos/StickyMoveHaloButton.java

     
    1616import org.sophie2.base.skins.Message; 
    1717import org.sophie2.base.skins.SkinElementId; 
    1818import org.sophie2.base.visual.skins.VisualElementDef; 
     19import org.sophie2.extra.func.annotations.actions.MoveStickyAction; 
    1920import org.sophie2.extra.func.annotations.view.StickyView; 
    2021import org.sophie2.main.app.commons.page.PageWorkArea; 
    2122import org.sophie2.main.app.halos.page.element.PageElementMoveHaloButton; 
     
    6869                                final ImmPoint newlocation =  
    6970                                        MemberElement.KEY_LOCATION.get(access).getValue(time); 
    7071 
    71                                 new AutoAction(Message.create(STICKY_MOVED), true) { 
    72  
    73                                         @Override 
    74                                         public void performAuto() { 
    75                                                 getChanger().setRaw(MemberElement.KEY_LOCATION, 
    76                                                                 locationChannel.setAll(newlocation)); 
    77                                         } 
    78                                 }.register(access); 
     72                                Message description = Message.create(STICKY_MOVED); 
     73                                AutoAction action = new MoveStickyAction(description, true, locationChannel, 
     74                                                newlocation); 
     75                                action.register(access); 
    7976 
    8077                        } 
    8178 
     
    8481                                ImmSize offset = sceneToParent.transform(new ImmPoint(newX, newY)).minus(zero);  
    8582                                final ImmPoint newLocation = oldLocation.plus(offset);  
    8683 
    87                                 new AutoAction(Message.create(STICKY_IS_MOVING), false) { 
    88  
    89                                         @Override 
    90                                         public void performAuto() { 
    91                                                 getChanger().setRaw(MemberElement.KEY_LOCATION, 
    92                                                                 locationChannel.setAll(newLocation)); 
    93                                         } 
    94                                 }.register(access); 
     84                                Message description = Message.create(STICKY_IS_MOVING); 
     85                                AutoAction action = new MoveStickyAction(description, false,  
     86                                                locationChannel, newLocation);                           
     87                                action.register(access); 
    9588                        } 
    9689 
    9790                        @Override 
  • modules/org.sophie2.main.func.resources/src/main/java/org/sophie2/main/func/resources/actions/SetFrameResourceAction.java

     
     1package org.sophie2.main.func.resources.actions; 
     2 
     3import org.sophie2.base.model.book.interfaces.ResourceFrame; 
     4import org.sophie2.base.model.resources.r4.ResourceRefR4; 
     5import org.sophie2.base.model.resources.r4.changes.AutoAction; 
     6import org.sophie2.base.model.resources.r4.resources.ResourceR4; 
     7import org.sophie2.base.skins.Message; 
     8 
     9/** 
     10 * {@link AutoAction} for changing the main resource of a frame. 
     11 *  
     12 * @author deni 
     13 */ 
     14public class SetFrameResourceAction extends AutoAction { 
     15         
     16        private final ResourceRefR4 relRef; 
     17        private final String newFrameKind; 
     18 
     19        /** 
     20         * Creates the action with a relative {@link ResourceRefR4} from the frame to 
     21         * the new main resource and new kind of the frame, corresponding to the resource. 
     22         *  
     23         * @param description  
     24         *                      Description of the action.  
     25         * @param significant  
     26         *                      Significance of the action.  
     27         * @param relRef 
     28         *                      Reference from the frame to the new main resource. 
     29         * @param newFrameKind 
     30         *                      The new frame kind, according to the new main resource. 
     31         */ 
     32        public SetFrameResourceAction(Message description, boolean significant, 
     33                        ResourceRefR4 relRef, String newFrameKind) { 
     34                super(description, significant); 
     35                 
     36                this.relRef = relRef; 
     37                this.newFrameKind = newFrameKind; 
     38        } 
     39 
     40        @Override 
     41        public void performAuto() { 
     42                getChanger().setRaw(ResourceR4.KEY_KIND, this.newFrameKind); 
     43                getChanger().setRaw(ResourceFrame.KEY_MAIN_RESOURCE, this.relRef); 
     44        } 
     45} 
  • modules/org.sophie2.main.func.resources/src/main/java/org/sophie2/main/func/resources/imports/ResourceImportUtil.java

     
    3030import org.sophie2.base.model.resources.r4.ResourceUtil; 
    3131import org.sophie2.base.model.resources.r4.access.ResourceAccess; 
    3232import org.sophie2.base.model.resources.r4.changes.AutoAction; 
    33 import org.sophie2.base.model.resources.r4.changes.ResourceChanger; 
    3433import org.sophie2.base.model.resources.r4.keys.TemplatedKey; 
    3534import org.sophie2.base.model.resources.r4.model.ResourceModel; 
    3635import org.sophie2.base.model.resources.r4.resources.ResourceH; 
    3736import org.sophie2.base.model.resources.r4.resources.ResourceR4; 
    3837import org.sophie2.base.skins.Message; 
    3938import org.sophie2.core.logging.SophieLog; 
    40 import org.sophie2.main.app.commons.util.TemplateUtil; 
    4139import org.sophie2.main.dialogs.input.DialogUtils; 
    4240import org.sophie2.main.dialogs.input.MessageDialogInput; 
    4341import org.sophie2.main.dialogs.input.MessageDialogInput.MessageType; 
    4442import org.sophie2.main.dialogs.input.file.FileDialogInput; 
     43import org.sophie2.main.func.resources.actions.ApplyTemplateAction; 
     44import org.sophie2.main.func.resources.actions.ImportResourceAction; 
     45import org.sophie2.main.func.resources.actions.InsertFrameAction; 
    4546import org.sophie2.main.func.resources.imports.bindata.ResourceImportType; 
    4647 
    4748/** 
     
    9495                        new ResourceImportInfo<D>(data, resFile.getName(), resFile.toURI(), 
    9596                                        ResourceImportType.EMBED); 
    9697 
    97                 // The description must be smarter... May be with skins --meddle 2009-10-21 
    98                 new AutoAction(Message.create(IMPORT_RES, importInfo.getName()), true) { 
    99                         @Override 
    100                         public void performAuto() { 
    101                                 ResourceChanger changer = getChanger(); 
    102  
    103                                 importManager.makeResource(changer, resourceRef, importInfo); 
    104  
    105                         } 
    106                 }.register(book.getAccess()); 
     98                Message description = Message.create(IMPORT_RES, importInfo.getName()); 
     99                ImportResourceAction<D> action = new ImportResourceAction<D>( 
     100                                description, true, importInfo, resourceRef, importManager); 
     101                action.register(book.getAccess()); 
    107102 
    108103                return resourceRef; 
    109104        }        
     
    135130                final ResourceImportInfo importInfo = new ResourceImportInfo(data, title); 
    136131                final ResourceRefR4 childRef = importManager.generateChildRef(); 
    137132                 
    138                 new AutoAction(Message.create(IMPORT_RES, importInfo.getName()), significant) { 
    139                         @Override 
    140                         public void performAuto() { 
    141  
    142                                 importManager.makeResource(getChanger(), childRef, importInfo); 
    143  
    144                         } 
    145                 }.register(book.getAccess()); 
     133                Message description = Message.create(IMPORT_RES, importInfo.getName()); 
     134                AutoAction action = new ImportResourceAction( 
     135                                description, significant, importInfo, childRef, importManager); 
     136                action.register(book.getAccess()); 
    146137                 
    147138                return book.getRef().append(childRef); 
    148139        } 
     
    179170                final boolean linked = importInfo.isModelLinked();  
    180171 
    181172 
    182                 // The description must be smarter... May be with skins --meddle 2009-10-21 
    183                 new AutoAction(Message.create(INSERT_FRAME_FOR_RESOURCE, importInfo.getName()), true) { 
    184                         @Override 
    185                         public void performAuto() { 
    186                                 ResourceChanger changer = getChanger(); 
    187                                 if (!linked) { 
    188                                         importManager.makeResource(changer, resourceRef, importInfo); 
    189                                 } 
    190  
    191                                 importManager.insertFrame(changer.getSub(parentRef), 
    192                                                 parentRef, frameRef, resourceRef, frameTitle, 
    193                                                 elements, pos, frameSize); 
    194  
    195                         } 
    196                 }.register(book.getAccess()); 
     173                Message description = Message.create(INSERT_FRAME_FOR_RESOURCE, importInfo.getName()); 
     174                AutoAction action = new InsertFrameAction<D>(description, true, importInfo,  
     175                                frameRef, pos, frameSize, elements, parentRef, importManager, linked, 
     176                                resourceRef, frameTitle); 
     177                action.register(book.getAccess()); 
    197178                 
    198179                if (isDefaultTemplate) { 
    199180                        ResourceRefR4 absoluteDefRef = book.getRef().getAbsolute(defaultTemplate); 
     
    211192                        FrameH templateH = ResourceH.getHelper(templateAccess, FrameH.class); 
    212193                        final NaiveImmList<TemplatedKey<?>> immKeys = templateH.getApplicableTemplatedKeys(); 
    213194 
    214                         new AutoAction(Message.create(APPLY_TEMPLATE_FOR_RESOURCE, importInfo.getName()), false) { 
    215                                 @Override 
    216                                 public void performAuto() { 
    217                                         TemplateUtil.applyFrameTemplate(getChanger(),  
    218                                                         immKeys.asList(),  
    219                                                         templateRef, false, kind, true); 
    220  
    221                                 } 
    222                         }.register(frameAccess); 
     195                        description = Message.create(APPLY_TEMPLATE_FOR_RESOURCE, importInfo.getName()); 
     196                        action =  
     197                                new ApplyTemplateAction(description, false, immKeys, templateRef, kind); 
     198                        action.register(frameAccess); 
    223199                } 
    224200        } 
    225201         
     
    537513                        int count; 
    538514                        byte data[] = new byte[1024]; 
    539515 
    540                         String fileName = tempDir + entry.getName(); 
     516                        String fileName = tempDir + ResourceFilesUtil.FILE_SEPARATOR + entry.getName(); 
    541517 
    542518                        File resFile = new File(fileName); 
    543519                        resFile.deleteOnExit(); 
    544520 
    545                         try{ 
     521                        try { 
     522                                new File(resFile.getParent()).mkdirs(); 
    546523                                resFile.createNewFile(); 
    547524                                FileOutputStream fos = new FileOutputStream(resFile); 
    548525                                out = new BufferedOutputStream(fos, 1024); 
  • modules/org.sophie2.extra.func.annotations/src/main/java/org/sophie2/extra/func/annotations/actions/CreateStickyAction.java

     
     1package org.sophie2.extra.func.annotations.actions; 
     2 
     3import org.sophie2.base.commons.util.ImmList; 
     4import org.sophie2.base.commons.util.position.ImmPoint; 
     5import org.sophie2.base.model.book.timelines.ActivationChannel; 
     6import org.sophie2.base.model.resources.r4.ResourceRefR4; 
     7import org.sophie2.base.model.resources.r4.changes.AutoAction; 
     8import org.sophie2.base.model.resources.r4.changes.SubResourceChanger; 
     9import org.sophie2.base.skins.Message; 
     10import org.sophie2.extra.func.annotations.model.StickyH; 
     11 
     12/** 
     13 * An {@link AutoAction} that creates a new sticky. 
     14 *  
     15 * @author mitex 
     16 */ 
     17public class CreateStickyAction extends AutoAction { 
     18         
     19        private final ResourceRefR4 pageExtraRef; 
     20        private final ImmPoint location; 
     21        private final String textTitle; 
     22        private final ImmList<ActivationChannel> channels; 
     23 
     24        /** 
     25         * Creates the action with the all needed data to create the sticky. 
     26         *  
     27         * @param description  
     28         *                      Description of the action.  
     29         * @param significant  
     30         *                      Significance of the action.  
     31         * @param pageExtraRef 
     32         *                      {@link ResourceRefR4} to the extra, parent of the new sticky. 
     33         * @param location 
     34         *                      The location of the sticky to create. 
     35         * @param textTitle 
     36         *                      The title of the sticky. 
     37         * @param channels 
     38         *                      Channels of the page extra. 
     39         */ 
     40        public CreateStickyAction(Message description, boolean significant, 
     41                        ResourceRefR4 pageExtraRef, ImmPoint location, 
     42                        String textTitle, ImmList<ActivationChannel> channels) { 
     43                super(description, significant); 
     44                 
     45                this.pageExtraRef = pageExtraRef; 
     46                this.location = location; 
     47                this.textTitle = textTitle; 
     48                this.channels = channels; 
     49        } 
     50 
     51        @Override 
     52        public void performAuto() { 
     53                SubResourceChanger extraCh = getChanger().getSub(this.pageExtraRef); 
     54                StickyH.create(extraCh, this.textTitle, this.location, this.channels);                                                           
     55        } 
     56} 
  • modules/org.sophie2.main.func.resources/src/main/java/org/sophie2/main/func/resources/logic/ChangeFrameMainResourceHandler.java

     
    33import org.sophie2.base.dnd.DndTransferable; 
    44import org.sophie2.base.dnd.DropHandler; 
    55import org.sophie2.base.model.book.BookH; 
    6 import org.sophie2.base.model.book.interfaces.ResourceFrame; 
    76import org.sophie2.base.model.resources.r4.ResourceRefR4; 
    87import org.sophie2.base.model.resources.r4.access.ResourceAccess; 
    98import org.sophie2.base.model.resources.r4.changes.AutoAction; 
     
    1514import org.sophie2.main.app.commons.element.ElementDropHandler; 
    1615import org.sophie2.main.app.commons.frame.FrameView; 
    1716import org.sophie2.main.dnd.dnddata.ResourceRefData; 
     17import org.sophie2.main.func.resources.actions.SetFrameResourceAction; 
    1818import org.sophie2.main.func.resources.imports.ResourceImportProvider; 
    1919import org.sophie2.main.func.resources.imports.ResourceImportUtil; 
    2020import org.sophie2.main.func.resources.imports.SimpleResourceImportProvider; 
     
    8888                LogicR3.fire(getView(), bdw, null, null, BookView.EventIds.DELETING_ELEMENT, 
    8989                                ResourceDeleteLogic.findElementView(bookToFrameRef, getView().getBookView())); 
    9090                 
    91                 new AutoAction(Message.create(MAIN_RESOURCE_OF_FRAME), true) { 
    92                          
    93                         @Override 
    94                         public void performAuto() { 
    95                                 getChanger().setRaw(ResourceR4.KEY_KIND, newFrameKind); 
    96                                 getChanger().setRaw(ResourceFrame.KEY_MAIN_RESOURCE, relRef); 
    97                         } 
    98                 }.register(frameAccess); 
     91                Message description = Message.create(MAIN_RESOURCE_OF_FRAME); 
     92                AutoAction action = new SetFrameResourceAction(description, true, relRef, newFrameKind); 
     93                action.register(frameAccess); 
    9994        } 
    10095} 
  • modules/org.sophie2.main.func.resources/src/main/java/org/sophie2/main/func/resources/actions/ImportResourceAction.java

     
     1package org.sophie2.main.func.resources.actions; 
     2 
     3import org.sophie2.base.model.resources.r4.ResourceRefR4; 
     4import org.sophie2.base.model.resources.r4.changes.AutoAction; 
     5import org.sophie2.base.model.resources.r4.changes.ResourceChanger; 
     6import org.sophie2.base.skins.Message; 
     7import org.sophie2.main.func.resources.imports.ResourceImportInfo; 
     8import org.sophie2.main.func.resources.imports.ResourceImportManager; 
     9 
     10/** 
     11 * {@link AutoAction} for importing a new resource in a parent resource. 
     12 *  
     13 * @author meddle 
     14 * 
     15 * @param <D> 
     16 *                      The type of the import information needed to import the resource. 
     17 */ 
     18public class ImportResourceAction<D> extends AutoAction { 
     19         
     20        private final ResourceImportInfo<D> importInfo; 
     21        private final ResourceRefR4 resourceRef; 
     22        private final ResourceImportManager<D> importManager; 
     23 
     24        /** 
     25         * Creates the action with the import manager used to import the resource, 
     26         * the {@link ResourceImportInfo} needed for the import and the {@link ResourceRefR4} 
     27         * that will be pointing to the new resource. 
     28         *  
     29         * @param description  
     30         *                      Description of the action.  
     31         * @param significant  
     32         *                      Significance of the action.  
     33         * @param importInfo 
     34         *                      The info needed to import the resource. 
     35         * @param resourceRef 
     36         *                      The reference to the resource to import. 
     37         * @param importManager 
     38         *                      The import manager used to import the resource. 
     39         */ 
     40        public ImportResourceAction(Message description, boolean significant, 
     41                        ResourceImportInfo<D> importInfo, ResourceRefR4 resourceRef, 
     42                        ResourceImportManager<D> importManager) { 
     43                super(description, significant); 
     44                 
     45                this.importInfo = importInfo; 
     46                this.resourceRef = resourceRef; 
     47                this.importManager = importManager; 
     48        } 
     49 
     50        @Override 
     51        public void performAuto() { 
     52                ResourceChanger changer = getChanger(); 
     53 
     54                this.importManager.makeResource(changer, this.resourceRef, this.importInfo); 
     55        } 
     56} 
  • modules/org.sophie2.base.model.book/src/main/java/org/sophie2/base/model/book/resource/ResourceFilesUtil.java

     
    4040        private static final String INSTANCE_RESOURCES_TEMP = UUID.randomUUID().toString(); 
    4141         
    4242        /** 
     43         * The file separator used for storing files from Sophie. 
     44         */ 
     45        public static final String FILE_SEPARATOR = "/"; 
     46         
     47        /** 
    4348         * Stores a file to the special folder relative to 
    4449         * a resource specified by {@link ResourceFilesUtil#FILES_DIRECTORY}. 
    4550         *   
     
    141146        public static boolean isRelativeToParent(ResourceRefR4 ref, String parentLocation) { 
    142147                File parentDir = ResourceFilesUtil.getDir(parentLocation); 
    143148                String parentDirLocation = parentDir.getAbsolutePath().replace( 
    144                                 File.separator, ResourceRefR4.SEPARATOR); 
     149                                File.separator, FILE_SEPARATOR); 
    145150                String location = ref.getLocation(); 
    146151 
    147152                if (location.contains(parentDirLocation) 
     
    158163                                                ".", "_") + FILES_DIRECTORY; 
    159164        } 
    160165         
    161         private static File getDir(String resourceLocation) { 
     166        private static File getDir(String originalResourceLocation) { 
     167                String resourceLocation = originalResourceLocation.replace( 
     168                                File.separator, FILE_SEPARATOR); 
     169                 
    162170                // Temp dir: 
    163171                if (resourceLocation.startsWith(LocationPrefix.MEMORY) 
    164172                                || resourceLocation.startsWith(LocationPrefix.SERVER)) { 
     
    166174 
    167175                        String parent = System.getProperty("java.io.tmpdir"); 
    168176                        String pathname = INSTANCE_RESOURCES_TEMP + resourceLocation.substring(start) + FILES_DIRECTORY; 
    169                         pathname = parent + File.separator + pathname.replaceAll(":", "_"); 
     177                        pathname = parent + FILE_SEPARATOR + pathname.replaceAll(":", "_"); 
    170178                        File tempDir = new File(pathname); 
    171179 
    172180                        if (!tempDir.exists()) { 
     
    176184                        return tempDir; 
    177185                } 
    178186 
    179                 int lastSeparator = resourceLocation.lastIndexOf(File.separator); 
     187                int lastSeparator = resourceLocation.lastIndexOf(FILE_SEPARATOR); 
    180188 
    181189                String resourceName = getDirName(resourceLocation, lastSeparator); 
    182190 
    183191                String dirName = resourceLocation.substring(0, lastSeparator) + 
    184                 File.separator + resourceName; 
     192                FILE_SEPARATOR + resourceName; 
    185193 
    186194                dirName = dirName.replace( 
    187                                 File.separator, ResourceRefR4.SEPARATOR); 
     195                                File.separator, FILE_SEPARATOR); 
    188196                if (dirName.startsWith(LocationPrefix.FILE)) { 
    189197                        dirName = dirName.substring(LocationPrefix.FILE.length()); 
    190198                } 
     
    202210         */ 
    203211        public static String getValidPath(String path) { 
    204212                String validPath = path.replace( 
    205                                 File.separator, ResourceRefR4.SEPARATOR); 
     213                                File.separator, FILE_SEPARATOR); 
    206214                if (validPath.startsWith(LocationPrefix.FILE)) { 
    207215                        validPath = validPath.substring(LocationPrefix.FILE.length()); 
    208216                } 
     
    278286         * Restores the original path to a file to load from a string generated by 
    279287         * {@link ResourceFilesUtil#getSaveableLocation(String, File)}.  
    280288         *  
    281          * @param parentPath 
     289         * @param originalParentPath 
    282290         *                      The parent file from which the location will be loaded. 
    283          * @param saveablePath 
     291         * @param originalSaveablePath 
    284292         *                      The save-able path. 
    285293         * @return 
    286294         *                      The location that is loadable. 
    287295         */ 
    288         public static String getLoadableLocation(String parentPath, String saveablePath) { 
    289                 if (parentPath == null) { 
     296        public static String getLoadableLocation(String originalParentPath, String originalSaveablePath) { 
     297                String saveablePath = originalSaveablePath.replace("\\", FILE_SEPARATOR); 
     298                 
     299                if (originalParentPath == null) { 
    290300                        return saveablePath; 
    291301                } 
     302                 
     303                String parentPath = originalParentPath.replace("\\", FILE_SEPARATOR);  
    292304 
    293305                ResourceRefR4 absolute = ResourceRefR4.make( 
    294306                                parentPath).append(ResourceRefR4.make(saveablePath)); 
     
    348360                if (!target.exists()) { 
    349361                        if (parentPath == null) { 
    350362                                String validParentPath = filePath.substring(0, 
    351                                                 filePath.lastIndexOf(File.separator)); 
     363                                                filePath.lastIndexOf(FILE_SEPARATOR)); 
    352364                                File validParentDir = new File(validParentPath); 
    353365                                if (!validParentDir.exists()) { 
    354366                                        validParentDir.mkdir(); 
  • modules/org.sophie2.main.func.resources/src/test/java/org/sophie2/main/func/resources/exports/ResourceExportManagerTest.java

     
    1313import javax.swing.filechooser.FileFilter; 
    1414 
    1515import org.junit.Test; 
     16import org.sophie2.base.config.BaseConfigModule; 
    1617import org.sophie2.base.media.BaseMediaModule; 
    1718import org.sophie2.base.model.resources.r4.BaseModelResourcesR4Module; 
    1819import org.sophie2.base.model.resources.r4.access.ResourceAccess; 
    1920import org.sophie2.base.model.resources.r4.resources.ResourceR4; 
     21import org.sophie2.base.persistence.BasePersistenceModule; 
    2022import org.sophie2.base.skins.BaseSkinsModule; 
    2123import org.sophie2.base.visual.BaseVisualModule; 
    2224import org.sophie2.core.modularity.CoreModularityModule; 
     
    4143        protected List<Class<? extends SophieModule>> fillDependencies() { 
    4244                return Arrays.asList( 
    4345                                CoreModularityModule.class, 
     46                                BasePersistenceModule.class, 
     47                                BaseConfigModule.class, 
    4448                                BaseModelResourcesR4Module.class, 
    4549                                BaseSkinsModule.class, BaseVisualModule.class, 
    4650                                BaseMediaModule.class, MainMediaNatlibModule.class, 
  • modules/org.sophie2.main.func.resources/src/main/java/org/sophie2/main/func/resources/actions/ChangeImageBackgroundAction.java

     
     1package org.sophie2.main.func.resources.actions; 
     2 
     3import org.sophie2.base.model.book.BackgroundType; 
     4import org.sophie2.base.model.book.interfaces.StyledElement; 
     5import org.sophie2.base.model.resources.r4.ResourceRefR4; 
     6import org.sophie2.base.model.resources.r4.changes.AutoAction; 
     7import org.sophie2.base.model.resources.r4.changes.ResourceChanger; 
     8import org.sophie2.base.skins.Message; 
     9 
     10/** 
     11 * {@link AutoAction} for changes the background of an element to an image. 
     12 *  
     13 * @author tanya, deni 
     14 */ 
     15public class ChangeImageBackgroundAction extends AutoAction { 
     16         
     17        private final ResourceRefR4 elementToImageRef; 
     18 
     19        /** 
     20         * Creates the action with the needed relative reference from the element to the image. 
     21         *  
     22         * @param description  
     23         *                      Description of the action.  
     24         * @param significant  
     25         *                      Significance of the action.  
     26         * @param elementToImageRef 
     27         *                      The reference from the element (for which the background will be changed) 
     28         *                      to the image. 
     29         */ 
     30        public ChangeImageBackgroundAction(Message description, 
     31                        boolean significant, ResourceRefR4 elementToImageRef) { 
     32                super(description, significant); 
     33                 
     34                this.elementToImageRef = elementToImageRef; 
     35        } 
     36 
     37        @Override 
     38        public void performAuto() { 
     39                ResourceChanger changer = getChanger(); 
     40 
     41                changer.setRaw(StyledElement.KEY_BACKGROUND__IMAGE, this.elementToImageRef); 
     42                changer.setRaw(StyledElement.KEY_BACKGROUND__TYPE, BackgroundType.IMAGE); 
     43        } 
     44} 
  • modules/org.sophie2.main.func.resources/src/main/java/org/sophie2/main/func/resources/logic/ResourceImportLogic.java

     
    235235 
    236236                                                if (ref.getLocation().startsWith(bookRef.getLocation()) || !linked) { 
    237237 
    238                                                         AppMainWindow mainWindow = AppViewUtil.findMainWindow(bookDocView); 
    239                                                         ResourceAccess access = mainWindow.locator().get().open(ref, null); 
     238                                                        ResourceAccess access = book.getAccess().open(ref, null); 
    240239 
    241240                                                        if (access != null) { 
    242241                                                                 
  • modules/org.sophie2.main.func.resources/src/test/java/org/sophie2/main/func/resources/actions/CreateColdTextAction.java

     
     1package org.sophie2.main.func.resources.actions; 
     2 
     3import org.sophie2.base.model.resources.r4.ResourceRefR4; 
     4import org.sophie2.base.model.resources.r4.changes.AutoAction; 
     5import org.sophie2.base.model.resources.r4.changes.ResourceChanger; 
     6import org.sophie2.base.skins.Message; 
     7import org.sophie2.main.func.resources.dummy.ColdTextResource; 
     8import org.sophie2.main.func.resources.dummy.ColdTextResourceHelper; 
     9 
     10 
     11/** 
     12 * {@link AutoAction} for creating the {@link ColdTextResource}. 
     13 *  
     14 * @author meddle 
     15 */ 
     16public class CreateColdTextAction extends AutoAction { 
     17         
     18        private final String text; 
     19        private final ResourceRefR4 coldRef; 
     20 
     21        /** 
     22         * Creates the action with the location of the new resource and the text 
     23         * contained by it. 
     24         *  
     25         * @param description  
     26         *                      Description of the action.  
     27         * @param significant  
     28         *                      Significance of the action. 
     29         * @param text 
     30         *                      The text as string for the new resource. 
     31         * @param coldRef 
     32         *                      The reference to the place the resource will be created. 
     33         */ 
     34        public CreateColdTextAction(Message description, boolean significant, 
     35                        String text, ResourceRefR4 coldRef) { 
     36                super(description, significant); 
     37                 
     38                this.text = text; 
     39                this.coldRef = coldRef; 
     40        } 
     41 
     42        @Override 
     43        public void performAuto() { 
     44                ResourceChanger changer = getChanger(); 
     45                 
     46                ColdTextResourceHelper.createColdText(changer, this.coldRef, this.text); 
     47        } 
     48} 
  • modules/org.sophie2.extra.func.annotations/src/main/java/org/sophie2/extra/func/annotations/logic/StickiesLogic.java

     
    11package org.sophie2.extra.func.annotations.logic; 
    22 
    33import org.sophie2.base.commons.util.ImmList; 
    4 import org.sophie2.base.commons.util.NaiveImmList; 
    54import org.sophie2.base.commons.util.position.ImmPoint; 
    65import org.sophie2.base.dialogs.DialogManager; 
    76import org.sophie2.base.halos.HaloButton; 
     
    1716import org.sophie2.core.mvc.EventFilterBuilder; 
    1817import org.sophie2.core.mvc.OperationDef; 
    1918import org.sophie2.core.mvc.events.EventR3; 
     19import org.sophie2.extra.func.annotations.actions.CreateStickyAction; 
     20import org.sophie2.extra.func.annotations.actions.CreateStickyInExtraAction; 
     21import org.sophie2.extra.func.annotations.actions.DeleteStickyAction; 
    2022import org.sophie2.extra.func.annotations.model.StickyH; 
    2123import org.sophie2.extra.func.annotations.view.halos.StickyHaloMenu; 
    2224import org.sophie2.extra.func.annotations.view.halos.StickyRemoveHaloButton; 
     
    7476                                                final ImmPoint location = PageExtraH.DEFAULT_ELEMENT_LOCATION; 
    7577                                                final ResourceRefList pageExtras = currentBookExtra.getPageExtras(); 
    7678 
    77                                                 new AutoAction(Message.create(CREATE_PAGE_EXTRA_WITH_STICKY), true) { 
    78  
    79                                                         @Override 
    80                                                         public void performAuto() {  
    81                                                                 PageExtraH.create(getChanger(), pageExtraRef, 
    82                                                                                 curPageRef, channels, pageExtras); 
    83  
    84                                                                 StickyH.create(getChanger().getSub(pageExtraRef), textTitle, 
    85                                                                                 location, NaiveImmList.<ActivationChannel>getEmpty()); 
    86                                                         } 
    87                                                 }.register(currentBookExtra.getAccess()); 
     79                                                Message description = Message.create(CREATE_PAGE_EXTRA_WITH_STICKY); 
     80                                                AutoAction action = new CreateStickyInExtraAction(description, true, 
     81                                                                textTitle, curPageRef, pageExtraRef, channels, 
     82                                                                pageExtras, location); 
     83                                                action.register(currentBookExtra.getAccess()); 
     84                                                 
    8885                                        } else { 
    8986 
    9087                                                final ResourceRefR4 pageExtraRef = curPageExtra.getRef().getThisChildRef(); 
     
    9289                                                        curPageExtra.get(CompositeElement.KEY_SUB_ELEMENTS); 
    9390                                                final ImmPoint location = curPageExtra.selectInsertLocation(); 
    9491 
    95                                                 new AutoAction(Message.create(CREATE_NEW_STICKY), true) { 
    96  
    97                                                         @Override 
    98                                                         public void performAuto() { 
    99                                                                 StickyH.create(getChanger().getSub(pageExtraRef),  
    100                                                                                 textTitle, location, channels);                                                          
    101                                                         } 
    102                                                 }.register(currentBookExtra.getAccess()); 
     92                                                Message description = Message.create(CREATE_NEW_STICKY); 
     93                                                AutoAction action = new CreateStickyAction(description, true, pageExtraRef, 
     94                                                                location, textTitle, channels); 
     95                                                action.register(currentBookExtra.getAccess()); 
    10396                                        } 
    10497                                } 
    10598                        } 
     
    151144                                        pageExtra.get(CompositeElement.KEY_SUB_ELEMENTS); 
    152145                                final ActivationChannel chan = pageExtra.getActivationChannel(stickyRef);  
    153146 
    154                                 new AutoAction(Message.create(DELETE_STICKY), true) { 
    155  
    156                                         @Override 
    157                                         public void performAuto() { 
    158                                                 getChanger().removeResource(stickyRef); 
    159                                                 getChanger().setRaw( 
    160                                                                 CompositeElement.KEY_SUB_ELEMENTS, channels.remove(chan)); 
    161                                         } 
    162                                 }.register(pageExtra.getAccess()); 
     147                                Message description = Message.create(DELETE_STICKY); 
     148                                AutoAction action = new DeleteStickyAction(description, true, channels, chan, 
     149                                                stickyRef); 
     150                                action.register(pageExtra.getAccess()); 
    163151 
    164152                        } 
    165153 
  • modules/org.sophie2.main.app.commons/src/main/java/org/sophie2/main/app/commons/frame/ErrorManipulationView.java

     
    167167                                                        this.refreshTask.cancel(); 
    168168                                                } 
    169169 
    170                                                 this.refreshTask = new RefreshTask(); 
     170                                                TimerTask task = new RefreshTask(); 
     171                                                this.refreshTask = task; 
    171172 
    172173                                                Timer timer = new Timer(); 
    173                                                 timer.schedule(this.refreshTask, expirable.getTimeOut()); 
     174                                                timer.schedule(task, expirable.getTimeOut()); 
    174175                                        } 
    175176                                } 
    176177 
  • modules/org.sophie2.main.func.resources/src/test/java/org/sophie2/main/func/resources/dummy/ColdTextResourceHelper.java

     
    77import org.sophie2.base.model.resources.r4.resources.ResourceH; 
    88import org.sophie2.base.model.resources.r4.resources.ResourceR4; 
    99import org.sophie2.base.skins.Message; 
     10import org.sophie2.main.func.resources.actions.CreateColdTextAction; 
    1011 
    1112/** 
    1213 * The helper of our cold text... 
     
    8283                final ResourceRefR4 coldRef =  
    8384                        ResourceRefR4.generateRandomSub(ColdTextResource.DEFAULT_TITLE); 
    8485                 
    85                 new AutoAction(Message.create(CREATING_COLD_TEXT), true) { 
    86                         @Override 
    87                         public void performAuto() { 
    88                                 ColdTextResourceHelper.createColdText( 
    89                                                 getChanger(), coldRef, text); 
    90                         } 
    91                 }.register(bookAccess); 
     86                Message description = Message.create(CREATING_COLD_TEXT); 
     87                AutoAction action = new CreateColdTextAction(description, true, text, coldRef); 
     88                action.register(bookAccess); 
    9289                 
    9390                return bookAccess.open(coldRef, null); 
    9491        } 
  • modules/org.sophie2.main.func.resources/src/main/java/org/sophie2/main/func/resources/logic/ChangeBackgroundHandler.java

     
    33import org.sophie2.base.dnd.DndTransferable; 
    44import org.sophie2.base.dnd.DropHandler; 
    55import org.sophie2.base.dnd.dnddata.ImageData; 
    6 import org.sophie2.base.model.book.BackgroundType; 
    76import org.sophie2.base.model.book.BookH; 
    8 import org.sophie2.base.model.book.interfaces.StyledElement; 
    97import org.sophie2.base.model.resources.r4.ResourceRefR4; 
    108import org.sophie2.base.model.resources.r4.changes.AutoAction; 
    11 import org.sophie2.base.model.resources.r4.changes.ResourceChanger; 
    129import org.sophie2.base.skins.Message; 
    1310import org.sophie2.main.app.commons.element.ElementDropHandler; 
    1411import org.sophie2.main.app.commons.element.ElementView; 
    1512import org.sophie2.main.dnd.dnddata.ResourceRefData; 
     13import org.sophie2.main.func.resources.actions.ChangeImageBackgroundAction; 
    1614import org.sophie2.main.func.resources.imports.ResourceImportUtil; 
    1715 
    1816/** 
     
    6967                final ResourceRefR4 elementToImageRef =  
    7068                        ResourceRefR4.getRelativeRef(absElementRef, absImageRef); 
    7169         
    72                 new AutoAction(Message.create(SET_IMAGE_BG), true) { 
    73  
    74                         @Override 
    75                         public void performAuto() { 
    76                                 ResourceChanger changer = getChanger(); 
    77  
    78                                 changer.setRaw(StyledElement.KEY_BACKGROUND__IMAGE, elementToImageRef); 
    79                                 changer.setRaw(StyledElement.KEY_BACKGROUND__TYPE, BackgroundType.IMAGE); 
    80                         } 
    81                 }.register(getView().getAccess()); 
     70                Message description = Message.create(SET_IMAGE_BG); 
     71                AutoAction action = new ChangeImageBackgroundAction(description, true, elementToImageRef); 
     72                action.register(getView().getAccess()); 
    8273        } 
    8374}