void createDefinitionsIfMissing() { EList<EObject> contents = resource.getContents(); if (contents.isEmpty() || !(contents.get(0) instanceof DocumentRoot)) { TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(resource); if (domain != null) { final DocumentRoot docRoot = FACTORY.createDocumentRoot(); final Definitions definitions = FACTORY.createDefinitions(); // definitions.setId(EcoreUtil.generateUUID()); ModelUtil.setID(definitions, resource); Collaboration collaboration = FACTORY.createCollaboration(); // collaboration.setId(EcoreUtil.generateUUID()); ModelUtil.setID(collaboration, resource); Participant participant = FACTORY.createParticipant(); // participant.setId(EcoreUtil.generateUUID()); ModelUtil.setID(participant, resource); participant.setName("Internal"); collaboration.getParticipants().add(participant); definitions.getRootElements().add(collaboration); domain .getCommandStack() .execute( new RecordingCommand(domain) { @Override protected void doExecute() { docRoot.setDefinitions(definitions); resource.getContents().add(docRoot); } }); return; } } }
void loadResource() { try { resource.load(null); } catch (IOException e) { Activator.logError(e); } }
private void saveResource() { fixZOrder(); try { resource.save(null); } catch (IOException e) { Activator.logError(e); } }
@SuppressWarnings("unchecked") public <T> List<T> getAll(final Class<T> class1) { ArrayList<T> l = new ArrayList<T>(); TreeIterator<EObject> contents = resource.getAllContents(); for (; contents.hasNext(); ) { Object t = contents.next(); if (class1.isInstance(t)) { l.add((T) t); } } return l; }
public Definitions getDefinitions() { return (Definitions) resource.getContents().get(0).eContents().get(0); }