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
.DeleteResult
;
34 import eu
.etaxonomy
.cdm
.api
.service
.IFeatureTreeService
;
35 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
36 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
39 * <p>SelectFeatureTreeWizardPage class.</p>
42 * @created Aug 5, 2010
45 public class SelectFeatureTreeWizardPage
extends WizardPage
implements ISelectionChangedListener
, ModifyListener
{
47 private ListViewer viewer
;
48 private Text text_title
;
49 private Button button_add
;
50 private Button button_remove
;
53 * <p>Constructor for SelectFeatureTreeWizardPage.</p>
55 * @param pageName a {@link java.lang.String} object.
57 protected SelectFeatureTreeWizardPage(String pageName
) {
59 setMessage("Select a Feature Tree or create a new one.");
63 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
67 public void createControl(Composite parent
) {
68 Composite composite
= new Composite(parent
, SWT
.NULL
);
70 composite
.setLayout(new GridLayout());
72 Composite composite_treeContent
= new Composite(composite
, SWT
.NULL
);
73 composite_treeContent
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
,
75 composite_treeContent
.setLayout(new GridLayout(2, false));
77 viewer
= new ListViewer(composite_treeContent
);
78 viewer
.getControl().setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
80 button_remove
= new Button(composite_treeContent
, SWT
.PUSH
);
81 button_remove
.setText("Remove");
82 button_remove
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.TOP
, false, false));
84 Composite composite_treeTitle
= new Composite(composite
, SWT
.NULL
);
85 composite_treeTitle
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true,
87 composite_treeTitle
.setLayout(new GridLayout(3, false));
91 Label label_title
= new Label(composite_treeTitle
, SWT
.NULL
);
92 label_title
.setText("New Feature Tree");
94 text_title
= new Text(composite_treeTitle
, SWT
.NULL
);
95 text_title
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
97 button_add
= new Button(composite_treeTitle
, SWT
.PUSH
);
98 button_add
.setText("Add");
100 viewer
.setContentProvider(new FeatureTreeContentProvider());
101 viewer
.setLabelProvider(new FeatureTreeLabelProvider());
103 viewer
.addSelectionChangedListener(this);
105 text_title
.addModifyListener(this);
106 button_add
.addSelectionListener(new AddButtonSelectionListener());
107 button_remove
.addSelectionListener(new RemoveButtonSelectionListener());
109 List
<FeatureTree
> input
= CdmStore
.getService(IFeatureTreeService
.class).list(FeatureTree
.class, null, null, null, null);
111 viewer
.setInput(input
);
113 setControl(composite
);
118 public void selectionChanged(SelectionChangedEvent event
) {
119 IStructuredSelection selection
= (IStructuredSelection
) event
.getSelection();
121 if(selection
.size() == 1){
122 FeatureTree selectedFeatureTree
= (FeatureTree
) selection
.getFirstElement();
123 ((FeatureTreeEditorWizard
) getWizard()).setSelectedFeatureTree(selectedFeatureTree
);
127 setPageComplete(true);
129 button_remove
.setEnabled(selection
.size() >= 1);
134 public boolean canFlipToNextPage() {
135 return ((IStructuredSelection
) viewer
.getSelection()).size() == 1;
140 public void modifyText(ModifyEvent e
) {
141 button_add
.setEnabled(! text_title
.getText().isEmpty());
144 private class AddButtonSelectionListener
extends SelectionAdapter
{
146 public void widgetSelected(SelectionEvent e
) {
147 FeatureTree featureTree
= FeatureTree
.NewInstance();
148 featureTree
.setTitleCache(text_title
.getText(), true);
150 viewer
.add(featureTree
);
151 if(CdmStore
.getCurrentSessionManager().isRemoting()) {
152 CdmStore
.getService(IFeatureTreeService
.class).merge(featureTree
);
154 CdmStore
.getService(IFeatureTreeService
.class).saveOrUpdate(featureTree
);
156 text_title
.setText("");
157 viewer
.setSelection(new StructuredSelection(featureTree
));
162 private class RemoveButtonSelectionListener
extends SelectionAdapter
{
164 public void widgetSelected(SelectionEvent e
) {
165 IStructuredSelection selection
= (IStructuredSelection
) viewer
.getSelection();
166 for(Object element
: selection
.toArray()){
167 viewer
.remove(element
);
169 DeleteResult result
= CdmStore
.getService(IFeatureTreeService
.class).delete(((FeatureTree
) element
).getUuid());
171 if (result
.isError()){
174 viewer
.setSelection(new StructuredSelection(new Object
[0]));