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
.model
.MessagingUtils
;
33 import eu
.etaxonomy
.taxeditor
.preference
.menu
.CdmPreferencePage
;
34 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
37 * <p>DefaultFeatureTreePreferenecs class.</p>
40 * @created Sep 16, 2010
43 public class DefaultFeatureTreePreferenecs
extends CdmPreferencePage
{
45 private FeatureTree defaultFeatureTreeForTextualDescription
;
46 private FeatureTree defaultFeatureTreeForStructuredDescription
;
49 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
54 protected Control
createContents(Composite parent
) {
55 defaultFeatureTreeForTextualDescription
= PreferencesUtil
.getDefaultFeatureTreeForTextualDescription();
56 defaultFeatureTreeForStructuredDescription
= PreferencesUtil
.getDefaultFeatureTreeForStructuredDescription();
58 Composite composite
= new Composite(parent
, SWT
.NULL
);
59 composite
.setLayout(new GridLayout());
60 if(!CdmStore
.isActive()) {
61 MessagingUtils
.noDataSourceWarningDialog(null);
63 createTextTreeSelection(composite
);
64 createStructureTreeSelection(composite
);
70 private void createTextTreeSelection(Composite parent
){
71 final CLabel label
= new CLabel(parent
, SWT
.NONE
);
72 label
.setText("Deafult Feature Tree to be used for textual descriptions");
74 final ListViewer viewer
= new ListViewer(parent
);
75 viewer
.getControl().setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
77 viewer
.setContentProvider(new FeatureTreeContentProvider());
78 viewer
.setLabelProvider(new FeatureTreeLabelProvider());
80 viewer
.addSelectionChangedListener(new ISelectionChangedListener() {
83 public void selectionChanged(SelectionChangedEvent arg0
) {
84 IStructuredSelection selection
= (IStructuredSelection
) viewer
.getSelection();
86 defaultFeatureTreeForTextualDescription
= (FeatureTree
) selection
.getFirstElement();
90 List
<FeatureTree
> input
= CdmStore
.getService(IFeatureTreeService
.class).list(FeatureTree
.class, null, null, null, null);
92 viewer
.setInput(input
);
94 if(defaultFeatureTreeForTextualDescription
!= null){
95 IStructuredSelection selection
= new StructuredSelection(defaultFeatureTreeForTextualDescription
);
96 viewer
.setSelection(selection
, true);
100 private void createStructureTreeSelection(Composite parent
){
101 final CLabel label
= new CLabel(parent
, SWT
.NONE
);
102 label
.setText("Deafult Feature Tree to be used for structured descriptions");
104 final ListViewer viewer
= new ListViewer(parent
);
105 viewer
.getControl().setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
107 viewer
.setContentProvider(new FeatureTreeContentProvider());
108 viewer
.setLabelProvider(new FeatureTreeLabelProvider());
110 viewer
.addSelectionChangedListener(new ISelectionChangedListener() {
113 public void selectionChanged(SelectionChangedEvent arg0
) {
114 IStructuredSelection selection
= (IStructuredSelection
) viewer
.getSelection();
116 defaultFeatureTreeForStructuredDescription
= (FeatureTree
) selection
.getFirstElement();
120 List
<FeatureTree
> input
= CdmStore
.getService(IFeatureTreeService
.class).list(FeatureTree
.class, null, null, null, null);
122 viewer
.setInput(input
);
124 if(defaultFeatureTreeForStructuredDescription
!= null){
125 IStructuredSelection selection
= new StructuredSelection(defaultFeatureTreeForStructuredDescription
);
126 viewer
.setSelection(selection
, true);
132 setPreferenceStore(PreferencesUtil
.getPreferenceStore());
137 public boolean performOk() {
138 String defaultFeatureTreeForTextualDescriptionUuid
= "";
139 String defaultFeatureTreeForStructuredDescriptionUuid
= "";
141 if(defaultFeatureTreeForTextualDescription
!= null){
142 defaultFeatureTreeForTextualDescriptionUuid
= defaultFeatureTreeForTextualDescription
.getUuid().toString();
144 if(defaultFeatureTreeForStructuredDescription
!= null){
145 defaultFeatureTreeForStructuredDescriptionUuid
= defaultFeatureTreeForStructuredDescription
.getUuid().toString();
148 getPreferenceStore().setValue(IPreferenceKeys
.FEATURE_TREE_DEFAULT_TEXT
, defaultFeatureTreeForTextualDescriptionUuid
);
149 getPreferenceStore().setValue(IPreferenceKeys
.FEATURE_TREE_DEFAULT_STRUCTURE
, defaultFeatureTreeForStructuredDescriptionUuid
);
151 return super.performOk();