[5] | 1 | package de.ugoe.cs.swe.bnftools.ui.views.syntaxdiagram;
|
---|
| 2 |
|
---|
| 3 | import org.eclipse.draw2d.ColorConstants;
|
---|
| 4 | import org.eclipse.draw2d.Figure;
|
---|
| 5 | import org.eclipse.draw2d.FigureCanvas;
|
---|
| 6 | import org.eclipse.draw2d.LightweightSystem;
|
---|
| 7 | import org.eclipse.draw2d.MarginBorder;
|
---|
| 8 | import org.eclipse.draw2d.ToolbarLayout;
|
---|
| 9 | import org.eclipse.draw2d.Viewport;
|
---|
| 10 | import org.eclipse.draw2d.geometry.Rectangle;
|
---|
| 11 | import org.eclipse.jface.text.ITextSelection;
|
---|
| 12 | import org.eclipse.jface.viewers.ISelection;
|
---|
| 13 | import org.eclipse.swt.SWT;
|
---|
| 14 | import org.eclipse.swt.layout.FillLayout;
|
---|
| 15 | import org.eclipse.swt.widgets.Composite;
|
---|
| 16 | import org.eclipse.ui.IEditorPart;
|
---|
| 17 | import org.eclipse.ui.ISelectionListener;
|
---|
| 18 | import org.eclipse.ui.IWorkbenchPage;
|
---|
| 19 | import org.eclipse.ui.IWorkbenchPart;
|
---|
| 20 | import org.eclipse.ui.PlatformUI;
|
---|
| 21 | import org.eclipse.ui.part.ViewPart;
|
---|
| 22 | import org.eclipse.xtext.parsetree.NodeAdapter;
|
---|
| 23 | import org.eclipse.xtext.ui.editor.XtextEditor;
|
---|
| 24 |
|
---|
| 25 | import de.ugoe.cs.swe.bnftools.utils.Utils;
|
---|
| 26 |
|
---|
| 27 | public class SyntaxDiagramView extends ViewPart {
|
---|
| 28 |
|
---|
| 29 | public static final String ID = "org.etsi.bnftools.views.syntaxdiagram.SyntaxDiagramView"; //$NON-NLS-1$
|
---|
| 30 |
|
---|
| 31 | private FigureCanvas canvas;
|
---|
| 32 |
|
---|
| 33 | public SyntaxDiagramView() {
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | public void createPartControl(Composite parent) {
|
---|
| 37 | Composite container = new Composite(parent, SWT.NONE);
|
---|
| 38 |
|
---|
| 39 | container.setLayout(new FillLayout());
|
---|
| 40 | canvas = new FigureCanvas(container, SWT.V_SCROLL | SWT.H_SCROLL);
|
---|
| 41 | canvas.setViewport(new Viewport(true));
|
---|
| 42 | canvas.setScrollBarVisibility(FigureCanvas.ALWAYS);
|
---|
| 43 |
|
---|
| 44 | createActions();
|
---|
| 45 | initializeToolBar();
|
---|
| 46 | initializeMenu();
|
---|
| 47 |
|
---|
| 48 | getSite().getWorkbenchWindow().getSelectionService()
|
---|
| 49 | .addPostSelectionListener(new ISelectionListener() {
|
---|
| 50 | public void selectionChanged(IWorkbenchPart part,
|
---|
| 51 | ISelection selection) {
|
---|
| 52 | if (selection instanceof ITextSelection) {
|
---|
| 53 | IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
|
---|
| 54 | if (activePage == null)
|
---|
| 55 | return;
|
---|
| 56 | IEditorPart activeEditor = activePage.getActiveEditor();
|
---|
| 57 | if (activeEditor == null)
|
---|
| 58 | return;
|
---|
| 59 | XtextEditor xtextEditor = (XtextEditor) activeEditor.getAdapter(XtextEditor.class);
|
---|
| 60 |
|
---|
| 61 | ITextSelection mySelection = (ITextSelection) selection;
|
---|
| 62 |
|
---|
| 63 | if ((xtextEditor != null) && (mySelection != null)) {
|
---|
| 64 | NodeAdapter node = Utils.findNodeFromSelection(
|
---|
| 65 | xtextEditor, mySelection);
|
---|
| 66 | if (node != null)
|
---|
| 67 | draw(node);
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 | });
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | public void draw(NodeAdapter node) {
|
---|
| 75 | Figure mainFigure = new Figure();
|
---|
| 76 | mainFigure.setBounds(new Rectangle(canvas.getBounds()));
|
---|
| 77 | ToolbarLayout mainLayout = new ToolbarLayout();
|
---|
| 78 | mainLayout.setStretchMinorAxis(false);
|
---|
| 79 | mainLayout.setMinorAlignment(ToolbarLayout.ALIGN_CENTER);
|
---|
| 80 | mainFigure.setLayoutManager(mainLayout);
|
---|
| 81 | mainFigure.setOpaque(true);
|
---|
| 82 | mainFigure.setBackgroundColor(ColorConstants.white);
|
---|
| 83 | mainFigure.setBorder(new MarginBorder(10));
|
---|
| 84 |
|
---|
| 85 | canvas.setContents(mainFigure);
|
---|
| 86 |
|
---|
| 87 | LightweightSystem lws = new LightweightSystem(canvas);
|
---|
| 88 | lws.setContents(canvas.getViewport());
|
---|
| 89 |
|
---|
| 90 | SyntaxDiagramFigure newSyntaxDiagram = new SyntaxDiagramCreator(node).createSyntaxDiagram();
|
---|
| 91 |
|
---|
| 92 | mainFigure.add(newSyntaxDiagram);
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | private void createActions() {
|
---|
| 96 | // Create the actions
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | private void initializeToolBar() {
|
---|
| 100 | // IToolBarManager toolbarManager = getViewSite().getActionBars()
|
---|
| 101 | // .getToolBarManager();
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | private void initializeMenu() {
|
---|
| 105 | // IMenuManager menuManager = getViewSite().getActionBars()
|
---|
| 106 | // .getMenuManager();
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | @Override
|
---|
| 110 | public void setFocus() {
|
---|
| 111 | // Set the focus
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | } |
---|