IDEADEV-41265 (IU-9.0 Beta - Undo does not revert file to unchanged)
[fedora-idea.git] / platform / vcs-impl / src / com / intellij / openapi / vcs / impl / projectlevelman / ProjectLevelVcsManagerSerialization.java
blob7c46f33bcf4d3cf328a252fabc3b67dcbee6c864
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.openapi.vcs.impl.projectlevelman;
18 import com.intellij.openapi.util.InvalidDataException;
19 import com.intellij.openapi.util.WriteExternalException;
20 import com.intellij.openapi.vcs.VcsShowConfirmationOption;
21 import com.intellij.openapi.vcs.VcsShowConfirmationOptionImpl;
22 import com.intellij.openapi.vcs.VcsShowOptionsSettingImpl;
23 import org.jdom.Element;
24 import org.jetbrains.annotations.NonNls;
26 import java.util.List;
27 import java.util.Map;
29 public class ProjectLevelVcsManagerSerialization {
30 @NonNls private static final String OPTIONS_SETTING = "OptionsSetting";
31 @NonNls private static final String CONFIRMATIONS_SETTING = "ConfirmationsSetting";
32 @NonNls private static final String VALUE_ATTTIBUTE = "value";
33 @NonNls private static final String ID_ATTRIBUTE = "id";
35 @NonNls private static final String ELEMENT_MAPPING = "mapping";
36 @NonNls private static final String ATTRIBUTE_DIRECTORY = "directory";
37 @NonNls private static final String ATTRIBUTE_VCS = "vcs";
38 @NonNls private static final String ATTRIBUTE_DEFAULT_PROJECT = "defaultProject";
39 @NonNls private static final String ELEMENT_ROOT_SETTINGS = "rootSettings";
40 @NonNls private static final String ATTRIBUTE_CLASS = "class";
42 // read-only can be kept here
43 private final Map<String, VcsShowConfirmationOption.Value> myReadValue;
45 public ProjectLevelVcsManagerSerialization() {
46 myReadValue = new com.intellij.util.containers.HashMap<String, VcsShowConfirmationOption.Value>();
49 private VcsShowOptionsSettingImpl getOrCreateOption(final Map<String, VcsShowOptionsSettingImpl> options, final String actionName) {
50 if (! options.containsKey(actionName)) {
51 options.put(actionName, new VcsShowOptionsSettingImpl(actionName));
53 return options.get(actionName);
56 public void readExternalUtil(final Element element, final OptionsAndConfirmations optionsAndConfirmations) throws InvalidDataException {
57 final Map<String, VcsShowOptionsSettingImpl> options = optionsAndConfirmations.getOptions();
58 List subElements = element.getChildren(OPTIONS_SETTING);
59 for (Object o : subElements) {
60 if (o instanceof Element) {
61 final Element subElement = ((Element)o);
62 final String id = subElement.getAttributeValue(ID_ATTRIBUTE);
63 final String value = subElement.getAttributeValue(VALUE_ATTTIBUTE);
64 if (id != null && value != null) {
65 try {
66 final boolean booleanValue = Boolean.valueOf(value).booleanValue();
67 getOrCreateOption(options, id).setValue(booleanValue);
69 catch (Exception e) {
70 //ignore
75 myReadValue.clear();
76 subElements = element.getChildren(CONFIRMATIONS_SETTING);
77 for (Object o : subElements) {
78 if (o instanceof Element) {
79 final Element subElement = ((Element)o);
80 final String id = subElement.getAttributeValue(ID_ATTRIBUTE);
81 final String value = subElement.getAttributeValue(VALUE_ATTTIBUTE);
82 if (id != null && value != null) {
83 try {
84 myReadValue.put(id, VcsShowConfirmationOption.Value.fromString(value));
86 catch (Exception e) {
87 //ignore
94 public void writeExternalUtil(final Element element, final OptionsAndConfirmations optionsAndConfirmations) throws WriteExternalException {
95 final Map<String, VcsShowOptionsSettingImpl> options = optionsAndConfirmations.getOptions();
96 final Map<String, VcsShowConfirmationOptionImpl> confirmations = optionsAndConfirmations.getConfirmations();
98 for (VcsShowOptionsSettingImpl setting : options.values()) {
99 final Element settingElement = new Element(OPTIONS_SETTING);
100 element.addContent(settingElement);
101 settingElement.setAttribute(VALUE_ATTTIBUTE, Boolean.toString(setting.getValue()));
102 settingElement.setAttribute(ID_ATTRIBUTE, setting.getDisplayName());
105 for (VcsShowConfirmationOptionImpl setting : confirmations.values()) {
106 final Element settingElement = new Element(CONFIRMATIONS_SETTING);
107 element.addContent(settingElement);
108 settingElement.setAttribute(VALUE_ATTTIBUTE, setting.getValue().toString());
109 settingElement.setAttribute(ID_ATTRIBUTE, setting.getDisplayName());
113 public VcsShowConfirmationOption.Value getInitOptionValue(final String id) {
114 return myReadValue.get(id);