Ticket #2278: deleteResources.patch
File deleteResources.patch, 50.0 KB (added by mira, 15 years ago) |
---|
-
src/main/java/org/sophie2/main/func/media/links/MediaConfigurationPanelsLogic.java
### Eclipse Workspace Patch 1.0 #P org.sophie2.main.func.media
1 1 package org.sophie2.main.func.media.links; 2 2 3 import java.util.HashMap; 4 import java.util.Map; 5 3 6 import org.sophie2.base.bound.ComboInput; 4 7 import org.sophie2.base.bound.BoundControl.EventIds; 5 8 import org.sophie2.base.model.book.links.LinkRule; … … 49 52 ResourceRefR4.getRelativeRef(holder.getRef(), targetFrame.getRef()); 50 53 51 54 assert currentRule.getAction() instanceof MediaAction; 55 Map<ResourceRefR4, ResourceRefR4> replaces = new HashMap<ResourceRefR4, ResourceRefR4>(); 56 MediaAction oldAction = (MediaAction)currentRule.getAction(); 57 replaces.put(oldAction.getReferences().get(0), newRef); 58 MediaAction newAction = oldAction.fixReferences(replaces); 52 59 53 MediaAction newAction = (54 (MediaAction)currentRule.getAction()).setRef(newRef);55 56 60 LinksUtil.addAction(hud, newAction); 57 61 } 58 62 } -
src/main/java/org/sophie2/main/func/media/links/MediaPlayAction.java
1 1 package org.sophie2.main.func.media.links; 2 2 3 import java.util.Map; 4 3 5 import org.sophie2.base.model.resources.r4.ResourceRefR4; 4 6 import org.sophie2.core.prolib.annot.Immutable; 5 7 … … 25 27 public String getDescription() { 26 28 return "Play Media"; 27 29 } 28 @Override 29 public MediaPlayAction setRef(ResourceRefR4 newRef) { 30 return new MediaPlayAction(newRef); 30 31 public MediaPlayAction fixReferences( 32 Map<ResourceRefR4, ResourceRefR4> replaces) { 33 return new MediaPlayAction(replaces.get(this.mediaFrame)); 31 34 } 32 35 33 36 } 37 No newline at end of file -
src/main/java/org/sophie2/main/func/media/links/StopMediaActionPersister.java
32 32 33 33 ValueRef<ResourceRefR4> frameRef = new ValueRef<ResourceRefR4>(); 34 34 if (options.isSaveMode()) { 35 frameRef.set(source.get().getRef ());35 frameRef.set(source.get().getReferences().get(0)); 36 36 } 37 37 38 38 MasterPersister.persist(frameRef, target.child("frame"), -
src/main/java/org/sophie2/main/func/media/links/MediaPauseAction.java
1 1 package org.sophie2.main.func.media.links; 2 2 3 import java.util.Map; 4 3 5 import org.sophie2.base.model.resources.r4.ResourceRefR4; 4 6 import org.sophie2.core.prolib.annot.Immutable; 5 7 … … 25 27 public String getDescription() { 26 28 return "Pause Media"; 27 29 } 28 29 @Override30 public MediaPauseAction setRef(ResourceRefR4 newRef) {31 return new MediaPauseAction(newRef);30 31 public MediaPauseAction fixReferences( 32 Map<ResourceRefR4, ResourceRefR4> replaces) { 33 return new MediaPauseAction(replaces.get(this.mediaFrame)); 32 34 } 33 35 34 36 } -
src/main/java/org/sophie2/main/func/media/links/MediaActionConfigurationPanel.java
120 120 && hud.holder().get() != null 121 121 && hud.currentRule().get() != null 122 122 && hud.currentRule().get().getAction() != null 123 && hud.currentRule().get().getAction() instanceof MediaAction 124 && ((MediaAction) hud.currentRule().get().getAction()).getRef() != null) { 123 && hud.currentRule().get().getAction() instanceof MediaAction) { 125 124 ResourceRefR4 selectedFrameRef = ((MediaAction) hud.currentRule().get() 126 .getAction()).getRef(); 127 absSelFrameRef = hud.holder().get().getRef().append(selectedFrameRef); 125 .getAction()).getReferences().get(0); 126 if (selectedFrameRef != null) { 127 absSelFrameRef = hud.holder().get().getRef().append(selectedFrameRef); 128 } 128 129 } 129 130 130 131 PageH page = pwa.getRootPageView().model().get(); -
src/main/java/org/sophie2/main/func/media/links/PauseMediaActionPersister.java
32 32 33 33 ValueRef<ResourceRefR4> frameRef = new ValueRef<ResourceRefR4>(); 34 34 if (options.isSaveMode()) { 35 frameRef.set(source.get().getRef ());35 frameRef.set(source.get().getReferences().get(0)); 36 36 } 37 37 38 38 MasterPersister.persist(frameRef, target.child("frame"), -
src/main/java/org/sophie2/main/func/media/links/MediaAction.java
1 1 package org.sophie2.main.func.media.links; 2 2 3 import java.util.ArrayList; 4 import java.util.List; 5 3 6 import org.sophie2.base.model.book.links.LinkAction; 4 7 import org.sophie2.base.model.resources.r4.ResourceRefR4; 5 import org.sophie2.base.model.resources.r4. immutables.ResourceRefWrapper;8 import org.sophie2.base.model.resources.r4.model.ResourceReferrer; 6 9 import org.sophie2.main.func.media.model.contents.MediaFrameR4; 7 10 8 11 /** … … 10 13 * 11 14 * @author diana 12 15 */ 13 public abstract class MediaAction extends LinkAction implements ResourceRefWrapper { 16 public abstract class MediaAction extends LinkAction 17 implements ResourceReferrer<MediaAction> { 14 18 15 private final ResourceRefR4 mediaView; 19 /** 20 * Ref to the controlled media frame. 21 */ 22 protected final ResourceRefR4 mediaFrame; 16 23 17 24 /** 18 25 * Constructor of the class. … … 21 28 * The reference to the controlled {@link MediaFrameR4}. 22 29 */ 23 30 public MediaAction(ResourceRefR4 mediaViewRef) { 24 this.media View= mediaViewRef;31 this.mediaFrame = mediaViewRef; 25 32 } 26 33 27 34 28 35 @Override 29 36 public int hashCode() { 30 37 return super.hashCode() + (31 * 31 ( getRef() == null ? 0 : getRef().hashCode()));38 (this.mediaFrame == null ? 0 : this.mediaFrame.hashCode())); 32 39 } 33 40 34 41 @Override … … 38 45 } 39 46 40 47 MediaAction action = (MediaAction) obj; 41 if (action. getRef()!= null) {42 return action. getRef().equals(getRef());48 if (action.mediaFrame != null) { 49 return action.mediaFrame.equals(this.mediaFrame); 43 50 } 44 return (action. getRef() == null) == (getRef()== null);51 return (action.mediaFrame == null) == (this.mediaFrame == null); 45 52 } 46 public ResourceRefR4 getRef() { 47 return this.mediaView; 53 54 public List<ResourceRefR4> getReferences() { 55 ArrayList<ResourceRefR4> res = new ArrayList<ResourceRefR4>(); 56 res.add(this.mediaFrame); 57 return res; 48 58 } 49 public abstract MediaAction setRef(ResourceRefR4 ref); 59 50 60 } -
src/main/java/org/sophie2/main/func/media/links/RewindMediaActionPersister.java
32 32 33 33 ValueRef<ResourceRefR4> frameRef = new ValueRef<ResourceRefR4>(); 34 34 if (options.isSaveMode()) { 35 frameRef.set(source.get().getRef ());35 frameRef.set(source.get().getReferences().get(0)); 36 36 } 37 37 38 38 MasterPersister.persist(frameRef, target.child("frame"), -
src/main/java/org/sophie2/main/func/media/links/MediaActionLogic.java
170 170 ResourceAccess access = event.getEventParam( 171 171 LinkEvent.RESOURCE_ACCESS_PARAM_INDEX, ResourceAccess.class); 172 172 173 ResourceRefR4 mediaFrameRef = action.getRef ();173 ResourceRefR4 mediaFrameRef = action.getReferences().get(0); 174 174 if (mediaFrameRef == null) { 175 175 return null; 176 176 } -
src/main/java/org/sophie2/main/func/media/links/MediaRewindAction.java
1 1 package org.sophie2.main.func.media.links; 2 2 3 import java.util.Map; 4 3 5 import org.sophie2.base.model.resources.r4.ResourceRefR4; 4 6 import org.sophie2.core.prolib.annot.Immutable; 5 7 … … 25 27 public String getDescription() { 26 28 return "Rewind Media"; 27 29 } 28 @Override 29 public MediaRewindAction setRef(ResourceRefR4 newRef) { 30 return new MediaRewindAction(newRef); 30 31 public MediaRewindAction fixReferences( 32 Map<ResourceRefR4, ResourceRefR4> replaces) { 33 return new MediaRewindAction(replaces.get(this.mediaFrame)); 31 34 } 32 35 33 36 } 37 No newline at end of file -
src/main/java/org/sophie2/main/func/media/links/PlayMediaActionPersister.java
32 32 33 33 ValueRef<ResourceRefR4> frameRef = new ValueRef<ResourceRefR4>(); 34 34 if (options.isSaveMode()) { 35 frameRef.set(source.get().getRef ());35 frameRef.set(source.get().getReferences().get(0)); 36 36 } 37 37 38 38 MasterPersister.persist(frameRef, target.child("frame"), -
src/main/java/org/sophie2/main/func/media/links/MediaStopAction.java
1 1 package org.sophie2.main.func.media.links; 2 2 3 import java.util.Map; 4 3 5 import org.sophie2.base.model.resources.r4.ResourceRefR4; 4 6 import org.sophie2.core.prolib.annot.Immutable; 5 7 … … 25 27 public String getDescription() { 26 28 return "Stop Media"; 27 29 } 28 @Override 29 public MediaStopAction setRef(ResourceRefR4 newRef) { 30 return new MediaStopAction(newRef); 30 31 public MediaStopAction fixReferences( 32 Map<ResourceRefR4, ResourceRefR4> replaces) { 33 return new MediaStopAction(replaces.get(this.mediaFrame)); 31 34 } 32 35 33 36 } -
src/main/java/org/sophie2/main/func/links/actions/showing/ShowFrameAction.java
#P org.sophie2.main.func.links
1 1 package org.sophie2.main.func.links.actions.showing; 2 2 3 import java.util.Map; 4 3 5 import org.sophie2.base.model.resources.r4.ResourceRefR4; 4 6 import org.sophie2.core.prolib.annot.Immutable; 5 7 … … 26 28 return "Show frame"; 27 29 } 28 30 29 @Override30 public ShowFrameAction setRef(ResourceRefR4 ref) {31 return new ShowFrameAction(re f);31 public FrameShowingAction fixReferences( 32 Map<ResourceRefR4, ResourceRefR4> replaces) { 33 return new ShowFrameAction(replaces.get(this.frame)); 32 34 } 33 35 34 36 } -
src/main/java/org/sophie2/main/func/links/actions/navigation/GoToPageAction.java
1 1 package org.sophie2.main.func.links.actions.navigation; 2 2 3 import java.util.ArrayList; 4 import java.util.List; 5 import java.util.Map; 6 3 7 import org.sophie2.base.model.book.links.LinkAction; 4 8 import org.sophie2.base.model.resources.r4.ResourceRefR4; 5 import org.sophie2.base.model.resources.r4. immutables.ResourceRefWrapper;9 import org.sophie2.base.model.resources.r4.model.ResourceReferrer; 6 10 import org.sophie2.core.prolib.annot.Immutable; 7 11 8 12 /** … … 11 15 * @author kyli 12 16 */ 13 17 @Immutable(kind="go-to-page-action") 14 public class GoToPageAction extends LinkAction implements ResourceRef Wrapper{18 public class GoToPageAction extends LinkAction implements ResourceReferrer<GoToPageAction> { 15 19 16 20 private final ResourceRefR4 page; 17 21 … … 33 37 @Override 34 38 public int hashCode() { 35 39 return super.hashCode() + (31 * 36 ( getRef() == null ? 0 : getRef().hashCode()));40 (this.page == null ? 0 : this.page.hashCode())); 37 41 } 38 42 39 43 @Override … … 43 47 } 44 48 45 49 GoToPageAction action = (GoToPageAction) obj; 46 if (action. getRef()!= null) {47 return action. getRef().equals(getRef());50 if (action.page != null) { 51 return action.page.equals(this.page); 48 52 } 49 return (action. getRef() == null) == (getRef()== null);53 return (action.page == null) == (this.page == null); 50 54 } 51 55 52 public ResourceRefR4 getRef() { 53 return this.page; 56 public GoToPageAction fixReferences( 57 Map<ResourceRefR4, ResourceRefR4> replaces) { 58 return new GoToPageAction(replaces.get(this.page)); 54 59 } 55 60 56 public ResourceRefWrapper setRef(ResourceRefR4 newRef) { 57 return new GoToPageAction(newRef); 61 public List<ResourceRefR4> getReferences() { 62 ArrayList<ResourceRefR4> res = new ArrayList<ResourceRefR4>(); 63 res.add(this.page); 64 return res; 58 65 } 59 66 60 67 } -
src/main/java/org/sophie2/main/func/links/actions/showing/ShowingActionLogic.java
141 141 ResourceAccess access = event.getEventParam( 142 142 LinkEvent.RESOURCE_ACCESS_PARAM_INDEX, ResourceAccess.class); 143 143 144 ResourceRefR4 frameRef = action.getRef ();144 ResourceRefR4 frameRef = action.getReferences().get(0); 145 145 if (frameRef == null) { 146 146 return null; 147 147 } -
src/main/java/org/sophie2/main/func/links/actions/navigation/NavigationActionsLogic.java
93 93 GoToPageAction action = event.getEventParam( 94 94 LinkEvent.ACTION_PARAM_INDEX, GoToPageAction.class); 95 95 96 if (action == null || action.getRef () == null) {96 if (action == null || action.getReferences().get(0) == null) { 97 97 return false; 98 98 } 99 99 100 100 ResourceAccess access = event.getEventParam( 101 101 LinkEvent.RESOURCE_ACCESS_PARAM_INDEX, ResourceAccess.class); 102 102 103 ResourceRefR4 pageRef = access.getRef().append(action.getRef ());103 ResourceRefR4 pageRef = access.getRef().append(action.getReferences().get(0)); 104 104 ResourceRefR4 relToBookPageRef = 105 105 ResourceRefR4.getRelativeRef(bv.getAccess().getRef(), pageRef); 106 106 if (bv.model().get().getIndexOf(relToBookPageRef) < 0) { -
src/main/java/org/sophie2/main/func/links/persist/ShowFrameActionPersister.java
34 34 ValueRef<ResourceRefR4> frame = new ValueRef<ResourceRefR4>() { 35 35 @Override 36 36 public ResourceRefR4 getInitial() { 37 return source.get().getRef ();37 return source.get().getReferences().get(0); 38 38 } 39 39 }; 40 40 -
src/main/java/org/sophie2/main/func/links/ConfigurationPanelsLogic.java
1 1 package org.sophie2.main.func.links; 2 2 3 import java.util.HashMap; 4 import java.util.Map; 5 3 6 import org.sophie2.base.bound.ComboInput; 4 7 import org.sophie2.base.bound.BoundControl.EventIds; 5 8 import org.sophie2.base.model.book.FrameH; … … 92 95 ResourceRefR4.getRelativeRef(holder.getRef(), targetFrame.getRef()); 93 96 94 97 assert currentRule.getAction() instanceof FrameShowingAction; 98 FrameShowingAction action = (FrameShowingAction)currentRule.getAction(); 99 Map<ResourceRefR4, ResourceRefR4> replaces = new HashMap<ResourceRefR4, ResourceRefR4>(); 100 replaces.put(action.getReferences().get(0), newRef); 101 FrameShowingAction newAction = action.fixReferences(replaces ); 95 102 96 FrameShowingAction newAction = (97 (FrameShowingAction)currentRule.getAction()).setRef(newRef);98 99 103 LinksUtil.addAction(hud, newAction); 100 104 } 101 105 } -
src/main/java/org/sophie2/main/func/links/persist/ToggleFrameActionPersister.java
34 34 ValueRef<ResourceRefR4> frame = new ValueRef<ResourceRefR4>() { 35 35 @Override 36 36 public ResourceRefR4 getInitial() { 37 return source.get().getRef ();37 return source.get().getReferences().get(0); 38 38 } 39 39 }; 40 40 -
src/main/java/org/sophie2/main/func/links/actions/showing/FrameShowingAction.java
1 1 package org.sophie2.main.func.links.actions.showing; 2 2 3 import java.util.ArrayList; 4 import java.util.List; 5 3 6 import org.sophie2.base.model.book.links.LinkAction; 4 7 import org.sophie2.base.model.resources.r4.ResourceRefR4; 5 import org.sophie2.base.model.resources.r4. immutables.ResourceRefWrapper;8 import org.sophie2.base.model.resources.r4.model.ResourceReferrer; 6 9 7 10 /** 8 11 * Base class for {@link ShowFrameAction}, {@link HideFrameAction} and … … 10 13 * 11 14 * @author kyli 12 15 */ 13 public abstract class FrameShowingAction extends LinkAction implements ResourceRef Wrapper{16 public abstract class FrameShowingAction extends LinkAction implements ResourceReferrer<FrameShowingAction>{ 14 17 15 private final ResourceRefR4 frame; 18 /** 19 * The frame pointed by this action. 20 */ 21 protected final ResourceRefR4 frame; 16 22 17 23 /** 18 24 * Constructor. … … 22 28 super(); 23 29 this.frame = frame; 24 30 } 25 26 public ResourceRefR4 getRef() {27 return this.frame;28 }29 30 /**31 * Returns a new action with the desired ref.32 * Override to provide a specific return type.33 *34 * @param ref35 * The new {@link ResourceRefR4}.36 * @return37 * The new action.38 */39 public abstract FrameShowingAction setRef(ResourceRefR4 ref);40 31 41 32 @Override 42 33 public int hashCode() { 43 34 return super.hashCode() + (31 * 44 ( getRef() == null ? 0 : getRef().hashCode()));35 (this.frame == null ? 0 : this.frame.hashCode())); 45 36 } 46 37 47 38 @Override … … 51 42 } 52 43 53 44 FrameShowingAction action = (FrameShowingAction) obj; 54 if (action. getRef()!= null) {55 return action. getRef().equals(getRef());45 if (action.frame != null) { 46 return action.frame.equals(this.frame); 56 47 } 57 return (action. getRef() == null) == (getRef()== null);48 return (action.frame == null) == (this.frame == null); 58 49 } 59 50 51 public List<ResourceRefR4> getReferences() { 52 ArrayList<ResourceRefR4> res = new ArrayList<ResourceRefR4>(); 53 res.add(this.frame); 54 return res; 55 } 56 60 57 } -
src/main/java/org/sophie2/main/func/links/actions/showing/ShowFrameConfigurationPanel.java
124 124 && hud.holder().get() != null 125 125 && hud.currentRule().get() != null 126 126 && hud.currentRule().get().getAction() != null 127 && hud.currentRule().get().getAction() instanceof FrameShowingAction 128 && ((FrameShowingAction) hud.currentRule().get().getAction()).getRef() != null) { 127 && hud.currentRule().get().getAction() instanceof FrameShowingAction) { 129 128 ResourceRefR4 selectedFrameRef = ((FrameShowingAction) hud.currentRule().get() 130 .getAction()).getRef(); 131 absSelFrameRef = hud.holder().get().getRef().append(selectedFrameRef); 129 .getAction()).getReferences().get(0); 130 if (selectedFrameRef != null) { 131 absSelFrameRef = hud.holder().get().getRef().append(selectedFrameRef); 132 } 132 133 } 133 134 134 135 PageH page = pwa.getRootPageView().model().get(); -
src/main/java/org/sophie2/main/func/links/actions/navigation/GoToPageConfigurationPanel.java
122 122 && hud.holder().get() != null 123 123 && hud.currentRule().get() != null 124 124 && hud.currentRule().get().getAction() != null 125 && hud.currentRule().get().getAction() instanceof GoToPageAction 126 && ((GoToPageAction) hud.currentRule().get().getAction()).getRef() != null) { 127 ResourceRefR4 rulePageRef = 128 ((GoToPageAction) hud.currentRule().get().getAction()).getRef(); 129 absRulePageRef = hud.holder().get().getRef().append(rulePageRef); 125 && hud.currentRule().get().getAction() instanceof GoToPageAction){ 126 ResourceRefR4 rulePageRef = ((GoToPageAction) hud.currentRule().get().getAction() 127 ).getReferences().get(0); 128 129 if (rulePageRef != null) { 130 absRulePageRef = hud.holder().get().getRef().append(rulePageRef); 131 } 130 132 } 131 133 PageH rulePage = null; 132 134 BookH book = bv.model().get(); -
src/main/java/org/sophie2/main/func/links/actions/showing/HideFrameAction.java
1 1 package org.sophie2.main.func.links.actions.showing; 2 2 3 import java.util.Map; 4 3 5 import org.sophie2.base.model.resources.r4.ResourceRefR4; 4 6 import org.sophie2.core.prolib.annot.Immutable; 5 7 6 7 8 8 /** 9 9 * Hides a frame. 10 10 * … … 12 12 */ 13 13 @Immutable(kind="hide-frame-action") 14 14 public class HideFrameAction extends FrameShowingAction { 15 15 16 16 /** 17 17 * Default constructor. 18 18 * … … 28 28 return "Hide frame"; 29 29 } 30 30 31 @Override32 public HideFrameAction setRef(ResourceRefR4 ref) {33 return new HideFrameAction(re f);31 public FrameShowingAction fixReferences( 32 Map<ResourceRefR4, ResourceRefR4> replaces) { 33 return new HideFrameAction(replaces.get(this.frame)); 34 34 } 35 35 36 36 } -
src/main/java/org/sophie2/main/func/links/actions/showing/ToggleFrameAction.java
1 1 package org.sophie2.main.func.links.actions.showing; 2 2 3 import java.util.Map; 4 3 5 import org.sophie2.base.model.resources.r4.ResourceRefR4; 4 6 import org.sophie2.core.prolib.annot.Immutable; 5 7 … … 26 28 return "Toggle frame"; 27 29 } 28 30 29 @Override30 public ToggleFrameAction setRef(ResourceRefR4 ref) {31 return new ToggleFrameAction(re f);31 public FrameShowingAction fixReferences( 32 Map<ResourceRefR4, ResourceRefR4> replaces) { 33 return new ToggleFrameAction(replaces.get(this.frame)); 32 34 } 33 34 35 } -
src/main/java/org/sophie2/main/func/links/persist/HideFrameActionPersister.java
34 34 ValueRef<ResourceRefR4> frame = new ValueRef<ResourceRefR4>() { 35 35 @Override 36 36 public ResourceRefR4 getInitial() { 37 return source.get().getRef ();37 return source.get().getReferences().get(0); 38 38 } 39 39 }; 40 40 -
src/main/java/org/sophie2/main/func/links/persist/GoToPageActionPersister.java
35 35 ValueRef<ResourceRefR4> page = new ValueRef<ResourceRefR4>() { 36 36 @Override 37 37 public ResourceRefR4 getInitial() { 38 return source.get().getRef ();38 return source.get().getReferences().get(0); 39 39 } 40 40 }; 41 41 -
src/main/java/org/sophie2/main/func/resources/logic/ResourceDeleteLogic.java
#P org.sophie2.main.func.resources
1 1 package org.sophie2.main.func.resources.logic; 2 2 3 import java.util.ArrayList;4 3 import java.util.List; 4 import java.util.Map; 5 5 6 6 import org.sophie2.base.dialogs.DialogManager; 7 7 import org.sophie2.base.layout.model.ListPaletteItem; … … 9 9 import org.sophie2.base.model.book.ElementH; 10 10 import org.sophie2.base.model.book.FrameH; 11 11 import org.sophie2.base.model.book.PageH; 12 import org.sophie2.base.model.book.interfaces.ResourceFrame;13 12 import org.sophie2.base.model.book.resource.r4.BookR4; 14 13 import org.sophie2.base.model.resources.r4.ResourceRefList; 15 14 import org.sophie2.base.model.resources.r4.ResourceRefR4; 16 15 import org.sophie2.base.model.resources.r4.access.ResourceAccess; 17 16 import org.sophie2.base.model.resources.r4.changes.AutoAction; 17 import org.sophie2.base.model.resources.r4.keys.Key; 18 import org.sophie2.base.model.resources.r4.model.ResourceReferrer; 18 19 import org.sophie2.base.model.resources.r4.resources.ResourceH; 19 20 import org.sophie2.base.model.resources.r4.resources.ResourceR4; 20 21 import org.sophie2.core.mvc.EventFilterBuilder; … … 39 40 * @author diana 40 41 */ 41 42 public enum ResourceDeleteLogic implements OperationDef { 42 43 43 44 /** 44 45 * Handles the deleting of the existing resources in the book. 45 46 */ … … 54 55 public boolean handle(EventR3 event) { 55 56 DeleteResourceButton source = event.getSource(DeleteResourceButton.class); 56 57 ResourceDetailsPalette palette = source.findParentElement(ResourceDetailsPalette.class); 57 58 58 59 assert palette != null : "The source must not be null!"; 59 60 60 61 BookDocView bookDocView = palette.findNearestElement(null, BookDocView.class); … … 69 70 ConfirmDialogInput input = new ConfirmDialogInput(null, 70 71 "Are you sure you want to delete this resource?", "Warning", false); 71 72 ConfirmDialogInput.Response result = DialogManager.get().showDialog(input); 72 73 73 74 if (result == ConfirmDialogInput.Response.NO 74 75 || result == ConfirmDialogInput.Response.CLOSED) { 75 76 return true; 76 77 } 77 78 78 79 ResourceH resource = ((ResourceItem) selectedItem).resource().get(); 79 80 if (!(resource instanceof ElementH)) { 80 if (!is MainResourceUsed(resource, bookDocView)) {81 if (!isResourceUsed(resource, bookDocView.model().get())) { 81 82 return deleteMainResource(resource, bookDocView); 82 83 } 83 84 84 85 showUserMsg("The selected resource is currently in use."); 85 86 return true; 86 87 } 87 88 88 89 return deleteResource(source, (ElementH)resource, bookDocView); 89 90 } 90 91 private boolean isMainResourceUsed(ResourceH resource, BookDocView bookDocView) { 92 List<FrameView> allFrameViews = getAllFrameViews(bookDocView); 93 ResourceRefR4 resourceRef = resource.getAccess().getRef(); 94 95 for (FrameView frameView : allFrameViews) { 96 String resName = 97 ResourceFrame.KEY_MAIN_RESOURCE.get(frameView.getAccess()).getName(); 98 99 if (resName.equals(resourceRef.getName())) { 100 return true; 91 92 private boolean isResourceUsed(ResourceH resource, ResourceH parent) { 93 ResourceRefR4 resourceRef = resource.getRef(); 94 Class<ResourceR4> clazz = ResourceR4.getClassByKind(parent.getKind()); 95 Map<String, Key<?>> keys = ResourceR4.getKnownKeys(clazz); 96 for (Key<?> key : keys.values()) { 97 98 if (contains(key.getValueClass().getInterfaces(), ResourceReferrer.class)) { 99 ResourceReferrer<?> referrer = 100 (ResourceReferrer<?>) key.get(parent.getAccess()); 101 List<ResourceRefR4> pointedRefs = referrer.getReferences(); 102 for (ResourceRefR4 ref : pointedRefs) { 103 if (ref.isRelative()) { 104 ref = parent.getRef().append(ref); 105 } 106 if (resourceRef.equals(ref)) { 107 return true; 108 } 109 } 101 110 } 102 111 } 103 112 ResourceRefList children = parent.getChildren(); 113 if (children != null) { 114 for (ResourceRefR4 childRef : children) { 115 ResourceAccess childAccess = parent.getAccess().open(childRef, null); 116 ResourceH child = ResourceH.getHelper(childAccess); 117 if (isResourceUsed(resource, child)) { 118 return true; 119 } 120 } 121 } 104 122 return false; 105 123 } 106 107 private List<FrameView> getAllFrameViews(BookDocView bookDocView) { 108 List<FrameView> availableViews = new ArrayList<FrameView>(); 109 BookView bookView = bookDocView.bookView().get(); 110 111 for (ResourceRefR4 pageRef : bookView.model().get().getPages()) { 112 RootPageView rootPageView = bookView.getPageView(pageRef); 113 List<FrameView> pageFrameView = rootPageView.getAll(FrameView.class); 114 availableViews.addAll(pageFrameView); 124 125 private boolean contains(Class<?>[] interfaces, Class<?> lookFor) { 126 for (Class<?> clazz : interfaces) { 127 if (clazz.equals(lookFor)) { 128 return true; 129 } 115 130 } 116 117 return availableViews; 131 return false; 118 132 } 119 133 120 134 private void showUserMsg(String text) { 121 DialogUtils.showErrorDialog(null, text, "Cannot delete it.");135 DialogUtils.showErrorDialog(null, text, "Cannot delete it."); 122 136 } 123 137 124 138 private boolean deleteMainResource(ResourceH resource, BookDocView bookDocView) { 125 139 ResourceAccess bookAccess = bookDocView.bookView().get().getAccess(); 126 140 if (resource.getRef().equals(bookAccess.getRef())) {//the resource is the book 127 141 showUserMsg("The resource to delete should not be book resource."); 128 142 return true; 129 143 } 130 144 131 145 final ResourceRefR4 resourceRef = resource.getRef().getThisChildRef(); 132 146 new AutoAction("Remove Main Resource", true) { 133 147 @Override … … 136 150 } 137 151 138 152 }.register(bookAccess); 139 153 140 154 return true; 141 155 } 142 156 143 157 private boolean deleteResource(DeleteResourceButton source, ElementH resource, BookDocView bookDocView) { 144 158 ElementView view = null; 145 159 146 160 if (resource instanceof PageH) { 147 161 //if the resource is a page template 148 162 final ResourceRefR4 pageRef = resource.getRef().getThisChildRef(); 149 163 ResourceRefList pageTemplates = BookR4.KEY_PAGE_TEMPLATES.get(bookDocView.getAccess()); 150 164 int pageTemplateNumber = containing(pageTemplates,pageRef); 151 165 152 166 if (pageTemplateNumber != -1) { 153 167 boolean isUsedPageTemplate = isUsedPageTemplate(resource.getRef().getThisChildRef(), bookDocView); 154 168 155 169 if (isUsedPageTemplate) { 156 170 showUserMsg("The page template is currently in use."); 157 171 return true; 158 172 } 159 173 160 174 final ResourceRefList finalPageTemplateList = pageTemplates.remove(pageTemplateNumber); 161 175 new AutoAction("Set New Page Template List", false) { 162 176 @Override … … 167 181 168 182 }.register(bookDocView.getAccess()); 169 183 return true; 170 184 171 185 } 172 186 view = bookDocView.bookView().get().getPageView(resource.getRef().getThisChildRef()); 173 187 174 188 } else if(resource instanceof FrameH) { 175 189 //if frame template 176 190 final ResourceRefR4 frameRef = resource.getRef().getThisChildRef(); 177 191 ResourceRefList frameTemplates = BookR4.KEY_FRAME_TEMPLATES.get(bookDocView.getAccess()); 178 192 int frameTemplateNumber = containing(frameTemplates, frameRef); 179 193 180 194 boolean isUsed = isUsedFrameTemplate(frameRef, bookDocView); 181 195 if (isUsed) { 182 196 showUserMsg("The frame template is currently in use."); 183 197 return true; 184 198 } 185 199 186 200 if (frameTemplateNumber != -1 && ! isUsed) { 187 201 final ResourceRefList finalFrameTemplateList = 188 202 frameTemplates.remove(frameTemplateNumber); … … 203 217 ResourceRefR4 grRef = resource.getRef().getThisChildRef(); 204 218 view = findView(grRef, bookDocView.bookView().get(), GroupView.class); 205 219 } 206 220 207 221 if (view != null) { 208 222 LogicR3.fire(source,bookDocView,null,null,BookView.EventIds.ELEMENT_DELETED, view); 209 223 } 210 224 211 225 return true; 212 226 } 213 227 … … 217 231 return i; 218 232 } 219 233 } 220 234 221 235 return -1; 222 236 } 223 237 224 238 private boolean isUsedPageTemplate(ResourceRefR4 pageTemplate, BookDocView bookDocView) { 225 239 BookView bookView = bookDocView.bookView().get(); 226 240 227 241 for (ResourceRefR4 page : bookView.model().get().getPages()) { 228 242 RootPageView pageView = bookView.getPageView(page); 229 243 ResourceRefR4 currentTemplate = ResourceRefR4.NONE_REF; 230 244 231 245 if (!ResourceR4.KEY_TEMPLATE.get(pageView.getAccess()).equals(currentTemplate)) { 232 246 currentTemplate = ResourceR4.KEY_TEMPLATE.get(pageView.getAccess()). 233 247 getThisChildRef(); 234 248 } 235 249 236 250 if (currentTemplate.equals(pageTemplate)) { 237 251 return true; 238 252 } … … 240 254 } 241 255 return false; 242 256 } 243 257 244 258 private boolean isUsedFrameTemplate(ResourceRefR4 frameTemplate, BookDocView bookDocView) { 245 259 BookView bookView = bookDocView.bookView().get(); 246 260 for (ResourceRefR4 page : bookView.model().get().getPages()) { 247 261 RootPageView pageView = bookView.getPageView(page); 248 262 List<FrameView> frames = pageView.getAll(FrameView.class); 249 263 250 264 for (FrameView frame : frames) { 251 265 ResourceRefR4 currentTemplate = ResourceRefR4.NONE_REF; 252 266 if (!ResourceR4.KEY_TEMPLATE.get(frame.getAccess()).equals(currentTemplate)) { … … 261 275 } 262 276 return false; 263 277 } 264 278 265 279 private ElementView findView(ResourceRefR4 groupRef, BookView bookView, 266 280 Class<? extends ElementView> searchedClass) { 267 281 for (ResourceRefR4 pageRef : bookView.model().get().getPages()) { … … 272 286 } 273 287 } 274 288 } 275 289 276 290 return null; 277 291 } 278 292 } -
src/main/java/org/sophie2/base/model/book/links/Link.java
#P org.sophie2.base.model.book
1 1 package org.sophie2.base.model.book.links; 2 2 3 import java.util.ArrayList; 4 import java.util.List; 5 import java.util.Map; 6 3 7 import org.sophie2.base.commons.util.ImmList; 4 8 import org.sophie2.base.commons.util.NaiveImmList; 5 import org.sophie2.base.model.resources.r4.ResourceRefList;6 9 import org.sophie2.base.model.resources.r4.ResourceRefR4; 7 import org.sophie2.base.model.resources.r4.immutables.ResourceRefHolder; 8 import org.sophie2.base.model.resources.r4.immutables.ResourceRefWrapper; 10 import org.sophie2.base.model.resources.r4.model.ResourceReferrer; 9 11 import org.sophie2.core.prolib.annot.Immutable; 10 12 11 13 /** … … 14 16 * @author boyan 15 17 */ 16 18 @Immutable(kind="link") 17 public class Link implements ResourceRef Holder{18 19 public class Link implements ResourceReferrer<Link> { 20 19 21 /** 20 22 * A link with no parent resource and no rules. 21 23 */ … … 36 38 public Link(ImmList<LinkRule> rules) { 37 39 this(rules, false); 38 40 } 39 41 40 42 private Link(ImmList<LinkRule> rules, boolean visited) { 41 43 this.rules = rules; 42 44 this.visited = visited; … … 74 76 public Link setVisited(boolean visited) { 75 77 return new Link(this.rules, visited); 76 78 } 77 79 78 80 /** 79 81 * Checks whether this Link has been visited, 80 82 * i.e. at least one of its actions has been executed at least once. … … 85 87 public boolean isVisited() { 86 88 return this.visited; 87 89 } 88 89 public ResourceRefList getRefs() {90 ResourceRefList res = ResourceRefList.EMPTY;90 91 public List<ResourceRefR4> getReferences() { 92 List<ResourceRefR4> res = new ArrayList<ResourceRefR4>(); 91 93 for (LinkRule rule : getRules()) { 92 94 LinkAction action = rule.getAction(); 93 if (action instanceof ResourceRefWrapper) { 94 ResourceRefR4 ref = ((ResourceRefWrapper)action).getRef(); 95 res = res.add(ref); 96 } else { 97 res = res.add(ResourceRefR4.NONE_REF); 95 if (action instanceof ResourceReferrer<?>) { 96 res.addAll(((ResourceReferrer<?>)action).getReferences()); 98 97 } 99 98 } 100 99 return res; 101 100 } 102 101 103 public ResourceRefHolder rewriteRefs(ResourceRefList rewritenRefs) {104 ImmList<LinkRule> newRules = NaiveImmList.<LinkRule>getEmpty();105 for (int i = 0; i < this.rules.size(); i++) {106 LinkRule rule = this.rules.get(i);102 public Link fixReferences(Map<ResourceRefR4, ResourceRefR4> replaces) { 103 ImmList<LinkRule> newRules = this.rules; 104 for (int i = 0; i < newRules.size(); i++) { 105 LinkRule rule = newRules.get(i); 107 106 LinkAction action = rule.getAction(); 108 if (action instanceof ResourceRefWrapper) { 109 ResourceRefWrapper wrapper = (ResourceRefWrapper)action; 110 LinkAction rewritenAction = (LinkAction) 111 wrapper.setRef(rewritenRefs.get(i)); 112 newRules = newRules.add( 113 new LinkRule(rule.getTrigger(), rewritenAction)); 114 } else { 115 newRules = newRules.add(rule); 107 if (action instanceof ResourceReferrer<?>) { 108 ResourceReferrer<?> referrerer = (ResourceReferrer<?>)action; 109 List<ResourceRefR4> refs = referrerer.getReferences(); 110 assert (refs.size() == 1) : "The action should have only one ref"; 111 ResourceRefR4 replaceRef = replaces.get(refs.get(0)); 112 if (replaceRef != null) { 113 LinkAction rewritenAction = (LinkAction) referrerer.fixReferences(replaces); 114 newRules = newRules.set(i, new LinkRule(rule.getTrigger(), rewritenAction)); 115 } 116 116 117 } 117 118 } 118 119 return new Link(newRules); 119 120 } 121 120 122 } -
src/main/java/org/sophie2/extra/func/scripting/links/RunScriptAction.java
#P org.sophie2.extra.func.scripting
1 1 package org.sophie2.extra.func.scripting.links; 2 2 3 import java.util.ArrayList; 4 import java.util.List; 5 import java.util.Map; 6 3 7 import org.sophie2.base.model.book.links.LinkAction; 4 8 import org.sophie2.base.model.resources.r4.ResourceRefR4; 5 import org.sophie2.base.model.resources.r4. immutables.ResourceRefWrapper;9 import org.sophie2.base.model.resources.r4.model.ResourceReferrer; 6 10 import org.sophie2.core.prolib.annot.Immutable; 7 11 8 12 /** … … 12 16 * @author deni, mitex 13 17 */ 14 18 @Immutable(kind="run-script-action") 15 public class RunScriptAction extends LinkAction implements ResourceRefWrapper{ 16 19 public class RunScriptAction extends LinkAction 20 implements ResourceReferrer<RunScriptAction>{ 21 17 22 private final ResourceRefR4 script; 18 23 19 24 /** 20 25 * Constructor. 21 26 * @param script The script to execute … … 29 34 public String getDescription() { 30 35 return "Run script..."; 31 36 } 32 37 33 38 @Override 34 39 public int hashCode() { 35 40 return super.hashCode() + (31 * 36 ( getRef() == null ? 0 : getRef().hashCode()));41 (this.script == null ? 0 : this.script.hashCode())); 37 42 } 38 43 39 44 @Override 40 45 public boolean equals(Object obj) { 41 46 if (!super.equals(obj)) { 42 47 return false; 43 48 } 44 49 45 50 RunScriptAction action = (RunScriptAction) obj; 46 if (action. getRef()!= null) {47 return action. getRef().equals(getRef());51 if (action.script != null) { 52 return action.script.equals(this.script); 48 53 } 49 return (action. getRef() == null) == (getRef()== null);54 return (action.script == null) == (this.script == null); 50 55 } 51 56 52 public ResourceRefR4 getRef() { 53 return this.script; 57 public RunScriptAction fixReferences( 58 Map<ResourceRefR4, ResourceRefR4> replaces) { 59 return new RunScriptAction(replaces.get(this.script)); 54 60 } 55 61 56 public ResourceRefWrapper setRef(ResourceRefR4 newRef) { 57 return new RunScriptAction(newRef); 62 public List<ResourceRefR4> getReferences() { 63 ArrayList<ResourceRefR4> res = new ArrayList<ResourceRefR4>(); 64 res.add(this.script); 65 return res; 58 66 } 59 67 } -
src/main/java/org/sophie2/extra/func/scripting/links/RunScriptConfigurationPanel.java
129 129 && hud.holder().get() != null 130 130 && hud.currentRule().get() != null 131 131 && hud.currentRule().get().getAction() != null 132 && hud.currentRule().get().getAction() instanceof RunScriptAction 133 && ((RunScriptAction) hud.currentRule().get().getAction()).getRef() != null) { 134 ruleScript = ((RunScriptAction) hud.currentRule().get().getAction()).getRef(); 132 && hud.currentRule().get().getAction() instanceof RunScriptAction) { 133 ResourceRefR4 ref = ((RunScriptAction) hud.currentRule().get().getAction()).getReferences().get(0); 134 if (ref != null) { 135 ruleScript = ref; 136 } 135 137 } 136 138 ScriptResourceH ruleScriptH = null; 137 139 BookH book = bdv.model().get(); -
src/main/java/org/sophie2/extra/func/scripting/model/persistence/RunScriptActionPersister.java
35 35 ValueRef<ResourceRefR4> script = new ValueRef<ResourceRefR4>() { 36 36 @Override 37 37 public ResourceRefR4 getInitial() { 38 return ref.get().getRef ();38 return ref.get().getReferences().get(0); 39 39 } 40 40 }; 41 41 -
src/main/java/org/sophie2/extra/func/scripting/logic/RunScriptLogic.java
136 136 137 137 BookView bookView = event.getSource(BookView.class); 138 138 139 ResourceRefR4 scriptRef = action.getRef ();139 ResourceRefR4 scriptRef = action.getReferences().get(0); 140 140 ResourceAccess access = event.getEventParam( 141 141 LinkEvent.RESOURCE_ACCESS_PARAM_INDEX, ResourceAccess.class); 142 142 ResourceAccess scriptAccess = access.open(scriptRef, null); -
src/main/java/org/sophie2/base/model/resources/r4/changes/ModelResourceChanger.java
#P org.sophie2.base.model.resources.r4
2 2 3 3 import java.util.ArrayList; 4 4 import java.util.Collection; 5 import java.util.HashMap; 5 6 import java.util.List; 7 import java.util.Map; 6 8 7 9 import org.sophie2.base.commons.util.ImmList; 8 import org.sophie2.base.model.resources.r4.ResourceRefList;9 10 import org.sophie2.base.model.resources.r4.ResourceRefR4; 10 11 import org.sophie2.base.model.resources.r4.immutables.NaiveSubEntryNames; 11 import org.sophie2.base.model.resources.r4.immutables.ResourceRefHolder;12 12 import org.sophie2.base.model.resources.r4.immutables.SubEntryNames; 13 13 import org.sophie2.base.model.resources.r4.keys.ChildrenKey; 14 14 import org.sophie2.base.model.resources.r4.keys.Key; 15 15 import org.sophie2.base.model.resources.r4.keys.RootKey; 16 16 import org.sophie2.base.model.resources.r4.keys.UndefinedKey; 17 17 import org.sophie2.base.model.resources.r4.model.ResourceModel; 18 import org.sophie2.base.model.resources.r4.model.ResourceReferrer; 18 19 import org.sophie2.base.model.resources.r4.resources.RedirectR4; 19 20 import org.sophie2.base.model.resources.r4.resources.ResourceR4; 20 21 … … 168 169 return; 169 170 } 170 171 171 if (current instanceof ResourceRefR4) { 172 current = (T) rewriteRef(source, destination,(ResourceRefR4) current); 173 } 174 175 if (current instanceof ResourceRefHolder) { 176 ResourceRefHolder holder = (ResourceRefHolder) current; 177 ResourceRefList rewritenRefs = ResourceRefList.EMPTY; 178 ResourceRefList list = holder.getRefs(); 179 for (ResourceRefR4 oldRef : list) { 172 if (current instanceof ResourceReferrer<?>) { 173 ResourceReferrer<?> referer = (ResourceReferrer<?>) current; 174 List<ResourceRefR4> oldRefs = referer.getReferences(); 175 Map<ResourceRefR4, ResourceRefR4> replaces = 176 new HashMap<ResourceRefR4, ResourceRefR4>(); 177 for (ResourceRefR4 oldRef : oldRefs) { 180 178 ResourceRefR4 correctRef = rewriteRef(source, destination, oldRef); 181 rewritenRefs = rewritenRefs.add(correctRef); 179 if (!oldRef.equals(correctRef)) { 180 replaces.put(oldRef, correctRef); 181 } 182 182 } 183 current = (T) holder.rewriteRefs(rewritenRefs);183 current = (T) referer.fixReferences(replaces); 184 184 } 185 185 186 186 setRaw(destKey, current); -
src/main/java/org/sophie2/base/model/resources/r4/immutables/ResourceRefWrapper.java
1 package org.sophie2.base.model.resources.r4.immutables;2 3 import org.sophie2.base.model.resources.r4.ResourceRefR4;4 import org.sophie2.core.prolib.annot.Immutable;5 6 /**7 * Interface used by to manipulate resource refs that are wrapped.8 *9 * @author mira10 */11 @Immutable12 public interface ResourceRefWrapper {13 14 /**15 * Gets the ref of this <code>ResourceRefWrapper</code>.16 *17 * @return18 * ResourceRefR4 wrapped by this immutable.19 */20 public ResourceRefR4 getRef();21 22 /**23 * Method used for producing <code>ResourceRefWrapper</code>s identical24 * to this one but with different <code>ResourceRefR4</code>.25 *26 * @param newRef27 * The ref to be set to the new wrapper.28 *29 * @return30 * New <code>ResourceRefWrapper</code> that is copy of this one31 * but with different ref.32 */33 public ResourceRefWrapper setRef(ResourceRefR4 newRef);34 35 } -
src/main/java/org/sophie2/base/model/resources/r4/immutables/ResourceRefHolder.java
1 package org.sophie2.base.model.resources.r4.immutables;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.ResourceChanger;6 import org.sophie2.core.prolib.annot.Immutable;7 8 /**9 * Interface used by the {@link ResourceChanger} to manipulate10 * {@link Immutable}s that contain {@link ResourceRefR4}s11 *12 * @author mira13 */14 @Immutable15 public interface ResourceRefHolder {16 17 /**18 * Gets the refs this <code>ResourceRefHolder</code> holds.19 *20 * @return21 * ResourceRefList of all refs held by this immutable.22 */23 public ResourceRefList getRefs();24 25 /**26 * Method used for producing <code>ResourceRefHolder</code>s27 * from this one but with different refs.28 *29 * @param rewritenRefs30 * The rewritten refs that should be set to the new holder.31 *32 * @return33 * New <code>ResourceRefHolder</code> that is copy of this one34 * but with rewritten refs.35 */36 public ResourceRefHolder rewriteRefs(ResourceRefList rewritenRefs);37 38 }39 No newline at end of file