|
| 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 | + |
0 commit comments