diff dbus-d-javatests/jsrc/filetree/FileTree.java @ 0:a5576806d36d

recreate repository without any libs for lightweight repository
author Frank Benoit <benoit@tionex.de>
date Sat, 20 Oct 2007 18:07:18 +0200
parents
children 65fb7ef02c50
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dbus-d-javatests/jsrc/filetree/FileTree.java	Sat Oct 20 18:07:18 2007 +0200
@@ -0,0 +1,157 @@
+package filetree;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.window.ApplicationWindow;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+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.freedesktop.dbus.DirectConnection;
+
+import dbus_d_javahelper.ConsoleProcess;
+
+/**
+ * This class demonstrates TreeViewer. It shows the drives, directories, and
+ * files on the system.
+ */
+public class FileTree extends ApplicationWindow {
+  private final DataFileSystem fs;
+
+/**
+   * FileTree constructor
+   */
+  public FileTree(DataFileSystem fs) {
+    super(null);
+	this.fs = fs;
+  }
+
+  /**
+   * Runs the application
+   */
+  public void run() {
+    // Don't return from open() until window closes
+    setBlockOnOpen(true);
+
+    // Open the main window
+    open();
+
+    // Dispose the display
+    Display.getCurrent().dispose();
+  }
+
+  /**
+   * Configures the shell
+   * 
+   * @param shell
+   *            the shell
+   */
+  protected void configureShell(Shell shell) {
+    super.configureShell(shell);
+
+    // Set the title bar text and the size
+    shell.setText("File Tree");
+    shell.setSize(400, 400);
+  }
+
+  /**
+   * Creates the main window's contents
+   * 
+   * @param parent
+   *            the main window
+   * @return Control
+   */
+  protected Control createContents(Composite parent) {
+    Composite composite = new Composite(parent, SWT.NONE);
+    composite.setLayout(new GridLayout(1, false));
+
+    // Add a checkbox to toggle whether the labels preserve case
+    Button preserveCase = new Button(composite, SWT.CHECK);
+    preserveCase.setText("&Preserve case");
+
+    // Create the tree viewer to display the file tree
+    final TreeViewer tv = new TreeViewer(composite);
+    tv.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
+    tv.setContentProvider(new FileTreeContentProvider());
+    tv.setLabelProvider(new FileTreeLabelProvider());
+    tv.setInput(fs); // pass a non-null that will be ignored
+
+    // When user checks the checkbox, toggle the preserve case attribute
+    // of the label provider
+    preserveCase.addSelectionListener(new SelectionAdapter() {
+      public void widgetSelected(SelectionEvent event) {
+        boolean preserveCase = ((Button) event.widget).getSelection();
+        FileTreeLabelProvider ftlp = (FileTreeLabelProvider) tv
+            .getLabelProvider();
+        ftlp.setPreserveCase(preserveCase);
+      }
+    });
+    return composite;
+  }
+
+  /**
+   * The application entry point
+   * 
+   * @param args
+   *            the command line arguments
+   */
+  public static void main2(String[] args) {
+	    new FileTree(null).run();
+  }
+	static DirectConnection dc;
+	static ConsoleProcess process;
+
+	public static void main(String[] args) throws Exception {
+		final String address = DirectConnection.createDynamicTCPSession();
+		// String address =
+		// "tcp:host=localhost,port=12344,guid="+Transport.genGUID();
+		System.err.println("----------------------------");
+		System.err.println(address);
+		System.err.println("----------------------------");
+		new Thread() {
+			@Override
+			public void run() {
+				try {
+					System.err.println("### start D ###");
+					process = new ConsoleProcess(new String[] {
+							"./dsrc/DHelper", address }, null, null,
+							System.out, System.err);
+					System.err.println("### started D ###");
+					process.join();
+				} catch (InterruptedException e) {
+					e.printStackTrace();
+				} catch (IOException e) {
+					e.printStackTrace();
+				}
+			}
+		}.start();
+		
+		try{
+			Thread.sleep( 200 );
+			System.err.println("--- starting connection ----");
+			dc = new DirectConnection(address + ",listen=true");
+			System.err.println("----------------------------");
+	
+			DataFileSystem rem = (DataFileSystem) dc.getRemoteObject(
+					"/DHelper/MyDataFileSystem/0", DataFileSystem.class);
+	
+		    new FileTree(rem).run();
+
+		}
+		finally{
+		    dc.disconnect();
+		}
+	}
+}
+
+
+ 
\ No newline at end of file