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.l10n.Messages;
|
29
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
30
|
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
|
31
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
32
|
import eu.etaxonomy.taxeditor.termtree.TermTreeContentProvider;
|
33
|
import eu.etaxonomy.taxeditor.termtree.TermTreeLabelProvider;
|
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
|
private ListViewer viewerText;
|
47
|
private ListViewer viewerStructure;
|
48
|
|
49
|
/** {@inheritDoc} */
|
50
|
@Override
|
51
|
protected Control createContents(Composite parent) {
|
52
|
defaultFeatureTreeForTextualDescription = PreferencesUtil.getDefaultFeatureTreeForTextualDescription();
|
53
|
defaultFeatureTreeForStructuredDescription = PreferencesUtil.getDefaultFeatureTreeForStructuredDescription();
|
54
|
|
55
|
Composite composite = new Composite(parent, SWT.NULL);
|
56
|
composite.setLayout(new GridLayout());
|
57
|
if(!CdmStore.isActive()) {
|
58
|
MessagingUtils.noDataSourceWarningDialog(null);
|
59
|
}else{
|
60
|
createStructureTreeSelection(composite);
|
61
|
createTextTreeSelection(composite);
|
62
|
}
|
63
|
|
64
|
return composite;
|
65
|
}
|
66
|
|
67
|
private void createTextTreeSelection(Composite parent){
|
68
|
final CLabel label = new CLabel(parent, SWT.NONE);
|
69
|
label.setText(Messages.DefaultFeatureTreePreferenecs_0);
|
70
|
viewerText = new ListViewer(parent, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
|
71
|
|
72
|
viewerText.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
73
|
|
74
|
viewerText.setContentProvider(new TermTreeContentProvider());
|
75
|
viewerText.setLabelProvider(new TermTreeLabelProvider());
|
76
|
|
77
|
viewerText.addSelectionChangedListener(new ISelectionChangedListener() {
|
78
|
|
79
|
@Override
|
80
|
public void selectionChanged(SelectionChangedEvent arg0) {
|
81
|
setApply(true);
|
82
|
// viewer.setSelection(arg0.getSelection());
|
83
|
IStructuredSelection selection = (IStructuredSelection) viewerText.getSelection();
|
84
|
|
85
|
defaultFeatureTreeForTextualDescription = (TermTree)selection.getFirstElement();
|
86
|
|
87
|
}
|
88
|
});
|
89
|
|
90
|
List<TermTree> input = CdmStore.getService(ITermTreeService.class).list(TermTree.class, null, null, null, null);
|
91
|
|
92
|
viewerText.setInput(input);
|
93
|
|
94
|
if(defaultFeatureTreeForTextualDescription != null){
|
95
|
IStructuredSelection selection = new StructuredSelection(defaultFeatureTreeForTextualDescription);
|
96
|
viewerText.setSelection(selection, true);
|
97
|
}
|
98
|
}
|
99
|
|
100
|
private void createStructureTreeSelection(Composite parent){
|
101
|
final CLabel label = new CLabel(parent, SWT.NONE);
|
102
|
label.setText(Messages.DefaultFeatureTreePreferenecs_1);
|
103
|
|
104
|
viewerStructure = new ListViewer(parent, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
|
105
|
|
106
|
viewerStructure.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
107
|
|
108
|
viewerStructure.setContentProvider(new TermTreeContentProvider());
|
109
|
viewerStructure.setLabelProvider(new TermTreeLabelProvider());
|
110
|
|
111
|
viewerStructure.addSelectionChangedListener(new ISelectionChangedListener() {
|
112
|
|
113
|
@Override
|
114
|
public void selectionChanged(SelectionChangedEvent arg0) {
|
115
|
setApply(true);
|
116
|
// viewer.setSelection(arg0.getSelection());
|
117
|
IStructuredSelection selection = (IStructuredSelection) viewerStructure.getSelection();
|
118
|
|
119
|
defaultFeatureTreeForStructuredDescription = (TermTree) selection.getFirstElement();
|
120
|
|
121
|
}
|
122
|
});
|
123
|
|
124
|
List<TermTree> input = CdmStore.getService(ITermTreeService.class).list(TermTree.class, null, null, null, null);
|
125
|
|
126
|
viewerStructure.setInput(input);
|
127
|
|
128
|
if(defaultFeatureTreeForStructuredDescription != null){
|
129
|
IStructuredSelection selection = new StructuredSelection(defaultFeatureTreeForStructuredDescription);
|
130
|
viewerStructure.setSelection(selection, true);
|
131
|
}
|
132
|
}
|
133
|
|
134
|
/** {@inheritDoc} */
|
135
|
@Override
|
136
|
public boolean performOk() {
|
137
|
String defaultFeatureTreeForTextualDescriptionUuid = ""; //$NON-NLS-1$
|
138
|
String defaultFeatureTreeForStructuredDescriptionUuid = ""; //$NON-NLS-1$
|
139
|
|
140
|
if(defaultFeatureTreeForTextualDescription != null){
|
141
|
defaultFeatureTreeForTextualDescriptionUuid = defaultFeatureTreeForTextualDescription.getUuid().toString();
|
142
|
}
|
143
|
if(defaultFeatureTreeForStructuredDescription != null){
|
144
|
defaultFeatureTreeForStructuredDescriptionUuid = defaultFeatureTreeForStructuredDescription.getUuid().toString();
|
145
|
}
|
146
|
|
147
|
getPreferenceStore().setValue(PreferencesUtil.createPreferenceString(IPreferenceKeys.FEATURE_TREE_DEFAULT_TEXT), defaultFeatureTreeForTextualDescriptionUuid);
|
148
|
getPreferenceStore().setValue(PreferencesUtil.createPreferenceString(IPreferenceKeys.FEATURE_TREE_DEFAULT_STRUCTURE), defaultFeatureTreeForStructuredDescriptionUuid);
|
149
|
|
150
|
return super.performOk();
|
151
|
}
|
152
|
@Override
|
153
|
protected void performDefaults() {
|
154
|
defaultFeatureTreeForTextualDescription = null;
|
155
|
defaultFeatureTreeForTextualDescription = null;
|
156
|
viewerStructure.setSelection(null);
|
157
|
viewerText.setSelection(null);
|
158
|
setApply(true);
|
159
|
super.performDefaults();
|
160
|
}
|
161
|
|
162
|
}
|