Editing a Label: set the selection when press F2 [message #508398] |
Mon, 18 January 2010 16:22 |
|
Hi!
I like to know if it's possible to set the selection of a Label when pressing F2 to the Label Edit Part.
For instance, an Operation from UML2 that shows the Visibility, the Name, the Type... I want to select by default only the Name when I was in editing mode (but showing all the other data!)
I think it's task for the Manager of the EditPart. I use the following manager:
protected DirectEditManager getManager() {
if (manager == null) {
setManager(new OperationsTextDirectEditManager(this, OperationsTextDirectEditManager
.getTextCellEditorClass(this), UMLEditPartFactory
.getTextCellEditorLocator(this)));
}
return manager;
}
And I modify the setEditText function in my OperationsTextDirectEditManager to modify the selection:
public void setEditText(String toEdit) {
super.setEditText(toEdit);
// Set the controls text and position the caret at the end of the text
setSelection(toEdit);
}
public void setSelection(String toEdit) {
Operation op = (Operation) ((IGraphicalEditPart) getEditPart()) .resolveSemanticElement();
String name = op.getName();
int x = toEdit.indexOf(name);
int y = x + name.length() - 1;
Point point = new Point(x, y);
((Text) getCellEditor().getControl()).setSelection(point);
}
But when I enter in editing mode, it selects all the String... Can anybody helps me please?
Marc Gil
|
|
|
Re: Editing a Label: set the selection when press F2 [message #508485 is a reply to message #508398] |
Tue, 19 January 2010 07:35 |
|
I get it.
Modifying in my class the method show() inherited from DirectEditManager, calling the super method and then doing the selection of the text I want to be selected by default:
@Override
public void show() {
super.show();
// Set the controls text and position the caret at the end of the text
setSelection();
}
public void setSelection() {
// Get the Text Compartments Edit Part and the text to be shown
ITextAwareEditPart textEP = (ITextAwareEditPart) getEditPart();
String toEdit = textEP.getEditText();
// Get the UML2 NamedElement element and the name
NamedElement ne = (NamedElement) ((IGraphicalEditPart) getEditPart())
.resolveSemanticElement();
String name = ne.getName();
// calculate the position of the name
int x = toEdit.indexOf(name);
int y = x + name.length();
Point point = new Point(x, y);
// set the selection
((Text) getCellEditor().getControl()).setSelection(point);
}
Thanks
Marc
[Updated on: Tue, 19 January 2010 07:42] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03976 seconds