1 17 package org.eclipse.emf.ecore.sdo.action; 18 19 20 import java.util.ArrayList ; 21 import java.util.List ; 22 23 import org.eclipse.jface.action.IAction; 24 import org.eclipse.jface.viewers.ISelection; 25 import org.eclipse.jface.viewers.IStructuredSelection; 26 import org.eclipse.ui.IActionDelegate; 27 import org.eclipse.ui.actions.ActionDelegate; 28 29 import org.eclipse.emf.codegen.ecore.genmodel.GenModel; 30 import org.eclipse.emf.codegen.ecore.genmodel.GenModelPackage; 31 import org.eclipse.emf.common.command.CompoundCommand; 32 import org.eclipse.emf.common.util.URI; 33 import org.eclipse.emf.ecore.sdo.SDOPackage; 34 import org.eclipse.emf.ecore.sdo.presentation.SDOEditorPlugin; 35 import org.eclipse.emf.edit.command.AddCommand; 36 import org.eclipse.emf.edit.command.SetCommand; 37 import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain; 38 import org.eclipse.emf.edit.domain.EditingDomain; 39 40 41 44 public class SetSDODefaultsAction 45 extends ActionDelegate 46 implements IActionDelegate 47 { 48 protected static final URI PLATFORM_RESOURCE = URI.createPlatformResourceURI("/"); 49 50 protected GenModel genModel; 51 52 public SetSDODefaultsAction() 53 { 54 } 55 56 public void run(IAction action) 57 { 58 EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(genModel); 59 if (editingDomain != null) 60 { 61 CompoundCommand compoundCommand = new CompoundCommand(0, SDOEditorPlugin.INSTANCE.getString("_UI_SetSDODefaults_menu_item")); 62 compoundCommand. 63 append 64 (SetCommand.create 65 (editingDomain, 66 genModel, 67 GenModelPackage.eINSTANCE.getGenModel_RootExtendsInterface(), 68 "")); 69 compoundCommand. 70 append 71 (SetCommand.create 72 (editingDomain, 73 genModel, 74 GenModelPackage.eINSTANCE.getGenModel_RootImplementsInterface(), 75 "org.eclipse.emf.ecore.sdo.InternalEDataObject")); 76 compoundCommand. 77 append 78 (SetCommand.create 79 (editingDomain, 80 genModel, 81 GenModelPackage.eINSTANCE.getGenModel_RootExtendsClass(), 82 "org.eclipse.emf.ecore.sdo.impl.EDataObjectImpl")); 83 compoundCommand. 84 append 85 (SetCommand.create 86 (editingDomain, 87 genModel, 88 GenModelPackage.eINSTANCE.getGenModel_FeatureMapWrapperInterface(), 89 "commonj.sdo.Sequence")); 90 compoundCommand. 91 append 92 (SetCommand.create 93 (editingDomain, 94 genModel, 95 GenModelPackage.eINSTANCE.getGenModel_FeatureMapWrapperInternalInterface(), 96 "org.eclipse.emf.ecore.sdo.util.ESequence")); 97 compoundCommand. 98 append 99 (SetCommand.create 100 (editingDomain, 101 genModel, 102 GenModelPackage.eINSTANCE.getGenModel_FeatureMapWrapperClass(), 103 "org.eclipse.emf.ecore.sdo.util.BasicESequence")); 104 compoundCommand. 105 append 106 (SetCommand.create 107 (editingDomain, 108 genModel, 109 GenModelPackage.eINSTANCE.getGenModel_SuppressEMFTypes(), 110 Boolean.TRUE)); 111 112 List modelPluginVariableAdditions = new ArrayList (); 113 modelPluginVariableAdditions.add("EMF_COMMONJ_SDO=org.eclipse.emf.commonj.sdo"); 114 modelPluginVariableAdditions.add("EMF_ECORE_SDO=org.eclipse.emf.ecore.sdo"); 115 modelPluginVariableAdditions.removeAll(genModel.getModelPluginVariables()); 116 if (!modelPluginVariableAdditions.isEmpty()) 117 { 118 compoundCommand. 119 append 120 (new AddCommand 121 (editingDomain, 122 genModel, 123 GenModelPackage.eINSTANCE.getGenModel_ModelPluginVariables(), 124 modelPluginVariableAdditions)); 125 } 126 127 List staticPackageURIAdditions = new ArrayList (); 128 staticPackageURIAdditions.add(SDOPackage.eNS_URI); 129 staticPackageURIAdditions.removeAll(genModel.getStaticPackages()); 130 if (!staticPackageURIAdditions.isEmpty()) 131 { 132 compoundCommand. 133 append 134 (new AddCommand 135 (editingDomain, 136 genModel, 137 GenModelPackage.eINSTANCE.getGenModel_StaticPackages(), 138 staticPackageURIAdditions)); 139 } 140 141 editingDomain.getCommandStack().execute(compoundCommand); 142 } 143 } 144 145 public void selectionChanged(IAction action, ISelection selection) 146 { 147 if (selection instanceof IStructuredSelection) 148 { 149 Object object = ((IStructuredSelection)selection).getFirstElement(); 150 if (object instanceof GenModel) 151 { 152 genModel = (GenModel)object; 153 154 action.setEnabled(true); 155 return; 156 } 157 } 158 genModel = null; 159 action.setEnabled(false); 160 } 161 } 162 | Popular Tags |