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:

  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

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

  • hibernate how to store binary, image and other major fields.

    model categories: reportByte binary type for the database fields. public class PfReportStyle implements java.io.Serializable , Cloneable { // Fields /** * */ private static final long serialVersionUID = 1L; private Long id; private byte[] reportByte; // C

  • hibernate study of the second

    Persistence of three main points: 1, a statement for persistent fields accessors (accessors) and whether the variable signs (mutators) Property statement is not necessarily required for the public's. Hibernate can be default, protected or private ...

  • eclipse Hibernate proposals

    Error: The 'Hibernate proposals' proposal computer from the' org.hibernate.eclipse.jdt.ui 'plug-in dod not complete normally. Unable to instantiate the extension. To Avoid this message, disable the 'org.hibernate.eclipse.jdt.ui ...

  • Workspace run under different Eclipse

    Now do live more and more often required to use eclipse in java and ruby & rails project conducted between the tangential shear from the past, because in the rails project used a coloring Aptana preferences, the results open the java project sour ...

  • jBPM Development Getting Started Guide

    Although the workflow is still immature stage of development, not even a recognized standard. But its application has already been launched in the Express, indicating the market's demand for job-flow framework are urgent and enormous. Backgrounds of o

  • hibernate (jpa) composite primary key annotation statement Ways

    In the design of the database tables are designed with a composite primary key of the table, that table's record by more than one field joint identification, such as: Table CREATE TABLE TB_HOUR_DATA ( STAT_DATE DATE NOT NULL, PATH_ID NUMBER(20) NOT NULL,

  • jboss ejb3 Message Driven Bean

    Super Medium ejb hate. . . . . . . . . . . . . . . . . . . ================================================ To configure a Message Driven Bean in a different application server parameters are not the same. Currently only passed the test jboss. Message Dri

  • myeclipse plugin

    myeclipsePlug-ins? 1.tomcatPlugin(Start tomcat ):http ://www.sysdeo.com/eclipse/tomcatPlugin.html,2.xVersions of eclipse 3 version 2 .1Version doesn't work. 2.Lomboz(Development of jsp program ,jspDynamic prompt, debugging ):http://forge.objectweb.org/pro

  • hibernate generic generic DAO

    package org.lzpeng.dao; import java.io.Serializable; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.criterion.Criterion; import org.springside.modules.orm.hibernate.Page; /** * * @version 2009-1-10 *

  • Java technology: Eclipse explain the use of techniques

    Editor settings: Window -> Preferences -> Java-> Editor appearance: Display line number, emphasizing symmetry shown in square brackets, to emphasize that the existing line to show Print Margins its check, Tab width set 4, print made from the fiel

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries