Example #1
0
 private void openUnclosedMapLastSession(File statusFile, final IWorkbenchPage page)
     throws FileNotFoundException, UnsupportedEncodingException, WorkbenchException, CoreException,
         PartInitException {
   FileInputStream input = new FileInputStream(statusFile);
   BufferedReader reader =
       new BufferedReader(new InputStreamReader(input, "utf-8")); // $NON-NLS-1$
   IMemento memento = XMLMemento.createReadRoot(reader);
   IMemento childMem = memento.getChild(IWorkbenchConstants.TAG_EDITORS);
   //        ((WorkbenchPage) page).getEditorManager().restoreState(childMem);
   IMemento[] childrenEditor = childMem.getChildren("editor"); // $NON-NLS-1$
   IEditorPart activeEditorPart = null;
   for (IMemento childEditor : childrenEditor) {
     IMemento childInput = childEditor.getChild("input"); // $NON-NLS-1$
     String path = childInput.getString("path"); // $NON-NLS-1$
     if (path != null) {
       IEditorInput editorInput = MME.createFileEditorInput(path);
       IEditorPart editorPart = page.openEditor(editorInput, MindMapUI.MINDMAP_EDITOR_ID);
       if ("true".equals(childEditor.getString("activePart"))) { // $NON-NLS-1$ //$NON-NLS-2$
         activeEditorPart = editorPart;
       }
     }
   }
   if (activeEditorPart != null) {
     page.activate(activeEditorPart);
   }
 }
 @Override
 public void load(IMemento memento) {
   super.load(memento);
   IMemento pref = memento.getChild(PREF_ID);
   if (pref != null) {
     prefId = pref.getTextData();
   }
   IMemento lbl = memento.getChild(LABEL);
   if (lbl != null) {
     label = lbl.getTextData();
   }
 }
  private ISelection restoreSelectionState(IMemento memento) {
    if (memento == null) return null;

    IMemento childMem;
    childMem = memento.getChild(TAG_SELECTED_ELEMENTS);
    if (childMem != null) {
      ArrayList list = new ArrayList();
      IMemento[] elementMem = childMem.getChildren(TAG_SELECTED_ELEMENT);
      for (int i = 0; i < elementMem.length; i++) {
        String javaElementHandle = elementMem[i].getString(TAG_SELECTED_ELEMENT_PATH);
        if (javaElementHandle == null) {
          // logical package
          IMemento[] packagesMem = elementMem[i].getChildren(TAG_LOGICAL_PACKAGE);
          LogicalPackage lp = null;
          for (int j = 0; j < packagesMem.length; j++) {
            javaElementHandle = packagesMem[j].getString(TAG_SELECTED_ELEMENT_PATH);
            Object pack = DLTKCore.create(javaElementHandle);
            if (pack instanceof IScriptFolder && ((IScriptFolder) pack).exists()) {
              if (lp == null) lp = new LogicalPackage((IScriptFolder) pack);
              else lp.add((IScriptFolder) pack);
            }
          }
          if (lp != null) list.add(lp);
        } else {
          IModelElement element = DLTKCore.create(javaElementHandle);
          if (element != null && element.exists()) list.add(element);
        }
      }
      return new StructuredSelection(list);
    }
    return null;
  }
Example #4
0
  /** Restores the object state from the memento. */
  public IStatus restoreState() {
    Assert.isTrue(!isRestored());

    IStatus result = Status.OK_STATUS;
    IMemento memento = this.memento;
    this.memento = null;

    String factoryId = memento.getString(IWorkbenchConstants.TAG_FACTORY_ID);
    if (factoryId == null) {
      WorkbenchPlugin.log("Unable to restore mru list - no input factory ID."); // $NON-NLS-1$
      return result;
    }
    IElementFactory factory = PlatformUI.getWorkbench().getElementFactory(factoryId);
    if (factory == null) {
      return result;
    }
    IMemento persistableMemento = memento.getChild(IWorkbenchConstants.TAG_PERSISTABLE);
    if (persistableMemento == null) {
      WorkbenchPlugin.log(
          "Unable to restore mru list - no input element state: " + factoryId); // $NON-NLS-1$
      return result;
    }
    IAdaptable adaptable = factory.createElement(persistableMemento);
    if (adaptable == null || (adaptable instanceof IEditorInput) == false) {
      return result;
    }
    input = (IEditorInput) adaptable;
    // Get the editor descriptor.
    String editorId = memento.getString(IWorkbenchConstants.TAG_ID);
    if (editorId != null) {
      IEditorRegistry registry = WorkbenchPlugin.getDefault().getEditorRegistry();
      descriptor = registry.findEditor(editorId);
    }
    return result;
  }
 /**
  * Retrieves the memento corresponding to the list of hidden palettes for a given editor part
  *
  * @param part the editor for which preferences should be found
  * @return the memento corresponding to the hidden palettes list
  */
 public static IMemento getEditorHiddenPalettesMemento(IMemento editorMemento) {
   IMemento hiddenPaletteMemento = editorMemento.getChild(HIDDEN_PALETTES);
   if (hiddenPaletteMemento == null) {
     hiddenPaletteMemento = editorMemento.createChild(HIDDEN_PALETTES);
   }
   return hiddenPaletteMemento;
 }
 private void restoreState() {
   if (memento == null) return;
   IMemento m = memento.getChild(ID);
   String objType = m.getString("objType");
   String counter = m.getString("counter");
   String sDate = CastUtil.cString(m.getString("sDate"));
   String eDate = CastUtil.cString(m.getString("eDate"));
   int serverId = CastUtil.cint(m.getInteger("serverId"));
   try {
     setInput(sDate, eDate, objType, counter, serverId);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.ui.internal.e4.compatibility.WorkbenchPartReference#initialize
   * (org.eclipse.ui.IWorkbenchPart)
   */
  @Override
  public void initialize(IWorkbenchPart part) throws PartInitException {
    IConfigurationElement element = descriptor.getConfigurationElement();
    editorSite = new EditorSite(getModel(), part, this, element);
    if (element == null) {
      editorSite.setExtensionId(descriptor.getId());
    }
    editorSite.setActionBars(
        createEditorActionBars((WorkbenchPage) getPage(), descriptor, editorSite));
    IEditorPart editor = (IEditorPart) part;
    try {
      editor.init(editorSite, getEditorInput());
    } catch (PartInitException e) {
      if (editor instanceof ErrorEditorPart) {
        editor.init(editorSite, new NullEditorInput(this));
      } else {
        throw e;
      }
    }

    if (editor.getSite() != editorSite || editor.getEditorSite() != editorSite) {
      String id = descriptor == null ? getModel().getElementId() : descriptor.getId();
      throw new PartInitException(NLS.bind(WorkbenchMessages.EditorManager_siteIncorrect, id));
    }

    if (part instanceof IPersistableEditor) {
      if (editorState != null) {
        ((IPersistableEditor) part).restoreState(editorState);
      } else if (useIPersistableEditor()) {
        String mementoString = getModel().getPersistedState().get(MEMENTO_KEY);
        if (mementoString != null) {
          try {
            IMemento createReadRoot = XMLMemento.createReadRoot(new StringReader(mementoString));
            IMemento editorStateMemento =
                createReadRoot.getChild(IWorkbenchConstants.TAG_EDITOR_STATE);
            if (editorStateMemento != null) {
              ((IPersistableEditor) part).restoreState(editorStateMemento);
            }
          } catch (WorkbenchException e) {
            throw new PartInitException(e.getStatus());
          }
        }
      }
    }

    legacyPart = part;
    addPropertyListeners();
  }
  private void restoreState() {
    if (memento == null) return;
    IMemento m = memento.getChild(ID);

    String date = m.getString("date");
    int objHash = CastUtil.cint(m.getInteger("objHash"));
    String objName = m.getString("objName");
    String counter = m.getString("counter");
    String objType = m.getString("objType");
    int serverId = CastUtil.cint(m.getInteger("serverId"));
    try {
      setInput(date, startTime, endTime, objHash, objName, objType, counter, serverId);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  public static IEditorInput createInput(IMemento editorMem) throws PartInitException {
    String editorId = editorMem.getString(IWorkbenchConstants.TAG_ID);

    IMemento inputMem = editorMem.getChild(IWorkbenchConstants.TAG_INPUT);

    String editorName = null;
    String factoryID = null;
    if (inputMem != null) {
      editorName = inputMem.getString(IWorkbenchConstants.TAG_PATH);
      factoryID = inputMem.getString(IWorkbenchConstants.TAG_FACTORY_ID);
    }
    if (factoryID == null) {
      throw new PartInitException(
          NLS.bind(WorkbenchMessages.EditorManager_no_input_factory_ID, editorId, editorName));
    }
    IAdaptable input = null;
    IElementFactory factory = PlatformUI.getWorkbench().getElementFactory(factoryID);
    if (factory == null) {
      throw new PartInitException(
          NLS.bind(
              WorkbenchMessages.EditorManager_bad_element_factory,
              new Object[] {factoryID, editorId, editorName}));
    }

    // Get the input element.
    input = factory.createElement(inputMem);
    if (input == null) {
      throw new PartInitException(
          NLS.bind(
              WorkbenchMessages.EditorManager_create_element_returned_null,
              new Object[] {factoryID, editorId, editorName}));
    }
    if (!(input instanceof IEditorInput)) {
      throw new PartInitException(
          NLS.bind(
              WorkbenchMessages.EditorManager_wrong_createElement_result,
              new Object[] {factoryID, editorId, editorName}));
    }
    return (IEditorInput) input;
  }