package open_file_location.actions;
import java.io.IOException;
import org.eclipse.core.internal.resources.Project;
import org.eclipse.core.internal.resources.WorkspaceRoot;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.ISelectionService;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.ui.internal.Workbench;
import org.eclipse.jface.dialogs.MessageDialog;
/**
* Our sample action implements workbench action delegate.
* The action proxy will be created by the workbench and
* shown in the UI. When the user tries to use the action,
* this delegate will be created and execution will be
* delegated to it.
* @see IWorkbenchWindowActionDelegate
*/
public class SampleAction implements IWorkbenchWindowActionDelegate {
private IWorkbenchWindow window;
/**
* The constructor.
*/
public SampleAction() {
}
/**
* The action has been activated. The argument of the
* method represents the 'real' action sitting
* in the workbench UI.
* @see IWorkbenchWindowActionDelegate#run
*/
public void run(IAction action) {
String SelectionLocationTmp = getCurrentSelectionLoction();
if (SelectionLocationTmp == null) {
MessageDialog.openInformation(
window.getShell(),
"失去目标!",
"没有要打开的目标,请选择一个目标!");
} else {
String SelectionLocation = SelectionLocationTmp.replace("/", "\\");
String ExploerPath = "explorer.exe";
try {
Runtime.getRuntime().exec(ExploerPath+" "+SelectionLocation+"\"");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
/**
* Selection in the workbench has been changed. We
* can change the state of the 'real' action here
* if we want, but this can only happen after
* the delegate has been created.
* @see IWorkbenchWindowActionDelegate#selectionChanged
*/
public void selectionChanged(IAction action, ISelection selection) {
}
/**
* We can use this method to dispose of any system
* resources we previously allocated.
* @see IWorkbenchWindowActionDelegate#dispose
*/
public void dispose() {
}
/**
* We will cache window object in order to
* be able to provide parent shell for the message dialog.
* @see IWorkbenchWindowActionDelegate#init
*/
public void init(IWorkbenchWindow window) {
this.window = window;
}
public static String getCurrentSelectionLoction(){
ISelectionService selectionService =
Workbench.getInstance().getActiveWorkbenchWindow().getSelectionService();
ISelection selection = selectionService.getSelection();
//IProject project = null;
IResource resource = null;
if(selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection)selection).getFirstElement();
if (element instanceof IResource) {
resource= ((IResource)element).getProject();
String resourceLocation = ((IResource)element).getLocation().toString();
int isProject = resourceLocation.compareTo(resource.getLocation().toString());
if (isProject > 0) {
String FilePath = resourceLocation;
String FileLocation[] = FilePath.split("/");
String fileLocation="" ;
int length = FileLocation.length;
for (int i = 0; i < length-1; i++) {
fileLocation = fileLocation + FileLocation[i] + "/";
}
return fileLocation;
}
} else if (element instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) element;
resource = (IResource) adaptable.getAdapter(org.eclipse.core.resources.IResource.class);
if (resource instanceof IFile) {
String FilePath = ((IFile) resource).getLocation().toString();
String FileLocation[] = FilePath.split("/");
String fileLocation="" ;
int length = FileLocation.length;
for (int i = 0; i < length-1; i++) {
fileLocation = fileLocation + FileLocation[i] + "/";
}
return fileLocation;
}
}
}
if (resource == null) {
return null;
}
if (resource.getLocation() != null) {
String FilePath = resource.getLocation().toString();
String FileLocation[] = FilePath.split("/");
String fileLocation="" ;
int length = FileLocation.length;
for (int i = 0; i < length-1; i++) {
fileLocation = fileLocation + FileLocation[i] + "/";
}
return fileLocation;
} else {
return null;
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
eclipse 打开选中文件或文件夹位置
共10个文件
gif:2个
classpath:1个
prefs:1个
需积分: 32 15 下载量 39 浏览量
2014-05-30
18:00:54
上传
评论
收藏 7KB RAR 举报
温馨提示
eclipse 有一个插件是open explorer,我最近下载下来安装不能用了,查了一下原理,自己开发了一个小插件 该插件主要是可以用windows的explorer 打开eclipse中被选择的文件或文件夹的位置,不用再复制路径信息然后粘贴到浏览器中打开。 这是源码,而且功能只是足够我的项目开发的需要,也许不满足他人的需要,可以自行下载进行修改
资源推荐
资源详情
资源评论
收起资源包目录
Open File Location.rar (10个子文件)
Open File Location
.project 679B
plugin.xml 658B
icons
sample.gif 351B
sample-1.gif 857B
src
open_file_location
actions
SampleAction.java 5KB
build.properties 134B
.settings
org.eclipse.jdt.core.prefs 364B
META-INF
MANIFEST.MF 371B
.classpath 376B
bin
open_file_location
actions
SampleAction.class 4KB
共 10 条
- 1
资源评论
flying_tear
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- python:利用matplotlib绘制直方图
- 基于matlab块匹配全景图像拼接系统代码12
- 基于matlab小波变换图像融合系统代码11
- 精雕3.5NC后置文件
- yolov8n-pose.pt 用 yolov8n-pose.onnx下载
- C++之STL的vector详解,包括初始化和各种函数:vector的初始化、数据的增删查改等
- stable-diffusion-webui-master
- openPLC-Editor C语言编程 在mp157 arm板上调用io等使用记录
- 无人机悬停时间计算软件.rar
- 主要讲解 mybatis中 实体层的属性与表的列不一致时如何处理? 可以采用将列重命名方法还可以采用resultMap 方式
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功