首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

eclipse 自持小工具

2012-07-26 
eclipse自制小工具?源码很简单。?? ?extension? ? ? ? ?pointorg.eclipse.ui.popupMenus? ? ? object

eclipse 自制小工具


eclipse   自持小工具


eclipse   自持小工具

?

源码很简单。

?

? ?<extension

? ? ? ? ?point="org.eclipse.ui.popupMenus">

? ? ? <objectContribution

? ? ? ? ? ? adaptable="true"

? ? ? ? ? ? id="com.lzs.tool.openContribution"

? ? ? ? ? ? objectClass="org.eclipse.core.resources.IContainer">

? ? ? ? ?<action

? ? ? ? ? ? ? ?class="com.lzs.tool.popup.actions.OpenAction"

? ? ? ? ? ? ? ?enablesFor="1"

? ? ? ? ? ? ? ?id="com.lzs.tool.openAction"

? ? ? ? ? ? ? ?label="使用系统打开资源"

? ? ? ? ? ? ? ?menubarPath="additions">

? ? ? ? ?</action>

? ? ? </objectContribution>

? ?</extension>

?

?

?

?

?

package com.lzs.tool.popup.actions;

?

import java.io.File;

import java.io.IOException;

?

import org.eclipse.core.resources.IResource;

import org.eclipse.jface.action.IAction;

import org.eclipse.jface.dialogs.MessageDialog;

import org.eclipse.jface.viewers.ISelection;

import org.eclipse.jface.viewers.IStructuredSelection;

import org.eclipse.swt.widgets.Shell;

import org.eclipse.ui.IObjectActionDelegate;

import org.eclipse.ui.IWorkbenchPart;

//通过os打开对应的资源

public class OpenAction implements IObjectActionDelegate {

?

private Shell shell;

/**

* Constructor for Action1.

*/

public OpenAction() {

super();

}

?

public void setActivePart(IAction action, IWorkbenchPart targetPart) {

shell = targetPart.getSite().getShell();

}

?

public void run(IAction action) {

?

if(o!=null)

{

if(o instanceof IResource)

{

? File file= ((IResource) o).getLocation().toFile();

? try {

java.awt.Desktop.getDesktop().open(file);

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}?

}

private ?Object o;

?

public void selectionChanged(IAction action, ISelection selection) {

if(selection instanceof ?IStructuredSelection)

{

IStructuredSelection ss = (IStructuredSelection) selection;

? ? o= ? ss.getFirstElement();

??

}

}?

?

}

?

下载该插件,直接放到eclipse ?plugins中就可以使用该功能。


热点排行