Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
kernel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
af3
kernel
Commits
ae5b6f67
Commit
ae5b6f67
authored
9 years ago
by
Johannes Eder
Browse files
Options
Downloads
Patches
Plain Diff
Renaming of pasted elements now works for every INamedElement.
refs 2304
parent
8552a7d3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/util/CopyPasteUtils.java
+50
-1
50 additions, 1 deletion
...rc/org/fortiss/tooling/kernel/ui/util/CopyPasteUtils.java
with
50 additions
and
1 deletion
org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/util/CopyPasteUtils.java
+
50
−
1
View file @
ae5b6f67
...
...
@@ -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: 6
2B147A455CDAFFBB66A1976A53B3EB3
* @ConQAT.Rating YELLOW Hash: 6
0F5B3B933DFFDDF65AEDD03B01FE38C
*/
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
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment