Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Editing a Label: set the selection when press F2
icon9.gif  Editing a Label: set the selection when press F2 [message #508398] Mon, 18 January 2010 16:22 Go to next message
Marc Mising name is currently offline Marc Mising nameFriend
Messages: 193
Registered: July 2009
Location: Valencia, Spain
Senior Member
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 Go to previous message
Marc Mising name is currently offline Marc Mising nameFriend
Messages: 193
Registered: July 2009
Location: Valencia, Spain
Senior Member
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 Wink
Marc

[Updated on: Tue, 19 January 2010 07:42]

Report message to a moderator

Previous Topic:Refresh error decoration with live validation
Next Topic:Set selection on focus an element
Goto Forum:
  


Current Time: Mon Apr 19 13:56:04 GMT 2021

Powered by FUDForum. Page generated in 0.01515 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top