Project

General

Profile

« Previous | Next » 

Revision c82a307b

Added by Patrick Plitzner over 6 years ago

ref #7006 Revert opcoach plugin for preferences

View differences:

eu.etaxonomy.taxeditor.bulkeditor/plugin.xml
129 129
      </fragment>
130 130
   </extension>
131 131
   <extension
132
         point="eu.etaxonomy.taxeditor.workbench.e4PreferencePages">
132
         point="org.eclipse.ui.preferencePages">
133 133
      <page
134 134
            category="eu.etaxonomy.taxeditor.preferences.bulkeditor.general"
135 135
            class="eu.etaxonomy.taxeditor.bulkeditor.preference.BulkEditorMarkerPreferencePage"
eu.etaxonomy.taxeditor.store/plugin.xml
713 713
   </fragment>
714 714
</extension>
715 715
<extension
716
      point="eu.etaxonomy.taxeditor.workbench.e4PreferencePages">
716
      point="org.eclipse.ui.preferencePages">
717 717
   <page
718 718
         category="eu.etaxonomy.taxeditor.preferences.general"
719 719
         class="eu.etaxonomy.taxeditor.preference.DebugPreferences"
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/DefaultFeatureTreePreferenecs.java
11 11

  
12 12
import java.util.List;
13 13

  
14
import javax.annotation.PostConstruct;
15

  
16 14
import org.eclipse.jface.viewers.ISelectionChangedListener;
17 15
import org.eclipse.jface.viewers.IStructuredSelection;
18 16
import org.eclipse.jface.viewers.ListViewer;
......
24 22
import org.eclipse.swt.layout.GridLayout;
25 23
import org.eclipse.swt.widgets.Composite;
26 24
import org.eclipse.swt.widgets.Control;
25
import org.eclipse.ui.IWorkbench;
26
import org.eclipse.ui.IWorkbenchPreferencePage;
27 27

  
28 28
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
29 29
import eu.etaxonomy.cdm.model.description.FeatureTree;
30 30
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeContentProvider;
31 31
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeLabelProvider;
32
import eu.etaxonomy.taxeditor.model.MessagingUtils;
32 33
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
33 34
import eu.etaxonomy.taxeditor.store.CdmStore;
34 35

  
......
39 40
 * @created Sep 16, 2010
40 41
 * @version 1.0
41 42
 */
42
public class DefaultFeatureTreePreferenecs extends CdmPreferencePage {
43
public class DefaultFeatureTreePreferenecs extends CdmPreferencePage implements IWorkbenchPreferencePage {
43 44

  
44 45
	private FeatureTree defaultFeatureTreeForTextualDescription;
45 46
	private FeatureTree defaultFeatureTreeForStructuredDescription;
......
49 50
	 */
50 51
	/** {@inheritDoc} */
51 52
	@Override
52
	@PostConstruct
53 53
	protected Control createContents(Composite parent) {
54 54
		defaultFeatureTreeForTextualDescription = PreferencesUtil.getDefaultFeatureTreeForTextualDescription();
55 55
		defaultFeatureTreeForStructuredDescription = PreferencesUtil.getDefaultFeatureTreeForStructuredDescription();
56 56

  
57 57
		Composite composite = new Composite(parent, SWT.NULL);
58 58
		composite.setLayout(new GridLayout());
59
		if(CdmStore.isActive()) {
59
		if(!CdmStore.isActive()) {
60
            MessagingUtils.noDataSourceWarningDialog(null);
61
		}else{
60 62
		    createTextTreeSelection(composite);
61 63
		    createStructureTreeSelection(composite);
62 64
		}
63
		init();
65

  
64 66
		return composite;
65 67
	}
66 68

  
67 69
	private void createTextTreeSelection(Composite parent){
68 70
		final CLabel label = new CLabel(parent, SWT.NONE);
69
		label.setText("Deafult Feature Tree to be used for textual descriptions");
71
		label.setText("Default Feature Tree to be used for textual descriptions");
70 72

  
71 73
		final ListViewer viewer = new ListViewer(parent);
72 74
		viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
......
125 127
	}
126 128

  
127 129
	/** {@inheritDoc} */
128
	public void init() {
130
	@Override
131
	public void init(IWorkbench workbench) {
129 132
		setPreferenceStore(PreferencesUtil.getPreferenceStore());
130 133
	}
131 134

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/matching/AbstractMatchingPreferences.java
12 12
import java.lang.reflect.Field;
13 13
import java.util.ArrayList;
14 14
import java.util.Arrays;
15
import java.util.HashMap;
15 16
import java.util.List;
16

  
17
import javax.inject.Inject;
17
import java.util.Map;
18 18

  
19 19
import org.eclipse.jface.preference.ComboFieldEditor;
20 20
import org.eclipse.jface.preference.FieldEditorPreferencePage;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Control;
21
import org.eclipse.swt.widgets.Combo;
22
import org.eclipse.ui.IWorkbench;
23
import org.eclipse.ui.IWorkbenchPreferencePage;
23 24

  
24
import eu.etaxonomy.cdm.model.common.CdmBase;
25 25
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
26 26
import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
27 27
import eu.etaxonomy.cdm.strategy.match.MatchException;
28 28
import eu.etaxonomy.cdm.strategy.match.MatchMode;
29
import eu.etaxonomy.taxeditor.model.MessagingUtils;
29 30
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
30 31
import eu.etaxonomy.taxeditor.store.CdmStore;
31 32

  
......
34 35
 * @created Jan 22, 2010
35 36
 * @version 1.0
36 37
 */
37
public abstract class AbstractMatchingPreferences<T extends IdentifiableEntity> extends FieldEditorPreferencePage {
38
public abstract class AbstractMatchingPreferences<T extends IdentifiableEntity> extends FieldEditorPreferencePage implements
39
		IWorkbenchPreferencePage {
38 40

  
39 41
	/**
40 42
	 * Fields that will be excluded from the display
......
42 44
	private static final String ExcludePattern = "serialVersionUID|logger|allFields|ajc.*|id|updated|updatedBy|created|createdBy|uuid" +
43 45
				"|parsingProblem|problemStarts|problemEnds|PROTECTED|NOT_PROTECTED|propertyChangeSupport";
44 46

  
47
	protected IMatchStrategy matchStrategy;
48

  
45 49
	protected Class<T> clazz;
46 50

  
47 51
	private List<MatchMode> matchModeList;
48 52

  
49
	@Inject
53
	protected Map<String, Combo> matchModeCombos = new HashMap<String, Combo>();
54

  
50 55
    @Override
51
    protected Control createContents(Composite parent) {
52
        Control contents = super.createContents(parent);
56
    public void init(IWorkbench workbench) {
53 57
        setPreferenceStore(PreferencesUtil.getPreferenceStore());
54
        return contents;
55 58
    }
56 59

  
57 60
	/**
......
59 62
	 */
60 63
	@Override
61 64
	protected void createFieldEditors() {
62
	    if(CdmStore.isActive()) {
65
	    if(!CdmStore.isActive()) {
66
            MessagingUtils.noDataSourceWarningDialog(null);
67
        }else{
63 68
            for(String fieldName : getFieldNames()){
64 69
                String[][] comboValues = new String[getMatchModeList().size()][2];
65 70
                for (int i=0;i<getMatchModeList().size();i++) {
......
85 90
		return matchModeList;
86 91
	}
87 92

  
88
	public abstract Class<? extends CdmBase> getType();
89

  
90 93
	/**
91 94
	 * Get names of all declared fields
92 95
	 *
......
95 98
	private List<String> getFieldNames(){
96 99
		List<Field> fields = new ArrayList<Field>();
97 100

  
98
		fields = getAllFields(fields, getType());
101
		fields = getAllFields(fields, clazz);
99 102
		List<String> fieldNames = new ArrayList<String>();
100 103

  
101 104
		for(Field field : fields){
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/matching/NonViralNameMatchingPreference.java
9 9

  
10 10
package eu.etaxonomy.taxeditor.preference.matching;
11 11

  
12
import eu.etaxonomy.cdm.model.common.CdmBase;
12
import org.eclipse.ui.IWorkbench;
13

  
13 14
import eu.etaxonomy.cdm.model.name.TaxonName;
14 15
import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
15 16
import eu.etaxonomy.cdm.strategy.match.MatchException;
16 17
import eu.etaxonomy.cdm.strategy.match.MatchStrategyConfigurator;
18
import eu.etaxonomy.taxeditor.model.MessagingUtils;
17 19

  
18 20
/**
19 21
 * <p>NonViralNameMatchingPreference class.</p>
......
23 25
 */
24 26
public class NonViralNameMatchingPreference extends AbstractMatchingPreferences<TaxonName>{
25 27

  
26
    @Override
27
    public Class<? extends CdmBase> getType(){
28
        return TaxonName.class;
29
    }
28
	/** {@inheritDoc} */
29
	@Override
30
    public void init(IWorkbench workbench) {
31
	    super.init(workbench);
32
		clazz = TaxonName.class;
33

  
34
		try {
35
			matchStrategy = MatchStrategyConfigurator.NonViralNameMatchStrategy();
36
		} catch (MatchException e) {
37
			MessagingUtils.error(this.getClass(), e);
38
			throw new RuntimeException(e);
39
		}
40
	}
30 41

  
31 42
	/** {@inheritDoc} */
32 43
	@Override
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/matching/ReferenceMatchingPreference.java
9 9

  
10 10
package eu.etaxonomy.taxeditor.preference.matching;
11 11

  
12
import eu.etaxonomy.cdm.model.common.CdmBase;
12
import org.eclipse.ui.IWorkbench;
13

  
13 14
import eu.etaxonomy.cdm.model.reference.Reference;
14 15
import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
15 16
import eu.etaxonomy.cdm.strategy.match.MatchException;
16 17
import eu.etaxonomy.cdm.strategy.match.MatchStrategyConfigurator;
18
import eu.etaxonomy.taxeditor.model.MessagingUtils;
17 19

  
18 20
/**
19 21
 * @author n.hoffmann
......
22 24
 */
23 25
public class ReferenceMatchingPreference extends AbstractMatchingPreferences<Reference> {
24 26

  
27
	/** {@inheritDoc} */
28
	@Override
29
    public void init(IWorkbench workbench) {
30
	    super.init(workbench);
31
		clazz = Reference.class;
25 32

  
26
    @Override
27
    public Class<? extends CdmBase> getType(){
28
        return Reference.class;
29
    }
33
		try {
34
			matchStrategy = MatchStrategyConfigurator.ReferenceMatchStrategy();
35
		} catch (MatchException e) {
36
			MessagingUtils.error(this.getClass(), e);
37
			throw new RuntimeException(e);
38
		}
39
	}
30 40

  
31 41
	/** {@inheritDoc} */
32 42
	@Override
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/matching/TeamOrPersonMatchingPreference.java
9 9

  
10 10
package eu.etaxonomy.taxeditor.preference.matching;
11 11

  
12
import org.eclipse.ui.IWorkbench;
13

  
12 14
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
13
import eu.etaxonomy.cdm.model.common.CdmBase;
14 15
import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
15 16
import eu.etaxonomy.cdm.strategy.match.MatchException;
16 17
import eu.etaxonomy.cdm.strategy.match.MatchStrategyConfigurator;
18
import eu.etaxonomy.taxeditor.model.MessagingUtils;
17 19

  
18 20
/**
19 21
 * @author n.hoffmann
......
23 25
public class TeamOrPersonMatchingPreference extends
24 26
		AbstractMatchingPreferences<TeamOrPersonBase> {
25 27

  
28
	/** {@inheritDoc} */
29
	@Override
30
    public void init(IWorkbench workbench) {
31
	    super.init(workbench);
32
		clazz = TeamOrPersonBase.class;
26 33

  
27
    @Override
28
    public Class<? extends CdmBase> getType(){
29
        return TeamOrPersonBase.class;
30
    }
34
		try {
35
			matchStrategy = MatchStrategyConfigurator.TeamOrPersonMatchStrategy();
36
		} catch (MatchException e) {
37
			MessagingUtils.error(this.getClass(), e);
38
			throw new RuntimeException(e);
39
		}
40
	}
31 41

  
32 42
	/** {@inheritDoc} */
33 43
	@Override
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/menu/AbstractMenuPreferences.java
13 13
import java.util.HashMap;
14 14
import java.util.List;
15 15

  
16
import javax.annotation.PostConstruct;
17

  
18 16
import org.eclipse.core.commands.Command;
19 17
import org.eclipse.core.commands.IParameter;
20 18
import org.eclipse.core.commands.Parameterization;
......
31 29
import org.eclipse.swt.widgets.Button;
32 30
import org.eclipse.swt.widgets.Composite;
33 31
import org.eclipse.swt.widgets.Control;
32
import org.eclipse.ui.IWorkbench;
33
import org.eclipse.ui.IWorkbenchPreferencePage;
34 34
import org.eclipse.ui.commands.ICommandService;
35 35
import org.eclipse.ui.handlers.IHandlerService;
36 36

  
......
39 39
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
40 40
import eu.etaxonomy.cdm.model.common.TermType;
41 41
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
42
import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermEditor;
42
import eu.etaxonomy.taxeditor.editor.definedterm.e4.DefinedTermEditorE4;
43 43
import eu.etaxonomy.taxeditor.model.AbstractUtility;
44 44
import eu.etaxonomy.taxeditor.model.MessagingUtils;
45 45
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
......
51 51
 * @created 12.06.2009
52 52
 * @version 1.0
53 53
 */
54
public abstract class AbstractMenuPreferences<T extends DefinedTermBase> extends CdmPreferencePage implements IConversationEnabled{
54
public abstract class AbstractMenuPreferences<T extends DefinedTermBase> extends CdmPreferencePage implements
55
		IWorkbenchPreferencePage, IConversationEnabled{
55 56

  
56 57
	private Button toggleButton;
57 58
	protected HashMap<DefinedTermBase<T>, Button> menuButtons;
......
98 99
	 * Create contents of the preference page
99 100
	 */
100 101
	@Override
101
	@PostConstruct
102 102
	public Control createContents(Composite parent) {
103 103

  
104 104
		Composite container = new Composite(parent, SWT.NULL);
......
147 147

  
148 148
		createAdditionalContent(container);
149 149

  
150
		init();
151

  
152 150
		return container;
153 151
	}
154 152

  
......
159 157
		tableViewer.setCheckedElements(preferedTerms.toArray());
160 158
	}
161 159

  
162
	protected void createAdditionalContent(@SuppressWarnings("unused") Composite container) {
160
	protected void createAdditionalContent(Composite container) {
163 161
		// implement where needed
164 162
	}
165 163

  
......
183 181

  
184 182
				ICommandService commandService = (ICommandService)  AbstractUtility.getService(ICommandService.class);
185 183

  
186
				Command command = commandService.getCommand(DefinedTermEditor.OPEN_COMMAND_ID);
184
				Command command = commandService.getCommand(DefinedTermEditorE4.OPEN_COMMAND_ID);
187 185

  
188 186
				IParameter parameter;
189 187
				try {
......
201 199
							handlerService.executeCommand(pCommand, null);
202 200
						} catch (NotDefinedException e) {
203 201
							throw new RuntimeException("Could not find open command: "
204
									+ DefinedTermEditor.OPEN_COMMAND_ID);
202
									+ DefinedTermEditorE4.OPEN_COMMAND_ID);
205 203
						} catch (Exception e) {
206 204
							MessagingUtils
207 205
									.error(getClass(),
......
221 219
	}
222 220

  
223 221
	/** {@inheritDoc} */
224
    public void init() {
222
	@Override
223
    public void init(IWorkbench workbench) {
225 224
	    setPreferenceStore(PreferencesUtil.getPreferenceStore());
226
	    if(CdmStore.isActive()) {
225
	    if(!CdmStore.isActive()) {
226
	        MessagingUtils.noDataSourceWarningDialog(null);
227

  
228
	    } else {
227 229
	        getConversationHolder().bind();
228 230
	    }
229 231
	}
......
270 272

  
271 273
	private boolean checkNoneChecked(){
272 274

  
273
		if(tableViewer.getTable().getItems().length>0
274
		        && tableViewer.getCheckedElements().length == 0){
275
		if(tableViewer.getCheckedElements().length == 0){
275 276
			setMessage("Please check at least one item", WARNING);
276 277
			return true;
277 278
		}else{
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/menu/LanguageMenuPreferences.java
9 9

  
10 10
package eu.etaxonomy.taxeditor.preference.menu;
11 11

  
12
import javax.annotation.PostConstruct;
13

  
14 12
import org.eclipse.jface.viewers.ITableLabelProvider;
15 13
import org.eclipse.jface.viewers.LabelProvider;
16 14
import org.eclipse.jface.viewers.ViewerComparator;
......
47 45
	 */
48 46
	/** {@inheritDoc} */
49 47
	@Override
50
	@PostConstruct
51 48
	public Control createContents(Composite parent) {
52 49
		Control control = super.createContents(parent);
53 50

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/menu/NameRelationshipTypeMenuPreferences.java
9 9

  
10 10
package eu.etaxonomy.taxeditor.preference.menu;
11 11

  
12
import javax.annotation.PostConstruct;
13

  
14 12
import org.eclipse.swt.graphics.Image;
15 13
import org.eclipse.swt.widgets.Composite;
16 14
import org.eclipse.swt.widgets.Control;
......
46 44
	 */
47 45
	/** {@inheritDoc} */
48 46
	@Override
49
    @PostConstruct
50 47
	public Control createContents(Composite parent) {
51 48
		Control container = super.createContents(parent);
52 49
		getTableViewer().setLabelProvider(new NameRelationLabelProvider());
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/menu/PresenceAbsenceMenuPreferences.java
9 9

  
10 10
package eu.etaxonomy.taxeditor.preference.menu;
11 11

  
12
import org.eclipse.ui.IWorkbenchPreferencePage;
13

  
12 14
import eu.etaxonomy.cdm.model.common.TermType;
13 15
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
14 16

  
......
19 21
 * @created 25.06.2009
20 22
 * @version 1.0
21 23
 */
22
public class PresenceAbsenceMenuPreferences extends AbstractMenuPreferences<PresenceAbsenceTerm> {
24
public class PresenceAbsenceMenuPreferences extends AbstractMenuPreferences<PresenceAbsenceTerm> implements
25
		IWorkbenchPreferencePage {
23 26

  
24 27
	/**
25 28
	 * <p>Constructor for PresenceAbsenceMenuPreferences.</p>
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/menu/RankMenuPreferences.java
13 13
import org.eclipse.swt.events.SelectionEvent;
14 14
import org.eclipse.swt.widgets.Button;
15 15
import org.eclipse.swt.widgets.Composite;
16
import org.eclipse.ui.IWorkbenchPreferencePage;
16 17

  
17 18
import eu.etaxonomy.cdm.model.common.TermType;
18 19
import eu.etaxonomy.cdm.model.name.Rank;
......
27 28
 * @created 17.09.2008
28 29
 * @version 1.0
29 30
 */
30
public class RankMenuPreferences extends AbstractMenuPreferences<Rank> {
31
public class RankMenuPreferences extends AbstractMenuPreferences<Rank> implements
32
		IWorkbenchPreferencePage {
31 33

  
32 34
	/** Constant <code>PLUGIN_ID="eu.etaxonomy.taxeditor.preferences.rank"{trunked}</code> */
33 35
	public static final String PLUGIN_ID = "eu.etaxonomy.taxeditor.preferences.ranks";
eu.etaxonomy.taxeditor.workbench/META-INF/MANIFEST.MF
1 1
Manifest-Version: 1.0
2 2
Bundle-SymbolicName: eu.etaxonomy.taxeditor.workbench;singleton:=true
3
Export-Package: com.opcoach.e4.preferences,
4
 com.opcoach.e4.preferences.handlers,
5
 eu.etaxonomy.taxeditor.bulkeditor,
3
Export-Package: eu.etaxonomy.taxeditor.bulkeditor,
6 4
 eu.etaxonomy.taxeditor.workbench,
7 5
 eu.etaxonomy.taxeditor.workbench.part
8 6
Bundle-Name: Workbench Bundle
eu.etaxonomy.taxeditor.workbench/build.properties
5 5
               plugin.xml,\
6 6
               OSGI-INF/,\
7 7
               fragment.e4xmi,\
8
               OSGI-INF/l10n/bundle.properties,\
9
               schema/
8
               OSGI-INF/l10n/bundle.properties
eu.etaxonomy.taxeditor.workbench/fragment.e4xmi
45 45
          <children xsi:type="menu:MenuSeparator" xmi:id="_OUNVYLMnEeeMU61m8yqdaA" elementId="eu.etaxonomy.taxeditor.workbench.menuseparator.referencing"/>
46 46
        </children>
47 47
        <children xsi:type="menu:MenuSeparator" xmi:id="_FaGnuCQNEeen_7LZsZSNoA" elementId="eu.etaxonomy.taxeditor.application.windowMenu.last"/>
48
        <children xsi:type="menu:HandledMenuItem" xmi:id="_FaGnuSQNEeen_7LZsZSNoA" elementId="org.eclipse.ui.main.menu.window.preferences" label="%command.label.12" command="_gYnhIKnTEeeTAPHmaMLwQQ"/>
48
        <children xsi:type="menu:HandledMenuItem" xmi:id="_FaGnuSQNEeen_7LZsZSNoA" elementId="org.eclipse.ui.main.menu.window.preferences" label="%command.label.12" command="_l9kXoB7PEeeC-JvycL9ysA"/>
49 49
      </children>
50 50
      <children xsi:type="menu:Menu" xmi:id="_FaGnuiQNEeen_7LZsZSNoA" elementId="eu.etaxonomy.taxeditor.workbench.menu.admin" label="%menu.label.4" mnemonics="A">
51 51
        <children xsi:type="menu:HandledMenuItem" xmi:id="_b4RFsCQsEeeq76l4saMAFQ" elementId="eu.etaxonomy.taxeditor.workbench.menu.admin.dbpreferences" label="%command.label.23" command="_VawPsCQsEeeq76l4saMAFQ">
......
107 107
    <elements xsi:type="commands:Command" xmi:id="_hMjgECZsEeer_rabtodzWA" elementId="eu.etaxonomy.taxeditor.command.openPart" commandName="Open Part">
108 108
      <parameters xmi:id="_hMjgESZsEeer_rabtodzWA" elementId="eu.etaxonomy.taxeditor.workbench.commandparameter.partName" name="partName" optional="false"/>
109 109
    </elements>
110
    <elements xsi:type="commands:Command" xmi:id="_gYnhIKnTEeeTAPHmaMLwQQ" elementId="eu.etaxonomy.taxeditor.workbench.preferences" commandName="%command.label.12"/>
111 110
  </fragments>
112 111
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_WLNcQCQsEeeq76l4saMAFQ" featurename="handlers" parentElementId="org.eclipse.e4.legacy.ide.application">
113 112
    <elements xsi:type="commands:Handler" xmi:id="_WLNcQSQsEeeq76l4saMAFQ" elementId="eu.etaxonomy.taxeditor.OpenExternalAboutPlatformHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.workbench/eu.etaxonomy.taxeditor.workbench.OpenExternalAboutPlatformHandler" command="_UZ2zYCQsEeeq76l4saMAFQ"/>
......
119 118
    <elements xsi:type="commands:Handler" xmi:id="_nSIiECUKEeeHw5lTgGMs1Q" elementId="eu.etaxonomy.taxeditor.handler.OpenImportPreferenceHandler" command="_fdEqUCUKEeeHw5lTgGMs1Q"/>
120 119
    <elements xsi:type="commands:Handler" xmi:id="_2fnUYCZ0EeeQLpuomSmVoQ" elementId="eu.etaxonomy.taxeditor.workbench.OpenPartHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.workbench/eu.etaxonomy.taxeditor.workbench.OpenPartHandler" command="_hMjgECZsEeer_rabtodzWA"/>
121 120
    <elements xsi:type="commands:Handler" xmi:id="_dBGosFp0Eee4PsIXei-TMg" elementId="eu.etaxonomy.taxeditor.workbench.SaveHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.workbench/eu.etaxonomy.taxeditor.workbench.SaveHandler" command="_X-56IFp0Eee4PsIXei-TMg"/>
122
    <elements xsi:type="commands:Handler" xmi:id="_zP4pcKnQEeeTAPHmaMLwQQ" elementId="com.opcoach.e4.preferences.handlers.E4PreferencesHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.workbench/com.opcoach.e4.preferences.handlers.E4PreferencesHandler" command="_gYnhIKnTEeeTAPHmaMLwQQ"/>
123 121
  </fragments>
124 122
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_Z4f0kFsaEeebk7BsM35KOg" featurename="children" parentElementId="org.eclipse.ui.contexts.dialogAndWindow">
125 123
    <elements xsi:type="commands:BindingContext" xmi:id="_5pEDMFsaEeebk7BsM35KOg" elementId="eu.etaxonomy.taxeditor.workbench.bindingcontext" name="Taxonomic Editor Keybinding Context"/>
eu.etaxonomy.taxeditor.workbench/schema/e4PreferencePages.exsd
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="com.opcoach.e4.preferences" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
5
      <appinfo>
6
         <meta.schema plugin="com.opcoach.e4.preferences" id="e4PreferencePages" name="e4PreferencePages"/>
7
      </appinfo>
8
      <documentation>
9
         [Enter description of this extension point.]
10
      </documentation>
11
   </annotation>
12

  
13
   <element name="extension">
14
      <annotation>
15
         <appinfo>
16
            <meta.element />
17
         </appinfo>
18
      </annotation>
19
      <complexType>
20
         <sequence>
21
            <element ref="page" minOccurs="0" maxOccurs="unbounded"/>
22
         </sequence>
23
         <attribute name="point" type="string" use="required">
24
            <annotation>
25
               <documentation>
26
                  a fully qualified identifier of the target extension point
27
               </documentation>
28
            </annotation>
29
         </attribute>
30
         <attribute name="id" type="string">
31
            <annotation>
32
               <documentation>
33
                  an optional identifier of the extension instance
34
               </documentation>
35
            </annotation>
36
         </attribute>
37
         <attribute name="name" type="string">
38
            <annotation>
39
               <documentation>
40
                  an optional name of the extension instance
41
               </documentation>
42
               <appinfo>
43
                  <meta.attribute translatable="true"/>
44
               </appinfo>
45
            </annotation>
46
         </attribute>
47
      </complexType>
48
   </element>
49

  
50
   <element name="page">
51
      <annotation>
52
         <appinfo>
53
            <meta.element labelAttribute="name"/>
54
         </appinfo>
55
      </annotation>
56
      <complexType>
57
         <sequence>
58
            <element ref="keywordReference" minOccurs="0" maxOccurs="unbounded"/>
59
         </sequence>
60
         <attribute name="id" type="string" use="required">
61
            <annotation>
62
               <documentation>
63
                  a unique name that will be used to identify this page.
64
               </documentation>
65
            </annotation>
66
         </attribute>
67
         <attribute name="name" type="string" use="required">
68
            <annotation>
69
               <documentation>
70
                  a translatable name that will be used in the UI for this page.
71
               </documentation>
72
               <appinfo>
73
                  <meta.attribute translatable="true"/>
74
               </appinfo>
75
            </annotation>
76
         </attribute>
77
         <attribute name="class" type="string" use="required">
78
            <annotation>
79
               <documentation>
80
                  a name of the fully qualified class that implements 
81
&lt;samp&gt;org.eclipse.jface.preference.IPreferencePage&lt;/samp&gt;.
82

  
83
IT IS EASYER to extend FieldEditorPreferencePage 
84

  
85
If this class extends directly org.eclipse.jface.preference.FieldEditorPreferencePage preferenceStore is automatically set on it.
86
               </documentation>
87
               <appinfo>
88
                  <meta.attribute kind="java" basedOn="org.eclipse.jface.preference.FieldEditorPreferencePage:"/>
89
               </appinfo>
90
            </annotation>
91
         </attribute>
92
         <attribute name="category" type="string">
93
            <annotation>
94
               <documentation>
95
                  a path indicating the location of the page in the preference tree. The path may either be a parent node ID or a sequence
96
     of IDs separated by &apos;/&apos;, representing the full path from the root node.
97
               </documentation>
98
               <appinfo>
99
                  <meta.attribute kind="identifier" basedOn="com.opcoach.e4.preferences.e4PreferencePages/page/@id"/>
100
               </appinfo>
101
            </annotation>
102
         </attribute>
103
      </complexType>
104
   </element>
105

  
106
   <element name="keywordReference">
107
      <annotation>
108
         <documentation>
109
            A reference by a preference page to a keyword. See the keywords extension point.
110
         </documentation>
111
      </annotation>
112
      <complexType>
113
         <attribute name="id" type="string" use="required">
114
            <annotation>
115
               <documentation>
116
                  The id of the keyword being referred to.
117
               </documentation>
118
               <appinfo>
119
                  <meta.attribute kind="identifier" basedOn="org.eclipse.ui.keywords/keyword/@id"/>
120
               </appinfo>
121
            </annotation>
122
         </attribute>
123
      </complexType>
124
   </element>
125

  
126
   <annotation>
127
      <appinfo>
128
         <meta.section type="since"/>
129
      </appinfo>
130
      <documentation>
131
         [Enter the first release in which this extension point appears.]
132
      </documentation>
133
   </annotation>
134

  
135
   <annotation>
136
      <appinfo>
137
         <meta.section type="examples"/>
138
      </appinfo>
139
      <documentation>
140
         [Enter extension point usage example here.]
141
      </documentation>
142
   </annotation>
143

  
144
   <annotation>
145
      <appinfo>
146
         <meta.section type="apiinfo"/>
147
      </appinfo>
148
      <documentation>
149
         [Enter API information here.]
150
      </documentation>
151
   </annotation>
152

  
153
   <annotation>
154
      <appinfo>
155
         <meta.section type="implementation"/>
156
      </appinfo>
157
      <documentation>
158
         [Enter information about supplied implementation of this extension point.]
159
      </documentation>
160
   </annotation>
161

  
162

  
163
</schema>
eu.etaxonomy.taxeditor.workbench/schema/e4PreferenceStoreProvider.exsd
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="com.opcoach.e4.preferences" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
5
      <appinfo>
6
         <meta.schema plugin="com.opcoach.e4.preferences" id="e4PreferenceStoreProvider" name="e4PreferenceStoreProvider"/>
7
      </appinfo>
8
      <documentation>
9
         This extension point is used to associate a preference store to a plugin. 
10
You can choose either to implement the IPreferenceStoreProvider interface or to give the ID of the IPreferenceStore to use (stored in the workbench context of your E4 application). 
11
If this extension point is not used, a default ScopedPreferenceStore will be used for the preference page. 
12

  
13
      </documentation>
14
   </annotation>
15

  
16
   <element name="extension">
17
      <annotation>
18
         <appinfo>
19
            <meta.element />
20
         </appinfo>
21
      </annotation>
22
      <complexType>
23
         <sequence>
24
            <element ref="preferenceStoreProvider" minOccurs="1" maxOccurs="unbounded"/>
25
         </sequence>
26
         <attribute name="point" type="string" use="required">
27
            <annotation>
28
               <documentation>
29
                  
30
               </documentation>
31
            </annotation>
32
         </attribute>
33
         <attribute name="id" type="string">
34
            <annotation>
35
               <documentation>
36
                  
37
               </documentation>
38
            </annotation>
39
         </attribute>
40
         <attribute name="name" type="string">
41
            <annotation>
42
               <documentation>
43
                  
44
               </documentation>
45
               <appinfo>
46
                  <meta.attribute translatable="true"/>
47
               </appinfo>
48
            </annotation>
49
         </attribute>
50
      </complexType>
51
   </element>
52

  
53
   <element name="preferenceStoreProvider">
54
      <complexType>
55
         <attribute name="pluginId" type="string" use="required">
56
            <annotation>
57
               <documentation>
58
                  Set here the plugin Id concerned by this extension. 
59
Must be a valid plugin ID (control will be done at runtime)
60
               </documentation>
61
            </annotation>
62
         </attribute>
63
         <attribute name="class" type="string">
64
            <annotation>
65
               <documentation>
66
                  Set a class to get the IPreferenceStore for the defined pluginID. 
67
This parameter is optional if you use the contextId attribute.
68
               </documentation>
69
               <appinfo>
70
                  <meta.attribute kind="java" basedOn=":com.opcoach.e4.preferences.IPreferenceStoreProvider"/>
71
               </appinfo>
72
            </annotation>
73
         </attribute>
74
         <attribute name="idInWorkbenchContext" type="string">
75
            <annotation>
76
               <documentation>
77
                  If no class is defined, you can set here the ID of the IPreferenceStore available in the context. 
78
This object must be set in the workbenchContext using an Addon for instance, with the following code (in addon): 
79

  
80
@PostContextCreate
81
public void initMyAddon(IEclipseContext ctx)
82
{
83
    IPreferenceStore ps = new ... .  // The code to create your pref store
84
    ctx.set(ID set in this extension,  ps);
85
}
86
               </documentation>
87
            </annotation>
88
         </attribute>
89
      </complexType>
90
   </element>
91

  
92
   <annotation>
93
      <appinfo>
94
         <meta.section type="since"/>
95
      </appinfo>
96
      <documentation>
97
         [Enter the first release in which this extension point appears.]
98
      </documentation>
99
   </annotation>
100

  
101
   <annotation>
102
      <appinfo>
103
         <meta.section type="examples"/>
104
      </appinfo>
105
      <documentation>
106
         The definition could be like the following : 
107

  
108
pluginId=&quot;yourPluginID&quot;
109
provider=&quot;a class implementing IPreferenceStoreProvider&quot;
110

  
111

  
112
Or using the key in context (usefull to share the same preference store between plugins) : 
113

  
114
pluginId=&quot;yourPluginID&quot;
115
keyInContext=&quot;the key of the IPreferenceStore stored in context&quot;
116

  
117

  
118

  
119
      </documentation>
120
   </annotation>
121

  
122
   <annotation>
123
      <appinfo>
124
         <meta.section type="apiinfo"/>
125
      </appinfo>
126
      <documentation>
127
         [Enter API information here.]
128
      </documentation>
129
   </annotation>
130

  
131
   <annotation>
132
      <appinfo>
133
         <meta.section type="implementation"/>
134
      </appinfo>
135
      <documentation>
136
         [Enter information about supplied implementation of this extension point.]
137
      </documentation>
138
   </annotation>
139

  
140
   <annotation>
141
      <appinfo>
142
         <meta.section type="copyright"/>
143
      </appinfo>
144
      <documentation>
145
         @OPCoach 2014
146
      </documentation>
147
   </annotation>
148

  
149
</schema>
eu.etaxonomy.taxeditor.workbench/src/main/java/com/opcoach/e4/preferences/E4PreferenceRegistry.java
1
/*******************************************************************************
2
 * Copyright (c) 2014 OPCoach.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     OPCoach - initial API and implementation
10
 *******************************************************************************/
11
package com.opcoach.e4.preferences;
12

  
13
import java.util.ArrayList;
14
import java.util.Collection;
15
import java.util.Collections;
16
import java.util.HashMap;
17
import java.util.Map;
18

  
19
import javax.inject.Inject;
20

  
21
import org.eclipse.core.runtime.IConfigurationElement;
22
import org.eclipse.core.runtime.IExtensionRegistry;
23
import org.eclipse.core.runtime.preferences.InstanceScope;
24
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
25
import org.eclipse.e4.core.contexts.IEclipseContext;
26
import org.eclipse.e4.core.di.annotations.Creatable;
27
import org.eclipse.e4.core.services.contributions.IContributionFactory;
28
import org.eclipse.e4.core.services.log.Logger;
29
import org.eclipse.jface.preference.IPreferenceNode;
30
import org.eclipse.jface.preference.IPreferenceStore;
31
import org.eclipse.jface.preference.PreferenceManager;
32
import org.eclipse.jface.preference.PreferenceNode;
33
import org.eclipse.jface.preference.PreferencePage;
34
import org.eclipse.swt.SWT;
35
import org.eclipse.swt.widgets.Composite;
36
import org.eclipse.swt.widgets.Control;
37
import org.eclipse.swt.widgets.Label;
38

  
39
@Creatable
40
public class E4PreferenceRegistry
41
{
42

  
43
	public static final String PREFS_PAGE_XP = "eu.etaxonomy.taxeditor.workbench.e4PreferencePages"; // $NON-NLS-1$
44
	public static final String PREF_STORE_PROVIDER = "eu.etaxonomy.taxeditor.workbench.e4PreferenceStoreProvider"; // $NON-NLS-1$
45
	protected static final String ELMT_PAGE = "page"; // $NON-NLS-1$
46
	protected static final String ATTR_ID = "id"; // $NON-NLS-1$
47
	protected static final String ATTR_CATEGORY = "category"; // $NON-NLS-1$
48
	protected static final String ATTR_CLASS = "class"; // $NON-NLS-1$
49
	protected static final String ATTR_NAME = "name"; // $NON-NLS-1$
50

  
51
	protected static final String ATTR_PLUGIN_ID = "pluginId"; // $NON-NLS-1$
52
	protected static final String ATTR_ID_IN_WBCONTEXT = "idInWorkbenchContext"; // $NON-NLS-1$
53

  
54
	@Inject
55
	protected Logger logger;
56

  
57
	@Inject
58
	protected IEclipseContext context;
59

  
60
	@Inject
61
	protected IExtensionRegistry registry;
62

  
63
	private PreferenceManager pm = null;
64

  
65
	// A map of (pluginId, { IPreferenceStoreProvider, or key in wbcontext }
66
	private Map<String, Object> psProviders;
67

  
68
	public PreferenceManager getPreferenceManager()
69
	{
70

  
71
		// Remember of the unbounded nodes to order parent pages.
72
		// Map<category, list of children> (all nodes except root nodes)
73
		Map<String, Collection<IPreferenceNode>> childrenNodes = new HashMap<String, Collection<IPreferenceNode>>();
74

  
75
		if (pm != null) {
76
            return pm;
77
        }
78

  
79
		pm = new PreferenceManager();
80
		IContributionFactory factory = context.get(IContributionFactory.class);
81

  
82
		for (IConfigurationElement elmt : registry.getConfigurationElementsFor(PREFS_PAGE_XP))
83
		{
84
			String bundleId = elmt.getNamespaceIdentifier();
85
			if (!elmt.getName().equals(ELMT_PAGE))
86
			{
87
				logger.warn("unexpected element: {0}", elmt.getName());
88
				continue;
89
			} else if (isEmpty(elmt.getAttribute(ATTR_ID)) || isEmpty(elmt.getAttribute(ATTR_NAME)))
90
			{
91
				logger.warn("missing id and/or name: {}", bundleId);
92
				continue;
93
			}
94
			PreferenceNode pn = null;
95
			if (elmt.getAttribute(ATTR_CLASS) != null)
96
			{
97
				PreferencePage page = null;
98
				try
99
				{
100
					String prefPageURI = getClassURI(bundleId, elmt.getAttribute(ATTR_CLASS));
101
					Object object = factory.create(prefPageURI, context);
102
					if (!(object instanceof PreferencePage))
103
					{
104
						logger.error("Expected instance of PreferencePage: {0}", elmt.getAttribute(ATTR_CLASS));
105
						continue;
106
					}
107
					page = (PreferencePage) object;
108
					setPreferenceStore(bundleId, page);
109

  
110
				} catch (ClassNotFoundException e)
111
				{
112
					logger.error(e);
113
					continue;
114
				}
115
				ContextInjectionFactory.inject(page, context);
116
				if ((page.getTitle() == null || page.getTitle().isEmpty()) && elmt.getAttribute(ATTR_NAME) != null)
117
				{
118
					page.setTitle(elmt.getAttribute(ATTR_NAME));
119
				}
120

  
121
				pn = new PreferenceNode(elmt.getAttribute(ATTR_ID), page);
122
			} else
123
			{
124
				pn = new PreferenceNode(elmt.getAttribute(ATTR_ID), new EmptyPreferencePage(elmt.getAttribute(ATTR_NAME)));
125
			}
126

  
127
			// Issue 2 : Fix bug on order (see :
128
			// https://github.com/opcoach/e4Preferences/issues/2)
129
			// Add only pages at root level and remember of child pages for
130
			// categories
131
			String category = elmt.getAttribute(ATTR_CATEGORY);
132
			if (isEmpty(category))
133
			{
134
				pm.addToRoot(pn);
135
			} else
136
			{
137
				/*
138
				 * IPreferenceNode parent = findNode(pm, category); if (parent
139
				 * == null) { // No parent found, but may be the extension has
140
				 * not been read yet. So remember of it unboundedNodes.put(pn,
141
				 * category); } else { parent.add(pn); }
142
				 */
143
				// Check if this category is already registered.
144
				Collection<IPreferenceNode> children = childrenNodes.get(category);
145
				if (children == null)
146
				{
147
					children = new ArrayList<IPreferenceNode>();
148
					childrenNodes.put(category, children);
149
				}
150
				children.add(pn);
151
			}
152
		}
153

  
154
		// Must now bind pages that has not been added in nodes (depends on the
155
		// preference page read order)
156
		// Iterate on all possible categories
157
		Collection<String> categoriesDone = new ArrayList<String>();
158

  
159
		while (!childrenNodes.isEmpty())
160
		{
161
			for (String cat : Collections.unmodifiableSet(childrenNodes.keySet()))
162
			{
163
				// Is this category already in preference manager ? If not add
164
				// it later...
165
				IPreferenceNode parent = findNode(pm, cat);
166
				if (parent != null)
167
				{
168
					// Can add the list of children to this parent page...
169
					for (IPreferenceNode pn : childrenNodes.get(cat))
170
					{
171
						parent.add(pn);
172
					}
173
					// Ok This parent page is done. Can remove it from map
174
					// outside of this loop
175
					categoriesDone.add(cat);
176
				}
177
			}
178

  
179
			for (String keyToRemove : categoriesDone) {
180
                childrenNodes.remove(keyToRemove);
181
            }
182
			categoriesDone.clear();
183

  
184
		}
185

  
186
		return pm;
187
	}
188

  
189
	private void setPreferenceStore(String bundleId, PreferencePage page)
190
	{
191
		// Affect preference store to this page if this is a
192
		// PreferencePage, else, must manage it internally
193
		// Set the issue#1 on github :
194
		// https://github.com/opcoach/e4Preferences/issues/1
195
		// And manage the extensions of IP
196
		initialisePreferenceStoreProviders();
197

  
198
		IPreferenceStore store = null;
199

  
200
		// Get the preference store according to policy.
201
		Object data = psProviders.get(bundleId);
202
		if (data != null)
203
		{
204
			if (data instanceof IPreferenceStore) {
205
                store = (IPreferenceStore) data;
206
            } else if (data instanceof IPreferenceStoreProvider) {
207
                store = ((IPreferenceStoreProvider) data).getPreferenceStore();
208
            } else if (data instanceof String) {
209
                store = (IPreferenceStore) context.get((String) data);
210
            }
211

  
212
		} else
213
		{
214
			// Default behavior : create a preference store for this bundle and remember of it
215
			store = new ScopedPreferenceStore(InstanceScope.INSTANCE, bundleId);
216
			psProviders.put(bundleId, store);
217
		}
218

  
219

  
220
		if (store != null) {
221
            page.setPreferenceStore(store);
222
        } else
223
		{
224
			logger.warn("Unable to set the preferenceStore for page " + page.getTitle() + " defined in bundle " + bundleId);
225
		}
226

  
227
	}
228

  
229
	/** Read the e4PreferenceStoreProvider extension point */
230
	private void initialisePreferenceStoreProviders()
231
	{
232
		if (psProviders == null)
233
		{
234
			IContributionFactory factory = context.get(IContributionFactory.class);
235

  
236
			psProviders = new HashMap<String, Object>();
237

  
238
			// Read extensions and fill the map...
239
			for (IConfigurationElement elmt : registry.getConfigurationElementsFor(PREF_STORE_PROVIDER))
240
			{
241
				String declaringBundle = elmt.getNamespaceIdentifier();
242
				String pluginId = elmt.getAttribute(ATTR_PLUGIN_ID);
243
				if (isEmpty(pluginId))
244
				{
245
					logger.warn("missing plugin Id in extension " + PREF_STORE_PROVIDER + " check the plugin " + declaringBundle);
246
					continue;
247
				}
248

  
249
				String classname = elmt.getAttribute(ATTR_CLASS);
250
				String objectId = elmt.getAttribute(ATTR_ID_IN_WBCONTEXT);
251

  
252
				if ((isEmpty(classname) && isEmpty(objectId)) || (((classname != null) && classname.length() > 0) && ((objectId != null) && objectId.length() > 0)))
253
				{
254
					logger.warn("In extension " + PREF_STORE_PROVIDER + " only one of the two attributes (pluginId or idInWorkbenchContext) must be set. Check the plugin "
255
							+ declaringBundle);
256
					continue;
257
				}
258

  
259
				// Ok can now work with data...
260
				Object data = objectId;
261
				if (classname != null)
262
				{
263
					data = factory.create(classname, context);
264
					if (!(data instanceof IPreferenceStoreProvider))
265
					{
266
						logger.warn("In extension " + PREF_STORE_PROVIDER + " the class must implements IPreferenceStoreProvider. Check the plugin " + declaringBundle);
267
						continue;
268
					}
269
				}
270

  
271
				psProviders.put(pluginId, data);
272

  
273
			}
274
		}
275
	}
276

  
277
	private IPreferenceNode findNode(PreferenceManager pm, String categoryId)
278
	{
279
		for (Object o : pm.getElements(PreferenceManager.POST_ORDER))
280
		{
281
			if (o instanceof IPreferenceNode && ((IPreferenceNode) o).getId().equals(categoryId))
282
			{
283
				return (IPreferenceNode) o;
284
			}
285
		}
286
		return null;
287
	}
288

  
289
	private String getClassURI(String definingBundleId, String spec) throws ClassNotFoundException
290
	{
291
		if (spec.startsWith("platform:"))
292
		{
293
			return spec;
294
		} // $NON-NLS-1$
295
		return "bundleclass://" + definingBundleId + '/' + spec;
296
	}
297

  
298
	private boolean isEmpty(String value)
299
	{
300
		return value == null || value.trim().isEmpty();
301
	}
302

  
303
	static class EmptyPreferencePage extends PreferencePage
304
	{
305

  
306
		public EmptyPreferencePage(String title)
307
		{
308
			setTitle(title);
309
			noDefaultAndApplyButton();
310
		}
311

  
312
		@Override
313
		protected Control createContents(Composite parent)
314
		{
315
			return new Label(parent, SWT.NONE);
316
		}
317

  
318
	}
319

  
320
}
eu.etaxonomy.taxeditor.workbench/src/main/java/com/opcoach/e4/preferences/IPreferenceStoreProvider.java
1
/*******************************************************************************
2
 * Copyright (c) 2014 OPCoach.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     OPCoach - initial API and implementation
10
 *******************************************************************************/
11
package com.opcoach.e4.preferences;
12

  
13
import org.eclipse.jface.preference.IPreferenceStore;
14

  
15
/** This interface can be implemented to provide a PreferenceStore for a given plugin. 
16
 * This associatino must be done in the e4PreferenceStoreProvider extension point. 
17
 * @author olivier
18
 *
19
 */
20
public interface IPreferenceStoreProvider
21
{
22
	/** Must be implemented to return a preference store */
23
	public IPreferenceStore getPreferenceStore();
24

  
25
}
eu.etaxonomy.taxeditor.workbench/src/main/java/com/opcoach/e4/preferences/ScopedPreferenceStore.java
1

  
2
/*******************************************************************************
3
 * Copyright (c) 2014 OPCoach.
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *     Eclipse - copy of the implementation coming from jface 
11
 *******************************************************************************/
12

  
13
package com.opcoach.e4.preferences;
14

  
15
import java.io.IOException;
16

  
17
import org.eclipse.core.commands.common.EventManager;
18
import org.eclipse.core.runtime.Assert;
19
import org.eclipse.core.runtime.Platform;
20
import org.eclipse.core.runtime.Plugin;
21
import org.eclipse.core.runtime.SafeRunner;
22
import org.eclipse.core.runtime.preferences.DefaultScope;
23
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
24
import org.eclipse.core.runtime.preferences.IScopeContext;
25
import org.eclipse.core.runtime.preferences.IEclipsePreferences.INodeChangeListener;
26
import org.eclipse.core.runtime.preferences.IEclipsePreferences.NodeChangeEvent;
27
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
28
import org.eclipse.jface.preference.IPersistentPreferenceStore;
29
import org.eclipse.jface.preference.IPreferenceStore;
30
import org.eclipse.jface.resource.JFaceResources;
31
import org.eclipse.jface.util.IPropertyChangeListener;
32
import org.eclipse.jface.util.PropertyChangeEvent;
33
import org.eclipse.jface.util.SafeRunnable;
34
import org.osgi.service.prefs.BackingStoreException;
35

  
36
/**
37
 * The ScopedPreferenceStore is an IPreferenceStore that uses the scopes
38
 * provided in org.eclipse.core.runtime.preferences.
39
 * <p>
40
 * A ScopedPreferenceStore does the lookup of a preference based on it's search
41
 * scopes and sets the value of the preference based on its store scope.
42
 * </p>
43
 * <p>
44
 * The default scope is always included in the search scopes when searching for
45
 * preference values.
46
 * </p>
47
 * 
48
 * @see org.eclipse.core.runtime.preferences
49
 * @since 3.1
50
 */
51
public class ScopedPreferenceStore extends EventManager implements
52
		IPreferenceStore, IPersistentPreferenceStore {
53

  
54
	/**
55
	 * The storeContext is the context where values will stored with the
56
	 * setValue methods. If there are no searchContexts this will be the search
57
	 * context. (along with the "default" context)
58
	 */
59
	private IScopeContext storeContext;
60

  
61
	/**
62
	 * The searchContext is the array of contexts that will be used by the get
63
	 * methods for searching for values.
64
	 */
65
	private IScopeContext[] searchContexts;
66

  
67
	/**
68
	 * A boolean to indicate the property changes should not be propagated.
69
	 */
70
	protected boolean silentRunning = false;
71

  
72
	/**
73
	 * The listener on the IEclipsePreferences. This is used to forward updates
74
	 * to the property change listeners on the preference store.
75
	 */
76
	IEclipsePreferences.IPreferenceChangeListener preferencesListener;
77

  
78
	/**
79
	 * The default context is the context where getDefault and setDefault
80
	 * methods will search. This context is also used in the search.
81
	 */
82
	private IScopeContext defaultContext = new DefaultScope();
83

  
84
	/**
85
	 * The nodeQualifer is the string used to look up the node in the contexts.
86
	 */
87
	String nodeQualifier;
88

  
89
	/**
90
	 * The defaultQualifier is the string used to look up the default node.
91
	 */
92
	String defaultQualifier;
93

  
94
	/**
95
	 * Boolean value indicating whether or not this store has changes to be
96
	 * saved.
97
	 */
98
	private boolean dirty;
99

  
100
	/**
101
	 * Create a new instance of the receiver. Store the values in context in the
102
	 * node looked up by qualifier. <strong>NOTE:</strong> Any instance of
103
	 * ScopedPreferenceStore should call
104
	 * 
105
	 * @param context
106
	 *            the scope to store to
107
	 * @param qualifier
108
	 *            the qualifier used to look up the preference node
109
	 * @param defaultQualifierPath
110
	 *            the qualifier used when looking up the defaults
111
	 */
112
	public ScopedPreferenceStore(IScopeContext context, String qualifier,
113
			String defaultQualifierPath) {
114
		this(context, qualifier);
115
		this.defaultQualifier = defaultQualifierPath;
116
	}
117

  
118
	/**
119
	 * Create a new instance of the receiver. Store the values in context in the
120
	 * node looked up by qualifier.
121
	 * 
122
	 * @param context
123
	 *            the scope to store to
124
	 * @param qualifier
125
	 *            the qualifer used to look up the preference node
126
	 */
127
	public ScopedPreferenceStore(IScopeContext context, String qualifier) {
128
		storeContext = context;
129
		this.nodeQualifier = qualifier;
130
		this.defaultQualifier = qualifier;
131

  
132
		((IEclipsePreferences) getStorePreferences().parent())
133
				.addNodeChangeListener(getNodeChangeListener());
134
	}
135

  
136
	/**
137
	 * Return a node change listener that adds a removes the receiver when nodes
138
	 * change.
139
	 * 
140
	 * @return INodeChangeListener
141
	 */
142
	private INodeChangeListener getNodeChangeListener() {
143
		return new IEclipsePreferences.INodeChangeListener() {
144
			/*
145
			 * (non-Javadoc)
146
			 * 
147
			 * @see org.eclipse.core.runtime.preferences.IEclipsePreferences.INodeChangeListener#added(org.eclipse.core.runtime.preferences.IEclipsePreferences.NodeChangeEvent)
148
			 */
149
			public void added(NodeChangeEvent event) {
150
				if (nodeQualifier.equals(event.getChild().name())
151
						&& isListenerAttached()) {
152
					getStorePreferences().addPreferenceChangeListener(
153
							preferencesListener);
154
				}
155
			}
156

  
157
			/*
158
			 * (non-Javadoc)
159
			 * 
160
			 * @see org.eclipse.core.runtime.preferences.IEclipsePreferences.INodeChangeListener#removed(org.eclipse.core.runtime.preferences.IEclipsePreferences.NodeChangeEvent)
161
			 */
162
			public void removed(NodeChangeEvent event) {
163
				// Do nothing as there are no events from removed node
164
			}
165
		};
166
	}
167

  
168
	/**
169
	 * Initialize the preferences listener.
170
	 */
171
	private void initializePreferencesListener() {
172
		if (preferencesListener == null) {
173
			preferencesListener = new IEclipsePreferences.IPreferenceChangeListener() {
174
				/*
175
				 * (non-Javadoc)
176
				 * 
177
				 * @see org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener#preferenceChange(org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent)
178
				 */
179
				public void preferenceChange(PreferenceChangeEvent event) {
180

  
181
					if (silentRunning) {
182
						return;
183
					}
184

  
185
					Object oldValue = event.getOldValue();
186
					Object newValue = event.getNewValue();
187
					String key = event.getKey();
188
					if (newValue == null) {
189
						newValue = getDefault(key, oldValue);
190
					} else if (oldValue == null) {
191
						oldValue = getDefault(key, newValue);
192
					}
193
					firePropertyChangeEvent(event.getKey(), oldValue, newValue);
194
				}
195
			};
196
			getStorePreferences().addPreferenceChangeListener(
197
					preferencesListener);
198
		}
199

  
200
	}
201

  
202
	/**
203
	 * Does its best at determining the default value for the given key. Checks
204
	 * the given object's type and then looks in the list of defaults to see if
205
	 * a value exists. If not or if there is a problem converting the value, the
206
	 * default default value for that type is returned.
207
	 * 
208
	 * @param key
209
	 *            the key to search
210
	 * @param obj
211
	 *            the object who default we are looking for
212
	 * @return Object or <code>null</code>
213
	 */
214
	Object getDefault(String key, Object obj) {
215
		IEclipsePreferences defaults = getDefaultPreferences();
216
		if (obj instanceof String) {
217
			return defaults.get(key, STRING_DEFAULT_DEFAULT);
218
		} else if (obj instanceof Integer) {
219
			return new Integer(defaults.getInt(key, INT_DEFAULT_DEFAULT));
220
		} else if (obj instanceof Double) {
221
			return new Double(defaults.getDouble(key, DOUBLE_DEFAULT_DEFAULT));
222
		} else if (obj instanceof Float) {
223
			return new Float(defaults.getFloat(key, FLOAT_DEFAULT_DEFAULT));
224
		} else if (obj instanceof Long) {
225
			return new Long(defaults.getLong(key, LONG_DEFAULT_DEFAULT));
226
		} else if (obj instanceof Boolean) {
227
			return defaults.getBoolean(key, BOOLEAN_DEFAULT_DEFAULT) ? Boolean.TRUE
228
					: Boolean.FALSE;
229
		} else {
230
			return null;
231
		}
232
	}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff