Skip to content

Commit 8167886

Browse files
committed
Heavy renaming
1 parent 948901d commit 8167886

File tree

6 files changed

+274
-280
lines changed

6 files changed

+274
-280
lines changed

pm.eclipse.editbox/src/pm/eclipse/editbox/impl/BoxProviderImpl.java

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,40 @@
1717
import pm.eclipse.editbox.IBoxProvider;
1818
import pm.eclipse.editbox.IBoxSettings;
1919

20+
/**
21+
* Provider
22+
*/
2023
public class BoxProviderImpl implements IBoxProvider {
2124

2225
protected String id;
2326
protected String name;
24-
protected IBoxSettings editorsSettings;
25-
protected BoxSettingsStoreImpl settingsStore;
27+
protected IBoxSettings theme;
28+
protected BoxSettingsStoreImpl providerStore;
2629
protected Map<String,Class> builders;
2730
protected Collection<String> defaultSettingsCatalog;
2831
private ArrayList<Matcher> matchers;
2932

3033
public BoxSettingsStoreImpl getSettingsStore() {
31-
if (settingsStore == null) {
32-
settingsStore = createSettingsStore();
33-
settingsStore.setProviderId(id);
34+
if (providerStore == null) {
35+
providerStore = createSettingsStore();
36+
providerStore.setProviderId(id);
3437
}
35-
return settingsStore;
38+
return providerStore;
3639
}
3740

3841
public IBoxSettings getEditorsBoxSettings() {
39-
if (editorsSettings == null) {
40-
editorsSettings = createEmptySettings();
41-
getSettingsStore().loadDefaults(editorsSettings);
42-
editorsSettings.addPropertyChangeListener(new IPropertyChangeListener() {
42+
if (theme == null) {
43+
theme = createEmptySettings();
44+
getSettingsStore().loadDefaults(theme);
45+
theme.addPropertyChangeListener(new IPropertyChangeListener() {
4346
public void propertyChange(PropertyChangeEvent event) {
4447
String p = event.getProperty();
4548
if (p!=null && (p.equals(IBoxSettings.PropertiesKeys.FileNames.name()) ||
4649
p.equals(IBoxSettings.PropertiesKeys.ALL.name())))
4750
matchers = null;
4851
}});
4952
}
50-
return editorsSettings;
53+
return theme;
5154
}
5255

5356
public IBoxDecorator decorate(IWorkbenchPart editorPart) {
@@ -122,29 +125,29 @@ public void setName(String newName) {
122125

123126

124127
protected BoxSettingsStoreImpl createSettingsStore() {
125-
BoxSettingsStoreImpl result = new BoxSettingsStoreImpl();
126-
result.setDefaultSettingsCatalog(defaultSettingsCatalog);
127-
return result;
128+
BoxSettingsStoreImpl pstore = new BoxSettingsStoreImpl();
129+
pstore.setDefaultSettingsCatalog(defaultSettingsCatalog);
130+
return pstore;
128131
}
129132

130133
public void setDefaultSettingsCatalog(Collection<String> cat){
131134
defaultSettingsCatalog = cat;
132135
}
133136

134137
public IBoxSettings createSettings() {
135-
BoxSettingsImpl result = createEmptySettings();
136-
result.copyFrom(getEditorsBoxSettings());
137-
return result;
138+
BoxSettingsImpl theme = createEmptySettings();
139+
theme.copyFrom(getEditorsBoxSettings());
140+
return theme;
138141
}
139142

140143
protected BoxSettingsImpl createEmptySettings() {
141144
return new BoxSettingsImpl();
142145
}
143146

144147
public IBoxDecorator createDecorator() {
145-
BoxDecoratorImpl result = new BoxDecoratorImpl();
146-
result.setProvider(this);
147-
return result;
148+
BoxDecoratorImpl decorator = new BoxDecoratorImpl();
149+
decorator.setProvider(this);
150+
return decorator;
148151
}
149152

150153
public Collection<String> getBuilders() {

pm.eclipse.editbox/src/pm/eclipse/editbox/impl/BoxProviderRegistry.java

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
import pm.eclipse.editbox.EditBox;
1717
import pm.eclipse.editbox.IBoxDecorator;
1818
import pm.eclipse.editbox.IBoxProvider;
19+
import pm.eclipse.editbox.IBoxSettings;
1920

2021
/**
21-
* Default settings
22+
* Registry keeps Providers list and initialize them or restores from preferences
2223
* @author Piotr Metel
2324
* @author Paul Verest : added "RainbowDrops" and ALL_THEMES_LIST to be used in every category
2425
*/
@@ -46,7 +47,15 @@ public static int getThemeIndex(String preferedThemeName) {
4647
}
4748
//}
4849

49-
50+
//{ like in BoxSettingsStoreImpl
51+
protected IPreferenceStore store = EditBox.getDefault().getPreferenceStore();
52+
// protected IPreferenceStore store{
53+
// if (store == null)
54+
// store = EditBox.getDefault().getPreferenceStore();
55+
// return store;
56+
// }
57+
//}
58+
5059
protected Collection<IBoxProvider> providers;
5160
protected Map<IWorkbenchPart, IBoxDecorator> decorators;
5261
protected Map<IPartService, IPartListener2> partListeners;
@@ -58,27 +67,16 @@ public Collection<IBoxProvider> getBoxProviders() {
5867
}
5968
if (providers == null){
6069
providers = defaultProviders();
61-
}else{
62-
// comparing providers from Preferences with defaultProviders can be here
6370
}
6471
return providers;
6572
}
6673

67-
//{ like in BoxSettingsStoreImpl
68-
protected IPreferenceStore store;
69-
protected IPreferenceStore getStore(){
70-
if (store == null)
71-
store = EditBox.getDefault().getPreferenceStore();
72-
return store;
73-
}
74-
//}
75-
7674
// Preferences have string like
7775
// proivders=java,python,markup,text,js
7876
// calls createProvider(name)
7977
protected Collection<IBoxProvider> loadProvidersFromPreferences() {
8078
List<IBoxProvider> result = null;
81-
String pSetting = getStore().getString(PROVIDERS);
79+
String pSetting = store.getString(PROVIDERS);
8280
if (pSetting != null && pSetting.length() > 0) {
8381
String[] split = pSetting.split(",");
8482
if (split.length > 0)
@@ -103,7 +101,7 @@ public void storeProviders(){
103101
if (sb.length()!=0) sb.append(",");
104102
sb.append(p.getName());
105103
}
106-
getStore().setValue(PROVIDERS,sb.toString());
104+
store.setValue(PROVIDERS,sb.toString());
107105
}
108106
}
109107

@@ -122,7 +120,7 @@ protected Collection<IBoxProvider> defaultProviders() {
122120
result.add(createProviderForNameAndExtentions("ruby", Arrays.asList("*.rb", "*.ruby") ) );
123121
result.add(createProviderForNameAndExtentions("text", Arrays.asList("*.txt", "*.") ) );
124122
result.add(createProviderForNameAndExtentions("xml", Arrays.asList("*.xml", "*.launch", "*.project", "*.classpath") ) );
125-
result.add(createProviderForNameAndExtentions("exclude", Arrays.asList("*.ascii") ) );
123+
result.add(createProviderForNameAndExtentionsDisabled("exclude", Arrays.asList("*.ascii") ) );
126124
result.add(createProviderForNameAndExtentions("others", Arrays.asList("*.*") ) ); // "*.*" makes default to every file
127125
return result;
128126
}
@@ -148,6 +146,13 @@ protected BoxProviderImpl createProviderForNameAndExtentions(String name, List<S
148146
provider.getEditorsBoxSettings().setFileNames(extentions);
149147
return provider;
150148
}
149+
protected BoxProviderImpl createProviderForNameAndExtentionsDisabled(String name, List<String> extentions) {
150+
BoxProviderImpl provider = createProviderForNameAndExtentions(name, extentions);
151+
// no effect :-(
152+
// IBoxSettings theme = provider.getEditorsBoxSettings();
153+
// theme.setEnabled(false); //this fires PropertyChangeListener
154+
return provider;
155+
}
151156

152157
protected Map<String, Class> defaultBuilders() {
153158
Map<String, Class> result = new HashMap<String, Class>();

pm.eclipse.editbox/src/pm/eclipse/editbox/impl/BoxSettingsImpl.java

Lines changed: 72 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ public class BoxSettingsImpl implements IBoxSettings {
7676
private transient Color[] highlightColors;
7777

7878

79-
8079
public void copyFrom(IBoxSettings other) {
8180
BoxSettingsImpl o = (BoxSettingsImpl) other;
8281
name = o.getName();
@@ -140,38 +139,6 @@ protected Color setColorCopy(Color old, Color newColor) {
140139
return newColor == null ? null : new Color(null, newColor.getRGB());
141140
}
142141

143-
public String export() {
144-
return new StringExternalization().export(this);
145-
}
146-
147-
public void load(String string) {
148-
StringExternalization ext = new StringExternalization();
149-
boolean error = false;
150-
if (string != null)
151-
try {
152-
ext.load(string, this);
153-
} catch (Exception e) {
154-
EditBox.logError(this, "Cannot load EditBox settings from string: "+string, e);
155-
error = true;
156-
}
157-
if (error || string == null) {
158-
this.copyFrom(DEFAULT);
159-
}
160-
notifyChange(PropertiesKeys.ALL.name(), null, null);
161-
}
162-
163-
public void export(OutputStream stream) throws Exception{
164-
new StringExternalization().export(stream,this);
165-
}
166-
167-
public void load(InputStream stream) throws Exception{
168-
if (stream==null)
169-
load((String)null);
170-
else
171-
new StringExternalization().load(stream,this);
172-
notifyChange(PropertiesKeys.ALL.name(), null, null);
173-
}
174-
175142
public boolean getEnabled() {
176143
return enabled;
177144
}
@@ -533,34 +500,86 @@ public int getFillKeyModifierSWTInt(){
533500
return SWT.SHIFT;
534501
return 0;
535502
}
503+
504+
//save/restore related {
505+
private StringExternalization ext = new StringExternalization();
506+
507+
public String export() {
508+
return ext.exportToString(this);
509+
}
510+
public void export(OutputStream stream) throws Exception{
511+
ext.export(stream,this);
512+
}
536513

514+
public void load(String string) {
515+
//StringExternalization ext = new StringExternalization();
516+
boolean error = false;
517+
if (string != null){
518+
try {
519+
ext.loadFromString(string, this);
520+
} catch (Exception e) {
521+
EditBox.logError(this, "Cannot load EditBox settings from string: "+string, e);
522+
error = true;
523+
}
524+
}
525+
if (error || string == null) {
526+
this.copyFrom(DEFAULT);
527+
}
528+
notifyChange(PropertiesKeys.ALL.name(), null, null);
529+
}
530+
public void load(InputStream stream) throws Exception{
531+
if (stream==null)
532+
load((String)null);
533+
else
534+
ext.loadFromStream(stream,this);
535+
notifyChange(PropertiesKeys.ALL.name(), null, null);
536+
}
537+
538+
// could have all methods static, but it just has too many methods to change
539+
/**
540+
* using Properties store and load methods
541+
*/
537542
class StringExternalization {
538543

539544
private static final String COMMENT = "Editbox Eclipse Plugin Settings";
540545

541-
public String export(BoxSettingsImpl b) {
546+
public void export(OutputStream stream, BoxSettingsImpl b) throws Exception {
542547
Properties p = toProperies(b);
543-
return propertiesToString(p);
548+
p.store(stream, COMMENT);
544549
}
545-
546-
public void load(InputStream stream, BoxSettingsImpl b) throws Exception {
550+
public String exportToString(BoxSettingsImpl b) {
551+
Properties p = toProperies(b);
552+
// return exportPropertiesToString(p);
553+
// }
554+
// private String exportPropertiesToString(Properties p) {
555+
try {
556+
ByteArrayOutputStream bo = new ByteArrayOutputStream();
557+
p.store(bo, "COMMENT");
558+
return bo.toString();
559+
} catch (IOException e) {
560+
EditBox.logError(this, "Cannot convert propeties to sring", e);
561+
}
562+
return "";
563+
}
564+
// private Properties loadProperties(String s) throws IOException {
565+
// Properties p = new Properties();
566+
// p.load(new StringBufferInputStream(s));
567+
// return p;
568+
// }
569+
public void loadFromString(String s, BoxSettingsImpl b) throws Exception {
570+
//Properties p = loadProperties(s);
547571
Properties p = new Properties();
548-
p.load(stream);
549-
load(p,b);
572+
p.load(new StringBufferInputStream(s));
573+
fromProperties(p,b);
550574
}
551-
552-
public void export(OutputStream stream, BoxSettingsImpl b) throws Exception {
553-
Properties p = toProperies(b);
554-
p.store(stream, COMMENT);
555-
575+
public void loadFromStream(InputStream stream, BoxSettingsImpl b) throws Exception {
576+
Properties p = new Properties();
577+
p.load(stream);
578+
fromProperties(p,b);
556579
}
557580

558-
public void load(String s, BoxSettingsImpl b) throws Exception {
559-
Properties p = loadProperties(s);
560-
load(p,b);
561-
}
562581

563-
private void load(Properties p, BoxSettingsImpl b) {
582+
private void fromProperties(Properties p, BoxSettingsImpl b) {
564583
b.name = parseString(p.get(PropertiesKeys.Name.name()));
565584
b.borderColor = parseColor(p.get(PropertiesKeys.BorderColor.name()));
566585
b.highlightColor = parseColor(p.get(PropertiesKeys.HighlightColor.name()));
@@ -618,23 +637,6 @@ private Properties toProperies(BoxSettingsImpl b) {
618637
return p;
619638
}
620639

621-
private Properties loadProperties(String s) throws IOException {
622-
Properties p = new Properties();
623-
p.load(new StringBufferInputStream(s));
624-
return p;
625-
}
626-
627-
private String propertiesToString(Properties p) {
628-
try {
629-
ByteArrayOutputStream bo = new ByteArrayOutputStream();
630-
p.store(bo, "COMMENT");
631-
return bo.toString();
632-
} catch (IOException e) {
633-
EditBox.logError(this, "Cannot convert propeties to sring", e);
634-
}
635-
return "";
636-
}
637-
638640

639641
private Color[] parseColorsArray(Object o) {
640642
if (o == null || o.equals("null"))
@@ -717,7 +719,9 @@ private String toS(String s) {
717719
return s == null ? "null" : s;
718720
}
719721
}
720-
722+
//}
723+
724+
//{
721725
public void addPropertyChangeListener(IPropertyChangeListener listener) {
722726
if (listeners == null)
723727
listeners = new ArrayList<IPropertyChangeListener>();
@@ -735,6 +739,7 @@ protected void notifyChange(String propertyName, Object oldValue, Object newValu
735739
listener.propertyChange(e);
736740
}
737741
}
742+
//}
738743

739744
public void setBorderLineStyle(int selectionIndex) {
740745
this.borderLineStyle = selectionIndex;

0 commit comments

Comments
 (0)