Project

General

Profile

Revision a2a04809

IDa2a04809ca6c7ee66db7bcaea8e760e7e37611fb
Parent e2ecfad8
Child 3f85ffbd

Added by Patrick Plitzner almost 3 years ago

ref #6932 Fix new element handler and save

View differences:

eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/e4/handler/NewObjectHandlerE4.java
15 15
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
16 16
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
17 17
import org.eclipse.e4.ui.services.IServiceConstants;
18
import org.eclipse.jface.dialogs.IInputValidator;
19
import org.eclipse.jface.dialogs.InputDialog;
20
import org.eclipse.jface.window.Window;
21
import org.eclipse.swt.widgets.Shell;
18 22

  
19 23
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
20 24
import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorConstants;
21 25
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
26
import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.GroupCreator;
27
import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.UserCreator;
22 28

  
23 29
/**
24 30
 *
......
30 36

  
31 37
    @Execute
32 38
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
39
            @Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
33 40
            MHandledMenuItem menuItem) {
34 41

  
35 42
        Object key = menuItem.getTransientData().get(IBulkEditorConstants.DYNAMIC_OPEN_OBJECT_ID+".key");
36 43

  
37 44
        BulkEditorE4 bulkEditor = (BulkEditorE4) activePart.getObject();
38 45

  
39

  
40 46
        if (key != null) {
41
            IEntityCreator entityCreator = bulkEditor.getEditorInput().getEntityCreator();
42 47
            String text = menuItem.getCommand().getCommandName();
43
            Object createdEntity = entityCreator.createEntity(text);
44
            bulkEditor.getEditorInput().getModel().add(createdEntity);
45
            bulkEditor.refresh();
48
            //FIXME : This should probably go into some ValidatorFactory
49
            IInputValidator nonEmptyInputValidator = null;
50
            //FIXME : This is a workaround to not allow empty strings in the
51
            //        input dialog for User and Group entities.
52
            //        Normally this should be default
53
            //        behaviour, so we need to discuss whether this handler
54
            //        should be used to handle the creating new entities of
55
            //        type other than User and Group.
56
            //        Once #4348 is fixed this check can be removed.
57
            if(text.equals(UserCreator.USER) || text.equals(GroupCreator.GROUP)) {
58
                nonEmptyInputValidator = new IInputValidator() {
59
                    @Override
60
                    public String isValid(String text) {
61
                        if(text == null || text.isEmpty()) {
62
                            return "Input cannot be empty";
63
                        }
64
                        return null;
65
                    }
66
                };
67
            }
68
            InputDialog dialog = new InputDialog(shell,
69
                    String.format("Create %s", text), String.format("Enter new %s", text), "",
70
                    nonEmptyInputValidator);
46 71

  
47
            //				if(!(key instanceof SpecimenOrObservationType)) {
48
            //
49
            //					//FIXME : This should probably go into some ValidatorFactory
50
            //					IInputValidator nonEmptyInputValidator = null;
51
            //					//FIXME : This is a workaround to not allow empty strings in the
52
            //					//        input dialog for User and Group entities.
53
            //					//        Normally this should be default
54
            //					//        behaviour, so we need to discuss whether this handler
55
            //					//        should be used to handle the creating new entities of
56
            //					//        type other than User and Group.
57
            //					//        Once #4348 is fixed this check can be removed.
58
            //					if(text.equals(UserCreator.USER) || text.equals(GroupCreator.GROUP)) {
59
            //						nonEmptyInputValidator = new IInputValidator() {
60
            //							@Override
61
            //                            public String isValid(String text) {
62
            //								if(text == null || text.isEmpty()) {
63
            //									return "Input cannot be empty";
64
            //								}
65
            //								return null;
66
            //							}
67
            //						};
68
            //					}
69
            //					InputDialog dialog = new InputDialog(shell,
70
            //							String.format("Create %s", text), String.format("Enter new %s", text), "",
71
            //							nonEmptyInputValidator);
72
            //
73
            //					if (dialog.open() != Window.CANCEL) {
74
            //						((AnnotatedLineEditor) editor).createAnnotatedLineNewObject(key, dialog.getValue());
75
            //					}
76
            //				} else {
77
            //					((AnnotatedLineEditor) editor).createAnnotatedLineNewObject(key, "Untitled");
78
            //				}
79
            //
80
            //			} else {
81
            //				((AnnotatedLineEditor) editor).createAnnotatedLineNewObject();
82
            //			}
72
            if (dialog.open() != Window.CANCEL) {
73
                IEntityCreator entityCreator = bulkEditor.getEditorInput().getEntityCreator();
74
                Object createdEntity = entityCreator.createEntity(key, dialog.getValue());
75
                bulkEditor.getEditorInput().getModel().add(createdEntity);
76
                bulkEditor.refresh(true);
77
                bulkEditor.setDirty();
78
            }
83 79
        }
84 80
    }
85 81
}
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/BulkEditorLineDisplay.java
22 22
import eu.etaxonomy.cdm.model.agent.AgentBase;
23 23
import eu.etaxonomy.cdm.model.common.CdmBase;
24 24
import eu.etaxonomy.cdm.model.common.IAnnotatableEntity;
25
import eu.etaxonomy.cdm.model.common.ICdmBase;
26 25
import eu.etaxonomy.cdm.model.common.Marker;
27 26
import eu.etaxonomy.cdm.model.name.TaxonName;
28 27
import eu.etaxonomy.cdm.model.reference.Reference;
......
64 63
	/** {@inheritDoc} */
65 64
	@Override
66 65
    public String getText(Object entity) {
67
		return editor.getEditorInput().getText((ICdmBase) entity);
66
		return editor.getEditorInput().getText((CdmBase) entity);
68 67
	}
69 68

  
70 69
	/** {@inheritDoc} */
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/AnnotatedTableItem.java
9 9
*/
10 10
package eu.etaxonomy.taxeditor.bulkeditor.e4;
11 11

  
12
import eu.etaxonomy.cdm.model.common.ICdmBase;
12
import eu.etaxonomy.cdm.model.common.CdmBase;
13 13

  
14 14
/**
15 15
 * @author pplitzner
16 16
 * @date 12.09.2017
17 17
 *
18 18
 */
19
public class AnnotatedTableItem <T extends ICdmBase> {
19
public class AnnotatedTableItem <T extends CdmBase> {
20 20

  
21 21
    private T element;
22 22
    private boolean isMergeCandidate = false;
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorE4.java
126 126

  
127 127
	@Persist
128 128
	public void save() {
129
	    dirty.setDirty(false);
129
	    // commit the conversation and start a new transaction immediately
130
	    conversation.commit(true);
130 131

  
131
	    this.searchBar.updateEditorInput();
132
	    Object object = viewer.getInput();
133
	    if(object instanceof List){
134
	        for (Object item: (List)object) {
135
	            if(item instanceof AnnotatedTableItem){
136
	                CdmBase cdmBase = ((AnnotatedTableItem) item).getElement();
137
                    CdmStore.getService(cdmBase).merge(cdmBase, true);
138
	            }
132 139

  
140
            }
141
	    }
142
        dirty.setDirty(false);
133 143
	}
134 144

  
135 145
	/** {@inheritDoc} */
......
156 166
    }
157 167

  
158 168
    public void refresh() {
169
        refresh(false);
170
    }
171

  
172
    public void refresh(boolean resetInput) {
173
        if(resetInput){
174
            viewer.setInput(getEditorInput().getWrappedModel());
175
        }
159 176
        viewer.refresh();
160 177
    }
161 178

  
179
    public TableViewer getViewer() {
180
        return viewer;
181
    }
182

  
183
    public void setDirty(){
184
        dirty.setDirty(true);
185
    }
186

  
162 187
    public boolean isDirty() {
163 188
        return dirty.isDirty();
164 189
    }
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/AbstractBulkEditorInput.java
23 23
import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
24 24
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
25 25
import eu.etaxonomy.cdm.model.common.CdmBase;
26
import eu.etaxonomy.cdm.model.common.ICdmBase;
27 26
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
28 27
import eu.etaxonomy.cdm.model.common.MarkerType;
29 28
import eu.etaxonomy.cdm.strategy.merge.IMergable;
......
46 45
 * @version 1.0
47 46
 * @param <T>
48 47
 */
49
public abstract class AbstractBulkEditorInput<T extends ICdmBase> extends CdmEntitySessionInput implements IEditorInput ,
48
public abstract class AbstractBulkEditorInput<T extends CdmBase> extends CdmEntitySessionInput implements IEditorInput ,
50 49
    IEntityPersistenceService<T> {
51 50

  
52 51
	private UUID entityUuid;
53 52

  
54
	private List<T> model;
53
	private List<T> model = new ArrayList<>();
55 54

  
56 55
	private IEntityCreator<T> entityCreator;
57 56
	private final ConversationHolder conversation;

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)