1
|
1 package de.mpg.mpiwg.itgroup.digilib.plugin.editors;
|
|
2
|
|
3
|
|
4 import java.io.IOException;
|
|
5 import java.util.Observable;
|
|
6 import java.util.Observer;
|
|
7
|
27
|
8 import org.eclipse.core.resources.IFile;
|
1
|
9 import org.eclipse.core.runtime.CoreException;
|
|
10 import org.eclipse.core.runtime.IProgressMonitor;
|
20
|
11 import org.eclipse.jface.viewers.StructuredSelection;
|
1
|
12 import org.eclipse.swt.SWT;
|
|
13 import org.eclipse.swt.custom.ScrolledComposite;
|
|
14 import org.eclipse.swt.graphics.Cursor;
|
|
15 import org.eclipse.swt.layout.GridLayout;
|
|
16 import org.eclipse.swt.widgets.Composite;
|
|
17 import org.eclipse.ui.IEditorInput;
|
|
18 import org.eclipse.ui.IEditorSite;
|
|
19 import org.eclipse.ui.PartInitException;
|
|
20 import org.eclipse.ui.part.EditorPart;
|
25
|
21 import org.eclipse.ui.views.properties.IPropertySheetPage;
|
|
22 import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
|
|
23 import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
|
1
|
24 import org.jdom.JDOMException;
|
|
25
|
|
26 import de.mpg.mpiwg.itgroup.digilib.digiImage.DigiImage;
|
|
27 import de.mpg.mpiwg.itgroup.digilib.digiImage.DigiImageController;
|
|
28 import de.mpg.mpiwg.itgroup.digilib.digiImage.DigiImageParameter;
|
|
29 import de.mpg.mpiwg.itgroup.digilib.digiImage.DigiNav;
|
27
|
30 import de.mpg.mpiwg.itgroup.digilib.digiImage.IDigiImage;
|
|
31 import de.mpg.mpiwg.itgroup.digilib.digiImage.TextGridDigiImage;
|
1
|
32 import de.mpg.mpiwg.itgroup.indexMeta.Utils.ParseIndexMeta;
|
|
33
|
|
34 /**
|
9
|
35 * Displays an image with digilib an allows image manipulation on the image.
|
1
|
36 *
|
|
37 * @author dwinter
|
|
38 *
|
|
39 */
|
25
|
40 public class DigilibLinkEditorPart extends EditorPart implements Observer, ITabbedPropertySheetPageContributor{
|
1
|
41
|
30
|
42 private static final int SIZE_DH = 1000;
|
|
43 private static final int SIZE_DW = 1000;
|
1
|
44 private Composite mainComposite;
|
|
45 private ScrolledComposite sc;
|
25
|
46 private boolean isDirty;
|
|
47 private TabbedPropertySheetPage tp=null;
|
1
|
48 @Override
|
|
49 public void doSave(IProgressMonitor monitor) {
|
|
50 // TODO Auto-generated method stub
|
|
51
|
|
52 }
|
|
53
|
|
54 @Override
|
|
55 public void doSaveAs() {
|
|
56 // TODO Auto-generated method stub
|
|
57
|
|
58 }
|
|
59
|
|
60 @Override
|
|
61 public void init(IEditorSite site, IEditorInput input)
|
|
62 throws PartInitException {
|
|
63 setInput(input);
|
|
64 setSite(site);
|
|
65
|
|
66 }
|
|
67
|
|
68 @Override
|
|
69 public boolean isDirty() {
|
25
|
70 return isDirty;
|
1
|
71 }
|
|
72
|
|
73 @Override
|
|
74 public boolean isSaveAsAllowed() {
|
|
75 // TODO Auto-generated method stub
|
|
76 return false;
|
|
77 }
|
|
78
|
|
79 @Override
|
|
80 public void createPartControl(Composite frame) {
|
|
81
|
|
82 sc = new ScrolledComposite(frame, SWT.H_SCROLL | SWT.V_SCROLL);
|
|
83 mainComposite = new Composite(sc,SWT.None);
|
|
84
|
|
85 GridLayout imageLayout = new GridLayout(2,false);
|
|
86 mainComposite.setLayout(imageLayout);
|
|
87 sc.setContent(mainComposite);
|
|
88 //sc.setMinSize(400, 400);
|
|
89
|
9
|
90
|
1
|
91
|
|
92 DigilibLinkEditorInput input= (DigilibLinkEditorInput) getEditorInput();
|
|
93 String path="";
|
27
|
94
|
|
95
|
|
96 IDigiImage digiImage;
|
|
97
|
1
|
98 if (input.getType()==DigilibLinkEditorInput.INDEX_META){
|
|
99 ParseIndexMeta im;
|
|
100 try {
|
9
|
101 im = new ParseIndexMeta(input.getFile());
|
1
|
102 } catch (JDOMException e) {
|
|
103 // TODO Auto-generated catch block
|
|
104 e.printStackTrace();
|
|
105 return;
|
|
106 } catch (IOException e) {
|
|
107 // TODO Auto-generated catch block
|
|
108 e.printStackTrace();
|
|
109 return;
|
|
110 } catch (CoreException e) {
|
|
111 // TODO Auto-generated catch block
|
|
112 e.printStackTrace();
|
|
113 return;
|
|
114 }
|
|
115 try {
|
|
116 path=im.getImagePath();
|
27
|
117 path=path.replace("/mpiwg/online", "");
|
|
118 DigiImageParameter dp = new DigiImageParameter(path);
|
|
119 dp.setType(input.getType());
|
30
|
120 dp.setDh(SIZE_DH);
|
|
121 dp.setDw(SIZE_DW);
|
27
|
122 digiImage = new DigiImage(mainComposite, SWT.BORDER, dp);
|
1
|
123 } catch (JDOMException e) {
|
|
124 // TODO Auto-generated catch block
|
|
125 e.printStackTrace();
|
|
126 return;
|
|
127 }
|
|
128 if (path==null)
|
|
129 return;
|
27
|
130 } else if (input.getType()==DigilibLinkEditorInput.TEXTGRID){
|
|
131 path = input.getUri().toASCIIString();
|
|
132 DigiImageParameter dp = new DigiImageParameter(path);
|
|
133 dp.setType(input.getType());
|
30
|
134 dp.setDh(SIZE_DH);
|
|
135 dp.setDw(SIZE_DW);
|
27
|
136 digiImage = new TextGridDigiImage(mainComposite, SWT.BORDER, dp,input.getSid());
|
|
137
|
1
|
138 } else {
|
|
139 //TODO: issue warning that type cannot be solved.
|
|
140 return;
|
|
141 }
|
|
142
|
|
143
|
27
|
144
|
1
|
145
|
|
146
|
27
|
147
|
1
|
148 DigiImageController digiImageController = new DigiImageController(digiImage);
|
|
149 //imageComp.setBackgroundImage(img);
|
24
|
150 new DigiNav(mainComposite,SWT.NONE,digiImageController);
|
1
|
151
|
20
|
152 getSite().setSelectionProvider(digiImage);
|
25
|
153 //StructuredSelection strucSel = new StructuredSelection(digiImage);
|
20
|
154 digiImage.setSelection(new StructuredSelection(digiImage));
|
|
155
|
1
|
156 sc.setMinSize(mainComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
|
|
157 sc.setExpandHorizontal(true);
|
|
158 sc.setExpandVertical(true);
|
|
159 sc.layout();
|
|
160 DigilibLinkEditorObservable.INSTANCE.addObserver(this);
|
|
161
|
20
|
162 //setSelection( digiImage);
|
1
|
163 }
|
|
164
|
|
165 @Override
|
|
166 public void setFocus() {
|
|
167 // TODO Auto-generated method stub
|
|
168
|
|
169 }
|
|
170
|
26
|
171 /* (non-Javadoc)
|
|
172 * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
|
|
173 * Called from the observable
|
|
174 */
|
1
|
175 public void update(Observable o, Object arg) {
|
26
|
176 /*
|
|
177 * If the argument ist digiImage then rerender the editor and update the properties
|
|
178 */
|
30
|
179 if (IDigiImage.class.isInstance(arg)){
|
1
|
180 mainComposite.pack();
|
|
181 sc.setMinSize(mainComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
|
|
182 sc.layout();
|
25
|
183 isDirty=true;
|
|
184 firePropertyChange(PROP_DIRTY);
|
20
|
185
|
25
|
186 //Object[] ls = getListeners();
|
|
187 //System.out.println(ls);
|
20
|
188
|
25
|
189 if (tp!=null)
|
|
190 tp.refresh();
|
|
191
|
20
|
192
|
1
|
193 } else if (Integer.class.isInstance(arg)){
|
26
|
194 //if it is in integer then the argument is the status of the cursor
|
1
|
195 int b = (Integer) arg;
|
|
196
|
29
|
197
|
|
198 try {
|
|
199 Cursor waitCursor = new Cursor(mainComposite.getDisplay(), b);
|
|
200 mainComposite.setCursor(waitCursor);
|
|
201 } catch (Exception e) {
|
|
202 // TODO: handle exception
|
|
203
|
|
204 }
|
1
|
205
|
|
206 }
|
|
207
|
20
|
208
|
1
|
209 }
|
25
|
210
|
26
|
211 /* (non-Javadoc)
|
|
212 * @see org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor#getContributorId()
|
|
213 */
|
25
|
214 public String getContributorId() {
|
|
215 String contribId = getSite().getId();
|
|
216 return contribId;
|
|
217 }
|
20
|
218
|
26
|
219 /* (non-Javadoc)
|
|
220 * @see org.eclipse.ui.part.WorkbenchPart#getAdapter(java.lang.Class)
|
|
221 */
|
|
222 @SuppressWarnings("rawtypes")
|
|
223 public Object getAdapter(Class adapter) {
|
25
|
224 if (adapter == IPropertySheetPage.class){
|
|
225
|
|
226 tp = new TabbedPropertySheetPage(this);
|
|
227 return tp;
|
|
228 }
|
|
229 return super.getAdapter(adapter);
|
|
230 }
|
1
|
231
|
|
232 }
|