-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0def0c
commit 2135f9d
Showing
5 changed files
with
127 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 101 additions & 7 deletions
108
...management/src/org/eclipse/fordiac/ide/typemanagement/refactoring/ReconnectPinChange.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,131 @@ | ||
package org.eclipse.fordiac.ide.typemanagement.refactoring; | ||
|
||
import java.util.EnumSet; | ||
|
||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.core.runtime.IProgressMonitor; | ||
import org.eclipse.core.runtime.OperationCanceledException; | ||
import org.eclipse.emf.common.util.EList; | ||
import org.eclipse.emf.common.util.URI; | ||
import org.eclipse.fordiac.ide.model.commands.change.ReconnectDataConnectionCommand; | ||
import org.eclipse.fordiac.ide.model.libraryElement.Connection; | ||
import org.eclipse.fordiac.ide.model.libraryElement.DataConnection; | ||
import org.eclipse.fordiac.ide.model.libraryElement.ErrorMarkerInterface; | ||
import org.eclipse.fordiac.ide.model.libraryElement.FBNetworkElement; | ||
import org.eclipse.fordiac.ide.model.libraryElement.IInterfaceElement; | ||
import org.eclipse.fordiac.ide.typemanagement.refactoring.IFordiacPreviewChange.ChangeState; | ||
import org.eclipse.gef.commands.Command; | ||
import org.eclipse.gef.commands.CompoundCommand; | ||
import org.eclipse.ltk.core.refactoring.RefactoringStatus; | ||
|
||
public class ReconnectPinChange extends AbstractCommandChange<FBNetworkElement> { | ||
public class ReconnectPinChange extends AbstractCommandChange<FBNetworkElement> implements IFordiacPreviewChange { | ||
|
||
private final EnumSet<ChangeState> state = EnumSet.noneOf(ChangeState.class); | ||
private final String newName; | ||
private final String oldName; | ||
private final FBNetworkElement instance; | ||
|
||
protected ReconnectPinChange(final URI elementURI, final Class<FBNetworkElement> elementClass) { | ||
protected ReconnectPinChange(final URI elementURI, final Class<FBNetworkElement> elementClass, final String newName, | ||
final String oldName, final FBNetworkElement fbNeworkElement) { | ||
super(elementURI, elementClass); | ||
// TODO Auto-generated constructor stub | ||
this.newName = newName; | ||
this.oldName = oldName; | ||
this.instance = fbNeworkElement; | ||
} | ||
|
||
@Override | ||
public void initializeValidationData(final FBNetworkElement element, final IProgressMonitor pm) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public RefactoringStatus isValid(final FBNetworkElement element, final IProgressMonitor pm) | ||
throws CoreException, OperationCanceledException { | ||
// TODO Auto-generated method stub | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
protected Command createCommand(final FBNetworkElement element) { | ||
// TODO Auto-generated method stub | ||
return null; | ||
|
||
return new ReconnectPinByName(oldName, newName, element, ChangeState.Reconnect); | ||
|
||
} | ||
|
||
@Override | ||
public EnumSet<ChangeState> getState() { | ||
return state; | ||
} | ||
|
||
@Override | ||
public EnumSet<ChangeState> getAllowedChoices() { | ||
return EnumSet.of(ChangeState.Reconnect, ChangeState.NO_CHANGE, ChangeState.DELETE); | ||
} | ||
|
||
@Override | ||
public void addState(final ChangeState newState) { | ||
state.add(newState); | ||
} | ||
|
||
@Override | ||
public EnumSet<ChangeState> getDefaultSelection() { | ||
return EnumSet.of(ChangeState.Reconnect); | ||
} | ||
|
||
} | ||
|
||
class ReconnectPinByName extends Command { | ||
|
||
final String oldName; | ||
final String newName; | ||
final FBNetworkElement element; | ||
private final ChangeState state; | ||
|
||
public ReconnectPinByName(final String oldName, final String newName, final FBNetworkElement fbNeworkElement, | ||
final ChangeState state) { | ||
this.oldName = oldName; | ||
this.newName = newName; | ||
this.element = fbNeworkElement; | ||
this.state = state; | ||
} | ||
|
||
@Override | ||
public boolean canExecute() { | ||
|
||
return state.equals(ChangeState.Reconnect); | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
System.out.println(element); | ||
final IInterfaceElement interfaceElement = element.getInterfaceElement(newName); | ||
System.out.println("new" + interfaceElement); | ||
final IInterfaceElement oldinterfaceElement = element.getInterfaceElement(oldName); | ||
|
||
if (oldinterfaceElement instanceof final ErrorMarkerInterface errorMarkerInterface) { | ||
final EList<Connection> inputConnections = getConnection(errorMarkerInterface); | ||
final Class<? extends EList> class1 = inputConnections.getClass(); | ||
|
||
final CompoundCommand cmds = new CompoundCommand(); | ||
for (final Connection c : inputConnections) { | ||
|
||
if (c instanceof final DataConnection dc) { | ||
final ReconnectDataConnectionCommand cmd = new ReconnectDataConnectionCommand(dc, | ||
!errorMarkerInterface.isIsInput(), interfaceElement, element.getFbNetwork()); | ||
cmds.add(cmd); | ||
} | ||
|
||
} | ||
|
||
cmds.execute(); | ||
} | ||
|
||
// System.out.println("old" + oldinterfaceElement); | ||
} | ||
|
||
private EList<Connection> getConnection(final ErrorMarkerInterface errorMarkerInterface) { | ||
return errorMarkerInterface.isIsInput() ? errorMarkerInterface.getInputConnections() | ||
: errorMarkerInterface.getOutputConnections(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters