@Override public IDecorator[] getDecorators(final PictogramElement pe) { IFeatureProvider featureProvider = getFeatureProvider(); Object bo = featureProvider.getBusinessObjectForPictogramElement(pe); Integer objectId; if (bo instanceof Method) { System.out.println("CHECKING METHOD"); objectId = System.identityHashCode(bo.getClass()); try { // generate decorator and markers if (!XcoreValidator.INSTANCE.validateMethod((Method) bo, diagnosticChain, null)) { Diagnostic lastDiagnostic = diagnosticChain.getChildren().get(diagnosticChain.getChildren().size() - 1); markers.put( objectId, AtomicDesignUtils.createMarker( lastDiagnostic.getMessage(), IMarker.SEVERITY_ERROR, ((Method) bo).getClass().getName())); return new ImageDecorator[] { AtomicDesignUtils.createImageDecorator( lastDiagnostic, lastDiagnostic.getMessage(), 20, 0) }; } else { AtomicDesignUtils.destroyMarker(markers.get(objectId)); } } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (bo instanceof ComputationUnit) { System.out.println("CHECKING CU"); if (!XcoreValidator.INSTANCE.validateComputationUnit( (ComputationUnit) bo, diagnosticChain, null)) { System.out.println("CHECKING METHOD"); } } if (bo instanceof DataElement) { System.out.println("CHECKING DATAELEMENT"); if (!XcoreValidator.INSTANCE.validateDataElement((DataElement) bo, diagnosticChain, null)) {} } if (bo instanceof Service) { System.out.println("CHECKING SERVICE"); if (!XcoreValidator.INSTANCE.validateService((Service) bo, diagnosticChain, null)) {} } if (bo instanceof Parameter) { System.out.println("CHECKING PARAMETER"); if (!XcoreValidator.INSTANCE.validateParameter((Parameter) bo, diagnosticChain, null)) {} } return super.getDecorators(pe); }
@Override public void execute(ICustomContext context) { PictogramElement[] pes = context.getPictogramElements(); if (pes != null && pes.length == 1) { Object bo = getBusinessObjectForPictogramElement(pes[0]); if (bo instanceof ComputationUnit) { final ComputationUnit cu = (ComputationUnit) bo; String workspaceDirectory = ResourcesPlugin.getWorkspace().getRoot().getLocation().toString() + "/"; IProject project = AtomicDesignUtils.getCurrentResource().getProject(); String currentProject = project.getName() + "/"; String projectDirectory = workspaceDirectory + currentProject; try { (new File(projectDirectory + COMPUTATION_UNIT_DIRECTORY_NAME + currentProject)).mkdirs(); final File fileToOpen = new File( projectDirectory + COMPUTATION_UNIT_DIRECTORY_NAME + currentProject + COMPUTATION_UNIT_FILE_NAME); fileToOpen.createNewFile(); if (cu.getSourceCode() != null) { FileWriter fw = new FileWriter(fileToOpen.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(cu.getSourceCode()); bw.close(); fw.close(); } IFileStore fileOnLocalDisk = EFS.getLocalFileSystem().getStore(fileToOpen.toURI()); IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); project.refreshLocal(IResource.DEPTH_INFINITE, null); IDE.openInternalEditorOnFileStore(page, fileOnLocalDisk) .addPropertyListener( new IPropertyListener() { @Override public void propertyChanged(Object source, int propId) { TransactionalEditingDomain editingDomain = getFeatureProvider() .getDiagramTypeProvider() .getDiagramBehavior() .getEditingDomain(); editingDomain .getCommandStack() .execute( new RecordingCommand(editingDomain) { @Override protected void doExecute() { try { BufferedReader reader = new BufferedReader(new FileReader(fileToOpen)); String line = null; StringBuilder stringBuilder = new StringBuilder(); String ls = System.getProperty("line.separator"); while ((line = reader.readLine()) != null) { stringBuilder.append(line); stringBuilder.append(ls); } cu.setSourceCode(stringBuilder.toString()); } catch (FileNotFoundException e) { System.out.println("Error opening file"); } catch (IOException e) { System.out.println("Error reading file"); e.printStackTrace(); } } }); } }); } catch (IOException e) { System.out.println("Error creating file"); } catch (PartInitException e) { System.out.println("Error opening editor"); } catch (CoreException e) { System.out.println("Error refreshing project"); } } } }