Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlorenzo2013-03-27 10:27:10 +0000
committervlorenzo2013-03-27 10:27:10 +0000
commit10c1072c7fe3b481dc5a2f6ed32e554c6b1d5352 (patch)
treed464003c270781ddbfbc654778f0c09fac18d979
parent3125a3774ac7c83981415139fb2a151bac98f5bb (diff)
downloadorg.eclipse.papyrus-10c1072c7fe3b481dc5a2f6ed32e554c6b1d5352.tar.gz
org.eclipse.papyrus-10c1072c7fe3b481dc5a2f6ed32e554c6b1d5352.tar.xz
org.eclipse.papyrus-10c1072c7fe3b481dc5a2f6ed32e554c6b1d5352.zip
404430: [Table 2] The default name of the table must be incremented
https://bugs.eclipse.org/bugs/show_bug.cgi?id=404430
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/EditorNameInitializer.java81
1 files changed, 81 insertions, 0 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/EditorNameInitializer.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/EditorNameInitializer.java
new file mode 100644
index 00000000000..d50b0724c4c
--- /dev/null
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/utils/EditorNameInitializer.java
@@ -0,0 +1,81 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.utils;
+
+import java.util.Collection;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.EStructuralFeature.Setting;
+import org.eclipse.emf.ecore.util.ECrossReferenceAdapter;
+
+/**
+ *
+ * This class provides useful method to get an unused name for a new editor
+ *
+ */
+public class EditorNameInitializer {
+
+ private EditorNameInitializer() {
+ //to prenvent instanciation
+ }
+
+ /**
+ *
+ * @param editorModelEClass
+ * the eclass of the model of the editor
+ * @param nameFeature
+ * the feature name
+ * @param wantedNameWithoutIndex
+ * the wantedname for the new editor
+ * @param context
+ * the context of the editor
+ * @return
+ * the name for this editor
+ */
+ public static final String getNameWithIncrement(final EClass editorModelEClass, final EStructuralFeature nameFeature, final String wantedNameWithoutIndex, final EObject context) {
+ //a set of the existing index for the wantedName
+ final SortedSet<Integer> existingIndex = new TreeSet<Integer>();
+ final ECrossReferenceAdapter crossRef = ECrossReferenceAdapter.getCrossReferenceAdapter(context);
+ final Collection<Setting> crossReference = crossRef.getNonNavigableInverseReferences(context, true);
+ for(final Setting set : crossReference) {
+ final EObject eobject = set.getEObject();
+ if(eobject.eClass() == editorModelEClass) {
+ if(nameFeature != null) {
+ final Object currentName = eobject.eGet(nameFeature);
+ if(currentName instanceof String) {
+ final String aName = (String)currentName;
+ if(aName.contains(wantedNameWithoutIndex)) {
+ final String lastChar = aName.substring(aName.length() - 1, aName.length());
+ try {
+ final Integer value = Integer.parseInt(lastChar);
+ existingIndex.add(value);
+ } catch (final Exception e) {
+ //nothing to do
+ }
+ }
+ }
+ }
+ }
+ }
+ int index = 0;
+ if(!existingIndex.isEmpty()) {
+ index = existingIndex.last().intValue() + 1;
+ }
+ return wantedNameWithoutIndex + String.valueOf(index);
+ }
+}

Back to the top