Commit ede1d6df authored by Sebastian Pretscher's avatar Sebastian Pretscher
Browse files

Added zoom to the graph view

parent 361f63df
......@@ -35,7 +35,7 @@ import de.in.tum.www2.cup.internal.parse_reduce_table;
import de.tum.in.www2.cupplugin.model.CupParserLaLrChangeObserver;
import de.tum.in.www2.cupplugin.model.Model;
public class CupGraphView implements CupParserLaLrChangeObserver {
public class CupGraphView implements CupParserLaLrChangeObserver, IZoomableWorkbenchPart {
private GraphViewer graphViewer;
private Model parseModel;
......@@ -226,4 +226,9 @@ public class CupGraphView implements CupParserLaLrChangeObserver {
}
}
@Override
public AbstractZoomableViewer getZoomableViewer() {
return getGraphViewer();
}
}
......@@ -6,6 +6,9 @@ import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.ContributionItem;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.viewers.Viewer;
......@@ -26,10 +29,15 @@ import org.eclipse.zest.core.viewers.ZoomContributionViewItem;
import de.tum.in.www2.cupplugin.controller.Controller;
import de.tum.in.www2.cupplugin.debug.Debugger;
public class MultiPageEditor extends MultiPageEditorPart implements IResourceChangeListener, IZoomableWorkbenchPart {
public class MultiPageEditor extends MultiPageEditorPart implements
IResourceChangeListener {
private CupTextEditor editor;
private CupGraphView graphView;
// Zoom for the GraphView
private ZoomContributionViewItem graphZoomContribution;
private IMenuManager graphMenu;
private CupOverviewView overviewView;
private CupActionTableView actionTableView;
private CupReduceTableView reduceTableView;
......@@ -41,7 +49,7 @@ public class MultiPageEditor extends MultiPageEditorPart implements IResourceCha
private final int REDUCE_TABLE_PAGE_INDEX = 4;
private int previousPageIndex = EDITOR_PAGE_INDEX;
public MultiPageEditor() {
super();
ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
......@@ -50,7 +58,7 @@ public class MultiPageEditor extends MultiPageEditorPart implements IResourceCha
public CupTextEditor getEditor() {
return editor;
}
void createEditorPage() {
try {
editor = new CupTextEditor();
......@@ -59,32 +67,32 @@ public class MultiPageEditor extends MultiPageEditorPart implements IResourceCha
setTitle(editor.getTitle());
addHooksToMainTextEditor(editor);
editor.addActions();
IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
IDocument doc = editor.getDocumentProvider().getDocument(
editor.getEditorInput());
Controller controller = Controller.getInstance(doc);
controller.initialRun();
} catch (PartInitException e) {
ErrorDialog.openError(
getSite().getShell(),
"Error creating nested text editor",
null,
e.getStatus());
ErrorDialog.openError(getSite().getShell(),
"Error creating nested text editor", null, e.getStatus());
}
}
void createGraphPage() {
Composite composite = new Composite(getContainer(), SWT.NONE);
IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
IDocument doc = editor.getDocumentProvider().getDocument(
editor.getEditorInput());
graphView = new CupGraphView(composite, doc);
int index = addPage(composite);
setPageText(index, "Visualization");
}
void createOverviewPage() {
Composite composite = new Composite(getContainer(), SWT.NONE);
IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
IDocument doc = editor.getDocumentProvider().getDocument(
editor.getEditorInput());
overviewView = new CupOverviewView(composite, doc);
addPage(OVERVIEW_PAGE_INDEX, composite);
setPageText(OVERVIEW_PAGE_INDEX, "Overview");
......@@ -92,20 +100,22 @@ public class MultiPageEditor extends MultiPageEditorPart implements IResourceCha
void createActionTablePage() {
Composite composite = new Composite(getContainer(), SWT.NONE);
IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
IDocument doc = editor.getDocumentProvider().getDocument(
editor.getEditorInput());
actionTableView = new CupActionTableView(composite, doc);
addPage(ACTION_TABLE_PAGE_INDEX, composite);
setPageText(ACTION_TABLE_PAGE_INDEX, "Action Table");
}
void createReduceTablePage() {
Composite composite = new Composite(getContainer(), SWT.NONE);
IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
IDocument doc = editor.getDocumentProvider().getDocument(
editor.getEditorInput());
reduceTableView = new CupReduceTableView(composite, doc);
addPage(REDUCE_TABLE_PAGE_INDEX, composite);
setPageText(REDUCE_TABLE_PAGE_INDEX, "Reduce Table");
}
protected void createPages() {
createEditorPage();
createOverviewPage();
......@@ -135,14 +145,16 @@ public class MultiPageEditor extends MultiPageEditorPart implements IResourceCha
setActivePage(EDITOR_PAGE_INDEX);
IDE.gotoMarker(getEditor(EDITOR_PAGE_INDEX), marker);
}
/**
* The <code>MultiPageEditorExample</code> implementation of this method
* checks that the input is an instance of <code>IFileEditorInput</code>.
*/
public void init(IEditorSite site, IEditorInput editorInput)
throws PartInitException {
throws PartInitException {
if (!(editorInput instanceof IFileEditorInput))
throw new PartInitException("Invalid Input: Must be IFileEditorInput");
throw new PartInitException(
"Invalid Input: Must be IFileEditorInput");
super.init(site, editorInput);
}
......@@ -151,72 +163,107 @@ public class MultiPageEditor extends MultiPageEditorPart implements IResourceCha
}
protected void pageChange(int newPageIndex) {
switch (previousPageIndex) {
case OVERVIEW_PAGE_INDEX: overviewView.becameHidden(); break;
case GRAPH_PAGE_INDEX: graphView.becameHidden(); break;
case ACTION_TABLE_PAGE_INDEX: actionTableView.becameHidden(); break;
case REDUCE_TABLE_PAGE_INDEX: reduceTableView.becameHidden(); break;
case OVERVIEW_PAGE_INDEX:
overviewView.becameHidden();
break;
case GRAPH_PAGE_INDEX:
graphView.becameHidden();
removeObjectsWithMenuFromToolbar(graphZoomContribution, graphMenu);
graphZoomContribution = null;
graphMenu = null;
break;
case ACTION_TABLE_PAGE_INDEX:
actionTableView.becameHidden();
break;
case REDUCE_TABLE_PAGE_INDEX:
reduceTableView.becameHidden();
break;
}
switch (newPageIndex) {
case OVERVIEW_PAGE_INDEX: overviewView.willBecomeVisible(); break;
case GRAPH_PAGE_INDEX: graphView.willBecomeVisible(); fillToolBar(); break;
case ACTION_TABLE_PAGE_INDEX: actionTableView.willBecomeVisible(); break;
case REDUCE_TABLE_PAGE_INDEX: reduceTableView.willBecomeVisible(); break;
case OVERVIEW_PAGE_INDEX:
overviewView.willBecomeVisible();
break;
case GRAPH_PAGE_INDEX:
graphView.willBecomeVisible();
addZoomContributionForCupGraphView(graphView);
break;
case ACTION_TABLE_PAGE_INDEX:
actionTableView.willBecomeVisible();
break;
case REDUCE_TABLE_PAGE_INDEX:
reduceTableView.willBecomeVisible();
break;
}
previousPageIndex = newPageIndex;
super.pageChange(newPageIndex);
}
/**
* Closes all project files on project close.
*/
public void resourceChanged(final IResourceChangeEvent event){
if(event.getType() == IResourceChangeEvent.PRE_CLOSE){
Display.getDefault().asyncExec(new Runnable(){
public void run(){
IWorkbenchPage[] pages = getSite().getWorkbenchWindow().getPages();
for (int i = 0; i<pages.length; i++){
if(((FileEditorInput)editor.getEditorInput()).getFile().getProject().equals(event.getResource())){
IEditorPart editorPart = pages[i].findEditor(editor.getEditorInput());
pages[i].closeEditor(editorPart,true);
public void resourceChanged(final IResourceChangeEvent event) {
if (event.getType() == IResourceChangeEvent.PRE_CLOSE) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
IWorkbenchPage[] pages = getSite().getWorkbenchWindow()
.getPages();
for (int i = 0; i < pages.length; i++) {
if (((FileEditorInput) editor.getEditorInput())
.getFile().getProject()
.equals(event.getResource())) {
IEditorPart editorPart = pages[i].findEditor(editor
.getEditorInput());
pages[i].closeEditor(editorPart, true);
}
}
}
}
});
}
}
boolean addHooksToMainTextEditor(ITextEditor editor) {
IFile file = ((FileEditorInput) editor.getEditorInput()).getFile();
IDocumentProvider dp = editor.getDocumentProvider();
if(dp == null)
if (dp == null)
return false;
IDocument doc = dp.getDocument(getEditorInput());
if(doc == null)
if (doc == null)
return false;
doc.addDocumentListener(new CTEDocumentListener(file));
if (editor instanceof CupTextEditor) {
if (!Debugger.addDebugHooksToTextEditor((CupTextEditor) editor)) {
return false;
}
}
return true;
}
@Override
public AbstractZoomableViewer getZoomableViewer() {
if(graphView!=null) {
return graphView.getGraphViewer();
}
return null;
private void addZoomContributionForCupGraphView(
IZoomableWorkbenchPart viewPart) {
graphZoomContribution = new ZoomContributionViewItem(viewPart);
/*
* IActionBars bars = getEditorSite().getActionBars();
* bars.getMenuManager().add(toolbarZoomContributionViewItem);
* bars.updateActionBars();
*/
IMenuManager manager = getEditorSite().getActionBars().getMenuManager();
graphMenu = new MenuManager("Graph &Menu");
manager.prependToGroup(IWorkbenchActionConstants.MB_ADDITIONS, graphMenu);
graphMenu.add(graphZoomContribution);
getEditorSite().getActionBars().updateActionBars();
}
private void fillToolBar() {
ZoomContributionViewItem toolbarZoomContributionViewItem = new ZoomContributionViewItem(this);
IActionBars bars = getEditorSite().getActionBars();
bars.getMenuManager().add(toolbarZoomContributionViewItem);
}
private void removeObjectsWithMenuFromToolbar(ContributionItem contItem, IMenuManager menu) {
if (contItem == null) {
return;
}
IMenuManager manager = getEditorSite().getActionBars().getMenuManager();
manager.remove(menu);
menu.remove(contItem);
//manager.remove(contItem);
}
}
......@@ -12,15 +12,19 @@ import org.eclipse.ui.ide.IDEActionFactory;
import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
import org.eclipse.zest.core.viewers.ZoomContributionViewItem;
/**
* Manages the installation/deinstallation of global actions for multi-page editors.
* Responsible for the redirection of global actions to the active editor.
* Multi-page contributor replaces the contributors for the individual editors in the multi-page editor.
* Manages the installation/deinstallation of global actions for multi-page
* editors. Responsible for the redirection of global actions to the active
* editor. Multi-page contributor replaces the contributors for the individual
* editors in the multi-page editor.
*/
public class MultiPageEditorContributor extends MultiPageEditorActionBarContributor {
public class MultiPageEditorContributor extends
MultiPageEditorActionBarContributor {
private IEditorPart activeEditorPart;
private Action sampleAction;
/**
* Creates a multi-page contributor.
*/
......@@ -28,15 +32,19 @@ public class MultiPageEditorContributor extends MultiPageEditorActionBarContribu
super();
createActions();
}
/**
* Returns the action registed with the given text editor.
*
* @return IAction or null if editor is null.
*/
protected IAction getAction(ITextEditor editor, String actionID) {
return (editor == null ? null : editor.getAction(actionID));
}
/* (non-JavaDoc)
* Method declared in AbstractMultiPageEditorActionBarContributor.
/*
* (non-JavaDoc) Method declared in
* AbstractMultiPageEditorActionBarContributor.
*/
public void setActivePage(IEditorPart part) {
......@@ -48,54 +56,52 @@ public class MultiPageEditorContributor extends MultiPageEditorActionBarContribu
IActionBars actionBars = getActionBars();
if (actionBars != null) {
ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor) part : null;
ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor) part
: null;
actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(),
getAction(editor, ITextEditorActionConstants.DELETE));
actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(),
getAction(editor, ITextEditorActionConstants.UNDO));
actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(),
getAction(editor, ITextEditorActionConstants.REDO));
actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(),
getAction(editor, ITextEditorActionConstants.CUT));
actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(),
getAction(editor, ITextEditorActionConstants.COPY));
actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(),
getAction(editor, ITextEditorActionConstants.PASTE));
actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(),
getAction(editor, ITextEditorActionConstants.SELECT_ALL));
actionBars.setGlobalActionHandler(ActionFactory.FIND.getId(),
getAction(editor, ITextEditorActionConstants.FIND));
actionBars.setGlobalActionHandler(
ActionFactory.DELETE.getId(),
getAction(editor, ITextEditorActionConstants.DELETE));
actionBars.setGlobalActionHandler(
ActionFactory.UNDO.getId(),
getAction(editor, ITextEditorActionConstants.UNDO));
actionBars.setGlobalActionHandler(
ActionFactory.REDO.getId(),
getAction(editor, ITextEditorActionConstants.REDO));
actionBars.setGlobalActionHandler(
ActionFactory.CUT.getId(),
getAction(editor, ITextEditorActionConstants.CUT));
actionBars.setGlobalActionHandler(
ActionFactory.COPY.getId(),
getAction(editor, ITextEditorActionConstants.COPY));
actionBars.setGlobalActionHandler(
ActionFactory.PASTE.getId(),
getAction(editor, ITextEditorActionConstants.PASTE));
actionBars.setGlobalActionHandler(
ActionFactory.SELECT_ALL.getId(),
getAction(editor, ITextEditorActionConstants.SELECT_ALL));
actionBars.setGlobalActionHandler(
ActionFactory.FIND.getId(),
getAction(editor, ITextEditorActionConstants.FIND));
actionBars.setGlobalActionHandler(
IDEActionFactory.BOOKMARK.getId(),
getAction(editor, IDEActionFactory.BOOKMARK.getId()));
IDEActionFactory.BOOKMARK.getId(),
getAction(editor, IDEActionFactory.BOOKMARK.getId()));
actionBars.updateActionBars();
}
}
private void createActions() {
sampleAction = new Action() {
public void run() {
MessageDialog.openInformation(null, "CupPlugin", "Sample Action Executed");
MessageDialog.openInformation(null, "CupPlugin",
"Sample Action Executed");
}
};
sampleAction.setText("Sample Action");
sampleAction.setToolTipText("Sample Action tool tip");
sampleAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
getImageDescriptor(IDE.SharedImages.IMG_OBJS_TASK_TSK));
sampleAction.setImageDescriptor(PlatformUI.getWorkbench()
.getSharedImages()
.getImageDescriptor(IDE.SharedImages.IMG_OBJS_TASK_TSK));
}
public void contributeToMenu(IMenuManager manager) {
IMenuManager menu = new MenuManager("Editor &Menu");
manager.prependToGroup(IWorkbenchActionConstants.MB_ADDITIONS, menu);
menu.add(sampleAction);
}
public void contributeToToolBar(IToolBarManager manager) {
manager.add(new Separator());
manager.add(sampleAction);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment