Project

General

Profile

« Previous | Next » 

Revision 972ecc88

Added by Patrick Plitzner over 6 years ago

ref #6913 Remove org.eclipse.ui dependency from AbstractUtility

  • inject IEclipseContext into CdmFactory

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/classification/AbstractEditWizard.java
1 1
/**
2
* Copyright (C) 2016 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
*/
2
 * Copyright (C) 2016 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 9
package eu.etaxonomy.taxeditor.ui.section.classification;
10 10

  
11 11

  
12
import javax.inject.Inject;
13

  
14
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
15
import org.eclipse.e4.core.contexts.IEclipseContext;
12 16
import org.eclipse.jface.viewers.IStructuredSelection;
13 17
import org.eclipse.jface.wizard.Wizard;
14
import org.eclipse.swt.widgets.Display;
15 18
import org.eclipse.ui.INewWizard;
16 19
import org.eclipse.ui.IWorkbench;
17 20

  
......
37 40

  
38 41
    private IWorkbench workbench;
39 42

  
40

  
41

  
42
        /**
43
         * <p>Constructor for AbstractNewEntityWizard.</p>
44
         *
45
         * @param <T> a T object.
46
         */
47
        public AbstractEditWizard(){
48
            setWindowTitle(String.format("New %s", getEntityName()));
49
        }
50

  
51
        /**
52
         * FIXME there might be a smarter way to do this,
53
         *
54
         * @return
55
         */
56
        protected abstract String getEntityName();
57

  
58
        /* (non-Javadoc)
59
         * @see org.eclipse.jface.wizard.Wizard#performFinish()
60
         */
61
        /** {@inheritDoc} */
62
        @Override
63
        public boolean performFinish() {
64
            saveEntity();
65

  
66
            conversation.commit();
67
            conversation.close();
68
            return true;
69
        }
70

  
71
        /**
72
         * <p>Getter for the field <code>entity</code>.</p>
73
         *
74
         * @return a T object.
75
         */
76
        public T getEntity() {
77
            return entity;
78
        }
79

  
80
        /**
81
         * <p>Setter for the field <code>entity</code>.</p>
82
         *
83
         * @param entity a T object.
84
         */
85
        public void setEntity(T entity){
86
            this.entity = entity;
87
        }
88

  
89
        /**
90
         * Adds the entity to the current persistence context
91
         */
92
        protected abstract void saveEntity();
93

  
94
        /* (non-Javadoc)
95
         * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
96
         */
97
        /** {@inheritDoc} */
98
        @Override
99
        public void init(IWorkbench workbench, IStructuredSelection selection) {
100
            this.workbench = workbench != null ? workbench : AbstractUtility.getWorkbench();
101

  
102

  
103
            formFactory = new CdmFormFactory(Display.getCurrent(), null);
104
            conversation = CdmStore.createConversation();
105

  
106

  
107
        }
108

  
109

  
110

  
111
        /**
112
         * <p>getConversationHolder</p>
113
         *
114
         * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
115
         */
116
        @Override
117
        public ConversationHolder getConversationHolder() {
118
            return conversation;
119
        }
120

  
121
        /** {@inheritDoc} */
122
        @Override
123
        public void update(CdmDataChangeMap changeEvents) {}
124

  
125
        /**
126
         * @return the workbench
127
         */
128
        public IWorkbench getWorkbench() {
129
            return workbench;
130
        }
43
    private IEclipseContext context;
44

  
45
    /**
46
     * <p>Constructor for AbstractNewEntityWizard.</p>
47
     *
48
     * @param <T> a T object.
49
     */
50
    @Inject
51
    public AbstractEditWizard(){
52
        setWindowTitle(String.format("New %s", getEntityName()));
53
    }
54

  
55
    /**
56
     * FIXME there might be a smarter way to do this,
57
     *
58
     * @return
59
     */
60
    protected abstract String getEntityName();
61

  
62
    /* (non-Javadoc)
63
     * @see org.eclipse.jface.wizard.Wizard#performFinish()
64
     */
65
    /** {@inheritDoc} */
66
    @Override
67
    public boolean performFinish() {
68
        saveEntity();
69

  
70
        conversation.commit();
71
        conversation.close();
72
        return true;
73
    }
74

  
75
    /**
76
     * <p>Getter for the field <code>entity</code>.</p>
77
     *
78
     * @return a T object.
79
     */
80
    public T getEntity() {
81
        return entity;
82
    }
83

  
84
    /**
85
     * <p>Setter for the field <code>entity</code>.</p>
86
     *
87
     * @param entity a T object.
88
     */
89
    public void setEntity(T entity){
90
        this.entity = entity;
91
    }
92

  
93
    /**
94
     * Adds the entity to the current persistence context
95
     */
96
    protected abstract void saveEntity();
97

  
98
    /* (non-Javadoc)
99
     * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
100
     */
101
    /** {@inheritDoc} */
102
    @Override
103
    public void init(IWorkbench workbench, IStructuredSelection selection) {
104
        this.workbench = workbench != null ? workbench : AbstractUtility.getWorkbench();
105

  
106

  
107
        formFactory = ContextInjectionFactory.make(CdmFormFactory.class, context);
108
        conversation = CdmStore.createConversation();
109

  
110

  
111
    }
112

  
113

  
114

  
115
    /**
116
     * <p>getConversationHolder</p>
117
     *
118
     * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
119
     */
120
    @Override
121
    public ConversationHolder getConversationHolder() {
122
        return conversation;
123
    }
124

  
125
    /** {@inheritDoc} */
126
    @Override
127
    public void update(CdmDataChangeMap changeEvents) {}
128

  
129
    /**
130
     * @return the workbench
131
     */
132
    public IWorkbench getWorkbench() {
133
        return workbench;
134
    }
131 135

  
132 136

  
133 137

  

Also available in: Unified diff