Changeset 895
- Timestamp:
- 05/10/12 18:13:06 (13 months ago)
- Location:
- dpf-model-editor/trunk/plugins/no.hib.dpf.codegen.xpand.ui/src/no/hib/dpf/codegen/xpand/ui
- Files:
-
- 3 modified
-
DpfMetaModelUIPlugin.java (modified) (1 diff)
-
wizards/DpfGeneratorPage.java (modified) (3 diffs)
-
wizards/NewDpfGeneratorWizard.java (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
dpf-model-editor/trunk/plugins/no.hib.dpf.codegen.xpand.ui/src/no/hib/dpf/codegen/xpand/ui/DpfMetaModelUIPlugin.java
r852 r895 296 296 return ""; 297 297 } 298 299 //Returns every IFile which matches isValidDsm300 // public boolean visit(IResource resource) throws CoreException {301 // if (resource instanceof IFile) {302 // IFile f = (IFile) resource;303 // if (isValidDsm(f)) {304 //// if (JavaCore.create(f.getParent()) != null) { //dafuq305 // try {306 // URI uri = URI.createURI(f.getFullPath().toString());307 //// DpfMetamodel p = loadDsm(uri);308 // Specification spectmp = CoreFactory.eINSTANCE.loadSpecification(uri);309 //// if (p != null) {310 //// fileModels.put(f, p);311 //// }312 // if(spectmp != null) {313 // fileModels.put(f, spectmp);314 // }315 // } catch (Exception e) {316 // System.out.println();317 // }318 //// }319 // }320 // }321 // return true;322 // }323 324 // private boolean isValidDsm(IFile f) {325 // return !f.isDerived()326 // && f.isAccessible()327 // && !f.isLinked()328 // && (f.getName().endsWith("dsm.xmi") && f.exists());329 // }330 331 // public synchronized final static DpfMetamodel loadDsm(URI uri) {332 // Resource r = dpfResourceSet.getResource(uri, false);333 // if (r == null) {334 // // this resource has not been loaded before...335 // // hence, demandLoad it336 // r = dpfResourceSet.getResource(uri, true);337 // } else {338 // if (r.isLoaded()) { // Is this a request to reload the resource?339 // r.unload();340 // }341 // try {342 // r.load(new HashMap<Object, Object>());343 // } catch (IOException e) {344 // throw new RuntimeException(e);345 // }346 // }347 //348 // List<EObject> c = r.getContents();349 // if (c.isEmpty()) {350 // return null;351 // }352 // if (c.get(0) instanceof DpfMetamodel) {353 // DpfMetamodel p = (DpfMetamodel) c.get(0);354 // URIConverter.URI_MAP.put(URI.createURI(uri.lastSegment()), uri);355 // return p;356 // }357 // return null;358 // }359 298 } 360 299 } -
dpf-model-editor/trunk/plugins/no.hib.dpf.codegen.xpand.ui/src/no/hib/dpf/codegen/xpand/ui/wizards/DpfGeneratorPage.java
r766 r895 3 3 import org.eclipse.jface.wizard.WizardPage; 4 4 import org.eclipse.swt.SWT; 5 import org.eclipse.swt.events.SelectionEvent; 6 import org.eclipse.swt.events.SelectionListener; 5 7 import org.eclipse.swt.layout.GridData; 6 8 import org.eclipse.swt.layout.GridLayout; 9 import org.eclipse.swt.widgets.Button; 7 10 import org.eclipse.swt.widgets.Composite; 11 import org.eclipse.swt.widgets.FileDialog; 8 12 import org.eclipse.swt.widgets.Label; 9 13 import org.eclipse.swt.widgets.Text; … … 13 17 private Text projectName, metaModelLocation; 14 18 private Label pname, mml; 19 private Button bml; 15 20 16 21 protected DpfGeneratorPage() { … … 21 26 22 27 @Override 23 public void createControl( Composite parent) {28 public void createControl(final Composite parent) { 24 29 Composite comp = new Composite(parent, SWT.NULL); 25 30 26 31 GridLayout gridLayout = new GridLayout(); 27 gridLayout.numColumns = 2;32 gridLayout.numColumns = 3; 28 33 29 34 comp.setLayout(gridLayout); 30 35 31 36 pname = new Label(comp, SWT.RIGHT); 32 pname.setText("Project Name:");33 34 projectName = new Text(comp, SWT.SINGLE );35 projectName.setLayoutData(new GridData( GridData.FILL_HORIZONTAL));37 pname.setText("Project name:"); 38 39 projectName = new Text(comp, SWT.SINGLE | SWT.BORDER); 40 projectName.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false, 2, 1)); 36 41 37 42 mml = new Label(comp, SWT.RIGHT); 38 mml.setText("Metamodel Location:");43 mml.setText("Metamodel location:"); 39 44 40 metaModelLocation = new Text(comp, SWT.SINGLE );45 metaModelLocation = new Text(comp, SWT.SINGLE | SWT.BORDER); 41 46 metaModelLocation.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 47 48 bml = new Button(comp, SWT.PUSH); 49 bml.setText("&Location"); 50 bml.addSelectionListener(new SelectionListener() { 51 52 @Override 53 public void widgetSelected(SelectionEvent e) { 54 FileDialog fd = new FileDialog(parent.getShell()); 55 fd.setFilterExtensions(new String[] {"*.xmi"}); 56 fd.setFilterNames(new String[] {"*.xmi"}); 57 fd.open(); 58 if(!fd.getFileName().isEmpty()) { 59 metaModelLocation.setText(fd.getFilterPath() + "/" + fd.getFileName()); 60 } 61 } 62 63 @Override 64 public void widgetDefaultSelected(SelectionEvent e) { 65 } 66 }); 42 67 43 68 setControl(comp); -
dpf-model-editor/trunk/plugins/no.hib.dpf.codegen.xpand.ui/src/no/hib/dpf/codegen/xpand/ui/wizards/NewDpfGeneratorWizard.java
r547 r895 12 12 *******************************************************************************/ 13 13 import java.io.ByteArrayOutputStream; 14 import java.io.File; 14 15 import java.io.IOException; 15 16 import java.io.InputStream; 16 17 import java.lang.reflect.InvocationTargetException; 18 import java.net.MalformedURLException; 17 19 import java.net.URL; 18 20 import java.util.ArrayList; … … 29 31 import no.hib.dpf.codegen.xpand.ui.properties.DpfMetaModelProperties; 30 32 33 import org.apache.log4j.Logger; 34 import org.eclipse.core.resources.IFolder; 31 35 import org.eclipse.core.resources.IProject; 32 36 import org.eclipse.core.resources.ResourcesPlugin; … … 58 62 59 63 private DpfGeneratorPage page; 60 61 64 private DpfMetaModelProperties props; 62 63 65 private IConfigurationElement configElement; 64 66 67 private String workflowContent; 65 68 private String metaModelLocation; 66 69 67 private String workflowContent; 70 private Logger log; 71 68 72 69 73 public NewDpfGeneratorWizard() { … … 71 75 super.setWindowTitle("New DPF Xpand Generator Project"); 72 76 setNeedsProgressMonitor(true); 77 log = Logger.getLogger(NewDpfGeneratorWizard.class); 73 78 } 74 79 … … 132 137 if (p == null) 133 138 return; 134 139 140 //We create a folder where our metamodel/models will reside. 141 IFolder mfolder = p.getFolder("models"); 142 if(!mfolder.exists()) { 143 try { 144 mfolder.create(false, true, monitor); 145 } catch (CoreException e) { 146 log.error("Could not create folder \"models\"", e); 147 } 148 } 149 135 150 String encoding = ResourcesPlugin.getEncoding(); 136 151 EclipseHelper.createFile(".settings/org.eclipse.core.resources.prefs", … … 150 165 monitor.worked(1); 151 166 152 // Cant access stuff outside of ui thread without this167 //We can not access stuff outside of ui thread without this 153 168 Display.getDefault().syncExec(new Runnable() { 154 169 @Override … … 157 172 try { 158 173 props.setNature(true); 159 //We use .settings file instead 160 // props.setDsmPaths(page.getMetaModelLocation()); 161 metaModelLocation = page.getMetaModelLocation(); 174 metaModelLocation = page.getMetaModelLocation(); 162 175 } catch (CoreException e) { 163 System.err.println("Problem loading dsmlocation from wizard."); 164 e.printStackTrace(); 176 log.error("Could not load metamodel location from wizard", e); 165 177 } 166 178 167 179 try { 168 WorkflowParser parse = new WorkflowParser(get ContentStream("workflowtemplate.txt"));169 parse.setProperty("dpf_metamodel", metaModelLocation);180 WorkflowParser parse = new WorkflowParser(getUIContentStream("workflowtemplate.txt")); 181 parse.setProperty("dpf_metamodel", "platform:/resource/" + p.getName() + "/models/metamodel.xmi"); 170 182 parse.setXpandEntryPoint("template::templ::main FOR dpf"); 171 183 workflowContent = parse.getXml(); … … 179 191 e.printStackTrace(); 180 192 } 181 182 183 193 } 184 194 }); 185 195 196 try { 197 EclipseHelper.createFile("models/metamodel.xmi", p, 198 getContents(new File(metaModelLocation).toURI().toURL().openStream()), monitor); 199 monitor.worked(1); 200 } catch (MalformedURLException e) { 201 // TODO Auto-generated catch block 202 e.printStackTrace(); 203 } catch (IOException e) { 204 // TODO Auto-generated catch block 205 e.printStackTrace(); 206 } 186 207 187 208 EclipseHelper.createFile("src/workflow/workflow.mwe", p, workflowContent, monitor); 188 189 monitor.worked(1); 190 191 EclipseHelper.createFile("src/template/templ.xpt", p, getContents("xpttemplate.txt"), monitor); 192 209 monitor.worked(1); 210 211 EclipseHelper.createFile("src/template/templ.xpt", p, getContentsOfTemplateResource("xpttemplate.txt"), monitor); 193 212 monitor.worked(1); 194 213 … … 196 215 p, 197 216 "eclipse.preferences.version=1\n" 198 + "metamodel.location=" + metaModelLocation,217 + "metamodel.location=" + "platform:/resource/" + p.getName() + "/models/metamodel.xmi", 199 218 new NullProgressMonitor()); 200 219 monitor.worked(1); 220 201 221 } 202 222 … … 215 235 } 216 236 217 private InputStream getContentStream(final String resource) { 237 private String getContents(final InputStream stream) { 238 try { 239 final InputStream inputStream = stream; 240 241 final byte[] buffer = new byte[4096]; 242 final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); 243 244 while (true) { 245 int read; 246 read = inputStream.read(buffer); 247 248 if (read == -1) { 249 break; 250 } 251 252 outputStream.write(buffer, 0, read); 253 } 254 255 outputStream.close(); 256 inputStream.close(); 257 258 return outputStream.toString("UTF-8"); 259 } 260 catch (final IOException e) { 261 log.error("Could not load resource", e); 262 return ""; 263 } 264 } 265 266 private URL findUIResource(String resource) { 218 267 Bundle b = Platform.getBundle("no.hib.dpf.codegen.xpand.ui"); 219 268 Enumeration<URL> ee = b.findEntries("resources", resource, false); … … 224 273 fileURL = ee.nextElement(); 225 274 } 226 try { 227 return fileURL.openStream(); 275 return fileURL; 276 } 277 278 private String getContentsOfTemplateResource(final String resource) { 279 try { 280 return getContents(findUIResource(resource).openStream()); 281 } catch (IOException e) { 282 log.error("Could not load local template resource", e); 283 return ""; 284 } 285 } 286 287 private InputStream getUIContentStream(final String resource) { 288 try { 289 return findUIResource(resource).openStream(); 228 290 } catch (IOException e) { 229 291 e.printStackTrace(); … … 231 293 } 232 294 } 233 234 private String getContents(final String resource) {235 Bundle b = Platform.getBundle("no.hib.dpf.codegen.xpand.ui");236 Enumeration<URL> ee = b.findEntries("resources", resource, false);237 238 URL fileURL = null;239 240 if(ee.hasMoreElements()) {241 fileURL = ee.nextElement();242 }243 244 try {245 final InputStream inputStream = fileURL.openStream();246 247 final byte[] buffer = new byte[4096];248 final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();249 250 while (true) {251 int read;252 read = inputStream.read(buffer);253 254 if (read == -1) {255 break;256 }257 258 outputStream.write(buffer, 0, read);259 }260 261 outputStream.close();262 inputStream.close();263 264 return outputStream.toString("UTF-8");265 }266 catch (final IOException e) {267 e.printStackTrace();268 return "";269 }270 }271 272 295 273 296 /**
![(please configure the [header_logo] section in trac.ini)](/trac/eclipsep/chrome/site/your_project_logo.png)