Getting Started with Eclipse RCP development study notes - 02. Menus and dialog boxes

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

Study: http://www.blogjava.net/youxia/archive/2006/11/20/82388.html

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

1. To edit ApplicationActionBarAdvisor.java way this class:

A) preparation of the menu action categories:

package hellorcp.action;

import hellorcp.dialog.FirstDialog;

import org.eclipse.jface.action.Action;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;

public class FirstAction extends Action implements IWorkbenchAction {
        private IWorkbenchWindow workbenchWindow;

        public FirstAction(IWorkbenchWindow window) {
                if (window == null) {
                        throw new IllegalArgumentException();
                }

                this.workbenchWindow = window;
        }

        public void run() {
                // make sure action is not disposed
                if (workbenchWindow != null) {
                        //  Add functionality here.  
                        FirstDialog dg = new FirstDialog(workbenchWindow.getShell());
                        dg.open();

                }
        }

        public void dispose() {
                workbenchWindow = null;

        }

}


2) The menu action to open the dialog box, it needs to write dialog class:

package hellorcp.dialog;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class FirstDialog extends Dialog {
        protected Shell shell;

        private int result;

        public FirstDialog(Shell parent, int style) {
                super(parent, style);
        }

        public FirstDialog(Shell parent) {
                this(parent, SWT.NONE);
        }

        public int open() {
                createContents();
                shell.open();
                shell.layout();
                Display display = getParent().getDisplay();
                while (!shell.isDisposed()) {
                        if (!display.readAndDispatch())
                                display.sleep();
                }
                return result;
        }

        protected void createContents() {
                shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
                shell.setSize(150, 70);
                shell.setText("  The first dialog box  ");

                final Button okButton = new Button(shell, SWT.NONE);
                okButton.addSelectionListener(new SelectionAdapter() {
                        public void widgetSelected(SelectionEvent e) {
                                result = 1;
                                shell.dispose();
                        }
                });
                okButton.setText(" OK ");
                okButton.setBounds(10, 10, 48, 22);

                final Button cancelButton = new Button(shell, SWT.NONE);
                cancelButton.addSelectionListener(new SelectionAdapter() {
                        public void widgetSelected(SelectionEvent e) {
                                result = 2;
                                shell.dispose();
                        }
                });
                cancelButton.setText(" Cancel ");
                cancelButton.setBounds(89, 10, 48, 22);
        }

}


3) The editing method makeActions, registration of the menu action; and then edit the way fillMenuBar draw menu:

package hellorcp;

import hellorcp.action.FirstAction;

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;

public class ApplicationActionBarAdvisor extends ActionBarAdvisor {

        private IWorkbenchAction action1;
        private IWorkbenchAction action2;

        public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
                super(configurer);
        }

        protected void makeActions(IWorkbenchWindow window) {
                action1 = new FirstAction(window);
                action1.setText("FirstMenu1");
                action1.setId(action1.getClass().getName());
                register(action1);
        
                action2 = new FirstAction(window);
                action2.setText("FirstMenu2");
                action2.setId(action2.getClass().getName());
                register(action2);
        }

        protected void fillMenuBar(IMenuManager menuBar) {
                MenuManager newMenu = new MenuManager(" The first menu  ", "hellorcp.firstmenu1");
                menuBar.add(newMenu);
                newMenu.add(action1);

                MenuManager newMenu2 = new MenuManager(" The first menu  ", "hellorcp.firstmenu2");
                menuBar.add(newMenu2);
                newMenu.add(action2);
        }

}


4) Run the following diagram results:

Getting Started with Eclipse RCP development study notes - 02. Menus and dialog boxes

2. A way to edit the plugin.xml to add the menu:

A) preparation of the menu action categories:

package hellorcp.action;

import hellorcp.dialog.FirstDialog;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;

public class Action2 implements IWorkbenchWindowActionDelegate {
        private IWorkbenchWindow window;

        public void dispose() {
                // TODO

        }

        public void init(IWorkbenchWindow window) {
                // TODO
                this.window = window;

        }

        public void run(IAction action) {
                // TODO
                FirstDialog dg = new FirstDialog(window.getShell());
                dg.open();

        }

        public void selectionChanged(IAction action, ISelection selection) {
                // TODO

        }

}


2) Double-click the plugin.xml to open Extensions editing window, click the "All Extensions" under the "Add ..." to open Extension selection window, and select org.eclipse.ui.actionSets, the following diagram:



3) Back to the Extensions editing interface, select the "org.eclipse.ui.actionSets", and on the right "Extension Details" of the "ID", "Name", enter the content, save the following diagram:



4) Click on the "plugin.xml" tab, you can see the file appears in the following code:

   <extension
        
         name=" Menu  "
         point="org.eclipse.ui.actionSets">
   </extension>


The fragment directly edit the contents as follows:

   <extension
        
         name=" Menu  "
         point="org.eclipse.ui.actionSets">
         <actionSet
                        description =" The first expansion  " 
            id ="RCP_Start.actionSet1" 
            label ="RCP_Start.actionSet1" 
            visible ="true"> 
                <action
                                class ="hellorcp.action.Action2" 
                icon ="icons/alt_window_16.gif" 
                id ="RCP_Start.action2" 
                    label =" The second menu item  " 
                                menubarPath ="hellorcp.firstmenu/additions" 
                style ="push" 
                toolbarPath ="additions" 
                tooltip =" The second menu item button  " /> 
       </actionSet> 
   </extension>


5) once again switch to the "Extensions" tab, you can see the corresponding content is there, and the following figure:



6) run the program, the effect the following figure:



Note: The need to type ApplicationWorkbenchWindowAdvisor method preWindowOpen () in configurer.setShowCoolBar (false); replaced configurer.setShowCoolBar (true); to appear in the icon menu.
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb
Tags:

Related Posts of Getting Started with Eclipse RCP development study notes - 02. Menus and dialog boxes

  • Android Development 06 - menus and dialog box (below)

    Android Development 06 - menus and dialog box (below) 1. Progress dialog ProgressDialog can wheel and a progress bar shows progress, as ProgressDialog inherited from AlertDialog, so the progress of the dialog box can also add buttons. Usage examples of th

  • Android Development 06 - menus and dialog box (on)

    Android Development 06 - menus and dialog box (on) 1. Menu 1) The options menu and sub menu in the foreground when the Activity work, press the appropriate menu option will pop up menu. This function is needed to achieve the developer compiled, if the pro

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

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

  • Getting Started with Eclipse RCP development study notes - 04. In Windows, use the Active X control

    -------------------------------------------------- ------------------------------------------------- Study: http://www.blogjava.net/youxia/archive/2006/11/28/84013.html -------------------------------------------------- ------------------------------ ...

  • Getting Started with Eclipse RCP development study notes - 07. Summary

    Follow the "Seaside Momo" series of articles had started studying the development of the RCP has been a general understanding of the increasing interest in this area, of course, if you really want to develop a practical small Dongdong years, Lea

  • Department of famous door Android (3) - dialog (Dialog) and notification (Notification)

    Introduced in the Android in the dialog box and various kinds of notification effects of application of the use of common dialog boxes, pop-up dialog box, select the date of the dialog box, timing dialog box, notice the progress bar dialog box (the list a

  • Getting Started with Eclipse RCP Developer Study Notes - 05.2D Drawing

    -------------------------------------------------- -------------------------------------------------- Study: http://www.blogjava.net/youxia/archive/2006/12/01/84855.html -------------------------------------------------- ----------------------------- ...

  • Getting Started with Eclipse RCP Developer Study Notes - 06.OpenGL

    -------------------------------------------------- ------------------------------------------------- Study: http://www.blogjava.net/youxia/archive/2006/12/09/86513.html -------------------------------------------------- -----------------------------------

  • Swt summary of the custom dialog box

    In rcp development, to the Customize dialog box, first of all to inherit org.eclipse.jface.dialogs.Dialog public class MyDialog extends Dialog 1, the definition of the dialog box size, need to override getInitialSize method @ Override protected Point getI

  • Simple model of dialogue JDialog

    JDialog (Dialog) (1) main display various dialog controls (buttons, text boxes and list boxes, etc.) (2) JDialog constructor a: JDialog (), the title bar text to create a non-modal dialog box is empty b: JDialog (Frame owner, String title, boolean mo

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