forked from magento/magento2-phpstorm-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettings.java
236 lines (203 loc) · 8.35 KB
/
Settings.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
package com.magento.idea.magento2plugin.project;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.components.*;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.EventDispatcher;
import com.intellij.util.xmlb.annotations.Attribute;
import com.intellij.util.xmlb.annotations.Tag;
import com.magento.idea.magento2plugin.init.ConfigurationManager;
import com.magento.idea.magento2plugin.util.magento.MagentoBasePathUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.EventListener;
@State(
name = "Magento2PluginSettings",
storages = {
@Storage("magento2plugin.xml")
}
)
public class Settings implements PersistentStateComponent<Settings.State> {
private final EventDispatcher<MagentoModuleDataListener> myEventDispatcher = EventDispatcher.create(MagentoModuleDataListener.class);
public boolean pluginEnabled = false;
public static String DEFAULT_LICENSE = "Proprietary";
public String magentoPath;
public boolean mftfSupportEnabled = false;
public boolean myDoNotAskContentConfigAgain = false;
public String magentoVersion = null;
@Nullable
public Settings.State getState() {
return new Settings.State(
this.pluginEnabled,
this.magentoPath,
DEFAULT_LICENSE,
this.mftfSupportEnabled,
this.myDoNotAskContentConfigAgain,
this.magentoVersion
);
}
public void setState(State state) {
State oldState = this.getState();
this.loadState(state);
this.notifyListeners(state, oldState);
}
public void loadState(@NotNull Settings.State state) {
this.pluginEnabled = state.isPluginEnabled();
this.magentoPath = state.getMagentoPath();
this.DEFAULT_LICENSE = state.getDefaultLicenseName();
this.mftfSupportEnabled = state.isMftfSupportEnabled();
this.myDoNotAskContentConfigAgain = state.isDoNotAskContentConfigAgain();
this.magentoVersion = state.getMagentoVersion();
}
public void addListener(MagentoModuleDataListener listener) {
this.myEventDispatcher.addListener(listener);
}
private void notifyListeners(State state, State oldState) {
if (!state.equals(oldState)) {
this.myEventDispatcher.getMulticaster().stateChanged(state, oldState);
}
}
public void setDoNotAskContentConfigurationAgain(boolean doNotAskContentConfigurationAgain) {
this.myDoNotAskContentConfigAgain = doNotAskContentConfigurationAgain;
}
public void setMagentoPath(String magentoPath) {
this.magentoPath = magentoPath;
}
public interface MagentoModuleDataListener extends EventListener {
void stateChanged(State state, State oldState);
}
public static Settings getInstance(Project project) {
return ServiceManager.getService(project, Settings.class);
}
public static boolean isEnabled(@NotNull Project project) {
return getInstance(project).pluginEnabled;
}
public static String getDefaultLicenseName(@NotNull Project project) {
return getInstance(project).DEFAULT_LICENSE;
}
public static boolean isMftfSupportEnabled(@NotNull Project project) {
return getInstance(project).mftfSupportEnabled;
}
@Nullable
public static String getLastMagentoPath() {
return PropertiesComponent.getInstance().getValue("magento.support.magentoPath");
}
@Nullable
public static String getMagentoPath(@NotNull Project project) {
Settings settings = getInstance(project);
String path = settings.magentoPath;
if (path == null || path.isEmpty()) {
if (MagentoBasePathUtil.isMagentoFolderValid(project.getBasePath())) {
settings.setMagentoPath(project.getBasePath());
} else {
settings.pluginEnabled = false;
ConfigurationManager.suggestToConfigureMagentoPath(project);
return null;
}
}
return settings.magentoPath;
}
@Tag
public static class State {
public boolean pluginEnabled;
public String defaultLicenseName;
public String magentoPath;
public boolean mftfSupportEnabled;
public boolean myDoNotAskContentConfigAgain;
public String magentoVersion;
public State() {
}
public State(
boolean pluginEnabled,
String magentoPath,
String defaultLicenseName,
boolean mftfSupportEnabled,
boolean myDoNotAskContentConfigAgain,
String magentoVersion
) {
this.pluginEnabled = pluginEnabled;
this.magentoPath = magentoPath;
this.defaultLicenseName = defaultLicenseName;
this.mftfSupportEnabled = mftfSupportEnabled;
this.myDoNotAskContentConfigAgain = myDoNotAskContentConfigAgain;
this.magentoVersion = magentoVersion;
}
@Attribute("enabled")
public boolean isPluginEnabled() {
return this.pluginEnabled;
}
public void setPluginEnabled(boolean enabled) {
this.pluginEnabled = enabled;
}
public String getMagentoPath() {
return this.magentoPath;
}
@Tag("magentoPath")
public void setMagentoPath(String magentoPath) {
this.magentoPath = magentoPath;
}
public String getMagentoVersion() {
return this.magentoVersion;
}
@Tag("magentoVersion")
public void setMagentoVersion(String magentoVersion) {
this.magentoVersion = magentoVersion;
}
public void setMagentoPathAndUpdateLastUsed(String magentoPath) {
this.setMagentoPath(magentoPath);
if (!StringUtil.isEmptyOrSpaces(magentoPath)) {
PropertiesComponent.getInstance().setValue("magento.support.magentoPath", magentoPath);
}
}
public String getDefaultLicenseName() {
return this.defaultLicenseName;
}
public void setDefaultLicenseName(String defaultLicenseName) {
this.defaultLicenseName = defaultLicenseName;
}
public boolean isMftfSupportEnabled() {
return this.mftfSupportEnabled;
}
public boolean isDoNotAskContentConfigAgain() {
return this.myDoNotAskContentConfigAgain;
}
public void setMftfSupportEnabled(boolean mftfSupportEnabled) {
this.mftfSupportEnabled = mftfSupportEnabled;
}
public boolean equals(Object objectToCompare) {
if (this == objectToCompare) {
return true;
} else if (objectToCompare != null && this.getClass() == objectToCompare.getClass()) {
State state = (State) objectToCompare;
if (this.isPluginEnabled() != state.isPluginEnabled()) {
return false;
} else if (this.isMftfSupportEnabled() != state.isMftfSupportEnabled()) {
return false;
} else if (this.isDoNotAskContentConfigAgain() != state.isDoNotAskContentConfigAgain()) {
return false;
} else {
if (this.magentoPath != null) {
return this.magentoPath.equals(state.magentoPath);
}
if (this.defaultLicenseName != null) {
return this.defaultLicenseName.equals(state.defaultLicenseName);
} else return state.defaultLicenseName == null;
}
} else {
return false;
}
}
public int hashCode() {
int result = this.isPluginEnabled() ? 1 : 0;
result = 31 * result + (this.magentoPath != null ? this.magentoPath.hashCode() : 0);
result = 31 * result + (this.isMftfSupportEnabled() ? 1 : 0);
result = 31 * result + (this.isDoNotAskContentConfigAgain() ? 1 : 0);
result = 31 * result + (this.defaultLicenseName != null ? this.defaultLicenseName.hashCode() : 0);
return result;
}
}
}