RCP II: Extended General Workbench Supplement - Small Improvement

xiaoxiao2021-03-06  60

1, improve reason and content

liCense Key button of the SearchView view is not very obvious, so add the license key menu item in the File menu to provide the same function.

l The program does not provide the function of opening the view. After the view is closed, it will not be opened, so add the function of the VIEW menu to open the view.

l Menu used two steps:

Ø Define action to implement specific features

Ø Add actions to menuManager, by Menumanager

2, define actions

(1) Action corresponding to the License Key menu item

Package com.xqtu.google.Actions;

Import org.eclipse.jface.action.Action;

Import org.eclipse.jface.wizard.wizarddialog;

Import org.eclipse.ui.iworkbenchwindow;

Import com.xqtu.google.wizards.LicenseKeywizard;

Public class licenseKeyMenuaction Extends action {

Private iWorkbenchWindow Window;

Public licenseKeyMenuAction (iWorkbenchWindow Window) {

THIS.WINDOW = WINDOW;

SetText ("License & Key ... @ Ctrl K");

}

Public void run () {

LicenseKeyWizard Wizard = new licenseKeyWizard ();

WizardDialog Dialog = New WizardDialog (Window.getshell (), Wizard);

Dialog.open ();

}

}

l Normal action needs to extend the Action class (the default base class for the IACTION interface), and rewrite the RUN method to implement the specific function to be completed.

l The action class typically performs some attributes of some attributes in its constructor, such as the setText method sets the author-related text, and behave in the menu as a menu item text.

l Another thing to do in its construction method is a reference to save the Window level (such as iWorkbenchWindow to use in the back RUN method.

l RUN method implements the same function as the SearchView view: Open Wizard Window

(2) Display the action of the view

Package com.xqtu.google.Actions;

Import org.eclipse.jface.action.Action;

Import org.eclipse.ui.iworkbenchpage;

Import org.eclipse.ui.iworkbenchwindow;

Import org.eclipse.ui.partinitexception;

Public class viewAction extends action {

Private iWorkbenchWindow Window;

PRIVATE STRING VIEWID;

Public viewAction (iWorkbenchWindow Window, String View) {

THIS.WINDOW = WINDOW;

THIS.VIEWID = viewId;

SetText ("Show" viewid.substring (".") 1));}

Public void run () {

IWorkbenchPage [] Pages = WINDOW.GETPAGES ();

For (int i = 0, len = pages.lend "{i

Try {

Pages [i] .showview;

Break;

} catch (partinitexception PIEX) {

CONTINUE;

}

}

}

}

The LiviewAction class is the same as the LicenseKeyMenuAction class, and the difference is to receive more viewid parameters in the construction method, used to receive view ID

l Menu item is generated according to the view ID (not very appropriate)

l In the RUN method, get WorkbenchPage in WorkbenchWindow, then call the SHOWVIEW method for WorkbenchPage Display the view of the corresponding view ID (feeling the FOR loop is not very good, but there is no way to think about other methods)

3, add actions to menuManager

l Modify the FillActionbars method for the GoogleWorkBenChadvisor class, add the action to menuManager

Public Void FillActionbars (iWorkbenchWindow Window,

IActionBarconfigurer Configurer, int flags) {

IMenumanager menubar = configurer.getMenumanager ();

Menumanager FileMenu = New Menumanager ("& File",

IWorkBenChatConstants.m_file);

FileMenu.add (New GroupMarker (iWorkBenChctionConstants.file_start);

FileMenu.add (New GroupMarker (iWorkbenChatconstants.mb_additions);

FileMenu.Add (New licenseKeyMenuAction (Window);

FileMenu.add (actionFactory.quit.create (Window);

FileMenu.add (New GroupMarker (iWorkBenChctionConstants.file_end);

MenuBar.Add (FileMenu);

Menumanager ViewMenu = New Menumanager ("& View");

ViewMenu.Add (New ViewAction (Window, BrowserView.ID);

ViewMenu.Add (New ViewAction (Window, SearchView.ID);

MenuBar.Add (ViewMenu);

}

转载请注明原文地址:https://www.9cbs.com/read-118782.html

New Post(0)