-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathBoxProviderImpl.java
More file actions
187 lines (157 loc) · 4.7 KB
/
BoxProviderImpl.java
File metadata and controls
187 lines (157 loc) · 4.7 KB
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
package pm.eclipse.editbox.impl;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IWorkbenchPart;
//import org.eclipse.ui.texteditor.AbstractTextEditor;
import pm.eclipse.editbox.EditBox;
import pm.eclipse.editbox.IBoxBuilder;
import pm.eclipse.editbox.IBoxDecorator;
import pm.eclipse.editbox.IBoxProvider;
import pm.eclipse.editbox.IBoxSettings;
/**
* Provider
*/
public class BoxProviderImpl implements IBoxProvider {
protected String id;
protected String name;
protected IBoxSettings theme;
protected BoxSettingsStoreImpl providerStore;
protected Map<String,Class> builders;
protected Collection<String> defaultSettingsCatalog;
private ArrayList<Matcher> matchers;
public BoxSettingsStoreImpl getSettingsStore() {
if (providerStore == null) {
providerStore = createSettingsStore();
providerStore.setProviderId(id);
}
return providerStore;
}
public IBoxSettings getEditorsBoxSettings() {
if (theme == null) {
theme = createEmptySettings();
getSettingsStore().loadDefaults(theme);
theme.addPropertyChangeListener(new IPropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
String p = event.getProperty();
if (p!=null && (p.equals(IBoxSettings.PropertiesKeys.FileNames.name()) ||
p.equals(IBoxSettings.PropertiesKeys.ALL.name())))
matchers = null;
}});
}
return theme;
}
public IBoxDecorator decorate(IWorkbenchPart editorPart) {
StyledText st = getStyledText(editorPart);
if (st == null)
return null;
IBoxSettings settings = getEditorsBoxSettings();
if (!settings.getEnabled())
return null;
IBoxDecorator result = createDecorator();
result.setStyledText(st);
result.setSettings(settings);
result.decorate(false);
return result;
}
protected StyledText getStyledText(final IWorkbenchPart editorPart) {
if (editorPart != null) {
Object obj = editorPart.getAdapter(Control.class);
if (obj instanceof StyledText)
return (StyledText) obj;
}
return null;
}
public boolean supports(IWorkbenchPart editorPart) {
return editorPart.getAdapter(Control.class) instanceof StyledText &&
(supportsFile(editorPart.getTitle()) || supportsFile(editorPart.getTitleToolTip()));
}
protected boolean supportsFile(String fileName) {
if (fileName != null)
for (Matcher matcher : getMatchers()) {
if (matcher.matches(fileName))
return true;
}
return false;
}
protected Collection<Matcher> getMatchers() {
if (matchers == null) {
matchers = new ArrayList<Matcher>();
Collection<String> fileNames = getEditorsBoxSettings().getFileNames();
if (fileNames != null)
for (String pattern : fileNames)
matchers.add(new Matcher(pattern));
}
return matchers;
}
public void releaseDecorator(IBoxDecorator decorator) {
decorator.undecorate();
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public void setId(String newId) {
id = newId;
}
public void setName(String newName) {
name = newName;
}
protected BoxSettingsStoreImpl createSettingsStore() {
BoxSettingsStoreImpl pstore = new BoxSettingsStoreImpl();
pstore.setDefaultSettingsCatalog(defaultSettingsCatalog);
return pstore;
}
public void setDefaultSettingsCatalog(Collection<String> cat){
defaultSettingsCatalog = cat;
}
public IBoxSettings createSettings() {
BoxSettingsImpl theme = createEmptySettings();
theme.copyFrom(getEditorsBoxSettings());
return theme;
}
protected BoxSettingsImpl createEmptySettings() {
return new BoxSettingsImpl();
}
public IBoxDecorator createDecorator() {
BoxDecoratorImpl decorator = new BoxDecoratorImpl();
decorator.setProvider(this);
return decorator;
}
public Collection<String> getBuilders() {
return builders!=null?builders.keySet():null;
}
public void setBuilders(Map<String,Class> newBuilders){
builders = newBuilders;
}
public IBoxBuilder createBoxBuilder(String name){
Class c = null;
if (name != null && builders != null)
c = builders.get(name);
if (c == null)
return new BoxBuilderImpl();
try {
return (IBoxBuilder) c.newInstance();
} catch (Exception e) {
EditBox.logError(this, "Cannot create box builder: "+name, e);
}
return null;
}
class Matcher {
// org.eclipse.ui.internal.misc.StringMatcher m;
StringMatcher m;
Matcher(String pattern) {
m = new StringMatcher(pattern, true, false);
// m = new org.eclipse.ui.internal.misc.StringMatcher(pattern, true, false);
}
boolean matches(String text) {
return m.match(text);
}
}
}