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.viewers.ISelectionChangedListener;
|
16
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
17
|
import org.eclipse.jface.viewers.ListViewer;
|
18
|
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
19
|
import org.eclipse.jface.viewers.StructuredSelection;
|
20
|
import org.eclipse.swt.SWT;
|
21
|
import org.eclipse.swt.custom.CLabel;
|
22
|
import org.eclipse.swt.layout.GridData;
|
23
|
import org.eclipse.swt.layout.GridLayout;
|
24
|
import org.eclipse.swt.widgets.Composite;
|
25
|
import org.eclipse.swt.widgets.Control;
|
26
|
import org.eclipse.ui.IWorkbench;
|
27
|
import org.eclipse.ui.IWorkbenchPreferencePage;
|
28
|
|
29
|
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
|
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.model.MessagingUtils;
|
34
|
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
|
35
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
36
|
|
37
|
/**
|
38
|
* <p>DefaultFeatureTreePreferenecs class.</p>
|
39
|
*
|
40
|
* @author n.hoffmann
|
41
|
* @created Sep 16, 2010
|
42
|
* @version 1.0
|
43
|
*/
|
44
|
public class DefaultFeatureTreePreferenecs extends CdmPreferencePage implements IWorkbenchPreferencePage {
|
45
|
|
46
|
private FeatureTree defaultFeatureTreeForTextualDescription;
|
47
|
private FeatureTree defaultFeatureTreeForStructuredDescription;
|
48
|
|
49
|
/* (non-Javadoc)
|
50
|
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
|
51
|
*/
|
52
|
/** {@inheritDoc} */
|
53
|
@Override
|
54
|
protected Control createContents(Composite parent) {
|
55
|
defaultFeatureTreeForTextualDescription = PreferencesUtil.getDefaultFeatureTreeForTextualDescription();
|
56
|
defaultFeatureTreeForStructuredDescription = PreferencesUtil.getDefaultFeatureTreeForStructuredDescription();
|
57
|
|
58
|
Composite composite = new Composite(parent, SWT.NULL);
|
59
|
composite.setLayout(new GridLayout());
|
60
|
if(!CdmStore.isActive()) {
|
61
|
MessagingUtils.noDataSourceWarningDialog(null);
|
62
|
}else{
|
63
|
createTextTreeSelection(composite);
|
64
|
createStructureTreeSelection(composite);
|
65
|
}
|
66
|
|
67
|
return composite;
|
68
|
}
|
69
|
|
70
|
private void createTextTreeSelection(Composite parent){
|
71
|
final CLabel label = new CLabel(parent, SWT.NONE);
|
72
|
label.setText("Deafult Feature Tree to be used for textual descriptions");
|
73
|
|
74
|
final ListViewer viewer = new ListViewer(parent);
|
75
|
viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
76
|
|
77
|
viewer.setContentProvider(new FeatureTreeContentProvider());
|
78
|
viewer.setLabelProvider(new FeatureTreeLabelProvider());
|
79
|
|
80
|
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
|
81
|
|
82
|
@Override
|
83
|
public void selectionChanged(SelectionChangedEvent arg0) {
|
84
|
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
|
85
|
|
86
|
defaultFeatureTreeForTextualDescription = (FeatureTree) selection.getFirstElement();
|
87
|
}
|
88
|
});
|
89
|
|
90
|
List<FeatureTree> input = CdmStore.getService(IFeatureTreeService.class).list(FeatureTree.class, null, null, null, null);
|
91
|
|
92
|
viewer.setInput(input);
|
93
|
|
94
|
if(defaultFeatureTreeForTextualDescription != null){
|
95
|
IStructuredSelection selection = new StructuredSelection(defaultFeatureTreeForTextualDescription);
|
96
|
viewer.setSelection(selection, true);
|
97
|
}
|
98
|
}
|
99
|
|
100
|
private void createStructureTreeSelection(Composite parent){
|
101
|
final CLabel label = new CLabel(parent, SWT.NONE);
|
102
|
label.setText("Deafult Feature Tree to be used for structured descriptions");
|
103
|
|
104
|
final ListViewer viewer = new ListViewer(parent);
|
105
|
viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
106
|
|
107
|
viewer.setContentProvider(new FeatureTreeContentProvider());
|
108
|
viewer.setLabelProvider(new FeatureTreeLabelProvider());
|
109
|
|
110
|
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
|
111
|
|
112
|
@Override
|
113
|
public void selectionChanged(SelectionChangedEvent arg0) {
|
114
|
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
|
115
|
|
116
|
defaultFeatureTreeForStructuredDescription = (FeatureTree) selection.getFirstElement();
|
117
|
}
|
118
|
});
|
119
|
|
120
|
List<FeatureTree> input = CdmStore.getService(IFeatureTreeService.class).list(FeatureTree.class, null, null, null, null);
|
121
|
|
122
|
viewer.setInput(input);
|
123
|
|
124
|
if(defaultFeatureTreeForStructuredDescription != null){
|
125
|
IStructuredSelection selection = new StructuredSelection(defaultFeatureTreeForStructuredDescription);
|
126
|
viewer.setSelection(selection, true);
|
127
|
}
|
128
|
}
|
129
|
|
130
|
/** {@inheritDoc} */
|
131
|
@Override
|
132
|
public void init(IWorkbench workbench) {
|
133
|
setPreferenceStore(PreferencesUtil.getPreferenceStore());
|
134
|
}
|
135
|
|
136
|
/** {@inheritDoc} */
|
137
|
@Override
|
138
|
public boolean performOk() {
|
139
|
String defaultFeatureTreeForTextualDescriptionUuid = "";
|
140
|
String defaultFeatureTreeForStructuredDescriptionUuid = "";
|
141
|
|
142
|
if(defaultFeatureTreeForTextualDescription != null){
|
143
|
defaultFeatureTreeForTextualDescriptionUuid = defaultFeatureTreeForTextualDescription.getUuid().toString();
|
144
|
}
|
145
|
if(defaultFeatureTreeForStructuredDescription != null){
|
146
|
defaultFeatureTreeForStructuredDescriptionUuid = defaultFeatureTreeForStructuredDescription.getUuid().toString();
|
147
|
}
|
148
|
|
149
|
getPreferenceStore().setValue(IPreferenceKeys.FEATURE_TREE_DEFAULT_TEXT, defaultFeatureTreeForTextualDescriptionUuid);
|
150
|
getPreferenceStore().setValue(IPreferenceKeys.FEATURE_TREE_DEFAULT_STRUCTURE, defaultFeatureTreeForStructuredDescriptionUuid);
|
151
|
|
152
|
return super.performOk();
|
153
|
}
|
154
|
}
|