diff options
Diffstat (limited to 'plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/editor/SashWindowsEventsProvider.java')
-rw-r--r-- | plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/editor/SashWindowsEventsProvider.java | 146 |
1 files changed, 80 insertions, 66 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/editor/SashWindowsEventsProvider.java b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/editor/SashWindowsEventsProvider.java index c7bbf437843..515f35cac8d 100644 --- a/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/editor/SashWindowsEventsProvider.java +++ b/plugins/infra/core/org.eclipse.papyrus.infra.core.sasheditor/src/org/eclipse/papyrus/infra/core/sasheditor/editor/SashWindowsEventsProvider.java @@ -1,5 +1,5 @@ /** - * + * */ package org.eclipse.papyrus.infra.core.sasheditor.editor; @@ -13,24 +13,24 @@ import org.eclipse.ui.IWorkbenchPart; /** * This class allows to listen on events coming from all the active main Editors containing - * a {@link SashWindowsContainer}. It send events when the active editor change and it contains + * a {@link SashWindowsContainer}. It send events when the active editor change and it contains * a {@link SashWindowsContainer}, and when the active page of one of the container has changed. - * + * * <br> * This class allow to listen on following events: * <ul> * <li>pageChanged - a page has changed in the current container</li> * <li>containerChanged - the active editor has changed, and so the currently active container.</li> * </ul> - * + * * This class require the current Eclipse page in order to listen on active editor changed. * This class connect itself to the Workbench editor changed event. Then, it ask the current editor for a ISashWindowsContainer (using getAdaptor() ). * If the editor return a ISashWindowsContainer, * this class listen to the pageChanged events. This class takes care to connect itself to the new ISashWindowsContainer when the editor changes. - * + * * @TODO rename as SashWindowsEventsNotifier * @author cedric dumoulin - * + * */ public class SashWindowsEventsProvider { @@ -65,25 +65,30 @@ public class SashWindowsEventsProvider { private IPartListener workbenchPartListener = new IPartListener() { + @Override public void partOpened(IWorkbenchPart part) { - // System.out.println("partOpened("+ part +")"); + // System.out.println("partOpened("+ part +")"); } + @Override public void partDeactivated(IWorkbenchPart part) { - // System.out.println("partDeactivated("+ part +")"); + // System.out.println("partDeactivated("+ part +")"); } + @Override public void partClosed(IWorkbenchPart part) { - // System.out.println("("+ part +")"); + // System.out.println("("+ part +")"); } + @Override public void partBroughtToTop(IWorkbenchPart part) { - // System.out.println("partClosed("+ part +")"); + // System.out.println("partClosed("+ part +")"); } + @Override public void partActivated(IWorkbenchPart part) { - // System.out.println("partActivated(" + part + ") - activeEditor: " + workbenchPage.getActiveEditor()); + // System.out.println("partActivated(" + part + ") - activeEditor: " + workbenchPage.getActiveEditor()); checkActiveEditorChange(); } }; @@ -93,13 +98,14 @@ public class SashWindowsEventsProvider { */ private IPageChangedListener sashPageChangedListener = new IPageChangedListener() { + @Override public void pageChanged(IPage newPage) { firePageChanged(newPage); } }; /** - * + * * Constructor. * Page can be acquired with : <code>IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();</code> */ @@ -114,35 +120,36 @@ public class SashWindowsEventsProvider { /** * Initialize the first values. - * + * * @param page */ private void init(IWorkbenchPage page) { - if(page == null) + if (page == null) { throw new IllegalArgumentException("page should not be null."); + } workbenchPage = page; // Get the currently active container, if any. -// ISashWindowsContainer newContainer = null; -// IEditorPart editorPart = page.getActiveEditor(); -// if(editorPart != null) { -// newContainer = (ISashWindowsContainer)editorPart.getAdapter(ISashWindowsContainer.class); -// } - - // // Set SashContainer and ActivePage - // currentContainer = newContainer; - // if( currentContainer != null) - // { - // activePage = newContainer.getActiveSashWindowsPage(); - // System.err.println("activePage=" + activePage.getPageTitle() - // + ", tab index=" + currentContainer.); - // } + // ISashWindowsContainer newContainer = null; + // IEditorPart editorPart = page.getActiveEditor(); + // if(editorPart != null) { + // newContainer = (ISashWindowsContainer)editorPart.getAdapter(ISashWindowsContainer.class); + // } + + // // Set SashContainer and ActivePage + // currentContainer = newContainer; + // if( currentContainer != null) + // { + // activePage = newContainer.getActiveSashWindowsPage(); + // System.err.println("activePage=" + activePage.getPageTitle() + // + ", tab index=" + currentContainer.); + // } } /** * Return the currently active ISashWindowsContainer or null if none is actif. - * + * * @return */ public ISashWindowsContainer activeSashWindowsContainer() { @@ -152,19 +159,20 @@ public class SashWindowsEventsProvider { /** * Return the currently active {@link IEditorPart} owning the currently active ISashWindowsContaineror. * Return null if no container is actif. - * + * * @return */ public IEditorPart activeSashWindowsContainerOwner() { - if(currentContainer == null) + if (currentContainer == null) { return null; + } return workbenchPage.getActiveEditor(); } /** * Return the currently active page associated to the currently active Container. * Return null if no container is actif. - * + * * @return */ public IPage activeSashWindowsPage() { @@ -177,7 +185,7 @@ public class SashWindowsEventsProvider { private void checkActiveEditorChange() { // If the currently active editor has changed, send an event. IEditorPart editor = workbenchPage.getActiveEditor(); - if(editor != lastActiveEditor) { + if (editor != lastActiveEditor) { lastActiveEditor = editor; activeEditorChanged(editor); } @@ -205,40 +213,42 @@ public class SashWindowsEventsProvider { * This method is called when the active editor has change. * The method checks the new editor and send appropriate events. * The editor can be null. - * + * * @param newEditor - * The new editor of null if none is set. + * The new editor of null if none is set. */ private void activeEditorChanged(IEditorPart newEditor) { // Editor has changed. It can be null. // Compute new container. ISashWindowsContainer newContainer = null; - if(newEditor != null) { - newContainer = (ISashWindowsContainer)newEditor.getAdapter(ISashWindowsContainer.class); + if (newEditor != null) { + newContainer = (ISashWindowsContainer) newEditor.getAdapter(ISashWindowsContainer.class); } // Throw event if necessary - if(newContainer != currentContainer) + if (newContainer != currentContainer) { activeContainerChanged(newContainer); + } } /** * This method is called when the active container has changed. * The pageChangedListener is removed from the oldContainer, and attached to the newContainer. - * + * * @param newContainer */ private void activeContainerChanged(ISashWindowsContainer newContainer) { // Detach listener from the old container - if(currentContainer != null && !currentContainer.isDisposed()) + if (currentContainer != null && !currentContainer.isDisposed()) { currentContainer.removePageChangedListener(sashPageChangedListener); + } // record new container currentContainer = newContainer; // attach listener to new container - if(currentContainer != null) { + if (currentContainer != null) { currentContainer.addPageChangedListener(sashPageChangedListener); firePageChanged(newContainer.getActiveSashWindowsPage()); } @@ -252,7 +262,7 @@ public class SashWindowsEventsProvider { /** * Send an event indicating a containerChanged. * Propagate the event to all the listeners. - * + * * @param activeEditor */ private void fireContainerChanged(ISashWindowsContainer newContainer) { @@ -263,7 +273,7 @@ public class SashWindowsEventsProvider { /** * Send an event indicating a pageChanged. * Propagate the event to all the listeners. - * + * * @param activeEditor */ private void firePageChanged(IPage newPage) { @@ -275,7 +285,7 @@ public class SashWindowsEventsProvider { /** * Add a listener on pageChanged event. - * + * * @param listener */ public void addPageChangedListener(IPageChangedListener listener) { @@ -284,7 +294,7 @@ public class SashWindowsEventsProvider { /** * Remove listener on pageChanged event. - * + * * @param listener */ public void removePageChangedListener(IPageChangedListener listener) { @@ -293,7 +303,7 @@ public class SashWindowsEventsProvider { /** * Add a listener on pageChanged event. - * + * * @param listener */ public void addSashWindowsContainerChangedListener(ISashWindowsContainerChangedListener listener) { @@ -302,7 +312,7 @@ public class SashWindowsEventsProvider { /** * Remove listener on pageChanged event. - * + * * @param listener */ public void removeSashWindowsContainerChangedListener(ISashWindowsContainerChangedListener listener) { @@ -310,9 +320,9 @@ public class SashWindowsEventsProvider { } /** - * + * * @author dumoulin - * + * */ private abstract class ListenersList<Listener, Event> { @@ -320,52 +330,56 @@ public class SashWindowsEventsProvider { /** * Add specified listener. - * + * * @param listener */ public void addListener(Listener listener) { // Lazy creation - if(listeners == null) + if (listeners == null) { listeners = new ArrayList<Listener>(); + } // do not add if already present. - if(listeners.contains(listener)) + if (listeners.contains(listener)) { return; + } listeners.add(listener); } /** * Remove specified listener. - * + * * @param listener */ public void removeListener(Listener listener) { // Lazy creation - if(listeners == null) + if (listeners == null) { return; + } listeners.remove(listener); } /** * Fire the event on each listener - * + * * @param event */ public void fireEvent(Event event) { // Lazy creation - if(listeners == null) + if (listeners == null) { return; + } - for(Listener listener : listeners) { + for (Listener listener : listeners) { propertyChanged(listener, event); } } /** * Call the listener appropriate property. - * + * * @param listener * @param event */ @@ -374,19 +388,19 @@ public class SashWindowsEventsProvider { /** * A list of {@link IPageChangedListener}. - * + * * @author dumoulin - * + * */ public class PageChangedListeners extends ListenersList<IPageChangedListener, IPage> { /** * Call the appropriate method on the listener. - * + * * @see org.eclipse.papyrus.infra.core.sasheditor.editor.SashWindowsEventsProvider.ListenersList#propertyChanged(java.lang.Object, java.lang.Object) * @param listener * @param newPage - * + * */ @Override public void propertyChanged(IPageChangedListener listener, IPage newPage) { @@ -405,19 +419,19 @@ public class SashWindowsEventsProvider { /** * A list of {@link ISashWindowsContainerChangedListener} listening on container changed event. - * + * * @author dumoulin - * + * */ public class SashWindowsContainerChangedListeners extends ListenersList<ISashWindowsContainerChangedListener, ISashWindowsContainer> { /** * Call the appropriate method on the listener. - * + * * @see org.eclipse.papyrus.infra.core.sasheditor.editor.SashWindowsEventsProvider.ListenersList#propertyChanged(java.lang.Object, java.lang.Object) * @param listener * @param newPage - * + * */ @Override public void propertyChanged(ISashWindowsContainerChangedListener listener, ISashWindowsContainer newContainer) { |