Java 类org.eclipse.ui.XMLMemento 实例源码

项目:eZooKeeper    文件:JmxConnectionDescriptorFiles.java   
@Override
public void toXml(JmxConnectionDescriptor connectionDescriptor, XMLMemento memento) {

    memento.putString(XML_TAG_JMX_URL, String.valueOf(connectionDescriptor.getJmxServiceUrl()));

    String userName = connectionDescriptor.getUserName();
    if (userName != null) {
        memento.putString(XML_TAG_USER_NAME, userName);
    }

    String password = connectionDescriptor.getPassword();
    if (password != null) {
        memento.putString(XML_TAG_PASSWORD, password);
    }

}
项目:DarwinSPL    文件:DwprofileCodeFoldingManager.java   
/**
 * <p>
 * Restores the code folding state from a XML file in the state location.
 * </p>
 * 
 * @param uriString the key to determine the file to load the state from
 */
public void restoreCodeFoldingStateFromFile(String uriString) {
    final File stateFile = getCodeFoldingStateFile(uriString);
    if (stateFile == null || !stateFile.exists()) {
        calculatePositions();
        return;
    }
    SafeRunner.run(new SafeRunnable("Unable to read code folding state. The state will be reset.") {
        public void run() throws Exception {
            FileInputStream input = new FileInputStream(stateFile);
            BufferedReader reader = new BufferedReader(new InputStreamReader(input, "utf-8"));
            IMemento memento = XMLMemento.createReadRoot(reader);
            reader.close();
            String sourceText = sourceViewer.getDocument().get();
            if (memento.getString(VERIFY_KEY).equals(makeMD5(sourceText))) {
                restoreCodeFolding(memento);
            } else {
                calculatePositions();
            }
        }
    });
}
项目:DarwinSPL    文件:DwprofileCodeFoldingManager.java   
/**
 * <p>
 * Saves the code folding state to a XML file in the state location.
 * </p>
 * 
 * @param uriString the key to determine the file to save to
 */
public void saveCodeFoldingStateFile(String uriString) {
    IDocument document = sourceViewer.getDocument();
    if (document == null) {
        return;
    }
    XMLMemento codeFoldingMemento = XMLMemento.createWriteRoot(MODEL);
    codeFoldingMemento.putString(VERIFY_KEY, makeMD5(document.get()));
    saveCodeFolding(codeFoldingMemento);
    File stateFile = getCodeFoldingStateFile(uriString);
    if (stateFile == null) {
        return;
    }
    try {
        FileOutputStream stream = new FileOutputStream(stateFile);
        OutputStreamWriter writer = new OutputStreamWriter(stream, "utf-8");
        codeFoldingMemento.save(writer);
        writer.close();
    } catch (IOException e) {
        stateFile.delete();
        MessageDialog.openError((Shell) null, "Saving Problems", "Unable to save code folding state.");
    }
}
项目:DarwinSPL    文件:HyexpressionCodeFoldingManager.java   
/**
 * <p>
 * Restores the code folding state from a XML file in the state location.
 * </p>
 * 
 * @param uriString the key to determine the file to load the state from
 */
public void restoreCodeFoldingStateFromFile(String uriString) {
    final File stateFile = getCodeFoldingStateFile(uriString);
    if (stateFile == null || !stateFile.exists()) {
        calculatePositions();
        return;
    }
    SafeRunner.run(new SafeRunnable("Unable to read code folding state. The state will be reset.") {
        public void run() throws Exception {
            FileInputStream input = new FileInputStream(stateFile);
            BufferedReader reader = new BufferedReader(new InputStreamReader(input, "utf-8"));
            IMemento memento = XMLMemento.createReadRoot(reader);
            reader.close();
            String sourceText = sourceViewer.getDocument().get();
            if (memento.getString(VERIFY_KEY).equals(makeMD5(sourceText))) {
                restoreCodeFolding(memento);
            } else {
                calculatePositions();
            }
        }
    });
}
项目:DarwinSPL    文件:HyexpressionCodeFoldingManager.java   
/**
 * <p>
 * Saves the code folding state to a XML file in the state location.
 * </p>
 * 
 * @param uriString the key to determine the file to save to
 */
public void saveCodeFoldingStateFile(String uriString) {
    IDocument document = sourceViewer.getDocument();
    if (document == null) {
        return;
    }
    XMLMemento codeFoldingMemento = XMLMemento.createWriteRoot(MODEL);
    codeFoldingMemento.putString(VERIFY_KEY, makeMD5(document.get()));
    saveCodeFolding(codeFoldingMemento);
    File stateFile = getCodeFoldingStateFile(uriString);
    if (stateFile == null) {
        return;
    }
    try {
        FileOutputStream stream = new FileOutputStream(stateFile);
        OutputStreamWriter writer = new OutputStreamWriter(stream, "utf-8");
        codeFoldingMemento.save(writer);
        writer.close();
    } catch (IOException e) {
        stateFile.delete();
        MessageDialog.openError((Shell) null, "Saving Problems", "Unable to save code folding state.");
    }
}
项目:DarwinSPL    文件:HyvalidityformulaCodeFoldingManager.java   
/**
 * <p>
 * Restores the code folding state from a XML file in the state location.
 * </p>
 * 
 * @param uriString the key to determine the file to load the state from
 */
public void restoreCodeFoldingStateFromFile(String uriString) {
    final File stateFile = getCodeFoldingStateFile(uriString);
    if (stateFile == null || !stateFile.exists()) {
        calculatePositions();
        return;
    }
    SafeRunner.run(new SafeRunnable("Unable to read code folding state. The state will be reset.") {
        public void run() throws Exception {
            FileInputStream input = new FileInputStream(stateFile);
            BufferedReader reader = new BufferedReader(new InputStreamReader(input, "utf-8"));
            IMemento memento = XMLMemento.createReadRoot(reader);
            reader.close();
            String sourceText = sourceViewer.getDocument().get();
            if (memento.getString(VERIFY_KEY).equals(makeMD5(sourceText))) {
                restoreCodeFolding(memento);
            } else {
                calculatePositions();
            }
        }
    });
}
项目:DarwinSPL    文件:HyvalidityformulaCodeFoldingManager.java   
/**
 * <p>
 * Saves the code folding state to a XML file in the state location.
 * </p>
 * 
 * @param uriString the key to determine the file to save to
 */
public void saveCodeFoldingStateFile(String uriString) {
    IDocument document = sourceViewer.getDocument();
    if (document == null) {
        return;
    }
    XMLMemento codeFoldingMemento = XMLMemento.createWriteRoot(MODEL);
    codeFoldingMemento.putString(VERIFY_KEY, makeMD5(document.get()));
    saveCodeFolding(codeFoldingMemento);
    File stateFile = getCodeFoldingStateFile(uriString);
    if (stateFile == null) {
        return;
    }
    try {
        FileOutputStream stream = new FileOutputStream(stateFile);
        OutputStreamWriter writer = new OutputStreamWriter(stream, "utf-8");
        codeFoldingMemento.save(writer);
        writer.close();
    } catch (IOException e) {
        stateFile.delete();
        MessageDialog.openError((Shell) null, "Saving Problems", "Unable to save code folding state.");
    }
}
项目:DarwinSPL    文件:HydatavalueCodeFoldingManager.java   
/**
 * <p>
 * Restores the code folding state from a XML file in the state location.
 * </p>
 * 
 * @param uriString the key to determine the file to load the state from
 */
public void restoreCodeFoldingStateFromFile(String uriString) {
    final File stateFile = getCodeFoldingStateFile(uriString);
    if (stateFile == null || !stateFile.exists()) {
        calculatePositions();
        return;
    }
    SafeRunner.run(new SafeRunnable("Unable to read code folding state. The state will be reset.") {
        public void run() throws Exception {
            FileInputStream input = new FileInputStream(stateFile);
            BufferedReader reader = new BufferedReader(new InputStreamReader(input, "utf-8"));
            IMemento memento = XMLMemento.createReadRoot(reader);
            reader.close();
            String sourceText = sourceViewer.getDocument().get();
            if (memento.getString(VERIFY_KEY).equals(makeMD5(sourceText))) {
                restoreCodeFolding(memento);
            } else {
                calculatePositions();
            }
        }
    });
}
项目:DarwinSPL    文件:HydatavalueCodeFoldingManager.java   
/**
 * <p>
 * Saves the code folding state to a XML file in the state location.
 * </p>
 * 
 * @param uriString the key to determine the file to save to
 */
public void saveCodeFoldingStateFile(String uriString) {
    IDocument document = sourceViewer.getDocument();
    if (document == null) {
        return;
    }
    XMLMemento codeFoldingMemento = XMLMemento.createWriteRoot(MODEL);
    codeFoldingMemento.putString(VERIFY_KEY, makeMD5(document.get()));
    saveCodeFolding(codeFoldingMemento);
    File stateFile = getCodeFoldingStateFile(uriString);
    if (stateFile == null) {
        return;
    }
    try {
        FileOutputStream stream = new FileOutputStream(stateFile);
        OutputStreamWriter writer = new OutputStreamWriter(stream, "utf-8");
        codeFoldingMemento.save(writer);
        writer.close();
    } catch (IOException e) {
        stateFile.delete();
        MessageDialog.openError((Shell) null, "Saving Problems", "Unable to save code folding state.");
    }
}
项目:DarwinSPL    文件:HymappingCodeFoldingManager.java   
/**
 * <p>
 * Restores the code folding state from a XML file in the state location.
 * </p>
 * 
 * @param uriString the key to determine the file to load the state from
 */
public void restoreCodeFoldingStateFromFile(String uriString) {
    final File stateFile = getCodeFoldingStateFile(uriString);
    if (stateFile == null || !stateFile.exists()) {
        calculatePositions();
        return;
    }
    SafeRunner.run(new SafeRunnable("Unable to read code folding state. The state will be reset.") {
        public void run() throws Exception {
            FileInputStream input = new FileInputStream(stateFile);
            BufferedReader reader = new BufferedReader(new InputStreamReader(input, "utf-8"));
            IMemento memento = XMLMemento.createReadRoot(reader);
            reader.close();
            String sourceText = sourceViewer.getDocument().get();
            if (memento.getString(VERIFY_KEY).equals(makeMD5(sourceText))) {
                restoreCodeFolding(memento);
            } else {
                calculatePositions();
            }
        }
    });
}
项目:DarwinSPL    文件:HymappingCodeFoldingManager.java   
/**
 * <p>
 * Saves the code folding state to a XML file in the state location.
 * </p>
 * 
 * @param uriString the key to determine the file to save to
 */
public void saveCodeFoldingStateFile(String uriString) {
    IDocument document = sourceViewer.getDocument();
    if (document == null) {
        return;
    }
    XMLMemento codeFoldingMemento = XMLMemento.createWriteRoot(MODEL);
    codeFoldingMemento.putString(VERIFY_KEY, makeMD5(document.get()));
    saveCodeFolding(codeFoldingMemento);
    File stateFile = getCodeFoldingStateFile(uriString);
    if (stateFile == null) {
        return;
    }
    try {
        FileOutputStream stream = new FileOutputStream(stateFile);
        OutputStreamWriter writer = new OutputStreamWriter(stream, "utf-8");
        codeFoldingMemento.save(writer);
        writer.close();
    } catch (IOException e) {
        stateFile.delete();
        MessageDialog.openError((Shell) null, "Saving Problems", "Unable to save code folding state.");
    }
}
项目:DarwinSPL    文件:HyconstraintsCodeFoldingManager.java   
/**
 * <p>
 * Restores the code folding state from a XML file in the state location.
 * </p>
 * 
 * @param uriString the key to determine the file to load the state from
 */
public void restoreCodeFoldingStateFromFile(String uriString) {
    final File stateFile = getCodeFoldingStateFile(uriString);
    if (stateFile == null || !stateFile.exists()) {
        calculatePositions();
        return;
    }
    SafeRunner.run(new SafeRunnable("Unable to read code folding state. The state will be reset.") {
        public void run() throws Exception {
            FileInputStream input = new FileInputStream(stateFile);
            BufferedReader reader = new BufferedReader(new InputStreamReader(input, "utf-8"));
            IMemento memento = XMLMemento.createReadRoot(reader);
            reader.close();
            String sourceText = sourceViewer.getDocument().get();
            if (memento.getString(VERIFY_KEY).equals(makeMD5(sourceText))) {
                restoreCodeFolding(memento);
            } else {
                calculatePositions();
            }
        }
    });
}
项目:DarwinSPL    文件:HyconstraintsCodeFoldingManager.java   
/**
 * <p>
 * Saves the code folding state to a XML file in the state location.
 * </p>
 * 
 * @param uriString the key to determine the file to save to
 */
public void saveCodeFoldingStateFile(String uriString) {
    IDocument document = sourceViewer.getDocument();
    if (document == null) {
        return;
    }
    XMLMemento codeFoldingMemento = XMLMemento.createWriteRoot(MODEL);
    codeFoldingMemento.putString(VERIFY_KEY, makeMD5(document.get()));
    saveCodeFolding(codeFoldingMemento);
    File stateFile = getCodeFoldingStateFile(uriString);
    if (stateFile == null) {
        return;
    }
    try {
        FileOutputStream stream = new FileOutputStream(stateFile);
        OutputStreamWriter writer = new OutputStreamWriter(stream, "utf-8");
        codeFoldingMemento.save(writer);
        writer.close();
    } catch (IOException e) {
        stateFile.delete();
        MessageDialog.openError((Shell) null, "Saving Problems", "Unable to save code folding state.");
    }
}
项目:DarwinSPL    文件:HymanifestCodeFoldingManager.java   
/**
 * <p>
 * Restores the code folding state from a XML file in the state location.
 * </p>
 * 
 * @param uriString the key to determine the file to load the state from
 */
public void restoreCodeFoldingStateFromFile(String uriString) {
    final File stateFile = getCodeFoldingStateFile(uriString);
    if (stateFile == null || !stateFile.exists()) {
        calculatePositions();
        return;
    }
    SafeRunner.run(new SafeRunnable("Unable to read code folding state. The state will be reset.") {
        public void run() throws Exception {
            FileInputStream input = new FileInputStream(stateFile);
            BufferedReader reader = new BufferedReader(new InputStreamReader(input, "utf-8"));
            IMemento memento = XMLMemento.createReadRoot(reader);
            reader.close();
            String sourceText = sourceViewer.getDocument().get();
            if (memento.getString(VERIFY_KEY).equals(makeMD5(sourceText))) {
                restoreCodeFolding(memento);
            } else {
                calculatePositions();
            }
        }
    });
}
项目:DarwinSPL    文件:HymanifestCodeFoldingManager.java   
/**
 * <p>
 * Saves the code folding state to a XML file in the state location.
 * </p>
 * 
 * @param uriString the key to determine the file to save to
 */
public void saveCodeFoldingStateFile(String uriString) {
    IDocument document = sourceViewer.getDocument();
    if (document == null) {
        return;
    }
    XMLMemento codeFoldingMemento = XMLMemento.createWriteRoot(MODEL);
    codeFoldingMemento.putString(VERIFY_KEY, makeMD5(document.get()));
    saveCodeFolding(codeFoldingMemento);
    File stateFile = getCodeFoldingStateFile(uriString);
    if (stateFile == null) {
        return;
    }
    try {
        FileOutputStream stream = new FileOutputStream(stateFile);
        OutputStreamWriter writer = new OutputStreamWriter(stream, "utf-8");
        codeFoldingMemento.save(writer);
        writer.close();
    } catch (IOException e) {
        stateFile.delete();
        MessageDialog.openError((Shell) null, "Saving Problems", "Unable to save code folding state.");
    }
}
项目:tlaplus    文件:FilteredItemsSelectionDialog.java   
/**
 * Stores dialog settings.
 *
 * @param settings
 *            settings used to store dialog
 */
protected void storeDialog(IDialogSettings settings) {
    settings.put(SHOW_STATUS_LINE, toggleStatusLineAction.isChecked());

    XMLMemento memento = XMLMemento.createWriteRoot(HISTORY_SETTINGS);
    this.contentProvider.saveHistory(memento);
    StringWriter writer = new StringWriter();
    try {
        memento.save(writer);
        settings.put(HISTORY_SETTINGS, writer.getBuffer().toString());
    } catch (IOException e) {
        // Simply don't store the settings
        StatusManager
                .getManager()
                .handle(
                        new Status(
                                IStatus.ERROR,
                                PlatformUI.PLUGIN_ID,
                                IStatus.ERROR,
                                WorkbenchMessages.FilteredItemsSelectionDialog_storeError,
                                e));
    }
}
项目:tlaplus    文件:FilteredItemsSelectionDialog.java   
/**
 * Load history elements from memento.
 *
 * @param memento
 *            memento from which the history will be retrieved
 */
public void load(IMemento memento) {

    XMLMemento historyMemento = (XMLMemento) memento
            .getChild(rootNodeName);

    if (historyMemento == null) {
        return;
    }

    IMemento[] mementoElements = historyMemento
            .getChildren(infoNodeName);
    for (int i = 0; i < mementoElements.length; ++i) {
        IMemento mementoElement = mementoElements[i];
        Object object = restoreItemFromMemento(mementoElement);
        if (object != null) {
            historyList.add(object);
        }
    }
}
项目:jsbuild-eclipse    文件:JSBuildFileView.java   
@Override
public void init(IViewSite site, IMemento memento) throws PartInitException {
    super.init(site, memento);
    String persistedMemento = JSBuildFileUIPlugin.getDefault()
            .getDialogSettingsSection(getClass().getName()).get("memento"); //$NON-NLS-1$
    if (persistedMemento != null) {
        try {
            memento = XMLMemento.createReadRoot(new StringReader(
                    persistedMemento));
        } catch (WorkbenchException e) {
            // don't do anything. Simply don't restore the settings
        }
    }
    if (memento != null) {
        restoreViewerInput(memento);
        /*
         * IMemento child = memento.getChild(TAG_FILTER_INTERNAL_TARGETS);
         * if (child != null) { filterInternalTargets =
         * Boolean.valueOf(child.getString(KEY_VALUE)).booleanValue(); }
         */
    }
}
项目:gerrit-tools    文件:BranchProjectTracker.java   
/**
 * Associate projects with branch. The specified memento must the one
 * previously returned from a call to {@link #snapshot()}.
 *
 * @see #snapshot()
 * @param memento
 * @return this tracker
 */
public BranchProjectTracker save(final IMemento memento) {
    if (!(memento instanceof XMLMemento))
        throw new IllegalArgumentException("Invalid memento"); //$NON-NLS-1$

    String branch = memento.getString(KEY_BRANCH);
    IPreferenceStore store = Activator.getDefault().getPreferenceStore();
    String pref = getPreference(branch);
    StringWriter writer = new StringWriter();
    try {
        ((XMLMemento) memento).save(writer);
        store.setValue(pref, writer.toString());
    } catch (IOException e) {
        Activator.logError("Error writing branch-project associations", e); //$NON-NLS-1$
    }
    return this;
}
项目:gerrit-tools    文件:BranchProjectTracker.java   
/**
 * Load the project paths associated with the given branch. These paths will
 * be relative to the repository root.
 *
 * @param branch
 * @return non-null but possibly empty array of projects
 */
public String[] getProjectPaths(final String branch) {
    String pref = getPreference(branch);
    String value = Activator.getDefault().getPreferenceStore()
            .getString(pref);
    if (value.length() == 0)
        return new String[0];
    XMLMemento memento;
    try {
        memento = XMLMemento.createReadRoot(new StringReader(value));
    } catch (WorkbenchException e) {
        Activator.logError("Error reading branch-project associations", e); //$NON-NLS-1$
        return new String[0];
    }
    IMemento[] children = memento.getChildren(KEY_PROJECT);
    if (children.length == 0)
        return new String[0];
    List<String> projects = new ArrayList<String>(children.length);
    for (int i = 0; i < children.length; i++) {
        String path = children[i].getTextData();
        if (path != null && path.length() > 0)
            projects.add(path);
    }
    return projects.toArray(new String[projects.size()]);
}
项目:org.csstudio.display.builder    文件:RuntimeViewPart.java   
/** Persist the view's input "on demand".
    *
    *  <p>Framework only persists to memento on exit,
    *  and only for the currently visible views.
    *
    *  <p>Display info for views in other perspectives
    *  which are hidden on application shutdown will be lost.
    *  By forcing a persist for each view while the app is still running,
    *  each view can be restored when a perspective is later re-activated.
    *
    *
    *  <p>Memento is saved in the
    *  .metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi
    *  inside a "persistedState" element of the E4 model element.
    *
    *  <p>This method places it in the model just as the framework
    *  does by calling saveState() on shutdown,
    *  but allows saving the state at any time.
    */
private void persist()
{
       try
       {
           // Obtain E4 model element for E3 view,
           // based on http://www.vogella.com/tutorials/EclipsePlugIn/article.html#eclipsecontext
           final IEclipseContext context = getViewSite().getService(IEclipseContext.class);
           final MPart part = context.get(MPart.class);

           // Based on org.eclipse.ui.internal.ViewReference#persist():
           //
           // XML version of memento is written to E4 model.
           // If compatibility layer changes its memento persistence,
           // this will break...
           final XMLMemento root = XMLMemento.createWriteRoot("view"); //$NON-NLS-1$
           saveState(root);
           final StringWriter writer = new StringWriter();
           root.save(writer);
           part.getPersistedState().put(TAG_MEMENTO, writer.toString());
       }
       catch (Exception ex)
       {
           logger.log(Level.WARNING, "Cannot persist " + display_info, ex);
       }
}
项目:gwt-eclipse-plugin    文件:CompilationUnitResourceDependencyIndex.java   
public void saveIndex() {
  XMLMemento memento = XMLMemento.createWriteRoot(TAG_ROOT);
  persistIndex(memento);

  File indexFile = getIndexFile();
  FileWriter writer = null;
  try {
    try {
      writer = new FileWriter(indexFile);
      memento.save(writer);
    } finally {
      if (writer != null) {
        writer.close();
      }
    }
  } catch (IOException e) {
    CorePluginLog.logError(e, "Error saving index " + indexName);

    // Make sure we remove any partially-written file
    if (indexFile.exists()) {
      indexFile.delete();
    }
  }
}
项目:gwt-eclipse-plugin    文件:JavaRefIndex.java   
private void saveIndex() {
  XMLMemento memento = XMLMemento.createWriteRoot(TAG_JAVA_REFS);
  saveIndex(memento);

  FileWriter writer = null;
  try {
    try {
      writer = new FileWriter(getIndexFile());
      memento.save(writer);
    } finally {
      if (writer != null) {
        writer.close();
      }
    }
  } catch (IOException e) {
    GWTPluginLog.logError(e, "Error saving search index");
  }
}
项目:gwt-eclipse-plugin    文件:JavaRefIndex.java   
private void saveIndex(XMLMemento memento) {
  for (Entry<IPath, Set<IIndexedJavaRef>> fileEntry : fileIndex.entrySet()) {
    for (IIndexedJavaRef ref : fileEntry.getValue()) {
      IMemento refNode = memento.createChild(TAG_JAVA_REF);
      /*
       * Embed the Java reference class name into the index. This ends up
       * making the resulting index file larger than it really needs to be
       * (around 100 KB for the index containing gwt-user, gwt-lang, and all
       * the gwt-dev projects), but it still loads in around 50 ms on average
       * on my system, so it doesn't seem to be a bottleneck.
       */
      String refClassName = ref.getClass().getName();
      refNode.putString(TAG_JAVA_REF_CLASS, refClassName);

      // The implementation of IIndexedJavaRef serializes itself
      ref.save(refNode);
    }
  }
}
项目:skin4eclipse    文件:TemporaryEditingSession.java   
protected IMemento createMemento() {
    Reader reader;
    IMemento mem = null;
    try {
        String content = getClipboardContent();
        if (content == null) {
            return null;
        }
        if (!content.startsWith("<?xml")) {
            return null;
        }
        reader = new StringReader(content);
        mem = XMLMemento.createReadRoot(reader);
    } catch (CoreException e) {
        PresentationPlugin.log("Couldn't restore session " + getName(), e);
        return mem;
    }
    return mem;
}
项目:mytourbook    文件:Map3Manager.java   
private static XMLMemento createLayerXml_100_WriteRoot() {

        final XMLMemento xmlRoot = XMLMemento.createWriteRoot(TAG_ROOT);

        // date/time
        xmlRoot.putString(Util.ATTR_ROOT_DATETIME, TimeTools.now().toString());

        // plugin version
        final Version version = _bundle.getVersion();
        xmlRoot.putInteger(Util.ATTR_ROOT_VERSION_MAJOR, version.getMajor());
        xmlRoot.putInteger(Util.ATTR_ROOT_VERSION_MINOR, version.getMinor());
        xmlRoot.putInteger(Util.ATTR_ROOT_VERSION_MICRO, version.getMicro());
        xmlRoot.putString(Util.ATTR_ROOT_VERSION_QUALIFIER, version.getQualifier());

        // layer structure version
        xmlRoot.putInteger(ATTR_MAP3_LAYER_VERSION, MAP3_LAYER_STRUCTURE_VERSION);

        return xmlRoot;
    }
项目:mytourbook    文件:TourTrackConfigManager.java   
private static XMLMemento create_Root() {

        final XMLMemento xmlRoot = XMLMemento.createWriteRoot(TAG_ROOT);

        // date/time
        xmlRoot.putString(Util.ATTR_ROOT_DATETIME, TimeTools.now().toString());

        // plugin version
        final Version version = _bundle.getVersion();
        xmlRoot.putInteger(Util.ATTR_ROOT_VERSION_MAJOR, version.getMajor());
        xmlRoot.putInteger(Util.ATTR_ROOT_VERSION_MINOR, version.getMinor());
        xmlRoot.putInteger(Util.ATTR_ROOT_VERSION_MICRO, version.getMicro());
        xmlRoot.putString(Util.ATTR_ROOT_VERSION_QUALIFIER, version.getQualifier());

        // config version
        xmlRoot.putInteger(ATTR_CONFIG_VERSION, TOUR_TRACK_CONFIG_VERSION);

        return xmlRoot;
    }
项目:mytourbook    文件:TourTrackConfigManager.java   
private static void parse_100_ConfigAttr(final XMLMemento xmlConfig, final TourTrackConfig config) {

        config.id = Util.getXmlString(xmlConfig,//
                ATTR_ID,
                Long.toString(System.nanoTime()));

        config.defaultId = Util.getXmlString(xmlConfig,//
                ATTR_DEFAULT_ID,
                DEFAULT_ID_DEFAULT);

        config.name = Util.getXmlString(xmlConfig,//
                ATTR_CONFIG_NAME,
                CONFIG_NAME_UNKNOWN);

        config.isFollowTerrain = Util.getXmlBoolean(xmlConfig, //
                ATTR_IS_FOLLOW_TERRAIN,
                CONFIG_IS_FOLLOW_TERRAIN_DEFAULT);

        config.trackColorOpacity = Util.getXmlFloatInt(
                xmlConfig,
                ATTR_TRACK_COLOR_OPACITY_DEFAULT,
                Map3GradientColorManager.OPACITY_DEFAULT,
                Map3GradientColorManager.OPACITY_MIN,
                Map3GradientColorManager.OPACITY_MAX);
    }
项目:mytourbook    文件:TourTrackConfigManager.java   
private static void parse_200_DirectionArrows(final XMLMemento xmlDirectionArrow, final TourTrackConfig config) {

        config.isShowDirectionArrows = Util.getXmlBoolean(xmlDirectionArrow,//
                ATTR_IS_VISIBLE,
                IS_DIRECTION_ARROWS_VISIBLE_DEFAULT);

        config.directionArrowSize = Util.getXmlFloatInt(xmlDirectionArrow,//
                ATTR_DIRECTION_ARROW_SIZE,
                DIRECTION_ARROW_SIZE_DEFAULT,
                DIRECTION_ARROW_SIZE_MIN,
                DIRECTION_ARROW_SIZE_MAX);

        config.directionArrowDistance = Util.getXmlFloatInt(xmlDirectionArrow,//
                ATTR_VERTICAL_DISTANCE,
                DIRECTION_ARROW_VERTICAL_DISTANCE_DEFAULT,
                DIRECTION_ARROW_VERTICAL_DISTANCE_MIN,
                DIRECTION_ARROW_VERTICAL_DISTANCE_MAX);
    }
项目:mytourbook    文件:TourTrackConfigManager.java   
private static void parse_330__Opacity(final XMLMemento xmlOpacity, final TourTrackConfig trackConfig) {

        trackConfig.outlineOpacity = Util.getXmlFloatInt(xmlOpacity,//
                ATTR_NORMAL,
                OUTLINE_OPACITY_NORMAL_DEFAULT,
                Map3GradientColorManager.OPACITY_MIN,
                Map3GradientColorManager.OPACITY_MAX);

        trackConfig.outlineOpacity_Hovered = Util.getXmlFloatInt(xmlOpacity,//
                ATTR_HOVERED,
                OUTLINE_OPACITY_HOVERED_DEFAULT,
                Map3GradientColorManager.OPACITY_MIN,
                Map3GradientColorManager.OPACITY_MAX);

        trackConfig.outlineOpacity_Selected = Util.getXmlFloatInt(xmlOpacity,//
                ATTR_SELECTED,
                OUTLINE_OPACITY_SELECTED_DEFAULT,
                Map3GradientColorManager.OPACITY_MIN,
                Map3GradientColorManager.OPACITY_MAX);

        trackConfig.outlineOpacity_HovSel = Util.getXmlFloatInt(xmlOpacity,//
                ATTR_HOV_AND_SEL,
                OUTLINE_OPACITY_HOV_SEL_DEFAULT,
                Map3GradientColorManager.OPACITY_MIN,
                Map3GradientColorManager.OPACITY_MAX);
    }
项目:mytourbook    文件:TourTrackConfigManager.java   
private static void parse_410__ColorMode(final XMLMemento xmlColorMode, final TourTrackConfig config) {

        config.interiorColorMode = Util.getXmlInteger(xmlColorMode,//
                ATTR_NORMAL,
                INTERIOR_COLOR_MODE_NORMAL_DEFAULT);

        config.interiorColorMode_Hovered = Util.getXmlInteger(xmlColorMode,//
                ATTR_HOVERED,
                INTERIOR_COLOR_MODE_HOVERED_DEFAULT);

        config.interiorColorMode_Selected = Util.getXmlInteger(xmlColorMode,//
                ATTR_SELECTED,
                INTERIOR_COLOR_MODE_SELECTED_DEFAULT);

        config.interiorColorMode_HovSel = Util.getXmlInteger(xmlColorMode,//
                ATTR_HOV_AND_SEL,
                INTERIOR_COLOR_MODE_HOV_SEL_DEFAULT);
    }
项目:mytourbook    文件:TourTrackConfigManager.java   
private static void parse_430__Opacity(final XMLMemento xmlOpacity, final TourTrackConfig config) {

        config.interiorOpacity = Util.getXmlFloatInt(xmlOpacity,//
                ATTR_NORMAL,
                INTERIOR_OPACITY_NORMAL_DEFAULT,
                Map3GradientColorManager.OPACITY_MIN,
                Map3GradientColorManager.OPACITY_MAX);

        config.interiorOpacity_Hovered = Util.getXmlFloatInt(xmlOpacity,//
                ATTR_HOVERED,
                INTERIOR_OPACITY_HOVERED_DEFAULT,
                Map3GradientColorManager.OPACITY_MIN,
                Map3GradientColorManager.OPACITY_MAX);

        config.interiorOpacity_Selected = Util.getXmlFloatInt(xmlOpacity,//
                ATTR_SELECTED,
                INTERIOR_OPACITY_SELECTED_DEFAULT,
                Map3GradientColorManager.OPACITY_MIN,
                Map3GradientColorManager.OPACITY_MAX);

        config.interiorOpacity_HovSel = Util.getXmlFloatInt(xmlOpacity,//
                ATTR_HOV_AND_SEL,
                INTERIOR_OPACITY_HOV_SEL_DEFAULT,
                Map3GradientColorManager.OPACITY_MIN,
                Map3GradientColorManager.OPACITY_MAX);
    }
项目:mytourbook    文件:Util.java   
/**
 * @param xmlMemento
 * @param key
 * @param defaultValue
 * @param minValue
 *            Float min value.
 * @param maxValue
 *            Float max value.
 * @return
 */
public static float getXmlFloatFloat(   final XMLMemento xmlMemento,
                                        final String key,
                                        final float defaultValue,
                                        final float minValue,
                                        final float maxValue) {

    final Float value = getXmlFloat(xmlMemento, key, defaultValue);

    if (value < minValue) {
        return minValue;
    }

    if (value > maxValue) {
        return maxValue;
    }

    return value;
}
项目:mytourbook    文件:MapBookmarkManager.java   
private static XMLMemento create_Root() {

        final XMLMemento xmlRoot = XMLMemento.createWriteRoot(TAG_ROOT);

        // date/time
        xmlRoot.putString(Util.ATTR_ROOT_DATETIME, TimeTools.now().toString());

        // plugin version
        final Version version = _bundle.getVersion();
        xmlRoot.putInteger(Util.ATTR_ROOT_VERSION_MAJOR, version.getMajor());
        xmlRoot.putInteger(Util.ATTR_ROOT_VERSION_MINOR, version.getMinor());
        xmlRoot.putInteger(Util.ATTR_ROOT_VERSION_MICRO, version.getMicro());
        xmlRoot.putString(Util.ATTR_ROOT_VERSION_QUALIFIER, version.getQualifier());

        // config version
        xmlRoot.putInteger(ATTR_CONFIG_VERSION, CONFIG_VERSION);

        return xmlRoot;
    }
项目:mytourbook    文件:MapBookmarkManager.java   
private static void parse_10_Options(final XMLMemento xmlRoot) {

        final XMLMemento xmlOptions = (XMLMemento) xmlRoot.getChild(TAG_OPTIONS);

        if (xmlOptions == null) {
            return;
        }

        numberOfBookmarkItems = Util.getXmlInteger(
                xmlOptions,
                ATTR_NUMBER_OF_BOOKMARK_ITEMS,
                NUM_BOOKMARK_ITEMS_DEFAULT,
                NUM_BOOKMARK_ITEMS_MIN,
                NUM_BOOKMARK_ITEMS_MAX);

        numberOfRecentBookmarks = Util.getXmlInteger(
                xmlOptions,
                ATTR_NUMBER_OF_RECENT_BOOKMARKS,
                NUM_RECENT_BOOKMARKS_DEFAULT,
                NUM_RECENT_BOOKMARKS_MIN,
                NUM_RECENT_BOOKMARKS_MAX);
    }
项目:mytourbook    文件:MapBookmarkManager.java   
private static void parse_22_Bookmarks_One(final XMLMemento xmlBookmark, final MapBookmark bookmark) {

// SET_FORMATTING_OFF
// SET_FORMATTING_ON

        bookmark.id = Util.getXmlString(xmlBookmark, ATTR_ID, Long.toString(System.nanoTime()));
        bookmark.name = Util.getXmlString(xmlBookmark, ATTR_NAME, UI.EMPTY_STRING);

        /*
         * Map position
         */
        final MapPosition mapPosition = new MapPosition();

        mapPosition.x = Util.getXmlDouble(xmlBookmark, ATTR_MAP_POSITION_X, 0.5);
        mapPosition.y = Util.getXmlDouble(xmlBookmark, ATTR_MAP_POSITION_Y, 0.5);
        mapPosition.scale = Util.getXmlDouble(xmlBookmark, ATTR_MAP_POSITION_SCALE, 1);

        mapPosition.bearing = Util.getXmlFloat(xmlBookmark, ATTR_MAP_POSITION_BEARING, 0f);
        mapPosition.tilt = Util.getXmlFloat(xmlBookmark, ATTR_MAP_POSITION_TILT, 0f);
        mapPosition.zoomLevel = Util.getXmlInteger(xmlBookmark, ATTR_MAP_POSITION_ZOOM_LEVEL, 1);

        bookmark.setMapPosition(mapPosition);
    }
项目:mytourbook    文件:TourFilterManager.java   
private static void readXml_Number_Float(   final IMemento xmlProperty,
                                            final TourFilterProperty filterProperty,
                                            final int fieldNo) {

    final TourFilterFieldConfig fieldConfig = filterProperty.fieldConfig;

    final float value = Util.getXmlFloatFloat(

            (XMLMemento) xmlProperty,
            ATTR_VALUE + fieldNo,

            0f,
            fieldConfig.minValue,
            fieldConfig.maxValue);

    if (fieldNo == 1) {
        filterProperty.doubleValue1 = value;
    } else {
        filterProperty.doubleValue2 = value;
    }
}
项目:mytourbook    文件:TourFilterManager.java   
private static XMLMemento writeFilterProfile_10_Root() {

        final XMLMemento xmlRoot = XMLMemento.createWriteRoot(TAG_ROOT);

        // date/time
        xmlRoot.putString(Util.ATTR_ROOT_DATETIME, TimeTools.now().toString());

        // plugin version
        final Version version = _bundle.getVersion();
        xmlRoot.putInteger(Util.ATTR_ROOT_VERSION_MAJOR, version.getMajor());
        xmlRoot.putInteger(Util.ATTR_ROOT_VERSION_MINOR, version.getMinor());
        xmlRoot.putInteger(Util.ATTR_ROOT_VERSION_MICRO, version.getMicro());
        xmlRoot.putString(Util.ATTR_ROOT_VERSION_QUALIFIER, version.getQualifier());

        // layer structure version
        xmlRoot.putInteger(ATTR_TOUR_FILTER_VERSION, TOUR_FILTER_VERSION);

        return xmlRoot;
    }
项目:mytourbook    文件:PrefPageSRTMColors.java   
private static IMemento createXmlProfile(   final XMLMemento xmlMemento,
                                            final int profileId,
                                            final String name,
                                            final String profileImagePath,
                                            final boolean isShadow,
                                            final float shadowValue,
                                            final String resolution) {

    final IMemento xmlProfile = xmlMemento.createChild(MEMENTO_CHILD_PROFILE);

    xmlProfile.putInteger(TAG_PROFILE_ID, profileId);
    xmlProfile.putString(TAG_NAME, name);
    xmlProfile.putString(TAG_IMAGE_PATH, profileImagePath);
    xmlProfile.putBoolean(TAG_IS_SHADOW, isShadow);
    xmlProfile.putString(TAG_RESOLUTION, resolution);
    xmlProfile.putFloat(TAG_SHADOW_VALUE, shadowValue);

    return xmlProfile;
}
项目:mytourbook    文件:PrefPageSRTMColors.java   
private static XMLMemento getXMLRoot() {

        try {

            final Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();

            // create root element
            final Element element = document.createElement(PROFILE_XML_ROOT);
            element.setAttribute("version", "1"); //$NON-NLS-1$ //$NON-NLS-2$
            document.appendChild(element);

            return new XMLMemento(document, element);

        } catch (final ParserConfigurationException e) {
            throw new Error(e.getMessage());
        }
    }