Omaha #3539 reworked link to editor action to avoid recursion warning
Change-Id: Iac2e6194a3ebd5b9c828555cdbd3dc98e0b66c01 Former-commit-id: dcf9ea1ef4f7a7139f6c3700c04e9f9e2fda98e3
This commit is contained in:
parent
bf5f1c27a7
commit
a609334abf
1 changed files with 137 additions and 54 deletions
|
@ -23,11 +23,12 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.jface.action.Action;
|
import org.eclipse.jface.action.Action;
|
||||||
|
import org.eclipse.swt.widgets.Display;
|
||||||
import org.eclipse.ui.IEditorPart;
|
import org.eclipse.ui.IEditorPart;
|
||||||
import org.eclipse.ui.IPartListener;
|
|
||||||
import org.eclipse.ui.IViewReference;
|
import org.eclipse.ui.IViewReference;
|
||||||
import org.eclipse.ui.IWorkbenchPage;
|
import org.eclipse.ui.IWorkbenchPage;
|
||||||
import org.eclipse.ui.IWorkbenchPart;
|
import org.eclipse.ui.IWorkbenchPart;
|
||||||
|
import org.eclipse.ui.IWorkbenchPartReference;
|
||||||
import org.eclipse.ui.IWorkbenchWindow;
|
import org.eclipse.ui.IWorkbenchWindow;
|
||||||
import org.eclipse.ui.PlatformUI;
|
import org.eclipse.ui.PlatformUI;
|
||||||
|
|
||||||
|
@ -41,9 +42,10 @@ import com.raytheon.uf.viz.collaboration.ui.session.CollaborationSessionView;
|
||||||
import com.raytheon.uf.viz.core.icon.IconUtil;
|
import com.raytheon.uf.viz.core.icon.IconUtil;
|
||||||
import com.raytheon.viz.ui.editor.AbstractEditor;
|
import com.raytheon.viz.ui.editor.AbstractEditor;
|
||||||
import com.raytheon.viz.ui.views.CaveWorkbenchPageManager;
|
import com.raytheon.viz.ui.views.CaveWorkbenchPageManager;
|
||||||
|
import com.raytheon.viz.ui.views.PartAdapter2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Link shared editors to their shared Sesion views.
|
* Link shared editors to their shared Session views.
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
*
|
*
|
||||||
|
@ -51,7 +53,8 @@ import com.raytheon.viz.ui.views.CaveWorkbenchPageManager;
|
||||||
*
|
*
|
||||||
* Date Ticket# Engineer Description
|
* Date Ticket# Engineer Description
|
||||||
* ------------ ---------- ----------- --------------------------
|
* ------------ ---------- ----------- --------------------------
|
||||||
* Jul 5, 2012 bsteffen Initial creation
|
* Jul 05, 2012 bsteffen Initial creation
|
||||||
|
* Aug 26, 2014 3539 bclement refactored to fix recursion warning in part listener
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -105,74 +108,154 @@ public class LinkToEditorAction extends Action {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class PartListener implements IPartListener {
|
private static class PartListener extends PartAdapter2 {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see org.eclipse.ui.IPartListener2#partActivated(org.eclipse.ui.
|
||||||
|
* IWorkbenchPartReference)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void partActivated(IWorkbenchPart part) {
|
public void partActivated(IWorkbenchPartReference partRef) {
|
||||||
if (part instanceof CollaborationSessionView) {
|
IWorkbenchPart part = partRef.getPart(false);
|
||||||
IWorkbenchPage page = PlatformUI.getWorkbench()
|
if (part != null) {
|
||||||
.getActiveWorkbenchWindow().getActivePage();
|
if (part instanceof CollaborationSessionView) {
|
||||||
IRemoteDisplayContainer container = ((CollaborationSessionView) part)
|
handleSessionActivated((CollaborationSessionView) part);
|
||||||
.getDisplayContainer();
|
} else if (part instanceof ICollaborationEditor) {
|
||||||
if (container != null) {
|
String sessionId = ((ICollaborationEditor) part)
|
||||||
IEditorPart editor = container.getActiveDisplayEditor();
|
.getSessionId();
|
||||||
if (editor != null) {
|
handleEditorActivated(sessionId);
|
||||||
page.bringToTop(editor);
|
|
||||||
} else if (container instanceof SharedEditorsManager) {
|
|
||||||
SharedEditorsManager sem = (SharedEditorsManager) container;
|
|
||||||
for (AbstractEditor sharedEditor : sem
|
|
||||||
.getSharedEditors()) {
|
|
||||||
page.bringToTop(sharedEditor);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
CaveWorkbenchPageManager page = CaveWorkbenchPageManager
|
|
||||||
.getActiveInstance();
|
|
||||||
String sessionId = null;
|
|
||||||
if (part instanceof ICollaborationEditor) {
|
|
||||||
sessionId = ((ICollaborationEditor) part).getSessionId();
|
|
||||||
} else if (part instanceof AbstractEditor) {
|
} else if (part instanceof AbstractEditor) {
|
||||||
ISharedDisplaySession session = SharedEditorsManager
|
ISharedDisplaySession session = SharedEditorsManager
|
||||||
.getSharedEditorSession((AbstractEditor) part);
|
.getSharedEditorSession((AbstractEditor) part);
|
||||||
if (session != null) {
|
if (session != null) {
|
||||||
sessionId = session.getSessionId();
|
String sessionId = session.getSessionId();
|
||||||
}
|
handleEditorActivated(sessionId);
|
||||||
}
|
|
||||||
if (sessionId != null) {
|
|
||||||
for (IViewReference ref : page.getViewReferences()) {
|
|
||||||
if (CollaborationSessionView.ID.equals(ref.getId())) {
|
|
||||||
CollaborationSessionView view = (CollaborationSessionView) ref
|
|
||||||
.getPart(false);
|
|
||||||
if (sessionId.equals(view.getSessionId())) {
|
|
||||||
page.bringToTop(view);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public void partBroughtToTop(IWorkbenchPart part) {
|
* Handles link from session to map editor. When the user clicks on the
|
||||||
// Do nothing
|
* session tab, this brings the map editor to the front of the page.
|
||||||
|
*
|
||||||
|
* @param session
|
||||||
|
*/
|
||||||
|
private void handleSessionActivated(CollaborationSessionView session) {
|
||||||
|
IWorkbenchPage page = PlatformUI.getWorkbench()
|
||||||
|
.getActiveWorkbenchWindow().getActivePage();
|
||||||
|
String sessionId = session.getSessionId();
|
||||||
|
IViewReference viewRef = getViewRef(sessionId);
|
||||||
|
if (viewRef == null || isMinimized(viewRef, page)) {
|
||||||
|
/*
|
||||||
|
* this means that the activation wasn't from a user clicking on
|
||||||
|
* the view (ie changing perspectives), so we don't want to
|
||||||
|
* bring the editor to the top
|
||||||
|
*/
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
IRemoteDisplayContainer container = session.getDisplayContainer();
|
||||||
|
if (container != null) {
|
||||||
|
IEditorPart editor = container.getActiveDisplayEditor();
|
||||||
|
if (editor != null) {
|
||||||
|
bringToTop(page, editor);
|
||||||
|
} else if (container instanceof SharedEditorsManager) {
|
||||||
|
SharedEditorsManager sem = (SharedEditorsManager) container;
|
||||||
|
for (AbstractEditor sharedEditor : sem.getSharedEditors()) {
|
||||||
|
bringToTop(page, sharedEditor);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public void partClosed(IWorkbenchPart part) {
|
* Handles link from map editor to session view. When the user clicks on
|
||||||
// Do nothing
|
* the map editor tab, this brings the session view to the front of the
|
||||||
|
* page.
|
||||||
|
*
|
||||||
|
* @param sessionId
|
||||||
|
*/
|
||||||
|
private void handleEditorActivated(String sessionId) {
|
||||||
|
if (sessionId != null) {
|
||||||
|
IWorkbenchPage page = PlatformUI.getWorkbench()
|
||||||
|
.getActiveWorkbenchWindow().getActivePage();
|
||||||
|
final IViewReference viewRef = getViewRef(sessionId);
|
||||||
|
/* avoid bringing view to top if user has it minimized */
|
||||||
|
if (viewRef != null && !isMinimized(viewRef, page)) {
|
||||||
|
bringToTop(viewRef);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public void partDeactivated(IWorkbenchPart part) {
|
* Brings view to top of page and activates it. This is done
|
||||||
// Do nothing
|
* asynchronously.
|
||||||
|
*
|
||||||
|
* @param viewRef
|
||||||
|
*/
|
||||||
|
private void bringToTop(final IViewReference viewRef) {
|
||||||
|
Display.getDefault().asyncExec(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
CaveWorkbenchPageManager pageManager = CaveWorkbenchPageManager
|
||||||
|
.getActiveInstance();
|
||||||
|
pageManager.bringToTop(viewRef.getView(false));
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public void partOpened(IWorkbenchPart part) {
|
* Brings editor to top of page and activates it. This is done
|
||||||
// Do nothing
|
* asynchronously.
|
||||||
|
*
|
||||||
|
* @param page
|
||||||
|
* @param editor
|
||||||
|
*/
|
||||||
|
private void bringToTop(final IWorkbenchPage page,
|
||||||
|
final IWorkbenchPart editor) {
|
||||||
|
Display.getDefault().asyncExec(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
page.bringToTop(editor);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param sessionId
|
||||||
|
* @return the first view in page that matches session id, null if not
|
||||||
|
* found
|
||||||
|
*/
|
||||||
|
private IViewReference getViewRef(String sessionId) {
|
||||||
|
CaveWorkbenchPageManager pageManager = CaveWorkbenchPageManager
|
||||||
|
.getActiveInstance();
|
||||||
|
for (IViewReference ref : pageManager.getViewReferences()) {
|
||||||
|
if (CollaborationSessionView.ID.equals(ref.getId())) {
|
||||||
|
CollaborationSessionView view = (CollaborationSessionView) ref
|
||||||
|
.getPart(false);
|
||||||
|
if (view.getSessionId().equals(sessionId)) {
|
||||||
|
return ref;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ref
|
||||||
|
* @param page
|
||||||
|
* @return true if part stack containing view is minimized
|
||||||
|
*/
|
||||||
|
private boolean isMinimized(IViewReference ref, IWorkbenchPage page) {
|
||||||
|
/*
|
||||||
|
* TODO investigate why this sometimes returns false when part stack
|
||||||
|
* is minimized for the first time after starting cave. May have
|
||||||
|
* something to do with floating views.
|
||||||
|
*/
|
||||||
|
return page.getPartState(ref) == IWorkbenchPage.STATE_MINIMIZED;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue