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