Source Code Cross Referenced for AddSourceFolderWizardPage.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » internal » ui » wizards » buildpaths » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » jdt » org.eclipse.jdt.internal.ui.wizards.buildpaths 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2007 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.jdt.internal.ui.wizards.buildpaths;
011:
012:        import java.io.File;
013:        import java.net.URI;
014:        import java.util.ArrayList;
015:        import java.util.HashSet;
016:        import java.util.Hashtable;
017:        import java.util.Iterator;
018:        import java.util.List;
019:        import java.util.Set;
020:
021:        import org.eclipse.core.filesystem.EFS;
022:        import org.eclipse.core.filesystem.IFileStore;
023:
024:        import org.eclipse.core.runtime.CoreException;
025:        import org.eclipse.core.runtime.IPath;
026:        import org.eclipse.core.runtime.IStatus;
027:        import org.eclipse.core.runtime.Path;
028:
029:        import org.eclipse.core.resources.IContainer;
030:        import org.eclipse.core.resources.IFolder;
031:        import org.eclipse.core.resources.IPathVariableManager;
032:        import org.eclipse.core.resources.IProject;
033:        import org.eclipse.core.resources.IResource;
034:        import org.eclipse.core.resources.IWorkspace;
035:        import org.eclipse.core.resources.IWorkspaceRoot;
036:        import org.eclipse.core.resources.ResourcesPlugin;
037:
038:        import org.eclipse.swt.SWT;
039:        import org.eclipse.swt.layout.GridLayout;
040:        import org.eclipse.swt.widgets.Composite;
041:        import org.eclipse.swt.widgets.Control;
042:        import org.eclipse.swt.widgets.DirectoryDialog;
043:
044:        import org.eclipse.jface.dialogs.Dialog;
045:        import org.eclipse.jface.dialogs.IDialogConstants;
046:        import org.eclipse.jface.viewers.ILabelProvider;
047:        import org.eclipse.jface.viewers.ITreeContentProvider;
048:        import org.eclipse.jface.viewers.ViewerFilter;
049:        import org.eclipse.jface.window.Window;
050:
051:        import org.eclipse.ui.PlatformUI;
052:        import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
053:        import org.eclipse.ui.dialogs.ISelectionStatusValidator;
054:        import org.eclipse.ui.model.WorkbenchContentProvider;
055:        import org.eclipse.ui.model.WorkbenchLabelProvider;
056:
057:        import org.eclipse.ui.views.navigator.ResourceComparator;
058:
059:        import org.eclipse.ui.ide.dialogs.PathVariableSelectionDialog;
060:
061:        import org.eclipse.jdt.core.IClasspathEntry;
062:        import org.eclipse.jdt.core.IJavaModelStatus;
063:        import org.eclipse.jdt.core.IJavaProject;
064:        import org.eclipse.jdt.core.JavaConventions;
065:
066:        import org.eclipse.jdt.internal.corext.util.Messages;
067:
068:        import org.eclipse.jdt.ui.JavaUI;
069:        import org.eclipse.jdt.ui.PreferenceConstants;
070:        import org.eclipse.jdt.ui.wizards.NewElementWizardPage;
071:
072:        import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
073:        import org.eclipse.jdt.internal.ui.JavaPlugin;
074:        import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
075:        import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
076:        import org.eclipse.jdt.internal.ui.wizards.TypedElementSelectionValidator;
077:        import org.eclipse.jdt.internal.ui.wizards.TypedViewerFilter;
078:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
079:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
080:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter;
081:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil;
082:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField;
083:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
084:        import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField;
085:
086:        public class AddSourceFolderWizardPage extends NewElementWizardPage {
087:
088:            private final class LinkFields implements  IStringButtonAdapter,
089:                    IDialogFieldListener {
090:                private StringButtonDialogField fLinkLocation;
091:
092:                private static final String DIALOGSTORE_LAST_EXTERNAL_LOC = JavaUI.ID_PLUGIN
093:                        + ".last.external.project"; //$NON-NLS-1$
094:
095:                private RootFieldAdapter fAdapter;
096:
097:                private SelectionButtonDialogField fVariables;
098:
099:                public LinkFields() {
100:                    fLinkLocation = new StringButtonDialogField(this );
101:
102:                    fLinkLocation
103:                            .setLabelText(NewWizardMessages.LinkFolderDialog_dependenciesGroup_locationLabel_desc);
104:                    fLinkLocation
105:                            .setButtonLabel(NewWizardMessages.LinkFolderDialog_dependenciesGroup_browseButton_desc);
106:                    fLinkLocation.setDialogFieldListener(this );
107:
108:                    fVariables = new SelectionButtonDialogField(SWT.PUSH);
109:                    fVariables
110:                            .setLabelText(NewWizardMessages.LinkFolderDialog_dependenciesGroup_variables_desc);
111:                    fVariables
112:                            .setDialogFieldListener(new IDialogFieldListener() {
113:                                public void dialogFieldChanged(DialogField field) {
114:                                    handleVariablesButtonPressed();
115:                                }
116:                            });
117:                }
118:
119:                public void setDialogFieldListener(RootFieldAdapter adapter) {
120:                    fAdapter = adapter;
121:                }
122:
123:                private void doFillIntoGrid(Composite parent, int numColumns) {
124:                    fLinkLocation.doFillIntoGrid(parent, numColumns);
125:
126:                    LayoutUtil.setHorizontalSpan(fLinkLocation
127:                            .getLabelControl(null), numColumns);
128:                    LayoutUtil.setHorizontalGrabbing(fLinkLocation
129:                            .getTextControl(null));
130:
131:                    fVariables.doFillIntoGrid(parent, 1);
132:                }
133:
134:                public IPath getLinkTarget() {
135:                    return Path.fromOSString(fLinkLocation.getText());
136:                }
137:
138:                public void setLinkTarget(IPath path) {
139:                    fLinkLocation.setText(path.toOSString());
140:                }
141:
142:                /*(non-Javadoc)
143:                 * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter#changeControlPressed(org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField)
144:                 */
145:                public void changeControlPressed(DialogField field) {
146:                    final DirectoryDialog dialog = new DirectoryDialog(
147:                            getShell());
148:                    dialog
149:                            .setMessage(NewWizardMessages.AddSourceFolderWizardPage_directory_message);
150:                    String directoryName = fLinkLocation.getText().trim();
151:                    if (directoryName.length() == 0) {
152:                        String prevLocation = JavaPlugin.getDefault()
153:                                .getDialogSettings().get(
154:                                        DIALOGSTORE_LAST_EXTERNAL_LOC);
155:                        if (prevLocation != null) {
156:                            directoryName = prevLocation;
157:                        }
158:                    }
159:
160:                    if (directoryName.length() > 0) {
161:                        final File path = new File(directoryName);
162:                        if (path.exists())
163:                            dialog.setFilterPath(directoryName);
164:                    }
165:                    final String selectedDirectory = dialog.open();
166:                    if (selectedDirectory != null) {
167:                        fLinkLocation.setText(selectedDirectory);
168:                        fRootDialogField.setText(selectedDirectory
169:                                .substring(selectedDirectory
170:                                        .lastIndexOf(File.separatorChar) + 1));
171:                        JavaPlugin.getDefault().getDialogSettings().put(
172:                                DIALOGSTORE_LAST_EXTERNAL_LOC,
173:                                selectedDirectory);
174:                        if (fAdapter != null) {
175:                            fAdapter.dialogFieldChanged(fRootDialogField);
176:                        }
177:                    }
178:                }
179:
180:                /**
181:                 * Opens a path variable selection dialog
182:                 */
183:                private void handleVariablesButtonPressed() {
184:                    int variableTypes = IResource.FOLDER;
185:                    PathVariableSelectionDialog dialog = new PathVariableSelectionDialog(
186:                            getShell(), variableTypes);
187:                    if (dialog.open() == IDialogConstants.OK_ID) {
188:                        String[] variableNames = (String[]) dialog.getResult();
189:                        if (variableNames != null && variableNames.length == 1) {
190:                            fLinkLocation.setText(variableNames[0]);
191:                            fRootDialogField.setText(variableNames[0]);
192:                            if (fAdapter != null) {
193:                                fAdapter.dialogFieldChanged(fRootDialogField);
194:                            }
195:                        }
196:                    }
197:                }
198:
199:                public void dialogFieldChanged(DialogField field) {
200:                    if (fAdapter != null) {
201:                        fAdapter.dialogFieldChanged(fLinkLocation);
202:                    }
203:                }
204:            }
205:
206:            private static final String PAGE_NAME = "NewSourceFolderWizardPage"; //$NON-NLS-1$
207:
208:            private final StringDialogField fRootDialogField;
209:            private final SelectionButtonDialogField fAddExclusionPatterns,
210:                    fRemoveProjectFolder, fIgnoreConflicts;
211:            private final LinkFields fLinkFields;
212:
213:            private final CPListElement fNewElement;
214:            private final List/*<CPListElement>*/fExistingEntries;
215:            private final Hashtable/*<CPListElement, IPath[]>*/fOrginalExlusionFilters,
216:                    fOrginalInclusionFilters,
217:                    fOrginalExlusionFiltersCopy,
218:                    fOrginalInclusionFiltersCopy;
219:            private final IPath fOrginalPath;
220:            private final boolean fLinkedMode;
221:
222:            private IPath fOutputLocation;
223:            private IPath fNewOutputLocation;
224:            private CPListElement fOldProjectSourceFolder;
225:
226:            private List fModifiedElements;
227:            private List fRemovedElements;
228:
229:            private final boolean fAllowConflict;
230:            private final boolean fAllowRemoveProjectFolder;
231:            private final boolean fAllowAddExclusionPatterns;
232:            private final boolean fCanCommitConflictingBuildpath;
233:            private final IContainer fParent;
234:
235:            public AddSourceFolderWizardPage(CPListElement newElement,
236:                    List/*<CPListElement>*/existingEntries,
237:                    IPath outputLocation, boolean linkedMode,
238:                    boolean canCommitConflictingBuildpath,
239:                    boolean allowIgnoreConflicts,
240:                    boolean allowRemoveProjectFolder,
241:                    boolean allowAddExclusionPatterns, IContainer parent) {
242:
243:                super (PAGE_NAME);
244:
245:                fLinkedMode = linkedMode;
246:                fCanCommitConflictingBuildpath = canCommitConflictingBuildpath;
247:                fAllowConflict = allowIgnoreConflicts;
248:                fAllowRemoveProjectFolder = allowRemoveProjectFolder;
249:                fAllowAddExclusionPatterns = allowAddExclusionPatterns;
250:                fParent = parent;
251:
252:                fOrginalExlusionFilters = new Hashtable();
253:                fOrginalInclusionFilters = new Hashtable();
254:                fOrginalExlusionFiltersCopy = new Hashtable();
255:                fOrginalInclusionFiltersCopy = new Hashtable();
256:                for (Iterator iter = existingEntries.iterator(); iter.hasNext();) {
257:                    CPListElement element = (CPListElement) iter.next();
258:                    IPath[] exlusions = (IPath[]) element
259:                            .getAttribute(CPListElement.EXCLUSION);
260:                    if (exlusions != null) {
261:                        IPath[] save = new IPath[exlusions.length];
262:                        for (int i = 0; i < save.length; i++) {
263:                            save[i] = exlusions[i];
264:                        }
265:                        fOrginalExlusionFiltersCopy.put(element, save);
266:                        fOrginalExlusionFilters.put(element, exlusions);
267:                    }
268:                    IPath[] inclusions = (IPath[]) element
269:                            .getAttribute(CPListElement.INCLUSION);
270:                    if (inclusions != null) {
271:                        IPath[] save = new IPath[inclusions.length];
272:                        for (int i = 0; i < save.length; i++) {
273:                            save[i] = inclusions[i];
274:                        }
275:                        fOrginalInclusionFiltersCopy.put(element, save);
276:                        fOrginalInclusionFilters.put(element, inclusions);
277:                    }
278:                }
279:
280:                setTitle(NewWizardMessages.NewSourceFolderWizardPage_title);
281:                fOrginalPath = newElement.getPath();
282:                if (fOrginalPath == null) {
283:                    if (linkedMode) {
284:                        setDescription(Messages.format(
285:                                NewWizardMessages.NewFolderDialog_createIn,
286:                                newElement.getJavaProject().getElementName()));
287:                    } else {
288:                        setDescription(Messages
289:                                .format(
290:                                        NewWizardMessages.AddSourceFolderWizardPage_description,
291:                                        fParent.getFullPath().toString()));
292:                    }
293:                } else {
294:                    setDescription(NewWizardMessages.NewSourceFolderWizardPage_edit_description);
295:                }
296:
297:                fNewElement = newElement;
298:                fExistingEntries = existingEntries;
299:                fModifiedElements = new ArrayList();
300:                fRemovedElements = new ArrayList();
301:                fOutputLocation = outputLocation;
302:
303:                RootFieldAdapter adapter = new RootFieldAdapter();
304:
305:                fRootDialogField = new StringDialogField();
306:                fRootDialogField
307:                        .setLabelText(NewWizardMessages.NewSourceFolderWizardPage_root_label);
308:                if (fNewElement.getPath() == null) {
309:                    fRootDialogField.setText(""); //$NON-NLS-1$
310:                } else {
311:                    setFolderDialogText(fNewElement.getPath());
312:                }
313:                fRootDialogField
314:                        .setEnabled(fNewElement.getJavaProject() != null);
315:
316:                int buttonStyle = SWT.CHECK;
317:                if ((fAllowConflict && fAllowAddExclusionPatterns)
318:                        || (fAllowConflict && fAllowRemoveProjectFolder)
319:                        || (fAllowAddExclusionPatterns && fAllowRemoveProjectFolder)) {
320:                    buttonStyle = SWT.RADIO;
321:                }
322:
323:                fAddExclusionPatterns = new SelectionButtonDialogField(
324:                        buttonStyle);
325:                fAddExclusionPatterns
326:                        .setLabelText(NewWizardMessages.NewSourceFolderWizardPage_exclude_label);
327:                fAddExclusionPatterns
328:                        .setSelection(!fCanCommitConflictingBuildpath
329:                                && !fAllowRemoveProjectFolder);
330:
331:                fRemoveProjectFolder = new SelectionButtonDialogField(
332:                        buttonStyle);
333:                fRemoveProjectFolder
334:                        .setLabelText(NewWizardMessages.NewSourceFolderWizardPage_ReplaceExistingSourceFolder_label);
335:                fRemoveProjectFolder
336:                        .setSelection(!fCanCommitConflictingBuildpath
337:                                && fAllowRemoveProjectFolder);
338:
339:                fIgnoreConflicts = new SelectionButtonDialogField(buttonStyle);
340:                fIgnoreConflicts
341:                        .setLabelText(NewWizardMessages.AddSourceFolderWizardPage_ignoreNestingConflicts);
342:                fIgnoreConflicts.setSelection(fCanCommitConflictingBuildpath);
343:
344:                fLinkFields = new LinkFields();
345:                if (fNewElement.getLinkTarget() != null) {
346:                    fLinkFields.setLinkTarget(fNewElement.getLinkTarget());
347:                }
348:
349:                fRemoveProjectFolder.setDialogFieldListener(adapter);
350:                fAddExclusionPatterns.setDialogFieldListener(adapter);
351:                fIgnoreConflicts.setDialogFieldListener(adapter);
352:                fRootDialogField.setDialogFieldListener(adapter);
353:                fLinkFields.setDialogFieldListener(adapter);
354:
355:                packRootDialogFieldChanged();
356:            }
357:
358:            // -------- UI Creation ---------
359:
360:            /*
361:             * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
362:             */
363:            public void createControl(Composite parent) {
364:                initializeDialogUnits(parent);
365:
366:                Composite composite = new Composite(parent, SWT.NONE);
367:
368:                GridLayout layout = new GridLayout();
369:                layout.numColumns = 4;
370:                composite.setLayout(layout);
371:
372:                if (fLinkedMode) {
373:                    fLinkFields.doFillIntoGrid(composite, layout.numColumns);
374:                    fRootDialogField.doFillIntoGrid(composite,
375:                            layout.numColumns - 1);
376:                } else {
377:                    fRootDialogField.doFillIntoGrid(composite,
378:                            layout.numColumns - 1);
379:                }
380:
381:                if (fAllowRemoveProjectFolder)
382:                    fRemoveProjectFolder.doFillIntoGrid(composite,
383:                            layout.numColumns);
384:
385:                if (fAllowAddExclusionPatterns)
386:                    fAddExclusionPatterns.doFillIntoGrid(composite,
387:                            layout.numColumns);
388:
389:                if (fAllowConflict)
390:                    fIgnoreConflicts.doFillIntoGrid(composite,
391:                            layout.numColumns);
392:
393:                LayoutUtil.setHorizontalSpan(fRootDialogField
394:                        .getLabelControl(null), layout.numColumns);
395:                LayoutUtil.setHorizontalGrabbing(fRootDialogField
396:                        .getTextControl(null));
397:
398:                setControl(composite);
399:                Dialog.applyDialogFont(composite);
400:                PlatformUI.getWorkbench().getHelpSystem().setHelp(composite,
401:                        IJavaHelpContextIds.NEW_PACKAGEROOT_WIZARD_PAGE);
402:            }
403:
404:            /*
405:             * @see org.eclipse.jface.dialogs.IDialogPage#setVisible(boolean)
406:             */
407:            public void setVisible(boolean visible) {
408:                super .setVisible(visible);
409:                if (visible) {
410:                    fRootDialogField.setFocus();
411:                }
412:            }
413:
414:            // -------- ContainerFieldAdapter --------
415:
416:            private class RootFieldAdapter implements  IStringButtonAdapter,
417:                    IDialogFieldListener {
418:
419:                // -------- IStringButtonAdapter
420:                public void changeControlPressed(DialogField field) {
421:                    packRootChangeControlPressed(field);
422:                }
423:
424:                // -------- IDialogFieldListener
425:                public void dialogFieldChanged(DialogField field) {
426:                    packRootDialogFieldChanged();
427:                }
428:            }
429:
430:            protected void packRootChangeControlPressed(DialogField field) {
431:                if (field == fRootDialogField) {
432:                    IPath initialPath = new Path(fRootDialogField.getText());
433:                    String title = NewWizardMessages.NewSourceFolderWizardPage_ChooseExistingRootDialog_title;
434:                    String message = NewWizardMessages.NewSourceFolderWizardPage_ChooseExistingRootDialog_description;
435:                    IFolder folder = chooseFolder(title, message, initialPath);
436:                    if (folder != null) {
437:                        setFolderDialogText(folder.getFullPath());
438:                    }
439:                }
440:            }
441:
442:            private void setFolderDialogText(IPath path) {
443:                IPath shortPath = path.removeFirstSegments(1);
444:                fRootDialogField.setText(shortPath.toString());
445:            }
446:
447:            protected void packRootDialogFieldChanged() {
448:                StatusInfo status = updateRootStatus();
449:                updateStatus(new IStatus[] { status });
450:            }
451:
452:            private StatusInfo updateRootStatus() {
453:                IJavaProject javaProject = fNewElement.getJavaProject();
454:                IProject project = javaProject.getProject();
455:
456:                StatusInfo pathNameStatus = validatePathName(fRootDialogField
457:                        .getText(), fParent);
458:
459:                if (!pathNameStatus.isOK())
460:                    return pathNameStatus;
461:
462:                if (fLinkedMode) {
463:                    IStatus linkNameStatus = validateLinkLocation(fRootDialogField
464:                            .getText());
465:                    if (linkNameStatus.matches(IStatus.ERROR)) {
466:                        StatusInfo result = new StatusInfo();
467:                        result.setError(linkNameStatus.getMessage());
468:                        return result;
469:                    }
470:                }
471:
472:                StatusInfo result = new StatusInfo();
473:                result.setOK();
474:
475:                IPath projPath = project.getFullPath();
476:                IPath path = fParent.getFullPath().append(
477:                        fRootDialogField.getText());
478:
479:                restoreCPElements();
480:
481:                int projectEntryIndex = -1;
482:                boolean createFolderForExisting = false;
483:
484:                IFolder folder = fParent.getFolder(new Path(fRootDialogField
485:                        .getText()));
486:                for (int i = 0; i < fExistingEntries.size(); i++) {
487:                    IClasspathEntry curr = ((CPListElement) fExistingEntries
488:                            .get(i)).getClasspathEntry();
489:                    if (curr.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
490:                        if (path.equals(curr.getPath())
491:                                && fExistingEntries.get(i) != fNewElement) {
492:                            if (folder.exists()) {
493:                                result
494:                                        .setError(NewWizardMessages.NewSourceFolderWizardPage_error_AlreadyExisting);
495:                                return result;
496:                            } else {
497:                                createFolderForExisting = true;
498:                            }
499:                        }
500:                        if (projPath.equals(curr.getPath())) {
501:                            projectEntryIndex = i;
502:                        }
503:                    }
504:                }
505:
506:                if (folder.exists()
507:                        && !folder.getFullPath().equals(fOrginalPath))
508:                    return new StatusInfo(
509:                            IStatus.ERROR,
510:                            Messages
511:                                    .format(
512:                                            NewWizardMessages.NewFolderDialog_folderNameEmpty_alreadyExists,
513:                                            folder.getFullPath().toString()));
514:
515:                boolean isProjectASourceFolder = projectEntryIndex != -1;
516:
517:                fModifiedElements.clear();
518:                updateFilters(fNewElement.getPath(), path);
519:
520:                fNewElement.setPath(path);
521:                if (fLinkedMode) {
522:                    fNewElement.setLinkTarget(fLinkFields.getLinkTarget());
523:                }
524:                fRemovedElements.clear();
525:                Set modified = new HashSet();
526:                boolean isProjectSourceFolderReplaced = false;
527:                if (fAddExclusionPatterns.isSelected()) {
528:                    if (fOrginalPath == null) {
529:                        addExclusionPatterns(fNewElement, fExistingEntries,
530:                                modified);
531:                        fModifiedElements.addAll(modified);
532:                        if (!createFolderForExisting)
533:                            CPListElement.insert(fNewElement, fExistingEntries);
534:                    }
535:                } else {
536:                    if (isProjectASourceFolder) {
537:                        if (fRemoveProjectFolder.isSelected()) {
538:                            fOldProjectSourceFolder = (CPListElement) fExistingEntries
539:                                    .get(projectEntryIndex);
540:                            fRemovedElements.add(fOldProjectSourceFolder);
541:                            fExistingEntries
542:                                    .set(projectEntryIndex, fNewElement);
543:                            isProjectSourceFolderReplaced = true;
544:                        } else {
545:                            if (!createFolderForExisting)
546:                                CPListElement.insert(fNewElement,
547:                                        fExistingEntries);
548:                        }
549:                    } else {
550:                        if (!createFolderForExisting)
551:                            CPListElement.insert(fNewElement, fExistingEntries);
552:                    }
553:                }
554:
555:                if ((!fAllowConflict && fCanCommitConflictingBuildpath)
556:                        || createFolderForExisting)
557:                    return new StatusInfo();
558:
559:                fNewOutputLocation = null;
560:                IJavaModelStatus status = JavaConventions.validateClasspath(
561:                        javaProject, CPListElement
562:                                .convertToClasspathEntries(fExistingEntries),
563:                        fOutputLocation);
564:                if (!status.isOK()) {
565:                    if (fOutputLocation.equals(projPath)) {
566:                        //Try to change the output folder
567:                        fNewOutputLocation = projPath
568:                                .append(PreferenceConstants
569:                                        .getPreferenceStore()
570:                                        .getString(
571:                                                PreferenceConstants.SRCBIN_BINNAME));
572:                        IStatus status2 = JavaConventions
573:                                .validateClasspath(
574:                                        javaProject,
575:                                        CPListElement
576:                                                .convertToClasspathEntries(fExistingEntries),
577:                                        fNewOutputLocation);
578:                        if (status2.isOK()) {
579:                            if (isProjectSourceFolderReplaced) {
580:                                result
581:                                        .setInfo(Messages
582:                                                .format(
583:                                                        NewWizardMessages.NewSourceFolderWizardPage_warning_ReplaceSFandOL,
584:                                                        fNewOutputLocation
585:                                                                .makeRelative()
586:                                                                .toString()));
587:                            } else {
588:                                result
589:                                        .setInfo(Messages
590:                                                .format(
591:                                                        NewWizardMessages.NewSourceFolderWizardPage_warning_ReplaceOL,
592:                                                        fNewOutputLocation
593:                                                                .makeRelative()
594:                                                                .toString()));
595:                            }
596:                            return result;
597:                        }
598:                    }
599:                    //Don't know what the problem is, report to user
600:                    fNewOutputLocation = null;
601:                    if (fCanCommitConflictingBuildpath) {
602:                        result
603:                                .setInfo(NewWizardMessages.AddSourceFolderWizardPage_conflictWarning
604:                                        + status.getMessage());
605:                    } else {
606:                        result.setError(status.getMessage());
607:                    }
608:                    return result;
609:                }
610:                if (!modified.isEmpty()) {
611:                    //Added exclusion patterns to solve problem
612:                    if (modified.size() == 1) {
613:                        CPListElement elem = (CPListElement) modified.toArray()[0];
614:                        IPath changed = elem.getPath().makeRelative();
615:                        IPath excl = fNewElement.getPath().makeRelative();
616:                        result
617:                                .setInfo(Messages
618:                                        .format(
619:                                                NewWizardMessages.AddSourceFolderWizardPage_addSinglePattern,
620:                                                new Object[] { excl, changed }));
621:                    } else {
622:                        result
623:                                .setInfo(Messages
624:                                        .format(
625:                                                NewWizardMessages.NewSourceFolderWizardPage_warning_AddedExclusions,
626:                                                String.valueOf(modified.size())));
627:                    }
628:                    return result;
629:                }
630:                if (isProjectSourceFolderReplaced) {
631:                    result
632:                            .setInfo(NewWizardMessages.AddSourceFolderWizardPage_replaceSourceFolderInfo);
633:                    return result;
634:                }
635:
636:                return result;
637:            }
638:
639:            public void restore() {
640:                for (Iterator iter = fExistingEntries.iterator(); iter
641:                        .hasNext();) {
642:                    CPListElement element = (CPListElement) iter.next();
643:                    if (fOrginalExlusionFilters.containsKey(element)) {
644:                        element.setAttribute(CPListElement.EXCLUSION,
645:                                fOrginalExlusionFiltersCopy.get(element));
646:                    }
647:                    if (fOrginalInclusionFilters.containsKey(element)) {
648:                        element.setAttribute(CPListElement.INCLUSION,
649:                                fOrginalInclusionFiltersCopy.get(element));
650:                    }
651:                }
652:                fNewElement.setPath(fOrginalPath);
653:            }
654:
655:            private void restoreCPElements() {
656:                if (fNewElement.getPath() != null) {
657:                    for (Iterator iter = fExistingEntries.iterator(); iter
658:                            .hasNext();) {
659:                        CPListElement element = (CPListElement) iter.next();
660:                        if (fOrginalExlusionFilters.containsKey(element)) {
661:                            element.setAttribute(CPListElement.EXCLUSION,
662:                                    fOrginalExlusionFilters.get(element));
663:                        }
664:                        if (fOrginalInclusionFilters.containsKey(element)) {
665:                            element.setAttribute(CPListElement.INCLUSION,
666:                                    fOrginalInclusionFilters.get(element));
667:                        }
668:                    }
669:
670:                    if (fOldProjectSourceFolder != null) {
671:                        fExistingEntries.set(fExistingEntries
672:                                .indexOf(fNewElement), fOldProjectSourceFolder);
673:                        fOldProjectSourceFolder = null;
674:                    } else if (fExistingEntries.contains(fNewElement)) {
675:                        fExistingEntries.remove(fNewElement);
676:                    }
677:                }
678:            }
679:
680:            private void updateFilters(IPath oldPath, IPath newPath) {
681:                if (oldPath == null)
682:                    return;
683:
684:                IPath projPath = fNewElement.getJavaProject().getProject()
685:                        .getFullPath();
686:                if (projPath.isPrefixOf(oldPath)) {
687:                    oldPath = oldPath.removeFirstSegments(
688:                            projPath.segmentCount()).addTrailingSeparator();
689:                }
690:                if (projPath.isPrefixOf(newPath)) {
691:                    newPath = newPath.removeFirstSegments(
692:                            projPath.segmentCount()).addTrailingSeparator();
693:                }
694:
695:                for (Iterator iter = fExistingEntries.iterator(); iter
696:                        .hasNext();) {
697:                    CPListElement element = (CPListElement) iter.next();
698:                    IPath elementPath = element.getPath();
699:                    if (projPath.isPrefixOf(elementPath)) {
700:                        elementPath = elementPath.removeFirstSegments(projPath
701:                                .segmentCount());
702:                        if (elementPath.segmentCount() > 0)
703:                            elementPath = elementPath.addTrailingSeparator();
704:                    }
705:
706:                    IPath[] exlusions = (IPath[]) element
707:                            .getAttribute(CPListElement.EXCLUSION);
708:                    if (exlusions != null) {
709:                        for (int i = 0; i < exlusions.length; i++) {
710:                            if (elementPath.append(exlusions[i])
711:                                    .equals(oldPath)) {
712:                                fModifiedElements.add(element);
713:                                exlusions[i] = newPath
714:                                        .removeFirstSegments(elementPath
715:                                                .segmentCount());
716:                            }
717:                        }
718:                        element
719:                                .setAttribute(CPListElement.EXCLUSION,
720:                                        exlusions);
721:                    }
722:
723:                    IPath[] inclusion = (IPath[]) element
724:                            .getAttribute(CPListElement.INCLUSION);
725:                    if (inclusion != null) {
726:                        for (int i = 0; i < inclusion.length; i++) {
727:                            if (elementPath.append(inclusion[i])
728:                                    .equals(oldPath)) {
729:                                fModifiedElements.add(element);
730:                                inclusion[i] = newPath
731:                                        .removeFirstSegments(elementPath
732:                                                .segmentCount());
733:                            }
734:                        }
735:                        element
736:                                .setAttribute(CPListElement.INCLUSION,
737:                                        inclusion);
738:                    }
739:                }
740:            }
741:
742:            /**
743:             * Validates this page's controls.
744:             * @param folderName the folder name
745:             *
746:             * @return IStatus indicating the validation result. IStatus.OK if the 
747:             *  specified link target is valid given the linkHandle.
748:             */
749:            private IStatus validateLinkLocation(String folderName) {
750:                IWorkspace workspace = JavaPlugin.getWorkspace();
751:                IPath path = Path.fromOSString(fLinkFields.fLinkLocation
752:                        .getText());
753:
754:                IFolder folder = fNewElement.getJavaProject().getProject()
755:                        .getFolder(new Path(folderName));
756:                IStatus locationStatus = workspace.validateLinkLocation(folder,
757:                        path);
758:                if (locationStatus.matches(IStatus.ERROR))
759:                    return locationStatus;
760:
761:                IPathVariableManager pathVariableManager = ResourcesPlugin
762:                        .getWorkspace().getPathVariableManager();
763:                IPath path1 = Path.fromOSString(fLinkFields.fLinkLocation
764:                        .getText());
765:                IPath resolvedPath = pathVariableManager.resolvePath(path1);
766:                // use the resolved link target name
767:                String resolvedLinkTarget = resolvedPath.toOSString();
768:
769:                path = new Path(resolvedLinkTarget);
770:                File linkTargetFile = new Path(resolvedLinkTarget).toFile();
771:                if (linkTargetFile.exists()) {
772:                    if (!linkTargetFile.isDirectory())
773:                        return new StatusInfo(
774:                                IStatus.ERROR,
775:                                NewWizardMessages.NewFolderDialog_linkTargetNotFolder);
776:                } else {
777:                    return new StatusInfo(
778:                            IStatus.ERROR,
779:                            NewWizardMessages.NewFolderDialog_linkTargetNonExistent);
780:                }
781:                if (locationStatus.isOK()) {
782:                    return new StatusInfo();
783:                }
784:                return new StatusInfo(locationStatus.getSeverity(),
785:                        locationStatus.getMessage());
786:            }
787:
788:            private static StatusInfo validatePathName(String str,
789:                    IContainer parent) {
790:                StatusInfo result = new StatusInfo();
791:                result.setOK();
792:
793:                IPath parentPath = parent.getFullPath();
794:
795:                if (str.length() == 0) {
796:                    result
797:                            .setError(Messages
798:                                    .format(
799:                                            NewWizardMessages.NewSourceFolderWizardPage_error_EnterRootName,
800:                                            parentPath.toString()));
801:                    return result;
802:                }
803:
804:                IPath path = parentPath.append(str);
805:
806:                IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace()
807:                        .getRoot();
808:                IStatus validate = workspaceRoot.getWorkspace().validatePath(
809:                        path.toString(), IResource.FOLDER);
810:                if (validate.matches(IStatus.ERROR)) {
811:                    result
812:                            .setError(Messages
813:                                    .format(
814:                                            NewWizardMessages.NewSourceFolderWizardPage_error_InvalidRootName,
815:                                            validate.getMessage()));
816:                    return result;
817:                }
818:
819:                IResource res = workspaceRoot.findMember(path);
820:                if (res != null) {
821:                    if (res.getType() != IResource.FOLDER) {
822:                        result
823:                                .setError(NewWizardMessages.NewSourceFolderWizardPage_error_NotAFolder);
824:                        return result;
825:                    }
826:                } else {
827:
828:                    URI parentLocation = parent.getLocationURI();
829:                    if (parentLocation != null) {
830:                        try {
831:                            IFileStore store = EFS.getStore(parentLocation)
832:                                    .getChild(str);
833:                            if (store.fetchInfo().exists()) {
834:                                result
835:                                        .setError(NewWizardMessages.NewSourceFolderWizardPage_error_AlreadyExistingDifferentCase);
836:                                return result;
837:                            }
838:                        } catch (CoreException e) {
839:                            // we couldn't create the file store. Ignore the exception
840:                            // since we can't check if the file exist. Pretend that it
841:                            // doesn't.
842:                        }
843:                    }
844:                }
845:
846:                return result;
847:            }
848:
849:            private void addExclusionPatterns(CPListElement newEntry,
850:                    List existing, Set modifiedEntries) {
851:                IPath entryPath = newEntry.getPath();
852:                for (int i = 0; i < existing.size(); i++) {
853:                    CPListElement curr = (CPListElement) existing.get(i);
854:                    IPath currPath = curr.getPath();
855:                    if (curr != newEntry
856:                            && curr.getEntryKind() == IClasspathEntry.CPE_SOURCE
857:                            && currPath.isPrefixOf(entryPath)) {
858:                        boolean added = curr.addToExclusions(entryPath);
859:                        if (added) {
860:                            modifiedEntries.add(curr);
861:                        }
862:                    }
863:                }
864:            }
865:
866:            public IResource getCorrespondingResource() {
867:                return fParent.getFolder(new Path(fRootDialogField.getText()));
868:            }
869:
870:            public IPath getOutputLocation() {
871:                if (fNewOutputLocation != null) {
872:                    return fNewOutputLocation;
873:                }
874:
875:                return fOutputLocation;
876:            }
877:
878:            // ------------- choose dialogs
879:
880:            private IFolder chooseFolder(String title, String message,
881:                    IPath initialPath) {
882:                Class[] acceptedClasses = new Class[] { IFolder.class };
883:                ISelectionStatusValidator validator = new TypedElementSelectionValidator(
884:                        acceptedClasses, false);
885:                ViewerFilter filter = new TypedViewerFilter(acceptedClasses,
886:                        null);
887:
888:                ILabelProvider lp = new WorkbenchLabelProvider();
889:                ITreeContentProvider cp = new WorkbenchContentProvider();
890:
891:                IProject currProject = fNewElement.getJavaProject()
892:                        .getProject();
893:
894:                ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(
895:                        getShell(), lp, cp) {
896:                    protected Control createDialogArea(Composite parent) {
897:                        Control result = super .createDialogArea(parent);
898:                        PlatformUI
899:                                .getWorkbench()
900:                                .getHelpSystem()
901:                                .setHelp(
902:                                        parent,
903:                                        IJavaHelpContextIds.BP_CHOOSE_EXISTING_FOLDER_TO_MAKE_SOURCE_FOLDER);
904:                        return result;
905:                    }
906:                };
907:                dialog.setValidator(validator);
908:                dialog.setTitle(title);
909:                dialog.setMessage(message);
910:                dialog.addFilter(filter);
911:                dialog.setInput(currProject);
912:                dialog.setComparator(new ResourceComparator(
913:                        ResourceComparator.NAME));
914:                IResource res = currProject.findMember(initialPath);
915:                if (res != null) {
916:                    dialog.setInitialSelection(res);
917:                }
918:
919:                if (dialog.open() == Window.OK) {
920:                    return (IFolder) dialog.getFirstResult();
921:                }
922:                return null;
923:            }
924:
925:            public List getModifiedElements() {
926:                if (fOrginalPath != null
927:                        && !fModifiedElements.contains(fNewElement))
928:                    fModifiedElements.add(fNewElement);
929:
930:                return fModifiedElements;
931:            }
932:
933:            public List getRemovedElements() {
934:                return fRemovedElements;
935:            }
936:
937:        }
ww__w__.___j__a_v__a_2__s_.__c___o__m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.