Project

General

Profile

Download (5.17 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

    
10
package eu.etaxonomy.taxeditor.preference;
11

    
12
import java.util.List;
13

    
14
import org.eclipse.jface.viewers.ISelectionChangedListener;
15
import org.eclipse.jface.viewers.IStructuredSelection;
16
import org.eclipse.jface.viewers.ListViewer;
17
import org.eclipse.jface.viewers.SelectionChangedEvent;
18
import org.eclipse.jface.viewers.StructuredSelection;
19
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.custom.CLabel;
21
import org.eclipse.swt.layout.GridData;
22
import org.eclipse.swt.layout.GridLayout;
23
import org.eclipse.swt.widgets.Composite;
24
import org.eclipse.swt.widgets.Control;
25

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

    
34
/**
35
 * <p>DefaultFeatureTreePreferenecs class.</p>
36
 *
37
 * @author n.hoffmann
38
 * @created Sep 16, 2010
39
 * @version 1.0
40
 */
41
public class DefaultFeatureTreePreferenecs extends CdmPreferencePage {
42

    
43
	private FeatureTree defaultFeatureTreeForTextualDescription;
44
	private FeatureTree defaultFeatureTreeForStructuredDescription;
45

    
46
	/** {@inheritDoc} */
47
	@Override
48
	protected Control createContents(Composite parent) {
49
		defaultFeatureTreeForTextualDescription = PreferencesUtil.getDefaultFeatureTreeForTextualDescription();
50
		defaultFeatureTreeForStructuredDescription = PreferencesUtil.getDefaultFeatureTreeForStructuredDescription();
51

    
52
		Composite composite = new Composite(parent, SWT.NULL);
53
		composite.setLayout(new GridLayout());
54
		if(!CdmStore.isActive()) {
55
            MessagingUtils.noDataSourceWarningDialog(null);
56
		}else{
57
		    createTextTreeSelection(composite);
58
		    createStructureTreeSelection(composite);
59
		}
60

    
61
		return composite;
62
	}
63

    
64
	private void createTextTreeSelection(Composite parent){
65
		final CLabel label = new CLabel(parent, SWT.NONE);
66
		label.setText("Default Feature Tree to be used for textual descriptions");
67

    
68
		final ListViewer viewer = new ListViewer(parent);
69
		viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
70

    
71
		viewer.setContentProvider(new FeatureTreeContentProvider());
72
		viewer.setLabelProvider(new FeatureTreeLabelProvider());
73

    
74
		viewer.addSelectionChangedListener(new ISelectionChangedListener() {
75

    
76
			@Override
77
			public void selectionChanged(SelectionChangedEvent arg0) {
78
				IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
79

    
80
				defaultFeatureTreeForTextualDescription = (FeatureTree) selection.getFirstElement();
81
			}
82
		});
83

    
84
		List<FeatureTree> input = CdmStore.getService(IFeatureTreeService.class).list(FeatureTree.class, null, null, null, null);
85

    
86
		viewer.setInput(input);
87

    
88
		if(defaultFeatureTreeForTextualDescription != null){
89
			IStructuredSelection selection = new StructuredSelection(defaultFeatureTreeForTextualDescription);
90
			viewer.setSelection(selection, true);
91
		}
92
	}
93

    
94
	private void createStructureTreeSelection(Composite parent){
95
		final CLabel label = new CLabel(parent, SWT.NONE);
96
		label.setText("Default Feature Tree to be used for structured descriptions");
97

    
98
		final ListViewer viewer = new ListViewer(parent);
99
		viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
100

    
101
		viewer.setContentProvider(new FeatureTreeContentProvider());
102
		viewer.setLabelProvider(new FeatureTreeLabelProvider());
103

    
104
		viewer.addSelectionChangedListener(new ISelectionChangedListener() {
105

    
106
			@Override
107
			public void selectionChanged(SelectionChangedEvent arg0) {
108
				IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
109

    
110
				defaultFeatureTreeForStructuredDescription = (FeatureTree) selection.getFirstElement();
111
			}
112
		});
113

    
114
		List<FeatureTree> input = CdmStore.getService(IFeatureTreeService.class).list(FeatureTree.class, null, null, null, null);
115

    
116
		viewer.setInput(input);
117

    
118
		if(defaultFeatureTreeForStructuredDescription != null){
119
			IStructuredSelection selection = new StructuredSelection(defaultFeatureTreeForStructuredDescription);
120
			viewer.setSelection(selection, true);
121
		}
122
	}
123

    
124
	/** {@inheritDoc} */
125
	@Override
126
	public boolean performOk() {
127
		String defaultFeatureTreeForTextualDescriptionUuid = "";
128
		String defaultFeatureTreeForStructuredDescriptionUuid = "";
129

    
130
		if(defaultFeatureTreeForTextualDescription != null){
131
			defaultFeatureTreeForTextualDescriptionUuid = defaultFeatureTreeForTextualDescription.getUuid().toString();
132
		}
133
		if(defaultFeatureTreeForStructuredDescription != null){
134
			defaultFeatureTreeForStructuredDescriptionUuid = defaultFeatureTreeForStructuredDescription.getUuid().toString();
135
		}
136

    
137
		getPreferenceStore().setValue(IPreferenceKeys.FEATURE_TREE_DEFAULT_TEXT, defaultFeatureTreeForTextualDescriptionUuid);
138
		getPreferenceStore().setValue(IPreferenceKeys.FEATURE_TREE_DEFAULT_STRUCTURE, defaultFeatureTreeForStructuredDescriptionUuid);
139

    
140
		return super.performOk();
141
	}
142
}
(5-5/24)