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.ITermTreeService;
|
27
|
import eu.etaxonomy.cdm.model.term.TermTree;
|
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
|
*/
|
41
|
public class DefaultFeatureTreePreferenecs extends CdmPreferencePage {
|
42
|
|
43
|
private TermTree defaultFeatureTreeForTextualDescription;
|
44
|
private TermTree 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(Messages.DefaultFeatureTreePreferenecs_0);
|
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 = (TermTree)selection.getFirstElement();
|
82
|
}
|
83
|
});
|
84
|
|
85
|
List<TermTree> input = CdmStore.getService(ITermTreeService.class).list(TermTree.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(Messages.DefaultFeatureTreePreferenecs_1);
|
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 = (TermTree) selection.getFirstElement();
|
113
|
}
|
114
|
});
|
115
|
|
116
|
List<TermTree> input = CdmStore.getService(ITermTreeService.class).list(TermTree.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 = ""; //$NON-NLS-1$
|
130
|
String defaultFeatureTreeForStructuredDescriptionUuid = ""; //$NON-NLS-1$
|
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(PreferencesUtil.createPreferenceString(IPreferenceKeys.FEATURE_TREE_DEFAULT_TEXT), defaultFeatureTreeForTextualDescriptionUuid);
|
140
|
getPreferenceStore().setValue(PreferencesUtil.createPreferenceString(IPreferenceKeys.FEATURE_TREE_DEFAULT_STRUCTURE), defaultFeatureTreeForStructuredDescriptionUuid);
|
141
|
|
142
|
return super.performOk();
|
143
|
}
|
144
|
}
|