|
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 com.nokia.carbide.cdt.builder.CarbideBuilderPlugin; |
|
20 import com.nokia.carbide.cdt.builder.ICarbideBuildManager; |
|
21 |
|
22 import java.util.ArrayList; |
|
23 import java.util.List; |
|
24 |
|
25 import org.eclipse.swt.layout.GridData; |
|
26 import org.eclipse.swt.layout.GridLayout; |
|
27 import org.eclipse.ui.model.WorkbenchLabelProvider; |
|
28 import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard; |
|
29 |
|
30 import org.eclipse.core.resources.IProject; |
|
31 import org.eclipse.core.resources.ResourcesPlugin; |
|
32 import org.eclipse.jface.dialogs.IPageChangingListener; |
|
33 import org.eclipse.jface.dialogs.PageChangingEvent; |
|
34 import org.eclipse.jface.viewers.ArrayContentProvider; |
|
35 import org.eclipse.jface.viewers.ISelectionChangedListener; |
|
36 import org.eclipse.jface.viewers.SelectionChangedEvent; |
|
37 import org.eclipse.jface.viewers.IStructuredSelection; |
|
38 import org.eclipse.jface.viewers.TableViewer; |
|
39 import org.eclipse.jface.wizard.WizardDialog; |
|
40 import org.eclipse.jface.wizard.WizardPage; |
|
41 import org.eclipse.swt.widgets.Composite; |
|
42 import org.eclipse.swt.widgets.Label; |
|
43 |
|
44 import com.nokia.testfw.codegen.ui.Messages; |
|
45 |
|
46 public class ChooseProjectPage extends WizardPage implements |
|
47 IPageChangingListener { |
|
48 |
|
49 private TableViewer iTableViewer; |
|
50 private IStructuredSelection iSelection; |
|
51 private ICarbideBuildManager iBuildManager; |
|
52 private IProject iTargetProject; |
|
53 |
|
54 public ChooseProjectPage() { |
|
55 super("ChooseProjectPage"); |
|
56 setTitle(Messages.getString("ChooseProjectPage.Title")); |
|
57 setDescription(Messages.getString("ChooseProjectPage.Description")); |
|
58 iBuildManager = CarbideBuilderPlugin.getBuildManager(); |
|
59 } |
|
60 |
|
61 public void createControl(Composite parent) { |
|
62 initializeDialogUnits(parent); |
|
63 Composite container = new Composite(parent, 0); |
|
64 GridLayout gridLayout = new GridLayout(); |
|
65 gridLayout.marginTop = 10; |
|
66 gridLayout.marginRight = 10; |
|
67 gridLayout.marginLeft = 10; |
|
68 gridLayout.marginBottom = 10; |
|
69 gridLayout.horizontalSpacing = 10; |
|
70 container.setLayout(gridLayout); |
|
71 Label selectAnExistingLabel = new Label(container, 0); |
|
72 GridData gridData = new GridData(4, 2, true, false); |
|
73 selectAnExistingLabel.setLayoutData(gridData); |
|
74 selectAnExistingLabel.setText(Messages |
|
75 .getString("ChooseProjectPage.Label")); |
|
76 iTableViewer = new TableViewer(container, 2816); |
|
77 iTableViewer.getTable().setLayoutData(new GridData(4, 4, true, true)); |
|
78 iTableViewer.setContentProvider(new ArrayContentProvider()); |
|
79 iTableViewer.setLabelProvider(new WorkbenchLabelProvider()); |
|
80 iTableViewer.setInput(getEligibleProjects()); |
|
81 iTableViewer |
|
82 .addSelectionChangedListener(new ISelectionChangedListener() { |
|
83 |
|
84 public void selectionChanged(SelectionChangedEvent event) { |
|
85 IStructuredSelection selection = (IStructuredSelection) event |
|
86 .getSelection(); |
|
87 handleSelection(selection); |
|
88 } |
|
89 }); |
|
90 setControl(container); |
|
91 |
|
92 iSelection = (IStructuredSelection) ((BasicNewResourceWizard) getWizard()) |
|
93 .getSelection(); |
|
94 iTableViewer.setSelection(iSelection); |
|
95 handleSelection(iSelection); |
|
96 |
|
97 ((WizardDialog) getContainer()).addPageChangingListener(this); |
|
98 } |
|
99 |
|
100 public IProject getTargetProject() { |
|
101 return iTargetProject; |
|
102 } |
|
103 |
|
104 private boolean isValid() { |
|
105 return !iSelection.isEmpty(); |
|
106 } |
|
107 |
|
108 protected void handleSelection(IStructuredSelection selection) { |
|
109 iSelection = selection; |
|
110 if (iTableViewer.getTable().getItemCount() == 0) { |
|
111 setErrorMessage(Messages |
|
112 .getString("ChooseProjectPage.NoProjectsError")); |
|
113 } else { |
|
114 if (iSelection.isEmpty()) { |
|
115 setErrorMessage(Messages |
|
116 .getString("ChooseProjectPage.NoSelectionError")); |
|
117 } else { |
|
118 iTargetProject = (IProject) iSelection.getFirstElement(); |
|
119 setErrorMessage(null); |
|
120 } |
|
121 } |
|
122 setPageComplete(isValid()); |
|
123 } |
|
124 |
|
125 private IProject[] getEligibleProjects() { |
|
126 List<IProject> eligibleProjects = new ArrayList<IProject>(); |
|
127 IProject projects[] = ResourcesPlugin.getWorkspace().getRoot() |
|
128 .getProjects(); |
|
129 for (int i = 0; i < projects.length; i++) { |
|
130 IProject project = projects[i]; |
|
131 if (projectIsEligible(project)) |
|
132 eligibleProjects.add(project); |
|
133 } |
|
134 |
|
135 return (IProject[]) eligibleProjects |
|
136 .toArray(new IProject[eligibleProjects.size()]); |
|
137 } |
|
138 |
|
139 private boolean projectIsEligible(IProject project) { |
|
140 return iBuildManager.isCarbideProject(project); |
|
141 } |
|
142 |
|
143 public void handlePageChanging(PageChangingEvent event) { |
|
144 if (event.getCurrentPage() instanceof ChooseProjectPage) { |
|
145 if(iTargetProject!=null){ |
|
146 ((AbstractTemplateWizard) getWizard()).setSelection(iSelection); |
|
147 ((AbstractTemplateWizard) getWizard()) |
|
148 .setTargetProject(iTargetProject); |
|
149 ((AbstractTemplateWizard) getWizard()) |
|
150 .setProjectLocation(iTargetProject.getLocation() |
|
151 .toOSString()); |
|
152 ((AbstractTemplateWizard) getWizard()).getDataMap().put( |
|
153 AbstractTemplateWizard.PROJECT_NAME, |
|
154 iTargetProject.getName()); |
|
155 ((AbstractTemplateWizard) getWizard()).initPages(); |
|
156 } |
|
157 } |
|
158 } |
|
159 } |