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