Lines 1-13
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2016 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2013 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
|
|
8 |
* This is an implementation of an early-draft specification developed under the Java |
9 |
* Community Process (JCP) and is made available for testing and evaluation purposes |
10 |
* only. The code is not compatible with any specification of the JCP. |
11 |
* |
7 |
* |
12 |
* Contributors: |
8 |
* Contributors: |
13 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
Lines 44-50
Link Here
|
44 |
import org.eclipse.core.resources.ResourcesPlugin; |
40 |
import org.eclipse.core.resources.ResourcesPlugin; |
45 |
|
41 |
|
46 |
import org.eclipse.jface.dialogs.Dialog; |
42 |
import org.eclipse.jface.dialogs.Dialog; |
47 |
import org.eclipse.jface.dialogs.IDialogSettings; |
|
|
48 |
import org.eclipse.jface.util.BidiUtils; |
43 |
import org.eclipse.jface.util.BidiUtils; |
49 |
import org.eclipse.jface.viewers.ILabelProvider; |
44 |
import org.eclipse.jface.viewers.ILabelProvider; |
50 |
import org.eclipse.jface.viewers.IStructuredSelection; |
45 |
import org.eclipse.jface.viewers.IStructuredSelection; |
Lines 65-77
Link Here
|
65 |
import org.eclipse.jdt.core.IJavaElement; |
60 |
import org.eclipse.jdt.core.IJavaElement; |
66 |
import org.eclipse.jdt.core.IJavaModelStatus; |
61 |
import org.eclipse.jdt.core.IJavaModelStatus; |
67 |
import org.eclipse.jdt.core.IJavaProject; |
62 |
import org.eclipse.jdt.core.IJavaProject; |
68 |
import org.eclipse.jdt.core.IPackageFragment; |
|
|
69 |
import org.eclipse.jdt.core.IPackageFragmentRoot; |
63 |
import org.eclipse.jdt.core.IPackageFragmentRoot; |
70 |
import org.eclipse.jdt.core.JavaConventions; |
64 |
import org.eclipse.jdt.core.JavaConventions; |
71 |
import org.eclipse.jdt.core.JavaCore; |
65 |
import org.eclipse.jdt.core.JavaCore; |
72 |
import org.eclipse.jdt.core.JavaModelException; |
66 |
import org.eclipse.jdt.core.JavaModelException; |
73 |
|
67 |
|
74 |
import org.eclipse.jdt.internal.corext.util.InfoFilesUtil; |
|
|
75 |
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; |
68 |
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; |
76 |
import org.eclipse.jdt.internal.corext.util.Messages; |
69 |
import org.eclipse.jdt.internal.corext.util.Messages; |
77 |
|
70 |
|
Lines 107-116
Link Here
|
107 |
|
100 |
|
108 |
private SelectionButtonDialogField fExcludeInOthersFields; |
101 |
private SelectionButtonDialogField fExcludeInOthersFields; |
109 |
private SelectionButtonDialogField fIgnoreOptionalProblemsField; |
102 |
private SelectionButtonDialogField fIgnoreOptionalProblemsField; |
110 |
private SelectionButtonDialogField fCreateModuleInfoJavaField; |
|
|
111 |
|
112 |
private static final String MODULE_INFO_JAVA_FILENAME= JavaModelUtil.MODULE_INFO_JAVA; |
113 |
private static final String SETTINGS_CREATE_MODULE_INFO_JAVA= "create_module_info_java"; //$NON-NLS-1$ |
114 |
|
103 |
|
115 |
private IWorkspaceRoot fWorkspaceRoot; |
104 |
private IWorkspaceRoot fWorkspaceRoot; |
116 |
|
105 |
|
Lines 155-165
Link Here
|
155 |
fIgnoreOptionalProblemsField.setLabelText(NewWizardMessages.NewSourceFolderWizardPage_ignore_optional_problems_label); |
144 |
fIgnoreOptionalProblemsField.setLabelText(NewWizardMessages.NewSourceFolderWizardPage_ignore_optional_problems_label); |
156 |
fIgnoreOptionalProblemsField.setSelection(false); |
145 |
fIgnoreOptionalProblemsField.setSelection(false); |
157 |
|
146 |
|
158 |
fCreateModuleInfoJavaField= new SelectionButtonDialogField(SWT.CHECK); |
|
|
159 |
fCreateModuleInfoJavaField.setDialogFieldListener(adapter); |
160 |
fCreateModuleInfoJavaField.setLabelText(NewWizardMessages.NewSourceFolderWizardPage_create_module_info_java); |
161 |
fCreateModuleInfoJavaField.setSelection(false); |
162 |
|
163 |
fRootStatus= new StatusInfo(); |
147 |
fRootStatus= new StatusInfo(); |
164 |
fProjectStatus= new StatusInfo(); |
148 |
fProjectStatus= new StatusInfo(); |
165 |
} |
149 |
} |
Lines 170-183
Link Here
|
170 |
String projPath= getProjectPath(selection); |
154 |
String projPath= getProjectPath(selection); |
171 |
fProjectField.setText(projPath != null ? projPath : ""); //$NON-NLS-1$ |
155 |
fProjectField.setText(projPath != null ? projPath : ""); //$NON-NLS-1$ |
172 |
fRootDialogField.setText(""); //$NON-NLS-1$ |
156 |
fRootDialogField.setText(""); //$NON-NLS-1$ |
173 |
|
|
|
174 |
IDialogSettings dialogSettings= getDialogSettings(); |
175 |
if (dialogSettings != null) { |
176 |
IDialogSettings section= dialogSettings.getSection(PAGE_NAME); |
177 |
if (section != null) { |
178 |
fCreateModuleInfoJavaField.setSelection(section.getBoolean(SETTINGS_CREATE_MODULE_INFO_JAVA)); |
179 |
} |
180 |
} |
181 |
} |
157 |
} |
182 |
|
158 |
|
183 |
private String getProjectPath(IStructuredSelection selection) { |
159 |
private String getProjectPath(IStructuredSelection selection) { |
Lines 222-228
Link Here
|
222 |
fRootDialogField.doFillIntoGrid(composite, 3); |
198 |
fRootDialogField.doFillIntoGrid(composite, 3); |
223 |
fExcludeInOthersFields.doFillIntoGrid(composite, 3); |
199 |
fExcludeInOthersFields.doFillIntoGrid(composite, 3); |
224 |
fIgnoreOptionalProblemsField.doFillIntoGrid(composite, 3); |
200 |
fIgnoreOptionalProblemsField.doFillIntoGrid(composite, 3); |
225 |
fCreateModuleInfoJavaField.doFillIntoGrid(composite, 3); |
|
|
226 |
|
201 |
|
227 |
int maxFieldWidth= convertWidthInCharsToPixels(40); |
202 |
int maxFieldWidth= convertWidthInCharsToPixels(40); |
228 |
LayoutUtil.setWidthHint(fProjectField.getTextControl(null), maxFieldWidth); |
203 |
LayoutUtil.setWidthHint(fProjectField.getTextControl(null), maxFieldWidth); |
Lines 291-298
Link Here
|
291 |
} else if (field == fExcludeInOthersFields) { |
266 |
} else if (field == fExcludeInOthersFields) { |
292 |
updateRootStatus(); |
267 |
updateRootStatus(); |
293 |
} else if (field == fIgnoreOptionalProblemsField) { |
268 |
} else if (field == fIgnoreOptionalProblemsField) { |
294 |
updateRootStatus(); |
|
|
295 |
} else if (field == fCreateModuleInfoJavaField) { |
296 |
updateRootStatus(); |
269 |
updateRootStatus(); |
297 |
} |
270 |
} |
298 |
updateStatus(new IStatus[] { fProjectStatus, fRootStatus }); |
271 |
updateStatus(new IStatus[] { fProjectStatus, fRootStatus }); |
Lines 392-401
Link Here
|
392 |
IClasspathEntry curr= fEntries[i]; |
365 |
IClasspathEntry curr= fEntries[i]; |
393 |
if (curr.getEntryKind() == IClasspathEntry.CPE_SOURCE) { |
366 |
if (curr.getEntryKind() == IClasspathEntry.CPE_SOURCE) { |
394 |
if (path.equals(curr.getPath())) { |
367 |
if (path.equals(curr.getPath())) { |
395 |
boolean createModuleInfoJava= isCreateModuleInfoJava() && !moduleInfoJavaAlreadyExists(fCurrJProject.getPackageFragmentRoot(res)); |
368 |
fRootStatus.setError(NewWizardMessages.NewSourceFolderWizardPage_error_AlreadyExisting); |
396 |
if (!createModuleInfoJava) { |
|
|
397 |
fRootStatus.setError(NewWizardMessages.NewSourceFolderWizardPage_error_AlreadyExisting); |
398 |
} |
399 |
return; |
369 |
return; |
400 |
} |
370 |
} |
401 |
if (projPath.equals(curr.getPath())) { |
371 |
if (projPath.equals(curr.getPath())) { |
Lines 461-487
Link Here
|
461 |
} |
431 |
} |
462 |
} |
432 |
} |
463 |
|
433 |
|
464 |
/** |
|
|
465 |
* Checks if the module-info.java file already exists in any package in the given package |
466 |
* fragment root. |
467 |
* |
468 |
* @param root the package fragment root |
469 |
* @return <code>true</code> if module-info.java exists in any package in the given |
470 |
* <code>root</code>, <code>false</code> otherwise |
471 |
*/ |
472 |
private boolean moduleInfoJavaAlreadyExists(IPackageFragmentRoot root) { |
473 |
try { |
474 |
for (IJavaElement pkgFragment : root.getChildren()) { |
475 |
if (((IPackageFragment) pkgFragment).getCompilationUnit(MODULE_INFO_JAVA_FILENAME).exists()) { |
476 |
return true; |
477 |
} |
478 |
} |
479 |
} catch (JavaModelException e) { |
480 |
// pretend that the file does not exist |
481 |
} |
482 |
return false; |
483 |
} |
484 |
|
485 |
private void insertAtEndOfCategory(IClasspathEntry entry, List<IClasspathEntry> entries) { |
434 |
private void insertAtEndOfCategory(IClasspathEntry entry, List<IClasspathEntry> entries) { |
486 |
int length= entries.size(); |
435 |
int length= entries.size(); |
487 |
IClasspathEntry[] elements= entries.toArray(new IClasspathEntry[length]); |
436 |
IClasspathEntry[] elements= entries.toArray(new IClasspathEntry[length]); |
Lines 539-608
Link Here
|
539 |
return fCreatedRoot; |
488 |
return fCreatedRoot; |
540 |
} |
489 |
} |
541 |
|
490 |
|
542 |
/** |
|
|
543 |
* @return <code>true</code> if module-info.java should be created, <code>false</code> otherwise |
544 |
*/ |
545 |
private boolean isCreateModuleInfoJava() { |
546 |
return JavaModelUtil.is9OrHigher(fCurrJProject) && fCreateModuleInfoJavaField.isSelected(); |
547 |
} |
548 |
|
549 |
public IResource getCorrespondingResource() { |
491 |
public IResource getCorrespondingResource() { |
550 |
IFolder folder= fCurrJProject.getProject().getFolder(fRootDialogField.getText()); |
492 |
return fCurrJProject.getProject().getFolder(fRootDialogField.getText()); |
551 |
if (isCreateModuleInfoJava()) { |
|
|
552 |
return folder.getFile(MODULE_INFO_JAVA_FILENAME); |
553 |
} |
554 |
return folder; |
555 |
} |
493 |
} |
556 |
|
494 |
|
557 |
public void createPackageFragmentRoot(IProgressMonitor monitor) throws CoreException, InterruptedException { |
495 |
public void createPackageFragmentRoot(IProgressMonitor monitor) throws CoreException, InterruptedException { |
558 |
if (monitor == null) { |
496 |
if (monitor == null) { |
559 |
monitor= new NullProgressMonitor(); |
497 |
monitor= new NullProgressMonitor(); |
560 |
} |
498 |
} |
561 |
String relPath= fRootDialogField.getText(); |
499 |
monitor.beginTask(NewWizardMessages.NewSourceFolderWizardPage_operation, 3); |
562 |
IFolder folder= fCurrJProject.getProject().getFolder(relPath); |
500 |
try { |
563 |
fCreatedRoot= fCurrJProject.getPackageFragmentRoot(folder); |
501 |
IPath projPath= fCurrJProject.getProject().getFullPath(); |
564 |
|
502 |
if (fOutputLocation.equals(projPath) && !fNewOutputLocation.equals(projPath)) { |
565 |
if (!fCreatedRoot.exists()) { |
503 |
if (BuildPathsBlock.hasClassfiles(fCurrJProject.getProject())) { |
566 |
monitor.beginTask(NewWizardMessages.NewSourceFolderWizardPage_operation, 3); |
504 |
if (BuildPathsBlock.getRemoveOldBinariesQuery(getShell()).doQuery(false, projPath)) { |
567 |
try { |
505 |
BuildPathsBlock.removeOldClassfiles(fCurrJProject.getProject()); |
568 |
IPath projPath= fCurrJProject.getProject().getFullPath(); |
|
|
569 |
if (fOutputLocation.equals(projPath) && !fNewOutputLocation.equals(projPath)) { |
570 |
if (BuildPathsBlock.hasClassfiles(fCurrJProject.getProject())) { |
571 |
if (BuildPathsBlock.getRemoveOldBinariesQuery(getShell()).doQuery(false, projPath)) { |
572 |
BuildPathsBlock.removeOldClassfiles(fCurrJProject.getProject()); |
573 |
} |
574 |
} |
506 |
} |
575 |
} |
507 |
} |
576 |
|
|
|
577 |
if (!folder.exists()) { |
578 |
CoreUtility.createFolder(folder, true, true, new SubProgressMonitor(monitor, 1)); |
579 |
} |
580 |
if (monitor.isCanceled()) { |
581 |
throw new InterruptedException(); |
582 |
} |
583 |
|
584 |
fCurrJProject.setRawClasspath(fNewEntries, fNewOutputLocation, new SubProgressMonitor(monitor, 2)); |
585 |
|
586 |
} finally { |
587 |
monitor.done(); |
588 |
} |
508 |
} |
589 |
} |
|
|
590 |
|
509 |
|
591 |
if (isCreateModuleInfoJava()) { |
510 |
String relPath= fRootDialogField.getText(); |
592 |
// default package always exists |
|
|
593 |
IPackageFragment pack= fCreatedRoot.getPackageFragment(""); //$NON-NLS-1$ |
594 |
String fileContent= JavaCore.createModuleFromPackageRoot(null, fCreatedRoot); |
595 |
InfoFilesUtil.createInfoJavaFile(MODULE_INFO_JAVA_FILENAME, fileContent, pack, monitor); |
596 |
} |
597 |
|
511 |
|
598 |
// save dialog settings for create_module_info_java |
512 |
IFolder folder= fCurrJProject.getProject().getFolder(relPath); |
599 |
IDialogSettings dialogSettings= getDialogSettings(); |
513 |
if (!folder.exists()) { |
600 |
if (dialogSettings != null) { |
514 |
CoreUtility.createFolder(folder, true, true, new SubProgressMonitor(monitor, 1)); |
601 |
IDialogSettings section= dialogSettings.getSection(PAGE_NAME); |
|
|
602 |
if (section == null) { |
603 |
section= dialogSettings.addNewSection(PAGE_NAME); |
604 |
} |
515 |
} |
605 |
section.put(SETTINGS_CREATE_MODULE_INFO_JAVA, fCreateModuleInfoJavaField.isSelected()); |
516 |
if (monitor.isCanceled()) { |
|
|
517 |
throw new InterruptedException(); |
518 |
} |
519 |
|
520 |
fCurrJProject.setRawClasspath(fNewEntries, fNewOutputLocation, new SubProgressMonitor(monitor, 2)); |
521 |
|
522 |
fCreatedRoot= fCurrJProject.getPackageFragmentRoot(folder); |
523 |
} finally { |
524 |
monitor.done(); |
606 |
} |
525 |
} |
607 |
} |
526 |
} |
608 |
|
527 |
|