### Eclipse Workspace Patch 1.0 #P org.eclipse.ui.workbench Index: Eclipse UI/org/eclipse/ui/internal/CycleBaseHandler.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/CycleBaseHandler.java,v retrieving revision 1.2 diff -u -r1.2 CycleBaseHandler.java --- Eclipse UI/org/eclipse/ui/internal/CycleBaseHandler.java 30 Oct 2007 22:45:35 -0000 1.2 +++ Eclipse UI/org/eclipse/ui/internal/CycleBaseHandler.java 27 Nov 2007 16:13:24 -0000 @@ -103,7 +103,9 @@ IWorkbenchPage page = window.getActivePage(); IWorkbenchPart activePart= page.getActivePart(); + getTriggers(); openDialog((WorkbenchPage) page, activePart); + clearTriggers(); activate(page, selection); return null; @@ -125,14 +127,14 @@ table.setLinesVisible(true); TableColumn tc = new TableColumn(table, SWT.NONE); tc.setResizable(false); - tc.setText(getTableHeader()); + tc.setText(getTableHeader(activePart)); addItems(table, page); int tableItemCount = table.getItemCount(); switch (tableItemCount) { case 0: - // do nothing; - break; + cancel(dialog); + return; case 1: table.setSelection(0); break; @@ -164,6 +166,37 @@ } }); + setDialogLocation(dialog, activePart); + + final IContextService contextService = (IContextService) window + .getWorkbench().getService(IContextService.class); + try { + dialog.open(); + addMouseListener(table, dialog); + contextService.registerShell(dialog, IContextService.TYPE_NONE); + addKeyListener(table, dialog); + addTraverseListener(table); + + while (!dialog.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + } finally { + if (!dialog.isDisposed()) { + cancel(dialog); + } + contextService.unregisterShell(dialog); + } + } + + /** + * Sets the dialog's location on the screen. + * + * @param dialog + */ + protected void setDialogLocation(final Shell dialog, IWorkbenchPart activePart) { + Display display = dialog.getDisplay(); Rectangle dialogBounds = dialog.getBounds(); Rectangle parentBounds = dialog.getParent().getBounds(); @@ -189,48 +222,30 @@ } dialog.setLocation(dialogBounds.x, dialogBounds.y); + } - /* - * Fetch the key bindings for the forward and backward commands. They - * will not change while the dialog is open, but the context will. Bug - * 55581. - */ + /** + * Clears the forward and backward trigger sequences. + */ + protected void clearTriggers() { + forwardTriggerSequences = null; + backwardTriggerSequences = null; + } + + /** + * Fetch the key bindings for the forward and backward commands. They will + * not change while the dialog is open, but the context will. Bug 55581. + */ + protected void getTriggers() { commandForward = getForwardCommand(); commandBackward = getBackwardCommand(); - /* - * Fetch the key bindings for the forward and backward commands. They - * will not change while the dialog is open, but the context will. Bug - * 55581. - */ + final IBindingService bindingService = (IBindingService) window .getWorkbench().getService(IBindingService.class); forwardTriggerSequences = bindingService .getActiveBindingsFor(commandForward); backwardTriggerSequences = bindingService .getActiveBindingsFor(commandBackward); - - final IContextService contextService = (IContextService) window - .getWorkbench().getService(IContextService.class); - try { - dialog.open(); - addMouseListener(table, dialog); - contextService.registerShell(dialog, IContextService.TYPE_NONE); - addKeyListener(table, dialog); - addTraverseListener(table); - - while (!dialog.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - } finally { - if (!dialog.isDisposed()) { - cancel(dialog); - } - contextService.unregisterShell(dialog); - forwardTriggerSequences = null; - backwardTriggerSequences = null; - } } protected void addKeyListener(final Table table, final Shell dialog) { @@ -380,7 +395,6 @@ IPerspectiveDescriptor persp = (IPerspectiveDescriptor) selectedItem; page.setPerspective(persp); } - } } @@ -424,7 +438,7 @@ }); } - protected abstract String getTableHeader(); + protected abstract String getTableHeader(IWorkbenchPart activePart); // return WorkbenchMessages.CyclePartAction_header; Index: Eclipse UI/org/eclipse/ui/internal/CyclePerspectiveHandler.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/CyclePerspectiveHandler.java,v retrieving revision 1.2 diff -u -r1.2 CyclePerspectiveHandler.java --- Eclipse UI/org/eclipse/ui/internal/CyclePerspectiveHandler.java 23 May 2007 14:31:32 -0000 1.2 +++ Eclipse UI/org/eclipse/ui/internal/CyclePerspectiveHandler.java 27 Nov 2007 16:13:24 -0000 @@ -17,6 +17,7 @@ import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableItem; import org.eclipse.ui.IPerspectiveDescriptor; +import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.commands.ICommandService; import org.eclipse.ui.model.PerspectiveLabelProvider; @@ -74,7 +75,7 @@ /* (non-Javadoc) * @see org.eclipse.ui.internal.CycleBaseHandler#getTableHeader() */ - protected String getTableHeader() { + protected String getTableHeader(IWorkbenchPart activePart) { return WorkbenchMessages.CyclePerspectiveAction_header; } Index: Eclipse UI/org/eclipse/ui/internal/CycleEditorHandler.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/CycleEditorHandler.java,v retrieving revision 1.1 diff -u -r1.1 CycleEditorHandler.java --- Eclipse UI/org/eclipse/ui/internal/CycleEditorHandler.java 17 Apr 2007 12:06:16 -0000 1.1 +++ Eclipse UI/org/eclipse/ui/internal/CycleEditorHandler.java 27 Nov 2007 16:13:24 -0000 @@ -17,6 +17,7 @@ import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableItem; import org.eclipse.ui.IEditorReference; +import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.commands.ICommandService; /** @@ -71,7 +72,7 @@ /* (non-Javadoc) * @see org.eclipse.ui.internal.CycleBaseHandler#getTableHeader() */ - protected String getTableHeader() { + protected String getTableHeader(IWorkbenchPart activePart) { // TODO Auto-generated method stub return WorkbenchMessages.CycleEditorAction_header; } Index: Eclipse UI/org/eclipse/ui/internal/CycleViewHandler.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/CycleViewHandler.java,v retrieving revision 1.1 diff -u -r1.1 CycleViewHandler.java --- Eclipse UI/org/eclipse/ui/internal/CycleViewHandler.java 17 Apr 2007 12:06:16 -0000 1.1 +++ Eclipse UI/org/eclipse/ui/internal/CycleViewHandler.java 27 Nov 2007 16:13:24 -0000 @@ -17,6 +17,7 @@ import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableItem; import org.eclipse.ui.IEditorReference; +import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchPartReference; import org.eclipse.ui.commands.ICommandService; @@ -83,7 +84,7 @@ /* (non-Javadoc) * @see org.eclipse.ui.internal.CycleBaseHandler#getTableHeader() */ - protected String getTableHeader() { + protected String getTableHeader(IWorkbenchPart activePart) { // TODO Auto-generated method stub return WorkbenchMessages.CyclePartAction_header; } Index: Eclipse UI/org/eclipse/ui/internal/handlers/CyclePageHandler.java =================================================================== RCS file: Eclipse UI/org/eclipse/ui/internal/handlers/CyclePageHandler.java diff -N Eclipse UI/org/eclipse/ui/internal/handlers/CyclePageHandler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ Eclipse UI/org/eclipse/ui/internal/handlers/CyclePageHandler.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,199 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + ******************************************************************************/ + +package org.eclipse.ui.internal.handlers; + +import org.eclipse.core.commands.Command; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.ParameterizedCommand; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.commands.ICommandService; +import org.eclipse.ui.internal.CycleBaseHandler; +import org.eclipse.ui.internal.PartSite; +import org.eclipse.ui.internal.WorkbenchPage; +import org.eclipse.ui.part.PageSwitcher; +import org.eclipse.ui.part.WorkbenchPart; + +/** + * Displays a dialog for cycling through pages of a view. A view may implement + * its pages however it wishes. As long as the view provides + * {@link IPageManager} behavior to return a {@link IPageSwitcher} object, + * {@link CyclePageHandler} will handle the cycling of pages. + * + * @since 3.4 + * + */ +public class CyclePageHandler extends CycleBaseHandler { + + /** + * The character limit before text is truncated. + */ + private static final int TEXT_LIMIT = 65; + private static final String COMMAND_PREVIOUS_PAGE = "org.eclipse.ui.part.previousPage"; //$NON-NLS-1$ + private static final String COMMAND_NEXT_PAGE = "org.eclipse.ui.part.nextPage"; //$NON-NLS-1$ + + private PageSwitcher pageSwitcher; + + public CyclePageHandler(PageSwitcher pageSwitcher) { + this.pageSwitcher = pageSwitcher; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.internal.CycleBaseHandler#addItems(org.eclipse.swt.widgets.Table, + * org.eclipse.ui.internal.WorkbenchPage) + */ + protected void addItems(Table table, WorkbenchPage page) { + Object[] pages = pageSwitcher.getPages(); + for (int i = 0; i < pages.length; i++) { + org.eclipse.swt.widgets.TableItem item = null; + item = new TableItem(table, SWT.NONE); + ImageDescriptor imageDescriptor = pageSwitcher + .getImageDescriptor(pages[i]); + if (imageDescriptor != null) { + item.setImage(imageDescriptor.createImage()); + } + item.setData(pages[i]); + String name = pageSwitcher.getName(pages[i]); + if (name.length() > TEXT_LIMIT) { + name = name.substring(0, TEXT_LIMIT) + "..."; //$NON-NLS-1$ + } + item.setText(name); + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.internal.CycleBaseHandler#getBackwardCommand() + */ + protected ParameterizedCommand getBackwardCommand() { + final ICommandService commandService = (ICommandService) window + .getWorkbench().getService(ICommandService.class); + final Command command = commandService + .getCommand(COMMAND_PREVIOUS_PAGE); + ParameterizedCommand commandF = new ParameterizedCommand(command, null); + return commandF; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.internal.CycleBaseHandler#getForwardCommand() + */ + protected ParameterizedCommand getForwardCommand() { + final ICommandService commandService = (ICommandService) window + .getWorkbench().getService(ICommandService.class); + final Command command = commandService.getCommand(COMMAND_NEXT_PAGE); + ParameterizedCommand commandF = new ParameterizedCommand(command, null); + return commandF; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.internal.CycleBaseHandler#getTableHeader() + */ + protected String getTableHeader(IWorkbenchPart activePart) { + if (activePart instanceof WorkbenchPart) { + return ((WorkbenchPart) activePart).getPartName(); + } + + return activePart.getTitle(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.internal.CycleBaseHandler#execute(org.eclipse.core.commands.ExecutionEvent) + */ + public Object execute(ExecutionEvent event) throws ExecutionException { + if (event.getCommand().getId().equals(COMMAND_NEXT_PAGE)) { + gotoDirection = true; + } else { + gotoDirection = false; + } + return super.execute(event); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.internal.CycleBaseHandler#setDialogLocation(org.eclipse.swt.widgets.Shell) + */ + protected void setDialogLocation(final Shell dialog, + IWorkbenchPart activePart) { + Display display = dialog.getDisplay(); + Rectangle dialogBounds = dialog.getBounds(); + WorkbenchPart workbenchPart = (WorkbenchPart) activePart; + Rectangle viewBounds = ((PartSite) workbenchPart.getSite()).getPane() + .getBounds(); + Rectangle parentBounds = ((PartSite) workbenchPart.getSite()) + .getShell().getBounds(); + + // the bounds of the monitor that contains the currently active part. + Rectangle monitorBounds = activePart == null ? display + .getPrimaryMonitor().getBounds() : ((PartSite) activePart + .getSite()).getPane().getControl().getMonitor().getBounds(); + + // Place it in the center of its parent; + dialogBounds.x = parentBounds.x + viewBounds.x + (viewBounds.width / 2) + - (dialogBounds.width / 2); + dialogBounds.y = parentBounds.y + viewBounds.y + + (viewBounds.height / 2) + (dialogBounds.height / 2); + if (!monitorBounds.contains(dialogBounds.x, dialogBounds.y) + || !monitorBounds.contains(dialogBounds.x + dialogBounds.width, + dialogBounds.y + dialogBounds.height)) { + // Place it in the center of the monitor if it is not visible + // when placed in the center of its parent; + dialogBounds.x = monitorBounds.x + + (monitorBounds.width - dialogBounds.width) / 2; + dialogBounds.y = monitorBounds.y + + (monitorBounds.height - dialogBounds.height) / 2; + } + + dialog.setLocation(dialogBounds.x, dialogBounds.y); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.core.commands.AbstractHandler#dispose() + */ + public void dispose() { + super.dispose(); + this.pageSwitcher = null; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.internal.CycleBaseHandler#activate(org.eclipse.ui.IWorkbenchPage, + * java.lang.Object) + */ + protected void activate(IWorkbenchPage page, Object selectedItem) { + if (selectedItem == null) { + return; + } + + pageSwitcher.activatePage(selectedItem); + } +} Index: Eclipse UI/org/eclipse/ui/part/PageSwitcher.java =================================================================== RCS file: Eclipse UI/org/eclipse/ui/part/PageSwitcher.java diff -N Eclipse UI/org/eclipse/ui/part/PageSwitcher.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ Eclipse UI/org/eclipse/ui/part/PageSwitcher.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + ******************************************************************************/ + +package org.eclipse.ui.part; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.handlers.IHandlerService; +import org.eclipse.ui.internal.handlers.CyclePageHandler; + +/** + * Provides the behavior for switching pages in a view. A view may track pages + * however it wishes. The view should subclass PageSwitcher to provide the + * abstract methods, and then instantiate their page switcher once, usually in + * IWorkbenchPart#createPartControl(Composite). + * + * + * @since 3.4 + * + */ +public abstract class PageSwitcher { + + private static final String COMMAND_PREVIOUS_PAGE = "org.eclipse.ui.part.previousPage"; //$NON-NLS-1$ + private static final String COMMAND_NEXT_PAGE = "org.eclipse.ui.part.nextPage"; //$NON-NLS-1$ + + public PageSwitcher(IWorkbenchPart part) { + IHandlerService service = (IHandlerService) part.getSite().getService( + IHandlerService.class); + service.activateHandler(COMMAND_NEXT_PAGE, new CyclePageHandler(this)); + service.activateHandler(COMMAND_PREVIOUS_PAGE, new CyclePageHandler( + this)); + } + + /** + * Displays the given page in the view. The page must already exist in the + * view. + * + * @param page + * the page to display, never null. + */ + public abstract void activatePage(Object page); + + /** + * Returns an {@link ImageDescriptor} for the page. + * + * @param page + * the page to retrieve an {@link ImageDescriptor} + * @return An {@link ImageDescriptor} for the page, may be null. + */ + public abstract ImageDescriptor getImageDescriptor(Object page); + + /** + * Returns a readable name to identify the page. + * + * @param page + * the page to get the name + * @return the name of the page + */ + public abstract String getName(Object page); + + /** + * Returns the pages available in the view. These may be used for populating + * the pop-up dialog when switching pages. These are the objects that will + * be used in activatePage(Object). + * + * @return an array of pages + */ + public abstract Object[] getPages(); +} #P org.eclipse.ui.console Index: src/org/eclipse/ui/internal/console/ConsoleView.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ConsoleView.java,v retrieving revision 1.45 diff -u -r1.45 ConsoleView.java --- src/org/eclipse/ui/internal/console/ConsoleView.java 27 Mar 2007 01:39:13 -0000 1.45 +++ src/org/eclipse/ui/internal/console/ConsoleView.java 27 Nov 2007 16:13:25 -0000 @@ -20,6 +20,7 @@ import org.eclipse.core.runtime.SafeRunner; import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.Separator; +import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.IBasicPropertyConstants; @@ -43,6 +44,7 @@ import org.eclipse.ui.part.MessagePage; import org.eclipse.ui.part.PageBook; import org.eclipse.ui.part.PageBookView; +import org.eclipse.ui.part.PageSwitcher; import org.eclipse.ui.progress.IWorkbenchSiteProgressService; /** @@ -95,6 +97,8 @@ private boolean fScrollLock; + private PageSwitcher pageSwitcher = null; + private boolean isAvailable() { return getPageBook() != null && !getPageBook().isDisposed(); } @@ -338,6 +342,7 @@ ConsoleManager consoleManager = (ConsoleManager) ConsolePlugin.getDefault().getConsoleManager(); consoleManager.removeConsoleListener(this); consoleManager.unregisterConsoleView(this); + pageSwitcher = null; } /** @@ -439,6 +444,38 @@ if (extensions.length > 0) { fOpenConsoleAction = new OpenConsoleAction(); } + + pageSwitcher = new PageSwitcher(this){ + + public void activatePage(Object page) { + if (page instanceof IConsole) { + IConsole console = (IConsole) page; + display(console); + } + } + + public ImageDescriptor getImageDescriptor(Object page) { + if (page instanceof IConsole) { + IConsole console = (IConsole) page; + return console.getImageDescriptor(); + } + + return null; + } + + public String getName(Object page) { + if (page instanceof IConsole) { + IConsole console = (IConsole) page; + return console.getName(); + } + + return null; + } + + public Object[] getPages() { + return getConsoleStack().toArray(); + } + }; } protected void configureToolBar(IToolBarManager mgr) { #P org.eclipse.ui Index: plugin.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui/plugin.properties,v retrieving revision 1.198 diff -u -r1.198 plugin.properties --- plugin.properties 22 Nov 2007 17:33:19 -0000 1.198 +++ plugin.properties 27 Nov 2007 16:13:26 -0000 @@ -177,6 +177,8 @@ command.next.name = Next command.nextEditor.description = Switch to the next editor command.nextEditor.name = Next Editor +command.nextPage.name = Next Page +command.nextPage.description = Switch to the next page command.nextPerspective.description = Switch to the next perspective command.nextPerspective.name = Next Perspective command.nextView.description = Switch to the next view @@ -194,6 +196,8 @@ command.previous.name = Previous command.previousEditor.description = Switch to the previous editor command.previousEditor.name = Previous Editor +command.previousPage.name = Previous Page +command.previousPage.description = Switch to the previous page command.previousPerspective.description = Switch to the previous perspective command.previousPerspective.name = Previous Perspective command.previousView.description = Switch to the previous view Index: plugin.xml =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui/plugin.xml,v retrieving revision 1.414 diff -u -r1.414 plugin.xml --- plugin.xml 23 Nov 2007 19:08:13 -0000 1.414 +++ plugin.xml 27 Nov 2007 16:13:26 -0000 @@ -626,6 +626,16 @@ parentId="org.eclipse.ui.defaultAcceleratorConfiguration" id="org.eclipse.ui.emacsAcceleratorConfiguration"> + + + + + + + +