Skip to content
Snippets Groups Projects
Commit ae5b6f67 authored by Johannes Eder's avatar Johannes Eder
Browse files

Renaming of pasted elements now works for every INamedElement.

refs 2304
parent 8552a7d3
No related branches found
No related tags found
No related merge requests found
......@@ -34,6 +34,7 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
import org.fortiss.tooling.kernel.extension.data.IElementCompositionContext;
import org.fortiss.tooling.kernel.model.INamedElement;
import org.fortiss.tooling.kernel.model.ISpeciallyCopyiable;
import org.fortiss.tooling.kernel.service.IElementCompositorService;
import org.fortiss.tooling.kernel.ui.dnd.CompositionServiceLocalCopyPasteTransfer;
......@@ -48,7 +49,7 @@ import org.fortiss.tooling.kernel.ui.internal.editor.ExtendableMultiPageEditor;
*
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 62B147A455CDAFFBB66A1976A53B3EB3
* @ConQAT.Rating YELLOW Hash: 60F5B3B933DFFDDF65AEDD03B01FE38C
*/
public class CopyPasteUtils {
......@@ -116,6 +117,7 @@ public class CopyPasteUtils {
EcoreUtil.Copier copier = new EcoreUtil.Copier();
for(EObject obj : getClipBoardContent()) {
EObject copy = copier.copy(obj);
adaptCopyNames(copy, target);
copier.copyReferences();
IElementCompositorService.INSTANCE.compose(target, copy, context);
}
......@@ -164,4 +166,51 @@ public class CopyPasteUtils {
}
return false;
}
/** Checks the names of all {@link INamedElement}s in the target and adapts the copy's name. */
private static void adaptCopyNames(EObject copy, EObject target) {
if(copy instanceof INamedElement) {
String PREFIX = "Copy of ";
INamedElement namedElement = (INamedElement)copy;
String copyName = namedElement.getName();
int iterator = 0;
for(EObject o : target.eContents()) {
// check class types
if(o.getClass().isInstance(copy) && o instanceof INamedElement) {
INamedElement contained = (INamedElement)o;
String containedName = contained.getName();
// check name and copy count
String pattern2 = "Copy of.*";
if(contained.getName().equals(copyName)) {
iterator++;
} else if(copyName.matches(pattern2) && containedName.matches(pattern2)) {
String initialNameCopy = copyName.split(" ")[2];
String initialNameContained = containedName.split(" ")[2];
if(initialNameCopy.equals(initialNameContained))
iterator++;
} else if(containedName.matches(pattern2)) {
String initialNameContained = containedName.split(" ")[2];
if(copyName.equals(initialNameContained))
iterator++;
} else if(copyName.matches(pattern2)) {
String initialNameCopy = copyName.split(" ")[2];
if(containedName.equals(initialNameCopy))
iterator++;
}
}
}
String newName = copyName;
if(iterator == 1) {
newName = PREFIX + copyName;
} else if(iterator > 1) {
if(copyName.startsWith(PREFIX)) {
String realName = copyName.split(" ")[2];
newName = PREFIX + realName + " (" + iterator + ")";
} else
newName = PREFIX + copyName + " (" + iterator + ")";
}
namedElement.setName(newName);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment