forked from magento/magento2-phpstorm-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettings.java
264 lines (230 loc) · 8.94 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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/*
* 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.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
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 java.util.EventListener;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@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;
public static String defaultLicense = "Proprietary";
public String magentoPath;
public boolean mftfSupportEnabled;
public boolean myDoNotAskContentConfigAgain;
public String magentoVersion;
@Override
@Nullable
public Settings.State getState() {
return new Settings.State(
this.pluginEnabled,
this.magentoPath,
defaultLicense,
this.mftfSupportEnabled,
this.myDoNotAskContentConfigAgain,
this.magentoVersion
);
}
/**
* State setter.
*
* @param state State
*/
public void setState(final State state) {
final State oldState = this.getState();
this.loadState(state);
this.notifyListeners(state, oldState);
}
@Override
public void loadState(final @NotNull Settings.State state) {
this.pluginEnabled = state.isPluginEnabled();
this.magentoPath = state.getMagentoPath();
this.defaultLicense = state.getDefaultLicenseName();
this.mftfSupportEnabled = state.isMftfSupportEnabled();
this.myDoNotAskContentConfigAgain = state.isDoNotAskContentConfigAgain();
this.magentoVersion = state.getMagentoVersion();
}
public void addListener(final MagentoModuleDataListener listener) {
this.myEventDispatcher.addListener(listener);
}
private void notifyListeners(final State state, final State oldState) {
if (!state.equals(oldState)) {
this.myEventDispatcher.getMulticaster().stateChanged(state, oldState);
}
}
public void setDoNotAskContentConfigurationAgain(
final boolean doNotAskContentConfigurationAgain
) {
this.myDoNotAskContentConfigAgain = doNotAskContentConfigurationAgain;
}
public void setMagentoPath(final String magentoPath) {
this.magentoPath = magentoPath;
}
public interface MagentoModuleDataListener extends EventListener {
void stateChanged(State state, State oldState);
}
public static Settings getInstance(final Project project) {
return ServiceManager.getService(project, Settings.class);
}
public static boolean isEnabled(final @NotNull Project project) {
return getInstance(project).pluginEnabled;
}
public static String getDefaultLicenseName(final @NotNull Project project) {
return getInstance(project).defaultLicense;
}
public static boolean isMftfSupportEnabled(final @NotNull Project project) {
return getInstance(project).mftfSupportEnabled;
}
@Nullable
public static String getLastMagentoPath() {
return PropertiesComponent.getInstance().getValue("magento.support.magentoPath");
}
@Nullable
public static String getMagentoPath(final @NotNull Project project) {
return getInstance(project).magentoPath;
}
@SuppressWarnings({"PMD.DataClass"})
@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() {//NOPMD
}
/**
* Settings State.
*
* @param pluginEnabled boolean
* @param magentoPath String
* @param defaultLicenseName String
* @param mftfSupportEnabled boolean
* @param myDoNotAskContentConfigAgain boolean
* @param magentoVersion String
*/
public State(
final boolean pluginEnabled,
final String magentoPath,
final String defaultLicenseName,
final boolean mftfSupportEnabled,
final boolean myDoNotAskContentConfigAgain,
final 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(final boolean enabled) {
this.pluginEnabled = enabled;
}
public String getMagentoPath() {
return this.magentoPath;
}
@Tag("magentoPath")
public void setMagentoPath(final String magentoPath) {
this.magentoPath = magentoPath;
}
public String getMagentoVersion() {
return this.magentoVersion;
}
@Tag("magentoVersion")
public void setMagentoVersion(final String magentoVersion) {
this.magentoVersion = magentoVersion;
}
/**
* Last Used Magento Path setter.
*
* @param magentoPath String
*/
public void setMagentoPathAndUpdateLastUsed(final 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(final String defaultLicenseName) {
this.defaultLicenseName = defaultLicenseName;
}
public boolean isMftfSupportEnabled() {
return this.mftfSupportEnabled;
}
public boolean isDoNotAskContentConfigAgain() {
return this.myDoNotAskContentConfigAgain;
}
public void setMftfSupportEnabled(final boolean mftfSupportEnabled) {
this.mftfSupportEnabled = mftfSupportEnabled;
}
@SuppressWarnings({"PMD.ConfusingTernary"})
@Override
public boolean equals(final Object objectToCompare) {
if (this == objectToCompare) {
return true;
} else if (objectToCompare != null && this.getClass() == objectToCompare.getClass()) {
final 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;
}
}
@SuppressWarnings({"PMD.ConfusingTernary"})
@Override
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;
}
}
}