Ejemplo n.º 1
0
          public boolean visit(IResourceDelta delta) {
            if (delta.getResource().getType() != IResource.FILE) {
              return true;
            }
            int deltaKind = delta.getKind();
            if (deltaKind == IResourceDelta.CHANGED && delta.getFlags() != IResourceDelta.MARKERS) {
              URI platformURI = URI.createPlatformResourceURI(delta.getFullPath().toString(), true);
              Resource changedResource = resourceSet.getResource(platformURI, false);
              if (changedResource != null) {
                changedResource.unload();
                com.github.funthomas424242.rezeptsammler.rezept.resource.rezept.IRezeptTextResource
                    currentResource = getResource();
                if (changedResource.equals(currentResource)) {
                  // reload the resource displayed in the editor
                  resourceSet.getResource(currentResource.getURI(), true);
                }
                if (currentResource != null && currentResource.getErrors().isEmpty()) {
                  EcoreUtil.resolveAll(currentResource);
                }
                // reset the selected element in outline and properties by text position
                if (highlighting != null) {
                  highlighting.updateEObjectSelection();
                }
              }
            }

            return true;
          }
Ejemplo n.º 2
0
 private void initializeResourceObjectFromFile(FileEditorInput input) {
   IFile inputFile = input.getFile();
   com.github.funthomas424242.rezeptsammler.rezept.resource.rezept.mopp.RezeptNature.activate(
       inputFile.getProject());
   String path = inputFile.getFullPath().toString();
   URI uri = URI.createPlatformResourceURI(path, true);
   ResourceSet resourceSet = getResourceSet();
   com.github.funthomas424242.rezeptsammler.rezept.resource.rezept.IRezeptTextResource
       loadedResource =
           (com.github.funthomas424242.rezeptsammler.rezept.resource.rezept.IRezeptTextResource)
               resourceSet.getResource(uri, false);
   if (loadedResource == null) {
     try {
       Resource demandLoadedResource = null;
       // here we do not use getResource(), because 'resource' might be null, which is ok
       // when initializing the resource object
       com.github.funthomas424242.rezeptsammler.rezept.resource.rezept.IRezeptTextResource
           currentResource = this.resource;
       if (currentResource != null
           && !currentResource.getURI().fileExtension().equals(uri.fileExtension())) {
         // do not attempt to load if file extension has changed in a 'save as' operation
       } else {
         demandLoadedResource = resourceSet.getResource(uri, true);
       }
       if (demandLoadedResource
           instanceof
           com.github.funthomas424242.rezeptsammler.rezept.resource.rezept.IRezeptTextResource) {
         setResource(
             (com.github.funthomas424242.rezeptsammler.rezept.resource.rezept.IRezeptTextResource)
                 demandLoadedResource);
       } else {
         // the resource was not loaded by an EMFText resource, but some other EMF resource
         com.github.funthomas424242.rezeptsammler.rezept.resource.rezept.ui.RezeptUIPlugin
             .showErrorDialog(
                 "Invalid resource.",
                 "The file '"
                     + uri.lastSegment()
                     + "' of type '"
                     + uri.fileExtension()
                     + "' can not be handled by the RezeptEditor.");
         // close this editor because it can not present the resource
         close(false);
       }
     } catch (Exception e) {
       com.github.funthomas424242.rezeptsammler.rezept.resource.rezept.ui.RezeptUIPlugin.logError(
           "Exception while loading resource in " + this.getClass().getSimpleName() + ".", e);
     }
   } else {
     setResource(loadedResource);
   }
 }