Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Text field and Text editor
icon5.gif  Text field and Text editor [message #665817] Sat, 16 April 2011 12:52 Go to next message
spcmdr is currently offline spcmdrFriend
Messages: 15
Registered: January 2011
Junior Member
Hi

I created a custom text editor.
In that text editor I overrided the « createPartControl » method to add a text field at the bottom of the text editor.

The text field display is fine but it does not work properly.
The home and end key does not work o the text field.
The copy paste works only with the menu.

How to solve this behavior?

I just need my composite to have two text field, the main textfield with coloring, completion and the other one a basic textfiel.

Here is my code

@Override
public void createPartControl(Composite parent)
{
	Composite composite = new Composite(parent, SWT.NONE);
	composite.setLayout(new GridLayout(2, false));
	
	Composite textComposite = new Composite(composite, SWT.BORDER);
	textComposite.setLayoutData(GridDataFactory.swtDefaults().grab(true, true).span(2, 1).align(SWT.FILL, SWT.FILL).create());
	textComposite.setLayout(new FillLayout());
	
	super.createPartControl(textComposite);
	
	Label label = new Label(composite, SWT.NONE);
	label.setText("label");
	label.setLayoutData(new GridData());
	
	Text text = new Text(composite, SWT.BORDER);
	text.setLayoutData(GridDataFactory.swtDefaults().grab(true, false).align(SWT.FILL, SWT.BEGINNING).create());
	text.setText(getTemplateDocumentProvider().getOutput());
}


Regards
Re: Text field and Text editor [message #665965 is a reply to message #665817] Mon, 18 April 2011 11:32 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

The workbench only differentiates down to the Part level. If you need
to manage 2 text fields, you'll have to do the work yourself.

Have a look at IFocusService, which allows you to specify a condition
that your extra text field has focus. Then you simply need to provide
handlers that work against that text field for any keybinding/commands
you wish to override.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Re: Text field and Text editor [message #666035 is a reply to message #665965] Mon, 18 April 2011 17:31 Go to previous messageGo to next message
spcmdr is currently offline spcmdrFriend
Messages: 15
Registered: January 2011
Junior Member
Hi

Thank you for your response but it does not help at all.

The IFocusService has one implementation FocusControlSourceProvider with is used in the Workbench.
I don't see the relation between IFocusService and TextEditor.

I have a focus problem on my text field but I don't know how to manage the focus between the text field and the text editor.

Regards
Re: Text field and Text editor [message #666044 is a reply to message #666035] Mon, 18 April 2011 17:58 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

On 04/18/2011 01:31 PM, spcmdr@yahoo.fr wrote:
> Hi
>
> Thank you for your response but it does not help at all.
>
> The IFocusService has one implementation FocusControlSourceProvider with
> is used in the Workbench.
> I don't see the relation between IFocusService and TextEditor.


IFocusService allows you to identify your text field to the framework
(by giving it a unique ID). The javadoc even gives an example of how to
then provide cut/copy/paste/selectAll for your text field, via a handler
definition in your plugin.xml. The control ID can be used when
programmically activating handlers in your editor subclass as well (by
including the correct Expression.

See fields like org.eclipse.ui.IWorkbenchCommandConstants.EDIT_CUT for
the command IDs associated with cut/copy/paste etc

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Re: Text field and Text editor [message #666054 is a reply to message #666044] Mon, 18 April 2011 19:26 Go to previous messageGo to next message
spcmdr is currently offline spcmdrFriend
Messages: 15
Registered: January 2011
Junior Member
Hi

I think you misunderstood what I am trying to do.
Here is a screenshot of my editor.

http://donopi.com/editor.png

There are a text field and a text editor.

The text field is a normal swt Text.
For some reason when I use that code (notice the commented line)
The home (place the cursor at the text start) and end (place the cursor at the text end) key works. I can use copy pas with the keyboard.

@Override
public void createPartControl(Composite parent)
{
	Composite composite = new Composite(parent, SWT.NONE);
	composite.setLayout(new GridLayout(2, false));
	
	Composite textComposite = new Composite(composite, SWT.BORDER);
	textComposite.setLayoutData(GridDataFactory.swtDefaults().grab(true, true).span(2, 1).align(SWT.FILL, SWT.FILL).create());
	textComposite.setLayout(new FillLayout());
	
	//super.createPartControl(textComposite);
	
	Label label = new Label(composite, SWT.NONE);
	label.setText("label");
	label.setLayoutData(new GridData());
	
	Text text = new Text(composite, SWT.BORDER);
	text.setLayoutData(GridDataFactory.swtDefaults().grab(true, false).align(SWT.FILL, SWT.BEGINNING).create());
	text.setText(getTemplateDocumentProvider().getOutput());
}



When the super.createPartControl(textComposite); is call the text field behavior change.
I can no more use begin and end, copy and paste work no more.

@Override
public void createPartControl(Composite parent)
{
	Composite composite = new Composite(parent, SWT.NONE);
	composite.setLayout(new GridLayout(2, false));
	
	Composite textComposite = new Composite(composite, SWT.BORDER);
	textComposite.setLayoutData(GridDataFactory.swtDefaults().grab(true, true).span(2, 1).align(SWT.FILL, SWT.FILL).create());
	textComposite.setLayout(new FillLayout());
	
	super.createPartControl(textComposite);
	
	Label label = new Label(composite, SWT.NONE);
	label.setText("label");
	label.setLayoutData(new GridData());
	
	Text text = new Text(composite, SWT.BORDER);
	text.setLayoutData(GridDataFactory.swtDefaults().grab(true, false).align(SWT.FILL, SWT.BEGINNING).create());
	text.setText(getTemplateDocumentProvider().getOutput());
}


Regards
Re: Text field and Text editor [message #666174 is a reply to message #666054] Tue, 19 April 2011 11:52 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

On 04/18/2011 03:27 PM, spcmdr@yahoo.fr wrote:
> Hi
>
> I think you misunderstood what I am trying to do.
> Here is a screenshot of my editor.

yes, I understood the problem. The text editor registers keybindings
and handlers for Home/End/Copy/Paste, etc. Therefore, your text field
will not react to those keys. Text editor is a complete workbench part
by itself. If you want to extend it and add another control that can
take focus, you'll have to mediate between the superclass text editor,
your text control, and the workbench (using commands and handlers).

You have 2 choices. 1) use the IFocusService and then provide handlers
for each of the commands that you want to work. Text Editor defines
many movements (like home/end) as commands as well, so you'll have to
provide something for each movement that was turned into a command that
you want.

2) Don't use Text Editor, use a TextViewer or SourceViewer in your
createPartControl(*) Then you control the entire setup of your editor.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


icon7.gif  Re: Text field and Text editor [message #666233 is a reply to message #666174] Tue, 19 April 2011 14:27 Go to previous messageGo to next message
spcmdr is currently offline spcmdrFriend
Messages: 15
Registered: January 2011
Junior Member
Hi Mr. Webster

Thank you very much for your help.

I skill have problem:

  • I have a warning is my plugin.xml: Access to referenced class 'org.eclipse.ui.internal.handlers.WidgetMethodHandler' in attribute 'class' is Discouraged
  • What is the key for home and end to place in org.eclipse.ui.internal.handlers.WidgetMethodHandler:paste, org.eclipse.ui.edit.paste


Here is my solution at this time.

public class MyEditor extends TextEditor implements IFocusService
{
	@Override
	public void createPartControl(Composite parent)
	{
		Composite composite = new Composite(parent, SWT.NONE);
		composite.setLayout(new GridLayout(2, false));
		
		Composite textComposite = new Composite(composite, SWT.BORDER);
		textComposite.setLayoutData(GridDataFactory.swtDefaults().grab(true, true).span(2, 1).align(SWT.FILL, SWT.FILL).create());
		textComposite.setLayout(new FillLayout());
		
		super.createPartControl(textComposite);
		
		Label label = new Label(composite, SWT.NONE);
		label.setText("label");
		label.setLayoutData(new GridData());
		
		Text text = new Text(composite, SWT.BORDER);
		text.setLayoutData(GridDataFactory.swtDefaults().grab(true, false).align(SWT.FILL, SWT.BEGINNING).create());
		text.setText(getTemplateDocumentProvider().getOutput());

		addFocusTracker(outputText, "outputText");
	}
	
	@Override
	public void dispose()
	{
		removeFocusTracker(outputText);
		super.dispose();
	}
	
	@Override
	public void addFocusTracker(Control control, String id)
	{
		IFocusService focusService = (IFocusService) getSite().getService(IFocusService.class);
		focusService.addFocusTracker(control, id);
	}
	
	@Override
	public void removeFocusTracker(Control control)
	{
		IFocusService focusService = (IFocusService) getSite().getService(IFocusService.class);
		focusService.removeFocusTracker(control);
	}
}


<extension point="org.eclipse.ui.handlers">
	<handler class="org.eclipse.ui.internal.handlers.WidgetMethodHandler:cut" commandId="org.eclipse.ui.edit.cut">
		<activeWhen>
			<with variable="activeFocusControlId">
				<equals value="outputText"/>
			</with>
		</activeWhen>
	</handler>
	<handler class="org.eclipse.ui.internal.handlers.WidgetMethodHandler:copy" commandId="org.eclipse.ui.edit.copy">
		<activeWhen>
			<with variable="activeFocusControlId">
				<equals value="outputText"/>
			</with>
		</activeWhen>
	</handler>
	<handler class="org.eclipse.ui.internal.handlers.WidgetMethodHandler:paste" commandId="org.eclipse.ui.edit.paste">
		<activeWhen>
			<with variable="activeFocusControlId">
				<equals value="outputText"/>
			</with>
		</activeWhen>
	</handler>
</extension>


Regards
Re: Text field and Text editor [message #666254 is a reply to message #666233] Tue, 19 April 2011 15:50 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

On 04/19/2011 10:27 AM, spcmdr@yahoo.fr wrote:
> I have a warning is my plugin.xml: Access to referenced class
> 'org.eclipse.ui.internal.handlers.WidgetMethodHandler' in attribute
> 'class' is Discouraged
> What is the key for home and end to place in
> org.eclipse.ui.internal.handlers.WidgetMethodHandler:paste,
> org.eclipse.ui.edit.paste

That's not a problem, just a warning. It's acceptable, however, that's
why we published those strings as API in IFocusService.

You don't have to remove the focus control in your dispose() if that
control is about to be disposed, although it won't hurt.


Home is commandId org.eclipse.ui.edit.text.goto.lineStart See
org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm


Previous Topic:DirectoryDialog initial directory
Next Topic:JVM terminated.Exit code=-2147483647
Goto Forum:
  


Current Time: Sat Apr 20 03:31:55 GMT 2024

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

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

Back to the top