⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractcontextmenuprovider.java

📁 对eclipse gef进行封装,可以生成图形化编辑器
💻 JAVA
字号:
/*******************************************************************************
 * $Header: /cvsroot/EOS6/work_dir/niegy/com.primeton.studio.gef.ui/src/com/primeton/studio/gef/ui/editor/AbstractContextMenuProvider.java,v 1.4 2006/12/11 04:04:00 niegy Exp $
 * $Revision: 1.4 $
 * $Date: 2006/12/11 04:04:00 $
 *
 *==============================================================================
 *
 * Copyright (c) 2001-2006 Primeton Technologies, Ltd.
 * All rights reserved. 
 * 
 * Created on 2006-9-28
 *******************************************************************************/


package com.primeton.studio.gef.ui.editor;

import org.eclipse.gef.ContextMenuProvider;
import org.eclipse.gef.EditPartViewer;
import org.eclipse.gef.ui.actions.ActionRegistry;
import org.eclipse.gef.ui.actions.GEFActionConstants;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.ui.actions.ActionFactory;

import com.primeton.studio.gef.ui.Constants;

/**
 * TODO此处填写 class 信息
 *
 * @author niegy (mailto:niegy@primeton.com)
 */
/*
 * 修改历史
 * $Log: AbstractContextMenuProvider.java,v $
 * Revision 1.4  2006/12/11 04:04:00  niegy
 * 重构代码
 *
 * Revision 1.3  2006/12/08 07:04:32  niegy
 * 重构代码
 *
 * Revision 1.2  2006/12/05 05:18:59  niegy
 * 修改模型,增加连线的扩展点
 *
 * Revision 1.1  2006/11/17 03:15:13  niegy
 * create
 * 
 */
public abstract class AbstractContextMenuProvider extends ContextMenuProvider {

    /** The editor's action registry. */
    private ActionRegistry actionRegistry;
        
    /**
     * Instantiate a new menu context provider for the specified EditPartViewer 
     * and ActionRegistry.
     * @param viewer    the editor's graphical viewer
     * @param registry  the editor's action registry
     * @throws IllegalArgumentException if registry is <tt>null</tt>. 
     */
//    public AbstractContextMenuProvider(EditPartViewer viewer, ActionRegistry registry) {
//        super(viewer);
//        if (registry == null) {
//            throw new IllegalArgumentException();
//        }
//        actionRegistry = registry;
//    }

    public AbstractContextMenuProvider(){
    	super(null);
    }
    
    /**
     * 初试化MenuProvider
     * @param viewer
     * @param registry
     */
    public void iniContextMenuProvider(EditPartViewer viewer, ActionRegistry registry){
    	setViewer(viewer);
    	addMenuListener(this);
    	setRemoveAllWhenShown(true);
    	if (registry == null) {
             throw new IllegalArgumentException();
        }
        actionRegistry = registry;
    }
    /**
     * Called when the context menu is about to show. Actions, 
     * whose state is enabled, will appear in the context menu.
     * @see org.eclipse.gef.ContextMenuProvider#buildContextMenu(org.eclipse.jface.action.IMenuManager)
     */
    public void buildContextMenu(IMenuManager menu) {
        // Add standard action groups to the menu
        GEFActionConstants.addStandardActionGroups(menu);
        
        // Add actions to the menu
        menu.appendToGroup(
                GEFActionConstants.GROUP_UNDO, // target group id
                getAction(ActionFactory.UNDO.getId())); // action to add
        menu.appendToGroup(
                GEFActionConstants.GROUP_UNDO, 
                getAction(ActionFactory.REDO.getId()));
        
        menu.appendToGroup(GEFActionConstants.GROUP_REST,
                getAction(Constants.ATTRIBUTE));
        
        menu.appendToGroup(GEFActionConstants.GROUP_REST,
                getAction(Constants.OPERAND));
        
        menu.appendToGroup(GEFActionConstants.GROUP_REST,
                getAction(Constants.ACTION_GROUP));
        
        menu.appendToGroup(GEFActionConstants.GROUP_REST,
                getAction(Constants.ACTION_UNGROUP));
        
        menu.appendToGroup(
                GEFActionConstants.GROUP_EDIT,
                getAction(ActionFactory.COPY.getId()));
        
        menu.appendToGroup(
                GEFActionConstants.GROUP_EDIT,
                getAction(ActionFactory.CUT.getId()));
        
        menu.appendToGroup(
                GEFActionConstants.GROUP_EDIT,
                getAction(ActionFactory.PASTE.getId()));
        
        menu.appendToGroup(
                GEFActionConstants.GROUP_EDIT,
                getAction(ActionFactory.DELETE.getId()));
        
        menu.appendToGroup(GEFActionConstants.GROUP_REST,
                getAction(ActionFactory.SELECT_ALL.getId()));
        
        menu.appendToGroup(GEFActionConstants.GROUP_REST,
                getAction("properties"));
        
    }

    private IAction getAction(String actionId) {
        return actionRegistry.getAction(actionId);
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -