public String getFactoryId() {
    IEditorPart editor = getEditor(false);
    if (editor == null) {
      if (input == null) {
        String memento = getModel().getPersistedState().get(MEMENTO_KEY);
        if (memento != null) {
          try {
            XMLMemento createReadRoot = XMLMemento.createReadRoot(new StringReader(memento));
            IMemento inputMem = createReadRoot.getChild(IWorkbenchConstants.TAG_INPUT);
            if (inputMem != null) {
              return inputMem.getString(IWorkbenchConstants.TAG_FACTORY_ID);
            }
          } catch (WorkbenchException e) {
            return null;
          }
        }
        return null;
      }

      IPersistableElement persistable = input.getPersistable();
      return persistable == null ? null : persistable.getFactoryId();
    }

    IPersistableElement persistable = editor.getEditorInput().getPersistable();
    return persistable == null ? null : persistable.getFactoryId();
  }
  private void restoreState() {
    String mementoString =
        Activator.getInstance().getPreferenceStore().getString("expressionMemento");
    if (mementoString == null || "".equals(mementoString)) return;
    StringReader mementoReader = new StringReader(mementoString);
    try {
      XMLMemento memento = XMLMemento.createReadRoot(mementoReader);
      IMemento[] workingSets = memento.getChildren("workingSet");
      for (int i = 0; i < workingSets.length; i++) {
        IMemento workingSetMemento = workingSets[i];
        String workingSetId = workingSetMemento.getID();
        if (workingSetId == null || "".equals(workingSetId)) {
          StatusManager.getManager()
              .handle(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "missing working set id"));
          continue;
        }
        String patternString = workingSetMemento.getString("pattern");
        if (patternString == null || "".equals(patternString)) {
          StatusManager.getManager()
              .handle(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "missing pattern"));
          continue;
        }

        Pattern pattern = null;
        try {
          pattern = Pattern.compile(patternString);
        } catch (PatternSyntaxException e) {
          StatusManager.getManager()
              .handle(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "bad pattern", e));
          continue;
        }

        IMemento rootMemento = memento.getChild("root");
        if (rootMemento == null) {
          StatusManager.getManager()
              .handle(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "missing root memento"));
          continue;
        }

        String factoryId = rootMemento.getString("factoryID");
        if (factoryId == null || "".equals(factoryId)) {
          StatusManager.getManager()
              .handle(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "missing root memento"));
          continue;
        }

        IElementFactory factory = PlatformUI.getWorkbench().getElementFactory(factoryId);
        if (factory == null) {
          StatusManager.getManager()
              .handle(
                  new Status(
                      IStatus.ERROR,
                      Activator.PLUGIN_ID,
                      "cannot create element factory: " + factoryId));
          continue;
        }

        IAdaptable item = factory.createElement(rootMemento);
        if (item == null) {
          StatusManager.getManager()
              .handle(
                  new Status(
                      IStatus.ERROR,
                      Activator.PLUGIN_ID,
                      "cannot create element from factory: " + factoryId));
          continue;
        }

        Record record = new Record();
        record.pattern = pattern;
        record.root = item;
        map.put(workingSetId, record);
      }
    } catch (WorkbenchException e) {
      StatusManager.getManager()
          .handle(
              new Status(
                  IStatus.ERROR, Activator.PLUGIN_ID, "problem restoring working set states", e));
    }
  }