Procedure
This test examines VE's general functionality by trying to
build, unscripted a small RCP application. The instructions below are
going to be detailed one, as the idea is for one to not build the app. correctly
up front, but rather in a free form manner, have mistakes, change things around,
have multiple editors open etc. Make sure that the VE works as expected,
and that no errors are generated on the .log.
Setup
Create a UI based RCP application Project->PluginProject->3.20->Yes for RCP app, and UI->Use the Hello World template.
Create a new java package, called "ui"
Create a new Visual RCP View class in the ui package named QuickPickView.
Drop a table and two columns on the top composite (make sure it is using a FillLayout)
Define the viewer in the manifest by creating a views extension point. The viewer id, must be the same one that is defined inside the QuickPickView.
Import the following .jar into the src directory of the RCP project - this is going to be the domain model we are going to populate the GUI with.
Code the following viewer on top of the table (really need to type it in the source panel):
Open the Perspective class, and update the prospective as following:
public void createInitialLayout(IPageLayout layout) { String editorArea = layout.getEditorArea(); layout.setEditorAreaVisible(true);// QuickPick layout.addStandaloneView(QuickPickView.ID, true, IPageLayout.LEFT, 0.45f, editorArea); layout.getViewLayout(QuickPickView.ID).setCloseable(false);}
Run the RCP app
Create a Visual PersonEditor RCP Editor class as following in the ui package:
Register the Editor with the manifest
Add the following code to the top of your PersonEditor class, to define an instance variable for user, and an EditorInput inner class:
public class PersonEditor extends EditorPart {
IUser user = null;
public static class EditorInput implements IEditorInput{
IUser user;
public EditorInput (IUser user) {
this.user=user;
}
public boolean exists() {
return false;
}
public ImageDescriptor getImageDescriptor() {
return null;
}
public String getName() {
return user.getUserID();
}
public IPersistableElement getPersistable() {
return null;
}
public String getToolTipText() {
return user.getFirstName() + " " + user.getLastName();
}
public Object getAdapter(Class adapter) {
return null;
}
public IUser getUser() {
return user;
}
}
At the end of the createPartControl method you can set the user instance variable as following
user = ((EditorInput)getEditorInput()).getUser();
Then, you can write code to bind the various TextFields to the given user instance. e.g., firstNameTextField.setText(user.getFirstName).
The last thing that remains, it to create an event on the QuickPickView's table so that a double click will create an EditorInput with the proper user, and open an instance of the editor.
table.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
ILightUser u = (ILightUser) ((TableItem)e.item).getData();
PersonEditor.EditorInput input = new PersonEditor.EditorInput(DummyUserService.getInstance().getUser(u.getUserID()));
try {
getSite().getPage().openEditor(input, PersonEditor.ID);
} catch (PartInitException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});