Index: ui/org/eclipse/jdt/internal/ui/text/AbstractInformationControl.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/AbstractInformationControl.java,v retrieving revision 1.29 diff -u -r1.29 AbstractInformationControl.java --- ui/org/eclipse/jdt/internal/ui/text/AbstractInformationControl.java 17 Jun 2005 15:51:55 -0000 1.29 +++ ui/org/eclipse/jdt/internal/ui/text/AbstractInformationControl.java 7 Oct 2005 22:15:16 -0000 @@ -13,8 +13,6 @@ import java.util.List; import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ControlAdapter; -import org.eclipse.swt.events.ControlEvent; import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.events.FocusListener; @@ -25,48 +23,31 @@ import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.MouseMoveListener; -import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.events.ShellAdapter; -import org.eclipse.swt.events.ShellEvent; import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.FontData; import org.eclipse.swt.graphics.FontMetrics; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Item; import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Layout; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; -import org.eclipse.swt.widgets.ToolBar; -import org.eclipse.swt.widgets.ToolItem; -import org.eclipse.swt.widgets.Tracker; import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeItem; import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.GroupMarker; import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.dialogs.PopupDialog; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITreeContentProvider; @@ -99,23 +80,23 @@ import org.eclipse.jdt.ui.actions.CustomFiltersActionGroup; import org.eclipse.jdt.internal.ui.JavaPlugin; -import org.eclipse.jdt.internal.ui.JavaPluginImages; import org.eclipse.jdt.internal.ui.actions.OpenActionUtil; import org.eclipse.jdt.internal.ui.util.StringMatcher; /** * Abstract class for Show hierarchy in light-weight controls. - * + * * @since 2.1 */ -public abstract class AbstractInformationControl implements IInformationControl, IInformationControlExtension, IInformationControlExtension2, IInformationControlExtension3, DisposeListener { - - +public abstract class AbstractInformationControl extends PopupDialog implements + IInformationControl, IInformationControlExtension, + IInformationControlExtension2, IInformationControlExtension3, + DisposeListener { /** - * The NamePatternFilter selects the elements which - * match the given string patterns. - * + * The NamePatternFilter selects the elements which match the given string + * patterns. + * * @since 2.0 */ protected class NamePatternFilter extends ViewerFilter { @@ -123,16 +104,18 @@ public NamePatternFilter() { } - /* (non-Javadoc) - * Method declared on ViewerFilter. + /* + * (non-Javadoc) Method declared on ViewerFilter. */ - public boolean select(Viewer viewer, Object parentElement, Object element) { - StringMatcher matcher= getMatcher(); + public boolean select(Viewer viewer, Object parentElement, + Object element) { + StringMatcher matcher = getMatcher(); if (matcher == null || !(viewer instanceof TreeViewer)) return true; - TreeViewer treeViewer= (TreeViewer) viewer; + TreeViewer treeViewer = (TreeViewer) viewer; - String matchName= ((ILabelProvider) treeViewer.getLabelProvider()).getText(element); + String matchName = ((ILabelProvider) treeViewer.getLabelProvider()) + .getText(element); if (matchName != null && matcher.match(matchName)) return true; @@ -141,8 +124,9 @@ private boolean hasUnfilteredChild(TreeViewer viewer, Object element) { if (element instanceof IParent) { - Object[] children= ((ITreeContentProvider) viewer.getContentProvider()).getChildren(element); - for (int i= 0; i < children.length; i++) + Object[] children = ((ITreeContentProvider) viewer + .getContentProvider()).getChildren(element); + for (int i = 0; i < children.length; i++) if (select(viewer, element, children[i])) return true; } @@ -150,264 +134,199 @@ } } - - private static class BorderFillLayout extends Layout { - - /** The border widths. */ - final int fBorderSize; - - /** - * Creates a fill layout with a border. - * - * @param borderSize the border size - */ - public BorderFillLayout(int borderSize) { - if (borderSize < 0) - throw new IllegalArgumentException(); - fBorderSize= borderSize; - } - - /** - * Returns the border size. - * - * @return the border size - */ - public int getBorderSize() { - return fBorderSize; - } - - /* - * @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) { - - 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); - } - } - - minSize.x += fBorderSize * 2 + RIGHT_MARGIN; - minSize.y += fBorderSize * 2; - - return minSize; - } - /* - * @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); - - 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); - child.setLocation(fBorderSize, fBorderSize); - } - } - } - } - - - /** - * The view menu's Remember Size and Location action. - * - * @since 3.0 - */ - private class RememberBoundsAction extends Action { - - RememberBoundsAction() { - super(TextMessages.AbstractInformationControl_viewMenu_remember_label, IAction.AS_CHECK_BOX); - setChecked(!getDialogSettings().getBoolean(STORE_DISABLE_RESTORE_LOCATION)); - } - - /* - * @see org.eclipse.jface.action.Action#run() - */ - public void run() { - IDialogSettings settings= getDialogSettings(); - - boolean newValue= !isChecked(); - - // store new value - settings.put(STORE_DISABLE_RESTORE_LOCATION, newValue); - settings.put(STORE_DISABLE_RESTORE_SIZE, newValue); - - fIsDecativateListenerActive= true; - } - } - - /** - * The view menu's Resize action. - * - * @since 3.0 - */ - private class ResizeAction extends Action { - - ResizeAction() { - super(TextMessages.AbstractInformationControl_viewMenu_resize_label, IAction.AS_PUSH_BUTTON); - } - - /* - * @see org.eclipse.jface.action.Action#run() - */ - public void run() { - Tracker tracker= new Tracker(fShell.getDisplay(), SWT.RESIZE); - tracker.setStippled(true); - Rectangle[] r= new Rectangle[] { getFilterText().getShell().getBounds() }; - tracker.setRectangles(r); - if (tracker.open()) - fShell.setBounds(tracker.getRectangles()[0]); - } - } - - /** - * The view menu's Move action. - * - * @since 3.0 - */ - private class MoveAction extends Action { - - MoveAction() { - super(TextMessages.AbstractInformationControl_viewMenu_move_label, IAction.AS_PUSH_BUTTON); - } - - /* - * @see org.eclipse.jface.action.Action#run() - */ - public void run() { - Tracker tracker= new Tracker(fShell.getDisplay(), SWT.NONE); - tracker.setStippled(true); - Rectangle[] r= new Rectangle[] { getFilterText().getShell().getBounds() }; - tracker.setRectangles(r); - if (tracker.open()) - fShell.setBounds(tracker.getRectangles()[0]); - } - } - - - /** Border thickness in pixels. */ - private static final int BORDER= 1; - /** Right margin in pixels. */ - private static final int RIGHT_MARGIN= 3; - /** - * Dialog constants telling whether this control can be resized or move. - * @since 3.0 - */ - private static final String STORE_DISABLE_RESTORE_SIZE= "DISABLE_RESTORE_SIZE"; //$NON-NLS-1$ - private static final String STORE_DISABLE_RESTORE_LOCATION= "DISABLE_RESTORE_LOCATION"; //$NON-NLS-1$ - - /** 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 current string matcher */ private StringMatcher fStringMatcher; + private ICommand fInvokingCommand; - private Label fStatusField; - private Font fStatusTextFont; + private KeySequence[] fInvokingCommandKeySequences; + /** * Remembers the bounds for this information control. + * * @since 3.0 */ private Rectangle fBounds; - private Rectangle fTrim; + private Rectangle fTrim; + /** - * Fields for view menu support. + * Fields that support the dialog menu + * * @since 3.0 + * @since 3.2 - now appended to framework menu */ - private Button fViewMenuButton; - private ToolBar fToolBar; private Composite fViewMenuButtonComposite; - private MenuManager fViewMenuManager; - - private Listener fDeactivateListener; - private boolean fIsDecativateListenerActive= false; + private CustomFiltersActionGroup fCustomFiltersActionGroup; private IKeyBindingService fKeyBindingService; + private String[] fKeyBindingScopes; + private IAction fShowViewMenuAction; - private HandlerSubmission fShowViewMenuHandlerSubmission; + private HandlerSubmission fShowViewMenuHandlerSubmission; + /** - * 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 - * @param invokingCommandId the id of the command that invoked this control or null - * @param showStatusField true iff the control has a status field at the bottom - */ - public AbstractInformationControl(Shell parent, int shellStyle, int treeStyle, String invokingCommandId, boolean showStatusField) { + * Field for tree style since it must be remembered by the instance. + * + * @since 3.2 + */ + private int treeStyle; + + /** + * 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 + * @param invokingCommandId + * the id of the command that invoked this control or + * null + * @param showStatusField + * true iff the control has a status field at the + * bottom + */ + public AbstractInformationControl(Shell parent, int shellStyle, + int treeStyle, String invokingCommandId, boolean showStatusField) { + super((Shell) null, shellStyle, true, true, true, true, null, null); if (invokingCommandId != null) { - ICommandManager commandManager= PlatformUI.getWorkbench().getCommandSupport().getCommandManager(); - fInvokingCommand= commandManager.getCommand(invokingCommandId); + ICommandManager commandManager = PlatformUI.getWorkbench() + .getCommandSupport().getCommandManager(); + fInvokingCommand = commandManager.getCommand(invokingCommandId); if (fInvokingCommand != null && !fInvokingCommand.isDefined()) - fInvokingCommand= null; + fInvokingCommand = null; else - // Pre-fetch key sequence - do not change because scope will change later. + // Pre-fetch key sequence - do not change because scope will + // change later. getInvokingCommandKeySequences(); } + this.treeStyle = treeStyle; + // Title and status text must be set to get the title label created, so + // force empty values here. + if (hasHeader()) + this.setTitleText(""); //$NON-NLS-1$ + this.setInfoText(""); // //$NON-NLS-1$ + + // Create all controls early to preserve the life cycle of the original + // implementation. + create(); + + // Status field text can only be computed after widgets are created. + this.setInfoText(getStatusFieldText()); + } - 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.setLayout(layout); - fComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - - fViewMenuButtonComposite= new Composite(fComposite, SWT.NONE); - layout= new GridLayout(2, false); - layout.marginHeight= 0; - layout.marginWidth= 0; - fViewMenuButtonComposite.setLayout(layout); - fViewMenuButtonComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - + /** + * 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 AbstractInformationControl(Shell parent, int shellStyle, + int treeStyle) { + this(parent, shellStyle, treeStyle, null, false); + } + /* + * Overridden to insert the filter text into the title and menu area. + * + * @since 3.2 + */ + protected Control createTitleMenuArea(Composite parent) { + fViewMenuButtonComposite = (Composite)super.createTitleMenuArea(parent); + + // If there is a header, then the filter text must be created + // underneath the title and menu area. + if (hasHeader()) { - createHeader(fViewMenuButtonComposite); - fFilterText= createFilterText(fComposite); - } else { - fFilterText= createFilterText(fViewMenuButtonComposite); + fFilterText = createFilterText(parent); } + + // Create a key binding for showing the dialog menu + // Key binding service + IWorkbenchPart part = JavaPlugin.getActivePage().getActivePart(); + IWorkbenchPartSite site = part.getSite(); + fKeyBindingService = site.getKeyBindingService(); - createViewMenu(fViewMenuButtonComposite); - - createHorizontalSeparator(fComposite); + // Remember current scope and then set window context. + fKeyBindingScopes = fKeyBindingService.getScopes(); + fKeyBindingService + .setScopes(new String[] { IWorkbenchContextSupport.CONTEXT_ID_WINDOW }); - fTreeViewer= createTreeViewer(fComposite, treeStyle); + // Create show view menu action + fShowViewMenuAction = new Action("showViewMenu") { //$NON-NLS-1$ + /* + * @see org.eclipse.jface.action.Action#run() + */ + public void run() { + showDialogMenu(); + } + }; + fShowViewMenuAction.setEnabled(true); + fShowViewMenuAction + .setActionDefinitionId("org.eclipse.ui.window.showViewMenu"); //$NON-NLS-1$ - fCustomFiltersActionGroup= new CustomFiltersActionGroup(getId(), fTreeViewer); + // Register action with command support + fShowViewMenuHandlerSubmission = new HandlerSubmission(null, getShell(), + null, fShowViewMenuAction.getActionDefinitionId(), + new ActionHandler(fShowViewMenuAction), Priority.MEDIUM); + PlatformUI.getWorkbench().getCommandSupport().addHandlerSubmission( + fShowViewMenuHandlerSubmission); + + return fViewMenuButtonComposite; + } + + /* + * Overridden to insert the filter text into the title control + * if there is no header specified. + * @since 3.2 + */ + protected Control createTitleControl(Composite parent) { + if (hasHeader()) { + return super.createTitleControl(parent); + } + fFilterText = createFilterText(parent); + return fFilterText; + } + + /** + * Create the main content for this information control. + * + * @param parent + * The parent composite + * @return The control representing the main content. + * + * @since 3.2 + */ + protected Control createMainContent(Composite parent) { + fTreeViewer = createTreeViewer(parent, treeStyle); - if (showStatusField) - createStatusField(fComposite); + fCustomFiltersActionGroup = new CustomFiltersActionGroup(getId(), + fTreeViewer); - final Tree tree= fTreeViewer.getTree(); + final Tree tree = fTreeViewer.getTree(); tree.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 } @@ -417,34 +336,37 @@ public void widgetSelected(SelectionEvent e) { // do nothing } + public void widgetDefaultSelected(SelectionEvent e) { gotoSelectedElement(); } }); - tree.addMouseMoveListener(new MouseMoveListener() { - TreeItem fLastItem= null; + tree.addMouseMoveListener(new MouseMoveListener() { + TreeItem fLastItem = null; + public void mouseMove(MouseEvent e) { if (tree.equals(e.getSource())) { - Object o= tree.getItem(new Point(e.x, e.y)); + Object o = tree.getItem(new Point(e.x, e.y)); if (o instanceof TreeItem) { if (!o.equals(fLastItem)) { - fLastItem= (TreeItem)o; + fLastItem = (TreeItem) o; tree.setSelection(new TreeItem[] { fLastItem }); } else if (e.y < tree.getItemHeight() / 4) { // Scroll up - Point p= tree.toDisplay(e.x, e.y); - Item item= fTreeViewer.scrollUp(p.x, p.y); + Point p = tree.toDisplay(e.x, e.y); + Item item = fTreeViewer.scrollUp(p.x, p.y); if (item instanceof TreeItem) { - fLastItem= (TreeItem)item; + fLastItem = (TreeItem) item; tree.setSelection(new TreeItem[] { fLastItem }); } - } else if (e.y > tree.getBounds().height - tree.getItemHeight() / 4) { + } else if (e.y > tree.getBounds().height + - tree.getItemHeight() / 4) { // Scroll down - Point p= tree.toDisplay(e.x, e.y); - Item item= fTreeViewer.scrollDown(p.x, p.y); + Point p = tree.toDisplay(e.x, e.y); + Item item = fTreeViewer.scrollDown(p.x, p.y); if (item instanceof TreeItem) { - fLastItem= (TreeItem)item; + fLastItem = (TreeItem) item; tree.setSelection(new TreeItem[] { fLastItem }); } } @@ -463,94 +385,36 @@ return; if (tree.equals(e.getSource())) { - Object o= tree.getItem(new Point(e.x, e.y)); - TreeItem selection= tree.getSelection()[0]; + Object o = tree.getItem(new Point(e.x, e.y)); + TreeItem selection = tree.getSelection()[0]; if (selection.equals(o)) gotoSelectedElement(); } } }); - int border= ((shellStyle & SWT.NO_TRIM) == 0) ? 0 : BORDER; - fShell.setLayout(new BorderFillLayout(border)); - - if (hasHeader()) { - fComposite.setTabList(new Control[] {fFilterText, fTreeViewer.getTree()}); - } else { - fViewMenuButtonComposite.setTabList(new Control[] {fFilterText}); - fComposite.setTabList(new Control[] {fViewMenuButtonComposite, fTreeViewer.getTree()}); - } - - setInfoSystemColor(); installFilter(); addDisposeListener(this); - fDeactivateListener= new Listener() { - /* - * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event) - */ - public void handleEvent(Event event) { - if (fIsDecativateListenerActive) - dispose(); - } - }; - fShell.addListener(SWT.Deactivate, fDeactivateListener); - fIsDecativateListenerActive= true; - fShell.addShellListener(new ShellAdapter() { - /* - * @see org.eclipse.swt.events.ShellAdapter#shellActivated(org.eclipse.swt.events.ShellEvent) - */ - public void shellActivated(ShellEvent e) { - if (e.widget == fShell && fShell.getShells().length == 0) - fIsDecativateListenerActive= true; - } - }); - - fShell.addControlListener(new ControlAdapter() { - /** - * {@inheritDoc} - */ - public void controlMoved(ControlEvent e) { - fBounds= fShell.getBounds(); - if (fTrim != null) { - Point location= fComposite.getLocation(); - fBounds.x= fBounds.x - fTrim.x + location.x; - fBounds.y= fBounds.y - fTrim.y + location.y; - } - - } - - /** - * {@inheritDoc} - */ - public void controlResized(ControlEvent e) { - fBounds= fShell.getBounds(); - if (fTrim != null) { - Point location= fComposite.getLocation(); - fBounds.x= fBounds.x - fTrim.x + location.x; - fBounds.y= fBounds.y - fTrim.y + location.y; - } - } - }); + return fTreeViewer.getControl(); } - - /** - * 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 AbstractInformationControl(Shell parent, int shellStyle, int treeStyle) { - this(parent, shellStyle, treeStyle, null, false); + + protected void setTabOrder(Composite composite) { + if (hasHeader()) { + composite.setTabList(new Control[] { fFilterText, + fTreeViewer.getTree() }); + } else { + fViewMenuButtonComposite.setTabList(new Control[] { fFilterText }); + composite.setTabList(new Control[] { fViewMenuButtonComposite, + fTreeViewer.getTree() }); + } } protected abstract TreeViewer createTreeViewer(Composite parent, int style); /** * Returns the name of the dialog settings section. - * + * * @return the name of the dialog settings section */ protected abstract String getId(); @@ -567,10 +431,12 @@ /** * Creates a header for this information control. *

- * Note: The header is only be created if {@link #hasHeader()} returns true. + * Note: The header is only be created if {@link #hasHeader()} returns + * true. *

- * + * * @param parent + * @deprecated use PopupDialog#createTitleControl instead. */ protected void createHeader(Composite parent) { // default is to have no header @@ -581,17 +447,17 @@ } protected Text createFilterText(Composite parent) { - fFilterText= new Text(parent, SWT.NONE); + fFilterText = new Text(parent, SWT.NONE); - GridData data= new GridData(GridData.FILL_HORIZONTAL); - GC gc= new GC(parent); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + GC gc = new GC(parent); gc.setFont(parent.getFont()); - FontMetrics fontMetrics= gc.getFontMetrics(); + FontMetrics fontMetrics = gc.getFontMetrics(); gc.dispose(); - data.heightHint= Dialog.convertHeightInCharsToPixels(fontMetrics, 1); - data.horizontalAlignment= GridData.FILL; - data.verticalAlignment= GridData.CENTER; + data.heightHint = Dialog.convertHeightInCharsToPixels(fontMetrics, 1); + data.horizontalAlignment = GridData.FILL; + data.verticalAlignment = GridData.CENTER; fFilterText.setLayoutData(data); fFilterText.addKeyListener(new KeyListener() { @@ -605,6 +471,7 @@ if (e.character == 0x1B) // ESC dispose(); } + public void keyReleased(KeyEvent e) { // do nothing } @@ -614,107 +481,13 @@ } protected void createHorizontalSeparator(Composite parent) { - 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)); } - private void createViewMenu(Composite toolbar) { - fToolBar= new ToolBar(toolbar, SWT.FLAT); - ToolItem viewMenuButton= new ToolItem(fToolBar, SWT.PUSH, 0); - - GridData data= new GridData(); - data.horizontalAlignment= GridData.END; - data.verticalAlignment= GridData.BEGINNING; - fToolBar.setLayoutData(data); - - viewMenuButton.setImage(JavaPluginImages.get(JavaPluginImages.IMG_ELCL_VIEW_MENU)); - viewMenuButton.setDisabledImage(JavaPluginImages.get(JavaPluginImages.IMG_DLCL_VIEW_MENU)); - viewMenuButton.setToolTipText(TextMessages.AbstractInformationControl_viewMenu_toolTipText); - viewMenuButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - showViewMenu(); - } - }); - - - // Key binding service - IWorkbenchPart part= JavaPlugin.getActivePage().getActivePart(); - IWorkbenchPartSite site= part.getSite(); - fKeyBindingService= site.getKeyBindingService(); - - // Remember current scope and then set window context. - fKeyBindingScopes= fKeyBindingService.getScopes(); - fKeyBindingService.setScopes(new String[] {IWorkbenchContextSupport.CONTEXT_ID_WINDOW}); - - // Create show view menu action - fShowViewMenuAction= new Action("showViewMenu") { //$NON-NLS-1$ - /* - * @see org.eclipse.jface.action.Action#run() - */ - public void run() { - showViewMenu(); - } - }; - fShowViewMenuAction.setEnabled(true); - fShowViewMenuAction.setActionDefinitionId("org.eclipse.ui.window.showViewMenu"); //$NON-NLS-1$ - - // Register action with command support - fShowViewMenuHandlerSubmission= new HandlerSubmission(null, fShell, null, fShowViewMenuAction.getActionDefinitionId(), new ActionHandler(fShowViewMenuAction), Priority.MEDIUM); - PlatformUI.getWorkbench().getCommandSupport().addHandlerSubmission(fShowViewMenuHandlerSubmission); - } - - private MenuManager getViewMenuManager() { - if (fViewMenuManager == null) { - fViewMenuManager= new MenuManager(); - fillViewMenu(fViewMenuManager); - } - return fViewMenuManager; - } - - private void showViewMenu( ) { - fIsDecativateListenerActive= false; - - Menu aMenu = getViewMenuManager().createContextMenu(fShell); - - Rectangle bounds = fToolBar.getBounds(); - Point topLeft = new Point(bounds.x, bounds.y + bounds.height); - topLeft = fShell.toDisplay(topLeft); - aMenu.setLocation(topLeft.x, topLeft.y); - - aMenu.setVisible(true); - } - - private void createStatusField(Composite parent) { - - Composite composite= new Composite(parent, SWT.NONE); - GridLayout layout= new GridLayout(1, false); - layout.marginHeight= 0; - layout.marginWidth= 0; - composite.setLayout(layout); - composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - // Horizontal separator line - Label separator= new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.LINE_DOT); - separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - // Status field label - fStatusField= new Label(parent, SWT.RIGHT); - fStatusField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - fStatusField.setText(getStatusFieldText()); - Font font= fStatusField.getFont(); - Display display= parent.getDisplay(); - FontData[] fontDatas= font.getFontData(); - for (int i= 0; i < fontDatas.length; i++) - fontDatas[i].setHeight(fontDatas[i].getHeight() * 9 / 10); - fStatusTextFont= new Font(display, fontDatas); - fStatusField.setFont(fStatusTextFont); - - fStatusField.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW)); - } - protected void updateStatusFieldText() { - if (fStatusField != null) - fStatusField.setText(getStatusFieldText()); + setInfoText(getStatusFieldText()); } /** @@ -730,21 +503,15 @@ return ""; //$NON-NLS-1$ } - private void setInfoSystemColor() { - Display display= fShell.getDisplay(); - setForegroundColor(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND)); - setBackgroundColor(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); - } - private void installFilter() { fFilterText.setText(""); //$NON-NLS-1$ fFilterText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { - String text= ((Text) e.widget).getText(); - int length= text.length(); - if (length > 0 && text.charAt(length -1 ) != '*') { - text= text + '*'; + String text = ((Text) e.widget).getText(); + int length = text.length(); + if (length > 0 && text.charAt(length - 1) != '*') { + text = text + '*'; } setMatcherString(text); } @@ -767,19 +534,19 @@ /** * 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 *

- * - * @param pattern the pattern + * + * @param pattern + * the pattern */ protected void setMatcherString(String pattern) { if (pattern.length() == 0) { - fStringMatcher= null; + fStringMatcher = null; } else { - boolean ignoreCase= pattern.toLowerCase().equals(pattern); - fStringMatcher= new StringMatcher(pattern, ignoreCase, false); + boolean ignoreCase = pattern.toLowerCase().equals(pattern); + fStringMatcher = new StringMatcher(pattern, ignoreCase, false); } stringMatcherUpdated(); } @@ -790,18 +557,19 @@ /** * Implementers can modify - * + * * @return the selected element */ protected Object getSelectedElement() { if (fTreeViewer == null) return null; - return ((IStructuredSelection) fTreeViewer.getSelection()).getFirstElement(); + return ((IStructuredSelection) fTreeViewer.getSelection()) + .getFirstElement(); } private void gotoSelectedElement() { - Object selectedElement= getSelectedElement(); + Object selectedElement = getSelectedElement(); if (selectedElement != null) { try { dispose(); @@ -813,12 +581,12 @@ } /** - * 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. */ protected 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 @@ -826,19 +594,20 @@ } 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; } @@ -858,21 +627,25 @@ public abstract void setInput(Object information); /** - * Fills the view menu. - * Clients can extend or override. - * - * @param viewMenu the menu manager that manages the menu + * Fills the view menu. Clients can extend or override. + * + * @param viewMenu + * the menu manager that manages the menu * @since 3.0 */ protected void fillViewMenu(IMenuManager viewMenu) { - viewMenu.add(new GroupMarker("SystemMenuStart")); //$NON-NLS-1$ - viewMenu.add(new MoveAction()); - viewMenu.add(new ResizeAction()); - viewMenu.add(new RememberBoundsAction()); - viewMenu.add(new Separator("SystemMenuEnd")); //$NON-NLS-1$ - fCustomFiltersActionGroup.fillViewMenu(viewMenu); } + + /* + * Overridden to call the old framework method. + * + * @see org.eclipse.jface.dialogs.PopupDialog#fillDialogMenu(IMenuManager) + */ + protected void fillDialogMenu(IMenuManager dialogMenu) { + super.fillDialogMenu(dialogMenu); + fillViewMenu(dialogMenu); + } protected void inputChanged(Object newInput, Object newSelection) { fFilterText.setText(""); //$NON-NLS-1$ @@ -886,45 +659,44 @@ * {@inheritDoc} */ public void setVisible(boolean visible) { - if (visible || fIsDecativateListenerActive) - fShell.setVisible(visible); + if (visible) + open(); + else { + saveDialogBounds(getShell()); + getShell().setVisible(false); + } } /** * {@inheritDoc} */ public final void dispose() { - if (fShell != null && !fShell.isDisposed()) - fShell.dispose(); - else - widgetDisposed(null); + close(); } /** * {@inheritDoc} - * @param event can be null - *

- * Subclasses may extend. - *

+ * + * @param event + * can be null + *

+ * Subclasses may extend. + *

*/ public void widgetDisposed(DisposeEvent event) { - if (fStatusTextFont != null && !fStatusTextFont.isDisposed()) - fStatusTextFont.dispose(); - fShell= null; - fTreeViewer= null; - fComposite= null; - fFilterText= null; - fStatusTextFont= null; + fTreeViewer = null; + fFilterText = null; // Remove handler submission - PlatformUI.getWorkbench().getCommandSupport().removeHandlerSubmission(fShowViewMenuHandlerSubmission); + PlatformUI.getWorkbench().getCommandSupport().removeHandlerSubmission( + fShowViewMenuHandlerSubmission); // Restore editor's key binding scope if (fKeyBindingScopes != null && fKeyBindingService != null) { fKeyBindingService.setScopes(fKeyBindingScopes); - fKeyBindingScopes= null; - fKeyBindingService= null; + fKeyBindingScopes = null; + fKeyBindingService = null; } } @@ -940,13 +712,13 @@ */ public void setSizeConstraints(int maxWidth, int maxHeight) { if (maxWidth > -1 && maxHeight > -1) { - GridData gd= new GridData(GridData.FILL_BOTH); + GridData gd = new GridData(GridData.FILL_BOTH); if (maxWidth > -1) - gd.widthHint= maxWidth; + gd.widthHint = maxWidth; if (maxHeight > -1) - gd.heightHint= maxHeight; + gd.heightHint = maxHeight; - fShell.setLayoutData(gd); + getShell().setLayoutData(gd); } } @@ -954,29 +726,30 @@ * {@inheritDoc} */ public Point computeSizeHint() { - return fShell.computeSize(SWT.DEFAULT, SWT.DEFAULT); + return getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT); } /** * {@inheritDoc} + * * @since 3.0 */ public Rectangle getBounds() { - return fBounds; + return getShell().getBounds(); } /* * @see org.eclipse.jface.text.IInformationControlExtension3#restoresLocation() */ public boolean restoresLocation() { - return !getDialogSettings().getBoolean(STORE_DISABLE_RESTORE_LOCATION); + return getPersistBounds(); } /* * @see org.eclipse.jface.text.IInformationControlExtension3#restoresSize() */ public boolean restoresSize() { - return !getDialogSettings().getBoolean(STORE_DISABLE_RESTORE_SIZE); + return getPersistBounds(); } /* @@ -992,76 +765,61 @@ * {@inheritDoc} */ public void setLocation(Point location) { - fTrim= fShell.computeTrim(0, 0, 0, 0); - Point compositeLocation= fComposite.getLocation(); + fTrim = getShell().computeTrim(0, 0, 0, 0); + Point compositeLocation = getContents().getLocation(); location.x += fTrim.x - compositeLocation.x; location.y += fTrim.y - compositeLocation.y; - fShell.setLocation(location); + getShell().setLocation(location); } /** * {@inheritDoc} */ public void setSize(int width, int height) { - fShell.setSize(width, height); + getShell().setSize(width, height); } /** * {@inheritDoc} */ public void addDisposeListener(DisposeListener listener) { - fShell.addDisposeListener(listener); + getShell().addDisposeListener(listener); } /** * {@inheritDoc} */ public void removeDisposeListener(DisposeListener listener) { - fShell.removeDisposeListener(listener); + getShell().removeDisposeListener(listener); } /** * {@inheritDoc} */ public void setForegroundColor(Color foreground) { - fTreeViewer.getTree().setForeground(foreground); - fFilterText.setForeground(foreground); - fComposite.setForeground(foreground); - fViewMenuButtonComposite.setForeground(foreground); - if (fStatusField != null) - fStatusField.getParent().setForeground(foreground); + applyForegroundColor(foreground, getContents()); } /** * {@inheritDoc} */ public void setBackgroundColor(Color background) { - fTreeViewer.getTree().setBackground(background); - fFilterText.setBackground(background); - fComposite.setBackground(background); - fViewMenuButtonComposite.setBackground(background); - if (fStatusField != null) { - fStatusField.setBackground(background); - fStatusField.getParent().setBackground(background); - } - if (fViewMenuButton != null) - fViewMenuButton.setBackground(background); - if (fToolBar != null) - fToolBar.setBackground(background); + applyBackgroundColor(background, getContents()); } /** * {@inheritDoc} */ public boolean isFocusControl() { - return fTreeViewer.getControl().isFocusControl() || fFilterText.isFocusControl(); + return fTreeViewer.getControl().isFocusControl() + || fFilterText.isFocusControl(); } /** * {@inheritDoc} */ public void setFocus() { - fShell.forceFocus(); + getShell().forceFocus(); fFilterText.setFocus(); } @@ -1069,14 +827,14 @@ * {@inheritDoc} */ public void addFocusListener(FocusListener listener) { - fShell.addFocusListener(listener); + getShell().addFocusListener(listener); } /** * {@inheritDoc} */ public void removeFocusListener(FocusListener listener) { - fShell.removeFocusListener(listener); + getShell().removeFocusListener(listener); } final protected ICommand getInvokingCommand() { @@ -1086,11 +844,12 @@ final protected KeySequence[] getInvokingCommandKeySequences() { if (fInvokingCommandKeySequences == null) { if (getInvokingCommand() != null) { - List list= getInvokingCommand().getKeySequenceBindings(); + List list = getInvokingCommand().getKeySequenceBindings(); if (!list.isEmpty()) { - fInvokingCommandKeySequences= new KeySequence[list.size()]; - for (int i= 0; i < fInvokingCommandKeySequences.length; i++) { - fInvokingCommandKeySequences[i]= ((IKeySequenceBinding) list.get(i)).getKeySequence(); + fInvokingCommandKeySequences = new KeySequence[list.size()]; + for (int i = 0; i < fInvokingCommandKeySequences.length; i++) { + fInvokingCommandKeySequences[i] = ((IKeySequenceBinding) list + .get(i)).getKeySequence(); } return fInvokingCommandKeySequences; } @@ -1100,11 +859,13 @@ } protected IDialogSettings getDialogSettings() { - String sectionName= getId(); + String sectionName = getId(); - IDialogSettings settings= JavaPlugin.getDefault().getDialogSettings().getSection(sectionName); + IDialogSettings settings = JavaPlugin.getDefault().getDialogSettings() + .getSection(sectionName); if (settings == null) - settings= JavaPlugin.getDefault().getDialogSettings().addNewSection(sectionName); + settings = JavaPlugin.getDefault().getDialogSettings() + .addNewSection(sectionName); return settings; } Index: ui/org/eclipse/jdt/internal/ui/typehierarchy/HierarchyInformationControl.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/typehierarchy/HierarchyInformationControl.java,v retrieving revision 1.29 diff -u -r1.29 HierarchyInformationControl.java --- ui/org/eclipse/jdt/internal/ui/typehierarchy/HierarchyInformationControl.java 18 Aug 2005 16:59:40 -0000 1.29 +++ ui/org/eclipse/jdt/internal/ui/typehierarchy/HierarchyInformationControl.java 7 Oct 2005 22:15:17 -0000 @@ -15,15 +15,12 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.events.KeyAdapter; import org.eclipse.swt.events.KeyEvent; -import org.eclipse.swt.graphics.Color; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Tree; -import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.viewers.AbstractTreeViewer; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; @@ -66,7 +63,6 @@ private TypeHierarchyLifeCycle fLifeCycle; private HierarchyLabelProvider fLabelProvider; - private Label fHeaderLabel; private KeyAdapter fKeyAdapter; private Object[] fOtherExpandedElements; @@ -113,16 +109,6 @@ protected boolean hasHeader() { return true; } - - /** - * {@inheritDoc} - */ - protected void createHeader(Composite parent) { - fHeaderLabel= new Label(parent, SWT.NONE); - // text set later - fHeaderLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - fHeaderLabel.setFont(JFaceResources.getBannerFont()); - } protected Text createFilterText(Composite parent) { // text set later @@ -211,24 +197,7 @@ return fMethodOverrideTester.findOverridingMethod(filterMethod, typeToFindIn); } } - - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.ui.text.AbstractInformationControl#setForegroundColor(org.eclipse.swt.graphics.Color) - */ - public void setForegroundColor(Color foreground) { - super.setForegroundColor(foreground); - fHeaderLabel.setForeground(foreground); - } - - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.ui.text.AbstractInformationControl#setBackgroundColor(org.eclipse.swt.graphics.Color) - */ - public void setBackgroundColor(Color background) { - super.setBackgroundColor(background); - fHeaderLabel.setBackground(background); - } - /** * {@inheritDoc} */ @@ -288,7 +257,7 @@ JavaPlugin.log(e); } - fHeaderLabel.setText(getHeaderLabel(locked == null ? input : locked)); + super.setTitleText(getHeaderLabel(locked == null ? input : locked)); try { fLifeCycle.ensureRefreshedTypeHierarchy(input, JavaPlugin.getActiveWorkbenchWindow()); } catch (InvocationTargetException e1) {