Commits

Roman Dawydkin committed 153cc42

Make input line a combo box.

  • Participants
  • Parent commits a655d9b

Comments (0)

Files changed (1)

src/ru/ezsk/ldapshell/LdapWindow.java

 import org.eclipse.swt.graphics.Font;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Combo;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.TabFolder;
 import org.eclipse.swt.widgets.TabItem;
-import org.eclipse.swt.widgets.Text;
 import org.eclipse.swt.widgets.Tree;
 import org.eclipse.swt.widgets.TreeColumn;
 import org.eclipse.swt.widgets.TreeItem;
 	// ================================================================== Fields
 	private LdapDirectory ldapDirectory;
 	StyledText console;
-	Text input;
+	Combo input;
 	Tree tree;
 	private Font boldFont;
 	TabFolder tabFolder;
 	}
 
 	private Control createInputLine(Composite parent) {
-		input = new Text(parent, SWT.BORDER | SWT.SINGLE);
+		input = new Combo(parent, SWT.BORDER | SWT.SINGLE);
 		input.addTraverseListener(new TraverseListener() {
 			public void keyTraversed(TraverseEvent event) {
 				if (event.detail == SWT.TRAVERSE_RETURN) {
 					event.doit = false;
-					try {
-						search(input.getText());
-					} catch (NamingException ex) {
-						printLn(ex.getMessage()); // TODO
-					}
-					input.setText("");
+					handleSearch();
 				}
 			}
 		});
 		return input;
 	}
 
+	void handleSearch() {
+		final String text = input.getText();
+		if (text.isEmpty()) {
+			return;
+		}
+		final String[] items = input.getItems();
+		for (int i = 0; i < items.length; i++) {
+			final String item = items[i];
+			if (item.equals(text)) {
+				input.remove(i);
+				break;
+			}
+		}
+		input.add(text, 0);
+		try {
+			search(text);
+		} catch (NamingException ex) {
+			printLn(ex.getMessage()); // TODO
+		}
+		input.setText("");
+	}
+
 	void print(String line) {
 		console.append(line);
 		console.setSelection(console.getCharCount());