ref #6190 removing svn property place holder in first line of code - java files
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / preference / DefaultFeatureTreePreferenecs.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
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 import org.eclipse.ui.IWorkbench;
26 import org.eclipse.ui.IWorkbenchPreferencePage;
27
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;
35
36 /**
37 * <p>DefaultFeatureTreePreferenecs class.</p>
38 *
39 * @author n.hoffmann
40 * @created Sep 16, 2010
41 * @version 1.0
42 */
43 public class DefaultFeatureTreePreferenecs extends CdmPreferencePage 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 /** {@inheritDoc} */
52 @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 if(!CdmStore.isActive()) {
60 MessagingUtils.noDataSourceWarningDialog(null);
61 }else{
62 createTextTreeSelection(composite);
63 createStructureTreeSelection(composite);
64 }
65
66 return composite;
67 }
68
69 private void createTextTreeSelection(Composite parent){
70 final CLabel label = new CLabel(parent, SWT.NONE);
71 label.setText("Deafult Feature Tree to be used for textual descriptions");
72
73 final ListViewer viewer = new ListViewer(parent);
74 viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
75
76 viewer.setContentProvider(new FeatureTreeContentProvider());
77 viewer.setLabelProvider(new FeatureTreeLabelProvider());
78
79 viewer.addSelectionChangedListener(new ISelectionChangedListener() {
80
81 @Override
82 public void selectionChanged(SelectionChangedEvent arg0) {
83 IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
84
85 defaultFeatureTreeForTextualDescription = (FeatureTree) selection.getFirstElement();
86 }
87 });
88
89 List<FeatureTree> input = CdmStore.getService(IFeatureTreeService.class).list(FeatureTree.class, null, null, null, null);
90
91 viewer.setInput(input);
92
93 if(defaultFeatureTreeForTextualDescription != null){
94 IStructuredSelection selection = new StructuredSelection(defaultFeatureTreeForTextualDescription);
95 viewer.setSelection(selection, true);
96 }
97 }
98
99 private void createStructureTreeSelection(Composite parent){
100 final CLabel label = new CLabel(parent, SWT.NONE);
101 label.setText("Deafult Feature Tree to be used for structured descriptions");
102
103 final ListViewer viewer = new ListViewer(parent);
104 viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
105
106 viewer.setContentProvider(new FeatureTreeContentProvider());
107 viewer.setLabelProvider(new FeatureTreeLabelProvider());
108
109 viewer.addSelectionChangedListener(new ISelectionChangedListener() {
110
111 @Override
112 public void selectionChanged(SelectionChangedEvent arg0) {
113 IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
114
115 defaultFeatureTreeForStructuredDescription = (FeatureTree) selection.getFirstElement();
116 }
117 });
118
119 List<FeatureTree> input = CdmStore.getService(IFeatureTreeService.class).list(FeatureTree.class, null, null, null, null);
120
121 viewer.setInput(input);
122
123 if(defaultFeatureTreeForStructuredDescription != null){
124 IStructuredSelection selection = new StructuredSelection(defaultFeatureTreeForStructuredDescription);
125 viewer.setSelection(selection, true);
126 }
127 }
128
129 /** {@inheritDoc} */
130 @Override
131 public void init(IWorkbench workbench) {
132 setPreferenceStore(PreferencesUtil.getPreferenceStore());
133 }
134
135 /** {@inheritDoc} */
136 @Override
137 public boolean performOk() {
138 String defaultFeatureTreeForTextualDescriptionUuid = "";
139 String defaultFeatureTreeForStructuredDescriptionUuid = "";
140
141 if(defaultFeatureTreeForTextualDescription != null){
142 defaultFeatureTreeForTextualDescriptionUuid = defaultFeatureTreeForTextualDescription.getUuid().toString();
143 }
144 if(defaultFeatureTreeForStructuredDescription != null){
145 defaultFeatureTreeForStructuredDescriptionUuid = defaultFeatureTreeForStructuredDescription.getUuid().toString();
146 }
147
148 getPreferenceStore().setValue(IPreferenceKeys.FEATURE_TREE_DEFAULT_TEXT, defaultFeatureTreeForTextualDescriptionUuid);
149 getPreferenceStore().setValue(IPreferenceKeys.FEATURE_TREE_DEFAULT_STRUCTURE, defaultFeatureTreeForStructuredDescriptionUuid);
150
151 return super.performOk();
152 }
153 }