Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4079a5903b3f182b31e865b202372a5fdd93d70b (plain) (blame)
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
/*****************************************************************************
 * Copyright (c) 2009, 2016 CEA LIST, Christian W. Damus, and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr
 *  Thibault Landre (Atos Origin)
 *  Christian W. Damus - bug 485220
 *  
 *****************************************************************************/
package org.eclipse.papyrus.infra.ui.preferences;

import java.util.HashSet;
import java.util.Set;

import org.eclipse.jface.dialogs.DialogPage;
import org.eclipse.jface.preference.FieldEditor;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;

/**
 * The Class AbstractPreferenceGroup.
 * 
 * @since 1.2
 */
public abstract class AbstractPreferenceGroup extends Composite {

	/** The key to find preference */
	private String key;

	/**
	 * The fieldsEditor : a set that will contain all editor in the composite. It is in charge of
	 * loading / storing / setting the preference store / loading default of all its contained field
	 * editor
	 */
	private Set<FieldEditor> fieldsEditor;

	/**
	 * Gets the dialog page.
	 *
	 * @return the dialogPage
	 */
	protected DialogPage getDialogPage() {
		return dialogPage;
	}

	/** The dialog page. */
	protected DialogPage dialogPage;

	/**
	 * Gets the title.
	 *
	 * @return the title
	 */
	public String getKey() {
		return key;
	}

	/**
	 * Sets the title.
	 *
	 * @param title
	 *            the title to set
	 */
	protected void setKey(String title) {
		this.key = title;
	}

	/**
	 * Instantiates a new abstract group.
	 *
	 * @param parent
	 *            the parent of the composite
	 * @param String
	 *            the title of the page
	 * @param dialogPage
	 *            to set the page in field editor
	 */
	public AbstractPreferenceGroup(Composite parent, String key, DialogPage dialogPage) {
		super(parent, SWT.None);
		this.key = key;
		this.dialogPage = dialogPage;
		this.setLayout(new GridLayout());
		fieldsEditor = new HashSet<FieldEditor>();
	}

	/**
	 * Gets an encapsulated composite. This composite is used to contain a FieldEditor and to allow
	 * developers to work with a FieldEditor like Composite element.
	 *
	 * @param parent
	 *            the parent
	 *
	 * @return the encapsulated compo
	 */
	protected final Composite getEncapsulatedComposite(Composite parent) {
		Composite compo = new Composite(parent, SWT.NONE);
		compo.setLayout(new GridLayout());
		return compo;
	}

	/**
	 * Register field editor. It will add the fieldEditor to a map that will be used to
	 * store/load/loadDefault/set the PreferenceStore of contained fieldEditor
	 *
	 * @param fieldEditor
	 *            the fieldEditor to add.
	 */
	protected void addFieldEditor(FieldEditor fieldEditor) {
		fieldsEditor.add(fieldEditor);
	}

	/**
	 * Load preferences of all registered fieldEditors.
	 *
	 * @see org.eclipse.papyrus.infra.AbstractPreferenceGroup.preferences.ui.AbstractGroup#addFieldEditor(FieldEditor)
	 */
	public void load() {
		for (FieldEditor fe : fieldsEditor) {
			fe.load();
		}
	}

	/**
	 * Set the preference store of all registered fieldEditors.
	 *
	 * @see org.eclipse.papyrus.infra.AbstractPreferenceGroup.preferences.ui.AbstractGroup#addFieldEditor(FieldEditor)
	 */
	public final void setPreferenceStore(IPreferenceStore store) {
		for (FieldEditor fe : fieldsEditor) {
			fe.setPreferenceStore(store);
		}
	}

	/**
	 * Load default preferences of all registered fieldEditors.
	 *
	 * @see org.eclipse.papyrus.infra.AbstractPreferenceGroup.preferences.ui.AbstractGroup#addFieldEditor(FieldEditor)
	 */
	public final void loadDefault() {
		for (FieldEditor fe : fieldsEditor) {
			fe.loadDefault();
		}
	}

	/**
	 * Store preferences of the registered fieldEditors.
	 *
	 * @see org.eclipse.papyrus.infra.AbstractPreferenceGroup.preferences.ui.AbstractGroup#addFieldEditor(FieldEditor)
	 */
	public final void storePreferences() {
		for (FieldEditor fe : fieldsEditor) {
			fe.store();
		}
	}

}

Back to the top