*** empty log message ***

cmurphy [2007-12-18 20:52:13]
*** empty log message ***
Filename
retina/db/XmlServer.java
testplugin/actions/SampleAction.java
testplugin/actions/XMLWriter.java
testplugin/views/SampleView.java
diff --git a/retina/db/XmlServer.java b/retina/db/XmlServer.java
index c08d472..9474732 100644
--- a/retina/db/XmlServer.java
+++ b/retina/db/XmlServer.java
@@ -13,12 +13,6 @@ import java.util.Scanner;

 public class XmlServer extends Thread
 {
-    // the output stream for writing the file
-    private PrintWriter out;
-
-    // the input stream for reading from the network
-    private Scanner in;
-
     // the server
     private ServerSocket server;

@@ -90,24 +84,58 @@ public class XmlServer extends Thread
     		{
     			// wait for a client
     			Socket socket = server.accept();
-    			//System.out.println("Connection established");
+
+    			// spin off a new thread
+    			Handler h = new Handler(socket);
+    			h.start();
+    		}
+    		catch (Exception e)
+    		{
+    			e.printStackTrace();
+    		}
+    	}
+    }
+
+    /**
+     * An inner class to do the work of reading the file and writing to the database and such
+     */
+    class Handler extends Thread
+    {
+    	Socket socket = null;
+
+    	Handler(Socket s)
+    	{
+    		socket = s;
+    	}
+
+    	public void run()
+    	{
+    	    // the output stream for writing the file
+    	    PrintWriter out = null;
+
+    	    // the input stream for reading from the network
+    	    Scanner in = null;

+    	    try
+    		{
+    			//System.out.println("Connection established");
+
     			// get the input stream
     			in = new Scanner(socket.getInputStream());

     			// the name of the file should be on the first line
     			String fileName = "_" + in.nextLine();
     			//System.out.println("File is " + fileName);
-
+
     			// create the File object
     			File file = new File(fileName);
-
+
     			// create the PrintWriter to write to the file
     			out = new PrintWriter(file);

     			// flag to indicate whether we should keep reading
     			boolean keepGoing = true;
-
+
     			while (keepGoing)
     			{
     				// read the next line
@@ -118,7 +146,7 @@ public class XmlServer extends Thread
     				{
     					// echo it out
     					//System.out.println(line);
-
+
     					// write to the file
     					out.println(line);
     					out.flush();
@@ -129,7 +157,7 @@ public class XmlServer extends Thread
     					keepGoing = false;
     				}
     			}
-
+
     			// we have the file, now write it to the database using the "XMLLoader"
     			loader.readAndLoad(fileName);
     		}
diff --git a/testplugin/actions/SampleAction.java b/testplugin/actions/SampleAction.java
new file mode 100644
index 0000000..ae2c14f
--- /dev/null
+++ b/testplugin/actions/SampleAction.java
@@ -0,0 +1,85 @@
+package testplugin.actions;
+
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+import org.eclipse.jface.dialogs.MessageDialog;
+
+/**
+ * Our sample action implements workbench action delegate.
+ * The action proxy will be created by the workbench and
+ * shown in the UI. When the user tries to use the action,
+ * this delegate will be created and execution will be
+ * delegated to it.
+ * @see IWorkbenchWindowActionDelegate
+ */
+public class SampleAction implements IWorkbenchWindowActionDelegate {
+	private IWorkbenchWindow window;
+	/**
+	 * The constructor.
+	 */
+	public SampleAction() {
+	}
+
+	/**
+	 * The action has been activated. The argument of the
+	 * method represents the 'real' action sitting
+	 * in the workbench UI.
+	 * @see IWorkbenchWindowActionDelegate#run
+	 */
+	public void run(IAction action) {
+	/*	MessageDialog.openInformation(
+			window.getShell(),
+			"TestPlugin",
+			"you should have your filename now!");*/
+		String str = null;
+		String displayName = null;
+
+		try {
+			IEditorInput iei = window.getActivePage().getActiveEditor().getEditorInput();
+			displayName = iei.getName();
+			if (iei instanceof FileEditorInput) {
+				str = (((FileEditorInput) iei).getPath()).toString();
+			}
+			viewtester.views.SampleView.setMessage(str);
+			String results = Compiler.compileFile(str, displayName);
+			viewtester.views.SampleView.setMessage(str + " compiled." + System.getProperty("line.separator") + results);
+		} catch(Exception e) {
+			e.printStackTrace();
+			MessageDialog.openInformation(
+					window.getShell(),
+					"TestPlugin Plug-in",
+					"No editor window open yet");
+		}
+	}
+
+	/**
+	 * Selection in the workbench has been changed. We
+	 * can change the state of the 'real' action here
+	 * if we want, but this can only happen after
+	 * the delegate has been created.
+	 * @see IWorkbenchWindowActionDelegate#selectionChanged
+	 */
+	public void selectionChanged(IAction action, ISelection selection) {
+	}
+
+	/**
+	 * We can use this method to dispose of any system
+	 * resources we previously allocated.
+	 * @see IWorkbenchWindowActionDelegate#dispose
+	 */
+	public void dispose() {
+	}
+
+	/**
+	 * We will cache window object in order to
+	 * be able to provide parent shell for the message dialog.
+	 * @see IWorkbenchWindowActionDelegate#init
+	 */
+	public void init(IWorkbenchWindow window) {
+		this.window = window;
+	}
+}
\ No newline at end of file
diff --git a/testplugin/actions/XMLWriter.java b/testplugin/actions/XMLWriter.java
index b38fe30..e141fd2 100644
--- a/testplugin/actions/XMLWriter.java
+++ b/testplugin/actions/XMLWriter.java
@@ -11,10 +11,11 @@ import java.util.Date;

 public class XMLWriter extends PrintWriter {
 	StringBuffer errorBfr;
+
 	public XMLWriter(File file) throws FileNotFoundException
     {
-	super(file);
-	errorBfr = new StringBuffer();
+		super(file);
+		errorBfr = new StringBuffer();
     }

 	/**
@@ -50,14 +51,8 @@ public class XMLWriter extends PrintWriter {
 		error = error.substring(index+1).trim();
 		//System.out.println(error);

-		// if it's a problem with something already being defined, just extract that
-		if (error.contains("already defined")) error = "already defined";
-		// if they're trying to access a non-static thing from a static method
-		else if (error.contains("static context"))
-		{
-			if (error.contains("non-static method")) error = "non-static method cannot be referenced from a static context";
-			else if (error.contains("non-static variable")) error = "non-static variable cannot be referenced from a static context";
-		}
+		// see if the error needs to be modified based on special cases
+		error = handleSpecialCases(error);


 		// this is where we write the actual error message
@@ -69,8 +64,11 @@ public class XMLWriter extends PrintWriter {
 	    // indicate that we're currently writing an error
 	    writing = true;

-	    // to skip two lines when there's an unexpected type... this will print the line of code
+	    // to skip two lines in the cases where we want to print the line of code
 	    if (error.equals("unexpected type")) counter = 2;
+	    else if (error.equals("inconvertible types")) counter = 2;
+	    else if (error.equals("incompatible types")) counter = 2;
+	    else if (error.equals("possible loss of precision")) counter = 2;

 	}
 	else if (writing)
@@ -101,19 +99,19 @@ public class XMLWriter extends PrintWriter {
      */
     public void writeHeader()
     {
-	super.println("<measurements>");
-	super.println("\t<metric name=\"compilation_errors\" measure=\"true\">");
-	super.println("\t\t<user name=\"" + System.getProperty("user.name") + "\"/>");
-	super.println("\t\t<time>");
-	Calendar now = Calendar.getInstance();
-	now.setTime(new Date());
-	super.println("\t\t\t<year>" + now.get(Calendar.YEAR) + "</year>");
-	super.println("\t\t\t<month>" + (now.get(Calendar.MONTH)+1) + "</month>");
-	super.println("\t\t\t<day>" + now.get(Calendar.DAY_OF_MONTH) + "</day>");
-	super.println("\t\t\t<hour>" + now.get(Calendar.HOUR_OF_DAY) + "</hour>");
-	super.println("\t\t\t<minute>" + now.get(Calendar.MINUTE) + "</minute>");
-	super.println("\t\t\t<second>" + now.get(Calendar.SECOND) + "</second>");
-	super.println("\t\t</time>");
+    	super.println("<measurements>");
+    	super.println("\t<metric name=\"compilation_errors\" measure=\"true\">");
+    	super.println("\t\t<user name=\"" + System.getProperty("user.name") + "\"/>");
+    	super.println("\t\t<time>");
+    	Calendar now = Calendar.getInstance();
+    	now.setTime(new Date());
+    	super.println("\t\t\t<year>" + now.get(Calendar.YEAR) + "</year>");
+    	super.println("\t\t\t<month>" + (now.get(Calendar.MONTH)+1) + "</month>");
+    	super.println("\t\t\t<day>" + now.get(Calendar.DAY_OF_MONTH) + "</day>");
+    	super.println("\t\t\t<hour>" + now.get(Calendar.HOUR_OF_DAY) + "</hour>");
+    	super.println("\t\t\t<minute>" + now.get(Calendar.MINUTE) + "</minute>");
+    	super.println("\t\t\t<second>" + now.get(Calendar.SECOND) + "</second>");
+    	super.println("\t\t</time>");
     }

     /**
@@ -122,7 +120,30 @@ public class XMLWriter extends PrintWriter {
      */
     public void writeFooter()
     {
-	super.println("\n\t</metric>");
-	super.println("</measurements>");
+    	super.println("\n\t</metric>");
+    	super.println("</measurements>");
+    }
+
+    /**
+     * Helper method to modify the original error string to something more generic, as necessary
+     */
+    private String handleSpecialCases(String error)
+    {
+		// if it's a problem with something already being defined, just extract that
+		if (error.contains("already defined")) error = "already defined";
+		// if they're trying to access a non-static thing from a static method
+		else if (error.contains("static context"))
+		{
+			if (error.contains("non-static method")) error = "non-static method cannot be referenced from a static context";
+			else if (error.contains("non-static variable")) error = "non-static variable cannot be referenced from a static context";
+		}
+		// if they try to pass the wrong parameters to a method
+		else if (error.contains("cannot be applied")) error = "parameter mismatch";
+		// if they try to call a method on a primitive datatype
+		else if (error.contains("cannot be dereferenced")) error = "cannot dereference primitive";
+		// if the name of the file doesn't match the name of the class
+		else if (error.contains("is public, should be declared in a file named")) error = "file name does not match class name";
+
+		return error;
     }
 }
diff --git a/testplugin/views/SampleView.java b/testplugin/views/SampleView.java
new file mode 100644
index 0000000..96f8b0d
--- /dev/null
+++ b/testplugin/views/SampleView.java
@@ -0,0 +1,199 @@
+package viewtester.views;
+
+import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.part.*;
+//import org.eclipse.jface.viewers.*;
+//import org.eclipse.swt.graphics.Image;
+//import org.eclipse.jface.action.*;
+//import org.eclipse.jface.dialogs.MessageDialog;
+//import org.eclipse.ui.*;
+//import org.eclipse.swt.widgets.Menu;
+//import org.eclipse.swt.SWT;
+
+
+/**
+ * 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 SampleView extends ViewPart {
+	/*	private TableViewer viewer;
+	private Action action1;
+	private Action action2;
+	private Action doubleClickAction;
+
+
+	 * 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 new String[] { "Ace", "Bow", "Five" };
+		}
+	}
+	class ViewLabelProvider extends LabelProvider implements ITableLabelProvider {
+		public String getColumnText(Object obj, int index) {
+			return getText(obj);
+		}
+		public Image getColumnImage(Object obj, int index) {
+			return getImage(obj);
+		}
+		public Image getImage(Object obj) {
+			return PlatformUI.getWorkbench().
+					getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
+		}
+	}
+	class NameSorter extends ViewerSorter {
+	}
+
+	 *//**
+	 * The constructor.
+	 *//*
+	public SampleView() {
+	}
+
+	  *//**
+	  * 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 | SWT.V_SCROLL);
+		viewer.setContentProvider(new ViewContentProvider());
+		viewer.setLabelProvider(new ViewLabelProvider());
+		viewer.setSorter(new NameSorter());
+		viewer.setInput(getViewSite());
+		makeActions();
+		hookContextMenu();
+		hookDoubleClickAction();
+		contributeToActionBars();
+	}
+
+	private void hookContextMenu() {
+		MenuManager menuMgr = new MenuManager("#PopupMenu");
+		menuMgr.setRemoveAllWhenShown(true);
+		menuMgr.addMenuListener(new IMenuListener() {
+			public void menuAboutToShow(IMenuManager manager) {
+				SampleView.this.fillContextMenu(manager);
+			}
+		});
+		Menu menu = menuMgr.createContextMenu(viewer.getControl());
+		viewer.getControl().setMenu(menu);
+		getSite().registerContextMenu(menuMgr, viewer);
+	}
+
+	private void contributeToActionBars() {
+		IActionBars bars = getViewSite().getActionBars();
+		fillLocalPullDown(bars.getMenuManager());
+		fillLocalToolBar(bars.getToolBarManager());
+	}
+
+	private void fillLocalPullDown(IMenuManager manager) {
+		manager.add(action1);
+		manager.add(new Separator());
+		manager.add(action2);
+	}
+
+	private void fillContextMenu(IMenuManager manager) {
+		manager.add(action1);
+		manager.add(action2);
+		// Other plug-ins can contribute there actions here
+		manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
+	}
+
+	private void fillLocalToolBar(IToolBarManager manager) {
+		manager.add(action1);
+		manager.add(action2);
+	}
+
+	private void makeActions() {
+		action1 = new Action() {
+			public void run() {
+				showMessage("Action 1 executed");
+			}
+		};
+		action1.setText("Action 1");
+		action1.setToolTipText("Action 1 tooltip");
+		action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
+			getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
+
+		action2 = new Action() {
+			public void run() {
+				showMessage("Action 2 executed");
+			}
+		};
+		action2.setText("Action 2");
+		action2.setToolTipText("Action 2 tooltip");
+		action2.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
+				getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
+		doubleClickAction = new Action() {
+			public void run() {
+				ISelection selection = viewer.getSelection();
+				Object obj = ((IStructuredSelection)selection).getFirstElement();
+				showMessage("Double-click detected on "+obj.toString());
+			}
+		};
+	}
+
+	private void hookDoubleClickAction() {
+		viewer.addDoubleClickListener(new IDoubleClickListener() {
+			public void doubleClick(DoubleClickEvent event) {
+				doubleClickAction.run();
+			}
+		});
+	}
+	private void showMessage(String message) {
+		MessageDialog.openInformation(
+			viewer.getControl().getShell(),
+			"Simple View",
+			message);
+	}
+
+	   *//**
+	   * Passing the focus request to the viewer's control.
+	   *//*
+	public void setFocus() {
+		viewer.getControl().setFocus();
+	}*/
+	private static Label lbl;
+	public static String message = "";
+
+	public SampleView() {
+		super();
+	}
+
+	public void setFocus() {
+		lbl.setFocus();
+	}
+	public void createPartControl(Composite parent) {
+		lbl = new Label(parent, 0);
+		lbl.setText(SampleView.message);
+	}
+
+	public static void setMessage(String msg) {
+		lbl.setText(msg);
+	}
+}
\ No newline at end of file