针对AbstractGraphicalEditPart(GMF)的上下文相关帮助

时间:2019-04-10 09:39:53

标签: java swt eclipse-rcp eclipse-gmf

问题很简单:要添加上下文相关帮助,我按照标准步骤进行操作,但是一旦我尝试使用IWorkbenchHelpSystem中的SetHelp()将块链接到上下文ID,就可以了。第一个参数应为Control(swt)或IAction。
void setHelp(Control control,String helpContextId);。如何从damos.dml.Block对象类型引用Control? org.eclipselabs.damos.dml.blockTypes

仅供参考 我已经尝试并访问了这些网站的所有内容

显示和搜索方法可以正常工作,但是我只需要设置帮助而不显示它,这样仅在调用帮助(F1或ctrl + F1)时才会显示上下文帮助。

谢谢。 经过尝试之后,我想也许这种解决方法可以使我获得与NADA相同的结果。

private Block getBlock() {
        EObject semanticElement = resolveSemanticElement();
        if (semanticElement instanceof Block) {
            Block block = (Block) semanticElement;
            PlatformUI.getWorkbench().getHelpSystem().search(block.getType().getName());
//PlatformUI.getWorkbench().getHelpSystem().setHelp(?, Activator.HELP_VIEW); Cannot cast block directly to Control 
PlatformUI.getWorkbench().getHelpSystem().displayHelp(Activator.HELP_VIEW);
                return block;
            } else {
                return null;
            }
        }

 @Override
protected NodeFigure createMainFigure() {
    blockFigure = new BlockFigure();
    // OB: java.awt.event.KeyEvent.VK_F1 is wrong, use SWT.F1
    blockFigure.setFocusTraversable(true);
    blockFigure.setRequestFocusEnabled(true);
    blockFigure.addMouseListener(new MouseListener.Stub() {
        @Override
        public void mousePressed(final MouseEvent me) {
            blockFigure.requestFocus();
        }
    });
    blockFigure.addKeyListener(new KeyListener.Stub() {

        @Override
        public void keyReleased(KeyEvent ke) {

        }

        @Override
        public void keyPressed(KeyEvent ke) {
            if (ke.keycode == SWT.F1) {
                PlatformUI.getWorkbench().getHelpSystem().search(getBlock().getType().getName());
                PlatformUI.getWorkbench().getHelpSystem().displayHelp(Activator.HELP_VIEW);
            }
        }
    });
    return blockFigure;
}

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

   public String getSelection() {
            String blockName = "SelectBlock";
            EObject element = null;
            EditPart part = getDiagramEditPart();
            EditPartViewer viewer = part.getViewer();
            List selectedList = viewer.getSelectedEditParts();
            try {
                GraphicalEditPart editPart = (GraphicalEditPart) selectedList.get(0);
                BlockEditPart blockPart = (BlockEditPart) editPart;
                viewer.getProperty("BlockFigure");
                NodeImpl node = (NodeImpl) blockPart.getModel();
                element = node.getElement();
            } catch (IndexOutOfBoundsException e) {
                // TODO: handle exception
                e.printStackTrace();
            }

            ISelection selection1 = viewer.getSelection();// EURêKA

            if (element instanceof Block) {
                Control control2 = getGraphicalViewer().getControl();
                blockName = ((Block) element).getType().getName();
                return blockName;
                // return part.getParent().getSelected();
            }
            return "SelectBlock";
        }

我可以选择一个块类型CTRL + F1,请显示该块的帮助定义。