Skip to content
This repository has been archived by the owner on Mar 26, 2023. It is now read-only.

Commit

Permalink
Special handling of .ecore and .codegen selection.
Browse files Browse the repository at this point in the history
If .ecore or .codegen files are selected when New wizard is activated
then the model is named after the file and the file is added to the 
package list.
  • Loading branch information
pvlasov committed Apr 19, 2017
1 parent eed0956 commit 2d28cf4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package org.nasdanika.codegen.ecore.presentation;

import org.eclipse.core.resources.IFile;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.presentation.EcoreActionBarContributor.ExtendedLoadResourceAction.ExtendedLoadResourceDialog;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
Expand All @@ -19,6 +25,7 @@
public class EPackagesSelectionPage extends WizardPage {

private org.eclipse.swt.widgets.List list;
private IFile modelFile;

public String[] getResourceURIs() {
return list.getItems();
Expand All @@ -29,8 +36,9 @@ public String[] getResourceURIs() {
* @param pageName Page name.
* @param newFileCreationPage
*/
public EPackagesSelectionPage(String pageName) {
public EPackagesSelectionPage(String pageName, IFile modelFile) {
super(pageName);
this.modelFile = modelFile;
}

/**
Expand Down Expand Up @@ -85,7 +93,16 @@ public void widgetSelected(SelectionEvent e) {
}
});

if (modelFile != null) {
URI modelFileURI = URI.createPlatformResourceURI(modelFile.getProject().getName()+"/"+modelFile.getProjectRelativePath().toString(), true);
list.add(modelFileURI.toString());
}

setPageComplete(list.getItemCount() > 0);
if (list.getSelectionCount() == 0 && list.getItemCount() > 0) {
list.select(0);
btnRemove.setEnabled(true);
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
* @generated
*/
public class EcoreModelWizard extends Wizard implements INewWizard {
private static final String EXTENSION_GENMODEL = ".genmodel";

private static final String EXTENSION_ECORE = ".ecore";

/**
* The supported extensions for created files.
* <!-- begin-user-doc -->
Expand Down Expand Up @@ -317,7 +321,20 @@ public void addPages() {
newFileCreationPage = new EcoreModelWizardNewFileCreationPage("Whatever", selection);
newFileCreationPage.setTitle(ecorecodegenerationEditorPlugin.INSTANCE.getString("_UI_EcoreModelWizard_label"));
newFileCreationPage.setDescription(ecorecodegenerationEditorPlugin.INSTANCE.getString("_UI_EcoreModelWizard_description"));
newFileCreationPage.setFileName(ecorecodegenerationEditorPlugin.INSTANCE.getString("_UI_EcoreEditorFilenameDefaultBase") + "." + FILE_EXTENSIONS.get(0));
String fileNameBase = ecorecodegenerationEditorPlugin.INSTANCE.getString("_UI_EcoreEditorFilenameDefaultBase");
IFile modelFile = null;
if (!selection.isEmpty()) {
Object fe = selection.getFirstElement();
if (fe instanceof IFile) {
IFile sf = (IFile) fe;
String sfn = sf.getName();
if (sfn.endsWith(EXTENSION_ECORE) || sfn.endsWith(EXTENSION_GENMODEL)) {
fileNameBase = sfn.substring(0, sfn.lastIndexOf('.'));
modelFile = sf;
}
}
}
newFileCreationPage.setFileName(fileNameBase + "." + FILE_EXTENSIONS.get(0));
addPage(newFileCreationPage);

// Try and get the resource selection to determine a current directory for the file dialog.
Expand All @@ -343,7 +360,7 @@ public void addPages() {

// Make up a unique new name here.
//
String defaultModelBaseFilename = ecorecodegenerationEditorPlugin.INSTANCE.getString("_UI_EcoreEditorFilenameDefaultBase");
String defaultModelBaseFilename = fileNameBase;
String defaultModelFilenameExtension = FILE_EXTENSIONS.get(0);
String modelFilename = defaultModelBaseFilename + "." + defaultModelFilenameExtension;
for (int i = 1; ((IContainer)selectedResource).findMember(modelFilename) != null; ++i) {
Expand All @@ -353,7 +370,7 @@ public void addPages() {
}
}
}
ePackagesSelectionPage = new EPackagesSelectionPage("ePackagesSelectionPage");
ePackagesSelectionPage = new EPackagesSelectionPage("ePackagesSelectionPage", modelFile);
ePackagesSelectionPage.setTitle(ecorecodegenerationEditorPlugin.INSTANCE.getString("_UI_EcoreModelWizard_label"));
ePackagesSelectionPage.setDescription("Select packages");
addPage(ePackagesSelectionPage);
Expand Down

0 comments on commit 2d28cf4

Please sign in to comment.