Search in sources :

Example 1 with Node

use of ch.hsr.ifs.pasta.tree.Node in project ch.hsr.ifs.cdttesting by IFS-HSR.

the class ASTWidget method setupCanvas.

private void setupCanvas() {
    resizeCanvas();
    canvas.setBackground(WHITE);
    canvas.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(final PaintEvent e) {
            if (lastControl != null) {
                adjustView(lastControl);
            }
            if (root != null) {
                root.visit(node -> {
                    if (node.data().getFirst().isVisible()) {
                        if (node.parent() != null) {
                            drawArrowFromParent(e.gc, node);
                        }
                        return NodeVisitor.AfterVisitBehaviour.Continue;
                    }
                    return NodeVisitor.AfterVisitBehaviour.Abort;
                });
            }
        }
    });
}
Also used : IASTPreprocessorIncludeStatement(org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement) NodeVisitor(ch.hsr.ifs.pasta.tree.NodeVisitor) PaintListener(org.eclipse.swt.events.PaintListener) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Rectangle(org.eclipse.swt.graphics.Rectangle) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) LinkedList(java.util.LinkedList) PreferenceConstants(ch.hsr.ifs.pasta.plugin.preferences.PreferenceConstants) Cursor(org.eclipse.swt.graphics.Cursor) Button(org.eclipse.swt.widgets.Button) IASTNode(org.eclipse.cdt.core.dom.ast.IASTNode) IASTFileLocation(org.eclipse.cdt.core.dom.ast.IASTFileLocation) Display(org.eclipse.swt.widgets.Display) CUIPlugin(org.eclipse.cdt.ui.CUIPlugin) Node(ch.hsr.ifs.pasta.tree.Node) MouseEvent(org.eclipse.swt.events.MouseEvent) MouseTrackListener(org.eclipse.swt.events.MouseTrackListener) Color(org.eclipse.swt.graphics.Color) TextSelection(org.eclipse.jface.text.TextSelection) SWT(org.eclipse.swt.SWT) ICPPASTTranslationUnit(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTranslationUnit) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Control(org.eclipse.swt.widgets.Control) IASTTranslationUnit(org.eclipse.cdt.core.dom.ast.IASTTranslationUnit) PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener)

Example 2 with Node

use of ch.hsr.ifs.pasta.tree.Node in project ch.hsr.ifs.cdttesting by IFS-HSR.

the class ASTWidget method createNode.

private Node<Pair<Button, IASTNode>> createNode(final Button button, final IASTNode astNode) {
    final Node<Pair<Button, IASTNode>> node = new Node<>(new Pair<>(button, astNode));
    final Point minButtonSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    nodeHeight = Math.max(nodeHeight, minButtonSize.y);
    node.setWidth(minButtonSize.x);
    node.treatAsLeaf(true);
    if (astNode instanceof ICPPASTTranslationUnit) {
        button.setBackground(GOLDEN_YELLOW);
        button.getFont().getFontData()[0].setStyle(SWT.BOLD);
    }
    button.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(final MouseEvent e) {
            int selectKey = 0;
            if (prefStore.getString(PreferenceConstants.P_HOW_TO_SELECT).equals(PreferenceConstants.P_SELECT_BY_RIGHT_CLICK)) {
                selectKey = 3;
            } else if (prefStore.getString(PreferenceConstants.P_HOW_TO_SELECT).equals(PreferenceConstants.P_SELECT_BY_LEFT_CLICK)) {
                selectKey = 1;
            }
            if (e.button == selectKey) {
                setNodeInNodeView(astNode);
            }
            if (e.button == 1) {
                buildChildrenAndRefresh(node);
            }
        }
    });
    button.addMouseTrackListener(new MouseTrackListener() {

        @Override
        public void mouseHover(final MouseEvent e) {
            if (prefStore.getString(PreferenceConstants.P_HOW_TO_SELECT).equals(PreferenceConstants.P_SELECT_BY_MOUSE_OVER)) {
                setNodeInNodeView(astNode);
            }
            IASTFileLocation fileLocation = astNode.getFileLocation();
            while (fileLocation.getContextInclusionStatement() != null) {
                final IASTPreprocessorIncludeStatement contextInclusionStatement = fileLocation.getContextInclusionStatement();
                fileLocation = contextInclusionStatement.getFileLocation();
            }
            final TextSelection textSelection = new TextSelection(fileLocation.getNodeOffset(), fileLocation.getNodeLength());
            CUIPlugin.getActivePage().getActiveEditor().getEditorSite().getSelectionProvider().setSelection(textSelection);
        }

        @Override
        public void mouseExit(final MouseEvent e) {
        }

        @Override
        public void mouseEnter(final MouseEvent e) {
        }
    });
    return node;
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) TextSelection(org.eclipse.jface.text.TextSelection) IASTNode(org.eclipse.cdt.core.dom.ast.IASTNode) Node(ch.hsr.ifs.pasta.tree.Node) MouseTrackListener(org.eclipse.swt.events.MouseTrackListener) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Point(org.eclipse.swt.graphics.Point) IASTFileLocation(org.eclipse.cdt.core.dom.ast.IASTFileLocation) IASTPreprocessorIncludeStatement(org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement) ICPPASTTranslationUnit(org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTranslationUnit)

Aggregations

Node (ch.hsr.ifs.pasta.tree.Node)2 IASTFileLocation (org.eclipse.cdt.core.dom.ast.IASTFileLocation)2 IASTNode (org.eclipse.cdt.core.dom.ast.IASTNode)2 IASTPreprocessorIncludeStatement (org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement)2 ICPPASTTranslationUnit (org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTranslationUnit)2 TextSelection (org.eclipse.jface.text.TextSelection)2 MouseAdapter (org.eclipse.swt.events.MouseAdapter)2 MouseEvent (org.eclipse.swt.events.MouseEvent)2 MouseTrackListener (org.eclipse.swt.events.MouseTrackListener)2 Point (org.eclipse.swt.graphics.Point)2 PreferenceConstants (ch.hsr.ifs.pasta.plugin.preferences.PreferenceConstants)1 NodeVisitor (ch.hsr.ifs.pasta.tree.NodeVisitor)1 LinkedList (java.util.LinkedList)1 IASTTranslationUnit (org.eclipse.cdt.core.dom.ast.IASTTranslationUnit)1 CUIPlugin (org.eclipse.cdt.ui.CUIPlugin)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 SWT (org.eclipse.swt.SWT)1 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)1 PaintEvent (org.eclipse.swt.events.PaintEvent)1 PaintListener (org.eclipse.swt.events.PaintListener)1