Project

General

Profile

« Previous | Next » 

Revision ec23f5f4

Added by Cherian Mathew over 8 years ago

#5301 Fix null session issues, Add remoting session for feature tree editor

View differences:

eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/CdmEntitySessionManager.java
186 186
            setActiveSession(null);
187 187
        }
188 188
        ownerSessionMap.remove(owner);
189
        notifyObservers();
189 190

  
190 191
    }
191 192

  
......
198 199
        if(nullSession != null && nullSession.getOwner() == owner) {
199 200
            nullSession = null;
200 201
        }
201
        notifyObservers();
202
    }
203 202

  
204
    @Override
205
    public void disposeNullSession() {
206
        nullSession = null;
207
        notifyObservers();
208 203
    }
209 204

  
205

  
210 206
    @Override
211 207
    public void disposeAll() {
212 208
        Set<ICdmEntitySessionEnabled> owners =
......
217 213
                session.dispose();
218 214
            }
219 215
        }
220
        notifyObservers();
216

  
221 217
    }
222 218

  
223 219
    void addToOwnerSessionMap(ICdmEntitySessionEnabled owner, ICdmEntitySession session) {
224 220
        ownerSessionMap.put(owner, session);
221
        notifyObservers();
225 222
    }
226 223

  
227 224
    /* (non-Javadoc)
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/ICdmEntitySessionManager.java
72 72
     */
73 73
    public ICdmEntitySession getNullSession();
74 74

  
75
    /**
76
     *
77
     */
78
    public void disposeNullSession();
79 75

  
80 76
}
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/session/mock/MockCdmEntitySessionManager.java
134 134
        return new MockCdmEntitySession();
135 135
    }
136 136

  
137
    /* (non-Javadoc)
138
     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#disposeNullSession()
139
     */
140
    @Override
141
    public void disposeNullSession() {
142
        // TODO Auto-generated method stub
143

  
144
    }
145

  
146

  
147

  
148 137
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/EditFeatureTreeWizardPage.java
1 1
// $Id$
2 2
/**
3 3
 * Copyright (C) 2007 EDIT
4
 * European Distributed Institute of Taxonomy 
4
 * European Distributed Institute of Taxonomy
5 5
 * http://www.e-taxonomy.eu
6
 * 
6
 *
7 7
 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 8
 * See LICENSE.TXT at the top of this package for the full license terms.
9 9
 */
......
49 49
 * <p>
50 50
 * EditFeatureTreeWizardPage class.
51 51
 * </p>
52
 * 
52
 *
53 53
 * @author n.hoffmann
54 54
 * @created Aug 5, 2010
55 55
 * @version 1.0
......
69 69
	 * <p>
70 70
	 * Constructor for EditFeatureTreeWizardPage.
71 71
	 * </p>
72
	 * 
72
	 *
73 73
	 * @param pageName
74 74
	 *            a {@link java.lang.String} object.
75 75
	 */
......
80 80

  
81 81
	/*
82 82
	 * (non-Javadoc)
83
	 * 
83
	 *
84 84
	 * @see
85 85
	 * org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
86 86
	 * .Composite)
......
153 153
	 * <p>
154 154
	 * setSelectedTree
155 155
	 * </p>
156
	 * 
156
	 *
157 157
	 * @param featureTree
158 158
	 *            a {@link eu.etaxonomy.cdm.model.description.FeatureTree}
159 159
	 *            object.
......
200 200
						.getAdditionalFeatures();
201 201
				for (Feature feature : additionalFeatures) {
202 202
					FeatureNode child = FeatureNode.NewInstance(feature);
203
					CdmStore.getService(IFeatureNodeService.class)
204
							.saveOrUpdate(child);
203
					if(CdmStore.getCurrentSessionManager().isRemoting()) {
204
					    CdmStore.getService(IFeatureNodeService.class).merge(child, true);
205
					} else {
206
					    CdmStore.getService(IFeatureNodeService.class).saveOrUpdate(child);
207
					}
205 208
					parent.addChild(child);
206 209
				}
207 210
				viewer.refresh();
......
237 240
		 */
238 241
		@Override
239 242
		public void dragFinished(DragSourceEvent event) {
240
			if (!event.doit)
241
				return;
243
			if (!event.doit) {
244
                return;
245
            }
242 246
			// if the featureNode was moved, remove it from the source viewer
243 247
			if (event.detail == DND.DROP_MOVE) {
244 248
				IStructuredSelection selection = (IStructuredSelection) viewer
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/FeatureTreeEditorWizard.java
1 1
// $Id$
2 2
/**
3 3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
4
* European Distributed Institute of Taxonomy
5 5
* http://www.e-taxonomy.eu
6
* 
6
*
7 7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8 8
* See LICENSE.TXT at the top of this package for the full license terms.
9 9
*/
10 10

  
11 11
package eu.etaxonomy.taxeditor.featuretree;
12 12

  
13
import java.util.Arrays;
14
import java.util.List;
15
import java.util.Map;
16

  
13 17
import org.eclipse.jface.wizard.Wizard;
14 18

  
15 19
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
16 20
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
17 21
import eu.etaxonomy.cdm.model.description.FeatureTree;
22
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
23
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
18 24
import eu.etaxonomy.taxeditor.store.CdmStore;
19 25

  
20 26
/**
......
24 30
 * @created Aug 5, 2010
25 31
 * @version 1.0
26 32
 */
27
public class FeatureTreeEditorWizard extends Wizard {
28
	
33
public class FeatureTreeEditorWizard extends Wizard implements ICdmEntitySessionEnabled {
34

  
29 35
	private SelectFeatureTreeWizardPage selectFeatureTreePage;
30 36
	private EditFeatureTreeWizardPage editFeatureTreePage;
31
	
37

  
32 38
	private FeatureTree selectedFeatureTree;
33 39

  
34 40
	private ConversationHolder conversation;
35
	
41
	private ICdmEntitySession cdmEntitySession;
42
	private ICdmEntitySession previousCdmEntitySession;
43

  
36 44
	/**
37 45
	 * <p>Constructor for FeatureTreeEditorWizard.</p>
38 46
	 */
39 47
	public FeatureTreeEditorWizard(){
40 48
		conversation = CdmStore.createConversation();
49
		previousCdmEntitySession = CdmStore.getCurrentSessionManager().getActiveSession();
50
		cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
41 51
		setWindowTitle("Feature Tree Editor");
42 52
	}
43
	
53

  
44 54
	/**
45 55
	 * <p>addPages</p>
46 56
	 */
47
	public void addPages() {
57
	@Override
58
    public void addPages() {
48 59
		selectFeatureTreePage = new SelectFeatureTreeWizardPage("SELECT");
49 60
		addPage(selectFeatureTreePage);
50
		
61

  
51 62
		editFeatureTreePage = new EditFeatureTreeWizardPage("EDIT");
52 63
		addPage(editFeatureTreePage);
53 64
	}
......
59 70
	public boolean performFinish() {
60 71
		try{
61 72
			if (selectedFeatureTree != null){
62
				CdmStore.getService(IFeatureTreeService.class).saveOrUpdate(selectedFeatureTree);
73
			    if(CdmStore.getCurrentSessionManager().isRemoting()) {
74
			        CdmStore.getService(IFeatureTreeService.class).merge(selectedFeatureTree, true);
75
			    } else {
76
			        CdmStore.getService(IFeatureTreeService.class).saveOrUpdate(selectedFeatureTree);
77
			    }
63 78
			}
64 79
			conversation.commit();
65 80
		}finally{
66 81
			conversation.close();
82
			cdmEntitySession.dispose();
83
			if(previousCdmEntitySession != null) {
84
			    previousCdmEntitySession.bind();
85
			}
67 86
		}
68
		
87

  
69 88
		return true;
70 89
	}
71 90

  
91
	/** {@inheritDoc} */
92
    @Override
93
    public boolean performCancel() {
94
        cdmEntitySession.dispose();
95
        if(previousCdmEntitySession != null) {
96
            previousCdmEntitySession.bind();
97
        }
98
        return true;
99
    }
100

  
72 101
	/**
73 102
	 * <p>Setter for the field <code>selectedFeatureTree</code>.</p>
74 103
	 *
......
87 116
	public FeatureTree getSelectedFeatureTree() {
88 117
		return selectedFeatureTree;
89 118
	}
90
	
119

  
120
    /* (non-Javadoc)
121
     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getCdmEntitySession()
122
     */
123
    @Override
124
    public ICdmEntitySession getCdmEntitySession() {
125
        // TODO Auto-generated method stub
126
        return null;
127
    }
128

  
129
    /* (non-Javadoc)
130
     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
131
     */
132
    @Override
133
    public List<FeatureTree> getRootEntities() {
134
        return Arrays.asList(selectedFeatureTree);
135
    }
136

  
137
    /* (non-Javadoc)
138
     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap()
139
     */
140
    @Override
141
    public Map<Object, List<String>> getPropertyPathsMap() {
142
        // TODO Auto-generated method stub
143
        return null;
144
    }
145

  
91 146
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/FeatureTreePreferences.java
10 10

  
11 11
package eu.etaxonomy.taxeditor.preference;
12 12

  
13
import org.eclipse.jface.preference.PreferencePage;
14 13
import org.eclipse.jface.resource.ImageDescriptor;
15 14
import org.eclipse.swt.SWT;
16 15
import org.eclipse.swt.layout.GridLayout;
......
19 18
import org.eclipse.ui.IWorkbench;
20 19
import org.eclipse.ui.IWorkbenchPreferencePage;
21 20

  
21
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
22 22
import eu.etaxonomy.taxeditor.store.CdmStore;
23 23
import eu.etaxonomy.taxeditor.ui.element.CommandHandlerButton;
24 24

  
......
31 31
 * @created Aug 5, 2010
32 32
 * @version 1.0
33 33
 */
34
public class FeatureTreePreferences extends PreferencePage implements
34
public class FeatureTreePreferences extends CdmPreferencePage implements
35 35
		IWorkbenchPreferencePage {
36 36

  
37 37
	/**
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/menu/CdmPreferencePage.java
14 14
import java.util.Map;
15 15

  
16 16
import org.eclipse.jface.preference.PreferencePage;
17
import org.eclipse.jface.resource.ImageDescriptor;
17 18

  
18 19
import eu.etaxonomy.cdm.model.common.CdmBase;
19 20
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
......
27 28
 */
28 29
public abstract class CdmPreferencePage extends PreferencePage implements ICdmEntitySessionEnabled {
29 30

  
31
    private ICdmEntitySession previousCdmEntitySession;
32
    private boolean isApply;
33

  
30 34
    public CdmPreferencePage() {
31
        bindNullSession();
35
        initSession();
32 36
    }
33 37

  
34 38
    public CdmPreferencePage(String title) {
35 39
        super(title);
40
        initSession();
41
    }
42

  
43
    public CdmPreferencePage(String title, ImageDescriptor image) {
44
        super(title, image);
45
        initSession();
46
    }
47

  
48
    private void initSession() {
49
        previousCdmEntitySession = CdmStore.getCurrentSessionManager().getActiveSession();
36 50
        bindNullSession();
37 51
    }
38 52

  
......
42 56
        }
43 57
    }
44 58

  
45
    protected void disposeNullSession() {
46
        if(CdmStore.isActive()) {
47
            CdmStore.getCurrentSessionManager().disposeNullSession();
48
        }
49
    }
50

  
51 59
    @Override
52 60
    public boolean performOk() {
53
        disposeNullSession();
61
        if(previousCdmEntitySession != null && !isApply) {
62
            previousCdmEntitySession.bind();
63
        }
54 64
        return super.performOk();
55 65
    }
56 66

  
57 67
    @Override
58 68
    public boolean performCancel() {
59
        disposeNullSession();
69
        if(previousCdmEntitySession != null) {
70
            previousCdmEntitySession.bind();
71
        }
60 72
        return super.performCancel();
61 73
    }
62 74

  
63
       /* (non-Javadoc)
75
    @Override
76
    public void performApply() {
77
        isApply = true;
78
        super.performApply();
79
        isApply = false;
80
    }
81

  
82
    /* (non-Javadoc)
64 83
     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getCdmEntitySession()
65 84
     */
66 85
    @Override

Also available in: Unified diff