| 1 |
<%@ jet package="org.eclipse.emf.codegen.ecore.templates.editor" imports="org.eclipse.emf.codegen.ecore.genmodel.*" class="ModelWizard"%> |
| 2 |
<% |
| 3 |
/** |
| 4 |
* Copyright (c) 2002-2010 IBM Corporation and others. |
| 5 |
* All rights reserved. This program and the accompanying materials |
| 6 |
* are made available under the terms of the Eclipse Public License v2.0 |
| 7 |
* which accompanies this distribution, and is available at |
| 8 |
* http://www.eclipse.org/legal/epl-v20.html |
| 9 |
* |
| 10 |
* Contributors: |
| 11 |
* IBM - Initial API and implementation |
| 12 |
*/ |
| 13 |
%> |
| 14 |
<%GenPackage genPackage = (GenPackage)argument; GenModel genModel=genPackage.getGenModel();%> |
| 15 |
<%final boolean isJDK50 = genModel.getComplianceLevel().getValue() >= GenJDKLevel.JDK50;%> |
| 16 |
<%@ include file="../Header.javajetinc"%> |
| 17 |
<%String _ListOfString = "List" + (genModel.useGenerics() ? "<" + genModel.getImportedName("java.lang.String") + ">" : "");%> |
| 18 |
<%String _ArrayListOfString = "ArrayList" + (genModel.useGenerics() ? "<" + genModel.getImportedName("java.lang.String") + ">" : "");%> |
| 19 |
<%String _CollectionOfString = "Collection" + (genModel.useGenerics() ? "<" + genModel.getImportedName("java.lang.String") + ">" : "");%> |
| 20 |
<%String _MapOfObjectToObject = "Map" + (genModel.useGenerics() ? "<" + genModel.getImportedName("java.lang.Object") + ", " + genModel.getImportedName("java.lang.Object") + ">" : "");%> |
| 21 |
<%String _HashMapOfObjectToObject = "HashMap" + (genModel.useGenerics() ? "<" + genModel.getImportedName("java.lang.Object") + ", " + genModel.getImportedName("java.lang.Object") + ">" : "");%> |
| 22 |
package <%=genPackage.getPresentationPackageName()%>; |
| 23 |
|
| 24 |
|
| 25 |
import java.util.ArrayList; |
| 26 |
import java.util.Arrays; |
| 27 |
import java.util.Collection; |
| 28 |
import java.util.Collections; |
| 29 |
import java.util.HashMap; |
| 30 |
<%if (!genModel.useGenerics()) {%> |
| 31 |
import java.util.Iterator; |
| 32 |
<%}%> |
| 33 |
import java.util.List; |
| 34 |
import java.util.Map; |
| 35 |
import java.util.MissingResourceException; |
| 36 |
import java.util.StringTokenizer; |
| 37 |
|
| 38 |
<%if (!genModel.isRichClientPlatform() && genModel.getComplianceLevel().getValue() >= GenJDKLevel.JDK50) {%> |
| 39 |
import org.eclipse.emf.common.CommonPlugin; |
| 40 |
|
| 41 |
<%}%> |
| 42 |
import org.eclipse.emf.common.util.URI; |
| 43 |
|
| 44 |
import org.eclipse.emf.ecore.EClass; |
| 45 |
import org.eclipse.emf.ecore.EClassifier; |
| 46 |
|
| 47 |
import org.eclipse.emf.ecore.resource.Resource; |
| 48 |
import org.eclipse.emf.ecore.resource.ResourceSet; |
| 49 |
|
| 50 |
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; |
| 51 |
|
| 52 |
import org.eclipse.emf.ecore.EObject; |
| 53 |
|
| 54 |
import org.eclipse.emf.ecore.xmi.XMLResource; |
| 55 |
|
| 56 |
import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry; |
| 57 |
|
| 58 |
<%if (!genModel.isRichClientPlatform()) {%> |
| 59 |
import org.eclipse.core.resources.IContainer; |
| 60 |
import org.eclipse.core.resources.IFile; |
| 61 |
import org.eclipse.core.resources.IFolder; |
| 62 |
import org.eclipse.core.resources.IProject; |
| 63 |
import org.eclipse.core.resources.IResource; |
| 64 |
import org.eclipse.core.resources.ResourcesPlugin; |
| 65 |
|
| 66 |
<%}%> |
| 67 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 68 |
|
| 69 |
import org.eclipse.jface.dialogs.MessageDialog; |
| 70 |
|
| 71 |
import org.eclipse.jface.viewers.IStructuredSelection; |
| 72 |
|
| 73 |
import org.eclipse.jface.wizard.Wizard; |
| 74 |
import org.eclipse.jface.wizard.WizardPage; |
| 75 |
|
| 76 |
import org.eclipse.swt.SWT; |
| 77 |
|
| 78 |
import org.eclipse.swt.events.ModifyListener; |
| 79 |
import org.eclipse.swt.events.ModifyEvent; |
| 80 |
|
| 81 |
import org.eclipse.swt.layout.GridData; |
| 82 |
import org.eclipse.swt.layout.GridLayout; |
| 83 |
|
| 84 |
import org.eclipse.swt.widgets.Combo; |
| 85 |
import org.eclipse.swt.widgets.Composite; |
| 86 |
import org.eclipse.swt.widgets.Label; |
| 87 |
|
| 88 |
import org.eclipse.ui.INewWizard; |
| 89 |
import org.eclipse.ui.IWorkbench; |
| 90 |
|
| 91 |
<%if (!genModel.isRichClientPlatform()) {%> |
| 92 |
import org.eclipse.ui.actions.WorkspaceModifyOperation; |
| 93 |
|
| 94 |
import org.eclipse.ui.dialogs.WizardNewFileCreationPage; |
| 95 |
|
| 96 |
import org.eclipse.ui.part.FileEditorInput; |
| 97 |
import org.eclipse.ui.part.ISetSelectionTarget; |
| 98 |
|
| 99 |
<%}%> |
| 100 |
<%if (!genModel.isSuppressEMFMetaData()) {%> |
| 101 |
import <%=genPackage.getQualifiedFactoryInterfaceName()%>; |
| 102 |
<%}%> |
| 103 |
import <%=genPackage.getQualifiedPackageInterfaceName()%>; |
| 104 |
import <%=genPackage.getQualifiedEditPluginClassName()%>; |
| 105 |
|
| 106 |
|
| 107 |
<%genModel.markImportLocation(stringBuffer);%> |
| 108 |
|
| 109 |
|
| 110 |
/** |
| 111 |
* This is a simple wizard for creating a new model file. |
| 112 |
* <!-- begin-user-doc --> |
| 113 |
* <!-- end-user-doc --> |
| 114 |
<%if (genPackage.hasAPITags()) {%> |
| 115 |
* <%=genPackage.getAPITags(genModel.getIndentation(stringBuffer))%> |
| 116 |
<%}%> |
| 117 |
* @generated |
| 118 |
*/ |
| 119 |
<%if (isJDK50 && genPackage.hasAPIDeprecatedTag()) {%> |
| 120 |
@Deprecated |
| 121 |
<%}%> |
| 122 |
public class <%=genPackage.getModelWizardClassName()%> extends Wizard implements INewWizard |
| 123 |
{ |
| 124 |
<%if (genModel.hasCopyrightField()) {%> |
| 125 |
/** |
| 126 |
* <!-- begin-user-doc --> |
| 127 |
* <!-- end-user-doc --> |
| 128 |
* @generated |
| 129 |
*/ |
| 130 |
public static final <%=genModel.getImportedName("java.lang.String")%> copyright = <%=genModel.getCopyrightFieldLiteral()%>;<%=genModel.getNonNLS()%> |
| 131 |
|
| 132 |
<%}%> |
| 133 |
/** |
| 134 |
* The supported extensions for created files. |
| 135 |
* <!-- begin-user-doc --> |
| 136 |
* <!-- end-user-doc --> |
| 137 |
* @generated |
| 138 |
*/ |
| 139 |
public static final <%=_ListOfString%> FILE_EXTENSIONS = |
| 140 |
Collections.unmodifiableList(Arrays.asList(<%=genPackage.getImportedEditorPluginClassName()%>.INSTANCE.getString("_UI_<%=genPackage.getEditorClassName()%>FilenameExtensions").split("\\s*,\\s*")));<%=genModel.getNonNLS()%><%=genModel.getNonNLS(2)%> |
| 141 |
|
| 142 |
/** |
| 143 |
* A formatted list of supported file extensions, suitable for display. |
| 144 |
* <!-- begin-user-doc --> |
| 145 |
* <!-- end-user-doc --> |
| 146 |
* @generated |
| 147 |
*/ |
| 148 |
public static final String FORMATTED_FILE_EXTENSIONS = |
| 149 |
<%=genPackage.getImportedEditorPluginClassName()%>.INSTANCE.getString("_UI_<%=genPackage.getEditorClassName()%>FilenameExtensions").replaceAll("\\s*,\\s*", ", ");<%=genModel.getNonNLS()%><%=genModel.getNonNLS(2)%><%=genModel.getNonNLS(3)%> |
| 150 |
|
| 151 |
/** |
| 152 |
* This caches an instance of the model package. |
| 153 |
* <!-- begin-user-doc --> |
| 154 |
* <!-- end-user-doc --> |
| 155 |
* @generated |
| 156 |
*/ |
| 157 |
protected <%=genModel.isSuppressEMFMetaData() ? genModel.getImportedName("org.eclipse.emf.ecore.EPackage") : genPackage.getPackageInterfaceName()%> <%=genPackage.getUncapPackageName()%> = <%=genPackage.getPackageInterfaceName()%>.eINSTANCE; |
| 158 |
|
| 159 |
/** |
| 160 |
* This caches an instance of the model factory. |
| 161 |
* <!-- begin-user-doc --> |
| 162 |
* <!-- end-user-doc --> |
| 163 |
* @generated |
| 164 |
*/ |
| 165 |
protected <%=genModel.isSuppressEMFMetaData() ? genModel.getImportedName("org.eclipse.emf.ecore.EFactory") : genPackage.getFactoryInterfaceName()%> <%=genPackage.getUncapFactoryName()%> = <%=genPackage.getUncapPackageName()%>.get<%=genModel.isSuppressEMFMetaData() ? "EFactoryInstance" : genPackage.getFactoryName()%>(); |
| 166 |
|
| 167 |
<%if (!genModel.isRichClientPlatform()) {%> |
| 168 |
/** |
| 169 |
* This is the file creation page. |
| 170 |
* <!-- begin-user-doc --> |
| 171 |
* <!-- end-user-doc --> |
| 172 |
* @generated |
| 173 |
*/ |
| 174 |
protected <%=genPackage.getModelWizardClassName()%>NewFileCreationPage newFileCreationPage; |
| 175 |
|
| 176 |
<%}%> |
| 177 |
/** |
| 178 |
* This is the initial object creation page. |
| 179 |
* <!-- begin-user-doc --> |
| 180 |
* <!-- end-user-doc --> |
| 181 |
* @generated |
| 182 |
*/ |
| 183 |
protected <%=genPackage.getModelWizardClassName()%>InitialObjectCreationPage initialObjectCreationPage; |
| 184 |
|
| 185 |
/** |
| 186 |
* Remember the selection during initialization for populating the default container. |
| 187 |
* <!-- begin-user-doc --> |
| 188 |
* <!-- end-user-doc --> |
| 189 |
* @generated |
| 190 |
*/ |
| 191 |
protected IStructuredSelection selection; |
| 192 |
|
| 193 |
/** |
| 194 |
* Remember the workbench during initialization. |
| 195 |
* <!-- begin-user-doc --> |
| 196 |
* <!-- end-user-doc --> |
| 197 |
* @generated |
| 198 |
*/ |
| 199 |
protected IWorkbench workbench; |
| 200 |
|
| 201 |
/** |
| 202 |
<%if (!genPackage.hasDocumentRoot()) {%> |
| 203 |
* Caches the names of the types that can be created as the root object. |
| 204 |
<%} else {%> |
| 205 |
* Caches the names of the features representing global elements. |
| 206 |
<%}%> |
| 207 |
* <!-- begin-user-doc --> |
| 208 |
* <!-- end-user-doc --> |
| 209 |
* @generated |
| 210 |
*/ |
| 211 |
protected <%=_ListOfString%> initialObjectNames; |
| 212 |
|
| 213 |
/** |
| 214 |
* This just records the information. |
| 215 |
* <!-- begin-user-doc --> |
| 216 |
* <!-- end-user-doc --> |
| 217 |
* @generated |
| 218 |
*/ |
| 219 |
<%if (genModel.useInterfaceOverrideAnnotation()) {%> |
| 220 |
@Override |
| 221 |
<%}%> |
| 222 |
public void init(IWorkbench workbench, IStructuredSelection selection) |
| 223 |
{ |
| 224 |
this.workbench = workbench; |
| 225 |
this.selection = selection; |
| 226 |
setWindowTitle(<%=genPackage.getImportedEditorPluginClassName()%>.INSTANCE.getString("_UI_Wizard_label"));<%=genModel.getNonNLS()%> |
| 227 |
setDefaultPageImageDescriptor(ExtendedImageRegistry.INSTANCE.getImageDescriptor(<%=genPackage.getImportedEditorPluginClassName()%>.INSTANCE.getImage("full/wizban/New<%=genPackage.getPrefix()%>")));<%=genModel.getNonNLS()%> |
| 228 |
} |
| 229 |
|
| 230 |
/** |
| 231 |
<%if (!genPackage.hasDocumentRoot()) {%> |
| 232 |
* Returns the names of the types that can be created as the root object. |
| 233 |
<%} else {%> |
| 234 |
* Returns the names of the features representing global elements. |
| 235 |
<%}%> |
| 236 |
* <!-- begin-user-doc --> |
| 237 |
* <!-- end-user-doc --> |
| 238 |
* @generated |
| 239 |
*/ |
| 240 |
protected <%=_CollectionOfString%> getInitialObjectNames() |
| 241 |
{ |
| 242 |
if (initialObjectNames == null) |
| 243 |
{ |
| 244 |
initialObjectNames = new <%=_ArrayListOfString%>(); |
| 245 |
<%if (!genPackage.hasDocumentRoot()) {%> |
| 246 |
<%if (genModel.useGenerics()) {%> |
| 247 |
for (EClassifier eClassifier : <%=genPackage.getUncapPackageName()%>.getEClassifiers()) |
| 248 |
<%} else {%> |
| 249 |
for (Iterator classifiers = <%=genPackage.getUncapPackageName()%>.getEClassifiers().iterator(); classifiers.hasNext(); ) |
| 250 |
<%}%> |
| 251 |
{ |
| 252 |
<%if (!genModel.useGenerics()) {%> |
| 253 |
EClassifier eClassifier = (EClassifier)classifiers.next(); |
| 254 |
<%}%> |
| 255 |
if (eClassifier instanceof EClass) |
| 256 |
{ |
| 257 |
EClass eClass = (EClass)eClassifier; |
| 258 |
if (!eClass.isAbstract()) |
| 259 |
{ |
| 260 |
initialObjectNames.add(eClass.getName()); |
| 261 |
} |
| 262 |
} |
| 263 |
} |
| 264 |
<%} else {%> |
| 265 |
<%if (genModel.useGenerics()) {%> |
| 266 |
for (<%=genModel.getImportedName("org.eclipse.emf.ecore.EStructuralFeature")%> eStructuralFeature : <%=genModel.getImportedName("org.eclipse.emf.ecore.util.ExtendedMetaData")%>.INSTANCE.getAllElements(<%=genModel.getImportedName("org.eclipse.emf.ecore.util.ExtendedMetaData")%>.INSTANCE.getDocumentRoot(<%=genPackage.getUncapPackageName()%>))) |
| 267 |
<%} else {%> |
| 268 |
for (Iterator elements = <%=genModel.getImportedName("org.eclipse.emf.ecore.util.ExtendedMetaData")%>.INSTANCE.getAllElements(<%=genModel.getImportedName("org.eclipse.emf.ecore.util.ExtendedMetaData")%>.INSTANCE.getDocumentRoot(<%=genPackage.getUncapPackageName()%>)).iterator(); elements.hasNext(); ) |
| 269 |
<%}%> |
| 270 |
{ |
| 271 |
<%if (!genModel.useGenerics()) {%> |
| 272 |
<%=genModel.getImportedName("org.eclipse.emf.ecore.EStructuralFeature")%> eStructuralFeature = (<%=genModel.getImportedName("org.eclipse.emf.ecore.EStructuralFeature")%>)elements.next(); |
| 273 |
<%}%> |
| 274 |
if (eStructuralFeature.isChangeable()) |
| 275 |
{ |
| 276 |
EClassifier eClassifier = eStructuralFeature.getEType(); |
| 277 |
if (eClassifier instanceof EClass) |
| 278 |
{ |
| 279 |
EClass eClass = (EClass)eClassifier; |
| 280 |
if (!eClass.isAbstract()) |
| 281 |
{ |
| 282 |
initialObjectNames.add(eStructuralFeature.getName()); |
| 283 |
} |
| 284 |
} |
| 285 |
} |
| 286 |
} |
| 287 |
<%}%> |
| 288 |
Collections.sort(initialObjectNames, <%if (!genModel.isRichClientPlatform() && genModel.getComplianceLevel().getValue() >= GenJDKLevel.JDK50) {%>CommonPlugin.INSTANCE.getComparator()<%} else {%>java.text.Collator.getInstance()<%}%>); |
| 289 |
} |
| 290 |
return initialObjectNames; |
| 291 |
} |
| 292 |
|
| 293 |
/** |
| 294 |
* Create a new model. |
| 295 |
* <!-- begin-user-doc --> |
| 296 |
* <!-- end-user-doc --> |
| 297 |
* @generated |
| 298 |
*/ |
| 299 |
protected EObject createInitialModel() |
| 300 |
{ |
| 301 |
<%if (!genPackage.hasDocumentRoot()) {%> |
| 302 |
EClass eClass = (EClass)<%=genPackage.getUncapPackageName()%>.getEClassifier(initialObjectCreationPage.getInitialObjectName()); |
| 303 |
EObject rootObject = <%=genPackage.getUncapFactoryName()%>.create(eClass); |
| 304 |
<%} else {%> |
| 305 |
EClass eClass = <%=genModel.getImportedName("org.eclipse.emf.ecore.util.ExtendedMetaData")%>.INSTANCE.getDocumentRoot(<%=genPackage.getUncapPackageName()%>); |
| 306 |
EStructuralFeature eStructuralFeature = eClass.getEStructuralFeature(initialObjectCreationPage.getInitialObjectName()); |
| 307 |
EObject rootObject = <%=genPackage.getUncapFactoryName()%>.create(eClass); |
| 308 |
rootObject.eSet(eStructuralFeature, <%=genModel.getImportedName("org.eclipse.emf.ecore.util.EcoreUtil")%>.create((EClass)eStructuralFeature.getEType())); |
| 309 |
<%}%> |
| 310 |
return rootObject; |
| 311 |
} |
| 312 |
|
| 313 |
/** |
| 314 |
* Do the work after everything is specified. |
| 315 |
* <!-- begin-user-doc --> |
| 316 |
* <!-- end-user-doc --> |
| 317 |
* @generated |
| 318 |
*/ |
| 319 |
<%if (genModel.useClassOverrideAnnotation()) {%> |
| 320 |
@Override |
| 321 |
<%}%> |
| 322 |
public boolean performFinish() |
| 323 |
{ |
| 324 |
try |
| 325 |
{ |
| 326 |
<%if (genModel.isRichClientPlatform()) {%> |
| 327 |
// Get the URI of the model file. |
| 328 |
// |
| 329 |
final URI fileURI = getModelURI(); |
| 330 |
if (new <%=genModel.getImportedName("java.io.File")%>(fileURI.toFileString()).exists()) |
| 331 |
{ |
| 332 |
if (!MessageDialog.openQuestion |
| 333 |
(getShell(), |
| 334 |
<%=genPackage.getImportedEditorPluginClassName()%>.INSTANCE.getString("_UI_Question_title"),<%=genModel.getNonNLS()%> |
| 335 |
<%=genPackage.getImportedEditorPluginClassName()%>.INSTANCE.getString("_WARN_FileConflict", new String []{ fileURI.toFileString() })))<%=genModel.getNonNLS()%> |
| 336 |
{ |
| 337 |
initialObjectCreationPage.selectFileField(); |
| 338 |
return false; |
| 339 |
} |
| 340 |
} |
| 341 |
|
| 342 |
// Do the work within an operation. |
| 343 |
// |
| 344 |
<%=genModel.getImportedName("org.eclipse.jface.operation.IRunnableWithProgress")%> operation = new <%=genModel.getImportedName("org.eclipse.jface.operation.IRunnableWithProgress")%>() |
| 345 |
{ |
| 346 |
<%if (genModel.useInterfaceOverrideAnnotation()) {%> |
| 347 |
@Override |
| 348 |
<%}%> |
| 349 |
public void run(IProgressMonitor progressMonitor) |
| 350 |
<%} else {%> |
| 351 |
// Remember the file. |
| 352 |
// |
| 353 |
final IFile modelFile = getModelFile(); |
| 354 |
|
| 355 |
// Do the work within an operation. |
| 356 |
// |
| 357 |
WorkspaceModifyOperation operation = |
| 358 |
new WorkspaceModifyOperation() |
| 359 |
{ |
| 360 |
<%if (genModel.useClassOverrideAnnotation()) {%> |
| 361 |
@Override |
| 362 |
<%}%> |
| 363 |
protected void execute(IProgressMonitor progressMonitor) |
| 364 |
<%}%> |
| 365 |
{ |
| 366 |
try |
| 367 |
{ |
| 368 |
// Create a resource set |
| 369 |
// |
| 370 |
ResourceSet resourceSet = new ResourceSetImpl(); |
| 371 |
|
| 372 |
<%if (!genModel.isRichClientPlatform()) {%> |
| 373 |
// Get the URI of the model file. |
| 374 |
// |
| 375 |
URI fileURI = URI.createPlatformResourceURI(modelFile.getFullPath().toString(), true); |
| 376 |
|
| 377 |
<%}%> |
| 378 |
// Create a resource for this file. |
| 379 |
// |
| 380 |
Resource resource = resourceSet.createResource(fileURI<%if (genPackage.isContentType()) {%>, <%=genPackage.getImportedPackageInterfaceName()%>.eCONTENT_TYPE<%}%>); |
| 381 |
|
| 382 |
// Add the initial model object to the contents. |
| 383 |
// |
| 384 |
EObject rootObject = createInitialModel(); |
| 385 |
if (rootObject != null) |
| 386 |
{ |
| 387 |
resource.getContents().add(rootObject); |
| 388 |
} |
| 389 |
|
| 390 |
// Save the contents of the resource to the file system. |
| 391 |
// |
| 392 |
<%=_MapOfObjectToObject%> options = new <%=_HashMapOfObjectToObject%>(); |
| 393 |
options.put(XMLResource.OPTION_ENCODING, initialObjectCreationPage.getEncoding()); |
| 394 |
resource.save(options); |
| 395 |
} |
| 396 |
catch (Exception exception) |
| 397 |
{ |
| 398 |
<%=genPackage.getImportedEditorPluginClassName()%>.INSTANCE.log(exception); |
| 399 |
} |
| 400 |
finally |
| 401 |
{ |
| 402 |
progressMonitor.done(); |
| 403 |
} |
| 404 |
} |
| 405 |
}; |
| 406 |
|
| 407 |
getContainer().run(false, false, operation); |
| 408 |
|
| 409 |
<%if (genModel.isRichClientPlatform()) {%> |
| 410 |
return <%=genModel.getImportedName(genModel.getQualifiedEditorAdvisorClassName())%>.openEditor(workbench, fileURI); |
| 411 |
<%} else {%> |
| 412 |
// Select the new file resource in the current view. |
| 413 |
// |
| 414 |
<%=genModel.getImportedName("org.eclipse.ui.IWorkbenchWindow")%> workbenchWindow = workbench.getActiveWorkbenchWindow(); |
| 415 |
<%=genModel.getImportedName("org.eclipse.ui.IWorkbenchPage")%> page = workbenchWindow.getActivePage(); |
| 416 |
final <%=genModel.getImportedName("org.eclipse.ui.IWorkbenchPart")%> activePart = page.getActivePart(); |
| 417 |
if (activePart instanceof ISetSelectionTarget) |
| 418 |
{ |
| 419 |
final <%=genModel.getImportedName("org.eclipse.jface.viewers.ISelection")%> targetSelection = new <%=genModel.getImportedName("org.eclipse.jface.viewers.StructuredSelection")%>(modelFile); |
| 420 |
getShell().getDisplay().asyncExec |
| 421 |
(new Runnable() |
| 422 |
{ |
| 423 |
<%if (genModel.useInterfaceOverrideAnnotation()) {%> |
| 424 |
@Override |
| 425 |
<%}%> |
| 426 |
public void run() |
| 427 |
{ |
| 428 |
((ISetSelectionTarget)activePart).selectReveal(targetSelection); |
| 429 |
} |
| 430 |
}); |
| 431 |
} |
| 432 |
|
| 433 |
// Open an editor on the new file. |
| 434 |
// |
| 435 |
try |
| 436 |
{ |
| 437 |
page.openEditor |
| 438 |
(new FileEditorInput(modelFile), |
| 439 |
workbench.getEditorRegistry().getDefaultEditor<%if (!genPackage.isContentType()) {%>(modelFile.getFullPath().toString()).getId());<%} else {%> |
| 440 |
(modelFile.getFullPath().toString(), |
| 441 |
<%=genModel.getImportedName("org.eclipse.core.runtime.Platform")%>.getContentTypeManager().getContentType(<%=genPackage.getImportedPackageInterfaceName()%>.eCONTENT_TYPE)).getId()); |
| 442 |
<%}%> |
| 443 |
} |
| 444 |
catch (<%=genModel.getImportedName("org.eclipse.ui.PartInitException")%> exception) |
| 445 |
{ |
| 446 |
MessageDialog.openError(workbenchWindow.getShell(), <%=genPackage.getImportedEditorPluginClassName()%>.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage());<%=genModel.getNonNLS()%> |
| 447 |
return false; |
| 448 |
} |
| 449 |
|
| 450 |
return true; |
| 451 |
<%}%> |
| 452 |
} |
| 453 |
catch (Exception exception) |
| 454 |
{ |
| 455 |
<%=genPackage.getImportedEditorPluginClassName()%>.INSTANCE.log(exception); |
| 456 |
return false; |
| 457 |
} |
| 458 |
} |
| 459 |
|
| 460 |
<%if (!genModel.isRichClientPlatform()) {%> |
| 461 |
/** |
| 462 |
* This is the one page of the wizard. |
| 463 |
* <!-- begin-user-doc --> |
| 464 |
* <!-- end-user-doc --> |
| 465 |
* @generated |
| 466 |
*/ |
| 467 |
public class <%=genPackage.getModelWizardClassName()%>NewFileCreationPage extends WizardNewFileCreationPage |
| 468 |
{ |
| 469 |
/** |
| 470 |
* Pass in the selection. |
| 471 |
* <!-- begin-user-doc --> |
| 472 |
* <!-- end-user-doc --> |
| 473 |
* @generated |
| 474 |
*/ |
| 475 |
public <%=genPackage.getModelWizardClassName()%>NewFileCreationPage(String pageId, IStructuredSelection selection) |
| 476 |
{ |
| 477 |
super(pageId, selection); |
| 478 |
} |
| 479 |
|
| 480 |
/** |
| 481 |
* The framework calls this to see if the file is correct. |
| 482 |
* <!-- begin-user-doc --> |
| 483 |
* <!-- end-user-doc --> |
| 484 |
* @generated |
| 485 |
*/ |
| 486 |
<%if (genModel.useClassOverrideAnnotation()) {%> |
| 487 |
@Override |
| 488 |
<%}%> |
| 489 |
protected boolean validatePage() |
| 490 |
{ |
| 491 |
if (super.validatePage()) |
| 492 |
{ |
| 493 |
String extension = new <%=genModel.getImportedName("org.eclipse.core.runtime.Path")%>(getFileName()).getFileExtension(); |
| 494 |
if (extension == null || !FILE_EXTENSIONS.contains(extension)) |
| 495 |
{ |
| 496 |
String key = FILE_EXTENSIONS.size() > 1 ? "_WARN_FilenameExtensions" : "_WARN_FilenameExtension";<%=genModel.getNonNLS()%><%=genModel.getNonNLS(2)%> |
| 497 |
setErrorMessage(<%=genPackage.getImportedEditorPluginClassName()%>.INSTANCE.getString(key, new Object [] { FORMATTED_FILE_EXTENSIONS })); |
| 498 |
return false; |
| 499 |
} |
| 500 |
return true; |
| 501 |
} |
| 502 |
return false; |
| 503 |
} |
| 504 |
|
| 505 |
/** |
| 506 |
* <!-- begin-user-doc --> |
| 507 |
* <!-- end-user-doc --> |
| 508 |
* @generated |
| 509 |
*/ |
| 510 |
public IFile getModelFile() |
| 511 |
{ |
| 512 |
return ResourcesPlugin.getWorkspace().getRoot().getFile(getContainerFullPath().append(getFileName())); |
| 513 |
} |
| 514 |
} |
| 515 |
|
| 516 |
<%}%> |
| 517 |
/** |
| 518 |
* This is the page where the type of object to create is selected. |
| 519 |
* <!-- begin-user-doc --> |
| 520 |
* <!-- end-user-doc --> |
| 521 |
* @generated |
| 522 |
*/ |
| 523 |
public class <%=genPackage.getModelWizardClassName()%>InitialObjectCreationPage extends WizardPage |
| 524 |
{ |
| 525 |
<%if (genModel.isRichClientPlatform()) {%> |
| 526 |
/** |
| 527 |
* <!-- begin-user-doc --> |
| 528 |
* <!-- end-user-doc --> |
| 529 |
* @generated |
| 530 |
*/ |
| 531 |
protected <%=genModel.getImportedName("org.eclipse.swt.widgets.Text")%> fileField; |
| 532 |
|
| 533 |
<%}%> |
| 534 |
/** |
| 535 |
* <!-- begin-user-doc --> |
| 536 |
* <!-- end-user-doc --> |
| 537 |
* @generated |
| 538 |
*/ |
| 539 |
protected Combo initialObjectField; |
| 540 |
|
| 541 |
/** |
| 542 |
* @generated |
| 543 |
* <!-- begin-user-doc --> |
| 544 |
* <!-- end-user-doc --> |
| 545 |
*/ |
| 546 |
protected <%=_ListOfString%> encodings; |
| 547 |
|
| 548 |
/** |
| 549 |
* <!-- begin-user-doc --> |
| 550 |
* <!-- end-user-doc --> |
| 551 |
* @generated |
| 552 |
*/ |
| 553 |
protected Combo encodingField; |
| 554 |
|
| 555 |
/** |
| 556 |
* Pass in the selection. |
| 557 |
* <!-- begin-user-doc --> |
| 558 |
* <!-- end-user-doc --> |
| 559 |
* @generated |
| 560 |
*/ |
| 561 |
public <%=genPackage.getModelWizardClassName()%>InitialObjectCreationPage(String pageId) |
| 562 |
{ |
| 563 |
super(pageId); |
| 564 |
} |
| 565 |
|
| 566 |
/** |
| 567 |
* <!-- begin-user-doc --> |
| 568 |
* <!-- end-user-doc --> |
| 569 |
* @generated |
| 570 |
*/ |
| 571 |
<%if (genModel.useInterfaceOverrideAnnotation()) {%> |
| 572 |
@Override |
| 573 |
<%}%> |
| 574 |
public void createControl(Composite parent) |
| 575 |
{ |
| 576 |
Composite composite = new Composite(parent, SWT.NONE); |
| 577 |
{ |
| 578 |
GridLayout layout = new GridLayout(); |
| 579 |
layout.numColumns = 1; |
| 580 |
layout.verticalSpacing = 12; |
| 581 |
composite.setLayout(layout); |
| 582 |
|
| 583 |
GridData data = new GridData(); |
| 584 |
data.verticalAlignment = GridData.FILL; |
| 585 |
data.grabExcessVerticalSpace = true; |
| 586 |
data.horizontalAlignment = GridData.FILL; |
| 587 |
composite.setLayoutData(data); |
| 588 |
} |
| 589 |
|
| 590 |
<%if (genModel.isRichClientPlatform()) {%> |
| 591 |
Label resourceURILabel = new Label(composite, SWT.LEFT); |
| 592 |
{ |
| 593 |
resourceURILabel.setText(<%=genPackage.getImportedEditorPluginClassName()%>.INSTANCE.getString("_UI_File_label"));<%=genModel.getNonNLS()%> |
| 594 |
|
| 595 |
GridData data = new GridData(); |
| 596 |
data.horizontalAlignment = GridData.FILL; |
| 597 |
resourceURILabel.setLayoutData(data); |
| 598 |
} |
| 599 |
|
| 600 |
Composite fileComposite = new Composite(composite, SWT.NONE); |
| 601 |
{ |
| 602 |
GridData data = new GridData(); |
| 603 |
data.horizontalAlignment = GridData.END; |
| 604 |
fileComposite.setLayoutData(data); |
| 605 |
|
| 606 |
GridLayout layout = new GridLayout(); |
| 607 |
data.horizontalAlignment = GridData.FILL; |
| 608 |
layout.marginHeight = 0; |
| 609 |
layout.marginWidth = 0; |
| 610 |
layout.numColumns = 2; |
| 611 |
fileComposite.setLayout(layout); |
| 612 |
} |
| 613 |
|
| 614 |
fileField = new <%=genModel.getImportedName("org.eclipse.swt.widgets.Text")%>(fileComposite, SWT.BORDER); |
| 615 |
{ |
| 616 |
GridData data = new GridData(); |
| 617 |
data.horizontalAlignment = GridData.FILL; |
| 618 |
data.grabExcessHorizontalSpace = true; |
| 619 |
data.horizontalSpan = 1; |
| 620 |
fileField.setLayoutData(data); |
| 621 |
} |
| 622 |
|
| 623 |
fileField.addModifyListener(validator); |
| 624 |
|
| 625 |
<%if (!genModel.isRichAjaxPlatform()) {%> |
| 626 |
<%=genModel.getImportedName("org.eclipse.swt.widgets.Button")%> resourceURIBrowseFileSystemButton = new <%=genModel.getImportedName("org.eclipse.swt.widgets.Button")%>(fileComposite, SWT.PUSH); |
| 627 |
resourceURIBrowseFileSystemButton.setText(<%=genPackage.getImportedEditorPluginClassName()%>.INSTANCE.getString("_UI_Browse_label"));<%=genModel.getNonNLS()%> |
| 628 |
|
| 629 |
resourceURIBrowseFileSystemButton.addSelectionListener |
| 630 |
(new <%=genModel.getImportedName("org.eclipse.swt.events.SelectionAdapter")%>() |
| 631 |
{ |
| 632 |
<%if (genModel.useClassOverrideAnnotation()) {%> |
| 633 |
@Override |
| 634 |
<%}%> |
| 635 |
public void widgetSelected(<%=genModel.getImportedName("org.eclipse.swt.events.SelectionEvent")%> event) |
| 636 |
{ |
| 637 |
String[] filters = <%if (!genModel.useGenerics()) {%>(String[])<%}%><%=genPackage.getImportedEditorClassName()%>.FILE_EXTENSION_FILTERS.toArray(new String[<%=genPackage.getImportedEditorClassName()%>.FILE_EXTENSION_FILTERS.size()]); |
| 638 |
String[] files = <%=genModel.getImportedName(genModel.getQualifiedEditorAdvisorClassName())%>.openFilePathDialog(getShell(), <%=genModel.getImportedName("org.eclipse.swt.SWT")%>.SAVE, filters); |
| 639 |
if (files.length > 0) |
| 640 |
{ |
| 641 |
fileField.setText(files[0]); |
| 642 |
} |
| 643 |
} |
| 644 |
}); |
| 645 |
<%}%> |
| 646 |
<%}%> |
| 647 |
Label containerLabel = new Label(composite, SWT.LEFT); |
| 648 |
{ |
| 649 |
containerLabel.setText(<%=genPackage.getImportedEditorPluginClassName()%>.INSTANCE.getString("_UI_ModelObject"));<%=genModel.getNonNLS()%> |
| 650 |
|
| 651 |
GridData data = new GridData(); |
| 652 |
data.horizontalAlignment = GridData.FILL; |
| 653 |
containerLabel.setLayoutData(data); |
| 654 |
} |
| 655 |
|
| 656 |
initialObjectField = new Combo(composite, SWT.BORDER); |
| 657 |
{ |
| 658 |
GridData data = new GridData(); |
| 659 |
data.horizontalAlignment = GridData.FILL; |
| 660 |
data.grabExcessHorizontalSpace = true; |
| 661 |
initialObjectField.setLayoutData(data); |
| 662 |
} |
| 663 |
|
| 664 |
<%if (genModel.useGenerics()) {%> |
| 665 |
for (String objectName : getInitialObjectNames()) |
| 666 |
{ |
| 667 |
initialObjectField.add(getLabel(objectName)); |
| 668 |
} |
| 669 |
<%} else {%> |
| 670 |
for (Iterator i = getInitialObjectNames().iterator(); i.hasNext(); ) |
| 671 |
{ |
| 672 |
initialObjectField.add(getLabel((String)i.next())); |
| 673 |
} |
| 674 |
<%}%> |
| 675 |
|
| 676 |
if (initialObjectField.getItemCount() == 1) |
| 677 |
{ |
| 678 |
initialObjectField.select(0); |
| 679 |
} |
| 680 |
initialObjectField.addModifyListener(validator); |
| 681 |
|
| 682 |
Label encodingLabel = new Label(composite, SWT.LEFT); |
| 683 |
{ |
| 684 |
encodingLabel.setText(<%=genPackage.getImportedEditorPluginClassName()%>.INSTANCE.getString("_UI_XMLEncoding"));<%=genModel.getNonNLS()%> |
| 685 |
|
| 686 |
GridData data = new GridData(); |
| 687 |
data.horizontalAlignment = GridData.FILL; |
| 688 |
encodingLabel.setLayoutData(data); |
| 689 |
} |
| 690 |
encodingField = new Combo(composite, SWT.BORDER); |
| 691 |
{ |
| 692 |
GridData data = new GridData(); |
| 693 |
data.horizontalAlignment = GridData.FILL; |
| 694 |
data.grabExcessHorizontalSpace = true; |
| 695 |
encodingField.setLayoutData(data); |
| 696 |
} |
| 697 |
|
| 698 |
<%if (genModel.useGenerics()) {%> |
| 699 |
for (String encoding : getEncodings()) |
| 700 |
{ |
| 701 |
encodingField.add(encoding); |
| 702 |
} |
| 703 |
<%} else {%> |
| 704 |
for (Iterator i = getEncodings().iterator(); i.hasNext(); ) |
| 705 |
{ |
| 706 |
encodingField.add((String)i.next()); |
| 707 |
} |
| 708 |
<%}%> |
| 709 |
|
| 710 |
encodingField.select(0); |
| 711 |
encodingField.addModifyListener(validator); |
| 712 |
|
| 713 |
setPageComplete(validatePage()); |
| 714 |
setControl(composite); |
| 715 |
} |
| 716 |
|
| 717 |
/** |
| 718 |
* <!-- begin-user-doc --> |
| 719 |
* <!-- end-user-doc --> |
| 720 |
* @generated |
| 721 |
*/ |
| 722 |
protected ModifyListener validator = |
| 723 |
new ModifyListener() |
| 724 |
{ |
| 725 |
<%if (genModel.useInterfaceOverrideAnnotation()) {%> |
| 726 |
@Override |
| 727 |
<%}%> |
| 728 |
public void modifyText(ModifyEvent e) |
| 729 |
{ |
| 730 |
setPageComplete(validatePage()); |
| 731 |
} |
| 732 |
}; |
| 733 |
|
| 734 |
/** |
| 735 |
* <!-- begin-user-doc --> |
| 736 |
* <!-- end-user-doc --> |
| 737 |
* @generated |
| 738 |
*/ |
| 739 |
protected boolean validatePage() |
| 740 |
{ |
| 741 |
<%if (genModel.isRichClientPlatform()) {%> |
| 742 |
URI fileURI = getFileURI(); |
| 743 |
if (fileURI == null || fileURI.isEmpty()) |
| 744 |
{ |
| 745 |
setErrorMessage(null); |
| 746 |
return false; |
| 747 |
} |
| 748 |
|
| 749 |
String extension = fileURI.fileExtension(); |
| 750 |
if (extension == null || !FILE_EXTENSIONS.contains(extension)) |
| 751 |
{ |
| 752 |
String key = FILE_EXTENSIONS.size() > 1 ? "_WARN_FilenameExtensions" : "_WARN_FilenameExtension";<%=genModel.getNonNLS()%><%=genModel.getNonNLS(2)%> |
| 753 |
setErrorMessage(<%=genPackage.getImportedEditorPluginClassName()%>.INSTANCE.getString(key, new Object [] { FORMATTED_FILE_EXTENSIONS })); |
| 754 |
return false; |
| 755 |
} |
| 756 |
|
| 757 |
setErrorMessage(null); |
| 758 |
<%}%> |
| 759 |
return getInitialObjectName() != null && getEncodings().contains(encodingField.getText()); |
| 760 |
} |
| 761 |
|
| 762 |
/** |
| 763 |
* <!-- begin-user-doc --> |
| 764 |
* <!-- end-user-doc --> |
| 765 |
* @generated |
| 766 |
*/ |
| 767 |
<%if (genModel.useClassOverrideAnnotation()) {%> |
| 768 |
@Override |
| 769 |
<%}%> |
| 770 |
public void setVisible(boolean visible) |
| 771 |
{ |
| 772 |
super.setVisible(visible); |
| 773 |
if (visible) |
| 774 |
{ |
| 775 |
<%if (!genModel.isRichClientPlatform()) {%> |
| 776 |
if (initialObjectField.getItemCount() == 1) |
| 777 |
{ |
| 778 |
initialObjectField.clearSelection(); |
| 779 |
encodingField.setFocus(); |
| 780 |
} |
| 781 |
else |
| 782 |
{ |
| 783 |
encodingField.clearSelection(); |
| 784 |
initialObjectField.setFocus(); |
| 785 |
} |
| 786 |
<%} else {%> |
| 787 |
initialObjectField.clearSelection(); |
| 788 |
encodingField.clearSelection(); |
| 789 |
fileField.setFocus(); |
| 790 |
<%}%> |
| 791 |
} |
| 792 |
} |
| 793 |
|
| 794 |
/** |
| 795 |
* <!-- begin-user-doc --> |
| 796 |
* <!-- end-user-doc --> |
| 797 |
* @generated |
| 798 |
*/ |
| 799 |
public String getInitialObjectName() |
| 800 |
{ |
| 801 |
String label = initialObjectField.getText(); |
| 802 |
|
| 803 |
<%if (genModel.useGenerics()) {%> |
| 804 |
for (String name : getInitialObjectNames()) |
| 805 |
<%} else {%> |
| 806 |
for (Iterator i = getInitialObjectNames().iterator(); i.hasNext(); ) |
| 807 |
<%}%> |
| 808 |
{ |
| 809 |
<%if (!genModel.useGenerics()) {%> |
| 810 |
String name = (String)i.next(); |
| 811 |
<%}%> |
| 812 |
if (getLabel(name).equals(label)) |
| 813 |
{ |
| 814 |
return name; |
| 815 |
} |
| 816 |
} |
| 817 |
return null; |
| 818 |
} |
| 819 |
|
| 820 |
/** |
| 821 |
* <!-- begin-user-doc --> |
| 822 |
* <!-- end-user-doc --> |
| 823 |
* @generated |
| 824 |
*/ |
| 825 |
public String getEncoding() |
| 826 |
{ |
| 827 |
return encodingField.getText(); |
| 828 |
} |
| 829 |
<%if (genModel.isRichClientPlatform()) {%> |
| 830 |
|
| 831 |
/** |
| 832 |
* <!-- begin-user-doc --> |
| 833 |
* <!-- end-user-doc --> |
| 834 |
* @generated |
| 835 |
*/ |
| 836 |
public URI getFileURI() |
| 837 |
{ |
| 838 |
try |
| 839 |
{ |
| 840 |
return URI.createFileURI(fileField.getText()); |
| 841 |
} |
| 842 |
catch (Exception exception) |
| 843 |
{ |
| 844 |
// Ignore |
| 845 |
} |
| 846 |
return null; |
| 847 |
} |
| 848 |
|
| 849 |
/** |
| 850 |
* <!-- begin-user-doc --> |
| 851 |
* <!-- end-user-doc --> |
| 852 |
* @generated |
| 853 |
*/ |
| 854 |
public void selectFileField() |
| 855 |
{ |
| 856 |
initialObjectField.clearSelection(); |
| 857 |
encodingField.clearSelection(); |
| 858 |
fileField.selectAll(); |
| 859 |
fileField.setFocus(); |
| 860 |
} |
| 861 |
<%}%> |
| 862 |
<%{ String type = genPackage.hasDocumentRoot() ? "feature" : "type"; String prefix = genPackage.hasDocumentRoot() ? "_UI_DocumentRoot_" : "_UI_";%> |
| 863 |
|
| 864 |
/** |
| 865 |
* Returns the label for the specified <%=type%> name. |
| 866 |
* <!-- begin-user-doc --> |
| 867 |
* <!-- end-user-doc --> |
| 868 |
* @generated |
| 869 |
*/ |
| 870 |
protected String getLabel(String <%=type%>Name) |
| 871 |
{ |
| 872 |
try |
| 873 |
{ |
| 874 |
return <%=genPackage.getEditPluginClassName()%>.INSTANCE.getString("<%=prefix%>" + <%=type%>Name + "_<%=type%>");<%=genModel.getNonNLS()%><%=genModel.getNonNLS(2)%> |
| 875 |
} |
| 876 |
catch(MissingResourceException mre) |
| 877 |
{ |
| 878 |
<%=genModel.getImportedName(genModel.getQualifiedEditorPluginClassName())%>.INSTANCE.log(mre); |
| 879 |
} |
| 880 |
return <%=type%>Name; |
| 881 |
} |
| 882 |
<%}%> |
| 883 |
|
| 884 |
/** |
| 885 |
* <!-- begin-user-doc --> |
| 886 |
* <!-- end-user-doc --> |
| 887 |
* @generated |
| 888 |
*/ |
| 889 |
protected <%=_CollectionOfString%> getEncodings() |
| 890 |
{ |
| 891 |
if (encodings == null) |
| 892 |
{ |
| 893 |
encodings = new <%=_ArrayListOfString%>(); |
| 894 |
for (StringTokenizer stringTokenizer = new StringTokenizer(<%=genPackage.getImportedEditorPluginClassName()%>.INSTANCE.getString("_UI_XMLEncodingChoices")); stringTokenizer.hasMoreTokens(); )<%=genModel.getNonNLS()%> |
| 895 |
{ |
| 896 |
encodings.add(stringTokenizer.nextToken()); |
| 897 |
} |
| 898 |
} |
| 899 |
return encodings; |
| 900 |
} |
| 901 |
} |
| 902 |
|
| 903 |
/** |
| 904 |
* The framework calls this to create the contents of the wizard. |
| 905 |
* <!-- begin-user-doc --> |
| 906 |
* <!-- end-user-doc --> |
| 907 |
* @generated |
| 908 |
*/ |
| 909 |
<%if (genModel.useClassOverrideAnnotation()) {%> |
| 910 |
@Override |
| 911 |
<%}%> |
| 912 |
public void addPages() |
| 913 |
{ |
| 914 |
<%if (!genModel.isRichClientPlatform()) {%> |
| 915 |
// Create a page, set the title, and the initial model file name. |
| 916 |
// |
| 917 |
newFileCreationPage = new <%=genPackage.getModelWizardClassName()%>NewFileCreationPage("Whatever", selection);<%=genModel.getNonNLS()%> |
| 918 |
newFileCreationPage.setTitle(<%=genPackage.getImportedEditorPluginClassName()%>.INSTANCE.getString("_UI_<%=genPackage.getModelWizardClassName()%>_label"));<%=genModel.getNonNLS()%> |
| 919 |
newFileCreationPage.setDescription(<%=genPackage.getImportedEditorPluginClassName()%>.INSTANCE.getString("_UI_<%=genPackage.getModelWizardClassName()%>_description"));<%=genModel.getNonNLS()%> |
| 920 |
newFileCreationPage.setFileName(<%=genPackage.getImportedEditorPluginClassName()%>.INSTANCE.getString("_UI_<%=genPackage.getEditorClassName()%>FilenameDefaultBase") + "." + <%if (!genModel.useGenerics()) {%>(String)<%}%>FILE_EXTENSIONS.get(0));<%=genModel.getNonNLS()%><%=genModel.getNonNLS(2)%> |
| 921 |
addPage(newFileCreationPage); |
| 922 |
|
| 923 |
// Try and get the resource selection to determine a current directory for the file dialog. |
| 924 |
// |
| 925 |
if (selection != null && !selection.isEmpty()) |
| 926 |
{ |
| 927 |
// Get the resource... |
| 928 |
// |
| 929 |
Object selectedElement = selection.iterator().next(); |
| 930 |
if (selectedElement instanceof IResource) |
| 931 |
{ |
| 932 |
// Get the resource parent, if its a file. |
| 933 |
// |
| 934 |
IResource selectedResource = (IResource)selectedElement; |
| 935 |
if (selectedResource.getType() == IResource.FILE) |
| 936 |
{ |
| 937 |
selectedResource = selectedResource.getParent(); |
| 938 |
} |
| 939 |
|
| 940 |
// This gives us a directory... |
| 941 |
// |
| 942 |
if (selectedResource instanceof IFolder || selectedResource instanceof IProject) |
| 943 |
{ |
| 944 |
// Set this for the container. |
| 945 |
// |
| 946 |
newFileCreationPage.setContainerFullPath(selectedResource.getFullPath()); |
| 947 |
|
| 948 |
// Make up a unique new name here. |
| 949 |
// |
| 950 |
String defaultModelBaseFilename = <%=genPackage.getImportedEditorPluginClassName()%>.INSTANCE.getString("_UI_<%=genPackage.getEditorClassName()%>FilenameDefaultBase");<%=genModel.getNonNLS()%> |
| 951 |
String defaultModelFilenameExtension = <%if (!genModel.useGenerics()) {%>(String)<%}%>FILE_EXTENSIONS.get(0); |
| 952 |
String modelFilename = defaultModelBaseFilename + "." + defaultModelFilenameExtension;<%=genModel.getNonNLS()%> |
| 953 |
for (int i = 1; ((IContainer)selectedResource).findMember(modelFilename) != null; ++i) |
| 954 |
{ |
| 955 |
modelFilename = defaultModelBaseFilename + i + "." + defaultModelFilenameExtension;<%=genModel.getNonNLS()%> |
| 956 |
} |
| 957 |
newFileCreationPage.setFileName(modelFilename); |
| 958 |
} |
| 959 |
} |
| 960 |
} |
| 961 |
<%}%> |
| 962 |
initialObjectCreationPage = new <%=genPackage.getModelWizardClassName()%>InitialObjectCreationPage("Whatever2");<%=genModel.getNonNLS()%> |
| 963 |
initialObjectCreationPage.setTitle(<%=genPackage.getImportedEditorPluginClassName()%>.INSTANCE.getString("_UI_<%=genPackage.getModelWizardClassName()%>_label"));<%=genModel.getNonNLS()%> |
| 964 |
initialObjectCreationPage.setDescription(<%=genPackage.getImportedEditorPluginClassName()%>.INSTANCE.getString("_UI_Wizard_initial_object_description"));<%=genModel.getNonNLS()%> |
| 965 |
addPage(initialObjectCreationPage); |
| 966 |
} |
| 967 |
|
| 968 |
<%if (genModel.isRichClientPlatform()) {%> |
| 969 |
/** |
| 970 |
* Get the URI from the page. |
| 971 |
* <!-- begin-user-doc --> |
| 972 |
* <!-- end-user-doc --> |
| 973 |
* @generated |
| 974 |
*/ |
| 975 |
public URI getModelURI() |
| 976 |
{ |
| 977 |
return initialObjectCreationPage.getFileURI(); |
| 978 |
} |
| 979 |
|
| 980 |
<%} else {%> |
| 981 |
/** |
| 982 |
* Get the file from the page. |
| 983 |
* <!-- begin-user-doc --> |
| 984 |
* <!-- end-user-doc --> |
| 985 |
* @generated |
| 986 |
*/ |
| 987 |
public IFile getModelFile() |
| 988 |
{ |
| 989 |
return newFileCreationPage.getModelFile(); |
| 990 |
} |
| 991 |
|
| 992 |
<%}%> |
| 993 |
} |
| 994 |
<%genModel.emitSortedImports();%> |