From b7bff57a0b04b564c80e4ca172db9837151f8374 Mon Sep 17 00:00:00 2001 From: "n.hoffmann" Date: Tue, 26 Jan 2010 17:48:11 +0000 Subject: [PATCH] fixes #1407 --- .gitattributes | 2 + .../operations/CreateUserOperation.java | 80 +++++++++++++++++++ .../operations/DeleteUserOperation.java | 60 ++++---------- .../operations/EditUserOperation.java | 78 ++++++++++++++++++ .../user/handler/DeleteUserHandler.java | 31 +++---- .../taxeditor/user/view/UserManagerView.java | 36 ++++++++- .../taxeditor/user/wizard/UserWizard.java | 24 +++++- .../taxeditor/user/wizard/UserWizardPage.java | 8 +- 8 files changed, 250 insertions(+), 69 deletions(-) create mode 100644 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/CreateUserOperation.java create mode 100644 taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/EditUserOperation.java diff --git a/.gitattributes b/.gitattributes index 190fe969b..97bdaadd0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -599,6 +599,7 @@ taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/CreateSynonymInN taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/CreateTaxonDescriptionOperation.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/CreateTaxonNodeOperation.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/CreateTaxonomicTreeOperation.java -text +taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/CreateUserOperation.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/DeleteConceptRelationOperation.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/DeleteDescriptionElementOperation.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/DeleteImageOperation.java -text @@ -609,6 +610,7 @@ taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/DeleteTaxonNodeO taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/DeleteTaxonomicTreeOperation.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/DeleteTreeNodeOperation.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/DeleteUserOperation.java -text +taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/EditUserOperation.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/IPostOperationEnabled.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/MoveImageInListOperation.java -text taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/MoveTaxonOperation.java -text diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/CreateUserOperation.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/CreateUserOperation.java new file mode 100644 index 000000000..6ed2c0a2f --- /dev/null +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/CreateUserOperation.java @@ -0,0 +1,80 @@ +// $Id$ +/** +* Copyright (C) 2007 EDIT +* European Distributed Institute of Taxonomy +* http://www.e-taxonomy.eu +* +* The contents of this file are subject to the Mozilla Public License Version 1.1 +* See LICENSE.TXT at the top of this package for the full license terms. +*/ + +package eu.etaxonomy.taxeditor.operations; + +import org.apache.log4j.Logger; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.operations.IUndoContext; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; + +import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; +import eu.etaxonomy.cdm.model.common.User; +import eu.etaxonomy.taxeditor.store.CdmStore; + +/** + * @author n.hoffmann + * @created Jan 19, 2010 + * @version 1.0 + */ +public class CreateUserOperation extends AbstractPersistentPostOperation { + + private static final Logger logger = Logger + .getLogger(CreateUserOperation.class); + + private User user; + + /** + * @param label + * @param undoContext + * @param postOperationEnabled + * @param conversationEnabled + */ + public CreateUserOperation(String label, IUndoContext undoContext, User user, + IPostOperationEnabled postOperationEnabled, + IConversationEnabled conversationEnabled) { + super(label, undoContext, postOperationEnabled, conversationEnabled); + this.user = user; + } + + /* (non-Javadoc) + * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) + */ + @Override + public IStatus execute(IProgressMonitor monitor, IAdaptable info) + throws ExecutionException { + bind(); + CdmStore.getUserService().createUser(user); + + return postExecute(null); + } + + /* (non-Javadoc) + * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) + */ + @Override + public IStatus redo(IProgressMonitor monitor, IAdaptable info) + throws ExecutionException { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) + */ + @Override + public IStatus undo(IProgressMonitor monitor, IAdaptable info) + throws ExecutionException { + // TODO Auto-generated method stub + return null; + } +} diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/DeleteUserOperation.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/DeleteUserOperation.java index 0f3f39b72..837acc385 100644 --- a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/DeleteUserOperation.java +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/DeleteUserOperation.java @@ -10,8 +10,6 @@ package eu.etaxonomy.taxeditor.operations; -import java.util.UUID; - import org.apache.log4j.Logger; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.commands.operations.IUndoContext; @@ -19,7 +17,7 @@ import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; -import eu.etaxonomy.cdm.api.conversation.ConversationHolder; +import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; import eu.etaxonomy.cdm.model.common.User; import eu.etaxonomy.taxeditor.store.CdmStore; import eu.etaxonomy.taxeditor.store.StoreUtil; @@ -29,13 +27,10 @@ import eu.etaxonomy.taxeditor.store.StoreUtil; * @created 02.07.2009 * @version 1.0 */ -public class DeleteUserOperation extends AbstractPostOperation { +public class DeleteUserOperation extends AbstractPersistentPostOperation { private static final Logger logger = Logger .getLogger(DeleteUserOperation.class); - - private UUID userUuid; - private User user; /** @@ -45,10 +40,9 @@ public class DeleteUserOperation extends AbstractPostOperation { * @param postOperationEnabled */ public DeleteUserOperation(String label, IUndoContext undoContext, - UUID userUuid, IPostOperationEnabled postOperationEnabled) { - super(label, undoContext, postOperationEnabled); - - this.userUuid = userUuid; + User user, IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled) { + super(label, undoContext, postOperationEnabled, conversationEnabled); + this.user = user; } /* (non-Javadoc) @@ -57,38 +51,25 @@ public class DeleteUserOperation extends AbstractPostOperation { @Override public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - // Start the main progress monitor. - IProgressMonitor newMonitor = StoreUtil.startMainMonitor(monitor,"Deleting User", 4); + IProgressMonitor newMonitor = StoreUtil.startMainMonitor(monitor,getLabel(), 4); // Do one step - newMonitor.worked(1); + newMonitor.worked(2); try { // Operation steps - - ConversationHolder conversation = CdmStore.NewTransactionalConversation(); - try{ - user = CdmStore.getUserService().find(userUuid); - StoreUtil.isCanceled(newMonitor, 1); - - CdmStore.getUserService().delete(user); - StoreUtil.isCanceled(newMonitor, 1); - - conversation.commit(); - StoreUtil.isCanceled(newMonitor, 1); - - return postExecute(null); - }finally{ - conversation.close(); - } + bind(); + StoreUtil.isCanceled(newMonitor, 1); + + CdmStore.getUserService().delete(user); + StoreUtil.isCanceled(newMonitor, 1); } finally { - // Stop the progress monitor. newMonitor.done(); } - + return postExecute(null); } /* (non-Javadoc) @@ -97,7 +78,6 @@ public class DeleteUserOperation extends AbstractPostOperation { @Override public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - return execute(monitor, info); } @@ -107,16 +87,8 @@ public class DeleteUserOperation extends AbstractPostOperation { @Override public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - - ConversationHolder conversation = CdmStore.NewTransactionalConversation(); - try{ - // store uuid for consecutive undo/redo steps - userUuid = CdmStore.getUserService().save(user); - conversation.commit(); - - return postExecute(null); - }finally{ - conversation.close(); - } + bind(); + CdmStore.getUserService().createUser(user); + return postExecute(null); } } diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/EditUserOperation.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/EditUserOperation.java new file mode 100644 index 000000000..87bfec7d6 --- /dev/null +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/operations/EditUserOperation.java @@ -0,0 +1,78 @@ +// $Id$ +/** +* Copyright (C) 2007 EDIT +* European Distributed Institute of Taxonomy +* http://www.e-taxonomy.eu +* +* The contents of this file are subject to the Mozilla Public License Version 1.1 +* See LICENSE.TXT at the top of this package for the full license terms. +*/ + +package eu.etaxonomy.taxeditor.operations; + +import org.apache.log4j.Logger; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.operations.IUndoContext; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; + +import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; +import eu.etaxonomy.cdm.model.common.User; +import eu.etaxonomy.taxeditor.store.CdmStore; + +/** + * @author n.hoffmann + * @created Jan 25, 2010 + * @version 1.0 + */ +public class EditUserOperation extends AbstractPersistentPostOperation { + private static final Logger logger = Logger + .getLogger(EditUserOperation.class); + + private User user; + + /** + * @param label + * @param undoContext + * @param postOperationEnabled + * @param conversationEnabled + */ + public EditUserOperation(String label, IUndoContext undoContext, User user, + IPostOperationEnabled postOperationEnabled, + IConversationEnabled conversationEnabled) { + super(label, undoContext, postOperationEnabled, conversationEnabled); + this.user = user; + } + + /* (non-Javadoc) + * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) + */ + @Override + public IStatus execute(IProgressMonitor monitor, IAdaptable info) + throws ExecutionException { + bind(); + CdmStore.getUserService().updateUser(user); + return postExecute(null); + } + + /* (non-Javadoc) + * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) + */ + @Override + public IStatus redo(IProgressMonitor monitor, IAdaptable info) + throws ExecutionException { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) + */ + @Override + public IStatus undo(IProgressMonitor monitor, IAdaptable info) + throws ExecutionException { + // TODO Auto-generated method stub + return null; + } +} diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/user/handler/DeleteUserHandler.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/user/handler/DeleteUserHandler.java index 26a7e2cc6..3a2c826d1 100644 --- a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/user/handler/DeleteUserHandler.java +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/user/handler/DeleteUserHandler.java @@ -16,14 +16,13 @@ import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.commands.common.NotDefinedException; import org.eclipse.core.commands.operations.IUndoableOperation; -import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.ui.handlers.HandlerUtil; import eu.etaxonomy.cdm.model.common.User; import eu.etaxonomy.taxeditor.operations.DeleteUserOperation; -import eu.etaxonomy.taxeditor.operations.IPostOperationEnabled; import eu.etaxonomy.taxeditor.store.StoreUtil; +import eu.etaxonomy.taxeditor.user.view.UserManagerView; /** * @author n.hoffmann @@ -39,20 +38,24 @@ public class DeleteUserHandler extends AbstractHandler { */ public Object execute(ExecutionEvent event) throws ExecutionException { - ISelection menuSelection = HandlerUtil.getActiveMenuSelection(event); - User user = (User) ((StructuredSelection) menuSelection).getFirstElement(); - - // TODO refresh the list -> set postOperationEnabled to the real deal - IPostOperationEnabled postOperationEnabled = (IPostOperationEnabled) HandlerUtil.getActivePart(event); + StructuredSelection menuSelection = (StructuredSelection) HandlerUtil.getActiveMenuSelection(event); + + for (Object object : menuSelection.toArray()){ - IUndoableOperation operation = null; - try { - operation = new DeleteUserOperation(event.getCommand().getName(), - StoreUtil.getUndoContext(), user.getUuid(), postOperationEnabled); + User user = (User) object; + + // TODO refresh the list -> set postOperationEnabled to the real deal + UserManagerView userManagerView = (UserManagerView) HandlerUtil.getActivePart(event); - StoreUtil.executeOperation(operation); - } catch (NotDefinedException e) { - logger.warn("Command name not set"); + IUndoableOperation operation = null; + try { + operation = new DeleteUserOperation(event.getCommand().getName(), + StoreUtil.getUndoContext(), user, userManagerView, userManagerView); + + StoreUtil.executeOperation(operation); + } catch (NotDefinedException e) { + logger.warn("Command name not set"); + } } return null; diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/user/view/UserManagerView.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/user/view/UserManagerView.java index aff4d3db7..e51551bb7 100644 --- a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/user/view/UserManagerView.java +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/user/view/UserManagerView.java @@ -17,6 +17,8 @@ import org.eclipse.jface.action.GroupMarker; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.viewers.ListViewer; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.FocusAdapter; +import org.eclipse.swt.events.FocusEvent; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; @@ -76,6 +78,32 @@ public class UserManagerView extends ViewPart implements IConversationEnabled, I listViewer.setLabelProvider(new UserManagerLabelProvider()); listViewer.setInput(getAllUser()); + +// listViewer.addDoubleClickListener(new IDoubleClickListener() { +// +// public void doubleClick(DoubleClickEvent event) { +// if (event.getSelection() instanceof StructuredSelection) { +// +// Object element = ((StructuredSelection) event +// .getSelection()).getFirstElement(); +// if (element instanceof User) { +// handler = new EditUserHandler(); +// } +// } +// } +// }); + + this.addListenerObject(new FocusAdapter() { + /* (non-Javadoc) + * @see org.eclipse.swt.events.FocusAdapter#focusGained(org.eclipse.swt.events.FocusEvent) + */ + @Override + public void focusGained(FocusEvent e) { + super.focusGained(e); + conversation.bind(); + listViewer.getControl().setFocus(); + } + }); } /* (non-Javadoc) @@ -87,11 +115,15 @@ public class UserManagerView extends ViewPart implements IConversationEnabled, I listViewer.getControl().setFocus(); } + + /* (non-Javadoc) * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase) */ public boolean postOperation(CdmBase objectAffectedByOperation) { - listViewer.setInput(getAllUser()); + List allUsers = getAllUser(); + + listViewer.setInput(allUsers); listViewer.refresh(); return true; @@ -102,7 +134,7 @@ public class UserManagerView extends ViewPart implements IConversationEnabled, I * @return */ private List getAllUser(){ - return CdmStore.getUserService().list(null, 100000, 0, null, null); + return CdmStore.getUserService().list(null, null, null, null, null); } /* (non-Javadoc) diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/user/wizard/UserWizard.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/user/wizard/UserWizard.java index 9041b2170..fb244985d 100644 --- a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/user/wizard/UserWizard.java +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/user/wizard/UserWizard.java @@ -11,10 +11,14 @@ package eu.etaxonomy.taxeditor.user.wizard; import org.apache.log4j.Logger; +import org.eclipse.core.commands.operations.IUndoableOperation; +import org.eclipse.core.runtime.Status; import org.eclipse.jface.wizard.Wizard; import eu.etaxonomy.cdm.model.common.User; -import eu.etaxonomy.taxeditor.store.CdmStore; +import eu.etaxonomy.taxeditor.operations.CreateUserOperation; +import eu.etaxonomy.taxeditor.operations.EditUserOperation; +import eu.etaxonomy.taxeditor.store.StoreUtil; import eu.etaxonomy.taxeditor.user.view.UserManagerView; /** @@ -27,15 +31,20 @@ public class UserWizard extends Wizard { private User user; private UserWizardPage page; private UserManagerView view; + private boolean createMode; public UserWizard(UserManagerView view){ this.view = view; setWindowTitle("User Wizard"); + createMode = true; } public UserWizard(UserManagerView view, User user){ this(view); - this.user = user; + if(user != null){ + this.user = user; + createMode = false; + } } /* (non-Javadoc) @@ -57,9 +66,16 @@ public class UserWizard extends Wizard { @Override public boolean performFinish() { - CdmStore.getUserService().save(page.getUser()); + IUndoableOperation operation; + if(createMode){ + operation = new CreateUserOperation("Create User", + StoreUtil.getUndoContext(), page.getUser(), view, view); + }else{ + operation = new EditUserOperation("Edit User", + StoreUtil.getUndoContext(), page.getUser(), view, view); + } - return view.postOperation(user); + return StoreUtil.executeOperation(operation) == Status.OK_STATUS ? true : false; } } diff --git a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/user/wizard/UserWizardPage.java b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/user/wizard/UserWizardPage.java index 1536b3bc5..b45354668 100644 --- a/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/user/wizard/UserWizardPage.java +++ b/taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/user/wizard/UserWizardPage.java @@ -22,7 +22,6 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Text; -import org.springframework.security.userdetails.UsernameNotFoundException; import eu.etaxonomy.cdm.model.agent.Person; import eu.etaxonomy.cdm.model.common.User; @@ -36,7 +35,7 @@ import eu.etaxonomy.taxeditor.store.CdmStore; */ public class UserWizardPage extends WizardPage implements ModifyListener{ - private static final Logger logger = Logger.getLogger(UserWizardPage.class); +// private static final Logger logger = Logger.getLogger(UserWizardPage.class); public static final String NAME = "USER_WIZARD_PAGE"; @@ -246,11 +245,10 @@ public class UserWizardPage extends WizardPage implements ModifyListener{ setPageComplete(false); return NAME_TO_SHORT; } - try{ - CdmStore.getUserService().loadUserByUsername(newText); + if(CdmStore.getUserService().userExists(newText)){ setPageComplete(false); return USER_EXISTS; - }catch (UsernameNotFoundException e){} + } setPageComplete(true); return null; -- 2.34.1