Getting Started with Eclipse RCP development study notes - 03. View

-------------------------------------------------- ----------------------------------------------

Study: http://www.blogjava.net/youxia/archive/2006/11/24/83377.html

-------------------------------------------------- ----------------------------------------------

1. Write FirstView categories:

package hellorcp.view;

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;

public class FirstView extends ViewPart {
        private Table table;
        private Text text_1;
        private Text text;
        public static final String ID = "hellorcp.views.FirstView"; //$NON-NLS-1$

        /**
         * Create contents of the view part
         *
         * @param parent
         */
        @Override
        public void createPartControl(Composite parent) {
                Composite container = new Composite(parent, SWT.NONE);

                final Label label = new Label(container, SWT.NONE);
                label.setText(" Name  :");
                label.setBounds(56, 41, 36, 12);

                text = new Text(container, SWT.BORDER);
                text.setBounds(98, 38, 80, 15);

                final Label label_1 = new Label(container, SWT.NONE);
                label_1.setText(" Gender  :");
                label_1.setBounds(212, 41, 30, 12);

                text_1 = new Text(container, SWT.BORDER);
                text_1.setBounds(252, 38, 80, 15);

                final TableViewer tableViewer = new TableViewer(container, SWT.BORDER);
                // tableViewer.setInput(new Object());
                table = tableViewer.getTable();
                table.setBounds(56, 75, 374, 143);
                table.setItemCount(10);
                table.setLinesVisible(true);
                //
                createActions();
                initializeToolBar();
                initializeMenu();
        }

        /**
         * Create the actions
         */
        private void createActions() {
                // Create the actions
        }

        /**
         * Initialize the toolbar
         */
        private void initializeToolBar() {
                IToolBarManager toolbarManager = getViewSite().getActionBars()
                                .getToolBarManager();
        }

        /**
         * Initialize the menu
         */
        private void initializeMenu() {
                IMenuManager menuManager = getViewSite().getActionBars()
                                .getMenuManager();
        }

        @Override
        public void setFocus() {
                // Set the focus
        }

}

2. Modify Perspective.java:

package hellorcp;

import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;

public class Perspective implements IPerspectiveFactory {

        public void createInitialLayout(IPageLayout layout) {
                String editorArea = layout.getEditorArea();
                layout.addView("hellorcp.view.FirstView", IPageLayout.RIGHT, 0.2f,
                                editorArea);
        }
}

3. Editor plugin.xml, add the following code snippet:

   <extension
         point="org.eclipse.ui.views">
         <view

                name=" The first view  " />
   </extension>

4. Run the program, the effect is as follows:

Getting Started with Eclipse RCP development study notes - 03. View

5. Custom view tag style:

1) New Document plugin_customization.ini, reads as follows:

org.eclipse.ui/SHOW_TRADITIONAL_STYLE_TABS=false
org.eclipse.ui/DOCK_PERSPECTIVE_BAR=topRight

2) modify the plugin.xml: find the following snippet:

   <extension

         point="org.eclipse.core.runtime.products">
      <product
            application="HelloRCP.application"
            name="RCP Application">

Add the following snippet:

         <property
               name="preferenceCustomization"
               value="plugin_customization.ini">
         </property>

3) The preservation, operation and effect of no change (plugin_customization.ini on the project root directory, should be placed where?);

6. To build a ListView:

1) New Person Bean Class:

package hellorcp.view;

public class Person {

        private String name;
        private String sex;

        public String getName() {
                return name;
        }

        public void setName(String name) {
                this.name = name;
        }

        public String getSex() {
                return sex;
        }

        public void setSex(String sex) {
                this.sex = sex;
        }

}

2) New PersonModel categories:

package hellorcp.view;

import java.util.ArrayList;

public class PersonModel {
        private ArrayList<Person> list = new ArrayList<Person>();

        public interface Listener {
                public void add(Person p);

                public void remove(Person p);
        }

        private Listener listener;

        public PersonModel() {
                //  To list which fill several initialization data
                Person p1 = new Person();
                p1.setName(" Patients 1  ");
                p1.setSex(" Male  ");
                list.add(p1);

                Person p2 = new Person();
                p2.setName(" Patients 2  ");
                p2.setSex(" Women  ");
                list.add(p2);

        }

        public void setListener(Listener listener) {
                this.listener = listener;
        }

        public void add(Person p) {
                list.add(p);
                if (listener != null) {
                        listener.add(p);
                }
        }

        public void remove(Person p) {
                list.remove(p);
                if (listener != null) {
                        listener.remove(p);
                }
        }

        public ArrayList elements() {
                return list;
        }

}

3) The realization of the content provider (implements PersonModel defined in Listener interface):

package hellorcp.view;

import hellorcp.view.PersonModel.Listener;

import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ListViewer;
import org.eclipse.jface.viewers.Viewer;

public class PersonContentProvider implements IStructuredContentProvider,
                Listener {
        PersonModel input;
        ListViewer viewer;

        public Object[] getElements(Object inputElement) {
                // TODO  Automatically generate method stub
                return input.elements().toArray();
        }

        public void dispose() {
                // TODO  Automatically generate method stub
                if (input != null) {
                        input.setListener(null);
                }
                input = null;

        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
                // TODO  Automatically generate method stub
                viewer = (ListViewer) viewer;
                input = (PersonModel) newInput;
                input.setListener(this);

        }

        public void add(Person p) {
                // TODO  Automatically generate method stub
                viewer.add(p);
        }

        public void remove(Person p) {
                // TODO  Automatically generate method stub
                viewer.remove(p);
        }

}

4) Achieving label provider (for the display list elements - Person class object):

package hellorcp.view;

import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.swt.graphics.Image;

public class PersonLabelProvider implements ILabelProvider {

        public Image getImage(Object element) {
                return null;
        }

        public String getText(Object element) {
                // TODO  Automatically generate method stub
                return ((Person) element).getName();
        }

        public void addListener(ILabelProviderListener listener) {
                // TODO  Automatically generate method stub
        }

        public void dispose() {
                // TODO  Automatically generate method stub  

        }

        public boolean isLabelProperty(Object element, String property) {
                // TODO  Automatically generate method stub
                return false;
        }

        public void removeListener(ILabelProviderListener listener) {
                // TODO  Automatically generate method stub
        }

}

5) New SecondView:

package hellorcp.view;

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.viewers.ListViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;

public class SecondView extends ViewPart {

        public void createPartControl(Composite parent) {
                ListViewer viewer = new ListViewer(parent, SWT.BORDER);
                viewer.setContentProvider(new PersonContentProvider());
                viewer.setLabelProvider(new PersonLabelProvider());
                viewer.setInput(new PersonModel());

                createActions();
                initializeToolBar();
                initializeMenu();
        }

        private void createActions() {
                // Create the actions
        }

        private void initializeToolBar() {
                IToolBarManager toolbarManager = getViewSite().getActionBars()
                                .getToolBarManager();
        }

        private void initializeMenu() {
                IMenuManager menuManager = getViewSite().getActionBars()
                                .getMenuManager();
        }

        public void setFocus() {
                // Set the focus
        }

}

6) Revise the Perspective.java, modified Perspective.java:

package hellorcp;

import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;

public class Perspective implements IPerspectiveFactory {

        public void createInitialLayout(IPageLayout layout) {
                // FirstView
                String editorArea = layout.getEditorArea();
                layout.addView("hellorcp.view.FirstView", IPageLayout.RIGHT, 0.2f,
                                editorArea);

                // SecondView
                layout.setEditorAreaVisible(false);
                layout.addView("hellorcp.view.SecondView", IPageLayout.RIGHT, 0.5f,
                                editorArea);
        }

}

7) plugin.xml added SecondView configuration, the increased fragment as follows:

   <extension
         point="org.eclipse.ui.views">
         <view

                name=" The first view  " />
         <view

                name=" The second view  " />
   </extension>

8) Save and run, the effect is as follows:

Getting Started with Eclipse RCP development study notes - 03. View

分类:Java 时间:2010-04-13 人气:553
分享到:
blog comments powered by Disqus

相关文章

  • public void testStatementAddBatch () public void testConnCommit () 2011-09-01

    public void testStatementAddBatch() { Connection conn = null; Statement stmt = null; try { conn = getDBConnectionMsSqlBySuperAdmin(); stmt = conn.createStatement(); for(int i = 0; i < 100; i++) { String sql = " sql " + i; stmt.addBatch(sql);

  • flex reads the text and display text messages 2010-12-21

    flex reads the text and display text messages package components { import flash.utils.ByteArray; [Embed(source="GridDemo.mxml", mimeType="application/octet-stream")] public class foobar extends ByteArray { } } GridDemo.mxml order to re

  • PostgreSQL 8.3.1 Full Text Search (Full Text Search) 2010-11-12

    Transfer from: http://www.blogjava.net/agun/archive/2008/04/23/195086.html In postgreSQL 8.3 comes with support for full-text search functions in the previous version needs to install and configure tsearch2 to use, safety switch configuration tsearch

  • How to import into the database table in the PowerDesigner 2010-11-13

    How to import into the database table in the PowerDesigner 1, open PowerDesigner12, follows in the menu to operate in accordance with file-> Reverse Engineer-> DataBase Click, pop-up dialog box New Physical Data Model 2, in the General tab Model nam

  • oracle text import. exporting skills 2011-06-07

    When using the oracle, the oracle of the total that import, export, there is no informix of load, unload easy to use, no way, can only refer to the idea of ​​online friends and informix to achieve, write a few scripts, I hope you expert guidance: ===

  • eclipse 保存文件时候自动格式化及import 条目优化 2015-04-18

    在eclipse设置页面,java -> editor-> save actions.的设置如下:当你ctrl +s 时候,格式和import 条目优化全搞定

  • Create a text input box text prompt 2010-05-25

    Formed using the TextInput change event listener user input, using regular expression testing whether the dictionary content of any user input that matches the word. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absol

  • js bulk form text box to create the table with rows and columns 2010-11-29

    <! DOCTYPE html PUBLIC "- / / W3C / / DTD XHTML 1.0 Transitional / / EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv=&quo

  • sublime text 3/sublime text 2 安装package control/必备 2014-04-02

    一.安装Package Control sublime text 2和sublime text 3 安装package control的代码是不同的,下面依次给出 sublime text 3 安装package control 首先使用Ctrl+`或者通过View->Show Console菜单打开命令行,粘贴如下代码: 1 import urllib.request,os; pf = 'Package Control.sublime-package'; ipp = sublime.insta

  • Customize subtotal text and grandtotal text in ALV 2010-02-23

    REPORT zalv_test. TABLES: ekko. TYPE-POOLS: slis. TYPES: BEGIN OF x_data, ebeln TYPE char30, ebelp TYPE ebelp, matnr TYPE matnr, matnr1 TYPE matnr, ntgew TYPE entge, [img] [/ img] END OF x_data. TYPES: BEGIN OF x_data_tot, const (15), ebeln TYPE char

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.292 (s). 12 q(s)