Project

General

Profile

« Previous | Next » 

Revision ddcbd609

Added by Alexander Oppermann over 9 years ago

fixed ticket #4367

View differences:

eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/preference/BulkEditorMarkerPreferencePage.java
1 1
// $Id$
2 2
/**
3 3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
4
* European Distributed Institute of Taxonomy
5 5
* http://www.e-taxonomy.eu
6
* 
6
*
7 7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8 8
* See LICENSE.TXT at the top of this package for the full license terms.
9 9
*/
......
25 25
import org.eclipse.ui.IWorkbenchPreferencePage;
26 26

  
27 27
import eu.etaxonomy.cdm.model.common.MarkerType;
28
import eu.etaxonomy.taxeditor.model.MessagingUtils;
28 29
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
30
import eu.etaxonomy.taxeditor.store.CdmStore;
29 31
import eu.etaxonomy.taxeditor.store.TermStore;
30 32

  
31 33
/**
......
45 47
	@Override
46 48
	public void init(IWorkbench workbench) {
47 49
		setPreferenceStore(PreferencesUtil.getPreferenceStore());
48
		markerTypeEditingMap = PreferencesUtil.getEditMarkerTypePreferences();
50
		if(!CdmStore.isActive()) {
51
            MessagingUtils.noDataSourceWarningDialog(null);
52
		}else{
53
		    markerTypeEditingMap = PreferencesUtil.getEditMarkerTypePreferences();
54
		}
49 55
	}
50 56

  
51 57
	/* (non-Javadoc)
......
55 61
	protected Control createContents(Composite parent) {
56 62
		Composite container = new Composite(parent, SWT.NULL);
57 63
		container.setLayout(new GridLayout());
64
        if(CdmStore.isActive()){
65
            for (final MarkerType markerType : TermStore.getTerms(MarkerType.class)) {
66
                final Button button = new Button(container, SWT.CHECK);
67
                button.setText(String.format("Edit '%s' markers", markerType.getLabel()));
58 68

  
59
		for (final MarkerType markerType : TermStore.getTerms(MarkerType.class)) {
60
			final Button button = new Button(container, SWT.CHECK);
61
			button.setText(String.format("Edit '%s' markers", markerType.getLabel()));
62
		
63
			button.addSelectionListener(new SelectionAdapter() {
64
				public void widgetSelected(SelectionEvent e) {
65
					markerTypeEditingMap.put(markerType, button.getSelection());
66
				}
67
			});
68
			
69
			boolean edit = markerTypeEditingMap.get(markerType) == null ? true : markerTypeEditingMap.get(markerType); 
70
			
71
			button.setSelection(edit);
72
		}
73
		
69
                button.addSelectionListener(new SelectionAdapter() {
70
                    @Override
71
                    public void widgetSelected(SelectionEvent e) {
72
                        markerTypeEditingMap.put(markerType, button.getSelection());
73
                    }
74
                });
75

  
76
                boolean edit = markerTypeEditingMap.get(markerType) == null ? true : markerTypeEditingMap.get(markerType);
77

  
78
                button.setSelection(edit);
79
            }
80
        }
74 81
		return container;
75 82
	}
76
	
83

  
77 84
	/* (non-Javadoc)
78 85
	 * @see org.eclipse.jface.preference.PreferencePage#performOk()
79 86
	 */
80 87
	@Override
81 88
	public boolean performOk() {
82 89
		PreferencesUtil.setEditMarkerTypePreferences(markerTypeEditingMap);
83
		
90

  
84 91
		return super.performOk();
85 92
	}
86 93
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/DefaultFeatureTreePreferenecs.java
1 1
// $Id$
2 2
/**
3 3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
4
* European Distributed Institute of Taxonomy
5 5
* http://www.e-taxonomy.eu
6
* 
6
*
7 7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8 8
* See LICENSE.TXT at the top of this package for the full license terms.
9 9
*/
......
31 31
import eu.etaxonomy.cdm.model.description.FeatureTree;
32 32
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeContentProvider;
33 33
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeLabelProvider;
34
import eu.etaxonomy.taxeditor.model.MessagingUtils;
34 35
import eu.etaxonomy.taxeditor.store.CdmStore;
35 36

  
36 37
/**
......
44 45

  
45 46
	private FeatureTree defaultFeatureTreeForTextualDescription;
46 47
	private FeatureTree defaultFeatureTreeForStructuredDescription;
47
	
48

  
48 49
	/* (non-Javadoc)
49 50
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
50 51
	 */
......
53 54
	protected Control createContents(Composite parent) {
54 55
		defaultFeatureTreeForTextualDescription = PreferencesUtil.getDefaultFeatureTreeForTextualDescription();
55 56
		defaultFeatureTreeForStructuredDescription = PreferencesUtil.getDefaultFeatureTreeForStructuredDescription();
56
		
57

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

  
63 67
		return composite;
64 68
	}
65
	
69

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

  
70 74
		final ListViewer viewer = new ListViewer(parent);
71 75
		viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
72
		
76

  
73 77
		viewer.setContentProvider(new FeatureTreeContentProvider());
74 78
		viewer.setLabelProvider(new FeatureTreeLabelProvider());
75
		
79

  
76 80
		viewer.addSelectionChangedListener(new ISelectionChangedListener() {
77
			
81

  
78 82
			@Override
79 83
			public void selectionChanged(SelectionChangedEvent arg0) {
80 84
				IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
81
				
85

  
82 86
				defaultFeatureTreeForTextualDescription = (FeatureTree) selection.getFirstElement();
83 87
			}
84 88
		});
85
		
89

  
86 90
		List<FeatureTree> input = CdmStore.getService(IFeatureTreeService.class).list(FeatureTree.class, null, null, null, null);
87
				
91

  
88 92
		viewer.setInput(input);
89
		
93

  
90 94
		if(defaultFeatureTreeForTextualDescription != null){
91 95
			IStructuredSelection selection = new StructuredSelection(defaultFeatureTreeForTextualDescription);
92 96
			viewer.setSelection(selection, true);
93 97
		}
94 98
	}
95
	
99

  
96 100
	private void createStructureTreeSelection(Composite parent){
97 101
		final CLabel label = new CLabel(parent, SWT.NONE);
98 102
		label.setText("Deafult Feature Tree to be used for structured descriptions");
99
		
103

  
100 104
		final ListViewer viewer = new ListViewer(parent);
101 105
		viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
102
		
106

  
103 107
		viewer.setContentProvider(new FeatureTreeContentProvider());
104 108
		viewer.setLabelProvider(new FeatureTreeLabelProvider());
105
		
109

  
106 110
		viewer.addSelectionChangedListener(new ISelectionChangedListener() {
107
			
111

  
108 112
			@Override
109 113
			public void selectionChanged(SelectionChangedEvent arg0) {
110 114
				IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
111
				
115

  
112 116
				defaultFeatureTreeForStructuredDescription = (FeatureTree) selection.getFirstElement();
113 117
			}
114 118
		});
115
		
119

  
116 120
		List<FeatureTree> input = CdmStore.getService(IFeatureTreeService.class).list(FeatureTree.class, null, null, null, null);
117
				
121

  
118 122
		viewer.setInput(input);
119
		
123

  
120 124
		if(defaultFeatureTreeForStructuredDescription != null){
121 125
			IStructuredSelection selection = new StructuredSelection(defaultFeatureTreeForStructuredDescription);
122 126
			viewer.setSelection(selection, true);
......
128 132
	public void init(IWorkbench workbench) {
129 133
		setPreferenceStore(PreferencesUtil.getPreferenceStore());
130 134
	}
131
	
135

  
132 136
	/** {@inheritDoc} */
133 137
	@Override
134 138
	public boolean performOk() {
135 139
		String defaultFeatureTreeForTextualDescriptionUuid = "";
136 140
		String defaultFeatureTreeForStructuredDescriptionUuid = "";
137
		
141

  
138 142
		if(defaultFeatureTreeForTextualDescription != null){
139 143
			defaultFeatureTreeForTextualDescriptionUuid = defaultFeatureTreeForTextualDescription.getUuid().toString();
140 144
		}
141 145
		if(defaultFeatureTreeForStructuredDescription != null){
142 146
			defaultFeatureTreeForStructuredDescriptionUuid = defaultFeatureTreeForStructuredDescription.getUuid().toString();
143 147
		}
144
		
148

  
145 149
		getPreferenceStore().setValue(IPreferenceKeys.FEATURE_TREE_DEFAULT_TEXT, defaultFeatureTreeForTextualDescriptionUuid);
146 150
		getPreferenceStore().setValue(IPreferenceKeys.FEATURE_TREE_DEFAULT_STRUCTURE, defaultFeatureTreeForStructuredDescriptionUuid);
147
		
151

  
148 152
		return super.performOk();
149 153
	}
150 154
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/matching/AbstractMatchingPreferences.java
1 1
// $Id$
2 2
/**
3 3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
4
* European Distributed Institute of Taxonomy
5 5
* http://www.e-taxonomy.eu
6
* 
6
*
7 7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8 8
* See LICENSE.TXT at the top of this package for the full license terms.
9 9
*/
......
34 34
import eu.etaxonomy.cdm.strategy.match.MatchMode;
35 35
import eu.etaxonomy.taxeditor.model.MessagingUtils;
36 36
import eu.etaxonomy.taxeditor.parser.MatchStrategyConfigurator;
37
import eu.etaxonomy.taxeditor.store.CdmStore;
37 38

  
38 39
/**
39 40
 * <p>Abstract AbstractMatchingPreferences class.</p>
......
52 53
				"|parsingProblem|problemStarts|problemEnds|PROTECTED|NOT_PROTECTED|propertyChangeSupport";
53 54

  
54 55
	protected IMatchStrategy matchStrategy;
55
	
56

  
56 57
	protected Class<T> clazz;
57 58

  
58 59
	private List<MatchMode> matchModeList;
59
	
60

  
60 61
	protected Map<String, Combo> matchModeCombos = new HashMap<String, Combo>();
61
	
62

  
62 63
	/* (non-Javadoc)
63 64
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
64 65
	 */
......
69 70
		GridLayout gridLayout = new GridLayout();
70 71
		gridLayout.numColumns = 2;
71 72
		composite.setLayout(gridLayout);
72
		
73
		
74
		for(String fieldName : getFieldNames()){
75
			createFieldWidget(composite, fieldName);
76
		}
77
		
73

  
74
		if(!CdmStore.isActive()) {
75
            MessagingUtils.noDataSourceWarningDialog(null);
76
        }else{
77
            for(String fieldName : getFieldNames()){
78
                createFieldWidget(composite, fieldName);
79
            }
80
        }
81

  
78 82
		return composite;
79 83
	}
80
	
84

  
81 85
	/**
82 86
	 * Creates a widget for a field consisting of the label and a combo
83
	 * 
87
	 *
84 88
	 * @see {@link #createMatchModeCombo(Composite, String, MatchMode)}
85 89
	 * @param composite
86 90
	 * @param fieldName
87 91
	 */
88 92
	private void createFieldWidget(Composite parent, String fieldName) {
89
		CLabel label = new CLabel(parent, SWT.NONE);
90
		label.setText(fieldName);
91
		
92
		MatchMode matchMode = matchStrategy.getMatchMode(fieldName);
93
		
94
		createMatchModeCombo(parent, fieldName, matchMode);		
95
	}	
96
	
93
	    CLabel label = new CLabel(parent, SWT.NONE);
94
	    label.setText(fieldName);
95
	    MatchMode matchMode = matchStrategy.getMatchMode(fieldName);
96

  
97
	    createMatchModeCombo(parent, fieldName, matchMode);
98
	}
99

  
97 100
	/**
98 101
	 * Creates a combo for a field with the currently selected match mode for that field preselected
99
	 * 
102
	 *
100 103
	 * @param parent
101 104
	 * @param matchMode
102 105
	 */
103 106
	private void createMatchModeCombo(Composite parent, String fieldName, MatchMode selectedMatchMode) {
104 107
		Combo matchModeCombo = new Combo(parent, SWT.NULL);
105
		
108

  
106 109
		for (MatchMode matchMode : getMatchModeList()) {
107 110
			matchModeCombo.add(matchMode.name());
108 111
		}
109
		
112

  
110 113
		int index = getMatchModeList().indexOf(selectedMatchMode);
111
		
114

  
112 115
		matchModeCombo.select(index);
113
		
116

  
114 117
		matchModeCombo.addSelectionListener(new MatchModeComboSelectionListener(matchModeCombo, fieldName));
115
		
118

  
116 119
		matchModeCombos.put(fieldName, matchModeCombo);
117 120
	}
118
	
121

  
119 122
	/**
120 123
	 * This listener updates the cache strategy when a value was changed in one of the combos
121
	 * 
124
	 *
122 125
	 * @author n.hoffmann
123 126
	 * @created Jan 28, 2010
124 127
	 * @version 1.0
125 128
	 */
126 129
	private class MatchModeComboSelectionListener extends SelectionAdapter{
127
		
128
		private Combo matchModeCombo;
129
		private String fieldName;
130

  
131
		private final Combo matchModeCombo;
132
		private final String fieldName;
130 133

  
131 134
		MatchModeComboSelectionListener(Combo matchModeCombo, String fieldName){
132 135
			this.matchModeCombo = matchModeCombo;
133 136
			this.fieldName = fieldName;
134 137
		}
135
		
138

  
136 139
		/* (non-Javadoc)
137 140
		 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
138 141
		 */
......
151 154

  
152 155
	/**
153 156
	 * Transforms the MatchMode enum into a list.
154
	 * 
157
	 *
155 158
	 * @return
156 159
	 */
157 160
	private List<MatchMode> getMatchModeList(){
......
163 166

  
164 167
	/**
165 168
	 * Get names of all declared fields
166
	 * 
169
	 *
167 170
	 * @return
168 171
	 */
169
	private List<String> getFieldNames(){				
172
	private List<String> getFieldNames(){
170 173
		List<Field> fields = new ArrayList<Field>();
171
		
174

  
172 175
		fields = getAllFields(fields, clazz);
173 176
		List<String> fieldNames = new ArrayList<String>();
174
		
177

  
175 178
		for(Field field : fields){
176 179
			String fieldName = field.getName();
177 180
			if(! fieldName.matches(ExcludePattern)){
178 181
				fieldNames.add(fieldName);
179 182
			}
180 183
		}
181
		
184

  
182 185
		return fieldNames;
183 186
	}
184
	
187

  
185 188
	/**
186 189
	 * Get all declared fields including fields of the superclasses.
187 190
	 *
......
198 201

  
199 202
	    return fields;
200 203
	}
201
	
204

  
202 205
	/* (non-Javadoc)
203 206
	 * @see org.eclipse.jface.preference.PreferencePage#performApply()
204 207
	 */
......
208 211
		MatchStrategyConfigurator.setMatchStrategy(matchStrategy);
209 212
		super.performApply();
210 213
	}
211
	
214

  
212 215
	/* (non-Javadoc)
213 216
	 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
214 217
	 */
......
218 221
		try {
219 222
			// set match strategy to default
220 223
			matchStrategy = getDefaultMatchStrategy();
221
			
224

  
222 225
			// set combos to their default values
223 226
			for(String fieldName : matchModeCombos.keySet()){
224 227
				Combo combo = matchModeCombos.get(fieldName);
225 228
				MatchMode matchMode = matchStrategy.getMatchMode(fieldName);
226 229
				combo.select(matchModeList.indexOf(matchMode));
227 230
			}
228
			
231

  
229 232
		} catch (MatchException e) {
230 233
			MessagingUtils.error(this.getClass(), e);
231 234
			throw new RuntimeException(e);
232 235
		}
233 236
		super.performDefaults();
234 237
	}
235
	
238

  
236 239
	/**
237 240
	 * Returns the default match strategy for the respective class
238 241
	 *

Also available in: Unified diff