@Override
  public void writeExternal(Element element) throws WriteExternalException {
    final CodeStyleSettings parentSettings = new CodeStyleSettings();
    DefaultJDOMExternalizer.writeExternal(
        this, element, new DifferenceFilter<CodeStyleSettings>(this, parentSettings));
    List<CustomCodeStyleSettings> customSettings =
        new ArrayList<CustomCodeStyleSettings>(getCustomSettingsValues());

    Collections.sort(
        customSettings,
        new Comparator<CustomCodeStyleSettings>() {
          @Override
          public int compare(final CustomCodeStyleSettings o1, final CustomCodeStyleSettings o2) {
            return o1.getTagName().compareTo(o2.getTagName());
          }
        });

    for (final CustomCodeStyleSettings settings : customSettings) {
      final CustomCodeStyleSettings parentCustomSettings =
          parentSettings.getCustomSettings(settings.getClass());
      if (parentCustomSettings == null) {
        throw new WriteExternalException("Custom settings are null for " + settings.getClass());
      }
      settings.writeExternal(element, parentCustomSettings);
    }

    final FileType[] fileTypes =
        myAdditionalIndentOptions
            .keySet()
            .toArray(new FileType[myAdditionalIndentOptions.keySet().size()]);
    Arrays.sort(
        fileTypes,
        new Comparator<FileType>() {
          @Override
          public int compare(final FileType o1, final FileType o2) {
            return o1.getDefaultExtension().compareTo(o2.getDefaultExtension());
          }
        });

    for (FileType fileType : fileTypes) {
      final IndentOptions indentOptions = myAdditionalIndentOptions.get(fileType);
      Element additionalIndentOptions = new Element(ADDITIONAL_INDENT_OPTIONS);
      indentOptions.serialize(additionalIndentOptions, getDefaultIndentOptions(fileType));
      additionalIndentOptions.setAttribute(FILETYPE, fileType.getDefaultExtension());
      if (!additionalIndentOptions.getChildren().isEmpty()) {
        element.addContent(additionalIndentOptions);
      }
    }

    myCommonSettingsManager.writeExternal(element);
  }
 @Override
 public void writeExternal(Element element) throws WriteExternalException {
   for (String s : myGroupPath) {
     Element path = new Element(PATH);
     path.setAttribute(VALUE, s);
     element.addContent(path);
   }
   if (myComponent instanceof String) {
     element.setAttribute(VALUE, (String) myComponent);
     element.setAttribute(IS_ACTION, Boolean.TRUE.toString());
   } else if (myComponent instanceof Separator) {
     element.setAttribute(SEPARATOR, Boolean.TRUE.toString());
   } else if (myComponent instanceof Group) {
     final String groupId =
         ((Group) myComponent).getId() != null && ((Group) myComponent).getId().length() != 0
             ? ((Group) myComponent).getId()
             : ((Group) myComponent).getName();
     element.setAttribute(VALUE, groupId != null ? groupId : "");
     element.setAttribute(IS_GROUP, Boolean.TRUE.toString());
   }
   element.setAttribute(ACTION_TYPE, Integer.toString(myActionType));
   element.setAttribute(POSITION, Integer.toString(myAbsolutePosition));
   DefaultJDOMExternalizer.writeExternal(this, element);
 }
Esempio n. 3
0
 public void writeExternal(Element element) throws WriteExternalException {
   DefaultJDOMExternalizer.writeExternal(this, element);
   if (myUserObject instanceof String) {
     element.setAttribute(USER_OBJECT, (String) myUserObject);
   }
 }