Revision 1625

tmp/org.txm.tests.rcp/plugin.xml (revision 1625)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?eclipse version="3.4"?>
3
<plugin>
4
   <extension
5
         point="org.eclipse.ui.editors">
6
      <editor
7
            class="org.txm.tests.rcp.editor.TestsEditor"
8
            default="false"
9
            id="org.txm.tests.rcp.editor.TestsEditor"
10
            name="Tests">
11
      </editor>
12
   </extension>
13
   <extension
14
         point="org.eclipse.ui.menus">
15
      <menuContribution
16
            allPopups="false"
17
            locationURI="menu:menu.tools">
18
         <command
19
               commandId="org.txm.tests.rcp.command.OpenTestsBench"
20
               style="push">
21
         </command>
22
      </menuContribution>
23
   </extension>
24
   <extension
25
         point="org.eclipse.ui.commands">
26
      <command
27
            defaultHandler="org.txm.tests.rcp.command.OpenTestsBench"
28
            id="org.txm.tests.rcp.command.OpenTestsBench"
29
            name="Open Tests bench">
30
      </command>
31
   </extension>
32

  
33
</plugin>
0 34

  
tmp/org.txm.tests.rcp/.settings/org.eclipse.jdt.core.prefs (revision 1625)
1
eclipse.preferences.version=1
2
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
4
org.eclipse.jdt.core.compiler.compliance=1.7
5
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7
org.eclipse.jdt.core.compiler.source=1.7
0 8

  
tmp/org.txm.tests.rcp/.classpath (revision 1625)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
3
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
4
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
5
		<accessrules>
6
			<accessrule kind="accessible" pattern="**"/>
7
		</accessrules>
8
	</classpathentry>
9
	<classpathentry kind="src" path="src"/>
10
	<classpathentry kind="output" path="bin"/>
11
</classpath>
0 12

  
tmp/org.txm.tests.rcp/META-INF/MANIFEST.MF (revision 1625)
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
3
Bundle-Name: Tests
4
Bundle-SymbolicName: org.txm.tests.rcp;singleton:=true
5
Bundle-Version: 1.0.0.qualifier
6
Automatic-Module-Name: org.txm.tests.rcp
7
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
8
Require-Bundle: org.txm.rcp;bundle-version="0.8.0";visibility:=reexport,
9
 org.txm.tests.core;bundle-version="1.0.0";visibility:=reexport
0 10

  
tmp/org.txm.tests.rcp/.project (revision 1625)
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>org.txm.tests.rcp</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
		<buildCommand>
14
			<name>org.eclipse.pde.ManifestBuilder</name>
15
			<arguments>
16
			</arguments>
17
		</buildCommand>
18
		<buildCommand>
19
			<name>org.eclipse.pde.SchemaBuilder</name>
20
			<arguments>
21
			</arguments>
22
		</buildCommand>
23
	</buildSpec>
24
	<natures>
25
		<nature>org.eclipse.pde.PluginNature</nature>
26
		<nature>org.eclipse.jdt.core.javanature</nature>
27
	</natures>
28
</projectDescription>
0 29

  
tmp/org.txm.tests.rcp/src/org/txm/tests/rcp/command/OpenTestsBench.java (revision 1625)
1
package org.txm.tests.rcp.command;
2

  
3
import org.eclipse.core.commands.AbstractHandler;
4
import org.eclipse.core.commands.ExecutionEvent;
5
import org.eclipse.core.commands.ExecutionException;
6
import org.eclipse.ui.IEditorPart;
7
import org.eclipse.ui.IWorkbenchPage;
8
import org.eclipse.ui.IWorkbenchWindow;
9
import org.eclipse.ui.PartInitException;
10
import org.eclipse.ui.PlatformUI;
11
import org.txm.core.results.TXMResult;
12
import org.txm.rcp.editors.TXMResultEditorInput;
13
import org.txm.tests.rcp.editor.TestsEditor;
14

  
15
public class OpenTestsBench extends AbstractHandler {
16

  
17
	@Override
18
	public Object execute(ExecutionEvent event) throws ExecutionException {
19
		
20
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
21
		IWorkbenchPage page = window.getActivePage();
22

  
23
		try {
24
			IEditorPart e = page.openEditor(new TXMResultEditorInput<TXMResult>(null), TestsEditor.class.getName(), true);
25
			if (e != null && e instanceof TestsEditor) {
26
				TestsEditor editor = (TestsEditor) e;
27
			}
28
		} catch (PartInitException e) {
29
			// TODO Auto-generated catch block
30
			e.printStackTrace();
31
		}
32
		return null;
33
	}
34
}
0 35

  
tmp/org.txm.tests.rcp/src/org/txm/tests/rcp/editor/TestsEditor.java (revision 1625)
1
package org.txm.tests.rcp.editor;
2

  
3
import java.io.File;
4
import java.io.IOException;
5
import java.util.HashSet;
6

  
7
import org.eclipse.core.runtime.IProgressMonitor;
8
import org.eclipse.jface.dialogs.InputDialog;
9
import org.eclipse.swt.SWT;
10
import org.eclipse.swt.events.SelectionEvent;
11
import org.eclipse.swt.events.SelectionListener;
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.Label;
17
import org.eclipse.swt.widgets.ToolBar;
18
import org.eclipse.swt.widgets.ToolItem;
19
import org.eclipse.ui.IEditorInput;
20
import org.eclipse.ui.IEditorSite;
21
import org.eclipse.ui.PartInitException;
22
import org.eclipse.ui.part.EditorPart;
23
import org.txm.Toolbox;
24
import org.txm.rcp.IImageKeys;
25
import org.txm.rcp.commands.tests.Test;
26
import org.txm.rcp.commands.tests.TestBench;
27
import org.txm.rcp.handlers.files.EditFile;
28

  
29
public class TestsEditor extends EditorPart {
30

  
31
	private TestBench bench;
32
	private Composite parent;
33
	private HashSet<TestComposite> testComposites = new HashSet<TestComposite>();
34

  
35
	public TestsEditor() {
36
		File dir = new File(Toolbox.getTxmHomePath(), "scripts/groovy/user/org/txm/scripts/tests");
37
		dir.mkdirs();
38
		bench = new TestBench(dir);
39
	}
40

  
41
	@Override
42
	public void doSave(IProgressMonitor monitor) { }
43

  
44
	@Override
45
	public void doSaveAs() { }
46

  
47
	@Override
48
	public void init(IEditorSite site, IEditorInput input) throws PartInitException {
49
		this.setSite(site);
50
		this.setInput(input);
51
		this.setPartName("Tests");
52
	}
53

  
54
	@Override
55
	public boolean isDirty() {
56
		return false;
57
	}
58

  
59
	@Override
60
	public boolean isSaveAsAllowed() {
61
		return false;
62
	}
63

  
64
	@Override
65
	public void createPartControl(Composite aparent) {
66
		this.parent = aparent;
67
		
68
		GridLayout glayout = new GridLayout(8, false);
69
		parent.setLayout(glayout);
70
		
71
		
72
		ToolBar bar = new ToolBar(parent, SWT.HORIZONTAL);
73
		GridData gdata = new GridData(GridData.FILL, GridData.CENTER, true, false, 8, 1);
74
		bar.setLayoutData(gdata);
75
		
76
		ToolItem addItem = new ToolItem(bar, SWT.PUSH);
77
		addItem.setText("New test");
78
		addItem.addSelectionListener(new SelectionListener() {
79
			
80
			@Override
81
			public void widgetSelected(SelectionEvent e) {
82
				InputDialog d = new InputDialog(e.display.getActiveShell(), "Enter test Name", "Test name", "test", null);
83
				if (d.open() == InputDialog.OK) {
84
					String name = d.getValue();
85
					if (name != null && name.length() > 0) {
86
						name = name.toLowerCase();
87
						if (bench.getTest(name) == null) {
88
							Test test = bench.newTest(name);
89
							new TestComposite(test);
90
							parent.layout();
91
							parent.getParent().layout();
92
						}
93
					}
94
				}
95
			}
96
			
97
			@Override
98
			public void widgetDefaultSelected(SelectionEvent e) { }
99
		});
100
		
101
		ToolItem resetAllItem = new ToolItem(bar, SWT.PUSH);
102
		resetAllItem.setText("Reset all");
103
		resetAllItem.addSelectionListener(new SelectionListener() {
104
			
105
			@Override
106
			public void widgetSelected(SelectionEvent e) {
107
				for (Test test : bench.getTests().values()) {
108
					try {
109
						test.reset();
110
					} catch(Exception ex) {
111
						ex.printStackTrace();
112
					}
113
				}
114
				
115
				for (TestComposite tc : testComposites) {
116
					tc.refresh();
117
				}
118
			}
119
			
120
			@Override
121
			public void widgetDefaultSelected(SelectionEvent e) { }
122
		});
123
		
124
		ToolItem runAllItem = new ToolItem(bar, SWT.PUSH);
125
		runAllItem.setText("Run all");
126
		runAllItem.addSelectionListener(new SelectionListener() {
127
			
128
			@Override
129
			public void widgetSelected(SelectionEvent e) {
130
				for (Test test : bench.getTests().values()) {
131
					try {
132
						test.run(0);
133
					} catch(Exception ex) {
134
						ex.printStackTrace();
135
					}
136
				}
137
				
138
				for (TestComposite tc : testComposites) {
139
					tc.refresh();
140
				}
141
			}
142
			
143
			@Override
144
			public void widgetDefaultSelected(SelectionEvent e) { }
145
		});
146
		
147
		new Label(parent, SWT.NONE).setText("");
148
		new Label(parent, SWT.NONE).setText("Create");
149
		new Label(parent, SWT.NONE).setText("edit");
150
		new Label(parent, SWT.NONE).setText("Export");
151
		new Label(parent, SWT.NONE).setText("edit");
152
		new Label(parent, SWT.NONE).setText("Test");
153
		new Label(parent, SWT.NONE).setText("edit");
154
		new Label(parent, SWT.NONE).setText(" ");
155
		
156
		for (Test test : bench.getTests().values()) {
157
			test.reset();
158
			TestComposite tc = new TestComposite(test);
159
			testComposites.add(tc);
160
		}
161
	}
162

  
163
	@Override
164
	public void setFocus() { }
165

  
166
	public class TestComposite {
167
		
168
		Label nameLabel;
169
		Button runCreateButton, runExportButton, runTestButton;
170
		Button editCreateButton, editExportButton, editTestButton;
171
		Button deleteTestButton;
172
		
173
		Test test;
174
		
175
		public TestComposite(Test atest) {
176
			
177
			this.test = atest;
178
			
179
			nameLabel = new Label(parent, SWT.NONE);
180
			nameLabel.setText(test.getName());
181
			
182
			
183
			runCreateButton = new Button(parent, SWT.PUSH);
184
			runCreateButton.addSelectionListener(new SelectionListener() {
185
				
186
				@Override
187
				public void widgetSelected(SelectionEvent e) {
188
					test.run(0);
189
					refresh();
190
				}
191
				
192
				@Override
193
				public void widgetDefaultSelected(SelectionEvent e) { }
194
			});
195
			editCreateButton = new Button(parent, SWT.PUSH);
196
			editCreateButton.setText("...");
197
			editCreateButton.addSelectionListener(new SelectionListener() {
198
				
199
				@Override
200
				public void widgetSelected(SelectionEvent e) {
201
					File newfile = new File(test.getDirectory(), "create.groovy");
202
					try {
203
						newfile.createNewFile();
204
					} catch (IOException e1) { }
205
					EditFile.openfile(newfile);
206
					refresh();
207
				}
208
				
209
				@Override
210
				public void widgetDefaultSelected(SelectionEvent e) { }
211
			});
212
			
213
			
214
			runExportButton = new Button(parent, SWT.PUSH);
215
			runExportButton.addSelectionListener(new SelectionListener() {
216
				
217
				@Override
218
				public void widgetSelected(SelectionEvent e) {
219
					test.run(1);
220
					refresh();
221
				}
222
				
223
				@Override
224
				public void widgetDefaultSelected(SelectionEvent e) { }
225
			});
226
			editExportButton = new Button(parent, SWT.PUSH);
227
			editExportButton.setText("...");
228
			editExportButton.addSelectionListener(new SelectionListener() {
229
				
230
				@Override
231
				public void widgetSelected(SelectionEvent e) {
232
					File newfile = new File(test.getDirectory(), "export.groovy");
233
					try {
234
						newfile.createNewFile();
235
					} catch (IOException e1) { }
236
					EditFile.openfile(newfile);
237
					refresh();
238
				}
239
				
240
				@Override
241
				public void widgetDefaultSelected(SelectionEvent e) { }
242
			});
243
			
244
			runTestButton = new Button(parent, SWT.PUSH);
245
			runTestButton.addSelectionListener(new SelectionListener() {
246
				
247
				@Override
248
				public void widgetSelected(SelectionEvent e) {
249
					test.run(2);
250
					refresh();
251
				}
252
				
253
				@Override
254
				public void widgetDefaultSelected(SelectionEvent e) { }
255
			});
256
			editTestButton = new Button(parent, SWT.PUSH);
257
			editTestButton.setText("...");
258
			editTestButton.addSelectionListener(new SelectionListener() {
259
				
260
				@Override
261
				public void widgetSelected(SelectionEvent e) {
262
					File newfile = new File(test.getDirectory(), "test.groovy");
263
					try {
264
						newfile.createNewFile();
265
					} catch (IOException e1) { }
266
					EditFile.openfile(newfile);
267
					refresh();
268
				}
269
				
270
				@Override
271
				public void widgetDefaultSelected(SelectionEvent e) { }
272
			});
273
			
274
			
275
			deleteTestButton = new Button(parent, SWT.PUSH);
276
			deleteTestButton.setImage(IImageKeys.getImage(IImageKeys.ACTION_DELETE));
277
			deleteTestButton.addSelectionListener(new SelectionListener() {
278
				
279
				@Override
280
				public void widgetSelected(SelectionEvent e) {
281
					nameLabel.dispose();
282
					runCreateButton.dispose();
283
					runExportButton.dispose();
284
					runTestButton.dispose();
285
					editCreateButton.dispose();
286
					editExportButton.dispose();
287
					editTestButton.dispose();
288
					deleteTestButton.dispose();
289
					
290
					bench.deleteTest(test.getName());
291
					
292
					parent.layout(true);
293
					
294
					testComposites.remove(TestComposite.this);
295
				}
296
				
297
				@Override
298
				public void widgetDefaultSelected(SelectionEvent e) { }
299
			});
300
			refresh();
301
		}
302
		
303
		public void refresh() {
304
			runCreateButton.setEnabled(test.hasCreateStep());
305
			runCreateButton.setText(test.isCreateStepOK()?" OK ":"NOPE");
306
			
307
			runExportButton.setEnabled(test.hasExportStep());
308
			runExportButton.setText(test.isExportStepOK()?" OK ":"NOPE");
309
			
310
			runTestButton.setEnabled(test.hasTestStep());
311
			runTestButton.setText(test.isTestStepOK()?" OK ":"NOPE");
312
		}
313
	}
314
}
0 315

  
tmp/org.txm.tests.rcp/build.properties (revision 1625)
1
source.. = src/
2
output.. = bin/
3
bin.includes = META-INF/,\
4
               .,\
5
               plugin.xml
0 6

  

Also available in: Unified diff