Package org.eclipse.ui

Examples of org.eclipse.ui.XMLMemento$DOMWriter


                reader = new BufferedReader(new InputStreamReader(stream,
                        "utf-8")); //$NON-NLS-1$
            } else {
                reader = new StringReader(xmlString);
            }
            XMLMemento memento = XMLMemento.createReadRoot(reader);
            EditorDescriptor editor;
            IMemento[] edMementos = memento
                    .getChildren(IWorkbenchConstants.TAG_DESCRIPTOR);
            // Get the editors and validate each one
            for (int i = 0; i < edMementos.length; i++) {
                editor = new EditorDescriptor();
                boolean valid = editor.loadValues(edMementos[i]);
View Full Code Here


     *
     * @throws WorkbenchException
     */
    public void readResources(Map editorTable, Reader reader)
            throws WorkbenchException {
        XMLMemento memento = XMLMemento.createReadRoot(reader);
        String versionString = memento.getString(IWorkbenchConstants.TAG_VERSION);
        boolean versionIs31 = "3.1".equals(versionString); //$NON-NLS-1$
       
        IMemento[] extMementos = memento
                .getChildren(IWorkbenchConstants.TAG_INFO);
        for (int i = 0; i < extMementos.length; i++) {
            String name = extMementos[i]
                    .getString(IWorkbenchConstants.TAG_NAME);
            if (name == null) {
View Full Code Here

        //Save the resource type descriptions
        List editors = new ArrayList();
        IPreferenceStore store = WorkbenchPlugin.getDefault()
                .getPreferenceStore();

        XMLMemento memento = XMLMemento
                .createWriteRoot(IWorkbenchConstants.TAG_EDITORS);
        memento.putString(IWorkbenchConstants.TAG_VERSION, "3.1"); //$NON-NLS-1$
        FileEditorMapping maps[] = typeEditorMappings.userMappings();
        for (int mapsIndex = 0; mapsIndex < maps.length; mapsIndex++) {
            FileEditorMapping type = maps[mapsIndex];
            IMemento editorMemento = memento
                    .createChild(IWorkbenchConstants.TAG_INFO);
            editorMemento.putString(IWorkbenchConstants.TAG_NAME, type
                    .getName());
            editorMemento.putString(IWorkbenchConstants.TAG_EXTENSION, type
                    .getExtension());
            IEditorDescriptor[] editorArray = type.getEditors();
            for (int i = 0; i < editorArray.length; i++) {
                EditorDescriptor editor = (EditorDescriptor) editorArray[i];
                if (!editors.contains(editor)) {
                    editors.add(editor);
                }
                IMemento idMemento = editorMemento
                        .createChild(IWorkbenchConstants.TAG_EDITOR);
                idMemento.putString(IWorkbenchConstants.TAG_ID, editorArray[i]
                        .getId());
            }
            editorArray = type.getDeletedEditors();
            for (int i = 0; i < editorArray.length; i++) {
                EditorDescriptor editor = (EditorDescriptor) editorArray[i];
                if (!editors.contains(editor)) {
                    editors.add(editor);
                }
                IMemento idMemento = editorMemento
                        .createChild(IWorkbenchConstants.TAG_DELETED_EDITOR);
                idMemento.putString(IWorkbenchConstants.TAG_ID, editorArray[i]
                        .getId());
            }
            editorArray = type.getDeclaredDefaultEditors();
            for (int i = 0; i < editorArray.length; i++) {
                EditorDescriptor editor = (EditorDescriptor) editorArray[i];
                if (!editors.contains(editor)) {
                    editors.add(editor);
                }
                IMemento idMemento = editorMemento
                        .createChild(IWorkbenchConstants.TAG_DEFAULT_EDITOR);
                idMemento.putString(IWorkbenchConstants.TAG_ID, editorArray[i]
                        .getId());
            }
        }
        Writer writer = null;
        try {
            writer = new StringWriter();
            memento.save(writer);
            writer.close();
            store.setValue(IPreferenceConstants.RESOURCES, writer.toString());
        } catch (IOException e) {
            try {
                if (writer != null) {
          writer.close();
        }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            MessageDialog.openError((Shell) null, "Saving Problems", //$NON-NLS-1$
                    "Unable to save resource associations."); //$NON-NLS-1$
            return;
        }

        memento = XMLMemento.createWriteRoot(IWorkbenchConstants.TAG_EDITORS);
        Iterator itr = editors.iterator();
        while (itr.hasNext()) {
            EditorDescriptor editor = (EditorDescriptor) itr.next();
            IMemento editorMemento = memento
                    .createChild(IWorkbenchConstants.TAG_DESCRIPTOR);
            editor.saveValues(editorMemento);
        }
        writer = null;
        try {
            writer = new StringWriter();
            memento.save(writer);
            writer.close();
            store.setValue(IPreferenceConstants.EDITORS, writer.toString());
        } catch (IOException e) {
            try {
                if (writer != null) {
View Full Code Here

    if (editorId == null) {
      return;
    }
    try {
      if (editor instanceof IPersistableEditor) {
        XMLMemento editorState = XMLMemento
            .createWriteRoot(IWorkbenchConstants.TAG_EDITOR_STATE);
        ((IPersistableEditor) editor).saveState(editorState);
        ((WorkbenchPage) page).openEditor(editor.getEditorInput(),
            editorId, true, IWorkbenchPage.MATCH_NONE, editorState);
      } else {
View Full Code Here

                {
                    mementoFile.createNewFile();
                }

                // Getting a (read-only) memento from the File
                XMLMemento readMemento = XMLMemento.createReadRoot( new FileReader( mementoFile ) );

                // Converting the read memento to a writable memento
                XMLMemento memento = XMLMemento.createWriteRoot( "memento" ); //$NON-NLS-1$
                memento.putMemento( readMemento );

                return memento;
            }

            return null;
View Full Code Here

   * Record the sharable workbench state in a document.
   *
   * @return {@link XMLMemento}
   */
  public XMLMemento recordSharableWorkbenchState() {
    XMLMemento memento = XMLMemento
        .createWriteRoot(IWorkbenchConstants.TAG_WORKBENCH);
    IStatus status = saveSettings(memento);
    if (status.getSeverity() != IStatus.OK) {
      // don't use newWindow as parent because it has not yet been opened
      // (bug 76724)
View Full Code Here

            WorkbenchPlugin.PI_WORKBENCH,
            WorkbenchMessages.WorkbenchSettings_CouldNotCreateDirectories);

      FileOutputStream stream = new FileOutputStream(workspaceFile);
      OutputStreamWriter writer = new OutputStreamWriter(stream, "utf-8"); //$NON-NLS-1$
      XMLMemento memento = XMLMemento
          .createWriteRoot(IWorkbenchConstants.TAG_WORKBENCH);
      IStatus status = saveSettings(memento);
      if (status.getSeverity() != IStatus.OK)
        return status;

      memento.save(writer);
      writer.close();

    } catch (IOException e) {
      return new Status(IStatus.ERROR, WorkbenchPlugin.PI_WORKBENCH,
          WorkbenchMessages.Workbench_problemsSavingMsg, e);
View Full Code Here

  /* (non-Javadoc)
   * @see net.sf.logsaw.ui.ILogResourceManager#saveState()
   */
  @Override
  public synchronized void saveState() throws CoreException {
    XMLMemento rootElem = XMLMemento.createWriteRoot(ELEM_ROOT);
    rootElem.putInteger(ATTRIB_COMPAT, COMPAT_VERSION);
    for (ILogResource log : logSet) {
      IMemento logElem = rootElem.createChild(ELEM_LOG_RESOURCE);
      logElem.createChild(ELEM_NAME).putTextData(log.getName());
      IMemento dialectElem = logElem.createChild(ELEM_DIALECT);
      dialectElem.putString(ATTRIB_FACTORY,
          log.getDialect().getFactory().getId());
      // Save config options of dialect
      saveConfigOptions(dialectElem, (IConfigurableObject) log.getDialect().getAdapter(IConfigurableObject.class));
      logElem.createChild(ELEM_PK).putTextData(log.getPK());
      // Save config options of resource
      saveConfigOptions(logElem, (IConfigurableObject) log.getAdapter(IConfigurableObject.class));
    }
    try {
      // Save to state file
      rootElem.save(new BufferedWriter(new OutputStreamWriter(
          FileUtils.openOutputStream(stateFile.toFile()), "UTF-8"))); //$NON-NLS-1$
    } catch (IOException e) {
      // Unexpected exception; wrap with CoreException
      throw new CoreException(new Status(IStatus.ERROR, UIPlugin.PLUGIN_ID,
          NLS.bind(Messages.LogResourceManager_error_failedToUpdateState,
View Full Code Here

      UIPlugin.logAndShowError(e, true);
    }
  }

  private void save() throws CoreException {
    XMLMemento rootElem = XMLMemento.createWriteRoot(ELEM_ROOT);
    int i = 0;
    for (ALogEntryField<?, ?> fld : fields) {
      IMemento colElem = rootElem.createChild(ELEM_COLUMN);
      colElem.putInteger(ATTRIB_WIDTH, widths[i++]);
      colElem.putTextData(fld.getKey());
    }
    try {
      StringWriter w = new StringWriter();
      // Save to byte buffer first
      rootElem.save(w);
      // Update log resource
      log.configure(OPTION_COLUMNS, w.toString());
    } catch (IOException e) {
      // Unexpected exception; wrap with CoreException
      throw new CoreException(new Status(IStatus.ERROR, UIPlugin.PLUGIN_ID,
View Full Code Here

    }
    return log.getAdapter(clazz);
  }

  private void save() throws CoreException {
    XMLMemento rootElem = XMLMemento.createWriteRoot(ELEM_ROOT);
    for (ARestriction<?> rest : restrictions) {
      final IMemento clauseElem = rootElem.createChild(ELEM_CLAUSE);
      clauseElem.putString(ATTRIB_FIELD, rest.getField().getKey());
      clauseElem.putInteger(ATTRIB_OPERATOR, rest.getOperator().getId());
      rest.visit(new IRestrictionVisitor() {
        /* (non-Javadoc)
         * @see net.sf.logsaw.core.query.IRestrictionVisitor#visit(net.sf.logsaw.core.query.LevelRestriction)
         */
        @Override
        public void visit(LevelRestriction restriction) {
          clauseElem.putTextData(restriction.getField().toInputValue(restriction.getValue(), log));
        }

        /* (non-Javadoc)
         * @see net.sf.logsaw.core.query.IRestrictionVisitor#visit(net.sf.logsaw.core.query.StringRestriction)
         */
        @Override
        public void visit(StringRestriction restriction) {
          clauseElem.putTextData(restriction.getField().toInputValue(restriction.getValue(), log));
        }

        /* (non-Javadoc)
         * @see net.sf.logsaw.core.query.IRestrictionVisitor#visit(net.sf.logsaw.core.query.DateRestriction)
         */
        @Override
        public void visit(DateRestriction restriction) {
          clauseElem.putTextData(restriction.getField().toInputValue(restriction.getValue(), log));
        }
      });
    }
    try {
      StringWriter w = new StringWriter();
      // Save to byte buffer first
      rootElem.save(w);
      // Update log resource
      log.configure(OPTION_FILTER, w.toString());
    } catch (IOException e) {
      // Unexpected exception; wrap with CoreException
      throw new CoreException(new Status(IStatus.ERROR, UIPlugin.PLUGIN_ID,
View Full Code Here

TOP

Related Classes of org.eclipse.ui.XMLMemento$DOMWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.