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
;
14 import java
.util
.logging
.ErrorManager
;
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
.DeleteResult
;
35 import eu
.etaxonomy
.cdm
.api
.service
.IFeatureTreeService
;
36 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
37 import eu
.etaxonomy
.taxeditor
.model
.DeleteResultMessagingUtils
;
38 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
39 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
42 * <p>SelectFeatureTreeWizardPage class.</p>
45 * @created Aug 5, 2010
48 public class SelectFeatureTreeWizardPage
extends WizardPage
implements ISelectionChangedListener
, ModifyListener
{
50 private ListViewer viewer
;
51 private Text text_title
;
52 private Button button_add
;
53 private Button button_remove
;
56 * <p>Constructor for SelectFeatureTreeWizardPage.</p>
58 * @param pageName a {@link java.lang.String} object.
60 protected SelectFeatureTreeWizardPage(String pageName
) {
62 setMessage("Select a Feature Tree or create a new one.");
66 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
70 public void createControl(Composite parent
) {
71 Composite composite
= new Composite(parent
, SWT
.NULL
);
73 composite
.setLayout(new GridLayout());
75 Composite composite_treeContent
= new Composite(composite
, SWT
.NULL
);
76 composite_treeContent
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
,
78 composite_treeContent
.setLayout(new GridLayout(2, false));
80 viewer
= new ListViewer(composite_treeContent
);
81 viewer
.getControl().setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
83 button_remove
= new Button(composite_treeContent
, SWT
.PUSH
);
84 button_remove
.setText("Remove");
85 button_remove
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.TOP
, false, false));
87 Composite composite_treeTitle
= new Composite(composite
, SWT
.NULL
);
88 composite_treeTitle
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true,
90 composite_treeTitle
.setLayout(new GridLayout(3, false));
94 Label label_title
= new Label(composite_treeTitle
, SWT
.NULL
);
95 label_title
.setText("New Feature Tree");
97 text_title
= new Text(composite_treeTitle
, SWT
.NULL
);
98 text_title
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
100 button_add
= new Button(composite_treeTitle
, SWT
.PUSH
);
101 button_add
.setText("Add");
103 viewer
.setContentProvider(new FeatureTreeContentProvider());
104 viewer
.setLabelProvider(new FeatureTreeLabelProvider());
106 viewer
.addSelectionChangedListener(this);
108 text_title
.addModifyListener(this);
109 button_add
.addSelectionListener(new AddButtonSelectionListener());
110 button_remove
.addSelectionListener(new RemoveButtonSelectionListener());
112 List
<FeatureTree
> input
= CdmStore
.getService(IFeatureTreeService
.class).list(FeatureTree
.class, null, null, null, null);
114 viewer
.setInput(input
);
116 setControl(composite
);
121 public void selectionChanged(SelectionChangedEvent event
) {
122 IStructuredSelection selection
= (IStructuredSelection
) event
.getSelection();
124 if(selection
.size() == 1){
125 FeatureTree selectedFeatureTree
= (FeatureTree
) selection
.getFirstElement();
126 ((FeatureTreeEditorWizard
) getWizard()).setSelectedFeatureTree(selectedFeatureTree
);
130 setPageComplete(true);
132 button_remove
.setEnabled(selection
.size() >= 1);
137 public boolean canFlipToNextPage() {
138 return ((IStructuredSelection
) viewer
.getSelection()).size() == 1;
143 public void modifyText(ModifyEvent e
) {
144 button_add
.setEnabled(! text_title
.getText().isEmpty());
147 private class AddButtonSelectionListener
extends SelectionAdapter
{
149 public void widgetSelected(SelectionEvent e
) {
150 FeatureTree featureTree
= FeatureTree
.NewInstance();
151 featureTree
.setTitleCache(text_title
.getText(), true);
153 viewer
.add(featureTree
);
154 if(CdmStore
.getCurrentSessionManager().isRemoting()) {
155 CdmStore
.getService(IFeatureTreeService
.class).merge(featureTree
, true);
157 CdmStore
.getService(IFeatureTreeService
.class).saveOrUpdate(featureTree
);
159 text_title
.setText("");
160 viewer
.setSelection(new StructuredSelection(featureTree
));
165 private class RemoveButtonSelectionListener
extends SelectionAdapter
{
167 public void widgetSelected(SelectionEvent e
) {
168 IStructuredSelection selection
= (IStructuredSelection
) viewer
.getSelection();
169 Object source
= e
.getSource();
170 for(Object element
: selection
.toArray()){
171 viewer
.remove(element
);
172 ((FeatureTreeEditorWizard
) getWizard()).setSelectedFeatureTree(null);
173 DeleteResult result
= CdmStore
.getService(IFeatureTreeService
.class).delete(((FeatureTree
) element
).getUuid());
175 if (result
.isError()){
176 DeleteResultMessagingUtils
.messageDialogWithDetails(result
, "The delete of the feature tree was not successful.", null);
178 viewer
.setSelection(new StructuredSelection(new Object
[0]));