1 /*******************************************************************************
2 * Copyright (c) 2000, 2011 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.internal.ui.dialogs;
13 import java.util.ArrayList;
14 import java.util.Arrays;
15 import java.util.Comparator;
16 import java.util.HashMap;
17 import java.util.HashSet;
18 import java.util.Iterator;
19 import java.util.List;
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.accessibility.AccessibleAdapter;
25 import org.eclipse.swt.accessibility.AccessibleEvent;
26 import org.eclipse.swt.events.ControlAdapter;
27 import org.eclipse.swt.events.ControlEvent;
28 import org.eclipse.swt.events.DisposeEvent;
29 import org.eclipse.swt.events.DisposeListener;
30 import org.eclipse.swt.events.KeyAdapter;
31 import org.eclipse.swt.events.KeyEvent;
32 import org.eclipse.swt.events.KeyListener;
33 import org.eclipse.swt.events.MenuAdapter;
34 import org.eclipse.swt.events.MenuEvent;
35 import org.eclipse.swt.events.ModifyEvent;
36 import org.eclipse.swt.events.ModifyListener;
37 import org.eclipse.swt.events.SelectionAdapter;
38 import org.eclipse.swt.events.SelectionEvent;
39 import org.eclipse.swt.events.TraverseEvent;
40 import org.eclipse.swt.events.TraverseListener;
41 import org.eclipse.swt.graphics.Color;
42 import org.eclipse.swt.graphics.Font;
43 import org.eclipse.swt.graphics.GC;
44 import org.eclipse.swt.graphics.Image;
45 import org.eclipse.swt.graphics.Rectangle;
46 import org.eclipse.swt.layout.GridData;
47 import org.eclipse.swt.widgets.Composite;
48 import org.eclipse.swt.widgets.Display;
49 import org.eclipse.swt.widgets.Event;
50 import org.eclipse.swt.widgets.Label;
51 import org.eclipse.swt.widgets.Listener;
52 import org.eclipse.swt.widgets.Menu;
53 import org.eclipse.swt.widgets.MenuItem;
54 import org.eclipse.swt.widgets.Table;
55 import org.eclipse.swt.widgets.TableItem;
56 import org.eclipse.swt.widgets.Text;
58 import org.eclipse.core.runtime.Assert;
59 import org.eclipse.core.runtime.CoreException;
60 import org.eclipse.core.runtime.IProgressMonitor;
61 import org.eclipse.core.runtime.IStatus;
62 import org.eclipse.core.runtime.OperationCanceledException;
63 import org.eclipse.core.runtime.Platform;
64 import org.eclipse.core.runtime.ProgressMonitorWrapper;
65 import org.eclipse.core.runtime.Status;
66 import org.eclipse.core.runtime.jobs.Job;
68 import org.eclipse.jface.resource.ImageDescriptor;
70 import org.eclipse.ui.progress.UIJob;
72 import org.eclipse.jdt.core.IPackageFragmentRoot;
73 import org.eclipse.jdt.core.JavaModelException;
74 import org.eclipse.jdt.core.WorkingCopyOwner;
75 import org.eclipse.jdt.core.search.IJavaSearchConstants;
76 import org.eclipse.jdt.core.search.IJavaSearchScope;
77 import org.eclipse.jdt.core.search.SearchEngine;
78 import org.eclipse.jdt.core.search.SearchPattern;
79 import org.eclipse.jdt.core.search.TypeNameMatch;
80 import org.eclipse.jdt.core.search.TypeNameMatchRequestor;
81 import org.eclipse.jdt.core.search.TypeNameRequestor;
83 import org.eclipse.jdt.internal.corext.util.Messages;
84 import org.eclipse.jdt.internal.corext.util.OpenTypeHistory;
85 import org.eclipse.jdt.internal.corext.util.Strings;
86 import org.eclipse.jdt.internal.corext.util.TypeFilter;
87 import org.eclipse.jdt.internal.corext.util.TypeInfoFilter;
88 import org.eclipse.jdt.internal.corext.util.TypeInfoRequestorAdapter;
90 import org.eclipse.jdt.launching.IVMInstall;
91 import org.eclipse.jdt.launching.IVMInstallType;
92 import org.eclipse.jdt.launching.JavaRuntime;
93 import org.eclipse.jdt.launching.LibraryLocation;
95 import org.eclipse.jdt.ui.JavaElementLabels;
96 import org.eclipse.jdt.ui.dialogs.ITypeInfoFilterExtension;
97 import org.eclipse.jdt.ui.dialogs.ITypeInfoImageProvider;
99 import org.eclipse.jdt.internal.ui.JavaPlugin;
100 import org.eclipse.jdt.internal.ui.JavaPluginImages;
101 import org.eclipse.jdt.internal.ui.JavaUIMessages;
105 * DO NOT REMOVE, used in a product.
106 * @deprecated As of 3.5, replaced by {@link org.eclipse.ui.dialogs.FilteredItemsSelectionDialog}
108 public class TypeInfoViewer {
110 private static class SearchRequestor extends TypeNameMatchRequestor {
111 private volatile boolean fStop;
113 private Set fHistory;
115 private TypeInfoFilter fFilter;
116 private List fResult;
118 public SearchRequestor(TypeInfoFilter filter) {
120 fResult= new ArrayList(2048);
123 public TypeNameMatch[] getResult() {
124 return (TypeNameMatch[])fResult.toArray(new TypeNameMatch[fResult.size()]);
126 public void cancel() {
129 public void setHistory(Set history) {
134 * @see org.eclipse.jdt.core.search.TypeNameMatchRequestor#acceptTypeNameMatch(org.eclipse.jdt.core.search.TypeNameMatch)
137 public void acceptTypeNameMatch(TypeNameMatch match) {
140 if (TypeFilter.isFiltered(match))
142 if (fHistory.contains(match))
144 if (fFilter.matchesFilterExtension(match))
149 public static class TypeInfoComparator implements Comparator {
150 private TypeInfoLabelProvider fLabelProvider;
151 public TypeInfoFilter fFilter;
152 public TypeInfoComparator(TypeInfoLabelProvider labelProvider, TypeInfoFilter filter) {
153 fLabelProvider= labelProvider;
156 public int compare(Object left, Object right) {
157 TypeNameMatch leftInfo= (TypeNameMatch)left;
158 TypeNameMatch rightInfo= (TypeNameMatch)right;
159 int leftCategory= getCamelCaseCategory(leftInfo);
160 int rightCategory= getCamelCaseCategory(rightInfo);
161 if (leftCategory < rightCategory)
163 if (leftCategory > rightCategory)
165 int result= compareName(leftInfo.getSimpleTypeName(), rightInfo.getSimpleTypeName());
168 result= compareTypeContainerName(leftInfo.getTypeContainerName(), rightInfo.getTypeContainerName());
172 leftCategory= getElementTypeCategory(leftInfo);
173 rightCategory= getElementTypeCategory(rightInfo);
174 if (leftCategory < rightCategory)
176 if (leftCategory > rightCategory)
178 return compareContainerName(leftInfo, rightInfo);
180 private int compareName(String leftString, String rightString) {
181 int result= leftString.compareToIgnoreCase(rightString);
182 if (result != 0 || rightString.length() == 0) {
184 } else if (Strings.isLowerCase(leftString.charAt(0)) &&
185 !Strings.isLowerCase(rightString.charAt(0))) {
187 } else if (Strings.isLowerCase(rightString.charAt(0)) &&
188 !Strings.isLowerCase(leftString.charAt(0))) {
191 return leftString.compareTo(rightString);
194 private int compareTypeContainerName(String leftString, String rightString) {
195 int leftLength= leftString.length();
196 int rightLength= rightString.length();
197 if (leftLength == 0 && rightLength > 0)
199 if (leftLength == 0 && rightLength == 0)
201 if (leftLength > 0 && rightLength == 0)
203 return compareName(leftString, rightString);
205 private int compareContainerName(TypeNameMatch leftType, TypeNameMatch rightType) {
206 return fLabelProvider.generated_4080221774471558952(leftType, rightType);
208 private int getCamelCaseCategory(TypeNameMatch type) {
211 return fFilter.generated_6162093895603037472(type);
213 private int getElementTypeCategory(TypeNameMatch type) {
215 if (type.getPackageFragmentRoot().getKind() == IPackageFragmentRoot.K_SOURCE)
217 } catch (JavaModelException e) {
218 // TODO Auto-generated catch block
225 public static class TypeInfoLabelProvider {
227 public ITypeInfoImageProvider fProviderExtension;
228 public TypeInfoRequestorAdapter fAdapter= new TypeInfoRequestorAdapter();
230 private Map fLib2Name= new HashMap();
231 private String[] fInstallLocations;
232 private String[] fVMNames;
234 private boolean fFullyQualifyDuplicates;
236 public TypeInfoLabelProvider(ITypeInfoImageProvider extension) {
237 fProviderExtension= extension;
238 List locations= new ArrayList();
239 List labels= new ArrayList();
240 IVMInstallType[] installs= JavaRuntime.getVMInstallTypes();
241 for (int i= 0; i < installs.length; i++) {
242 processVMInstallType(installs[i], locations, labels);
244 fInstallLocations= (String[])locations.toArray(new String[locations.size()]);
245 fVMNames= (String[])labels.toArray(new String[labels.size()]);
248 public void setFullyQualifyDuplicates(boolean value) {
249 fFullyQualifyDuplicates= value;
251 private void processVMInstallType(IVMInstallType installType, List locations, List labels) {
252 if (installType != null) {
253 IVMInstall[] installs= installType.getVMInstalls();
254 boolean isMac= Platform.OS_MACOSX.equals(Platform.getOS());
255 final String HOME_SUFFIX= "/Home"; //$NON-NLS-1$
256 for (int i= 0; i < installs.length; i++) {
257 String label= getFormattedLabel(installs[i].getName());
258 LibraryLocation[] libLocations= installs[i].getLibraryLocations();
259 if (libLocations != null) {
260 processLibraryLocation(libLocations, label);
262 String filePath= installs[i].getInstallLocation().getAbsolutePath();
263 // on MacOS X install locations end in an additional "/Home" segment; remove it
264 if (isMac && filePath.endsWith(HOME_SUFFIX))
265 filePath= filePath.substring(0, filePath.length()- HOME_SUFFIX.length() + 1);
266 locations.add(filePath);
272 private void processLibraryLocation(LibraryLocation[] libLocations, String label) {
273 for (int l= 0; l < libLocations.length; l++) {
274 LibraryLocation location= libLocations[l];
275 fLib2Name.put(location.getSystemLibraryPath().toString(), label);
278 private String getFormattedLabel(String name) {
279 return Messages.format(JavaUIMessages.TypeInfoViewer_library_name_format, name);
281 public String getText(Object element) {
282 return ((TypeNameMatch)element).getSimpleTypeName();
284 public String getQualifiedText(TypeNameMatch type) {
285 StringBuffer result= new StringBuffer();
286 result.append(type.getSimpleTypeName());
287 String containerName= type.getTypeContainerName();
288 result.append(JavaElementLabels.CONCAT_STRING);
289 if (containerName.length() > 0) {
290 result.append(containerName);
292 result.append(JavaUIMessages.TypeInfoViewer_default_package);
294 return result.toString();
296 public String getFullyQualifiedText(TypeNameMatch type) {
297 StringBuffer result= new StringBuffer();
298 result.append(type.getSimpleTypeName());
299 String containerName= type.getTypeContainerName();
300 if (containerName.length() > 0) {
301 result.append(JavaElementLabels.CONCAT_STRING);
302 result.append(containerName);
304 result.append(JavaElementLabels.CONCAT_STRING);
305 result.append(getContainerName(type));
306 return result.toString();
308 public String getText(TypeNameMatch last, TypeNameMatch current, TypeNameMatch next) {
309 StringBuffer result= new StringBuffer();
310 int qualifications= 0;
311 String currentTN= current.getSimpleTypeName();
312 result.append(currentTN);
313 String currentTCN= getTypeContainerName(current);
315 String lastTN= last.getSimpleTypeName();
316 String lastTCN= getTypeContainerName(last);
317 if (currentTCN.equals(lastTCN)) {
318 if (currentTN.equals(lastTN)) {
319 result.append(JavaElementLabels.CONCAT_STRING);
320 result.append(currentTCN);
321 result.append(JavaElementLabels.CONCAT_STRING);
322 result.append(getContainerName(current));
323 return result.toString();
325 } else if (currentTN.equals(lastTN)) {
330 String nextTN= next.getSimpleTypeName();
331 String nextTCN= getTypeContainerName(next);
332 if (currentTCN.equals(nextTCN)) {
333 if (currentTN.equals(nextTN)) {
334 result.append(JavaElementLabels.CONCAT_STRING);
335 result.append(currentTCN);
336 result.append(JavaElementLabels.CONCAT_STRING);
337 result.append(getContainerName(current));
338 return result.toString();
340 } else if (currentTN.equals(nextTN)) {
344 if (qualifications > 0) {
345 result.append(JavaElementLabels.CONCAT_STRING);
346 result.append(currentTCN);
347 if (fFullyQualifyDuplicates) {
348 result.append(JavaElementLabels.CONCAT_STRING);
349 result.append(getContainerName(current));
352 return result.toString();
354 public String getQualificationText(TypeNameMatch type) {
355 StringBuffer result= new StringBuffer();
356 String containerName= type.getTypeContainerName();
357 if (containerName.length() > 0) {
358 result.append(containerName);
359 result.append(JavaElementLabels.CONCAT_STRING);
361 result.append(getContainerName(type));
362 return result.toString();
365 public boolean isInnerType(TypeNameMatch match) {
366 return match.getTypeQualifiedName().indexOf('.') != -1;
369 public ImageDescriptor getImageDescriptor(Object element) {
370 TypeNameMatch type= (TypeNameMatch)element;
371 return fAdapter.generated_6686271377108945784(this, type);
373 private String getTypeContainerName(TypeNameMatch info) {
374 String result= info.getTypeContainerName();
375 if (result.length() > 0)
377 return JavaUIMessages.TypeInfoViewer_default_package;
380 String getContainerName(TypeNameMatch type) {
381 IPackageFragmentRoot root= type.getPackageFragmentRoot();
382 if (root.isExternal()) {
383 String name= root.getPath().toOSString();
384 for (int i= 0; i < fInstallLocations.length; i++) {
385 if (name.startsWith(fInstallLocations[i])) {
389 String lib= (String)fLib2Name.get(name);
393 StringBuffer buf= new StringBuffer();
394 JavaElementLabels.getPackageFragmentRootLabel(root, JavaElementLabels.ROOT_QUALIFIED | JavaElementLabels.ROOT_VARIABLE, buf);
395 return buf.toString();
397 public void generated_7293536804022995861(TypeInfoViewer typeinfoviewer, TableItem item, int index, TypeNameMatch type) {
399 item.setImage(typeinfoviewer.fImageManager.get(getImageDescriptor(type)));
400 item.setText(getText(
401 typeinfoviewer.getTypeInfo(index - 1),
403 typeinfoviewer.getTypeInfo(index + 1)));
404 item.setForeground(null);
406 public String generated_7876537592558312876(TypeInfoViewer typeinfoviewer, TypeNameMatch type) {
407 return typeinfoviewer.fFullyQualifySelection
408 ? getFullyQualifiedText(type)
409 : getQualifiedText(type);
411 public int generated_4080221774471558952(TypeNameMatch leftType, TypeNameMatch rightType) {
412 return getContainerName(leftType).compareTo(
413 getContainerName(rightType));
415 public void generated_5565475567477228589(TypeNameMatch last, TypeNameMatch type, TypeNameMatch next, List imageDescriptors, List labels) {
416 imageDescriptors.add(getImageDescriptor(type));
417 labels.add(getText(last, type, next));
421 private static class ProgressUpdateJob extends UIJob {
422 private TypeInfoViewer fViewer;
423 private boolean fStopped;
424 public ProgressUpdateJob(Display display, TypeInfoViewer viewer) {
425 super(display, JavaUIMessages.TypeInfoViewer_progressJob_label);
433 public IStatus runInUIThread(IProgressMonitor monitor) {
435 return new Status(IStatus.CANCEL, JavaPlugin.getPluginId(), IStatus.CANCEL, "", null); //$NON-NLS-1$
436 fViewer.updateProgressMessage();
439 return new Status(IStatus.OK, JavaPlugin.getPluginId(), IStatus.OK, "", null); //$NON-NLS-1$
441 private boolean stopped() {
442 return fStopped || fViewer.getTable().isDisposed();
446 public static class ProgressMonitor extends ProgressMonitorWrapper {
447 private TypeInfoViewer fViewer;
448 private String fName;
449 private int fTotalWork;
450 private double fWorked;
451 private boolean fDone;
453 public ProgressMonitor(IProgressMonitor monitor, TypeInfoViewer viewer) {
458 public void setTaskName(String name) {
459 super.setTaskName(name);
463 public void beginTask(String name, int totalWork) {
464 super.beginTask(name, totalWork);
467 fTotalWork= totalWork;
470 public void worked(int work) {
472 internalWorked(work);
477 fViewer.setProgressMessage(""); //$NON-NLS-1$
481 public void internalWorked(double work) {
482 fWorked= fWorked + work;
483 fViewer.setProgressMessage(getMessage());
485 private String getMessage() {
487 return ""; //$NON-NLS-1$
488 } else if (fTotalWork == 0) {
491 return Messages.format(
492 JavaUIMessages.TypeInfoViewer_progress_label,
493 new Object[] { fName, new Integer((int)((fWorked * 100) / fTotalWork)) });
496 public void generated_4483633629445221987(AbstractSearchJob abstractsearchjob) throws CoreException, InterruptedException {
497 if (TypeInfoViewer.VIRTUAL) {
498 abstractsearchjob.internalRunVirtual(this);
500 abstractsearchjob.internalRun(this);
503 public void generated_5068716864496295402() throws JavaModelException {
504 setTaskName(JavaUIMessages.TypeInfoViewer_syncJob_taskName);
505 new SearchEngine().searchAllTypeNames(
508 // make sure we search a concrete name. This is faster according to Kent
509 "_______________".toCharArray(), //$NON-NLS-1$
510 SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE,
511 IJavaSearchConstants.ENUM,
512 SearchEngine.createWorkspaceScope(),
513 new TypeNameRequestor() {},
514 IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
519 private static abstract class AbstractJob extends Job {
520 protected TypeInfoViewer fViewer;
521 protected AbstractJob(String name, TypeInfoViewer viewer) {
527 protected final IStatus run(IProgressMonitor parent) {
528 ProgressMonitor monitor= new ProgressMonitor(parent, fViewer);
530 fViewer.scheduleProgressUpdateJob();
531 return doRun(monitor);
533 fViewer.stopProgressUpdateJob();
536 protected abstract IStatus doRun(ProgressMonitor monitor);
539 public static abstract class AbstractSearchJob extends AbstractJob {
542 protected int fTicket;
543 public TypeInfoLabelProvider fLabelProvider;
545 public TypeInfoFilter fFilter;
546 protected OpenTypeHistory fHistory;
548 protected AbstractSearchJob(int ticket, TypeInfoViewer viewer, TypeInfoFilter filter, OpenTypeHistory history, int numberOfVisibleItems, int mode) {
549 super(JavaUIMessages.TypeInfoViewer_job_label, viewer);
553 fLabelProvider= fViewer.getLabelProvider();
561 protected IStatus doRun(ProgressMonitor monitor) {
563 monitor.generated_4483633629445221987(AbstractSearchJob.this);
564 } catch (CoreException e) {
565 fViewer.searchJobFailed(fTicket, e);
566 return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.ERROR, JavaUIMessages.TypeInfoViewer_job_error, e);
567 } catch (InterruptedException e) {
568 return canceled(e, true);
569 } catch (OperationCanceledException e) {
570 return canceled(e, false);
572 fViewer.searchJobDone(fTicket);
575 protected abstract TypeNameMatch[] getSearchResult(Set matchIdsInHistory, ProgressMonitor monitor) throws CoreException;
577 void internalRun(ProgressMonitor monitor) throws CoreException, InterruptedException {
578 if (monitor.isCanceled())
579 throw new OperationCanceledException();
581 fViewer.clear(fTicket);
583 // local vars to speed up rendering
584 TypeNameMatch last= null;
585 TypeNameMatch type= null;
586 TypeNameMatch next= null;
587 List elements= new ArrayList();
588 List imageDescriptors= new ArrayList();
589 List labels= new ArrayList();
590 Set filteredMatches= new HashSet();
592 TypeNameMatch[] matchingTypes= fHistory.getFilteredTypeInfos(fFilter);
593 if (matchingTypes.length > 0) {
594 Arrays.sort(matchingTypes, new TypeInfoComparator(fLabelProvider, fFilter));
595 type= matchingTypes[0];
597 while(type != null) {
598 next= (i == matchingTypes.length) ? null : matchingTypes[i];
600 filteredMatches.add(type);
601 fLabelProvider.generated_5565475567477228589(last, type, next, imageDescriptors, labels);
608 fViewer.fExpectedItemCount= elements.size();
609 fViewer.addHistory(fTicket, elements, imageDescriptors, labels);
611 if ((fMode & INDEX) == 0) {
614 TypeNameMatch[] result= getSearchResult(filteredMatches, monitor);
615 fViewer.fExpectedItemCount+= result.length;
616 if (result.length == 0) {
619 if (monitor.isCanceled())
620 throw new OperationCanceledException();
624 if (!filteredMatches.isEmpty()) {
625 fViewer.addDashLineAndUpdateLastHistoryEntry(fTicket, type);
628 long startTime= System.currentTimeMillis();
630 imageDescriptors.clear();
632 int delta = Math.min(nextIndex == 1 ? fViewer.getNumberOfVisibleItems() : 10, result.length - processed);
635 processed= processed + delta;
637 next= (nextIndex == result.length) ? null : result[nextIndex];
639 labels.add(fLabelProvider.getText(last, type, next));
640 imageDescriptors.add(fLabelProvider.getImageDescriptor(type));
646 fViewer.addAll(fTicket, elements, imageDescriptors, labels);
647 long sleep= 100 - (System.currentTimeMillis() - startTime);
652 if (monitor.isCanceled())
653 throw new OperationCanceledException();
656 void internalRunVirtual(ProgressMonitor monitor) throws CoreException, InterruptedException {
657 if (monitor.isCanceled())
658 throw new OperationCanceledException();
660 fViewer.clear(fTicket);
662 TypeNameMatch[] matchingTypes= fHistory.getFilteredTypeInfos(fFilter);
663 fViewer.setHistoryResult(fTicket, matchingTypes);
664 if ((fMode & INDEX) == 0)
667 Set filteredMatches= new HashSet(matchingTypes.length * 2);
668 for (int i= 0; i < matchingTypes.length; i++) {
669 filteredMatches.add(matchingTypes[i]);
672 TypeNameMatch[] result= getSearchResult(filteredMatches, monitor);
673 if (monitor.isCanceled())
674 throw new OperationCanceledException();
676 fViewer.setSearchResult(fTicket, result);
678 private IStatus canceled(Exception e, boolean removePendingItems) {
679 fViewer.searchJobCanceled(fTicket, removePendingItems);
680 return new Status(IStatus.CANCEL, JavaPlugin.getPluginId(), IStatus.CANCEL, JavaUIMessages.TypeInfoViewer_job_cancel, e);
682 private IStatus ok() {
683 return new Status(IStatus.OK, JavaPlugin.getPluginId(), IStatus.OK, "", null); //$NON-NLS-1$
687 public static class SearchEngineJob extends AbstractSearchJob {
688 public IJavaSearchScope fScope;
689 public int fElementKind;
690 public SearchRequestor fReqestor;
692 public SearchEngineJob(int ticket, TypeInfoViewer viewer, TypeInfoFilter filter, OpenTypeHistory history, int numberOfVisibleItems, int mode,
693 IJavaSearchScope scope, int elementKind) {
694 super(ticket, viewer, filter, history, numberOfVisibleItems, mode);
696 fElementKind= elementKind;
697 fReqestor= new SearchRequestor(filter);
705 protected TypeNameMatch[] getSearchResult(Set matchIdsInHistory, ProgressMonitor monitor) throws CoreException {
706 long start= System.currentTimeMillis();
707 fReqestor.setHistory(matchIdsInHistory);
708 // consider primary working copies during searching
709 SearchEngine engine= new SearchEngine((WorkingCopyOwner)null);
710 String packPattern= fFilter.getPackagePattern();
711 monitor.setTaskName(JavaUIMessages.TypeInfoViewer_searchJob_taskName);
712 fFilter.generated_2887788459050990176(this, monitor, engine, packPattern);
714 System.out.println("Time needed until search has finished: " + (System.currentTimeMillis() - start)); //$NON-NLS-1$
715 TypeNameMatch[] result= fReqestor.getResult();
716 Arrays.sort(result, new TypeInfoComparator(fLabelProvider, fFilter));
718 System.out.println("Time needed until sort has finished: " + (System.currentTimeMillis() - start)); //$NON-NLS-1$
719 fViewer.rememberResult(fTicket, result);
724 public static class CachedResultJob extends AbstractSearchJob {
725 public TypeNameMatch[] fLastResult;
726 public CachedResultJob(int ticket, TypeNameMatch[] lastResult, TypeInfoViewer viewer, TypeInfoFilter filter, OpenTypeHistory history, int numberOfVisibleItems, int mode) {
727 super(ticket, viewer, filter, history, numberOfVisibleItems, mode);
728 fLastResult= lastResult;
731 protected TypeNameMatch[] getSearchResult(Set filteredHistory, ProgressMonitor monitor) throws CoreException {
732 return fFilter.generated_395777301205010512(this, filteredHistory);
736 private static class SyncJob extends AbstractJob {
737 public SyncJob(TypeInfoViewer viewer) {
738 super(JavaUIMessages.TypeInfoViewer_syncJob_label, viewer);
744 protected IStatus doRun(ProgressMonitor monitor) {
746 monitor.generated_5068716864496295402();
747 } catch (JavaModelException e) {
749 return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.ERROR, JavaUIMessages.TypeInfoViewer_job_error, e);
750 } catch (OperationCanceledException e) {
751 return new Status(IStatus.CANCEL, JavaPlugin.getPluginId(), IStatus.CANCEL, JavaUIMessages.TypeInfoViewer_job_cancel, e);
753 fViewer.syncJobDone();
755 return new Status(IStatus.OK, JavaPlugin.getPluginId(), IStatus.OK, "", null); //$NON-NLS-1$
759 static class DashLine {
760 private int fSeparatorWidth;
761 private String fMessage;
762 private int fMessageLength;
763 public String getText(int width) {
764 StringBuffer dashes= new StringBuffer();
765 int chars= (((width - fMessageLength) / fSeparatorWidth) / 2) -2;
766 for (int i= 0; i < chars; i++) {
767 dashes.append(SEPARATOR);
769 StringBuffer result= new StringBuffer();
770 result.append(dashes);
771 result.append(fMessage);
772 result.append(dashes);
773 return result.toString();
775 public void initialize(GC gc) {
776 fSeparatorWidth= gc.getAdvanceWidth(SEPARATOR);
777 fMessage= " " + JavaUIMessages.TypeInfoViewer_separator_message + " "; //$NON-NLS-1$ //$NON-NLS-2$
778 fMessageLength= gc.textExtent(fMessage).x;
780 public void generated_4106678073497933459(TypeInfoViewer typeinfoviewer, TableItem item, Rectangle bounds, Rectangle area) {
781 boolean willHaveScrollBar= typeinfoviewer.fExpectedItemCount + 1 > typeinfoviewer.fNumberOfVisibleItems;
782 item.setText(getText(area.width - bounds.x - bounds.width - typeinfoviewer.fTableWidthDelta -
783 (willHaveScrollBar ? typeinfoviewer.fScrollbarWidth : 0)));
784 item.setImage(typeinfoviewer.fSeparatorIcon);
785 item.setForeground(typeinfoviewer.fDashLineColor);
790 static class ImageManager {
791 private Map fImages= new HashMap(20);
793 public Image get(ImageDescriptor descriptor) {
794 if (descriptor == null)
795 descriptor= ImageDescriptor.getMissingImageDescriptor();
797 Image result= (Image)fImages.get(descriptor);
800 result= descriptor.createImage();
802 fImages.put(descriptor, result);
806 public void dispose() {
807 for (Iterator iter= fImages.values().iterator(); iter.hasNext(); ) {
808 Image image= (Image)iter.next();
815 private Display fDisplay;
817 private String fProgressMessage;
818 private Label fProgressLabel;
819 private int fProgressCounter;
820 private ProgressUpdateJob fProgressUpdateJob;
822 public OpenTypeHistory fHistory;
824 /* non virtual table */
825 private int fNextElement;
829 private TypeNameMatch[] fHistoryMatches;
830 private TypeNameMatch[] fSearchMatches;
832 public int fNumberOfVisibleItems;
833 private int fExpectedItemCount;
834 private Color fDashLineColor;
835 private int fScrollbarWidth;
836 private int fTableWidthDelta;
837 private int fDashLineIndex= -1;
838 private Image fSeparatorIcon;
839 private DashLine fDashLine= new DashLine();
841 private boolean fFullyQualifySelection;
842 /* remembers the last selection to restore unqualified labels */
843 private TableItem[] fLastSelection;
844 private String[] fLastLabels;
846 private TypeInfoLabelProvider fLabelProvider;
847 private ImageManager fImageManager;
849 private Table fTable;
851 private SyncJob fSyncJob;
853 public TypeInfoFilter fTypeInfoFilter;
854 private ITypeInfoFilterExtension fFilterExtension;
855 public TypeNameMatch[] fLastCompletedResult;
856 public TypeInfoFilter fLastCompletedFilter;
858 public int fSearchJobTicket;
859 public int fElementKind;
860 public IJavaSearchScope fSearchScope;
862 public AbstractSearchJob fSearchJob;
864 private static final int HISTORY= 1;
865 private static final int INDEX= 2;
866 private static final int FULL= HISTORY | INDEX;
868 private static final char SEPARATOR= '-';
870 private static final boolean DEBUG= false;
871 private static final boolean VIRTUAL= false;
873 private static final TypeNameMatch[] EMTPY_TYPE_INFO_ARRAY= new TypeNameMatch[0];
874 // only needed when in virtual table mode
876 private static final TypeNameMatch DASH_LINE= SearchEngine.createTypeNameMatch(null, 0);
879 public TypeInfoViewer(Composite parent, int flags, Label progressLabel,
880 IJavaSearchScope scope, int elementKind, String initialFilter,
881 ITypeInfoFilterExtension filterExtension, ITypeInfoImageProvider imageExtension) {
882 Assert.isNotNull(scope);
883 fDisplay= parent.getDisplay();
884 fProgressLabel= progressLabel;
886 fElementKind= elementKind;
887 fFilterExtension= filterExtension;
888 fFullyQualifySelection= (flags & SWT.MULTI) != 0;
891 fTable= new Table(parent, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | SWT.FLAT | flags);
892 fTable.setFont(parent.getFont());
893 fLabelProvider= new TypeInfoLabelProvider(imageExtension);
894 fItems= new ArrayList(500);
895 fTable.setHeaderVisible(false);
897 fTable.addControlListener(new ControlAdapter() {
899 public void controlResized(ControlEvent event) {
900 int itemHeight= fTable.getItemHeight();
901 Rectangle clientArea= fTable.getClientArea();
902 fNumberOfVisibleItems= (clientArea.height / itemHeight) + 1;
905 fTable.addKeyListener(new KeyAdapter() {
907 public void keyPressed(KeyEvent e) {
908 if (e.keyCode == SWT.DEL) {
909 deleteHistoryEntry();
910 } else if (e.keyCode == SWT.ARROW_DOWN) {
911 int index= fTable.getSelectionIndex();
912 if (index == fDashLineIndex - 1) {
914 setTableSelection(index + 2);
916 } else if (e.keyCode == SWT.ARROW_UP) {
917 int index= fTable.getSelectionIndex();
918 if (fDashLineIndex != -1 && index == fDashLineIndex + 1) {
920 setTableSelection(index - 2);
925 fTable.addSelectionListener(new SelectionAdapter() {
927 public void widgetSelected(SelectionEvent e) {
928 if (fLastSelection != null) {
929 for (int i= 0; i < fLastSelection.length; i++) {
930 TableItem item= fLastSelection[i];
931 // could be disposed by deleting element from
933 if (!item.isDisposed())
934 item.setText(fLastLabels[i]);
937 TableItem[] items= fTable.getSelection();
938 fLastSelection= new TableItem[items.length];
939 fLastLabels= new String[items.length];
940 for (int i= 0; i < items.length; i++) {
941 TableItem item= items[i];
942 fLastSelection[i]= item;
943 fLastLabels[i]= item.getText();
944 Object data= item.getData();
945 if (data instanceof TypeNameMatch) {
946 String qualifiedText= getQualifiedText((TypeNameMatch)data);
947 if (qualifiedText.length() > fLastLabels[i].length())
948 item.setText(qualifiedText);
953 fTable.addDisposeListener(new DisposeListener() {
954 public void widgetDisposed(DisposeEvent e) {
956 fDashLineColor.dispose();
957 fSeparatorIcon.dispose();
958 fImageManager.dispose();
959 if (fProgressUpdateJob != null) {
960 fProgressUpdateJob.stop();
961 fProgressUpdateJob= null;
966 fHistoryMatches= EMTPY_TYPE_INFO_ARRAY;
967 fSearchMatches= EMTPY_TYPE_INFO_ARRAY;
968 fTable.addListener(SWT.SetData, new Listener() {
969 public void handleEvent(Event event) {
970 TableItem item= (TableItem)event.item;
976 fDashLineColor= computeDashLineColor();
977 fScrollbarWidth= computeScrollBarWidth();
978 fTableWidthDelta= fTable.computeTrim(0, 0, 0, 0).width - fScrollbarWidth;
979 fSeparatorIcon= JavaPluginImages.DESC_OBJS_TYPE_SEPARATOR.createImage(fTable.getDisplay());
980 // Use a new image manager since an extension can provide its own
981 // image descriptors. To avoid thread problems with SWT the registry
982 // must be created in the UI thread.
983 fImageManager= new ImageManager();
985 fHistory= OpenTypeHistory.getInstance();
986 if (initialFilter != null && initialFilter.length() > 0)
987 fTypeInfoFilter= createTypeInfoFilter(initialFilter);
991 gc.setFont(fTable.getFont());
992 fDashLine.initialize(gc);
996 // If we do have a type info filter then we are
997 // scheduling a search job in startup. So no
998 // need to sync the search indices.
999 if (fTypeInfoFilter == null) {
1004 /* package */ void startup() {
1005 if (fTypeInfoFilter == null) {
1008 scheduleSearchJob(FULL);
1012 public Table getTable() {
1016 /* package */ TypeInfoLabelProvider getLabelProvider() {
1017 return fLabelProvider;
1020 private int getNumberOfVisibleItems() {
1021 return fNumberOfVisibleItems;
1024 public void setFocus() {
1029 public void setQualificationStyle(boolean value) {
1030 if (fFullyQualifySelection == value)
1032 fFullyQualifySelection= value;
1033 if (fLastSelection != null) {
1034 for (int i= 0; i < fLastSelection.length; i++) {
1035 TableItem item= fLastSelection[i];
1036 Object data= item.getData();
1037 if (data instanceof TypeNameMatch) {
1038 item.setText(getQualifiedText((TypeNameMatch)data));
1044 public TypeNameMatch[] getSelection() {
1045 TableItem[] items= fTable.getSelection();
1046 List result= new ArrayList(items.length);
1047 for (int i= 0; i < items.length; i++) {
1048 Object data= items[i].getData();
1049 if (data instanceof TypeNameMatch) {
1053 return (TypeNameMatch[])result.toArray(new TypeNameMatch[result.size()]);
1056 public void stop() {
1060 public void stop(boolean stopSyncJob, boolean dispose) {
1061 if (fSyncJob != null && stopSyncJob) {
1065 if (fSearchJob != null) {
1071 public void forceSearch() {
1073 if (fTypeInfoFilter == null) {
1076 // clear last results
1077 fLastCompletedFilter= null;
1078 fLastCompletedResult= null;
1079 scheduleSearchJob(isSyncJobRunning() ? HISTORY : FULL);
1083 public void setSearchPattern(String text) {
1085 if (text.length() == 0 || "*".equals(text)) { //$NON-NLS-1$
1086 fTypeInfoFilter= null;
1089 fTypeInfoFilter= createTypeInfoFilter(text);
1090 scheduleSearchJob(isSyncJobRunning() ? HISTORY : FULL);
1094 public void setSearchScope(IJavaSearchScope scope, boolean refresh) {
1095 fSearchScope= scope;
1099 fLastCompletedFilter= null;
1100 fLastCompletedResult= null;
1101 if (fTypeInfoFilter == null) {
1104 scheduleSearchJob(isSyncJobRunning() ? HISTORY : FULL);
1108 public void setFullyQualifyDuplicates(boolean value, boolean refresh) {
1109 fLabelProvider.setFullyQualifyDuplicates(value);
1113 if (fTypeInfoFilter == null) {
1116 scheduleSearchJob(isSyncJobRunning() ? HISTORY : FULL);
1120 public void reset() {
1121 fLastSelection= null;
1123 fExpectedItemCount= 0;
1125 TypeInfoFilter filter= (fTypeInfoFilter != null)
1127 : new TypeInfoFilter("*", fSearchScope, fElementKind, fFilterExtension); //$NON-NLS-1$
1129 fHistoryMatches= fHistory.getFilteredTypeInfos(filter);
1130 fExpectedItemCount= fHistoryMatches.length;
1131 fTable.setItemCount(fHistoryMatches.length);
1132 // bug under windows.
1133 if (fHistoryMatches.length == 0) {
1136 fTable.clear(0, fHistoryMatches.length - 1);
1139 TypeNameMatch[] historyItems= fHistory.getFilteredTypeInfos(filter);
1140 if (historyItems.length == 0) {
1144 fExpectedItemCount= historyItems.length;
1145 int lastIndex= historyItems.length - 1;
1146 TypeNameMatch last= null;
1147 TypeNameMatch type= historyItems[0];
1148 for (int i= 0; i < historyItems.length; i++) {
1149 TypeNameMatch next= i == lastIndex ? null : historyItems[i + 1];
1150 addSingleElement(type,
1151 fLabelProvider.getImageDescriptor(type),
1152 fLabelProvider.getText(last, type, next));
1160 protected TypeInfoFilter createTypeInfoFilter(String text) {
1161 if ("**".equals(text)) //$NON-NLS-1$
1162 text= "*"; //$NON-NLS-1$
1163 return new TypeInfoFilter(text, fSearchScope, fElementKind, fFilterExtension);
1166 private void addPopupMenu() {
1167 Menu menu= new Menu(fTable.getShell(), SWT.POP_UP);
1168 fTable.setMenu(menu);
1169 final MenuItem remove= new MenuItem(menu, SWT.NONE);
1170 remove.setText(JavaUIMessages.TypeInfoViewer_remove_from_history);
1171 menu.addMenuListener(new MenuAdapter() {
1173 public void menuShown(MenuEvent e) {
1174 TableItem[] selection= fTable.getSelection();
1175 remove.setEnabled(canEnable(selection));
1178 remove.addSelectionListener(new SelectionAdapter() {
1180 public void widgetSelected(SelectionEvent e) {
1181 deleteHistoryEntry();
1186 private boolean canEnable(TableItem[] selection) {
1187 if (selection.length == 0)
1189 for (int i= 0; i < selection.length; i++) {
1190 TableItem item= selection[i];
1191 Object data= item.getData();
1192 if (!(data instanceof TypeNameMatch))
1194 if (!(fHistory.contains((TypeNameMatch)data)))
1200 //---- History management -------------------------------------------------------
1202 private void deleteHistoryEntry() {
1203 int index= fTable.getSelectionIndex();
1206 TableItem item= fTable.getItem(index);
1207 Object element= item.getData();
1208 if (!(element instanceof TypeNameMatch))
1210 if (fHistory.remove(element) != null) {
1212 fItems.remove(index);
1213 int count= fTable.getItemCount();
1215 item= fTable.getItem(0);
1216 if (item.getData() instanceof DashLine) {
1221 setTableSelection(0);
1224 if (index >= count) {
1227 setTableSelection(index);
1230 // send dummy selection
1231 fTable.notifyListeners(SWT.Selection, new Event());
1236 //-- Search result updating ----------------------------------------------------
1238 private void clear(int ticket) {
1239 syncExec(ticket, new Runnable() {
1243 fLastSelection= null;
1245 fExpectedItemCount= 0;
1250 private void rememberResult(int ticket, final TypeNameMatch[] result) {
1251 syncExec(ticket, new Runnable() {
1253 if (fLastCompletedResult == null) {
1254 fLastCompletedFilter= fTypeInfoFilter;
1255 fLastCompletedResult= result;
1261 private void addHistory(int ticket, final List elements, final List imageDescriptors, final List labels) {
1262 addAll(ticket, elements, imageDescriptors, labels);
1265 private void addAll(int ticket, final List elements, final List imageDescriptors, final List labels) {
1266 syncExec(ticket, new Runnable() {
1268 int size= elements.size();
1269 for(int i= 0; i < size; i++) {
1270 addSingleElement(elements.get(i),
1271 (ImageDescriptor)imageDescriptors.get(i),
1272 (String)labels.get(i));
1278 private void addDashLineAndUpdateLastHistoryEntry(int ticket, final TypeNameMatch next) {
1279 syncExec(ticket, new Runnable() {
1281 if (fNextElement > 0) {
1282 TableItem item= fTable.getItem(fNextElement - 1);
1283 String label= item.getText();
1284 String newLabel= fLabelProvider.getText(null, (TypeNameMatch)item.getData(), next);
1285 if (newLabel.length() != label.length())
1286 item.setText(newLabel);
1287 if (fLastSelection != null && fLastSelection.length > 0) {
1288 TableItem last= fLastSelection[fLastSelection.length - 1];
1290 fLastLabels[fLastLabels.length - 1]= newLabel;
1294 fDashLineIndex= fNextElement;
1300 private void addDashLine() {
1301 TableItem item= null;
1302 if (fItems.size() > fNextElement) {
1303 item= (TableItem)fItems.get(fNextElement);
1305 item= new TableItem(fTable, SWT.NONE);
1312 private void addSingleElement(Object element, ImageDescriptor imageDescriptor, String label) {
1313 TableItem item= null;
1315 if (fItems.size() > fNextElement) {
1316 item= (TableItem)fItems.get(fNextElement);
1317 old= item.getData();
1318 item.setForeground(null);
1320 item= new TableItem(fTable, SWT.NONE);
1323 item.setData(element);
1324 item.setImage(fImageManager.get(imageDescriptor));
1325 if (fNextElement == 0) {
1326 if (needsSelectionChange(old, element) || fLastSelection != null) {
1327 item.setText(label);
1328 fTable.setSelection(0);
1329 fTable.notifyListeners(SWT.Selection, new Event());
1331 fLastSelection= new TableItem[] { item };
1332 fLastLabels= new String[] { label };
1335 item.setText(label);
1340 private boolean needsSelectionChange(Object oldElement, Object newElement) {
1341 int[] selected= fTable.getSelectionIndices();
1342 if (selected.length != 1)
1344 if (selected[0] != 0)
1346 if (oldElement == null)
1348 return !oldElement.equals(newElement);
1351 private void scheduleSearchJob(int mode) {
1352 fTypeInfoFilter.generated_2392701484878639473(this, mode);
1353 fSearchJob.schedule();
1356 private void searchJobDone(int ticket) {
1357 syncExec(ticket, new Runnable() {
1366 private void searchJobCanceled(int ticket, final boolean removePendingItems) {
1367 syncExec(ticket, new Runnable() {
1369 if (removePendingItems) {
1378 private synchronized void searchJobFailed(int ticket, CoreException e) {
1379 searchJobDone(ticket);
1383 //-- virtual table support -------------------------------------------------------
1385 private void setHistoryResult(int ticket, final TypeNameMatch[] types) {
1386 syncExec(ticket, new Runnable() {
1388 fExpectedItemCount= types.length;
1389 int lastHistoryLength= fHistoryMatches.length;
1390 fHistoryMatches= types;
1391 int length= fHistoryMatches.length + fSearchMatches.length;
1392 int dash= (fHistoryMatches.length > 0 && fSearchMatches.length > 0) ? 1 : 0;
1393 fTable.setItemCount(length + dash);
1395 // bug under windows.
1399 int update= Math.max(lastHistoryLength, fHistoryMatches.length);
1401 fTable.clear(0, update + dash - 1);
1407 private void setSearchResult(int ticket, final TypeNameMatch[] types) {
1408 syncExec(ticket, new Runnable() {
1410 fExpectedItemCount+= types.length;
1411 fSearchMatches= types;
1412 int length= fHistoryMatches.length + fSearchMatches.length;
1413 int dash= (fHistoryMatches.length > 0 && fSearchMatches.length > 0) ? 1 : 0;
1414 fTable.setItemCount(length + dash);
1416 // bug under windows.
1420 if (fHistoryMatches.length == 0) {
1421 fTable.clear(0, length + dash - 1);
1423 fTable.clear(fHistoryMatches.length - 1, length + dash - 1);
1429 private void setData(TableItem item) {
1430 int index= fTable.indexOf(item);
1431 TypeNameMatch type= getTypeInfo(index);
1432 if (type == DASH_LINE) {
1433 item.setData(fDashLine);
1436 fLabelProvider.generated_7293536804022995861(this, item, index, type);
1440 private TypeNameMatch getTypeInfo(int index) {
1443 if (index < fHistoryMatches.length) {
1444 return fHistoryMatches[index];
1446 int dash= (fHistoryMatches.length > 0 && fSearchMatches.length > 0) ? 1 : 0;
1447 if (index == fHistoryMatches.length && dash == 1) {
1450 index= index - fHistoryMatches.length - dash;
1451 if (index >= fSearchMatches.length)
1453 return fSearchMatches[index];
1456 //-- Sync Job updates ------------------------------------------------------------
1458 private void scheduleSyncJob() {
1459 fSyncJob= new SyncJob(this);
1460 fSyncJob.schedule();
1463 private void syncJobDone() {
1464 syncExec(new Runnable() {
1467 if (fTypeInfoFilter != null) {
1468 scheduleSearchJob(FULL);
1474 private boolean isSyncJobRunning() {
1475 return fSyncJob != null;
1478 //-- progress monitor updates -----------------------------------------------------
1480 private void scheduleProgressUpdateJob() {
1481 syncExec(new Runnable() {
1483 if (fProgressCounter == 0) {
1484 clearProgressMessage();
1485 fProgressUpdateJob= new ProgressUpdateJob(fDisplay, TypeInfoViewer.this);
1486 fProgressUpdateJob.schedule(300);
1493 private void stopProgressUpdateJob() {
1494 syncExec(new Runnable() {
1497 if (fProgressCounter == 0 && fProgressUpdateJob != null) {
1498 fProgressUpdateJob.stop();
1499 fProgressUpdateJob= null;
1500 clearProgressMessage();
1506 private void setProgressMessage(String message) {
1507 fProgressMessage= message;
1510 private void clearProgressMessage() {
1511 fProgressMessage= ""; //$NON-NLS-1$
1512 fProgressLabel.setText(fProgressMessage);
1515 private void updateProgressMessage() {
1516 fProgressLabel.setText(fProgressMessage);
1519 //-- Helper methods --------------------------------------------------------------
1521 private void syncExec(final Runnable runnable) {
1522 if (fDisplay.isDisposed())
1524 fDisplay.syncExec(new Runnable() {
1526 if (fTable.isDisposed())
1533 private void syncExec(final int ticket, final Runnable runnable) {
1534 if (fDisplay.isDisposed())
1536 fDisplay.syncExec(new Runnable() {
1538 if (fTable.isDisposed() || ticket != fSearchJobTicket)
1545 private void fillDashLine(TableItem item) {
1546 Rectangle bounds= item.getImageBounds(0);
1547 Rectangle area= fTable.getBounds();
1548 fDashLine.generated_4106678073497933459(this, item, bounds, area);
1551 private void shortenTable() {
1554 if (fNextElement < fItems.size()) {
1555 fTable.setRedraw(false);
1556 fTable.remove(fNextElement, fItems.size() - 1);
1557 fTable.setRedraw(true);
1559 for (int i= fItems.size() - 1; i >= fNextElement; i--) {
1564 private void checkEmptyList() {
1565 if (fTable.getItemCount() == 0) {
1566 fTable.notifyListeners(SWT.Selection, new Event());
1570 private void setTableSelection(int index) {
1571 fTable.setSelection(index);
1572 fTable.notifyListeners(SWT.Selection, new Event());
1575 private Color computeDashLineColor() {
1576 Color fg= fTable.getForeground();
1577 int fGray= (int)(0.3*fg.getRed() + 0.59*fg.getGreen() + 0.11*fg.getBlue());
1578 Color bg= fTable.getBackground();
1579 int bGray= (int)(0.3*bg.getRed() + 0.59*bg.getGreen() + 0.11*bg.getBlue());
1580 int gray= (int)((fGray + bGray) * 0.66);
1581 return new Color(fDisplay, gray, gray, gray);
1584 private int computeScrollBarWidth() {
1585 Composite t= new Composite(fTable.getShell(), SWT.V_SCROLL);
1586 int result= t.computeTrim(0, 0, 0, 0).width;
1591 private String getQualifiedText(TypeNameMatch type) {
1592 return fLabelProvider.generated_7876537592558312876(this, type);
1595 public void generated_694059975286430385(final TypeSelectionComponent typeselectioncomponent, final String message, Font font, GridData gd) {
1596 typeselectioncomponent.fFilter.setLayoutData(gd);
1597 typeselectioncomponent.fFilter.addModifyListener(new ModifyListener() {
1598 public void modifyText(ModifyEvent e) {
1599 typeselectioncomponent.patternChanged((Text)e.widget);
1602 typeselectioncomponent.fFilter.addKeyListener(new KeyListener() {
1603 public void keyReleased(KeyEvent e) {
1605 public void keyPressed(KeyEvent e) {
1606 if (e.keyCode == SWT.ARROW_DOWN) {
1611 typeselectioncomponent.fFilter.getAccessible().addAccessibleListener(new AccessibleAdapter() {
1613 public void getName(AccessibleEvent e) {
1614 e.result= Strings.removeMnemonicIndicator(message);
1617 TextFieldNavigationHandler.install(typeselectioncomponent.fFilter);
1619 Label label= new Label(typeselectioncomponent, SWT.NONE);
1620 label.setFont(font);
1621 label.setText(JavaUIMessages.TypeSelectionComponent_label);
1622 label.addTraverseListener(new TraverseListener() {
1623 public void keyTraversed(TraverseEvent e) {
1624 if (e.detail == SWT.TRAVERSE_MNEMONIC && e.doit) {
1625 e.detail= SWT.TRAVERSE_NONE;