`
jackini
  • 浏览: 34305 次
社区版块
存档分类
最新评论

Eclipse插件开发常用功能(以后会继续加入)

阅读更多
1、选择java类的Dialog的使用
java 代码
 
  1. final IJavaSearchScope searchScope = SearchEngine  
  2.                 .createWorkspaceScope();  
  3.         addButton.addSelectionListener(new SelectionAdapter() {  
  4.             public void widgetSelected(SelectionEvent e) {  
  5.                 TypeSelectionDialog2 dialog = new TypeSelectionDialog2(  
  6.                         getShell(), false,  
  7.                         new ProgressMonitorDialog(getShell()), searchScope,  
  8.                         IJavaSearchConstants.TYPE);  
  9.                 dialog.setMessage("Select an Entity bean"); //$NON-NLS-1$  
  10.                 dialog.setBlockOnOpen(true);  
  11.                 dialog.setTitle("Type Selection");  
  12.                 if (Dialog.OK == dialog.open()) {  
  13.                     IType obj = (IType) dialog.getFirstResult();  
  14.                     String className = obj.getResource().getName();  
  15.                     String packageName = obj.getPackageFragment()  
  16.                             .getElementName();  
  17.                     list.add(packageName + "."+ className);  
  18.                 }  
  19.             }  
  20.         });  
2、包选择的Dialog的使用
java 代码
 
  1. browseButton.addSelectionListener(new SelectionAdapter() {  
  2.             public void widgetSelected(SelectionEvent e) {  
  3.                 super.widgetSelected(e);  
  4.                 IJavaProject javaProject = JavaCore.create(getProject(obj));  
  5.                 SelectionDialog dialog = null;  
  6.                 try {  
  7.                     dialog = JavaUI  
  8.                             .createPackageDialog(  
  9.                                     getShell(),  
  10.                                     javaProject,  
  11. IJavaElementSearchConstants.CONSIDER_REQUIRED_PROJECTS);  
  12.                     dialog.setTitle("Package Selection");  
  13.                     dialog.setMessage("Choose a folder");  
  14.                 } catch (JavaModelException e1) {  
  15.                     // ExceptionHandler.handleExceptionAndAbort(e1);  
  16.                 }  
  17.                 if (dialog.open() != Window.OK) {  
  18.                     return;  
  19.                 }  
  20.                 IPackageFragment pck = (IPackageFragment) dialog.getResult()[0];  
  21.                 if (pck != null) {  
  22.                     packageTxt.setText(pck.getElementName());  
  23.                 }  
  24.             }  
  25.         });  
 
 3、自定义带有多选框的Dialog的创建及其使用
创建:
java 代码
 
  1. public class CheckboxSelectionDialog extends Dialog {  
  2.   
  3.     class ContentProvider implements IStructuredContentProvider {  
  4.         public Object[] getElements(Object inputElement) {  
  5.             return new Object[] {};  
  6.         }  
  7.   
  8.         public void dispose() {  
  9.         }  
  10.   
  11.         public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {  
  12.         }  
  13.     }  
  14.   
  15.     private Table table;  
  16.   
  17.     private CheckboxTableViewer ctv;  
  18.   
  19.     private TableViewer tv;  
  20.   
  21.     private java.util.List initialSelections;  
  22.   
  23.     private String[] result;  
  24.   
  25.     private String title;  
  26.   
  27.     private String label;  
  28.   
  29.     /** 
  30.      * Create the dialog 
  31.      *  
  32.      * @param parentShell 
  33.      */  
  34.     public CheckboxSelectionDialog (Shell parentShell,  
  35.             java.util.List initialSelections, String title, String label) {  
  36.         super(parentShell);  
  37.         this.initialSelections = initialSelections;  
  38.         this.title = title;  
  39.         this.label = label;  
  40.     }  
  41.   
  42.     /** 
  43.      * Create contents of the dialog 
  44.      *  
  45.      * @param parent 
  46.      */  
  47.     protected Control createDialogArea(Composite parent) {  
  48.         Composite container = (Composite) super.createDialogArea(parent);  
  49.         final GridLayout gridLayout = new GridLayout();  
  50.         container.setLayout(gridLayout);  
  51.   
  52.         final Label selectLabel = new Label(container, SWT.NONE);  
  53.         selectLabel.setLayoutData(new GridData());  
  54.         // selectLabel.setText("Select the ejb container.");  
  55.         selectLabel.setText(label);  
  56.   
  57.         tv = new TableViewer(container, SWT.CHECK | SWT.MULTI | SWT.BORDER  
  58.                 | SWT.FULL_SELECTION);  
  59.         // ctv = new CheckboxTableViewer(tv.getTable());  
  60.         tv.setContentProvider(new ContentProvider());  
  61.         tv.setInput(new Object());  
  62.         table = tv.getTable();  
  63.         table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, truetrue));  
  64.         tv.add(initialSelections.toArray());  
  65.         //  
  66.         return container;  
  67.     }  
  68.   
  69.     /** 
  70.      * Create contents of the button bar 
  71.      *  
  72.      * @param parent 
  73.      */  
  74.     protected void createButtonsForButtonBar(Composite parent) {  
  75.         final Button button = createButton(parent, IDialogConstants.OK_ID,  
  76.                 IDialogConstants.OK_LABEL, true);  
  77.         if (initialSelections.size() <= 0)  
  78.             button.setEnabled(false);  
  79.         createButton(parent, IDialogConstants.CANCEL_ID,  
  80.                 IDialogConstants.CANCEL_LABEL, false);  
  81.     }  
  82.   
  83.     /** 
  84.      * Return the initial size of the dialog 
  85.      */  
  86.     protected Point getInitialSize() {  
  87.         return new Point(300375);  
  88.     }  
  89.   
  90.     public String[] getResult() {  
  91.         return this.result;  
  92.     }  
  93.   
  94.     protected void configureShell(Shell newShell) {  
  95.         super.configureShell(newShell);  
  96.         // newShell.setText("Select EJB Module");  
  97.         newShell.setText(title);  
  98.     }  
  99.   
  100.     protected void buttonPressed(int buttonId) {  
  101.         if (buttonId == IDialogConstants.OK_ID) {  
  102.             TableItem[] children = table.getItems();  
  103.             ArrayList v = new ArrayList(children.length);  
  104.             for (int i = 0; i < children.length; i++) {  
  105.                 TableItem item = children[i];  
  106.                 if (item.getChecked()) {  
  107.                     v.add(item.getData());  
  108.                 }  
  109.             }  
  110.             int size = v.size();  
  111.             result = new String[size];  
  112.             for (int i = 0; i < v.size(); i++)  
  113.                 result[i] = v.get(i).toString();  
  114.         }  
  115.         super.buttonPressed(buttonId);  
  116.     }  
  117.   
  118. }  
使用:
java 代码
 
  1. List list = new ArrayList();  
  2. for (int i = 0; i < file.length; i++) {  
  3.             list.add(i);  
  4. }  
  5.   
  6. CheckModuleSelectionDialog dialog = new CheckModuleSelectionDialog(  
  7.     ProjectUtil.getShell(), list, "Select a Project",  
  8.                 "Select the Project container.");  
  9. if (dialog.open() == ContainerSelectionDialog.OK) {  
  10.     String[] result = dialog.getResult();  
  11. }  
分享到:
评论

相关推荐

    Eclipse插件开发指南

    ### Eclipse插件开发指南 #### 一、Eclipse概述 **1.1 Eclipse简介** Eclipse是一个开源的、可扩展的集成开发环境(IDE),主要应用于Java开发,但通过插件支持,它也广泛用于C/C++、PHP、Python、Ruby等其他语言...

    Eclipse插件开发(英文版) Eclipse plug-ins

    ### Eclipse插件开发知识点概述 #### 一、Eclipse插件开发简介 Eclipse插件开发是指在Eclipse平台上创建自定义插件的过程。Eclipse作为一个开源的集成开发环境(IDE),支持通过添加插件来扩展其功能。《Eclipse...

    Eclipse从入门到精通 常用插件扩展点

    本章中,我们介绍了Eclipse插件开发中两个重要的扩展点:透视图(Perspectives)和视图(Views)。通过学习这些扩展点,开发者可以轻松地构建定制化的开发环境,满足不同项目的需求。在实际开发中,还有许多其他扩展...

    eclipse插件安装方法

    由于其高度可扩展性,用户可以通过安装各种插件来增强Eclipse的功能,满足特定的需求。本文主要介绍一种常用的插件安装方法——通过外部目录安装插件。 #### 二、准备工作 在详细介绍安装方法之前,首先需要做一些...

    如何下载Eclipse开发环境

    - **广泛的插件支持**:用户可以根据需求安装各种插件来扩展Eclipse的功能。 - **良好的社区支持**:拥有活跃的用户社区和丰富的文档资源。 #### 下载Eclipse的准备工作 在下载Eclipse之前,需要确保已经安装了Java...

    Eclipse 安装最新版的SVN插件

    安装过程中,Eclipse可能会提示你安装额外的依赖项,如SVN连接器,确保都勾选上并继续安装。 安装完毕后,需要重启Eclipse以使新安装的插件生效。重启后,你可以在Eclipse的“资源”(Resources)视图或“项目”...

    eclipse本地开发代码通过git库管理

    常用的Eclipse Git插件包括EGit等。安装EGit后,用户可以直接在Eclipse中进行版本控制操作,如克隆仓库、提交更改、拉取更新等。 #### 二、使用Eclipse进行Git代码管理的步骤 ##### 1. 安装EGit插件 在Eclipse中...

    eclipse自动补齐

    在开发过程中,代码编辑器的智能辅助功能极大提升了编码效率,其中,自动补齐(代码提示)是最为常用的功能之一。Eclipse作为一款强大的开源集成开发环境(IDE),提供了丰富的功能来支持Java、Android等项目的开发...

    Eclipse使用入门教程介绍

    Eclipse 是 Java 开发中最流行的集成开发环境(IDE),它提供了强大的功能和插件来提高开发效率。本篇博文旨在为刚刚入门 Java 的新手提供一个快速掌握 Eclipse 使用的指南。 1. 常用快捷键 熟练使用快捷键对于...

    eclipse For C/C++

    2. **插件开发**:学习如何开发自定义插件,扩展 Eclipse 的功能。 3. **性能优化**:合理配置内存分配、减少不必要的插件加载等措施,提高 Eclipse 的运行速度。 #### 六、社区资源 - **官方文档**:访问 Eclipse ...

    怎样安装eclipse

    4. **安装插件**:如果需要使用特定的功能,可以通过Eclipse内置的市场来搜索并安装插件。例如,安装Git插件可以通过“Help”菜单下的“Marketplace”选项进行搜索安装。 #### 四、常用操作简介 - **创建新项目**...

    解决常见的Eclipse SVN插件报错方法详解

    Eclipse SVN插件可以集成SVN版本控制功能到Eclipse开发环境中,让开发者可以直接在Eclipse中进行版本控制的操作。然而,在实际使用Eclipse SVN插件时,用户可能会遇到各种各样的报错信息,这些报错信息可能会阻碍...

    eclipse安装基础

    #### 四、Eclipse常用快捷键及技巧 Eclipse提供了许多快捷键,能够极大地提高开发效率。 1. **加注释**:`Ctrl+/`。 2. **查看变量定义或方法源代码**:`Ctrl+左键`。 3. **引出Source**:`Alt+Shift+S`。 4. **...

    eclipse-jee-luna-SR1a-linux-gtk.tar.gz

    它包含了Eclipse Classic的基本功能,同时还加入了支持Java EE标准的各种工具和插件。 - **Luna SR1a**: “Luna”是Eclipse的一个版本代号,而“SR1a”则代表Service Release 1a,即Luna版本的一个维护更新版本。...

    Eclipse

    这一特性使得 Eclipse 能够迅速聚集开发者社区的支持,并不断吸引新的贡献者加入到项目的开发中来。 **1.3 Eclipse 版本介绍** Eclipse 有不同的版本,包括但不限于: - **Eclipse Classic**:这是最经典的 ...

    Java EE Development with Eclipse.pdf

    - 插件系统:用户可以通过安装插件扩展Eclipse的功能。 - 集成的开发工具:包括项目管理、版本控制、调试工具等。 - **使用场景**:Eclipse IDE适用于各种规模的Java项目开发,包括桌面应用、Web应用以及企业级...

    JAVA反编译工具

    标签中的“eclipse插件”表明jdeclipse是为Eclipse IDE设计的,Eclipse作为开源且高度可扩展的开发平台,拥有丰富的插件生态系统。jdeclipse插件的加入使得Eclipse不仅能够处理Java开发的常规任务,还能方便地处理反...

    eclips常用扩展点

    在Eclipse插件开发中,通常会为插件创建一个专用的透视图(Perspective)。首先,我们需要准备一些资源文件,例如图标等。例如,将包含图标的`icons`目录复制到当前插件项目中,如`myplugin2`项目,复制后的路径应...

Global site tag (gtag.js) - Google Analytics