ConvertToAction
来源:互联网 发布:c语言buffer 编辑:程序博客网 时间:2024/06/06 02:58
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 ConvertToAction 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("to", type);
return null;
}
}
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 ConvertToAction 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("to", type);
return null;
}
}
0 0