]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.graphfile/src/org/simantics/graphfile/hack/GraphFileEditorInput.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.graphfile / src / org / simantics / graphfile / hack / GraphFileEditorInput.java
index 2673f3a45d37fba1c6366d961940351d5545b811..f1ac6f485b8cdf406cc701bdf6724506be66508a 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2013 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.graphfile.hack;\r
-\r
-import java.net.URI;\r
-\r
-import org.eclipse.core.resources.IFile;\r
-import org.eclipse.core.resources.IStorage;\r
-import org.eclipse.core.runtime.IPath;\r
-import org.eclipse.core.runtime.PlatformObject;\r
-import org.eclipse.core.runtime.content.IContentType;\r
-import org.eclipse.jface.resource.ImageDescriptor;\r
-import org.eclipse.ui.IFileEditorInput;\r
-import org.eclipse.ui.IMemento;\r
-import org.eclipse.ui.IPathEditorInput;\r
-import org.eclipse.ui.IPersistableElement;\r
-import org.eclipse.ui.IURIEditorInput;\r
-import org.eclipse.ui.PlatformUI;\r
-import org.eclipse.ui.ide.IDE;\r
-import org.eclipse.ui.model.IWorkbenchAdapter;\r
-\r
-\r
-/**\r
- * Editor input for files stored in the graph.\r
- * \r
- * Note: this class is required, since FileEditorInput is not able to load/save GraphFile references.\r
- * Contents of this class are mostly copy-pasted from FileEditorInput.\r
- * \r
- * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
- *\r
- */\r
-public class GraphFileEditorInput  extends PlatformObject implements IFileEditorInput, IPathEditorInput, IURIEditorInput,\r
- IPersistableElement {\r
-private GraphFile file;\r
-       \r
-\r
-       /**\r
-        * Creates an editor input based of the given file resource.\r
-        *\r
-        * @param file the file resource\r
-        */\r
-       public GraphFileEditorInput(GraphFile file) {\r
-               if (file == null)\r
-                       throw new IllegalArgumentException();\r
-               this.file = file;\r
-       \r
-       }\r
-\r
-       /* (non-Javadoc)\r
-        * Method declared on Object.\r
-        */\r
-       public int hashCode() {\r
-               return file.hashCode();\r
-       }\r
-\r
-       /* (non-Javadoc)\r
-        * Method declared on Object.\r
-        *\r
-        * The <code>FileEditorInput</code> implementation of this <code>Object</code>\r
-        * method bases the equality of two <code>FileEditorInput</code> objects on the\r
-        * equality of their underlying <code>IFile</code> resources.\r
-        */\r
-       public boolean equals(Object obj) {\r
-               if (this == obj) {\r
-                       return true;\r
-               }\r
-               if (!(obj instanceof IFileEditorInput)) {\r
-                       return false;\r
-               }\r
-               IFileEditorInput other = (IFileEditorInput) obj;\r
-               return file.equals(other.getFile());\r
-       }\r
-\r
-       /* (non-Javadoc)\r
-        * Method declared on IEditorInput.\r
-        */\r
-       public boolean exists() {\r
-               return file.exists();\r
-       }\r
-\r
-       /* (non-Javadoc)\r
-        * Method declared on IPersistableElement.\r
-        */\r
-       public String getFactoryId() {\r
-               return GraphFileEditorInputFactory.getFactoryId();\r
-       }\r
-\r
-       /* (non-Javadoc)\r
-        * Method declared on IFileEditorInput.\r
-        */\r
-       public IFile getFile() {\r
-               return file;\r
-       }\r
-\r
-       /* (non-Javadoc)\r
-        * Method declared on IEditorInput.\r
-        */\r
-       public ImageDescriptor getImageDescriptor() {\r
-               IContentType contentType = IDE.getContentType(file);\r
-               return PlatformUI.getWorkbench().getEditorRegistry()\r
-                               .getImageDescriptor(file.getName(), contentType);\r
-       }\r
-\r
-       /* (non-Javadoc)\r
-        * Method declared on IEditorInput.\r
-        */\r
-       public String getName() {\r
-               return file.getName();\r
-       }\r
-\r
-       /* (non-Javadoc)\r
-        * Method declared on IEditorInput.\r
-        */\r
-       public IPersistableElement getPersistable() {\r
-               return this;\r
-       }\r
-\r
-       /* (non-Javadoc)\r
-        * Method declared on IStorageEditorInput.\r
-        */\r
-       public IStorage getStorage() {\r
-               return file;\r
-       }\r
-\r
-       /* (non-Javadoc)\r
-        * Method declared on IEditorInput.\r
-        */\r
-       public String getToolTipText() {\r
-               return file.getFullPath().makeRelative().toString();\r
-       }\r
-\r
-       /* (non-Javadoc)\r
-        * Method declared on IPersistableElement.\r
-        */\r
-       public void saveState(IMemento memento) {\r
-               GraphFileEditorInputFactory.saveState(memento, this);\r
-       }\r
-\r
-       \r
-\r
-       /* (non-Javadoc)\r
-        * @see org.eclipse.ui.IURIEditorInput#getURI()\r
-        */\r
-       public URI getURI() {\r
-               return file.getLocationURI();\r
-       }\r
-       \r
-       \r
-       /* (non-Javadoc)\r
-        * @see org.eclipse.ui.IPathEditorInput#getPath()\r
-        */\r
-       public IPath getPath() {\r
-               IPath location = file.getLocation();\r
-               if (location != null)\r
-                       return location;\r
-\r
-               throw new IllegalArgumentException();\r
-       }\r
-\r
-\r
-       /* (non-Javadoc)\r
-        * @see java.lang.Object#toString()\r
-        */\r
-       public String toString() {\r
-               return getClass().getName() + "(" + getFile().getFullPath() + ")"; //$NON-NLS-1$ //$NON-NLS-2$\r
-       }\r
-       \r
-       /*\r
-        * Allows for the return of an {@link IWorkbenchAdapter} adapter.\r
-        * \r
-        * @since 3.5\r
-        * \r
-        * @see org.eclipse.core.runtime.PlatformObject#getAdapter(java.lang.Class)\r
-        */\r
-       @SuppressWarnings("rawtypes")\r
-       public Object getAdapter(Class adapter) {\r
-               if (IWorkbenchAdapter.class.equals(adapter)) {\r
-                       return new IWorkbenchAdapter() {\r
-\r
-                               public Object[] getChildren(Object o) {\r
-                                       return new Object[0];\r
-                               }\r
-\r
-                               public ImageDescriptor getImageDescriptor(Object object) {\r
-                                       return GraphFileEditorInput.this.getImageDescriptor();\r
-                               }\r
-\r
-                               public String getLabel(Object o) {\r
-                                       return GraphFileEditorInput.this.getName();\r
-                               }\r
-\r
-                               public Object getParent(Object o) {\r
-                                       return GraphFileEditorInput.this.getFile().getParent();\r
-                               }\r
-                       };\r
-               }\r
-\r
-               return super.getAdapter(adapter);\r
-       }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2013 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.graphfile.hack;
+
+import java.net.URI;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IStorage;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IPathEditorInput;
+import org.eclipse.ui.IPersistableElement;
+import org.eclipse.ui.IURIEditorInput;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.model.IWorkbenchAdapter;
+
+
+/**
+ * Editor input for files stored in the graph.
+ * 
+ * Note: this class is required, since FileEditorInput is not able to load/save GraphFile references.
+ * Contents of this class are mostly copy-pasted from FileEditorInput.
+ * 
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
+ *
+ */
+public class GraphFileEditorInput  extends PlatformObject implements IFileEditorInput, IPathEditorInput, IURIEditorInput,
+ IPersistableElement {
+private GraphFile file;
+       
+
+       /**
+        * Creates an editor input based of the given file resource.
+        *
+        * @param file the file resource
+        */
+       public GraphFileEditorInput(GraphFile file) {
+               if (file == null)
+                       throw new IllegalArgumentException();
+               this.file = file;
+       
+       }
+
+       /* (non-Javadoc)
+        * Method declared on Object.
+        */
+       public int hashCode() {
+               return file.hashCode();
+       }
+
+       /* (non-Javadoc)
+        * Method declared on Object.
+        *
+        * The <code>FileEditorInput</code> implementation of this <code>Object</code>
+        * method bases the equality of two <code>FileEditorInput</code> objects on the
+        * equality of their underlying <code>IFile</code> resources.
+        */
+       public boolean equals(Object obj) {
+               if (this == obj) {
+                       return true;
+               }
+               if (!(obj instanceof IFileEditorInput)) {
+                       return false;
+               }
+               IFileEditorInput other = (IFileEditorInput) obj;
+               return file.equals(other.getFile());
+       }
+
+       /* (non-Javadoc)
+        * Method declared on IEditorInput.
+        */
+       public boolean exists() {
+               return file.exists();
+       }
+
+       /* (non-Javadoc)
+        * Method declared on IPersistableElement.
+        */
+       public String getFactoryId() {
+               return GraphFileEditorInputFactory.getFactoryId();
+       }
+
+       /* (non-Javadoc)
+        * Method declared on IFileEditorInput.
+        */
+       public IFile getFile() {
+               return file;
+       }
+
+       /* (non-Javadoc)
+        * Method declared on IEditorInput.
+        */
+       public ImageDescriptor getImageDescriptor() {
+               IContentType contentType = IDE.getContentType(file);
+               return PlatformUI.getWorkbench().getEditorRegistry()
+                               .getImageDescriptor(file.getName(), contentType);
+       }
+
+       /* (non-Javadoc)
+        * Method declared on IEditorInput.
+        */
+       public String getName() {
+               return file.getName();
+       }
+
+       /* (non-Javadoc)
+        * Method declared on IEditorInput.
+        */
+       public IPersistableElement getPersistable() {
+               return this;
+       }
+
+       /* (non-Javadoc)
+        * Method declared on IStorageEditorInput.
+        */
+       public IStorage getStorage() {
+               return file;
+       }
+
+       /* (non-Javadoc)
+        * Method declared on IEditorInput.
+        */
+       public String getToolTipText() {
+               return file.getFullPath().makeRelative().toString();
+       }
+
+       /* (non-Javadoc)
+        * Method declared on IPersistableElement.
+        */
+       public void saveState(IMemento memento) {
+               GraphFileEditorInputFactory.saveState(memento, this);
+       }
+
+       
+
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.IURIEditorInput#getURI()
+        */
+       public URI getURI() {
+               return file.getLocationURI();
+       }
+       
+       
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.IPathEditorInput#getPath()
+        */
+       public IPath getPath() {
+               IPath location = file.getLocation();
+               if (location != null)
+                       return location;
+
+               throw new IllegalArgumentException();
+       }
+
+
+       /* (non-Javadoc)
+        * @see java.lang.Object#toString()
+        */
+       public String toString() {
+               return getClass().getName() + "(" + getFile().getFullPath() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
+       }
+       
+       /*
+        * Allows for the return of an {@link IWorkbenchAdapter} adapter.
+        * 
+        * @since 3.5
+        * 
+        * @see org.eclipse.core.runtime.PlatformObject#getAdapter(java.lang.Class)
+        */
+       @SuppressWarnings("rawtypes")
+       public Object getAdapter(Class adapter) {
+               if (IWorkbenchAdapter.class.equals(adapter)) {
+                       return new IWorkbenchAdapter() {
+
+                               public Object[] getChildren(Object o) {
+                                       return new Object[0];
+                               }
+
+                               public ImageDescriptor getImageDescriptor(Object object) {
+                                       return GraphFileEditorInput.this.getImageDescriptor();
+                               }
+
+                               public String getLabel(Object o) {
+                                       return GraphFileEditorInput.this.getName();
+                               }
+
+                               public Object getParent(Object o) {
+                                       return GraphFileEditorInput.this.getFile().getParent();
+                               }
+                       };
+               }
+
+               return super.getAdapter(adapter);
+       }
+}