diff options
author | Aurelien Didier | 2015-09-07 17:06:44 +0000 |
---|---|---|
committer | Aurelien Didier | 2015-09-08 14:32:25 +0000 |
commit | d605ada2d3c3f5b3582e72e64fb63cb91ea5ac35 (patch) | |
tree | 71c34784dad6915997b0f41bbe37b54a9c7a678b | |
parent | 816900f5e6e225eee891dd75ef3368884b529ad1 (diff) | |
download | org.eclipse.amalgam-d605ada2d3c3f5b3582e72e64fb63cb91ea5ac35.tar.gz org.eclipse.amalgam-d605ada2d3c3f5b3582e72e64fb63cb91ea5ac35.tar.xz org.eclipse.amalgam-d605ada2d3c3f5b3582e72e64fb63cb91ea5ac35.zip |
[476811] Activity Explorer Session Listener correction
Change-Id: Id027d7934f51628d4e517b51624c8131ed672e7e
Signed-off-by: Aurelien Didier <aurelien.didier51@gmail.com>
-rw-r--r-- | plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/internal/session/listeners/ActivityExplorerSessionListener.java | 299 |
1 files changed, 150 insertions, 149 deletions
diff --git a/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/internal/session/listeners/ActivityExplorerSessionListener.java b/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/internal/session/listeners/ActivityExplorerSessionListener.java index 0253c76b..45550cf4 100644 --- a/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/internal/session/listeners/ActivityExplorerSessionListener.java +++ b/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/internal/session/listeners/ActivityExplorerSessionListener.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.amalgam.explorer.activity.ui.internal.session.listeners; +import java.lang.ref.WeakReference; + import org.eclipse.amalgam.explorer.activity.ui.ActivityExplorerActivator; import org.eclipse.amalgam.explorer.activity.ui.api.editor.ActivityExplorerEditor; import org.eclipse.amalgam.explorer.activity.ui.api.editor.input.ActivityExplorerEditorInput; @@ -18,6 +20,7 @@ import org.eclipse.amalgam.explorer.activity.ui.api.preferences.PreferenceConsta import org.eclipse.core.runtime.IStatus; import org.eclipse.sirius.business.api.session.Session; import org.eclipse.sirius.business.api.session.SessionListener; +import org.eclipse.sirius.business.api.session.SessionManager; import org.eclipse.sirius.business.api.session.SessionManagerListener; import org.eclipse.sirius.viewpoint.description.Viewpoint; import org.eclipse.swt.widgets.Display; @@ -29,163 +32,161 @@ import org.eclipse.ui.forms.IManagedForm; * */ public class ActivityExplorerSessionListener implements SessionManagerListener { - public Session session = null; - - @Override - public void notify(Session session_p, int notification_p) { - // Filter on event for other sessions. - session = session_p; - final ActivityExplorerEditor editor = ActivityExplorerManager.INSTANCE.getEditorFromSession(session_p); - - Runnable runnable = null; - switch (notification_p) { - case SessionListener.CLOSING: /* - * Closing event is used to have a chance to - * persist the editor input at workbench - * shutdown - */ - - runnable = new Runnable() { - /** - * @see java.lang.Runnable#run() - */ - public void run() { - if (editor != null) - // Close this editor. - editor.close(false); - } - }; - break; - case SessionListener.REPRESENTATION_CHANGE: - runnable = new Runnable() { - /** - * @see java.lang.Runnable#run() - */ - @SuppressWarnings("synthetic-access") - public void run() { - // Handle fpages to mark them as dirty. - if (editor != null) { - IManagedForm headerForm = editor.getHeaderForm(); - if (null != headerForm) { - headerForm.dirtyStateChanged(); - } - } - } - }; - break; - - case SessionListener.OPENED: - if (!(session.getSemanticResources().isEmpty())) { - runnable = new Runnable() { - @SuppressWarnings("synthetic-access") - public void run() { - try { - - final boolean open = ActivityExplorerActivator.getDefault().getPreferenceStore() - .getBoolean(PreferenceConstants.P_OPEN_ACTIVITY_EXPLORER); - - if (open) { - - IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow() - .getActivePage(); - if (activePage != null) { - activePage - .openEditor( - new ActivityExplorerEditorInput( - session, - org.eclipse.amalgam.explorer.activity.ui.api.editor.pages.helper.SessionHelper - .getRootSemanticModel(session)), ActivityExplorerEditor.ID); - } - } - } catch (Exception exception_p) { - StringBuilder loggerMessage = new StringBuilder(".run(..) _ ActivityExplorer not Found."); //$NON-NLS-1$ - loggerMessage.append(exception_p.getMessage()); - ActivityExplorerActivator.getDefault().sentToLogger(loggerMessage.toString(), IStatus.ERROR); - // __logger.warn(new - // EmbeddedMessage(loggerMessage.toString(), - // IReportManagerDefaultComponents.UI), - // exception_p); - } - } - }; - } - break; - case SessionListener.DIRTY: - case SessionListener.SYNC: - case SessionListener.SEMANTIC_CHANGE: // Listening to changes to mark - // the ActivityExplorerEditor editor dirty - // hence saveable. - runnable = new Runnable() { - /** - * {@inheritDoc} - */ - public void run() { - if (editor != null) { - if (editor.getEditorInput() != null && !session.equals(editor.getEditorInput().getSession())) { - return; - } - IManagedForm headerForm = editor.getHeaderForm(); - if (null != headerForm) { - headerForm.dirtyStateChanged(); - } - } - } - }; - break; - } - if (null != runnable) { - Display display = Display.getCurrent(); - if (null == display) { - PlatformUI.getWorkbench().getDisplay().asyncExec(runnable); - } else { - runnable.run(); - } - } - } - - public void notifyAddSession(Session newSession_p) { - // Do nothing. - } - - public void notifyRemoveSession(Session removedSession_p) { - // Do nothing. - } - - public void notifyUpdatedSession(Session updatedSession_p) { - // Fake a representation change - notify(updatedSession_p, SessionListener.REPRESENTATION_CHANGE); - } + public WeakReference<Session> session = null; + + @Override + public void notify(Session sessionp, int notification) { + // Filter on event for other sessions. + session = new WeakReference<Session>(sessionp); + final ActivityExplorerEditor editor = ActivityExplorerManager.INSTANCE.getEditorFromSession(sessionp); + + Runnable runnable = null; + switch (notification) { + case SessionListener.CLOSING: /* + * Closing event is used to have a chance to persist the editor input at workbench + * shutdown + */ + + runnable = new Runnable() { + /** + * @see java.lang.Runnable#run() + */ + public void run() { + if (editor != null) + // Close this editor. + editor.close(false); + } + }; + break; + case SessionListener.REPRESENTATION_CHANGE: + runnable = new Runnable() { + /** + * @see java.lang.Runnable#run() + */ + @SuppressWarnings("synthetic-access") + public void run() { + // Handle fpages to mark them as dirty. + if (editor != null) { + IManagedForm headerForm = editor.getHeaderForm(); + if (null != headerForm) { + headerForm.dirtyStateChanged(); + } + } + } + }; + break; + + case SessionListener.OPENED: + if (!(session.get().getSemanticResources().isEmpty())) { + runnable = new Runnable() { + @SuppressWarnings("synthetic-access") + public void run() { + try { + + final boolean open = ActivityExplorerActivator.getDefault().getPreferenceStore() + .getBoolean(PreferenceConstants.P_OPEN_ACTIVITY_EXPLORER); + + if (open) { + + IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + if (activePage != null) { + activePage.openEditor( + new ActivityExplorerEditorInput(session.get(), + org.eclipse.amalgam.explorer.activity.ui.api.editor.pages.helper.SessionHelper + .getRootSemanticModel(session.get())), ActivityExplorerEditor.ID); + } + } + } catch (Exception exception) { + StringBuilder loggerMessage = new StringBuilder(".run(..) _ ActivityExplorer not Found."); //$NON-NLS-1$ + loggerMessage.append(exception.getMessage()); + ActivityExplorerActivator.getDefault().sentToLogger(loggerMessage.toString(), IStatus.ERROR); + // __logger.warn(new + // EmbeddedMessage(loggerMessage.toString(), + // IReportManagerDefaultComponents.UI), + // exception); + } + } + }; + } + break; + case SessionListener.DIRTY: + case SessionListener.SYNC: + case SessionListener.SEMANTIC_CHANGE: // Listening to changes to mark + // the ActivityExplorerEditor editor dirty + // hence saveable. + runnable = new Runnable() { + /** + * {@inheritDoc} + */ + public void run() { + if (editor != null) { + if (editor.getEditorInput() != null && !session.get().equals(editor.getEditorInput().getSession())) { + return; + } + IManagedForm headerForm = editor.getHeaderForm(); + if (null != headerForm) { + headerForm.dirtyStateChanged(); + } + } + } + }; + break; + } + if (null != runnable) { + Display display = Display.getCurrent(); + if (null == display) { + PlatformUI.getWorkbench().getDisplay().asyncExec(runnable); + } else { + runnable.run(); + } + } + } + + public void notifyAddSession(Session newSession) { + // Do nothing. + } + + public void notifyRemoveSession(Session removedSession) { + // Do nothing. + } + + public void notifyUpdatedSession(Session updatedSession) { + // Fake a representation change + notify(updatedSession, SessionListener.REPRESENTATION_CHANGE); + } @Override public void viewpointSelected(Viewpoint selectedViewpoint) { - update(selectedViewpoint); + update(selectedViewpoint); } @Override public void viewpointDeselected(Viewpoint deselectedViewpoint) { - update(deselectedViewpoint); + update(deselectedViewpoint); } - /** - * Update the ActivityExplorer Editor. - * - * @param selectedViewpoint - */ - private void update(Viewpoint selectedViewpoint) { - if (selectedViewpoint != null && session != null && session.isOpen()) { - - Runnable refresh = new Runnable() { - - @Override - public void run() { - ActivityExplorerEditor editor = ActivityExplorerManager.INSTANCE.getEditorFromSession(session); - if (editor != null) { - editor.updateEditorPages(0); - } - } - }; - Display.getDefault().syncExec(refresh); - } - } + /** + * Update the ActivityExplorer Editor. + * + * @param selectedViewpoint + */ + private void update(Viewpoint selectedViewpoint) { + final Session currentSession = SessionManager.INSTANCE.getSession(selectedViewpoint); + + if (selectedViewpoint != null && currentSession != null && currentSession.isOpen()) { + + Runnable refresh = new Runnable() { + + @Override + public void run() { + ActivityExplorerEditor editor = ActivityExplorerManager.INSTANCE.getEditorFromSession(currentSession); + if (editor != null) { + editor.updateEditorPages(0); + } + } + }; + Display.getDefault().syncExec(refresh); + } + } } |