Bug 442108 - Add methods to set or clear selection for FormText
Summary: Add methods to set or clear selection for FormText
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: User Assistance (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Platform-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: bugday, helpwanted
Depends on:
Blocks:
 
Reported: 2014-08-19 15:26 EDT by Adam Briska CLA
Modified: 2015-11-13 17:17 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Briska CLA 2014-08-19 15:26:11 EDT
Currently, in a FormText object, it is possible to programmatically get the selection.

I would like to also be able to set or clear the selection.
Comment 1 Eclipse Genie CLA 2015-11-13 17:11:54 EST
New Gerrit change created: https://git.eclipse.org/r/60383
Comment 2 daniel jaeger CLA 2015-11-13 17:17:00 EST
Bug 442108 - Implemented clearSelectionText Method to clear the selection programmatically. A method to programmatically set the selection has not yet been implemented.

This change was not properly tested but I successfully use the new method for the intended purpose with the code below:

/**
	* main method for testing and documentation purposes.
	*
	* @param args
	*/
	public static void main(String[] args) throws Exception {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setSize(300, 300);
		shell.setLayout(new FillLayout());
		FormText t = new FormText(shell, SWT.NONE);
		t.setText("<content>HUBBAHUBBA</content>", true, false);
		Button btn = new Button(shell, SWT.PUSH);
		btn.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
		btn.setText("Print Selection");
		btn.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				System.out.println(t.getSelectionText());
			}
		});
		Button btnClear = new Button(t, SWT.PUSH);
		btnClear.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
		btnClear.setText("Clear Selection");
		btnClear.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				t.clearSelection();
			}
		});

		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		display.dispose();
	}