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.l10n.Messages;
|
31
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
32
|
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
|
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 CdmPreferencePage {
|
43
|
|
44
|
private FeatureTree defaultFeatureTreeForTextualDescription;
|
45
|
private FeatureTree defaultFeatureTreeForStructuredDescription;
|
46
|
|
47
|
/** {@inheritDoc} */
|
48
|
@Override
|
49
|
protected Control createContents(Composite parent) {
|
50
|
defaultFeatureTreeForTextualDescription = PreferencesUtil.getDefaultFeatureTreeForTextualDescription();
|
51
|
defaultFeatureTreeForStructuredDescription = PreferencesUtil.getDefaultFeatureTreeForStructuredDescription();
|
52
|
|
53
|
Composite composite = new Composite(parent, SWT.NULL);
|
54
|
composite.setLayout(new GridLayout());
|
55
|
if(!CdmStore.isActive()) {
|
56
|
MessagingUtils.noDataSourceWarningDialog(null);
|
57
|
}else{
|
58
|
createTextTreeSelection(composite);
|
59
|
createStructureTreeSelection(composite);
|
60
|
}
|
61
|
|
62
|
return composite;
|
63
|
}
|
64
|
|
65
|
private void createTextTreeSelection(Composite parent){
|
66
|
final CLabel label = new CLabel(parent, SWT.NONE);
|
67
|
label.setText(Messages.DefaultFeatureTreePreferenecs_0);
|
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
|
setApply(true);
|
80
|
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
|
81
|
|
82
|
defaultFeatureTreeForTextualDescription = (FeatureTree) selection.getFirstElement();
|
83
|
}
|
84
|
});
|
85
|
|
86
|
List<FeatureTree> input = CdmStore.getService(IFeatureTreeService.class).list(FeatureTree.class, null, null, null, null);
|
87
|
|
88
|
viewer.setInput(input);
|
89
|
|
90
|
if(defaultFeatureTreeForTextualDescription != null){
|
91
|
IStructuredSelection selection = new StructuredSelection(defaultFeatureTreeForTextualDescription);
|
92
|
viewer.setSelection(selection, true);
|
93
|
}
|
94
|
}
|
95
|
|
96
|
private void createStructureTreeSelection(Composite parent){
|
97
|
final CLabel label = new CLabel(parent, SWT.NONE);
|
98
|
label.setText(Messages.DefaultFeatureTreePreferenecs_1);
|
99
|
|
100
|
final ListViewer viewer = new ListViewer(parent);
|
101
|
viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
102
|
|
103
|
viewer.setContentProvider(new FeatureTreeContentProvider());
|
104
|
viewer.setLabelProvider(new FeatureTreeLabelProvider());
|
105
|
|
106
|
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
|
107
|
|
108
|
@Override
|
109
|
public void selectionChanged(SelectionChangedEvent arg0) {
|
110
|
setApply(true);
|
111
|
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
|
112
|
|
113
|
defaultFeatureTreeForStructuredDescription = (FeatureTree) selection.getFirstElement();
|
114
|
}
|
115
|
});
|
116
|
|
117
|
List<FeatureTree> input = CdmStore.getService(IFeatureTreeService.class).list(FeatureTree.class, null, null, null, null);
|
118
|
|
119
|
viewer.setInput(input);
|
120
|
|
121
|
if(defaultFeatureTreeForStructuredDescription != null){
|
122
|
IStructuredSelection selection = new StructuredSelection(defaultFeatureTreeForStructuredDescription);
|
123
|
viewer.setSelection(selection, true);
|
124
|
}
|
125
|
}
|
126
|
|
127
|
/** {@inheritDoc} */
|
128
|
@Override
|
129
|
public boolean performOk() {
|
130
|
String defaultFeatureTreeForTextualDescriptionUuid = ""; //$NON-NLS-1$
|
131
|
String defaultFeatureTreeForStructuredDescriptionUuid = ""; //$NON-NLS-1$
|
132
|
|
133
|
if(defaultFeatureTreeForTextualDescription != null){
|
134
|
defaultFeatureTreeForTextualDescriptionUuid = defaultFeatureTreeForTextualDescription.getUuid().toString();
|
135
|
}
|
136
|
if(defaultFeatureTreeForStructuredDescription != null){
|
137
|
defaultFeatureTreeForStructuredDescriptionUuid = defaultFeatureTreeForStructuredDescription.getUuid().toString();
|
138
|
}
|
139
|
|
140
|
getPreferenceStore().setValue(PreferencesUtil.createPreferenceString(IPreferenceKeys.FEATURE_TREE_DEFAULT_TEXT), defaultFeatureTreeForTextualDescriptionUuid);
|
141
|
getPreferenceStore().setValue(PreferencesUtil.createPreferenceString(IPreferenceKeys.FEATURE_TREE_DEFAULT_STRUCTURE), defaultFeatureTreeForStructuredDescriptionUuid);
|
142
|
|
143
|
return super.performOk();
|
144
|
}
|
145
|
}
|