Project

General

Profile

« Previous | Next » 

Revision a1a081b7

Added by Pepe Ciardelli almost 16 years ago

Checkin before starting datasource.

View differences:

.gitattributes
484 484
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/name/messages.properties -text
485 485
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/model/CdmUtil.java -text
486 486
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/model/NameEditorInput.java -text
487
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/model/NameTreeContentProvider.java -text
488 487
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/model/PropertySheetNode.java -text
489
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/model/TaxTreeContentProvider.java -text
490 488
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/model/TaxonomicTreeContentProvider.java -text
491 489
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/FavoritesTableViewer.java -text
492 490
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/FavoritesView.java -text
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/FreetextPropertiesPerspective.java
42 42
//		layout.addView(IPageLayout.ID_PROBLEM_VIEW, IPageLayout.BOTTOM, 0.8f, editorArea);		
43 43
		
44 44
		IFolderLayout folderLayoutLeft = layout.createFolder("leftfolder", IPageLayout.LEFT, 0.3f, editorArea);
45
		
45 46
		folderLayoutLeft.addView(TaxonomicTreeView.ID);
46 47
		folderLayoutLeft.addView(SearchView.ID);
47 48
		
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/ITaxEditorConstants.java
55 55
	public static final String CODE_PREFERENCE_ICZN = "iczn";
56 56
	public static final String DEFAULT_CODE_PREFERENCE = CODE_PREFERENCE_ICBN;
57 57
	public static final String INITIALIZED = "initialized";
58
	public static final String INITIALIZE_W_TESTDATA = "init_w_testdata";
58 59

  
59 60
	/* ***************************************************************************************
60 61
			STRINGS
......
91 92
	 ************************************************************************************** */
92 93
	public static final String FEATURE_PREFERENCE = "feature_preference";
93 94
	public static final String RANK_PREFERENCE = "rank_preference";
95
;
94 96
	
95 97
}
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/TaxEditorPlugin.java
117 117
		plugin = this;
118 118
		
119 119
		boolean initDatastore = false;
120

  
120
		
121 121
		// If the preferences INITIALIZED has not been set, the IF clause
122 122
		// will return false, i.e. datastore will be initialized first
123 123
		// time the application is run after being installed.
124
		boolean initialized = getPreferenceStore()
125
				.getBoolean(ITaxEditorConstants.INITIALIZED);
126
		
127
//		initialized = false; // to re-init db, uncomment this line
124
		boolean initialized = false;
125
		if (getPreferenceStore()
126
				.contains(ITaxEditorConstants.INITIALIZED)) {
127
			initialized = getPreferenceStore().getBoolean(
128
					ITaxEditorConstants.INITIALIZED);
129
		}
130
				
128 131
		if (!initialized) {
132
			
129 133
			logger.warn("Initializing datastore");
130
			initDatastore = true;
134
			
135
			dbSchemaValidation = DbSchemaValidation.CREATE;
136
			
137
			if (getPreferenceStore().getBoolean(
138
					ITaxEditorConstants.INITIALIZE_W_TESTDATA)) {
139
				initDatastore();
140
				getPreferenceStore().setValue(
141
						ITaxEditorConstants.INITIALIZE_W_TESTDATA, false);				
142
			}
131 143

  
132 144
			getPreferenceStore()
133 145
					.setValue(ITaxEditorConstants.INITIALIZED, true);
134
		} else {
135
			logger.warn("Datastore already initialized");
136 146
		}
137 147

  
138
		if (initDatastore) {
139
			dbSchemaValidation = DbSchemaValidation.CREATE;
140
			initDatastore();
141
		}
142

  
143
		cdmApp = getCdmApp();
144

  
145
//		if (initDatastore) {
146
//			initDatastore();
147
//		}
148
		
148
		cdmApp = getCdmApp();		
149 149
	}
150 150

  
151 151
	/*
......
154 154
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
155 155
	 */
156 156
	public void stop(BundleContext context) throws Exception {
157
		stopTransaction();
157
		commitTransaction();
158 158
		plugin = null;
159 159
		super.stop(context);
160 160
		
......
245 245
			try {
246 246
				 ICdmDataSource ds =
247 247
					 CdmDataSource.NewH2EmbeddedInstance("cdm", "sa", "");
248
//					 CdmDataSource.NewMySqlInstance("192.168.2.10", "cdm_test_andreasM2", "edit", "wp5");
248
//					 CdmDataSource.NewMySqlInstance("192.168.2.10", "cdm_editor_test1", "edit", "wp5");
249 249
				 
250
				 // Is this the problem?
251 250
				 cdmApp = CdmApplicationController
252 251
				 		.NewInstance(ds, dbSchemaValidation);
253
 
254
				 
252
 				 
255 253
//				cdmApp = CdmApplicationController
256 254
//						.NewInstance(dbSchemaValidation);
257 255

  
258 256
				startTransaction();
259
				 Object txStatus = cdmApp.startTransaction();
257
//				Object txStatus = cdmApp.startTransaction();
258
				
260 259
				// cdmApp.commitTransaction((TransactionStatus) txStatus);
261 260

  
262 261
			} catch (DataSourceNotFoundException e) {
......
276 275
		}
277 276
	}
278 277

  
279
	public void stopTransaction() {
278
	public void commitTransaction() {
280 279
		if (txStatus != null) {
281 280
			cdmApp.commitTransaction(txStatus);
282 281
			txStatus = null;
......
447 446
			 colorMap = new HashMap<String, Color>();
448 447
			 
449 448
			 colorMap.put(ITaxEditorConstants.GROUP_GRAY_BKG_COLOR,
450
					 new Color(null, 246, 246, 246));
449
					 new Color(null, 240, 240, 240));
451 450
		}
452 451
		return colorMap;
453 452
	}
......
488 487

  
489 488
	public Set<Taxon> getSessionRootTaxa() {
490 489
		if (sessionRootTaxa == null) {
490
			
491 491
			sessionRootTaxa = new HashSet<Taxon>();
492 492
			sessionRootTaxa.addAll(getCdmApp().getTaxonService().getRootTaxa(
493 493
					getSec(), null, false));
494 494
//			sessionRootTaxa.addAll(getCdmApp().getTaxonService().getRootTaxa(
495 495
//					getSec(), null, true));			
496 496
			addSessionTaxa(sessionRootTaxa);
497
						
497 498
		}
498 499
		return sessionRootTaxa;
499 500
	}
......
520 521
			
521 522
				// BUG deleted taxon were re-appearing as NULL children
522 523
				Set<Taxon> childTaxa = new HashSet<Taxon>();
524
				
525
//				TransactionStatus tx = getCdmApp().startTransaction();
526
//				getCdmApp().getTaxonService().saveTaxon(parentTaxon);
523 527
				for (Taxon taxon : parentTaxon.getTaxonomicChildren()) {
524 528
					if (taxon != null) {
525 529
						childTaxa.add(taxon);
526 530
					}
527 531
				}
532
//				getCdmApp().commitTransaction(tx);
533
				
528 534
				getTaxonomicChildrenMap().put(parentTaxon, childTaxa);
529 535
			}
530 536
		}
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/cdm/DeleteTaxonAction.java
27 27
import eu.etaxonomy.taxeditor.ITaxEditorConstants;
28 28
import eu.etaxonomy.taxeditor.TaxEditorPlugin;
29 29
import eu.etaxonomy.taxeditor.UiUtil;
30
import eu.etaxonomy.taxeditor.model.CdmUtil;
31 30

  
32 31
/**
33 32
 * Delete this taxon from the CDM
......
80 79
				TaxonRelationshipType type = taxonRelation.getType();
81 80
				Taxon fromTaxon = taxonRelation.getFromTaxon();
82 81

  
83
				// BUG beware of phantom taxon relations with a "NULL" fromTaxon
82
				// Beware of phantom taxon relations with a "NULL" fromTaxon
84 83
				if (fromTaxon == null) {
85 84
					continue;
86 85
				}
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/ChangeTaxonToSynonymAction.java
16 16
import org.eclipse.ui.IEditorPart;
17 17
import org.eclipse.ui.PartInitException;
18 18

  
19
import eu.etaxonomy.cdm.model.description.TaxonDescription;
19 20
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
21
import eu.etaxonomy.cdm.model.taxon.Synonym;
20 22
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
21 23
import eu.etaxonomy.cdm.model.taxon.Taxon;
24
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
25
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
22 26
import eu.etaxonomy.taxeditor.ITaxEditorConstants;
23 27
import eu.etaxonomy.taxeditor.TaxEditorPlugin;
24 28
import eu.etaxonomy.taxeditor.UiUtil;
25 29
import eu.etaxonomy.taxeditor.actions.cdm.SaveTaxonAction;
26 30
import eu.etaxonomy.taxeditor.editor.SelectTaxonDialog;
31
import eu.etaxonomy.taxeditor.editor.name.IterableSynonymyList;
27 32
import eu.etaxonomy.taxeditor.model.CdmUtil;
28 33

  
29 34
/**
......
92 97
				null, null);
93 98
		
94 99
		// TODO move any children, descriptions, synonyms
95
		// TODO delete taxon from CDM, tree, recent names list		
100
		for (TaxonDescription description: oldTaxon.getDescriptions()) {
101
			destinationTaxon.addDescription(description);
102
			oldTaxon.removeDescription(description);
103
		}
104
		
105
		for (TaxonRelationship fromRelation : oldTaxon.getRelationsFromThisTaxon()) {
106
			fromRelation.setFromTaxon(destinationTaxon);
107
		}
108
		
109
		for (TaxonRelationship toRelation : oldTaxon.getRelationsToThisTaxon()) {
110
			toRelation.setToTaxon(destinationTaxon);
111
		}
112
				
113
//		if (!TaxEditorPlugin.getDefault().getObservableRecentNamesList().
114
//				contains(oldTaxon)) {	
115
			TaxEditorPlugin.getDefault().getObservableRecentNamesList().
116
					remove(oldTaxon);
117
//		}
118
			
119
		TaxEditorPlugin.getDefault().removeSessionTaxon(oldTaxon);	
96 120
		
97 121
		// Close open editor for oldTaxon without forcing save.
98 122
		// User has already saved or declined to do so above.
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/actions/ui/OpenTaxonEditorAction.java
36 36
			.getLogger(OpenTaxonEditorAction.class);
37 37

  
38 38
	private static String editTaxonText = "Edit taxon";
39
	private static String newTaxonText = "Open new taxon";
39
	private static String newTaxonText = "Add new taxon";
40 40
//	private ImageDescriptor image = TaxEditorPlugin.getDefault()
41 41
//			.getImageDescriptor(ITaxEditorConstants.OPEN_TAXON_ICON);
42 42
	private ImageDescriptor image = null;
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/EditorGroupedComposite.java
103 103
		
104 104
		draggableLabel = new Label(this, SWT.NONE);
105 105
		draggableLabel.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
106
		draggableLabel.setLayoutData(new TableWrapData(TableWrapData.CENTER, TableWrapData.MIDDLE));
106
		draggableLabel.setLayoutData(new TableWrapData(TableWrapData.CENTER, TableWrapData.TOP));
107 107
		
108 108
		setDraggableControl(draggableLabel);
109 109
	}
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/MultiPageTaxonEditor.java
18 18
import org.eclipse.ui.IEditorSite;
19 19
import org.eclipse.ui.PartInitException;
20 20
import org.eclipse.ui.part.MultiPageEditorPart;
21
import org.springframework.transaction.TransactionStatus;
21 22

  
22 23
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
23 24
import eu.etaxonomy.cdm.model.taxon.Taxon;
24 25
import eu.etaxonomy.taxeditor.actions.cdm.SaveTaxonAction;
25 26
import eu.etaxonomy.taxeditor.editor.description.TaxonDescriptionEditorView;
26 27
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditorView;
28
import eu.etaxonomy.taxeditor.model.CdmUtil;
27 29

  
28 30
/**
29 31
 * 
......
41 43
	
42 44
	private Taxon taxon;
43 45
	private boolean dirty;
46

  
47
	private TransactionStatus tx;
44 48
		
49
	public MultiPageTaxonEditor() {
50
		super();
51
//		tx = CdmUtil.startTransaction();
52
	}
53
	
54
	@Override
55
	public void dispose() {
56
		super.dispose();
57
//		CdmUtil.commitTransaction(tx);
58
	}
59
	
45 60
	@Override
46 61
	protected void createPages() {
47 62
				
......
51 66
			
52 67
			// TODO lazy create
53 68
			addPage(1, new TaxonDescriptionEditorView(), getEditorInput());
54
//			addPage(1, new EmptyEditorView(), getEditorInput());
55 69
			setPageText(1, "Descriptive");
56 70
			
57 71
			addPage(2, new EmptyEditorView(), getEditorInput());
......
73 87
	@Override
74 88
	public void doSave(IProgressMonitor monitor) {
75 89
//		monitor.beginTask(name, totalWork)
76
		logger.warn("Calling doSave");
77 90
		new SaveTaxonAction(taxon).run();
91
//		CdmUtil.commitTransaction(tx);
78 92
		setDirty(false);
93
		tx = CdmUtil.startTransaction();
94
		CdmUtil.getTaxonService().saveTaxon(taxon);
79 95
	}
80 96

  
81 97
	private void setDirty(boolean dirty) {
......
127 143
			taxon = null;
128 144
		}
129 145

  
146
		// Save taxon to put it into this transaction
147
//		CdmUtil.getTaxonService().saveTaxon(taxon);
148
		
130 149
		// Listen for name changes, 
131 150
		//  change tab for this taxon editor accordingly
132 151
		taxon.addPropertyChangeListener("name", new PropertyChangeListener() {
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/editor/name/NameComposite.java
299 299
				NonViralName nonViralName = (NonViralName) taxonBase.getName();
300 300
				if (nonViralName != null) {
301 301
//					CdmUtil.parseFullName(nonViralName, text, null, true);
302
					CdmUtil.parseFullReference(nonViralName, text, null, true);
302
					
303
					// Changed makeEmpty from true -> false
304
//					CdmUtil.parseFullReference(nonViralName, text, null, true);
305
					CdmUtil.parseFullReference(nonViralName, text, null, false);
303 306
					
304 307
					nameViewer.setShowError(nonViralName.getHasProblem());
305 308
				}
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/model/CdmUtil.java
14 14
import java.util.SortedSet;
15 15

  
16 16
import org.apache.log4j.Logger;
17
import org.springframework.transaction.TransactionStatus;
17 18

  
18 19
import eu.etaxonomy.cdm.api.service.IDescriptionService;
19 20
import eu.etaxonomy.cdm.api.service.INameService;
......
338 339
	
339 340
	public static SortedSet<Rank> getRanks() {
340 341
		if (ranks == null) {
342
//			TransactionStatus tx = startReadOnlyTransaction();
341 343
			OrderedTermVocabulary<Rank> rankVocabulary = TaxEditorPlugin.getDefault().getRankVocabulary();
342 344
			ranks = rankVocabulary.getOrderedTerms(null);
345
//			commitTransaction(tx);
343 346
		}
344 347
		return ranks;
345 348
	}
......
356 359
		return resultsSet;
357 360
	}
358 361
	
359

  
362
	public static TransactionStatus startTransaction() {
363
		return TaxEditorPlugin.getDefault().getCdmApp().startTransaction();
364
	}
365
	
366
	public static TransactionStatus startReadOnlyTransaction() {
367
		return TaxEditorPlugin.getDefault().getCdmApp().startTransaction(true);
368
	}
369
	
370
	public static void commitTransaction(TransactionStatus tx) {
371
		TaxEditorPlugin.getDefault().getCdmApp().commitTransaction(tx);
372
	}
360 373
}
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/model/NameTreeContentProvider.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.model;
11

  
12
import java.util.Set;
13

  
14
import org.apache.log4j.Logger;
15
import org.eclipse.core.databinding.observable.Realm;
16
import org.eclipse.core.databinding.observable.list.IListChangeListener;
17
import org.eclipse.core.databinding.observable.list.IObservableList;
18
import org.eclipse.core.databinding.observable.list.ListChangeEvent;
19
import org.eclipse.core.databinding.observable.list.ListDiffEntry;
20
import org.eclipse.core.databinding.observable.list.WritableList;
21
import org.eclipse.core.databinding.observable.set.IObservableSet;
22
import org.eclipse.core.databinding.observable.set.WritableSet;
23
import org.eclipse.core.runtime.Assert;
24
import org.eclipse.jface.databinding.swt.SWTObservables;
25
import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
26
import org.eclipse.jface.viewers.ITreeContentProvider;
27
import org.eclipse.jface.viewers.TreeViewer;
28
import org.eclipse.jface.viewers.Viewer;
29
import org.eclipse.swt.widgets.Display;
30
import org.eclipse.ui.model.WorkbenchContentProvider;
31

  
32
import eu.etaxonomy.cdm.model.taxon.Taxon;
33
import eu.etaxonomy.taxeditor.TaxEditorPlugin;
34

  
35
/**
36
 * Adds tree functionality (get parent, get children) to ObservableListContentProvider;
37
 *  much code was copied almost in tact from parent class due to
38
 *  viewer type restrictions and private settings of variables and methods
39
 * 
40
 * @author p.ciardelli
41
 * @created 14.05.2008
42
 * @version 1.0
43
 */
44
public class NameTreeContentProvider extends ObservableListContentProvider 
45
//		implements ILazyTreeContentProvider {
46
		implements ITreeContentProvider {
47
	private static final Logger logger = Logger.getLogger(NameTreeContentProvider.class);
48

  
49
	public Object[] getChildren(Object parentElement) {
50
		Taxon parentTaxon = (Taxon) parentElement;
51
//		Set<Taxon> children = TaxEditorPlugin.getDefault().getTaxonomicChildren(parentTaxon);
52
		
53
		Set<Taxon> children = parentTaxon.getTaxonomicChildren();
54
//		for (Taxon childTaxon : children) {
55
//			observableList.add(childTaxon);
56
//		}
57
		// TODO: suppress notify
58
		observableList.addAll(children);
59
		return children == null ? new Object[0] : children.toArray();
60
	}
61

  
62
	@Override
63
	public Object getParent(Object element) {
64
		return ((Taxon) element).getTaxonomicParent();
65
	}
66

  
67
	public boolean hasChildren(Object element) {
68
		return ((Taxon) element).hasTaxonomicChildren();
69
	}
70
	
71
	private IObservableList observableList;
72

  
73
	private Viewer viewer;
74

  
75
	private IListChangeListener listener = new IListChangeListener() {
76
		public void handleListChange(ListChangeEvent event) {
77
			if (viewer.getControl().isDisposed()) {
78
				return;
79
			}
80
			ListDiffEntry[] differences = event.diff.getDifferences();
81
			for (int i = 0; i < differences.length; i++) {
82
				ListDiffEntry entry = differences[i];
83
				
84
				if (entry.isAddition()) {
85
					
86
					knownElements.add(entry.getElement());
87
						
88
					Taxon newTaxon = (Taxon) entry.getElement();
89
					Taxon parent = newTaxon.getTaxonomicParent();
90
					((TreeViewer) viewer).add(parent, newTaxon);
91
					
92
				} else {
93

  
94
					knownElements.remove(entry.getElement());
95
					
96
					((TreeViewer) viewer).remove(entry.getElement());
97
				}
98
			}
99
		}
100
	};
101

  
102
	private IObservableSet knownElements;
103

  
104
	/**
105
	 * 
106
	 */
107
	public NameTreeContentProvider() {
108
		
109
		Assert.isNotNull(Realm.getDefault());
110
		
111
		observableList = new WritableList(SWTObservables.getRealm(Display.getDefault()));
112
		knownElements = new WritableSet(SWTObservables.getRealm(Display.getDefault()));
113
	}
114

  
115
	public Object[] getElements(Object inputElement) {
116
		return observableList.toArray();
117
	}
118

  
119
	public void dispose() {
120
		observableList.removeListChangeListener(listener);
121
	}
122

  
123
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
124
		this.viewer = viewer;
125

  
126
		if (newInput != null && !(newInput instanceof IObservableList)) {
127
			throw new IllegalArgumentException(
128
					"This content provider only works with input of type IObservableList"); //$NON-NLS-1$
129
		}
130

  
131
		setInput((IObservableList) newInput);
132
	}
133

  
134
	/**
135
	 * @param list
136
	 */
137
	private void setInput(IObservableList list) {
138
		
139
//		list = null;
140
		
141
		if (list == null) {
142
			list = new WritableList(SWTObservables.getRealm(Display.getDefault()));
143
//			list.addAll(TaxEditorPlugin.getDefault().getCdmApp().getTaxonService().getRootTaxa(null));
144
		}
145

  
146
		if (observableList != null) {
147
			observableList.removeListChangeListener(listener);
148
		}
149
		observableList = list; // this sets observablelist to TaxEditorPlugin.getDefault().getObservableTaxonTreeList()
150
		/*
151
		 * So then the question is: what's the first call that gets made to the content provider?
152
		 */
153
		observableList.addListChangeListener(listener);
154
		
155
		knownElements.clear();		
156
//		knownElements.addAll(list);
157
		knownElements.addAll(TaxEditorPlugin.getDefault().getCdmApp().getTaxonService().getRootTaxa(null));
158

  
159
	}
160

  
161
	/**
162
	 * @return the set of elements known to this content provider. Label providers may track
163
	 * this set if they need to be notified about additions before the viewer sees the added
164
	 * element, and notified about removals after the element was removed from the viewer.
165
	 */
166
	public IObservableSet getKnownElements() {
167
		return knownElements;
168
	}
169
}
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/model/TaxTreeContentProvider.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.model;
11

  
12
import java.util.ArrayList;
13
import java.util.Collection;
14
import java.util.List;
15
import java.util.Set;
16

  
17
import org.apache.log4j.Logger;
18
import org.eclipse.jface.viewers.ITreeContentProvider;
19
import org.eclipse.jface.viewers.Viewer;
20

  
21
import eu.etaxonomy.cdm.model.taxon.Taxon;
22
import eu.etaxonomy.taxeditor.TaxEditorPlugin;
23

  
24
/**
25
 * @author p.ciardelli
26
 * @created 27.06.2008
27
 * @version 1.0
28
 */
29
public class TaxTreeContentProvider implements ITreeContentProvider {
30
	private static final Logger logger = Logger
31
			.getLogger(TaxTreeContentProvider.class);
32

  
33
	/*
34
	 * (non-Javadoc)
35
	 * 
36
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
37
	 */
38
	@Override
39
	public Object[] getChildren(Object parentElement) {
40
		
41
		if (parentElement instanceof Taxon) {
42
			return getTaxonChildren((Taxon) parentElement).toArray();
43
		}
44
		
45
		if (!(parentElement instanceof Collection)) {
46
			throw new IllegalArgumentException(
47
					"getChildren() expects either a Collection or a Taxon object."); //$NON-NLS-1$	
48
		}
49
		
50
		List<Taxon> children = new ArrayList<Taxon>();
51
		for (Object parent : (Collection) parentElement) {
52
			if (!(parent instanceof Taxon)) {
53
				throw new IllegalArgumentException(
54
						"parentElement Collection can only contain Taxon objects."); //$NON-NLS-1$				
55
			}
56
			
57
			children.addAll(getTaxonChildren((Taxon) parent));
58
		}
59
		return children.toArray();
60
	}
61

  
62
	public Set<Taxon> getTaxonChildren(Taxon parentTaxon) {
63

  
64
		return TaxEditorPlugin.getDefault().getSessionTaxonomicChildren(
65
				parentTaxon);
66
	}
67

  
68
	/*
69
	 * (non-Javadoc)
70
	 * 
71
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
72
	 */
73
	@Override
74
	public Object getParent(Object element) {
75
		if (!(element instanceof Taxon)) {
76
			throw new IllegalArgumentException(
77
					"getParent() expects a Taxon object."); //$NON-NLS-1$				
78
		}
79
		return ((Taxon) element).getTaxonomicParent();
80
	}
81

  
82
	/*
83
	 * (non-Javadoc)
84
	 * 
85
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
86
	 */
87
	@Override
88
	public boolean hasChildren(Object element) {
89
		if (!(element instanceof Taxon)) {
90
			throw new IllegalArgumentException(
91
					"getParent() expects a Taxon object."); //$NON-NLS-1$				
92
		}
93
		
94
		// This seems a bit buggy
95
//		return ((Taxon) element).hasTaxonomicChildren();
96
		
97
		// Replace with this for now:
98
		return getChildren(element).length > 0;
99
	}
100

  
101
	/*
102
	 * (non-Javadoc)
103
	 * 
104
	 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
105
	 */
106
	@Override
107
	public Object[] getElements(Object inputElement) {
108
		
109
		// BIG QUESTION: should getElements return only root taxa, or all taxa?
110
		// CONFLICTING INFO ONLINE!!!
111
//		return TaxEditorPlugin.getDefault().getObservableSessionTaxa().toArray();
112
		return TaxEditorPlugin.getDefault().getSessionRootTaxa().toArray();
113
	}
114

  
115
	/*
116
	 * (non-Javadoc)
117
	 * 
118
	 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
119
	 */
120
	@Override
121
	public void dispose() {}
122

  
123
	/*
124
	 * (non-Javadoc)
125
	 * 
126
	 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
127
	 *      java.lang.Object, java.lang.Object)
128
	 */
129
	@Override
130
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
131
		// TODO Auto-generated method stub
132
	}
133
}
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/model/TaxonomicTreeContentProvider.java
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
 */
9

  
10 9
package eu.etaxonomy.taxeditor.model;
11 10

  
12 11
import java.util.ArrayList;
......
15 14
import java.util.Set;
16 15

  
17 16
import org.apache.log4j.Logger;
18
import org.eclipse.core.databinding.observable.set.IObservableSet;
19
import org.eclipse.core.databinding.observable.set.ISetChangeListener;
20
import org.eclipse.core.databinding.observable.set.SetChangeEvent;
21 17
import org.eclipse.jface.viewers.ITreeContentProvider;
22
import org.eclipse.jface.viewers.TreeViewer;
23 18
import org.eclipse.jface.viewers.Viewer;
24 19

  
25 20
import eu.etaxonomy.cdm.model.taxon.Taxon;
26 21
import eu.etaxonomy.taxeditor.TaxEditorPlugin;
27 22

  
28 23
/**
29
 * An implementation of ITreeContentProvider which adds taxa displayed in the tree
30
 *  to the Editor session on an as-loaded basis. Listens for any changes to the 
31
 *  set of session taxa, updates the TreeViewer accordingly.
32
 * <p> 
33
 * Could be re-written to implement ILazyTreeContentProvider at some point in the future. 
34
 *  NO: sorting not possible with lazy tree.
35
 * 
36 24
 * @author p.ciardelli
37
 * @created 28.05.2008
25
 * @created 27.06.2008
38 26
 * @version 1.0
39 27
 */
40 28
public class TaxonomicTreeContentProvider implements ITreeContentProvider {
41 29
	private static final Logger logger = Logger
42 30
			.getLogger(TaxonomicTreeContentProvider.class);
43 31

  
44
	TreeViewer viewer;
45
	
46
	/* (non-Javadoc)
32
	/*
33
	 * (non-Javadoc)
34
	 * 
47 35
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
48 36
	 */
49 37
	@Override
50 38
	public Object[] getChildren(Object parentElement) {
51
		if (!(parentElement instanceof Taxon)) {
52
			logger.error("Method getChildren() expects a parentElement of type Taxon");
53
			return new Object[0];
39
		
40
		if (parentElement instanceof Taxon) {
41
			return getTaxonChildren((Taxon) parentElement).toArray();
54 42
		}
55

  
56
		Taxon parentTaxon = (Taxon) parentElement;
57

  
58
		// If this does not return null, the taxon's children have already
59
		//	been requested during this session
60
		Set<Taxon> childTaxa = TaxEditorPlugin.getDefault()
61
				.getSessionTaxonomicChildren(parentTaxon);
62
		if (childTaxa == null) {
63
			
64
			removeSessionTaxaListener();
65
			
66
			// Request this taxon's children for the first time 
67
			//	during this session
68
			childTaxa = parentTaxon.getTaxonomicChildren();
69
			TaxEditorPlugin.getDefault().addSessionTaxa(childTaxa);
43
		
44
		if (!(parentElement instanceof Collection)) {
45
			throw new IllegalArgumentException(
46
					"getChildren() expects either a Collection or a Taxon object."); //$NON-NLS-1$	
47
		}
48
		
49
		List<Taxon> children = new ArrayList<Taxon>();
50
		for (Object parent : (Collection) parentElement) {
51
			if (!(parent instanceof Taxon)) {
52
				throw new IllegalArgumentException(
53
						"parentElement Collection can only contain Taxon objects."); //$NON-NLS-1$				
54
			}
70 55
			
71
			addSessionTaxaListener();
56
			children.addAll(getTaxonChildren((Taxon) parent));
72 57
		}
58
		return children.toArray();
59
	}
60

  
61
	public Set<Taxon> getTaxonChildren(Taxon parentTaxon) {
73 62

  
74
		logger.warn("returning " + childTaxa.toString());
75
		return childTaxa.toArray();
63
		return TaxEditorPlugin.getDefault().getSessionTaxonomicChildren(
64
				parentTaxon);
76 65
	}
77 66

  
67
	/*
68
	 * (non-Javadoc)
69
	 * 
70
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
71
	 */
78 72
	@Override
79 73
	public Object getParent(Object element) {
80 74
		if (!(element instanceof Taxon)) {
81
			return null;			
75
			throw new IllegalArgumentException(
76
					"getParent() expects a Taxon object."); //$NON-NLS-1$				
82 77
		}
83 78
		return ((Taxon) element).getTaxonomicParent();
84 79
	}
85 80

  
81
	/*
82
	 * (non-Javadoc)
83
	 * 
84
	 * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
85
	 */
86 86
	@Override
87 87
	public boolean hasChildren(Object element) {
88 88
		if (!(element instanceof Taxon)) {
89
			return false;			
89
			throw new IllegalArgumentException(
90
					"getParent() expects a Taxon object."); //$NON-NLS-1$				
90 91
		}
91
		return ((Taxon) element).hasTaxonomicChildren();
92
		
93
		return getChildren(element).length > 0;
92 94
	}
93 95

  
96
	/*
97
	 * (non-Javadoc)
98
	 * 
99
	 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
100
	 */
94 101
	@Override
95 102
	public Object[] getElements(Object inputElement) {
96
//		logger.warn("Get elements for " + inputElement.toString() + " with class " + inputElement.getClass());
97
//		List elements = new ArrayList();
98
//		if (inputElement instanceof Collection) {
99
//			logger.warn("instanceof collection");
100
////			elements.addAll((Collection) inputElement);
101
//			for (Object parentElement : (Collection) inputElement) {
102
//				if (parentElement instanceof Taxon) {
103
//					for (Object childElement : getChildren(parentElement)) {
104
//						elements.add(childElement);
105
//					}
106
//				}
107
//			}
108
//		}
109
////		return TaxEditorPlugin.getDefault().getSessionRootTaxa().toArray();
110
////		return getChildren(inputElement);
111
//		logger.warn("elements have " + elements.size());
112
//		return elements.toArray();
113
		return null;
103
		
104
		// BIG QUESTION: should getElements return only root taxa, or all taxa?
105
		// CONFLICTING INFO ONLINE!!!
106
//		return TaxEditorPlugin.getDefault().getObservableSessionTaxa().toArray();
107
		
108
		return TaxEditorPlugin.getDefault().getSessionRootTaxa().toArray();
114 109
	}
115 110

  
111
	/*
112
	 * (non-Javadoc)
113
	 * 
114
	 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
115
	 */
116 116
	@Override
117
	public void dispose() {
118
		removeSessionTaxaListener();
119
	}
117
	public void dispose() {}
120 118

  
119
	/*
120
	 * (non-Javadoc)
121
	 * 
122
	 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
123
	 *      java.lang.Object, java.lang.Object)
124
	 */
121 125
	@Override
122 126
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
123
		if (!(viewer instanceof TreeViewer)) {
124
			throw new IllegalArgumentException(
125
					"This content provider only works with viewer of type TreeViewer"); //$NON-NLS-1$			
126
		}
127
		this.viewer = (TreeViewer) viewer;
128
		
129
		if (newInput != null && !(newInput instanceof Collection)) {
130
			throw new IllegalArgumentException(
131
					"This content provider only works with input of type Collection<Taxon>"); //$NON-NLS-1$
132
		}
133
		
134
		try {
135
			Collection<Taxon> input = (Collection<Taxon>) newInput;
136
			setInput(input);
137
		} catch (ClassCastException e) {
138
			throw new IllegalArgumentException(
139
				"This content provider only works with input of type Collection<Taxon>"); //$NON-NLS-1$
140
		}
127
		// TODO Auto-generated method stub
141 128
	}
142
	
143
	private void setInput(Collection<Taxon> input) {
144
		
145
		removeSessionTaxaListener();
146
		
147
		if (input != null) {
148
			TaxEditorPlugin.getDefault().addSessionTaxa(input);
149
		}
150

  
151
		addSessionTaxaListener();
152
	}
153

  
154
	private IObservableSet getObservableSessionTaxonSet() {
155
		return TaxEditorPlugin.getDefault().getObservableSessionTaxa();
156
	}
157
	
158
	private void addSessionTaxaListener() {
159
		getObservableSessionTaxonSet().addSetChangeListener(listener);
160
	}
161
	
162
	private void removeSessionTaxaListener() {
163
		getObservableSessionTaxonSet().removeSetChangeListener(listener);
164
	}
165
	
166
	private ISetChangeListener listener = new ISetChangeListener() {
167
		@Override
168
		public void handleSetChange(SetChangeEvent event) {
169
			if (viewer.getControl().isDisposed()) {
170
				return;
171
			}
172
			for (Object addition : event.diff.getAdditions()) {
173
				if (addition instanceof Taxon) {
174
					Taxon taxon = (Taxon) addition;
175
					Taxon parentTaxon = taxon.getTaxonomicParent();
176
					if (parentTaxon == null) {
177
						
178
						// If a new root item has been added, 
179
						//  set it as the viewer's input
180
						List<Taxon> newInput = new ArrayList<Taxon>();
181
						newInput.add(taxon);
182
						viewer.setInput(newInput);
183
//						viewer.setInput(TaxEditorPlugin.getDefault().getSessionRootTaxa());
184
					} else {
185
						viewer.add(parentTaxon, taxon);
186
					}
187
				}
188
			}
189
			for (Object removal : event.diff.getRemovals()) {
190
				if (removal instanceof Taxon) {
191
					Taxon taxon = (Taxon) removal; 
192
					viewer.remove(taxon);
193
				}
194
			}
195
//			viewer.getControl().setRedraw(true);
196
			viewer.refresh();
197
		}
198
	};
199
}
129
}
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/FavoritesView.java
57 57
		favoritesLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
58 58
		favoritesLabel.setText("Drag favorite elements into this area for easy access later.");
59 59
		
60
		// TEMPORARY PENDING IMPLEMENTATION - Disable visible fields
61
		favoritesComposite.setEnabled(false);
62
		favoritesLabel.setEnabled(false);
63
		
60 64
		new FavoritesTableViewer(favoritesComposite);	
61 65

  
62 66
		createActions();
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/SearchView.java
81 81
		final Button searchButton = new Button(searchComposite, SWT.NONE);
82 82
		searchButton.setText("Search");
83 83

  
84
		// TEMPORARY PENDING IMPLEMENTATION - Disable visible fields
85
		searchComposite.setEnabled(false);
86
		searchButton.setEnabled(false);
87
		
84 88
		createActions();
85 89
		initializeToolBar();
86 90
		initializeMenu();
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/TaxonomicTreeView.java
59 59
	 */
60 60
	@Override
61 61
	public void createPartControl(Composite parent) {
62
		
62
				
63 63
		parent.setLayout(new FillLayout());
64 64
		GridLayout gridLayout = new GridLayout();
65 65
		gridLayout.horizontalSpacing = 0;
......
171 171
		}
172 172
		
173 173
		// Create tree
174
		
174 175
		treeViewer = new TaxonomicTreeViewer(taxTreeComposite);
175 176
		
176 177
		// TODO move these into this class
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/navigation/TaxonomicTreeViewer.java
38 38
import org.eclipse.swt.dnd.DropTargetAdapter;
39 39
import org.eclipse.swt.dnd.DropTargetEvent;
40 40
import org.eclipse.swt.dnd.Transfer;
41
import org.eclipse.swt.events.SelectionAdapter;
42
import org.eclipse.swt.events.SelectionEvent;
43 41
import org.eclipse.swt.graphics.Point;
44 42
import org.eclipse.swt.graphics.Rectangle;
45 43
import org.eclipse.swt.layout.FillLayout;
......
53 51
import org.eclipse.swt.widgets.Shell;
54 52
import org.eclipse.swt.widgets.Tree;
55 53
import org.eclipse.swt.widgets.TreeItem;
54
import org.springframework.transaction.TransactionStatus;
56 55

  
57
import eu.etaxonomy.cdm.model.name.BotanicalName;
58 56
import eu.etaxonomy.cdm.model.name.NonViralName;
59
import eu.etaxonomy.cdm.model.name.Rank;
60 57
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
61 58
import eu.etaxonomy.cdm.model.taxon.Taxon;
62 59
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
......
72 69
import eu.etaxonomy.taxeditor.editor.ContextMenu;
73 70
import eu.etaxonomy.taxeditor.editor.name.IterableSynonymyList;
74 71
import eu.etaxonomy.taxeditor.model.CdmUtil;
75
import eu.etaxonomy.taxeditor.model.TaxTreeContentProvider;
72
import eu.etaxonomy.taxeditor.model.TaxonomicTreeContentProvider;
76 73

  
77 74
/**
78 75
 * Taxon tree viewer which responds to events within individual taxa.
......
297 294
	 * Set up content providers and viewer input
298 295
	 */
299 296
	private void createContent() {
300
		// IContentProvider viewerContentProviderList = new
301
		// TaxonomicTreeContentProvider();
302

  
297
		
303 298
		// Yet another custom content provider ...
304
		IContentProvider viewerContentProviderList = new TaxTreeContentProvider();
299
		IContentProvider viewerContentProviderList = new TaxonomicTreeContentProvider();
305 300
		this.setContentProvider(viewerContentProviderList);
306 301

  
307 302
		// Label provider that listens for changes to name cache
308 303
		IObservableSet observableTaxonSet = TaxEditorPlugin.getDefault()
309 304
				.getObservableSessionTaxa();
310
		this
311
				.setLabelProvider(new TaxonomicTreeLabelProvider(
305
		this.setLabelProvider(new TaxonomicTreeLabelProvider(
312 306
						observableTaxonSet));
313 307

  
314 308
		// TaxonTreeList added to every time a node is opened with its
eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/preference/InitializeDbPreferences.java
14 14
import org.eclipse.swt.SWT;
15 15
import org.eclipse.swt.events.SelectionAdapter;
16 16
import org.eclipse.swt.events.SelectionEvent;
17
import org.eclipse.swt.layout.GridData;
17 18
import org.eclipse.swt.layout.GridLayout;
18 19
import org.eclipse.swt.widgets.Button;
19 20
import org.eclipse.swt.widgets.Composite;
......
22 23
import org.eclipse.ui.IWorkbenchPreferencePage;
23 24

  
24 25
import eu.etaxonomy.taxeditor.ITaxEditorConstants;
25
import eu.etaxonomy.taxeditor.TaxEditorPlugin;
26
import eu.etaxonomy.taxeditor.UiUtil;
26 27

  
27 28
/**
28 29
 * @author p.ciardelli
......
36 37

  
37 38
	public static final String PLUGIN_ID = "eu.etaxonomy.taxeditor.preferences.initdb";
38 39

  
39
	private boolean doReinitialize;
40
	private Button btnInit;
41
	private Button btnTestData;
40 42
	
41 43
	public InitializeDbPreferences() {
42 44
		super();
......
53 55
		Composite container = new Composite(parent, SWT.NULL);
54 56
		container.setLayout(new GridLayout());
55 57

  
56
		final Button btnInit = new Button(container, SWT.CHECK);
58
		btnInit = new Button(container, SWT.CHECK);
59
		btnInit.setText("Initialize datastore on next application start");
57 60
		btnInit.addSelectionListener(new SelectionAdapter() {
58
			public void widgetSelected(final SelectionEvent e) {
59
				setDoReinitialize(btnInit.getSelection());
61

  
62
			@Override
63
			public void widgetSelected(SelectionEvent e) {
64
				if (btnInit.getSelection() == true) {
65
					
66
					// Enable test data option
67
					btnTestData.setEnabled(true);
68
					
69
				} else {
70
				
71
					// Disable test data option, set selected to "false"
72
					btnTestData.setEnabled(false);
73
					btnTestData.setSelection(false);
74
				}
60 75
			}
76
			
61 77
		});
62
		btnInit.setText("Initialize datastore on next application start");
63
		
78

  
79
		btnTestData = new Button(container, SWT.CHECK);
80
		btnTestData.setEnabled(false);
81
		final GridData gridData = new GridData();
82
		gridData.horizontalIndent = 20;
83
		btnTestData.setLayoutData(gridData);
84
		btnTestData.setText("Initialize with Palmweb test data");
64 85
		
65 86
		return container;
66 87
	}
......
69 90
	 * Initialize the preference page
70 91
	 */
71 92
	public void init(IWorkbench workbench) {
72
		setPreferenceStore(TaxEditorPlugin.getDefault().getPreferenceStore());
93
		setPreferenceStore(UiUtil.getPrefStore());
73 94
	}
74 95
	
75
	public boolean performOk() {
76
		logger.warn("Setting init'ed to " + doReinitialize);
77
		TaxEditorPlugin.getDefault().getPreferenceStore().
78
				setValue(ITaxEditorConstants.INITIALIZED, !doReinitialize);
79
		return true;
96
	@Override
97
	protected void performDefaults() {
98
		btnInit.setSelection(false);
99
		btnTestData.setSelection(false);
100
		super.performDefaults();
80 101
	}
81 102
	
82
	private void setDoReinitialize(boolean doReinitialize) {
83
		this.doReinitialize = doReinitialize;
103
	@Override	
104
	public boolean performOk() {
105
		boolean doReinitialize = !(btnInit.getSelection());
106
		boolean doInitTestdata = btnTestData.getSelection();
107
		
108
		UiUtil.getPrefStore().setValue(ITaxEditorConstants.INITIALIZED, doReinitialize);
109
		UiUtil.getPrefStore().setValue(ITaxEditorConstants.INITIALIZE_W_TESTDATA, doInitTestdata);		
110
		return true;
84 111
	}
85 112
}

Also available in: Unified diff