Skip to content

Commit

Permalink
[57706] Fixes unset InterfaceList on internal FBs
Browse files Browse the repository at this point in the history
InternalFBs did not get their InterfaceList set, which lead to several
unexpected behaviours and errors.

This fix now correctly creates and adds the InterfaceList to the created
Internal FB.

Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=577602

Change-Id: If5817709a013997f18ad76d7ab6ba4cef36d321e
Signed-off-by: Martin Melik Merkumians <[email protected]>
  • Loading branch information
MartinMelikMerkumians committed Dec 7, 2021
1 parent de73a4b commit f31f035
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*******************************************************************************/
package org.eclipse.fordiac.ide.gef.properties;

import org.eclipse.fordiac.ide.model.Palette.PaletteEntry;
import org.eclipse.fordiac.ide.model.Palette.FBTypePaletteEntry;
import org.eclipse.fordiac.ide.model.commands.change.ChangeCommentCommand;
import org.eclipse.fordiac.ide.model.commands.change.ChangeFbTypeCommand;
import org.eclipse.fordiac.ide.model.commands.change.ChangeInternalFBOrderCommand;
Expand Down Expand Up @@ -97,9 +97,9 @@ public void createInternalFbsControls(final Composite parent) {
ref -> new ChangeInternalFBOrderCommand(getType(), (FB) ref, IndexUpDown.DOWN));
}

private PaletteEntry getFBTypePaletteEntry() {
private FBTypePaletteEntry getFBTypePaletteEntry() {
final FB fb = getLastSelectedFB();
return (null != fb) ? fb.getType().getPaletteEntry() : null;
return (null != fb) ? (FBTypePaletteEntry) fb.getPaletteEntry() : null;
}

private String getName() {
Expand Down Expand Up @@ -197,12 +197,11 @@ public void modify(final Object element, final String property, final Object val
cmd = new ChangeNameCommand(fb, value.toString());
break;
case FB_TYPE:
final PaletteEntry fbTypeEntry = getPalette().getFBTypeEntry(value.toString());
final FBTypePaletteEntry fbTypeEntry = getPalette().getFBTypeEntry(value.toString());
if (null == fbTypeEntry) {
return;
}
final FBType fbType = (FBType) fbTypeEntry.getType();
cmd = new ChangeFbTypeCommand(fb, fbType);
cmd = new ChangeFbTypeCommand(fb, fbTypeEntry);
break;
default:
cmd = new ChangeCommentCommand(fb, value.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public final class Messages extends NLS {
public static String DeleteConnectionCommand_DeleteConnection;
public static String DeleteFBNetworkElement;
public static String DeleteFBNetworkElementCommand_DeleteFBOrSubapplication;
public static String FBCreateCommand_LABLE_CreateFunctionBlock;
public static String FBCreateCommand_LABEL_CreateFunctionBlock;
public static String LinkConstraints_ClassLinconstraintsShouldNotBeCreated;
public static String LinkConstraints_ERROR_NotConnectedToAnEventByAWithConstruct;
public static String LinkConstraints_STATUSMessage_hasAlreadyInputConnection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,47 @@

package org.eclipse.fordiac.ide.model.commands.change;


import org.eclipse.fordiac.ide.model.Palette.FBTypePaletteEntry;
import org.eclipse.fordiac.ide.model.helpers.FBNetworkHelper;
import org.eclipse.fordiac.ide.model.libraryElement.FB;
import org.eclipse.fordiac.ide.model.libraryElement.FBType;
import org.eclipse.gef.commands.Command;

public class ChangeFbTypeCommand extends Command {

final FB fb;
FBType oldType;
final FBType newType;
FBTypePaletteEntry oldFBTypePaletteEntry;
final FBTypePaletteEntry newType;

public ChangeFbTypeCommand(final FB fb, final FBType newType) {
public ChangeFbTypeCommand(final FB fb, final FBTypePaletteEntry newType) {
super();
this.fb = fb;
this.newType = newType;
}

@Override
public boolean canExecute() {
return FBNetworkHelper.isTypeInsertionSave(newType, fb);
return FBNetworkHelper.isTypeInsertionSave(newType.getFBType(), fb);
}

@Override
public void execute() {
oldType = fb.getType();
redo();
oldFBTypePaletteEntry = (FBTypePaletteEntry) fb.getType().getPaletteEntry();
setFBType(newType);
}

private void setFBType(final FBTypePaletteEntry paletteEntry) {
fb.setPaletteEntry(paletteEntry);
fb.setInterface(paletteEntry.getFBType().getInterfaceList().copy());
}

@Override
public void redo() {
fb.setPaletteEntry(newType.getPaletteEntry());
setFBType(newType);
}

@Override
public void undo() {
fb.setPaletteEntry(oldType.getPaletteEntry());
setFBType(oldFBTypePaletteEntry);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.eclipse.fordiac.ide.model.NameRepository;
import org.eclipse.fordiac.ide.model.Palette.FBTypePaletteEntry;
import org.eclipse.fordiac.ide.model.Palette.Palette;
import org.eclipse.fordiac.ide.model.Palette.PaletteEntry;
import org.eclipse.fordiac.ide.model.libraryElement.BaseFBType;
import org.eclipse.fordiac.ide.model.libraryElement.FB;
import org.eclipse.fordiac.ide.model.libraryElement.LibraryElementFactory;
Expand All @@ -31,7 +30,7 @@ public class CreateInternalFBCommand extends Command implements CreationCommand
private final BaseFBType baseFbType;

/** Command information */
private PaletteEntry fbType;
private FBTypePaletteEntry fbType;
private final String name;
private final int index;

Expand All @@ -45,7 +44,7 @@ protected CreateInternalFBCommand(final BaseFBType baseFbType) {
}

public CreateInternalFBCommand(final BaseFBType baseFbType, final int index, final String name,
final PaletteEntry fbType) {
final FBTypePaletteEntry fbType) {
this.baseFbType = baseFbType;
this.fbType = fbType;
if (null == fbType) {
Expand All @@ -56,12 +55,12 @@ public CreateInternalFBCommand(final BaseFBType baseFbType, final int index, fin
this.index = index;
}

public CreateInternalFBCommand(final BaseFBType baseFbType, int index, String name, PaletteEntry fbType,
Palette palette) {
public CreateInternalFBCommand(final BaseFBType baseFbType, final int index, final String name,
final FBTypePaletteEntry fbType, final Palette palette) {
this.baseFbType = baseFbType;
this.fbType = fbType;
if (null == fbType) {
this.fbType = (PaletteEntry) palette.eContents().get(0);
this.fbType = (FBTypePaletteEntry) palette.eContents().get(0);
}
this.name = (null != name) ? name : DEFAULT_INTERNAL_FB_NAME;
this.index = index;
Expand All @@ -82,7 +81,8 @@ public void execute() {
internalFB = LibraryElementFactory.eINSTANCE.createFB();
internalFB.setPaletteEntry(fbType);
internalFB.setComment(""); //$NON-NLS-1$
redo();
internalFB.setInterface(fbType.getFBType().getInterfaceList().copy());
getInteralFBList().add(index, internalFB);
internalFB.setName(NameRepository.createUniqueName(internalFB, name));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class FBCreateCommand extends AbstractCreateFBNetworkElementCommand {
public FBCreateCommand(final FBTypePaletteEntry paletteEntry, final FBNetwork fbNetwork, final int x, final int y) {
super(fbNetwork, createNewFb(paletteEntry), x, y);
this.paletteEntry = paletteEntry;
setLabel(Messages.FBCreateCommand_LABLE_CreateFunctionBlock);
setLabel(Messages.FBCreateCommand_LABEL_CreateFunctionBlock);
getFB().setPaletteEntry(paletteEntry);
}

Expand All @@ -51,7 +51,7 @@ private static FB createNewFb(final FBTypePaletteEntry paletteEntry) {
protected FBCreateCommand(final FBNetwork fbNetwork, final FBNetworkElement adapter, final int x, final int y) {
super(fbNetwork, adapter, x, y);
this.paletteEntry = null;
setLabel(Messages.FBCreateCommand_LABLE_CreateFunctionBlock);
setLabel(Messages.FBCreateCommand_LABEL_CreateFunctionBlock);
getFB().setPaletteEntry(paletteEntry);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CreateSubAppInstanceCommand_CreateSubapplicationInstance=Create Subapplication I
DeleteConnectionCommand_DeleteConnection=Delete Connection
DeleteFBNetworkElement=Can not be deleted -> is ResourceType FB
DeleteFBNetworkElementCommand_DeleteFBOrSubapplication=Delete FB or Subapplication
FBCreateCommand_LABLE_CreateFunctionBlock=Create Function Block
FBCreateCommand_LABEL_CreateFunctionBlock=Create Function Block
LinkConstraints_ClassLinconstraintsShouldNotBeCreated=Class Linconstraints should not be created!
LinkConstraints_ERROR_NotConnectedToAnEventByAWithConstruct={0} is not connected to an Event by a With-Construct
LinkConstraints_STATUSMessage_hasAlreadyInputConnection={0} has already an input connection\!
Expand Down

0 comments on commit f31f035

Please sign in to comment.