Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for additional view elements #59

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added support for additional view elements
-Added a workbenchGazeHandler to recursively keep track of editors and views and their respective gaze handlers.
-Added a projectExplorerGazeHandler
-Additional views types can now be tracked and managed inside the workbenchGazeHandler
  • Loading branch information
clptrsn committed Sep 9, 2021
commit fb427ef483d5d05be0b8ff3a755ba16b791bb6f0
30 changes: 10 additions & 20 deletions src/org/itrace/ControlView.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IPartListener2;
import org.eclipse.ui.IViewSite;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbenchPartReference;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
Expand Down Expand Up @@ -112,35 +111,26 @@ public void setFocus() {
public void partActivated(IWorkbenchPartReference partRef) {
if(partRef.getPart(false) instanceof IEditorPart) {
ITrace.getDefault().setActiveEditor((IEditorPart)partRef.getPart(false));
IEditorPart ep = (IEditorPart)partRef.getPart(true);
ITrace.getDefault().setLineManager(ep.getEditorSite().getActionBars().getStatusLineManager());
} else {
IWorkbenchPart ep = partRef.getPart(true);
ITrace.getDefault().setLineManager(((IViewSite) ep.getSite()).getActionBars().getStatusLineManager());
} else if(partRef instanceof IViewReference) {
ITrace.getDefault().setActiveViewPart((IViewPart)partRef.getPart(false));
}
}

@Override
public void partBroughtToTop(IWorkbenchPartReference partRef) {
if(partRef.getPart(false) instanceof IEditorPart) {
ITrace.getDefault().setActiveEditor((IEditorPart)partRef.getPart(false));
IEditorPart ep = (IEditorPart)partRef.getPart(true);
ITrace.getDefault().setLineManager(ep.getEditorSite().getActionBars().getStatusLineManager());
} else {
IWorkbenchPart ep = partRef.getPart(true);
ITrace.getDefault().setLineManager(((IViewSite) ep.getSite()).getActionBars().getStatusLineManager());
} else if(partRef instanceof IViewReference) {
ITrace.getDefault().setActiveViewPart((IViewPart)partRef.getPart(false));
}
}

@Override
public void partClosed(IWorkbenchPartReference partRef) {
if(partRef instanceof IEditorReference){
ITrace.getDefault().setActionBars(getViewSite().getActionBars());
IEditorPart editorPart = (IEditorPart)partRef.getPart(true);
ITrace.getDefault().removeEditor(editorPart);

IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
ITrace.getDefault().setActiveEditor(activeEditor);
if(partRef.getPart(false) instanceof IEditorPart) {
ITrace.getDefault().removeEditor((IEditorPart)partRef.getPart(false));
} else if(partRef instanceof IViewReference) {
ITrace.getDefault().removeViewPart((IViewPart)partRef.getPart(false));
}
}

Expand Down
49 changes: 24 additions & 25 deletions src/org/itrace/ITrace.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;

import org.itrace.gaze.IGazeResponse;
import org.itrace.gaze.handlers.IGazeHandler;
import org.itrace.gaze.handlers.StyledTextGazeHandler;
import org.itrace.gaze.handlers.WorkbenchGazeHandler;
import org.itrace.solvers.XMLGazeExportSolver;

/**
Expand All @@ -37,7 +36,7 @@ public class ITrace extends AbstractUIPlugin implements EventHandler {
private static ITrace plugin;
private IEditorPart activeEditor;
private HashMap<IEditorPart, TokenHighlighter> tokenHighlighters = new HashMap<IEditorPart, TokenHighlighter>();
private HashMap<IEditorPart, IGazeHandler> editorHandlers = new HashMap<IEditorPart, IGazeHandler>();
private WorkbenchGazeHandler workbenchGazeHandler;
private boolean showTokenHighlights = false;

private volatile boolean isConnected;
Expand All @@ -63,9 +62,9 @@ public ITrace() {
StyledText styledText = (StyledText) editorPart.getAdapter(Control.class);
if (styledText != null) {
tokenHighlighters.put(editorPart, new TokenHighlighter(editorPart, showTokenHighlights));
editorHandlers.put(editorPart, new StyledTextGazeHandler(styledText, editorPart));
}
}

connectionManager = new ConnectionManager();
// iTrace invokes the events to the Eventbroker and these events are subscribed
// in an order.
Expand Down Expand Up @@ -118,6 +117,9 @@ public Shell getRootShell() {

public void setRootShell(Shell shell) {
rootShell = shell;
if(workbenchGazeHandler == null) {
workbenchGazeHandler = new WorkbenchGazeHandler(PlatformUI.getWorkbench());
}
}

public void setActionBars(IActionBars bars) {
Expand Down Expand Up @@ -220,19 +222,26 @@ public void setActiveEditor(IEditorPart editorPart) {
if (!tokenHighlighters.containsKey(editorPart)) {
tokenHighlighters.put(editorPart, new TokenHighlighter(editorPart, showTokenHighlights));
}
if (!editorHandlers.containsKey(editorPart)) {
StyledText styledText = (StyledText) editorPart.getAdapter(Control.class);
if (styledText != null) {
editorHandlers.put(editorPart, new StyledTextGazeHandler(styledText, editorPart));
}
}
setLineManager(editorPart.getEditorSite().getActionBars().getStatusLineManager());
workbenchGazeHandler.addEditor(editorPart);
}
}

public void setActiveViewPart(IViewPart viewPart) {
setLineManager(viewPart.getViewSite().getActionBars().getStatusLineManager());
workbenchGazeHandler.addViewPart(viewPart);
}

public void removeEditor(IEditorPart editorPart) {
tokenHighlighters.remove(editorPart);
editorHandlers.remove(editorPart);
workbenchGazeHandler.removeEditor(editorPart);
}

public void removeViewPart(IViewPart viewPart) {
workbenchGazeHandler.removeViewPart(viewPart);

}


public void activateHighlights() {
showTokenHighlights = !showTokenHighlights;
Expand All @@ -258,21 +267,11 @@ public void clearTokenHighlights() {
* is not handled.
*/
private IGazeResponse handleGaze(int screenX, int screenY, Gaze gaze) {
if(workbenchGazeHandler.containsGaze(screenX, screenY)) {
return workbenchGazeHandler.handleGaze(screenX, screenY, gaze);
}
// Look at all editors and find an active one that contains the point
// Returns the result of the editor's handleGaze method
for (IEditorPart editor : editorHandlers.keySet()) {
Control editorControl = editor.getAdapter(Control.class);
Rectangle editorScreenBounds = editorControl.getBounds();
Point screenPos = editorControl.toDisplay(0, 0);
editorScreenBounds.x = screenPos.x;
editorScreenBounds.y = screenPos.y;

if (editorControl.isVisible() && editorScreenBounds.contains(screenX, screenY)) {
IGazeHandler handler = editorHandlers.get(editor);
return handler.handleGaze(screenX, screenY, screenX - editorScreenBounds.x,
screenY - editorScreenBounds.y, gaze);
}
}
return null;
}

Expand Down
10 changes: 8 additions & 2 deletions src/org/itrace/gaze/handlers/IGazeHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@
*/
public interface IGazeHandler {

/**
* Determines whether the gaze is within the boundaries of the
* target object. Return value will be true if the gaze is contained
* within the target object
*/
public boolean containsGaze(int absoluteX, int absoluteY);

/**
* Handles the specified gaze at the specified x and y coordinates relative
* to the target object. Return value may be null if the gaze is not
* meaningful to the target.
*/
public IGazeResponse handleGaze(int absoluteX, int absoluteY,
int relativeX, int relativeY, Gaze gaze);
public IGazeResponse handleGaze(int absoluteX, int absoluteY, Gaze gaze);

}
63 changes: 63 additions & 0 deletions src/org/itrace/gaze/handlers/ProjectExplorerGazeHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.itrace.gaze.handlers;

import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.IViewPart;
import org.itrace.Gaze;
import org.itrace.gaze.IGazeResponse;

public class ProjectExplorerGazeHandler implements IGazeHandler {
private String name;
private Tree tree;

public ProjectExplorerGazeHandler(Tree target, IViewPart partRef) {
this.name = partRef.getTitle();
this.tree = (Tree) target;
}

@Override
public boolean containsGaze(int absoluteX, int absoluteY) {
Rectangle viewScreenBounds = tree.getBounds();
Point screenPos = tree.toDisplay(0, 0);
viewScreenBounds.x = screenPos.x;
viewScreenBounds.y = screenPos.y;

if (tree.isVisible() && viewScreenBounds.contains(absoluteX, absoluteY)) {
return true;
}
else {
return false;
}
}

@Override
public IGazeResponse handleGaze(int absoluteX, int absoluteY, final Gaze gaze) {
int relativeX = absoluteX - tree.toDisplay(0, 0).x;
int relativeY = absoluteY - tree.toDisplay(0, 0).y;

tree.getItem(new Point(relativeX, relativeY));
return new IGazeResponse() {
@Override
public String getName() {
return name;
}

@Override
public Gaze getGaze() {
return gaze;
}

@Override
public IGazeHandler getGazeHandler() {
return ProjectExplorerGazeHandler.this;
}

@Override
public String getGazeType() {
// TODO Auto-generated method stub
return "view_part";
}
};
}
}
21 changes: 20 additions & 1 deletion src/org/itrace/gaze/handlers/StyledTextGazeHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//import org.eclipse.jface.text.source.projection.ProjectionViewer;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
import org.itrace.Gaze;
Expand All @@ -28,9 +29,24 @@ public StyledTextGazeHandler(Object target, IEditorPart editor) {
this.editor = editor;
projectionViewer = (ProjectionViewer) editor.getAdapter(ITextOperationTarget.class);
}

@Override
public boolean containsGaze(int absoluteX, int absoluteY) {
Rectangle viewScreenBounds = targetStyledText.getBounds();
Point screenPos = targetStyledText.toDisplay(0, 0);
viewScreenBounds.x = screenPos.x;
viewScreenBounds.y = screenPos.y;

if (targetStyledText.isVisible() && viewScreenBounds.contains(absoluteX, absoluteY)) {
return true;
}
else {
return false;
}
}

@Override
public IStyledTextGazeResponse handleGaze(int absoluteX, int absoluteY, int relativeX, int relativeY, final Gaze gaze) {
public IStyledTextGazeResponse handleGaze(int absoluteX, int absoluteY, final Gaze gaze) {
final int lineIndex;
final int col;
final Point absoluteLineAnchorPosition;
Expand All @@ -40,6 +56,9 @@ public IStyledTextGazeResponse handleGaze(int absoluteX, int absoluteY, int rela
final String path;

try {
int relativeX = absoluteX - targetStyledText.toDisplay(0, 0).x;
int relativeY = absoluteY - targetStyledText.toDisplay(0, 0).y;

// Get the actual offset of the current line from the top
// Allows code folding to be taken into account
int foldedLineIndex = targetStyledText.getLineIndex(relativeY);
Expand Down
Loading