Skip to content

Commit 39ad8dc

Browse files
committed
Made Flatten and New Subapplication a QualNameAffectedCommand
1 parent 65f40e5 commit 39ad8dc

File tree

5 files changed

+68
-6
lines changed

5 files changed

+68
-6
lines changed

plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/commands/AddElementsToSubAppCommand.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,4 +372,9 @@ private void collectElementsToRemoveFromGroup() {
372372
public Set<EObject> getAffectedObjects() {
373373
return Set.of(targetSubApp);
374374
}
375+
376+
public List<FBNetworkElement> getElements() {
377+
return elementsToAdd;
378+
}
379+
375380
}

plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/commands/FlattenSubAppCommand.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@
1919

2020
import java.util.ArrayList;
2121
import java.util.Arrays;
22+
import java.util.HashMap;
2223
import java.util.List;
24+
import java.util.Map;
2325
import java.util.Objects;
2426
import java.util.Set;
2527

2628
import org.eclipse.emf.ecore.EObject;
2729
import org.eclipse.fordiac.ide.application.Messages;
2830
import org.eclipse.fordiac.ide.gef.utilities.ElementSelector;
2931
import org.eclipse.fordiac.ide.model.NameRepository;
30-
import org.eclipse.fordiac.ide.model.commands.ScopedCommand;
32+
import org.eclipse.fordiac.ide.model.commands.QualNameAffectedCommand;
3133
import org.eclipse.fordiac.ide.model.commands.change.ChangeNameCommand;
3234
import org.eclipse.fordiac.ide.model.commands.change.MapToCommand;
3335
import org.eclipse.fordiac.ide.model.commands.create.AbstractConnectionCreateCommand;
@@ -46,13 +48,14 @@
4648
import org.eclipse.fordiac.ide.model.libraryElement.FBNetwork;
4749
import org.eclipse.fordiac.ide.model.libraryElement.FBNetworkElement;
4850
import org.eclipse.fordiac.ide.model.libraryElement.IInterfaceElement;
51+
import org.eclipse.fordiac.ide.model.libraryElement.INamedElement;
4952
import org.eclipse.fordiac.ide.model.libraryElement.Position;
5053
import org.eclipse.fordiac.ide.model.libraryElement.SubApp;
5154
import org.eclipse.fordiac.ide.model.libraryElement.VarDeclaration;
5255
import org.eclipse.gef.commands.Command;
5356
import org.eclipse.gef.commands.CompoundCommand;
5457

55-
public class FlattenSubAppCommand extends Command implements ScopedCommand {
58+
public class FlattenSubAppCommand extends Command implements QualNameAffectedCommand {
5659
private final SubApp subapp;
5760
private final FBNetwork parentNetwork;
5861
private final List<FBNetworkElement> elements = new ArrayList<>();
@@ -66,6 +69,8 @@ public class FlattenSubAppCommand extends Command implements ScopedCommand {
6669
private final CompoundCommand setUniqueName = new CompoundCommand();
6770
private final Position fbnetworkPosInSubapp;
6871
private boolean select = true;
72+
private final Map<INamedElement, String> oldQualNames = new HashMap<>();
73+
private final Map<INamedElement, String> newQualNames = new HashMap<>();
6974

7075
public FlattenSubAppCommand(final SubApp subapp) {
7176
super(Messages.FlattenSubAppCommand_LABEL_FlattenSubAppCommand);
@@ -83,6 +88,7 @@ public FlattenSubAppCommand(final SubApp subapp, final boolean select) {
8388
@Override
8489
public void execute() {
8590
elements.addAll(subapp.getSubAppNetwork().getNetworkElements());
91+
elements.forEach(e -> oldQualNames.put(e, e.getQualifiedName()));
8692
elementsToMove.addAll(elements.stream().filter(el -> !el.isInGroup()).toList());
8793
// add elements to parent
8894
FBNetworkHelper.moveFBNetworkByOffset(elementsToMove, -getOriginalPositionX(), -getOriginalPositionY());
@@ -116,6 +122,7 @@ public void execute() {
116122
if (select) {
117123
ElementSelector.selectViewObjects(elementsToMove);
118124
}
125+
elements.forEach(e -> newQualNames.put(e, e.getQualifiedName()));
119126
}
120127

121128
private void ensureUniqueName(final FBNetworkElement element) {
@@ -260,4 +267,19 @@ private AbstractConnectionCreateCommand createConnCreateCmd(final IInterfaceElem
260267
public Set<EObject> getAffectedObjects() {
261268
return Set.of(parentNetwork);
262269
}
270+
271+
@Override
272+
public String getOldQualName(final INamedElement element) {
273+
return oldQualNames.get(element);
274+
}
275+
276+
@Override
277+
public String getNewQualName(final INamedElement element) {
278+
return newQualNames.get(element);
279+
}
280+
281+
@Override
282+
public List<INamedElement> getChangedElements() {
283+
return new ArrayList<>(elements);
284+
}
263285
}

plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/commands/NewSubAppCommand.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@
1717
*******************************************************************************/
1818
package org.eclipse.fordiac.ide.application.commands;
1919

20+
import java.util.ArrayList;
21+
import java.util.HashMap;
2022
import java.util.List;
23+
import java.util.Map;
2124

25+
import org.eclipse.fordiac.ide.model.commands.QualNameAffectedCommand;
2226
import org.eclipse.fordiac.ide.model.commands.change.MapToCommand;
2327
import org.eclipse.fordiac.ide.model.commands.create.AbstractCreateFBNetworkElementCommand;
2428
import org.eclipse.fordiac.ide.model.libraryElement.FBNetwork;
2529
import org.eclipse.fordiac.ide.model.libraryElement.FBNetworkElement;
30+
import org.eclipse.fordiac.ide.model.libraryElement.INamedElement;
2631
import org.eclipse.fordiac.ide.model.libraryElement.InterfaceList;
2732
import org.eclipse.fordiac.ide.model.libraryElement.LibraryElementFactory;
2833
import org.eclipse.fordiac.ide.model.libraryElement.Position;
@@ -31,12 +36,16 @@
3136
import org.eclipse.gef.EditPart;
3237
import org.eclipse.gef.commands.Command;
3338

34-
public class NewSubAppCommand extends AbstractCreateFBNetworkElementCommand {
39+
public class NewSubAppCommand extends AbstractCreateFBNetworkElementCommand implements QualNameAffectedCommand {
3540
private final List<?> parts;
3641
private final AddElementsToSubAppCommand addElements;
3742
private Command mapSubappCmd; // can not be in the compound command as it needs to be performed when
3843
// subapp interface is finished
3944

45+
private final Map<INamedElement, String> oldQualNames = new HashMap<>(); // store qualnames for plant hierchachy
46+
// update
47+
private final Map<INamedElement, String> newQualNames = new HashMap<>();
48+
4049
public NewSubAppCommand(final FBNetwork fbNetwork, final List<?> selection, final Position pos) {
4150
super(fbNetwork, LibraryElementFactory.eINSTANCE.createUntypedSubApp(), pos);
4251
getElement().setSubAppNetwork(LibraryElementFactory.eINSTANCE.createFBNetwork());
@@ -74,11 +83,13 @@ private boolean allElementsInSameFBnetwork() {
7483

7584
@Override
7685
public void execute() {
86+
addElements.getElements().forEach(e -> oldQualNames.put(e, e.getQualifiedName()));
7787
super.execute();
7888
addElements.execute();
7989
if (null != mapSubappCmd) {
8090
mapSubappCmd.execute();
8191
}
92+
addElements.getElements().forEach(e -> newQualNames.put(e, e.getQualifiedName()));
8293
}
8394

8495
@Override
@@ -136,4 +147,20 @@ protected String getInitialInstanceName() {
136147
public UntypedSubApp getElement() {
137148
return (UntypedSubApp) super.getElement();
138149
}
150+
151+
@Override
152+
public String getOldQualName(final INamedElement elemt) {
153+
return oldQualNames.get(elemt);
154+
}
155+
156+
@Override
157+
public String getNewQualName(final INamedElement element) {
158+
return newQualNames.get(element);
159+
}
160+
161+
@Override
162+
public List<INamedElement> getChangedElements() {
163+
return new ArrayList<>(addElements.getElements());
164+
}
165+
139166
}

plugins/org.eclipse.fordiac.ide.model.commands/src/org/eclipse/fordiac/ide/model/commands/QualNameAffectedCommand.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@
2525

2626
public interface QualNameAffectedCommand extends ScopedCommand {
2727

28-
String getOldQualName(INamedElement elemt);
28+
String getOldQualName(INamedElement element);
2929

3030
String getNewQualName(INamedElement element);
3131

3232
List<INamedElement> getChangedElements();
3333

34-
// private
35-
3634
/**
3735
* encapsulate the change to not provide the command to the receiver
3836
*/

plugins/org.eclipse.fordiac.ide.model.commands/src/org/eclipse/fordiac/ide/model/commands/QualNameChangeListenerManager.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
import org.eclipse.fordiac.ide.ui.FordiacLogHelper;
2424
import org.eclipse.fordiac.ide.ui.editors.EditorFilter;
2525
import org.eclipse.fordiac.ide.ui.editors.EditorUtils;
26+
import org.eclipse.gef.commands.Command;
2627
import org.eclipse.gef.commands.CommandStack;
2728
import org.eclipse.gef.commands.CommandStackEvent;
2829
import org.eclipse.gef.commands.CommandStackEventListener;
30+
import org.eclipse.gef.commands.CompoundCommand;
2931
import org.eclipse.ui.IEditorPart;
3032

3133
public enum QualNameChangeListenerManager implements CommandStackEventListener {
@@ -66,6 +68,14 @@ public void removeCommandStackEventListener(final CommandStack commandStack, fin
6668
@Override
6769
public void stackChanged(final CommandStackEvent event) {
6870

71+
if (event.getCommand() instanceof final CompoundCommand cmd) {
72+
for (final Command c : cmd.getCommands()) {
73+
final CommandStack stack = (CommandStack) event.getSource();
74+
stackChanged(new CommandStackEvent(stack, c, event.getDetail()));
75+
}
76+
return;
77+
}
78+
6979
if (event.getCommand() instanceof final QualNameAffectedCommand cmd) {
7080
switch (event.getDetail()) {
7181
case CommandStack.POST_EXECUTE:

0 commit comments

Comments
 (0)