Commits

Roman Dawydkin committed 5d4aaf2

Tree view added.

  • Participants
  • Parent commits 4a44192

Comments (0)

Files changed (1)

File src/ru/ezsk/ldapshell/LdapWindow.java

 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
 import javax.naming.directory.SearchResult;
 
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.MenuManager;
 import org.eclipse.jface.action.Separator;
-import org.eclipse.jface.layout.GridDataFactory;
 import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.resource.FontRegistry;
+import org.eclipse.jface.resource.JFaceResources;
 import org.eclipse.jface.window.ApplicationWindow;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.StyledText;
 import org.eclipse.swt.events.DisposeListener;
 import org.eclipse.swt.events.TraverseEvent;
 import org.eclipse.swt.events.TraverseListener;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 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;
 
 public class LdapWindow extends ApplicationWindow
 {
 	private LdapDirectory ldapDirectory;
 	StyledText console;
 	Text input;
+	private Tree tree;
+	private Font boldFont;
+	private FontRegistry fontRegistry;
 
 	// ============================================================ Constructors
 	public LdapWindow(LdapDirectory ldapDirectory) {
 		});
 		shell.setSize(800, 600);
 		shell.setText("LDAP Shell");
+
+		fontRegistry = JFaceResources.getFontRegistry();
+		boldFont = fontRegistry.getBold(JFaceResources.DEFAULT_FONT);
 	}
 
 	void disposed() {
 			}
 			ldapDirectory = null;
 		}
+		if (boldFont != null) {
+			boldFont.dispose();
+			boldFont = null;
+		}
 	}
 
 	protected MenuManager createMenuManager() {
 	}
 
 	protected Control createContents(Composite parent) {
-		final Composite composite = (Composite) super.createContents(parent);
+		final Composite composite = new Composite(parent, SWT.NONE);
 		GridLayoutFactory.swtDefaults().applyTo(composite);
 
-		console = new StyledText(
-				composite,
+		final TabFolder tabFolder = new TabFolder(composite, SWT.TOP);
+		tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+		final Control consolePanel = createConsolePanel(tabFolder);
+		final TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
+		tabItem.setText("Console");
+		tabItem.setControl(consolePanel);
+
+		final Control treePanel = createTreePanel(tabFolder);
+		TabItem treeTabItem = new TabItem(tabFolder, SWT.NONE);
+		treeTabItem.setText("Tree");
+		treeTabItem.setControl(treePanel);
+
+		final Control inputLine = createInputLine(composite);
+		inputLine.setLayoutData(
+				new GridData(SWT.FILL, SWT.CENTER, true, false));
+
+		return composite;
+	}
+
+	private Control createConsolePanel(Composite parent) {
+		console = new StyledText(parent,
 				SWT.BORDER | SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL);
-		GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL)
-				.grab(true, true).applyTo(console);
+		console.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+		return console;
+	}
 
-		input = new Text(composite, SWT.BORDER | SWT.SINGLE);
-		GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER)
-				.grab(true, false).applyTo(input);
+	private Control createTreePanel(Composite parent) {
+		tree = new Tree(parent, SWT.BORDER | SWT.V_SCROLL | SWT.FULL_SELECTION);
+		tree.setHeaderVisible(true);
+		tree.setLinesVisible(true);
+		TreeColumn column;
+		column = new TreeColumn(tree, SWT.NONE);
+		column.setText("Name");
+		column.setWidth(200);
+		column = new TreeColumn(tree, SWT.NONE);
+		column.setText("Value");
+		column.setWidth(400);
+		return tree;
+	}
+
+	private Control createInputLine(Composite parent) {
+		input = new Text(parent, SWT.BORDER | SWT.SINGLE);
 		input.addTraverseListener(new TraverseListener() {
 			public void keyTraversed(TraverseEvent event) {
 				if (event.detail == SWT.TRAVERSE_RETURN) {
 			}
 		});
 		input.setFocus();
-
-		return composite;
+		return input;
 	}
 
 	void print(String line) {
 
 	void search(String query) throws NamingException {
 		printLn("> " + query);
+		tree.removeAll();
 		final NamingEnumeration<SearchResult> enumeration =
 				ldapDirectory.search(query);
 		while (enumeration.hasMore()) {
 			final SearchResult result = enumeration.next();
-			printLn(result.getNameInNamespace());
-			final Attributes attributes = result.getAttributes();
-			final List<Attribute> list = toList(attributes.getAll());
+
+			final String itemName = result.getNameInNamespace();
+			printLn(itemName);
+			final TreeItem treeItem = new TreeItem(tree, SWT.NONE);
+			treeItem.setText(0, itemName);
+			treeItem.setFont(boldFont);
+
+			final List<Attribute> list =
+					toList(result.getAttributes().getAll());
 			for (Attribute attribute : list) {
-				final String id = attribute.getID();
-				print("\t" + id + ":");
+				final String attrId = attribute.getID();
+				print("\t" + attrId + ":");
+				final TreeItem attrItem = new TreeItem(treeItem, SWT.NONE);
+				attrItem.setText(0, attrId);
+
 				final int size = attribute.size();
 				if (size <= 1) {
-					printLn(" " + attribute.get().toString());
+					final String value = attribute.get().toString();
+					printLn(" " + value);
+					attrItem.setText(1, value);
 				} else {
 					printLn("");
+					attrItem.setText(1, "(" + size + " values)");
+					attrItem.setForeground(1,
+							tree.getDisplay().getSystemColor(SWT.COLOR_GRAY));
 					for (int i = 0; i < size; i++) {
-						printLn("\t\t" + attribute.get(i).toString());
+						final String value = attribute.get(i).toString();
+						printLn("\t\t" + value);
+						final TreeItem valueItem =
+								new TreeItem(attrItem, SWT.NONE);
+						valueItem.setText(0, attrId);
+						valueItem.setText(1, value);
 					}
 				}
 			}
 
 	void clearResult() {
 		console.setText("");
+		tree.removeAll();
 	}
 
 	private static List<Attribute> toList(