X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/JavaOutlineInformationControl.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/JavaOutlineInformationControl.java index 68db9b5..b99ee96 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/JavaOutlineInformationControl.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/JavaOutlineInformationControl.java @@ -64,51 +64,52 @@ import org.eclipse.swt.widgets.TreeItem; /** * @author dmegert - * + * * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. + * Window>Preferences>Java>Templates. To enable and disable the creation of type + * comments go to Window>Preferences>Java>Code Generation. */ -public class JavaOutlineInformationControl implements IInformationControl, IInformationControlExtension, IInformationControlExtension2 { - +public class JavaOutlineInformationControl implements IInformationControl, + IInformationControlExtension, IInformationControlExtension2 { /** - * The NamePatternFilter selects the elements which - * match the given string patterns. + * The NamePatternFilter selects the elements which match the given string + * patterns. *
- * The following characters have special meaning: - * ? => any character - * * => any string + * The following characters have special meaning: ? => any character * => + * any string *
- * + * * @since 2.0 */ private static class NamePatternFilter extends ViewerFilter { private String fPattern; + private StringMatcher fMatcher; + private ILabelProvider fLabelProvider; + private Viewer fViewer; private StringMatcher getMatcher() { return fMatcher; } - - /* (non-Javadoc) - * Method declared on ViewerFilter. + /* + * (non-Javadoc) Method declared on ViewerFilter. */ - public boolean select(Viewer viewer, Object parentElement, Object element) { + public boolean select(Viewer viewer, Object parentElement, + Object element) { if (fMatcher == null) return true; - ILabelProvider labelProvider= getLabelProvider(viewer); + ILabelProvider labelProvider = getLabelProvider(viewer); - String matchName= null; + String matchName = null; if (labelProvider != null) - matchName= ((ILabelProvider)labelProvider).getText(element); + matchName = ((ILabelProvider) labelProvider).getText(element); else if (element instanceof IJavaElement) - matchName= ((IJavaElement) element).getElementName(); + matchName = ((IJavaElement) element).getElementName(); if (matchName != null && fMatcher.match(matchName)) return true; @@ -120,13 +121,14 @@ public class JavaOutlineInformationControl implements IInformationControl, IInfo if (fViewer == viewer) return fLabelProvider; - fLabelProvider= null; - IBaseLabelProvider baseLabelProvider= null; + fLabelProvider = null; + IBaseLabelProvider baseLabelProvider = null; if (viewer instanceof StructuredViewer) - baseLabelProvider= ((StructuredViewer)viewer).getLabelProvider(); + baseLabelProvider = ((StructuredViewer) viewer) + .getLabelProvider(); if (baseLabelProvider instanceof ILabelProvider) - fLabelProvider= (ILabelProvider)baseLabelProvider; + fLabelProvider = (ILabelProvider) baseLabelProvider; return fLabelProvider; } @@ -135,11 +137,11 @@ public class JavaOutlineInformationControl implements IInformationControl, IInfo IJavaElement[] children; if (element instanceof IParent) { try { - children= ((IParent)element).getChildren(); + children = ((IParent) element).getChildren(); } catch (JavaModelException ex) { return false; } - for (int i= 0; i < children.length; i++) + for (int i = 0; i < children.length; i++) if (select(viewer, element, children[i])) return true; } @@ -149,23 +151,21 @@ public class JavaOutlineInformationControl implements IInformationControl, IInfo /** * Sets the patterns to filter out for the receiver. *- * The following characters have special meaning: - * ? => any character - * * => any string + * The following characters have special meaning: ? => any character * => + * any string *
*/ public void setPattern(String pattern) { - fPattern= pattern; + fPattern = pattern; if (fPattern == null) { - fMatcher= null; + fMatcher = null; return; } - boolean ignoreCase= pattern.toLowerCase().equals(pattern); - fMatcher= new StringMatcher(pattern, ignoreCase, false); + boolean ignoreCase = pattern.toLowerCase().equals(pattern); + fMatcher = new StringMatcher(pattern, ignoreCase, false); } } - private static class BorderFillLayout extends Layout { /** The border widths. */ @@ -177,7 +177,7 @@ public class JavaOutlineInformationControl implements IInformationControl, IInfo public BorderFillLayout(int borderSize) { if (borderSize < 0) throw new IllegalArgumentException(); - fBorderSize= borderSize; + fBorderSize = borderSize; } /** @@ -188,18 +188,21 @@ public class JavaOutlineInformationControl implements IInformationControl, IInfo } /* - * @see org.eclipse.swt.widgets.Layout#computeSize(org.eclipse.swt.widgets.Composite, int, int, boolean) + * @see org.eclipse.swt.widgets.Layout#computeSize(org.eclipse.swt.widgets.Composite, + * int, int, boolean) */ - protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) { + protected Point computeSize(Composite composite, int wHint, int hHint, + boolean flushCache) { - Control[] children= composite.getChildren(); - Point minSize= new Point(0, 0); + Control[] children = composite.getChildren(); + Point minSize = new Point(0, 0); if (children != null) { - for (int i= 0; i < children.length; i++) { - Point size= children[i].computeSize(wHint, hHint, flushCache); - minSize.x= Math.max(minSize.x, size.x); - minSize.y= Math.max(minSize.y, size.y); + for (int i = 0; i < children.length; i++) { + Point size = children[i].computeSize(wHint, hHint, + flushCache); + minSize.x = Math.max(minSize.x, size.x); + minSize.y = Math.max(minSize.y, size.y); } } @@ -208,125 +211,144 @@ public class JavaOutlineInformationControl implements IInformationControl, IInfo return minSize; } + /* - * @see org.eclipse.swt.widgets.Layout#layout(org.eclipse.swt.widgets.Composite, boolean) + * @see org.eclipse.swt.widgets.Layout#layout(org.eclipse.swt.widgets.Composite, + * boolean) */ protected void layout(Composite composite, boolean flushCache) { - Control[] children= composite.getChildren(); - Point minSize= new Point(composite.getClientArea().width, composite.getClientArea().height); + Control[] children = composite.getChildren(); + Point minSize = new Point(composite.getClientArea().width, + composite.getClientArea().height); if (children != null) { - for (int i= 0; i < children.length; i++) { - Control child= children[i]; - child.setSize(minSize.x - fBorderSize * 2, minSize.y - fBorderSize * 2); + for (int i = 0; i < children.length; i++) { + Control child = children[i]; + child.setSize(minSize.x - fBorderSize * 2, minSize.y + - fBorderSize * 2); child.setLocation(fBorderSize, fBorderSize); } } } } - /** Border thickness in pixels. */ - private static final int BORDER= 1; + private static final int BORDER = 1; + /** Right margin in pixels. */ - private static final int RIGHT_MARGIN= 3; + private static final int RIGHT_MARGIN = 3; /** The control's shell */ private Shell fShell; + /** The composite */ Composite fComposite; + /** The control's text widget */ private Text fFilterText; + /** The control's tree widget */ private TreeViewer fTreeViewer; + /** The control width constraint */ - private int fMaxWidth= -1; + private int fMaxWidth = -1; + /** The control height constraint */ - private int fMaxHeight= -1; + private int fMaxHeight = -1; private StringMatcher fStringMatcher; - /** - * Creates a tree information control with the given shell as parent. The given - * style is applied to the tree widget. - * - * @param parent the parent shell - * @param style the additional styles for the tree widget + * Creates a tree information control with the given shell as parent. The + * given style is applied to the tree widget. + * + * @param parent + * the parent shell + * @param style + * the additional styles for the tree widget */ public JavaOutlineInformationControl(Shell parent, int style) { this(parent, SWT.RESIZE, style); } /** - * Creates a tree information control with the given shell as parent. - * No additional styles are applied. - * - * @param parent the parent shell + * Creates a tree information control with the given shell as parent. No + * additional styles are applied. + * + * @param parent + * the parent shell */ - public JavaOutlineInformationControl(Shell parent) { - this(parent, SWT.NONE); - } +// public JavaOutlineInformationControl(Shell parent) { +// this(parent, SWT.NONE); +// } /** - * Creates a tree information control with the given shell as parent. The given - * styles are applied to the shell and the tree widget. - * - * @param parent the parent shell - * @param shellStyle the additional styles for the shell - * @param treeStyle the additional styles for the tree widget + * Creates a tree information control with the given shell as parent. The + * given styles are applied to the shell and the tree widget. + * + * @param parent + * the parent shell + * @param shellStyle + * the additional styles for the shell + * @param treeStyle + * the additional styles for the tree widget */ - public JavaOutlineInformationControl(Shell parent, int shellStyle, int treeStyle) { - fShell= new Shell(parent, shellStyle); - Display display= fShell.getDisplay(); + public JavaOutlineInformationControl(Shell parent, int shellStyle, + int treeStyle) { + fShell = new Shell(parent, shellStyle); + Display display = fShell.getDisplay(); fShell.setBackground(display.getSystemColor(SWT.COLOR_BLACK)); // Composite for filter text and tree - fComposite= new Composite(fShell,SWT.RESIZE); - GridLayout layout= new GridLayout(1, false); + fComposite = new Composite(fShell, SWT.RESIZE); + GridLayout layout = new GridLayout(1, false); fComposite.setLayout(layout); fComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - + createFilterText(fComposite); createTreeViewer(fComposite, treeStyle); - int border= ((shellStyle & SWT.NO_TRIM) == 0) ? 0 : BORDER; + int border = ((shellStyle & SWT.NO_TRIM) == 0) ? 0 : BORDER; fShell.setLayout(new BorderFillLayout(border)); - + setInfoSystemColor(); installFilter(); } private void createTreeViewer(Composite parent, int style) { - Tree tree= new Tree(parent, SWT.SINGLE | (style & ~SWT.MULTI)); - GridData data= new GridData(GridData.FILL_BOTH); + Tree tree = new Tree(parent, SWT.SINGLE | (style & ~SWT.MULTI)); + GridData data = new GridData(GridData.FILL_BOTH); tree.setLayoutData(data); - fTreeViewer= new TreeViewer(tree); + fTreeViewer = new TreeViewer(tree); // Hide import declartions but show the container -// fTreeViewer.addFilter(new ViewerFilter() { -// public boolean select(Viewer viewer, Object parentElement, Object element) { -// return !(element instanceof IImportDeclaration); -// } -// }); - - fTreeViewer.setContentProvider(new StandardJavaElementContentProvider(true, true)); + // fTreeViewer.addFilter(new ViewerFilter() { + // public boolean select(Viewer viewer, Object parentElement, Object + // element) { + // return !(element instanceof IImportDeclaration); + // } + // }); + + fTreeViewer.setContentProvider(new StandardJavaElementContentProvider( + true, true)); fTreeViewer.setSorter(new JavaElementSorter()); fTreeViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS); - - AppearanceAwareLabelProvider lprovider= new AppearanceAwareLabelProvider( - AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS | JavaElementLabels.F_APP_TYPE_SIGNATURE, - AppearanceAwareLabelProvider.DEFAULT_IMAGEFLAGS - ); - fTreeViewer.setLabelProvider(new DecoratingJavaLabelProvider(lprovider)); + + AppearanceAwareLabelProvider lprovider = new AppearanceAwareLabelProvider( + AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS + | JavaElementLabels.F_APP_TYPE_SIGNATURE, + AppearanceAwareLabelProvider.DEFAULT_IMAGEFLAGS); + fTreeViewer + .setLabelProvider(new DecoratingJavaLabelProvider(lprovider)); fTreeViewer.getTree().addKeyListener(new KeyListener() { - public void keyPressed(KeyEvent e) { + public void keyPressed(KeyEvent e) { if (e.character == 0x1B) // ESC dispose(); } + public void keyReleased(KeyEvent e) { // do nothing } @@ -336,6 +358,7 @@ public class JavaOutlineInformationControl implements IInformationControl, IInfo public void widgetSelected(SelectionEvent e) { // do nothing } + public void widgetDefaultSelected(SelectionEvent e) { gotoSelectedElement(); } @@ -343,19 +366,20 @@ public class JavaOutlineInformationControl implements IInformationControl, IInfo } private Text createFilterText(Composite parent) { - fFilterText= new Text(parent, SWT.FLAT); + fFilterText = new Text(parent, SWT.FLAT); - GridData data= new GridData(); - GC gc= new GC(parent); + GridData data = new GridData(); + GC gc = new GC(parent); gc.setFont(parent.getFont()); - FontMetrics fontMetrics= gc.getFontMetrics(); + FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); - data.heightHint= org.eclipse.jface.dialogs.Dialog.convertHeightInCharsToPixels(fontMetrics, 1); - data.horizontalAlignment= GridData.FILL; - data.verticalAlignment= GridData.BEGINNING; + data.heightHint = org.eclipse.jface.dialogs.Dialog + .convertHeightInCharsToPixels(fontMetrics, 1); + data.horizontalAlignment = GridData.FILL; + data.verticalAlignment = GridData.BEGINNING; fFilterText.setLayoutData(data); - + fFilterText.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { if (e.keyCode == 0x0D) // return @@ -367,42 +391,44 @@ public class JavaOutlineInformationControl implements IInformationControl, IInfo if (e.character == 0x1B) // ESC dispose(); } + public void keyReleased(KeyEvent e) { // do nothing } }); // Horizonral separator line - Label separator= new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.LINE_DOT); + Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL + | SWT.LINE_DOT); separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); return fFilterText; } - + private void setInfoSystemColor() { - Display display= fShell.getDisplay(); + Display display = fShell.getDisplay(); setForegroundColor(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND)); setBackgroundColor(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); } private void installFilter() { - final NamePatternFilter viewerFilter= new NamePatternFilter(); + final NamePatternFilter viewerFilter = new NamePatternFilter(); fTreeViewer.addFilter(viewerFilter); fFilterText.setText(""); //$NON-NLS-1$ fFilterText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { - String pattern= fFilterText.getText(); + String pattern = fFilterText.getText(); if (pattern != null) { - int length= pattern.length(); + int length = pattern.length(); if (length == 0) - pattern= null; - else if (pattern.charAt(length -1 ) != '*') - pattern= pattern + '*'; + pattern = null; + else if (pattern.charAt(length - 1) != '*') + pattern = pattern + '*'; } else - pattern= null; + pattern = null; viewerFilter.setPattern(pattern); - fStringMatcher= viewerFilter.getMatcher(); + fStringMatcher = viewerFilter.getMatcher(); fTreeViewer.getControl().setRedraw(false); fTreeViewer.refresh(); fTreeViewer.expandAll(); @@ -413,7 +439,8 @@ public class JavaOutlineInformationControl implements IInformationControl, IInfo } private void gotoSelectedElement() { - Object selectedElement= ((IStructuredSelection)fTreeViewer.getSelection()).getFirstElement(); + Object selectedElement = ((IStructuredSelection) fTreeViewer + .getSelection()).getFirstElement(); if (selectedElement != null) { try { dispose(); @@ -425,12 +452,12 @@ public class JavaOutlineInformationControl implements IInformationControl, IInfo } /** - * Selects the first element in the tree which - * matches the current filter pattern. + * Selects the first element in the tree which matches the current filter + * pattern. */ private void selectFirstMatch() { - Tree tree= fTreeViewer.getTree(); - Object element= findElement(tree.getItems()); + Tree tree = fTreeViewer.getTree(); + Object element = findElement(tree.getItems()); if (element != null) fTreeViewer.setSelection(new StructuredSelection(element), true); else @@ -438,19 +465,20 @@ public class JavaOutlineInformationControl implements IInformationControl, IInfo } private IJavaElement findElement(TreeItem[] items) { - ILabelProvider labelProvider= (ILabelProvider)fTreeViewer.getLabelProvider(); - for (int i= 0; i < items.length; i++) { - IJavaElement element= (IJavaElement)items[i].getData(); + ILabelProvider labelProvider = (ILabelProvider) fTreeViewer + .getLabelProvider(); + for (int i = 0; i < items.length; i++) { + IJavaElement element = (IJavaElement) items[i].getData(); if (fStringMatcher == null) return element; - + if (element != null) { - String label= labelProvider.getText(element); + String label = labelProvider.getText(element); if (fStringMatcher.match(label)) return element; } - element= findElement(items[i].getItems()); + element = findElement(items[i].getItems()); if (element != null) return element; } @@ -463,7 +491,7 @@ public class JavaOutlineInformationControl implements IInformationControl, IInfo public void setInformation(String information) { // this method is ignored, see IInformationControlExtension2 } - + /* * @see IInformationControlExtension2#setInput(Object) */ @@ -473,13 +501,14 @@ public class JavaOutlineInformationControl implements IInformationControl, IInfo setInput(null); return; } - IJavaElement je= (IJavaElement)information; - IJavaElement sel= null; - ICompilationUnit cu= (ICompilationUnit)je.getAncestor(IJavaElement.COMPILATION_UNIT); + IJavaElement je = (IJavaElement) information; + IJavaElement sel = null; + ICompilationUnit cu = (ICompilationUnit) je + .getAncestor(IJavaElement.COMPILATION_UNIT); if (cu != null) - sel= cu; + sel = cu; else - sel= je.getAncestor(IJavaElement.CLASS_FILE); + sel = je.getAncestor(IJavaElement.CLASS_FILE); fTreeViewer.setInput(sel); fTreeViewer.setSelection(new StructuredSelection(information)); } @@ -488,7 +517,7 @@ public class JavaOutlineInformationControl implements IInformationControl, IInfo * @see IInformationControl#setVisible(boolean) */ public void setVisible(boolean visible) { - fShell.setVisible(visible); + fShell.setVisible(visible); } /* @@ -498,29 +527,30 @@ public class JavaOutlineInformationControl implements IInformationControl, IInfo if (fShell != null) { if (!fShell.isDisposed()) fShell.dispose(); - fShell= null; - fTreeViewer= null; - fComposite= null; - fFilterText= null; + fShell = null; + fTreeViewer = null; + fComposite = null; + fFilterText = null; } } - /* + /* * @see org.eclipse.jface.text.IInformationControlExtension#hasContents() */ public boolean hasContents() { return fTreeViewer != null && fTreeViewer.getInput() != null; } - /* - * @see org.eclipse.jface.text.IInformationControl#setSizeConstraints(int, int) + /* + * @see org.eclipse.jface.text.IInformationControl#setSizeConstraints(int, + * int) */ public void setSizeConstraints(int maxWidth, int maxHeight) { - fMaxWidth= maxWidth; - fMaxHeight= maxHeight; + fMaxWidth = maxWidth; + fMaxHeight = maxHeight; } - /* + /* * @see org.eclipse.jface.text.IInformationControl#computeSizeHint() */ public Point computeSizeHint() { @@ -531,11 +561,11 @@ public class JavaOutlineInformationControl implements IInformationControl, IInfo * @see IInformationControl#setLocation(Point) */ public void setLocation(Point location) { - Rectangle trim= fShell.computeTrim(0, 0, 0, 0); - Point textLocation= fComposite.getLocation(); - location.x += trim.x - textLocation.x; - location.y += trim.y - textLocation.y; - fShell.setLocation(location); + Rectangle trim = fShell.computeTrim(0, 0, 0, 0); + Point textLocation = fComposite.getLocation(); + location.x += trim.x - textLocation.x; + location.y += trim.y - textLocation.y; + fShell.setLocation(location); } /* @@ -581,7 +611,8 @@ public class JavaOutlineInformationControl implements IInformationControl, IInfo * @see IInformationControl#isFocusControl() */ public boolean isFocusControl() { - return fTreeViewer.getControl().isFocusControl() || fFilterText.isFocusControl(); + return fTreeViewer.getControl().isFocusControl() + || fFilterText.isFocusControl(); } /*