|
Added
Link Here
|
| 1 |
/********************************************************************** |
| 2 |
* Copyright (c) 2006, 2007 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* $Id: TPTPJUnitTestSuiteGenerationPane.java,v 1.5 2007/04/19 18:43:36 paules Exp $ |
| 8 |
* |
| 9 |
* Contributors: |
| 10 |
* IBM - Initial API and implementation |
| 11 |
**********************************************************************/ |
| 12 |
package org.eclipse.tptp.test.tools.api.internal.ui.test.generation; |
| 13 |
|
| 14 |
import java.util.Collections; |
| 15 |
|
| 16 |
import org.eclipse.core.resources.IFile; |
| 17 |
import org.eclipse.core.runtime.IPath; |
| 18 |
import org.eclipse.core.runtime.Path; |
| 19 |
import org.eclipse.emf.common.ui.dialogs.WorkspaceResourceDialog; |
| 20 |
import org.eclipse.jface.layout.GridDataFactory; |
| 21 |
import org.eclipse.swt.SWT; |
| 22 |
import org.eclipse.swt.events.SelectionAdapter; |
| 23 |
import org.eclipse.swt.events.SelectionEvent; |
| 24 |
import org.eclipse.swt.graphics.Color; |
| 25 |
import org.eclipse.swt.layout.GridData; |
| 26 |
import org.eclipse.swt.layout.GridLayout; |
| 27 |
import org.eclipse.swt.widgets.Button; |
| 28 |
import org.eclipse.swt.widgets.Combo; |
| 29 |
import org.eclipse.swt.widgets.Composite; |
| 30 |
import org.eclipse.swt.widgets.Group; |
| 31 |
import org.eclipse.swt.widgets.Label; |
| 32 |
import org.eclipse.swt.widgets.Text; |
| 33 |
|
| 34 |
/** |
| 35 |
* TPTP JUnit test suite generation pane. |
| 36 |
* <p> |
| 37 |
* |
| 38 |
* |
| 39 |
* @author Paul E. Slauenwhite |
| 40 |
* @version November 15, 2006 |
| 41 |
* @since September 7, 2006 |
| 42 |
* @provisional |
| 43 |
*/ |
| 44 |
public class TPTPJUnitTestSuiteGenerationPaneAPI extends Composite { |
| 45 |
|
| 46 |
private Text testSuiteLocationText = null; |
| 47 |
private Combo testSuiteGeneratorCombo = null; |
| 48 |
private Button testSuiteLocationButton = null; |
| 49 |
|
| 50 |
public TPTPJUnitTestSuiteGenerationPaneAPI(Composite parent){ |
| 51 |
this(parent, SWT.SHADOW_NONE); |
| 52 |
} |
| 53 |
|
| 54 |
public TPTPJUnitTestSuiteGenerationPaneAPI(Composite parent, int style){ |
| 55 |
|
| 56 |
super(parent, style); |
| 57 |
|
| 58 |
buildPane(); |
| 59 |
} |
| 60 |
|
| 61 |
public Combo getTestSuiteGeneratorCombo() { |
| 62 |
return testSuiteGeneratorCombo; |
| 63 |
} |
| 64 |
|
| 65 |
public Text getTestSuiteLocationText() { |
| 66 |
return testSuiteLocationText; |
| 67 |
} |
| 68 |
|
| 69 |
public void init(){ |
| 70 |
|
| 71 |
testSuiteGeneratorCombo.select(0); |
| 72 |
|
| 73 |
testSuiteLocationText.setEnabled(false); |
| 74 |
testSuiteLocationText.setText(""); |
| 75 |
|
| 76 |
//Work-around: Set the text field's background color to gray since disabled/enabled un-editable text fields have a gray background, by default. |
| 77 |
testSuiteLocationText.setBackground(((Color)(testSuiteGeneratorCombo.getData("Background")))); |
| 78 |
|
| 79 |
testSuiteLocationButton.setEnabled(false); |
| 80 |
} |
| 81 |
|
| 82 |
private void buildPane(){ |
| 83 |
|
| 84 |
setLayout(new GridLayout()); |
| 85 |
setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 86 |
|
| 87 |
GridLayout layout = new GridLayout(); |
| 88 |
layout.numColumns = 3; |
| 89 |
layout.horizontalSpacing = 5; |
| 90 |
layout.verticalSpacing = 10; |
| 91 |
|
| 92 |
Group testGroup = new Group(this, SWT.SHADOW_ETCHED_IN); |
| 93 |
testGroup.setLayout(layout); |
| 94 |
testGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 95 |
testGroup.setText("Test suite generator and location"); |
| 96 |
|
| 97 |
Label testSuiteGeneratorLabel = new Label(testGroup, SWT.NONE); |
| 98 |
testSuiteGeneratorLabel.setText("Generator: "); |
| 99 |
|
| 100 |
testSuiteGeneratorCombo = new Combo(testGroup, SWT.READ_ONLY); |
| 101 |
testSuiteGeneratorCombo.setLayoutData(GridDataFactory.fillDefaults().span(2, 1).grab(true, false).create()); |
| 102 |
testSuiteGeneratorCombo.add("Do not generate test suite"); |
| 103 |
testSuiteGeneratorCombo.add("TPTP JUnit Test Suite Generator"); |
| 104 |
testSuiteGeneratorCombo.addSelectionListener(new SelectionAdapter() { |
| 105 |
|
| 106 |
public void widgetSelected(SelectionEvent e) { |
| 107 |
|
| 108 |
if(testSuiteGeneratorCombo.getSelectionIndex() != 0){ |
| 109 |
|
| 110 |
testSuiteLocationButton.setEnabled(true); |
| 111 |
|
| 112 |
testSuiteLocationText.setEnabled(true); |
| 113 |
|
| 114 |
//Work-around: Set the text field's background color to white since disabled/enabled un-editable text fields have a gray background, by default. |
| 115 |
testSuiteLocationText.setBackground(testSuiteGeneratorCombo.getBackground()); |
| 116 |
} |
| 117 |
else{ |
| 118 |
init(); |
| 119 |
} |
| 120 |
} |
| 121 |
}); |
| 122 |
|
| 123 |
//TODO: Create extension point for user-defined test suite generators: |
| 124 |
// IConfigurationElement[] elements = |
| 125 |
// Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.hyades.test.core.TestGenerator"); |
| 126 |
// for(int i = 0; i < elements.length; i++) { |
| 127 |
// String name = elements[i].getAttribute("name"); |
| 128 |
// testSuiteGeneratorCombo.add(name); |
| 129 |
// } |
| 130 |
|
| 131 |
Label testSuiteLocationLabel = new Label(testGroup, SWT.NONE); |
| 132 |
testSuiteLocationLabel.setText("Location: "); |
| 133 |
|
| 134 |
testSuiteLocationText = new Text(testGroup, SWT.SINGLE | SWT.BORDER); |
| 135 |
testSuiteLocationText.setEditable(false); |
| 136 |
testSuiteLocationText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).create()); |
| 137 |
|
| 138 |
//Work-around: Persist the text field's background original color since disabled/enabled un-editable text fields have a gray background, by default. |
| 139 |
testSuiteLocationText.setData("Background",testSuiteLocationText.getBackground()); |
| 140 |
|
| 141 |
testSuiteLocationButton = new Button(testGroup, SWT.PUSH); |
| 142 |
testSuiteLocationButton.setText("Browse..."); |
| 143 |
|
| 144 |
testSuiteLocationButton.addSelectionListener(new SelectionAdapter() { |
| 145 |
|
| 146 |
public void widgetSelected(SelectionEvent e) { |
| 147 |
|
| 148 |
//TODO: Use standard Eclipse/TPTP dialog: |
| 149 |
//TODO: Only select Java and Pluign projects. |
| 150 |
//TODO: Use UIUtil.validateJavaFileName and UIUtil.validateOSFileName: |
| 151 |
//TODO: Check for existing file and do not allow user to overwrite: |
| 152 |
//TODO: Create new directory?: |
| 153 |
IPath path = null; |
| 154 |
String testSuiteLocationPath = testSuiteLocationText.getText().trim(); |
| 155 |
|
| 156 |
if((testSuiteLocationPath.length() > 0) && (Path.EMPTY.isValidPath(testSuiteLocationPath))){ |
| 157 |
path = new Path(testSuiteLocationPath); |
| 158 |
} |
| 159 |
|
| 160 |
//TODO: If project does not exist, only set file name: |
| 161 |
//TODO: Set text field to "" if file is null and cancel is selected: |
| 162 |
IFile testSuiteLocationFile = WorkspaceResourceDialog.openNewFile( |
| 163 |
testSuiteLocationButton.getParent().getShell(), |
| 164 |
"Test Suite", |
| 165 |
"Select a test suite location under a Java project:", |
| 166 |
path, |
| 167 |
Collections.EMPTY_LIST); |
| 168 |
|
| 169 |
if(testSuiteLocationFile != null){ |
| 170 |
|
| 171 |
testSuiteLocationPath = testSuiteLocationFile.getFullPath().toString(); |
| 172 |
|
| 173 |
if(!testSuiteLocationPath.endsWith(".testsuite")){ |
| 174 |
testSuiteLocationText.setText(testSuiteLocationPath.concat(".testsuite")); |
| 175 |
} |
| 176 |
else{ |
| 177 |
testSuiteLocationText.setText(testSuiteLocationPath); |
| 178 |
} |
| 179 |
} |
| 180 |
} |
| 181 |
}); |
| 182 |
|
| 183 |
init(); |
| 184 |
|
| 185 |
layout(false,true); |
| 186 |
} |
| 187 |
} |