Bug 196685 - [Schema][Editors] New element and attribute name generation creates duplicates
Summary: [Schema][Editors] New element and attribute name generation creates duplicates
Status: RESOLVED FIXED
Alias: None
Product: PDE
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.4 M1   Edit
Assignee: Adam Archer CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2007-07-16 13:21 EDT by Mike Pawlowski CLA
Modified: 2007-07-19 11:58 EDT (History)
1 user (show)

See Also:
mike.pawlowski: review+


Attachments
patch (9.44 KB, patch)
2007-07-17 11:56 EDT, Adam Archer CLA
mike.pawlowski: review+
Details | Diff
additional patch (5.65 KB, patch)
2007-07-18 22:42 EDT, Adam Archer CLA
mike.pawlowski: review+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Pawlowski CLA 2007-07-16 13:21:46 EDT
Steps To Reproduce:

(1) Launch a new runtime Eclipse workbench
(2) Create an extension point schema
(3) Create a new element
    -> Auto-generated name is "new_element1"
(4) Create another new element
    -> Auto-generated name is "new_element2"
(5) Create another new element
    -> Auto-generated name is "new_element3"
(6) Rename "new_element3" to "new_element5"
(7) Close and relaunch the runtime Eclipse workbench
(8) Open the extension point schema created earlier
(9) Create 5 new elements
    -> BUG:  "new_element1", "new_element2", "new_element3", 
             "new_element4", "new_element5"  created
    -> This is bad since element names are used as IDs
    -> Duplicate element names are now 'linked' in a very bad way
    -> EXPECTED:  "new_element", "new_element3", "new_element4", 
                  "new_element6", "new_element7", created

The same problem exists for local attribute objects with the same parent.

Reference for correct behaviour and code:  Simple Cheat Sheet Editor

Noam generalized some code to handle this in:
org.eclipse.pde.internal.ui.util.PDELabelUtility.generateName(String[], String)

Ideally we would want to reuse this; however, it will have to be adapted
or generalized some more to generate "1" instead of " (1)", etc.
Comment 1 Adam Archer CLA 2007-07-17 11:56:36 EDT
Created attachment 73958 [details]
patch

Created a new method, PDELabelUtility.generateName(String[], String, boolean). The boolean parameter (bracketed) controls the style of name to be generated.

if bracketed is true, result is of the form: "<base> (#)"
otherwise, result is of the form: "<base>#"

Changed PDELabelUtility.generateName(String[], String) to simply call the new method with bracketed set to true.

Used the new utility to generate element names in NewElementAction.
Comment 2 Mike Pawlowski CLA 2007-07-17 14:39:19 EDT
Comment on attachment 73958 [details]
patch

Good patch.  Thanks Adam.  However need to implement this for attributes as well ;)
Comment 3 Mike Pawlowski CLA 2007-07-17 14:41:44 EDT
Patch applied to HEAD.

Target:  3.4 M1

Adam, just provide another patch for local attribute objects with the same parent.
Comment 4 Adam Archer CLA 2007-07-17 14:53:48 EDT
Oops! Will do.
Comment 5 Adam Archer CLA 2007-07-18 22:42:08 EDT
Created attachment 74108 [details]
additional patch

Applies the fix to attribute name generation as well.
Comment 6 Mike Pawlowski CLA 2007-07-19 11:57:46 EDT
Comment on attachment 74108 [details]
additional patch

Tested well.  Thanks, Adam.
Comment 7 Mike Pawlowski CLA 2007-07-19 11:58:24 EDT
Patch applied to HEAD.