3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.featuretree
;
13 import java
.util
.List
;
15 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
16 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
17 import org
.eclipse
.jface
.viewers
.ListViewer
;
18 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
19 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
20 import org
.eclipse
.jface
.wizard
.WizardPage
;
21 import org
.eclipse
.swt
.SWT
;
22 import org
.eclipse
.swt
.events
.ModifyEvent
;
23 import org
.eclipse
.swt
.events
.ModifyListener
;
24 import org
.eclipse
.swt
.events
.SelectionAdapter
;
25 import org
.eclipse
.swt
.events
.SelectionEvent
;
26 import org
.eclipse
.swt
.layout
.GridData
;
27 import org
.eclipse
.swt
.layout
.GridLayout
;
28 import org
.eclipse
.swt
.widgets
.Button
;
29 import org
.eclipse
.swt
.widgets
.Composite
;
30 import org
.eclipse
.swt
.widgets
.Label
;
31 import org
.eclipse
.swt
.widgets
.Text
;
33 import eu
.etaxonomy
.cdm
.api
.service
.IFeatureTreeService
;
34 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
35 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
38 * <p>SelectFeatureTreeWizardPage class.</p>
41 * @created Aug 5, 2010
44 public class SelectFeatureTreeWizardPage
extends WizardPage
implements ISelectionChangedListener
, ModifyListener
{
46 private ListViewer viewer
;
47 private Text text_title
;
48 private Button button_add
;
49 private Button button_remove
;
52 * <p>Constructor for SelectFeatureTreeWizardPage.</p>
54 * @param pageName a {@link java.lang.String} object.
56 protected SelectFeatureTreeWizardPage(String pageName
) {
58 setMessage("Select a Feature Tree or create a new one.");
62 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
66 public void createControl(Composite parent
) {
67 Composite composite
= new Composite(parent
, SWT
.NULL
);
69 composite
.setLayout(new GridLayout());
71 Composite composite_treeContent
= new Composite(composite
, SWT
.NULL
);
72 composite_treeContent
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
,
74 composite_treeContent
.setLayout(new GridLayout(2, false));
76 viewer
= new ListViewer(composite_treeContent
);
77 viewer
.getControl().setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
79 button_remove
= new Button(composite_treeContent
, SWT
.PUSH
);
80 button_remove
.setText("Remove");
81 button_remove
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.TOP
, false, false));
83 Composite composite_treeTitle
= new Composite(composite
, SWT
.NULL
);
84 composite_treeTitle
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true,
86 composite_treeTitle
.setLayout(new GridLayout(3, false));
90 Label label_title
= new Label(composite_treeTitle
, SWT
.NULL
);
91 label_title
.setText("New Feature Tree");
93 text_title
= new Text(composite_treeTitle
, SWT
.NULL
);
94 text_title
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
96 button_add
= new Button(composite_treeTitle
, SWT
.PUSH
);
97 button_add
.setText("Add");
99 viewer
.setContentProvider(new FeatureTreeContentProvider());
100 viewer
.setLabelProvider(new FeatureTreeLabelProvider());
102 viewer
.addSelectionChangedListener(this);
104 text_title
.addModifyListener(this);
105 button_add
.addSelectionListener(new AddButtonSelectionListener());
106 button_remove
.addSelectionListener(new RemoveButtonSelectionListener());
108 List
<FeatureTree
> input
= CdmStore
.getService(IFeatureTreeService
.class).list(FeatureTree
.class, null, null, null, null);
110 viewer
.setInput(input
);
112 setControl(composite
);
117 public void selectionChanged(SelectionChangedEvent event
) {
118 IStructuredSelection selection
= (IStructuredSelection
) event
.getSelection();
120 if(selection
.size() == 1){
121 FeatureTree selectedFeatureTree
= (FeatureTree
) selection
.getFirstElement();
122 ((FeatureTreeEditorWizard
) getWizard()).setSelectedFeatureTree(selectedFeatureTree
);
126 setPageComplete(true);
128 button_remove
.setEnabled(selection
.size() >= 1);
133 public boolean canFlipToNextPage() {
134 return ((IStructuredSelection
) viewer
.getSelection()).size() == 1;
139 public void modifyText(ModifyEvent e
) {
140 button_add
.setEnabled(! text_title
.getText().isEmpty());
143 private class AddButtonSelectionListener
extends SelectionAdapter
{
144 public void widgetSelected(SelectionEvent e
) {
145 FeatureTree featureTree
= FeatureTree
.NewInstance();
146 featureTree
.setTitleCache(text_title
.getText(), true);
148 viewer
.add(featureTree
);
149 CdmStore
.getService(IFeatureTreeService
.class).saveOrUpdate(featureTree
);
150 text_title
.setText("");
151 viewer
.setSelection(new StructuredSelection(featureTree
));
156 private class RemoveButtonSelectionListener
extends SelectionAdapter
{
157 public void widgetSelected(SelectionEvent e
) {
158 IStructuredSelection selection
= (IStructuredSelection
) viewer
.getSelection();
159 for(Object element
: selection
.toArray()){
160 viewer
.remove(element
);
161 CdmStore
.getService(IFeatureTreeService
.class).delete((FeatureTree
) element
);
162 viewer
.setSelection(new StructuredSelection(new Object
[0]));