Project

General

Profile

Download (5.22 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
			    setApply(true);
79
				IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
80

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

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

    
87
		viewer.setInput(input);
88

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

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

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

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

    
105
		viewer.addSelectionChangedListener(new ISelectionChangedListener() {
106

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

    
112
				defaultFeatureTreeForStructuredDescription = (FeatureTree) selection.getFirstElement();
113
			}
114
		});
115

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

    
118
		viewer.setInput(input);
119

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

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

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

    
139
		getPreferenceStore().setValue(IPreferenceKeys.FEATURE_TREE_DEFAULT_TEXT, defaultFeatureTreeForTextualDescriptionUuid);
140
		getPreferenceStore().setValue(IPreferenceKeys.FEATURE_TREE_DEFAULT_STRUCTURE, defaultFeatureTreeForStructuredDescriptionUuid);
141

    
142
		return super.performOk();
143
	}
144
}
(5-5/30)