Пример #1
0
  private static void writeMemento(IMemento memento) {
    IWaypoint[] waypoints =
        TagSEAPlugin.getWaypointsModel().getWaypoints(URLWaypointPlugin.WAYPOINT_ID);

    for (IWaypoint waypoint : waypoints) {
      IMemento waypointMemento = memento.createChild(URL_WAYPOINT);

      waypointMemento.putString(
          URL_ATTRIBUTE, waypoint.getStringValue(URLWaypointUtil.URL_ATTR, ""));
      waypointMemento.putString(AUTHOR_ATTRIBUTE, waypoint.getAuthor());

      if (waypoint.getDate() != null) {
        SimpleDateFormat format = new SimpleDateFormat();
        String dateString = format.format(waypoint.getDate());
        waypointMemento.putString(DATE_ATTRIBUTE, dateString);
      }

      waypointMemento.putString(DESCRIPTION_ATTRIBUTE, waypoint.getText());

      ITag[] tags = waypoint.getTags();

      for (ITag tag : tags) {
        IMemento tagMemento = waypointMemento.createChild(TAG);
        tagMemento.putString(NAME_ATTRIBUTE, tag.getName());
      }
    }
  }
 @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);
   }
 }
Пример #3
0
 /**
  * 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;
 }
Пример #4
0
  /**
   * Implements IPersistableElement. Persist the working set name and working set contents. The
   * contents has to be either IPersistableElements or provide adapters for it to be persistent.
   *
   * @see org.eclipse.ui.IPersistableElement#saveState(IMemento)
   */
  public void saveState(IMemento memento) {
    if (workingSetMemento != null) {
      // just re-save the previous memento if the working set has
      // not been restored
      memento.putMemento(workingSetMemento);
    } else {
      memento.putString(IWorkbenchConstants.TAG_NAME, getName());
      memento.putString(IWorkbenchConstants.TAG_LABEL, getLabel());
      memento.putString(IWorkbenchConstants.TAG_ID, getUniqueId());
      memento.putString(IWorkbenchConstants.TAG_EDIT_PAGE_ID, editPageId);
      Iterator iterator = elements.iterator();
      while (iterator.hasNext()) {
        IAdaptable adaptable = (IAdaptable) iterator.next();
        final IPersistableElement persistable =
            (IPersistableElement) Util.getAdapter(adaptable, IPersistableElement.class);
        if (persistable != null) {
          final IMemento itemMemento = memento.createChild(IWorkbenchConstants.TAG_ITEM);

          itemMemento.putString(IWorkbenchConstants.TAG_FACTORY_ID, persistable.getFactoryId());
          SafeRunner.run(
              new SafeRunnable(
                  "Problems occurred while saving persistable item state") { //$NON-NLS-1$

                public void run() throws Exception {
                  persistable.saveState(itemMemento);
                }
              });
        }
      }
    }
  }
Пример #5
0
  /**
   * Saves the object state in the given memento.
   *
   * @param memento the memento to save the object state in
   */
  public IStatus saveState(IMemento memento) {
    if (!isRestored()) {
      memento.putMemento(this.memento);
    } else if (input != null) {

      IPersistableElement persistable = input.getPersistable();
      if (persistable != null) {
        /*
         * Store IPersistable of the IEditorInput in a separate section
         * since it could potentially use a tag already used in the parent
         * memento and thus overwrite data.
         */
        IMemento persistableMemento = memento.createChild(IWorkbenchConstants.TAG_PERSISTABLE);
        persistable.saveState(persistableMemento);
        memento.putString(IWorkbenchConstants.TAG_FACTORY_ID, persistable.getFactoryId());
        if (descriptor != null && descriptor.getId() != null) {
          memento.putString(IWorkbenchConstants.TAG_ID, descriptor.getId());
        }
        // save the name and tooltip separately so they can be restored
        // without having to instantiate the input, which can activate plugins
        memento.putString(IWorkbenchConstants.TAG_NAME, input.getName());
        memento.putString(IWorkbenchConstants.TAG_TOOLTIP, input.getToolTipText());
      }
    }
    return Status.OK_STATUS;
  }
Пример #6
0
  /** Adds or update local palette */
  public static void addLocalPalette(
      String paletteID,
      String paletteName,
      ProviderPriority priority,
      String editorID,
      Set<String> requiredProfiles) {
    // retrieves memento
    XMLMemento rootMemento = getExistingLocalPalettes();

    // search existing customization
    IMemento paletteMemento = searchPaletteMemento(rootMemento, paletteID);
    if (paletteMemento == null) {
      paletteMemento = createMemento(rootMemento, paletteID);
    }

    // update values in the memento
    paletteMemento.putString(NAME, paletteName);
    paletteMemento.putString(PRIORITY, priority.getName());
    paletteMemento.putString(EDITOR_ID, editorID);
    paletteMemento.putString(PATH, getPalettePathFromID(paletteID));

    // add properties if required
    IMemento propertiesMemento =
        paletteMemento.createChild(IPapyrusPaletteConstant.PALETTE_DESCRIPTION_PROPERTIES);
    propertiesMemento.putString(
        IPapyrusPaletteConstant.PROFILE_LIST,
        PaletteUtil.getSerializedProfileListFromSet(requiredProfiles));

    // saves the root memento
    saveLocalPalettes(rootMemento);
  }
 public void saveState(IMemento memento) {
   super.saveState(memento);
   memento = memento.createChild(ID);
   memento.putString("objType", objType);
   memento.putString("counter", counter);
   memento.putString("sDate", this.sDate);
   memento.putString("eDate", this.eDate);
 }
Пример #8
0
  public void saveState(IMemento memento) {
    for (int i = 0; i < infos.length; i++) {
      SortInfo info = infos[i];
      IMemento mem = memento.createChild(TAG_TYPE);
      mem.putInteger(TAG_COLUMN_INDEX, info.columnIndex);

      if (info.descending) mem.putString(TAG_DESCENDING, TAG_TRUE);
    }
  }
Пример #9
0
 public void saveState(IMemento memento) {
   super.saveState(memento);
   memento = memento.createChild(ID);
   memento.putString("date", date);
   memento.putInteger("objHash", objHash);
   memento.putString("objName", objName);
   memento.putString("counter", counter);
   memento.putString("objType", objType);
   memento.putInteger("serverId", serverId);
 }
 private void saveSelectionState(IMemento memento) {
   Object elements[] = ((IStructuredSelection) fViewer.getSelection()).toArray();
   if (elements.length > 0) {
     IMemento selectionMem = memento.createChild(TAG_SELECTED_ELEMENTS);
     for (int i = 0; i < elements.length; i++) {
       IMemento elementMem = selectionMem.createChild(TAG_SELECTED_ELEMENT);
       Object o = elements[i];
       if (o instanceof IModelElement)
         elementMem.putString(
             TAG_SELECTED_ELEMENT_PATH, ((IModelElement) elements[i]).getHandleIdentifier());
       else if (o instanceof LogicalPackage) {
         IScriptFolder[] packages = ((LogicalPackage) o).getScriptFolders();
         for (int j = 0; j < packages.length; j++) {
           IMemento packageMem = elementMem.createChild(TAG_LOGICAL_PACKAGE);
           packageMem.putString(TAG_SELECTED_ELEMENT_PATH, packages[j].getHandleIdentifier());
         }
       }
     }
   }
 }
Пример #11
0
 /**
  * Save the most-recently-used history in the given memento.
  *
  * @param memento the memento to save the mru history in
  */
 public IStatus saveState(IMemento memento) {
   Iterator iterator = fifoList.iterator();
   while (iterator.hasNext()) {
     EditorHistoryItem item = (EditorHistoryItem) iterator.next();
     if (item.canSave()) {
       IMemento itemMemento = memento.createChild(IWorkbenchConstants.TAG_FILE);
       item.saveState(itemMemento);
     }
   }
   return Status.OK_STATUS;
 }
Пример #12
0
 /** Saves the code folding state into the given memento. */
 public void saveCodeFolding(org.eclipse.ui.IMemento memento) {
   java.util.Iterator<?> annotationIt = projectionAnnotationModel.getAnnotationIterator();
   while (annotationIt.hasNext()) {
     org.eclipse.jface.text.source.projection.ProjectionAnnotation annotation =
         (org.eclipse.jface.text.source.projection.ProjectionAnnotation) annotationIt.next();
     org.eclipse.ui.IMemento annotationMemento = memento.createChild(ANNOTATION);
     org.eclipse.jface.text.Position position = projectionAnnotationModel.getPosition(annotation);
     annotationMemento.putBoolean(IS_COLLAPSED, annotation.isCollapsed());
     annotationMemento.putInteger(OFFSET, position.offset);
     annotationMemento.putInteger(LENGTH, position.length);
   }
 }
Пример #13
0
  @Override
  public void saveState(IMemento memento) {
    for (Iterator<Entry<IPageBookViewPage, DummyPart>> iter = fPagesToParts.entrySet().iterator();
        iter.hasNext(); ) {
      Entry<IPageBookViewPage, DummyPart> entry = iter.next();
      ISearchResultPage page = (ISearchResultPage) entry.getKey();
      DummyPart part = entry.getValue();

      IMemento child = memento.createChild(MEMENTO_TYPE, page.getID());
      page.saveState(child);
      child.putInteger(MEMENTO_KEY_LAST_ACTIVATION, part.getLastActivation());
    }
  }
Пример #14
0
  /** Add a child node to a given memento, named after the object's {@link Root} annotation. */
  public static void addChild(IMemento memento, Object object) throws IOException {
    checkObject(object);

    final IMemento child = toMemento(object);
    memento.createChild(child.getType()).putMemento(child);
  }
  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;
  }