@Override
 public void save(IMemento memento) {
   super.save(memento);
   if (prefId != null) {
     IMemento pref = memento.createChild(PREF_ID);
     pref.putTextData(prefId);
   }
   if (label != null) {
     IMemento lbl = memento.createChild(LABEL);
     lbl.putTextData(label);
   }
 }
  IMemento getEditorState() {
    IEditorPart editor = getEditor(false);

    // If the editor hasn't been rendered yet then see if we can grab the
    // info from the model
    if (editor == null && getModel() != null) {
      String savedState = getModel().getPersistedState().get(MEMENTO_KEY);
      if (savedState != null) {
        StringReader sr = new StringReader(savedState);
        try {
          XMLMemento memento = XMLMemento.createReadRoot(sr);
          return memento;
        } catch (WorkbenchException e) {
          WorkbenchPlugin.log(e);
          return null;
        }
      }
      return null;
    }

    IEditorInput input = editor.getEditorInput();
    if (input == null) {
      return null;
    }

    IPersistableElement persistable = input.getPersistable();
    if (persistable == null) {
      return null;
    }

    XMLMemento editorMem = XMLMemento.createWriteRoot(IWorkbenchConstants.TAG_EDITOR);
    editorMem.putString(IWorkbenchConstants.TAG_ID, descriptor.getId());
    editorMem.putString(IWorkbenchConstants.TAG_TITLE, getTitle());
    editorMem.putString(IWorkbenchConstants.TAG_NAME, getName());
    editorMem.putString(IWorkbenchConstants.TAG_ID, getId());
    editorMem.putString(IWorkbenchConstants.TAG_TOOLTIP, getTitleToolTip());
    editorMem.putString(IWorkbenchConstants.TAG_PART_NAME, getPartName());

    if (editor instanceof IWorkbenchPart3) {
      Map properties = ((IWorkbenchPart3) editor).getPartProperties();
      if (!properties.isEmpty()) {
        IMemento propBag = editorMem.createChild(IWorkbenchConstants.TAG_PROPERTIES);
        Iterator i = properties.entrySet().iterator();
        while (i.hasNext()) {
          Map.Entry entry = (Map.Entry) i.next();
          IMemento p =
              propBag.createChild(IWorkbenchConstants.TAG_PROPERTY, (String) entry.getKey());
          p.putTextData((String) entry.getValue());
        }
      }
    }

    if (isPinned()) {
      editorMem.putString(IWorkbenchConstants.TAG_PINNED, "true"); // $NON-NLS-1$
    }

    IMemento inputMem = editorMem.createChild(IWorkbenchConstants.TAG_INPUT);
    inputMem.putString(IWorkbenchConstants.TAG_FACTORY_ID, persistable.getFactoryId());
    persistable.saveState(inputMem);

    if (editor instanceof IPersistableEditor) {
      IMemento editorStateMem = editorMem.createChild(IWorkbenchConstants.TAG_EDITOR_STATE);
      ((IPersistableEditor) editor).saveState(editorStateMem);
    }

    return editorMem;
  }