Project

General

Profile

Download (4.93 KB) Statistics
| Branch: | Tag: | Revision:
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.preference;
12

    
13
import java.util.List;
14

    
15
import org.eclipse.jface.preference.PreferencePage;
16
import org.eclipse.jface.viewers.ISelectionChangedListener;
17
import org.eclipse.jface.viewers.IStructuredSelection;
18
import org.eclipse.jface.viewers.ListViewer;
19
import org.eclipse.jface.viewers.SelectionChangedEvent;
20
import org.eclipse.jface.viewers.StructuredSelection;
21
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.custom.CLabel;
23
import org.eclipse.swt.layout.GridData;
24
import org.eclipse.swt.layout.GridLayout;
25
import org.eclipse.swt.widgets.Composite;
26
import org.eclipse.swt.widgets.Control;
27
import org.eclipse.ui.IWorkbench;
28
import org.eclipse.ui.IWorkbenchPreferencePage;
29

    
30
import eu.etaxonomy.cdm.model.description.FeatureTree;
31
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeContentProvider;
32
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeLabelProvider;
33
import eu.etaxonomy.taxeditor.store.CdmStore;
34

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

    
44
	private FeatureTree defaultFeatureTreeForTextualDescription;
45
	private FeatureTree defaultFeatureTreeForStructuredDescription;
46
	
47
	/* (non-Javadoc)
48
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
49
	 */
50
	/** {@inheritDoc} */
51
	@Override
52
	protected Control createContents(Composite parent) {
53
		defaultFeatureTreeForTextualDescription = PreferencesUtil.getDefaultFeatureTreeForTextualDescription();
54
		defaultFeatureTreeForStructuredDescription = PreferencesUtil.getDefaultFeatureTreeForStructuredDescription();
55
		
56
		Composite composite = new Composite(parent, SWT.NULL);
57
		composite.setLayout(new GridLayout());
58
		
59
		createTextTreeSelection(composite);
60
		createStructureTreeSelection(composite);
61
		
62
		return composite;
63
	}
64
	
65
	private void createTextTreeSelection(Composite parent){
66
		final CLabel label = new CLabel(parent, SWT.NONE);
67
		label.setText("Deafult Feature Tree to be used for textual descriptions");
68
		
69
		final ListViewer viewer = new ListViewer(parent);
70
		viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
71
		
72
		viewer.setContentProvider(new FeatureTreeContentProvider());
73
		viewer.setLabelProvider(new FeatureTreeLabelProvider());
74
		
75
		viewer.addSelectionChangedListener(new ISelectionChangedListener() {
76
			
77
			@Override
78
			public void selectionChanged(SelectionChangedEvent arg0) {
79
				IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
80
				
81
				defaultFeatureTreeForTextualDescription = (FeatureTree) selection.getFirstElement();
82
			}
83
		});
84
		
85
		List<FeatureTree> input = CdmStore.getFeatureTreeService().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("Deafult 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
				IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
110
				
111
				defaultFeatureTreeForStructuredDescription = (FeatureTree) selection.getFirstElement();
112
			}
113
		});
114
		
115
		List<FeatureTree> input = CdmStore.getFeatureTreeService().list(FeatureTree.class, null, null, null, null);
116
				
117
		viewer.setInput(input);
118
		
119
		if(defaultFeatureTreeForStructuredDescription != null){
120
			IStructuredSelection selection = new StructuredSelection(defaultFeatureTreeForStructuredDescription);
121
			viewer.setSelection(selection, true);
122
		}
123
	}
124

    
125
	/** {@inheritDoc} */
126
	@Override
127
	public void init(IWorkbench workbench) {
128
		setPreferenceStore(PreferencesUtil.getPreferenceStore());
129
	}
130
	
131
	/** {@inheritDoc} */
132
	@Override
133
	public boolean performOk() {
134
		
135
		getPreferenceStore().setValue(IPreferenceKeys.FEATURE_TREE_DEFAULT_TEXT, defaultFeatureTreeForTextualDescription.getUuid().toString());
136
		getPreferenceStore().setValue(IPreferenceKeys.FEATURE_TREE_DEFAULT_STRUCTURE, defaultFeatureTreeForStructuredDescription.getUuid().toString());
137
		
138
		return super.performOk();
139
	}
140
}
(2-2/13)