|
Lines 12-17
Link Here
|
| 12 |
package org.eclipse.hyades.ui.internal.wizard; |
12 |
package org.eclipse.hyades.ui.internal.wizard; |
| 13 |
|
13 |
|
| 14 |
import org.eclipse.core.resources.IFile; |
14 |
import org.eclipse.core.resources.IFile; |
|
|
15 |
import org.eclipse.core.resources.IProject; |
| 15 |
import org.eclipse.core.resources.IResource; |
16 |
import org.eclipse.core.resources.IResource; |
| 16 |
import org.eclipse.core.resources.IWorkspaceRoot; |
17 |
import org.eclipse.core.resources.IWorkspaceRoot; |
| 17 |
import org.eclipse.core.resources.ResourcesPlugin; |
18 |
import org.eclipse.core.resources.ResourcesPlugin; |
|
Lines 20-41
Link Here
|
| 20 |
import org.eclipse.hyades.ui.HyadesUIPlugin; |
21 |
import org.eclipse.hyades.ui.HyadesUIPlugin; |
| 21 |
import org.eclipse.hyades.ui.internal.util.ResourceUtil; |
22 |
import org.eclipse.hyades.ui.internal.util.ResourceUtil; |
| 22 |
import org.eclipse.hyades.ui.internal.util.UIUtil; |
23 |
import org.eclipse.hyades.ui.internal.util.UIUtil; |
|
|
24 |
import org.eclipse.jdt.core.IJavaProject; |
| 23 |
import org.eclipse.jface.viewers.IStructuredSelection; |
25 |
import org.eclipse.jface.viewers.IStructuredSelection; |
| 24 |
import org.eclipse.jface.viewers.StructuredSelection; |
26 |
import org.eclipse.jface.viewers.StructuredSelection; |
| 25 |
import org.eclipse.tptp.platform.common.ui.wizard.LocationPage; |
27 |
import org.eclipse.tptp.platform.common.ui.wizard.LocationPage; |
| 26 |
import org.eclipse.ui.INewWizard; |
28 |
import org.eclipse.ui.INewWizard; |
| 27 |
import org.eclipse.ui.PartInitException; |
29 |
import org.eclipse.ui.PartInitException; |
|
|
30 |
import org.eclipse.ui.actions.NewProjectAction; |
| 28 |
|
31 |
|
| 29 |
/** |
32 |
/** |
| 30 |
* Abstract extension of the Eclipse's <code>NewWizard</code> that defines a location |
33 |
* Abstract extension of the Eclipse's <code>NewWizard</code> that defines a location |
| 31 |
* page and a "name and description" page. The subclasses are supposed to add the pages |
34 |
* page and a "name and description" page. The subclasses are supposed to add the pages |
| 32 |
* in the appropriate order and using the correct values for their titles and descriptions. |
35 |
* in the appropriate order and using the correct values for their titles and descriptions. |
| 33 |
* |
36 |
* <p/> |
| 34 |
* <p>This implementation is based on the |
37 |
* This implementation is based on the |
| 35 |
* <code>org.eclipse.ui.wizards.newresource.BasicNewResourceWizard</code> class. |
38 |
* <code>org.eclipse.ui.wizards.newresource.BasicNewResourceWizard</code> class. |
|
|
39 |
* <p/> |
| 40 |
* |
| 36 |
* |
41 |
* |
| 37 |
* @author marcelop |
42 |
* @author Marcelo Paternostro |
| 38 |
* @since 0.0.1 |
43 |
* @author Paul E. Slauenwhite |
|
|
44 |
* @version April 16, 2008 |
| 45 |
* @since January 26, 2005 |
| 39 |
*/ |
46 |
*/ |
| 40 |
public abstract class HyadesNewWizard extends HyadesWizard implements INewWizard { |
47 |
public abstract class HyadesNewWizard extends HyadesWizard implements INewWizard { |
| 41 |
/* |
48 |
/* |
|
Lines 63-86
Link Here
|
| 63 |
} |
70 |
} |
| 64 |
|
71 |
|
| 65 |
/** |
72 |
/** |
| 66 |
* Adjusts the selection passed to this wizard. |
73 |
* Adjusts the {@link IStructuredSelection} passed to this wizard. |
| 67 |
* @return IStructuredSelection |
74 |
* <p/> |
|
|
75 |
* |
| 76 |
* @return The adjusted {@link IStructuredSelection}. |
| 68 |
*/ |
77 |
*/ |
| 69 |
protected IStructuredSelection adjustSeletion() { |
78 |
protected IStructuredSelection adjustSeletion() { |
| 70 |
IStructuredSelection structuredSelection = getSelection(); |
79 |
|
| 71 |
if (getDialogSettings() != null) { |
80 |
//Case 1: Workspace does not contain an open project so open the create project wizard (File >> New >> Project...): |
| 72 |
if ((structuredSelection == null) || (structuredSelection.isEmpty())) { |
81 |
if(UIUtil.getFirstOpenProject() == null){ |
| 73 |
String lastSelection = getDialogSettings().get(SET_LAST_SELECTION); |
82 |
|
| 74 |
if (lastSelection != null) { |
83 |
new NewProjectAction().run(); |
| 75 |
IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(lastSelection); |
84 |
|
| 76 |
if ((resource != null) && (resource.exists())) structuredSelection = new StructuredSelection(resource); |
85 |
IProject newProject = UIUtil.getFirstOpenProject(); |
| 77 |
} |
86 |
|
| 78 |
} |
87 |
if(newProject != null){ |
| 79 |
} |
88 |
return (new StructuredSelection(newProject)); |
|
|
89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
IStructuredSelection structuredSelection = getSelection(); |
| 93 |
|
| 94 |
//Case 2: Selection contains a resource (project or folder/file) so check if accessible (open for projects and exists for folders/files): |
| 95 |
if ((structuredSelection != null) && (!structuredSelection.isEmpty())) { |
| 96 |
|
| 97 |
IResource resource = null; |
| 98 |
Object firstSelectedElement = structuredSelection.getFirstElement(); |
| 99 |
|
| 100 |
if(firstSelectedElement instanceof IResource){ |
| 101 |
resource = ((IResource)(firstSelectedElement)); |
| 102 |
} |
| 103 |
else if(firstSelectedElement instanceof IJavaProject){ |
| 104 |
resource = ((IJavaProject)(firstSelectedElement)).getProject(); |
| 105 |
} |
| 106 |
|
| 107 |
if ((resource != null) && (resource.isAccessible())){ |
| 108 |
return structuredSelection; |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
//Case 3: Selection is null/empty so check if the last selected resource (project or folder/file) for the dialog is accessible (open for projects and exists for folders/files): |
| 113 |
if (getDialogSettings() != null) { |
| 114 |
|
| 115 |
String lastSelection = getDialogSettings().get(SET_LAST_SELECTION); |
| 116 |
|
| 117 |
if (lastSelection != null) { |
| 118 |
|
| 119 |
IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(lastSelection); |
| 120 |
|
| 121 |
if ((resource != null) && (resource.isAccessible())){ |
| 122 |
return (new StructuredSelection(resource)); |
| 123 |
} |
| 124 |
} |
| 125 |
} |
| 80 |
|
126 |
|
| 81 |
return structuredSelection; |
127 |
//Case 4: Return an empty selection: |
|
|
128 |
return (StructuredSelection.EMPTY); |
| 82 |
} |
129 |
} |
| 83 |
|
130 |
|
| 84 |
/** |
131 |
/** |
| 85 |
* Returns the location page used by this wizard. |
132 |
* Returns the location page used by this wizard. |
| 86 |
* @return LocationPage |
133 |
* @return LocationPage |
|
Lines 138-143
Link Here
|
| 138 |
handleException(file.getFullPath().toString(), e); |
185 |
handleException(file.getFullPath().toString(), e); |
| 139 |
} |
186 |
} |
| 140 |
|
187 |
|
|
|
188 |
//Save the last selected resource (project or folder/file) for the dialog: |
| 189 |
getDialogSettings().put(SET_LAST_SELECTION, getLocationPage().getContainerFullPath().toString()); |
| 190 |
|
| 141 |
return true; |
191 |
return true; |
| 142 |
} |
192 |
} |
| 143 |
|
193 |
|