Project

General

Profile

« Previous | Next » 

Revision 2d07da9a

Added by Katja Luther over 3 years ago

ref #8547: default type of inreference depending on ref type

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/handler/create/NewReferenceHandler.java
28 28

  
29 29
    @Execute
30 30
	public void execute(@Named(IServiceConstants.ACTIVE_SHELL)Shell shell) {
31
		NewReferenceWizard wizard = new NewReferenceWizard();
31
		NewReferenceWizard wizard = new NewReferenceWizard(null);
32 32
		wizard.init(null, null);
33 33
		WizardDialog dialog = new WizardDialog(shell, wizard);
34 34
		dialog.open();
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/newWizard/AbstractNewEntityWizard.java
29 29
public abstract class AbstractNewEntityWizard<T> extends Wizard implements
30 30
		IConversationEnabled {
31 31

  
32
	private ConversationHolder conversation;
32
	protected ConversationHolder conversation;
33 33

  
34 34
	protected CdmFormFactory formFactory;
35 35

  
36 36
	private T entity;
37 37

  
38
	private IStructuredSelection selection;
38
	protected IStructuredSelection selection;
39 39

  
40 40
	public AbstractNewEntityWizard(){
41 41
		setWindowTitle(String.format("New %s", getEntityName()));
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/newWizard/NewCommonNameReferenceWizard.java
11 11
import eu.etaxonomy.cdm.api.service.IReferenceService;
12 12
import eu.etaxonomy.cdm.model.common.Marker;
13 13
import eu.etaxonomy.cdm.model.common.MarkerType;
14
import eu.etaxonomy.cdm.model.reference.ReferenceType;
14 15
import eu.etaxonomy.taxeditor.store.CdmStore;
15 16

  
16 17
/**
......
21 22
public class NewCommonNameReferenceWizard extends NewReferenceWizard {
22 23

  
23 24

  
25
    /**
26
     * @param type
27
     */
28
    public NewCommonNameReferenceWizard(ReferenceType type) {
29
        super(type);
30
    }
31

  
24 32
    @Override
25 33
    protected void saveEntity() {
26 34
        getEntity().addMarker(Marker.NewInstance(MarkerType.COMMON_NAME_REFERENCE(), true));
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/newWizard/NewReferenceWizard.java
9 9

  
10 10
package eu.etaxonomy.taxeditor.newWizard;
11 11

  
12
import java.util.Set;
13

  
14
import org.eclipse.e4.ui.workbench.IWorkbench;
15
import org.eclipse.jface.viewers.IStructuredSelection;
16
import org.eclipse.swt.widgets.Display;
17

  
12 18
import eu.etaxonomy.cdm.api.service.IReferenceService;
13 19
import eu.etaxonomy.cdm.model.reference.Reference;
14 20
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
21
import eu.etaxonomy.cdm.model.reference.ReferenceType;
15 22
import eu.etaxonomy.taxeditor.store.CdmStore;
23
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
16 24
import eu.etaxonomy.taxeditor.ui.section.reference.ReferenceWizardPage;
17 25

  
18 26
/**
......
25 33
public class NewReferenceWizard extends AbstractNewEntityWizard<Reference> {
26 34

  
27 35
	private ReferenceWizardPage referencePage;
36
	private ReferenceType refType = null;
37

  
38
	public NewReferenceWizard(ReferenceType type){
39
	    super();
40
	    refType = type;
41
	}
42

  
43
	@Override
44
	public void init(IWorkbench workbench, IStructuredSelection selection) {
45
        formFactory = new CdmFormFactory(Display.getCurrent(), null);
46
        conversation = CdmStore.createConversation();
47
        this.selection = selection;
48
        setEntity(createNewEntity());
49

  
50
    }
28 51

  
29 52
	/** {@inheritDoc} */
30 53
	@Override
......
38 61
	/** {@inheritDoc} */
39 62
	@Override
40 63
	protected Reference createNewEntity() {
64
	    if (refType != null){
65
	        Set<ReferenceType> inReferenceTypes = ReferenceType.inReferenceContraints(refType);
66
	        if (!inReferenceTypes.isEmpty()){
67
	            return ReferenceFactory.newReference(inReferenceTypes.iterator().next());
68
	        }
69
	    }
41 70
		return ReferenceFactory.newGeneric();
42 71
	}
43 72

  
......
51 80
	@Override
52 81
	public void setEntity(Reference entity) {
53 82
		super.setEntity(entity);
54
		referencePage.getDetailElement().setEntity(entity);
83
		if (referencePage != null){
84
		    referencePage.getDetailElement().setEntity(entity);
85
		}
55 86
	}
56 87

  
57 88
	@Override
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/CommonNameReferenceSelectionDialog.java
66 66

  
67 67
    @Override
68 68
    protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
69
        return new NewCommonNameReferenceWizard();
69
        return new NewCommonNameReferenceWizard(null);
70 70
    }
71 71

  
72 72
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/ExtReferenceSelectionDialog.java
203 203

  
204 204
    @Override
205 205
    protected NewReferenceWizard getNewEntityWizard(String parameter) {
206
        return new NewReferenceWizard();
206
        return new NewReferenceWizard(null);
207 207
    }
208 208

  
209 209
    @Override
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/ReferenceSelectionDialog.java
254 254
	/** {@inheritDoc} */
255 255
	@Override
256 256
	protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
257
		return new NewReferenceWizard();
257
	    if (isInReference){
258
	        return new NewReferenceWizard(this.currentReference.getType());
259
	    }
260
		return new NewReferenceWizard(null);
258 261
	}
259 262

  
260 263
	/** {@inheritDoc} */
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/SelectionDialogFactory.java
94 94
			return (T) TaxonNodeSelectionDialog.select(shell, //conversation,
95 95
			        null, null, (TaxonNode) currentSelection, ((TaxonNode) currentSelection).getClassification().getUuid());
96 96
		}
97
		if(clazz.equals(Reference.class) && parentElement instanceof NomenclaturalReferenceDetailElement){
97
		if(clazz.equals(Reference.class) && parentElement.getParentElement() instanceof NomenclaturalReferenceDetailElement){
98 98
			return (T) NomenclaturalReferenceSelectionDialog.select(shell, //conversation,
99
			        (Reference) currentSelection, ((NomenclaturalReferenceDetailElement)parentElement).getEntity().getCombinationAuthorship());
99
			        (Reference) currentSelection, ((NomenclaturalReferenceDetailElement)parentElement.getParentElement()).getEntity().getCombinationAuthorship());
100 100
		}
101 101
		if(clazz.equals(Reference.class) && parentElement instanceof CommonNameSourceElement && PreferencesUtil.getFilterCommonNameReferences()){
102 102
            return (T) CommonNameReferenceSelectionDialog.select(shell, //conversation,

Also available in: Unified diff