Skip to content
This repository has been archived by the owner on Apr 3, 2018. It is now read-only.

Commit

Permalink
LANG: refactor TextStylingPreference, overlay preferences, SVC.
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-medeiros committed Oct 6, 2015
1 parent e504135 commit 0a021cf
Show file tree
Hide file tree
Showing 21 changed files with 348 additions and 631 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@
import org.osgi.service.prefs.BackingStoreException;

import melnorme.lang.ide.core.LangCore;
import melnorme.utilbox.fields.DomainField;
import melnorme.utilbox.ownership.IDisposable;

public abstract class PreferenceHelper<T> extends AbstractPreferenceHelper {

public final String qualifier;
protected final T defaultValue;

protected final DomainField<T> field = new DomainField<>();

public PreferenceHelper(String key, T defaultValue) {
this(LangCore.PLUGIN_ID, key, defaultValue);
}
Expand All @@ -41,7 +44,9 @@ public PreferenceHelper(String pluginId, String key, T defaultValue) {

initializeDefaultValueInDefaultScope();

get(); // called just to check assertions
InstanceScope.INSTANCE.getNode(qualifier).addPreferenceChangeListener(event -> handlePreferenceChange(event));

field.setFieldValue(get());
}

public final String getQualifier() {
Expand All @@ -52,6 +57,10 @@ public T getDefault() {
return defaultValue;
}

public DomainField<T> getPrefField() {
return field;
}

protected IPreferencesAccess combinedScopes() {
return new PreferencesLookupHelper(getQualifier());
}
Expand Down Expand Up @@ -88,6 +97,14 @@ public final void set(T value) {
doSet(InstanceScope.INSTANCE.getNode(getQualifier()), value);
}

protected void handlePreferenceChange(PreferenceChangeEvent event) {
if(event.getKey().equals(key)) {
field.setFieldValue(get());
}
}

/* ----------------- ----------------- */

public final void set(IProject project, T value) throws BackingStoreException {
IEclipsePreferences projectPreferences = getProjectNode(project);
doSet(projectPreferences, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import melnorme.lang.ide.ui.EditorSettings_Actual.EditorPrefConstants;
import melnorme.lang.ide.ui.LangUIPlugin;
import melnorme.lang.ide.ui.editor.LangSourceViewer;
import melnorme.lang.ide.ui.text.SimpleSourceViewerConfiguration;
import melnorme.util.swt.jface.text.ColorManager2;

/**
Expand Down Expand Up @@ -166,7 +167,7 @@ public SourceViewerInformationControl(Shell parent, boolean isResizable, int ori
IPreferenceStore store= LangUIPlugin.getInstance().getCombinedPreferenceStore();

fViewer= new LangSourceViewer(composite, null, null, false, textStyle);
fViewer.configure(EditorSettings_Actual.createSimpleSourceViewerConfiguration(store, getColorManager()));
fViewer.configure(new SimpleSourceViewerConfiguration(store, getColorManager()));

fViewer.setEditable(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
package melnorme.lang.ide.ui.editor;


import melnorme.lang.ide.ui.text.SimpleLangSourceViewerConfiguration;
import melnorme.lang.ide.ui.text.AbstractSimpleLangSourceViewerConfiguration;
import melnorme.utilbox.ownership.IDisposable;
import melnorme.utilbox.ownership.OwnedArraylist;

Expand Down Expand Up @@ -55,8 +55,8 @@ public final void configure(SourceViewerConfiguration configuration) {
public void doConfigure(SourceViewerConfiguration configuration) {
super.configure(configuration);

if(configuration instanceof SimpleLangSourceViewerConfiguration) {
SimpleLangSourceViewerConfiguration svc = (SimpleLangSourceViewerConfiguration) configuration;
if(configuration instanceof AbstractSimpleLangSourceViewerConfiguration) {
AbstractSimpleLangSourceViewerConfiguration svc = (AbstractSimpleLangSourceViewerConfiguration) configuration;
svc.configureViewer(this);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


import melnorme.lang.ide.ui.LangUIPlugin;
import melnorme.lang.ide.ui.text.SimpleLangSourceViewerConfiguration;
import melnorme.lang.ide.ui.text.AbstractSimpleLangSourceViewerConfiguration;
import melnorme.lang.ide.ui.views.AbstractFilteredTreePopupControl;
import melnorme.lang.ide.ui.views.StructureElementLabelProvider;
import melnorme.lang.tooling.structure.ISourceFileStructure;
Expand Down Expand Up @@ -104,9 +104,9 @@ protected boolean matchNameDirectlyFilteredIn(String matchName) {

public static class OutlineInformationControlCreator implements IInformationControlCreator {

protected final SimpleLangSourceViewerConfiguration svc;
protected final AbstractSimpleLangSourceViewerConfiguration svc;

public OutlineInformationControlCreator(SimpleLangSourceViewerConfiguration svc) {
public OutlineInformationControlCreator(AbstractSimpleLangSourceViewerConfiguration svc) {
this.svc = svc;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ public abstract class AbstractPreferencesBlockPrefPage_Old extends AbstractCompo

public interface IPreferencesBlock_Old extends IWidgetComponent, IDisposable {

public void loadFromStore();
public void saveSettings();

public void saveToStore();

public void loadStoreDefaults();
public void loadDefaults();

}

Expand All @@ -46,17 +44,14 @@ public AbstractPreferencesBlockPrefPage_Old(IPreferenceStore store) {

@Override
protected Control createContents(Composite parent) {
Control body = fConfigurationBlock.createComponent(parent);

fConfigurationBlock.loadFromStore();
return body;
return fConfigurationBlock.createComponent(parent);
}

@Override
public boolean performOk() {
super.performOk();

fConfigurationBlock.saveToStore();
fConfigurationBlock.saveSettings();
LangUIPlugin.flushInstanceScope();

return true;
Expand All @@ -66,7 +61,7 @@ public boolean performOk() {
public void performDefaults() {
super.performDefaults();

fConfigurationBlock.loadStoreDefaults();
fConfigurationBlock.loadDefaults();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import melnorme.lang.ide.ui.LangUIMessages;
import melnorme.lang.ide.ui.LangUIPlugin;
import melnorme.lang.ide.ui.editor.LangSourceViewer;
import melnorme.lang.ide.ui.text.SimpleSourceViewerConfiguration;
import melnorme.util.swt.jface.text.ColorManager2;

public abstract class LangTemplatePreferencePage extends TemplatePreferencePage implements IWorkbenchPreferencePage {
Expand Down Expand Up @@ -89,7 +90,7 @@ protected IDocument createViewerDocument() {
}

protected SourceViewerConfiguration createPreviewerSourceViewerConfiguration() {
return EditorSettings_Actual.createSimpleSourceViewerConfiguration(getPreferenceStore(), getColorManager());
return new SimpleSourceViewerConfiguration(getPreferenceStore(), getColorManager());
}

// Note: Mostly copied from parent, in the future we might need to modify this code.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.widgets.Shell;

import _org.eclipse.jdt.internal.ui.JavaPlugin;
import _org.eclipse.jdt.internal.ui.text.java.hover.SourceViewerInformationControl;
import melnorme.lang.ide.ui.text.AbstractSimpleLangSourceViewerConfiguration;


public class TemplateInformationControlCreator
Expand Down Expand Up @@ -66,4 +66,14 @@ public boolean canReplace(IInformationControlCreator creator) {
return (creator != null && getClass() == creator.getClass());
}

}

/* ----------------- ----------------- */

class JavaPlugin {

public static String getAdditionalInfoAffordanceString() {
return AbstractSimpleLangSourceViewerConfiguration.getAdditionalInfoAffordanceString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package melnorme.lang.ide.ui.text;


import static melnorme.utilbox.core.Assert.AssertNamespace.assertNotNull;
import static melnorme.utilbox.core.Assert.AssertNamespace.assertTrue;

import org.eclipse.jface.text.rules.ICharacterScanner;
Expand All @@ -23,25 +24,28 @@
import melnorme.lang.ide.core.text.BufferedRuleBasedScannerExt;
import melnorme.lang.ide.core.text.CharacterScanner_ReaderHelper;
import melnorme.lang.ide.ui.text.coloring.ILangTokenScanner;
import melnorme.lang.ide.ui.text.coloring.TextStylingPreference;
import melnorme.lang.ide.ui.text.coloring.ITextStylingPref;
import melnorme.lang.ide.ui.text.coloring.StylingPreferences;
import melnorme.lang.ide.ui.text.coloring.TokenRegistry;
import melnorme.lang.tooling.parser.lexer.ILexingRule2;
import melnorme.utilbox.collections.ArrayList2;

public abstract class AbstractLangScanner extends BufferedRuleBasedScannerExt implements ILangTokenScanner {

protected final TokenRegistry tokenStore;
protected final StylingPreferences stylingPrefs;

public AbstractLangScanner(TokenRegistry tokenStore) {
this.tokenStore = tokenStore;
public AbstractLangScanner(TokenRegistry tokenStore, StylingPreferences stylingPrefs) {
this.tokenStore = assertNotNull(tokenStore);
this.stylingPrefs = stylingPrefs;

ArrayList2<IRule> arrayList2 = new ArrayList2<>();
initRules(arrayList2);
setRules(arrayList2.toArray(IRule.class));
}

public IToken getToken(TextStylingPreference coloringPref) {
return tokenStore.getToken(coloringPref);
public IToken getToken(ITextStylingPref stylingPref) {
return tokenStore.getToken(stylingPref);
}

/* ----------------- ----------------- */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
import melnorme.util.swt.jface.text.ColorManager2;
import melnorme.utilbox.collections.Indexable;

public abstract class AbstractLangSourceViewerConfiguration extends SimpleLangSourceViewerConfiguration {
public abstract class AbstractLangSourceViewerConfiguration extends AbstractSimpleLangSourceViewerConfiguration {

protected final AbstractLangStructureEditor editor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@
* Abstract SourceViewConfiguration
* Has code to help manage the configured scanners, and let respond to preference changes.
*/
public abstract class SimpleLangSourceViewerConfiguration extends TextSourceViewerConfiguration {
public abstract class AbstractSimpleLangSourceViewerConfiguration extends TextSourceViewerConfiguration {

protected final ColorManager2 colorManager;
protected final IPreferenceStore preferenceStore;

public SimpleLangSourceViewerConfiguration(IPreferenceStore preferenceStore, ColorManager2 colorManager) {
public AbstractSimpleLangSourceViewerConfiguration(IPreferenceStore preferenceStore,
ColorManager2 colorManager) {
super(assertNotNull(preferenceStore));
this.colorManager = colorManager;
this.preferenceStore = preferenceStore;
Expand Down Expand Up @@ -110,7 +111,7 @@ protected void setupPresentationReconciler(PresentationReconciler reconciler, IS
assertTrue(Display.getCurrent() != null);

// Create a token registry for given sourceViewer
TokenRegistry tokenRegistry = new TokenRegistry(getPreferenceStore(), colorManager) {
TokenRegistry tokenRegistry = new TokenRegistry(colorManager) {
@Override
protected void handleTokenModified(Token token) {
sourceViewer.invalidateTextPresentation();
Expand Down
Loading

0 comments on commit 0a021cf

Please sign in to comment.