@Override
  public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    setSite(site);
    setInput(input);
    setPartName(input.getName());

    // The contract of init() mentions we need to fail if we can't
    // understand the input.
    if (input instanceof FileEditorInput) {
      // We try to open a file that is part of the current workspace
      mFileEditorInput = (FileEditorInput) input;
      mFileName = mFileEditorInput.getName();
      mProject = mFileEditorInput.getFile().getProject();
    } else {
      throw new PartInitException(
          "Input is not of type FileEditorInput "
                      + //$NON-NLS-1$
                      "nor FileStoreEditorInput: "
                      + //$NON-NLS-1$
                      input
                  == null
              ? "null"
              : input.toString()); // $NON-NLS-1$
    }
  }
  @Override
  public void doSaveAs() {
    IPath relativePath = null;
    if ((relativePath = showSaveAsDialog()) != null) {
      mFileEditorInput =
          new FileEditorInput(ResourcesPlugin.getWorkspace().getRoot().getFile(relativePath));
      mFileName = mFileEditorInput.getName();
      setInput(mFileEditorInput);

      doSave(new NullProgressMonitor());
    }
  }
  /*
   * (non-Javadoc)
   *
   * @seeorg.eclipse.ui.navigator.ILinkHelper#activateEditor(org.eclipse.ui.
   * IWorkbenchPage, org.eclipse.jface.viewers.IStructuredSelection)
   */
  @Override
  public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) {

    // System.out.println("activateEditor: "+isDragActive);

    if (aSelection == null || aSelection.isEmpty()) {
      return;
    }

    Object obj = aSelection.getFirstElement();
    if (obj instanceof IOfsModelResource) {
      IOfsModelResource ofsResource = (IOfsModelResource) obj;
      URI uri = ofsResource.getURI();
      String extension = uri.fileExtension();
      if (extension != null
          && StringUtils.contains(PageConstants.PAGE_DESIGNER_FILE_EXTENSIONS, extension, true)) {
        // check if an editor is alread open for the given uri.
        String filename = uri.lastSegment();
        String id =
            PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(filename).getId();
        for (IEditorReference editor : aPage.getEditorReferences()) {
          if (editor.getId().equals(id)) {
            try {
              IEditorInput eInput = editor.getEditorInput();
              if (eInput instanceof FileEditorInput) {
                FileEditorInput fInput = (FileEditorInput) eInput;
                if (filename.equals(fInput.getName())) {
                  if (isDragActive) {
                    // an editor is already open, simply return
                    // to avoid the activation of this editor.
                    isDragActive = false;
                    return;
                  }
                }
              }
            } catch (PartInitException ex) {
              // silently ignore
            }
          }
        }
      }
    }

    // editor not found
    super.activateEditor(aPage, aSelection);
  }
 public String getName() {
   return innerEidtorInput.getName();
 }
  @Override
  public void doSave(final IProgressMonitor monitor) {
    boolean hasNinePatchExtension = mFileName.endsWith(DOT_9PNG);
    boolean doConvert = false;

    if (!hasNinePatchExtension) {
      String patchedName = NinePatchedImage.getNinePatchedFileName(mFileName);
      doConvert =
          MessageDialog.openQuestion(
              AndmoreAndroidPlugin.getDisplay().getActiveShell(),
              "Warning",
              String.format(
                  "The file \"%s\" doesn't seem to be a 9-patch file. \n"
                      + "Do you want to convert and save as \"%s\" ?",
                  mFileName, patchedName));

      if (doConvert) {
        IFile destFile =
            mProject.getFile(
                NinePatchedImage.getNinePatchedFileName(
                    mFileEditorInput.getFile().getProjectRelativePath().toOSString()));
        if (!destFile.exists()) {
          mFileEditorInput = new FileEditorInput(destFile);
          mFileName = mFileEditorInput.getName();
        } else {
          IPath relativePath = null;
          if ((relativePath = showSaveAsDialog()) != null) {
            mFileEditorInput =
                new FileEditorInput(ResourcesPlugin.getWorkspace().getRoot().getFile(relativePath));
            mFileName = mFileEditorInput.getName();
          } else {
            doConvert = false;
          }
        }
      }
    }

    if (hasNinePatchExtension || doConvert) {
      ImageLoader loader = new ImageLoader();
      loader.data = new ImageData[] {mNinePatchedImage.getRawImageData()};

      IFile file = mFileEditorInput.getFile();

      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
      loader.save(outputStream, SWT.IMAGE_PNG);
      byte[] byteArray = outputStream.toByteArray();

      try {
        if (file.exists()) {
          file.setContents(new ByteArrayInputStream(byteArray), true, false, monitor);
        } else {
          file.create(new ByteArrayInputStream(byteArray), true, monitor);
        }

        mNinePatchedImage.clearDirtyFlag();

        AndmoreAndroidPlugin.getDisplay()
            .asyncExec(
                new Runnable() {
                  @Override
                  public void run() {
                    setPartName(mFileName);
                    firePropertyChange(PROP_DIRTY);
                  }
                });
      } catch (CoreException e) {
        AndmoreAndroidPlugin.log(e, null);
      }
    }
  }