ConvertFromAction

来源:互联网 发布:c语言buffer 编辑:程序博客网 时间:2024/05/28 11:50
package com.test.myplugin.handlers;


import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IType;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.ISelectionService;
import org.eclipse.ui.internal.Workbench;


import com.test.myplugin.ConvertStore;


public class ConvertFromAction extends AbstractHandler{


@Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
ISelectionService selectionService =     
                Workbench.getInstance().getActiveWorkbenchWindow().getSelectionService();    
        ISelection selection = selectionService.getSelection();  
        
        Object [] compUnits = ((IStructuredSelection) selection).toArray();
        
        ICompilationUnit compUnit = (ICompilationUnit) compUnits[0];
        IType type = compUnit.findPrimaryType();
        ConvertStore.setValue("from", type);
        
return null;
}

}
0 0
原创粉丝点击