Project

General

Profile

Revision c88cdfbe

IDc88cdfbe87af6ee023cd6e6b3d3fcd1a46cb811d
Parent 939829bc
Child 361f2123

Added by Patrick Plitzner over 3 years ago

Extract string constants

View differences:

eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/handler/NewObjectHandler.java
1 1
/**
2 2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
9 9

  
10 10
package eu.etaxonomy.taxeditor.annotatedlineeditor.handler;
11 11

  
12
import java.net.URI;
13
import java.net.URISyntaxException;
14

  
15 12
import org.eclipse.core.commands.AbstractHandler;
16 13
import org.eclipse.core.commands.ExecutionEvent;
17 14
import org.eclipse.core.commands.ExecutionException;
......
25 22

  
26 23
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
27 24
import eu.etaxonomy.taxeditor.annotatedlineeditor.AnnotatedLineEditor;
25
import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.GroupCreator;
26
import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.UserCreator;
28 27

  
29 28
/**
30 29
 * <p>NewObjectHandler class.</p>
......
39 38
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
40 39
	 */
41 40
	/** {@inheritDoc} */
42
	public Object execute(ExecutionEvent event) throws ExecutionException {
43
		
41
	@Override
42
    public Object execute(ExecutionEvent event) throws ExecutionException {
43

  
44 44
		IEditorPart editor = HandlerUtil.getActiveEditor(event);
45 45
		IEditorInput input = editor.getEditorInput();
46
		
46

  
47 47
		if (editor instanceof AnnotatedLineEditor) {
48
			
48

  
49 49
			Object key = ((Event)event.getTrigger()).data;
50 50
			if (key != null) {
51 51
				if(!(key instanceof SpecimenOrObservationType)) {
52
					String text = ((Event)event.getTrigger()).text; 
53
					
52
					String text = ((Event)event.getTrigger()).text;
53

  
54 54
					//FIXME : This should probably go into some ValidatorFactory
55 55
					IInputValidator nonEmptyInputValidator = null;
56
					//FIXME : This is a workaround to not allow empty strings in the 
57
					//        input dialog for User and Group entities. 
56
					//FIXME : This is a workaround to not allow empty strings in the
57
					//        input dialog for User and Group entities.
58 58
					//        Normally this should be default
59 59
					//        behaviour, so we need to discuss whether this handler
60 60
					//        should be used to handle the creating new entities of
61 61
					//        type other than User and Group.
62 62
					//        Once #4348 is fixed this check can be removed.
63
					if(text.equals("User") || text.equals("Group")) {
63
					if(text.equals(UserCreator.USER) || text.equals(GroupCreator.GROUP)) {
64 64
						nonEmptyInputValidator = new IInputValidator() {
65
							public String isValid(String text) {							
65
							@Override
66
                            public String isValid(String text) {
66 67
								if(text == null || text.isEmpty()) {
67 68
									return "Input cannot be empty";
68 69
								}
69 70
								return null;
70
							}			
71
							}
71 72
						};
72 73
					}
73
					InputDialog dialog = new InputDialog(HandlerUtil.getActiveShell(event), 
74
							"Create " + text, 
75
							"Enter new " + text, "",
76
							nonEmptyInputValidator); 
74
					InputDialog dialog = new InputDialog(HandlerUtil.getActiveShell(event),
75
							String.format("Create %s", text), String.format("Enter new %s", text), "",
76
							nonEmptyInputValidator);
77 77

  
78
					if (dialog.open() != Window.CANCEL) { 
79
						((AnnotatedLineEditor) editor).createAnnotatedLineNewObject(key, dialog.getValue()); 
78
					if (dialog.open() != Window.CANCEL) {
79
						((AnnotatedLineEditor) editor).createAnnotatedLineNewObject(key, dialog.getValue());
80 80
					}
81 81
				} else {
82
					((AnnotatedLineEditor) editor).createAnnotatedLineNewObject(key, "Untitled"); 
82
					((AnnotatedLineEditor) editor).createAnnotatedLineNewObject(key, "Untitled");
83 83
				}
84
				
84

  
85 85
			} else {
86 86
				((AnnotatedLineEditor) editor).createAnnotatedLineNewObject();
87 87
			}
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/entitycreator/GroupCreator.java
1 1
/**
2 2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
22 22
 */
23 23
public class GroupCreator implements IEntityCreator<Group> {
24 24

  
25
	/* (non-Javadoc)
25
    public static final String GROUP = "Group";
26

  
27
    /* (non-Javadoc)
26 28
	 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#createEntity(java.lang.String)
27 29
	 */
28 30
	@Override
......
44 46
	@Override
45 47
	public Map<Object, String> getKeyLabelPairs() {
46 48
		Map<Object, String> result = new HashMap<Object, String>();
47
		result.put(Group.class, "Group");
49
		result.put(Group.class, GROUP);
48 50
		return result;
49 51
	}
50 52

  
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/entitycreator/UserCreator.java
30 30
 */
31 31
public class UserCreator  implements IEntityCreator<User>{
32 32

  
33
	/* (non-Javadoc)
33
    public static final String USER = "User";
34

  
35
    /* (non-Javadoc)
34 36
	 * @see eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator#createEntity(java.lang.String)
35 37
	 */
36 38
	@Override
......
66 68
	@Override
67 69
	public Map<Object, String> getKeyLabelPairs() {
68 70
		Map<Object, String> result = new HashMap<Object, String>();
69
		result.put(User.class, "User");
71
		result.put(User.class, USER);
70 72
		return result;
71 73
	}
72 74

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)