X Tutup
Skip to content

Commit 53e4fa0

Browse files
committed
Added Code of the Editor Tutorial
Change-Id: I512cc810538404f239c832f84310a8eee1e1e943 Signed-off-by: Simon Scholz <simon.scholz@vogella.com>
1 parent 32a019a commit 53e4fa0

File tree

14 files changed

+520
-0
lines changed

14 files changed

+520
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
4+
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5+
<classpathentry kind="src" path="src"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>com.vogella.rcp.editor.example</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.pde.ManifestBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.pde.SchemaBuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
</buildSpec>
24+
<natures>
25+
<nature>org.eclipse.pde.PluginNature</nature>
26+
<nature>org.eclipse.jdt.core.javanature</nature>
27+
</natures>
28+
</projectDescription>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.compliance=1.8
5+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7+
org.eclipse.jdt.core.compiler.source=1.8
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
eclipse.preferences.version=1
2+
pluginProject.extensions=true
3+
resolve.requirebundle=false
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Manifest-Version: 1.0
2+
Bundle-ManifestVersion: 2
3+
Bundle-Name: Example
4+
Bundle-SymbolicName: com.vogella.rcp.editor.example;singleton:=true
5+
Bundle-Version: 1.0.0.qualifier
6+
Bundle-Activator: com.vogella.rcp.editor.example.Activator
7+
Bundle-Vendor: VOGELLA
8+
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
9+
Import-Package: org.osgi.framework;version="1.3.0"
10+
Bundle-ActivationPolicy: lazy
11+
Require-Bundle: org.eclipse.ui;bundle-version="3.107.0",
12+
org.eclipse.core.runtime;bundle-version="3.10.0"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
source.. = src/
2+
output.. = bin/
3+
bin.includes = META-INF/,\
4+
.,\
5+
plugin.xml
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<?eclipse version="3.4"?>
3+
<plugin>
4+
<extension
5+
point="org.eclipse.ui.editors">
6+
<editor
7+
class="com.vogella.rcp.editor.example.editor.TodoEditor"
8+
default="false"
9+
id="com.vogella.rcp.editor.example.editor.todoeditor"
10+
name="Todo Editor">
11+
</editor>
12+
</extension>
13+
<extension
14+
point="org.eclipse.ui.views">
15+
<view
16+
class="com.vogella.rcp.editor.example.parts.TodoOverview"
17+
id="com.vogella.rcp.editor.example.todooverview"
18+
name="Todo Overview"
19+
restorable="true">
20+
</view>
21+
</extension>
22+
<extension
23+
point="org.eclipse.ui.commands">
24+
<command
25+
defaultHandler="com.vogella.rcp.editor.example.handler.CallEditor"
26+
id="com.vogella.rcp.editor.example.openEditor"
27+
name="Open Todo Editor">
28+
</command>
29+
</extension>
30+
31+
</plugin>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.vogella.rcp.editor.example;
2+
3+
import org.osgi.framework.BundleActivator;
4+
import org.osgi.framework.BundleContext;
5+
6+
public class Activator implements BundleActivator {
7+
8+
private static BundleContext context;
9+
10+
static BundleContext getContext() {
11+
return context;
12+
}
13+
14+
@Override
15+
public void start(BundleContext bundleContext) throws Exception {
16+
Activator.context = bundleContext;
17+
}
18+
19+
@Override
20+
public void stop(BundleContext bundleContext) throws Exception {
21+
Activator.context = null;
22+
}
23+
24+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package com.vogella.rcp.editor.example.editor;
2+
3+
import java.util.Date;
4+
5+
import org.eclipse.core.runtime.IProgressMonitor;
6+
import org.eclipse.swt.SWT;
7+
import org.eclipse.swt.layout.GridData;
8+
import org.eclipse.swt.layout.GridLayout;
9+
import org.eclipse.swt.widgets.Button;
10+
import org.eclipse.swt.widgets.Composite;
11+
import org.eclipse.swt.widgets.DateTime;
12+
import org.eclipse.swt.widgets.Label;
13+
import org.eclipse.swt.widgets.Text;
14+
import org.eclipse.ui.IEditorInput;
15+
import org.eclipse.ui.IEditorSite;
16+
import org.eclipse.ui.PartInitException;
17+
import org.eclipse.ui.part.EditorPart;
18+
19+
import com.vogella.rcp.editor.example.model.Todo;
20+
import com.vogella.rcp.editor.example.model.TodoService;
21+
22+
public class TodoEditor extends EditorPart {
23+
24+
public static final String ID = "com.vogella.rcp.editor.example.editor.todoeditor";
25+
private Todo todo;
26+
private TodoEditorInput input;
27+
28+
// Will be called before createPartControl
29+
@Override
30+
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
31+
if (!(input instanceof TodoEditorInput)) {
32+
throw new RuntimeException("Wrong input");
33+
}
34+
35+
this.input = (TodoEditorInput) input;
36+
setSite(site);
37+
setInput(input);
38+
todo = TodoService.getInstance().getTodoById(this.input.getId());
39+
setPartName("Todo ID: " + todo.getId());
40+
}
41+
42+
@Override
43+
public void createPartControl(Composite parent) {
44+
GridLayout layout = new GridLayout();
45+
layout.numColumns = 2;
46+
parent.setLayout(layout);
47+
Label label1 = new Label(parent, SWT.NONE);
48+
label1.setText("Summary");
49+
Text text = new Text(parent, SWT.BORDER);
50+
text.setText(todo.getSummary());
51+
text.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
52+
new Label(parent, SWT.NONE).setText("Description");
53+
Text lastName = new Text(parent, SWT.BORDER);
54+
lastName.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
55+
lastName.setText(todo.getDescription());
56+
new Label(parent, SWT.NONE).setText("Done");
57+
Button doneBtn = new Button(parent, SWT.CHECK);
58+
doneBtn.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
59+
doneBtn.setSelection(todo.isDone());
60+
new Label(parent, SWT.NONE).setText("Due Date");
61+
DateTime dueDate = new DateTime(parent, SWT.CHECK);
62+
dueDate.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
63+
Date date = todo.getDueDate();
64+
dueDate.setDate(date.getYear(), date.getMonth(), date.getDay());
65+
}
66+
67+
@Override
68+
public void doSave(IProgressMonitor monitor) {
69+
}
70+
71+
@Override
72+
public void doSaveAs() {
73+
}
74+
75+
@Override
76+
public boolean isDirty() {
77+
return false;
78+
}
79+
80+
@Override
81+
public boolean isSaveAsAllowed() {
82+
return false;
83+
}
84+
85+
@Override
86+
public void setFocus() {
87+
}
88+
89+
}
90+
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.vogella.rcp.editor.example.editor;
2+
3+
import org.eclipse.jface.resource.ImageDescriptor;
4+
import org.eclipse.ui.IEditorInput;
5+
import org.eclipse.ui.IPersistableElement;
6+
7+
public class TodoEditorInput implements IEditorInput {
8+
9+
private final long id;
10+
11+
public TodoEditorInput(long id) {
12+
this.id = id;
13+
}
14+
15+
public long getId() {
16+
return id;
17+
}
18+
19+
@Override
20+
public boolean exists() {
21+
return true;
22+
}
23+
24+
@Override
25+
public ImageDescriptor getImageDescriptor() {
26+
return null;
27+
}
28+
29+
@Override
30+
public String getName() {
31+
return String.valueOf(id);
32+
}
33+
34+
@Override
35+
public IPersistableElement getPersistable() {
36+
return null;
37+
}
38+
39+
@Override
40+
public String getToolTipText() {
41+
return "Displays a person";
42+
}
43+
44+
@Override
45+
public Object getAdapter(Class adapter) {
46+
return null;
47+
}
48+
49+
@Override
50+
public int hashCode() {
51+
final int prime = 31;
52+
int result = 1;
53+
result = prime * result + (int) (id ^ (id >>> 32));
54+
return result;
55+
}
56+
57+
@Override
58+
public boolean equals(Object obj) {
59+
if (this == obj)
60+
return true;
61+
if (obj == null)
62+
return false;
63+
if (getClass() != obj.getClass())
64+
return false;
65+
TodoEditorInput other = (TodoEditorInput) obj;
66+
if (id != other.id)
67+
return false;
68+
return true;
69+
}
70+
}

0 commit comments

Comments
 (0)
X Tutup