Project

General

Profile

« Previous | Next » 

Revision 9d63acde

Added by Cherian Mathew over 8 years ago

#5301 Add merge call for saving new feature tree

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/SelectFeatureTreeWizardPage.java
1 1
// $Id$
2 2
/**
3 3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
4
* European Distributed Institute of Taxonomy
5 5
* http://www.e-taxonomy.eu
6
* 
6
*
7 7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8 8
* See LICENSE.TXT at the top of this package for the full license terms.
9 9
*/
......
12 12

  
13 13
import java.util.List;
14 14

  
15
import org.eclipse.core.commands.ExecutionException;
16 15
import org.eclipse.jface.viewers.ISelectionChangedListener;
17 16
import org.eclipse.jface.viewers.IStructuredSelection;
18 17
import org.eclipse.jface.viewers.ListViewer;
......
33 32

  
34 33
import eu.etaxonomy.cdm.api.service.DeleteResult;
35 34
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
36
import eu.etaxonomy.cdm.api.service.exception.DataChangeNoRollbackException;
37 35
import eu.etaxonomy.cdm.model.description.FeatureTree;
38 36
import eu.etaxonomy.taxeditor.store.CdmStore;
39
import eu.etaxonomy.taxeditor.store.StoreUtil;
40 37

  
41 38
/**
42 39
 * <p>SelectFeatureTreeWizardPage class.</p>
......
61 58
		super(pageName);
62 59
		setMessage("Select a Feature Tree or create a new one.");
63 60
	}
64
	
61

  
65 62
	/* (non-Javadoc)
66 63
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
67 64
	 */
......
69 66
	@Override
70 67
	public void createControl(Composite parent) {
71 68
		Composite composite = new Composite(parent, SWT.NULL);
72
		
69

  
73 70
		composite.setLayout(new GridLayout());
74
		
71

  
75 72
		Composite composite_treeContent = new Composite(composite, SWT.NULL);
76 73
		composite_treeContent.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
77 74
				true, true));
78 75
		composite_treeContent.setLayout(new GridLayout(2, false));
79
		
76

  
80 77
		viewer = new ListViewer(composite_treeContent);
81 78
		viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
82
	
79

  
83 80
		button_remove = new Button(composite_treeContent, SWT.PUSH);
84 81
		button_remove.setText("Remove");
85 82
		button_remove.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false));
86
		
83

  
87 84
		Composite composite_treeTitle = new Composite(composite, SWT.NULL);
88 85
		composite_treeTitle.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true,
89 86
				false));
90 87
		composite_treeTitle.setLayout(new GridLayout(3, false));
91 88

  
92
		
93
		
89

  
90

  
94 91
		Label label_title = new Label(composite_treeTitle, SWT.NULL);
95 92
		label_title.setText("New Feature Tree");
96 93

  
97 94
		text_title = new Text(composite_treeTitle, SWT.NULL);
98 95
		text_title.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
99
		
96

  
100 97
		button_add = new Button(composite_treeTitle, SWT.PUSH);
101 98
		button_add.setText("Add");
102
				
99

  
103 100
		viewer.setContentProvider(new FeatureTreeContentProvider());
104 101
		viewer.setLabelProvider(new FeatureTreeLabelProvider());
105
		
102

  
106 103
		viewer.addSelectionChangedListener(this);
107
		
104

  
108 105
		text_title.addModifyListener(this);
109 106
		button_add.addSelectionListener(new AddButtonSelectionListener());
110 107
		button_remove.addSelectionListener(new RemoveButtonSelectionListener());
111
		
108

  
112 109
		List<FeatureTree> input = CdmStore.getService(IFeatureTreeService.class).list(FeatureTree.class, null, null, null, null);
113
		
110

  
114 111
		viewer.setInput(input);
115 112
		modifyText(null);
116 113
		setControl(composite);
......
120 117
	@Override
121 118
	public void selectionChanged(SelectionChangedEvent event) {
122 119
		IStructuredSelection selection = (IStructuredSelection) event.getSelection();
123
			
120

  
124 121
		if(selection.size() == 1){
125 122
			FeatureTree selectedFeatureTree = (FeatureTree) selection.getFirstElement();
126 123
			((FeatureTreeEditorWizard) getWizard()).setSelectedFeatureTree(selectedFeatureTree);
127
			
124

  
128 125
		}
129
		
126

  
130 127
		setPageComplete(true);
131
		
128

  
132 129
		button_remove.setEnabled(selection.size() >= 1);
133 130
	}
134 131

  
......
137 134
	public boolean canFlipToNextPage() {
138 135
		return ((IStructuredSelection) viewer.getSelection()).size() == 1;
139 136
	}
140
	
137

  
141 138
	/** {@inheritDoc} */
142 139
	@Override
143 140
	public void modifyText(ModifyEvent e) {
144 141
		button_add.setEnabled(! text_title.getText().isEmpty());
145 142
	}
146
	
143

  
147 144
	private class AddButtonSelectionListener extends SelectionAdapter {
148
		public void widgetSelected(SelectionEvent e) {
145
		@Override
146
        public void widgetSelected(SelectionEvent e) {
149 147
			FeatureTree featureTree = FeatureTree.NewInstance();
150 148
			featureTree.setTitleCache(text_title.getText(), true);
151
			
149

  
152 150
			viewer.add(featureTree);
153
			CdmStore.getService(IFeatureTreeService.class).saveOrUpdate(featureTree);
151
			if(CdmStore.getCurrentSessionManager().isRemoting()) {
152
                CdmStore.getService(IFeatureTreeService.class).merge(featureTree);
153
			} else {
154
			    CdmStore.getService(IFeatureTreeService.class).saveOrUpdate(featureTree);
155
			}
154 156
			text_title.setText("");
155 157
			viewer.setSelection(new StructuredSelection(featureTree));
156
			
158

  
157 159
		}
158 160
	}
159
	
161

  
160 162
	private class RemoveButtonSelectionListener extends SelectionAdapter {
161
		public void widgetSelected(SelectionEvent e) {
163
		@Override
164
        public void widgetSelected(SelectionEvent e) {
162 165
			IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
163 166
			for(Object element : selection.toArray()){
164 167
				viewer.remove(element);
165
				
166
				DeleteResult result =	CdmStore.getService(IFeatureTreeService.class).delete((FeatureTree) element);
167
				
168

  
169
				DeleteResult result =	CdmStore.getService(IFeatureTreeService.class).delete(((FeatureTree) element).getUuid());
170

  
168 171
				if (result.isError()){
169
					
172

  
170 173
				}
171 174
				viewer.setSelection(new StructuredSelection(new Object[0]));
172 175
			}

Also available in: Unified diff