Project

General

Profile

Revision 6931cd11

ID6931cd1154a9b451ca72e1642a443ccfb89482b2
Parent 27e3249a
Child cc26e350

Added by Cherian Mathew over 8 years ago

updated handlers to be more consistent and use the new TermEditorInput which stores the in memory list of vocabularies
OpenDefinedTermMenu : not used anymore

View differences:

.gitattributes
1081 1081
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/handler/CreateTermVocabularyHandler.java -text
1082 1082
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/handler/DeleteTermBaseHandler.java -text
1083 1083
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/handler/OpenDefinedTermEditorHandler.java -text
1084
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/handler/OpenDefinedTermMenu.java -text
1085 1084
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/input/AbstractDefinedTermEditorInput.java -text
1086 1085
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/input/TermEditorInput.java -text
1087 1086
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/operation/CreateDefinedTermOperation.java -text
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/handler/CreateDefinedTermHandler.java
14 14
import org.eclipse.core.commands.ExecutionException;
15 15
import org.eclipse.core.commands.IHandler;
16 16
import org.eclipse.core.commands.common.NotDefinedException;
17
import org.eclipse.core.commands.operations.IUndoContext;
17 18
import org.eclipse.jface.viewers.IStructuredSelection;
18 19
import org.eclipse.ui.handlers.HandlerUtil;
19 20

  
21
import eu.etaxonomy.cdm.model.common.DefinedTerm;
20 22
import eu.etaxonomy.cdm.model.common.TermBase;
23
import eu.etaxonomy.cdm.model.common.TermVocabulary;
21 24
import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermEditor;
22 25
import eu.etaxonomy.taxeditor.editor.definedterm.operation.CreateDefinedTermOperation;
23 26
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
......
43 46
		IPostOperationEnabled editor = (IPostOperationEnabled) HandlerUtil
44 47
				.getActiveEditor(event);
45 48

  
46
		IStructuredSelection selection = (IStructuredSelection) HandlerUtil
47
				.getCurrentSelection(event);
49
		if (editor instanceof DefinedTermEditor){
50
			DefinedTermEditor dfe = (DefinedTermEditor) editor;
51
			IStructuredSelection selection = (IStructuredSelection) HandlerUtil
52
					.getCurrentSelection(event);
53
			if (selection.getFirstElement() instanceof TermBase) {
54
				try {
55
					String label = event.getCommand().getName();
56
					IUndoContext undoContext = StoreUtil.getUndoContext();
48 57

  
49
		TermBase selectedElement = (TermBase) selection.getFirstElement();
58
					TermBase termBase = (TermBase) selection.getFirstElement();
50 59

  
51
		try {
52
			AbstractPostOperation operation = new CreateDefinedTermOperation(
53
					event.getCommand().getName(), StoreUtil.getUndoContext(),
54
					selectedElement, editor);
55
			StoreUtil.executeOperation(operation);
60
					AbstractPostOperation operation = 
61
							new CreateDefinedTermOperation(label, 
62
									undoContext, 
63
									termBase, 
64
									dfe.getDefinedTermEditorInput(),
65
									editor);
66
					StoreUtil.executeOperation(operation);
56 67

  
57
		} catch (NotDefinedException e) {
58
			StoreUtil.error(getClass(), e);
68
				} catch (NotDefinedException e) {
69
					StoreUtil.error(getClass(), e);
70
				}
71
			}
59 72
		}
60 73

  
61 74
		return null;
62 75
	}
63 76

  
64
}
77
	}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/handler/CreateTermVocabularyHandler.java
14 14
import org.eclipse.core.commands.ExecutionException;
15 15
import org.eclipse.core.commands.IHandler;
16 16
import org.eclipse.core.commands.common.NotDefinedException;
17
import org.eclipse.core.commands.operations.IUndoContext;
17 18
import org.eclipse.jface.viewers.IStructuredSelection;
18 19
import org.eclipse.ui.handlers.HandlerUtil;
19 20

  
20
import eu.etaxonomy.cdm.model.common.TermBase;
21
import eu.etaxonomy.cdm.model.common.TermType;
22
import eu.etaxonomy.cdm.model.common.TermVocabulary;
21 23
import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermEditor;
22
import eu.etaxonomy.taxeditor.editor.definedterm.operation.CreateDefinedTermOperation;
23 24
import eu.etaxonomy.taxeditor.editor.definedterm.operation.CreateTermVocabularyOperation;
24 25
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
25 26
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
......
41 42
		IPostOperationEnabled editor = (IPostOperationEnabled) HandlerUtil
42 43
				.getActiveEditor(event);
43 44

  
44
		if (! (editor instanceof DefinedTermEditor)){
45
			return null;
46
		}
47
		
48
		try {
49
			AbstractPostOperation operation = new CreateTermVocabularyOperation(
50
					event.getCommand().getName(), StoreUtil.getUndoContext(), (DefinedTermEditor) editor);
51
			StoreUtil.executeOperation(operation);
52

  
53
		} catch (NotDefinedException e) {
54
			StoreUtil.error(getClass(), e);
55
		}
45
		if (editor instanceof DefinedTermEditor){
46
			DefinedTermEditor dfe = (DefinedTermEditor) editor;
47

  
48
			try {
49
				String label = event.getCommand().getName();
50
				IUndoContext undoContext = StoreUtil.getUndoContext();
56 51

  
52
				AbstractPostOperation operation = 
53
						new CreateTermVocabularyOperation(label, 
54
								undoContext, 
55
								dfe.getDefinedTermEditorInput(), 
56
								(DefinedTermEditor) editor);
57
				StoreUtil.executeOperation(operation);
58

  
59
			} catch (NotDefinedException e) {
60
				StoreUtil.error(getClass(), e);
61
			}			
62
		}
57 63
		return null;
58 64
	}
59

  
60 65
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/handler/DeleteTermBaseHandler.java
15 15
import org.eclipse.core.commands.ExecutionEvent;
16 16
import org.eclipse.core.commands.ExecutionException;
17 17
import org.eclipse.core.commands.common.NotDefinedException;
18
import org.eclipse.core.commands.operations.IUndoContext;
18 19
import org.eclipse.jface.viewers.IStructuredSelection;
19 20
import org.eclipse.ui.handlers.HandlerUtil;
20 21

  
22
import eu.etaxonomy.cdm.model.common.DefinedTerm;
21 23
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
22 24
import eu.etaxonomy.cdm.model.common.TermBase;
23 25
import eu.etaxonomy.cdm.model.common.TermVocabulary;
......
41 43
		DefinedTermEditor editor = (DefinedTermEditor) HandlerUtil
42 44
				.getActiveEditor(event);
43 45

  
44
		IStructuredSelection selection = (IStructuredSelection) HandlerUtil
45
				.getCurrentSelection(event);
46
		if (editor instanceof DefinedTermEditor){
47
			DefinedTermEditor dfe = (DefinedTermEditor) editor;
48
			try {
49
				String label = event.getCommand().getName();
50
				IUndoContext undoContext = StoreUtil.getUndoContext();
46 51

  
47
		Iterator<TermBase> selectionIterator = selection.iterator();
52
				IStructuredSelection selection = (IStructuredSelection) HandlerUtil
53
						.getCurrentSelection(event);
48 54

  
49
		while (selectionIterator.hasNext()){
50
			
51
			TermBase term = selectionIterator.next();
52
			
53
			try {
54
				AbstractPostOperation operation = new DeleteTermBaseOperation(
55
						event.getCommand().getName(), StoreUtil.getUndoContext(),
56
						term, editor);
57
				StoreUtil.executeOperation(operation);
58
	
55
				Iterator<TermBase> selectionIterator = selection.iterator();
56

  
57
				while (selectionIterator.hasNext()){
58

  
59
					TermBase term = selectionIterator.next();
60

  
61

  
62
					AbstractPostOperation operation = 
63
							new DeleteTermBaseOperation(label, 
64
									undoContext,
65
									term,
66
									dfe.getDefinedTermEditorInput(), 
67
									editor);
68
					StoreUtil.executeOperation(operation);
69

  
70
				}	
59 71
			} catch (NotDefinedException e) {
60 72
				StoreUtil.error(getClass(), e);
61 73
			}
62 74
		}
63

  
64 75
		return null;
65 76
	}
66 77

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/handler/OpenDefinedTermEditorHandler.java
1 1
package eu.etaxonomy.taxeditor.editor.definedterm.handler;
2
import java.util.UUID;
3

  
2 4
import org.eclipse.core.commands.AbstractHandler;
3 5
import org.eclipse.core.commands.ExecutionEvent;
4 6
import org.eclipse.core.commands.ExecutionException;
5 7
import org.eclipse.core.commands.IHandler;
6
import org.eclipse.core.commands.IParameter;
7
import org.eclipse.core.commands.common.NotDefinedException;
8 8
import org.eclipse.ui.IWorkbenchPage;
9 9
import org.eclipse.ui.PartInitException;
10
import org.eclipse.ui.handlers.HandlerUtil;
11
import org.eclipse.ui.handlers.ShowViewHandler;
12 10

  
13
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
14
import eu.etaxonomy.cdm.model.location.NamedArea;
11
import eu.etaxonomy.cdm.model.common.TermType;
15 12
import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermEditor;
16
import eu.etaxonomy.taxeditor.editor.definedterm.input.DefinedTermEditorInputFactory;
13
import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput;
17 14
import eu.etaxonomy.taxeditor.store.StoreUtil;
18 15

  
19 16
// $Id$
......
31 28
 * @date 8 Dec 2011
32 29
 *
33 30
 */
34
public class OpenDefinedTermEditorHandler extends AbstractHandler implements
35
		IHandler {
31
public class OpenDefinedTermEditorHandler extends AbstractHandler implements IHandler {
36 32

  
37 33
	/* (non-Javadoc)
38 34
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
39 35
	 */
40 36
	@Override
41 37
	public Object execute(ExecutionEvent event) throws ExecutionException {
42
		
38

  
39
		String termTypeUuid = event.getParameter("eu.etaxonomy.taxeditor.store.openDefinedTermEditor.termTypeUuid");
40
		IWorkbenchPage activePage = StoreUtil.getActivePage();
43 41
		try {
44
			String parameter = event.getParameter("eu.etaxonomy.taxeditor.store.openDefinedTermEditor.parameter");
45
			Class<? extends DefinedTermBase> clazz = (Class<? extends DefinedTermBase>) Class.forName(parameter);
46
		
47
			IWorkbenchPage activePage = StoreUtil.getActivePage();
48
			try {
49
				activePage.openEditor(DefinedTermEditorInputFactory.NewInstance(clazz), DefinedTermEditor.ID);
50
			} catch (PartInitException e) {
51
				StoreUtil.error(getClass(), e);
52
			}
53
		} catch (ClassNotFoundException e) {
42
			activePage.openEditor(new TermEditorInput(TermType.getByUuid(UUID.fromString(termTypeUuid))), DefinedTermEditor.ID);
43
		} catch (PartInitException e) {
54 44
			StoreUtil.error(getClass(), e);
55 45
		}
46

  
56 47
		return null;
57 48
	}
58 49

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

  
12
import java.util.HashMap;
13
import java.util.Map;
14

  
15
import org.eclipse.jface.action.IContributionItem;
16
import org.eclipse.swt.SWT;
17
import org.eclipse.ui.PlatformUI;
18
import org.eclipse.ui.actions.CompoundContributionItem;
19
import org.eclipse.ui.menus.CommandContributionItem;
20
import org.eclipse.ui.menus.CommandContributionItemParameter;
21

  
22
/**
23
 * @author l.morris
24
 * @date 4 Jan 2012
25
 *
26
 */
27
public class OpenDefinedTermMenu extends CompoundContributionItem {
28

  
29
	/**
30
	 * 
31
	 */
32
	public OpenDefinedTermMenu() {
33
		// TODO Auto-generated constructor stub
34
	}
35

  
36
	/**
37
	 * @param id
38
	 */
39
	public OpenDefinedTermMenu(String id) {
40
		super(id);
41
		// TODO Auto-generated constructor stub
42
	}
43

  
44
	/* (non-Javadoc)
45
	 * @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems()
46
	 */
47
	@Override
48
	protected IContributionItem[] getContributionItems() {
49
		// TODO Auto-generated method stub
50
		return null;
51
	}
52
	
53
	/**
54
	 * @param key
55
	 * @param object
56
	 * @return
57
	 */
58
	private IContributionItem createContributionItem(String label,
59
			String inputType) {
60
		CommandContributionItemParameter parameter = new CommandContributionItemParameter(
61
				PlatformUI.getWorkbench().getActiveWorkbenchWindow(), null,
62
				"eu.etaxonomy.taxeditor.store.definedterm.menu.open", SWT.NONE);
63

  
64
		parameter.label = label;
65

  
66
		Map parameters = new HashMap();
67
		parameters.put("eu.etaxonomy.taxeditor.store.definedterm.menu.open", inputType);
68
		parameter.parameters = parameters;
69

  
70
		return new CommandContributionItem(parameter);
71
	}
72

  
73
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)