add new class openDistributionPerAreaStatusAdminWizardHandler - continue
[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
26 import eu.etaxonomy.cdm.api.service.ITermTreeService;
27 import eu.etaxonomy.cdm.model.term.TermTree;
28 import eu.etaxonomy.taxeditor.l10n.Messages;
29 import eu.etaxonomy.taxeditor.model.MessagingUtils;
30 import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
31 import eu.etaxonomy.taxeditor.store.CdmStore;
32 import eu.etaxonomy.taxeditor.termtree.TermTreeContentProvider;
33 import eu.etaxonomy.taxeditor.termtree.TermTreeLabelProvider;
34
35 /**
36 * <p>DefaultFeatureTreePreferenecs class.</p>
37 *
38 * @author n.hoffmann
39 * @created Sep 16, 2010
40 */
41 public class DefaultFeatureTreePreferenecs extends CdmPreferencePage {
42
43 private TermTree defaultFeatureTreeForTextualDescription;
44 private TermTree defaultFeatureTreeForStructuredDescription;
45
46 /** {@inheritDoc} */
47 @Override
48 protected Control createContents(Composite parent) {
49 defaultFeatureTreeForTextualDescription = PreferencesUtil.getDefaultFeatureTreeForTextualDescription();
50 defaultFeatureTreeForStructuredDescription = PreferencesUtil.getDefaultFeatureTreeForStructuredDescription();
51
52 Composite composite = new Composite(parent, SWT.NULL);
53 composite.setLayout(new GridLayout());
54 if(!CdmStore.isActive()) {
55 MessagingUtils.noDataSourceWarningDialog(null);
56 }else{
57 createStructureTreeSelection(composite);
58 createTextTreeSelection(composite);
59 }
60
61 return composite;
62 }
63
64 private void createTextTreeSelection(Composite parent){
65 final CLabel label = new CLabel(parent, SWT.NONE);
66 label.setText(Messages.DefaultFeatureTreePreferenecs_0);
67
68 final ListViewer viewer = new ListViewer(parent, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
69 viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
70
71 viewer.setContentProvider(new TermTreeContentProvider());
72 viewer.setLabelProvider(new TermTreeLabelProvider());
73
74 viewer.addSelectionChangedListener(new ISelectionChangedListener() {
75
76 @Override
77 public void selectionChanged(SelectionChangedEvent arg0) {
78 setApply(true);
79 // viewer.setSelection(arg0.getSelection());
80 IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
81
82 defaultFeatureTreeForTextualDescription = (TermTree)selection.getFirstElement();
83
84 }
85 });
86
87 List<TermTree> input = CdmStore.getService(ITermTreeService.class).list(TermTree.class, null, null, null, null);
88
89 viewer.setInput(input);
90
91 if(defaultFeatureTreeForTextualDescription != null){
92 IStructuredSelection selection = new StructuredSelection(defaultFeatureTreeForTextualDescription);
93 viewer.setSelection(selection, true);
94 }
95 }
96
97 private void createStructureTreeSelection(Composite parent){
98 final CLabel label = new CLabel(parent, SWT.NONE);
99 label.setText(Messages.DefaultFeatureTreePreferenecs_1);
100
101 final ListViewer viewer = new ListViewer(parent, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
102
103 viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
104
105 viewer.setContentProvider(new TermTreeContentProvider());
106 viewer.setLabelProvider(new TermTreeLabelProvider());
107
108 viewer.addSelectionChangedListener(new ISelectionChangedListener() {
109
110 @Override
111 public void selectionChanged(SelectionChangedEvent arg0) {
112 setApply(true);
113 // viewer.setSelection(arg0.getSelection());
114 IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
115
116 defaultFeatureTreeForStructuredDescription = (TermTree) selection.getFirstElement();
117
118 }
119 });
120
121 List<TermTree> input = CdmStore.getService(ITermTreeService.class).list(TermTree.class, null, null, null, null);
122
123 viewer.setInput(input);
124
125 if(defaultFeatureTreeForStructuredDescription != null){
126 IStructuredSelection selection = new StructuredSelection(defaultFeatureTreeForStructuredDescription);
127 viewer.setSelection(selection, true);
128 }
129 }
130
131 /** {@inheritDoc} */
132 @Override
133 public boolean performOk() {
134 String defaultFeatureTreeForTextualDescriptionUuid = ""; //$NON-NLS-1$
135 String defaultFeatureTreeForStructuredDescriptionUuid = ""; //$NON-NLS-1$
136
137 if(defaultFeatureTreeForTextualDescription != null){
138 defaultFeatureTreeForTextualDescriptionUuid = defaultFeatureTreeForTextualDescription.getUuid().toString();
139 }
140 if(defaultFeatureTreeForStructuredDescription != null){
141 defaultFeatureTreeForStructuredDescriptionUuid = defaultFeatureTreeForStructuredDescription.getUuid().toString();
142 }
143
144 getPreferenceStore().setValue(PreferencesUtil.createPreferenceString(IPreferenceKeys.FEATURE_TREE_DEFAULT_TEXT), defaultFeatureTreeForTextualDescriptionUuid);
145 getPreferenceStore().setValue(PreferencesUtil.createPreferenceString(IPreferenceKeys.FEATURE_TREE_DEFAULT_STRUCTURE), defaultFeatureTreeForStructuredDescriptionUuid);
146
147 return super.performOk();
148 }
149 }