RESOLVED - bug 183819: [pde viz] Add search support to allow users to sarch the list of shown plug-ins
https://bugs.eclipse.org/bugs/show_bug.cgi?id=183819
diff --git a/visualization/plugins/org.eclipse.pde.visualization.dependency/icons/obj16/progress_rem.gif b/visualization/plugins/org.eclipse.pde.visualization.dependency/icons/obj16/progress_rem.gif
new file mode 100644
index 0000000..2cd9c54
--- /dev/null
+++ b/visualization/plugins/org.eclipse.pde.visualization.dependency/icons/obj16/progress_rem.gif
Binary files differ
diff --git a/visualization/plugins/org.eclipse.pde.visualization.dependency/src/org/eclipse/pde/visualization/dependency/views/PluginVisualizationView.java b/visualization/plugins/org.eclipse.pde.visualization.dependency/src/org/eclipse/pde/visualization/dependency/views/PluginVisualizationView.java
index 74ac1a8..e3e9cd4 100644
--- a/visualization/plugins/org.eclipse.pde.visualization.dependency/src/org/eclipse/pde/visualization/dependency/views/PluginVisualizationView.java
+++ b/visualization/plugins/org.eclipse.pde.visualization.dependency/src/org/eclipse/pde/visualization/dependency/views/PluginVisualizationView.java
@@ -15,7 +15,6 @@
 import java.util.Iterator;
 import java.util.Stack;
 
-import org.eclipse.draw2d.ColorConstants;
 import org.eclipse.draw2d.SWTGraphics;
 import org.eclipse.draw2d.geometry.Dimension;
 import org.eclipse.draw2d.geometry.Rectangle;
@@ -57,16 +56,13 @@
 import org.eclipse.pde.internal.ui.wizards.PluginSelectionDialog;
 import org.eclipse.pde.visualization.dependency.Activator;
 import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.KeyAdapter;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.PaintEvent;
-import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
 import org.eclipse.swt.graphics.Font;
 import org.eclipse.swt.graphics.FontData;
 import org.eclipse.swt.graphics.GC;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Region;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Menu;
@@ -121,7 +117,6 @@
 	private ZoomContributionViewItem contextZoomContributionViewItem;
 	private ZoomContributionViewItem toolbarZoomContributionViewItem;
 	private VisualizationForm visualizationForm;
-	private StringBuffer stringBuffer;
 	private Font searchFont;
 
 	/**
@@ -166,7 +161,6 @@
 		
 		FontData fontData = Display.getCurrent().getSystemFont().getFontData()[0];
 		fontData.height = 42;
-		stringBuffer = new StringBuffer();
 
 		searchFont = new Font(Display.getCurrent(), fontData);
 		viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@@ -203,19 +197,10 @@
 
 		});
 		
-		viewer.getGraphControl().addKeyListener(new KeyAdapter() {
+		visualizationForm.getSearchBox().addModifyListener(new ModifyListener() {
 
-			public void keyPressed(KeyEvent e) {
-				boolean complete = false;
-				if (e.keyCode == BACKSPACE) {
-					if (stringBuffer.length() > 0) {
-						stringBuffer.deleteCharAt(stringBuffer.length() - 1);
-					}
-				} else if (e.keyCode == ENTER) {
-					complete = true;
-				} else if ((e.character >= 'a' && e.character <= 'z') || (e.character >= 'A' && e.character <= 'Z') || (e.character == '.') || (e.character >= '0' && e.character <= '9')) {
-					stringBuffer.append(e.character);
-				}
+			public void modifyText(ModifyEvent e) {
+				String textString = visualizationForm.getSearchBox().getText();
 	
 				HashMap figureListing = new HashMap();
 				ArrayList list = new ArrayList();
@@ -225,35 +210,19 @@
 					figureListing.put(item.getText(), item);
 				}
 				iterator = figureListing.keySet().iterator();
-				if (stringBuffer.length() > 0) {
+				if (textString.length() > 0) {
 					while (iterator.hasNext()) {
 						String string = (String) iterator.next();
-						if (string.toLowerCase().indexOf(stringBuffer.toString().toLowerCase()) >= 0) {
+						if (string.toLowerCase().indexOf(textString.toLowerCase()) >= 0) {
 							list.add(figureListing.get(string));
 						}
 					}
 				}
 				viewer.getGraphControl().setSelection((GraphItem[]) list.toArray(new GraphItem[list.size()]));
-				if (complete && stringBuffer.length() > 0) {
-					stringBuffer.delete(0, stringBuffer.length());
-				}
-
-				viewer.getGraphControl().redraw();
 			}
 
 		});
-		viewer.getGraphControl().addPaintListener(new PaintListener() {
-			private int x;
-
-			public void paintControl(PaintEvent e) {
-				e.gc.setFont(searchFont);
-				e.gc.setClipping((Region) null);
-				e.gc.setForeground(ColorConstants.darkGray);
-				x = viewer.getGraphControl().getSize().x;
-				int textWidth = e.gc.textExtent(stringBuffer.toString()).x;
-				e.gc.drawText(stringBuffer.toString(), (x / 2) - (textWidth / 2), 50, true);
-			}
-		});
+		
 		toolbarZoomContributionViewItem = new ZoomContributionViewItem(this);
 		contextZoomContributionViewItem = new ZoomContributionViewItem(this);
 
diff --git a/visualization/plugins/org.eclipse.pde.visualization.dependency/src/org/eclipse/pde/visualization/dependency/views/VisualizationForm.java b/visualization/plugins/org.eclipse.pde.visualization.dependency/src/org/eclipse/pde/visualization/dependency/views/VisualizationForm.java
index ef87274..f2bbf98 100644
--- a/visualization/plugins/org.eclipse.pde.visualization.dependency/src/org/eclipse/pde/visualization/dependency/views/VisualizationForm.java
+++ b/visualization/plugins/org.eclipse.pde.visualization.dependency/src/org/eclipse/pde/visualization/dependency/views/VisualizationForm.java
@@ -23,6 +23,8 @@
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.forms.ManagedForm;
 import org.eclipse.ui.forms.widgets.ExpandableComposite;
 import org.eclipse.ui.forms.widgets.FormToolkit;
@@ -85,6 +87,7 @@
 
 	private String currentPathAnalysis = null;
 	private SashForm sash;
+	private Text searchBox;
 
 	/**
 	 * Creates the form.
@@ -97,6 +100,23 @@
 		this.view = view;
 		form = this.toolkit.createScrolledForm(parent);
 		managedForm = new ManagedForm(this.toolkit, this.form);
+		
+		Composite headClient = new Composite(form.getForm().getHead(),
+				SWT.NULL);
+		GridLayout glayout = new GridLayout();
+		glayout.marginWidth = glayout.marginHeight = 0;
+		glayout.numColumns = 2;
+		headClient.setLayout(glayout);
+		headClient.setBackgroundMode(SWT.INHERIT_DEFAULT);
+		Label searchLabel = new Label(headClient, SWT.NONE);
+		searchLabel.setText("Search:");
+		searchBox = new Text(headClient, toolkit.getBorderStyle() | SWT.SEARCH | SWT.CANCEL);
+		GridData data = new GridData();
+		data.widthHint = 300;
+		searchBox.setLayoutData(data);
+		toolkit.paintBordersFor(headClient);
+		form.setHeadClient(headClient);
+		
 		FillLayout layout = new FillLayout();
 		layout.marginHeight = 10;
 		layout.marginWidth = 4;
@@ -304,5 +324,9 @@
 	public ManagedForm getManagedForm() {
 		return managedForm;
 	}
+	
+	public Text getSearchBox() {
+		return this.searchBox;
+	}
 
 }