Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlois Zoitl2018-05-11 15:21:19 +0000
committerAlois Zoitl2018-05-11 15:21:19 +0000
commit0a36b4b9a837329524e3390fa88b910bec14ae69 (patch)
tree0c4d31803fea4f3fa1553a57109e55856c0f61c8
parent910bb32187dcddf53f11fe7431370b4c47b558be (diff)
downloadorg.eclipse.4diac.ide-0a36b4b9a837329524e3390fa88b910bec14ae69.tar.gz
org.eclipse.4diac.ide-0a36b4b9a837329524e3390fa88b910bec14ae69.tar.xz
org.eclipse.4diac.ide-0a36b4b9a837329524e3390fa88b910bec14ae69.zip
[533957] Update fb type correctly handles mapped FBs
this fixe now adds checks for also recreating resoruce connectiosn taht the remapping of the udpate FB would not create. Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=533957 Signed-off-by: Alois Zoitl <alois.zoitl@gmx.at>
-rw-r--r--plugins/org.eclipse.fordiac.ide.model.commands/src/org/eclipse/fordiac/ide/model/commands/change/UnmapCommand.java4
-rw-r--r--plugins/org.eclipse.fordiac.ide.model.commands/src/org/eclipse/fordiac/ide/model/commands/change/UpdateFBTypeCommand.java168
-rw-r--r--plugins/org.eclipse.fordiac.ide.model.commands/src/org/eclipse/fordiac/ide/model/commands/delete/DeleteFBNetworkElementCommand.java4
3 files changed, 121 insertions, 55 deletions
diff --git a/plugins/org.eclipse.fordiac.ide.model.commands/src/org/eclipse/fordiac/ide/model/commands/change/UnmapCommand.java b/plugins/org.eclipse.fordiac.ide.model.commands/src/org/eclipse/fordiac/ide/model/commands/change/UnmapCommand.java
index f781d3211..0ba0b8957 100644
--- a/plugins/org.eclipse.fordiac.ide.model.commands/src/org/eclipse/fordiac/ide/model/commands/change/UnmapCommand.java
+++ b/plugins/org.eclipse.fordiac.ide.model.commands/src/org/eclipse/fordiac/ide/model/commands/change/UnmapCommand.java
@@ -68,4 +68,8 @@ public class UnmapCommand extends Command {
system.getMapping().remove(mapping);
deleteMappedFBCmd.redo();
}
+
+ public FBNetworkElement getMappedFBNetworkElement() {
+ return deleteMappedFBCmd.getFBNetworkElement();
+ }
}
diff --git a/plugins/org.eclipse.fordiac.ide.model.commands/src/org/eclipse/fordiac/ide/model/commands/change/UpdateFBTypeCommand.java b/plugins/org.eclipse.fordiac.ide.model.commands/src/org/eclipse/fordiac/ide/model/commands/change/UpdateFBTypeCommand.java
index d2fdf3ee4..2304f0eae 100644
--- a/plugins/org.eclipse.fordiac.ide.model.commands/src/org/eclipse/fordiac/ide/model/commands/change/UpdateFBTypeCommand.java
+++ b/plugins/org.eclipse.fordiac.ide.model.commands/src/org/eclipse/fordiac/ide/model/commands/change/UpdateFBTypeCommand.java
@@ -16,19 +16,18 @@ import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.fordiac.ide.model.Palette.AdapterTypePaletteEntry;
+import org.eclipse.fordiac.ide.model.Palette.FBTypePaletteEntry;
+import org.eclipse.fordiac.ide.model.Palette.PaletteEntry;
import org.eclipse.fordiac.ide.model.commands.create.AbstractConnectionCreateCommand;
import org.eclipse.fordiac.ide.model.commands.create.AdapterConnectionCreateCommand;
import org.eclipse.fordiac.ide.model.commands.create.DataConnectionCreateCommand;
import org.eclipse.fordiac.ide.model.commands.create.EventConnectionCreateCommand;
-import org.eclipse.fordiac.ide.model.Palette.AdapterTypePaletteEntry;
-import org.eclipse.fordiac.ide.model.Palette.FBTypePaletteEntry;
-import org.eclipse.fordiac.ide.model.Palette.PaletteEntry;
import org.eclipse.fordiac.ide.model.commands.delete.DeleteConnectionCommand;
-import org.eclipse.fordiac.ide.model.libraryElement.AdapterConnection;
+import org.eclipse.fordiac.ide.model.libraryElement.AdapterDeclaration;
import org.eclipse.fordiac.ide.model.libraryElement.AdapterFB;
import org.eclipse.fordiac.ide.model.libraryElement.Connection;
-import org.eclipse.fordiac.ide.model.libraryElement.DataConnection;
-import org.eclipse.fordiac.ide.model.libraryElement.EventConnection;
+import org.eclipse.fordiac.ide.model.libraryElement.Event;
import org.eclipse.fordiac.ide.model.libraryElement.FB;
import org.eclipse.fordiac.ide.model.libraryElement.FBNetwork;
import org.eclipse.fordiac.ide.model.libraryElement.IInterfaceElement;
@@ -38,12 +37,25 @@ import org.eclipse.fordiac.ide.model.libraryElement.Resource;
import org.eclipse.fordiac.ide.model.libraryElement.Value;
import org.eclipse.fordiac.ide.model.libraryElement.VarDeclaration;
import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.CompoundCommand;
/**
* UpdateFBTypeCommand triggers an update of the type for an FB instance
*/
public class UpdateFBTypeCommand extends Command {
+ //hleper data class for stroing connectiond ata of resoruce connection as the connections are lost during the unmapping process
+ class ConnData{
+ public IInterfaceElement source;
+ public IInterfaceElement dest;
+
+ public ConnData(IInterfaceElement source, IInterfaceElement dest) {
+ this.source = source;
+ this.dest = dest;
+ }
+
+ };
+
/** The FB view */
private FB fb;
@@ -54,10 +66,10 @@ public class UpdateFBTypeCommand extends Command {
private PaletteEntry entry;
private FBNetwork network;
-
- private List<DeleteConnectionCommand> deleteConnCmds = new ArrayList<>();
- private List<AbstractConnectionCreateCommand> connCreateCmds = new ArrayList<>();
+ private CompoundCommand deleteConnCmds = new CompoundCommand();
+ private CompoundCommand connCreateCmds = new CompoundCommand();
+ private CompoundCommand resourceConnCreateCmds = new CompoundCommand();
private MapToCommand mapCmd = null;
private UnmapCommand unmapCmd = null;
@@ -90,6 +102,7 @@ public class UpdateFBTypeCommand extends Command {
@Override
public void execute() {
Resource resource = null;
+ List<ConnData> resourceConns = null; //buffer for the resource specific connections form the mapped fb that need to be recreated
if (fb.isMapped()) {
if(network.equals(fb.getResource().getFBNetwork())) {
//this is the resource fb we need to use the oposite for a correct update
@@ -97,6 +110,7 @@ public class UpdateFBTypeCommand extends Command {
network = fb.getFbNetwork();
}
resource = fb.getResource();
+ resourceConns = getResourceCons();
unmapCmd = new UnmapCommand(fb);
unmapCmd.execute();
}
@@ -105,30 +119,20 @@ public class UpdateFBTypeCommand extends Command {
copyFB(fb);
// Find connections which should be reconnected
- List<Connection> reConnections = new ArrayList<>();
- for (IInterfaceElement ifEle : fb.getInterface().getAllInterfaceElements()) {
- reConnections.addAll(ifEle.getInputConnections());
- reConnections.addAll(ifEle.getOutputConnections());
- }
- for (Connection conn : reConnections) {
- doReconnect(conn, findUpdatedInterfaceElement(copiedFB, conn.getSource()),
- findUpdatedInterfaceElement(copiedFB, conn.getDestination()));
- }
+ handleApplicationConnections();
// Change name
- String name = fb.getName();
- copiedFB.setName(name);
-
+ copiedFB.setName(fb.getName());
// Map FB
if (resource != null) {
mapCmd = new MapToCommand(copiedFB, resource);
if (mapCmd.canExecute()) {
mapCmd.execute();
+ recreateResourceConns(resourceConns);
}
}
}
-
/* (non-Javadoc)
* @see org.eclipse.gef.commands.Command#redo()
@@ -139,18 +143,14 @@ public class UpdateFBTypeCommand extends Command {
unmapCmd.redo();
}
- for (DeleteConnectionCommand cmd : deleteConnCmds) {
- cmd.redo();
- }
-
- replaceFBs(fb, copiedFB);
-
- for (AbstractConnectionCreateCommand cmd : connCreateCmds) {
- cmd.redo();
- }
+ deleteConnCmds.redo();
+ replaceFBs(fb, copiedFB);
+ connCreateCmds.redo();
if (mapCmd != null) {
mapCmd.redo();
+ //after redoing the mapping for the new FB recreate the resoruce cons
+ resourceConnCreateCmds.redo();
}
}
@@ -160,33 +160,48 @@ public class UpdateFBTypeCommand extends Command {
@Override
public void undo() {
if (mapCmd != null) {
+ //before removing the copied FB remove the newly created resource connections
+ resourceConnCreateCmds.undo();
mapCmd.undo();
}
- for (AbstractConnectionCreateCommand cmd : connCreateCmds) {
- cmd.undo();
- }
-
+ connCreateCmds.undo();
replaceFBs(copiedFB, fb);
-
- for (DeleteConnectionCommand cmd : deleteConnCmds) {
- cmd.undo();
- }
+ deleteConnCmds.undo();
if (unmapCmd != null) {
unmapCmd.undo();
+ }
+ }
+
+ private void handleApplicationConnections() {
+ for (Connection conn : getAllConnectionsForFB(fb)) {
+ doReconnect(conn, findUpdatedInterfaceElement(copiedFB, fb, conn.getSource()),
+ findUpdatedInterfaceElement(copiedFB, fb, conn.getDestination()));
}
-
+ }
+
+ private static List<Connection> getAllConnectionsForFB(FB functionBlock) {
+ List<Connection> retVal = new ArrayList<>();
+ for (IInterfaceElement ifEle : functionBlock.getInterface().getAllInterfaceElements()) {
+ if(ifEle.isIsInput()) {
+ retVal.addAll(ifEle.getInputConnections());
+ } else {
+ retVal.addAll(ifEle.getOutputConnections());
+ }
+ }
+ return retVal;
}
- private IInterfaceElement findUpdatedInterfaceElement(FB copiedFB, IInterfaceElement orig) {
+
+ private static IInterfaceElement findUpdatedInterfaceElement(FB copiedFB, FB orgFB, IInterfaceElement orig) {
if (orig == null) {
// this happens when a connection has already been reconnected,
// i.e., a connection from an output to an input of the same FB
return null;
}
IInterfaceElement retval = orig;
- if (orig.getFBNetworkElement() == fb) {
+ if (orig.getFBNetworkElement() == orgFB) {
// origView is an interface of the original FB => find same interface on copied FB
retval = copiedFB.getInterfaceElement(orig.getName());
}
@@ -204,15 +219,7 @@ public class UpdateFBTypeCommand extends Command {
if (source != null && dest != null) {
// if source or dest is null it means that an interface element is not available any more
- AbstractConnectionCreateCommand dccc = null;
-
- if(oldConn instanceof EventConnection){
- dccc = new EventConnectionCreateCommand(fbn);
- } else if(oldConn instanceof DataConnection){
- dccc = new DataConnectionCreateCommand(fbn);
- } else if(oldConn instanceof AdapterConnection){
- dccc = new AdapterConnectionCreateCommand(fbn);
- }
+ AbstractConnectionCreateCommand dccc = createConnCreateCMD(source, fbn);
if(null != dccc){
dccc.setSource(source);
dccc.setDestination(dest);
@@ -225,9 +232,21 @@ public class UpdateFBTypeCommand extends Command {
}
}
+ private static AbstractConnectionCreateCommand createConnCreateCMD(IInterfaceElement refIE, FBNetwork fbn) {
+ AbstractConnectionCreateCommand retVal = null;
+ if(refIE instanceof Event){
+ retVal = new EventConnectionCreateCommand(fbn);
+ } else if(refIE instanceof AdapterDeclaration){
+ retVal = new AdapterConnectionCreateCommand(fbn);
+ } else if(refIE instanceof VarDeclaration){
+ retVal = new DataConnectionCreateCommand(fbn);
+ }
+ return retVal;
+ }
+
private boolean isInDeleteConnList(Connection conn) {
- for (DeleteConnectionCommand cmd : deleteConnCmds) {
- if(cmd.getConnectionView().equals(conn)){
+ for (Object cmd : deleteConnCmds.getCommands()) {
+ if(((DeleteConnectionCommand)cmd).getConnectionView().equals(conn)){
return true;
}
}
@@ -296,14 +315,53 @@ public class UpdateFBTypeCommand extends Command {
}
}
}
-
}
protected void createValues(FB copiedFB) {
for (IInterfaceElement element : copiedFB.getInterface().getInputVars()) {
Value value = LibraryElementFactory.eINSTANCE.createValue();
element.setValue(value);
-
}
}
+
+ private List<ConnData> getResourceCons() {
+ List<ConnData> retVal = new ArrayList<>();
+ FB resFB = (FB)fb.getOpposite();
+ for (Connection conn : getAllConnectionsForFB(resFB)) {
+ IInterfaceElement source = conn.getSource();
+ IInterfaceElement dest = conn.getDestination();
+ if(!source.getFBNetworkElement().isMapped() || !dest.getFBNetworkElement().isMapped()) {
+ //one of both ends is a resourceFB therefore the connection needs to be restored
+ retVal.add(new ConnData(conn.getSource(), conn.getDestination()));
+ } else if (((source.getFBNetworkElement() == resFB) && (dest.getFBNetworkElement().getOpposite().getFbNetwork() != fb.getFbNetwork())) ||
+ ((dest.getFBNetworkElement() == resFB) && (source.getFBNetworkElement().getOpposite().getFbNetwork() != fb.getFbNetwork()))){
+ //one of both ends is a FB comming from a different fb network and therefore this is also a resource specific connection
+ retVal.add(new ConnData(conn.getSource(), conn.getDestination()));
+ }
+
+ }
+ return retVal;
+ }
+
+ private void recreateResourceConns(List<ConnData> resourceConns) {
+ FB orgMappedFB = (FB)unmapCmd.getMappedFBNetworkElement();
+ FB copiedMappedFB = (FB)copiedFB.getOpposite();
+ for (ConnData connData : resourceConns) {
+ IInterfaceElement source = findUpdatedInterfaceElement(copiedMappedFB, orgMappedFB, connData.source);
+ IInterfaceElement dest = findUpdatedInterfaceElement(copiedMappedFB, orgMappedFB, connData.dest);
+ if (source != null && dest != null) {
+ // if source or dest is null it means that an interface element is not available any more
+ AbstractConnectionCreateCommand dccc = createConnCreateCMD(source, copiedMappedFB.getFbNetwork());
+ if(null != dccc){
+ dccc.setSource(source);
+ dccc.setDestination(dest);
+ if (dccc.canExecute()) {
+ dccc.execute();
+ resourceConnCreateCmds.add(dccc);
+ }
+ }
+ }
+ }
+ }
+
}
diff --git a/plugins/org.eclipse.fordiac.ide.model.commands/src/org/eclipse/fordiac/ide/model/commands/delete/DeleteFBNetworkElementCommand.java b/plugins/org.eclipse.fordiac.ide.model.commands/src/org/eclipse/fordiac/ide/model/commands/delete/DeleteFBNetworkElementCommand.java
index 683236c53..c164bcaa2 100644
--- a/plugins/org.eclipse.fordiac.ide.model.commands/src/org/eclipse/fordiac/ide/model/commands/delete/DeleteFBNetworkElementCommand.java
+++ b/plugins/org.eclipse.fordiac.ide.model.commands/src/org/eclipse/fordiac/ide/model/commands/delete/DeleteFBNetworkElementCommand.java
@@ -38,6 +38,10 @@ public class DeleteFBNetworkElementCommand extends Command {
super("Delete FB or Subapplication");
this.element = element;
}
+
+ public FBNetworkElement getFBNetworkElement() {
+ return element;
+ }
@Override
public boolean canUndo() {

Back to the top