Fixes inadvertant sharing of TerminalView instances.

The sharing behavior is not the desired behavior: this patch makes the
opening behavior create fresh views.  Previously, TerminalView
instances could be shared by id, where the id is the base path of the
directory being opend.  However, this means that if two terminal
windows have the same base identifier, they'll be shared.  So, for
example, if "/foo/bar/baz" is an opened terminal, a request to open
"/foogle/baz" will incorrectly reopen the terminal for "/foo/bar/baz".

Change-Id: I5ed9f1c6534d8cdac81948e970081bffaf0cfceb
diff --git a/com.google.eclipse.elt.view/src/com/google/eclipse/elt/view/ui/TerminalView.java b/com.google.eclipse.elt.view/src/com/google/eclipse/elt/view/ui/TerminalView.java
index 70c6714..fa8c751 100644
--- a/com.google.eclipse.elt.view/src/com/google/eclipse/elt/view/ui/TerminalView.java
+++ b/com.google.eclipse.elt.view/src/com/google/eclipse/elt/view/ui/TerminalView.java
@@ -13,7 +13,6 @@
 import static org.eclipse.jface.resource.JFaceResources.TEXT_FONT;
 import static org.eclipse.jface.window.Window.OK;
 import static org.eclipse.ui.IWorkbenchPage.VIEW_ACTIVATE;
-
 import static com.google.eclipse.elt.view.Activator.*;
 import static com.google.eclipse.elt.view.ImageKeys.*;
 import static com.google.eclipse.elt.view.preferences.ColorsAndFontsPreferences.*;
@@ -21,8 +20,6 @@
 import static com.google.eclipse.elt.view.ui.Messages.*;
 import static com.google.eclipse.elt.view.util.Platform.userHomeDirectory;
 
-import java.util.UUID;
-
 import org.eclipse.core.runtime.*;
 import org.eclipse.jface.action.*;
 import org.eclipse.jface.dialogs.*;
@@ -64,16 +61,30 @@
 
   private IContextActivation contextActivation;
 
+  /**
+   * Creates a new terminal view.
+   *
+   * @param workingDirectory the working directory to be opened on initialization
+   */
   public static void openTerminalView(IPath workingDirectory) {
-    openTerminalView(null, workingDirectory);
+    openNewTerminalView(workingDirectory);
   }
 
-  private static void openTerminalView(String id, IPath workingDirectory) {
+  private static int freshTerminalId = 0;
+
+  /**
+   * Opens a new {@link TerminalView}.
+   *
+   * @param workingDirectory the working directory to be opened on initialization
+   */
+  private static void openNewTerminalView(IPath workingDirectory) {
     IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
     IPath safeWorkingDirectory = (workingDirectory != null) ? workingDirectory : userHomeDirectory();
     try {
       String directoryName = safeWorkingDirectory.lastSegment();
-      String secondaryId = (id != null) ? id : directoryName;
+      // Use of a freshTerminalId to force freshness of the identifier.
+      String secondaryId = Integer.toString(freshTerminalId);
+      freshTerminalId++;
       TerminalView view = (TerminalView) page.showView(VIEW_ID, secondaryId, VIEW_ACTIVATE);
       view.setPartName(directoryName);
       view.open(safeWorkingDirectory);
@@ -324,7 +335,7 @@
     }
 
     @Override public void run() {
-      openTerminalView(UUID.randomUUID().toString(), workingDirectory);
+      openNewTerminalView(workingDirectory);
     }
   }