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