Skip to content

Commit 9550085

Browse files
Merge branch 'IEP-128' into 'master'
IEP-128 "Copy Project into workspace" option in import project wizard Closes IEP-128 See merge request idf/idf-eclipse-plugin!92
2 parents 71aa811 + 330711f commit 9550085

File tree

6 files changed

+123
-48
lines changed

6 files changed

+123
-48
lines changed

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/templates/IDFProjectGenerator.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.eclipse.core.resources.IResource;
1919
import org.eclipse.core.runtime.CoreException;
2020
import org.eclipse.core.runtime.IProgressMonitor;
21+
import org.eclipse.core.runtime.Path;
2122
import org.osgi.framework.Bundle;
2223

2324
import com.espressif.idf.core.IDFProjectNature;
@@ -34,11 +35,13 @@ public class IDFProjectGenerator extends CMakeProjectGenerator
3435
{
3536

3637
private File sourceTemplatePath;
38+
private boolean copyIntoWorkspace;
3739

38-
public IDFProjectGenerator(String manifestFile, File source)
40+
public IDFProjectGenerator(String manifestFile, File source, boolean copyIntoWorkspace)
3941
{
4042
super(manifestFile);
4143
this.sourceTemplatePath = source;
44+
this.copyIntoWorkspace = copyIntoWorkspace;
4245
}
4346

4447
@Override
@@ -49,6 +52,10 @@ protected void initProjectDescription(IProjectDescription description)
4952
ICommand command = description.newCommand();
5053
CBuilder.setupBuilder(command);
5154
description.setBuildSpec(new ICommand[] { command });
55+
if (!copyIntoWorkspace)
56+
{
57+
description.setLocation(new Path(sourceTemplatePath.getAbsolutePath()));
58+
}
5259
}
5360

5461
@Override
@@ -64,14 +71,17 @@ public void generate(Map<String, Object> model, IProgressMonitor monitor) throws
6471
// Target project
6572
IProject project = getProject();
6673

67-
// copy IDF template resources
68-
try
69-
{
70-
copyIDFTemplateToWorkspace(project.getName(), sourceTemplatePath, project);
71-
}
72-
catch (IOException e)
74+
if (copyIntoWorkspace)
7375
{
74-
Logger.log(e);
76+
// copy IDF template resources
77+
try
78+
{
79+
copyIDFTemplateToWorkspace(project.getName(), sourceTemplatePath, project);
80+
}
81+
catch (IOException e)
82+
{
83+
Logger.log(e);
84+
}
7585
}
7686

7787
// refresh to see the copied resources in the project explorer

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/ImportIDFProjectWizard.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ protected IGenerator getGenerator()
4646
{
4747
projectName = page.getProjectName();
4848
locationStr = page.getLocation();
49+
boolean canCopyIntoWorkspace = page.canCopyIntoWorkspace();
4950

50-
IDFProjectGenerator generator = new IDFProjectGenerator(null, new File(locationStr));
51+
IDFProjectGenerator generator = new IDFProjectGenerator(null, new File(locationStr), canCopyIntoWorkspace);
5152
generator.setProjectName(projectName);
5253
return generator;
5354
}

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/ImportIDFProjectWizardPage.java

Lines changed: 100 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.eclipse.swt.events.KeyEvent;
2929
import org.eclipse.swt.events.ModifyEvent;
3030
import org.eclipse.swt.events.ModifyListener;
31+
import org.eclipse.swt.events.SelectionAdapter;
3132
import org.eclipse.swt.events.SelectionEvent;
3233
import org.eclipse.swt.events.SelectionListener;
3334
import org.eclipse.swt.layout.GridData;
@@ -46,20 +47,23 @@
4647
* @author Kondal Kolipaka <[email protected]>
4748
*
4849
*/
49-
public class ImportIDFProjectWizardPage extends WizardPage {
50+
public class ImportIDFProjectWizardPage extends WizardPage
51+
{
5052

5153
private Text projectName;
5254
private Text location;
5355
private IWorkspaceRoot root;
5456

5557
/**
56-
* True if the user entered a non-empty string in the project name field. In that state, we avoid
57-
* automatically filling the project name field with the directory name (last segment of the location) he
58-
* has entered.
58+
* True if the user entered a non-empty string in the project name field. In that state, we avoid automatically
59+
* filling the project name field with the directory name (last segment of the location) he has entered.
5960
*/
6061
boolean projectNameSetByUser;
62+
private Button copyCheckbox;
63+
private boolean copyProject;
6164

62-
protected ImportIDFProjectWizardPage() {
65+
protected ImportIDFProjectWizardPage()
66+
{
6367
super(Messages.ImportIDFProjectWizardPage_0);
6468
setTitle(Messages.ImportIDFProjectWizardPage_1);
6569
setDescription(Messages.ImportIDFProjectWizardPage_2);
@@ -68,7 +72,8 @@ protected ImportIDFProjectWizardPage() {
6872
}
6973

7074
@Override
71-
public void createControl(Composite parent) {
75+
public void createControl(Composite parent)
76+
{
7277
Composite comp = new Composite(parent, SWT.NONE);
7378
GridLayout layout = new GridLayout();
7479
comp.setLayout(layout);
@@ -77,9 +82,27 @@ public void createControl(Composite parent) {
7782
addProjectNameSelector(comp);
7883
addSourceSelector(comp);
7984
setControl(comp);
85+
createOptions(comp);
8086
}
8187

82-
public void addProjectNameSelector(Composite parent) {
88+
public void createOptions(Composite comp)
89+
{
90+
copyCheckbox = new Button(comp, SWT.CHECK);
91+
copyCheckbox.setText(Messages.ImportIDFProjectWizardPage_CopyIntoWorkspace);
92+
copyCheckbox.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
93+
copyCheckbox.addSelectionListener(new SelectionAdapter()
94+
{
95+
@Override
96+
public void widgetSelected(SelectionEvent e)
97+
{
98+
copyProject = copyCheckbox.getSelection();
99+
}
100+
});
101+
102+
}
103+
104+
public void addProjectNameSelector(Composite parent)
105+
{
83106
Group group = new Group(parent, SWT.NONE);
84107
GridLayout layout = new GridLayout();
85108
layout.numColumns = 2;
@@ -89,21 +112,26 @@ public void addProjectNameSelector(Composite parent) {
89112

90113
projectName = new Text(group, SWT.BORDER);
91114
projectName.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
92-
projectName.addModifyListener(new ModifyListener() {
115+
projectName.addModifyListener(new ModifyListener()
116+
{
93117
@Override
94-
public void modifyText(ModifyEvent e) {
118+
public void modifyText(ModifyEvent e)
119+
{
95120
validatePage();
96-
if (getProjectName().isEmpty()) {
121+
if (getProjectName().isEmpty())
122+
{
97123
projectNameSetByUser = false;
98124
}
99125
}
100126
});
101127

102128
// Note that the modify listener gets called not only when the user enters text but also when we
103129
// programatically set the field. This listener only gets called when the user modifies the field
104-
projectName.addKeyListener(new KeyAdapter() {
130+
projectName.addKeyListener(new KeyAdapter()
131+
{
105132
@Override
106-
public void keyPressed(KeyEvent e) {
133+
public void keyPressed(KeyEvent e)
134+
{
107135
projectNameSetByUser = true;
108136
}
109137
});
@@ -113,44 +141,61 @@ public void keyPressed(KeyEvent e) {
113141
* Validates the contents of the page, setting the page error message and Finish button state accordingly
114142
*
115143
*/
116-
protected void validatePage() {
144+
protected void validatePage()
145+
{
117146
// Don't generate an error if project name or location is empty, but do disable Finish button.
118147
String msg = null;
119148
boolean complete = true; // ultimately treated as false if msg != null
120149

121150
String name = getProjectName();
122-
if (name.isEmpty()) {
151+
if (name.isEmpty())
152+
{
123153
complete = false;
124-
} else {
154+
}
155+
else
156+
{
125157
IStatus status = ResourcesPlugin.getWorkspace().validateName(name, IResource.PROJECT);
126-
if (!status.isOK()) {
158+
if (!status.isOK())
159+
{
127160
msg = status.getMessage();
128-
} else {
161+
}
162+
else
163+
{
129164
IProject project = root.getProject(name);
130-
if (project.exists()) {
165+
if (project.exists())
166+
{
131167
msg = Messages.ImportIDFProjectWizardPage_4;
132168

133169
}
134170
}
135171
}
136-
if (msg == null) {
172+
if (msg == null)
173+
{
137174
String loc = getLocation();
138-
if (loc.isEmpty()) {
175+
if (loc.isEmpty())
176+
{
139177
complete = false;
140-
} else {
178+
}
179+
else
180+
{
141181
final File file = new File(loc);
142-
if (file.isDirectory()) {
182+
if (file.isDirectory())
183+
{
143184
// Ensure we can create files in the directory.
144185
if (!file.canWrite())
145186
msg = Messages.ImportIDFProjectWizardPage_5;
146187
// Set the project name to the directory name but not if the user has supplied a name
147188
// (bugzilla 368987). Use a job to ensure proper sequence of activity, as setting the Text
148189
// will invoke the listener, which will invoke this method.
149-
else if (!projectNameSetByUser && !name.equals(file.getName())) {
150-
WorkbenchJob wjob = new WorkbenchJob("update project name") { //$NON-NLS-1$
190+
else if (!projectNameSetByUser && !name.equals(file.getName()))
191+
{
192+
WorkbenchJob wjob = new WorkbenchJob("update project name") //$NON-NLS-1$
193+
{
151194
@Override
152-
public IStatus runInUIThread(IProgressMonitor monitor) {
153-
if (!projectName.isDisposed()) {
195+
public IStatus runInUIThread(IProgressMonitor monitor)
196+
{
197+
if (!projectName.isDisposed())
198+
{
154199
projectName.setText(file.getName());
155200
}
156201
return Status.OK_STATUS;
@@ -159,7 +204,9 @@ public IStatus runInUIThread(IProgressMonitor monitor) {
159204
wjob.setSystem(true);
160205
wjob.schedule();
161206
}
162-
} else {
207+
}
208+
else
209+
{
163210
msg = Messages.ImportIDFProjectWizardPage_6;
164211
}
165212
}
@@ -171,11 +218,13 @@ public IStatus runInUIThread(IProgressMonitor monitor) {
171218

172219
/** @deprecated Replaced by {@link #validatePage()} */
173220
@Deprecated
174-
public void validateProjectName() {
221+
public void validateProjectName()
222+
{
175223
validatePage();
176224
}
177225

178-
public void addSourceSelector(Composite parent) {
226+
public void addSourceSelector(Composite parent)
227+
{
179228
Group group = new Group(parent, SWT.NONE);
180229
GridLayout layout = new GridLayout();
181230
layout.numColumns = 2;
@@ -185,9 +234,11 @@ public void addSourceSelector(Composite parent) {
185234

186235
location = new Text(group, SWT.BORDER);
187236
location.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
188-
location.addModifyListener(new ModifyListener() {
237+
location.addModifyListener(new ModifyListener()
238+
{
189239
@Override
190-
public void modifyText(ModifyEvent e) {
240+
public void modifyText(ModifyEvent e)
241+
{
191242
validatePage();
192243
}
193244
});
@@ -196,9 +247,11 @@ public void modifyText(ModifyEvent e) {
196247
Button browse = new Button(group, SWT.NONE);
197248
browse.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
198249
browse.setText(Messages.ImportIDFProjectWizardPage_8);
199-
browse.addSelectionListener(new SelectionListener() {
250+
browse.addSelectionListener(new SelectionListener()
251+
{
200252
@Override
201-
public void widgetSelected(SelectionEvent e) {
253+
public void widgetSelected(SelectionEvent e)
254+
{
202255
DirectoryDialog dialog = new DirectoryDialog(location.getShell());
203256
dialog.setMessage(Messages.ImportIDFProjectWizardPage_9);
204257
String dir = dialog.open();
@@ -207,23 +260,32 @@ public void widgetSelected(SelectionEvent e) {
207260
}
208261

209262
@Override
210-
public void widgetDefaultSelected(SelectionEvent e) {
263+
public void widgetDefaultSelected(SelectionEvent e)
264+
{
211265
}
212266
});
213267
}
214268

215269
/** @deprecated Replaced by {@link #validatePage()} */
216270
@Deprecated
217-
void validateSource() {
271+
void validateSource()
272+
{
218273
validatePage();
219274
}
220-
221-
public String getProjectName() {
275+
276+
public String getProjectName()
277+
{
222278
return projectName.getText().trim();
223279
}
224280

225-
public String getLocation() {
281+
public String getLocation()
282+
{
226283
return location.getText().trim();
227284
}
228285

286+
public boolean canCopyIntoWorkspace()
287+
{
288+
return copyProject;
289+
}
290+
229291
}

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/Messages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class Messages extends NLS {
2323
public static String ImportIDFProjectWizardPage_7;
2424
public static String ImportIDFProjectWizardPage_8;
2525
public static String ImportIDFProjectWizardPage_9;
26+
public static String ImportIDFProjectWizardPage_CopyIntoWorkspace;
2627
public static String NewIDFProjectWizard_NewIDFProject;
2728
public static String NewIDFProjectWizard_Project_Title;
2829
public static String NewIDFProjectWizard_ProjectDesc;

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/NewIDFProjectWizard.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ protected IGenerator getGenerator()
9797
manifest = null;
9898
}
9999

100-
IDFProjectGenerator generator = new IDFProjectGenerator(manifest, selectedTemplate);
100+
IDFProjectGenerator generator = new IDFProjectGenerator(manifest, selectedTemplate, true);
101101
generator.setProjectName(mainPage.getProjectName());
102102
if (!mainPage.useDefaults())
103103
{

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ ImportIDFProjectWizardPage_6=Not a valid directory
99
ImportIDFProjectWizardPage_7=Existing project Location
1010
ImportIDFProjectWizardPage_8=Browse...
1111
ImportIDFProjectWizardPage_9=Select root directory of existing project
12+
ImportIDFProjectWizardPage_CopyIntoWorkspace=Copy project into workspace
1213
NewIDFProjectWizard_NewIDFProject=New IDF Project
1314
NewIDFProjectWizard_Project_Title=IDF Project
1415
NewIDFProjectWizard_ProjectDesc=Create a new IoT Development Framework(IDF) project.

0 commit comments

Comments
 (0)