Example #1
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;
  }
  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;
  }
  private void saveState() {
    XMLMemento memento = XMLMemento.createWriteRoot("map");
    for (Iterator i = map.entrySet().iterator(); i.hasNext(); ) {
      Map.Entry entry = (Map.Entry) i.next();
      String workingSetId = (String) entry.getKey();
      Record record = (Record) entry.getValue();
      IPersistableElement element =
          (IPersistableElement) record.root.getAdapter(IPersistableElement.class);
      if (element == null) {
        StatusManager.getManager()
            .handle(
                new Status(
                    IStatus.ERROR,
                    Activator.PLUGIN_ID,
                    "could not persist root element for dynamic resource working set.  No persistable element adapter found."));
      }

      IMemento child = memento.createChild("workingSet", workingSetId);
      child.putString("pattern", record.pattern.pattern());

      IMemento rootItem = memento.createChild("root");
      rootItem.putString("factoryID", element.getFactoryId());
      element.saveState(rootItem);
    }
    StringWriter result = new StringWriter();
    try {
      memento.save(result);
      Activator.getInstance().getPreferenceStore().setValue("expressionMemento", result.toString());
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
 /**
  * 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;
 }
  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();
  }
Example #6
0
  /*
   * @see org.eclipse.debug.internal.ui.viewers.model.provisional.IElementMementoProvider#compareElements(org.eclipse.debug.internal.ui.viewers.model.provisional.IElementCompareRequest[])
   */
  @Override
  public void compareElements(IElementCompareRequest[] requests) {

    for (IElementCompareRequest request : requests) {

      Object element = request.getElement();
      IMemento memento = request.getMemento();
      String mementoName = memento.getString(MEMENTO_NAME);

      if (mementoName != null) {
        if (element instanceof IDMVMContext) {

          IDMContext dmc = ((IDMVMContext) element).getDMContext();

          if (dmc instanceof IMIExecutionDMContext) {

            String elementName =
                produceThreadElementName(
                    request.getPresentationContext().getId(), (IMIExecutionDMContext) dmc);
            request.setEqual(elementName.equals(mementoName));
          }
        }
      }
      request.done();
    }
  }
Example #7
0
  @Override
  public void init(final IViewSite site, final IMemento memento) throws PartInitException {
    super.init(site, memento);

    if (memento != null) {
      try {
        String dbpath = memento.getString(KEY_DB);
        String itempath = memento.getString(KEY_ITEM);

        if (dbpath != null && itempath != null) {
          ILocalMixedMediaDb mmdb;
          mmdb = Activator.getMediaFactory().getLocalMixedMediaDb(dbpath);
          mmdb.read();
          IMediaPicture item = mmdb.getByFile(itempath);

          if (item != null) {
            setInput(mmdb, item);
          } else {
            // TODO something with this error.
            System.err.println("Failed to restore item '" + itempath + "' from '" + dbpath + "'.");
          }
        }
      } catch (Exception e) {
        new MorriganMsgDlg(e).open();
      }

      Boolean b = memento.getBoolean(KEY_TIMER);
      if (b == null || b.booleanValue()) { // Default to true.
        startTimer();
      }
    }
  }
Example #8
0
 /** Restores the code folding state information from the given memento. */
 public void restoreCodeFolding(org.eclipse.ui.IMemento memento) {
   if (memento == null) {
     return;
   }
   org.eclipse.ui.IMemento[] annotationMementos = memento.getChildren(ANNOTATION);
   if (annotationMementos == null) {
     return;
   }
   java.util.Map<org.eclipse.jface.text.source.projection.ProjectionAnnotation, Boolean>
       collapsedStates =
           new java.util.LinkedHashMap<
               org.eclipse.jface.text.source.projection.ProjectionAnnotation, Boolean>();
   for (org.eclipse.ui.IMemento annotationMemento : annotationMementos) {
     org.eclipse.jface.text.source.projection.ProjectionAnnotation annotation =
         new org.eclipse.jface.text.source.projection.ProjectionAnnotation();
     collapsedStates.put(annotation, annotationMemento.getBoolean(IS_COLLAPSED));
     int offset = annotationMemento.getInteger(OFFSET);
     int length = annotationMemento.getInteger(LENGTH);
     org.eclipse.jface.text.Position position =
         new org.eclipse.jface.text.Position(offset, length);
     projectionAnnotationModel.addAnnotation(annotation, position);
   }
   // postset collapse state to prevent wrong displaying folding code.
   for (org.eclipse.jface.text.source.projection.ProjectionAnnotation annotation :
       collapsedStates.keySet()) {
     Boolean isCollapsed = collapsedStates.get(annotation);
     if (isCollapsed != null && isCollapsed.booleanValue()) {
       projectionAnnotationModel.collapse(annotation);
     }
   }
 }
Example #9
0
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite,
   * org.eclipse.ui.IMemento)
   */
  @Override
  public void init(final IViewSite site, final IMemento memento) throws PartInitException {
    // let the parent do its bits
    super.init(site, memento);

    final Vector<String> pendingFilenames = new Vector<String>();

    // are we showing the units column?
    if (memento != null) {
      final String scenFile = memento.getString(SCENARIO_FILE_INDEX);
      if (scenFile != null) {
        pendingFilenames.add(scenFile);
      }
      final String contFile = memento.getString(CONTROL_FILE_INDEX);
      if (contFile != null) {
        pendingFilenames.add(contFile);
      }

      // also, see if we have an auto-step size property
      final String stepSizeStr = memento.getString("StepInterval");
      if (stepSizeStr != null) {
        // and store it.
        try {
          final Double duration = MWCXMLReader.readThisDouble(stepSizeStr);
          _myPendingStepSize = new Duration(duration, Duration.MILLISECONDS);
        } catch (final ParseException pe) {
          MWC.Utilities.Errors.Trace.trace(pe);
        }
      }
    }

    // did we receive any?
    if (pendingFilenames.size() > 0)
      _myPendingFilenames = pendingFilenames.toArray(new String[] {});
  }
 @Override
 public ITargetPhone load(IMemento memento, String name) {
   String addr = memento.getString("addr");
   Integer portInt = memento.getInteger("port");
   int port = portInt == null ? -1 : portInt.intValue();
   BTTargetPhone newPhone = new BTTargetPhone(name.toCharArray(), Util.fromBase16(addr), port);
   return newPhone;
 }
  @Override
  public void saveState(IMemento memento) {
    memento.putString(ATTR_NAME, getProjectName());

    if (getSelectedConfigurationID() != null) {
      memento.putString(ATTR_CONFIG, getSelectedConfigurationID());
    }
  }
 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);
 }
Example #13
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);
    }
  }
 @Override
 public void save(IMemento memento, Object value) {
   FontStyle style = (FontStyle) value;
   if (style.getFont() != null) {
     memento.putString(FONT_NAME, style.getFont().getFamily());
     memento.putInteger(STYLE, style.getFont().getStyle());
     memento.putInteger(SIZE, style.getFont().getSize());
   }
 }
Example #15
0
 @Override
 public void saveState(IMemento memento) {
   super.saveState(memento);
   saveColumnWidths();
   memento.putInteger(KEY_DEFINITION_COLUMN_WIDTH, fColumnWidths[DEFINITION_COLUMN_INDEX]);
   memento.putInteger(KEY_LOCATION_COLUMN_WIDTH, fColumnWidths[LOCATION_COLUMN_INDEX]);
   memento.putInteger(KEY_MATCH_COLUMN_WIDTH, fColumnWidths[MATCH_COLUMN_INDEX]);
   memento.putBoolean(KEY_SHOW_ENCLOSING_DEFINITIONS, fShowEnclosingDefinitions);
 }
  /** Saves the state of the filter actions */
  public void saveState(IMemento memento) {
    fMemberFilterActionGroup.saveState(memento);

    memento.putString(TAG_SHOWINHERITED, String.valueOf(isShowInheritedMethods()));
    memento.putString(TAG_SORTBYDEFININGTYPE, String.valueOf(isShowDefiningTypes()));

    ScrollBar bar = getTable().getVerticalBar();
    int position = bar != null ? bar.getSelection() : 0;
    memento.putString(TAG_VERTICAL_SCROLL, String.valueOf(position));
  }
 /**
  * Returns the path for a given palette
  *
  * @param paletteID the unique identifier of the palette to retrieve
  * @return the path to the configuration of the palette or <code>null</code> if no customization
  *     exists for this palette configuration
  */
 public static String getPaletteRedefinition(String paletteID) {
   if (paletteID == null) {
     Activator.log.debug("Trying to find preferences for a null palette identifier");
   }
   IMemento memento = getPaletteRedefinitionNode(paletteID);
   if (memento != null) {
     return memento.getString(PATH);
   }
   return null;
 }
 @Override
 public void saveState(IMemento memento) {
   super.saveState(memento);
   memento.putInteger(DETAILS_VIEW_FLYOUT_STATE, detailsViewerFlyout.getPreferences().getState());
   memento.putInteger(
       PATTERNS_VIEWER_FLYOUT_STATE, patternsViewerFlyout.getPreferences().getState());
   memento.putString(
       PACKAGE_PRESENTATION_STATE,
       (patternsTreeViewer.getContentProvider() == flatCP) ? "flat" : "hierarchical");
 }
 /**
  * search the palette memento for the given palette ID.
  *
  * @param rootMemento the root memento to look in
  * @param paletteID the palette ID to search
  * @return the palette memento or <code>null</code> if none was found.
  */
 protected static IMemento searchPaletteMemento(XMLMemento rootMemento, String paletteID) {
   for (IMemento memento : rootMemento.getChildren(PALETTE)) {
     String id = memento.getString(ID);
     if (paletteID.equals(id)) {
       return memento;
     }
   }
   // palette not found
   return null;
 }
  public void testPreferenceMigration() throws Exception {
    final TaskListSorter sorter = new TaskListSorter();
    TaskListView view = new TaskListView();
    XMLMemento memento = XMLMemento.createWriteRoot(MEMENTO_KEY_SORT_INDEX);
    IMemento child = memento.createChild(MEMENTO_KEY_SORTER);
    child.putInteger(MEMENTO_KEY_SORT_INDEX, 0);
    child.putInteger(MEMENTO_KEY_SORT_DIRECTION, 1);
    child = memento.createChild(MEMENTO_KEY_SORTER2);
    child.putInteger(MEMENTO_KEY_SORT_INDEX, 1);
    child.putInteger(MEMENTO_KEY_SORT_DIRECTION, -1);
    view.migrateSorterState(sorter, memento);
    assertEquals(
        SortCriterion.SortKey.PRIORITY, sorter.getComparator().getSortCriterion(0).getKey());
    assertEquals(1, sorter.getComparator().getSortCriterion(0).getDirection());
    assertEquals(
        SortCriterion.SortKey.SUMMARY, sorter.getComparator().getSortCriterion(1).getKey());
    assertEquals(-1, sorter.getComparator().getSortCriterion(1).getDirection());

    memento = XMLMemento.createWriteRoot(MEMENTO_KEY_SORT_INDEX);
    child = memento.createChild(MEMENTO_KEY_SORTER);
    child.putInteger(MEMENTO_KEY_SORT_INDEX, 3);
    child.putInteger(MEMENTO_KEY_SORT_DIRECTION, -1);
    child = memento.createChild(MEMENTO_KEY_SORTER2);
    child.putInteger(MEMENTO_KEY_SORT_INDEX, 2);
    child.putInteger(MEMENTO_KEY_SORT_DIRECTION, -1);
    view.migrateSorterState(sorter, memento);
    assertEquals(
        SortCriterion.SortKey.TASK_ID, sorter.getComparator().getSortCriterion(0).getKey());
    assertEquals(-1, sorter.getComparator().getSortCriterion(0).getDirection());
    assertEquals(
        SortCriterion.SortKey.DATE_CREATED, sorter.getComparator().getSortCriterion(1).getKey());
    assertEquals(-1, sorter.getComparator().getSortCriterion(1).getDirection());
  }
Example #21
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());
      }
    }
  }
Example #22
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);
   }
 }
Example #23
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);
   }
 }
 /**
  * A shortcut for:
  *
  * <pre>
  * fromMemento(clazz, memento.getChild(childName))
  * </pre>
  *
  * verifying precondition that only one child of a given name exists.
  */
 static <T> T fromMemento(Class<T> clazz, IMemento memento, String childName) throws IOException {
   final IMemento[] children = memento.getChildren(childName);
   if (children.length != 1) {
     throw new IOException(
         "Expected a single node named '"
             + childName
             + "' under memento '"
             + memento.getType()
             + "'.");
   }
   return fromMemento(clazz, children[0]);
 }
Example #25
0
  @Override
  public void saveState(final IMemento memento) {
    super.saveState(memento);

    memento.putBoolean(KEY_TIMER, isTimerEnabled());

    if (this.editedItemDb != null
        && this.editedItemDb.getType().equals(MediaListType.LOCALMMDB.toString())) {
      memento.putString(KEY_DB, this.editedItemDb.getDbPath());
      memento.putString(KEY_ITEM, this.editedItem.getFilepath());
    }
  }
Example #26
0
  private static String[] getTagNames(IMemento urlMemento) {
    IMemento[] tagMementos = urlMemento.getChildren(TAG);
    List<String> tags = new ArrayList<String>();

    for (IMemento tagMemento : tagMementos) {
      String tagName = tagMemento.getString(NAME_ATTRIBUTE);

      if (tagName != null) tags.add(tagName);
    }

    String[] array = new String[0];
    return tags.toArray(array);
  }
Example #27
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());
    }
  }
 /**
  * Returns the memento associated to the palette, or <code>null</code> if none exists
  *
  * @param paletteID the identifier of the palette to find
  * @return the memento found or <code>null</code> if no customization exists for this palette
  */
 private static IMemento getPaletteRedefinitionNode(String paletteID) {
   XMLMemento rootMemento = getLocalRedefinitions();
   IMemento[] redefinitions = rootMemento.getChildren(PALETTE_REDEFINITION);
   for (IMemento redefinitionMemento : redefinitions) {
     String paletteNodeID = redefinitionMemento.getString(ID);
     // check equals. Palette ID is not null, as checked at the begining
     // of the method.
     if (paletteID.equals(paletteNodeID)) {
       return redefinitionMemento;
     }
   }
   return null;
 }
 @Override
 public void loadSettings(IMemento memento) {
   String modifier = memento.getString(TAG_CONTAINS_MODIFIER);
   if (modifier == null) {
     return;
   }
   String contains = memento.getString(TAG_CONTAINS_TEXT);
   if (contains == null) {
     return;
   }
   containsText = contains;
   containsModifier = modifier;
 }
Example #30
0
 /** Load all monitors from persistent storage. */
 private void loadMonitors() {
   try {
     FileReader reader = new FileReader(getSaveLocation());
     IMemento memento = XMLMemento.createReadRoot(reader);
     IMemento[] monitorsMemento = memento.getChildren(MONITOR_ID_ATTR);
     for (IMemento monitorMemento : monitorsMemento) {
       loadMonitor(monitorMemento);
     }
   } catch (FileNotFoundException e) {
     LMLMonitorCorePlugin.log(e.getLocalizedMessage());
   } catch (WorkbenchException e) {
     LMLMonitorCorePlugin.log(e.getLocalizedMessage());
   }
 }