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 javax
.annotation
.PostConstruct
;
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
;
28 import eu
.etaxonomy
.cdm
.api
.service
.IFeatureTreeService
;
29 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
30 import eu
.etaxonomy
.taxeditor
.featuretree
.FeatureTreeContentProvider
;
31 import eu
.etaxonomy
.taxeditor
.featuretree
.FeatureTreeLabelProvider
;
32 import eu
.etaxonomy
.taxeditor
.preference
.menu
.CdmPreferencePage
;
33 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
36 * <p>DefaultFeatureTreePreferenecs class.</p>
39 * @created Sep 16, 2010
42 public class DefaultFeatureTreePreferenecs
extends CdmPreferencePage
{
44 private FeatureTree defaultFeatureTreeForTextualDescription
;
45 private FeatureTree defaultFeatureTreeForStructuredDescription
;
48 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
53 protected Control
createContents(Composite parent
) {
54 defaultFeatureTreeForTextualDescription
= PreferencesUtil
.getDefaultFeatureTreeForTextualDescription();
55 defaultFeatureTreeForStructuredDescription
= PreferencesUtil
.getDefaultFeatureTreeForStructuredDescription();
57 Composite composite
= new Composite(parent
, SWT
.NULL
);
58 composite
.setLayout(new GridLayout());
59 if(CdmStore
.isActive()) {
60 createTextTreeSelection(composite
);
61 createStructureTreeSelection(composite
);
67 private void createTextTreeSelection(Composite parent
){
68 final CLabel label
= new CLabel(parent
, SWT
.NONE
);
69 label
.setText("Deafult Feature Tree to be used for textual descriptions");
71 final ListViewer viewer
= new ListViewer(parent
);
72 viewer
.getControl().setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
74 viewer
.setContentProvider(new FeatureTreeContentProvider());
75 viewer
.setLabelProvider(new FeatureTreeLabelProvider());
77 viewer
.addSelectionChangedListener(new ISelectionChangedListener() {
80 public void selectionChanged(SelectionChangedEvent arg0
) {
81 IStructuredSelection selection
= (IStructuredSelection
) viewer
.getSelection();
83 defaultFeatureTreeForTextualDescription
= (FeatureTree
) selection
.getFirstElement();
87 List
<FeatureTree
> input
= CdmStore
.getService(IFeatureTreeService
.class).list(FeatureTree
.class, null, null, null, null);
89 viewer
.setInput(input
);
91 if(defaultFeatureTreeForTextualDescription
!= null){
92 IStructuredSelection selection
= new StructuredSelection(defaultFeatureTreeForTextualDescription
);
93 viewer
.setSelection(selection
, true);
97 private void createStructureTreeSelection(Composite parent
){
98 final CLabel label
= new CLabel(parent
, SWT
.NONE
);
99 label
.setText("Default Feature Tree to be used for structured descriptions");
101 final ListViewer viewer
= new ListViewer(parent
);
102 viewer
.getControl().setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
104 viewer
.setContentProvider(new FeatureTreeContentProvider());
105 viewer
.setLabelProvider(new FeatureTreeLabelProvider());
107 viewer
.addSelectionChangedListener(new ISelectionChangedListener() {
110 public void selectionChanged(SelectionChangedEvent arg0
) {
111 IStructuredSelection selection
= (IStructuredSelection
) viewer
.getSelection();
113 defaultFeatureTreeForStructuredDescription
= (FeatureTree
) selection
.getFirstElement();
117 List
<FeatureTree
> input
= CdmStore
.getService(IFeatureTreeService
.class).list(FeatureTree
.class, null, null, null, null);
119 viewer
.setInput(input
);
121 if(defaultFeatureTreeForStructuredDescription
!= null){
122 IStructuredSelection selection
= new StructuredSelection(defaultFeatureTreeForStructuredDescription
);
123 viewer
.setSelection(selection
, true);
129 setPreferenceStore(PreferencesUtil
.getPreferenceStore());
134 public boolean performOk() {
135 String defaultFeatureTreeForTextualDescriptionUuid
= "";
136 String defaultFeatureTreeForStructuredDescriptionUuid
= "";
138 if(defaultFeatureTreeForTextualDescription
!= null){
139 defaultFeatureTreeForTextualDescriptionUuid
= defaultFeatureTreeForTextualDescription
.getUuid().toString();
141 if(defaultFeatureTreeForStructuredDescription
!= null){
142 defaultFeatureTreeForStructuredDescriptionUuid
= defaultFeatureTreeForStructuredDescription
.getUuid().toString();
145 getPreferenceStore().setValue(IPreferenceKeys
.FEATURE_TREE_DEFAULT_TEXT
, defaultFeatureTreeForTextualDescriptionUuid
);
146 getPreferenceStore().setValue(IPreferenceKeys
.FEATURE_TREE_DEFAULT_STRUCTURE
, defaultFeatureTreeForStructuredDescriptionUuid
);
148 return super.performOk();