Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 73958 Details for
Bug 196685
[Schema][Editors] New element and attribute name generation creates duplicates
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
patch
patch196685.txt (text/plain), 9.44 KB, created by
Adam Archer
on 2007-07-17 11:56:36 EDT
(
hide
)
Description:
patch
Filename:
MIME Type:
Creator:
Adam Archer
Created:
2007-07-17 11:56:36 EDT
Size:
9.44 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.pde.ui >Index: src/org/eclipse/pde/internal/ui/util/PDELabelUtility.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/util/PDELabelUtility.java,v >retrieving revision 1.3 >diff -u -r1.3 PDELabelUtility.java >--- src/org/eclipse/pde/internal/ui/util/PDELabelUtility.java 25 Jun 2007 20:48:16 -0000 1.3 >+++ src/org/eclipse/pde/internal/ui/util/PDELabelUtility.java 17 Jul 2007 15:44:47 -0000 >@@ -96,7 +96,7 @@ > * @param base > * @param set > */ >- private static void addNumberToBase(StringBuffer base, HashSet set) { >+ private static void addNumberToBase(StringBuffer base, boolean bracketed, HashSet set) { > if (set.size() > 0) { > // Limit on the number of auto-generated item numbers to check for > int limit = 100; >@@ -109,9 +109,11 @@ > // Check if the number was already used to auto-generate an > // existing item > if (set.contains(new Integer(x)) == false) { >- base.append(" ("); //$NON-NLS-1$ >+ if (bracketed) >+ base.append(" ("); //$NON-NLS-1$ > base.append(x); >- base.append(")"); //$NON-NLS-1$ >+ if (bracketed) >+ base.append(")"); //$NON-NLS-1$ > break; > } > } >@@ -124,34 +126,60 @@ > * @param set > * @param title > */ >- private static void compareTitleWithBase(String base, HashSet set, String title) { >- // Check to see it the name starts with the base >+ private static void compareTitleWithBase(String base, boolean bracketed, HashSet set, String title) { >+ // Check to see it the name starts with the prefix > if (title.startsWith(base)) { >- // space, (, number, ) >- int minSizeNumAddOn = 4; >+ // with brackets add on is: space, (, #, ) >+ int minSizeNumAddOn = 4; >+ if (!bracketed) >+ // without brackets and space add on is just number >+ minSizeNumAddOn = 1; > // We found a possible auto-generated name > // Determine number > if (title.length() >= (base.length() + minSizeNumAddOn)) { >- // We skipped the space >- String numPart = title.substring(base.length() + 1); >+ String numPart; >+ if (bracketed && title.charAt(base.length()) == ' ') { >+ // We skipped the space since we already checked >+ numPart = title.substring(base.length() + 1); >+ } else if (!bracketed) { >+ // without brackets, the numPart is everything after the prefix >+ numPart = title.substring(base.length()); >+ } else { >+ // We are using brackets and there was no space >+ return; >+ } >+ if (bracketed) { >+ if (numPart.charAt(0) == '(') { >+ // We are using brackets and confirmed that the open bracket exists >+ // move on to just the number part >+ numPart = numPart.substring(1); >+ } >+ else { >+ // We are using brackets and there is no opening bracket >+ return; >+ } >+ } > // We found an auto-generated name >- if (numPart.charAt(0) == '(') { >- StringBuffer buffer = new StringBuffer(); >- // Parse the number between the brackets >- for (int j = 1; j < numPart.length(); j++) { >- char current = numPart.charAt(j); >- // Make sure its a digit >- if (Character.isDigit(current)) { >- buffer.append(current); >- } else { >- // Break on non digits including ')' >- break; >+ StringBuffer buffer = new StringBuffer(); >+ // Parse the number between the brackets >+ for (int j = 0; j < numPart.length(); j++) { >+ char current = numPart.charAt(j); >+ // Make sure its a digit >+ if (Character.isDigit(current)) { >+ buffer.append(current); >+ } else { >+ if (!bracketed || numPart.charAt(j) != ')' || j != numPart.length() - 1) { >+ // without brackets, a non digits means this will not conflict >+ // with brackets, anything other than a ')' means this will not conflict >+ // with brackets, if this is not the last character it will not conflict >+ return; > } >+ // if all conditions passed, this is the last loop, no need to break > } >- // Convert the number we found into an actual number >- if (buffer.length() > 0) { >- set.add(new Integer(buffer.toString())); >- } >+ } >+ // Convert the number we found into an actual number >+ if (buffer.length() > 0) { >+ set.add(new Integer(buffer.toString())); > } > > } else { >@@ -166,6 +194,24 @@ > * @return > */ > public static String generateName(String[] names, String base) { >+ return generateName(names, base, true); >+ } >+ >+ /** >+ * <p>Generates a name that does not conflict with any of the given names with one of two forms: >+ * <ol><li>"<base> (#)"</li><li>"<base>#"</li></ol> >+ * The number will be omitted if the base name alone is available.</p> >+ * >+ * @param names >+ * the existing names that should not be conflicted >+ * @param base >+ * the base name to add numbers to >+ * @param bracketed >+ * if true use the first form, otherwise use the second >+ * @return >+ * the non-conflicting name >+ */ >+ public static String generateName(String[] names, String base, boolean bracketed){ > StringBuffer result = new StringBuffer(base); > // Used to track auto-generated numbers used > HashSet set = new HashSet(); >@@ -174,11 +220,12 @@ > // Performance hit unnoticeable because number of items per cheatsheet > // should be minimal. > for (int i = 0; i < names.length; i++) { >- PDELabelUtility.compareTitleWithBase(base, set, names[i]); >+ PDELabelUtility.compareTitleWithBase(base, bracketed, set, names[i]); > } > // Add an auto-generated number >- PDELabelUtility.addNumberToBase(result, set); >+ PDELabelUtility.addNumberToBase(result, bracketed, set); > > return result.toString(); >+ > } > } >Index: src/org/eclipse/pde/internal/ui/pderesources.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties,v >retrieving revision 1.888 >diff -u -r1.888 pderesources.properties >--- src/org/eclipse/pde/internal/ui/pderesources.properties 17 Jul 2007 13:50:43 -0000 1.888 >+++ src/org/eclipse/pde/internal/ui/pderesources.properties 17 Jul 2007 15:44:47 -0000 >@@ -395,7 +395,7 @@ > SchemaElementDetails_description= Properties for the "{0}" element. > SchemaEditor_NewElement_tooltip = New Global Element > SchemaIncludesSection_addButton=Add... >-SchemaEditor_NewElement_initialName = new_element{0} >+SchemaEditor_NewElement_initialName = new_element > SchemaIncludesSection_dialogMessage=Select an extension point schema file: > SchemaIncludesSection_missingWarningTitle=Missing Schema Include > SchemaIncludesSection_missingWarningMessage={0} could not be found. >Index: src/org/eclipse/pde/internal/ui/editor/schema/NewElementAction.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/NewElementAction.java,v >retrieving revision 1.13 >diff -u -r1.13 NewElementAction.java >--- src/org/eclipse/pde/internal/ui/editor/schema/NewElementAction.java 3 Apr 2006 19:47:22 -0000 1.13 >+++ src/org/eclipse/pde/internal/ui/editor/schema/NewElementAction.java 17 Jul 2007 15:44:47 -0000 >@@ -10,37 +10,35 @@ > *******************************************************************************/ > package org.eclipse.pde.internal.ui.editor.schema; > >-import java.util.Hashtable; >- > import org.eclipse.jface.action.Action; >-import org.eclipse.osgi.util.NLS; > import org.eclipse.pde.internal.core.ischema.ISchema; >+import org.eclipse.pde.internal.core.ischema.ISchemaElement; > import org.eclipse.pde.internal.core.schema.Schema; > import org.eclipse.pde.internal.core.schema.SchemaElement; > import org.eclipse.pde.internal.core.schema.SchemaRootElement; > import org.eclipse.pde.internal.core.schema.SchemaSimpleType; >-import org.eclipse.pde.internal.ui.PDEPlugin; > import org.eclipse.pde.internal.ui.PDEPluginImages; > import org.eclipse.pde.internal.ui.PDEUIMessages; >+import org.eclipse.pde.internal.ui.util.PDELabelUtility; > > public class NewElementAction extends Action { > private Schema schema; >- private static final String NAME_COUNTER_KEY = "__schema_element_name"; //$NON-NLS-1$ > public NewElementAction() { > setText(PDEUIMessages.SchemaEditor_NewElement_label); > setImageDescriptor(PDEPluginImages.DESC_GEL_SC_OBJ); > setToolTipText(PDEUIMessages.SchemaEditor_NewElement_tooltip); > } > private String getInitialName() { >- Hashtable counters = PDEPlugin.getDefault().getDefaultNameCounters(); >- Integer counter = (Integer) counters.get(NAME_COUNTER_KEY); >- if (counter == null) { >- counter = new Integer(1); >- } else { >- counter = new Integer(counter.intValue() + 1); >- } >- counters.put(NAME_COUNTER_KEY, counter); >- return NLS.bind(PDEUIMessages.SchemaEditor_NewElement_initialName, counter.intValue() + ""); //$NON-NLS-1$ >+ return PDELabelUtility.generateName(getElementNames(), PDEUIMessages.SchemaEditor_NewElement_initialName, false); >+ } >+ private String[] getElementNames() { >+ if (schema == null) >+ return new String[0]; >+ ISchemaElement[] elements = schema.getElements(); >+ String[] names = new String[elements.length]; >+ for (int i = 0; i < elements.length; i++) >+ names[i] = elements[i].getName(); >+ return names; > } > public org.eclipse.pde.internal.core.schema.Schema getSchema() { > return schema;
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
mike.pawlowski
:
review+
Actions:
View
|
Diff
Attachments on
bug 196685
: 73958 |
74108