|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 package com.nokia.testfw.codegen.ui.wizard; |
|
18 |
|
19 import java.util.Map; |
|
20 |
|
21 import org.eclipse.jface.dialogs.IPageChangedListener; |
|
22 import org.eclipse.jface.dialogs.IPageChangingListener; |
|
23 import org.eclipse.jface.dialogs.PageChangedEvent; |
|
24 import org.eclipse.jface.dialogs.PageChangingEvent; |
|
25 import org.eclipse.jface.viewers.ISelectionChangedListener; |
|
26 import org.eclipse.jface.viewers.ITreeSelection; |
|
27 import org.eclipse.jface.viewers.SelectionChangedEvent; |
|
28 import org.eclipse.jface.viewers.TreeViewer; |
|
29 import org.eclipse.jface.wizard.WizardDialog; |
|
30 import org.eclipse.jface.wizard.WizardPage; |
|
31 import org.eclipse.swt.SWT; |
|
32 import org.eclipse.swt.custom.SashForm; |
|
33 import org.eclipse.swt.graphics.Color; |
|
34 import org.eclipse.swt.layout.GridData; |
|
35 import org.eclipse.swt.layout.GridLayout; |
|
36 import org.eclipse.swt.widgets.Composite; |
|
37 import org.eclipse.swt.widgets.Label; |
|
38 import org.eclipse.ui.part.PageBook; |
|
39 |
|
40 import com.nokia.testfw.codegen.ChangeFileContent; |
|
41 import com.nokia.testfw.codegen.ui.util.PathNode; |
|
42 import com.nokia.testfw.codegen.ui.util.PathNodeConverter; |
|
43 import com.nokia.testfw.codegen.ui.util.PathNodeTreeContentLabelProvoder; |
|
44 import com.nokia.testfw.codegen.ui.util.PathNodeTreeViewerComparator; |
|
45 import com.nokia.testfw.codegen.ui.wizard.preview.ChangeElement; |
|
46 import com.nokia.testfw.codegen.ui.wizard.preview.ComparePreviewer; |
|
47 |
|
48 /** |
|
49 * Test Case Wizard page for reviewing changes |
|
50 * |
|
51 */ |
|
52 public class TestCasePreviewPage extends WizardPage implements |
|
53 IPageChangedListener, IPageChangingListener { |
|
54 |
|
55 private PageBook previewContainer; |
|
56 private ComparePreviewer comparePreview; |
|
57 private TreeViewer iTreeViewer; |
|
58 |
|
59 private Map<String, ChangeFileContent> iResultMap; |
|
60 |
|
61 Composite container; |
|
62 |
|
63 /** |
|
64 * @param pageName |
|
65 */ |
|
66 public TestCasePreviewPage() { |
|
67 super("SkeletonPreviewPage"); |
|
68 setTitle("Preview changes"); |
|
69 setDescription("Click finish to generate test case(s)"); |
|
70 } |
|
71 |
|
72 /* |
|
73 * (non-Javadoc) |
|
74 * |
|
75 * @see |
|
76 * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets |
|
77 * .Composite) |
|
78 */ |
|
79 public void createControl(Composite parent) { |
|
80 container = new Composite(parent, SWT.NONE); |
|
81 container.setLayout(new GridLayout(1, true)); |
|
82 |
|
83 // table to display all files that are going to be changed |
|
84 Label label1 = new Label(container, SWT.SINGLE); |
|
85 label1.setText("Files to be modified"); |
|
86 |
|
87 iTreeViewer = new TreeViewer(container, SWT.BORDER | SWT.H_SCROLL |
|
88 | SWT.V_SCROLL); |
|
89 iTreeViewer.getTree().setLayoutData( |
|
90 new GridData(SWT.FILL, SWT.TOP, true, false)); |
|
91 PathNodeTreeContentLabelProvoder provider = new PathNodeTreeContentLabelProvoder(); |
|
92 iTreeViewer.setLabelProvider(provider); |
|
93 iTreeViewer.setContentProvider(provider); |
|
94 iTreeViewer.setComparator(new PathNodeTreeViewerComparator()); |
|
95 iTreeViewer |
|
96 .addSelectionChangedListener(new ISelectionChangedListener() { |
|
97 public void selectionChanged(SelectionChangedEvent event) { |
|
98 ITreeSelection sel = (ITreeSelection) event |
|
99 .getSelection(); |
|
100 if (sel != null) { |
|
101 PathNode node = (PathNode) sel.getFirstElement(); |
|
102 if (node != null) { |
|
103 setSelectElement((ChangeElement) node.getData()); |
|
104 } |
|
105 } |
|
106 } |
|
107 }); |
|
108 |
|
109 // UI elements to show the CompareViewerSwitchingPane |
|
110 SashForm sashForm = new SashForm(container, SWT.VERTICAL); |
|
111 sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
|
112 sashForm.setBackground(new Color(getShell().getDisplay(), 0, 0, 0)); |
|
113 previewContainer = new PageBook(sashForm, SWT.NONE); |
|
114 comparePreview = new ComparePreviewer(previewContainer, false, false); |
|
115 |
|
116 setSelectElement(null); |
|
117 setControl(container); |
|
118 |
|
119 /** |
|
120 * We want to be informed about pageChanged event in order to generate |
|
121 * content. |
|
122 */ |
|
123 ((WizardDialog) getContainer()).addPageChangedListener(this); |
|
124 ((WizardDialog) getContainer()).addPageChangingListener(this); |
|
125 } |
|
126 |
|
127 private void update() { |
|
128 if (iResultMap != null) { |
|
129 PathNode root = new PathNode(""); |
|
130 PathNode targetProject = new PathNode( |
|
131 ((AbstractTemplateWizard) getWizard()).getProjectName()); |
|
132 root.addChild(targetProject); |
|
133 for (String path : iResultMap.keySet()) { |
|
134 ChangeFileContent lChangeContent = iResultMap.get(path); |
|
135 if (lChangeContent.getNewContent().equals( |
|
136 lChangeContent.getOldContent())) { |
|
137 continue; |
|
138 } |
|
139 PathNode node = PathNodeConverter.pathToNode(targetProject, |
|
140 path); |
|
141 node.setData(new ChangeElement(lChangeContent)); |
|
142 } |
|
143 iTreeViewer.setInput(root); |
|
144 iTreeViewer.expandAll(); |
|
145 } |
|
146 } |
|
147 |
|
148 /** |
|
149 * Sets input to compare preview (called from wizard when page is set to |
|
150 * visible) |
|
151 * |
|
152 * @param changeElement |
|
153 * to set to the preview |
|
154 **/ |
|
155 private void setSelectElement(ChangeElement changeElement) { |
|
156 comparePreview.setInput(changeElement); |
|
157 previewContainer.showPage(comparePreview.getControl()); |
|
158 } |
|
159 |
|
160 public void pageChanged(PageChangedEvent event) { |
|
161 if (event.getSelectedPage() instanceof TestCasePreviewPage) { |
|
162 iResultMap = ((IPreviewResult) getWizard()).getPreviewResult(); |
|
163 ((IPreviewResult) getWizard()).setPreviewResult(iResultMap); |
|
164 update(); |
|
165 } |
|
166 } |
|
167 |
|
168 public void handlePageChanging(PageChangingEvent event) { |
|
169 if (event.getCurrentPage() instanceof TestCasePreviewPage) { |
|
170 ((IPreviewResult) getWizard()).setPreviewResult(null); |
|
171 } |
|
172 } |
|
173 } |