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