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
.core
.commands
.ExecutionException
;
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
.jface
.wizard
.WizardPage
;
22 import org
.eclipse
.swt
.SWT
;
23 import org
.eclipse
.swt
.events
.ModifyEvent
;
24 import org
.eclipse
.swt
.events
.ModifyListener
;
25 import org
.eclipse
.swt
.events
.SelectionAdapter
;
26 import org
.eclipse
.swt
.events
.SelectionEvent
;
27 import org
.eclipse
.swt
.layout
.GridData
;
28 import org
.eclipse
.swt
.layout
.GridLayout
;
29 import org
.eclipse
.swt
.widgets
.Button
;
30 import org
.eclipse
.swt
.widgets
.Composite
;
31 import org
.eclipse
.swt
.widgets
.Label
;
32 import org
.eclipse
.swt
.widgets
.Text
;
34 import eu
.etaxonomy
.cdm
.api
.service
.IFeatureTreeService
;
35 import eu
.etaxonomy
.cdm
.api
.service
.exception
.DataChangeNoRollbackException
;
36 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
37 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
38 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
41 * <p>SelectFeatureTreeWizardPage class.</p>
44 * @created Aug 5, 2010
47 public class SelectFeatureTreeWizardPage
extends WizardPage
implements ISelectionChangedListener
, ModifyListener
{
49 private ListViewer viewer
;
50 private Text text_title
;
51 private Button button_add
;
52 private Button button_remove
;
55 * <p>Constructor for SelectFeatureTreeWizardPage.</p>
57 * @param pageName a {@link java.lang.String} object.
59 protected SelectFeatureTreeWizardPage(String pageName
) {
61 setMessage("Select a Feature Tree or create a new one.");
65 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
69 public void createControl(Composite parent
) {
70 Composite composite
= new Composite(parent
, SWT
.NULL
);
72 composite
.setLayout(new GridLayout());
74 Composite composite_treeContent
= new Composite(composite
, SWT
.NULL
);
75 composite_treeContent
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
,
77 composite_treeContent
.setLayout(new GridLayout(2, false));
79 viewer
= new ListViewer(composite_treeContent
);
80 viewer
.getControl().setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
82 button_remove
= new Button(composite_treeContent
, SWT
.PUSH
);
83 button_remove
.setText("Remove");
84 button_remove
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.TOP
, false, false));
86 Composite composite_treeTitle
= new Composite(composite
, SWT
.NULL
);
87 composite_treeTitle
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true,
89 composite_treeTitle
.setLayout(new GridLayout(3, false));
93 Label label_title
= new Label(composite_treeTitle
, SWT
.NULL
);
94 label_title
.setText("New Feature Tree");
96 text_title
= new Text(composite_treeTitle
, SWT
.NULL
);
97 text_title
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
99 button_add
= new Button(composite_treeTitle
, SWT
.PUSH
);
100 button_add
.setText("Add");
102 viewer
.setContentProvider(new FeatureTreeContentProvider());
103 viewer
.setLabelProvider(new FeatureTreeLabelProvider());
105 viewer
.addSelectionChangedListener(this);
107 text_title
.addModifyListener(this);
108 button_add
.addSelectionListener(new AddButtonSelectionListener());
109 button_remove
.addSelectionListener(new RemoveButtonSelectionListener());
111 List
<FeatureTree
> input
= CdmStore
.getService(IFeatureTreeService
.class).list(FeatureTree
.class, null, null, null, null);
113 viewer
.setInput(input
);
115 setControl(composite
);
120 public void selectionChanged(SelectionChangedEvent event
) {
121 IStructuredSelection selection
= (IStructuredSelection
) event
.getSelection();
123 if(selection
.size() == 1){
124 FeatureTree selectedFeatureTree
= (FeatureTree
) selection
.getFirstElement();
125 ((FeatureTreeEditorWizard
) getWizard()).setSelectedFeatureTree(selectedFeatureTree
);
129 setPageComplete(true);
131 button_remove
.setEnabled(selection
.size() >= 1);
136 public boolean canFlipToNextPage() {
137 return ((IStructuredSelection
) viewer
.getSelection()).size() == 1;
142 public void modifyText(ModifyEvent e
) {
143 button_add
.setEnabled(! text_title
.getText().isEmpty());
146 private class AddButtonSelectionListener
extends SelectionAdapter
{
147 public void widgetSelected(SelectionEvent e
) {
148 FeatureTree featureTree
= FeatureTree
.NewInstance();
149 featureTree
.setTitleCache(text_title
.getText(), true);
151 viewer
.add(featureTree
);
152 CdmStore
.getService(IFeatureTreeService
.class).saveOrUpdate(featureTree
);
153 text_title
.setText("");
154 viewer
.setSelection(new StructuredSelection(featureTree
));
159 private class RemoveButtonSelectionListener
extends SelectionAdapter
{
160 public void widgetSelected(SelectionEvent e
) {
161 IStructuredSelection selection
= (IStructuredSelection
) viewer
.getSelection();
162 for(Object element
: selection
.toArray()){
163 viewer
.remove(element
);
165 String result
= CdmStore
.getService(IFeatureTreeService
.class).delete((FeatureTree
) element
);
167 viewer
.setSelection(new StructuredSelection(new Object
[0]));