Mercurial > projects > dbus-d
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a5576806d36d |
---|---|
1 package filetree; | |
2 | |
3 import java.io.FileOutputStream; | |
4 import java.io.IOException; | |
5 import java.io.PrintWriter; | |
6 | |
7 import org.eclipse.jface.viewers.TreeViewer; | |
8 import org.eclipse.jface.window.ApplicationWindow; | |
9 import org.eclipse.swt.SWT; | |
10 import org.eclipse.swt.events.SelectionAdapter; | |
11 import org.eclipse.swt.events.SelectionEvent; | |
12 import org.eclipse.swt.layout.GridData; | |
13 import org.eclipse.swt.layout.GridLayout; | |
14 import org.eclipse.swt.widgets.Button; | |
15 import org.eclipse.swt.widgets.Composite; | |
16 import org.eclipse.swt.widgets.Control; | |
17 import org.eclipse.swt.widgets.Display; | |
18 import org.eclipse.swt.widgets.Shell; | |
19 import org.freedesktop.dbus.DirectConnection; | |
20 | |
21 import dbus_d_javahelper.ConsoleProcess; | |
22 | |
23 /** | |
24 * This class demonstrates TreeViewer. It shows the drives, directories, and | |
25 * files on the system. | |
26 */ | |
27 public class FileTree extends ApplicationWindow { | |
28 private final DataFileSystem fs; | |
29 | |
30 /** | |
31 * FileTree constructor | |
32 */ | |
33 public FileTree(DataFileSystem fs) { | |
34 super(null); | |
35 this.fs = fs; | |
36 } | |
37 | |
38 /** | |
39 * Runs the application | |
40 */ | |
41 public void run() { | |
42 // Don't return from open() until window closes | |
43 setBlockOnOpen(true); | |
44 | |
45 // Open the main window | |
46 open(); | |
47 | |
48 // Dispose the display | |
49 Display.getCurrent().dispose(); | |
50 } | |
51 | |
52 /** | |
53 * Configures the shell | |
54 * | |
55 * @param shell | |
56 * the shell | |
57 */ | |
58 protected void configureShell(Shell shell) { | |
59 super.configureShell(shell); | |
60 | |
61 // Set the title bar text and the size | |
62 shell.setText("File Tree"); | |
63 shell.setSize(400, 400); | |
64 } | |
65 | |
66 /** | |
67 * Creates the main window's contents | |
68 * | |
69 * @param parent | |
70 * the main window | |
71 * @return Control | |
72 */ | |
73 protected Control createContents(Composite parent) { | |
74 Composite composite = new Composite(parent, SWT.NONE); | |
75 composite.setLayout(new GridLayout(1, false)); | |
76 | |
77 // Add a checkbox to toggle whether the labels preserve case | |
78 Button preserveCase = new Button(composite, SWT.CHECK); | |
79 preserveCase.setText("&Preserve case"); | |
80 | |
81 // Create the tree viewer to display the file tree | |
82 final TreeViewer tv = new TreeViewer(composite); | |
83 tv.getTree().setLayoutData(new GridData(GridData.FILL_BOTH)); | |
84 tv.setContentProvider(new FileTreeContentProvider()); | |
85 tv.setLabelProvider(new FileTreeLabelProvider()); | |
86 tv.setInput(fs); // pass a non-null that will be ignored | |
87 | |
88 // When user checks the checkbox, toggle the preserve case attribute | |
89 // of the label provider | |
90 preserveCase.addSelectionListener(new SelectionAdapter() { | |
91 public void widgetSelected(SelectionEvent event) { | |
92 boolean preserveCase = ((Button) event.widget).getSelection(); | |
93 FileTreeLabelProvider ftlp = (FileTreeLabelProvider) tv | |
94 .getLabelProvider(); | |
95 ftlp.setPreserveCase(preserveCase); | |
96 } | |
97 }); | |
98 return composite; | |
99 } | |
100 | |
101 /** | |
102 * The application entry point | |
103 * | |
104 * @param args | |
105 * the command line arguments | |
106 */ | |
107 public static void main2(String[] args) { | |
108 new FileTree(null).run(); | |
109 } | |
110 static DirectConnection dc; | |
111 static ConsoleProcess process; | |
112 | |
113 public static void main(String[] args) throws Exception { | |
114 final String address = DirectConnection.createDynamicTCPSession(); | |
115 // String address = | |
116 // "tcp:host=localhost,port=12344,guid="+Transport.genGUID(); | |
117 System.err.println("----------------------------"); | |
118 System.err.println(address); | |
119 System.err.println("----------------------------"); | |
120 new Thread() { | |
121 @Override | |
122 public void run() { | |
123 try { | |
124 System.err.println("### start D ###"); | |
125 process = new ConsoleProcess(new String[] { | |
126 "./dsrc/DHelper", address }, null, null, | |
127 System.out, System.err); | |
128 System.err.println("### started D ###"); | |
129 process.join(); | |
130 } catch (InterruptedException e) { | |
131 e.printStackTrace(); | |
132 } catch (IOException e) { | |
133 e.printStackTrace(); | |
134 } | |
135 } | |
136 }.start(); | |
137 | |
138 try{ | |
139 Thread.sleep( 200 ); | |
140 System.err.println("--- starting connection ----"); | |
141 dc = new DirectConnection(address + ",listen=true"); | |
142 System.err.println("----------------------------"); | |
143 | |
144 DataFileSystem rem = (DataFileSystem) dc.getRemoteObject( | |
145 "/DHelper/MyDataFileSystem/0", DataFileSystem.class); | |
146 | |
147 new FileTree(rem).run(); | |
148 | |
149 } | |
150 finally{ | |
151 dc.disconnect(); | |
152 } | |
153 } | |
154 } | |
155 | |
156 | |
157 |