You are viewing a plain text version of this content. The canonical link for it is here.
Posted to kato-commits@incubator.apache.org by sp...@apache.org on 2009/05/13 10:20:55 UTC

svn commit: r774279 [1/2] - in /incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor: ./ .settings/ META-INF/ bin/ icons/ src/ src/org/ src/org/apache/ src/org/apache/kato/ src/org/apache/kato/tools/ src/org/apache/kato/tools/plugins/ src/org/a...

Author: spoole
Date: Wed May 13 10:20:54 2009
New Revision: 774279

URL: http://svn.apache.org/viewvc?rev=774279&view=rev
Log:
initial commit of hex editor plugin contributed by Adam Pilkington

Added:
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/.classpath   (with props)
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/.project   (with props)
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/.settings/
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/.settings/org.eclipse.jdt.core.prefs   (with props)
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/META-INF/
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/META-INF/MANIFEST.MF   (with props)
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/bin/
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/build.properties   (with props)
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/icons/
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/icons/sample.gif   (with props)
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/plugin.xml   (with props)
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/Activator.java   (with props)
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/editors/
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/editors/BinaryHexViewer.java   (with props)
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/editors/FileEditorSelection.java   (with props)
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/editors/MultiPageEditorContributor.java   (with props)
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/eyecatchers/
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/eyecatchers/Eyecatcher.java   (with props)
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/eyecatchers/EyecatcherScanner.java   (with props)
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/popup/
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/popup/actions/
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/popup/actions/NewAction.java   (with props)
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/views/
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/views/BinarySourceProvider.java   (with props)
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/views/BookmarksView.java   (with props)
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/views/EyecatcherView.java   (with props)
    incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/views/RawByteModel.java   (with props)

Added: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/.classpath
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/.classpath?rev=774279&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/.classpath (added)
+++ incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/.classpath Wed May 13 10:20:54 2009
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

Propchange: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/.classpath
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/.project
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/.project?rev=774279&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/.project (added)
+++ incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/.project Wed May 13 10:20:54 2009
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.apache.kato.tools.plugins.hexeditor</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.ManifestBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.SchemaBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.pde.PluginNature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

Propchange: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/.project
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/.settings/org.eclipse.jdt.core.prefs?rev=774279&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/.settings/org.eclipse.jdt.core.prefs (added)
+++ incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/.settings/org.eclipse.jdt.core.prefs Wed May 13 10:20:54 2009
@@ -0,0 +1,7 @@
+#Tue Apr 28 14:27:22 BST 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5

Propchange: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/.settings/org.eclipse.jdt.core.prefs
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/META-INF/MANIFEST.MF?rev=774279&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/META-INF/MANIFEST.MF (added)
+++ incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/META-INF/MANIFEST.MF Wed May 13 10:20:54 2009
@@ -0,0 +1,14 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Kato hex editor plugin
+Bundle-SymbolicName: Kato_Plugins_HexEditor;singleton:=true
+Bundle-Version: 1.0.0
+Bundle-Activator: org.apache.kato.tools.plugins.hexeditor.Activator
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.jface.text,
+ org.eclipse.core.resources,
+ org.eclipse.ui.editors,
+ org.eclipse.ui.ide
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: J2SE-1.5

Propchange: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/META-INF/MANIFEST.MF
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/build.properties
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/build.properties?rev=774279&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/build.properties (added)
+++ incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/build.properties Wed May 13 10:20:54 2009
@@ -0,0 +1,6 @@
+source.. = src/
+output.. = bin/
+bin.includes = plugin.xml,\
+               META-INF/,\
+               .,\
+               icons/,

Propchange: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/build.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/icons/sample.gif
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/icons/sample.gif?rev=774279&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/icons/sample.gif
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/plugin.xml
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/plugin.xml?rev=774279&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/plugin.xml (added)
+++ incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/plugin.xml Wed May 13 10:20:54 2009
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+
+   <extension
+         point="org.eclipse.ui.views">
+      <category
+            name="Apache Kato"
+            id="org.apache.kato.tools">
+      </category>
+      
+      <view
+            name="Bookmarks"
+            icon="icons/sample.gif"
+            category="org.apache.kato.tools"
+            class="org.apache.kato.tools.plugins.hexeditor.views.BookmarksView"
+            id="org.apache.kato.tools.plugins.hexeditor.views.BookmarksView">
+      </view>
+      <view
+            name="Eyecatchers"
+            icon="icons/sample.gif"
+            category="org.apache.kato.tools"
+            class="org.apache.kato.tools.plugins.hexeditor.views.EyecatcherView"
+            id="org.apache.kato.tools.plugins.hexeditor.views.EyecatcherView">
+      </view>
+   </extension>
+   <extension
+         point="org.eclipse.ui.perspectiveExtensions">
+      <perspectiveExtension
+            targetID="org.eclipse.jdt.ui.JavaPerspective">
+         <view
+               ratio="0.5"
+               relative="org.eclipse.ui.views.TaskList"
+               relationship="right"
+               id="org.apache.kato.tools.plugins.hexeditor.views.RawDumpView">
+         </view>
+      </perspectiveExtension>
+   </extension>
+   <extension
+         point="org.eclipse.help.contexts">
+      <contexts
+            file="contexts.xml">
+      </contexts>
+   </extension>
+   <extension
+         point="org.eclipse.ui.editors">
+      <editor
+            class="org.apache.kato.tools.plugins.hexeditor.editors.BinaryHexViewer"
+            contributorClass="org.apache.kato.tools.plugins.hexeditor.editors.MultiPageEditorContributor"
+            icon="icons/sample.gif"
+            id="org.apache.kato.tools.plugins.hexeditor.editors.BinaryHexViewer"
+            name="Binary Hex Viewer">
+      </editor>
+   </extension>
+   <extension
+         point="org.eclipse.ui.commands">
+      <category
+            id="org.apache.kato.plugins.hexeditor.commands"
+            name="Hex Viewer"
+            description="Hex viewer commands" />
+      <command
+            categoryId="org.apache.kato.plugins.hexeditor.commands"
+            id="org.apache.kato.plugins.hexeditor.commands.jumpto"
+            name="Jump to"
+            description="Jump to the specified position in the file" />
+      <command
+            categoryId="org.apache.kato.plugins.hexeditor.commands"
+            id="org.apache.kato.plugins.hexeditor.commands.find"
+            name="Find"
+            description="Find a sequence in the file" />
+   </extension>
+   <extension
+         point="org.eclipse.ui.bindings">
+         <key sequence="Ctrl+J"
+			commandId="org.apache.kato.plugins.hexeditor.commands.jumpto"
+			schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" />
+		<key sequence="Ctrl+Shift+F"
+			commandId="org.apache.kato.plugins.hexeditor.commands.find"
+			schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" />
+   </extension>
+	<extension
+	      point="org.eclipse.ui.services">
+	   <sourceProvider
+	         provider="org.apache.kato.tools.plugins.hexeditor.views.BinarySourceProvider">
+	      <variable
+	            name="org.apache.kato.tools.plugins.hexeditor.views.BinaryData"
+	            priorityLevel="workbench">
+	      </variable>
+	   </sourceProvider>
+	</extension>
+</plugin>

Propchange: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/plugin.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/Activator.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/Activator.java?rev=774279&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/Activator.java (added)
+++ incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/Activator.java Wed May 13 10:20:54 2009
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.tools.plugins.hexeditor;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+	// The plug-in ID
+	public static final String PLUGIN_ID = "Kato_Plugins_HexEditor";
+
+	// The shared instance
+	private static Activator plugin;
+	
+	/**
+	 * The constructor
+	 */
+	public Activator() {
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+	 */
+	public void start(BundleContext context) throws Exception {
+		super.start(context);
+		plugin = this;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+	 */
+	public void stop(BundleContext context) throws Exception {
+		plugin = null;
+		super.stop(context);
+	}
+
+	/**
+	 * Returns the shared instance
+	 *
+	 * @return the shared instance
+	 */
+	public static Activator getDefault() {
+		return plugin;
+	}
+
+	/**
+	 * Returns an image descriptor for the image file at the given
+	 * plug-in relative path
+	 *
+	 * @param path the path
+	 * @return the image descriptor
+	 */
+	public static ImageDescriptor getImageDescriptor(String path) {
+		return imageDescriptorFromPlugin(PLUGIN_ID, path);
+	}
+}

Propchange: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/Activator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/editors/BinaryHexViewer.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/editors/BinaryHexViewer.java?rev=774279&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/editors/BinaryHexViewer.java (added)
+++ incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/editors/BinaryHexViewer.java Wed May 13 10:20:54 2009
@@ -0,0 +1,581 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.tools.plugins.hexeditor.editors;
+
+
+import java.io.File;
+import java.util.ArrayList;
+
+import org.apache.kato.tools.plugins.hexeditor.eyecatchers.Eyecatcher;
+import org.apache.kato.tools.plugins.hexeditor.views.BinarySourceProvider;
+import org.apache.kato.tools.plugins.hexeditor.views.BookmarksView;
+import org.apache.kato.tools.plugins.hexeditor.views.RawByteModel;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.ui.part.MultiPageEditorPart;
+import org.eclipse.ui.services.ISourceProviderService;
+
+
+
+public class BinaryHexViewer  extends MultiPageEditorPart  {
+
+	
+	class NameSorter extends ViewerSorter {
+	}  
+	class ViewContentProvider implements IStructuredContentProvider {
+		private FileEditorSelection[] rows = new FileEditorSelection[pageSize];
+		
+		public ViewContentProvider() {
+			for(int i = 0; i < rows.length; i++) rows[i] = new FileEditorSelection(fileInput.getPath().toString(), new Integer(i));
+		}
+		
+		public void dispose() {
+		}
+		public Object[] getElements(Object parent) {
+			//return new Object[] { new byte[]{1,2},new String[]{"Two","TwoA"},new String[]{"Three","ThreeA"} };
+			return rows;
+		}
+		public void inputChanged(Viewer v, Object oldInput, Object newInput) {
+		}
+	}
+	class ViewLabelProvider extends LabelProvider implements ITableLabelProvider {
+		private int rowCount = 0;
+		private StringBuffer text = new StringBuffer(16);;
+		
+		public Image getColumnImage(Object obj, int index) {
+			//return getImage(obj);
+			return null;
+		}
+		
+		public String getColumnText(Object obj, int index) {
+			long offset = currentPos + (rowCount * 16);
+			long pos = offset + (index - 1);					//index - 1 as the first column is the offset
+			switch (index) {
+				case 0 :
+					if(!model.isInRange(pos)) return "";		//we are reading beyond the end of the available data so show blank lines
+					return "0x" + Long.toHexString(offset)  + " [" + offset + "]";
+				case 17 :
+					rowCount++;
+					String label = text.toString();
+					text = new StringBuffer(16);
+					return label;						//display a partial string if present
+				default :
+					if(!model.isInRange(pos)) return "";		//we are reading beyond the end of the available data so show blank lines
+					int data = 0x00FF & model.getData(pos);
+					if(data > 31) {
+						text.append((char)data);
+					} else {
+						text.append('.');
+					}
+					return Integer.toHexString(data);	
+				}
+		}
+		
+		public Image getImage(Object obj) {
+			return PlatformUI.getWorkbench().
+					getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
+		}
+		public void setRowCount(int value) {
+			rowCount = value;
+		}
+	}
+	private Action actionFind;
+	private Action actionJump;
+	private Action actionBookmark;
+	
+	private Action doubleClickAction;
+	private FileEditorInput fileInput=null;
+	private ViewLabelProvider labelProvider = new ViewLabelProvider();
+	private Composite  mainPanel=null;
+	
+	private RawByteModel model=null;
+	private int pageNum = -1;
+	private int maxPageNum = 0;				//the largest page number in the file
+	private long currentPos = -1;			//current position being displayed on the screen
+	private long maxPos = -1;				//the largest position to be displayed
+	private ArrayList<CellLocation> cells = new ArrayList<CellLocation>();
+
+
+	private final int pageSize = 40;
+		
+	 private ISelectionListener selectListener = null;
+
+	TableViewer viewer=null;
+
+	private void addMainPage() {
+		
+		
+		
+		Composite parent=getContainer();
+		
+		viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL);
+		
+		//configure the table first as this will set the number of columns. 
+		//If you set the provider first then the column count is not updated in the providers
+		configureTable();
+		configureProviders();
+		// Create the help context id for the viewer's control
+		PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), "org.apache.kato.tools.plugins.hexeditor.viewer");
+
+		makeActions();
+		hookDoubleClickAction();
+		hookContextMenu();
+		contributeToActionBars();
+		hookPageSelection();
+		addPage(viewer.getControl());
+	}
+	
+	private void hookContextMenu() {
+		MenuManager menuMgr = new MenuManager("#PopupMenu");
+		menuMgr.setRemoveAllWhenShown(true);
+		menuMgr.addMenuListener(new IMenuListener() {
+			public void menuAboutToShow(IMenuManager manager) {
+				fillContextMenu(manager);
+			}
+		});
+		Menu menu = menuMgr.createContextMenu(viewer.getControl());
+		viewer.getControl().setMenu(menu);
+		getSite().registerContextMenu(menuMgr, viewer);
+	}
+	private void fillLocalPullDown(IMenuManager manager) {
+		manager.add(new Separator());
+	
+	}
+
+	private void fillContextMenu(IMenuManager manager) {
+		manager.add(actionJump);
+		manager.add(actionFind);
+		manager.add(actionBookmark);
+		// Other plug-ins can contribute there actions here
+		manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
+	}
+	
+	private void fillLocalToolBar(IToolBarManager manager) {
+		manager.add(actionJump);
+		manager.add(actionFind);
+		
+	}
+	private void contributeToActionBars() {
+		IActionBars bars = getEditorSite().getActionBars();
+
+		fillLocalPullDown(bars.getMenuManager());
+		fillLocalToolBar(bars.getToolBarManager());
+	}
+	
+	private void configureProviders() {
+		viewer.setContentProvider(new ViewContentProvider());
+		viewer.setLabelProvider(labelProvider);
+		viewer.setSorter(new NameSorter());
+		getSite().setSelectionProvider(viewer);			//allow this editor to be used for things like bookmarks
+		updateDisplay(0);
+	}
+	
+	private void configureTable() {
+		Table table= viewer.getTable();
+		Font font = new Font(null, "Courier", 10, SWT.NORMAL); 
+		table.setFont(font);
+		table.setHeaderVisible(true);
+		table.setLinesVisible(true);
+		TableColumn column = new TableColumn(table, SWT.LEFT);
+		column.setText("Offset");
+		column.setWidth(200);
+		for(int i = 0; i < 0x10; i++) {
+			column = new TableColumn(table, SWT.LEFT);
+			column.setText(Integer.toHexString(i));
+			column.setWidth(50);
+		}
+		column = new TableColumn(table, SWT.LEFT);
+		column.setText("Text");
+		column.setWidth(200);
+	}
+
+	private void createDoubleClick() {
+		doubleClickAction = new Action() {
+			public void run() {
+				ISelection selection = viewer.getSelection();
+				Object obj = ((IStructuredSelection)selection).getFirstElement();
+				showMessage("Double-click detected on "+obj.toString());
+			}
+		};		
+	}
+
+	private void createFindButton() {
+		actionFind = new Action() {
+			public void run() {
+				InputDialog entry = new InputDialog(viewer.getControl().getShell(), "Find", "Search for a byte sequence", null, null);
+				entry.open();
+				if(entry.getReturnCode() == IDialogConstants.OK_ID) {
+					findBytes(entry.getValue());
+				}
+			}
+		};
+		actionFind.setActionDefinitionId("org.apache.kato.plugins.hexeditor.commands.find");		
+		getSite().getKeyBindingService().registerAction(actionFind);
+		actionFind.setText("find");
+		actionFind.setToolTipText("Search for a byte sequence");
+		actionFind.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
+				getImageDescriptor(ISharedImages.IMG_OPEN_MARKER));
+	}
+
+	private void createJumpButton() {
+		actionJump = new Action() {
+			public void run() {
+				InputDialog entry = new InputDialog(getSite().getShell(), "Jump", "Enter address to jump to", null, null);
+				entry.open();
+				if(entry.getReturnCode() == IDialogConstants.OK_ID) {
+					jumpToAddress(entry.getValue());
+				}
+			}
+		};
+		actionJump.setActionDefinitionId("org.apache.kato.plugins.hexeditor.commands.jumpto");		
+		getSite().getKeyBindingService().registerAction(actionJump);
+		actionJump.setText("Jump");
+		actionJump.setToolTipText("Jump to an address");
+		actionJump.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
+				getImageDescriptor(ISharedImages.IMG_OBJS_BKMRK_TSK));
+	}
+	
+	private void createBookmarkButton() {
+		actionBookmark = new Action() {
+			public void run() {
+				try {
+					PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("org.apache.kato.tools.plugins.hexeditor.views.BookmarksView");
+					int index = viewer.getTable().getSelectionIndex();
+					if (index == -1) {
+						showMessage("You must select a column on the left hand side first");
+					}
+					String description = viewer.getTable().getItem(index).getText(0);
+					String address = description.substring(0, description.indexOf(' '));
+					InputDialog entry = new InputDialog(getSite().getShell(), "Bookmark", "Enter description for " + address, null, null);
+					if(entry.open() == IDialogConstants.OK_ID) {
+						BookmarksView bmv = BookmarksView.getInstance();
+						bmv.addBookmark(address, entry.getValue());
+					}
+					
+				} catch (PartInitException e) {
+					e.printStackTrace();
+					showMessage(e.getMessage());
+				}
+			}
+		};
+		actionBookmark.setText("Bookmark");
+		actionBookmark.setToolTipText("Bookmark this address");
+		actionBookmark.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
+				getImageDescriptor(ISharedImages.IMG_OBJS_BKMRK_TSK));
+	}
+	
+	@Override
+	protected void createPages() {
+		
+		addMainPage();
+		
+		 getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(new ISelectionListener(){
+
+			public void selectionChanged(IWorkbenchPart part,
+					ISelection s) {
+				if(s instanceof IStructuredSelection) {
+					IStructuredSelection ss=(IStructuredSelection) s;
+					Object o=ss.getFirstElement();
+					if(o==null) return;
+					Long address=null;
+					if(o instanceof IAdaptable) {
+						IAdaptable a=(IAdaptable) o;
+						address=(Long) a.getAdapter(Long.class);
+						if(address==null) return;
+					}
+					else if(o instanceof Long) {
+						address=(Long) o;
+					}
+					
+					if(address!=null) {
+						updateDisplay(address);
+					}
+				}
+				
+				
+			}});
+		
+		
+		
+	}
+	
+	@Override
+	public void dispose() {
+		
+		super.dispose();
+	}
+	
+	@Override
+	public void doSave(IProgressMonitor monitor) {
+		// nothing to do
+		
+	}
+	
+	@Override
+	public void doSaveAs() {
+		// nothing to do
+		
+	}
+	
+	private void findBytes(String searchFor) {
+		long result = model.findData(searchFor);
+		if(result == -1) {
+			showMessage("Could not find " + searchFor);
+		} else {
+			updateDisplay(result);
+			setEyecatchers(new Color(null, 255, 255, 128));
+		}
+	}
+	
+	private void hookDoubleClickAction() {
+		viewer.addDoubleClickListener(new IDoubleClickListener() {
+			public void doubleClick(DoubleClickEvent event) {
+				doubleClickAction.run();
+			}
+		});
+	}
+	
+	private void hookPageSelection() {
+		selectListener = new ISelectionListener() {
+			public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+				pageSelectionChanged(part, selection);
+			}
+		};
+		getSite().getPage().addPostSelectionListener(selectListener);
+	}
+	
+	public void init(IEditorSite site, IEditorInput input)
+     throws PartInitException {
+		 
+		 if(input instanceof FileEditorInput) {
+			 fileInput=(FileEditorInput) input;
+			IPath fileLocation=fileInput.getPath();
+			File file=fileLocation.toFile();
+			 openDumpFile(file.getAbsolutePath());
+			 setTitle(file.getName());
+			 maxPageNum = (int)(file.length() / pageSize);
+			 maxPos = file.length();
+			 		 }
+		 
+		 else {	 
+			 throw new PartInitException(
+             "Invalid Input: Must be FileEditorInput  not "+input); 
+		 }
+		 
+		
+		 super.init(site, input);
+		 
+}
+
+	@Override
+	public boolean isDirty() {
+		
+		return false;
+	}
+	@Override
+	public boolean isSaveAsAllowed() {
+	
+		return false;
+	}
+	private void jumpToAddress(String address) {
+		long jumpto = 0;
+		if (address.startsWith("0x")) {
+			jumpto = Long.parseLong(address.substring(2), 16);
+		} else {
+			jumpto = Long.parseLong(address);
+		}
+		updateDisplay(jumpto);
+		
+	}
+	
+//	private void jumpToAddress(long jumpto) {
+//		pageNum = (int)(jumpto / pageSize);
+//		
+//		updateDisplay();
+//	}
+	
+	private void makeActions() {
+		
+		createDoubleClick();
+		createJumpButton();
+		createFindButton();
+		createBookmarkButton();
+		
+	}
+
+	private void openDumpFile(String path) {
+		if(model != null) {
+			model.dispose();
+		}
+		model = new RawByteModel(path);
+		//updateDisplay();
+	}
+
+	protected void pageSelectionChanged(IWorkbenchPart part, ISelection selection) {
+		if(part == this) return;		//do not process myself
+		if(!(selection instanceof IStructuredSelection)) return;
+		IStructuredSelection iss = (IStructuredSelection) selection;
+		jumpToAddress((String)iss.getFirstElement());
+	}
+
+	@Override
+	public void setFocus() {
+		if(mainPanel!=null) mainPanel.setFocus();
+		
+	}
+	private void showMessage(String message) {
+		MessageDialog.openInformation(
+			viewer.getControl().getShell(),
+			"Raw Dump View",
+			message);
+	}
+	private void updateDisplay(long jumpto) {
+		if(jumpto > maxPos) {				//check that we can display the requested location
+			showMessage("The requested position " + jumpto + " is beyond the end of the file");
+			return;
+		}
+		clearEyecatchers();
+		currentPos = jumpto;
+		labelProvider.setRowCount(0);		//reset the row count
+		viewer.setInput(model);
+		viewer.getTable().setSelection(0);
+		viewer.setSelection(new ISelection() {
+			public boolean isEmpty() {
+				return false;
+			}
+		});
+		viewer.getTable().showSelection();
+		signalSourceChange();
+	}
+	
+	private void signalSourceChange() {
+		ISourceProviderService service = (ISourceProviderService)getSite().getWorkbenchWindow().getService(ISourceProviderService.class);
+		BinarySourceProvider bsp = (BinarySourceProvider)service.getSourceProvider("org.apache.kato.tools.plugins.hexeditor.views.BinarySourceProvider");
+		if(bsp == null) {
+			System.err.println("HexViewer : Could not get BSP");
+			return;
+		}
+		bsp.sourceChanged(1, "test", "new value");
+	}
+	
+	/**
+	 * Clear any eye catchers that have been set
+	 */
+	private void clearEyecatchers() {
+		if(cells.size() > 0) {
+			Color white = new Color(null, 255, 255, 255);
+			for(int i = 0; i < cells.size(); i++) {
+				CellLocation location = cells.get(i);
+				location.setColour(white);
+				location.apply();
+			}
+			cells.removeAll(cells);
+		}
+	}
+	
+	private void setEyecatchers(Color colour) {
+		Table table = viewer.getTable();
+		Eyecatcher eye = model.getEyecatcher();
+		for(int i = 0; i < (eye.getText().length() / 2); i++) {
+			long row = (eye.getLocation() + i) / 16;
+			long index = ((eye.getLocation() + i) % 16) + 1;				//+1 to skip offset column at the start
+			TableItem item = table.getItem((int)row);
+			CellLocation location = new CellLocation(item, (int)index, colour);
+			location.apply();
+			cells.add(location);
+		}
+	}
+	
+	private class CellLocation {
+		private TableItem item = null;
+		private int index = 0;
+		private Color colour = null;
+		
+		public CellLocation(TableItem item, int index, Color colour) {
+			super();
+			this.item = item;
+			this.index = index;
+			this.colour = colour;
+		}
+
+		public TableItem getItem() {
+			return item;
+		}
+
+		public void setItem(TableItem item) {
+			this.item = item;
+		}
+
+		public int getIndex() {
+			return index;
+		}
+
+		public void setIndex(int index) {
+			this.index = index;
+		}
+
+		public Color getColour() {
+			return colour;
+		}
+
+		public void setColour(Color colour) {
+			this.colour = colour;
+		}
+		
+		//apply the settings to the cell background
+		public void apply() {
+			item.setBackground(index, colour);
+		}
+		
+	}
+}

Propchange: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/editors/BinaryHexViewer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/editors/FileEditorSelection.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/editors/FileEditorSelection.java?rev=774279&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/editors/FileEditorSelection.java (added)
+++ incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/editors/FileEditorSelection.java Wed May 13 10:20:54 2009
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.tools.plugins.hexeditor.editors;
+
+//class to represent the current selection in a file based editor 
+public class FileEditorSelection {
+	private String path = null;
+	private Object data = null;
+	
+	public FileEditorSelection(String path, Object data) {
+		super();
+		this.path = path;
+		this.data = data;
+	}
+	
+	public String getPath() {
+		return path;
+	}
+	
+	public void setPath(String path) {
+		this.path = path;
+	}
+	
+	public Object getData() {
+		return data;
+	}
+	
+	public void setData(Object data) {
+		this.data = data;
+	}
+
+	@Override
+	public String toString() {
+		return "File : " + path + "\nData : " + data.toString();
+	}
+	
+	
+}

Propchange: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/editors/FileEditorSelection.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/editors/MultiPageEditorContributor.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/editors/MultiPageEditorContributor.java?rev=774279&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/editors/MultiPageEditorContributor.java (added)
+++ incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/editors/MultiPageEditorContributor.java Wed May 13 10:20:54 2009
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.tools.plugins.hexeditor.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 MultiPageEditorContributor extends MultiPageEditorActionBarContributor {
+	private IEditorPart activeEditorPart;
+	private Action sampleAction;
+	/**
+	 * Creates a multi-page contributor.
+	 */
+	public MultiPageEditorContributor() {
+		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, "Kato Plug-in", "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);
+	}
+}

Propchange: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/editors/MultiPageEditorContributor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/eyecatchers/Eyecatcher.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/eyecatchers/Eyecatcher.java?rev=774279&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/eyecatchers/Eyecatcher.java (added)
+++ incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/eyecatchers/Eyecatcher.java Wed May 13 10:20:54 2009
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.tools.plugins.hexeditor.eyecatchers;
+
+public class Eyecatcher {
+	private long location = 0;
+	private String text = null;
+
+	public Eyecatcher() {
+		//default constructor
+	}
+	
+	public Eyecatcher(String text) {
+		this.text = text;
+	}
+	
+	public long getLocation() {
+		return location;
+	}
+	
+	public void setLocation(long location) {
+		this.location = location;
+	}
+	
+	public String getText() {
+		return text;
+	}
+	
+	public void setText(String text) {
+		this.text = text;
+	}
+	
+	public Eyecatcher(long location, String text) {
+		super();
+		this.location = location;
+		this.text = text;
+	}
+}

Propchange: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/eyecatchers/Eyecatcher.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/eyecatchers/EyecatcherScanner.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/eyecatchers/EyecatcherScanner.java?rev=774279&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/eyecatchers/EyecatcherScanner.java (added)
+++ incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/eyecatchers/EyecatcherScanner.java Wed May 13 10:20:54 2009
@@ -0,0 +1,110 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.tools.plugins.hexeditor.eyecatchers;
+//scans a given set of bytes for known eyecatchers
+public class EyecatcherScanner {
+	private static final int STATE_SCANNING = 1;
+	private static final int STATE_MATCHING = 2;
+	private static final int STATE_MATCHED = 3;
+	
+	private int state = STATE_SCANNING;
+	private int index = -1;				//index of any matched eye catcher
+	private int location = -1;			//location within search bytes
+	private Eyecatcher eyecatcher = null;
+
+	private String[] eyecatchers = new String[]{"C4D9F240"};
+	
+	//returns true if an eyecatcher was found
+	public boolean scan(byte[] bytes) {
+		for(int i = 0; i < eyecatchers.length; i++) {
+			byte[] searchfor = stringToBytes(eyecatchers[i]);
+			startScanning(searchfor, bytes);
+			if(state == STATE_MATCHED) {
+				index = 1;
+				eyecatcher = new Eyecatcher(location, eyecatchers[i]);
+				return true;
+			}
+		}
+		reset();		//remove any currently set eyecatcher
+		return false;
+	}
+	
+	//returns true if an eyecatcher was found
+	public boolean scan(byte[] bytes, String searchFor) {
+		byte[] searchfor = stringToBytes(searchFor);
+		startScanning(searchfor, bytes);
+		if(state == STATE_MATCHED) {
+			index = 1;
+			eyecatcher = new Eyecatcher(location, searchFor);
+			return true;
+		}
+		reset();		//remove any currently set eyecatcher
+		return false;
+	}
+	
+	//convert a hex string into a byte array equivalent
+	private byte[] stringToBytes(String hex) {
+		byte[] bytes= new byte[hex.length() / 2];
+		for(int i = 0, j = 0; i < hex.length(); i+=2, j++) {
+			int data = Integer.parseInt(hex.substring(i, i+2), 16);
+			bytes[j] = (byte)data;
+		}
+		return bytes;
+	}
+	
+	public void reset() {
+		eyecatcher = null;
+	}
+	
+	public boolean hasEyecatcher() {
+		return (eyecatcher != null);
+	}
+	
+	public Eyecatcher getEyecatcher() {
+		return eyecatcher;
+	}
+	
+	private void startScanning(byte[] searchfor, byte[] bytes) {
+		state = STATE_SCANNING;
+		int marker = 0;
+		for(int i = 0; i < bytes.length; i++) {
+			switch (state) {
+				case STATE_SCANNING :
+					if(bytes[i] == searchfor[0]) {
+						if(searchfor.length == 1) {			//only searching for a single byte
+							state = STATE_MATCHED;
+							location = i;
+							return;
+						}
+						marker = 1;
+						state = STATE_MATCHING;
+					}
+					break;
+				case STATE_MATCHING :
+					if(searchfor[marker] == bytes[i]) {
+						marker++;
+						if(marker == searchfor.length) {
+							state = STATE_MATCHED;
+						}
+					} else {			//no match
+						state = STATE_SCANNING;
+					}
+					break;
+				case STATE_MATCHED :
+					location = i - searchfor.length;
+					return;
+			}
+		}
+	}
+}

Propchange: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/eyecatchers/EyecatcherScanner.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/popup/actions/NewAction.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/popup/actions/NewAction.java?rev=774279&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/popup/actions/NewAction.java (added)
+++ incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/popup/actions/NewAction.java Wed May 13 10:20:54 2009
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.tools.plugins.hexeditor.popup.actions;
+
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+
+public class NewAction implements IObjectActionDelegate {
+
+	private Shell shell;
+	
+	/**
+	 * Constructor for Action1.
+	 */
+	public NewAction() {
+		super();
+	}
+
+	/**
+	 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
+	 */
+	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+		shell = targetPart.getSite().getShell();
+	}
+
+	/**
+	 * @see IActionDelegate#run(IAction)
+	 */
+	public void run(IAction action) {
+		MessageDialog.openInformation(
+			shell,
+			"Kato Plug-in",
+			"New Action was executed.");
+	}
+
+	/**
+	 * @see IActionDelegate#selectionChanged(IAction, ISelection)
+	 */
+	public void selectionChanged(IAction action, ISelection selection) {
+	}
+
+}

Propchange: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/popup/actions/NewAction.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/views/BinarySourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/views/BinarySourceProvider.java?rev=774279&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/views/BinarySourceProvider.java (added)
+++ incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/views/BinarySourceProvider.java Wed May 13 10:20:54 2009
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.tools.plugins.hexeditor.views;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.ui.AbstractSourceProvider;
+import org.eclipse.ui.services.IServiceLocator;
+
+public class BinarySourceProvider extends AbstractSourceProvider {
+	private HashMap<String, String> state = new HashMap<String, String>();
+	
+	public void dispose() {
+		System.err.println("Disposed of source provider");
+	}
+
+	public Map getCurrentState() {
+		return state;
+	}
+
+	public String[] getProvidedSourceNames() {
+		return new String[] {"org.apache.kato.tools.plugins.hexeditor.BinarySourceProvider"};
+	}
+
+	@Override
+	public void initialize(IServiceLocator locator) {
+		super.initialize(locator);
+		state.put("org.apache.kato.tools.plugins.hexeditor.views.BinaryData", "unused");
+		System.err.println("Initialised the service");
+	}
+
+	public void sourceChanged(int sourcePriority, String sourceName, Object sourceValue) {
+		fireSourceChanged(sourcePriority, sourceName, sourceValue);
+	}
+	
+}

Propchange: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/views/BinarySourceProvider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/views/BookmarksView.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/views/BookmarksView.java?rev=774279&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/views/BookmarksView.java (added)
+++ incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/views/BookmarksView.java Wed May 13 10:20:54 2009
@@ -0,0 +1,393 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.tools.plugins.hexeditor.views;
+
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.Properties;
+
+import org.apache.kato.tools.plugins.hexeditor.editors.FileEditorSelection;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.ViewPart;
+
+import org.apache.kato.tools.plugins.hexeditor.Activator;
+
+
+/**
+ * This sample class demonstrates how to plug-in a new
+ * workbench view. The view shows data obtained from the
+ * model. The sample creates a dummy model on the fly,
+ * but a real implementation would connect to the model
+ * available either in this or another plug-in (e.g. the workspace).
+ * The view is connected to the model using a content provider.
+ * <p>
+ * The view uses a label provider to define how model
+ * objects should be presented in the view. Each
+ * view can present the same model objects using
+ * different labels and icons, if needed. Alternatively,
+ * a single label provider can be shared between views
+ * in order to ensure that objects of the same type are
+ * presented in the same way everywhere.
+ * <p>
+ */
+
+public class BookmarksView extends ViewPart {
+	private TableViewer viewer;
+	private Action actionAdd;
+	private Action actionDelete;
+	private Action doubleClickAction;
+	private Properties model = null;
+	private ViewContentProvider contentProvider = new ViewContentProvider();
+	private ISelectionListener selectListener = null;
+	private static BookmarksView instance = null;
+	private MessageDigest md5 = null;
+	private String id = null;
+	private boolean isDirty = false;
+	
+
+	public static BookmarksView getInstance() {
+		return instance;
+	}
+	
+	/*
+	 * The content provider class is responsible for
+	 * providing objects to the view. It can wrap
+	 * existing objects in adapters or simply return
+	 * objects as-is. These objects may be sensitive
+	 * to the current input of the view, or ignore
+	 * it and always show the same content 
+	 * (like Task List, for example).
+	 */
+	 
+	class ViewContentProvider implements IStructuredContentProvider {
+	
+		public void inputChanged(Viewer v, Object oldInput, Object newInput) {
+		}
+		public void dispose() {
+		}
+		public Object[] getElements(Object parent) {
+			return model.keySet().toArray();
+		}
+		
+		public void addBookmark(TableViewer viewer, String id, String description) {
+			model.put(id, description);
+			viewer.add(id);
+		}
+	}
+	class ViewLabelProvider extends LabelProvider implements ITableLabelProvider {
+		
+		public String getColumnText(Object obj, int index) {
+			String key = (String) obj;
+			switch (index) {
+				case 0 :
+					return key;
+				default :
+					return model.getProperty((String)obj);
+			}
+		}
+		
+		public Image getColumnImage(Object obj, int index) {
+			//return getImage(obj);
+			return null;
+		}
+		public Image getImage(Object obj) {
+			return PlatformUI.getWorkbench().
+					getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
+		}
+	}
+	class NameSorter extends ViewerSorter {
+	}
+
+	/**
+	 * The constructor.
+	 */
+	public BookmarksView() {
+		instance = this;
+		try {
+			md5 = MessageDigest.getInstance("MD5");
+		} catch (NoSuchAlgorithmException e) {
+			throw new RuntimeException("Error creating MD5", e);
+		}
+	}
+
+	private void loadData(String id) {
+		try {
+			//File file = new File(baseConfig + id + ".properties");
+			File file = Activator.getDefault().getStateLocation().append(id + ".properties").toFile();
+			model = new Properties();
+			if(file.exists()) {
+				FileInputStream fis = new FileInputStream(file);
+				model.load(fis);
+			}
+			this.id = id;
+		} catch (FileNotFoundException e) {
+			//this is not an error and also should not be thrown as we check for the existance of the file beforehand
+		} catch (IOException e) {
+			throw new RuntimeException("Error reading bookmarks file", e);
+		} 	
+	}
+	
+	public void addBookmark(String id, String description) {
+		contentProvider.addBookmark(viewer, id, description);
+		isDirty = true;
+	}
+	
+	/**
+	 * This is a callback that will allow us
+	 * to create the viewer and initialize it.
+	 */
+	public void createPartControl(Composite parent) {
+		viewer = new TableViewer(parent, SWT.FULL_SELECTION | SWT.SINGLE);
+		//configure the table first as this will set the number of columns. 
+		//If you set the provider first then the column count is not updated in the providers
+		configureTable();
+		configureProviders();
+		// Create the help context id for the viewer's control
+		PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), "org.apache.kato.tools.plugins.hexeditor.viewer");
+		makeActions();
+		hookContextMenu();
+		hookDoubleClickAction();
+		contributeToActionBars();
+		hookPageSelection();
+	}
+
+	@Override
+	public void dispose() {
+		super.dispose();
+	}
+
+	private void configureProviders() {
+		viewer.setContentProvider(contentProvider);
+		viewer.setLabelProvider(new ViewLabelProvider());
+		viewer.setSorter(new NameSorter());
+		viewer.setInput(model);
+		getSite().setSelectionProvider(viewer);
+	}
+	
+	private void configureTable() {
+		Table table = viewer.getTable();
+		table.setHeaderVisible(true);
+		table.setLinesVisible(true);
+		TableColumn column = new TableColumn(table, SWT.LEFT);
+		column.setText("Position");
+		column.setWidth(100);
+		column = new TableColumn(table, SWT.LEFT);
+		column.setText("Notes");
+		column.setWidth(200);
+	}
+	
+	private void hookContextMenu() {
+		MenuManager menuMgr = new MenuManager("#PopupMenu");
+		menuMgr.setRemoveAllWhenShown(true);
+		menuMgr.addMenuListener(new IMenuListener() {
+			public void menuAboutToShow(IMenuManager manager) {
+				BookmarksView.this.fillContextMenu(manager);
+			}
+		});
+		Menu menu = menuMgr.createContextMenu(viewer.getControl());
+		viewer.getControl().setMenu(menu);
+		getSite().registerContextMenu(menuMgr, viewer);
+	}
+
+	private void hookPageSelection() {
+		selectListener = new ISelectionListener() {
+			public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+				pageSelectionChanged(part, selection);
+			}
+		};
+		getSite().getPage().addPostSelectionListener(selectListener);
+	}
+	
+	protected void pageSelectionChanged(IWorkbenchPart part, ISelection selection) {
+		if(part == this) return;		//do not process myself
+		if(!(selection instanceof IStructuredSelection)) return;
+		IStructuredSelection iss = (IStructuredSelection) selection;
+		if(iss.getFirstElement() instanceof FileEditorSelection) {
+			updateBookmarks((FileEditorSelection)iss.getFirstElement());
+			//this.getSite().getWorkbenchWindow().getWorkbench().getViewRegistry().find(arg0)
+		}
+	}
+	
+	private void updateBookmarks(FileEditorSelection selection) {
+		byte[] fingerprint = md5.digest(selection.getPath().getBytes());
+		StringBuffer data = new StringBuffer();
+		for(int i = 0; i < fingerprint.length; i++) {
+			data.append(Integer.toHexString(fingerprint[i] & 0xff));
+		}
+		String newID = data.toString();
+		if((newID.equalsIgnoreCase(id)) && (!isDirty)) return;				//we haven't changed files
+		if((id != null) || isDirty) saveBookmarks(id);	//need to save existing bookmarks if changing or these ones have been altered
+		id = newID;
+		loadData(id);						//load the currently selected file bookmarks
+		viewer.setInput(model);				//display the new bookmarks for this file
+	}
+	
+	private void saveBookmarks(String id) {
+		if((id == null) || !isDirty) return;
+		try {
+			File file = Activator.getDefault().getStateLocation().append(id + ".properties").toFile();
+			if(file.exists()) file.delete();
+			FileOutputStream out = new FileOutputStream(file);
+			model.store(out, "Updated file");
+			isDirty = false;
+		} catch (Exception e) {
+			showMessage("Error saving file " + e.getMessage());
+			e.printStackTrace();
+		}
+	}
+	
+	
+	
+	@Override
+	public void saveState(IMemento memento) {
+		super.saveState(memento);
+		saveBookmarks(id);
+	}
+
+	private void contributeToActionBars() {
+		IActionBars bars = getViewSite().getActionBars();
+		fillLocalPullDown(bars.getMenuManager());
+		fillLocalToolBar(bars.getToolBarManager());
+	}
+
+	private void fillLocalPullDown(IMenuManager manager) {
+		manager.add(actionAdd);
+		manager.add(new Separator());
+		manager.add(actionDelete);
+	}
+
+	private void fillContextMenu(IMenuManager manager) {
+		manager.add(actionAdd);
+		manager.add(actionDelete);
+		// Other plug-ins can contribute there actions here
+		manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
+	}
+	
+	private void fillLocalToolBar(IToolBarManager manager) {
+		manager.add(actionAdd);
+		manager.add(actionDelete);
+	}
+
+	private void makeActions() {
+		actionAdd = new Action() {
+			public void run() {
+				String id = null;
+				String description = null;
+				InputDialog entry = new InputDialog(getSite().getShell(), "New Bookmark", "Enter address to bookmark", null, null);
+				if(entry.open() != SWT.CANCEL) {
+					id = entry.getValue();
+					entry = new InputDialog(getSite().getShell(), "New Bookmark", "Enter description", null, null);
+					if(entry.open() != SWT.CANCEL) {
+						description = entry.getValue();
+						contentProvider.addBookmark(viewer, id, description);
+					}
+				}
+			}
+		};
+		actionAdd.setText("Add");
+		actionAdd.setToolTipText("Add a new bookmark");
+		actionAdd.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
+			getImageDescriptor(ISharedImages.IMG_OBJ_ADD));
+		
+		actionDelete = new Action() {
+			public void run() {
+				deleteBookmark();
+			}
+		};
+		actionDelete.setText("Delete");
+		actionDelete.setToolTipText("Delete the currently selected bookmark");
+		actionDelete.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
+				getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));
+		doubleClickAction = new Action() {
+			public void run() {
+				ISelection selection = viewer.getSelection();
+				Object obj = ((IStructuredSelection)selection).getFirstElement();
+				showMessage("Double-click detected on "+obj.toString());
+			}
+		};
+	}
+	
+	private void deleteBookmark() {
+		int[] selected = viewer.getTable().getSelectionIndices();
+		Table table = viewer.getTable();
+		
+		if(selected.length == 0) {
+			showMessage("You must select at least one bookmark to delete");
+		} else {
+			for(int i = 0; i < selected.length; i++) {					//remove the selected bookmarks from the underlying model
+				String key = table.getItem(selected[i]).getText(0);
+				model.remove(key);
+			}
+			table.remove(selected);
+			isDirty = true;
+		}
+	}
+	
+	private void hookDoubleClickAction() {
+		viewer.addDoubleClickListener(new IDoubleClickListener() {
+			public void doubleClick(DoubleClickEvent event) {
+				doubleClickAction.run();
+			}
+		});
+	}
+	private void showMessage(String message) {
+		MessageDialog.openInformation(
+			viewer.getControl().getShell(),
+			"Bookmarks",
+			message);
+	}
+
+	/**
+	 * Passing the focus request to the viewer's control.
+	 */
+	public void setFocus() {
+		viewer.getControl().setFocus();
+	}
+}
\ No newline at end of file

Propchange: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/views/BookmarksView.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/views/EyecatcherView.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/views/EyecatcherView.java?rev=774279&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/views/EyecatcherView.java (added)
+++ incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/views/EyecatcherView.java Wed May 13 10:20:54 2009
@@ -0,0 +1,413 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.kato.tools.plugins.hexeditor.views;
+
+//view showing all the known eyecatchers
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.kato.tools.plugins.hexeditor.Activator;
+import org.apache.kato.tools.plugins.hexeditor.editors.FileEditorSelection;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IPartListener;
+import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.ISourceProviderListener;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.ViewPart;
+import org.eclipse.ui.services.ISourceProviderService;
+
+
+/**
+ * This sample class demonstrates how to plug-in a new
+ * workbench view. The view shows data obtained from the
+ * model. The sample creates a dummy model on the fly,
+ * but a real implementation would connect to the model
+ * available either in this or another plug-in (e.g. the workspace).
+ * The view is connected to the model using a content provider.
+ * <p>
+ * The view uses a label provider to define how model
+ * objects should be presented in the view. Each
+ * view can present the same model objects using
+ * different labels and icons, if needed. Alternatively,
+ * a single label provider can be shared between views
+ * in order to ensure that objects of the same type are
+ * presented in the same way everywhere.
+ * <p>
+ */
+
+public class EyecatcherView extends ViewPart {
+	private TableViewer viewer;
+	private Action actionAdd;
+	private Action actionDelete;
+	private Action doubleClickAction;
+	private Properties model = new Properties();
+	private File currentFile = null;
+	private ViewContentProvider contentProvider = new ViewContentProvider();
+	private boolean isDirty = false;
+	private ISelectionListener selectListener = null;
+	private IPartListener partListerner = null;
+	
+
+	/*
+	 * The content provider class is responsible for
+	 * providing objects to the view. It can wrap
+	 * existing objects in adapters or simply return
+	 * objects as-is. These objects may be sensitive
+	 * to the current input of the view, or ignore
+	 * it and always show the same content 
+	 * (like Task List, for example).
+	 */
+	 
+	class ViewContentProvider implements IStructuredContentProvider {
+	
+		public void inputChanged(Viewer v, Object oldInput, Object newInput) {
+		}
+		public void dispose() {
+		}
+		public Object[] getElements(Object parent) {
+			return model.keySet().toArray();
+		}
+		
+		public void addEyecatcher(TableViewer viewer, String id, String description) {
+			model.put(id, description);
+			viewer.add(id);
+		}
+	}
+	class ViewLabelProvider extends LabelProvider implements ITableLabelProvider {
+		
+		public String getColumnText(Object obj, int index) {
+			String key = (String) obj;
+			switch (index) {
+				case 0 :
+					return key;
+				default :
+					return model.getProperty((String)obj);
+			}
+		}
+		
+		public Image getColumnImage(Object obj, int index) {
+			//return getImage(obj);
+			return null;
+		}
+		public Image getImage(Object obj) {
+			return PlatformUI.getWorkbench().
+					getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
+		}
+	}
+	class NameSorter extends ViewerSorter {
+	}
+
+	private void loadData(String name) {
+		try {
+			if (name == null) {		//prompt if a null name is supplied
+				FileDialog dialog = new FileDialog(getSite().getShell(), SWT.OPEN);
+				   dialog.setFilterExtensions(new String [] {"*.*"});
+				   dialog.setFilterPath(Activator.getDefault().getStateLocation().toString());
+				   name = dialog.open();
+				   if (name == null) return;		//user cancelled the operation
+				   currentFile = new File(dialog.getFileName());
+			} else {
+				currentFile = Activator.getDefault().getStateLocation().append(name).toFile();
+			}
+			if(currentFile.exists()) {
+				model = new Properties();
+				FileInputStream fis = new FileInputStream(currentFile);
+				model.load(fis);
+			}
+		} catch (FileNotFoundException e) {
+			//this is not an error and also should not be thrown as we check for the existance of the file beforehand
+		} catch (IOException e) {
+			throw new RuntimeException("Error reading bookmarks file", e);
+		} 	
+	}
+	
+	public void addEyecatcher(String id, String description) {
+		contentProvider.addEyecatcher(viewer, id, description);
+		isDirty = true;
+	}
+	
+	/**
+	 * The constructor.
+	 */
+	public EyecatcherView() {
+		loadData("eyecatchers.properties");			//default eyecatcher file
+	}
+
+	/**
+	 * This is a callback that will allow us
+	 * to create the viewer and initialize it.
+	 */
+	public void createPartControl(Composite parent) {
+		viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL);
+		//configure the table first as this will set the number of columns. 
+		//If you set the provider first then the column count is not updated in the providers
+		configureTable();
+		configureProviders();
+		// Create the help context id for the viewer's control
+		PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), "org.apache.kato.tools.plugins.hexeditor.viewer");
+		makeActions();
+		hookContextMenu();
+		hookDoubleClickAction();
+		contributeToActionBars();
+		hookPageSelection();
+		hookHexEditor();
+	}
+
+	@Override
+	public void dispose() {
+		super.dispose();
+	}
+
+	private void configureProviders() {
+		viewer.setContentProvider(contentProvider);
+		viewer.setLabelProvider(new ViewLabelProvider());
+		viewer.setSorter(new NameSorter());
+		viewer.setInput(model);
+		getSite().setSelectionProvider(viewer);
+	}
+	
+	private void configureTable() {
+		Table table = viewer.getTable();
+		table.setHeaderVisible(true);
+		table.setLinesVisible(true);
+		TableColumn column = new TableColumn(table, SWT.LEFT);
+		column.setText("Eyecatcher");
+		column.setWidth(100);
+		column = new TableColumn(table, SWT.LEFT);
+		column.setText("Description");
+		column.setWidth(200);
+	}
+	
+	private void hookContextMenu() {
+		MenuManager menuMgr = new MenuManager("#PopupMenu");
+		menuMgr.setRemoveAllWhenShown(true);
+		menuMgr.addMenuListener(new IMenuListener() {
+			public void menuAboutToShow(IMenuManager manager) {
+				EyecatcherView.this.fillContextMenu(manager);
+			}
+		});
+		Menu menu = menuMgr.createContextMenu(viewer.getControl());
+		viewer.getControl().setMenu(menu);
+		getSite().registerContextMenu(menuMgr, viewer);
+	}
+
+	@Override
+	public void saveState(IMemento memento) {
+		super.saveState(memento);
+		saveEyecatchers();
+	}
+
+	private void saveEyecatchers() {
+		if (currentFile == null) return; 		//nothing to save
+		try {
+			if(currentFile.exists()) currentFile.delete();
+			FileOutputStream out = new FileOutputStream(currentFile);
+			model.store(out, "Updated file");
+			isDirty = false;
+		} catch (Exception e) {
+			showMessage("Error saving file " + e.getMessage());
+			e.printStackTrace();
+		}
+	}
+	
+	private void hookPageSelection() {
+		selectListener = new ISelectionListener() {
+			public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+				pageSelectionChanged(part, selection);
+			}
+		};
+		partListerner = new IPartListener() {
+			public void partOpened(IWorkbenchPart part) {
+				//do nothing
+			}
+			public void partDeactivated(IWorkbenchPart part) {
+				//do nothing
+			}
+			public void partClosed(IWorkbenchPart part) {
+				//do nothing
+			}
+			public void partActivated(IWorkbenchPart part) {
+				//showMessage(part.getSite().getPluginId());
+			}
+			public void partBroughtToTop(IWorkbenchPart part) {
+				//do nothing
+			}
+		};
+		//getSite().getPage().addSelectionListener(selectListener);
+		getSite().getPage().addPartListener(partListerner);
+	}
+	
+	private void hookHexEditor() {
+		ISourceProviderService service = (ISourceProviderService)getSite().getWorkbenchWindow().getService(ISourceProviderService.class);
+		BinarySourceProvider bsp = (BinarySourceProvider)service.getSourceProvider("org.apache.kato.tools.plugins.hexeditor.views.BinarySourceProvider");
+		if(bsp == null) {
+			System.err.println("Eyecatcher : Could not get BSP");
+			return;
+		}
+		bsp.addSourceProviderListener(new ISourceProviderListener() {
+			public void sourceChanged(int sourcePriority, Map sourceValuesByName) {
+				System.err.println("Source changed : map");
+			}
+			
+			public void sourceChanged(int sourcePriority, String sourceName, Object sourceValue)  {
+				System.err.println("Source changed : item");
+			}
+		});
+	}
+	
+	protected void pageSelectionChanged(IWorkbenchPart part, ISelection selection) {
+		if(part == this) return;		//do not process myself
+		if(!(selection instanceof IStructuredSelection)) return;
+		IStructuredSelection iss = (IStructuredSelection) selection;
+		if(iss.getFirstElement() instanceof FileEditorSelection) {
+			//showMessage("The editor changed");
+			//updateBookmarks((FileEditorSelection)iss.getFirstElement());
+			//this.getSite().getWorkbenchWindow().getWorkbench().getViewRegistry().find(arg0)
+		}
+	}
+	
+	private void contributeToActionBars() {
+		IActionBars bars = getViewSite().getActionBars();
+		fillLocalPullDown(bars.getMenuManager());
+		fillLocalToolBar(bars.getToolBarManager());
+	}
+
+	private void fillLocalPullDown(IMenuManager manager) {
+		manager.add(actionAdd);
+		manager.add(new Separator());
+		manager.add(actionDelete);
+	}
+
+	private void fillContextMenu(IMenuManager manager) {
+		manager.add(actionAdd);
+		manager.add(actionDelete);
+		// Other plug-ins can contribute there actions here
+		manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
+	}
+	
+	private void fillLocalToolBar(IToolBarManager manager) {
+		manager.add(actionAdd);
+		manager.add(actionDelete);
+	}
+
+	private void makeActions() {
+		actionAdd = new Action() {
+			public void run() {
+				String id = null;
+				String description = null;
+				InputDialog entry = new InputDialog(getSite().getShell(), "New eyecatcher", "Enter a new eyecatcher", null, null);
+				if(entry.open() != SWT.CANCEL) {
+					id = entry.getValue();
+					entry = new InputDialog(getSite().getShell(), "New eyecatcher", "Enter description", null, null);
+					if(entry.open() != SWT.CANCEL) {
+						description = entry.getValue();
+						contentProvider.addEyecatcher(viewer, id, description);
+					}
+				}
+			}
+		};
+		actionAdd.setText("Add");
+		actionAdd.setToolTipText("Add a new eyecatcher");
+		actionAdd.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
+			getImageDescriptor(ISharedImages.IMG_OBJ_ADD));
+		
+		actionDelete = new Action() {
+			public void run() {
+				deleteEyecatcher();
+			}
+		};
+		actionDelete.setText("Delete");
+		actionDelete.setToolTipText("Delete the currently selected eyecatcher");
+		actionDelete.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
+				getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));
+		doubleClickAction = new Action() {
+			public void run() {
+				ISelection selection = viewer.getSelection();
+				Object obj = ((IStructuredSelection)selection).getFirstElement();
+				showMessage("Double-click detected on "+obj.toString());
+			}
+		};
+	}
+	
+	private void deleteEyecatcher() {
+		int[] selected = viewer.getTable().getSelectionIndices();
+		Table table = viewer.getTable();
+		
+		if(selected.length == 0) {
+			showMessage("You must select at least one bookmark to delete");
+		} else {
+			for(int i = 0; i < selected.length; i++) {					//remove the selected bookmarks from the underlying model
+				String key = table.getItem(selected[i]).getText(0);
+				model.remove(key);
+			}
+			table.remove(selected);
+			isDirty = true;
+		}
+	}
+	
+	private void hookDoubleClickAction() {
+		viewer.addDoubleClickListener(new IDoubleClickListener() {
+			public void doubleClick(DoubleClickEvent event) {
+				doubleClickAction.run();
+			}
+		});
+	}
+	private void showMessage(String message) {
+		MessageDialog.openInformation(
+			viewer.getControl().getShell(),
+			"Raw Dump View",
+			message);
+	}
+
+	/**
+	 * Passing the focus request to the viewer's control.
+	 */
+	public void setFocus() {
+		viewer.getControl().setFocus();
+	}
+}
\ No newline at end of file

Propchange: incubator/kato/trunk/org.apache.kato.tools.plugins.hexeditor/src/org/apache/kato/tools/plugins/hexeditor/views/EyecatcherView.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain