// $Id$
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
-*
+*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
import java.util.List;
-import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ListViewer;
import eu.etaxonomy.cdm.api.service.DeleteResult;
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
-import eu.etaxonomy.cdm.api.service.exception.DataChangeNoRollbackException;
import eu.etaxonomy.cdm.model.description.FeatureTree;
import eu.etaxonomy.taxeditor.store.CdmStore;
-import eu.etaxonomy.taxeditor.store.StoreUtil;
/**
* <p>SelectFeatureTreeWizardPage class.</p>
super(pageName);
setMessage("Select a Feature Tree or create a new one.");
}
-
+
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NULL);
-
+
composite.setLayout(new GridLayout());
-
+
Composite composite_treeContent = new Composite(composite, SWT.NULL);
composite_treeContent.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
true, true));
composite_treeContent.setLayout(new GridLayout(2, false));
-
+
viewer = new ListViewer(composite_treeContent);
viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-
+
button_remove = new Button(composite_treeContent, SWT.PUSH);
button_remove.setText("Remove");
button_remove.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false));
-
+
Composite composite_treeTitle = new Composite(composite, SWT.NULL);
composite_treeTitle.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true,
false));
composite_treeTitle.setLayout(new GridLayout(3, false));
-
-
+
+
Label label_title = new Label(composite_treeTitle, SWT.NULL);
label_title.setText("New Feature Tree");
text_title = new Text(composite_treeTitle, SWT.NULL);
text_title.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
-
+
button_add = new Button(composite_treeTitle, SWT.PUSH);
button_add.setText("Add");
-
+
viewer.setContentProvider(new FeatureTreeContentProvider());
viewer.setLabelProvider(new FeatureTreeLabelProvider());
-
+
viewer.addSelectionChangedListener(this);
-
+
text_title.addModifyListener(this);
button_add.addSelectionListener(new AddButtonSelectionListener());
button_remove.addSelectionListener(new RemoveButtonSelectionListener());
-
+
List<FeatureTree> input = CdmStore.getService(IFeatureTreeService.class).list(FeatureTree.class, null, null, null, null);
-
+
viewer.setInput(input);
modifyText(null);
setControl(composite);
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
-
+
if(selection.size() == 1){
FeatureTree selectedFeatureTree = (FeatureTree) selection.getFirstElement();
((FeatureTreeEditorWizard) getWizard()).setSelectedFeatureTree(selectedFeatureTree);
-
+
}
-
+
setPageComplete(true);
-
+
button_remove.setEnabled(selection.size() >= 1);
}
public boolean canFlipToNextPage() {
return ((IStructuredSelection) viewer.getSelection()).size() == 1;
}
-
+
/** {@inheritDoc} */
@Override
public void modifyText(ModifyEvent e) {
button_add.setEnabled(! text_title.getText().isEmpty());
}
-
+
private class AddButtonSelectionListener extends SelectionAdapter {
- public void widgetSelected(SelectionEvent e) {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
FeatureTree featureTree = FeatureTree.NewInstance();
featureTree.setTitleCache(text_title.getText(), true);
-
+
viewer.add(featureTree);
- CdmStore.getService(IFeatureTreeService.class).saveOrUpdate(featureTree);
+ if(CdmStore.getCurrentSessionManager().isRemoting()) {
+ CdmStore.getService(IFeatureTreeService.class).merge(featureTree);
+ } else {
+ CdmStore.getService(IFeatureTreeService.class).saveOrUpdate(featureTree);
+ }
text_title.setText("");
viewer.setSelection(new StructuredSelection(featureTree));
-
+
}
}
-
+
private class RemoveButtonSelectionListener extends SelectionAdapter {
- public void widgetSelected(SelectionEvent e) {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
for(Object element : selection.toArray()){
viewer.remove(element);
-
- DeleteResult result = CdmStore.getService(IFeatureTreeService.class).delete((FeatureTree) element);
-
+
+ DeleteResult result = CdmStore.getService(IFeatureTreeService.class).delete(((FeatureTree) element).getUuid());
+
if (result.isError()){
-
+
}
viewer.setSelection(new StructuredSelection(new Object[0]));
}