Ticket #1352 fixed.
[taxeditor.git] / taxeditor-bulkeditor / src / main / java / eu / etaxonomy / taxeditor / bulkeditor / BulkEditorMarkerPreferenceComposite.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.taxeditor.bulkeditor;
12
13 import java.util.HashMap;
14 import java.util.Map;
15
16 import org.apache.log4j.Logger;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.events.SelectionAdapter;
19 import org.eclipse.swt.events.SelectionEvent;
20 import org.eclipse.swt.layout.GridLayout;
21 import org.eclipse.swt.widgets.Button;
22 import org.eclipse.swt.widgets.Composite;
23
24 import eu.etaxonomy.cdm.model.common.MarkerType;
25 import eu.etaxonomy.taxeditor.bulkeditor.input.BulkEditorInput;
26 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
27 import eu.etaxonomy.taxeditor.store.VocabularyStore;
28
29 /**
30 * @author p.ciardelli
31 * @created 17.08.2009
32 * @version 1.0
33 */
34 public class BulkEditorMarkerPreferenceComposite extends Composite {
35 private static final Logger logger = Logger.getLogger(BulkEditorMarkerPreferenceComposite.class);
36
37 private BulkEditorInput editorInput;
38
39 Map<Button, MarkerType> markerTypeButtons = new HashMap<Button, MarkerType>();
40
41 /**
42 * @param parent
43 * @param style
44 */
45 public BulkEditorMarkerPreferenceComposite(BulkEditorInput editorInput, Composite parent, int style) {
46 super(parent, style);
47 this.editorInput = editorInput;
48 createControl();
49 }
50
51 /**
52 * @param markerType
53 * @return
54 *
55 */
56 private boolean getEditMarkerPreference(MarkerType markerType) {
57 return PreferencesUtil.getEditMarkerTypePreference(editorInput, markerType);
58 }
59
60 private void setEditMarkerPreference(MarkerType markerType, boolean edit) {
61 PreferencesUtil.setEditMarkerTypePreference(editorInput, markerType, edit);
62 }
63
64 protected void createControl() {
65
66 GridLayout gridLayout = new GridLayout();
67 gridLayout.numColumns = 3;
68 gridLayout.marginHeight = 0;
69 gridLayout.marginWidth = 12;
70 setLayout(gridLayout);
71
72 for (final MarkerType markerType : VocabularyStore.getNonTechnicalMarkerTypes()) {
73 if (editorInput.isMarkerTypeEditingEnabled(markerType)) {
74 final Button button = new Button(this, SWT.CHECK);
75 button.setText("Edit " + markerType.getLabel() + " markers");
76 button.addSelectionListener(new SelectionAdapter() {
77 public void widgetSelected(SelectionEvent e) {
78 setEditMarkerPreference(markerType, button.getSelection());
79 }
80 });
81 button.setSelection(getEditMarkerPreference(markerType));
82
83 markerTypeButtons.put(button, markerType);
84 }
85 }
86 }
87 }