diff options
author | Christian W. Damus | 2013-10-10 19:33:38 +0000 |
---|---|---|
committer | Christian W. Damus | 2013-10-10 19:33:38 +0000 |
commit | 022e354b2a93624a8046710a79e1b1c75525d3e2 (patch) | |
tree | 585d2581c0eaa1dfa83d146165a415a648c7aded | |
parent | 275bb45e4d929b5415327ddd5cc8c8fada8069b7 (diff) | |
download | cdo-022e354b2a93624a8046710a79e1b1c75525d3e2.tar.gz cdo-022e354b2a93624a8046710a79e1b1c75525d3e2.tar.xz cdo-022e354b2a93624a8046710a79e1b1c75525d3e2.zip |
[418452] [Security] Simplified security model editor
https://bugs.eclipse.org/bugs/show_bug.cgi?id=418452
Implement support for drag-and-drop between the master table sections on the left-hand side.
4 files changed, 140 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/internal/security/ui/editor/GroupsSection.java b/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/internal/security/ui/editor/GroupsSection.java index 671fe1a2d5..a6d831bc67 100644 --- a/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/internal/security/ui/editor/GroupsSection.java +++ b/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/internal/security/ui/editor/GroupsSection.java @@ -12,9 +12,13 @@ package org.eclipse.emf.cdo.internal.security.ui.editor; import org.eclipse.emf.cdo.internal.security.ui.messages.Messages; import org.eclipse.emf.cdo.security.Group; +import org.eclipse.emf.cdo.security.Role; import org.eclipse.emf.cdo.security.SecurityPackage; +import org.eclipse.emf.cdo.security.User; import org.eclipse.emf.common.notify.AdapterFactory; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EReference; import org.eclipse.emf.edit.domain.EditingDomain; /** @@ -34,4 +38,20 @@ public class GroupsSection extends TableSection<Group> return Messages.GroupsSection_0; } + @Override + protected EReference getDropReference(EObject target, EObject objectToDrop) + { + EReference result = null; + + if (objectToDrop instanceof User) + { + result = SecurityPackage.Literals.GROUP__USERS; + } + else if (objectToDrop instanceof Role) + { + result = SecurityPackage.Literals.ASSIGNEE__ROLES; + } + + return result; + } } diff --git a/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/internal/security/ui/editor/RolesSection.java b/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/internal/security/ui/editor/RolesSection.java index d2997d46e6..3bbd8f1b52 100644 --- a/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/internal/security/ui/editor/RolesSection.java +++ b/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/internal/security/ui/editor/RolesSection.java @@ -11,10 +11,13 @@ package org.eclipse.emf.cdo.internal.security.ui.editor; import org.eclipse.emf.cdo.internal.security.ui.messages.Messages; +import org.eclipse.emf.cdo.security.Assignee; import org.eclipse.emf.cdo.security.Role; import org.eclipse.emf.cdo.security.SecurityPackage; import org.eclipse.emf.common.notify.AdapterFactory; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EReference; import org.eclipse.emf.edit.domain.EditingDomain; /** @@ -33,4 +36,17 @@ public class RolesSection extends TableSection<Role> { return Messages.RolesSection_0; } + + @Override + protected EReference getDropReference(EObject target, EObject objectToDrop) + { + EReference result = null; + + if (objectToDrop instanceof Assignee) + { + result = SecurityPackage.Literals.ROLE__ASSIGNEES; + } + + return result; + } } diff --git a/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/internal/security/ui/editor/TableSection.java b/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/internal/security/ui/editor/TableSection.java index d3b1fffa48..953d781416 100644 --- a/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/internal/security/ui/editor/TableSection.java +++ b/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/internal/security/ui/editor/TableSection.java @@ -22,12 +22,16 @@ import org.eclipse.emf.cdo.security.SecurityFactory; import org.eclipse.emf.cdo.security.SecurityPackage; import org.eclipse.emf.cdo.ui.shared.SharedIcons; +import org.eclipse.net4j.util.ui.UIUtil; + import org.eclipse.emf.common.command.Command; import org.eclipse.emf.common.notify.AdapterFactory; import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EClassifier; import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EReference; import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.emf.edit.command.AddCommand; import org.eclipse.emf.edit.command.CommandActionDelegate; import org.eclipse.emf.edit.command.CommandParameter; import org.eclipse.emf.edit.command.CreateChildCommand; @@ -51,12 +55,14 @@ import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.StructuredViewer; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerDropAdapter; import org.eclipse.jface.viewers.ViewerFilter; import org.eclipse.swt.SWT; import org.eclipse.swt.dnd.DND; import org.eclipse.swt.dnd.DragSourceAdapter; import org.eclipse.swt.dnd.DragSourceEvent; import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.dnd.TransferData; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; @@ -105,6 +111,7 @@ public abstract class TableSection<T extends EObject> extends AbstractSectionPar getContext().bindValue(ViewersObservables.observeInput(viewer), getValue()); configureDragSupport(viewer); + configureDropSupport(viewer); } @Override @@ -312,6 +319,83 @@ public abstract class TableSection<T extends EObject> extends AbstractSectionPar }); } + protected void configureDropSupport(final TableViewer viewer) + { + viewer.addDropSupport(DND.DROP_LINK | DND.DROP_MOVE | DND.DROP_COPY, + new Transfer[] { LocalSelectionTransfer.getTransfer() }, new ViewerDropAdapter(viewer) + { + + { + // we don't want it to look like you can insert new elements, only drop onto existing elements + setFeedbackEnabled(false); + } + + @Override + public boolean validateDrop(Object target, int operation, TransferData transferType) + { + boolean result = false; + + if (target instanceof EObject && LocalSelectionTransfer.getTransfer().isSupportedType(transferType)) + { + EObject objectToDrop = getObjectToDrop(transferType); + if (objectToDrop != null) + { + result = getDropReference((EObject)target, objectToDrop) != null; + + if (result && (getCurrentEvent().operations | DND.DROP_COPY) != 0) + { + overrideOperation(DND.DROP_COPY); + } + } + } + + return result; + } + + @Override + public boolean performDrop(Object data) + { + IStructuredSelection selection = (IStructuredSelection)data; + EObject objectToDrop = UIUtil.getElement(selection, EObject.class); + EObject target = (EObject)getCurrentTarget(); + + Command command = AddCommand.create(getEditingDomain(), target, getDropReference(target, objectToDrop), + selection.toList()); + + boolean result = execute(command); + if (result) + { + viewer.getControl().setFocus(); + viewer.setSelection(new StructuredSelection(target)); + } + + return result; + } + + private EObject getObjectToDrop(TransferData transferType) + { + return UIUtil.getElement(LocalSelectionTransfer.getTransfer().getSelection(), EObject.class); + } + }); + } + + protected EReference getDropReference(EObject target, EObject objectToDrop) + { + return null; + } + + protected boolean execute(Command command) + { + boolean result = command.canExecute(); + + if (result) + { + getEditingDomain().getCommandStack().execute(command); + } + + return result; + } + protected void checkForUnsupportedModelContent() { if (getInput() == null) diff --git a/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/internal/security/ui/editor/UsersSection.java b/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/internal/security/ui/editor/UsersSection.java index 6c86325e26..e12a7e56d6 100644 --- a/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/internal/security/ui/editor/UsersSection.java +++ b/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/internal/security/ui/editor/UsersSection.java @@ -11,10 +11,14 @@ package org.eclipse.emf.cdo.internal.security.ui.editor; import org.eclipse.emf.cdo.internal.security.ui.messages.Messages; +import org.eclipse.emf.cdo.security.Group; +import org.eclipse.emf.cdo.security.Role; import org.eclipse.emf.cdo.security.SecurityPackage; import org.eclipse.emf.cdo.security.User; import org.eclipse.emf.common.notify.AdapterFactory; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EReference; import org.eclipse.emf.edit.domain.EditingDomain; /** @@ -34,4 +38,20 @@ public class UsersSection extends TableSection<User> return Messages.UsersSection_0; } + @Override + protected EReference getDropReference(EObject target, EObject objectToDrop) + { + EReference result = null; + + if (objectToDrop instanceof Group) + { + result = SecurityPackage.Literals.USER__GROUPS; + } + else if (objectToDrop instanceof Role) + { + result = SecurityPackage.Literals.ASSIGNEE__ROLES; + } + + return result; + } } |