Merge "Omaha #3539 reworked link to editor action to avoid recursion warning" into omaha_14.4.1
Former-commit-id:697e1c0b79
[formerly6fca563d21
] [formerly7acf4a04b2
[formerly bdc7d4cb7873651a4b59e0b6af9bb9dae931de77]] Former-commit-id:7acf4a04b2
Former-commit-id:ff03dc5783
This commit is contained in:
commit
783a805a8a
1 changed files with 137 additions and 54 deletions
|
@ -23,11 +23,12 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.IPartListener;
|
||||
import org.eclipse.ui.IViewReference;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
import org.eclipse.ui.IWorkbenchPart;
|
||||
import org.eclipse.ui.IWorkbenchPartReference;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
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.viz.ui.editor.AbstractEditor;
|
||||
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>
|
||||
*
|
||||
|
@ -51,7 +53,8 @@ import com.raytheon.viz.ui.views.CaveWorkbenchPageManager;
|
|||
*
|
||||
* 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>
|
||||
*
|
||||
|
@ -105,74 +108,154 @@ public class LinkToEditorAction extends Action {
|
|||
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
|
||||
public void partActivated(IWorkbenchPart part) {
|
||||
if (part instanceof CollaborationSessionView) {
|
||||
IWorkbenchPage page = PlatformUI.getWorkbench()
|
||||
.getActiveWorkbenchWindow().getActivePage();
|
||||
IRemoteDisplayContainer container = ((CollaborationSessionView) part)
|
||||
.getDisplayContainer();
|
||||
if (container != null) {
|
||||
IEditorPart editor = container.getActiveDisplayEditor();
|
||||
if (editor != null) {
|
||||
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();
|
||||
public void partActivated(IWorkbenchPartReference partRef) {
|
||||
IWorkbenchPart part = partRef.getPart(false);
|
||||
if (part != null) {
|
||||
if (part instanceof CollaborationSessionView) {
|
||||
handleSessionActivated((CollaborationSessionView) part);
|
||||
} else if (part instanceof ICollaborationEditor) {
|
||||
String sessionId = ((ICollaborationEditor) part)
|
||||
.getSessionId();
|
||||
handleEditorActivated(sessionId);
|
||||
} else if (part instanceof AbstractEditor) {
|
||||
ISharedDisplaySession session = SharedEditorsManager
|
||||
.getSharedEditorSession((AbstractEditor) part);
|
||||
if (session != null) {
|
||||
sessionId = session.getSessionId();
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
String sessionId = session.getSessionId();
|
||||
handleEditorActivated(sessionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void partBroughtToTop(IWorkbenchPart part) {
|
||||
// Do nothing
|
||||
/**
|
||||
* Handles link from session to map editor. When the user clicks on the
|
||||
* 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) {
|
||||
// Do nothing
|
||||
/**
|
||||
* Handles link from map editor to session view. When the user clicks on
|
||||
* 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) {
|
||||
// Do nothing
|
||||
/**
|
||||
* Brings view to top of page and activates it. This is done
|
||||
* 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) {
|
||||
// Do nothing
|
||||
/**
|
||||
* Brings editor to top of page and activates it. This is done
|
||||
* 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