2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.preference
;
12 import java
.util
.List
;
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
;
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
.model
.MessagingUtils
;
31 import eu
.etaxonomy
.taxeditor
.preference
.menu
.CdmPreferencePage
;
32 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
35 * <p>DefaultFeatureTreePreferenecs class.</p>
38 * @created Sep 16, 2010
41 public class DefaultFeatureTreePreferenecs
extends CdmPreferencePage
{
43 private FeatureTree defaultFeatureTreeForTextualDescription
;
44 private FeatureTree defaultFeatureTreeForStructuredDescription
;
48 protected Control
createContents(Composite parent
) {
49 defaultFeatureTreeForTextualDescription
= PreferencesUtil
.getDefaultFeatureTreeForTextualDescription();
50 defaultFeatureTreeForStructuredDescription
= PreferencesUtil
.getDefaultFeatureTreeForStructuredDescription();
52 Composite composite
= new Composite(parent
, SWT
.NULL
);
53 composite
.setLayout(new GridLayout());
54 if(!CdmStore
.isActive()) {
55 MessagingUtils
.noDataSourceWarningDialog(null);
57 createTextTreeSelection(composite
);
58 createStructureTreeSelection(composite
);
64 private void createTextTreeSelection(Composite parent
){
65 final CLabel label
= new CLabel(parent
, SWT
.NONE
);
66 label
.setText("Default Feature Tree to be used for textual descriptions");
68 final ListViewer viewer
= new ListViewer(parent
);
69 viewer
.getControl().setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
71 viewer
.setContentProvider(new FeatureTreeContentProvider());
72 viewer
.setLabelProvider(new FeatureTreeLabelProvider());
74 viewer
.addSelectionChangedListener(new ISelectionChangedListener() {
77 public void selectionChanged(SelectionChangedEvent arg0
) {
78 IStructuredSelection selection
= (IStructuredSelection
) viewer
.getSelection();
80 defaultFeatureTreeForTextualDescription
= (FeatureTree
) selection
.getFirstElement();
84 List
<FeatureTree
> input
= CdmStore
.getService(IFeatureTreeService
.class).list(FeatureTree
.class, null, null, null, null);
86 viewer
.setInput(input
);
88 if(defaultFeatureTreeForTextualDescription
!= null){
89 IStructuredSelection selection
= new StructuredSelection(defaultFeatureTreeForTextualDescription
);
90 viewer
.setSelection(selection
, true);
94 private void createStructureTreeSelection(Composite parent
){
95 final CLabel label
= new CLabel(parent
, SWT
.NONE
);
96 label
.setText("Default Feature Tree to be used for structured descriptions");
98 final ListViewer viewer
= new ListViewer(parent
);
99 viewer
.getControl().setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
101 viewer
.setContentProvider(new FeatureTreeContentProvider());
102 viewer
.setLabelProvider(new FeatureTreeLabelProvider());
104 viewer
.addSelectionChangedListener(new ISelectionChangedListener() {
107 public void selectionChanged(SelectionChangedEvent arg0
) {
108 IStructuredSelection selection
= (IStructuredSelection
) viewer
.getSelection();
110 defaultFeatureTreeForStructuredDescription
= (FeatureTree
) selection
.getFirstElement();
114 List
<FeatureTree
> input
= CdmStore
.getService(IFeatureTreeService
.class).list(FeatureTree
.class, null, null, null, null);
116 viewer
.setInput(input
);
118 if(defaultFeatureTreeForStructuredDescription
!= null){
119 IStructuredSelection selection
= new StructuredSelection(defaultFeatureTreeForStructuredDescription
);
120 viewer
.setSelection(selection
, true);
126 public boolean performOk() {
127 String defaultFeatureTreeForTextualDescriptionUuid
= "";
128 String defaultFeatureTreeForStructuredDescriptionUuid
= "";
130 if(defaultFeatureTreeForTextualDescription
!= null){
131 defaultFeatureTreeForTextualDescriptionUuid
= defaultFeatureTreeForTextualDescription
.getUuid().toString();
133 if(defaultFeatureTreeForStructuredDescription
!= null){
134 defaultFeatureTreeForStructuredDescriptionUuid
= defaultFeatureTreeForStructuredDescription
.getUuid().toString();
137 getPreferenceStore().setValue(IPreferenceKeys
.FEATURE_TREE_DEFAULT_TEXT
, defaultFeatureTreeForTextualDescriptionUuid
);
138 getPreferenceStore().setValue(IPreferenceKeys
.FEATURE_TREE_DEFAULT_STRUCTURE
, defaultFeatureTreeForStructuredDescriptionUuid
);
140 return super.performOk();