external system: before_sync/after_sync actions
[idea/community.git] / platform / external-system-impl / src / com / intellij / openapi / externalSystem / service / project / manage / ExternalProjectsState.java
1 /*
2  * Copyright 2000-2014 JetBrains s.r.o.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package com.intellij.openapi.externalSystem.service.project.manage;
17
18 import com.intellij.openapi.externalSystem.view.ExternalProjectsViewState;
19 import com.intellij.util.containers.FactoryMap;
20 import com.intellij.util.xmlb.annotations.MapAnnotation;
21 import com.intellij.util.xmlb.annotations.Property;
22 import com.intellij.util.xmlb.annotations.Tag;
23 import org.jetbrains.annotations.Nullable;
24
25 import java.util.LinkedHashMap;
26 import java.util.Map;
27
28 /**
29  * @author Vladislav.Soroka
30  * @since 10/23/2014
31  */
32 public class ExternalProjectsState {
33
34
35   private final Map<String, State> myExternalSystemsState = new NullSafeMap<String, State>() {
36     @Nullable
37     @Override
38     protected State create(String key) {
39       return new State();
40     }
41   };
42
43   @Property(surroundWithTag = false)
44   @MapAnnotation(surroundWithTag = false, surroundValueWithTag = false, surroundKeyWithTag = false,
45     keyAttributeName = "id", entryTagName = "system")
46   public Map<String, State> getExternalSystemsState() {
47     return myExternalSystemsState;
48   }
49
50   @SuppressWarnings("UnusedDeclaration")
51   public void setExternalSystemsState(Map<String, State> externalSystemsState) {
52   }
53
54
55   @Tag("state")
56   public static class State {
57     private ExternalProjectsViewState projectsViewState = new ExternalProjectsViewState();
58
59     private final Map<String, TaskActivationState> myExternalSystemsTaskActivation = new FactoryMap<String, TaskActivationState>() {
60       @Nullable
61       @Override
62       protected TaskActivationState create(String key) {
63         return new TaskActivationState();
64       }
65
66       @Override
67       public TaskActivationState put(String key, TaskActivationState value) {
68         if(value == null) return null;
69         return super.put(key, value);
70       }
71
72       @Override
73       protected Map<String, TaskActivationState> createMap() {
74         return new LinkedHashMap<String, TaskActivationState>();
75       }
76     };
77
78     @Property(surroundWithTag = false)
79     @MapAnnotation(surroundWithTag = false, surroundValueWithTag = false, surroundKeyWithTag = false,
80       keyAttributeName = "path", entryTagName = "task", sortBeforeSave = false)
81     public Map<String, TaskActivationState> getExternalSystemsTaskActivation() {
82       return myExternalSystemsTaskActivation;
83     }
84
85     @SuppressWarnings("UnusedDeclaration")
86     public void setExternalSystemsTaskActivation(Map<String, TaskActivationState> externalSystemsTaskActivation) {
87     }
88
89     @Property(surroundWithTag = false)
90     public ExternalProjectsViewState getProjectsViewState() {
91       return projectsViewState;
92     }
93
94     public void setProjectsViewState(ExternalProjectsViewState projectsViewState) {
95       this.projectsViewState = projectsViewState;
96     }
97   }
98
99   public static abstract class NullSafeMap<K,V> extends FactoryMap<K,V> {
100     @Override
101     public V put(K key, V value) {
102       if(value == null) return null;
103       return super.put(key, value);
104     }
105   }
106 }