From 17cbea28d59d2ec7ea7b3a4efbaa70088f1e534d Mon Sep 17 00:00:00 2001 From: Terra Date: Thu, 4 Apr 2024 16:08:08 +0200 Subject: [PATCH 01/22] WIP new refactor layout --- .../fordiac/ide/typemanagement/Messages.java | 1 + .../ide/typemanagement/messages.properties | 9 +- .../refactoring/InterfaceDataTypeChange.java | 18 +- .../refactoring/RenameTypeRefactoring.java | 233 ------------------ .../RenameTypeRefactoringParticipant.java | 97 ++++++-- ...java => UpdateTypeLibraryEntryChange.java} | 6 +- 6 files changed, 99 insertions(+), 265 deletions(-) delete mode 100644 plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/RenameTypeRefactoring.java rename plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/{UpdateTypeEntryChange.java => UpdateTypeLibraryEntryChange.java} (94%) diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/Messages.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/Messages.java index 2b5f130202..6dfd58feea 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/Messages.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/Messages.java @@ -131,6 +131,7 @@ public final class Messages extends NLS { public static String WillBeImported; public static String Refactoring_RenameFromTo; + public static String Refactoring_AffectedFuctionBlock; public static String Refactoring_AffectedStruct; public static String Refactoring_AffectedInstancesOfFB; public static String Refactoring_UpdateTypeEntryChange; diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/messages.properties b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/messages.properties index 6ec9efbb78..f4c7ed0715 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/messages.properties +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/messages.properties @@ -77,7 +77,7 @@ RenameElementRefactoringParticipant_Name=Rename model elements RenameElementRefactoringProcessor_Name=Rename element to {0} RenameElementRefactoringWizardPage_Name=Name RenameType_Name=Rename IEC 61499 Type -RenameType_TypeExists=The type {0} is already included in the library +RenameType_TypeExists=The type ''{0}'' is already included in the library OldTypeLibVersionCouldNotBeDeleted= There was a problem while importing the new Type Library version, old one could not be deleted! OpenTypeHandler_EDITOR_OPEN_ERROR_MESSAGE=Could not open according editor OpenTypeHandler_NO_FILES_IN_WORKSPACE=There are no files in your workspace @@ -90,10 +90,11 @@ typeManagementPreferencePageIdentificationTitle=Identification information typeManagementPreferencePageVersionTitle=Version information typeManagementPreferencePageDescription=Default values for created Function Blocks Warning=Warning -Refactoring_RenameFromTo=Rename Type from {0} to : {1} -Refactoring_AffectedStruct=Affected Struct that contain struct as member +Refactoring_RenameFromTo=Rename Type from ''{0}'' to ''{1}'' +Refactoring_AffectedFuctionBlock=Update affected Function Blocks +Refactoring_AffectedStruct=Update affected Structs Refactoring_AffectedInstancesOfFB=Affected Instances of this FB Type -Refactoring_UpdateTypeEntryChange=Update type entry and editors +Refactoring_UpdateTypeEntryChange=Update type library and editors UpdatedInstances=Instances which have been updated with the new type library version PreviewChange_DeleteChoice=Delete PreviewChange_ChangeToAnyStruct=Change to ANY_STRUCT diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/InterfaceDataTypeChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/InterfaceDataTypeChange.java index a08b3894a6..99f1d705e6 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/InterfaceDataTypeChange.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/InterfaceDataTypeChange.java @@ -12,13 +12,13 @@ *******************************************************************************/ package org.eclipse.fordiac.ide.typemanagement.refactoring; -import java.util.ArrayList; import java.util.List; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.fordiac.ide.model.libraryElement.FBType; +import org.eclipse.fordiac.ide.model.libraryElement.IInterfaceElement; import org.eclipse.fordiac.ide.model.typelibrary.DataTypeEntry; import org.eclipse.fordiac.ide.model.typelibrary.TypeEntry; import org.eclipse.fordiac.ide.typemanagement.util.FBUpdater; @@ -33,20 +33,26 @@ public class InterfaceDataTypeChange extends Change { private final FBType fbType; private final TypeEntry typeEntry; private final String oldName; - private final List pinNames; + private final List inputPinNames; + private final List outputPinNames; public InterfaceDataTypeChange(final FBType fbType, final TypeEntry oldTypeEntry, final String oldName) { this.fbType = fbType; this.typeEntry = oldTypeEntry; this.oldName = oldName; - this.pinNames = new ArrayList<>(); + this.inputPinNames = fbType.getInterfaceList().getInputs() + .filter(input -> input.getTypeName().equals(oldTypeEntry.getTypeName())).map(IInterfaceElement::getName) + .toList(); + + this.outputPinNames = fbType.getInterfaceList().getOutputs() + .filter(output -> output.getTypeName().equals(oldTypeEntry.getTypeName())) + .map(IInterfaceElement::getName).toList(); + } @Override public String getName() { - return "Update InterfacePins: - " + fbType.getName() + "." //$NON-NLS-1$ //$NON-NLS-2$ - + fbType.getTypeEntry().getFile().getFileExtension() + " - " //$NON-NLS-1$ - + fbType.getTypeEntry().getFile().getProject().getName() + ": " + pinNames.toString(); //$NON-NLS-1$ + return "Update Interface Pins: " + this.inputPinNames.toString() + "<->" + this.outputPinNames.toString(); //$NON-NLS-1$ } @Override diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/RenameTypeRefactoring.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/RenameTypeRefactoring.java deleted file mode 100644 index 10c9961808..0000000000 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/RenameTypeRefactoring.java +++ /dev/null @@ -1,233 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2023 Primetals Technologies Austria GmbH - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Michael Oberlehner - initial API and implementation and/or initial documentation - *******************************************************************************/ -package org.eclipse.fordiac.ide.typemanagement.refactoring; - -import java.text.MessageFormat; -import java.util.Set; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.fordiac.ide.model.data.StructuredType; -import org.eclipse.fordiac.ide.model.libraryElement.FBNetworkElement; -import org.eclipse.fordiac.ide.model.libraryElement.FBType; -import org.eclipse.fordiac.ide.model.libraryElement.INamedElement; -import org.eclipse.fordiac.ide.model.libraryElement.LibraryElement; -import org.eclipse.fordiac.ide.model.libraryElement.SubAppType; -import org.eclipse.fordiac.ide.model.search.types.FBInstanceSearch; -import org.eclipse.fordiac.ide.model.search.types.FBTypeSearch; -import org.eclipse.fordiac.ide.model.search.types.InstanceSearch; -import org.eclipse.fordiac.ide.model.search.types.StructDataTypeSearch; -import org.eclipse.fordiac.ide.model.typelibrary.DataTypeEntry; -import org.eclipse.fordiac.ide.model.typelibrary.TypeEntry; -import org.eclipse.fordiac.ide.model.typelibrary.TypeLibraryManager; -import org.eclipse.fordiac.ide.model.typelibrary.TypeLibraryTags; -import org.eclipse.fordiac.ide.typemanagement.Messages; -import org.eclipse.fordiac.ide.ui.editors.EditorUtils; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.CompositeChange; -import org.eclipse.ltk.core.refactoring.Refactoring; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.part.FileEditorInput; - -public class RenameTypeRefactoring extends Refactoring { - - private final TypeEntry typeEntry; - private String newName; - private final String oldName; - - protected String getOldName() { - return oldName; - } - - public RenameTypeRefactoring(final TypeEntry typeEntry, final String oldName) { - this.typeEntry = typeEntry; - this.oldName = oldName; - } - - public RenameTypeRefactoring() { - this.typeEntry = null; - this.oldName = ""; //$NON-NLS-1$ - } - - @Override - public RefactoringStatus checkFinalConditions(final IProgressMonitor monitor) - throws CoreException, OperationCanceledException { - return new RefactoringStatus(); - } - - @Override - public RefactoringStatus checkInitialConditions(final IProgressMonitor monitor) - throws CoreException, OperationCanceledException { - final RefactoringStatus status = new RefactoringStatus(); - try { - monitor.beginTask("Checking preconditions...", 1); //$NON-NLS-1$ - checkEditor(status, typeEntry, getOldName()); - - } finally { - monitor.done(); - } - return status; - } - - public static void checkEditor(final RefactoringStatus result, final TypeEntry typeEntry, final String oldName) { - // depending if the in-place renaming is active we may not be in the display - // thread - Display.getDefault().syncExec(() -> { - final IEditorPart findEditor = EditorUtils.findEditor( - (final IEditorPart editor) -> editor.getEditorInput() instanceof final FileEditorInput fei - && fei.getFile().equals(typeEntry.getFile())); - if (findEditor != null && findEditor.isDirty()) { - if (shouldSaveFile(findEditor.getSite().getShell(), oldName)) { - findEditor.doSave(new NullProgressMonitor()); - } else { - result.addFatalError("Abort rename as editor is dirty!"); //$NON-NLS-1$ - } - } - }); - } - - private static boolean shouldSaveFile(final Shell shell, final String oldName) { - final int result = MessageDialog.open(MessageDialog.QUESTION, shell, "Rename of Type with unsaved changes!", //$NON-NLS-1$ - MessageFormat.format( - "There are unsaved changes for type \"{0}\". Do you want to save them before renaming?", //$NON-NLS-1$ - TypeEntry.getTypeNameFromFileName(oldName)), - SWT.NONE, "Save", "Cancel"); //$NON-NLS-1$//$NON-NLS-2$ - return result == 0; - } - - @Override - public Change createChange(final IProgressMonitor monitor) throws CoreException, OperationCanceledException { - try { - monitor.beginTask("Creating change...", 1); //$NON-NLS-1$ - - final LibraryElement type = typeEntry.getType(); - if (type instanceof final StructuredType structType) { - return createStructDataChange(structType); - } - if (type instanceof final FBType fbType) { - return createFBDataChange(fbType); - } - return null; - - } finally { - monitor.done(); - } - } - - private CompositeChange createStructDataChange(final StructuredType type) { - InstanceSearch search = StructDataTypeSearch - .createStructMemberSearch((StructuredType) typeEntry.getTypeEditable()); - - final Set allFBWithStruct = InstanceSearch.performProjectSearch(typeEntry.getFile().getProject(), - StructDataTypeSearch.createStructMemberSearch((StructuredType) typeEntry.getTypeEditable()), - StructDataTypeSearch.createStructInterfaceSearch((StructuredType) typeEntry.getTypeEditable()), - new FBInstanceSearch((DataTypeEntry) typeEntry)); - allFBWithStruct.addAll(search.searchStructuredTypes(typeEntry.getTypeLibrary())); - final CompositeChange parentChange = new CompositeChange( - MessageFormat.format(Messages.Refactoring_RenameFromTo, typeEntry.getTypeName(), getNewName())); - - parentChange.add(new RenameTypeChange(typeEntry, getNewName() + ".dtp")); //$NON-NLS-1$ - - final CompositeChange change = new CompositeChange(Messages.Refactoring_AffectedStruct); - final CompositeChange fbTypeChanges = new CompositeChange("Fb Types:"); //$NON-NLS-1$ - search = StructDataTypeSearch.createStructInterfaceSearch((StructuredType) typeEntry.getTypeEditable()); - final Set fbTypes = search.performTypeLibBlockSearch(typeEntry.getTypeLibrary()); - fbTypes.forEach(fb -> fbTypeChanges.add(new InterfaceDataTypeChange((FBType) fb, typeEntry, oldName))); - parentChange.add(fbTypeChanges); - allFBWithStruct.stream().map(this::createSubChange).forEach(change::add); - - if (!allFBWithStruct.isEmpty()) { - parentChange.add(change); - } - - return parentChange; - } - - private CompositeChange createFBDataChange(final FBType type) { - final CompositeChange parentChange = new CompositeChange( - MessageFormat.format(Messages.Refactoring_RenameFromTo, typeEntry.getTypeName(), getNewName())); - Set allFBs; - if (type instanceof SubAppType) { - parentChange.add( - new RenameTypeChange(typeEntry, getNewName() + TypeLibraryTags.SUBAPP_TYPE_FILE_ENDING_WITH_DOT)); - } else { - parentChange - .add(new RenameTypeChange(typeEntry, getNewName() + TypeLibraryTags.FB_TYPE_FILE_ENDING_WITH_DOT)); - } - final CompositeChange change = new CompositeChange(Messages.Refactoring_AffectedInstancesOfFB); - allFBs = InstanceSearch.performProjectSearch(typeEntry.getFile().getProject(), - FBTypeSearch.createFBTypeSearch(type)); - allFBs.stream().map(FBNetworkElement.class::cast).map(fbn -> new UpdateInstancesChange(fbn, typeEntry)) - .forEach(change::add); - if (!allFBs.isEmpty()) { - parentChange.add(change); - } - return parentChange; - } - - private Change createSubChange(final INamedElement element) { - if (element instanceof final StructuredType stElement) { - return new StructuredTypeMemberChange(stElement, typeEntry, typeEntry.getTypeName(), getNewName()); - } - if (element instanceof final FBType fbType) { - return new InterfaceDataTypeChange(fbType, typeEntry, oldName); - } - if (element instanceof final FBNetworkElement elem) { - return new UpdateInstancesChange(elem, typeEntry); - } - return null; - } - - public RefactoringStatus setAndValidateTypeName(final String name) { - - final RefactoringStatus result = new RefactoringStatus(); - - if (getOldName().equals(name)) { - result.addFatalError(MessageFormat.format(" {0} is not a new Name", name)); //$NON-NLS-1$ - - } else if (nameExistsInTypeLibrary(name)) { - result.addFatalError(MessageFormat.format(Messages.RenameType_TypeExists, name)); - } - - if (result.isOK()) { - newName = name; - } - return result; - - } - - protected boolean nameExistsInTypeLibrary(final String name) { - return TypeLibraryManager.INSTANCE.getTypeLibrary(typeEntry.getFile().getProject()).find(name) != null; - } - - @Override - public String getName() { - return Messages.RenameType_Name; - } - - public TypeEntry getTypeEntry() { - return typeEntry; - } - - public String getNewName() { - return newName; - } - -} \ No newline at end of file diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/RenameTypeRefactoringParticipant.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/RenameTypeRefactoringParticipant.java index dbd18f0584..1ecc05b98e 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/RenameTypeRefactoringParticipant.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/RenameTypeRefactoringParticipant.java @@ -14,7 +14,12 @@ package org.eclipse.fordiac.ide.typemanagement.refactoring; import java.text.MessageFormat; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Objects; import java.util.Set; +import java.util.stream.Stream; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; @@ -104,38 +109,92 @@ public Change createChange(final IProgressMonitor monitor) throws CoreException, } private CompositeChange createStructDataChange(final StructuredType type) { - InstanceSearch search = StructDataTypeSearch - .createStructMemberSearch((StructuredType) typeEntry.getTypeEditable()); + final CompositeChange parentChange = new CompositeChange( + MessageFormat.format(Messages.Refactoring_RenameFromTo, typeEntry.getTypeName(), newName)); + + final Change typeLibraryChange = new UpdateTypeLibraryEntryChange(file, typeEntry, newName, oldName); + parentChange.add(typeLibraryChange); + + final CompositeChange fbTypeChange = getRequiredFbTypeChange(); + if (Objects.nonNull(fbTypeChange)) { + parentChange.add(fbTypeChange); + } + + final CompositeChange structChange = getRequiredStructChange(); + if (Objects.nonNull(structChange)) { + parentChange.add(structChange); + } + + return parentChange; + } + + private CompositeChange getRequiredFbTypeChange() { + final InstanceSearch search = StructDataTypeSearch + .createStructInterfaceSearch((StructuredType) typeEntry.getTypeEditable()); + final Set fbTypes = search.performTypeLibBlockSearch(typeEntry.getTypeLibrary()); + + if (fbTypes.isEmpty()) { + return null; + } + + final CompositeChange fbTypeChanges = new CompositeChange(Messages.Refactoring_AffectedFuctionBlock); + + final Map> affectedFunctionBlockChangeInterfaces = new HashMap<>(); + + fbTypes.stream().filter(FBType.class::isInstance).map(fb -> (FBType) fb).forEach(fb -> { + + final String label = fb.getTypeEntry().getFile().getName() + " [" + + fb.getTypeEntry().getFile().getProject().getName() + "]"; + + if (!affectedFunctionBlockChangeInterfaces.containsKey(label)) { + affectedFunctionBlockChangeInterfaces.put(label, new HashSet<>()); + } + + affectedFunctionBlockChangeInterfaces.get(label).add(new InterfaceDataTypeChange(fb, typeEntry, oldName)); + + }); + + final Stream changesStream = affectedFunctionBlockChangeInterfaces.entrySet().stream() + .map(entry -> { + final CompositeChange fbChange = new CompositeChange(entry.getKey()); + + entry.getValue().stream().forEach(fbChange::add); + + return fbChange; + }); + + changesStream.forEach(fbTypeChanges::add); + + return fbTypeChanges; + } + + private CompositeChange getRequiredStructChange() { final IProject project = typeEntry.getFile().getProject(); - final Set allFBWithStruct = InstanceSearch.performProjectSearch(project, - StructDataTypeSearch.createStructMemberSearch((StructuredType) typeEntry.getTypeEditable()), + final CompositeChange structChange = new CompositeChange(Messages.Refactoring_AffectedStruct); + + final InstanceSearch structMemberSearch = StructDataTypeSearch + .createStructMemberSearch((StructuredType) typeEntry.getTypeEditable()); + + final Set allFBWithStruct = InstanceSearch.performProjectSearch(project, structMemberSearch, StructDataTypeSearch.createStructInterfaceSearch((StructuredType) typeEntry.getTypeEditable()), new FBInstanceSearch((DataTypeEntry) typeEntry)); - allFBWithStruct.addAll(search.searchStructuredTypes(typeEntry.getTypeLibrary())); - final CompositeChange parentChange = new CompositeChange( - MessageFormat.format(Messages.Refactoring_RenameFromTo, typeEntry.getTypeName(), newName)); - parentChange.add(new UpdateTypeEntryChange(file, typeEntry, newName, oldName)); - final CompositeChange change = new CompositeChange(Messages.Refactoring_AffectedStruct); - final CompositeChange fbTypeChanges = new CompositeChange("Fb Types:"); //$NON-NLS-1$ - search = StructDataTypeSearch.createStructInterfaceSearch((StructuredType) typeEntry.getTypeEditable()); - final Set fbTypes = search.performTypeLibBlockSearch(typeEntry.getTypeLibrary()); - fbTypes.forEach(fb -> fbTypeChanges.add(new InterfaceDataTypeChange((FBType) fb, typeEntry, oldName))); - parentChange.add(fbTypeChanges); - allFBWithStruct.stream().map(this::createSubChange).forEach(change::add); + allFBWithStruct.addAll(structMemberSearch.searchStructuredTypes(typeEntry.getTypeLibrary())); - if (!allFBWithStruct.isEmpty()) { - parentChange.add(change); + if (allFBWithStruct.isEmpty()) { + return null; } - return parentChange; + allFBWithStruct.stream().map(this::createSubChange).forEach(structChange::add); + + return structChange; } private CompositeChange createFBDataChange(final FBType type) { final CompositeChange parentChange = new CompositeChange( MessageFormat.format(Messages.Refactoring_RenameFromTo, typeEntry.getTypeName(), newName)); - parentChange.add(new UpdateTypeEntryChange(file, typeEntry, newName, oldName)); + parentChange.add(new UpdateTypeLibraryEntryChange(file, typeEntry, newName, oldName)); Set allFBs; final CompositeChange change = new CompositeChange(Messages.Refactoring_AffectedInstancesOfFB); final IProject project = type.getTypeEntry().getFile().getProject(); diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/UpdateTypeEntryChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/UpdateTypeLibraryEntryChange.java similarity index 94% rename from plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/UpdateTypeEntryChange.java rename to plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/UpdateTypeLibraryEntryChange.java index 86bfd5bc28..925bca3ac2 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/UpdateTypeEntryChange.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/UpdateTypeLibraryEntryChange.java @@ -35,14 +35,14 @@ import org.eclipse.ui.IEditorPart; import org.eclipse.ui.part.FileEditorInput; -public class UpdateTypeEntryChange extends Change { +public class UpdateTypeLibraryEntryChange extends Change { IFile file; TypeEntry typeEntry; String newName; String oldName; - UpdateTypeEntryChange(final IFile file, final TypeEntry typeEntry, final String newName, final String oldName) { + UpdateTypeLibraryEntryChange(final IFile file, final TypeEntry typeEntry, final String newName, final String oldName) { this.file = file; this.typeEntry = typeEntry; this.newName = newName; @@ -98,7 +98,7 @@ public Change perform(final IProgressMonitor pm) throws CoreException { if (newFile != null) { FordiacResourceChangeListener.updateTypeEntryByRename(newFile, typeEntry); - return new UpdateTypeEntryChange(newFile, typeEntry, oldName, newName); + return new UpdateTypeLibraryEntryChange(newFile, typeEntry, oldName, newName); } return null; } From f9e7c1ce71340f0d5d8b86647b36d58b5943005f Mon Sep 17 00:00:00 2001 From: Terra Date: Mon, 8 Apr 2024 20:58:44 +0200 Subject: [PATCH 02/22] Completed refactor view refactor --- .../fordiac/ide/typemanagement/Messages.java | 1 + .../ide/typemanagement/messages.properties | 1 + .../refactoring/InterfaceDataTypeChange.java | 11 +-- .../RenameTypeRefactoringParticipant.java | 97 +++---------------- .../StructuredTypeMemberChange.java | 23 ++--- .../refactoring/UpdateInstancesChange.java | 3 +- .../refactoring/rename/FbInstanceChange.java | 76 +++++++++++++++ .../refactoring/rename/FbTypeChange.java | 72 ++++++++++++++ .../refactoring/rename/StructTypeChange.java | 76 +++++++++++++++ 9 files changed, 255 insertions(+), 105 deletions(-) create mode 100644 plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbInstanceChange.java create mode 100644 plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbTypeChange.java create mode 100644 plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/StructTypeChange.java diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/Messages.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/Messages.java index 6dfd58feea..6487384905 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/Messages.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/Messages.java @@ -133,6 +133,7 @@ public final class Messages extends NLS { public static String Refactoring_RenameFromTo; public static String Refactoring_AffectedFuctionBlock; public static String Refactoring_AffectedStruct; + public static String Refactoring_AffectedFbInstances; public static String Refactoring_AffectedInstancesOfFB; public static String Refactoring_UpdateTypeEntryChange; diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/messages.properties b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/messages.properties index f4c7ed0715..b14ef9ce10 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/messages.properties +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/messages.properties @@ -93,6 +93,7 @@ Warning=Warning Refactoring_RenameFromTo=Rename Type from ''{0}'' to ''{1}'' Refactoring_AffectedFuctionBlock=Update affected Function Blocks Refactoring_AffectedStruct=Update affected Structs +Refactoring_AffectedFbInstances=Update affected Function Block instances Refactoring_AffectedInstancesOfFB=Affected Instances of this FB Type Refactoring_UpdateTypeEntryChange=Update type library and editors UpdatedInstances=Instances which have been updated with the new type library version diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/InterfaceDataTypeChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/InterfaceDataTypeChange.java index 99f1d705e6..ab71d693f2 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/InterfaceDataTypeChange.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/InterfaceDataTypeChange.java @@ -31,15 +31,13 @@ public class InterfaceDataTypeChange extends Change { private final FBType fbType; - private final TypeEntry typeEntry; - private final String oldName; + private final TypeEntry oldTypeEntry; private final List inputPinNames; private final List outputPinNames; - public InterfaceDataTypeChange(final FBType fbType, final TypeEntry oldTypeEntry, final String oldName) { + public InterfaceDataTypeChange(final FBType fbType, final TypeEntry oldTypeEntry) { this.fbType = fbType; - this.typeEntry = oldTypeEntry; - this.oldName = oldName; + this.oldTypeEntry = oldTypeEntry; this.inputPinNames = fbType.getInterfaceList().getInputs() .filter(input -> input.getTypeName().equals(oldTypeEntry.getTypeName())).map(IInterfaceElement::getName) .toList(); @@ -61,7 +59,8 @@ public void initializeValidationData(final IProgressMonitor pm) { } private Command getUpdatePinInTypeDelcarationCommand() { - return FBUpdater.createUpdatePinInTypeDeclarationCommand(fbType, (DataTypeEntry) typeEntry, oldName); + return FBUpdater.createUpdatePinInTypeDeclarationCommand(fbType, (DataTypeEntry) this.oldTypeEntry, + this.oldTypeEntry.getTypeName()); } @Override diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/RenameTypeRefactoringParticipant.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/RenameTypeRefactoringParticipant.java index 1ecc05b98e..d566d29d1b 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/RenameTypeRefactoringParticipant.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/RenameTypeRefactoringParticipant.java @@ -14,12 +14,7 @@ package org.eclipse.fordiac.ide.typemanagement.refactoring; import java.text.MessageFormat; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Objects; import java.util.Set; -import java.util.stream.Stream; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; @@ -32,12 +27,12 @@ import org.eclipse.fordiac.ide.model.libraryElement.INamedElement; import org.eclipse.fordiac.ide.model.libraryElement.LibraryElement; import org.eclipse.fordiac.ide.model.search.types.FBInstanceSearch; -import org.eclipse.fordiac.ide.model.search.types.InstanceSearch; -import org.eclipse.fordiac.ide.model.search.types.StructDataTypeSearch; -import org.eclipse.fordiac.ide.model.typelibrary.DataTypeEntry; import org.eclipse.fordiac.ide.model.typelibrary.TypeEntry; import org.eclipse.fordiac.ide.model.typelibrary.TypeLibraryManager; import org.eclipse.fordiac.ide.typemanagement.Messages; +import org.eclipse.fordiac.ide.typemanagement.refactoring.rename.FbInstanceChange; +import org.eclipse.fordiac.ide.typemanagement.refactoring.rename.FbTypeChange; +import org.eclipse.fordiac.ide.typemanagement.refactoring.rename.StructTypeChange; import org.eclipse.ltk.core.refactoring.Change; import org.eclipse.ltk.core.refactoring.CompositeChange; import org.eclipse.ltk.core.refactoring.RefactoringStatus; @@ -115,80 +110,22 @@ private CompositeChange createStructDataChange(final StructuredType type) { final Change typeLibraryChange = new UpdateTypeLibraryEntryChange(file, typeEntry, newName, oldName); parentChange.add(typeLibraryChange); - final CompositeChange fbTypeChange = getRequiredFbTypeChange(); - if (Objects.nonNull(fbTypeChange)) { + final CompositeChange fbTypeChange = new FbTypeChange(file); + if (fbTypeChange.getChildren().length != 0) { parentChange.add(fbTypeChange); } - final CompositeChange structChange = getRequiredStructChange(); - if (Objects.nonNull(structChange)) { + final CompositeChange structChange = new StructTypeChange(file); + if (structChange.getChildren().length != 0) { parentChange.add(structChange); } - return parentChange; - } - - private CompositeChange getRequiredFbTypeChange() { - final InstanceSearch search = StructDataTypeSearch - .createStructInterfaceSearch((StructuredType) typeEntry.getTypeEditable()); - final Set fbTypes = search.performTypeLibBlockSearch(typeEntry.getTypeLibrary()); - - if (fbTypes.isEmpty()) { - return null; + final CompositeChange fbInstanceChange = new FbInstanceChange(file); + if (fbInstanceChange.getChildren().length != 0) { + parentChange.add(fbInstanceChange); } - final CompositeChange fbTypeChanges = new CompositeChange(Messages.Refactoring_AffectedFuctionBlock); - - final Map> affectedFunctionBlockChangeInterfaces = new HashMap<>(); - - fbTypes.stream().filter(FBType.class::isInstance).map(fb -> (FBType) fb).forEach(fb -> { - - final String label = fb.getTypeEntry().getFile().getName() + " [" - + fb.getTypeEntry().getFile().getProject().getName() + "]"; - - if (!affectedFunctionBlockChangeInterfaces.containsKey(label)) { - affectedFunctionBlockChangeInterfaces.put(label, new HashSet<>()); - } - - affectedFunctionBlockChangeInterfaces.get(label).add(new InterfaceDataTypeChange(fb, typeEntry, oldName)); - - }); - - final Stream changesStream = affectedFunctionBlockChangeInterfaces.entrySet().stream() - .map(entry -> { - final CompositeChange fbChange = new CompositeChange(entry.getKey()); - - entry.getValue().stream().forEach(fbChange::add); - - return fbChange; - }); - - changesStream.forEach(fbTypeChanges::add); - - return fbTypeChanges; - } - - private CompositeChange getRequiredStructChange() { - final IProject project = typeEntry.getFile().getProject(); - - final CompositeChange structChange = new CompositeChange(Messages.Refactoring_AffectedStruct); - - final InstanceSearch structMemberSearch = StructDataTypeSearch - .createStructMemberSearch((StructuredType) typeEntry.getTypeEditable()); - - final Set allFBWithStruct = InstanceSearch.performProjectSearch(project, structMemberSearch, - StructDataTypeSearch.createStructInterfaceSearch((StructuredType) typeEntry.getTypeEditable()), - new FBInstanceSearch((DataTypeEntry) typeEntry)); - - allFBWithStruct.addAll(structMemberSearch.searchStructuredTypes(typeEntry.getTypeLibrary())); - - if (allFBWithStruct.isEmpty()) { - return null; - } - - allFBWithStruct.stream().map(this::createSubChange).forEach(structChange::add); - - return structChange; + return parentChange; } private CompositeChange createFBDataChange(final FBType type) { @@ -213,16 +150,4 @@ private CompositeChange createFBDataChange(final FBType type) { return parentChange; } - private Change createSubChange(final INamedElement element) { - if (element instanceof final StructuredType stElement) { - return new StructuredTypeMemberChange(stElement, typeEntry, typeEntry.getTypeName(), newName); - } - if (element instanceof final FBType fbType) { - return new InterfaceDataTypeChange(fbType, typeEntry, oldName); - } - if (element instanceof final FBNetworkElement elem) { - return new UpdateInstancesChange(elem, typeEntry); - } - return null; - } } diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/StructuredTypeMemberChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/StructuredTypeMemberChange.java index 3a73e90e11..2c23ced71a 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/StructuredTypeMemberChange.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/StructuredTypeMemberChange.java @@ -12,6 +12,8 @@ *******************************************************************************/ package org.eclipse.fordiac.ide.typemanagement.refactoring; +import java.util.List; + import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; @@ -27,23 +29,21 @@ public class StructuredTypeMemberChange extends Change { private final StructuredType affectedStruct; - private final TypeEntry typeEntry; - private final String oldName; + private final TypeEntry oldTypeEntry; + private final List affectedMembers; private final CompoundCommand cmd = new CompoundCommand(); - public StructuredTypeMemberChange(final StructuredType affectedStruct, final TypeEntry oldTypeEntry, - final String oldName, final String newName) { + public StructuredTypeMemberChange(final StructuredType affectedStruct, final TypeEntry oldTypeEntry) { this.affectedStruct = affectedStruct; - this.typeEntry = oldTypeEntry; - this.oldName = oldName; + this.oldTypeEntry = oldTypeEntry; + this.affectedMembers = affectedStruct.getMemberVariables().stream() + .filter(var -> var.getType().equals(oldTypeEntry.getType())).map(VarDeclaration::getName).toList(); } @Override public String getName() { - return "Update Struct Members - " + affectedStruct.getName() + "." //$NON-NLS-1$ //$NON-NLS-2$ - + affectedStruct.getTypeEntry().getFile().getFileExtension() + " - " //$NON-NLS-1$ - + affectedStruct.getTypeEntry().getFile().getProject().getName(); + return "Update Struct Members: " + this.affectedMembers.toString(); //$NON-NLS-1$ } @Override @@ -63,8 +63,9 @@ public Change perform(final IProgressMonitor pm) throws CoreException { final StructuredType structuredTypeEditable = (StructuredType) affectedStruct.getTypeEntry().getTypeEditable(); for (final VarDeclaration varDeclaration : structuredTypeEditable.getMemberVariables()) { final String typeName = varDeclaration.getTypeName(); - if (typeName.equals(oldName)) { - cmd.add(ChangeDataTypeCommand.forDataType(varDeclaration, (DataType) typeEntry.getTypeEditable())); + if (typeName.equals(this.oldTypeEntry.getTypeName())) { + cmd.add(ChangeDataTypeCommand.forDataType(varDeclaration, + (DataType) this.oldTypeEntry.getTypeEditable())); } } diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/UpdateInstancesChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/UpdateInstancesChange.java index 5c17af9161..d20377c9c4 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/UpdateInstancesChange.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/UpdateInstancesChange.java @@ -23,7 +23,6 @@ import org.eclipse.fordiac.ide.model.commands.change.UpdateInternalFBCommand; import org.eclipse.fordiac.ide.model.commands.change.UpdateUntypedSubAppInterfaceCommand; import org.eclipse.fordiac.ide.model.data.StructuredType; -import org.eclipse.fordiac.ide.model.helpers.FBNetworkHelper; import org.eclipse.fordiac.ide.model.libraryElement.BaseFBType; import org.eclipse.fordiac.ide.model.libraryElement.FB; import org.eclipse.fordiac.ide.model.libraryElement.FBNetworkElement; @@ -52,7 +51,7 @@ public UpdateInstancesChange(final FBNetworkElement instance) { @Override public String getName() { - return "Update FB instances - " + FBNetworkHelper.getFullHierarchicalName(instance); //$NON-NLS-1$ + return "Update FB instance: " + instance.getName(); //$NON-NLS-1$ } @Override diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbInstanceChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbInstanceChange.java new file mode 100644 index 0000000000..8b995ebe28 --- /dev/null +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbInstanceChange.java @@ -0,0 +1,76 @@ +package org.eclipse.fordiac.ide.typemanagement.refactoring.rename; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.eclipse.core.resources.IFile; +import org.eclipse.fordiac.ide.model.data.StructuredType; +import org.eclipse.fordiac.ide.model.libraryElement.FBNetworkElement; +import org.eclipse.fordiac.ide.model.libraryElement.INamedElement; +import org.eclipse.fordiac.ide.model.search.types.FBInstanceSearch; +import org.eclipse.fordiac.ide.model.search.types.InstanceSearch; +import org.eclipse.fordiac.ide.model.search.types.StructDataTypeSearch; +import org.eclipse.fordiac.ide.model.typelibrary.DataTypeEntry; +import org.eclipse.fordiac.ide.model.typelibrary.TypeEntry; +import org.eclipse.fordiac.ide.model.typelibrary.TypeLibraryManager; +import org.eclipse.fordiac.ide.typemanagement.Messages; +import org.eclipse.fordiac.ide.typemanagement.refactoring.UpdateInstancesChange; +import org.eclipse.ltk.core.refactoring.Change; +import org.eclipse.ltk.core.refactoring.CompositeChange; + +public class FbInstanceChange extends CompositeChange { + + private final IFile file; + private final TypeEntry oldTypeEntry; + + public FbInstanceChange(final IFile file) { + super(Messages.Refactoring_AffectedFbInstances); + this.file = file; + this.oldTypeEntry = TypeLibraryManager.INSTANCE.getTypeEntryForFile(file); + buildChanges(); + } + + private void buildChanges() { + buildSubChanges().forEach(this::add); + } + + private List buildSubChanges() { + final Map> affectedStructChanges = new HashMap<>(); + + searchAffectedStructuredType().forEach(impactedStructuredType -> { + final String label = impactedStructuredType.getTypeEntry().getFile().getProject().getName(); + + if (!affectedStructChanges.containsKey(label)) { + affectedStructChanges.put(label, new HashSet<>()); + } + + affectedStructChanges.get(label).add(new UpdateInstancesChange(impactedStructuredType, oldTypeEntry)); + }); + + return affectedStructChanges.entrySet().stream().map(entry -> { + final CompositeChange fbChange = new CompositeChange(entry.getKey()); + + entry.getValue().stream().forEach(fbChange::add); + + return fbChange; + }).toList(); + } + + private List searchAffectedStructuredType() { + final InstanceSearch structMemberSearch = StructDataTypeSearch + .createStructMemberSearch((StructuredType) oldTypeEntry.getTypeEditable()); + + final Set search = InstanceSearch.performProjectSearch(this.file.getProject(), + StructDataTypeSearch.createStructMemberSearch((StructuredType) oldTypeEntry.getTypeEditable()), + StructDataTypeSearch.createStructInterfaceSearch((StructuredType) oldTypeEntry.getTypeEditable()), + new FBInstanceSearch((DataTypeEntry) oldTypeEntry)); + + search.addAll(StructDataTypeSearch.createStructMemberSearch((StructuredType) oldTypeEntry.getTypeEditable()) + .searchStructuredTypes(oldTypeEntry.getTypeLibrary())); + return search.stream().filter(FBNetworkElement.class::isInstance).map(FBNetworkElement.class::cast).toList(); + } + +} diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbTypeChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbTypeChange.java new file mode 100644 index 0000000000..e26342a1b1 --- /dev/null +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbTypeChange.java @@ -0,0 +1,72 @@ +package org.eclipse.fordiac.ide.typemanagement.refactoring.rename; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.eclipse.core.resources.IFile; +import org.eclipse.fordiac.ide.model.data.StructuredType; +import org.eclipse.fordiac.ide.model.libraryElement.FBType; +import org.eclipse.fordiac.ide.model.search.types.InstanceSearch; +import org.eclipse.fordiac.ide.model.search.types.StructDataTypeSearch; +import org.eclipse.fordiac.ide.model.typelibrary.TypeEntry; +import org.eclipse.fordiac.ide.model.typelibrary.TypeLibraryManager; +import org.eclipse.fordiac.ide.typemanagement.Messages; +import org.eclipse.fordiac.ide.typemanagement.refactoring.InterfaceDataTypeChange; +import org.eclipse.ltk.core.refactoring.Change; +import org.eclipse.ltk.core.refactoring.CompositeChange; + +public class FbTypeChange extends CompositeChange { + + private final IFile file; + private final TypeEntry oldTypeEntry; + + public FbTypeChange(final IFile targetFile) { + super(Messages.Refactoring_AffectedFuctionBlock); + this.file = targetFile; + this.oldTypeEntry = TypeLibraryManager.INSTANCE.getTypeEntryForFile(this.file); + buildChanges(); + } + + private void buildChanges() { + buildSubChanges().forEach(this::add); + } + + private List buildSubChanges() { + final List affectedFBs = searchAffectedFBs(); + + final Map> functionBlockChangeMap = new HashMap<>(); + + affectedFBs.forEach(functionBlockType -> { + final String label = buildLabel(functionBlockType.getTypeEntry().getFile().getName(), + functionBlockType.getTypeEntry().getFile().getProject().getName()); + + if (!functionBlockChangeMap.containsKey(label)) { + functionBlockChangeMap.put(label, new HashSet<>()); + } + + functionBlockChangeMap.get(label).add(new InterfaceDataTypeChange(functionBlockType, oldTypeEntry)); + }); + + return functionBlockChangeMap.entrySet().stream().map(entry -> { + final CompositeChange fbChange = new CompositeChange(entry.getKey()); + entry.getValue().stream().forEach(fbChange::add); + return fbChange; + }).toList(); + } + + private List searchAffectedFBs() { + final InstanceSearch search = StructDataTypeSearch + .createStructInterfaceSearch((StructuredType) oldTypeEntry.getTypeEditable()); + + return search.performTypeLibBlockSearch(oldTypeEntry.getTypeLibrary()).stream().filter(FBType.class::isInstance) + .map(FBType.class::cast).toList(); + } + + private String buildLabel(final String fbFileName, final String projectName) { + return fbFileName + " [" + projectName + "]"; //$NON-NLS-1$ + } + +} diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/StructTypeChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/StructTypeChange.java new file mode 100644 index 0000000000..cee71cf33c --- /dev/null +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/StructTypeChange.java @@ -0,0 +1,76 @@ +package org.eclipse.fordiac.ide.typemanagement.refactoring.rename; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.eclipse.core.resources.IFile; +import org.eclipse.fordiac.ide.model.data.StructuredType; +import org.eclipse.fordiac.ide.model.libraryElement.INamedElement; +import org.eclipse.fordiac.ide.model.search.types.InstanceSearch; +import org.eclipse.fordiac.ide.model.search.types.StructDataTypeSearch; +import org.eclipse.fordiac.ide.model.typelibrary.TypeEntry; +import org.eclipse.fordiac.ide.model.typelibrary.TypeLibraryManager; +import org.eclipse.fordiac.ide.typemanagement.Messages; +import org.eclipse.fordiac.ide.typemanagement.refactoring.StructuredTypeMemberChange; +import org.eclipse.ltk.core.refactoring.Change; +import org.eclipse.ltk.core.refactoring.CompositeChange; + +public class StructTypeChange extends CompositeChange { + + private final IFile file; + private final TypeEntry oldTypeEntry; + + public StructTypeChange(final IFile file) { + super(Messages.Refactoring_AffectedStruct); + this.file = file; + this.oldTypeEntry = TypeLibraryManager.INSTANCE.getTypeEntryForFile(file); + buildChanges(); + } + + private void buildChanges() { + buildSubChanges().forEach(this::add); + } + + private List buildSubChanges() { + final Map> affectedStructChanges = new HashMap<>(); + + searchAffectedStructuredType().forEach(impactedStructuredType -> { + final String label = buildLabel(impactedStructuredType.getTypeEntry().getFile().getName(), + impactedStructuredType.getTypeEntry().getFile().getProject().getName()); + + if (!affectedStructChanges.containsKey(label)) { + affectedStructChanges.put(label, new HashSet<>()); + } + + affectedStructChanges.get(label).add(new StructuredTypeMemberChange(impactedStructuredType, oldTypeEntry)); + }); + + return affectedStructChanges.entrySet().stream().map(entry -> { + final CompositeChange fbChange = new CompositeChange(entry.getKey()); + + entry.getValue().stream().forEach(fbChange::add); + + return fbChange; + }).toList(); + } + + private List searchAffectedStructuredType() { + final InstanceSearch structMemberSearch = StructDataTypeSearch + .createStructMemberSearch((StructuredType) oldTypeEntry.getTypeEditable()); + + final Set search = InstanceSearch.performProjectSearch(this.file.getProject(), + StructDataTypeSearch.createStructMemberSearch((StructuredType) oldTypeEntry.getTypeEditable()), + StructDataTypeSearch.createStructInterfaceSearch((StructuredType) oldTypeEntry.getTypeEditable())); + + search.addAll(StructDataTypeSearch.createStructMemberSearch((StructuredType) oldTypeEntry.getTypeEditable()) + .searchStructuredTypes(oldTypeEntry.getTypeLibrary())); + return search.stream().filter(StructuredType.class::isInstance).map(StructuredType.class::cast).toList(); + } + + private String buildLabel(final String fbFileName, final String projectName) { + return fbFileName + " [" + projectName + "]"; //$NON-NLS-1$ + } +} From 19e372df545b6a5bd901f62cd851f8dd45c510c3 Mon Sep 17 00:00:00 2001 From: Terra Date: Tue, 9 Apr 2024 22:54:36 +0200 Subject: [PATCH 03/22] Added first EMF compare view - wip --- .../META-INF/MANIFEST.MF | 10 +- .../plugin.xml | 12 +- .../ide/typemanagement/PreviewCommand.java | 110 ++++++++++++++++++ .../ChangeConfigurationViewer.java | 2 +- .../previews/StructChangePreviewViewer.java | 79 +++++++++++++ .../StructuredTypeMemberChange.java | 32 +++-- 6 files changed, 231 insertions(+), 14 deletions(-) create mode 100644 plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/PreviewCommand.java rename plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/{wizards => previews}/ChangeConfigurationViewer.java (98%) create mode 100644 plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/StructChangePreviewViewer.java diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/META-INF/MANIFEST.MF b/plugins/org.eclipse.fordiac.ide.typemanagement/META-INF/MANIFEST.MF index 6b271634f1..9d8071e183 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/META-INF/MANIFEST.MF @@ -19,7 +19,10 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.ltk.ui.refactoring, org.eclipse.fordiac.ide.model.search, org.eclipse.fordiac.ide.model.commands, - org.eclipse.fordiac.ide.model.ui + org.eclipse.fordiac.ide.model.ui, + org.eclipse.compare;bundle-version="3.9.300", + org.eclipse.emf.common, + org.eclipse.emf.compare.ide.ui;bundle-version="4.4.3" Bundle-Vendor: Eclipse 4diac Bundle-ActivationPolicy: lazy Bundle-Version: 2.0.1.qualifier @@ -35,4 +38,7 @@ Export-Package: org.eclipse.fordiac.ide.typemanagement, org.eclipse.fordiac.ide.typemanagement.util, org.eclipse.fordiac.ide.typemanagement.wizards Automatic-Module-Name: org.eclipse.fordiac.ide.typemanagement -Import-Package: org.eclipse.fordiac.ide.model.ui.editors +Import-Package: org.eclipse.emf.compare, + org.eclipse.emf.compare.domain, + org.eclipse.emf.compare.domain.impl, + org.eclipse.fordiac.ide.model.ui.editors diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/plugin.xml b/plugins/org.eclipse.fordiac.ide.typemanagement/plugin.xml index 347c42bcb6..a91fa67c90 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/plugin.xml +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/plugin.xml @@ -721,7 +721,7 @@ @@ -731,6 +731,16 @@ + + + + + + + diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/PreviewCommand.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/PreviewCommand.java new file mode 100644 index 0000000000..d695cb7c4a --- /dev/null +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/PreviewCommand.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * Copyright (c) Philipps University of Marburg. All rights reserved. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Philipps University of Marburg - initial API and implementation + *******************************************************************************/ +package org.eclipse.fordiac.ide.typemanagement; + +import org.eclipse.emf.common.command.AbstractCommand; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.gef.commands.CompoundCommand; + +/** + * Class used for providing a command that provides a preview of the rfactored + * EMF model. + * + * @generated NOT + * @author Florian Mantz + */ +public class PreviewCommand extends AbstractCommand { + + /** + * Command that was the origin of the PreviewCommand. + */ + final CompoundCommand command; + + /** + * Root element of the EMF model. + */ + private final EObject root; + + /** + * Copy of the root element of the model (temporary model). + */ + private EObject rootCopy; + + /** + * Default constructor using the origin RefactoringCommand and the root of the + * EMF model. + * + * @param command Origin RefactoringCommand. + * @param root Root element of the EMF model. + */ + public PreviewCommand(final CompoundCommand command, final EObject root) { + this.command = command; + this.root = root; + } + + /** + * @see org.eclipse.emf.common.command.Command#execute() + */ + @Override + public void execute() { + this.command.execute(); + rootCopy = this.generateRootCopy(); + this.command.undo(); + } + + /** + * Generates a copy of the EMF model presented by the root element. + * + * @return Copy of the EMF model presented by the root element. + */ + private EObject generateRootCopy() { + // final Copier copier = new Copier(); + return EcoreUtil.copy(this.root); + // final EObject rootCopy = copier.copy(this.root); + // copier.copyReferences(); + // return rootCopy; + } + + /** + * @see org.eclipse.emf.common.command.Command#redo() + */ + @Override + public void redo() { + // do nothing + } + + /** + * @see org.eclipse.emf.common.command.AbstractCommand#canExecute() + */ + @Override + public boolean canExecute() { + return true; + } + + /** + * @see org.eclipse.emf.common.command.AbstractCommand#canUndo() + */ + @Override + public boolean canUndo() { + return false; // Important + } + + /** + * Gets a copy of the root element of the model (temporary model). + * + * @return Copy of the root element of the model (temporary model). + */ + public EObject getRootCopy() { + return rootCopy; + } + +} diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/wizards/ChangeConfigurationViewer.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/ChangeConfigurationViewer.java similarity index 98% rename from plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/wizards/ChangeConfigurationViewer.java rename to plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/ChangeConfigurationViewer.java index 7d6dd7f5a2..121863af71 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/wizards/ChangeConfigurationViewer.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/ChangeConfigurationViewer.java @@ -13,7 +13,7 @@ * Dario Romano * - add correct preservation of selection and ui initialization from change state *******************************************************************************/ -package org.eclipse.fordiac.ide.typemanagement.wizards; +package org.eclipse.fordiac.ide.typemanagement.previews; import java.util.HashMap; import java.util.Map; diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/StructChangePreviewViewer.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/StructChangePreviewViewer.java new file mode 100644 index 0000000000..1fe7bf67f2 --- /dev/null +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/StructChangePreviewViewer.java @@ -0,0 +1,79 @@ +package org.eclipse.fordiac.ide.typemanagement.previews; + +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.compare.CompareConfiguration; +import org.eclipse.compare.CompareEditorInput; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.emf.common.notify.AdapterFactory; +import org.eclipse.emf.compare.Comparison; +import org.eclipse.emf.compare.EMFCompare; +import org.eclipse.emf.compare.domain.ICompareEditingDomain; +import org.eclipse.emf.compare.domain.impl.EMFCompareEditingDomain; +import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration; +import org.eclipse.emf.compare.ide.ui.internal.editor.ComparisonEditorInput; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.edit.provider.ComposedAdapterFactory; +import org.eclipse.fordiac.ide.typemanagement.PreviewCommand; +import org.eclipse.fordiac.ide.typemanagement.refactoring.StructuredTypeMemberChange; +import org.eclipse.ltk.ui.refactoring.ChangePreviewViewerInput; +import org.eclipse.ltk.ui.refactoring.IChangePreviewViewer; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + +public class StructChangePreviewViewer implements IChangePreviewViewer { + + private Composite parent; + private Control previewControl; + + @Override + public void createControl(final Composite parent) { + parent.setSize(500, 500); + this.parent = parent; + } + + @Override + public Control getControl() { + return previewControl; + } + + @Override + public void setInput(final ChangePreviewViewerInput input) { + + // There is a with EMF compare where it will not show struct member changes! + + System.out.println("===>> change: " + input.getChange()); + if (!(input.getChange() instanceof StructuredTypeMemberChange)) { + return; + } + + final StructuredTypeMemberChange change = (StructuredTypeMemberChange) input.getChange(); + final EObject model1 = change.getModifiedElement(); + final PreviewCommand previewCommand = new PreviewCommand(change.getRefactoringCommand(), model1); + change.getRefactoringCommand().execute(); + final EObject model2 = change.getModifiedElement().getTypeEntry().getTypeEditable(); + + // final EObject model2 = previewCommand.getRootCopy(); + // final EObject model2 = change.getModifiedElement(); + + System.out.println("===>> model1: " + model1); + System.out.println("===>> model2: " + model2); + final EMFCompare compare = EMFCompare.builder().build(); + final Comparison comparison = compare.compare(EMFCompare.createDefaultScope(model2, model1)); + final AdapterFactory adapterFactory = new ComposedAdapterFactory( + ComposedAdapterFactory.Descriptor.Registry.INSTANCE); + final ICompareEditingDomain editingDomain = EMFCompareEditingDomain.create(model2, model1, null); + final CompareEditorInput compareEditorInput = new ComparisonEditorInput( + new EMFCompareConfiguration(new CompareConfiguration()), comparison, editingDomain, adapterFactory); + try { + compareEditorInput.run(new NullProgressMonitor()); + previewControl = compareEditorInput.createContents(parent); + previewControl.setLayoutData(new FillLayout()); + } catch (final InvocationTargetException | InterruptedException e) { + e.printStackTrace(); + } + + } + +} diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/StructuredTypeMemberChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/StructuredTypeMemberChange.java index 2c23ced71a..2a5539c60d 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/StructuredTypeMemberChange.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/StructuredTypeMemberChange.java @@ -35,10 +35,26 @@ public class StructuredTypeMemberChange extends Change { private final CompoundCommand cmd = new CompoundCommand(); public StructuredTypeMemberChange(final StructuredType affectedStruct, final TypeEntry oldTypeEntry) { + this.affectedStruct = affectedStruct; this.oldTypeEntry = oldTypeEntry; this.affectedMembers = affectedStruct.getMemberVariables().stream() .filter(var -> var.getType().equals(oldTypeEntry.getType())).map(VarDeclaration::getName).toList(); + + this.buildRefactoringChange(); + + } + + public void buildRefactoringChange() { + final StructuredType structuredTypeEditable = (StructuredType) affectedStruct.getTypeEntry().getTypeEditable(); + for (final VarDeclaration varDeclaration : structuredTypeEditable.getMemberVariables()) { + final String typeName = varDeclaration.getTypeName(); + if (typeName.equals(this.oldTypeEntry.getTypeName())) { + cmd.add(ChangeDataTypeCommand.forDataType(varDeclaration, + (DataType) this.oldTypeEntry.getTypeEditable())); + } + } + } @Override @@ -56,18 +72,10 @@ public RefactoringStatus isValid(final IProgressMonitor pm) throws CoreException return new RefactoringStatus(); } - /** TODO here we need to return the Undo change */ @Override public Change perform(final IProgressMonitor pm) throws CoreException { final StructuredType structuredTypeEditable = (StructuredType) affectedStruct.getTypeEntry().getTypeEditable(); - for (final VarDeclaration varDeclaration : structuredTypeEditable.getMemberVariables()) { - final String typeName = varDeclaration.getTypeName(); - if (typeName.equals(this.oldTypeEntry.getTypeName())) { - cmd.add(ChangeDataTypeCommand.forDataType(varDeclaration, - (DataType) this.oldTypeEntry.getTypeEditable())); - } - } cmd.execute(); structuredTypeEditable.getTypeEntry().save(structuredTypeEditable, pm); @@ -76,8 +84,12 @@ public Change perform(final IProgressMonitor pm) throws CoreException { } @Override - public Object getModifiedElement() { - return null; + public StructuredType getModifiedElement() { + return this.affectedStruct; + } + + public CompoundCommand getRefactoringCommand() { + return cmd; } } From b375de3aa1dcf169cbdef5198a67aaaf92075eb4 Mon Sep 17 00:00:00 2001 From: Terra Date: Thu, 18 Apr 2024 17:39:24 +0200 Subject: [PATCH 04/22] WIP EMF comparator. It works, but throws error on display change. To be fixed --- .../actions/FBNetworkSelectAllAction.java | 4 +- .../policies/FBNConnectionEndpointPolicy.java | 6 +- .../ExpandedInterfacePositionMap.java | 14 +-- .../META-INF/MANIFEST.MF | 3 +- .../typemanagement/EMFCompareSingleton.java | 39 +++++++ .../ide/typemanagement/PreviewCommand.java | 110 ------------------ .../previews/ChangeConfigurationViewer.java | 35 +++--- .../previews/StructChangePreviewViewer.java | 93 ++++++++++----- .../RenameTypeRefactoringParticipant.java | 2 +- .../StructuredTypeMemberChange.java | 13 ++- .../refactoring/rename/StructTypeChange.java | 7 +- 11 files changed, 151 insertions(+), 175 deletions(-) create mode 100644 plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/EMFCompareSingleton.java delete mode 100644 plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/PreviewCommand.java diff --git a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/actions/FBNetworkSelectAllAction.java b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/actions/FBNetworkSelectAllAction.java index f8585789c8..35595265b0 100644 --- a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/actions/FBNetworkSelectAllAction.java +++ b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/actions/FBNetworkSelectAllAction.java @@ -20,6 +20,7 @@ import org.eclipse.fordiac.ide.application.editparts.AbstractFBNElementEditPart; import org.eclipse.fordiac.ide.application.editparts.GroupEditPart; import org.eclipse.gef.EditPart; +import org.eclipse.gef.GraphicalEditPart; import org.eclipse.gef.GraphicalViewer; import org.eclipse.gef.editparts.AbstractGraphicalEditPart; import org.eclipse.gef.ui.actions.SelectAllAction; @@ -66,7 +67,8 @@ private static void addConnectionsTo(final List selectableChildren, fi final List elementChildren = child.getChildren(); for (final Object elementChild : elementChildren) { if (elementChild instanceof AbstractGraphicalEditPart) { - final List connections = ((AbstractGraphicalEditPart) elementChild).getSourceConnections(); + final List connections = ((AbstractGraphicalEditPart) elementChild) + .getSourceConnections(); connections.stream().filter(EditPart::isSelectable).forEach(selectableChildren::add); } } diff --git a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/policies/FBNConnectionEndpointPolicy.java b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/policies/FBNConnectionEndpointPolicy.java index 399c6e7494..df2be31dd1 100644 --- a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/policies/FBNConnectionEndpointPolicy.java +++ b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/policies/FBNConnectionEndpointPolicy.java @@ -89,11 +89,9 @@ private void setAssociatedConnectionsWidth(final int width) { } } - private void setConnectionsWidth(final List list, final int width) { + private void setConnectionsWidth(final List list, final int width) { list.forEach(ep -> { - if (ep instanceof ConnectionEditPart) { - setConnectionWidth((ConnectionEditPart) ep, width); - } + setConnectionWidth((ConnectionEditPart) ep, width); }); } diff --git a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/utilities/ExpandedInterfacePositionMap.java b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/utilities/ExpandedInterfacePositionMap.java index e1666814ab..2f8bdd7a26 100644 --- a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/utilities/ExpandedInterfacePositionMap.java +++ b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/utilities/ExpandedInterfacePositionMap.java @@ -95,10 +95,10 @@ private Map calculateInput(final List input final Map map = new HashMap<>(); for (final var ie : inputList) { final var connections = ie.getSourceConnections(); - final Optional max = connections.stream() - .min((conn1, conn2) -> Integer.compare( - ((ConnectionEditPart) conn1).getConnectionFigure().getEnd().y, - ((ConnectionEditPart) conn2).getConnectionFigure().getEnd().y)); + final Optional max = connections.stream() + .filter(ConnectionEditPart.class::isInstance).map(obj -> (ConnectionEditPart) obj) + .min((conn1, conn2) -> Integer.compare(conn1.getConnectionFigure().getEnd().y, + conn2.getConnectionFigure().getEnd().y)); if (max.isPresent()) { final Point start = max.get().getConnectionFigure().getStart(); final Point end = max.get().getConnectionFigure().getEnd(); @@ -120,9 +120,9 @@ private Map calculateOutput(final List outp for (final var ie : outputList) { final var connections = ie.getTargetConnections(); final Optional max = connections.stream() - .min((conn1, conn2) -> Integer.compare( - ((ConnectionEditPart) conn1).getConnectionFigure().getStart().y, - ((ConnectionEditPart) conn2).getConnectionFigure().getStart().y)); + .filter(ConnectionEditPart.class::isInstance).map(obj -> (ConnectionEditPart) obj) + .min((conn1, conn2) -> Integer.compare(conn1.getConnectionFigure().getStart().y, + conn2.getConnectionFigure().getStart().y)); if (max.isPresent()) { final Point start = max.get().getConnectionFigure().getStart(); final Point end = max.get().getConnectionFigure().getEnd(); diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/META-INF/MANIFEST.MF b/plugins/org.eclipse.fordiac.ide.typemanagement/META-INF/MANIFEST.MF index 9d8071e183..e3c08f8ec0 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/META-INF/MANIFEST.MF @@ -22,7 +22,8 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.fordiac.ide.model.ui, org.eclipse.compare;bundle-version="3.9.300", org.eclipse.emf.common, - org.eclipse.emf.compare.ide.ui;bundle-version="4.4.3" + org.eclipse.emf.compare.ide.ui;bundle-version="4.4.3", + org.eclipse.emf.compare Bundle-Vendor: Eclipse 4diac Bundle-ActivationPolicy: lazy Bundle-Version: 2.0.1.qualifier diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/EMFCompareSingleton.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/EMFCompareSingleton.java new file mode 100644 index 0000000000..a2c4ebaccd --- /dev/null +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/EMFCompareSingleton.java @@ -0,0 +1,39 @@ +package org.eclipse.fordiac.ide.typemanagement; + +import java.util.Objects; + +import org.eclipse.compare.CompareConfiguration; +import org.eclipse.emf.common.notify.AdapterFactory; +import org.eclipse.emf.compare.EMFCompare; +import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration; +import org.eclipse.emf.edit.provider.ComposedAdapterFactory; + +public class EMFCompareSingleton { + + private static EMFCompare emfCompare; + private static AdapterFactory adapterFactory; + private static EMFCompareConfiguration emfCompareConfiguration; + + public static EMFCompare getEmfCompare() { + if (Objects.isNull(emfCompare)) { + EMFCompareSingleton.emfCompare = EMFCompare.builder().build(); + } + return EMFCompareSingleton.emfCompare; + } + + public static AdapterFactory getAdapterFactory() { + if (Objects.isNull(adapterFactory)) { + EMFCompareSingleton.adapterFactory = new ComposedAdapterFactory( + ComposedAdapterFactory.Descriptor.Registry.INSTANCE); + } + return EMFCompareSingleton.adapterFactory; + } + + public static EMFCompareConfiguration getEmfCompareConfiguration() { + if (Objects.isNull(emfCompareConfiguration)) { + EMFCompareSingleton.emfCompareConfiguration = new EMFCompareConfiguration(new CompareConfiguration()); + } + return EMFCompareSingleton.emfCompareConfiguration; + } + +} diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/PreviewCommand.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/PreviewCommand.java deleted file mode 100644 index d695cb7c4a..0000000000 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/PreviewCommand.java +++ /dev/null @@ -1,110 +0,0 @@ -/******************************************************************************* - * Copyright (c) Philipps University of Marburg. All rights reserved. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Philipps University of Marburg - initial API and implementation - *******************************************************************************/ -package org.eclipse.fordiac.ide.typemanagement; - -import org.eclipse.emf.common.command.AbstractCommand; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.gef.commands.CompoundCommand; - -/** - * Class used for providing a command that provides a preview of the rfactored - * EMF model. - * - * @generated NOT - * @author Florian Mantz - */ -public class PreviewCommand extends AbstractCommand { - - /** - * Command that was the origin of the PreviewCommand. - */ - final CompoundCommand command; - - /** - * Root element of the EMF model. - */ - private final EObject root; - - /** - * Copy of the root element of the model (temporary model). - */ - private EObject rootCopy; - - /** - * Default constructor using the origin RefactoringCommand and the root of the - * EMF model. - * - * @param command Origin RefactoringCommand. - * @param root Root element of the EMF model. - */ - public PreviewCommand(final CompoundCommand command, final EObject root) { - this.command = command; - this.root = root; - } - - /** - * @see org.eclipse.emf.common.command.Command#execute() - */ - @Override - public void execute() { - this.command.execute(); - rootCopy = this.generateRootCopy(); - this.command.undo(); - } - - /** - * Generates a copy of the EMF model presented by the root element. - * - * @return Copy of the EMF model presented by the root element. - */ - private EObject generateRootCopy() { - // final Copier copier = new Copier(); - return EcoreUtil.copy(this.root); - // final EObject rootCopy = copier.copy(this.root); - // copier.copyReferences(); - // return rootCopy; - } - - /** - * @see org.eclipse.emf.common.command.Command#redo() - */ - @Override - public void redo() { - // do nothing - } - - /** - * @see org.eclipse.emf.common.command.AbstractCommand#canExecute() - */ - @Override - public boolean canExecute() { - return true; - } - - /** - * @see org.eclipse.emf.common.command.AbstractCommand#canUndo() - */ - @Override - public boolean canUndo() { - return false; // Important - } - - /** - * Gets a copy of the root element of the model (temporary model). - * - * @return Copy of the root element of the model (temporary model). - */ - public EObject getRootCopy() { - return rootCopy; - } - -} diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/ChangeConfigurationViewer.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/ChangeConfigurationViewer.java index 121863af71..bd9aa03b85 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/ChangeConfigurationViewer.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/ChangeConfigurationViewer.java @@ -23,8 +23,6 @@ import org.eclipse.ltk.ui.refactoring.ChangePreviewViewerInput; import org.eclipse.ltk.ui.refactoring.IChangePreviewViewer; import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; @@ -47,25 +45,20 @@ public void createControl(final Composite parent) { table.setSize(100, 100); - // Add a SelectionListener to the table to listen for checkbox changes - table.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(final SelectionEvent e) { - if (e.detail == SWT.CHECK) { - final TableItem item = (TableItem) e.item; - final ChangeState cs = choices.get(item); - // do not allow de-selection of currently selected choice. - if (change.getState().contains(cs)) { - item.setChecked(true); - return; - } - change.addState(cs); - change.getState().removeIf(state -> !state.equals(cs)); - choices.keySet().stream().filter(anyItem -> !anyItem.equals(item)) - .forEach(otherItem -> otherItem.setChecked(false)); - } - } - }); + // TODO inspect this + /* + * // Add a SelectionListener to the table to listen for checkbox changes + * table.addSelectionListener(new SelectionAdapter() { + * + * @Override public void widgetSelected(final SelectionEvent e) { if (e.detail + * == SWT.CHECK) { final TableItem item = (TableItem) e.item; final ChangeState + * cs = choices.get(item); // do not allow de-selection of currently selected + * choice. if (change.getState().contains(cs)) { item.setChecked(true); return; + * } change.addState(cs); change.getState().removeIf(state -> + * !state.equals(cs)); choices.keySet().stream().filter(anyItem -> + * !anyItem.equals(item)) .forEach(otherItem -> otherItem.setChecked(false)); } + * } }); + */ } diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/StructChangePreviewViewer.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/StructChangePreviewViewer.java index 1fe7bf67f2..731fa22542 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/StructChangePreviewViewer.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/StructChangePreviewViewer.java @@ -1,6 +1,7 @@ package org.eclipse.fordiac.ide.typemanagement.previews; import java.lang.reflect.InvocationTargetException; +import java.util.Objects; import org.eclipse.compare.CompareConfiguration; import org.eclipse.compare.CompareEditorInput; @@ -12,25 +13,45 @@ import org.eclipse.emf.compare.domain.impl.EMFCompareEditingDomain; import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration; import org.eclipse.emf.compare.ide.ui.internal.editor.ComparisonEditorInput; -import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.compare.scope.DefaultComparisonScope; +import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.emf.edit.provider.ComposedAdapterFactory; -import org.eclipse.fordiac.ide.typemanagement.PreviewCommand; +import org.eclipse.fordiac.ide.model.data.StructuredType; import org.eclipse.fordiac.ide.typemanagement.refactoring.StructuredTypeMemberChange; +import org.eclipse.jface.action.ActionContributionItem; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IContributionItem; +import org.eclipse.jface.action.IToolBarManager; import org.eclipse.ltk.ui.refactoring.ChangePreviewViewerInput; import org.eclipse.ltk.ui.refactoring.IChangePreviewViewer; -import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +@SuppressWarnings("restriction") public class StructChangePreviewViewer implements IChangePreviewViewer { private Composite parent; - private Control previewControl; + private static Control previewControl; + private EMFCompareConfiguration emfCompareConfiguration; + private AdapterFactory adapterFactory; + private EMFCompare emfCompare; @Override public void createControl(final Composite parent) { parent.setSize(500, 500); this.parent = parent; + this.emfCompareConfiguration = new EMFCompareConfiguration(new CompareConfiguration()); + this.emfCompareConfiguration.setLeftEditable(false); + this.emfCompareConfiguration.setLeftLabel("Before Refactor"); + this.emfCompareConfiguration.setRightEditable(false); + this.emfCompareConfiguration.setRightLabel("After Refactor"); + + this.adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE); + this.emfCompare = EMFCompare.builder().build(); + if (Objects.nonNull(previewControl)) { + previewControl.dispose(); + previewControl = null; + } } @Override @@ -40,37 +61,55 @@ public Control getControl() { @Override public void setInput(final ChangePreviewViewerInput input) { - - // There is a with EMF compare where it will not show struct member changes! - - System.out.println("===>> change: " + input.getChange()); if (!(input.getChange() instanceof StructuredTypeMemberChange)) { return; } final StructuredTypeMemberChange change = (StructuredTypeMemberChange) input.getChange(); - final EObject model1 = change.getModifiedElement(); - final PreviewCommand previewCommand = new PreviewCommand(change.getRefactoringCommand(), model1); - change.getRefactoringCommand().execute(); - final EObject model2 = change.getModifiedElement().getTypeEntry().getTypeEditable(); - - // final EObject model2 = previewCommand.getRootCopy(); - // final EObject model2 = change.getModifiedElement(); - - System.out.println("===>> model1: " + model1); - System.out.println("===>> model2: " + model2); - final EMFCompare compare = EMFCompare.builder().build(); - final Comparison comparison = compare.compare(EMFCompare.createDefaultScope(model2, model1)); - final AdapterFactory adapterFactory = new ComposedAdapterFactory( - ComposedAdapterFactory.Descriptor.Registry.INSTANCE); - final ICompareEditingDomain editingDomain = EMFCompareEditingDomain.create(model2, model1, null); - final CompareEditorInput compareEditorInput = new ComparisonEditorInput( - new EMFCompareConfiguration(new CompareConfiguration()), comparison, editingDomain, adapterFactory); + final StructuredType originalStructuredType = change.getModifiedElement(); + final StructuredType refactoredStructuredType = EcoreUtil.copy(originalStructuredType); + + refactoredStructuredType.getMemberVariables().stream() + .filter(var -> var.getType().getTypeEntry() == change.getModifiedTypeEntry()).forEach(var -> { + var.setType(EcoreUtil.copy(var.getType())); + var.getType().setName(change.getNewTypeEntryName()); + }); + + final Comparison comparison = this.emfCompare + .compare(new DefaultComparisonScope(originalStructuredType, refactoredStructuredType, null)); + + final ICompareEditingDomain editingDomain = EMFCompareEditingDomain.create(originalStructuredType, + refactoredStructuredType, null); + + final CompareEditorInput compareEditorInput = new ComparisonEditorInput(this.emfCompareConfiguration, + comparison, editingDomain, this.adapterFactory); + try { + + if (Objects.nonNull(compareEditorInput.getActionBars())) { + // This is an ugly workaround for a bug in EMF compare that will register + // certain actions twice. See bug 580988 + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=580988 + final IToolBarManager toolBarManager = compareEditorInput.getActionBars().getToolBarManager(); + final IContributionItem[] items = toolBarManager.getItems(); + for (final IContributionItem iContributionItem : items) { + if (iContributionItem instanceof ActionContributionItem) { + final IAction action = ((ActionContributionItem) iContributionItem).getAction(); + final String id = action.getActionDefinitionId(); + if ("org.eclipse.compare.copyAllLeftToRight".equals(id)) { + toolBarManager.remove(iContributionItem); + } else if ("org.eclipse.compare.copyAllRightToLeft".equals(id)) { + toolBarManager.remove(iContributionItem); + } + } + } + } + compareEditorInput.run(new NullProgressMonitor()); + compareEditorInput.setTitle("Refactor comparison"); previewControl = compareEditorInput.createContents(parent); - previewControl.setLayoutData(new FillLayout()); - } catch (final InvocationTargetException | InterruptedException e) { + + } catch (final InvocationTargetException | InterruptedException | IllegalStateException e) { e.printStackTrace(); } diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/RenameTypeRefactoringParticipant.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/RenameTypeRefactoringParticipant.java index d566d29d1b..df4ce248c7 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/RenameTypeRefactoringParticipant.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/RenameTypeRefactoringParticipant.java @@ -115,7 +115,7 @@ private CompositeChange createStructDataChange(final StructuredType type) { parentChange.add(fbTypeChange); } - final CompositeChange structChange = new StructTypeChange(file); + final CompositeChange structChange = new StructTypeChange(file, newName); if (structChange.getChildren().length != 0) { parentChange.add(structChange); } diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/StructuredTypeMemberChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/StructuredTypeMemberChange.java index 2a5539c60d..5df7c2e862 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/StructuredTypeMemberChange.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/StructuredTypeMemberChange.java @@ -31,13 +31,16 @@ public class StructuredTypeMemberChange extends Change { private final StructuredType affectedStruct; private final TypeEntry oldTypeEntry; private final List affectedMembers; + private final String newStructMemberName; private final CompoundCommand cmd = new CompoundCommand(); - public StructuredTypeMemberChange(final StructuredType affectedStruct, final TypeEntry oldTypeEntry) { + public StructuredTypeMemberChange(final StructuredType affectedStruct, final TypeEntry oldTypeEntry, + final String newStructMemberName) { this.affectedStruct = affectedStruct; this.oldTypeEntry = oldTypeEntry; + this.newStructMemberName = newStructMemberName; this.affectedMembers = affectedStruct.getMemberVariables().stream() .filter(var -> var.getType().equals(oldTypeEntry.getType())).map(VarDeclaration::getName).toList(); @@ -92,4 +95,12 @@ public CompoundCommand getRefactoringCommand() { return cmd; } + public TypeEntry getModifiedTypeEntry() { + return this.oldTypeEntry; + } + + public String getNewTypeEntryName() { + return this.newStructMemberName; + } + } diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/StructTypeChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/StructTypeChange.java index cee71cf33c..3f8e780a94 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/StructTypeChange.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/StructTypeChange.java @@ -21,12 +21,14 @@ public class StructTypeChange extends CompositeChange { private final IFile file; + private final String newName; private final TypeEntry oldTypeEntry; - public StructTypeChange(final IFile file) { + public StructTypeChange(final IFile file, final String newName) { super(Messages.Refactoring_AffectedStruct); this.file = file; this.oldTypeEntry = TypeLibraryManager.INSTANCE.getTypeEntryForFile(file); + this.newName = newName; buildChanges(); } @@ -45,7 +47,8 @@ private List buildSubChanges() { affectedStructChanges.put(label, new HashSet<>()); } - affectedStructChanges.get(label).add(new StructuredTypeMemberChange(impactedStructuredType, oldTypeEntry)); + affectedStructChanges.get(label) + .add(new StructuredTypeMemberChange(impactedStructuredType, oldTypeEntry, newName)); }); return affectedStructChanges.entrySet().stream().map(entry -> { From c061918bb184b43ef85aa44cf91f57dfa6f79a9d Mon Sep 17 00:00:00 2001 From: Terra Date: Thu, 9 May 2024 19:02:26 +0200 Subject: [PATCH 05/22] EMFCompare issue workaround attempt #1 --- .../editparts/FBNetworkRootEditPart.java | 5 +++-- .../previews/StructChangePreviewViewer.java | 19 +++++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/editparts/FBNetworkRootEditPart.java b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/editparts/FBNetworkRootEditPart.java index efb6ffdf87..57feb9d2f4 100644 --- a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/editparts/FBNetworkRootEditPart.java +++ b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/editparts/FBNetworkRootEditPart.java @@ -33,6 +33,7 @@ import org.eclipse.gef.DragTracker; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPartViewer; +import org.eclipse.gef.GraphicalEditPart; import org.eclipse.gef.Request; import org.eclipse.gef.RequestConstants; import org.eclipse.gef.commands.Command; @@ -49,8 +50,8 @@ public class FBNetworkRootEditPart extends ZoomScalableFreeformRootEditPart { public static class FBNetworkMarqueeDragTracker extends AdvancedMarqueeDragTracker { @Override - protected Collection calculateMarqueeSelectedEditParts() { - final Collection marqueeSelectedEditParts = super.calculateMarqueeSelectedEditParts(); + protected Collection calculateMarqueeSelectedEditParts() { + final Collection marqueeSelectedEditParts = super.calculateMarqueeSelectedEditParts(); // only report connections and fbelements, isMarqueeslectable can not be used // for that as it affects connection selection in the wrong way return marqueeSelectedEditParts.stream().filter(ep -> ep instanceof ConnectionEditPart && ep.isSelectable() diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/StructChangePreviewViewer.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/StructChangePreviewViewer.java index 731fa22542..fea9087321 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/StructChangePreviewViewer.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/StructChangePreviewViewer.java @@ -1,6 +1,5 @@ package org.eclipse.fordiac.ide.typemanagement.previews; -import java.lang.reflect.InvocationTargetException; import java.util.Objects; import org.eclipse.compare.CompareConfiguration; @@ -26,11 +25,13 @@ import org.eclipse.ltk.ui.refactoring.IChangePreviewViewer; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.handlers.IHandlerService; @SuppressWarnings("restriction") public class StructChangePreviewViewer implements IChangePreviewViewer { - private Composite parent; + private static Composite parent; private static Control previewControl; private EMFCompareConfiguration emfCompareConfiguration; private AdapterFactory adapterFactory; @@ -39,7 +40,6 @@ public class StructChangePreviewViewer implements IChangePreviewViewer { @Override public void createControl(final Composite parent) { parent.setSize(500, 500); - this.parent = parent; this.emfCompareConfiguration = new EMFCompareConfiguration(new CompareConfiguration()); this.emfCompareConfiguration.setLeftEditable(false); this.emfCompareConfiguration.setLeftLabel("Before Refactor"); @@ -51,7 +51,10 @@ public void createControl(final Composite parent) { if (Objects.nonNull(previewControl)) { previewControl.dispose(); previewControl = null; + StructChangePreviewViewer.parent.dispose(); } + StructChangePreviewViewer.parent = parent; + } @Override @@ -86,6 +89,10 @@ public void setInput(final ChangePreviewViewerInput input) { try { + System.out.println("Checking..."); + + final IHandlerService service = PlatformUI.getWorkbench().getService(IHandlerService.class); + if (Objects.nonNull(compareEditorInput.getActionBars())) { // This is an ugly workaround for a bug in EMF compare that will register // certain actions twice. See bug 580988 @@ -96,6 +103,8 @@ public void setInput(final ChangePreviewViewerInput input) { if (iContributionItem instanceof ActionContributionItem) { final IAction action = ((ActionContributionItem) iContributionItem).getAction(); final String id = action.getActionDefinitionId(); + System.out.println("Action"); + System.out.println(id); if ("org.eclipse.compare.copyAllLeftToRight".equals(id)) { toolBarManager.remove(iContributionItem); } else if ("org.eclipse.compare.copyAllRightToLeft".equals(id)) { @@ -107,9 +116,11 @@ public void setInput(final ChangePreviewViewerInput input) { compareEditorInput.run(new NullProgressMonitor()); compareEditorInput.setTitle("Refactor comparison"); + previewControl = compareEditorInput.createContents(parent); - } catch (final InvocationTargetException | InterruptedException | IllegalStateException e) { + } catch (final Exception e) { + System.out.println("Comparison failure"); e.printStackTrace(); } From 8f1ea0dfdba220d45ae5e92fff04d71f0072cab2 Mon Sep 17 00:00:00 2001 From: Terra Date: Wed, 15 May 2024 20:23:32 +0200 Subject: [PATCH 06/22] Fixed merge conflicts for develop --- .../application/actions/FBNetworkSelectAllAction.java | 3 +-- .../META-INF/MANIFEST.MF | 9 +++++++-- .../refactoring/RenameTypeRefactoringParticipant.java | 9 +++------ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/actions/FBNetworkSelectAllAction.java b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/actions/FBNetworkSelectAllAction.java index 435650d594..754559e9ac 100644 --- a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/actions/FBNetworkSelectAllAction.java +++ b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/actions/FBNetworkSelectAllAction.java @@ -49,7 +49,6 @@ private static List getSelectableEditParts(final GraphicalViewer viewe for (final Object child : children) { if ((child instanceof AbstractFBNElementEditPart) || (child instanceof GroupEditPart)) { - final GraphicalEditPart childPart = (GraphicalEditPart) child; final EditPart childPart = (EditPart) child; if (childPart.isSelectable()) { selectableChildren.add(childPart); @@ -60,7 +59,6 @@ private static List getSelectableEditParts(final GraphicalViewer viewe return Collections.unmodifiableList(selectableChildren); } - private static void addConnectionsTo(final List selectableChildren, final GraphicalEditPart child) { private static void addConnectionsTo(final List selectableChildren, final EditPart child) { // the editparts are in charge of managing the connections if we take all source // connections @@ -73,6 +71,7 @@ private static void addConnectionsTo(final List selectableChildren, fi .getSourceConnections(); connections.stream().filter(EditPart::isSelectable).forEach(selectableChildren::add); } + } } diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/META-INF/MANIFEST.MF b/plugins/org.eclipse.fordiac.ide.typemanagement/META-INF/MANIFEST.MF index de1b70e666..255804bedf 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/META-INF/MANIFEST.MF @@ -21,7 +21,11 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.fordiac.ide.model.commands, org.eclipse.fordiac.ide.model.ui, org.eclipse.fordiac.ide.library.model, - org.eclipse.fordiac.ide.gitlab + org.eclipse.fordiac.ide.gitlab, + org.eclipse.compare, + org.eclipse.emf.compare, + org.eclipse.emf.compare.edit, + org.eclipse.emf.compare.ide.ui;bundle-version="4.4.3" Bundle-Vendor: Eclipse 4diac Bundle-ActivationPolicy: lazy Bundle-Version: 3.0.0.qualifier @@ -37,4 +41,5 @@ Export-Package: org.eclipse.fordiac.ide.typemanagement, org.eclipse.fordiac.ide.typemanagement.util, org.eclipse.fordiac.ide.typemanagement.wizards Automatic-Module-Name: org.eclipse.fordiac.ide.typemanagement -Import-Package: org.eclipse.fordiac.ide.model.ui.editors +Import-Package: org.eclipse.emf.compare, + org.eclipse.fordiac.ide.model.ui.editors diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/RenameTypeRefactoringParticipant.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/RenameTypeRefactoringParticipant.java index fed7ac1534..acc10aebfe 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/RenameTypeRefactoringParticipant.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/RenameTypeRefactoringParticipant.java @@ -15,10 +15,8 @@ import java.text.MessageFormat; import java.util.List; -import java.util.Set; import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; @@ -26,10 +24,9 @@ import org.eclipse.fordiac.ide.model.data.StructuredType; import org.eclipse.fordiac.ide.model.libraryElement.FBNetworkElement; import org.eclipse.fordiac.ide.model.libraryElement.FBType; -import org.eclipse.fordiac.ide.model.libraryElement.INamedElement; import org.eclipse.fordiac.ide.model.libraryElement.LibraryElement; import org.eclipse.fordiac.ide.model.search.types.BlockTypeInstanceSearch; -import org.eclipse.fordiac.ide.model.search.types.FBInstanceSearch; +import org.eclipse.fordiac.ide.model.search.types.IEC61499ElementSearch; import org.eclipse.fordiac.ide.model.typelibrary.TypeEntry; import org.eclipse.fordiac.ide.model.typelibrary.TypeLibraryManager; import org.eclipse.fordiac.ide.typemanagement.Messages; @@ -106,7 +103,7 @@ public Change createChange(final IProgressMonitor monitor) throws CoreException, } } - private CompositeChange createStructDataChange(final StructuredType type) { + private CompositeChange createStructDataChange() { final CompositeChange parentChange = new CompositeChange( MessageFormat.format(Messages.Refactoring_RenameFromTo, typeEntry.getTypeName(), newName)); @@ -134,7 +131,7 @@ private CompositeChange createStructDataChange(final StructuredType type) { private CompositeChange createFBDataChange() { final CompositeChange parentChange = new CompositeChange( MessageFormat.format(Messages.Refactoring_RenameFromTo, typeEntry.getTypeName(), newName)); - parentChange.add(new UpdateTypeEntryChange(file, typeEntry, newName, oldName)); + parentChange.add(new UpdateTypeLibraryEntryChange(file, typeEntry, newName, oldName)); final CompositeChange change = new CompositeChange(Messages.Refactoring_AffectedInstancesOfFB); final IEC61499ElementSearch search = new BlockTypeInstanceSearch(typeEntry); From d52b5c95dfa2577a027dcb181197174a030e2806 Mon Sep 17 00:00:00 2001 From: Terra Date: Sun, 19 May 2024 20:31:09 +0200 Subject: [PATCH 07/22] Updated copyright messages --- .../previews/StructChangePreviewViewer.java | 12 +++++++++ .../RenameTypeRefactoringParticipant.java | 4 +-- ...Change.java => UpdateTypeEntryChange.java} | 6 ++--- .../refactoring/rename/FbInstanceChange.java | 13 ++++++++++ .../refactoring/rename/FbTypeChange.java | 15 +++++++++++ .../refactoring/rename/StructTypeChange.java | 25 ++++++++++++++++++- 6 files changed, 69 insertions(+), 6 deletions(-) rename plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/{UpdateTypeLibraryEntryChange.java => UpdateTypeEntryChange.java} (94%) diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/StructChangePreviewViewer.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/StructChangePreviewViewer.java index fea9087321..18fd6621f2 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/StructChangePreviewViewer.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/StructChangePreviewViewer.java @@ -1,3 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2024 Johannes Kepler University + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Martin Schwarz - initial implementation + *******************************************************************************/ package org.eclipse.fordiac.ide.typemanagement.previews; import java.util.Objects; diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/RenameTypeRefactoringParticipant.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/RenameTypeRefactoringParticipant.java index acc10aebfe..33b3165dd1 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/RenameTypeRefactoringParticipant.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/RenameTypeRefactoringParticipant.java @@ -107,7 +107,7 @@ private CompositeChange createStructDataChange() { final CompositeChange parentChange = new CompositeChange( MessageFormat.format(Messages.Refactoring_RenameFromTo, typeEntry.getTypeName(), newName)); - final Change typeLibraryChange = new UpdateTypeLibraryEntryChange(file, typeEntry, newName, oldName); + final Change typeLibraryChange = new UpdateTypeEntryChange(file, typeEntry, newName, oldName); parentChange.add(typeLibraryChange); final CompositeChange fbTypeChange = new FbTypeChange(file); @@ -131,7 +131,7 @@ private CompositeChange createStructDataChange() { private CompositeChange createFBDataChange() { final CompositeChange parentChange = new CompositeChange( MessageFormat.format(Messages.Refactoring_RenameFromTo, typeEntry.getTypeName(), newName)); - parentChange.add(new UpdateTypeLibraryEntryChange(file, typeEntry, newName, oldName)); + parentChange.add(new UpdateTypeEntryChange(file, typeEntry, newName, oldName)); final CompositeChange change = new CompositeChange(Messages.Refactoring_AffectedInstancesOfFB); final IEC61499ElementSearch search = new BlockTypeInstanceSearch(typeEntry); diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/UpdateTypeLibraryEntryChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/UpdateTypeEntryChange.java similarity index 94% rename from plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/UpdateTypeLibraryEntryChange.java rename to plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/UpdateTypeEntryChange.java index 925bca3ac2..86bfd5bc28 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/UpdateTypeLibraryEntryChange.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/UpdateTypeEntryChange.java @@ -35,14 +35,14 @@ import org.eclipse.ui.IEditorPart; import org.eclipse.ui.part.FileEditorInput; -public class UpdateTypeLibraryEntryChange extends Change { +public class UpdateTypeEntryChange extends Change { IFile file; TypeEntry typeEntry; String newName; String oldName; - UpdateTypeLibraryEntryChange(final IFile file, final TypeEntry typeEntry, final String newName, final String oldName) { + UpdateTypeEntryChange(final IFile file, final TypeEntry typeEntry, final String newName, final String oldName) { this.file = file; this.typeEntry = typeEntry; this.newName = newName; @@ -98,7 +98,7 @@ public Change perform(final IProgressMonitor pm) throws CoreException { if (newFile != null) { FordiacResourceChangeListener.updateTypeEntryByRename(newFile, typeEntry); - return new UpdateTypeLibraryEntryChange(newFile, typeEntry, oldName, newName); + return new UpdateTypeEntryChange(newFile, typeEntry, oldName, newName); } return null; } diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbInstanceChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbInstanceChange.java index 8b995ebe28..d8ae010e12 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbInstanceChange.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbInstanceChange.java @@ -1,3 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2024 Johannes Kepler University + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Martin Schwarz - initial implementation + *******************************************************************************/ package org.eclipse.fordiac.ide.typemanagement.refactoring.rename; import java.util.HashMap; @@ -60,6 +72,7 @@ private List buildSubChanges() { } private List searchAffectedStructuredType() { + // TODO use new search final InstanceSearch structMemberSearch = StructDataTypeSearch .createStructMemberSearch((StructuredType) oldTypeEntry.getTypeEditable()); diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbTypeChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbTypeChange.java index e26342a1b1..b5770de9d0 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbTypeChange.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbTypeChange.java @@ -1,3 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2024 Johannes Kepler University + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Martin Schwarz - initial implementation + *******************************************************************************/ package org.eclipse.fordiac.ide.typemanagement.refactoring.rename; import java.util.HashMap; @@ -58,6 +70,9 @@ private List buildSubChanges() { } private List searchAffectedFBs() { + + // TODO refactor to new search + final InstanceSearch search = StructDataTypeSearch .createStructInterfaceSearch((StructuredType) oldTypeEntry.getTypeEditable()); diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/StructTypeChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/StructTypeChange.java index 3f8e780a94..b8673d3220 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/StructTypeChange.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/StructTypeChange.java @@ -1,3 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2024 Johannes Kepler University + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Martin Schwarz - initial implementation + *******************************************************************************/ package org.eclipse.fordiac.ide.typemanagement.refactoring.rename; import java.util.HashMap; @@ -7,10 +19,15 @@ import java.util.Set; import org.eclipse.core.resources.IFile; +import org.eclipse.emf.ecore.EObject; import org.eclipse.fordiac.ide.model.data.StructuredType; import org.eclipse.fordiac.ide.model.libraryElement.INamedElement; +import org.eclipse.fordiac.ide.model.search.types.BlockTypeInstanceSearch; +import org.eclipse.fordiac.ide.model.search.types.DataTypeInstanceSearch; +import org.eclipse.fordiac.ide.model.search.types.IEC61499ElementSearch; import org.eclipse.fordiac.ide.model.search.types.InstanceSearch; import org.eclipse.fordiac.ide.model.search.types.StructDataTypeSearch; +import org.eclipse.fordiac.ide.model.typelibrary.DataTypeEntry; import org.eclipse.fordiac.ide.model.typelibrary.TypeEntry; import org.eclipse.fordiac.ide.model.typelibrary.TypeLibraryManager; import org.eclipse.fordiac.ide.typemanagement.Messages; @@ -61,6 +78,7 @@ private List buildSubChanges() { } private List searchAffectedStructuredType() { + // TODO refactor to new search final InstanceSearch structMemberSearch = StructDataTypeSearch .createStructMemberSearch((StructuredType) oldTypeEntry.getTypeEditable()); @@ -70,7 +88,12 @@ private List searchAffectedStructuredType() { search.addAll(StructDataTypeSearch.createStructMemberSearch((StructuredType) oldTypeEntry.getTypeEditable()) .searchStructuredTypes(oldTypeEntry.getTypeLibrary())); - return search.stream().filter(StructuredType.class::isInstance).map(StructuredType.class::cast).toList(); + + // TODO new search does not yet work + final IEC61499ElementSearch search2 = new DataTypeInstanceSearch((DataTypeEntry) oldTypeEntry.getTypeEditable()); + final List searchResults = search2.performSearch(); + + return searchResults.stream().filter(StructuredType.class::isInstance).map(StructuredType.class::cast).toList(); } private String buildLabel(final String fbFileName, final String projectName) { From 0afbaef7df5ac8fc43c423724569fe207159cdbe Mon Sep 17 00:00:00 2001 From: Terra Date: Tue, 18 Jun 2024 22:29:55 +0200 Subject: [PATCH 08/22] Updated WIP - EMFcompare now available for FBs --- .../plugin.xml | 22 +++- .../typemanagement/EMFCompareSingleton.java | 39 ------ .../InterfaceDataTypeChangePreviewViewer.java | 117 ++++++++++++++++++ .../previews/StructChangePreviewViewer.java | 34 +---- .../UpdateInstancesChangePreviewViewer.java | 54 ++++++++ .../refactoring/InterfaceDataTypeChange.java | 9 +- .../refactoring/rename/StructTypeChange.java | 13 +- .../StructuredTypeMemberChange.java | 2 +- 8 files changed, 205 insertions(+), 85 deletions(-) delete mode 100644 plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/EMFCompareSingleton.java create mode 100644 plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/InterfaceDataTypeChangePreviewViewer.java create mode 100644 plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/UpdateInstancesChangePreviewViewer.java rename plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/{ => rename}/StructuredTypeMemberChange.java (98%) diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/plugin.xml b/plugins/org.eclipse.fordiac.ide.typemanagement/plugin.xml index c6e54a9919..eccd0d515e 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/plugin.xml +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/plugin.xml @@ -750,7 +750,27 @@ + value="org.eclipse.fordiac.ide.typemanagement.refactoring.rename.StructuredTypeMemberChange"> + + + + + + + + + + + + + + diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/EMFCompareSingleton.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/EMFCompareSingleton.java deleted file mode 100644 index a2c4ebaccd..0000000000 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/EMFCompareSingleton.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.eclipse.fordiac.ide.typemanagement; - -import java.util.Objects; - -import org.eclipse.compare.CompareConfiguration; -import org.eclipse.emf.common.notify.AdapterFactory; -import org.eclipse.emf.compare.EMFCompare; -import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration; -import org.eclipse.emf.edit.provider.ComposedAdapterFactory; - -public class EMFCompareSingleton { - - private static EMFCompare emfCompare; - private static AdapterFactory adapterFactory; - private static EMFCompareConfiguration emfCompareConfiguration; - - public static EMFCompare getEmfCompare() { - if (Objects.isNull(emfCompare)) { - EMFCompareSingleton.emfCompare = EMFCompare.builder().build(); - } - return EMFCompareSingleton.emfCompare; - } - - public static AdapterFactory getAdapterFactory() { - if (Objects.isNull(adapterFactory)) { - EMFCompareSingleton.adapterFactory = new ComposedAdapterFactory( - ComposedAdapterFactory.Descriptor.Registry.INSTANCE); - } - return EMFCompareSingleton.adapterFactory; - } - - public static EMFCompareConfiguration getEmfCompareConfiguration() { - if (Objects.isNull(emfCompareConfiguration)) { - EMFCompareSingleton.emfCompareConfiguration = new EMFCompareConfiguration(new CompareConfiguration()); - } - return EMFCompareSingleton.emfCompareConfiguration; - } - -} diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/InterfaceDataTypeChangePreviewViewer.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/InterfaceDataTypeChangePreviewViewer.java new file mode 100644 index 0000000000..d0e0d32ead --- /dev/null +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/InterfaceDataTypeChangePreviewViewer.java @@ -0,0 +1,117 @@ +/******************************************************************************* + * Copyright (c) 2024 Johannes Kepler University + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Martin Schwarz - initial implementation + *******************************************************************************/ +package org.eclipse.fordiac.ide.typemanagement.previews; + +import java.util.Objects; + +import org.eclipse.compare.CompareConfiguration; +import org.eclipse.compare.CompareEditorInput; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.emf.common.notify.AdapterFactory; +import org.eclipse.emf.compare.Comparison; +import org.eclipse.emf.compare.EMFCompare; +import org.eclipse.emf.compare.domain.ICompareEditingDomain; +import org.eclipse.emf.compare.domain.impl.EMFCompareEditingDomain; +import org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration; +import org.eclipse.emf.compare.ide.ui.internal.editor.ComparisonEditorInput; +import org.eclipse.emf.compare.scope.DefaultComparisonScope; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.emf.edit.provider.ComposedAdapterFactory; +import org.eclipse.fordiac.ide.model.libraryElement.FBType; +import org.eclipse.fordiac.ide.model.typelibrary.TypeEntry; +import org.eclipse.fordiac.ide.typemanagement.refactoring.InterfaceDataTypeChange; +import org.eclipse.ltk.ui.refactoring.ChangePreviewViewerInput; +import org.eclipse.ltk.ui.refactoring.IChangePreviewViewer; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + +@SuppressWarnings("restriction") +public class InterfaceDataTypeChangePreviewViewer implements IChangePreviewViewer { + + private static Composite parent; + private static Control previewControl; + private EMFCompareConfiguration emfCompareConfiguration; + private AdapterFactory adapterFactory; + private EMFCompare emfCompare; + + @Override + public void createControl(final Composite parent) { + parent.setSize(500, 500); + this.emfCompareConfiguration = new EMFCompareConfiguration(new CompareConfiguration()); + this.emfCompareConfiguration.setLeftEditable(false); + this.emfCompareConfiguration.setLeftLabel("Before Refactor"); + this.emfCompareConfiguration.setRightEditable(false); + this.emfCompareConfiguration.setRightLabel("After Refactor"); + + this.adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE); + this.emfCompare = EMFCompare.builder().build(); + if (Objects.nonNull(previewControl)) { + previewControl.dispose(); + previewControl = null; + InterfaceDataTypeChangePreviewViewer.parent.dispose(); + } + InterfaceDataTypeChangePreviewViewer.parent = parent; + + } + + @Override + public Control getControl() { + return previewControl; + } + + @Override + public void setInput(final ChangePreviewViewerInput input) { + if (!(input.getChange() instanceof InterfaceDataTypeChange)) { + return; + } + + final InterfaceDataTypeChange change = (InterfaceDataTypeChange) input.getChange(); + final TypeEntry oldTypeEntry = change.getOldTypeEntry(); + final FBType originalFbType = (FBType) change.getModifiedElement(); + final FBType refactoredFbType = EcoreUtil.copy(originalFbType); + + refactoredFbType.getInterfaceList().getInputs() + .filter(var -> var.getTypeName().equals(oldTypeEntry.getTypeName())).forEach(var -> { + var.setType(EcoreUtil.copy(var.getType())); + var.getType().setName("TODO"); + }); + + refactoredFbType.getInterfaceList().getOutputs() + .filter(var -> var.getTypeName().equals(oldTypeEntry.getTypeName())).forEach(var -> { + var.setType(EcoreUtil.copy(var.getType())); + var.getType().setName("TODO"); + }); + + final Comparison comparison = this.emfCompare + .compare(new DefaultComparisonScope(originalFbType, refactoredFbType, null)); + + final ICompareEditingDomain editingDomain = EMFCompareEditingDomain.create(originalFbType, refactoredFbType, + null); + + final CompareEditorInput compareEditorInput = new ComparisonEditorInput(this.emfCompareConfiguration, + comparison, editingDomain, this.adapterFactory); + + try { + + compareEditorInput.run(new NullProgressMonitor()); + compareEditorInput.setTitle("Refactor comparison"); + previewControl = compareEditorInput.createContents(parent); + + } catch (final Exception e) { + System.out.println("Comparison failure"); + e.printStackTrace(); + } + + } + +} diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/StructChangePreviewViewer.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/StructChangePreviewViewer.java index 18fd6621f2..25bf910d9a 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/StructChangePreviewViewer.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/StructChangePreviewViewer.java @@ -28,17 +28,11 @@ import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.emf.edit.provider.ComposedAdapterFactory; import org.eclipse.fordiac.ide.model.data.StructuredType; -import org.eclipse.fordiac.ide.typemanagement.refactoring.StructuredTypeMemberChange; -import org.eclipse.jface.action.ActionContributionItem; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IContributionItem; -import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.fordiac.ide.typemanagement.refactoring.rename.StructuredTypeMemberChange; import org.eclipse.ltk.ui.refactoring.ChangePreviewViewerInput; import org.eclipse.ltk.ui.refactoring.IChangePreviewViewer; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.handlers.IHandlerService; @SuppressWarnings("restriction") public class StructChangePreviewViewer implements IChangePreviewViewer { @@ -101,34 +95,8 @@ public void setInput(final ChangePreviewViewerInput input) { try { - System.out.println("Checking..."); - - final IHandlerService service = PlatformUI.getWorkbench().getService(IHandlerService.class); - - if (Objects.nonNull(compareEditorInput.getActionBars())) { - // This is an ugly workaround for a bug in EMF compare that will register - // certain actions twice. See bug 580988 - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=580988 - final IToolBarManager toolBarManager = compareEditorInput.getActionBars().getToolBarManager(); - final IContributionItem[] items = toolBarManager.getItems(); - for (final IContributionItem iContributionItem : items) { - if (iContributionItem instanceof ActionContributionItem) { - final IAction action = ((ActionContributionItem) iContributionItem).getAction(); - final String id = action.getActionDefinitionId(); - System.out.println("Action"); - System.out.println(id); - if ("org.eclipse.compare.copyAllLeftToRight".equals(id)) { - toolBarManager.remove(iContributionItem); - } else if ("org.eclipse.compare.copyAllRightToLeft".equals(id)) { - toolBarManager.remove(iContributionItem); - } - } - } - } - compareEditorInput.run(new NullProgressMonitor()); compareEditorInput.setTitle("Refactor comparison"); - previewControl = compareEditorInput.createContents(parent); } catch (final Exception e) { diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/UpdateInstancesChangePreviewViewer.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/UpdateInstancesChangePreviewViewer.java new file mode 100644 index 0000000000..5075c1e42a --- /dev/null +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/UpdateInstancesChangePreviewViewer.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2024 Johannes Kepler University + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Martin Schwarz - initial implementation + *******************************************************************************/ +package org.eclipse.fordiac.ide.typemanagement.previews; + +import org.eclipse.fordiac.ide.typemanagement.refactoring.UpdateInstancesChange; +import org.eclipse.ltk.ui.refactoring.ChangePreviewViewerInput; +import org.eclipse.ltk.ui.refactoring.IChangePreviewViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Table; + +@SuppressWarnings("restriction") +public class UpdateInstancesChangePreviewViewer implements IChangePreviewViewer { + + private Composite parent; + private Control previewControl; + + @Override + public void createControl(final Composite parent) { + parent.setSize(500, 500); + + final Composite control = new Composite(parent, SWT.NONE); + control.setLayoutData(new FillLayout()); + + final Table table = new Table(control, SWT.CHECK | SWT.BORDER); + + } + + @Override + public Control getControl() { + return previewControl; + } + + @Override + public void setInput(final ChangePreviewViewerInput input) { + if (!(input.getChange() instanceof UpdateInstancesChange)) { + return; + } + + } + +} diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/InterfaceDataTypeChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/InterfaceDataTypeChange.java index ab71d693f2..a293b8c834 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/InterfaceDataTypeChange.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/InterfaceDataTypeChange.java @@ -50,12 +50,13 @@ public InterfaceDataTypeChange(final FBType fbType, final TypeEntry oldTypeEntry @Override public String getName() { - return "Update Interface Pins: " + this.inputPinNames.toString() + "<->" + this.outputPinNames.toString(); //$NON-NLS-1$ + return "Update Interface Pins - Inputs: " + this.inputPinNames.toString() + " / Outputs: " //$NON-NLS-1$//$NON-NLS-2$ + + this.outputPinNames.toString(); } @Override public void initializeValidationData(final IProgressMonitor pm) { - + // Unused } private Command getUpdatePinInTypeDelcarationCommand() { @@ -89,4 +90,8 @@ public Object getModifiedElement() { return fbType; } + public TypeEntry getOldTypeEntry() { + return oldTypeEntry; + } + } diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/StructTypeChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/StructTypeChange.java index b8673d3220..0c0d873282 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/StructTypeChange.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/StructTypeChange.java @@ -19,19 +19,13 @@ import java.util.Set; import org.eclipse.core.resources.IFile; -import org.eclipse.emf.ecore.EObject; import org.eclipse.fordiac.ide.model.data.StructuredType; import org.eclipse.fordiac.ide.model.libraryElement.INamedElement; -import org.eclipse.fordiac.ide.model.search.types.BlockTypeInstanceSearch; -import org.eclipse.fordiac.ide.model.search.types.DataTypeInstanceSearch; -import org.eclipse.fordiac.ide.model.search.types.IEC61499ElementSearch; import org.eclipse.fordiac.ide.model.search.types.InstanceSearch; import org.eclipse.fordiac.ide.model.search.types.StructDataTypeSearch; -import org.eclipse.fordiac.ide.model.typelibrary.DataTypeEntry; import org.eclipse.fordiac.ide.model.typelibrary.TypeEntry; import org.eclipse.fordiac.ide.model.typelibrary.TypeLibraryManager; import org.eclipse.fordiac.ide.typemanagement.Messages; -import org.eclipse.fordiac.ide.typemanagement.refactoring.StructuredTypeMemberChange; import org.eclipse.ltk.core.refactoring.Change; import org.eclipse.ltk.core.refactoring.CompositeChange; @@ -90,10 +84,11 @@ private List searchAffectedStructuredType() { .searchStructuredTypes(oldTypeEntry.getTypeLibrary())); // TODO new search does not yet work - final IEC61499ElementSearch search2 = new DataTypeInstanceSearch((DataTypeEntry) oldTypeEntry.getTypeEditable()); - final List searchResults = search2.performSearch(); + // final IEC61499ElementSearch search2 = new + // DataTypeInstanceSearch((DataTypeEntry) oldTypeEntry.getTypeEditable()); + /// final List searchResults = search2.performSearch(); - return searchResults.stream().filter(StructuredType.class::isInstance).map(StructuredType.class::cast).toList(); + return search.stream().filter(StructuredType.class::isInstance).map(StructuredType.class::cast).toList(); } private String buildLabel(final String fbFileName, final String projectName) { diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/StructuredTypeMemberChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/StructuredTypeMemberChange.java similarity index 98% rename from plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/StructuredTypeMemberChange.java rename to plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/StructuredTypeMemberChange.java index 5df7c2e862..b65a1999fd 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/StructuredTypeMemberChange.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/StructuredTypeMemberChange.java @@ -10,7 +10,7 @@ * Contributors: * Michael Oberlehner - initial API and implementation and/or initial documentation *******************************************************************************/ -package org.eclipse.fordiac.ide.typemanagement.refactoring; +package org.eclipse.fordiac.ide.typemanagement.refactoring.rename; import java.util.List; From 9d12803877bd1b6344ad0df197ea3d824574603e Mon Sep 17 00:00:00 2001 From: Terra Date: Sat, 10 Aug 2024 14:48:36 +0200 Subject: [PATCH 09/22] Build fix after conflict resolution #1 --- .../META-INF/MANIFEST.MF | 1 + .../META-INF/MANIFEST.MF | 4 ---- .../refactoring/InterfaceDataTypeChange.java | 9 +++------ 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/plugins/org.eclipse.fordiac.ide.structuredtextcore.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.fordiac.ide.structuredtextcore.ui/META-INF/MANIFEST.MF index 92a9dbf59d..94ab0bd68a 100644 --- a/plugins/org.eclipse.fordiac.ide.structuredtextcore.ui/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.fordiac.ide.structuredtextcore.ui/META-INF/MANIFEST.MF @@ -28,6 +28,7 @@ Require-Bundle: org.eclipse.fordiac.ide.model, org.eclipse.fordiac.ide.globalconstantseditor.model, org.eclipse.fordiac.ide.typemanagement Import-Package: org.apache.log4j, + org.eclipse.fordiac.ide.typemanagement.refactoring, org.eclipse.xtext.ui.codemining;resolution:=optional Bundle-RequiredExecutionEnvironment: JavaSE-21 Export-Package: org.eclipse.fordiac.ide.structuredtextcore.ui, diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/META-INF/MANIFEST.MF b/plugins/org.eclipse.fordiac.ide.typemanagement/META-INF/MANIFEST.MF index 073e29937c..140987549c 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/META-INF/MANIFEST.MF @@ -19,7 +19,6 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.ltk.ui.refactoring, org.eclipse.fordiac.ide.model.search, org.eclipse.fordiac.ide.model.commands, -<<<<<<< HEAD org.eclipse.fordiac.ide.model.ui, org.eclipse.fordiac.ide.library.model, org.eclipse.fordiac.ide.gitlab, @@ -27,9 +26,6 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.emf.compare, org.eclipse.emf.compare.edit, org.eclipse.emf.compare.ide.ui;bundle-version="4.4.3" -======= - org.eclipse.fordiac.ide.model.ui ->>>>>>> refs/remotes/origin/develop Bundle-Vendor: Eclipse 4diac Bundle-ActivationPolicy: lazy Bundle-Version: 3.0.0.qualifier diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/InterfaceDataTypeChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/InterfaceDataTypeChange.java index 0c3b8581cd..06f0e53916 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/InterfaceDataTypeChange.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/InterfaceDataTypeChange.java @@ -21,6 +21,7 @@ import org.eclipse.fordiac.ide.model.libraryElement.IInterfaceElement; import org.eclipse.fordiac.ide.model.search.AbstractLiveSearchContext; import org.eclipse.fordiac.ide.model.typelibrary.DataTypeEntry; +import org.eclipse.fordiac.ide.model.typelibrary.TypeEntry; import org.eclipse.fordiac.ide.typemanagement.util.FBUpdater; import org.eclipse.gef.commands.Command; import org.eclipse.ltk.core.refactoring.Change; @@ -33,8 +34,6 @@ public class InterfaceDataTypeChange extends Change { private final List inputPinNames; private final List outputPinNames; - private final List pinNames; - public InterfaceDataTypeChange(final FBType fbType, final TypeEntry oldTypeEntry) { this.fbType = fbType; @@ -48,7 +47,6 @@ public InterfaceDataTypeChange(final FBType fbType, final TypeEntry oldTypeEntry .filter(output -> output.getTypeName().equals(oldTypeEntry.getTypeName())) .map(IInterfaceElement::getName).toList(); - } @Override @@ -62,9 +60,8 @@ public void initializeValidationData(final IProgressMonitor pm) { // Unused } - private Command getUpdatePinInTypeDelcarationCommand() { - return FBUpdater.createUpdatePinInTypeDeclarationCommand(fbType, (DataTypeEntry) this.oldTypeEntry, - this.oldTypeEntry.getTypeName()); + private Command getUpdatePinInTypeDeclarationCommand() { + return FBUpdater.createUpdatePinInTypeDeclarationCommand(fbType, (DataTypeEntry) this.oldTypeEntry); } From 3137bdb0fb67c9adb63edb66f82ce47da2cf46fa Mon Sep 17 00:00:00 2001 From: Terra Date: Sun, 18 Aug 2024 19:06:12 +0200 Subject: [PATCH 10/22] Merge fix --- .../fordiac/ide/typemanagement/messages.properties | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/messages.properties b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/messages.properties index 3a16c41d85..646e1e1867 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/messages.properties +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/messages.properties @@ -72,12 +72,8 @@ RenameElementRefactoringProcessor_Name=Rename element to {0} RenameElementRefactoringProcessor_RenamePinInType=Rename Pin in type: {0} RenameElementRefactoringWizardPage_Name=Name RenameType_Name=Rename IEC 61499 Type -<<<<<<< HEAD RenameType_TypeExists=The type ''{0}'' is already included in the library OldTypeLibVersionCouldNotBeDeleted= There was a problem while importing the new Type Library version, old one could not be deleted! -======= -RenameType_TypeExists=The type {0} is already included in the library ->>>>>>> refs/remotes/origin/develop OpenTypeHandler_EDITOR_OPEN_ERROR_MESSAGE=Could not open according editor OpenTypeHandler_NO_FILES_IN_WORKSPACE=There are no files in your workspace OpenTypeHandler_NO_FILES_SELECTED=No file selected @@ -89,22 +85,14 @@ typeManagementPreferencePageIdentificationTitle=Identification information typeManagementPreferencePageVersionTitle=Version information typeManagementPreferencePageDescription=Default values for created Function Blocks Warning=Warning -<<<<<<< HEAD Refactoring_RenameFromTo=Rename Type from ''{0}'' to ''{1}'' Refactoring_AffectedFuctionBlock=Update affected Function Blocks -Refactoring_AffectedStruct=Update affected Structs Refactoring_AffectedFbInstances=Update affected Function Block instances -======= Refactoring_RenameFromTo=Rename Type from {0} to : {1} Refactoring_AffectedStruct=Affected Struct {0} that contain struct {1} as member ->>>>>>> refs/remotes/origin/develop Refactoring_AffectedInstancesOfFB=Affected Instances of this FB Type -<<<<<<< HEAD -Refactoring_UpdateTypeEntryChange=Update type library and editors UpdatedInstances=Instances which have been updated with the new type library version -======= Refactoring_UpdateTypeEntryChange=Update type entry and editors ->>>>>>> refs/remotes/origin/develop PreviewChange_DeleteChoice=Delete PreviewChange_ChangeToAnyStruct=Change to ANY_STRUCT PreviewChange_NoChange=No Change From 3372d1f2584d2fada36f107143de5ec03b26df8b Mon Sep 17 00:00:00 2001 From: Terra Date: Mon, 19 Aug 2024 19:35:14 +0200 Subject: [PATCH 11/22] Updated first changes to new search --- .../META-INF/MANIFEST.MF | 8 +- .../ide/typemanagement/messages.properties | 2 +- .../RenameTypeRefactoringParticipant.java | 148 ------------------ .../refactoring/rename/FbTypeChange.java | 24 +-- .../RenameTypeRefactoringParticipant.java | 105 +++---------- .../refactoring/rename/StructTypeChange.java | 26 +-- 6 files changed, 41 insertions(+), 272 deletions(-) delete mode 100644 plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/RenameTypeRefactoringParticipant.java diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/META-INF/MANIFEST.MF b/plugins/org.eclipse.fordiac.ide.typemanagement/META-INF/MANIFEST.MF index 140987549c..c0ce96dd9c 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/META-INF/MANIFEST.MF @@ -19,13 +19,10 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.ltk.ui.refactoring, org.eclipse.fordiac.ide.model.search, org.eclipse.fordiac.ide.model.commands, - org.eclipse.fordiac.ide.model.ui, - org.eclipse.fordiac.ide.library.model, - org.eclipse.fordiac.ide.gitlab, org.eclipse.compare, org.eclipse.emf.compare, org.eclipse.emf.compare.edit, - org.eclipse.emf.compare.ide.ui;bundle-version="4.4.3" + org.eclipse.emf.compare.ide.ui Bundle-Vendor: Eclipse 4diac Bundle-ActivationPolicy: lazy Bundle-Version: 3.0.0.qualifier @@ -43,4 +40,5 @@ Export-Package: org.eclipse.fordiac.ide.typemanagement, org.eclipse.fordiac.ide.typemanagement.wizards Automatic-Module-Name: org.eclipse.fordiac.ide.typemanagement Import-Package: org.eclipse.emf.compare, - org.eclipse.fordiac.ide.model.ui.editors + org.eclipse.fordiac.ide.model.ui.editors, + org.eclipse.fordiac.ide.model.ui.widgets diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/messages.properties b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/messages.properties index 646e1e1867..7b22a7e803 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/messages.properties +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/messages.properties @@ -89,7 +89,7 @@ Refactoring_RenameFromTo=Rename Type from ''{0}'' to ''{1}'' Refactoring_AffectedFuctionBlock=Update affected Function Blocks Refactoring_AffectedFbInstances=Update affected Function Block instances Refactoring_RenameFromTo=Rename Type from {0} to : {1} -Refactoring_AffectedStruct=Affected Struct {0} that contain struct {1} as member +Refactoring_AffectedStruct=Update affected Structs Refactoring_AffectedInstancesOfFB=Affected Instances of this FB Type UpdatedInstances=Instances which have been updated with the new type library version Refactoring_UpdateTypeEntryChange=Update type entry and editors diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/RenameTypeRefactoringParticipant.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/RenameTypeRefactoringParticipant.java deleted file mode 100644 index 33b3165dd1..0000000000 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/RenameTypeRefactoringParticipant.java +++ /dev/null @@ -1,148 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2023 Primetals Technologies Austria GmbH - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Fabio Gandolfi, Michael Oberlehner - - * initial API and implementation and/or initial documentation - *******************************************************************************/ -package org.eclipse.fordiac.ide.typemanagement.refactoring; - -import java.text.MessageFormat; -import java.util.List; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.fordiac.ide.model.data.StructuredType; -import org.eclipse.fordiac.ide.model.libraryElement.FBNetworkElement; -import org.eclipse.fordiac.ide.model.libraryElement.FBType; -import org.eclipse.fordiac.ide.model.libraryElement.LibraryElement; -import org.eclipse.fordiac.ide.model.search.types.BlockTypeInstanceSearch; -import org.eclipse.fordiac.ide.model.search.types.IEC61499ElementSearch; -import org.eclipse.fordiac.ide.model.typelibrary.TypeEntry; -import org.eclipse.fordiac.ide.model.typelibrary.TypeLibraryManager; -import org.eclipse.fordiac.ide.typemanagement.Messages; -import org.eclipse.fordiac.ide.typemanagement.refactoring.rename.FbInstanceChange; -import org.eclipse.fordiac.ide.typemanagement.refactoring.rename.FbTypeChange; -import org.eclipse.fordiac.ide.typemanagement.refactoring.rename.StructTypeChange; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.CompositeChange; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; -import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; -import org.eclipse.ltk.core.refactoring.participants.RenameParticipant; - -public class RenameTypeRefactoringParticipant extends RenameParticipant { - - IFile file; - TypeEntry typeEntry; - String oldName; - String newName; - - @Override - protected boolean initialize(final Object element) { - if (element instanceof final IFile targetFile - && TypeLibraryManager.INSTANCE.getTypeEntryForFile(targetFile) != null) { - this.file = targetFile; - typeEntry = TypeLibraryManager.INSTANCE.getTypeEntryForFile(targetFile); - oldName = typeEntry.getTypeName(); - newName = TypeEntry.getTypeNameFromFileName(getArguments().getNewName()); - return true; - } - return false; - } - - @Override - public String getName() { - return Messages.RenameType_Name; - } - - @Override - public RefactoringStatus checkConditions(final IProgressMonitor monitor, final CheckConditionsContext context) - throws OperationCanceledException { - final RefactoringStatus status = new RefactoringStatus(); - try { - monitor.beginTask("Checking preconditions...", 1); //$NON-NLS-1$ - checkFileEnding(status); - - } finally { - monitor.done(); - } - return status; - } - - protected void checkFileEnding(final RefactoringStatus result) { - if (!getArguments().getNewName().endsWith(file.getFileExtension())) { - result.addFatalError("The file-ending is different to the old one!"); //$NON-NLS-1$ - } - } - - @Override - public Change createChange(final IProgressMonitor monitor) throws CoreException, OperationCanceledException { - try { - monitor.beginTask("Creating change...", 1); //$NON-NLS-1$ - - final LibraryElement type = typeEntry.getType(); - if (type instanceof StructuredType) { - return createStructDataChange(); - } - if (type instanceof FBType) { - return createFBDataChange(); - } - return null; - - } finally { - monitor.done(); - } - } - - private CompositeChange createStructDataChange() { - final CompositeChange parentChange = new CompositeChange( - MessageFormat.format(Messages.Refactoring_RenameFromTo, typeEntry.getTypeName(), newName)); - - final Change typeLibraryChange = new UpdateTypeEntryChange(file, typeEntry, newName, oldName); - parentChange.add(typeLibraryChange); - - final CompositeChange fbTypeChange = new FbTypeChange(file); - if (fbTypeChange.getChildren().length != 0) { - parentChange.add(fbTypeChange); - } - - final CompositeChange structChange = new StructTypeChange(file, newName); - if (structChange.getChildren().length != 0) { - parentChange.add(structChange); - } - - final CompositeChange fbInstanceChange = new FbInstanceChange(file); - if (fbInstanceChange.getChildren().length != 0) { - parentChange.add(fbInstanceChange); - } - - return parentChange; - } - - private CompositeChange createFBDataChange() { - final CompositeChange parentChange = new CompositeChange( - MessageFormat.format(Messages.Refactoring_RenameFromTo, typeEntry.getTypeName(), newName)); - parentChange.add(new UpdateTypeEntryChange(file, typeEntry, newName, oldName)); - final CompositeChange change = new CompositeChange(Messages.Refactoring_AffectedInstancesOfFB); - - final IEC61499ElementSearch search = new BlockTypeInstanceSearch(typeEntry); - final List searchResults = search.performSearch(); - searchResults.stream().filter(FBNetworkElement.class::isInstance).map(FBNetworkElement.class::cast) - .map(fbn -> new UpdateInstancesChange(fbn, typeEntry)).forEach(change::add); - - if (!searchResults.isEmpty()) { - parentChange.add(change); - } - return parentChange; - } - -} diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbTypeChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbTypeChange.java index ecac6fe002..98ef827ba0 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbTypeChange.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbTypeChange.java @@ -20,12 +20,9 @@ import org.eclipse.core.resources.IFile; import org.eclipse.emf.ecore.EObject; -import org.eclipse.fordiac.ide.model.data.StructuredType; import org.eclipse.fordiac.ide.model.libraryElement.FBType; -import org.eclipse.fordiac.ide.model.libraryElement.impl.VarDeclarationImpl; +import org.eclipse.fordiac.ide.model.libraryElement.InterfaceList; import org.eclipse.fordiac.ide.model.search.types.DataTypeInstanceSearch; -import org.eclipse.fordiac.ide.model.search.types.InstanceSearch; -import org.eclipse.fordiac.ide.model.search.types.StructDataTypeSearch; import org.eclipse.fordiac.ide.model.typelibrary.DataTypeEntry; import org.eclipse.fordiac.ide.model.typelibrary.TypeEntry; import org.eclipse.fordiac.ide.model.typelibrary.TypeLibraryManager; @@ -76,23 +73,10 @@ private List buildSubChanges() { private List searchAffectedFBs() { final DataTypeInstanceSearch nsearch = new DataTypeInstanceSearch((DataTypeEntry) oldTypeEntry); final List res = nsearch.performSearch(); - System.out.println("Performing search"); - for (final var r : res) { - // this returns vars used in FBs?? But not all? - System.out.println("Found: Type " + ((VarDeclarationImpl) r).getTypeName()); - System.out.println("Found: FQN " + ((VarDeclarationImpl) r).getFullTypeName()); - System.out.println("Found: Name " + ((VarDeclarationImpl) r).getName()); - - } - - // TODO refactor to new search - - final InstanceSearch search = StructDataTypeSearch - .createStructInterfaceSearch((StructuredType) oldTypeEntry.getTypeEditable()); - - return search.performTypeLibBlockSearch(oldTypeEntry.getTypeLibrary()).stream().filter(FBType.class::isInstance) - .map(FBType.class::cast).toList(); + return res.stream().filter(r -> InterfaceList.class.isInstance(r.eContainer())) + .filter(r -> FBType.class.isInstance(r.eContainer().eContainer())) + .map(r -> FBType.class.cast(r.eContainer().eContainer())).distinct().toList(); } private String buildLabel(final String fbFileName, final String projectName) { diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/RenameTypeRefactoringParticipant.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/RenameTypeRefactoringParticipant.java index 0fc632dd37..f35415d712 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/RenameTypeRefactoringParticipant.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/RenameTypeRefactoringParticipant.java @@ -14,50 +14,36 @@ package org.eclipse.fordiac.ide.typemanagement.refactoring.rename; import java.text.MessageFormat; -import java.util.HashSet; import java.util.List; -import java.util.Set; import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.fordiac.ide.model.data.StructuredType; import org.eclipse.fordiac.ide.model.libraryElement.FBNetworkElement; import org.eclipse.fordiac.ide.model.libraryElement.FBType; import org.eclipse.fordiac.ide.model.libraryElement.LibraryElement; -import org.eclipse.fordiac.ide.model.libraryElement.StructManipulator; -import org.eclipse.fordiac.ide.model.libraryElement.VarDeclaration; import org.eclipse.fordiac.ide.model.search.types.BlockTypeInstanceSearch; -import org.eclipse.fordiac.ide.model.search.types.DataTypeInstanceSearch; import org.eclipse.fordiac.ide.model.search.types.IEC61499ElementSearch; -import org.eclipse.fordiac.ide.model.typelibrary.DataTypeEntry; import org.eclipse.fordiac.ide.model.typelibrary.TypeEntry; import org.eclipse.fordiac.ide.model.typelibrary.TypeLibraryManager; import org.eclipse.fordiac.ide.typemanagement.Messages; -import org.eclipse.fordiac.ide.typemanagement.refactoring.InterfaceDataTypeChange; -import org.eclipse.fordiac.ide.typemanagement.refactoring.UpdateFBInstanceChange; +import org.eclipse.fordiac.ide.typemanagement.refactoring.UpdateInstancesChange; import org.eclipse.fordiac.ide.typemanagement.refactoring.UpdateTypeEntryChange; -import org.eclipse.fordiac.ide.typemanagement.refactoring.delete.UpdateStructDataTypeMemberVariableChange; import org.eclipse.ltk.core.refactoring.Change; import org.eclipse.ltk.core.refactoring.CompositeChange; import org.eclipse.ltk.core.refactoring.RefactoringStatus; import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; import org.eclipse.ltk.core.refactoring.participants.RenameParticipant; -/** - * A participant for type rename refactorings triggered within a model context, - * such as file rename. - */ public class RenameTypeRefactoringParticipant extends RenameParticipant { - private IFile file; - private TypeEntry typeEntry; - private String oldName; - private String newName; + IFile file; + TypeEntry typeEntry; + String oldName; + String newName; @Override protected boolean initialize(final Object element) { @@ -84,7 +70,7 @@ public RefactoringStatus checkConditions(final IProgressMonitor monitor, final C try { monitor.beginTask("Checking preconditions...", 1); //$NON-NLS-1$ checkFileEnding(status); - checkFileName(status); + } finally { monitor.done(); } @@ -97,21 +83,6 @@ protected void checkFileEnding(final RefactoringStatus result) { } } - protected void checkFileName(final RefactoringStatus result) { - if (!oldName.equalsIgnoreCase(newName)) { - try { - final String name = getArguments().getNewName(); - for (final IResource resource : file.getParent().members()) { - if (name.equalsIgnoreCase(resource.getName())) { - result.addFatalError("File already exists!"); //$NON-NLS-1$ - } - } - } catch (final CoreException e) { - // do nothing - } - } - } - @Override public Change createChange(final IProgressMonitor monitor) throws CoreException, OperationCanceledException { try { @@ -119,7 +90,7 @@ public Change createChange(final IProgressMonitor monitor) throws CoreException, final LibraryElement type = typeEntry.getType(); if (type instanceof StructuredType) { - return createStructDataChange((DataTypeEntry) typeEntry); + return createStructDataChange(); } if (type instanceof FBType) { return createFBDataChange(); @@ -131,30 +102,29 @@ public Change createChange(final IProgressMonitor monitor) throws CoreException, } } - private CompositeChange createStructDataChange(final DataTypeEntry dataTypeEntry) { - + private CompositeChange createStructDataChange() { final CompositeChange parentChange = new CompositeChange( MessageFormat.format(Messages.Refactoring_RenameFromTo, typeEntry.getTypeName(), newName)); - parentChange.add(new UpdateTypeEntryChange(file, typeEntry, newName, oldName)); - final CompositeChange structUsageChanges = new CompositeChange("Refactoring struct users:"); - parentChange.add(structUsageChanges); - createStructChanges(dataTypeEntry, structUsageChanges); + final Change typeLibraryChange = new UpdateTypeEntryChange(file, typeEntry, newName, oldName); + parentChange.add(typeLibraryChange); - return parentChange; - } + final CompositeChange fbTypeChange = new FbTypeChange(file); + if (fbTypeChange.getChildren().length != 0) { + parentChange.add(fbTypeChange); + } - private static void createStructChanges(final DataTypeEntry dataTypeEntry, - final CompositeChange structUsageChanges) { - final DataTypeInstanceSearch dataTypeInstanceSearch = new DataTypeInstanceSearch(dataTypeEntry); - final Set rootElements = new HashSet<>(); - dataTypeInstanceSearch.performSearch().forEach(obj -> { - if (obj instanceof final VarDeclaration varDecl) { - structUsageChanges.add(createSubChange(varDecl, dataTypeEntry, rootElements)); - } else if (obj instanceof final StructManipulator structMan) { - structUsageChanges.add(new UpdateFBInstanceChange(structMan, dataTypeEntry)); - } - }); + final CompositeChange structChange = new StructTypeChange(file, newName); + if (structChange.getChildren().length != 0) { + parentChange.add(structChange); + } + + final CompositeChange fbInstanceChange = new FbInstanceChange(file); + if (fbInstanceChange.getChildren().length != 0) { + parentChange.add(fbInstanceChange); + } + + return parentChange; } private CompositeChange createFBDataChange() { @@ -166,7 +136,7 @@ private CompositeChange createFBDataChange() { final IEC61499ElementSearch search = new BlockTypeInstanceSearch(typeEntry); final List searchResults = search.performSearch(); searchResults.stream().filter(FBNetworkElement.class::isInstance).map(FBNetworkElement.class::cast) - .map(fbn -> new UpdateFBInstanceChange(fbn, typeEntry)).forEach(change::add); + .map(fbn -> new UpdateInstancesChange(fbn, typeEntry)).forEach(change::add); if (!searchResults.isEmpty()) { parentChange.add(change); @@ -174,27 +144,4 @@ private CompositeChange createFBDataChange() { return parentChange; } - private static Change createSubChange(final VarDeclaration varDecl, final DataTypeEntry dataTypeEntry, - final Set rootElements) { - if (varDecl.getFBNetworkElement() != null) { - if (rootElements.add(varDecl.getFBNetworkElement())) { - return new UpdateFBInstanceChange(varDecl.getFBNetworkElement(), dataTypeEntry); - } - } else { - final EObject rootContainer = EcoreUtil.getRootContainer(varDecl); - if (rootElements.add(rootContainer)) { - if (rootContainer instanceof final StructuredType stElement) { - final CompositeChange change = new CompositeChange(MessageFormat.format( - Messages.Refactoring_AffectedStruct, stElement.getName(), dataTypeEntry.getTypeName())); - change.add(new UpdateStructDataTypeMemberVariableChange(varDecl)); - createStructChanges((DataTypeEntry) stElement.getTypeEntry(), change); - return change; - } - if (rootContainer instanceof final FBType fbType) { - return new InterfaceDataTypeChange(fbType, dataTypeEntry); - } - } - } - return null; - } } diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/StructTypeChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/StructTypeChange.java index 0c0d873282..8521effcb4 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/StructTypeChange.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/StructTypeChange.java @@ -19,10 +19,10 @@ import java.util.Set; import org.eclipse.core.resources.IFile; +import org.eclipse.emf.ecore.EObject; import org.eclipse.fordiac.ide.model.data.StructuredType; -import org.eclipse.fordiac.ide.model.libraryElement.INamedElement; -import org.eclipse.fordiac.ide.model.search.types.InstanceSearch; -import org.eclipse.fordiac.ide.model.search.types.StructDataTypeSearch; +import org.eclipse.fordiac.ide.model.search.types.DataTypeInstanceSearch; +import org.eclipse.fordiac.ide.model.typelibrary.DataTypeEntry; import org.eclipse.fordiac.ide.model.typelibrary.TypeEntry; import org.eclipse.fordiac.ide.model.typelibrary.TypeLibraryManager; import org.eclipse.fordiac.ide.typemanagement.Messages; @@ -72,23 +72,11 @@ private List buildSubChanges() { } private List searchAffectedStructuredType() { - // TODO refactor to new search - final InstanceSearch structMemberSearch = StructDataTypeSearch - .createStructMemberSearch((StructuredType) oldTypeEntry.getTypeEditable()); + final DataTypeInstanceSearch nsearch = new DataTypeInstanceSearch((DataTypeEntry) oldTypeEntry); + final List res = nsearch.performSearch(); - final Set search = InstanceSearch.performProjectSearch(this.file.getProject(), - StructDataTypeSearch.createStructMemberSearch((StructuredType) oldTypeEntry.getTypeEditable()), - StructDataTypeSearch.createStructInterfaceSearch((StructuredType) oldTypeEntry.getTypeEditable())); - - search.addAll(StructDataTypeSearch.createStructMemberSearch((StructuredType) oldTypeEntry.getTypeEditable()) - .searchStructuredTypes(oldTypeEntry.getTypeLibrary())); - - // TODO new search does not yet work - // final IEC61499ElementSearch search2 = new - // DataTypeInstanceSearch((DataTypeEntry) oldTypeEntry.getTypeEditable()); - /// final List searchResults = search2.performSearch(); - - return search.stream().filter(StructuredType.class::isInstance).map(StructuredType.class::cast).toList(); + return res.stream().filter(r -> StructuredType.class.isInstance(r.eContainer())) + .map(r -> StructuredType.class.cast(r.eContainer())).distinct().toList(); } private String buildLabel(final String fbFileName, final String projectName) { From 0a7ac265c9078ae7120cdbf00214798d1e1a98a4 Mon Sep 17 00:00:00 2001 From: Terra Date: Sat, 14 Sep 2024 12:43:33 +0200 Subject: [PATCH 12/22] Updated to use new search --- .../commands/ResizeGroupOrSubappCommand.java | 5 ++- .../ContainerContentLayoutPolicy.java | 2 +- .../editparts/FBDebugViewRootEditPart.java | 10 ++--- .../ide/gef/utilities/ElementSelector.java | 8 ++-- .../refactoring/rename/FbInstanceChange.java | 43 +++++++++++-------- 5 files changed, 40 insertions(+), 28 deletions(-) diff --git a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/commands/ResizeGroupOrSubappCommand.java b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/commands/ResizeGroupOrSubappCommand.java index 7ea8d55ffb..ed0868c5af 100644 --- a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/commands/ResizeGroupOrSubappCommand.java +++ b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/commands/ResizeGroupOrSubappCommand.java @@ -30,6 +30,7 @@ import org.eclipse.fordiac.ide.model.ConnectionLayoutTagger; import org.eclipse.fordiac.ide.model.commands.change.AbstractChangeContainerBoundsCommand; import org.eclipse.fordiac.ide.model.libraryElement.FBNetworkElement; +import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPartViewer; import org.eclipse.gef.GraphicalEditPart; import org.eclipse.gef.commands.Command; @@ -222,7 +223,7 @@ private EditPartViewer getViewer() { } private Rectangle getFBBounds(final List children) { - final Map editPartRegistry = getViewer().getEditPartRegistry(); + final Map editPartRegistry = getViewer().getEditPartRegistry(); Rectangle fbBounds = null; for (final FBNetworkElement fbe : children) { @@ -243,7 +244,7 @@ private Rectangle getFBBounds(final List children) { } private static void addValueBounds(final Rectangle fbBounds, final FBNetworkElement fbe, - final Map editPartRegistry) { + final Map editPartRegistry) { fbe.getInterface().getInputVars().stream().filter(Objects::nonNull) .map(ie -> editPartRegistry.get(ie.getValue())).filter(GraphicalEditPart.class::isInstance) .forEach(ep -> { diff --git a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/policies/ContainerContentLayoutPolicy.java b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/policies/ContainerContentLayoutPolicy.java index 74c3925d95..28c0f2e53b 100644 --- a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/policies/ContainerContentLayoutPolicy.java +++ b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/policies/ContainerContentLayoutPolicy.java @@ -94,7 +94,7 @@ protected Rectangle getNewContentBounds(final List editParts) { } private void addValueBounds(final FBNetworkElement model, final Rectangle selectionExtend) { - final Map editPartRegistry = getHost().getViewer().getEditPartRegistry(); + final Map editPartRegistry = getHost().getViewer().getEditPartRegistry(); model.getInterface().getInputVars().stream().filter(Objects::nonNull) .map(ie -> editPartRegistry.get(ie.getValue())).filter(GraphicalEditPart.class::isInstance) .forEach(ep -> selectionExtend.union(((GraphicalEditPart) ep).getFigure().getBounds())); diff --git a/plugins/org.eclipse.fordiac.ide.debug.ui/src/org/eclipse/fordiac/ide/debug/ui/view/editparts/FBDebugViewRootEditPart.java b/plugins/org.eclipse.fordiac.ide.debug.ui/src/org/eclipse/fordiac/ide/debug/ui/view/editparts/FBDebugViewRootEditPart.java index 5a1c7793c1..4a25dc5b88 100644 --- a/plugins/org.eclipse.fordiac.ide.debug.ui/src/org/eclipse/fordiac/ide/debug/ui/view/editparts/FBDebugViewRootEditPart.java +++ b/plugins/org.eclipse.fordiac.ide.debug.ui/src/org/eclipse/fordiac/ide/debug/ui/view/editparts/FBDebugViewRootEditPart.java @@ -190,7 +190,7 @@ public void terminated(final EvaluatorThreadPoolExecutor executor) { } private void updateValues(final Collection> variables) { - final Map editPartRegistry = getViewer().getEditPartRegistry(); + final Map editPartRegistry = getViewer().getEditPartRegistry(); if (shouldUpdate()) { Display.getDefault().asyncExec(() -> { variables @@ -210,7 +210,7 @@ private boolean shouldUpdate() { return false; } - private void updateVariable(final Map editPartRegistry, final String variableName, + private void updateVariable(final Map editPartRegistry, final String variableName, final Value value) { final InterfaceValueEntity interfaceValueEntity = interfaceValues.get(variableName); if (interfaceValueEntity != null) { @@ -233,7 +233,7 @@ public void handleDebugEvents(final DebugEvent[] events) { break; case DebugEvent.CHANGE: if (ev.getSource() instanceof EvaluatorDebugVariable) { - final Map editPartRegistry = getViewer().getEditPartRegistry(); + final Map editPartRegistry = getViewer().getEditPartRegistry(); Display.getDefault().asyncExec(() -> { final EvaluatorDebugVariable evaluatorDebugVariable = (EvaluatorDebugVariable) ev.getSource(); updateVariable(editPartRegistry, evaluatorDebugVariable.getName(), @@ -248,7 +248,7 @@ public void handleDebugEvents(final DebugEvent[] events) { } private void updateAllValues() { - final Map editPartRegistry = getViewer().getEditPartRegistry(); + final Map editPartRegistry = getViewer().getEditPartRegistry(); Display.getDefault().asyncExec(() -> { interfaceValues.entrySet().forEach(entry -> updateVariable(editPartRegistry, entry.getKey(), entry.getValue().getVariable().getValue())); @@ -256,7 +256,7 @@ private void updateAllValues() { }); } - private void updateAllEvents(final Map editPartRegistry) { + private void updateAllEvents(final Map editPartRegistry) { eventValues.entrySet().forEach(entry -> { final Object ep = editPartRegistry.get(entry.getValue()); if (ep instanceof EventValueEditPart) { diff --git a/plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/utilities/ElementSelector.java b/plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/utilities/ElementSelector.java index d59ace39fa..6e95916d12 100644 --- a/plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/utilities/ElementSelector.java +++ b/plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/utilities/ElementSelector.java @@ -41,7 +41,8 @@ public final class ElementSelector { * @param viewObjects list with objects to select */ public static void selectViewObjects(final Collection viewObjects) { - final IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart(); + final IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() + .getActivePart(); final GraphicalViewer viewer = part.getAdapter(GraphicalViewer.class); if (viewer != null) { viewer.flush(); @@ -58,9 +59,10 @@ public static void selectViewObjects(final Collection viewObje } - private static List getSelectableEditParts(final GraphicalViewer viewer, final Collection viewObjects) { + private static List getSelectableEditParts(final GraphicalViewer viewer, + final Collection viewObjects) { final List selectableChildren = new ArrayList<>(); - final Map editPartRegistry = viewer.getEditPartRegistry(); + final Map editPartRegistry = viewer.getEditPartRegistry(); for (final Object view : viewObjects) { final Object child = editPartRegistry.get(view); if ((child instanceof EditPart) && ((EditPart) child).getModel().equals(view)) { diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbInstanceChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbInstanceChange.java index 2d1d6b6719..dc7415cd92 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbInstanceChange.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbInstanceChange.java @@ -12,6 +12,7 @@ *******************************************************************************/ package org.eclipse.fordiac.ide.typemanagement.refactoring.rename; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -19,12 +20,12 @@ import java.util.Set; import org.eclipse.core.resources.IFile; -import org.eclipse.fordiac.ide.model.data.StructuredType; -import org.eclipse.fordiac.ide.model.libraryElement.FBNetworkElement; -import org.eclipse.fordiac.ide.model.libraryElement.INamedElement; -import org.eclipse.fordiac.ide.model.search.types.FBInstanceSearch; -import org.eclipse.fordiac.ide.model.search.types.InstanceSearch; -import org.eclipse.fordiac.ide.model.search.types.StructDataTypeSearch; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.fordiac.ide.model.libraryElement.impl.BasicFBTypeImpl; +import org.eclipse.fordiac.ide.model.libraryElement.impl.FBImpl; +import org.eclipse.fordiac.ide.model.libraryElement.impl.InterfaceListImpl; +import org.eclipse.fordiac.ide.model.search.types.BlockTypeInstanceSearch; +import org.eclipse.fordiac.ide.model.search.types.DataTypeInstanceSearch; import org.eclipse.fordiac.ide.model.typelibrary.DataTypeEntry; import org.eclipse.fordiac.ide.model.typelibrary.TypeEntry; import org.eclipse.fordiac.ide.model.typelibrary.TypeLibraryManager; @@ -71,20 +72,28 @@ private List buildSubChanges() { }).toList(); } - private List searchAffectedStructuredType() { + private List searchAffectedStructuredType() { + final List affectedFbInstances = new ArrayList<>(); - // TODO use new search - final InstanceSearch structMemberSearch = StructDataTypeSearch - .createStructMemberSearch((StructuredType) oldTypeEntry.getTypeEditable()); + final DataTypeInstanceSearch affectedFbSearch = new DataTypeInstanceSearch((DataTypeEntry) oldTypeEntry); + final List results = affectedFbSearch.performSearch(); - final Set search = InstanceSearch.performProjectSearch(this.file.getProject(), - StructDataTypeSearch.createStructMemberSearch((StructuredType) oldTypeEntry.getTypeEditable()), - StructDataTypeSearch.createStructInterfaceSearch((StructuredType) oldTypeEntry.getTypeEditable()), - new FBInstanceSearch((DataTypeEntry) oldTypeEntry)); + final List affectedFbs = results.stream() + .filter(r -> InterfaceListImpl.class.isInstance(r.eContainer())) + .filter(r -> BasicFBTypeImpl.class.isInstance(r.eContainer().eContainer())) + .map(r -> BasicFBTypeImpl.class.cast(r.eContainer().eContainer())).distinct().toList(); - search.addAll(StructDataTypeSearch.createStructMemberSearch((StructuredType) oldTypeEntry.getTypeEditable()) - .searchStructuredTypes(oldTypeEntry.getTypeLibrary())); - return search.stream().filter(FBNetworkElement.class::isInstance).map(FBNetworkElement.class::cast).toList(); + for (final BasicFBTypeImpl fbType : affectedFbs) { + final BlockTypeInstanceSearch affectedFbInstanceSearch = new BlockTypeInstanceSearch(fbType.getTypeEntry()); + final List affectedFbInstanceSearchResults = affectedFbInstanceSearch.performSearch(); + + for (final EObject object : affectedFbInstanceSearchResults) { + affectedFbInstances.add((FBImpl) object); + } + + } + + return affectedFbInstances; } } From eaefaebd8c81cf623ab1caa029d49cc5787087e7 Mon Sep 17 00:00:00 2001 From: Terra Date: Sat, 14 Sep 2024 13:06:50 +0200 Subject: [PATCH 13/22] Updated copyright notes --- .../actions/FBNetworkSelectAllAction.java | 2 + .../commands/ResizeGroupOrSubappCommand.java | 1 + .../ContainerContentLayoutPolicy.java | 1 + .../editparts/FBDebugViewRootEditPart.java | 1 + .../ide/gef/utilities/ElementSelector.java | 1 + .../fordiac/ide/typemanagement/Messages.java | 2 + .../ide/typemanagement/messages.properties | 1 + .../previews/ChangeConfigurationViewer.java | 38 +++++++++++-------- .../refactoring/InterfaceDataTypeChange.java | 1 + .../refactoring/UpdateInstancesChange.java | 1 + .../RenameTypeRefactoringParticipant.java | 1 + .../rename/StructuredTypeMemberChange.java | 4 +- 12 files changed, 37 insertions(+), 17 deletions(-) diff --git a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/actions/FBNetworkSelectAllAction.java b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/actions/FBNetworkSelectAllAction.java index 754559e9ac..9e4ae23f35 100644 --- a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/actions/FBNetworkSelectAllAction.java +++ b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/actions/FBNetworkSelectAllAction.java @@ -10,6 +10,8 @@ * Contributors: * Alois Zoitl, Filip Andren * - initial API and implementation and/or initial documentation + * Martin Schwarz + * - Build fixes *******************************************************************************/ package org.eclipse.fordiac.ide.application.actions; diff --git a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/commands/ResizeGroupOrSubappCommand.java b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/commands/ResizeGroupOrSubappCommand.java index ed0868c5af..f1ae8c19f9 100644 --- a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/commands/ResizeGroupOrSubappCommand.java +++ b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/commands/ResizeGroupOrSubappCommand.java @@ -9,6 +9,7 @@ * * Contributors: * Fabio Gandolfi - initial implementation and/or documentation + * Martin Schwarz - Build fixes *******************************************************************************/ package org.eclipse.fordiac.ide.application.commands; diff --git a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/policies/ContainerContentLayoutPolicy.java b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/policies/ContainerContentLayoutPolicy.java index 28c0f2e53b..bbcc056aaa 100644 --- a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/policies/ContainerContentLayoutPolicy.java +++ b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/policies/ContainerContentLayoutPolicy.java @@ -14,6 +14,7 @@ * Alois Zoitl - extracted most code into common base class for group * infrastructure * - extracted this policy from the AbstractContainerContentEditPart + * Martin Schwarz - Build fixes *******************************************************************************/ package org.eclipse.fordiac.ide.application.policies; diff --git a/plugins/org.eclipse.fordiac.ide.debug.ui/src/org/eclipse/fordiac/ide/debug/ui/view/editparts/FBDebugViewRootEditPart.java b/plugins/org.eclipse.fordiac.ide.debug.ui/src/org/eclipse/fordiac/ide/debug/ui/view/editparts/FBDebugViewRootEditPart.java index 4a25dc5b88..02a9d32184 100644 --- a/plugins/org.eclipse.fordiac.ide.debug.ui/src/org/eclipse/fordiac/ide/debug/ui/view/editparts/FBDebugViewRootEditPart.java +++ b/plugins/org.eclipse.fordiac.ide.debug.ui/src/org/eclipse/fordiac/ide/debug/ui/view/editparts/FBDebugViewRootEditPart.java @@ -11,6 +11,7 @@ * Contributors: * Alois Zoitl - initial API and implementation and/or initial documentation * Martin Jobst - refactor evaluator API + * Martin Schwarz - Build fixes *******************************************************************************/ package org.eclipse.fordiac.ide.debug.ui.view.editparts; diff --git a/plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/utilities/ElementSelector.java b/plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/utilities/ElementSelector.java index 6e95916d12..bf7959dcf4 100644 --- a/plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/utilities/ElementSelector.java +++ b/plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/utilities/ElementSelector.java @@ -12,6 +12,7 @@ * Filip Adren, Alois Zoitl * - initial API and implementation and/or initial documentation * Fabio Gandolfi - added doubleclickevent for pin jumps + * Martin Schwarz - Build fixes *******************************************************************************/ package org.eclipse.fordiac.ide.gef.utilities; diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/Messages.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/Messages.java index 5c0bd39def..1a4a533af0 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/Messages.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/Messages.java @@ -16,6 +16,8 @@ * - Externalized all translatable strings * Martin Jobst * - add strings for Build Path property page + * Martin Schwarz + * - add/modify strings for rename refactoring *******************************************************************************/ package org.eclipse.fordiac.ide.typemanagement; diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/messages.properties b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/messages.properties index 7b22a7e803..f4f8d7b04b 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/messages.properties +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/messages.properties @@ -13,6 +13,7 @@ # Jose Cabral - Add preferences for information about new types # Andrea Zoitl - Externalized all translatable strings # Martin Jobst - add strings for Build Path property page + # Martin Schwarz - add/modify strings for rename refactoring ############################################################################### AbstractCommandChange_CannotExecuteCommand=Cannot execute command diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/ChangeConfigurationViewer.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/ChangeConfigurationViewer.java index bd9aa03b85..017cd80cd7 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/ChangeConfigurationViewer.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/ChangeConfigurationViewer.java @@ -12,6 +12,8 @@ * - initial API and implementation and/or initial documentation * Dario Romano * - add correct preservation of selection and ui initialization from change state + * Martin Schwarz + * - moved file *******************************************************************************/ package org.eclipse.fordiac.ide.typemanagement.previews; @@ -23,6 +25,8 @@ import org.eclipse.ltk.ui.refactoring.ChangePreviewViewerInput; import org.eclipse.ltk.ui.refactoring.IChangePreviewViewer; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; @@ -45,21 +49,25 @@ public void createControl(final Composite parent) { table.setSize(100, 100); - // TODO inspect this - /* - * // Add a SelectionListener to the table to listen for checkbox changes - * table.addSelectionListener(new SelectionAdapter() { - * - * @Override public void widgetSelected(final SelectionEvent e) { if (e.detail - * == SWT.CHECK) { final TableItem item = (TableItem) e.item; final ChangeState - * cs = choices.get(item); // do not allow de-selection of currently selected - * choice. if (change.getState().contains(cs)) { item.setChecked(true); return; - * } change.addState(cs); change.getState().removeIf(state -> - * !state.equals(cs)); choices.keySet().stream().filter(anyItem -> - * !anyItem.equals(item)) .forEach(otherItem -> otherItem.setChecked(false)); } - * } }); - */ - + // Add a SelectionListener to the table to listen for checkbox changes + table.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(final SelectionEvent e) { + if (e.detail == SWT.CHECK) { + final TableItem item = (TableItem) e.item; + final ChangeState cs = choices.get(item); + // do not allow de-selection of currently selected choice. + if (change.getState().contains(cs)) { + item.setChecked(true); + return; + } + change.addState(cs); + change.getState().removeIf(state -> !state.equals(cs)); + choices.keySet().stream().filter(anyItem -> !anyItem.equals(item)) + .forEach(otherItem -> otherItem.setChecked(false)); + } + } + }); } @Override diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/InterfaceDataTypeChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/InterfaceDataTypeChange.java index 06f0e53916..7fdd973b10 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/InterfaceDataTypeChange.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/InterfaceDataTypeChange.java @@ -9,6 +9,7 @@ * * Contributors: * Michael Oberlehner - initial API and implementation and/or initial documentation + * Martin Schwarz - added additional information to refactoring preview *******************************************************************************/ package org.eclipse.fordiac.ide.typemanagement.refactoring; diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/UpdateInstancesChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/UpdateInstancesChange.java index d20377c9c4..79dec803f2 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/UpdateInstancesChange.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/UpdateInstancesChange.java @@ -11,6 +11,7 @@ * Contributors: * Dario Romano - initial API and implementation and/or initial documentation * Fabio Gandolfi - added FB type update + * Martin Schwarz - moved file and refactored for new preview grouping *******************************************************************************/ package org.eclipse.fordiac.ide.typemanagement.refactoring; diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/RenameTypeRefactoringParticipant.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/RenameTypeRefactoringParticipant.java index f35415d712..87c99b8386 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/RenameTypeRefactoringParticipant.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/RenameTypeRefactoringParticipant.java @@ -10,6 +10,7 @@ * Contributors: * Fabio Gandolfi, Michael Oberlehner - * initial API and implementation and/or initial documentation + * Martin Schwarz - refactored for proper change grouping *******************************************************************************/ package org.eclipse.fordiac.ide.typemanagement.refactoring.rename; diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/StructuredTypeMemberChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/StructuredTypeMemberChange.java index b65a1999fd..a0b95d73fc 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/StructuredTypeMemberChange.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/StructuredTypeMemberChange.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2023 Primetals Technologies Austria GmbH + * Copyright (c) 2024 Johannes Kepler University * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at @@ -8,7 +8,7 @@ * SPDX-License-Identifier: EPL-2.0 * * Contributors: - * Michael Oberlehner - initial API and implementation and/or initial documentation + * Martin Schwarz - initial implementation *******************************************************************************/ package org.eclipse.fordiac.ide.typemanagement.refactoring.rename; From fd046b9d354ca481c4f3db79219007d8b1751a77 Mon Sep 17 00:00:00 2001 From: Terra Date: Sat, 16 Nov 2024 12:32:50 +0100 Subject: [PATCH 14/22] Merge fixes --- .../META-INF/MANIFEST.MF | 3 +- .../RenameTypeRefactoringParticipant.java | 43 ++++++++----------- .../ide/typemanagement/util/FBUpdater.java | 19 ++++++++ 3 files changed, 38 insertions(+), 27 deletions(-) diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/META-INF/MANIFEST.MF b/plugins/org.eclipse.fordiac.ide.typemanagement/META-INF/MANIFEST.MF index c0ce96dd9c..2994050bec 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/META-INF/MANIFEST.MF @@ -22,7 +22,8 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.compare, org.eclipse.emf.compare, org.eclipse.emf.compare.edit, - org.eclipse.emf.compare.ide.ui + org.eclipse.emf.compare.ide.ui, + org.eclipse.fordiac.ide.model.ui Bundle-Vendor: Eclipse 4diac Bundle-ActivationPolicy: lazy Bundle-Version: 3.0.0.qualifier diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/RenameTypeRefactoringParticipant.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/RenameTypeRefactoringParticipant.java index 0324bdd1e8..dfa43a258d 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/RenameTypeRefactoringParticipant.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/RenameTypeRefactoringParticipant.java @@ -31,8 +31,6 @@ import org.eclipse.fordiac.ide.model.typelibrary.TypeEntry; import org.eclipse.fordiac.ide.model.typelibrary.TypeLibraryManager; import org.eclipse.fordiac.ide.typemanagement.Messages; -import org.eclipse.fordiac.ide.typemanagement.refactoring.UpdateFBInstanceChange; -import org.eclipse.fordiac.ide.typemanagement.refactoring.UpdateFBTypeInterfaceChange; import org.eclipse.fordiac.ide.typemanagement.refactoring.UpdateInstancesChange; import org.eclipse.fordiac.ide.typemanagement.refactoring.UpdateTypeEntryChange; import org.eclipse.ltk.core.refactoring.Change; @@ -147,28 +145,21 @@ private CompositeChange createFBDataChange() { return parentChange; } - private static Change createSubChange(final VarDeclaration varDecl, final DataTypeEntry dataTypeEntry, - final Set rootElements) { - if (varDecl.getFBNetworkElement() != null) { - if (rootElements.add(varDecl.getFBNetworkElement())) { - return new UpdateFBInstanceChange(varDecl.getFBNetworkElement(), dataTypeEntry); - } - } else { - final EObject rootContainer = EcoreUtil.getRootContainer(varDecl); - if (rootElements.add(rootContainer)) { - if (rootContainer instanceof final StructuredType stElement) { - final CompositeChange change = new CompositeChange(MessageFormat.format( - Messages.Refactoring_AffectedStruct, stElement.getName(), dataTypeEntry.getTypeName())); - change.add(new UpdateStructDataTypeMemberVariableChange(varDecl)); - createStructChanges((DataTypeEntry) stElement.getTypeEntry(), change); - return change; - } - if (rootContainer instanceof final FBType fbType - && dataTypeEntry.getType() instanceof final StructuredType type) { - return new UpdateFBTypeInterfaceChange(fbType, type); - } - } - } - return null; - } + /* + * private static Change createSubChange(final VarDeclaration varDecl, final + * DataTypeEntry dataTypeEntry, final Set rootElements) { if + * (varDecl.getFBNetworkElement() != null) { if + * (rootElements.add(varDecl.getFBNetworkElement())) { return new + * UpdateFBInstanceChange(varDecl.getFBNetworkElement(), dataTypeEntry); } } + * else { final EObject rootContainer = EcoreUtil.getRootContainer(varDecl); if + * (rootElements.add(rootContainer)) { if (rootContainer instanceof final + * StructuredType stElement) { final CompositeChange change = new + * CompositeChange(MessageFormat.format( Messages.Refactoring_AffectedStruct, + * stElement.getName(), dataTypeEntry.getTypeName())); change.add(new + * UpdateStructDataTypeMemberVariableChange(varDecl)); + * createStructChanges((DataTypeEntry) stElement.getTypeEntry(), change); return + * change; } if (rootContainer instanceof final FBType fbType && + * dataTypeEntry.getType() instanceof final StructuredType type) { return new + * UpdateFBTypeInterfaceChange(fbType, type); } } } return null; } + */ } diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/util/FBUpdater.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/util/FBUpdater.java index 08292efe21..c3f1c64f9c 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/util/FBUpdater.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/util/FBUpdater.java @@ -23,10 +23,12 @@ import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.fordiac.ide.model.commands.change.ChangeStructCommand; import org.eclipse.fordiac.ide.model.commands.change.UpdateFBTypeCommand; +import org.eclipse.fordiac.ide.model.commands.change.UpdatePinInTypeDeclarationCommand; import org.eclipse.fordiac.ide.model.commands.change.UpdateUntypedSubAppInterfaceCommand; import org.eclipse.fordiac.ide.model.data.StructuredType; import org.eclipse.fordiac.ide.model.libraryElement.AutomationSystem; import org.eclipse.fordiac.ide.model.libraryElement.FBNetworkElement; +import org.eclipse.fordiac.ide.model.libraryElement.FBType; import org.eclipse.fordiac.ide.model.libraryElement.INamedElement; import org.eclipse.fordiac.ide.model.libraryElement.StructManipulator; import org.eclipse.fordiac.ide.model.libraryElement.SubApp; @@ -71,6 +73,23 @@ public static Command createUpdateUntypedSubappInterfaceCommand(final Collection return cmd; } + public static Command createUpdatePinInTypeDeclarationCommand(final List types, + final List dataTypeEntries) { + final List commands = new ArrayList<>(); + types.forEach(type -> commands + .add(createUpdatePinInTypeDeclarationCommand(type, dataTypeEntries.get(types.indexOf(type))))); + Command cmd = new CompoundCommand(); + for (final Command subCmd : commands) { + cmd = cmd.chain(subCmd); + } + return cmd; + } + + public static Command createUpdatePinInTypeDeclarationCommand(final FBType type, + final DataTypeEntry dataTypeEntry) { + return new UpdatePinInTypeDeclarationCommand(type, dataTypeEntry); + } + public static Command createStructManipulatorsUpdateCommand(final List muxes, final List dataTypeEntries) { final List commands = new ArrayList<>(); From cb10c64aaf8cc2557d77e87cb7fa8f087ecf415a Mon Sep 17 00:00:00 2001 From: Terra Date: Sun, 17 Nov 2024 17:18:50 +0100 Subject: [PATCH 15/22] Initial WIP POC FBInterface editor in change previews --- .../META-INF/MANIFEST.MF | 3 +- .../plugin.xml | 14 +++ .../InterfaceDataTypeChangePreviewViewer.java | 107 ++++++++++++++++++ .../plugin.xml | 10 -- 4 files changed, 123 insertions(+), 11 deletions(-) create mode 100644 plugins/org.eclipse.fordiac.ide.fbtypeeditor/src/org/eclipse/fordiac/ide/fbtypeeditor/previews/InterfaceDataTypeChangePreviewViewer.java diff --git a/plugins/org.eclipse.fordiac.ide.fbtypeeditor/META-INF/MANIFEST.MF b/plugins/org.eclipse.fordiac.ide.fbtypeeditor/META-INF/MANIFEST.MF index 0439f18f36..242af2f476 100644 --- a/plugins/org.eclipse.fordiac.ide.fbtypeeditor/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.fordiac.ide.fbtypeeditor/META-INF/MANIFEST.MF @@ -30,7 +30,8 @@ Require-Bundle: org.eclipse.ui, org.eclipse.xtext.ui, org.eclipse.nebula.widgets.nattable.core, org.eclipse.fordiac.ide.model.search, - org.eclipse.fordiac.ide.typeeditor + org.eclipse.fordiac.ide.typeeditor, + org.eclipse.ltk.ui.refactoring Bundle-Vendor: Eclipse 4diac Bundle-ActivationPolicy: lazy Bundle-Version: 3.0.0.qualifier diff --git a/plugins/org.eclipse.fordiac.ide.fbtypeeditor/plugin.xml b/plugins/org.eclipse.fordiac.ide.fbtypeeditor/plugin.xml index c7d6bd6b57..29fc391ace 100644 --- a/plugins/org.eclipse.fordiac.ide.fbtypeeditor/plugin.xml +++ b/plugins/org.eclipse.fordiac.ide.fbtypeeditor/plugin.xml @@ -175,5 +175,19 @@ + + + + + + + + + + diff --git a/plugins/org.eclipse.fordiac.ide.fbtypeeditor/src/org/eclipse/fordiac/ide/fbtypeeditor/previews/InterfaceDataTypeChangePreviewViewer.java b/plugins/org.eclipse.fordiac.ide.fbtypeeditor/src/org/eclipse/fordiac/ide/fbtypeeditor/previews/InterfaceDataTypeChangePreviewViewer.java new file mode 100644 index 0000000000..1e6dea0a3e --- /dev/null +++ b/plugins/org.eclipse.fordiac.ide.fbtypeeditor/src/org/eclipse/fordiac/ide/fbtypeeditor/previews/InterfaceDataTypeChangePreviewViewer.java @@ -0,0 +1,107 @@ +/******************************************************************************* + * Copyright (c) 2024 Johannes Kepler University + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Martin Schwarz - initial implementation + *******************************************************************************/ +package org.eclipse.fordiac.ide.fbtypeeditor.previews; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.fordiac.ide.fbtypeeditor.editparts.FBInterfaceEditPartFactory; +import org.eclipse.fordiac.ide.model.ui.editors.AdvancedScrollingGraphicalViewer; +import org.eclipse.fordiac.ide.typemanagement.refactoring.InterfaceDataTypeChange; +import org.eclipse.gef.ui.parts.GraphicalEditor; +import org.eclipse.ltk.ui.refactoring.ChangePreviewViewerInput; +import org.eclipse.ltk.ui.refactoring.IChangePreviewViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; + +@SuppressWarnings("restriction") +public class InterfaceDataTypeChangePreviewViewer implements IChangePreviewViewer { + + private SashForm control; + private AdvancedScrollingGraphicalViewer graphicalViewerLeft; + private AdvancedScrollingGraphicalViewer graphicalViewerRight; + + @Override + public void createControl(final Composite parent) { + // Use GridLayout instead of FillLayout + parent.setLayout(new GridLayout()); + control = new SashForm(parent, SWT.HORIZONTAL); + + // Use GridData to make the SashForm fill all available space + control.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + // Add left and right composites + final Composite compl = new Composite(control, SWT.NONE); + compl.setLayout(new GridLayout()); + final Label labell = new Label(compl, SWT.NONE); + labell.setText("Before refactor"); + graphicalViewerLeft = new AdvancedScrollingGraphicalViewer(); + graphicalViewerLeft.createControl(compl); + graphicalViewerLeft.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + final Composite compr = new Composite(control, SWT.NONE); + compr.setLayout(new GridLayout()); + final Label labelr = new Label(compr, SWT.NONE); + labelr.setText("After refactor"); + graphicalViewerRight = new AdvancedScrollingGraphicalViewer(); + graphicalViewerRight.createControl(compr); + graphicalViewerRight.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + // todo lotsa things + control.setWeights(50, 50); + } + + @Override + public Control getControl() { + return control; + } + + @Override + public void setInput(final ChangePreviewViewerInput input) { + if (!(input.getChange() instanceof InterfaceDataTypeChange)) { + return; + } + + final InterfaceDataTypeChange change = (InterfaceDataTypeChange) input.getChange(); + + final GraphicalEditor mockEditor = new GraphicalEditor() { + + @Override + protected void initializeGraphicalViewer() { + // No initialization needed for mock + } + + @Override + public void doSave(final IProgressMonitor monitor) { + // No save operation needed for mock + } + }; + + graphicalViewerLeft.setEditPartFactory( + new FBInterfaceEditPartFactory(mockEditor, change.getOldTypeEntry().getTypeLibrary())); + + // Set the contents to the modified element + graphicalViewerLeft.setContents(change.getModifiedElement()); + + graphicalViewerRight.setEditPartFactory( + new FBInterfaceEditPartFactory(mockEditor, change.getOldTypeEntry().getTypeLibrary())); + + // Set the contents to the modified element + graphicalViewerRight.setContents(change.getModifiedElement()); + + } + +} \ No newline at end of file diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/plugin.xml b/plugins/org.eclipse.fordiac.ide.typemanagement/plugin.xml index bd133995ef..4bfe8c790d 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/plugin.xml +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/plugin.xml @@ -723,16 +723,6 @@ - - - - - - - From 555747cacdcdf14499112cb49ed2a3ec293deb68 Mon Sep 17 00:00:00 2001 From: Terra Date: Thu, 19 Dec 2024 17:28:14 +0100 Subject: [PATCH 16/22] Completed implementation of the function block instance editor into the change preview --- .../InterfaceDataTypeChangePreviewViewer.java | 94 ++++++++++++++++--- .../InterfaceDataTypeChangePreviewViewer.java | 5 +- .../refactoring/InterfaceDataTypeChange.java | 9 +- .../refactoring/rename/FbTypeChange.java | 7 +- .../RenameTypeRefactoringParticipant.java | 2 +- 5 files changed, 99 insertions(+), 18 deletions(-) diff --git a/plugins/org.eclipse.fordiac.ide.fbtypeeditor/src/org/eclipse/fordiac/ide/fbtypeeditor/previews/InterfaceDataTypeChangePreviewViewer.java b/plugins/org.eclipse.fordiac.ide.fbtypeeditor/src/org/eclipse/fordiac/ide/fbtypeeditor/previews/InterfaceDataTypeChangePreviewViewer.java index 1e6dea0a3e..5cb6325d6f 100644 --- a/plugins/org.eclipse.fordiac.ide.fbtypeeditor/src/org/eclipse/fordiac/ide/fbtypeeditor/previews/InterfaceDataTypeChangePreviewViewer.java +++ b/plugins/org.eclipse.fordiac.ide.fbtypeeditor/src/org/eclipse/fordiac/ide/fbtypeeditor/previews/InterfaceDataTypeChangePreviewViewer.java @@ -13,9 +13,16 @@ package org.eclipse.fordiac.ide.fbtypeeditor.previews; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.draw2d.FigureCanvas; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.fordiac.ide.fbtypeeditor.editparts.FBInterfaceEditPartFactory; +import org.eclipse.fordiac.ide.model.libraryElement.FBType; +import org.eclipse.fordiac.ide.model.typelibrary.TypeEntry; import org.eclipse.fordiac.ide.model.ui.editors.AdvancedScrollingGraphicalViewer; import org.eclipse.fordiac.ide.typemanagement.refactoring.InterfaceDataTypeChange; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.editparts.ScalableRootEditPart; import org.eclipse.gef.ui.parts.GraphicalEditor; import org.eclipse.ltk.ui.refactoring.ChangePreviewViewerInput; import org.eclipse.ltk.ui.refactoring.IChangePreviewViewer; @@ -26,6 +33,7 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.ScrollBar; @SuppressWarnings("restriction") public class InterfaceDataTypeChangePreviewViewer implements IChangePreviewViewer { @@ -36,14 +44,13 @@ public class InterfaceDataTypeChangePreviewViewer implements IChangePreviewViewe @Override public void createControl(final Composite parent) { - // Use GridLayout instead of FillLayout - parent.setLayout(new GridLayout()); - control = new SashForm(parent, SWT.HORIZONTAL); + // Ensure parent layout is set correctly + parent.setLayout(new GridLayout(1, false)); - // Use GridData to make the SashForm fill all available space + control = new SashForm(parent, SWT.VERTICAL); control.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - // Add left and right composites + // Left Composite final Composite compl = new Composite(control, SWT.NONE); compl.setLayout(new GridLayout()); final Label labell = new Label(compl, SWT.NONE); @@ -52,6 +59,7 @@ public void createControl(final Composite parent) { graphicalViewerLeft.createControl(compl); graphicalViewerLeft.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + // Right Composite final Composite compr = new Composite(control, SWT.NONE); compr.setLayout(new GridLayout()); final Label labelr = new Label(compr, SWT.NONE); @@ -60,8 +68,9 @@ public void createControl(final Composite parent) { graphicalViewerRight.createControl(compr); graphicalViewerRight.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - // todo lotsa things - control.setWeights(50, 50); + // Force parent layout + parent.layout(true, true); + } @Override @@ -77,6 +86,23 @@ public void setInput(final ChangePreviewViewerInput input) { final InterfaceDataTypeChange change = (InterfaceDataTypeChange) input.getChange(); + final String newName = change.getNewName(); + final TypeEntry oldTypeEntry = change.getOldTypeEntry(); + final FBType originalFbType = (FBType) change.getModifiedElement(); + final FBType refactoredFbType = EcoreUtil.copy(originalFbType); + + refactoredFbType.getInterfaceList().getInputs() + .filter(var -> var.getTypeName().equals(oldTypeEntry.getTypeName())).forEach(var -> { + var.setType(EcoreUtil.copy(var.getType())); + var.getType().setName(newName); + }); + + refactoredFbType.getInterfaceList().getOutputs() + .filter(var -> var.getTypeName().equals(oldTypeEntry.getTypeName())).forEach(var -> { + var.setType(EcoreUtil.copy(var.getType())); + var.getType().setName(newName); + }); + final GraphicalEditor mockEditor = new GraphicalEditor() { @Override @@ -88,20 +114,66 @@ protected void initializeGraphicalViewer() { public void doSave(final IProgressMonitor monitor) { // No save operation needed for mock } + }; + graphicalViewerLeft.setRootEditPart(new ScalableRootEditPart()); graphicalViewerLeft.setEditPartFactory( new FBInterfaceEditPartFactory(mockEditor, change.getOldTypeEntry().getTypeLibrary())); - - // Set the contents to the modified element graphicalViewerLeft.setContents(change.getModifiedElement()); + graphicalViewerRight.setRootEditPart(new ScalableRootEditPart()); graphicalViewerRight.setEditPartFactory( new FBInterfaceEditPartFactory(mockEditor, change.getOldTypeEntry().getTypeLibrary())); + graphicalViewerRight.setContents(refactoredFbType); + + synchronizeScrolling(graphicalViewerLeft, graphicalViewerRight); + synchronizeScrolling(graphicalViewerRight, graphicalViewerLeft); + + final GraphicalEditPart gEditPartR = (GraphicalEditPart) graphicalViewerRight.getContents(); + + gEditPartR.setLayoutConstraint(gEditPartR.getChildren().get(0), gEditPartR.getChildren().get(0).getFigure(), + new Rectangle(400, 50, -1, -1)); - // Set the contents to the modified element - graphicalViewerRight.setContents(change.getModifiedElement()); + final GraphicalEditPart gEditPartL = (GraphicalEditPart) graphicalViewerLeft.getContents(); + gEditPartL.setLayoutConstraint(gEditPartL.getChildren().get(0), gEditPartL.getChildren().get(0).getFigure(), + new Rectangle(400, 50, -1, -1)); + + // todo remove grid + + } + + private void synchronizeScrolling(final AdvancedScrollingGraphicalViewer source, + final AdvancedScrollingGraphicalViewer target) { + if (source.getControl() instanceof FigureCanvas && target.getControl() instanceof FigureCanvas) { + final FigureCanvas sourceCanvas = (FigureCanvas) source.getControl(); + final FigureCanvas targetCanvas = (FigureCanvas) target.getControl(); + + final ScrollBar sourceHBar = sourceCanvas.getHorizontalBar(); + if (sourceHBar != null) { + sourceHBar.addListener(SWT.Selection, event -> { + final ScrollBar targetHBar = targetCanvas.getHorizontalBar(); + if (targetHBar != null) { + targetHBar.setSelection(sourceHBar.getSelection()); + targetCanvas.scrollTo(sourceCanvas.getHorizontalBar().getSelection(), + sourceCanvas.getVerticalBar().getSelection()); + } + }); + } + + final ScrollBar sourceVBar = sourceCanvas.getVerticalBar(); + if (sourceVBar != null) { + sourceVBar.addListener(SWT.Selection, event -> { + final ScrollBar targetVBar = targetCanvas.getVerticalBar(); + if (targetVBar != null) { + targetVBar.setSelection(sourceVBar.getSelection()); + targetCanvas.scrollTo(sourceCanvas.getHorizontalBar().getSelection(), + sourceCanvas.getVerticalBar().getSelection()); + } + }); + } + } } } \ No newline at end of file diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/InterfaceDataTypeChangePreviewViewer.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/InterfaceDataTypeChangePreviewViewer.java index d0e0d32ead..334eb30c5b 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/InterfaceDataTypeChangePreviewViewer.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/previews/InterfaceDataTypeChangePreviewViewer.java @@ -79,17 +79,18 @@ public void setInput(final ChangePreviewViewerInput input) { final TypeEntry oldTypeEntry = change.getOldTypeEntry(); final FBType originalFbType = (FBType) change.getModifiedElement(); final FBType refactoredFbType = EcoreUtil.copy(originalFbType); + final String newName = change.getNewName(); refactoredFbType.getInterfaceList().getInputs() .filter(var -> var.getTypeName().equals(oldTypeEntry.getTypeName())).forEach(var -> { var.setType(EcoreUtil.copy(var.getType())); - var.getType().setName("TODO"); + var.getType().setName(newName); }); refactoredFbType.getInterfaceList().getOutputs() .filter(var -> var.getTypeName().equals(oldTypeEntry.getTypeName())).forEach(var -> { var.setType(EcoreUtil.copy(var.getType())); - var.getType().setName("TODO"); + var.getType().setName(newName); }); final Comparison comparison = this.emfCompare diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/InterfaceDataTypeChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/InterfaceDataTypeChange.java index 7fdd973b10..6b0de600ba 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/InterfaceDataTypeChange.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/InterfaceDataTypeChange.java @@ -32,13 +32,14 @@ public class InterfaceDataTypeChange extends Change { private final FBType fbType; private final TypeEntry oldTypeEntry; + private final String newName; private final List inputPinNames; private final List outputPinNames; - public InterfaceDataTypeChange(final FBType fbType, final TypeEntry oldTypeEntry) { + public InterfaceDataTypeChange(final FBType fbType, final TypeEntry oldTypeEntry, final String newName) { this.fbType = fbType; - + this.newName = newName; this.oldTypeEntry = oldTypeEntry; this.inputPinNames = fbType.getInterfaceList().getInputs() .filter(input -> input.getTypeName().equals(oldTypeEntry.getTypeName())).map(IInterfaceElement::getName) @@ -89,4 +90,8 @@ public TypeEntry getOldTypeEntry() { return oldTypeEntry; } + public String getNewName() { + return newName; + } + } diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbTypeChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbTypeChange.java index 98ef827ba0..3d766df05d 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbTypeChange.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbTypeChange.java @@ -34,11 +34,13 @@ public class FbTypeChange extends CompositeChange { private final IFile file; + private final String newName; private final TypeEntry oldTypeEntry; - public FbTypeChange(final IFile targetFile) { + public FbTypeChange(final IFile targetFile, final String newName) { super(Messages.Refactoring_AffectedFuctionBlock); this.file = targetFile; + this.newName = newName; this.oldTypeEntry = TypeLibraryManager.INSTANCE.getTypeEntryForFile(this.file); buildChanges(); } @@ -60,7 +62,8 @@ private List buildSubChanges() { functionBlockChangeMap.put(label, new HashSet<>()); } - functionBlockChangeMap.get(label).add(new InterfaceDataTypeChange(functionBlockType, oldTypeEntry)); + functionBlockChangeMap.get(label) + .add(new InterfaceDataTypeChange(functionBlockType, oldTypeEntry, newName)); }); return functionBlockChangeMap.entrySet().stream().map(entry -> { diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/RenameTypeRefactoringParticipant.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/RenameTypeRefactoringParticipant.java index dfa43a258d..5ebada9cc2 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/RenameTypeRefactoringParticipant.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/RenameTypeRefactoringParticipant.java @@ -110,7 +110,7 @@ private CompositeChange createStructDataChange() { final Change typeLibraryChange = new UpdateTypeEntryChange(file, typeEntry, newName, oldName); parentChange.add(typeLibraryChange); - final CompositeChange fbTypeChange = new FbTypeChange(file); + final CompositeChange fbTypeChange = new FbTypeChange(file, newName); if (fbTypeChange.getChildren().length != 0) { parentChange.add(fbTypeChange); } From 2e8539ce443b3e4279006f1f81a2b7126a2d1fac Mon Sep 17 00:00:00 2001 From: Terra Date: Sat, 4 Jan 2025 21:38:43 +0100 Subject: [PATCH 17/22] WIP system editor --- .../META-INF/MANIFEST.MF | 2 + .../plugin.xml | 14 ++ .../editors/ApplicationEditor.java | 1 + .../application/editors/FBNetworkEditor.java | 2 + .../previews/ProjectChangePreviewViewer.java | 138 ++++++++++++++++++ .../editparts/FBInterfaceEditPartFactory.java | 1 + .../plugin.xml | 10 -- .../refactoring/UpdateInstancesChange.java | 13 +- .../refactoring/rename/FbInstanceChange.java | 16 +- .../rename/ProjectFbInstanceChange.java | 38 +++++ .../RenameTypeRefactoringParticipant.java | 3 +- 11 files changed, 215 insertions(+), 23 deletions(-) create mode 100644 plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/applications/previews/ProjectChangePreviewViewer.java create mode 100644 plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/ProjectFbInstanceChange.java diff --git a/plugins/org.eclipse.fordiac.ide.application/META-INF/MANIFEST.MF b/plugins/org.eclipse.fordiac.ide.application/META-INF/MANIFEST.MF index 42f053ac25..c40b25de84 100644 --- a/plugins/org.eclipse.fordiac.ide.application/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.fordiac.ide.application/META-INF/MANIFEST.MF @@ -37,3 +37,5 @@ Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.eclipse.fordiac.ide.application;singleton:=true Bundle-RequiredExecutionEnvironment: JavaSE-21 Automatic-Module-Name: org.eclipse.fordiac.ide.application +Import-Package: org.eclipse.ltk.core.refactoring, + org.eclipse.ltk.ui.refactoring diff --git a/plugins/org.eclipse.fordiac.ide.application/plugin.xml b/plugins/org.eclipse.fordiac.ide.application/plugin.xml index 69921a425a..b712937441 100644 --- a/plugins/org.eclipse.fordiac.ide.application/plugin.xml +++ b/plugins/org.eclipse.fordiac.ide.application/plugin.xml @@ -1857,4 +1857,18 @@ type="java.lang.Object"> + + + + + + + + + + diff --git a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/editors/ApplicationEditor.java b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/editors/ApplicationEditor.java index b2a589c32b..80d67eba60 100644 --- a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/editors/ApplicationEditor.java +++ b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/editors/ApplicationEditor.java @@ -37,6 +37,7 @@ public void notifyChanged(final Notification notification) { @Override public void setInput(final IEditorInput input) { + System.out.println("ApplicationEditorInput called"); if (input instanceof final ApplicationEditorInput appInput) { final Application app = appInput.getContent(); setModel(app.getFBNetwork()); diff --git a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/editors/FBNetworkEditor.java b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/editors/FBNetworkEditor.java index d61a9482bd..165c55fa87 100644 --- a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/editors/FBNetworkEditor.java +++ b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/editors/FBNetworkEditor.java @@ -99,6 +99,8 @@ public FBNetwork getModel() { * Instantiates a new fB network editor. */ public FBNetworkEditor() { + System.out.println("FBNetworkEditor called"); + // empty constructor } diff --git a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/applications/previews/ProjectChangePreviewViewer.java b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/applications/previews/ProjectChangePreviewViewer.java new file mode 100644 index 0000000000..5d8ef0e58e --- /dev/null +++ b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/applications/previews/ProjectChangePreviewViewer.java @@ -0,0 +1,138 @@ +/******************************************************************************* + * Copyright (c) 2024 Johannes Kepler University + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Martin Schwarz - initial implementation + *******************************************************************************/ +package org.eclipse.fordiac.ide.applications.previews; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.draw2d.FigureCanvas; +import org.eclipse.fordiac.ide.application.editparts.ElementEditPartFactory; +import org.eclipse.fordiac.ide.model.libraryElement.AutomationSystem; +import org.eclipse.fordiac.ide.model.libraryElement.FBNetwork; +import org.eclipse.fordiac.ide.model.ui.editors.AdvancedScrollingGraphicalViewer; +import org.eclipse.fordiac.ide.systemmanagement.SystemManager; +import org.eclipse.fordiac.ide.typemanagement.refactoring.UpdateInstancesChange; +import org.eclipse.gef.editparts.ScalableFreeformRootEditPart; +import org.eclipse.gef.ui.parts.GraphicalEditor; +import org.eclipse.ltk.ui.refactoring.ChangePreviewViewerInput; +import org.eclipse.ltk.ui.refactoring.IChangePreviewViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.ScrollBar; + +@SuppressWarnings("restriction") +public class ProjectChangePreviewViewer implements IChangePreviewViewer { + + private SashForm control; + private AdvancedScrollingGraphicalViewer graphicalViewerLeft; + private AdvancedScrollingGraphicalViewer graphicalViewerRight; + + @Override + public void createControl(final Composite parent) { + System.out.println("Creating Project Change preview"); + + // Ensure parent layout is set correctly + parent.setLayout(new GridLayout(1, false)); + + control = new SashForm(parent, SWT.VERTICAL); + control.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + // Left Composite + final Composite compl = new Composite(control, SWT.NONE); + compl.setLayout(new GridLayout()); + final Label labell = new Label(compl, SWT.NONE); + graphicalViewerLeft = new AdvancedScrollingGraphicalViewer(); + graphicalViewerLeft.createControl(compl); + graphicalViewerLeft.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + // Force parent layout + parent.layout(true, true); + + } + + @Override + public Control getControl() { + return control; + } + + @Override + public void setInput(final ChangePreviewViewerInput input) { + + System.out.println("Creating Project Change preview"); + if (!(input.getChange() instanceof UpdateInstancesChange)) { + return; + } + + final UpdateInstancesChange change = (UpdateInstancesChange) input.getChange(); + + final AutomationSystem system = SystemManager.INSTANCE.getProjectSystems(change.getProject()).getFirst(); + + final FBNetwork network = system.getApplication().getFirst().getFBNetwork(); + + final GraphicalEditor mockEditor = new GraphicalEditor() { + + @Override + protected void initializeGraphicalViewer() { + // No initialization needed for mock + } + + @Override + public void doSave(final IProgressMonitor monitor) { + // No save final operation needed for mock + + } + + }; + + graphicalViewerLeft.setRootEditPart(new ScalableFreeformRootEditPart()); + graphicalViewerLeft.setEditPartFactory(new ElementEditPartFactory(mockEditor)); + graphicalViewerLeft.setContents(network); + + } + + private void synchronizeScrolling(final AdvancedScrollingGraphicalViewer source, + final AdvancedScrollingGraphicalViewer target) { + if (source.getControl() instanceof FigureCanvas && target.getControl() instanceof FigureCanvas) { + final FigureCanvas sourceCanvas = (FigureCanvas) source.getControl(); + final FigureCanvas targetCanvas = (FigureCanvas) target.getControl(); + + final ScrollBar sourceHBar = sourceCanvas.getHorizontalBar(); + if (sourceHBar != null) { + sourceHBar.addListener(SWT.Selection, event -> { + final ScrollBar targetHBar = targetCanvas.getHorizontalBar(); + if (targetHBar != null) { + targetHBar.setSelection(sourceHBar.getSelection()); + targetCanvas.scrollTo(sourceCanvas.getHorizontalBar().getSelection(), + sourceCanvas.getVerticalBar().getSelection()); + } + }); + } + + final ScrollBar sourceVBar = sourceCanvas.getVerticalBar(); + if (sourceVBar != null) { + sourceVBar.addListener(SWT.Selection, event -> { + final ScrollBar targetVBar = targetCanvas.getVerticalBar(); + if (targetVBar != null) { + targetVBar.setSelection(sourceVBar.getSelection()); + targetCanvas.scrollTo(sourceCanvas.getHorizontalBar().getSelection(), + sourceCanvas.getVerticalBar().getSelection()); + } + }); + } + } + } + +} \ No newline at end of file diff --git a/plugins/org.eclipse.fordiac.ide.fbtypeeditor/src/org/eclipse/fordiac/ide/fbtypeeditor/editparts/FBInterfaceEditPartFactory.java b/plugins/org.eclipse.fordiac.ide.fbtypeeditor/src/org/eclipse/fordiac/ide/fbtypeeditor/editparts/FBInterfaceEditPartFactory.java index 40fbc464d8..ceaa2a8a52 100644 --- a/plugins/org.eclipse.fordiac.ide.fbtypeeditor/src/org/eclipse/fordiac/ide/fbtypeeditor/editparts/FBInterfaceEditPartFactory.java +++ b/plugins/org.eclipse.fordiac.ide.fbtypeeditor/src/org/eclipse/fordiac/ide/fbtypeeditor/editparts/FBInterfaceEditPartFactory.java @@ -34,6 +34,7 @@ public FBInterfaceEditPartFactory(final GraphicalEditor editor, final TypeLibrar @Override protected EditPart getPartForElement(final EditPart context, final Object modelElement) { + System.out.println("Loaded editor for:" + modelElement.getClass()); if (modelElement instanceof FBType && context == null) { return new FBTypeRootEditPart(); } diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/plugin.xml b/plugins/org.eclipse.fordiac.ide.typemanagement/plugin.xml index 4bfe8c790d..0781e794ef 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/plugin.xml +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/plugin.xml @@ -723,16 +723,6 @@ - - - - - - - diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/UpdateInstancesChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/UpdateInstancesChange.java index 79dec803f2..32ef0f0c3e 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/UpdateInstancesChange.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/UpdateInstancesChange.java @@ -15,6 +15,7 @@ *******************************************************************************/ package org.eclipse.fordiac.ide.typemanagement.refactoring; +import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; @@ -40,14 +41,12 @@ public class UpdateInstancesChange extends Change { private final FBNetworkElement instance; private final TypeEntry typeEntry; + private final IProject project; - public UpdateInstancesChange(final FBNetworkElement instance, final TypeEntry typeEntry) { + public UpdateInstancesChange(final FBNetworkElement instance, final TypeEntry typeEntry, final IProject project) { this.instance = instance; this.typeEntry = typeEntry; - } - - public UpdateInstancesChange(final FBNetworkElement instance) { - this(instance, null); + this.project = project; } @Override @@ -93,4 +92,8 @@ public Object getModifiedElement() { return null; } + public IProject getProject() { + return project; + } + } diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbInstanceChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbInstanceChange.java index dc7415cd92..37c8ef8ac3 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbInstanceChange.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/FbInstanceChange.java @@ -20,6 +20,7 @@ import java.util.Set; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; import org.eclipse.emf.ecore.EObject; import org.eclipse.fordiac.ide.model.libraryElement.impl.BasicFBTypeImpl; import org.eclipse.fordiac.ide.model.libraryElement.impl.FBImpl; @@ -50,21 +51,22 @@ private void buildChanges() { buildSubChanges().forEach(this::add); } - private List buildSubChanges() { - final Map> affectedStructChanges = new HashMap<>(); + private List buildSubChanges() { + final Map> affectedStructChanges = new HashMap<>(); searchAffectedStructuredType().forEach(impactedStructuredType -> { - final String label = impactedStructuredType.getTypeEntry().getFile().getProject().getName(); + final IProject project = impactedStructuredType.getTypeEntry().getFile().getProject(); - if (!affectedStructChanges.containsKey(label)) { - affectedStructChanges.put(label, new HashSet<>()); + if (!affectedStructChanges.containsKey(project)) { + affectedStructChanges.put(project, new HashSet<>()); } - affectedStructChanges.get(label).add(new UpdateInstancesChange(impactedStructuredType, oldTypeEntry)); + affectedStructChanges.get(project) + .add(new UpdateInstancesChange(impactedStructuredType, oldTypeEntry, project)); }); return affectedStructChanges.entrySet().stream().map(entry -> { - final CompositeChange fbChange = new CompositeChange(entry.getKey()); + final ProjectFbInstanceChange fbChange = new ProjectFbInstanceChange(file, entry.getKey()); entry.getValue().stream().forEach(fbChange::add); diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/ProjectFbInstanceChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/ProjectFbInstanceChange.java new file mode 100644 index 0000000000..4e311f2a5f --- /dev/null +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/ProjectFbInstanceChange.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2024 Johannes Kepler University + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Martin Schwarz - initial implementation + *******************************************************************************/ +package org.eclipse.fordiac.ide.typemanagement.refactoring.rename; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.fordiac.ide.model.typelibrary.TypeEntry; +import org.eclipse.fordiac.ide.model.typelibrary.TypeLibraryManager; +import org.eclipse.ltk.core.refactoring.CompositeChange; + +public class ProjectFbInstanceChange extends CompositeChange { + + private final IFile file; + private final IProject project; + private final TypeEntry oldTypeEntry; + + public ProjectFbInstanceChange(final IFile file, final IProject project) { + super(project.getName()); + this.file = file; + this.project = project; + this.oldTypeEntry = TypeLibraryManager.INSTANCE.getTypeEntryForFile(file); + } + + public IProject getProject() { + return project; + } + +} diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/RenameTypeRefactoringParticipant.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/RenameTypeRefactoringParticipant.java index 5ebada9cc2..e1ba68aa77 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/RenameTypeRefactoringParticipant.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/rename/RenameTypeRefactoringParticipant.java @@ -137,7 +137,8 @@ private CompositeChange createFBDataChange() { final IEC61499ElementSearch search = new BlockTypeInstanceSearch(typeEntry); final List searchResults = search.performSearch(); searchResults.stream().filter(FBNetworkElement.class::isInstance).map(FBNetworkElement.class::cast) - .map(fbn -> new UpdateInstancesChange(fbn, typeEntry)).forEach(change::add); + .map(fbn -> new UpdateInstancesChange(fbn, typeEntry, typeEntry.getFile().getProject())) + .forEach(change::add); if (!searchResults.isEmpty()) { parentChange.add(change); From 55934aca7fc62e70717d48b44c21a01aaae32fc5 Mon Sep 17 00:00:00 2001 From: Terra Date: Mon, 6 Jan 2025 15:15:21 +0100 Subject: [PATCH 18/22] Working project FB interface preview --- .../previews/ProjectChangePreviewViewer.java | 159 +++++++++++++----- .../refactoring/UpdateInstancesChange.java | 4 + 2 files changed, 122 insertions(+), 41 deletions(-) diff --git a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/applications/previews/ProjectChangePreviewViewer.java b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/applications/previews/ProjectChangePreviewViewer.java index 5d8ef0e58e..8ceb5707bb 100644 --- a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/applications/previews/ProjectChangePreviewViewer.java +++ b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/applications/previews/ProjectChangePreviewViewer.java @@ -13,13 +13,21 @@ package org.eclipse.fordiac.ide.applications.previews; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.draw2d.ColorConstants; import org.eclipse.draw2d.FigureCanvas; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Polyline; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.Rectangle; import org.eclipse.fordiac.ide.application.editparts.ElementEditPartFactory; import org.eclipse.fordiac.ide.model.libraryElement.AutomationSystem; import org.eclipse.fordiac.ide.model.libraryElement.FBNetwork; +import org.eclipse.fordiac.ide.model.libraryElement.FBNetworkElement; import org.eclipse.fordiac.ide.model.ui.editors.AdvancedScrollingGraphicalViewer; import org.eclipse.fordiac.ide.systemmanagement.SystemManager; import org.eclipse.fordiac.ide.typemanagement.refactoring.UpdateInstancesChange; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.editparts.AbstractGraphicalEditPart; import org.eclipse.gef.editparts.ScalableFreeformRootEditPart; import org.eclipse.gef.ui.parts.GraphicalEditor; import org.eclipse.ltk.ui.refactoring.ChangePreviewViewerInput; @@ -31,36 +39,42 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.ScrollBar; @SuppressWarnings("restriction") public class ProjectChangePreviewViewer implements IChangePreviewViewer { private SashForm control; - private AdvancedScrollingGraphicalViewer graphicalViewerLeft; - private AdvancedScrollingGraphicalViewer graphicalViewerRight; + private Composite parent; + + private AdvancedScrollingGraphicalViewer graphicalViewer; @Override public void createControl(final Composite parent) { - System.out.println("Creating Project Change preview"); + System.out.println("Creating Project Change preview control"); // Ensure parent layout is set correctly parent.setLayout(new GridLayout(1, false)); + this.parent = parent; + + resetControl(); + } + + private void resetControl() { + if (control != null) { + control.dispose(); + } + control = new SashForm(parent, SWT.VERTICAL); control.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - // Left Composite final Composite compl = new Composite(control, SWT.NONE); compl.setLayout(new GridLayout()); final Label labell = new Label(compl, SWT.NONE); - graphicalViewerLeft = new AdvancedScrollingGraphicalViewer(); - graphicalViewerLeft.createControl(compl); - graphicalViewerLeft.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - - // Force parent layout + graphicalViewer = new AdvancedScrollingGraphicalViewer(); + graphicalViewer.createControl(compl); + graphicalViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); parent.layout(true, true); - } @Override @@ -71,7 +85,7 @@ public Control getControl() { @Override public void setInput(final ChangePreviewViewerInput input) { - System.out.println("Creating Project Change preview"); + System.out.println("Creating Project Change preview input"); if (!(input.getChange() instanceof UpdateInstancesChange)) { return; } @@ -97,42 +111,105 @@ public void doSave(final IProgressMonitor monitor) { }; - graphicalViewerLeft.setRootEditPart(new ScalableFreeformRootEditPart()); - graphicalViewerLeft.setEditPartFactory(new ElementEditPartFactory(mockEditor)); - graphicalViewerLeft.setContents(network); + resetControl(); + + graphicalViewer.setRootEditPart(new ScalableFreeformRootEditPart()); + graphicalViewer.setEditPartFactory(new ElementEditPartFactory(mockEditor)); + graphicalViewer.setContents(network); // exception here + drawRedRectangleForElement(graphicalViewer, change.getFBNetworkElement()); } - private void synchronizeScrolling(final AdvancedScrollingGraphicalViewer source, - final AdvancedScrollingGraphicalViewer target) { - if (source.getControl() instanceof FigureCanvas && target.getControl() instanceof FigureCanvas) { - final FigureCanvas sourceCanvas = (FigureCanvas) source.getControl(); - final FigureCanvas targetCanvas = (FigureCanvas) target.getControl(); - - final ScrollBar sourceHBar = sourceCanvas.getHorizontalBar(); - if (sourceHBar != null) { - sourceHBar.addListener(SWT.Selection, event -> { - final ScrollBar targetHBar = targetCanvas.getHorizontalBar(); - if (targetHBar != null) { - targetHBar.setSelection(sourceHBar.getSelection()); - targetCanvas.scrollTo(sourceCanvas.getHorizontalBar().getSelection(), - sourceCanvas.getVerticalBar().getSelection()); - } - }); + private void resetGraphicalViewer(final AdvancedScrollingGraphicalViewer viewer) { + if (viewer != null) { + // Clear previous contents, remove listeners, and reinitialize + viewer.setContents(null); // Ensure we clear the current contents + if (viewer.getControl() != null) { + viewer.getControl().setRedraw(false); // Disable redraw during reset to avoid flicker + viewer.getControl().dispose(); // Dispose the old canvas/control if necessary } + } + } - final ScrollBar sourceVBar = sourceCanvas.getVerticalBar(); - if (sourceVBar != null) { - sourceVBar.addListener(SWT.Selection, event -> { - final ScrollBar targetVBar = targetCanvas.getVerticalBar(); - if (targetVBar != null) { - targetVBar.setSelection(sourceVBar.getSelection()); - targetCanvas.scrollTo(sourceCanvas.getHorizontalBar().getSelection(), - sourceCanvas.getVerticalBar().getSelection()); - } - }); + private void drawRedRectangleForElement(final AdvancedScrollingGraphicalViewer viewer, final FBNetworkElement fb) { + if (viewer != null && fb != null) { + // Get the edit part for the FBNetworkElement + final EditPart editPart = viewer.getEditPartRegistry().get(fb); + + if (editPart != null) { + // Get the figure for the edit part (this represents the visual element) + final IFigure figure = ((AbstractGraphicalEditPart) editPart).getFigure(); + if (figure != null) { + // Ensure layout is complete before accessing bounds + viewer.getControl().getDisplay().asyncExec(() -> { + // Now, access the bounds after ensuring the figure is laid out + final Rectangle bounds = figure.getBounds(); + System.out.println("Figure bounds (local): " + bounds.x + ", " + bounds.y); + + // Translate to absolute coordinates + figure.translateToAbsolute(bounds); + System.out.println("Figure bounds (absolute): " + bounds.x + ", " + bounds.y); + + createRedBorder(viewer, bounds); + + // Add the red rectangle to the canvas (drawing layer) + final FigureCanvas canvas = (FigureCanvas) viewer.getControl(); + if (canvas != null) { + + System.out.println("Scroll to " + bounds.x + "X and " + bounds.y + "Y"); + canvas.scrollTo(bounds.x - 10, bounds.y - 10); + } + + }); + } else { + System.out.println("Figure for edit part is null."); + } + } else { + System.out.println("EditPart for FBNetworkElement is null."); } } } + private void createRedBorder(final AdvancedScrollingGraphicalViewer viewer, final Rectangle bounds) { + final int padding = 5; + + // Top line with padding + final Polyline topLine = new Polyline(); + topLine.addPoint(new Point(bounds.x - padding, bounds.y - padding)); // Apply padding + topLine.addPoint(new Point(bounds.x + bounds.width + padding, bounds.y - padding)); // Apply padding + topLine.setForegroundColor(ColorConstants.red); + topLine.setLineWidth(2); // Thicker line width + + // Bottom line with padding + final Polyline bottomLine = new Polyline(); + bottomLine.addPoint(new Point(bounds.x - padding, bounds.y + bounds.height + padding)); // Apply padding + bottomLine.addPoint(new Point(bounds.x + bounds.width + padding, bounds.y + bounds.height + padding)); // Apply + // padding + bottomLine.setForegroundColor(ColorConstants.red); + bottomLine.setLineWidth(2); // Thicker line width + + // Left line with padding + final Polyline leftLine = new Polyline(); + leftLine.addPoint(new Point(bounds.x - padding, bounds.y - padding)); // Apply padding + leftLine.addPoint(new Point(bounds.x - padding, bounds.y + bounds.height + padding)); // Apply padding + leftLine.setForegroundColor(ColorConstants.red); + leftLine.setLineWidth(2); // Thicker line width + + // Right line with padding + final Polyline rightLine = new Polyline(); + rightLine.addPoint(new Point(bounds.x + bounds.width + padding, bounds.y - padding)); // Apply padding + rightLine.addPoint(new Point(bounds.x + bounds.width + padding, bounds.y + bounds.height + padding)); // Apply + // padding + rightLine.setForegroundColor(ColorConstants.red); + rightLine.setLineWidth(2); // Thicker line width + + // Add the lines to the canvas (drawing layer) + final FigureCanvas canvas = (FigureCanvas) viewer.getControl(); + if (canvas != null) { + canvas.getContents().add(topLine); + canvas.getContents().add(bottomLine); + canvas.getContents().add(leftLine); + canvas.getContents().add(rightLine); + } + } } \ No newline at end of file diff --git a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/UpdateInstancesChange.java b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/UpdateInstancesChange.java index 32ef0f0c3e..1ab9f7a4ad 100644 --- a/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/UpdateInstancesChange.java +++ b/plugins/org.eclipse.fordiac.ide.typemanagement/src/org/eclipse/fordiac/ide/typemanagement/refactoring/UpdateInstancesChange.java @@ -96,4 +96,8 @@ public IProject getProject() { return project; } + public FBNetworkElement getFBNetworkElement() { + return instance; + } + } From 648626a56135dfefd783fd4cb6c6c0a2f2d4d660 Mon Sep 17 00:00:00 2001 From: Terra Date: Mon, 6 Jan 2025 15:48:24 +0100 Subject: [PATCH 19/22] Added marking of changed/impacted visual elements in change preview --- .../InterfaceDataTypeChangePreviewViewer.java | 112 +++++++++++++++++- 1 file changed, 111 insertions(+), 1 deletion(-) diff --git a/plugins/org.eclipse.fordiac.ide.fbtypeeditor/src/org/eclipse/fordiac/ide/fbtypeeditor/previews/InterfaceDataTypeChangePreviewViewer.java b/plugins/org.eclipse.fordiac.ide.fbtypeeditor/src/org/eclipse/fordiac/ide/fbtypeeditor/previews/InterfaceDataTypeChangePreviewViewer.java index 5cb6325d6f..2ba02a6632 100644 --- a/plugins/org.eclipse.fordiac.ide.fbtypeeditor/src/org/eclipse/fordiac/ide/fbtypeeditor/previews/InterfaceDataTypeChangePreviewViewer.java +++ b/plugins/org.eclipse.fordiac.ide.fbtypeeditor/src/org/eclipse/fordiac/ide/fbtypeeditor/previews/InterfaceDataTypeChangePreviewViewer.java @@ -13,10 +13,15 @@ package org.eclipse.fordiac.ide.fbtypeeditor.previews; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.draw2d.ColorConstants; import org.eclipse.draw2d.FigureCanvas; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Polyline; +import org.eclipse.draw2d.geometry.Point; import org.eclipse.draw2d.geometry.Rectangle; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.fordiac.ide.fbtypeeditor.editparts.FBInterfaceEditPartFactory; +import org.eclipse.fordiac.ide.fbtypeeditor.editparts.InterfaceEditPart; import org.eclipse.fordiac.ide.model.libraryElement.FBType; import org.eclipse.fordiac.ide.model.typelibrary.TypeEntry; import org.eclipse.fordiac.ide.model.ui.editors.AdvancedScrollingGraphicalViewer; @@ -39,6 +44,8 @@ public class InterfaceDataTypeChangePreviewViewer implements IChangePreviewViewer { private SashForm control; + private Composite parent; + private AdvancedScrollingGraphicalViewer graphicalViewerLeft; private AdvancedScrollingGraphicalViewer graphicalViewerRight; @@ -47,6 +54,16 @@ public void createControl(final Composite parent) { // Ensure parent layout is set correctly parent.setLayout(new GridLayout(1, false)); + this.parent = parent; + + resetControl(); + } + + private void resetControl() { + if (control != null) { + control.dispose(); + } + control = new SashForm(parent, SWT.VERTICAL); control.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); @@ -70,7 +87,6 @@ public void createControl(final Composite parent) { // Force parent layout parent.layout(true, true); - } @Override @@ -89,6 +105,7 @@ public void setInput(final ChangePreviewViewerInput input) { final String newName = change.getNewName(); final TypeEntry oldTypeEntry = change.getOldTypeEntry(); final FBType originalFbType = (FBType) change.getModifiedElement(); + final FBType refactoredFbType = EcoreUtil.copy(originalFbType); refactoredFbType.getInterfaceList().getInputs() @@ -117,6 +134,8 @@ public void doSave(final IProgressMonitor monitor) { }; + resetControl(); + graphicalViewerLeft.setRootEditPart(new ScalableRootEditPart()); graphicalViewerLeft.setEditPartFactory( new FBInterfaceEditPartFactory(mockEditor, change.getOldTypeEntry().getTypeLibrary())); @@ -142,6 +161,8 @@ public void doSave(final IProgressMonitor monitor) { // todo remove grid + drawRedRectangleForElement(graphicalViewerLeft, oldTypeEntry.getTypeName()); + } private void synchronizeScrolling(final AdvancedScrollingGraphicalViewer source, @@ -176,4 +197,93 @@ private void synchronizeScrolling(final AdvancedScrollingGraphicalViewer source, } } + private void drawRedRectangleForElement(final AdvancedScrollingGraphicalViewer viewer, + final String originalTypeName) { + if (viewer != null) { + // Iterate over all entries in the EditPartRegistry + viewer.getEditPartRegistry().forEach((key, val) -> { + + // Check if the EditPart is an instance of InterfaceEditPart + // Check if the InterfaceEditPart's model matches the originalTypeName + if ((val instanceof final InterfaceEditPart part) + && part.getCastedModel().getFullTypeName().equals(originalTypeName)) { + // We found a matching InterfaceEditPart + System.out.println("Found matching InterfaceEditPart: " + originalTypeName); + + // Get the corresponding figure for the EditPart + final IFigure figure = part.getFigure(); + if (figure != null) { + // Ensure layout is complete before accessing bounds + viewer.getControl().getDisplay().asyncExec(() -> { + // Access the bounds after ensuring the figure is laid out + final Rectangle bounds = figure.getBounds(); + System.out.println("Figure bounds (local): " + bounds.x + ", " + bounds.y); + + // Translate the bounds to absolute coordinates + figure.translateToAbsolute(bounds); + System.out.println("Figure bounds (absolute): " + bounds.x + ", " + bounds.y); + + // Create the red border around the figure + createRedBorder(viewer, bounds); + + // Add the red border to the canvas (drawing layer) + final FigureCanvas canvas = (FigureCanvas) viewer.getControl(); + if (canvas != null) { + // Optionally scroll the canvas to the position of the element + System.out.println("Scroll to " + bounds.x + "X and " + bounds.y + "Y"); + canvas.scrollTo(bounds.x - 10, bounds.y - 10); // Adding a small offset to make sure + // it's visible + } + }); + } else { + System.out.println("Figure for InterfaceEditPart is null."); + } + } + }); + } + } + + private void createRedBorder(final AdvancedScrollingGraphicalViewer viewer, final Rectangle bounds) { + final int padding = 2; + + // Top line with padding + final Polyline topLine = new Polyline(); + topLine.addPoint(new Point(bounds.x - padding, bounds.y - padding)); // Apply padding + topLine.addPoint(new Point(bounds.x + bounds.width + padding, bounds.y - padding)); // Apply padding + topLine.setForegroundColor(ColorConstants.red); + topLine.setLineWidth(2); // Thicker line width + + // Bottom line with padding + final Polyline bottomLine = new Polyline(); + bottomLine.addPoint(new Point(bounds.x - padding, bounds.y + bounds.height + padding)); // Apply padding + bottomLine.addPoint(new Point(bounds.x + bounds.width + padding, bounds.y + bounds.height + padding)); // Apply + // padding + bottomLine.setForegroundColor(ColorConstants.red); + bottomLine.setLineWidth(2); // Thicker line width + + // Left line with padding + final Polyline leftLine = new Polyline(); + leftLine.addPoint(new Point(bounds.x - padding, bounds.y - padding)); // Apply padding + leftLine.addPoint(new Point(bounds.x - padding, bounds.y + bounds.height + padding)); // Apply padding + leftLine.setForegroundColor(ColorConstants.red); + leftLine.setLineWidth(2); // Thicker line width + + // Right line with padding + final Polyline rightLine = new Polyline(); + rightLine.addPoint(new Point(bounds.x + bounds.width + padding, bounds.y - padding)); // Apply padding + rightLine.addPoint(new Point(bounds.x + bounds.width + padding, bounds.y + bounds.height + padding)); // Apply + // padding + rightLine.setForegroundColor(ColorConstants.red); + rightLine.setLineWidth(2); // Thicker line width + + // Add the lines to the canvas (drawing layer) + final FigureCanvas canvas = (FigureCanvas) viewer.getControl(); + if (canvas != null) { + canvas.getContents().add(topLine); + canvas.getContents().add(bottomLine); + canvas.getContents().add(leftLine); + canvas.getContents().add(rightLine); + } + } + } \ No newline at end of file From 162b850afab21a6f93672f8d04ddcbb513248374 Mon Sep 17 00:00:00 2001 From: Terra Date: Wed, 8 Jan 2025 10:46:30 +0100 Subject: [PATCH 20/22] Some cleanup --- .../previews/ProjectChangePreviewViewer.java | 48 +++++----------- .../InterfaceDataTypeChangePreviewViewer.java | 56 +++++-------------- 2 files changed, 28 insertions(+), 76 deletions(-) diff --git a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/applications/previews/ProjectChangePreviewViewer.java b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/applications/previews/ProjectChangePreviewViewer.java index 8ceb5707bb..a9ee771514 100644 --- a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/applications/previews/ProjectChangePreviewViewer.java +++ b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/applications/previews/ProjectChangePreviewViewer.java @@ -52,7 +52,6 @@ public class ProjectChangePreviewViewer implements IChangePreviewViewer { public void createControl(final Composite parent) { System.out.println("Creating Project Change preview control"); - // Ensure parent layout is set correctly parent.setLayout(new GridLayout(1, false)); this.parent = parent; @@ -122,37 +121,31 @@ public void doSave(final IProgressMonitor monitor) { private void resetGraphicalViewer(final AdvancedScrollingGraphicalViewer viewer) { if (viewer != null) { - // Clear previous contents, remove listeners, and reinitialize - viewer.setContents(null); // Ensure we clear the current contents + viewer.setContents(null); if (viewer.getControl() != null) { - viewer.getControl().setRedraw(false); // Disable redraw during reset to avoid flicker - viewer.getControl().dispose(); // Dispose the old canvas/control if necessary + viewer.getControl().setRedraw(false); + viewer.getControl().dispose(); } } } private void drawRedRectangleForElement(final AdvancedScrollingGraphicalViewer viewer, final FBNetworkElement fb) { if (viewer != null && fb != null) { - // Get the edit part for the FBNetworkElement final EditPart editPart = viewer.getEditPartRegistry().get(fb); if (editPart != null) { - // Get the figure for the edit part (this represents the visual element) final IFigure figure = ((AbstractGraphicalEditPart) editPart).getFigure(); if (figure != null) { // Ensure layout is complete before accessing bounds viewer.getControl().getDisplay().asyncExec(() -> { - // Now, access the bounds after ensuring the figure is laid out final Rectangle bounds = figure.getBounds(); System.out.println("Figure bounds (local): " + bounds.x + ", " + bounds.y); - // Translate to absolute coordinates figure.translateToAbsolute(bounds); System.out.println("Figure bounds (absolute): " + bounds.x + ", " + bounds.y); createRedBorder(viewer, bounds); - // Add the red rectangle to the canvas (drawing layer) final FigureCanvas canvas = (FigureCanvas) viewer.getControl(); if (canvas != null) { @@ -161,11 +154,7 @@ private void drawRedRectangleForElement(final AdvancedScrollingGraphicalViewer v } }); - } else { - System.out.println("Figure for edit part is null."); } - } else { - System.out.println("EditPart for FBNetworkElement is null."); } } } @@ -173,37 +162,30 @@ private void drawRedRectangleForElement(final AdvancedScrollingGraphicalViewer v private void createRedBorder(final AdvancedScrollingGraphicalViewer viewer, final Rectangle bounds) { final int padding = 5; - // Top line with padding final Polyline topLine = new Polyline(); - topLine.addPoint(new Point(bounds.x - padding, bounds.y - padding)); // Apply padding - topLine.addPoint(new Point(bounds.x + bounds.width + padding, bounds.y - padding)); // Apply padding + topLine.addPoint(new Point(bounds.x - padding, bounds.y - padding)); + topLine.addPoint(new Point(bounds.x + bounds.width + padding, bounds.y - padding)); topLine.setForegroundColor(ColorConstants.red); - topLine.setLineWidth(2); // Thicker line width + topLine.setLineWidth(2); - // Bottom line with padding final Polyline bottomLine = new Polyline(); - bottomLine.addPoint(new Point(bounds.x - padding, bounds.y + bounds.height + padding)); // Apply padding - bottomLine.addPoint(new Point(bounds.x + bounds.width + padding, bounds.y + bounds.height + padding)); // Apply - // padding + bottomLine.addPoint(new Point(bounds.x - padding, bounds.y + bounds.height + padding)); + bottomLine.addPoint(new Point(bounds.x + bounds.width + padding, bounds.y + bounds.height + padding)); bottomLine.setForegroundColor(ColorConstants.red); - bottomLine.setLineWidth(2); // Thicker line width + bottomLine.setLineWidth(2); - // Left line with padding final Polyline leftLine = new Polyline(); - leftLine.addPoint(new Point(bounds.x - padding, bounds.y - padding)); // Apply padding - leftLine.addPoint(new Point(bounds.x - padding, bounds.y + bounds.height + padding)); // Apply padding + leftLine.addPoint(new Point(bounds.x - padding, bounds.y - padding)); + leftLine.addPoint(new Point(bounds.x - padding, bounds.y + bounds.height + padding)); leftLine.setForegroundColor(ColorConstants.red); - leftLine.setLineWidth(2); // Thicker line width + leftLine.setLineWidth(2); - // Right line with padding final Polyline rightLine = new Polyline(); - rightLine.addPoint(new Point(bounds.x + bounds.width + padding, bounds.y - padding)); // Apply padding - rightLine.addPoint(new Point(bounds.x + bounds.width + padding, bounds.y + bounds.height + padding)); // Apply - // padding + rightLine.addPoint(new Point(bounds.x + bounds.width + padding, bounds.y - padding)); + rightLine.addPoint(new Point(bounds.x + bounds.width + padding, bounds.y + bounds.height + padding)); rightLine.setForegroundColor(ColorConstants.red); - rightLine.setLineWidth(2); // Thicker line width + rightLine.setLineWidth(2); - // Add the lines to the canvas (drawing layer) final FigureCanvas canvas = (FigureCanvas) viewer.getControl(); if (canvas != null) { canvas.getContents().add(topLine); diff --git a/plugins/org.eclipse.fordiac.ide.fbtypeeditor/src/org/eclipse/fordiac/ide/fbtypeeditor/previews/InterfaceDataTypeChangePreviewViewer.java b/plugins/org.eclipse.fordiac.ide.fbtypeeditor/src/org/eclipse/fordiac/ide/fbtypeeditor/previews/InterfaceDataTypeChangePreviewViewer.java index 2ba02a6632..0640173af9 100644 --- a/plugins/org.eclipse.fordiac.ide.fbtypeeditor/src/org/eclipse/fordiac/ide/fbtypeeditor/previews/InterfaceDataTypeChangePreviewViewer.java +++ b/plugins/org.eclipse.fordiac.ide.fbtypeeditor/src/org/eclipse/fordiac/ide/fbtypeeditor/previews/InterfaceDataTypeChangePreviewViewer.java @@ -51,7 +51,6 @@ public class InterfaceDataTypeChangePreviewViewer implements IChangePreviewViewe @Override public void createControl(final Composite parent) { - // Ensure parent layout is set correctly parent.setLayout(new GridLayout(1, false)); this.parent = parent; @@ -67,7 +66,6 @@ private void resetControl() { control = new SashForm(parent, SWT.VERTICAL); control.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - // Left Composite final Composite compl = new Composite(control, SWT.NONE); compl.setLayout(new GridLayout()); final Label labell = new Label(compl, SWT.NONE); @@ -76,7 +74,6 @@ private void resetControl() { graphicalViewerLeft.createControl(compl); graphicalViewerLeft.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - // Right Composite final Composite compr = new Composite(control, SWT.NONE); compr.setLayout(new GridLayout()); final Label labelr = new Label(compr, SWT.NONE); @@ -85,7 +82,6 @@ private void resetControl() { graphicalViewerRight.createControl(compr); graphicalViewerRight.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - // Force parent layout parent.layout(true, true); } @@ -159,8 +155,6 @@ public void doSave(final IProgressMonitor monitor) { gEditPartL.setLayoutConstraint(gEditPartL.getChildren().get(0), gEditPartL.getChildren().get(0).getFigure(), new Rectangle(400, 50, -1, -1)); - // todo remove grid - drawRedRectangleForElement(graphicalViewerLeft, oldTypeEntry.getTypeName()); } @@ -200,43 +194,26 @@ private void synchronizeScrolling(final AdvancedScrollingGraphicalViewer source, private void drawRedRectangleForElement(final AdvancedScrollingGraphicalViewer viewer, final String originalTypeName) { if (viewer != null) { - // Iterate over all entries in the EditPartRegistry viewer.getEditPartRegistry().forEach((key, val) -> { - // Check if the EditPart is an instance of InterfaceEditPart - // Check if the InterfaceEditPart's model matches the originalTypeName if ((val instanceof final InterfaceEditPart part) && part.getCastedModel().getFullTypeName().equals(originalTypeName)) { - // We found a matching InterfaceEditPart System.out.println("Found matching InterfaceEditPart: " + originalTypeName); - // Get the corresponding figure for the EditPart final IFigure figure = part.getFigure(); if (figure != null) { // Ensure layout is complete before accessing bounds viewer.getControl().getDisplay().asyncExec(() -> { - // Access the bounds after ensuring the figure is laid out final Rectangle bounds = figure.getBounds(); - System.out.println("Figure bounds (local): " + bounds.x + ", " + bounds.y); - - // Translate the bounds to absolute coordinates figure.translateToAbsolute(bounds); - System.out.println("Figure bounds (absolute): " + bounds.x + ", " + bounds.y); - // Create the red border around the figure createRedBorder(viewer, bounds); - // Add the red border to the canvas (drawing layer) final FigureCanvas canvas = (FigureCanvas) viewer.getControl(); if (canvas != null) { - // Optionally scroll the canvas to the position of the element - System.out.println("Scroll to " + bounds.x + "X and " + bounds.y + "Y"); - canvas.scrollTo(bounds.x - 10, bounds.y - 10); // Adding a small offset to make sure - // it's visible + canvas.scrollTo(bounds.x - 10, bounds.y - 10); } }); - } else { - System.out.println("Figure for InterfaceEditPart is null."); } } }); @@ -246,37 +223,30 @@ private void drawRedRectangleForElement(final AdvancedScrollingGraphicalViewer v private void createRedBorder(final AdvancedScrollingGraphicalViewer viewer, final Rectangle bounds) { final int padding = 2; - // Top line with padding final Polyline topLine = new Polyline(); - topLine.addPoint(new Point(bounds.x - padding, bounds.y - padding)); // Apply padding - topLine.addPoint(new Point(bounds.x + bounds.width + padding, bounds.y - padding)); // Apply padding + topLine.addPoint(new Point(bounds.x - padding, bounds.y - padding)); + topLine.addPoint(new Point(bounds.x + bounds.width + padding, bounds.y - padding)); topLine.setForegroundColor(ColorConstants.red); - topLine.setLineWidth(2); // Thicker line width + topLine.setLineWidth(2); - // Bottom line with padding final Polyline bottomLine = new Polyline(); - bottomLine.addPoint(new Point(bounds.x - padding, bounds.y + bounds.height + padding)); // Apply padding - bottomLine.addPoint(new Point(bounds.x + bounds.width + padding, bounds.y + bounds.height + padding)); // Apply - // padding + bottomLine.addPoint(new Point(bounds.x - padding, bounds.y + bounds.height + padding)); + bottomLine.addPoint(new Point(bounds.x + bounds.width + padding, bounds.y + bounds.height + padding)); bottomLine.setForegroundColor(ColorConstants.red); - bottomLine.setLineWidth(2); // Thicker line width + bottomLine.setLineWidth(2); - // Left line with padding final Polyline leftLine = new Polyline(); - leftLine.addPoint(new Point(bounds.x - padding, bounds.y - padding)); // Apply padding - leftLine.addPoint(new Point(bounds.x - padding, bounds.y + bounds.height + padding)); // Apply padding + leftLine.addPoint(new Point(bounds.x - padding, bounds.y - padding)); + leftLine.addPoint(new Point(bounds.x - padding, bounds.y + bounds.height + padding)); leftLine.setForegroundColor(ColorConstants.red); - leftLine.setLineWidth(2); // Thicker line width + leftLine.setLineWidth(2); - // Right line with padding final Polyline rightLine = new Polyline(); - rightLine.addPoint(new Point(bounds.x + bounds.width + padding, bounds.y - padding)); // Apply padding - rightLine.addPoint(new Point(bounds.x + bounds.width + padding, bounds.y + bounds.height + padding)); // Apply - // padding + rightLine.addPoint(new Point(bounds.x + bounds.width + padding, bounds.y - padding)); + rightLine.addPoint(new Point(bounds.x + bounds.width + padding, bounds.y + bounds.height + padding)); rightLine.setForegroundColor(ColorConstants.red); - rightLine.setLineWidth(2); // Thicker line width + rightLine.setLineWidth(2); - // Add the lines to the canvas (drawing layer) final FigureCanvas canvas = (FigureCanvas) viewer.getControl(); if (canvas != null) { canvas.getContents().add(topLine); From 6c11a1ff160b190508ce8533fb445e19128ec247 Mon Sep 17 00:00:00 2001 From: Terra Date: Wed, 8 Jan 2025 10:47:51 +0100 Subject: [PATCH 21/22] Some more cleanup --- .../applications/previews/ProjectChangePreviewViewer.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/applications/previews/ProjectChangePreviewViewer.java b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/applications/previews/ProjectChangePreviewViewer.java index a9ee771514..99516b32f6 100644 --- a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/applications/previews/ProjectChangePreviewViewer.java +++ b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/applications/previews/ProjectChangePreviewViewer.java @@ -50,8 +50,6 @@ public class ProjectChangePreviewViewer implements IChangePreviewViewer { @Override public void createControl(final Composite parent) { - System.out.println("Creating Project Change preview control"); - parent.setLayout(new GridLayout(1, false)); this.parent = parent; @@ -83,8 +81,6 @@ public Control getControl() { @Override public void setInput(final ChangePreviewViewerInput input) { - - System.out.println("Creating Project Change preview input"); if (!(input.getChange() instanceof UpdateInstancesChange)) { return; } @@ -139,17 +135,13 @@ private void drawRedRectangleForElement(final AdvancedScrollingGraphicalViewer v // Ensure layout is complete before accessing bounds viewer.getControl().getDisplay().asyncExec(() -> { final Rectangle bounds = figure.getBounds(); - System.out.println("Figure bounds (local): " + bounds.x + ", " + bounds.y); figure.translateToAbsolute(bounds); - System.out.println("Figure bounds (absolute): " + bounds.x + ", " + bounds.y); createRedBorder(viewer, bounds); final FigureCanvas canvas = (FigureCanvas) viewer.getControl(); if (canvas != null) { - - System.out.println("Scroll to " + bounds.x + "X and " + bounds.y + "Y"); canvas.scrollTo(bounds.x - 10, bounds.y - 10); } From e0b62106dbbbfa3e77c2701a43db22d4d0585bf1 Mon Sep 17 00:00:00 2001 From: Terra Date: Wed, 8 Jan 2025 10:48:07 +0100 Subject: [PATCH 22/22] Even more cleanup --- .../previews/InterfaceDataTypeChangePreviewViewer.java | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/org.eclipse.fordiac.ide.fbtypeeditor/src/org/eclipse/fordiac/ide/fbtypeeditor/previews/InterfaceDataTypeChangePreviewViewer.java b/plugins/org.eclipse.fordiac.ide.fbtypeeditor/src/org/eclipse/fordiac/ide/fbtypeeditor/previews/InterfaceDataTypeChangePreviewViewer.java index 0640173af9..e286a9449d 100644 --- a/plugins/org.eclipse.fordiac.ide.fbtypeeditor/src/org/eclipse/fordiac/ide/fbtypeeditor/previews/InterfaceDataTypeChangePreviewViewer.java +++ b/plugins/org.eclipse.fordiac.ide.fbtypeeditor/src/org/eclipse/fordiac/ide/fbtypeeditor/previews/InterfaceDataTypeChangePreviewViewer.java @@ -198,7 +198,6 @@ private void drawRedRectangleForElement(final AdvancedScrollingGraphicalViewer v if ((val instanceof final InterfaceEditPart part) && part.getCastedModel().getFullTypeName().equals(originalTypeName)) { - System.out.println("Found matching InterfaceEditPart: " + originalTypeName); final IFigure figure = part.getFigure(); if (figure != null) {