Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 184720 Details for
Bug 332027
auto completing anonymous inner type duplicates (almost) whole class - code assist
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
java source
AssistErrDemo.java (text/plain), 3.09 KB, created by
pengcheng
on 2010-12-07 09:53:02 EST
(
hide
)
Description:
java source
Filename:
MIME Type:
Creator:
pengcheng
Created:
2010-12-07 09:53:02 EST
Size:
3.09 KB
patch
obsolete
>package swt.text; > >import org.eclipse.swt.SWT; >import org.eclipse.swt.graphics.Rectangle; >import org.eclipse.swt.layout.FillLayout; >import org.eclipse.swt.layout.GridData; >import org.eclipse.swt.layout.GridLayout; >import org.eclipse.swt.widgets.Display; >import org.eclipse.swt.widgets.Event; >import org.eclipse.swt.widgets.Listener; >import org.eclipse.swt.widgets.Shell; >import org.eclipse.swt.widgets.Table; >import org.eclipse.swt.widgets.TableItem; >import org.eclipse.swt.widgets.Text; > >public class AssistErrDemo { > > private Text text; > private Provider provider; > private Shell popup; > private Table table; > > public AssistErrDemo(final Text text, Provider provider) { > if(provider == null) > throw new NullPointerException("provider is null"); > > this.text = text; > this.provider = provider; > text.addListener(SWT.KeyDown, new Listener() { > public void handleEvent(Event event) { > switch(event.keyCode) { > case SWT.ESC : > hide(); > break; > case SWT.CR : > if(isVisible() && table.getSelectionIndex() != -1) { > text.setText(table.getSelection()[0].getText()); > hide(); > } > break; > default : > show(); > > > } // switch > } > }); > text.getShell().addListener(SWT.Move, new Listener() { > public void handleEvent(Event event) { > hide(); > } > }); > } > > public void show() { > if(popup == null) { > init(); > } > if( ! popup.isVisible() ) { > Rectangle textBounds = text.getDisplay().map(text.getShell(), null, text.getBounds()); > popup.setBounds(textBounds.x, textBounds.y + textBounds.height, textBounds.width, 150); > popup.setVisible(true); > } > } > > public void hide() { > if(popup != null) > popup.setVisible(false); > } > > public boolean isVisible() { > return popup != null && popup.isVisible(); > } > > private void init() { > popup = new Shell(text.getDisplay(), SWT.ON_TOP); > popup.setLayout(new FillLayout()); > table = new Table(popup, SWT.SINGLE); > popup.addListener(SWT.Show, new Listener() { > private String last = null; > public void handleEvent(Event event) { > String s = text.getText(); > if(! s.equals(last)) { > last = s; > table.removeAll(); > String[] as = provider.assist(s, 10); > for(int i=0, len=(as == null ? 0 : as.length); i<len; i++) { > new TableItem(table, SWT.None).setText(as[i]); > } > table.select(0); > } > } > }); > } > > //----------- Provider > > public static interface Provider { > > String[] assist(String str, int size); > > } // Provider > > > public static void main(String[] args) { > Display display = new Display(); > Shell shell = new Shell(display); > shell.setLayout(new GridLayout()); > Text text = new Text(shell, SWT.SINGLE | SWT.BORDER); > text.setLayoutData(new GridData(150, SWT.DEFAULT)); > shell.pack(); > shell.open(); > > new AssistErrDemo(text, null); >// new AssistErrDemo(text, new Provider(< auto completion here causes duplication >)); > > while (!shell.isDisposed()) { > if (!display.readAndDispatch()) display.sleep(); > } > display.dispose(); > } > >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 332027
: 184720 |
184721