# HG changeset patch
# User dwinter
# Date 1345794177 -7200
# Node ID 0205c3f41d1dcac60b10f2a5e8be2ca05b780fd2
# Parent 361d8c89338afc08980bbbf0b9d9972857fa12cb
repackaging (separate textgridlab and dgilib local parts more rigorously
diff -r 361d8c89338a -r 0205c3f41d1d .classpath
--- a/.classpath Sat Jun 18 09:53:01 2011 +0200
+++ b/.classpath Fri Aug 24 09:42:57 2012 +0200
@@ -3,7 +3,6 @@
-
diff -r 361d8c89338a -r 0205c3f41d1d META-INF/MANIFEST.MF
--- a/META-INF/MANIFEST.MF Sat Jun 18 09:53:01 2011 +0200
+++ b/META-INF/MANIFEST.MF Fri Aug 24 09:42:57 2012 +0200
@@ -11,10 +11,11 @@
org.eclipse.ui.editors,
org.eclipse.ui.ide,
org.eclipse.ui.views.properties.tabbed;bundle-version="3.5.100",
- org.apache.axis2.full;bundle-version="1.4.0",
de.mpg.mpiwg.itgroup.digilib.core;bundle-version="0.0.1"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ClassPath: libs/commons-lang-2.3.jar,
.,
libs/digilibservice-client-1.0-SNAPSHOT.jar
+Import-Package: org.eclipse.core.filesystem,
+ org.jdom;version="1.1.1"
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/back.png
Binary file icons/obj16/back.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/bg-round.png
Binary file icons/obj16/bg-round.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/birds-eye.png
Binary file icons/obj16/birds-eye.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/brightness.png
Binary file icons/obj16/brightness.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/calibration.png
Binary file icons/obj16/calibration.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/cat.png
Binary file icons/obj16/cat.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/contrast.png
Binary file icons/obj16/contrast.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/delmark.png
Binary file icons/obj16/delmark.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/digilib-logo.png
Binary file icons/obj16/digilib-logo.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/down.png
Binary file icons/obj16/down.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/down1.png
Binary file icons/obj16/down1.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/first.png
Binary file icons/obj16/first.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/fwd.png
Binary file icons/obj16/fwd.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/info.png
Binary file icons/obj16/info.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/last.png
Binary file icons/obj16/last.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/left.png
Binary file icons/obj16/left.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/left1.png
Binary file icons/obj16/left1.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/mark.png
Binary file icons/obj16/mark.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/mirror-horizontal.png
Binary file icons/obj16/mirror-horizontal.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/mirror-vertical.png
Binary file icons/obj16/mirror-vertical.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/options.png
Binary file icons/obj16/options.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/original-size.png
Binary file icons/obj16/original-size.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/page.png
Binary file icons/obj16/page.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/pagewidth.png
Binary file icons/obj16/pagewidth.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/quality.png
Binary file icons/obj16/quality.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/reference.png
Binary file icons/obj16/reference.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/reset.png
Binary file icons/obj16/reset.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/rgb.png
Binary file icons/obj16/rgb.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/right.png
Binary file icons/obj16/right.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/right1.png
Binary file icons/obj16/right1.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/rotate.png
Binary file icons/obj16/rotate.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/size-bigger.png
Binary file icons/obj16/size-bigger.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/size-smaller.png
Binary file icons/obj16/size-smaller.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/up.png
Binary file icons/obj16/up.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/up1.png
Binary file icons/obj16/up1.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/zoom-area.png
Binary file icons/obj16/zoom-area.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/zoom-full.png
Binary file icons/obj16/zoom-full.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/zoom-in.png
Binary file icons/obj16/zoom-in.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d icons/obj16/zoom-out.png
Binary file icons/obj16/zoom-out.png has changed
diff -r 361d8c89338a -r 0205c3f41d1d plugin.xml
--- a/plugin.xml Sat Jun 18 09:53:01 2011 +0200
+++ b/plugin.xml Fri Aug 24 09:42:57 2012 +0200
@@ -46,4 +46,16 @@
+
+
+
+
+
+
diff -r 361d8c89338a -r 0205c3f41d1d src/de/mpg/mpiwg/itgroup/digilib/digiImage/DigiImage.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/de/mpg/mpiwg/itgroup/digilib/digiImage/DigiImage.java Fri Aug 24 09:42:57 2012 +0200
@@ -0,0 +1,292 @@
+package de.mpg.mpiwg.itgroup.digilib.digiImage;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.lang.StringUtils;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.internal.Workbench;
+import org.eclipse.ui.views.properties.IPropertySource;
+
+
+import de.mpg.mpiwg.itgroup.digilib.plugin.Activator;
+import de.mpg.mpiwg.itgroup.digilib.digiImage.properties.DigiImageProperties;
+import de.mpg.mpiwg.itgroup.digilib.listener.MoveClickListener;
+import de.mpg.mpiwg.itgroup.digilib.listener.ZoomAreaRectangleListener;
+import de.mpg.mpiwg.itgroup.digilib.plugin.editors.DigilibLinkEditorObservable;
+import de.mpg.mpiwg.itgroup.digilib.plugin.preferences.PluginPreferencePage;
+
+
+
+
+/**
+ * Refers to an Digilib-Scaler Object either an image or an folder. The object contains an swt-label object, so that it can be embedded e.g. in Eclipse.
+ * @author dwinter
+ *
+ */
+public class DigiImage implements IDigiImage, IAdaptable{
+
+ /**
+ * Implemens a connection to Digilib.
+ */
+
+
+
+ private List selectionChangeListener = new ArrayList();
+
+ /* some parameters should not occur in the URL constructed by {@link #createUrlFromParameter(DigiImageParameter)} if set to negative values.
+ *
+ */
+ private static String[] omitIfNegativeArray = {"dw","dh","ddpi","ddpix","ddpiy"};
+ private static List omitIfNegative = Arrays.asList(omitIfNegativeArray);
+
+
+ //private String baseUrl="http://digilib.mpiwg-berlin.mpg.de/digitallibrary/servlet/Scaler";
+
+ /**
+ * Get the Url of the digilib scaler, set to http://digilib.mpiwg-berlin.mpg.de/digitallibrary/servlet/Scaler, if not changed.
+ * TODO should be part of a configuration/preference file
+ * @return
+ */
+ public String getBaseUrl() {
+ return baseUrl;
+ }
+
+ /**
+ * Setze die Basis url des Digilib-Scalers
+ * @param baseUrl
+ */
+ public void setBaseUrl(String baseUrl) {
+ this.baseUrl = baseUrl;
+ }
+
+ private Label label;
+
+ /* (non-Javadoc)
+ * @see de.mpg.mpiwg.itgroup.digilib.digiImage.IDigiImage#getLabel()
+ */
+ public Label getLabel() {
+ return label;
+ }
+
+ /* (non-Javadoc)
+ * @see de.mpg.mpiwg.itgroup.digilib.digiImage.IDigiImage#setLabel(org.eclipse.swt.widgets.Label)
+ */
+ public void setLabel(Label label) {
+ this.label = label;
+ }
+
+ //private URL url;
+ private Composite parent;
+
+ private DigiImageParameter dp;
+
+ private String baseUrl;
+
+
+ /**
+ *
+ * @param parent Composite where the image should be become a child of.
+ * @param style SWT Style how to display the image as a composite. For more the the style parameter at @see import org.eclipse.swt.widgets.Label
+ * @param dp Set of Parameters which define how the image should be displayed.
+ */
+ public DigiImage(Composite parent, int style, DigiImageParameter dp) {
+ //super(parent,style);
+ label = new Label(parent, style);
+ this.parent = parent;
+ this.dp=dp;
+ IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+ this.baseUrl = store.getString(PluginPreferencePage.baseUrl_id);
+ try {
+ setNewURL(createUrlFromParameter(dp));
+ } catch (MalformedURLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+ /**
+ * Sets the complete URL of the manipulated image and changes the image object in the composite.
+ * @param url
+ */
+ private void setNewURL(URL url) {
+ //this.url = url;
+
+
+ InputStream is;
+ try {
+ is = url.openStream();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return;
+ }
+ Image img = new Image(parent.getDisplay(),is);
+ //Label label = new Label(parent, SWT.None);
+ label.setImage(img);
+
+ label.setVisible(true);
+ }
+
+
+ /* (non-Javadoc)
+ * @see de.mpg.mpiwg.itgroup.digilib.digiImage.IDigiImage#getParent()
+ */
+ public Composite getParent() {
+ return parent;
+ }
+
+
+ /**
+ * Creates the URL to digilib from the given parameter set. For the documentation @see {@link http://developer.berlios.de/docman/display_doc.php?docid=106&group_id=251}.
+ * @param dp
+ * @return
+ * @throws MalformedURLException
+ */
+ private URL createUrlFromParameter(DigiImageParameter dp) throws MalformedURLException{
+
+ Map qa = dp.createMapFromParameters(omitIfNegative);
+
+ List queryArray = new ArrayList();
+ for(String key:qa.keySet()){
+ queryArray.add(key+"="+qa.get(key));
+ }
+ String queryString = StringUtils.join(queryArray,"&");
+
+ String stringUrl=baseUrl+"?"+queryString;
+
+ return new URL(stringUrl);
+ }
+
+
+
+ /* (non-Javadoc)
+ * @see de.mpg.mpiwg.itgroup.digilib.digiImage.IDigiImage#getParameter()
+ */
+ public DigiImageParameter getParameter() {
+
+ return dp;
+ }
+
+ /* (non-Javadoc)
+ * @see de.mpg.mpiwg.itgroup.digilib.digiImage.IDigiImage#setParameter(de.mpg.mpiwg.itgroup.digilib.digiImage.DigiImageParameter)
+ */
+ public void setParameter(DigiImageParameter dp) {
+ this.dp=dp;
+
+ }
+
+ /* (non-Javadoc)
+ * @see de.mpg.mpiwg.itgroup.digilib.digiImage.IDigiImage#redraw()
+ */
+ public void redraw(){
+ try {
+ setNewURL(createUrlFromParameter(dp));
+ setSelection(new StructuredSelection(this));
+ DigilibLinkEditorObservable.INSTANCE.imageHasChanged(this);
+
+ } catch (MalformedURLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+
+ private ZoomAreaRectangleListener rectangleListener=null;
+
+ /* (non-Javadoc)
+ * @see de.mpg.mpiwg.itgroup.digilib.digiImage.IDigiImage#getRectangleListener()
+ */
+ public ZoomAreaRectangleListener getRectangleListener() {
+
+ return rectangleListener;
+ }
+
+ /* (non-Javadoc)
+ * @see de.mpg.mpiwg.itgroup.digilib.digiImage.IDigiImage#setRectangleListener(de.mpg.mpiwg.itgroup.digilib.manipulator.extensions.RectangleListener)
+ */
+ public void setRectangleListener(ZoomAreaRectangleListener rectangleListener) {
+ this.rectangleListener = rectangleListener;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
+ *
+ * Digiimage shows properties if asked to.
+ */
+ @SuppressWarnings("rawtypes")
+ public DigiImageProperties getAdapter(Class adapter) {
+ if (adapter == IPropertySource.class)
+ return new DigiImageProperties(this);
+
+ return null;
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ISelectionProvider#addSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
+ * Digiimage registeres selelection changers
+ */
+ public void addSelectionChangedListener(ISelectionChangedListener listener) {
+ selectionChangeListener.add(listener);
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ISelectionProvider#getSelection()
+ * Selection is the object itself.
+ */
+ public ISelection getSelection() {
+
+ return new StructuredSelection(this);
+ }
+
+ public void removeSelectionChangedListener(
+ ISelectionChangedListener listener) {
+ selectionChangeListener.remove(listener);
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection)
+ * Informs all listeners that selection has changed.
+ */
+ public void setSelection(ISelection selection) {
+
+ for (ISelectionChangedListener sl: selectionChangeListener){
+ SelectionChangedEvent event = new SelectionChangedEvent(this, selection);
+ sl.selectionChanged(event);
+
+
+ }
+
+ }
+
+
+ @Override
+ public MoveClickListener getMoveClickListener() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+
+}
+
+
diff -r 361d8c89338a -r 0205c3f41d1d src/de/mpg/mpiwg/itgroup/digilib/plugin/DigilibHandler.java
--- a/src/de/mpg/mpiwg/itgroup/digilib/plugin/DigilibHandler.java Sat Jun 18 09:53:01 2011 +0200
+++ b/src/de/mpg/mpiwg/itgroup/digilib/plugin/DigilibHandler.java Fri Aug 24 09:42:57 2012 +0200
@@ -11,7 +11,7 @@
import org.eclipse.ui.handlers.HandlerUtil;
import de.mpg.mpiwg.itgroup.digilib.plugin.editors.DigilibLinkEditorInput;
-import de.mpg.mpiwg.itgroup.digilib.plugin.editors.DigilibLinkEditorPart;
+import de.mpg.mpiwg.itgroup.digilib.plugin.editors.IDigilibLinkEditorPart;
/**
* @author dwinter
@@ -44,7 +44,7 @@
DigilibLinkEditorInput input = new DigilibLinkEditorInput(file,DigilibLinkEditorInput.INDEX_META);
try {
- DigilibLinkEditorPart dp = (DigilibLinkEditorPart) HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().openEditor(input,"de.mpg.mpiwg.itgroup.digilib.plugin.digilibLinkEditor");
+ IDigilibLinkEditorPart dp = (IDigilibLinkEditorPart) HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().openEditor(input,"de.mpg.mpiwg.itgroup.digilib.plugin.digilibLinkEditor");
return dp;
} catch (PartInitException e) {
// TODO Auto-generated catch block
diff -r 361d8c89338a -r 0205c3f41d1d src/de/mpg/mpiwg/itgroup/digilib/plugin/editors/DigilibLinkEditorContributor.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/de/mpg/mpiwg/itgroup/digilib/plugin/editors/DigilibLinkEditorContributor.java Fri Aug 24 09:42:57 2012 +0200
@@ -0,0 +1,103 @@
+package de.mpg.mpiwg.itgroup.digilib.plugin.editors;
+
+import org.eclipse.jface.action.*;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.ide.IDEActionFactory;
+import org.eclipse.ui.part.MultiPageEditorActionBarContributor;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.ui.texteditor.ITextEditorActionConstants;
+
+/**
+ * Manages the installation/deinstallation of global actions for multi-page editors.
+ * Responsible for the redirection of global actions to the active editor.
+ * Multi-page contributor replaces the contributors for the individual editors in the multi-page editor.
+ */
+public class DigilibLinkEditorContributor extends MultiPageEditorActionBarContributor {
+ private IEditorPart activeEditorPart;
+ //private Action sampleAction;
+ /**
+ * Creates a multi-page contributor.
+ */
+ public DigilibLinkEditorContributor() {
+ super();
+ //createActions();
+ }
+ /**
+ * Returns the action registed with the given text editor.
+ * @return IAction or null if editor is null.
+ */
+ protected IAction getAction(ITextEditor editor, String actionID) {
+ return (editor == null ? null : editor.getAction(actionID));
+ }
+ /* (non-JavaDoc)
+ * Method declared in AbstractMultiPageEditorActionBarContributor.
+ */
+
+ public void setActivePage(IEditorPart part) {
+ if (activeEditorPart == part)
+ return;
+
+ activeEditorPart = part;
+
+ IActionBars actionBars = getActionBars();
+ if (actionBars != null) {
+
+ ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor) part : null;
+
+ actionBars.setGlobalActionHandler(
+ ActionFactory.DELETE.getId(),
+ getAction(editor, ITextEditorActionConstants.DELETE));
+ actionBars.setGlobalActionHandler(
+ ActionFactory.UNDO.getId(),
+ getAction(editor, ITextEditorActionConstants.UNDO));
+ actionBars.setGlobalActionHandler(
+ ActionFactory.REDO.getId(),
+ getAction(editor, ITextEditorActionConstants.REDO));
+ actionBars.setGlobalActionHandler(
+ ActionFactory.CUT.getId(),
+ getAction(editor, ITextEditorActionConstants.CUT));
+ actionBars.setGlobalActionHandler(
+ ActionFactory.COPY.getId(),
+ getAction(editor, ITextEditorActionConstants.COPY));
+ actionBars.setGlobalActionHandler(
+ ActionFactory.PASTE.getId(),
+ getAction(editor, ITextEditorActionConstants.PASTE));
+ actionBars.setGlobalActionHandler(
+ ActionFactory.SELECT_ALL.getId(),
+ getAction(editor, ITextEditorActionConstants.SELECT_ALL));
+ actionBars.setGlobalActionHandler(
+ ActionFactory.FIND.getId(),
+ getAction(editor, ITextEditorActionConstants.FIND));
+ actionBars.setGlobalActionHandler(
+ IDEActionFactory.BOOKMARK.getId(),
+ getAction(editor, IDEActionFactory.BOOKMARK.getId()));
+ actionBars.updateActionBars();
+ }
+ }
+ private void createActions() {
+// sampleAction = new Action() {
+// public void run() {
+// MessageDialog.openInformation(null, "digilibClient", "Sample Action Executed");
+// }
+// };
+// sampleAction.setText("Sample Action");
+// sampleAction.setToolTipText("Sample Action tool tip");
+// sampleAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
+// getImageDescriptor(IDE.SharedImages.IMG_OBJS_TASK_TSK));
+ }
+ public void contributeToMenu(IMenuManager manager) {
+// IMenuManager menu = new MenuManager("Editor &Menu");
+// manager.prependToGroup(IWorkbenchActionConstants.MB_ADDITIONS, menu);
+// menu.add(sampleAction);
+ }
+ public void contributeToToolBar(IToolBarManager manager) {
+ //manager.add(new Separator());
+ //manager.add(sampleAction);
+ }
+}
diff -r 361d8c89338a -r 0205c3f41d1d src/de/mpg/mpiwg/itgroup/digilib/plugin/editors/DigilibLinkEditorPart.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/de/mpg/mpiwg/itgroup/digilib/plugin/editors/DigilibLinkEditorPart.java Fri Aug 24 09:42:57 2012 +0200
@@ -0,0 +1,499 @@
+// TODO: Navigationselemente sollen nach Eclipserichtlinien in den local (view) toolbar (http://www.eclipse.org/articles/Article-UI-Guidelines/Contents.html)
+
+package de.mpg.mpiwg.itgroup.digilib.plugin.editors;
+
+
+//
+//import info.textgrid.lab.core.model.TGContentType;
+//import info.textgrid.lab.core.model.TextGridObject;
+//import info.textgrid.lab.core.model.TextGridProject;
+//import info.textgrid.lab.core.swtutils.AdapterUtils;
+import de.mpg.mpiwg.itgroup.digilib.digiImage.Messages;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.URI;
+import java.util.Observable;
+import java.util.Observer;
+
+import javax.xml.transform.stream.StreamResult;
+
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileStore;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.ScrolledComposite;
+import org.eclipse.swt.graphics.Cursor;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Layout;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.ide.FileStoreEditorInput;
+import org.eclipse.ui.part.EditorPart;
+import org.eclipse.ui.progress.UIJob;
+import org.eclipse.ui.statushandlers.StatusManager;
+import org.eclipse.ui.views.properties.IPropertySheetPage;
+import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
+import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
+import org.jdom.JDOMException;
+
+import de.mpg.mpiwg.itgroup.digilib.core.plugin.Activator;
+
+import de.mpg.mpiwg.itgroup.digilib.digiImage.DigiImage;
+import de.mpg.mpiwg.itgroup.digilib.digiImage.DigiImageController;
+import de.mpg.mpiwg.itgroup.digilib.digiImage.DigiImageParameter;
+import de.mpg.mpiwg.itgroup.digilib.digiImage.DigiNav;
+import de.mpg.mpiwg.itgroup.digilib.digiImage.IDigiImage;
+import de.mpg.mpiwg.itgroup.digilib.digiImage.ImageLayout;
+import de.mpg.mpiwg.itgroup.digilib.digiImage.TextGridDigiImage;
+import de.mpg.mpiwg.itgroup.indexMeta.Utils.ParseIndexMeta;
+
+/**
+ * Displays an image with digilib an allows image manipulation on the image.
+ * TODO: textgrid elemente sollten in eine Extraklasse
+ *
+ * @author dwinter
+ *
+ */
+public class DigilibLinkEditorPart extends EditorPart implements Observer, ITabbedPropertySheetPageContributor, IDigilibLinkEditorPart{
+
+ private static final int SIZE_DH = 1000;
+ private static final int SIZE_DW = 1000;
+ private Composite mainComposite;
+ private ScrolledComposite sc;
+ private TabbedPropertySheetPage tp=null;
+ private DigiImageParameter dp = null;
+ private boolean dirty;
+ private IDigiImage digiImage;
+ //private TextGridProject textGridProject;
+ private Composite imageComposite;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
+ *
+ * Abgespeichert werden die Parameter des Digilib-Objektes als ein JSON object
+ * FIXME: doSave erkennt nicht richtig den Filenamen wird daher immer zu saveas
+ */
+ /* (non-Javadoc)
+ * @see de.mpg.mpiwg.itgroup.digilib.plugin.editors.IDigilibLinkEditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+
+ public void doSave(final IProgressMonitor monitor) {
+ if (dp== null)
+ return;
+
+ final IFile file = getAdapter(getEditorInput(), IFile.class);
+ if (file != null) {
+ final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ try {
+ dp.save(outputStream);
+ file.setContents(new ByteArrayInputStream(outputStream.toByteArray()), true, true, monitor);
+ setDirty(false);
+
+ } catch (final CoreException e) {
+ StatusManager.getManager().handle(e, Activator.PLUGIN_ID);
+ }
+ } else if (getEditorInput() instanceof FileStoreEditorInput) {
+ final URI targetURI = ((FileStoreEditorInput) getEditorInput()).getURI();
+ try {
+ final IFileStore store = EFS.getStore(targetURI);
+ final OutputStream outputStream = store.openOutputStream(EFS.NONE, monitor);
+ dp.save(outputStream);
+ outputStream.close();
+ setDirty(false);
+ } catch (final CoreException e) {
+ StatusManager.getManager().handle(e, Activator.PLUGIN_ID);
+ } catch (final IOException e) {
+ StatusManager.getManager().handle(
+ new Status(IStatus.ERROR, Activator.PLUGIN_ID, NLS.bind(
+ "save failed", targetURI,
+ e.getLocalizedMessage()), e), StatusManager.LOG | StatusManager.SHOW);
+ }
+ } else {
+ doSaveAs();
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see de.mpg.mpiwg.itgroup.digilib.plugin.editors.IDigilibLinkEditorPart#doSaveAs()
+ */
+ @Override
+
+ public void doSaveAs() {
+ int selection = new MessageDialog(getSite().getShell(), "save as title", null,
+ Messages.DiglibLinkEditor_Save_As_What, MessageDialog.QUESTION_WITH_CANCEL, new String[] {
+ Messages.DiglibLinkEditor_TextGridRep, Messages.DiglibLinkEditor_Local_File, Messages.DiglibLinkEditor_Cancel }, 1 ).open();
+ switch (selection) {
+ case 0:
+ //saveAsTextGridObject(true);
+ break;
+ case 1:
+ saveAsLocalFile();
+ break;
+ }
+ }
+
+// public void saveAsTextGridObject(boolean forceNew) {
+// TextGridObject object = null;
+// if (getEditorInput() instanceof IFileEditorInput)
+// object = AdapterUtils.getAdapter(((IFileEditorInput) getEditorInput()).getFile(), TextGridObject.class);
+// if (object == null || forceNew) {
+// object = TextGridObject.getNewObjectInstance(textGridProject,
+// TGContentType.of(Activator.CONTENT_TYPE_ID));
+// final InputDialog dialog = new InputDialog(
+// getSite().getShell(),
+// Messages.DiglibLinkEditor_Save_as_TextGrid_Title,
+// NLS.bind(
+// Messages.DiglibLinkEditor_Save_to_Target_Project,
+// textGridProject), "", new IInputValidator() { //$NON-NLS-1$
+//
+// @Override
+// public String isValid(final String newText) {
+// if (newText == null || newText.trim().isEmpty()) {
+// return Messages.DigilibLinkEditor_Title_Validation_Warning;
+// } else
+// return null;
+// }
+// });
+// if (dialog.open() != Window.CANCEL) {
+// object.setTitle(dialog.getValue().trim());
+// } else {
+// return;
+// }
+//
+// final IEditorInput input = AdapterUtils.getAdapter(object, IEditorInput.class);
+// setInputWithNotify(input);
+// }
+// new Job(NLS.bind(Messages.DiglibLinkEditor_Saving_x, object)) {
+//
+// @Override
+// protected IStatus run(final IProgressMonitor monitor) {
+// doSave(monitor);
+// if (monitor.isCanceled())
+// return Status.CANCEL_STATUS;
+// return Status.OK_STATUS;
+// }
+// }.schedule();
+// }
+//
+//
+
+
+ /* (non-Javadoc)
+ * @see de.mpg.mpiwg.itgroup.digilib.plugin.editors.IDigilibLinkEditorPart#saveAsLocalFile()
+ */
+ @Override
+ public void saveAsLocalFile() {
+ final FileDialog fileDialog = new FileDialog(getSite().getShell(), SWT.SAVE);
+ //fileDialog.setFilterExtensions(new String[] { "." //$NON-NLS-1$
+ // + TGContentType.getContentType(Activator.CONTENT_TYPE_ID).getExtension() });
+ //fileDialog.setFilterNames(new String[] { TGContentType.getContentType(Activator.CONTENT_TYPE_ID).getDescription() });
+ fileDialog.setText(Messages.DiglibLinkEditor_SaveImportSpecAsTitle);
+ final String fileName = fileDialog.open();
+ if (fileName != null) {
+ final URI fileURI = new File(fileName).toURI();
+ try {
+ final FileStoreEditorInput input = new FileStoreEditorInput(EFS.getStore(fileURI));
+ setPartName(input.getName());
+ setInputWithNotify(input);
+ doSave(new NullProgressMonitor());
+ } catch (final CoreException e) {
+ StatusManager.getManager().handle(e, Activator.PLUGIN_ID);
+ }
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see de.mpg.mpiwg.itgroup.digilib.plugin.editors.IDigilibLinkEditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
+ */
+
+ @Override
+ public void init(IEditorSite site, IEditorInput input)
+ throws PartInitException {
+ setInput(input);
+ setSite(site);
+
+ }
+
+ /* (non-Javadoc)
+ * @see de.mpg.mpiwg.itgroup.digilib.plugin.editors.IDigilibLinkEditorPart#isDirty()
+ */
+
+ @Override
+ public boolean isDirty() {
+ return dirty;
+ }
+
+ /* (non-Javadoc)
+ * @see de.mpg.mpiwg.itgroup.digilib.plugin.editors.IDigilibLinkEditorPart#isSaveAsAllowed()
+ */
+ @Override
+
+ public boolean isSaveAsAllowed() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see de.mpg.mpiwg.itgroup.digilib.plugin.editors.IDigilibLinkEditorPart#createPartControl(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+
+ public void createPartControl(Composite frame) {
+
+ sc = new ScrolledComposite(frame, SWT.H_SCROLL | SWT.V_SCROLL);
+ mainComposite = new Composite(sc,SWT.None);
+
+ GridLayout imageLayout = new GridLayout(2,false);
+ mainComposite.setLayout(imageLayout);
+
+ Layout imgLayout = new ImageLayout();
+ imageComposite = new Composite(mainComposite,SWT.None);
+ imageComposite.setLayout(imgLayout);
+ sc.setContent(mainComposite);
+ //sc.setMinSize(400, 400);
+
+
+
+ DigilibLinkEditorInput input= (DigilibLinkEditorInput) getEditorInput();
+
+ String path="";
+
+ sc.layout();
+ Point size = sc.getSize();
+
+ //this.getViewer().
+
+
+ int dh = SIZE_DH;
+ int dw = SIZE_DW;
+
+ if (input.getType()==DigilibLinkEditorInput.INDEX_META){
+ ParseIndexMeta im;
+ try {
+ im = new ParseIndexMeta(input.getFile());
+ } catch (JDOMException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return;
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return;
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return;
+ }
+ try {
+ path=im.getImagePath();
+ path=path.replace("/mpiwg/online", "");
+ dp = new DigiImageParameter(path);
+ dp.setType(input.getType());
+ dp.setDh(dh);
+ dp.setDw(dw);
+ //dp.setDh(SIZE_DH);
+ //dp.setDw(SIZE_DW);
+ digiImage = new DigiImage(mainComposite, SWT.BORDER, dp);
+ } catch (JDOMException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return;
+ }
+ if (path==null)
+ return;
+ } else if (input.getType()==DigilibLinkEditorInput.TEXTGRID){
+ path = input.getUri().toASCIIString();
+
+ dp = input.getParameter();
+ if (dp==null){
+ dp = new DigiImageParameter(path);
+ }
+ dp.setType(input.getType());
+ dp.setDh(SIZE_DH);
+ dp.setDw(SIZE_DW);
+ digiImage = new TextGridDigiImage(imageComposite, SWT.BORDER, dp,input.getSid());
+
+ } else {
+ //TODO: issue warning that type cannot be solved.
+ return;
+ }
+
+
+
+
+
+
+ DigiImageController digiImageController = new DigiImageController(digiImage);
+ //imageComp.setBackgroundImage(img);
+ new DigiNav(mainComposite,SWT.NONE,digiImageController);
+
+ getSite().setSelectionProvider(digiImage);
+ //StructuredSelection strucSel = new StructuredSelection(digiImage);
+ digiImage.setSelection(new StructuredSelection(digiImage));
+
+ sc.setMinSize(mainComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
+ sc.setExpandHorizontal(true);
+ sc.setExpandVertical(true);
+ sc.layout();
+ DigilibLinkEditorObservable.INSTANCE.addObserver(this);
+
+ //setSelection( digiImage);
+ }
+
+ /* (non-Javadoc)
+ * @see de.mpg.mpiwg.itgroup.digilib.plugin.editors.IDigilibLinkEditorPart#setFocus()
+ */
+ @Override
+
+ public void setFocus() {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
+ * Called from the observable
+ */
+ /* (non-Javadoc)
+ * @see de.mpg.mpiwg.itgroup.digilib.plugin.editors.IDigilibLinkEditorPart#update(java.util.Observable, java.lang.Object)
+ */
+ @Override
+ public void update(Observable o, Object arg) {
+ /*
+ * If the argument ist digiImage then rerender the editor and update the properties
+ */
+ if (IDigiImage.class.isInstance(arg)){
+
+ mainComposite.pack();
+
+ sc.setMinSize(mainComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
+ sc.layout();
+ dirty=true;
+ firePropertyChange(PROP_DIRTY);
+
+ //Object[] ls = getListeners();
+ //System.out.println(ls);
+
+ if (tp!=null)
+ tp.refresh();
+
+
+ } else if (Integer.class.isInstance(arg)){
+ //if it is in integer then the argument is the status of the cursor
+ int b = (Integer) arg;
+
+
+ try {
+ Cursor waitCursor = new Cursor(mainComposite.getDisplay(), b);
+ mainComposite.setCursor(waitCursor);
+ } catch (Exception e) {
+ // TODO: handle exception
+
+ }
+
+ }
+
+
+ }
+
+ /* (non-Javadoc)
+ * @see de.mpg.mpiwg.itgroup.digilib.plugin.editors.IDigilibLinkEditorPart#getDigiImage()
+ */
+ @Override
+ public IDigiImage getDigiImage(){
+ return digiImage;
+
+
+
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor#getContributorId()
+ */
+ /* (non-Javadoc)
+ * @see de.mpg.mpiwg.itgroup.digilib.plugin.editors.IDigilibLinkEditorPart#getContributorId()
+ */
+ @Override
+ public String getContributorId() {
+ String contribId = getSite().getId();
+ return contribId;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.WorkbenchPart#getAdapter(java.lang.Class)
+ */
+ /* (non-Javadoc)
+ * @see de.mpg.mpiwg.itgroup.digilib.plugin.editors.IDigilibLinkEditorPart#getAdapter(java.lang.Class)
+ */
+ @Override
+ @SuppressWarnings("rawtypes")
+ public Object getAdapter(Class adapter) {
+ if (adapter == IPropertySheetPage.class){
+
+ tp = new TabbedPropertySheetPage(this);
+ return tp;
+ }
+ return super.getAdapter(adapter);
+ }
+
+ void setDirty(final boolean dirty) {
+ this.dirty = dirty;
+ UIJob uiJob = new UIJob("Set dirty") { //$NON-NLS-1$
+
+ public IStatus runInUIThread(IProgressMonitor monitor) {
+ firePropertyChange(PROP_DIRTY);
+ return Status.OK_STATUS;
+ }
+ };
+ uiJob.setSystem(true);
+ uiJob.schedule();
+ }
+
+
+ public static T getAdapter(Object source, Class type) {
+
+ if (source == null)
+ return null;
+
+ if (type.isInstance(source))
+ return (T) source;
+
+ if (source instanceof IAdaptable)
+ return (T) ((IAdaptable) source).getAdapter(type);
+
+ return (T) Platform.getAdapterManager().getAdapter(source, type);
+ }
+
+
+// public void setTextGridProject(TextGridProject project) {
+// this.textGridProject=project;
+//
+// }
+
+}