private boolean setSelection(ISelection selection, boolean reveal) {
   if (selection instanceof IStructuredSelection) {
     IStructuredSelection structuredSelection = (IStructuredSelection) selection;
     Object object = structuredSelection.getFirstElement();
     if (object instanceof EObject) {
       EObject element = (EObject) object;
       Resource resource = element.eResource();
       if (resource == null) {
         return false;
       }
       if (!(resource
           instanceof
           com.github.funthomas424242.rezeptsammler.rezept.resource.rezept.IRezeptTextResource)) {
         return false;
       }
       com.github.funthomas424242.rezeptsammler.rezept.resource.rezept.IRezeptTextResource
           textResource =
               (com.github.funthomas424242.rezeptsammler.rezept.resource.rezept
                       .IRezeptTextResource)
                   resource;
       com.github.funthomas424242.rezeptsammler.rezept.resource.rezept.IRezeptLocationMap
           locationMap = textResource.getLocationMap();
       int destination = locationMap.getCharStart(element);
       if (destination < 0) {
         destination = 0;
       }
       selectAndReveal(destination, 0);
       int length = locationMap.getCharEnd(element) - destination + 1;
       getSourceViewer().setRangeIndication(destination, length, true);
       getSourceViewer().setSelectedRange(destination, length);
       return true;
     }
   }
   return false;
 }
          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;
          }
 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);
   }
 }
  /**
   * Sets the caret to the offset of the given element.
   *
   * @param element has to be contained in the resource of this editor.
   */
  public void setCaret(EObject element, String text) {
    try {
      if (element == null || text == null || text.equals("")) {
        return;
      }
      ISourceViewer viewer = getSourceViewer();
      com.github.funthomas424242.rezeptsammler.rezept.resource.rezept.IRezeptTextResource
          textResource =
              (com.github.funthomas424242.rezeptsammler.rezept.resource.rezept.IRezeptTextResource)
                  element.eResource();
      com.github.funthomas424242.rezeptsammler.rezept.resource.rezept.IRezeptLocationMap
          locationMap = textResource.getLocationMap();
      int destination = locationMap.getCharStart(element);
      int length = locationMap.getCharEnd(element) + 1 - destination;

      com.github.funthomas424242.rezeptsammler.rezept.resource.rezept.IRezeptTextScanner lexer =
          getResource().getMetaInformation().createLexer();
      try {
        lexer.setText(viewer.getDocument().get(destination, length));
        com.github.funthomas424242.rezeptsammler.rezept.resource.rezept.IRezeptTextToken token =
            lexer.getNextToken();
        String tokenText = token.getText();
        while (tokenText != null) {
          if (token.getText().equals(text)) {
            destination += token.getOffset();
            break;
          }
          token = lexer.getNextToken();
          if (token == null) {
            break;
          }
          tokenText = token.getText();
        }
      } catch (BadLocationException e) {
      }
      destination = ((ProjectionViewer) viewer).modelOffset2WidgetOffset(destination);
      if (destination < 0) {
        destination = 0;
      }
      viewer.getTextWidget().setSelection(destination);
    } catch (Exception e) {
      com.github.funthomas424242.rezeptsammler.rezept.resource.rezept.ui.RezeptUIPlugin.logError(
          "Exception in setCaret()", e);
    }
  }
 private void initializeResourceObjectFromStorage(IStorageEditorInput input) {
   URI uri = null;
   try {
     IStorage storage = input.getStorage();
     InputStream inputStream = storage.getContents();
     uri = URI.createURI(storage.getName(), true);
     ResourceSet resourceSet = getResourceSet();
     com.github.funthomas424242.rezeptsammler.rezept.resource.rezept.IRezeptTextResource resource =
         (com.github.funthomas424242.rezeptsammler.rezept.resource.rezept.IRezeptTextResource)
             resourceSet.createResource(uri);
     resource.load(inputStream, null);
     setResource(resource);
   } catch (CoreException e) {
     com.github.funthomas424242.rezeptsammler.rezept.resource.rezept.ui.RezeptUIPlugin.logError(
         "Exception while loading resource (" + uri + ") in " + getClass().getSimpleName() + ".",
         e);
   } catch (IOException e) {
     com.github.funthomas424242.rezeptsammler.rezept.resource.rezept.ui.RezeptUIPlugin.logError(
         "Exception while loading resource (" + uri + ") in " + getClass().getSimpleName() + ".",
         e);
   }
 }