Project

General

Profile

« Previous | Next » 

Revision b0ce5b17

Added by Patrick Plitzner over 10 years ago

merged trunk into branch

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/MultiPageTaxonEditor.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
 */
......
32 32
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
33 33
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
34 34
import eu.etaxonomy.taxeditor.editor.name.container.AbstractGroupedContainer;
35
import eu.etaxonomy.taxeditor.model.AbstractUtility;
35 36
import eu.etaxonomy.taxeditor.model.DataChangeBridge;
36 37
import eu.etaxonomy.taxeditor.model.IDataChangeBehavior;
37 38
import eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider;
......
39 40
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
40 41

  
41 42
/**
42
 * 
43
 *
43 44
 * Generates the tabbed editor with <code>TaxonNameEditor</code> on top and tabs
44 45
 * for "Descriptions", "Concepts", "Geography", etc.
45
 * 
46
 *
46 47
 * @author p.ciardelli
47 48
 * @author n.hoffmann
48 49
 * @created 15.05.2008
......
83 84

  
84 85
	/*
85 86
	 * (non-Javadoc)
86
	 * 
87
	 *
87 88
	 * @see org.eclipse.ui.forms.editor.FormEditor#addPages()
88 89
	 */
89 90
	/** {@inheritDoc} */
......
107 108
			// EditorUtil.showPropertySheet();
108 109

  
109 110
		} catch (PartInitException e) {
110
			EditorUtil.error(getClass(), e);
111
			AbstractUtility.error(getClass(), e);
111 112
		}
112 113
	}
113 114

  
......
121 122
			}
122 123
			monitor.worked(1);
123 124

  
124
			for (IEditorPart editorPage : getPages()) {
125
				if (editorPage instanceof TaxonNameEditor) {
126
					if (((TaxonNameEditor) editorPage).checkForEmptyNames()) {
127
						MessageDialog
128
								.openWarning(
129
										EditorUtil.getShell(),
130
										"No Name Specified",
131
										"An attempt was made to save a taxon or synonym with "
132
												+ "an empty name. Operation was cancelled.");
133
						return;
134
					}
135
				}
136

  
137
				editorPage.doSave(monitor);
138
				monitor.worked(1);
139
			}
125
            for (IEditorPart editorPage : getPages()) {
126
                if (editorPage instanceof TaxonNameEditor) {
127
                    if (((TaxonNameEditor) editorPage).checkForEmptyNames()) {
128
                        MessageDialog.openWarning(AbstractUtility.getShell(), "No Name Specified",
129
                                "An attempt was made to save a taxon or synonym with "
130
                                        + "an empty name. Operation was cancelled.");
131
                        return;
132
                    }
133
                }
134

  
135
                editorPage.doSave(monitor);
136
                monitor.worked(1);
137
            }
140 138

  
141 139
			// commit the conversation and start a new transaction immediately
142 140
			conversation.commit(true);
143 141
			monitor.worked(1);
144 142

  
145
			this.setDirty(false);
146
			monitor.worked(1);
147
		} catch (Exception e) {
148
			setFocus();
149
			EditorUtil
150
					.errorDialog(
151
							"An error occurred while saving",
152
							getClass(),
153
							"An error occurred while saving the editor. Please close and reopen the taxon again.",
154
							e);
155
			disableEditor(true);
156
		} finally {
157
			monitor.done();
158
		}
143
            this.setDirty(false);
144
            monitor.worked(1);
145
        } catch (Exception e) {
146
            setFocus();
147
            AbstractUtility.errorDialog("An error occurred while saving", getClass(),
148
                    "An error occurred while saving the editor. Please close and reopen the taxon again.", e);
149
            disableEditor(true);
150
        } finally {
151
            monitor.done();
152
        }
159 153
	}
160 154

  
161 155
	private void disableEditor(boolean isOnError) {
......
163 157
			if(isOnError){
164 158
				editorPage.setOnError();
165 159
			}else {
166
				editorPage.setDisabled();				
160
				editorPage.setDisabled();
167 161
			}
168 162
		}
169 163
		conversation.unregisterForDataStoreChanges(this);
......
178 172

  
179 173
	/*
180 174
	 * (non-Javadoc)
181
	 * 
175
	 *
182 176
	 * @see org.eclipse.ui.part.MultiPageEditorPart#isDirty()
183 177
	 */
184 178
	/**
185 179
	 * <p>
186 180
	 * isDirty
187 181
	 * </p>
188
	 * 
182
	 *
189 183
	 * @return a boolean.
190 184
	 */
191
	public boolean isDirty() {
185
	@Override
186
    public boolean isDirty() {
192 187
		return dirty;
193 188
	}
194 189

  
195 190
	/*
196 191
	 * (non-Javadoc)
197
	 * 
192
	 *
198 193
	 * @see org.eclipse.ui.forms.editor.FormEditor#editorDirtyStateChanged()
199 194
	 */
200 195
	/** {@inheritDoc} */
......
206 201

  
207 202
	/**
208 203
	 * {@inheritDoc}
209
	 * 
204
	 *
210 205
	 * Checks whether nested editors are calling
211 206
	 * <code>firePropertyChange(PROP_DIRTY)</code> to signal an edit has taken
212 207
	 * place before passing property change along to
......
214 209
	 */
215 210
	/*
216 211
	 * (non-Javadoc)
217
	 * 
212
	 *
218 213
	 * @see org.eclipse.ui.part.MultiPageEditorPart#handlePropertyChange(int)
219 214
	 */
220
	protected void handlePropertyChange(int propertyId) {
215
	@Override
216
    protected void handlePropertyChange(int propertyId) {
221 217
		if (propertyId == PROP_DIRTY) {
222 218
			setDirty(true);
223 219
		}
......
240 236
	public void init(IEditorSite site, IEditorInput input)
241 237
			throws PartInitException {
242 238

  
243
		if (!(input instanceof TaxonEditorInput))
244
			throw new PartInitException(
239
		if (!(input instanceof TaxonEditorInput)) {
240
            throw new PartInitException(
245 241
					"Invalid Input: Must be TaxonEditorInput");
242
        }
246 243

  
247 244
		this.input = (TaxonEditorInput) input;
248 245

  
......
289 286
		setPartName(partName);
290 287
	}
291 288

  
292
	/**
293
	 * {@inheritDoc}
294
	 * 
295
	 * Editor pages call this in their postOperation to notify the
296
	 * MultiPageTaxonEditor of unsaved changes
297
	 */
298
	public void changed(Object element) {
299
		// setDirty(true);
300
		dirty = true;
301
		super.editorDirtyStateChanged();
302
		if (element instanceof TaxonBase) {
303
			TaxonNameEditor page = (TaxonNameEditor) getPage(Page.NAME);
304
			AbstractGroupedContainer container = page
305
					.getContainer((TaxonBase) element);
306
			if (container != null) {
307
				container.refresh();
308
			}
309
		}
310
	}
289
    /**
290
     * {@inheritDoc}
291
     *
292
     * Editor pages call this in their postOperation to notify the
293
     * MultiPageTaxonEditor of unsaved changes
294
     */
295
    @Override
296
    public void changed(Object element) {
297
        // setDirty(true);
298
        dirty = true;
299
        super.editorDirtyStateChanged();
300
        if (element instanceof TaxonBase) {
301
            TaxonNameEditor page = (TaxonNameEditor) getPage(Page.NAME);
302
            AbstractGroupedContainer container = page.getContainer((TaxonBase) element);
303
            if (container != null) {
304
                container.refresh();
305
            }
306
        }
307
    }
311 308

  
312 309
	/**
313 310
	 * The accepted taxon that is the input for this editor
314
	 * 
311
	 *
315 312
	 * @return the accepted taxon
316 313
	 */
317 314
	public Taxon getTaxon() {
......
320 317

  
321 318
	/*
322 319
	 * (non-Javadoc)
323
	 * 
320
	 *
324 321
	 * @see
325 322
	 * eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder
326 323
	 * ()
......
329 326
	 * <p>
330 327
	 * getConversationHolder
331 328
	 * </p>
332
	 * 
329
	 *
333 330
	 * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
334 331
	 *         object.
335 332
	 */
336
	public ConversationHolder getConversationHolder() {
333
	@Override
334
    public ConversationHolder getConversationHolder() {
337 335
		return conversation;
338 336
	}
339 337

  
......
341 339
	 * <p>
342 340
	 * setConversationHolder
343 341
	 * </p>
344
	 * 
342
	 *
345 343
	 * @param conversation
346 344
	 *            a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
347 345
	 *            object.
......
354 352
	 * <p>
355 353
	 * Getter for the field <code>undoContext</code>.
356 354
	 * </p>
357
	 * 
355
	 *
358 356
	 * @return a {@link org.eclipse.core.commands.operations.IUndoContext}
359 357
	 *         object.
360 358
	 */
......
366 364
	 * <p>
367 365
	 * Setter for the field <code>undoContext</code>.
368 366
	 * </p>
369
	 * 
367
	 *
370 368
	 * @param undoContext
371 369
	 *            a {@link org.eclipse.core.commands.operations.IUndoContext}
372 370
	 *            object.
......
385 383
		getActiveEditor().setFocus();
386 384
	}
387 385

  
388
	/*
389
	 * (non-Javadoc)
390
	 * 
391
	 * @see
392
	 * eu.etaxonomy.cdm.persistence.hibernate.ICdmPostCrudObserver#update(eu
393
	 * .etaxonomy.cdm.persistence.hibernate.CdmCrudEvent)
394
	 */
395
	/** {@inheritDoc} */
396
	public void update(CdmDataChangeMap events) {
397
		if (dataChangeBehavior == null) {
398
			dataChangeBehavior = new MultiPageTaxonEditorDataChangeBehaviour(
399
					this);
400
		}
401

  
402
		DataChangeBridge.handleDataChange(events, dataChangeBehavior);
403
	}
404

  
405
	/*
406
	 * (non-Javadoc)
407
	 * 
408
	 * @see
409
	 * eu.etaxonomy.taxeditor.store.operations.IPostOperationEnabled#postOperation
410
	 * ()
411
	 */
412
	/** {@inheritDoc} */
413
	public boolean postOperation(CdmBase objectAffectedByOperation) {
414
		setDirty(true);
415

  
416
		for (IEditorPart editor : this.getPages()) {
417
			if (editor instanceof IPostOperationEnabled) {
418
				((IPostOperationEnabled) editor)
419
						.postOperation(objectAffectedByOperation);
420
			} else {
421
				EditorUtil.warn(getClass(),
422
						"postOperation not enabled for editor " + editor);
423
			}
424
		}
425
		EditorUtil
426
				.warn(getClass(),
427
						"postOperation called on MultiPageTaxonEditor. Can you make it more specific?");
428

  
429
		return false;
430
	}
386
    /*
387
     * (non-Javadoc)
388
     *
389
     * @see
390
     * eu.etaxonomy.cdm.persistence.hibernate.ICdmPostCrudObserver#update(eu
391
     * .etaxonomy.cdm.persistence.hibernate.CdmCrudEvent)
392
     */
393
    /** {@inheritDoc} */
394
    @Override
395
    public void update(CdmDataChangeMap events) {
396
        if (dataChangeBehavior == null) {
397
            dataChangeBehavior = new MultiPageTaxonEditorDataChangeBehaviour(this);
398
        }
399

  
400
        DataChangeBridge.handleDataChange(events, dataChangeBehavior);
401
    }
402

  
403
    /*
404
     * (non-Javadoc)
405
     *
406
     * @see
407
     * eu.etaxonomy.taxeditor.store.operations.IPostOperationEnabled#postOperation
408
     * ()
409
     */
410
    /** {@inheritDoc} */
411
    @Override
412
    public boolean postOperation(CdmBase objectAffectedByOperation) {
413
        setDirty(true);
414

  
415
        for (IEditorPart editor : this.getPages()) {
416
            if (editor instanceof IPostOperationEnabled) {
417
                ((IPostOperationEnabled) editor).postOperation(objectAffectedByOperation);
418
            } else {
419
                AbstractUtility.warn(getClass(), "postOperation not enabled for editor " + editor);
420
            }
421
        }
422
        AbstractUtility.warn(getClass(), "postOperation called on MultiPageTaxonEditor. Can you make it more specific?");
423

  
424
        return false;
425
    }
431 426

  
432 427
	/**
433 428
	 * Returns an <code>IEditorPart</code> implementation by type
434
	 * 
429
	 *
435 430
	 * @param page
436 431
	 *            the page type
437 432
	 * @return a {@link eu.etaxonomy.taxeditor.editor.IMultiPageTaxonEditorPage}
......
449 444
	/**
450 445
	 * Return a list of <code>AbstractTaxonEditor</code>s registered with this
451 446
	 * <code>MultiPageTaxonEditor</code>.
452
	 * 
447
	 *
453 448
	 * @return a {@link java.util.List} object.
454 449
	 */
455 450
	public List<IMultiPageTaxonEditorPage> getPages() {
......
463 458

  
464 459
	/**
465 460
	 * Refreshes a certain page of the MultipageTaxonEditor
466
	 * 
461
	 *
467 462
	 * @param page
468 463
	 *            a {@link eu.etaxonomy.taxeditor.editor.Page} object.
469 464
	 * @return a boolean.
......
475 470
	/**
476 471
	 * Refreshes a certain page of the MultipageTaxonEditor and sets focus to
477 472
	 * that page
478
	 * 
473
	 *
479 474
	 * @param page
480 475
	 *            a {@link eu.etaxonomy.taxeditor.editor.Page} object.
481 476
	 * @param focus
......
491 486
	 * <p>
492 487
	 * onComplete
493 488
	 * </p>
494
	 * 
489
	 *
495 490
	 * @return a boolean.
496 491
	 */
497
	public boolean onComplete() {
492
	@Override
493
    public boolean onComplete() {
498 494
		return false;
499 495
	}
500 496

  
501
	/**
502
	 * Reloads the data for this
503
	 */
504
	public void reload() {
505
		if (isDirty()) {
506
			EditorUtil
507
					.warningDialog(
508
							"Editor has unsaved data",
509
							getClass(),
510
							"This editor can not be "
511
									+ "refreshed because it contains unsaved data. Refreshing "
512
									+ "this editor would discard the changes. Please save this editor, "
513
									+ "close and reopen it manually in order to get the latest content");
514
		} else {
515
			TaxonEditorInput input = (TaxonEditorInput) getEditorInput();
516

  
517
			UUID uuid = input.getTaxonNode().getUuid();
518

  
519
			conversation.clear();
520

  
521
			try {
522
				TaxonEditorInput newInput = TaxonEditorInput.NewInstance(uuid);
523
				setInput(newInput);
524
				for (IMultiPageTaxonEditorPage editorPart : getPages()) {
525
					editorPart.redraw();
526
				}
527
			} catch (Exception e) {
528
				EditorUtil.errorDialog("Error refreshing editor", getClass(),
529
						"Could not refresh this editor", e);
530
			}
531
		}
532
	}
533
	
497
    /**
498
     * Reloads the data for this
499
     */
500
    public void reload() {
501
        if (isDirty()) {
502
            AbstractUtility.warningDialog("Editor has unsaved data", getClass(), "This editor can not be "
503
                    + "refreshed because it contains unsaved data. Refreshing "
504
                    + "this editor would discard the changes. Please save this editor, "
505
                    + "close and reopen it manually in order to get the latest content");
506
        } else {
507
            TaxonEditorInput input = (TaxonEditorInput) getEditorInput();
508

  
509
            UUID uuid = input.getTaxonNode().getUuid();
510

  
511
            conversation.clear();
512

  
513
            try {
514
                TaxonEditorInput newInput = TaxonEditorInput.NewInstance(uuid);
515
                setInput(newInput);
516
                for (IMultiPageTaxonEditorPage editorPart : getPages()) {
517
                    editorPart.redraw();
518
                }
519
            } catch (Exception e) {
520
                AbstractUtility.errorDialog("Error refreshing editor", getClass(), "Could not refresh this editor", e);
521
            }
522
        }
523
    }
524

  
534 525
	@Override
535 526
	public String toString() {
536 527
		return String.format("%s[%s]", this.getClass().getSimpleName(), getEditorInput());

Also available in: Unified diff