Пример #1
0
  @Override
  public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    super.init(site, input);
    sourcePage.init(site, input);

    setPartNameForInput(input);

    IResource resource = ResourceUtil.getResource(input);
    if (resource != null) {
      resource.getWorkspace().addResourceChangeListener(this);
    }

    final IDocumentProvider docProvider = sourcePage.getDocumentProvider();
    IDocument document = docProvider.getDocument(input);
    try {
      model.loadFrom(new IDocumentWrapper(document));
      model.setProjectFile(Project.BNDFILE.equals(input.getName()));

      if (resource != null) {
        model.setBndResource(resource.getLocation().toFile());
      }
      // model.addPropertyChangeListener(modelListener);
    } catch (IOException e) {
      throw new PartInitException("Error reading editor input.", e);
    }

    // Ensure the field values are updated if the file content is replaced
    docProvider.addElementStateListener(
        new IElementStateListener() {
          public void elementMoved(Object originalElement, Object movedElement) {}

          public void elementDirtyStateChanged(Object element, boolean isDirty) {}

          public void elementDeleted(Object element) {}

          public void elementContentReplaced(Object element) {
            try {
              model.loadFrom(new IDocumentWrapper(docProvider.getDocument(element)));
            } catch (IOException e) {
              logger.logError("Error loading model from document.", e);
            }
          }

          public void elementContentAboutToBeReplaced(Object element) {}
        });
  }