Project

General

Profile

« Previous | Next » 

Revision c88cdfbe

Added by Patrick Plitzner about 7 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
			}

Also available in: Unified diff