Project

General

Profile

Revision 4aca5046

ID4aca504657c8af3b325c218539b1175f8ecbf144
Parent d455719e
Child 47aa3510

Added by Patrick Plitzner about 3 years ago

ref #6694 Remove wizard pages and plugin configurations

View differences:

eu.etaxonomy.taxeditor.printpublisher/src/main/java/eu/etaxonomy/taxeditor/printpublisher/wizard/SelectFeatureTreeWizardPage.java
1 1
/**
2 2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
13 13
import java.util.List;
14 14
import java.util.UUID;
15 15

  
16
import org.eclipse.core.runtime.IStatus;
17 16
import org.eclipse.jface.viewers.ISelectionChangedListener;
18 17
import org.eclipse.jface.viewers.IStructuredContentProvider;
19 18
import org.eclipse.jface.viewers.IStructuredSelection;
......
22 21
import org.eclipse.jface.viewers.SelectionChangedEvent;
23 22
import org.eclipse.jface.viewers.StructuredSelection;
24 23
import org.eclipse.jface.viewers.Viewer;
25
import org.eclipse.jface.wizard.WizardDialog;
26 24
import org.eclipse.swt.SWT;
27 25
import org.eclipse.swt.events.SelectionAdapter;
28 26
import org.eclipse.swt.events.SelectionEvent;
......
34 32

  
35 33
import eu.etaxonomy.cdm.print.IXMLEntityFactory;
36 34
import eu.etaxonomy.cdm.print.XMLHelper;
37
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeEditorWizard;
38 35

  
39 36
/**
40 37
 * <p>SelectFeatureTreeWizardPage class.</p>
......
43 40
 * @created Aug 6, 2010
44 41
 * @version 1.0
45 42
 */
46
public class SelectFeatureTreeWizardPage extends AbstractPublishWizardPage 
43
public class SelectFeatureTreeWizardPage extends AbstractPublishWizardPage
47 44
	implements ISelectionChangedListener, IHasPersistableSettings{
48
	
45

  
49 46
	private static final String DIALOG_SETTING_FEATURE_TREE_UUID = "dialogSettingFeatureTreeUuid";
50 47
	private ListViewer viewer;
51 48

  
......
58 55
		super(pageName);
59 56
		setTitle("Select Feature Tree");
60 57
	}
61
	
58

  
62 59
	/* (non-Javadoc)
63 60
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
64 61
	 */
......
66 63
	@Override
67 64
	public void createControl(Composite parent) {
68 65
		setPageComplete(false);
69
		
66

  
70 67
		Composite composite = new Composite(parent, SWT.NULL);
71 68
		composite.setLayout(new GridLayout());
72
		
69

  
73 70
		viewer = new ListViewer(composite);
74 71
		viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
75 72
		viewer.setContentProvider(new FeatureTreeContentProvider());
76 73
		viewer.setLabelProvider(new FeatureTreeLabelProvider());
77
		
74

  
78 75
		viewer.addSelectionChangedListener(this);
79
				
76

  
80 77
		// offer feature tree editor when local
81 78
		if(getConfigurator().isLocal()){
82 79
			final Button button_openFeatureTree = new Button(composite, SWT.PUSH);
83 80
			button_openFeatureTree.setText("Open FeatureTree Editor");
84
			
81

  
85 82
			button_openFeatureTree.addSelectionListener(new SelectionAdapter() {
86 83
				@Override
87 84
				public void widgetSelected(SelectionEvent e) {
88
					FeatureTreeEditorWizard featureTreeEditorDialog = new FeatureTreeEditorWizard();
89
					WizardDialog dialog = new WizardDialog(getShell(), featureTreeEditorDialog);
90
					
91
					if(dialog.open() == IStatus.OK){
92
						refresh();
93
					}
85
				    //FIXME: this wizard page has been removed by implementing #6694
86
				    //If print publishing is used again the selection has to be re-implemented
87

  
88
//					FeatureTreeEditorWizard featureTreeEditorDialog = new FeatureTreeEditorWizard();
89
//					WizardDialog dialog = new WizardDialog(getShell(), featureTreeEditorDialog);
90
//
91
//					if(dialog.open() == IStatus.OK){
92
//						refresh();
93
//					}
94 94
				}
95 95
			});
96 96
		}
97
				
97

  
98 98
		// when using a local factory we can set the input right here
99 99
		if(getConfigurator() != null && getConfigurator().isLocal()){
100 100
			refresh();
101 101
		}
102
		
102

  
103 103
		loadSettings();
104
		
104

  
105 105
		setControl(composite);
106 106
	}
107 107

  
108 108
	@Override
109 109
	public void loadSettings() {
110
		String featureTreeUuidString = getDialogSettingValue(DIALOG_SETTING_FEATURE_TREE_UUID); 
111
		
110
		String featureTreeUuidString = getDialogSettingValue(DIALOG_SETTING_FEATURE_TREE_UUID);
111

  
112 112
		if(featureTreeUuidString != null){
113 113
			setSelectedFeatureTree(featureTreeUuidString);
114
			
114

  
115 115
		}
116 116
	}
117
	
117

  
118 118
	/** {@inheritDoc} */
119 119
	@Override
120 120
	public void selectionChanged(SelectionChangedEvent event) {
121 121
		IStructuredSelection selection = (IStructuredSelection) event.getSelection();
122
		
122

  
123 123
		if(selection.isEmpty()){
124 124
			return;
125 125
		}
126
		
126

  
127 127
		setPageComplete(true);
128
		
129
		
128

  
129

  
130 130
		Element featureTreeElement = (Element) selection.getFirstElement();
131
			
131

  
132 132
		UUID featureTreeUuid = XMLHelper.getUuid(featureTreeElement);
133
		
133

  
134 134
		setFeatureTree(featureTreeUuid.toString());
135 135
	}
136
	
136

  
137 137
	private void setSelectedFeatureTree(String featureTreeUuid){
138 138
		List<Element> input = (ArrayList<Element>) viewer.getInput();
139
		
139

  
140 140
		for(Element element : input){
141 141
			UUID uuid = XMLHelper.getUuid(element);
142 142
			if(uuid.toString().equals(featureTreeUuid)){
......
145 145
			}
146 146
		}
147 147
	}
148
	
148

  
149 149
	public void setFeatureTree(String featureTreeUuidString){
150 150
		putDialogSettingValue(DIALOG_SETTING_FEATURE_TREE_UUID, featureTreeUuidString);
151 151
		UUID featureTreeUuid = UUID.fromString(featureTreeUuidString);
152 152
		getConfigurator().setFeatureTree(featureTreeUuid);
153 153
		setPageComplete(featureTreeUuid != null);
154 154
	}
155
	
155

  
156 156
	/** {@inheritDoc} */
157 157
	@Override
158 158
	public boolean canFlipToNextPage() {
......
174 174
		}
175 175
		viewer.setInput(realFeatureTrees);
176 176
	}
177
	
177

  
178 178
	private class FeatureTreeContentProvider implements IStructuredContentProvider {
179 179

  
180 180
		@Override
......
190 190
			}
191 191
			return new Object[0];
192 192
		}
193
		
193

  
194 194
	}
195
	
195

  
196 196
	private class FeatureTreeLabelProvider extends LabelProvider {
197
		
197

  
198 198
		/*
199 199
		 * (non-Javadoc)
200 200
		 * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
......
202 202
		@Override
203 203
		public String getText(Object element) {
204 204
			if(element instanceof Element){
205
				Element xmlElement = (Element) element;			
205
				Element xmlElement = (Element) element;
206 206
				return XMLHelper.getTitleCache(xmlElement);
207 207
			}
208 208
			return "no title cache";
209 209
		}
210
		
210

  
211 211
	}
212 212
}
eu.etaxonomy.taxeditor.store/OSGI-INF/l10n/bundle.properties
21 21
page.name.18 = Team or Person Matching Strategy
22 22
page.name.19 = Stage
23 23
page.name.20 = Preservation Method
24
page.name.21 = Feature Tree
25 24
page.name.22 = Default Feature Trees
26 25
page.name.23 = Representation
27 26
page.name.24 = Mobot Open Url
eu.etaxonomy.taxeditor.store/OSGI-INF/l10n/bundle_de.properties
21 21
page.name.18 = Team oder Personen Matching-Strategie
22 22
page.name.19 = Stadium
23 23
page.name.20 = Konservierungsmethode
24
page.name.21 = Merkmalsbaum
25 24
page.name.22 = Standard Merkmalsbaum
26 25
page.name.23 = Repr\u00e4sentation
27 26
page.name.24 = Mobot Open Url
eu.etaxonomy.taxeditor.store/plugin.xml
167 167
      </page>
168 168
      <page
169 169
            category="eu.etaxonomy.taxeditor.preferences.feature"
170
            class="eu.etaxonomy.taxeditor.preference.FeatureTreePreferences"
171
            id="eu.etaxonomy.taxeditor.preferences.featureTree"
172
            name="%page.name.21">
173
      </page>
174
      <page
175
            category="eu.etaxonomy.taxeditor.preferences.feature"
176 170
            class="eu.etaxonomy.taxeditor.preference.DefaultFeatureTreePreferenecs"
177 171
            id="eu.etaxonomy.taxeditor.preferences.defaultFeatureTreePreferenecs"
178 172
            name="%page.name.22">
......
536 530
         </activeWhen>
537 531
      </handler>
538 532
      <handler
539
            class="eu.etaxonomy.taxeditor.featuretree.OpenFeatureTreeEditorWizardHandler"
540
            commandId="eu.etaxonomy.taxeditor.store.open.FeatureTreeEditorWizard">
541
         <activeWhen>
542
            <reference
543
                  definitionId="hasROLE_PROJECT_MANAGER">
544
            </reference>
545
         </activeWhen>
546
      </handler>
547
      <handler
548 533
            class="eu.etaxonomy.taxeditor.handler.ShowRemotingLoginWindowHandler"
549 534
            commandId="eu.etaxonomy.taxeditor.store.operations.showRemotingLoginWindow">
550 535
      </handler>
......
661 646
            name="%command.name.7">
662 647
      </command>
663 648
      <command
664
         id="eu.etaxonomy.taxeditor.store.open.FeatureTreeEditorWizard"
665
         name="%command.name.9">
666
   	  </command>
667
      <command
668 649
            id="eu.etaxonomy.taxeditor.store.openPasswordWizzard"
669 650
            name="%command.name.10">
670 651
      </command>
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/EditFeatureTreeWizardPage.java
1
/**
2
 * Copyright (C) 2007 EDIT
3
 * European Distributed Institute of Taxonomy
4
 * http://www.e-taxonomy.eu
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7
 * See LICENSE.TXT at the top of this package for the full license terms.
8
 */
9

  
10
package eu.etaxonomy.taxeditor.featuretree;
11

  
12
import java.util.Collection;
13

  
14
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.jface.viewers.ISelectionChangedListener;
16
import org.eclipse.jface.viewers.IStructuredSelection;
17
import org.eclipse.jface.viewers.SelectionChangedEvent;
18
import org.eclipse.jface.viewers.TreeViewer;
19
import org.eclipse.jface.viewers.Viewer;
20
import org.eclipse.jface.viewers.ViewerDropAdapter;
21
import org.eclipse.jface.wizard.WizardDialog;
22
import org.eclipse.jface.wizard.WizardPage;
23
import org.eclipse.swt.SWT;
24
import org.eclipse.swt.dnd.DND;
25
import org.eclipse.swt.dnd.DragSourceAdapter;
26
import org.eclipse.swt.dnd.DragSourceEvent;
27
import org.eclipse.swt.dnd.Transfer;
28
import org.eclipse.swt.dnd.TransferData;
29
import org.eclipse.swt.events.ModifyEvent;
30
import org.eclipse.swt.events.ModifyListener;
31
import org.eclipse.swt.events.SelectionAdapter;
32
import org.eclipse.swt.events.SelectionEvent;
33
import org.eclipse.swt.layout.GridData;
34
import org.eclipse.swt.layout.GridLayout;
35
import org.eclipse.swt.widgets.Button;
36
import org.eclipse.swt.widgets.Composite;
37
import org.eclipse.swt.widgets.Label;
38
import org.eclipse.swt.widgets.Text;
39
import org.hibernate.proxy.HibernateProxy;
40

  
41
import eu.etaxonomy.cdm.api.service.IFeatureNodeService;
42
import eu.etaxonomy.cdm.api.service.config.FeatureNodeDeletionConfigurator;
43
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
44
import eu.etaxonomy.cdm.model.description.Feature;
45
import eu.etaxonomy.cdm.model.description.FeatureNode;
46
import eu.etaxonomy.cdm.model.description.FeatureTree;
47
import eu.etaxonomy.taxeditor.model.MessagingUtils;
48
import eu.etaxonomy.taxeditor.store.CdmStore;
49

  
50
/**
51
 * <p>
52
 * EditFeatureTreeWizardPage class.
53
 * </p>
54
 *
55
 * @author n.hoffmann
56
 * @created Aug 5, 2010
57
 * @version 1.0
58
 */
59
public class EditFeatureTreeWizardPage extends WizardPage implements
60
		ModifyListener, ISelectionChangedListener {
61

  
62
	private TreeViewer viewer;
63
	private Label label_title;
64
	private Text text_title;
65
	private Button button_add;
66
	private Button button_remove;
67
	private Label label_treeInfo;
68
	private FeatureTree featureTree;
69

  
70
	/**
71
	 * <p>
72
	 * Constructor for EditFeatureTreeWizardPage.
73
	 * </p>
74
	 *
75
	 * @param pageName
76
	 *            a {@link java.lang.String} object.
77
	 */
78
	protected EditFeatureTreeWizardPage(String pageName) {
79
		super(pageName);
80
		setMessage("Edit the Feature Tree.");
81
	}
82

  
83
	/*
84
	 * (non-Javadoc)
85
	 *
86
	 * @see
87
	 * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
88
	 * .Composite)
89
	 */
90
	/** {@inheritDoc} */
91
	@Override
92
	public void createControl(Composite parent) {
93
		Composite composite = new Composite(parent, SWT.NULL);
94
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
95
		composite.setLayout(new GridLayout());
96

  
97
		Composite composite_treeTitle = new Composite(composite, SWT.NULL);
98
		composite_treeTitle.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true,
99
				false));
100
		composite_treeTitle.setLayout(new GridLayout(2, false));
101

  
102
		label_title = new Label(composite_treeTitle, SWT.NULL);
103
		label_title.setText("Title");
104

  
105
		text_title = new Text(composite_treeTitle, SWT.NULL);
106
		text_title.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
107

  
108
		Composite composite_treeContent = new Composite(composite, SWT.NULL);
109
		composite_treeContent.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
110
				true, true));
111
		composite_treeContent.setLayout(new GridLayout(2, false));
112

  
113
		viewer = new TreeViewer(composite_treeContent);
114
		viewer.getControl().setLayoutData(
115
				new GridData(SWT.FILL, SWT.FILL, true, true));
116

  
117
		Composite composite_buttons = new Composite(composite_treeContent,
118
				SWT.NULL);
119
		composite_buttons.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false,
120
				false));
121
		composite_buttons.setLayout(new GridLayout());
122

  
123
		button_add = new Button(composite_buttons, SWT.PUSH);
124
		button_add.setText("Add");
125
		button_add.setToolTipText("Add a feature to this feature treee.");
126
		button_remove = new Button(composite_buttons, SWT.PUSH);
127
		button_remove.setText("Remove");
128
		button_remove
129
				.setToolTipText("Remove a feature from this feature tree.");
130

  
131
		label_treeInfo = new Label(composite, SWT.NULL);
132
		label_treeInfo
133
				.setText("Order and nesting of feature nodes may be changed through drag and drop.");
134

  
135
		viewer.setContentProvider(new FeatureTreeContentProvider());
136
		viewer.setLabelProvider(new FeatureTreeLabelProvider());
137

  
138
		int ops = DND.DROP_COPY | DND.DROP_MOVE;
139
		Transfer[] transfers = new Transfer[] { FeatureNodeTransfer
140
				.getInstance() };
141
		viewer.addDragSupport(ops, transfers, new FeatureNodeDragListener(
142
				viewer));
143
		viewer.addDropSupport(ops, transfers,
144
				new FeatureNodeDropAdapter(viewer));
145

  
146
		viewer.addSelectionChangedListener(this);
147

  
148
		button_add.addSelectionListener(new AddButtonListener());
149
		button_remove.addSelectionListener(new RemoveSelectionListener());
150

  
151
		setControl(composite);
152
	}
153

  
154
	/**
155
	 * <p>
156
	 * setSelectedTree
157
	 * </p>
158
	 *
159
	 * @param featureTree
160
	 *            a {@link eu.etaxonomy.cdm.model.description.FeatureTree}
161
	 *            object.
162
	 */
163
	public void setSelectedTree(FeatureTree featureTree) {
164
		this.featureTree = HibernateProxyHelper.deproxy(featureTree, FeatureTree.class);
165
		this.featureTree.setRoot(HibernateProxyHelper.deproxy(featureTree.getRoot(), FeatureNode.class));
166
		viewer.setInput(featureTree);
167

  
168
		text_title.removeModifyListener(this);
169
		if (featureTree != null){
170
			text_title.setText(featureTree.getTitleCache());
171
		}
172
		text_title.addModifyListener(this);
173
	}
174

  
175
	/** {@inheritDoc} */
176
	@Override
177
	public void modifyText(ModifyEvent e) {
178
		featureTree.setTitleCache(text_title.getText(), true);
179
	}
180

  
181
	/** {@inheritDoc} */
182
	@Override
183
	public void selectionChanged(SelectionChangedEvent event) {
184
		IStructuredSelection selection = (IStructuredSelection) event
185
				.getSelection();
186

  
187
		button_add.setEnabled(selection.size() <= 1);
188
		button_remove.setEnabled(selection.size() > 0);
189
	}
190

  
191
	private class AddButtonListener extends SelectionAdapter {
192
		@Override
193
		public void widgetSelected(SelectionEvent e) {
194
			AvailableFeaturesWizard wizard = new AvailableFeaturesWizard(
195
					featureTree);
196
			WizardDialog dialog = new WizardDialog(getShell(), wizard);
197

  
198
			if (dialog.open() == IStatus.OK) {
199
				IStructuredSelection selection = (IStructuredSelection) viewer
200
						.getSelection();
201
				FeatureNode parent = (FeatureNode) (selection.getFirstElement() != null ? selection
202
						.getFirstElement() : ((FeatureTree) viewer.getInput())
203
						.getRoot());
204
				Collection<Feature> additionalFeatures = wizard
205
						.getAdditionalFeatures();
206
				for (Feature feature : additionalFeatures) {
207
					FeatureNode child = FeatureNode.NewInstance(feature);
208
					CdmStore.getService(IFeatureNodeService.class).merge(child, true);
209
					
210
					parent.addChild(child);
211
				}
212
				viewer.refresh();
213
			}
214
		}
215
	}
216

  
217
	private class RemoveSelectionListener extends SelectionAdapter {
218
		@Override
219
		public void widgetSelected(SelectionEvent e) {
220
			IStructuredSelection selection = (IStructuredSelection) viewer
221
					.getSelection();
222

  
223
			for (Object selectedObject : selection.toArray()) {
224
				FeatureNode featureNode = (FeatureNode) selectedObject;
225
				FeatureNode parent = featureNode.getParent();
226
				parent.removeChild(featureNode);
227
				
228
				CdmStore.getService(IFeatureNodeService.class).deleteFeatureNode(featureNode.getUuid(), new FeatureNodeDeletionConfigurator());
229
				
230
			}
231
			viewer.refresh();
232
		}
233
	}
234

  
235
	private class FeatureNodeDragListener extends DragSourceAdapter {
236

  
237
		private final TreeViewer viewer;
238

  
239
		public FeatureNodeDragListener(TreeViewer viewer) {
240
			this.viewer = viewer;
241
		}
242

  
243
		/**
244
		 * Method declared on DragSourceListener
245
		 */
246
		@Override
247
		public void dragFinished(DragSourceEvent event) {
248
			if (!event.doit) {
249
                return;
250
            }
251
			// if the featureNode was moved, remove it from the source viewer
252
			if (event.detail == DND.DROP_MOVE) {
253
				IStructuredSelection selection = (IStructuredSelection) viewer
254
						.getSelection();
255
				viewer.refresh();
256
			}
257
		}
258

  
259
		/**
260
		 * Method declared on DragSourceListener
261
		 */
262
		@Override
263
		public void dragSetData(DragSourceEvent event) {
264
			IStructuredSelection selection = (IStructuredSelection) viewer
265
					.getSelection();
266
			FeatureNode[] featureNodes = (FeatureNode[]) selection.toList()
267
					.toArray(new FeatureNode[selection.size()]);
268
			if (FeatureNodeTransfer.getInstance().isSupportedType(
269
					event.dataType)) {
270
				event.data = featureNodes;
271
			}
272
		}
273

  
274
		/**
275
		 * Method declared on DragSourceListener
276
		 */
277
		@Override
278
		public void dragStart(DragSourceEvent event) {
279
			event.doit = !viewer.getSelection().isEmpty();
280
		}
281

  
282
	}
283

  
284
	private class FeatureNodeDropAdapter extends ViewerDropAdapter {
285

  
286
		protected FeatureNodeDropAdapter(Viewer viewer) {
287
			super(viewer);
288
		}
289

  
290
		@Override
291
		public boolean performDrop(Object data) {
292
			FeatureNode target = (FeatureNode) getCurrentTarget();
293
			int position = 0;
294

  
295
			if (target != null) {
296
				int location = getCurrentLocation();
297
				FeatureNode parent = target.getParent();
298
				if (location == LOCATION_BEFORE) {
299
					position = Math.max(0, parent.getIndex(target) - 1);
300
					target = parent;
301
				}
302

  
303
				if (location == LOCATION_AFTER) {
304
					position = parent.getIndex(target);
305
					target = parent;
306
				}
307
			}
308

  
309
			// set target to root node if there is no target specified
310
			if (target == null) {
311
				FeatureTree featureTree = (FeatureTree) getViewer().getInput();
312
				target = featureTree.getRoot();
313
			}
314

  
315
			Object[] droppedObjects = (Object[]) data;
316
			TreeViewer viewer = (TreeViewer) getViewer();
317

  
318
			// cannot drop a feature node onto itself
319
			for (Object droppedObject : droppedObjects) {
320
				if (droppedObject == null) {
321
					MessagingUtils.warningDialog(
322
									"Operation not supported yet",
323
									this,
324
									"We are currently unable to change the order of freshly created "
325
											+ "feature trees nodes. Please close and reopen the dialog to change the order of features.");
326
					return false;
327
				}
328
				if (droppedObject.equals(target)) {
329
					return false;
330
				}
331
			}
332
			for (Object droppedObject : droppedObjects) {
333
				FeatureNode droppedNode = (FeatureNode) droppedObject;
334
				target.addChild(droppedNode, position);
335
				viewer.add(target, droppedNode);
336
				viewer.reveal(droppedNode);
337
			}
338
			return true;
339
		}
340

  
341
		@Override
342
		public boolean validateDrop(Object target, int operation,
343
				TransferData transferData) {
344
			return FeatureNodeTransfer.getInstance().isSupportedType(
345
					transferData);
346
		}
347

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

  
10
package eu.etaxonomy.taxeditor.featuretree;
11

  
12
import java.util.Arrays;
13
import java.util.List;
14
import java.util.Map;
15

  
16
import org.eclipse.jface.wizard.Wizard;
17

  
18
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
19
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
20
import eu.etaxonomy.cdm.model.description.FeatureTree;
21
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
22
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
23
import eu.etaxonomy.taxeditor.store.CdmStore;
24

  
25
/**
26
 * <p>FeatureTreeEditorWizard class.</p>
27
 *
28
 * @author n.hoffmann
29
 * @created Aug 5, 2010
30
 * @version 1.0
31
 */
32
public class FeatureTreeEditorWizard extends Wizard implements ICdmEntitySessionEnabled {
33

  
34
	private SelectFeatureTreeWizardPage selectFeatureTreePage;
35
	private EditFeatureTreeWizardPage editFeatureTreePage;
36

  
37
	private FeatureTree selectedFeatureTree;
38

  
39
	private ConversationHolder conversation;
40
	private ICdmEntitySession cdmEntitySession;
41
	private ICdmEntitySession previousCdmEntitySession;
42

  
43
	/**
44
	 * <p>Constructor for FeatureTreeEditorWizard.</p>
45
	 */
46
	public FeatureTreeEditorWizard(){
47
		conversation = CdmStore.createConversation();
48
		previousCdmEntitySession = CdmStore.getCurrentSessionManager().getActiveSession();
49
		cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
50
		setWindowTitle("Feature Tree Editor");
51
	}
52

  
53
	/**
54
	 * <p>addPages</p>
55
	 */
56
	@Override
57
    public void addPages() {
58
		selectFeatureTreePage = new SelectFeatureTreeWizardPage("SELECT");
59
		addPage(selectFeatureTreePage);
60

  
61
		editFeatureTreePage = new EditFeatureTreeWizardPage("EDIT");
62
		addPage(editFeatureTreePage);
63
	}
64

  
65

  
66

  
67
	/** {@inheritDoc} */
68
	@Override
69
	public boolean performFinish() {
70
		try{
71
			if (selectedFeatureTree != null){
72
			    CdmStore.getService(IFeatureTreeService.class).merge(selectedFeatureTree, true);
73
			}
74
			conversation.commit();
75
		}finally{
76
			conversation.close();
77
			cdmEntitySession.dispose();
78
			if(previousCdmEntitySession != null) {
79
			    previousCdmEntitySession.bind();
80
			}
81
		}
82

  
83
		return true;
84
	}
85

  
86
	/** {@inheritDoc} */
87
    @Override
88
    public boolean performCancel() {
89
        cdmEntitySession.dispose();
90
        if(previousCdmEntitySession != null) {
91
            previousCdmEntitySession.bind();
92
        }
93
        return true;
94
    }
95

  
96
	/**
97
	 * <p>Setter for the field <code>selectedFeatureTree</code>.</p>
98
	 *
99
	 * @param selectedFeatureTree the selectedFeatureTree to set
100
	 */
101
	public void setSelectedFeatureTree(FeatureTree selectedFeatureTree) {
102
		this.selectedFeatureTree = selectedFeatureTree;
103
		editFeatureTreePage.setSelectedTree(selectedFeatureTree);
104
	}
105

  
106
	/**
107
	 * <p>Getter for the field <code>selectedFeatureTree</code>.</p>
108
	 *
109
	 * @return the selectedFeatureTree
110
	 */
111
	public FeatureTree getSelectedFeatureTree() {
112
		return selectedFeatureTree;
113
	}
114

  
115
    /* (non-Javadoc)
116
     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getCdmEntitySession()
117
     */
118
    @Override
119
    public ICdmEntitySession getCdmEntitySession() {
120
        // TODO Auto-generated method stub
121
        return null;
122
    }
123

  
124
    /* (non-Javadoc)
125
     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
126
     */
127
    @Override
128
    public List<FeatureTree> getRootEntities() {
129
        return Arrays.asList(selectedFeatureTree);
130
    }
131

  
132
    /* (non-Javadoc)
133
     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap()
134
     */
135
    @Override
136
    public Map<Object, List<String>> getPropertyPathsMap() {
137
        // TODO Auto-generated method stub
138
        return null;
139
    }
140

  
141
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/OpenFeatureTreeEditorWizardHandler.java
1
package eu.etaxonomy.taxeditor.featuretree;
2

  
3
import org.eclipse.core.commands.AbstractHandler;
4
import org.eclipse.core.commands.ExecutionEvent;
5
import org.eclipse.core.commands.ExecutionException;
6
import org.eclipse.jface.wizard.WizardDialog;
7

  
8
import eu.etaxonomy.taxeditor.store.StoreUtil;
9

  
10
/**
11
 * 
12
 * @author a.kohlbecker
13
 *
14
 */
15
public class OpenFeatureTreeEditorWizardHandler extends AbstractHandler {
16
	
17
	/**
18
	 * unused, only added as reference
19
	 */
20
	String commandID = "eu.etaxonomy.taxeditor.store.open.FeatureTreeEditorWizard"; 
21

  
22
	@Override
23
	public Object execute(ExecutionEvent event) throws ExecutionException {
24
		FeatureTreeEditorWizard featureTreeEditorDialog = new FeatureTreeEditorWizard();
25
		WizardDialog dialog = new WizardDialog(StoreUtil.getShell(),
26
				featureTreeEditorDialog);
27

  
28
		dialog.open();
29
		return null;
30
	}
31

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

  
10
package eu.etaxonomy.taxeditor.featuretree;
11

  
12
import org.eclipse.jface.wizard.Wizard;
13

  
14
/**
15
 * <p>SelectFeatureTreeWizard class.</p>
16
 *
17
 * @author n.hoffmann
18
 * @created Sep 17, 2010
19
 * @version 1.0
20
 */
21
public class SelectFeatureTreeWizard extends Wizard {
22

  
23
	/** Constant <code>PAGE_NAME="Select Feature Tree"</code> */
24
	public static final String PAGE_NAME = "Select Feature Tree";
25
	
26
	/** {@inheritDoc} */
27
	@Override
28
	public void addPages() {
29
		addPage(new SelectFeatureTreeWizardPage(PAGE_NAME));
30
	}
31
	
32
	/* (non-Javadoc)
33
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
34
	 */
35
	/** {@inheritDoc} */
36
	@Override
37
	public boolean performFinish() {
38
		return false;
39
	}
40
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/SelectFeatureTreeWizardPage.java
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

  
10
package eu.etaxonomy.taxeditor.featuretree;
11

  
12
import java.util.List;
13
import java.util.logging.ErrorManager;
14

  
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;
32

  
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.model.DeleteResultMessagingUtils;
37
import eu.etaxonomy.taxeditor.model.MessagingUtils;
38
import eu.etaxonomy.taxeditor.store.CdmStore;
39

  
40
/**
41
 * <p>SelectFeatureTreeWizardPage class.</p>
42
 *
43
 * @author n.hoffmann
44
 * @created Aug 5, 2010
45
 * @version 1.0
46
 */
47
public class SelectFeatureTreeWizardPage extends WizardPage implements ISelectionChangedListener, ModifyListener{
48

  
49
	private ListViewer viewer;
50
	private Text text_title;
51
	private Button button_add;
52
	private Button button_remove;
53

  
54
	/**
55
	 * <p>Constructor for SelectFeatureTreeWizardPage.</p>
56
	 *
57
	 * @param pageName a {@link java.lang.String} object.
58
	 */
59
	protected SelectFeatureTreeWizardPage(String pageName) {
60
		super(pageName);
61
		setMessage("Select a Feature Tree or create a new one.");
62
	}
63

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

  
72
		composite.setLayout(new GridLayout());
73

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

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

  
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));
85

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

  
91

  
92

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

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

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

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

  
105
		viewer.addSelectionChangedListener(this);
106

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

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

  
113
		viewer.setInput(input);
114
		modifyText(null);
115
		setControl(composite);
116
	}
117

  
118
	/** {@inheritDoc} */
119
	@Override
120
	public void selectionChanged(SelectionChangedEvent event) {
121
		IStructuredSelection selection = (IStructuredSelection) event.getSelection();
122

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

  
127
		}
128

  
129
		setPageComplete(true);
130

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

  
134
	/** {@inheritDoc} */
135
	@Override
136
	public boolean canFlipToNextPage() {
137
		return ((IStructuredSelection) viewer.getSelection()).size() == 1;
138
	}
139

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

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

  
152
			viewer.add(featureTree);
153
			CdmStore.getService(IFeatureTreeService.class).merge(featureTree, true);
154
			
155
			text_title.setText("");
156
			viewer.setSelection(new StructuredSelection(featureTree));
157

  
158
		}
159
	}
160

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

  
171
				if (result.isError()){
172
					DeleteResultMessagingUtils.messageDialogWithDetails(result, "The delete of the feature tree was not successful.", null);
173
				}
174
				viewer.setSelection(new StructuredSelection(new Object[0]));
175
			}
176
		}
177
	}
178
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/FeatureTreePreferences.java
1
/**
2
 * Copyright (C) 2007 EDIT
3
 * European Distributed Institute of Taxonomy
4
 * http://www.e-taxonomy.eu
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7
 * See LICENSE.TXT at the top of this package for the full license terms.
8
 */
9

  
10
package eu.etaxonomy.taxeditor.preference;
11

  
12
import org.eclipse.jface.resource.ImageDescriptor;
13
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.layout.GridLayout;
15
import org.eclipse.swt.widgets.Composite;
16
import org.eclipse.swt.widgets.Control;
17
import org.eclipse.ui.IWorkbench;
18
import org.eclipse.ui.IWorkbenchPreferencePage;
19

  
20
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
21
import eu.etaxonomy.taxeditor.store.CdmStore;
22
import eu.etaxonomy.taxeditor.ui.element.CommandHandlerButton;
23

  
24
/**
25
 * <p>
26
 * FeatureTreePreferences class.
27
 * </p>
28
 *
29
 * @author n.hoffmann
30
 * @created Aug 5, 2010
31
 * @version 1.0
32
 */
33
public class FeatureTreePreferences extends CdmPreferencePage implements
34
		IWorkbenchPreferencePage {
35

  
36
	/**
37
	 * <p>
38
	 * Constructor for FeatureTreePreferences.
39
	 * </p>
40
	 */
41
	public FeatureTreePreferences() {
42
	}
43

  
44
	/**
45
	 * <p>
46
	 * Constructor for FeatureTreePreferences.
47
	 * </p>
48
	 *
49
	 * @param title
50
	 *            a {@link java.lang.String} object.
51
	 */
52
	public FeatureTreePreferences(String title) {
53
		super(title);
54
	}
55

  
56
	/**
57
	 * <p>
58
	 * Constructor for FeatureTreePreferences.
59
	 * </p>
60
	 *
61
	 * @param title
62
	 *            a {@link java.lang.String} object.
63
	 * @param image
64
	 *            a {@link org.eclipse.jface.resource.ImageDescriptor} object.
65
	 */
66
	public FeatureTreePreferences(String title, ImageDescriptor image) {
67
		super(title, image);
68
	}
69

  
70
	/*
71
	 * (non-Javadoc)
72
	 *
73
	 * @see
74
	 * org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
75
	 */
76
	/** {@inheritDoc} */
77
	@Override
78
	public void init(IWorkbench workbench) {
79
	}
80

  
81
	/*
82
	 * (non-Javadoc)
83
	 *
84
	 * @see
85
	 * org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse
86
	 * .swt.widgets.Composite)
87
	 */
88
	/** {@inheritDoc} */
89
	@Override
90
	protected Control createContents(Composite parent) {
91
		Composite composite = new Composite(parent, SWT.NULL);
92
		composite.setLayout(new GridLayout());
93

  
94
		final CommandHandlerButton button_openFeatureTree = new CommandHandlerButton(composite, SWT.PUSH, "eu.etaxonomy.taxeditor.store.open.FeatureTreeEditorWizard");
95
		button_openFeatureTree.setText("Open FeatureTree Editor");
96
		PreferencesUtil.recursiveSetEnabled(composite, CdmStore.isActive());
97
		return composite;
98
	}
99
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)