Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 96846 invoked from network); 9 Mar 2010 05:46:17 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 9 Mar 2010 05:46:17 -0000 Received: (qmail 75406 invoked by uid 500); 9 Mar 2010 05:45:51 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 75348 invoked by uid 500); 9 Mar 2010 05:45:50 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 75338 invoked by uid 99); 9 Mar 2010 05:45:50 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Mar 2010 05:45:49 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Mar 2010 05:45:47 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id EA63A23889E7; Tue, 9 Mar 2010 05:45:24 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r920697 - /directory/studio/trunk/rcp/src/main/java/org/apache/directory/studio/ApplicationWorkbenchWindowAdvisor.java Date: Tue, 09 Mar 2010 05:45:24 -0000 To: commits@directory.apache.org From: seelmann@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100309054524.EA63A23889E7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: seelmann Date: Tue Mar 9 05:45:24 2010 New Revision: 920697 URL: http://svn.apache.org/viewvc?rev=920697&view=rev Log: Fix for DIRSTUDIO-625 (Add Connection Context in the LDAP Browser Window) Modified: directory/studio/trunk/rcp/src/main/java/org/apache/directory/studio/ApplicationWorkbenchWindowAdvisor.java Modified: directory/studio/trunk/rcp/src/main/java/org/apache/directory/studio/ApplicationWorkbenchWindowAdvisor.java URL: http://svn.apache.org/viewvc/directory/studio/trunk/rcp/src/main/java/org/apache/directory/studio/ApplicationWorkbenchWindowAdvisor.java?rev=920697&r1=920696&r2=920697&view=diff ============================================================================== --- directory/studio/trunk/rcp/src/main/java/org/apache/directory/studio/ApplicationWorkbenchWindowAdvisor.java (original) +++ directory/studio/trunk/rcp/src/main/java/org/apache/directory/studio/ApplicationWorkbenchWindowAdvisor.java Tue Mar 9 05:45:24 2010 @@ -21,7 +21,22 @@ package org.apache.directory.studio; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProduct; +import org.eclipse.core.runtime.Platform; +import org.eclipse.osgi.util.NLS; import org.eclipse.swt.graphics.Point; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IEditorReference; +import org.eclipse.ui.IPageListener; +import org.eclipse.ui.IPartListener2; +import org.eclipse.ui.IPerspectiveDescriptor; +import org.eclipse.ui.IPropertyListener; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPartConstants; +import org.eclipse.ui.IWorkbenchPartReference; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PerspectiveAdapter; import org.eclipse.ui.application.ActionBarAdvisor; import org.eclipse.ui.application.IActionBarConfigurer; import org.eclipse.ui.application.IWorkbenchWindowConfigurer; @@ -54,6 +69,30 @@ import org.eclipse.ui.application.Workbe public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { + private IEditorPart lastActiveEditor = null; + private IPerspectiveDescriptor lastPerspective = null; + private IWorkbenchPage lastActivePage; + private String lastEditorTitle = ""; //$NON-NLS-1$ + private IAdaptable lastInput; + private IPropertyListener editorPropertyListener = new IPropertyListener() + { + public void propertyChanged( Object source, int propId ) + { + if ( propId == IWorkbenchPartConstants.PROP_TITLE ) + { + if ( lastActiveEditor != null ) + { + String newTitle = lastActiveEditor.getTitle(); + if ( !lastEditorTitle.equals( newTitle ) ) + { + recomputeTitle(); + } + } + } + } + }; + + /** * Default constructor * @param configurer @@ -96,6 +135,242 @@ public class ApplicationWorkbenchWindowA configurer.setShowPerspectiveBar( true ); configurer.setShowProgressIndicator( true ); configurer.setShowFastViewBars( true ); + + // hopk up the listeners to update the window title + // adapted from org.eclipse.ui.internal.ide.application.IDEWorkbenchWindowAdvisor + // http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.ui.ide.application/src/org/eclipse/ui/internal/ide/application/IDEWorkbenchWindowAdvisor.java?view=markup + hookTitleUpdateListeners( configurer ); + } + + + /** + * Hooks up the listeners to update the window title. + * + * @param configurer + */ + private void hookTitleUpdateListeners( IWorkbenchWindowConfigurer configurer ) + { + configurer.getWindow().addPageListener( new IPageListener() + { + public void pageActivated( IWorkbenchPage page ) + { + updateTitle( false ); + } + + + public void pageClosed( IWorkbenchPage page ) + { + updateTitle( false ); + } + + + public void pageOpened( IWorkbenchPage page ) + { + // do nothing + } + } ); + configurer.getWindow().addPerspectiveListener( new PerspectiveAdapter() + { + public void perspectiveActivated( IWorkbenchPage page, IPerspectiveDescriptor perspective ) + { + updateTitle( false ); + } + + + public void perspectiveSavedAs( IWorkbenchPage page, IPerspectiveDescriptor oldPerspective, + IPerspectiveDescriptor newPerspective ) + { + updateTitle( false ); + } + + + public void perspectiveDeactivated( IWorkbenchPage page, IPerspectiveDescriptor perspective ) + { + updateTitle( false ); + } + } ); + configurer.getWindow().getPartService().addPartListener( new IPartListener2() + { + public void partActivated( IWorkbenchPartReference ref ) + { + if ( ref instanceof IEditorReference ) + { + updateTitle( false ); + } + } + + + public void partBroughtToTop( IWorkbenchPartReference ref ) + { + if ( ref instanceof IEditorReference ) + { + updateTitle( false ); + } + } + + + public void partClosed( IWorkbenchPartReference ref ) + { + updateTitle( false ); + } + + + public void partDeactivated( IWorkbenchPartReference ref ) + { + // do nothing + } + + + public void partOpened( IWorkbenchPartReference ref ) + { + // do nothing + } + + + public void partHidden( IWorkbenchPartReference ref ) + { + if ( ref.getPart( false ) == lastActiveEditor && lastActiveEditor != null ) + { + updateTitle( true ); + } + } + + + public void partVisible( IWorkbenchPartReference ref ) + { + if ( ref.getPart( false ) == lastActiveEditor && lastActiveEditor != null ) + { + updateTitle( false ); + } + } + + + public void partInputChanged( IWorkbenchPartReference ref ) + { + // do nothing + } + } ); + + } + + + /** + * Computes the title. + * + * @return the computed title + */ + private String computeTitle() + { + IWorkbenchWindowConfigurer configurer = getWindowConfigurer(); + IWorkbenchPage currentPage = configurer.getWindow().getActivePage(); + IEditorPart activeEditor = null; + if ( currentPage != null ) + { + activeEditor = lastActiveEditor; + } + + String title = null; + IProduct product = Platform.getProduct(); + if ( product != null ) + { + title = product.getName(); + } + if ( title == null ) + { + title = ""; //$NON-NLS-1$ + } + + if ( currentPage != null ) + { + if ( activeEditor != null ) + { + lastEditorTitle = activeEditor.getTitleToolTip(); + title = NLS.bind( "{0} - {1}", lastEditorTitle, title ); //$NON-NLS-1$ + } + IPerspectiveDescriptor persp = currentPage.getPerspective(); + String label = ""; //$NON-NLS-1$ + if ( persp != null ) + { + label = persp.getLabel(); + } + IAdaptable input = currentPage.getInput(); + if ( input != null ) + { + label = currentPage.getLabel(); + } + if ( label != null && !label.equals( "" ) ) { //$NON-NLS-1$ + title = NLS.bind( "{0} - {1}", label, title ); //$NON-NLS-1$ + } + } + + return title; + } + + + /** + * Recomputes the title. + */ + private void recomputeTitle() + { + IWorkbenchWindowConfigurer configurer = getWindowConfigurer(); + String oldTitle = configurer.getTitle(); + String newTitle = computeTitle(); + if ( !newTitle.equals( oldTitle ) ) + { + configurer.setTitle( newTitle ); + } + } + + + /** + * Updates the window title. Format will be: [pageInput -] + * [currentPerspective -] [editorInput -] [workspaceLocation -] productName + * @param editorHidden + */ + private void updateTitle( boolean editorHidden ) + { + IWorkbenchWindowConfigurer configurer = getWindowConfigurer(); + IWorkbenchWindow window = configurer.getWindow(); + IEditorPart activeEditor = null; + IWorkbenchPage currentPage = window.getActivePage(); + IPerspectiveDescriptor persp = null; + IAdaptable input = null; + + if ( currentPage != null ) + { + activeEditor = currentPage.getActiveEditor(); + persp = currentPage.getPerspective(); + input = currentPage.getInput(); + } + + if ( editorHidden ) + { + activeEditor = null; + } + + // Nothing to do if the editor hasn't changed + if ( activeEditor == lastActiveEditor && currentPage == lastActivePage && persp == lastPerspective + && input == lastInput ) + { + return; + } + + if ( lastActiveEditor != null ) + { + lastActiveEditor.removePropertyListener( editorPropertyListener ); + } + + lastActiveEditor = activeEditor; + lastActivePage = currentPage; + lastPerspective = persp; + lastInput = input; + + if ( activeEditor != null ) + { + activeEditor.addPropertyListener( editorPropertyListener ); + } + + recomputeTitle(); } }