1 |
cfcb0ce6
|
n.hoffmann
|
/**
|
2 |
|
|
* Copyright (C) 2007 EDIT
|
3 |
ddcbd609
|
Alexander Oppermann
|
* European Distributed Institute of Taxonomy
|
4 |
cfcb0ce6
|
n.hoffmann
|
* http://www.e-taxonomy.eu
|
5 |
ddcbd609
|
Alexander Oppermann
|
*
|
6 |
cfcb0ce6
|
n.hoffmann
|
* 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 |
db5e366d
|
n.hoffmann
|
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
|
27 |
cfcb0ce6
|
n.hoffmann
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
28 |
|
|
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeContentProvider;
|
29 |
|
|
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeLabelProvider;
|
30 |
c82a307b
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
31 |
068cf826
|
Cherian Mathew
|
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
|
32 |
cfcb0ce6
|
n.hoffmann
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
33 |
|
|
|
34 |
|
|
/**
|
35 |
3be6ef3e
|
n.hoffmann
|
* <p>DefaultFeatureTreePreferenecs class.</p>
|
36 |
|
|
*
|
37 |
cfcb0ce6
|
n.hoffmann
|
* @author n.hoffmann
|
38 |
|
|
* @created Sep 16, 2010
|
39 |
|
|
* @version 1.0
|
40 |
|
|
*/
|
41 |
672874ab
|
Patrick Plitzner
|
public class DefaultFeatureTreePreferenecs extends CdmPreferencePage {
|
42 |
cfcb0ce6
|
n.hoffmann
|
|
43 |
|
|
private FeatureTree defaultFeatureTreeForTextualDescription;
|
44 |
|
|
private FeatureTree defaultFeatureTreeForStructuredDescription;
|
45 |
ddcbd609
|
Alexander Oppermann
|
|
46 |
3be6ef3e
|
n.hoffmann
|
/** {@inheritDoc} */
|
47 |
cfcb0ce6
|
n.hoffmann
|
@Override
|
48 |
|
|
protected Control createContents(Composite parent) {
|
49 |
|
|
defaultFeatureTreeForTextualDescription = PreferencesUtil.getDefaultFeatureTreeForTextualDescription();
|
50 |
|
|
defaultFeatureTreeForStructuredDescription = PreferencesUtil.getDefaultFeatureTreeForStructuredDescription();
|
51 |
ddcbd609
|
Alexander Oppermann
|
|
52 |
cfcb0ce6
|
n.hoffmann
|
Composite composite = new Composite(parent, SWT.NULL);
|
53 |
|
|
composite.setLayout(new GridLayout());
|
54 |
c82a307b
|
Patrick Plitzner
|
if(!CdmStore.isActive()) {
|
55 |
|
|
MessagingUtils.noDataSourceWarningDialog(null);
|
56 |
|
|
}else{
|
57 |
ddcbd609
|
Alexander Oppermann
|
createTextTreeSelection(composite);
|
58 |
|
|
createStructureTreeSelection(composite);
|
59 |
|
|
}
|
60 |
c82a307b
|
Patrick Plitzner
|
|
61 |
cfcb0ce6
|
n.hoffmann
|
return composite;
|
62 |
|
|
}
|
63 |
ddcbd609
|
Alexander Oppermann
|
|
64 |
cfcb0ce6
|
n.hoffmann
|
private void createTextTreeSelection(Composite parent){
|
65 |
|
|
final CLabel label = new CLabel(parent, SWT.NONE);
|
66 |
c82a307b
|
Patrick Plitzner
|
label.setText("Default Feature Tree to be used for textual descriptions");
|
67 |
ddcbd609
|
Alexander Oppermann
|
|
68 |
cfcb0ce6
|
n.hoffmann
|
final ListViewer viewer = new ListViewer(parent);
|
69 |
|
|
viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
70 |
ddcbd609
|
Alexander Oppermann
|
|
71 |
cfcb0ce6
|
n.hoffmann
|
viewer.setContentProvider(new FeatureTreeContentProvider());
|
72 |
|
|
viewer.setLabelProvider(new FeatureTreeLabelProvider());
|
73 |
ddcbd609
|
Alexander Oppermann
|
|
74 |
cfcb0ce6
|
n.hoffmann
|
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
|
75 |
ddcbd609
|
Alexander Oppermann
|
|
76 |
cfcb0ce6
|
n.hoffmann
|
@Override
|
77 |
|
|
public void selectionChanged(SelectionChangedEvent arg0) {
|
78 |
|
|
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
|
79 |
ddcbd609
|
Alexander Oppermann
|
|
80 |
cfcb0ce6
|
n.hoffmann
|
defaultFeatureTreeForTextualDescription = (FeatureTree) selection.getFirstElement();
|
81 |
|
|
}
|
82 |
|
|
});
|
83 |
ddcbd609
|
Alexander Oppermann
|
|
84 |
db5e366d
|
n.hoffmann
|
List<FeatureTree> input = CdmStore.getService(IFeatureTreeService.class).list(FeatureTree.class, null, null, null, null);
|
85 |
ddcbd609
|
Alexander Oppermann
|
|
86 |
cfcb0ce6
|
n.hoffmann
|
viewer.setInput(input);
|
87 |
ddcbd609
|
Alexander Oppermann
|
|
88 |
cfcb0ce6
|
n.hoffmann
|
if(defaultFeatureTreeForTextualDescription != null){
|
89 |
|
|
IStructuredSelection selection = new StructuredSelection(defaultFeatureTreeForTextualDescription);
|
90 |
|
|
viewer.setSelection(selection, true);
|
91 |
|
|
}
|
92 |
|
|
}
|
93 |
ddcbd609
|
Alexander Oppermann
|
|
94 |
cfcb0ce6
|
n.hoffmann
|
private void createStructureTreeSelection(Composite parent){
|
95 |
|
|
final CLabel label = new CLabel(parent, SWT.NONE);
|
96 |
dbb4a896
|
Patrick Plitzner
|
label.setText("Default Feature Tree to be used for structured descriptions");
|
97 |
ddcbd609
|
Alexander Oppermann
|
|
98 |
cfcb0ce6
|
n.hoffmann
|
final ListViewer viewer = new ListViewer(parent);
|
99 |
|
|
viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
100 |
ddcbd609
|
Alexander Oppermann
|
|
101 |
cfcb0ce6
|
n.hoffmann
|
viewer.setContentProvider(new FeatureTreeContentProvider());
|
102 |
|
|
viewer.setLabelProvider(new FeatureTreeLabelProvider());
|
103 |
ddcbd609
|
Alexander Oppermann
|
|
104 |
cfcb0ce6
|
n.hoffmann
|
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
|
105 |
ddcbd609
|
Alexander Oppermann
|
|
106 |
cfcb0ce6
|
n.hoffmann
|
@Override
|
107 |
|
|
public void selectionChanged(SelectionChangedEvent arg0) {
|
108 |
|
|
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
|
109 |
ddcbd609
|
Alexander Oppermann
|
|
110 |
cfcb0ce6
|
n.hoffmann
|
defaultFeatureTreeForStructuredDescription = (FeatureTree) selection.getFirstElement();
|
111 |
|
|
}
|
112 |
|
|
});
|
113 |
ddcbd609
|
Alexander Oppermann
|
|
114 |
db5e366d
|
n.hoffmann
|
List<FeatureTree> input = CdmStore.getService(IFeatureTreeService.class).list(FeatureTree.class, null, null, null, null);
|
115 |
ddcbd609
|
Alexander Oppermann
|
|
116 |
cfcb0ce6
|
n.hoffmann
|
viewer.setInput(input);
|
117 |
ddcbd609
|
Alexander Oppermann
|
|
118 |
cfcb0ce6
|
n.hoffmann
|
if(defaultFeatureTreeForStructuredDescription != null){
|
119 |
|
|
IStructuredSelection selection = new StructuredSelection(defaultFeatureTreeForStructuredDescription);
|
120 |
|
|
viewer.setSelection(selection, true);
|
121 |
|
|
}
|
122 |
|
|
}
|
123 |
|
|
|
124 |
3be6ef3e
|
n.hoffmann
|
/** {@inheritDoc} */
|
125 |
cfcb0ce6
|
n.hoffmann
|
@Override
|
126 |
|
|
public boolean performOk() {
|
127 |
e7afa732
|
n.hoffmann
|
String defaultFeatureTreeForTextualDescriptionUuid = "";
|
128 |
|
|
String defaultFeatureTreeForStructuredDescriptionUuid = "";
|
129 |
ddcbd609
|
Alexander Oppermann
|
|
130 |
e7afa732
|
n.hoffmann
|
if(defaultFeatureTreeForTextualDescription != null){
|
131 |
|
|
defaultFeatureTreeForTextualDescriptionUuid = defaultFeatureTreeForTextualDescription.getUuid().toString();
|
132 |
|
|
}
|
133 |
|
|
if(defaultFeatureTreeForStructuredDescription != null){
|
134 |
|
|
defaultFeatureTreeForStructuredDescriptionUuid = defaultFeatureTreeForStructuredDescription.getUuid().toString();
|
135 |
|
|
}
|
136 |
ddcbd609
|
Alexander Oppermann
|
|
137 |
e7afa732
|
n.hoffmann
|
getPreferenceStore().setValue(IPreferenceKeys.FEATURE_TREE_DEFAULT_TEXT, defaultFeatureTreeForTextualDescriptionUuid);
|
138 |
|
|
getPreferenceStore().setValue(IPreferenceKeys.FEATURE_TREE_DEFAULT_STRUCTURE, defaultFeatureTreeForStructuredDescriptionUuid);
|
139 |
ddcbd609
|
Alexander Oppermann
|
|
140 |
cfcb0ce6
|
n.hoffmann
|
return super.performOk();
|
141 |
|
|
}
|
142 |
|
|
}
|