Home » Eclipse Projects » Rich Client Platform (RCP) » Text field and Text editor
Text field and Text editor [message #665817] |
Sat, 16 April 2011 12:52 |
spcmdr 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 #666054 is a reply to message #666044] |
Mon, 18 April 2011 19:26 |
spcmdr 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.
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 |
|
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
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
|
|
|
Re: Text field and Text editor [message #666233 is a reply to message #666174] |
Tue, 19 April 2011 14:27 |
spcmdr 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
|
|
| |
Goto Forum:
Current Time: Sat Oct 19 15:40:23 GMT 2024
Powered by FUDForum. Page generated in 0.04159 seconds
|