Ticket #2427: autoActions.patch
File autoActions.patch, 46.3 KB (added by meddle, 15 years ago) |
---|
-
modules/org.sophie2.main.func.resources/src/main/java/org/sophie2/main/func/resources/actions/RemoveResourceAction.java
### Eclipse Workspace Patch 1.0 #P sophie
1 package org.sophie2.main.func.resources.actions; 2 3 import org.sophie2.base.model.resources.r4.ResourceRefR4; 4 import org.sophie2.base.model.resources.r4.changes.AutoAction; 5 import org.sophie2.base.skins.Message; 6 7 /** 8 * {@link AutoAction} for deleting a resource. 9 * 10 * @author diana 11 */ 12 public 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
1 package org.sophie2.main.func.resources.actions; 2 3 import org.sophie2.base.commons.util.NaiveImmList; 4 import org.sophie2.base.model.resources.r4.ResourceRefR4; 5 import org.sophie2.base.model.resources.r4.changes.AutoAction; 6 import org.sophie2.base.model.resources.r4.keys.TemplatedKey; 7 import org.sophie2.base.skins.Message; 8 import org.sophie2.main.app.commons.util.TemplateUtil; 9 10 /** 11 * {@link AutoAction} for applying a template to a resource. 12 * 13 * @author deni 14 */ 15 public 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.main.func.resources/src/test/java/org/sophie2/main/func/resources/imports/ResourceImportUtilTest.java
8 8 9 9 import org.junit.Before; 10 10 import org.junit.Test; 11 import org.sophie2.base.bound.BoundModule; 11 12 import org.sophie2.base.commons.BaseCommonsModule; 12 13 import org.sophie2.base.commons.util.position.ImmPoint; 14 import org.sophie2.base.config.BaseConfigModule; 13 15 import org.sophie2.base.dialogs.BaseDialogsModule; 14 16 import org.sophie2.base.dialogs.TestingDialogManager; 15 17 import org.sophie2.base.dnd.DndData; … … 28 30 import org.sophie2.base.model.resources.r4.immutables.SubEntryNames; 29 31 import org.sophie2.base.model.resources.r4.resources.ResourceH; 30 32 import org.sophie2.base.model.resources.r4.resources.ResourceR4; 33 import org.sophie2.base.persistence.BasePersistenceModule; 31 34 import org.sophie2.base.skins.BaseSkinsModule; 32 35 import org.sophie2.base.skins.Message; 33 36 import org.sophie2.base.visual.BaseVisualModule; … … 41 44 import org.sophie2.main.dialogs.input.file.FileDialogInput; 42 45 import org.sophie2.main.dialogs.input.file.FileFilterInfo; 43 46 import org.sophie2.main.func.file.FileFunctionalityModule; 47 import org.sophie2.main.func.resources.actions.CreateColdTextAction; 44 48 import org.sophie2.main.func.resources.dummy.ColdTextData; 45 49 import org.sophie2.main.func.resources.dummy.ColdTextFrame; 46 50 import org.sophie2.main.func.resources.dummy.ColdTextImportManager; … … 117 121 protected List<Class<? extends SophieModule>> fillDependencies() { 118 122 return Arrays.asList(BaseModelResourcesR4Module.class, 119 123 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, 124 129 ColdTextModule.class); 125 130 } 126 131 … … 275 280 ResourceRefR4.generateRandomSub(ColdTextResource.DEFAULT_TITLE); 276 281 final String text = "My text"; 277 282 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); 286 286 287 287 // text and page: 288 288 assertEquals(2, book.getChildren().size()); -
modules/org.sophie2.main.func.resources/src/main/java/org/sophie2/main/func/resources/actions/SetFrameResourceAction.java
1 package org.sophie2.main.func.resources.actions; 2 3 import org.sophie2.base.model.book.interfaces.ResourceFrame; 4 import org.sophie2.base.model.resources.r4.ResourceRefR4; 5 import org.sophie2.base.model.resources.r4.changes.AutoAction; 6 import org.sophie2.base.model.resources.r4.resources.ResourceR4; 7 import org.sophie2.base.skins.Message; 8 9 /** 10 * {@link AutoAction} for changing the main resource of a frame. 11 * 12 * @author deni 13 */ 14 public 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
30 30 import org.sophie2.base.model.resources.r4.ResourceUtil; 31 31 import org.sophie2.base.model.resources.r4.access.ResourceAccess; 32 32 import org.sophie2.base.model.resources.r4.changes.AutoAction; 33 import org.sophie2.base.model.resources.r4.changes.ResourceChanger;34 33 import org.sophie2.base.model.resources.r4.keys.TemplatedKey; 35 34 import org.sophie2.base.model.resources.r4.model.ResourceModel; 36 35 import org.sophie2.base.model.resources.r4.resources.ResourceH; 37 36 import org.sophie2.base.model.resources.r4.resources.ResourceR4; 38 37 import org.sophie2.base.skins.Message; 39 38 import org.sophie2.core.logging.SophieLog; 40 import org.sophie2.main.app.commons.util.TemplateUtil;41 39 import org.sophie2.main.dialogs.input.DialogUtils; 42 40 import org.sophie2.main.dialogs.input.MessageDialogInput; 43 41 import org.sophie2.main.dialogs.input.MessageDialogInput.MessageType; 44 42 import org.sophie2.main.dialogs.input.file.FileDialogInput; 43 import org.sophie2.main.func.resources.actions.ApplyTemplateAction; 44 import org.sophie2.main.func.resources.actions.ImportResourceAction; 45 import org.sophie2.main.func.resources.actions.InsertFrameAction; 45 46 import org.sophie2.main.func.resources.imports.bindata.ResourceImportType; 46 47 47 48 /** … … 94 95 new ResourceImportInfo<D>(data, resFile.getName(), resFile.toURI(), 95 96 ResourceImportType.EMBED); 96 97 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()); 107 102 108 103 return resourceRef; 109 104 } … … 135 130 final ResourceImportInfo importInfo = new ResourceImportInfo(data, title); 136 131 final ResourceRefR4 childRef = importManager.generateChildRef(); 137 132 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()); 146 137 147 138 return book.getRef().append(childRef); 148 139 } … … 179 170 final boolean linked = importInfo.isModelLinked(); 180 171 181 172 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()); 197 178 198 179 if (isDefaultTemplate) { 199 180 ResourceRefR4 absoluteDefRef = book.getRef().getAbsolute(defaultTemplate); … … 211 192 FrameH templateH = ResourceH.getHelper(templateAccess, FrameH.class); 212 193 final NaiveImmList<TemplatedKey<?>> immKeys = templateH.getApplicableTemplatedKeys(); 213 194 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); 223 199 } 224 200 } 225 201 … … 537 513 int count; 538 514 byte data[] = new byte[1024]; 539 515 540 String fileName = tempDir + entry.getName();516 String fileName = tempDir + ResourceFilesUtil.FILE_SEPARATOR + entry.getName(); 541 517 542 518 File resFile = new File(fileName); 543 519 resFile.deleteOnExit(); 544 520 545 try{ 521 try { 522 new File(resFile.getParent()).mkdirs(); 546 523 resFile.createNewFile(); 547 524 FileOutputStream fos = new FileOutputStream(resFile); 548 525 out = new BufferedOutputStream(fos, 1024); -
modules/org.sophie2.main.func.resources/src/main/java/org/sophie2/main/func/resources/logic/ChangeFrameMainResourceHandler.java
3 3 import org.sophie2.base.dnd.DndTransferable; 4 4 import org.sophie2.base.dnd.DropHandler; 5 5 import org.sophie2.base.model.book.BookH; 6 import org.sophie2.base.model.book.interfaces.ResourceFrame;7 6 import org.sophie2.base.model.resources.r4.ResourceRefR4; 8 7 import org.sophie2.base.model.resources.r4.access.ResourceAccess; 9 8 import org.sophie2.base.model.resources.r4.changes.AutoAction; … … 15 14 import org.sophie2.main.app.commons.element.ElementDropHandler; 16 15 import org.sophie2.main.app.commons.frame.FrameView; 17 16 import org.sophie2.main.dnd.dnddata.ResourceRefData; 17 import org.sophie2.main.func.resources.actions.SetFrameResourceAction; 18 18 import org.sophie2.main.func.resources.imports.ResourceImportProvider; 19 19 import org.sophie2.main.func.resources.imports.ResourceImportUtil; 20 20 import org.sophie2.main.func.resources.imports.SimpleResourceImportProvider; … … 88 88 LogicR3.fire(getView(), bdw, null, null, BookView.EventIds.DELETING_ELEMENT, 89 89 ResourceDeleteLogic.findElementView(bookToFrameRef, getView().getBookView())); 90 90 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); 99 94 } 100 95 } -
modules/org.sophie2.main.func.resources/src/test/java/org/sophie2/main/func/resources/imports/ResourceImportManagerTest.java
6 6 7 7 import org.junit.Before; 8 8 import org.junit.Test; 9 import org.sophie2.base.bound.BoundModule; 9 10 import org.sophie2.base.commons.BaseCommonsModule; 10 11 import org.sophie2.base.commons.structures.ImmTreeList; 11 12 import org.sophie2.base.commons.util.ImmList; 12 import org.sophie2.base.co mmons.util.position.ImmPoint;13 import org.sophie2.base.config.BaseConfigModule; 13 14 import org.sophie2.base.dialogs.BaseDialogsModule; 14 15 import org.sophie2.base.dialogs.TestingDialogManager; 15 16 import org.sophie2.base.media.BaseMediaModule; 16 17 import org.sophie2.base.model.book.BaseModelBookModule; 17 18 import org.sophie2.base.model.book.FrameH; 18 import org.sophie2.base.model.book.frame.FrameR4;19 19 import org.sophie2.base.model.book.interfaces.ResourceFrame; 20 20 import org.sophie2.base.model.book.resource.r4.BookR4; 21 21 import org.sophie2.base.model.book.timelines.ActivationChannel; … … 28 28 import org.sophie2.base.model.resources.r4.keys.ChildrenKey; 29 29 import org.sophie2.base.model.resources.r4.keys.TemplatedKey; 30 30 import org.sophie2.base.model.resources.r4.resources.ResourceR4; 31 import org.sophie2.base.persistence.BasePersistenceModule; 31 32 import org.sophie2.base.skins.BaseSkinsModule; 32 33 import org.sophie2.base.skins.Message; 33 34 import org.sophie2.base.visual.BaseVisualModule; … … 40 41 import org.sophie2.main.dialogs.input.file.FileDialogInput; 41 42 import org.sophie2.main.dialogs.input.file.FileFilterInfo; 42 43 import org.sophie2.main.func.file.FileFunctionalityModule; 44 import org.sophie2.main.func.resources.actions.CreateColdTextAction; 45 import org.sophie2.main.func.resources.actions.InsertTextFrameAction; 43 46 import org.sophie2.main.func.resources.dummy.ColdTextImportManager; 44 47 import org.sophie2.main.func.resources.dummy.ColdTextModule; 45 48 import org.sophie2.main.func.resources.dummy.ColdTextResource; … … 80 83 protected List<Class<? extends SophieModule>> fillDependencies() { 81 84 return Arrays.asList(BaseModelResourcesR4Module.class, 82 85 BaseVisualModule.class, BaseMediaModule.class, 86 BaseConfigModule.class, BasePersistenceModule.class, 83 87 BaseCommonsModule.class, MainMediaNatlibModule.class, 84 BaseDialogsModule.class, B aseSkinsModule.class,88 BaseDialogsModule.class, BoundModule.class, BaseSkinsModule.class, 85 89 BaseModelBookModule.class, FileFunctionalityModule.class, 86 90 MainAppModule.class, 87 91 ColdTextModule.class); … … 183 187 ResourceRefR4.generateRandomSub(ColdTextResource.DEFAULT_TITLE); 184 188 final String text = "Some text"; 185 189 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); 193 193 194 194 SubEntryNames children = ResourceR4.KEY_CHILDREN.get(bookAccess); 195 195 … … 207 207 ResourceRefR4.generateRandomSub(FrameH.NAME_PREFIX); 208 208 final ImmList<ActivationChannel> elements = ImmTreeList.empty(); 209 209 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); 221 214 222 215 ChildrenKey pageChildrenKey = 223 216 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
23 23 import org.sophie2.main.app.commons.util.AppViewUtil; 24 24 import org.sophie2.main.dialogs.input.ConfirmDialogInput; 25 25 import org.sophie2.main.dialogs.input.DialogUtils; 26 import org.sophie2.main.func.resources.actions.RemoveResourceAction; 27 import org.sophie2.main.func.resources.actions.RemoveTemplateAction; 26 28 import org.sophie2.main.func.resources.view.ResourceDetailsPalette; 27 29 import org.sophie2.main.func.resources.view.ResourceDetailsPalette.DeleteResourceButton; 28 30 import org.sophie2.main.func.resources.view.ResourcesPalette.ResourceItem; … … 83 85 return true; 84 86 } 85 87 }; 86 88 87 89 /** 88 90 * Constant created for removing template. 89 91 * Constant created to be a parameter of a message of an {@link AutoAction}. … … 121 123 122 124 final ResourceRefR4 resourceRef = ResourceRefR4.getRelativeRef( 123 125 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); 131 130 132 131 return true; 133 132 } … … 205 204 ResourceAccess bookAccess = bookView.getAccess(); 206 205 final ResourceRefList templates = key.get(bookAccess); 207 206 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); 216 210 217 211 return true; 218 212 } -
modules/org.sophie2.main.func.resources/src/main/java/org/sophie2/main/func/resources/actions/ImportResourceAction.java
1 package org.sophie2.main.func.resources.actions; 2 3 import org.sophie2.base.model.resources.r4.ResourceRefR4; 4 import org.sophie2.base.model.resources.r4.changes.AutoAction; 5 import org.sophie2.base.model.resources.r4.changes.ResourceChanger; 6 import org.sophie2.base.skins.Message; 7 import org.sophie2.main.func.resources.imports.ResourceImportInfo; 8 import 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 */ 18 public 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
40 40 private static final String INSTANCE_RESOURCES_TEMP = UUID.randomUUID().toString(); 41 41 42 42 /** 43 * The file separator used for storing files from Sophie. 44 */ 45 public static final String FILE_SEPARATOR = "/"; 46 47 /** 43 48 * Stores a file to the special folder relative to 44 49 * a resource specified by {@link ResourceFilesUtil#FILES_DIRECTORY}. 45 50 * … … 141 146 public static boolean isRelativeToParent(ResourceRefR4 ref, String parentLocation) { 142 147 File parentDir = ResourceFilesUtil.getDir(parentLocation); 143 148 String parentDirLocation = parentDir.getAbsolutePath().replace( 144 File.separator, ResourceRefR4.SEPARATOR);149 File.separator, FILE_SEPARATOR); 145 150 String location = ref.getLocation(); 146 151 147 152 if (location.contains(parentDirLocation) … … 166 171 167 172 String parent = System.getProperty("java.io.tmpdir"); 168 173 String pathname = INSTANCE_RESOURCES_TEMP + resourceLocation.substring(start) + FILES_DIRECTORY; 169 pathname = parent + F ile.separator+ pathname.replaceAll(":", "_");174 pathname = parent + FILE_SEPARATOR + pathname.replaceAll(":", "_"); 170 175 File tempDir = new File(pathname); 171 176 172 177 if (!tempDir.exists()) { … … 176 181 return tempDir; 177 182 } 178 183 179 int lastSeparator = resourceLocation.lastIndexOf(F ile.separator);184 int lastSeparator = resourceLocation.lastIndexOf(FILE_SEPARATOR); 180 185 181 186 String resourceName = getDirName(resourceLocation, lastSeparator); 182 187 183 188 String dirName = resourceLocation.substring(0, lastSeparator) + 184 F ile.separator+ resourceName;189 FILE_SEPARATOR + resourceName; 185 190 186 191 dirName = dirName.replace( 187 File.separator, ResourceRefR4.SEPARATOR);192 File.separator, FILE_SEPARATOR); 188 193 if (dirName.startsWith(LocationPrefix.FILE)) { 189 194 dirName = dirName.substring(LocationPrefix.FILE.length()); 190 195 } … … 202 207 */ 203 208 public static String getValidPath(String path) { 204 209 String validPath = path.replace( 205 File.separator, ResourceRefR4.SEPARATOR);210 File.separator, FILE_SEPARATOR); 206 211 if (validPath.startsWith(LocationPrefix.FILE)) { 207 212 validPath = validPath.substring(LocationPrefix.FILE.length()); 208 213 } … … 348 353 if (!target.exists()) { 349 354 if (parentPath == null) { 350 355 String validParentPath = filePath.substring(0, 351 filePath.lastIndexOf(F ile.separator));356 filePath.lastIndexOf(FILE_SEPARATOR)); 352 357 File validParentDir = new File(validParentPath); 353 358 if (!validParentDir.exists()) { 354 359 validParentDir.mkdir(); -
modules/org.sophie2.main.func.resources/src/test/java/org/sophie2/main/func/resources/exports/ResourceExportManagerTest.java
13 13 import javax.swing.filechooser.FileFilter; 14 14 15 15 import org.junit.Test; 16 import org.sophie2.base.config.BaseConfigModule; 16 17 import org.sophie2.base.media.BaseMediaModule; 17 18 import org.sophie2.base.model.resources.r4.BaseModelResourcesR4Module; 18 19 import org.sophie2.base.model.resources.r4.access.ResourceAccess; 19 20 import org.sophie2.base.model.resources.r4.resources.ResourceR4; 21 import org.sophie2.base.persistence.BasePersistenceModule; 20 22 import org.sophie2.base.skins.BaseSkinsModule; 21 23 import org.sophie2.base.visual.BaseVisualModule; 22 24 import org.sophie2.core.modularity.CoreModularityModule; … … 41 43 protected List<Class<? extends SophieModule>> fillDependencies() { 42 44 return Arrays.asList( 43 45 CoreModularityModule.class, 46 BasePersistenceModule.class, 47 BaseConfigModule.class, 44 48 BaseModelResourcesR4Module.class, 45 49 BaseSkinsModule.class, BaseVisualModule.class, 46 50 BaseMediaModule.class, MainMediaNatlibModule.class, -
modules/org.sophie2.main.func.resources/src/main/java/org/sophie2/main/func/resources/actions/ChangeImageBackgroundAction.java
1 package org.sophie2.main.func.resources.actions; 2 3 import org.sophie2.base.model.book.BackgroundType; 4 import org.sophie2.base.model.book.interfaces.StyledElement; 5 import org.sophie2.base.model.resources.r4.ResourceRefR4; 6 import org.sophie2.base.model.resources.r4.changes.AutoAction; 7 import org.sophie2.base.model.resources.r4.changes.ResourceChanger; 8 import 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 */ 15 public 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/test/java/org/sophie2/main/func/resources/actions/InsertTextFrameAction.java
1 package org.sophie2.main.func.resources.actions; 2 3 import org.sophie2.base.commons.util.ImmList; 4 import org.sophie2.base.commons.util.position.ImmPoint; 5 import org.sophie2.base.model.book.frame.FrameR4; 6 import org.sophie2.base.model.book.timelines.ActivationChannel; 7 import org.sophie2.base.model.resources.r4.ResourceRefR4; 8 import org.sophie2.base.model.resources.r4.changes.AutoAction; 9 import org.sophie2.base.skins.Message; 10 import org.sophie2.main.func.resources.dummy.ColdTextImportManager; 11 12 /** 13 * {@link AutoAction} for inserting test frame with text. 14 * 15 * @author meddle 16 */ 17 public 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.main.func.resources/src/test/java/org/sophie2/main/func/resources/actions/CreateColdTextAction.java
1 package org.sophie2.main.func.resources.actions; 2 3 import org.sophie2.base.model.resources.r4.ResourceRefR4; 4 import org.sophie2.base.model.resources.r4.changes.AutoAction; 5 import org.sophie2.base.model.resources.r4.changes.ResourceChanger; 6 import org.sophie2.base.skins.Message; 7 import org.sophie2.main.func.resources.dummy.ColdTextResource; 8 import org.sophie2.main.func.resources.dummy.ColdTextResourceHelper; 9 10 11 /** 12 * {@link AutoAction} for creating the {@link ColdTextResource}. 13 * 14 * @author meddle 15 */ 16 public 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.main.func.resources/src/test/java/org/sophie2/main/func/resources/SophiePackageFormatTest.java
2 2 3 3 import java.io.File; 4 4 import java.net.URL; 5 import java.util.Arrays; 5 6 import java.util.Collection; 6 7 import java.util.Collections; 7 8 import java.util.List; … … 11 12 import org.junit.Test; 12 13 import org.sophie2.base.commons.util.bindata.BinData; 13 14 import org.sophie2.base.commons.util.bindata.RawBinData; 15 import org.sophie2.base.config.BaseConfigModule; 14 16 import org.sophie2.base.model.book.BaseModelBookModule; 15 17 import org.sophie2.base.model.book.BookH; 16 18 import org.sophie2.base.model.book.resource.r4.BookR4; 17 19 import org.sophie2.base.model.book.testing.ModelTestBase; 20 import org.sophie2.base.model.resources.r4.BaseModelResourcesR4Module; 18 21 import org.sophie2.base.model.resources.r4.ResourceRefR4; 19 22 import org.sophie2.base.model.resources.r4.access.ResourceAccess; 20 23 import org.sophie2.base.model.resources.r4.immutables.SubEntryNames; … … 50 53 51 54 private File exportOtputFile = null; 52 55 56 @SuppressWarnings("unchecked") 53 57 @Override 54 58 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 } 64 67 65 68 @Override 66 69 @Before -
modules/org.sophie2.main.func.resources/src/test/java/org/sophie2/main/func/resources/dummy/ColdTextResourceHelper.java
7 7 import org.sophie2.base.model.resources.r4.resources.ResourceH; 8 8 import org.sophie2.base.model.resources.r4.resources.ResourceR4; 9 9 import org.sophie2.base.skins.Message; 10 import org.sophie2.main.func.resources.actions.CreateColdTextAction; 10 11 11 12 /** 12 13 * The helper of our cold text... … … 82 83 final ResourceRefR4 coldRef = 83 84 ResourceRefR4.generateRandomSub(ColdTextResource.DEFAULT_TITLE); 84 85 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); 92 89 93 90 return bookAccess.open(coldRef, null); 94 91 } -
modules/org.sophie2.main.func.resources/src/main/java/org/sophie2/main/func/resources/actions/RemoveTemplateAction.java
1 package org.sophie2.main.func.resources.actions; 2 3 import org.sophie2.base.model.resources.r4.ResourceRefList; 4 import org.sophie2.base.model.resources.r4.ResourceRefR4; 5 import org.sophie2.base.model.resources.r4.changes.AutoAction; 6 import org.sophie2.base.model.resources.r4.keys.Key; 7 import org.sophie2.base.skins.Message; 8 9 /** 10 * {@link AutoAction} for removing a template. 11 * 12 * @author diana 13 */ 14 public 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
1 package org.sophie2.main.func.resources.actions; 2 3 import org.sophie2.base.commons.util.ImmList; 4 import org.sophie2.base.commons.util.position.ImmPoint; 5 import org.sophie2.base.commons.util.position.ImmSize; 6 import org.sophie2.base.model.book.timelines.ActivationChannel; 7 import org.sophie2.base.model.resources.r4.ResourceRefR4; 8 import org.sophie2.base.model.resources.r4.changes.AutoAction; 9 import org.sophie2.base.model.resources.r4.changes.ResourceChanger; 10 import org.sophie2.base.skins.Message; 11 import org.sophie2.main.func.resources.imports.ResourceImportInfo; 12 import 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 */ 23 public 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/logic/ChangeBackgroundHandler.java
3 3 import org.sophie2.base.dnd.DndTransferable; 4 4 import org.sophie2.base.dnd.DropHandler; 5 5 import org.sophie2.base.dnd.dnddata.ImageData; 6 import org.sophie2.base.model.book.BackgroundType;7 6 import org.sophie2.base.model.book.BookH; 8 import org.sophie2.base.model.book.interfaces.StyledElement;9 7 import org.sophie2.base.model.resources.r4.ResourceRefR4; 10 8 import org.sophie2.base.model.resources.r4.changes.AutoAction; 11 import org.sophie2.base.model.resources.r4.changes.ResourceChanger;12 9 import org.sophie2.base.skins.Message; 13 10 import org.sophie2.main.app.commons.element.ElementDropHandler; 14 11 import org.sophie2.main.app.commons.element.ElementView; 15 12 import org.sophie2.main.dnd.dnddata.ResourceRefData; 13 import org.sophie2.main.func.resources.actions.ChangeImageBackgroundAction; 16 14 import org.sophie2.main.func.resources.imports.ResourceImportUtil; 17 15 18 16 /** … … 69 67 final ResourceRefR4 elementToImageRef = 70 68 ResourceRefR4.getRelativeRef(absElementRef, absImageRef); 71 69 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()); 82 73 } 83 74 }