上一主题下一主题
关键字
主题 : 今天自己开发了一个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邮箱索取 ($vaj;  
package cn.com.mg.copytouchversion; 7/UdE:~]*=  
B S^P&TR!  
import org.eclipse.core.resources.IFile; %z_L}L  
import org.eclipse.core.resources.IResource; jW< aAd  
import org.eclipse.core.runtime.IAdaptable; RPh8n4&("  
0\X' a}8Bu  
import org.eclipse.jdt.internal.core.JarPackageFragmentRoot; ]CnqPLqL  
import org.eclipse.jdt.internal.core.PackageFragment; X^% E"{!nU  
<:YD.zAh|  
import org.eclipse.jface.action.IAction; Y;B#_}yF  
import org.eclipse.jface.dialogs.MessageDialog; @8$3Q,fF(  
import org.eclipse.jface.viewers.ISelection; ;/- X;!a>  
import org.eclipse.jface.viewers.IStructuredSelection; h]w5N2$}?  
A:JW Ux  
import org.eclipse.swt.dnd.Clipboard; $1ZF kw  
import org.eclipse.swt.dnd.TextTransfer; LL}b]B[  
import org.eclipse.swt.dnd.Transfer; ]ICBNJ  
import org.eclipse.swt.widgets.Display; z"*$ .  
import org.eclipse.swt.widgets.Shell; `(dRb  
ywl7bU-f  
import org.eclipse.ui.IActionDelegate; D_(K{? KU  
import org.eclipse.ui.IObjectActionDelegate; E~| XY9U36  
import org.eclipse.ui.IWorkbenchPart; Do\YPo_Mr  
\.AI;^)X@]  
import j****a.io.File; |TE\]  
rf:C B&u  
8>(DQ"h  
@SuppressWarnings("restriction") |-'.\)7:  
public class CopyPathAction implements IObjectActionDelegate { J]=2] oI2  
    private Object selected = null; zr1,A#BV  
    private Class selectedClass = null; d O'apey  
gvi]#|  
    /**  * Constructor for EasyExploreAction.  */ public CopyPathAction() { ="Edt+a)t  
        super(); yS2[V,vS7  
    } #]_S)_Z-  
wwI'n*Q'$  
    /**  * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)  */ public void setActivePart(IAction action, IWorkbenchPart targetPart) { ;[[GA0  
    } 5( }Qg9%  
RE?j)$y?`  
    /**  * @see IActionDelegate#run(IAction)  */ public void run(IAction action) { r:n-?P  
        if (selected == null) { oP0ZJK&;  
            MessageDialog.openInformation(new Shell(), "Easy Explorer", ?xgrr7  
                "Unable to explore " + selectedClass.getName()); 1M F0HiC  
$sTvXf:g  
            return; TM1D|H  
        } "VfV;)]|w  
 #VA8a=t  
        File directory = null; TiF2c#Q* y  
        String fullPath = ""; IxxA8[^V  
HcKZmL. wp  
        if (selected instanceof IResource) { 8pQ:B /3=  
            directory = new File(((IResource) selected).getLocation() oB8x_0#n  
                                  .toOSString()); Wz^M*=,  
            fullPath = directory.getAbsolutePath(); lW8!_h"G`n  
        } else if (selected instanceof File) { nYF *f  
            directory = (File) selected; EEJsNF  
            fullPath = directory.getAbsolutePath(); ~_YU%y  
        } |,G=k,?_p  
t'F_1P^*/  
        if (selected instanceof IFile) { ]mW)T0_  
            fullPath = directory.getAbsolutePath(); s7~[7  
            directory = directory.getParentFile(); p 7YfOUo k  
        } O [81nlhS0  
<g^!xX<r?  
        if (selected instanceof File) { )7j CEA03  
            fullPath = directory.getAbsolutePath(); tluyx  
            directory = directory.getParentFile(); D}| 30s?u1  
        } LE" t'R   
;~>E^0M  
        try { -5Km 9X8  
            Clipboard cd = new Clipboard(Display.getCurrent()); Dn#GoDMJ[  
            cd.setContents(new Object[] { fullPath }, M]Y72K^  
                new Transfer[] { TextTransfer.getInstance() }); #n[1%8l,  
        } catch (Exception e) { qC%[J:RwF  
            e.printStackTrace(); kr_!AW<.tz  
        } WG_20Jd JY  
    }  VS:UVe  
LD~s@}yH>  
    /**  * @see IActionDelegate#selectionChanged(IAction, ISelection)  */ public void selectionChanged(IAction action, ISelection selection) { .skR4f,h  
        IAdaptable adaptable = null; <KFE.\*Z4  
        this.selected = null; x*9CK8o=  
^rKA=siz  
        if (selection instanceof IStructuredSelection) { 0V:DeX$bZ  
            adaptable = (IAdaptable) ((IStructuredSelection) selection).getFirstElement(); g8_C|lVZi  
            this.selectedClass = adaptable.getClass(); 4l2xhx  
-%U 15W;  
            if (adaptable instanceof IResource) { \I"UW1)B  
                this.selected = (IResource) adaptable; UI*^$7z1 +  
            } else if (adaptable instanceof PackageFragment && b$24${*'  
                    ((PackageFragment) adaptable).getPackageFragmentRoot() instanceof JarPackageFragmentRoot) { ]J t8]w  
                this.selected = getJarFile(((PackageFragment) adaptable).getPackageFragmentRoot()); _PPW9US{  
            } else if (adaptable instanceof JarPackageFragmentRoot) { xz+Y1fYT  
                this.selected = getJarFile(adaptable); Y{ho[%  
            } else { 4)BPrWea1  
                this.selected = (IResource) adaptable.getAdapter(IResource.class); Y!kz0 ([  
            } Qr/8kWa0 C  
        } x=>+.'K  
    } 3q>6gaTv  
7I6bZ;}d  
    protected File getJarFile(IAdaptable adaptable) { o|s JTY  
        JarPackageFragmentRoot jpfr = (JarPackageFragmentRoot) adaptable; 2>.2H  
        File selected = (File) jpfr.getPath().makeAbsolute().toFile(); r 3@Q(Rb  
0 gyg  
        if (!((File) selected).exists()) { J {gqm  
            File projectFile = new File(jpfr.getJ****aProject().getProject() I$Q%i Z{  
                                            .getLocation().toOSString()); xb!h?F&  
            selected = new File(projectFile.getParent() + selected.toString()); n.{+\M6k  
        } |EJ&s393&  
ZD9UE3-  
        return selected; !9!kb  
    } qNhQ2x\  
}
此帖悬赏中(剩余时间:已结束)...
最佳答案: 1 学点
只要翅膀硬,哪里没有天~~