/** * Create a resource from the given URI and append a new Network instance to its contents. The * resourceSet used must be authorized to write on the disk. This means that the default * EditingDomain's resourceSet must be used in a write transaction (for example). If it is not * possible, do not provide a resourceSet, the default one will be used. * * @param resourceSet * @param uri * @return The created network * @throws IOException */ public static Network createNetworkResource(final ResourceSet resourceSet, final URI uri) throws IOException { final String fileName; if (uri.isPlatform()) { fileName = uri.toPlatformString(true); } else { fileName = uri.toString(); } // Create the network final Network network = DfFactory.eINSTANCE.createNetwork(fileName); // Compute the new network name final Path networkPath = new Path(uri.trimFileExtension().path()); // 3 first segments are resource/<PROJECT>/src network.setName(networkPath.removeFirstSegments(3).toString().replace('/', '.')); // Create the resource Resource res = resourceSet.createResource(uri); res.getContents().add(network); res.save(Collections.EMPTY_MAP); return network; }
@Override public boolean isAffected( Collection<Delta> deltas, IResourceDescription candidate, IResourceDescriptions context) { Set<URI> outgoingReferences = descriptionUtils.collectOutgoingReferences(candidate); if (!outgoingReferences.isEmpty()) { for (IResourceDescription.Delta delta : deltas) if (hasChanges(delta, candidate) && outgoingReferences.contains(delta.getUri())) return true; } // this is a tradeoff - we could either check whether a given delta uri is contained // in a reachable container and check for intersecting names afterwards, or we can do // the other way round // unfortunately there is no way to decide reliably which algorithm scales better // note that this method is called for each description so we have something like a // number of deltas x number of resources which is not really nice List<IContainer> containers = null; Collection<QualifiedName> importedNames = getImportedNames(candidate); for (IResourceDescription.Delta delta : deltas) { if (hasChanges(delta, candidate)) { // not a java resource - delta's resource should be contained in a visible container // as long as we did not delete the resource URI uri = delta.getUri(); if ((uri.isPlatform() || uri.isArchive()) && delta.getNew() != null) { if (containers == null) containers = containerManager.getVisibleContainers(candidate, context); boolean descriptionIsContained = false; for (int i = 0; i < containers.size() && !descriptionIsContained; i++) { descriptionIsContained = containers.get(i).hasResourceDescription(uri); } if (!descriptionIsContained) return false; } if (isAffected(importedNames, delta.getNew()) || isAffected(importedNames, delta.getOld())) { return true; } } } return false; }
public boolean loadResource(ModelSet modelSet, URI uri) { // pathmap resource are always loaded boolean result = !uri.isPlatform() && !uri.isFile(); if (!result) { URI lastInitialURI = SashModelUtils.getInitialURI(modelSet).trimFileExtension(); if (!lastInitialURI.equals(initialURI)) { clear(); initialURI = lastInitialURI; } URI uritrimFragment = uri.trimFragment().trimFileExtension(); Set<String> extensions = mappingURIExtensions.get(uritrimFragment); if (extensions == null) { extensions = new HashSet<String>(); mappingURIExtensions.put(uritrimFragment, extensions); } extensions.add(uri.fileExtension()); result = lastInitialURI.equals(uritrimFragment); if (!result) { result = alreadyValidated.contains(uritrimFragment); if (!result) { if (!alreadyGuessed.contains(uritrimFragment)) { String message = new StringBuffer("<form><p>Your model is linked to an external resource (") .append(uritrimFragment.toString()) .append(").</p><p>Do you want to load it ?</p></form>") .toString(); NotificationBuilder builder = getNotification(message, uritrimFragment, modelSet); builder.run(); alreadyGuessed.add(uritrimFragment); // notification } } } } return result; }
/** * @param eObj * @return boolean */ protected boolean isReadOnly(EObject eObj) { boolean isReadOnly = false; Resource resource = eObj.eResource(); if (resource != null) { IOfsProject ofsProject = OfsResourceHelper.getOfsProject(resource); if (ofsProject != null) { try { URI uri = eObj.eResource().getURI(); if (uri.isPlatform()) { String[] segments = resource.getURI().segments(); StringBuffer path = new StringBuffer(); for (int kx = 3; kx < segments.length; kx++) { path.append("/" + segments[kx]); } uri = ModelURIConverter.createModelURI(path.toString()); } IOfsModelResource ofsResource = ofsProject.getOfsModelResource(uri); isReadOnly = ofsResource.isReadOnly(); } catch (ModelNotFoundException ex) {;; // ignore } } } return isReadOnly; }