1 11 12 package org.eclipse.jface.internal.text.link.contentassist; 13 14 15 import org.eclipse.swt.events.SelectionEvent; 16 import org.eclipse.swt.events.SelectionListener; 17 import org.eclipse.swt.graphics.Point; 18 import org.eclipse.swt.graphics.Rectangle; 19 import org.eclipse.swt.widgets.Control; 20 import org.eclipse.swt.widgets.Table; 21 import org.eclipse.swt.widgets.TableItem; 22 23 import org.eclipse.core.runtime.Assert; 24 25 import org.eclipse.jface.text.AbstractInformationControlManager; 26 import org.eclipse.jface.text.IInformationControl; 27 import org.eclipse.jface.text.IInformationControlCreator; 28 import org.eclipse.jface.text.contentassist.ICompletionProposal; 29 import org.eclipse.jface.text.contentassist.ICompletionProposalExtension3; 30 31 32 33 38 class AdditionalInfoController2 extends AbstractInformationControlManager implements Runnable { 39 40 43 private class TableSelectionListener implements SelectionListener { 44 45 48 public void widgetSelected(SelectionEvent e) { 49 handleTableSelectionChanged(); 50 } 51 52 55 public void widgetDefaultSelected(SelectionEvent e) { 56 } 57 } 58 59 60 61 private Table fProposalTable; 62 63 private Thread fThread; 64 65 private boolean fIsReset= false; 66 67 private final Object fMutex= new Object (); 68 69 private final Object fThreadAccess= new Object (); 70 71 private Object fStartSignal; 72 73 private SelectionListener fSelectionListener= new TableSelectionListener(); 74 75 private int fDelay; 76 77 78 84 AdditionalInfoController2(IInformationControlCreator creator, int delay) { 85 super(creator); 86 fDelay= delay; 87 setAnchor(ANCHOR_RIGHT); 88 setFallbackAnchors(new Anchor[] {ANCHOR_RIGHT, ANCHOR_LEFT, ANCHOR_BOTTOM }); 89 } 90 91 94 public void install(Control control) { 95 96 if (fProposalTable == control) { 97 return; 99 } 100 101 super.install(control); 102 103 Assert.isTrue(control instanceof Table); 104 fProposalTable= (Table) control; 105 fProposalTable.addSelectionListener(fSelectionListener); 106 synchronized (fThreadAccess) { 107 if (fThread != null) 108 fThread.interrupt(); 109 fThread= new Thread (this, ContentAssistMessages.getString("InfoPopup.info_delay_timer_name")); 111 fStartSignal= new Object (); 112 synchronized (fStartSignal) { 113 fThread.start(); 114 try { 115 fStartSignal.wait(); 117 } catch (InterruptedException x) { 118 } 119 } 120 } 121 } 122 123 126 public void disposeInformationControl() { 127 128 synchronized (fThreadAccess) { 129 if (fThread != null) { 130 fThread.interrupt(); 131 fThread= null; 132 } 133 } 134 135 if (fProposalTable != null && !fProposalTable.isDisposed()) { 136 fProposalTable.removeSelectionListener(fSelectionListener); 137 fProposalTable= null; 138 } 139 140 super.disposeInformationControl(); 141 } 142 143 146 public void run() { 147 try { 148 while (true) { 149 150 synchronized (fMutex) { 151 152 if (fStartSignal != null) { 153 synchronized (fStartSignal) { 154 fStartSignal.notifyAll(); 155 fStartSignal= null; 156 } 157 } 158 159 fMutex.wait(); 161 162 while (true) { 163 fIsReset= false; 164 fMutex.wait(fDelay); 166 if (!fIsReset) 167 break; 168 } 169 } 170 171 if (fProposalTable != null && !fProposalTable.isDisposed()) { 172 fProposalTable.getDisplay().asyncExec(new Runnable () { 173 public void run() { 174 if (!fIsReset) 175 showInformation(); 176 } 177 }); 178 } 179 180 } 181 } catch (InterruptedException e) { 182 } 183 184 synchronized (fThreadAccess) { 185 if (Thread.currentThread() == fThread) 187 fThread= null; 188 } 189 } 190 191 194 public void handleTableSelectionChanged() { 195 196 if (fProposalTable != null && !fProposalTable.isDisposed() && fProposalTable.isVisible()) { 197 synchronized (fMutex) { 198 fIsReset= true; 199 fMutex.notifyAll(); 200 } 201 } 202 } 203 204 207 protected void computeInformation() { 208 209 if (fProposalTable == null || fProposalTable.isDisposed()) 210 return; 211 212 TableItem[] selection= fProposalTable.getSelection(); 213 if (selection != null && selection.length > 0) { 214 215 TableItem item= selection[0]; 216 217 String information= null; 219 Object d= item.getData(); 220 221 if (d instanceof ICompletionProposal) { 222 ICompletionProposal p= (ICompletionProposal) d; 223 information= p.getAdditionalProposalInfo(); 224 } 225 226 if (d instanceof ICompletionProposalExtension3) 227 setCustomInformationControlCreator(((ICompletionProposalExtension3) d).getInformationControlCreator()); 228 else 229 setCustomInformationControlCreator(null); 230 231 setMargins(4, -1); 233 Rectangle area= fProposalTable.getBounds(); 234 area.x= 0; area.y= 0; 236 237 setInformation(information, area); 239 } 240 } 241 242 245 protected Point computeSizeConstraints(Control subjectControl, IInformationControl informationControl) { 246 Point sizeConstraint= super.computeSizeConstraints(subjectControl, informationControl); 247 Point size= subjectControl.getSize(); 248 if (sizeConstraint.x < size.x) 249 sizeConstraint.x= size.x; 250 if (sizeConstraint.y < size.y) 251 sizeConstraint.y= size.y; 252 return sizeConstraint; 253 } 254 } 255 256 257 | Popular Tags |