1 package org.eparapher.rcp.editors;
2
3 import org.eclipse.core.resources.IMarker;
4 import org.eclipse.core.resources.IResourceChangeEvent;
5 import org.eclipse.core.resources.IResourceChangeListener;
6 import org.eclipse.core.resources.ResourcesPlugin;
7 import org.eclipse.core.runtime.IProgressMonitor;
8 import org.eclipse.jface.dialogs.ErrorDialog;
9 import org.eclipse.swt.graphics.Font;
10 import org.eclipse.swt.widgets.Composite;
11 import org.eclipse.swt.widgets.Display;
12 import org.eclipse.ui.IEditorInput;
13 import org.eclipse.ui.IEditorPart;
14 import org.eclipse.ui.IEditorSite;
15 import org.eclipse.ui.IFileEditorInput;
16 import org.eclipse.ui.IPathEditorInput;
17 import org.eclipse.ui.IWorkbenchPage;
18 import org.eclipse.ui.PartInitException;
19 import org.eclipse.ui.editors.text.TextEditor;
20 import org.eclipse.ui.forms.widgets.Form;
21 import org.eclipse.ui.ide.IDE;
22 import org.eclipse.ui.part.MultiPageEditorPart;
23
24
25
26
27
28
29
30
31 public class BasicMultiPageEditor extends MultiPageEditorPart implements IResourceChangeListener{
32
33
34 private TextEditor editor;
35
36
37 private Font font;
38
39 SignatureTabEditor ftesignature;
40
41
42
43
44 public BasicMultiPageEditor() {
45 super();
46 ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
47 }
48
49
50
51
52
53 void createEditableTab() {
54 try {
55 editor = new SimpleEditor();
56 int index = addPage(editor, getEditorInput());
57 setPageText(index, "File Content");
58 } catch (PartInitException e) {
59 ErrorDialog.openError(
60 getSite().getShell(),
61 "Error creating nested text editor",
62 null,
63 e.getStatus());
64 }
65 }
66
67
68
69
70 void createSignatureTab() {
71 ftesignature = new SignatureTabEditor();
72 Composite composite = ftesignature.createSignatureForm(getContainer());
73
74 int index = addPage(composite);
75 setPageText(index, "Signature info");
76 }
77
78
79
80
81 protected void createPages() {
82 createEditableTab();
83 createSignatureTab();
84
85 }
86
87
88
89
90
91 public void dispose() {
92 ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
93 ftesignature.dispose();
94 super.dispose();
95 }
96
97
98
99 public void doSave(IProgressMonitor monitor) {
100 getEditor(0).doSave(monitor);
101 }
102
103
104
105
106
107 public void doSaveAs() {
108 IEditorPart editor = getEditor(0);
109 editor.doSaveAs();
110 setPageText(0, editor.getTitle());
111 setInput(editor.getEditorInput());
112 }
113
114
115
116 public void gotoMarker(IMarker marker) {
117 setActivePage(0);
118 IDE.gotoMarker(getEditor(0), marker);
119 }
120
121
122
123
124 public void init(IEditorSite site, IEditorInput editorInput)
125 throws PartInitException {
126 if (!(editorInput instanceof FileEditorInput))
127 throw new PartInitException("Invalid Input: Must be FileEditorInput");
128
129 if (editorInput instanceof IPathEditorInput) {
130 IPathEditorInput pathInput = (IPathEditorInput) editorInput;
131 setPartName(pathInput.getName());
132 }
133 super.init(site, editorInput);
134 }
135
136
137
138 public boolean isSaveAsAllowed() {
139 return true;
140 }
141
142
143
144 protected void pageChange(int newPageIndex) {
145 super.pageChange(newPageIndex);
146 if (newPageIndex == 2) {
147
148 }
149 }
150
151
152
153 public void resourceChanged(final IResourceChangeEvent event){
154 if(event.getType() == IResourceChangeEvent.PRE_CLOSE){
155 Display.getDefault().asyncExec(new Runnable(){
156 public void run(){
157 IWorkbenchPage[] pages = getSite().getWorkbenchWindow().getPages();
158 for (int i = 0; i<pages.length; i++){
159 if(((FileEditorInput)editor.getEditorInput()).getPath().equals(event.getResource())){
160 IEditorPart editorPart = pages[i].findEditor(editor.getEditorInput());
161 pages[i].closeEditor(editorPart,true);
162 }
163 }
164 }
165 });
166 }
167 }
168
169 }