|
Lines 141-198
Link Here
|
| 141 |
// -------- Initialization --------- |
141 |
// -------- Initialization --------- |
| 142 |
|
142 |
|
| 143 |
public void init(IStructuredSelection selection) { |
143 |
public void init(IStructuredSelection selection) { |
| 144 |
if (selection == null || selection.isEmpty()) { |
144 |
String projPath= getProjectPath(selection); |
| 145 |
setDefaultAttributes(); |
145 |
if (projPath != null) { |
| 146 |
return; |
146 |
fProjectField.setText(projPath); |
| 147 |
} |
147 |
} |
| 148 |
|
148 |
fRootDialogField.setText(""); //$NON-NLS-1$ |
| 149 |
Object selectedElement= selection.getFirstElement(); |
149 |
} |
| 150 |
if (selectedElement == null) { |
150 |
|
|
|
151 |
private String getProjectPath(IStructuredSelection selection) { |
| 152 |
Object selectedElement= null; |
| 153 |
if (selection == null || selection.isEmpty()) { |
| 151 |
selectedElement= EditorUtility.getActiveEditorJavaInput(); |
154 |
selectedElement= EditorUtility.getActiveEditorJavaInput(); |
| 152 |
} |
155 |
} else if (selection.size() == 1) { |
| 153 |
|
156 |
selectedElement= selection.getFirstElement(); |
| 154 |
String projPath= null; |
157 |
} |
| 155 |
|
158 |
|
| 156 |
if (selectedElement instanceof IResource) { |
159 |
if (selectedElement instanceof IResource) { |
| 157 |
IProject proj= ((IResource)selectedElement).getProject(); |
160 |
IProject proj= ((IResource)selectedElement).getProject(); |
| 158 |
if (proj != null) { |
161 |
if (proj != null) { |
| 159 |
projPath= proj.getFullPath().makeRelative().toString(); |
162 |
return proj.getFullPath().makeRelative().toString(); |
| 160 |
} |
163 |
} |
| 161 |
} else if (selectedElement instanceof IJavaElement) { |
164 |
} else if (selectedElement instanceof IJavaElement) { |
| 162 |
IJavaProject jproject= ((IJavaElement)selectedElement).getJavaProject(); |
165 |
IJavaProject jproject= ((IJavaElement)selectedElement).getJavaProject(); |
| 163 |
if (jproject != null) { |
166 |
if (jproject != null) { |
| 164 |
projPath= jproject.getProject().getFullPath().makeRelative().toString(); |
167 |
return jproject.getProject().getFullPath().makeRelative().toString(); |
| 165 |
} |
168 |
} |
| 166 |
} |
169 |
} |
| 167 |
|
170 |
|
| 168 |
if (projPath != null) { |
171 |
return null; |
| 169 |
fProjectField.setText(projPath); |
|
|
| 170 |
fRootDialogField.setText(""); //$NON-NLS-1$ |
| 171 |
} else { |
| 172 |
setDefaultAttributes(); |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
private void setDefaultAttributes() { |
| 177 |
String projPath= ""; //$NON-NLS-1$ |
| 178 |
|
| 179 |
try { |
| 180 |
// find the first java project |
| 181 |
IProject[] projects= fWorkspaceRoot.getProjects(); |
| 182 |
for (int i= 0; i < projects.length; i++) { |
| 183 |
IProject proj= projects[i]; |
| 184 |
if (proj.hasNature(JavaCore.NATURE_ID)) { |
| 185 |
projPath= proj.getFullPath().makeRelative().toString(); |
| 186 |
break; |
| 187 |
} |
| 188 |
} |
| 189 |
} catch (CoreException e) { |
| 190 |
// ignore here |
| 191 |
} |
| 192 |
fProjectField.setText(projPath); |
| 193 |
fRootDialogField.setText(""); //$NON-NLS-1$ |
| 194 |
} |
172 |
} |
| 195 |
|
|
|
| 196 |
|
173 |
|
| 197 |
// -------- UI Creation --------- |
174 |
// -------- UI Creation --------- |
| 198 |
|
175 |
|