| 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 |
|
package com.bonevich.eclipse.cvsgrapher.prefs; |
| 59 |
|
|
| 60 |
|
import java.util.HashMap; |
| 61 |
|
import java.util.Map; |
| 62 |
|
|
| 63 |
|
import org.eclipse.jface.preference.BooleanFieldEditor; |
| 64 |
|
import org.eclipse.jface.preference.ColorFieldEditor; |
| 65 |
|
import org.eclipse.jface.preference.FieldEditor; |
| 66 |
|
import org.eclipse.jface.preference.PreferencePage; |
| 67 |
|
import org.eclipse.jface.preference.StringFieldEditor; |
| 68 |
|
import org.eclipse.swt.SWT; |
| 69 |
|
import org.eclipse.swt.layout.GridData; |
| 70 |
|
import org.eclipse.swt.layout.GridLayout; |
| 71 |
|
import org.eclipse.swt.widgets.Composite; |
| 72 |
|
import org.eclipse.swt.widgets.Control; |
| 73 |
|
import org.eclipse.swt.widgets.Group; |
| 74 |
|
import org.eclipse.swt.widgets.Label; |
| 75 |
|
import org.eclipse.ui.IWorkbench; |
| 76 |
|
import org.eclipse.ui.IWorkbenchPreferencePage; |
| 77 |
|
|
| 78 |
|
import com.bonevich.eclipse.cvsgrapher.CvsGraphPlugin; |
| 79 |
|
import com.bonevich.eclipse.cvsgrapher.CvsGraphPluginMessages; |
| 80 |
|
import com.bonevich.eclipse.cvsgrapher.CvsGraphPluginResources; |
| 81 |
|
|
| 82 |
|
|
| 83 |
|
|
| 84 |
|
|
| 85 |
|
|
| 86 |
|
|
| 87 |
|
|
| 88 |
|
|
| 89 |
|
public class CvsGrapherPreferencePage |
| 90 |
|
extends PreferencePage |
| 91 |
|
implements IWorkbenchPreferencePage, CvsGraphPluginResources |
| 92 |
|
{ |
| 93 |
|
private static final String PREFERENCE_PAGE_TITLE = "CVSGrapher"; |
| 94 |
|
|
| 95 |
|
|
| 96 |
|
private static final String FIELDEDITOR_COLOR_VERSION = "cvsgrapher.color.version"; |
| 97 |
|
private static final String FIELDEDITOR_COLOR_BRANCH = "cvsgrapher.color.branch"; |
| 98 |
|
|
| 99 |
|
private static final String FIELDEDITOR_MERGETAG_SOURCE = "cvsgrapher.mergetag.pattern.source"; |
| 100 |
|
private static final String FIELDEDITOR_MERGETAG_DEST = "cvsgrapher.mergetag.pattern.destination"; |
| 101 |
|
|
| 102 |
|
private static final String FIELDEDITOR_SHOW_AUTHOR = "cvsgrapher.show.author"; |
| 103 |
|
private static final String FIELDEDITOR_SHOW_TIMESTAMP = "cvsgrapher.show.timestamp"; |
| 104 |
|
private static final String FIELDEDITOR_SHOW_TAGS = "cvsgrapher.show.tags"; |
| 105 |
|
|
| 106 |
0 |
private Map _fieldEditors = new HashMap(); |
| 107 |
|
|
| 108 |
|
public CvsGrapherPreferencePage() |
| 109 |
|
{ |
| 110 |
0 |
super(PREFERENCE_PAGE_TITLE); |
| 111 |
0 |
} |
| 112 |
|
|
| 113 |
|
public void init(IWorkbench workbench) |
| 114 |
|
{ |
| 115 |
0 |
setPreferenceStore(CvsGraphPlugin.getPlugin().getPreferenceStore()); |
| 116 |
0 |
} |
| 117 |
|
|
| 118 |
|
protected Control createContents(Composite parent) |
| 119 |
|
{ |
| 120 |
0 |
Composite top = createContainerWithDescription(parent); |
| 121 |
|
|
| 122 |
0 |
createColorFieldEditors(top); |
| 123 |
0 |
createMergeTagPatternFields(top); |
| 124 |
0 |
createShowAttributesCheckboxGroup(top); |
| 125 |
|
|
| 126 |
0 |
return top; |
| 127 |
|
} |
| 128 |
|
|
| 129 |
|
private void createColorFieldEditors(Composite top) |
| 130 |
|
{ |
| 131 |
0 |
Composite colorFieldCmp = new Composite(top, SWT.LEFT); |
| 132 |
0 |
colorFieldCmp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 133 |
0 |
colorFieldCmp.setLayout(new GridLayout()); |
| 134 |
|
|
| 135 |
0 |
ColorFieldEditor versionColorField = new ColorFieldEditor( |
| 136 |
|
CvsGraphPlugin.PREFERENCE_COLOR_VERSION, |
| 137 |
|
CvsGraphPluginMessages.bind(CVSGRAPHER_PREFS_COLOR_VERSION_LABEL), |
| 138 |
|
colorFieldCmp |
| 139 |
|
); |
| 140 |
|
|
| 141 |
0 |
ColorFieldEditor branchColorField = new ColorFieldEditor( |
| 142 |
|
CvsGraphPlugin.PREFERENCE_COLOR_BRANCH, |
| 143 |
|
CvsGraphPluginMessages.bind(CVSGRAPHER_PREFS_COLOR_BRANCH_LABEL), |
| 144 |
|
colorFieldCmp |
| 145 |
|
); |
| 146 |
0 |
addFieldEditor(FIELDEDITOR_COLOR_BRANCH, branchColorField); |
| 147 |
0 |
addFieldEditor(FIELDEDITOR_COLOR_VERSION, versionColorField); |
| 148 |
0 |
} |
| 149 |
|
|
| 150 |
|
private void createShowAttributesCheckboxGroup(Composite top) |
| 151 |
|
{ |
| 152 |
0 |
Group group1 = new Group(top, SWT.LEFT); |
| 153 |
0 |
group1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 154 |
0 |
GridLayout layout = new GridLayout(); |
| 155 |
0 |
layout.marginWidth = 7; |
| 156 |
0 |
group1.setLayout(layout); |
| 157 |
0 |
group1.setText(CvsGraphPluginMessages.bind(CVSGRAPHER_PREFS_SHOW_LABEL)); |
| 158 |
|
|
| 159 |
0 |
Composite group = new Composite(group1, SWT.NONE); |
| 160 |
0 |
group.setLayoutData(new GridData(GridData.CENTER)); |
| 161 |
0 |
group.setLayout(new GridLayout()); |
| 162 |
|
|
| 163 |
0 |
BooleanFieldEditor useTraceConditionals = new BooleanFieldEditor( |
| 164 |
|
CvsGraphPlugin.PREFERENCE_SHOW_AUTHOR, |
| 165 |
|
CvsGraphPluginMessages.bind(CVSGRAPHER_PREFS_SHOW_AUTHOR_LABEL), |
| 166 |
|
group |
| 167 |
|
); |
| 168 |
0 |
BooleanFieldEditor useDebugConditionals = new BooleanFieldEditor( |
| 169 |
|
CvsGraphPlugin.PREFERENCE_SHOW_TIMESTAMP, |
| 170 |
|
CvsGraphPluginMessages.bind(CVSGRAPHER_PREFS_SHOW_TIMESTAMP_LABEL), |
| 171 |
|
group |
| 172 |
|
); |
| 173 |
0 |
BooleanFieldEditor useInfoConditionals = new BooleanFieldEditor( |
| 174 |
|
CvsGraphPlugin.PREFERENCE_SHOW_TAGS, |
| 175 |
|
CvsGraphPluginMessages.bind(CVSGRAPHER_PREFS_SHOW_TAGS_LABEL), |
| 176 |
|
group |
| 177 |
|
); |
| 178 |
|
|
| 179 |
0 |
addFieldEditor(FIELDEDITOR_SHOW_AUTHOR, useTraceConditionals); |
| 180 |
0 |
addFieldEditor(FIELDEDITOR_SHOW_TIMESTAMP, useDebugConditionals); |
| 181 |
0 |
addFieldEditor(FIELDEDITOR_SHOW_TAGS, useInfoConditionals); |
| 182 |
0 |
} |
| 183 |
|
|
| 184 |
|
private void createMergeTagPatternFields(Composite top) |
| 185 |
|
{ |
| 186 |
0 |
Group group1 = new Group(top, SWT.LEFT); |
| 187 |
0 |
group1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 188 |
0 |
GridLayout layout = new GridLayout(); |
| 189 |
0 |
layout.marginWidth = 7; |
| 190 |
0 |
group1.setLayout(layout); |
| 191 |
0 |
group1.setText(CvsGraphPluginMessages.bind(CVSGRAPHER_PREFS_MERGETAGS_LABEL)); |
| 192 |
|
|
| 193 |
0 |
Composite mergeTagPatternComp = new Composite(group1, SWT.LEFT); |
| 194 |
0 |
mergeTagPatternComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 195 |
0 |
mergeTagPatternComp.setLayout(new GridLayout()); |
| 196 |
|
|
| 197 |
0 |
StringFieldEditor sourceMergeTagPattern = new StringFieldEditor( |
| 198 |
|
CvsGraphPlugin.PREFERENCE_MERGETAG_SOURCE, |
| 199 |
|
CvsGraphPluginMessages.bind(CVSGRAPHER_PREFS_MERGETAG_SOURCE_LABEL), |
| 200 |
|
15, |
| 201 |
|
StringFieldEditor.VALIDATE_ON_FOCUS_LOST, |
| 202 |
|
mergeTagPatternComp |
| 203 |
|
); |
| 204 |
0 |
sourceMergeTagPattern.setEmptyStringAllowed(true); |
| 205 |
|
|
| 206 |
0 |
StringFieldEditor destMergeTagPattern = new StringFieldEditor( |
| 207 |
|
CvsGraphPlugin.PREFERENCE_MERGETAG_DEST, |
| 208 |
|
CvsGraphPluginMessages.bind(CVSGRAPHER_PREFS_MERGETAG_DEST_LABEL), |
| 209 |
|
15, |
| 210 |
|
StringFieldEditor.VALIDATE_ON_FOCUS_LOST, |
| 211 |
|
mergeTagPatternComp |
| 212 |
|
); |
| 213 |
0 |
destMergeTagPattern.setEmptyStringAllowed(true); |
| 214 |
|
|
| 215 |
0 |
addFieldEditor(FIELDEDITOR_MERGETAG_SOURCE, sourceMergeTagPattern); |
| 216 |
0 |
addFieldEditor(FIELDEDITOR_MERGETAG_DEST, destMergeTagPattern); |
| 217 |
0 |
} |
| 218 |
|
|
| 219 |
|
private Composite createContainerWithDescription(Composite parent) |
| 220 |
|
{ |
| 221 |
0 |
Composite top = new Composite(parent, SWT.LEFT); |
| 222 |
0 |
top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| 223 |
0 |
top.setLayout(new GridLayout()); |
| 224 |
|
|
| 225 |
0 |
Label description = new Label(top, SWT.NONE); |
| 226 |
0 |
description.setText(CvsGraphPluginMessages.bind(CVSGRAPHER_PREFS_GENERAL)); |
| 227 |
0 |
return top; |
| 228 |
|
} |
| 229 |
|
|
| 230 |
|
private void addFieldEditor(String name, FieldEditor editor) |
| 231 |
|
{ |
| 232 |
0 |
_fieldEditors.put(name, editor); |
| 233 |
0 |
editor.setPreferencePage(this); |
| 234 |
0 |
editor.setPreferenceStore(getPreferenceStore()); |
| 235 |
0 |
editor.load(); |
| 236 |
0 |
} |
| 237 |
|
|
| 238 |
|
private FieldEditor getFieldEditor(String name) |
| 239 |
|
{ |
| 240 |
0 |
return (FieldEditor) _fieldEditors.get(name); |
| 241 |
|
} |
| 242 |
|
|
| 243 |
|
protected void performDefaults() |
| 244 |
|
{ |
| 245 |
0 |
super.performDefaults(); |
| 246 |
|
|
| 247 |
0 |
loadDefault(FIELDEDITOR_COLOR_VERSION); |
| 248 |
0 |
loadDefault(FIELDEDITOR_COLOR_BRANCH); |
| 249 |
0 |
loadDefault(FIELDEDITOR_MERGETAG_SOURCE); |
| 250 |
0 |
loadDefault(FIELDEDITOR_MERGETAG_DEST); |
| 251 |
0 |
loadDefault(FIELDEDITOR_SHOW_AUTHOR); |
| 252 |
0 |
loadDefault(FIELDEDITOR_SHOW_TIMESTAMP); |
| 253 |
0 |
loadDefault(FIELDEDITOR_SHOW_TAGS); |
| 254 |
0 |
} |
| 255 |
|
|
| 256 |
|
private void loadDefault(String field) |
| 257 |
|
{ |
| 258 |
0 |
FieldEditor editor = getFieldEditor(field); |
| 259 |
0 |
editor.loadDefault(); |
| 260 |
0 |
} |
| 261 |
|
|
| 262 |
|
public boolean performOk() |
| 263 |
|
{ |
| 264 |
0 |
storeValue(FIELDEDITOR_COLOR_VERSION); |
| 265 |
0 |
storeValue(FIELDEDITOR_COLOR_BRANCH); |
| 266 |
0 |
storeValue(FIELDEDITOR_MERGETAG_SOURCE); |
| 267 |
0 |
storeValue(FIELDEDITOR_MERGETAG_DEST); |
| 268 |
0 |
storeValue(FIELDEDITOR_SHOW_AUTHOR); |
| 269 |
0 |
storeValue(FIELDEDITOR_SHOW_TIMESTAMP); |
| 270 |
0 |
storeValue(FIELDEDITOR_SHOW_TAGS); |
| 271 |
|
|
| 272 |
0 |
return super.performOk(); |
| 273 |
|
} |
| 274 |
|
|
| 275 |
|
private void storeValue(String field) |
| 276 |
|
{ |
| 277 |
0 |
FieldEditor editor = getFieldEditor(field); |
| 278 |
0 |
editor.store(); |
| 279 |
0 |
} |
| 280 |
|
|
| 281 |
|
} |