- 전체
- JAVA 일반
- JAVA 수학
- JAVA 그래픽
- JAVA 자료구조
- JAVA 인공지능
- JAVA 인터넷
- Java Framework
- Java GUI (AWT,SWING,SWT,JFACE)
- SWT and RCP (web RAP/RWT)[eclipse], EMF
SWT and RCP (web RAP/RWT)[eclipse], EMF Eclipse RAP Tutorial for Beginners - Workbench Application (OLD)
2021.01.30 06:06
Eclipse RAP Tutorial for Beginners - Workbench Application (OLD)
Eclipse RAP Tutorial for Beginners - Workbench Application (OLD).pdf
1- Instroduction
-
Eclipse 4.4 (LUNA)
-
RAP 2.3
-
OLD Model of Workbench (Earlier E4)
- 30-08-2014: First version
Some documents you should view before:
In my opinion you to download package: "Eclipse IDE for Java EE Developers". The only difference is the number of Plugin, for the purpose of different programming. During the programming, you can install additional plugins for other purposes.
See installation instructions at:
RAP Tools installation:
You need to install RAP Tools in Eclipse, you can see the instructions here:You can see an example online demo at: Or other Online demo related to the RAP at:You can view guide to programing the applications RCP Workbench (Run on the Desktop) at here:
On Eclipse select: File/Switch Workspace/Other ...
- Check selected on (1)
- On the (2) select "No" to create Eclipse RAP Project (Running on Web), otherwise it will create RCP Project (Running on the Desktop).
- RAP Hello World: Creating a sample application, but the basic RAP (Basic Application), not Workbench Application.
- RAP Mail Template: Creates a management application RAP Workbench email, but much generated code, not under our purposes.
It is best not to choose any template, completely from scratch.
In fact the newly created Project is declared using the Bundle of RCP, not RAP. The illustration below shows that.
- http://download.eclipse.org/rt/rap/2.3
- org.eclipse.rap.ui
Create 5 classes:
- Application
- ApplicationActionBarAdvisor
- ApplicationWorkbenchAdvisor
- ApplicationWorkbenchWindowAdvisor
- Perspective
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
package org.o7planning.tutorial.rapwb; import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplicationContext; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.PlatformUI; public class Application implements IApplication { public Object start(IApplicationContext context) throws Exception { Display display = PlatformUI.createDisplay(); try { int returnCode = PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor()); if (returnCode == PlatformUI.RETURN_RESTART) return IApplication.EXIT_RESTART; else return IApplication.EXIT_OK; } finally { display.dispose(); } } public void stop() { if (!PlatformUI.isWorkbenchRunning()) return ; final IWorkbench workbench = PlatformUI.getWorkbench(); final Display display = workbench.getDisplay(); display.syncExec( new Runnable() { public void run() { if (!display.isDisposed()) workbench.close(); } }); } } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
package org.o7planning.tutorial.rapwb; import org.eclipse.jface.action.IMenuManager; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.application.ActionBarAdvisor; import org.eclipse.ui.application.IActionBarConfigurer; public class ApplicationActionBarAdvisor extends ActionBarAdvisor { public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) { super (configurer); } protected void makeActions(IWorkbenchWindow window) { } protected void fillMenuBar(IMenuManager menuBar) { } } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
package org.o7planning.tutorial.rapwb; import org.eclipse.ui.application.IWorkbenchWindowConfigurer; import org.eclipse.ui.application.WorkbenchAdvisor; import org.eclipse.ui.application.WorkbenchWindowAdvisor; public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor { private static final String PERSPECTIVE_ID = "RAPWorkbenchTutorial.perspective" ; //$NON-NLS-1$ public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) { return new ApplicationWorkbenchWindowAdvisor(configurer); } public String getInitialWindowPerspectiveId() { return PERSPECTIVE_ID; } } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
package org.o7planning.tutorial.rapwb; import org.eclipse.swt.graphics.Point; import org.eclipse.ui.application.ActionBarAdvisor; import org.eclipse.ui.application.IActionBarConfigurer; import org.eclipse.ui.application.IWorkbenchWindowConfigurer; import org.eclipse.ui.application.WorkbenchWindowAdvisor; public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) { super (configurer); } public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer) { return new ApplicationActionBarAdvisor(configurer); } public void preWindowOpen() { IWorkbenchWindowConfigurer configurer = getWindowConfigurer(); configurer.setInitialSize( new Point( 400 , 300 )); // Show MenuBar configurer.setShowMenuBar( true ); // Show CoolBar. configurer.setShowCoolBar( true ); // Show Status Line. configurer.setShowStatusLine( true ); // Show PerspectiveBar configurer.setShowPerspectiveBar( true ); // Show FastViewBars configurer.setShowFastViewBars( true ); // Show ProgressIndicator configurer.setShowProgressIndicator( true ); configurer.setTitle( "Hello RAP Workbench" ); //$NON-NLS-1$ } } |
1
2
3
4
5
6
7
8
9
10
11
|
package org.o7planning.tutorial.rapwb; import org.eclipse.ui.IPageLayout; import org.eclipse.ui.IPerspectiveFactory; public class Perspective implements IPerspectiveFactory { public void createInitialLayout(IPageLayout layout) { } } |
- org.o7planning.tutorial.rapwb.Application
Declare a Perspective
- id: RAPWorkbenchTutorial.perspective
- name: Default Perspective
- class: org.o7planning.tutorial.rapwb.Perspective
RAP application will run starting from an "Entry Point". RAP application has one or more EntryPoint.
Here we define an EntryPoint path /hello, and later can access the path:
http://host:port/ContextPath/hello
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
<? xml version = "1.0" encoding = "UTF-8" ?> <? eclipse version = "3.4" ?> < plugin > < extension id = "id1" point = "org.eclipse.core.runtime.applications" > < application cardinality = "singleton-global" thread = "main" visible = "true" > < run class = "org.o7planning.tutorial.rapwb.Application" > </ run > </ application > </ extension > < extension point = "org.eclipse.ui.perspectives" > < perspective class = "org.o7planning.tutorial.rapwb.Perspective" id = "RAPWorkbenchTutorial.perspective" name = "Default Perspective" > </ perspective > </ extension > < extension point = "org.eclipse.rap.ui.entrypoint" > < entrypoint applicationId = "RAPWorkbenchTutorial.id1" id = "entryPoint1" path = "/hello" > </ entrypoint > </ extension > </ plugin > |
Add 7 plugin. This is the plugin for RAP applications can be run directly from Eclipse. (RAP 2.3)
- org.apache.felix.gogo.command
- org.apache.felix.gogo.runtime
- org.apache.felix.gogo.shell
- org.eclipse.equinox.console
- org.eclipse.equinox.http.jetty
- org.eclipse.equinox.ds
- org.eclipse.rap.rwt.osgi
- Select "External Web browser" to configure applications to run outside the browser.
- Click the Configure Browser to select the system browser "Firefox" or "Chrome".
- Select the port to run
- Click Apply
- Check Select RAPWorkbenchTutorial
- Uncheck select Target Platform.
- Click on "Add Required Bundles" to the system automatically calculates the minimum dependency plugin.
- Click Apply.
- Click Run to run the application.
- org.eclipse.rap.design.example
- org.eclipse.rap.design.example.business.theme
- org.eclipse.rap.design.example.fancy.theme
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
<? xml version = "1.0" encoding = "UTF-8" ?> <? eclipse version = "3.4" ?> < plugin > < extension id = "id1" point = "org.eclipse.core.runtime.applications" > < application cardinality = "singleton-global" thread = "main" visible = "true" > < run class = "org.o7planning.tutorial.rapwb.Application" > </ run > </ application > </ extension > < extension point = "org.eclipse.ui.perspectives" > < perspective class = "org.o7planning.tutorial.rapwb.Perspective" id = "RAPWorkbenchTutorial.perspective" name = "Default Perspective" > </ perspective > </ extension > < extension point = "org.eclipse.rap.ui.entrypoint" > < entrypoint applicationId = "RAPWorkbenchTutorial.id1" brandingId = "myBranding" id = "entryPoint1" path = "/hello" > </ entrypoint > </ extension > < extension point = "org.eclipse.rap.ui.branding" > < branding favicon = "favicon.png" id = "myBranding" themeId = "org.eclipse.rap.design.example.fancy.theme" title = "Fancy Theme" > </ branding > </ extension > </ plugin > |
And run the application:
You need to configure it before running, because there has been a change in the dependent Bundles.
10- Create a few Command used in applications
- Open the file
- Exit the application
- Open AboutDialog
- ....
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
package org.o7planning.tutorial.rapwb.dialog; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Dialog; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; public class AboutDialog extends Dialog { private static final long serialVersionUID = -1969407778775319986L; protected Object result; protected Shell shlAbout; /** * Create the dialog. * @param parent * @param style */ public AboutDialog(Shell parent, int style) { super (parent, style); setText( "SWT Dialog" ); } /** * Open the dialog. * @return the result */ public Object open() { createContents(); shlAbout.open(); shlAbout.layout(); Display display = getParent().getDisplay(); while (!shlAbout.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } return result; } /** * Create contents of the dialog. */ private void createContents() { shlAbout = new Shell(getParent(), getStyle()); shlAbout.setSize( 418 , 145 ); shlAbout.setText( "About" ); shlAbout.setLayout( new GridLayout( 1 , false )); Label lblNewLabel = new Label(shlAbout, SWT.NONE); lblNewLabel.setLayoutData( new GridData(SWT.CENTER, SWT.CENTER, true , true , 1 , 1 )); lblNewLabel.setText( "RAP Workbench Tutorial" ); } } |
- org.eclipse.ui.commands
Next we will create a Command class with ID:
- org.o7planning.tutorial.rcp.cmd.about
- id: org.o7planning.tutorial.rapwb.cmd.about
- defaultHandler: org.o7planning.tutorial.rapwb.cmd.AboutCommand
- org.eclipse.core.commands.AbstractHandler.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
package org.o7planning.tutorial.rapwb.cmd; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.handlers.HandlerUtil; import org.o7planning.tutorial.rapwb.dialog.AboutDialog; public class AboutCommand extends AbstractHandler { @Override public Object execute(ExecutionEvent event) throws ExecutionException { Shell shell = HandlerUtil.getActiveWorkbenchWindow(event).getShell(); AboutDialog dialog = new AboutDialog(shell, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); dialog.open(); return null ; } } |
- org.eclipse.ui.menus
- locationURI: menu:org.eclipse.ui.main.menu
menu:org.eclipse.ui.main.menu ==> ID to Locate of the menu, it is a constant of the RCP workbench available. You can also create locationURI to define the position display MENU.
- org.eclipse.ui.file.exit
- org.o7planning.tutorial.rapwb.cmd.about
Class AboutCommand with ID: org.o7planning.tutorial.rapwb.cmd.about was created above.
Run the application:
Create Coolbar:
- locationURI: toolbar:org.eclipse.ui.main.toolbar
locationURI: ID- defines the position of the Toolbar.
toolbar:org.eclipse.ui.main.toolbar: an ID has been declared available by RAP Platform. You can also create locationURI to define certain location.
- org.eclipse.ui.file.exit
- org.o7planning.tutorial.rapwb.cmd.about
- org.eclipse.ui.views
- id: org.o7planning.tutorial.rapwb.view.contact
- class: org.o7planning.tutorial.rapwb.view.ContactView
- name: Category
- id: org.o7planning.tutorial.rapwb.view.category
- class: org.o7planning.tutorial.rapwb.view.CategoryView
- icon: icons/category16.png
HistoryView
- name: History
- id: org.o7planning.tutorial.rapwb.view.history
- class: org.o7planning.tutorial.rapwb.view.HistoryView
- icon: icons/history16.png
TaskView
- name: Task
- id: org.o7planning.tutorial.rapwb.view.task
- class: org.o7planning.tutorial.rapwb.view.TaskView
- icon: icons/task16.png
Registry Views to the Perpective
- org.eclipse.ui.perspectiveExtensions
Rerun Application:
- org.eclipse.ui.editors
- id: org.o7planning.tutorial.rapwb.editor.user
- Name: UserEditor
- icon: icons/user16.png
- class: org.o7planning.tutorial.rapwb.editor.UserEditor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
package org.o7planning.tutorial.rapwb.editor; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IPersistableElement; public class UserEditorInput implements IEditorInput { @Override public Object getAdapter(Class adapter) { return null ; } @Override public boolean exists() { return false ; } @Override public ImageDescriptor getImageDescriptor() { return null ; } @Override public String getName() { return "User Editor" ; } @Override public IPersistableElement getPersistable() { return null ; } @Override public String getToolTipText() { return "User Editor" ; } } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
package org.o7planning.tutorial.rapwb.editor; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorSite; import org.eclipse.ui.PartInitException; import org.eclipse.ui.part.EditorPart; public class UserEditor extends EditorPart { public static final String ID= "org.o7planning.tutorial.rapwb.editor.user" ; public UserEditor() { } @Override public void doSave(IProgressMonitor monitor) { } @Override public void doSaveAs() { } /** * Important!!! */ @Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { if (!(input instanceof UserEditorInput)) { throw new PartInitException( "Invalid Input: Must be " + UserEditorInput. class .getName()); } setSite(site); setInput(input); } @Override public boolean isDirty() { return false ; } @Override public boolean isSaveAsAllowed() { return false ; } @Override public void createPartControl(Composite parent) { // Add Code. // Important!!! // If you want to design with WindowBuilder // First change code like: // And open with WindowBuilder Designer. parent.setLayout( new FillLayout()); Composite body= new Composite(parent,SWT.NONE); } @Override public void setFocus() { } } |
- id: org.o7planning.tutorial.rapwb.cmd.user
- name: Call UserEditor
- defaultHandler: org.o7planning.tutorial.rapwb.cmd.UserCommand
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
package org.o7planning.tutorial.rapwb.cmd; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PartInitException; import org.eclipse.ui.handlers.HandlerUtil; import org.o7planning.tutorial.rapwb.editor.UserEditor; import org.o7planning.tutorial.rapwb.editor.UserEditorInput; public class UserCommand extends AbstractHandler { public static final String ID = "org.o7planning.tutorial.rapwb.cmd.user" ; @Override public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); IWorkbenchPage page = window.getActivePage(); UserEditorInput input = new UserEditorInput(); try { page.openEditor(input, UserEditor.ID); } catch (PartInitException e) { System.out.println( "Error:" + this .getClass().getName() + ":" + e); e.printStackTrace(); throw new ExecutionException( "Error open UserEditor" ); } return null ; } } |
Rerun Application:
[출처] https://o7planning.org/10385/eclipse-rap-tutorial-for-beginners-workbench-application
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.