Beispiel #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());
      }
    }
  }
Beispiel #2
0
  private static void restoreStateFromMemento(IMemento memento) {
    IMemento[] urlMementos = memento.getChildren(URL_WAYPOINT);

    for (IMemento urlMemento : urlMementos) {
      String urlString = urlMemento.getString(URL_ATTRIBUTE);

      String author = urlMemento.getString(AUTHOR_ATTRIBUTE);
      String dateString = urlMemento.getString(DATE_ATTRIBUTE);
      String description = urlMemento.getString(DESCRIPTION_ATTRIBUTE);

      String[] tagNames = getTagNames(urlMemento);

      Date date = null;

      if (dateString != null) {
        try {
          date = SimpleDateFormat.getInstance().parse(dateString);
        } catch (ParseException e) {
          e.printStackTrace();
        }
      }

      IWaypoint waypoint =
          TagSEAPlugin.getWaypointsModel()
              .createWaypoint(URLWaypointPlugin.WAYPOINT_ID, new String[0]);

      for (String tagName : tagNames) {
        waypoint.addTag(tagName);
      }

      waypoint.setAuthor(author);
      waypoint.setDate(date);
      waypoint.setText(description);
      waypoint.setStringValue(URLWaypointUtil.URL_ATTR, urlString);
    }
  }