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
3962c337
Commit
3962c337
authored
8 years ago
by
Sudeep Kanav
Browse files
Options
Downloads
Patches
Plain Diff
distinct names of new component
refs 2572
parent
1a321a72
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.base/trunk/src/org/fortiss/tooling/base/compose/ModelElementCompositorBase.java
+32
-1
32 additions, 1 deletion
...tiss/tooling/base/compose/ModelElementCompositorBase.java
with
32 additions
and
1 deletion
org.fortiss.tooling.base/trunk/src/org/fortiss/tooling/base/compose/ModelElementCompositorBase.java
+
32
−
1
View file @
3962c337
...
...
@@ -20,6 +20,7 @@ package org.fortiss.tooling.base.compose;
import
static
org
.
eclipse
.
emf
.
ecore
.
util
.
EcoreUtil
.
delete
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Observable
;
import
org.eclipse.emf.ecore.EObject
;
...
...
@@ -30,6 +31,7 @@ import org.fortiss.tooling.base.model.element.IModelElementReference;
import
org.fortiss.tooling.base.model.element.IModelElementSpecification
;
import
org.fortiss.tooling.kernel.extension.IElementCompositor
;
import
org.fortiss.tooling.kernel.extension.data.IElementCompositionContext
;
import
org.fortiss.tooling.kernel.model.INamedElement
;
import
org.fortiss.tooling.kernel.service.IElementCompositorService
;
/**
...
...
@@ -39,7 +41,7 @@ import org.fortiss.tooling.kernel.service.IElementCompositorService;
* @author diewald
* @author $Author$
* @version $Rev$
* @ConQAT.Rating
GREEN
Hash:
58F65C328C5D37AA24F7593C34F224F1
* @ConQAT.Rating
YELLOW
Hash:
FB3638BD4FAE190CE22B8C7C89F028AB
*/
public
abstract
class
ModelElementCompositorBase
<
C
extends
EObject
>
extends
Observable
implements
IElementCompositor
<
C
>
{
...
...
@@ -57,6 +59,7 @@ public abstract class ModelElementCompositorBase<C extends EObject> extends Obse
if
(
contained
instanceof
IModelElement
)
{
IAnnotationValueService
.
INSTANCE
.
instantiateAnnotations
((
IModelElement
)
contained
);
}
makeNameDistinct
(
container
,
contained
);
return
true
;
}
...
...
@@ -147,4 +150,32 @@ public abstract class ModelElementCompositorBase<C extends EObject> extends Obse
delete
(
element
,
true
);
return
true
;
}
/**
* This function checks if the name of any element of same type and name as "contained" exists
* in the container, and modifies the name in case if required.
* */
private
void
makeNameDistinct
(
EObject
container
,
EObject
contained
)
{
if
(!(
contained
instanceof
INamedElement
)
||
((
INamedElement
)
contained
).
getName
()
==
null
)
return
;
INamedElement
neNew
=
(
INamedElement
)
contained
;
String
newName
=
((
INamedElement
)
contained
).
getName
();
List
<
String
>
listNames
=
new
ArrayList
<
String
>();
for
(
EObject
o
:
container
.
eContents
())
{
if
(
o
.
getClass
().
isInstance
(
contained
)
&&
o
instanceof
INamedElement
&&
o
!=
contained
)
{
listNames
.
add
(((
INamedElement
)
o
).
getName
());
}
}
if
(!
listNames
.
contains
(
newName
))
{
return
;
}
int
index
=
1
;
while
(
listNames
.
contains
(
newName
+
index
))
index
++;
neNew
.
setName
(
neNew
.
getName
()
+
index
);
}
}
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