|
Lines 11-39
Link Here
|
| 11 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
| 12 |
package org.eclipse.hyades.test.tools.ui.java.internal.junit.wizard; |
12 |
package org.eclipse.hyades.test.tools.ui.java.internal.junit.wizard; |
| 13 |
|
13 |
|
|
|
14 |
import java.util.ArrayList; |
| 15 |
import java.util.Iterator; |
| 14 |
import java.util.List; |
16 |
import java.util.List; |
| 15 |
|
17 |
|
| 16 |
import org.eclipse.core.resources.ResourcesPlugin; |
18 |
import org.eclipse.core.resources.ResourcesPlugin; |
|
|
19 |
import org.eclipse.core.runtime.IAdaptable; |
| 20 |
import org.eclipse.core.runtime.Platform; |
| 21 |
import org.eclipse.hyades.test.tools.core.internal.java.modelsync.JUnitExtensionsRegistry; |
| 22 |
import org.eclipse.hyades.test.tools.core.internal.java.modelsync.JUnitExtensionsRegistry.JUnitTestSuiteFactoryDescriptor; |
| 23 |
import org.eclipse.hyades.test.tools.core.java.IJUnitTestSuiteFactory; |
| 17 |
import org.eclipse.hyades.test.tools.ui.ToolsUiPlugin; |
24 |
import org.eclipse.hyades.test.tools.ui.ToolsUiPlugin; |
|
|
25 |
import org.eclipse.hyades.test.ui.TestUIExtension; |
| 26 |
import org.eclipse.hyades.ui.HyadesUIPlugin; |
| 27 |
import org.eclipse.hyades.ui.extension.IAssociationDescriptor; |
| 28 |
import org.eclipse.hyades.ui.extension.IAssociationMapping; |
| 29 |
import org.eclipse.hyades.ui.internal.extension.AssociationMappingRegistry; |
| 18 |
import org.eclipse.hyades.ui.util.TreeSelector; |
30 |
import org.eclipse.hyades.ui.util.TreeSelector; |
| 19 |
import org.eclipse.jdt.core.ICompilationUnit; |
31 |
import org.eclipse.jdt.core.ICompilationUnit; |
| 20 |
import org.eclipse.jdt.core.IJavaModel; |
32 |
import org.eclipse.jdt.core.IJavaModel; |
| 21 |
import org.eclipse.jdt.core.JavaCore; |
33 |
import org.eclipse.jdt.core.JavaCore; |
| 22 |
import org.eclipse.jdt.ui.JavaElementLabelProvider; |
34 |
import org.eclipse.jdt.ui.JavaElementLabelProvider; |
|
|
35 |
import org.eclipse.jface.dialogs.IDialogSettings; |
| 23 |
import org.eclipse.jface.viewers.CheckStateChangedEvent; |
36 |
import org.eclipse.jface.viewers.CheckStateChangedEvent; |
|
|
37 |
import org.eclipse.jface.viewers.ComboViewer; |
| 24 |
import org.eclipse.jface.viewers.ICheckStateListener; |
38 |
import org.eclipse.jface.viewers.ICheckStateListener; |
|
|
39 |
import org.eclipse.jface.viewers.ISelection; |
| 40 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
| 41 |
import org.eclipse.jface.viewers.IStructuredContentProvider; |
| 42 |
import org.eclipse.jface.viewers.IStructuredSelection; |
| 43 |
import org.eclipse.jface.viewers.LabelProvider; |
| 44 |
import org.eclipse.jface.viewers.SelectionChangedEvent; |
| 45 |
import org.eclipse.jface.viewers.StructuredSelection; |
| 46 |
import org.eclipse.jface.viewers.Viewer; |
| 25 |
import org.eclipse.jface.wizard.WizardPage; |
47 |
import org.eclipse.jface.wizard.WizardPage; |
| 26 |
import org.eclipse.swt.SWT; |
48 |
import org.eclipse.swt.SWT; |
|
|
49 |
import org.eclipse.swt.graphics.Image; |
| 27 |
import org.eclipse.swt.layout.GridData; |
50 |
import org.eclipse.swt.layout.GridData; |
| 28 |
import org.eclipse.swt.layout.GridLayout; |
51 |
import org.eclipse.swt.layout.GridLayout; |
| 29 |
import org.eclipse.swt.widgets.Composite; |
52 |
import org.eclipse.swt.widgets.Composite; |
|
|
53 |
import org.eclipse.swt.widgets.Label; |
| 30 |
|
54 |
|
| 31 |
/** |
55 |
/** |
| 32 |
* @author jgout |
56 |
* @author jgout |
| 33 |
*/ |
57 |
*/ |
| 34 |
public class JUnitScriptsSelectionPage extends WizardPage implements ICheckStateListener { |
58 |
public class JUnitScriptsSelectionPage extends WizardPage implements ICheckStateListener { |
| 35 |
|
59 |
|
| 36 |
private TreeSelector selector; |
60 |
private static final String DS_TYPE = "type"; //$NON-NLS-1$ |
|
|
61 |
|
| 62 |
private TreeSelector selector; |
| 63 |
private ComboViewer testFactoryList; |
| 64 |
private JUnitWorkspaceContentProvider contentProvider; |
| 65 |
protected List initialSelection; |
| 37 |
|
66 |
|
| 38 |
public JUnitScriptsSelectionPage() { |
67 |
public JUnitScriptsSelectionPage() { |
| 39 |
super("JUnitScriptSelectionPage"); //$NON-NLS-1$ |
68 |
super("JUnitScriptSelectionPage"); //$NON-NLS-1$ |
|
Lines 45-68
Link Here
|
| 45 |
public void createControl(Composite parent) { |
74 |
public void createControl(Composite parent) { |
| 46 |
initializeDialogUnits(parent); |
75 |
initializeDialogUnits(parent); |
| 47 |
Composite composite = new Composite(parent, SWT.NULL); |
76 |
Composite composite = new Composite(parent, SWT.NULL); |
| 48 |
GridLayout gl = new GridLayout(); |
77 |
GridLayout gl = new GridLayout(2, false); |
| 49 |
gl.numColumns = 1; |
|
|
| 50 |
composite.setLayout(gl); |
78 |
composite.setLayout(gl); |
| 51 |
composite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL)); |
79 |
gl.verticalSpacing = 20; |
|
|
80 |
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
| 52 |
composite.setFont(parent.getFont()); |
81 |
composite.setFont(parent.getFont()); |
|
|
82 |
|
| 83 |
Label label = new Label(composite, SWT.NONE); |
| 84 |
label.setText("Destination type:"); |
| 85 |
label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); |
| 86 |
testFactoryList = new ComboViewer(composite, SWT.DROP_DOWN | SWT.READ_ONLY); |
| 87 |
testFactoryList.getControl().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); |
| 88 |
testFactoryList.setContentProvider(new IStructuredContentProvider() { |
| 89 |
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
| 90 |
// n/a |
| 91 |
} |
| 92 |
public void dispose() { |
| 93 |
// NOP |
| 94 |
} |
| 95 |
public Object[] getElements(Object inputElement) { |
| 96 |
return JUnitExtensionsRegistry.getInstance().getAvailableFactories(/*updateSupport*/false); |
| 97 |
} |
| 98 |
}); |
| 99 |
testFactoryList.setLabelProvider(new LabelProvider() { |
| 100 |
public String getText(Object element) { |
| 101 |
String type = ((JUnitExtensionsRegistry.JUnitTestSuiteFactoryDescriptor)element).getType(); |
| 102 |
AssociationMappingRegistry registry = (AssociationMappingRegistry)TestUIExtension.getTestSuiteMappingRegistry(); |
| 103 |
IAssociationMapping associationMapping = registry.getAssociationMapping(HyadesUIPlugin.EP_TYPE_DESCRIPTIONS); |
| 104 |
IAssociationDescriptor descriptor = associationMapping.getDefaultAssociationDescriptor(type); |
| 105 |
return descriptor.getName(); |
| 106 |
} |
| 107 |
public Image getImage(Object element) { |
| 108 |
String type = ((JUnitExtensionsRegistry.JUnitTestSuiteFactoryDescriptor)element).getType(); |
| 109 |
AssociationMappingRegistry registry = (AssociationMappingRegistry)TestUIExtension.getTestSuiteMappingRegistry(); |
| 110 |
IAssociationMapping associationMapping = registry.getAssociationMapping(HyadesUIPlugin.EP_TYPE_DESCRIPTIONS); |
| 111 |
IAssociationDescriptor descriptor = associationMapping.getDefaultAssociationDescriptor(type); |
| 112 |
return descriptor.getImage(); |
| 113 |
} |
| 114 |
}); |
| 115 |
testFactoryList.setInput(ResourcesPlugin.getWorkspace().getRoot()); |
| 116 |
testFactoryList.addSelectionChangedListener(new ISelectionChangedListener() { |
| 117 |
public void selectionChanged(SelectionChangedEvent event) { |
| 118 |
IJUnitTestSuiteFactory factory = getTestSuiteFactory(); |
| 119 |
if (factory != null) { |
| 120 |
contentProvider.setJUnitTestSuiteFactory(factory); |
| 121 |
List checkedElements; |
| 122 |
if (initialSelection != null) { |
| 123 |
checkedElements = initialSelection; |
| 124 |
initialSelection = null; |
| 125 |
} else { |
| 126 |
checkedElements = selector.getSelectedElements(); |
| 127 |
} |
| 128 |
IJavaModel javaWorkspace = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); |
| 129 |
selector.setInput(null); |
| 130 |
selector.setInput(javaWorkspace); |
| 131 |
selector.setInitialCheckedElements(checkedElements); |
| 132 |
setPageComplete(true); |
| 133 |
setErrorMessage(null); |
| 134 |
} else { |
| 135 |
selector.setInput(null); |
| 136 |
setPageComplete(false); |
| 137 |
setErrorMessage("The selected generator has encountered an internal error"); |
| 138 |
} |
| 139 |
} |
| 140 |
}); |
| 141 |
|
| 53 |
//- build the selection widget |
142 |
//- build the selection widget |
| 54 |
IJavaModel javaWorkspace = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); |
143 |
IJavaModel javaWorkspace = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); |
| 55 |
JavaElementLabelProvider javaLabelProvider = new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT); |
144 |
JavaElementLabelProvider javaLabelProvider = new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT); |
| 56 |
JUnitWorkspaceContentProvider contentProvider = createContentProvider(); |
145 |
contentProvider = new JUnitWorkspaceContentProvider(); |
| 57 |
selector = new TreeSelector(composite, javaWorkspace, contentProvider, javaLabelProvider, SWT.BORDER); |
146 |
selector = new TreeSelector(composite, javaWorkspace, contentProvider, javaLabelProvider, SWT.BORDER); |
| 58 |
contentProvider.setRunnableContext(this.getContainer()); |
147 |
contentProvider.setRunnableContext(this.getContainer()); |
| 59 |
selector.getTreeViewer().addCheckStateListener(this); |
148 |
selector.getTreeViewer().addCheckStateListener(this); |
|
|
149 |
selector.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); |
| 150 |
|
| 151 |
readDialogSettings(); |
| 152 |
|
| 60 |
setPageComplete(false); |
153 |
setPageComplete(false); |
| 61 |
setControl(composite); |
154 |
setControl(composite); |
| 62 |
} |
155 |
} |
| 63 |
|
156 |
|
| 64 |
protected JUnitWorkspaceContentProvider createContentProvider() { |
157 |
protected void init(IStructuredSelection selection) { |
| 65 |
return new JUnitWorkspaceContentProvider(); |
158 |
Iterator it = selection.iterator(); |
|
|
159 |
initialSelection = new ArrayList(selection.size()); |
| 160 |
while (it.hasNext()) { |
| 161 |
Object o = it.next(); |
| 162 |
if (o instanceof IAdaptable) { |
| 163 |
ICompilationUnit cu = (ICompilationUnit) ((IAdaptable)o).getAdapter(ICompilationUnit.class); |
| 164 |
if (cu != null) { |
| 165 |
initialSelection.add(cu); |
| 166 |
} |
| 167 |
} |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
protected IJUnitTestSuiteFactory getTestSuiteFactory() { |
| 172 |
ISelection selection = testFactoryList.getSelection(); |
| 173 |
if (selection instanceof IStructuredSelection) { |
| 174 |
JUnitExtensionsRegistry.JUnitTestSuiteFactoryDescriptor descr = |
| 175 |
(JUnitExtensionsRegistry.JUnitTestSuiteFactoryDescriptor) ((IStructuredSelection)selection).getFirstElement(); |
| 176 |
if (descr != null) { |
| 177 |
return descr.getFactory(); |
| 178 |
} |
| 179 |
} |
| 180 |
return null; |
| 181 |
} |
| 182 |
|
| 183 |
public String getSelectedType() { |
| 184 |
ISelection selection = testFactoryList.getSelection(); |
| 185 |
if (selection instanceof IStructuredSelection) { |
| 186 |
JUnitTestSuiteFactoryDescriptor descr = |
| 187 |
(JUnitTestSuiteFactoryDescriptor) ((IStructuredSelection)selection).getFirstElement(); |
| 188 |
if (descr != null) { |
| 189 |
return descr.getType(); |
| 190 |
} |
| 191 |
} |
| 192 |
return null; |
| 193 |
} |
| 194 |
|
| 195 |
public void setSelectedType(String type) { |
| 196 |
JUnitTestSuiteFactoryDescriptor descr = JUnitExtensionsRegistry.getInstance().getDescriptor(type); |
| 197 |
if (descr != null) { |
| 198 |
testFactoryList.setSelection(new StructuredSelection(descr)); |
| 199 |
} else { |
| 200 |
testFactoryList.setSelection(StructuredSelection.EMPTY); |
| 201 |
} |
| 66 |
} |
202 |
} |
| 67 |
|
203 |
|
| 68 |
public List getSelectedElements() { |
204 |
public List getSelectedElements() { |
|
Lines 72-75
Link Here
|
| 72 |
public void checkStateChanged(CheckStateChangedEvent event) { |
208 |
public void checkStateChanged(CheckStateChangedEvent event) { |
| 73 |
setPageComplete(selector.getSelectedElements().size() != 0); |
209 |
setPageComplete(selector.getSelectedElements().size() != 0); |
| 74 |
} |
210 |
} |
|
|
211 |
|
| 212 |
protected IDialogSettings getDialogSettings() { |
| 213 |
IDialogSettings pluginSettings = ToolsUiPlugin.getDefault().getDialogSettings(); |
| 214 |
IDialogSettings settings = pluginSettings.getSection(JUnitScriptsSelectionPage.class.getName()); |
| 215 |
if (settings == null) { |
| 216 |
settings = pluginSettings.addNewSection(JUnitScriptsSelectionPage.class.getName()); |
| 217 |
} |
| 218 |
return settings; |
| 219 |
} |
| 220 |
|
| 221 |
protected void readDialogSettings() { |
| 222 |
IDialogSettings settings = getDialogSettings(); |
| 223 |
String type = settings.get(DS_TYPE); |
| 224 |
if (type != null) { |
| 225 |
setSelectedType(type); |
| 226 |
} |
| 227 |
if (getSelectedType() == null) { |
| 228 |
// Default to the first item in list |
| 229 |
Object o = testFactoryList.getElementAt(0); |
| 230 |
if (o != null) testFactoryList.setSelection(new StructuredSelection(o)); |
| 231 |
} |
| 232 |
} |
| 233 |
|
| 234 |
/*package*/ void saveDialogSettings() { |
| 235 |
IDialogSettings settings = getDialogSettings(); |
| 236 |
settings.put(DS_TYPE, getSelectedType()); |
| 237 |
} |
| 238 |
|
| 75 |
} |
239 |
} |