3 * Copyright (C) 2015 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.bulkeditor
.handler
;
12 import org
.eclipse
.core
.commands
.AbstractHandler
;
13 import org
.eclipse
.core
.commands
.ExecutionEvent
;
14 import org
.eclipse
.core
.commands
.ExecutionException
;
15 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
16 import org
.eclipse
.jface
.viewers
.ISelection
;
17 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
18 import org
.eclipse
.ui
.IEditorInput
;
19 import org
.eclipse
.ui
.IEditorPart
;
20 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
21 import org
.eclipse
.ui
.texteditor
.IDocumentProvider
;
23 import eu
.etaxonomy
.cdm
.api
.service
.IAgentService
;
24 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
25 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
26 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
27 import eu
.etaxonomy
.cdm
.strategy
.merge
.MergeException
;
28 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.IEntityPersistenceService
;
29 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.LineAnnotation
;
30 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.LineAnnotationModel
;
31 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditor
;
32 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
33 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
40 public class ConvertPerson2TeamHandler
extends AbstractHandler
{
46 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
47 ISelection selection
= HandlerUtil
.getCurrentSelection(event
);
49 IEditorPart editor
= HandlerUtil
.getActiveEditor(event
);
51 IEditorInput input
= editor
.getEditorInput();
52 if (editor
.isDirty()){
53 boolean proceed
= MessageDialog
.openQuestion(null,
54 "Save changes", "You have made changes that must be saved before this query can be executed. Would you like to proceed?");
61 if((input
instanceof IEntityPersistenceService
) && (selection
instanceof IStructuredSelection
)){
64 IDocumentProvider provider
= ((BulkEditor
) editor
).getDocumentProvider();
65 LineAnnotationModel model
=
66 (LineAnnotationModel
) provider
.getAnnotationModel(input
);
69 IStructuredSelection structuredSelection
= (IStructuredSelection
) selection
;
71 IEntityPersistenceService persistenceService
= (IEntityPersistenceService
) input
;
74 for(Object object
: structuredSelection
.toList()){
75 LineAnnotation annotation
= (LineAnnotation
) model
.getAnnotation(object
);
77 if (object
instanceof Person
){
78 Person person
= HibernateProxyHelper
.deproxy(object
, Person
.class);
80 team
= CdmStore
.getService(IAgentService
.class).convertPerson2Team(person
);
81 } catch (IllegalArgumentException e
) {
82 MessagingUtils
.errorDialog("Can not convert Team to Person", null, e
.getMessage(), null,e
, true);
83 } catch (MergeException e
) {
84 MessagingUtils
.errorDialog("Can not convert Team to Person", null, e
.getMessage(), null,e
, true);
87 MessagingUtils
.informationDialog("Can not convert Team to Person", "convertTeam2Person can only be called on a team.");
91 ((BulkEditor
) editor
).removeAnnotatedLine(annotation
);
92 ((BulkEditor
) editor
).createAnnotatedLine(team
);