上一主题下一主题
关键字
主题 : 今天自己开发了一个eclipse插件
rpc eclipse插件开发 rap开发 swt jface开发
级别: 北风工程师


UID: 214762
精华: 0
发帖: 243
威望: 2538 点
学点: 1500 点
贡献: 81 点
好评: 0 点
学币: 78 个
注册时间: 2010-01-22
最后登录: 2015-11-24
楼主  发表于: 2014-06-11 21:25||

今天自己开发了一个eclipse插件

今天自己****发了一个eclipse插件用于拷贝当前选中的文件或者目录的文件夹到剪切板分享一下代码需要完成插件代码请发邮箱到515768476 qq邮箱索取 w<d*#$[,*  
package cn.com.mg.copytouchversion; yH(V&Tv  
uiK:*[  
import org.eclipse.core.resources.IFile; >i8~dEbB  
import org.eclipse.core.resources.IResource; W#45a.v  
import org.eclipse.core.runtime.IAdaptable; h[l{ 5Z*  
+(AwSh!  
import org.eclipse.jdt.internal.core.JarPackageFragmentRoot; ;Prg'R[o;  
import org.eclipse.jdt.internal.core.PackageFragment; XZ@ >]P  
\Ut S>4w\  
import org.eclipse.jface.action.IAction; 3o7xN=N  
import org.eclipse.jface.dialogs.MessageDialog; fm6]CU1^  
import org.eclipse.jface.viewers.ISelection; Xa Gz].Sv  
import org.eclipse.jface.viewers.IStructuredSelection; ' C6:e?R  
T{~MiC6A  
import org.eclipse.swt.dnd.Clipboard; 7z>+w  
import org.eclipse.swt.dnd.TextTransfer; QX/]gX  
import org.eclipse.swt.dnd.Transfer; Q=XA"R  
import org.eclipse.swt.widgets.Display; au A.6DQ  
import org.eclipse.swt.widgets.Shell; g _x\T +=  
w#d} TY  
import org.eclipse.ui.IActionDelegate; T Xl\hL\+  
import org.eclipse.ui.IObjectActionDelegate; \#_@qHAG  
import org.eclipse.ui.IWorkbenchPart; *lY+Yy(  
1G_xP^H!  
import j****a.io.File; Rh yegD  
]kH}lr yG  
PoY>5  
@SuppressWarnings("restriction") T/5nu ?v  
public class CopyPathAction implements IObjectActionDelegate { m^c%]5$  
    private Object selected = null; Xi*SDy  
    private Class selectedClass = null; z}mvX .j7  
eAU"fu6d  
    /**  * Constructor for EasyExploreAction.  */ public CopyPathAction() { _AAx )  
        super(); >T(M0Tkt  
    } [5-!d!a|st  
|/2LWc?  
    /**  * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)  */ public void setActivePart(IAction action, IWorkbenchPart targetPart) {  TVj1C  
    } MXh^dOWR  
w8U2y/:>  
    /**  * @see IActionDelegate#run(IAction)  */ public void run(IAction action) { TLX^~W[gOm  
        if (selected == null) { wbl ${@4  
            MessageDialog.openInformation(new Shell(), "Easy Explorer", =sL(^UISl  
                "Unable to explore " + selectedClass.getName()); *;Ak5.du  
Ep,1}Dx  
            return; -aA<.+  
        } D@2Ya/c  
Mn-<51.%  
        File directory = null; .!!79 6hS  
        String fullPath = ""; -Zttj/K  
d!w1t=2H  
        if (selected instanceof IResource) { R<_mK33hd  
            directory = new File(((IResource) selected).getLocation() 2c!h2$w  
                                  .toOSString()); %!>k#F^S  
            fullPath = directory.getAbsolutePath(); S|s3}]g9  
        } else if (selected instanceof File) { 'et(:}i  
            directory = (File) selected; `x5ll;"J  
            fullPath = directory.getAbsolutePath(); yo'q[YtP'  
        } =H L9Z  
;&/sj-xJ2  
        if (selected instanceof IFile) { ;CLR{t(N#V  
            fullPath = directory.getAbsolutePath(); (Be$$W  
            directory = directory.getParentFile(); ojiM2QT}m  
        } ;|2U f   
N+ak[axN  
        if (selected instanceof File) { wEZqkV  
            fullPath = directory.getAbsolutePath(); o:p{^D@#k  
            directory = directory.getParentFile(); hQ\#Fhu7  
        } W,0KBkkp  
sxf}Mmsk  
        try { `#-p,NElV  
            Clipboard cd = new Clipboard(Display.getCurrent()); cYBrRTrI#  
            cd.setContents(new Object[] { fullPath }, 2l]C55p)s  
                new Transfer[] { TextTransfer.getInstance() }); F Bd+=bx,Z  
        } catch (Exception e) { =MQ2sb  
            e.printStackTrace(); kfH9Y%bOy  
        } W66}\&5  
    } V3aY]#Su  
11nO<WH  
    /**  * @see IActionDelegate#selectionChanged(IAction, ISelection)  */ public void selectionChanged(IAction action, ISelection selection) { }W^V^i)  
        IAdaptable adaptable = null; D/+@d:-G  
        this.selected = null; %Z-TbOX  
UMnR=~.  
        if (selection instanceof IStructuredSelection) { V>~*]N^f  
            adaptable = (IAdaptable) ((IStructuredSelection) selection).getFirstElement(); @]}Qh;a~  
            this.selectedClass = adaptable.getClass(); /v<e$0~s<  
2gK p\!  
            if (adaptable instanceof IResource) { V}3~7(   
                this.selected = (IResource) adaptable; rd f85%%7  
            } else if (adaptable instanceof PackageFragment &&  |V*e2w  
                    ((PackageFragment) adaptable).getPackageFragmentRoot() instanceof JarPackageFragmentRoot) { %'K +$  
                this.selected = getJarFile(((PackageFragment) adaptable).getPackageFragmentRoot()); ?dATMmT-  
            } else if (adaptable instanceof JarPackageFragmentRoot) { oW\Q>c7 =  
                this.selected = getJarFile(adaptable); X"]mR7k  
            } else { 7~Xu71^3s  
                this.selected = (IResource) adaptable.getAdapter(IResource.class); +4p2KYO  
            } `UzCq06rJ1  
        } E!O(:/*  
    } ~a0d .dU  
1{Sx V  
    protected File getJarFile(IAdaptable adaptable) { ]xVL11p  
        JarPackageFragmentRoot jpfr = (JarPackageFragmentRoot) adaptable; j:\_*f  
        File selected = (File) jpfr.getPath().makeAbsolute().toFile(); kG~ivB}x  
]c~rPi  
        if (!((File) selected).exists()) { \f<thd*bC  
            File projectFile = new File(jpfr.getJ****aProject().getProject() `s|\" @ 2  
                                            .getLocation().toOSString()); .*clY  
            selected = new File(projectFile.getParent() + selected.toString()); v@<lEG#$"|  
        } 's%ct}y\J  
C$EFh4  
        return selected; hyr5D9d  
    } ek_i{'hFd  
}
此帖悬赏中(剩余时间:已结束)...
最佳答案: 1 学点
只要翅膀硬,哪里没有天~~