Project

General

Profile

Download (1.9 KB) Statistics
| Branch: | Tag: | Revision:
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.propertysheet;
11

    
12
import java.util.Set;
13

    
14
import org.eclipse.jface.viewers.CellEditor;
15
import org.eclipse.jface.viewers.DialogCellEditor;
16
import org.eclipse.swt.widgets.Composite;
17
import org.eclipse.swt.widgets.Control;
18
import org.eclipse.swt.widgets.Dialog;
19
import org.eclipse.ui.views.properties.PropertyDescriptor;
20

    
21
import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
22

    
23
/**
24
 * Property sheet descriptor that pops up a dialog window
25
 *  returning a set.
26
 *  
27
 * @author p.ciardelli
28
 * @created 19.05.2008
29
 * @version 1.0
30
 */
31
abstract public class AnnotationsPropertyDescriptor extends PropertyDescriptor {
32
	
33
	private AnnotatableEntity entity;
34
	
35
	public AnnotationsPropertyDescriptor(Object id, String displayName, AnnotatableEntity entity) {
36
		super(id, displayName);
37
		this.entity = entity;
38
	}
39

    
40
    public CellEditor createPropertyEditor(Composite parent) {
41
        CellEditor editor = new DialogCellEditor(parent) {
42

    
43
        	protected Dialog dialog;
44
        	
45
			@Override
46
			protected Object openDialogBox(
47
					Control cellEditorWindow) {
48
		        dialog = new AnnotationsDialog(cellEditorWindow.getShell(), entity);
49
		        Object value = ((AnnotationsDialog) dialog).open();
50
				if (value instanceof Set) {
51
					
52
					Set<?> annotations = (Set<?>) value;
53
					saveAnnotations(annotations);
54
					return new AnnotationPropertySource(entity);
55
				}
56
				return null;
57
			}
58
        	
59
        };
60
        if (getValidator() != null) {
61
			editor.setValidator(getValidator());
62
		}
63
        return editor;
64
    }
65
        
66
    abstract protected void saveAnnotations(Set<?> set);	
67
}
(4-4/24)