diff options
author | Christian W. Damus | 2013-10-08 21:51:24 +0000 |
---|---|---|
committer | Christian W. Damus | 2013-10-10 18:08:56 +0000 |
commit | 29c5b9a763f33d530d808c9e730d314375219714 (patch) | |
tree | 65756ddd1974690e6111177a39a4ca0701f55986 | |
parent | dbbcef97d7e7de903d936447dac0764bd5ba225c (diff) | |
download | cdo-29c5b9a763f33d530d808c9e730d314375219714.tar.gz cdo-29c5b9a763f33d530d808c9e730d314375219714.tar.xz cdo-29c5b9a763f33d530d808c9e730d314375219714.zip |
[418452] [Security] Simplified security model editor
https://bugs.eclipse.org/bugs/show_bug.cgi?id=418452
Browse button for selecting a resource in the filter details.
4 files changed, 226 insertions, 5 deletions
diff --git a/plugins/org.eclipse.emf.cdo.security.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.security.ui/META-INF/MANIFEST.MF index 01f5a1a994..19c8ac1bfd 100644 --- a/plugins/org.eclipse.emf.cdo.security.ui/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.emf.cdo.security.ui/META-INF/MANIFEST.MF @@ -17,6 +17,7 @@ Require-Bundle: org.eclipse.emf.cdo.security;bundle-version="[4.3.0,5.0.0)", Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.emf.cdo.internal.security.ui.actions;version="1.0.0";x-internal:=true, org.eclipse.emf.cdo.internal.security.ui.bundle;version="1.0.0";x-internal:=true, + org.eclipse.emf.cdo.internal.security.ui.dialogs;version="1.0.0";x-internal:=true, org.eclipse.emf.cdo.internal.security.ui.editor;version="1.0.0";x-internal:=true, org.eclipse.emf.cdo.internal.security.ui.messages;version="1.0.0";x-internal:=true, org.eclipse.emf.cdo.internal.security.ui.util;version="1.0.0";x-internal:=true diff --git a/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/internal/security/ui/dialogs/FilterTreeSelectionDialog.java b/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/internal/security/ui/dialogs/FilterTreeSelectionDialog.java new file mode 100644 index 0000000000..8448c5e412 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/internal/security/ui/dialogs/FilterTreeSelectionDialog.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2004-2013 Eike Stepper (Berlin, Germany), CEA LIST, and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Christian W. Damus (CEA LIST) - initial API and implementation + */ +package org.eclipse.emf.cdo.internal.security.ui.dialogs; + +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.dialogs.ElementTreeSelectionDialog; +import org.eclipse.ui.dialogs.FilteredTree; +import org.eclipse.ui.dialogs.PatternFilter; + +/** + * A tree selection dialog that offers the user a filter field. + */ +public class FilterTreeSelectionDialog extends ElementTreeSelectionDialog +{ + + private PatternFilter filter = new PatternFilter(); + + public FilterTreeSelectionDialog(Shell parent, ILabelProvider labelProvider, ITreeContentProvider contentProvider) + { + super(parent, labelProvider, contentProvider); + } + + @Override + protected TreeViewer doCreateTreeViewer(Composite parent, int style) + { + FilteredTree tree = new FilteredTree(parent, style, filter, true); + tree.setLayoutData(new GridData(GridData.FILL_BOTH)); + tree.setQuickSelectionMode(false); + + applyDialogFont(tree); + + return tree.getViewer(); + } + +} diff --git a/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/internal/security/ui/editor/RoleDetailsPage.java b/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/internal/security/ui/editor/RoleDetailsPage.java index 152bd21b90..7afbd51573 100644 --- a/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/internal/security/ui/editor/RoleDetailsPage.java +++ b/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/internal/security/ui/editor/RoleDetailsPage.java @@ -10,7 +10,14 @@ */ package org.eclipse.emf.cdo.internal.security.ui.editor; +import static org.eclipse.emf.cdo.internal.security.ui.util.SecurityModelUtil.getTypeFilter; +import static org.eclipse.emf.cdo.internal.security.ui.util.SecurityModelUtil.viewerFilter; + +import org.eclipse.emf.cdo.eresource.CDOResourceNode; +import org.eclipse.emf.cdo.eresource.EresourcePackage; +import org.eclipse.emf.cdo.internal.security.ui.dialogs.FilterTreeSelectionDialog; import org.eclipse.emf.cdo.internal.security.ui.messages.Messages; +import org.eclipse.emf.cdo.internal.security.ui.util.EditableDialogCellEditor; import org.eclipse.emf.cdo.internal.security.ui.util.INewObjectConfigurator; import org.eclipse.emf.cdo.internal.security.ui.util.OneToManyTableBlock; import org.eclipse.emf.cdo.internal.security.ui.util.ResourceBasedPermissionFilter; @@ -22,8 +29,11 @@ import org.eclipse.emf.cdo.security.Role; import org.eclipse.emf.cdo.security.SecurityFactory; import org.eclipse.emf.cdo.security.SecurityPackage; import org.eclipse.emf.cdo.security.provider.SecurityEditPlugin; +import org.eclipse.emf.cdo.ui.CDOItemProvider; +import org.eclipse.emf.cdo.view.CDOView; import org.eclipse.net4j.util.ObjectUtil; +import org.eclipse.net4j.util.container.IContainer; import org.eclipse.emf.common.command.Command; import org.eclipse.emf.common.notify.AdapterFactory; @@ -39,9 +49,10 @@ import org.eclipse.jface.viewers.CellLabelProvider; import org.eclipse.jface.viewers.ColumnLabelProvider; import org.eclipse.jface.viewers.ComboBoxViewerCellEditor; import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.TextCellEditor; +import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; import org.eclipse.ui.forms.widgets.FormToolkit; import java.util.Collections; @@ -71,9 +82,11 @@ public class RoleDetailsPage extends AbstractDetailsPage<Role> space(parent, toolkit); - oneToMany(parent, toolkit, Messages.RoleDetailsPage_2, SecurityPackage.Literals.ROLE__ASSIGNEES, SecurityPackage.Literals.GROUP); + oneToMany(parent, toolkit, Messages.RoleDetailsPage_2, SecurityPackage.Literals.ROLE__ASSIGNEES, + SecurityPackage.Literals.GROUP); - oneToMany(parent, toolkit, Messages.RoleDetailsPage_3, SecurityPackage.Literals.ROLE__ASSIGNEES, SecurityPackage.Literals.USER); + oneToMany(parent, toolkit, Messages.RoleDetailsPage_3, SecurityPackage.Literals.ROLE__ASSIGNEES, + SecurityPackage.Literals.USER); } protected INewObjectConfigurator createNewPermissionConfigurator() @@ -104,7 +117,8 @@ public class RoleDetailsPage extends AbstractDetailsPage<Role> private static final int COL_PATH = 2; - private final String[] columnTitles = { Messages.RoleDetailsPage_5, Messages.RoleDetailsPage_6, Messages.RoleDetailsPage_7 }; + private final String[] columnTitles = { Messages.RoleDetailsPage_5, Messages.RoleDetailsPage_6, + Messages.RoleDetailsPage_7 }; private final CellEditor[] cellEditors = new CellEditor[3]; @@ -293,7 +307,77 @@ public class RoleDetailsPage extends AbstractDetailsPage<Role> return result; } case COL_PATH: - return new TextCellEditor(parent); + return new EditableDialogCellEditor(parent) + { + + @Override + protected Object openDialogBox(Control cellEditorWindow) + { + final CDOView view = getInput().cdoView(); + @SuppressWarnings({ "rawtypes", "unchecked" }) + CDOItemProvider provider = new CDOItemProvider(null) + { + private boolean connected; + + { + // connect the input now, because the dialog will try to access the content provider before it has + // been set into the tree viewer + connectInput((IContainer)view); + } + + @Override + protected void connectInput(IContainer<Object> input) + { + if (!connected) + { + super.connectInput(input); + connected = true; + } + } + + @Override + protected void disconnectInput(IContainer<Object> input) + { + if (connected) + { + connected = false; + super.disconnectInput(input); + } + } + }; + + FilterTreeSelectionDialog dlg = new FilterTreeSelectionDialog(cellEditorWindow.getShell(), provider, + provider); + + dlg.setAllowMultiple(false); + dlg.setMessage("Choose a resource node to which to grant access."); + dlg.setTitle("Browse Resources"); + dlg.setDoubleClickSelects(true); + dlg.addFilter(viewerFilter(getTypeFilter(EresourcePackage.Literals.CDO_RESOURCE_NODE))); + dlg.setBlockOnOpen(true); + + String current = (String)getValue(); + + dlg.setInput(view); + if (current != null && view.hasResource(current)) + { + dlg.setInitialSelection(view.getResourceNode(current)); + } + + String result = null; + + if (dlg.open() == Window.OK) + { + CDOResourceNode node = (CDOResourceNode)dlg.getFirstResult(); + if (node != null) + { + result = node.getPath(); + } + } + + return result; + } + }; default: throw new IllegalArgumentException("columnIndex"); //$NON-NLS-1$ } diff --git a/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/internal/security/ui/util/EditableDialogCellEditor.java b/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/internal/security/ui/util/EditableDialogCellEditor.java new file mode 100644 index 0000000000..c5005c7381 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.security.ui/src/org/eclipse/emf/cdo/internal/security/ui/util/EditableDialogCellEditor.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2004-2013 Eike Stepper (Berlin, Germany), CEA LIST, and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Christian W. Damus (CEA LIST) - initial API and implementation + */ +package org.eclipse.emf.cdo.internal.security.ui.util; + +import org.eclipse.jface.viewers.DialogCellEditor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Text; + +import java.text.MessageFormat; + +/** + * A dialog cell editor in which the text field is editable: the user can directly edit the value without opening the dialog. + */ +public abstract class EditableDialogCellEditor extends DialogCellEditor +{ + + private Text text; + + public EditableDialogCellEditor() + { + } + + public EditableDialogCellEditor(Composite parent) + { + super(parent); + } + + public EditableDialogCellEditor(Composite parent, int style) + { + super(parent, style); + } + + @Override + protected Control createContents(Composite cell) + { + text = new Text(cell, SWT.SINGLE); + text.setFont(cell.getFont()); + text.setBackground(cell.getBackground()); + + text.addSelectionListener(new SelectionAdapter() + { + @Override + public void widgetDefaultSelected(SelectionEvent e) + { + String newValue = text.getText(); + + if (isCorrect(newValue)) + { + markDirty(); + doSetValue(newValue); + } + else + { + setErrorMessage(MessageFormat.format(getErrorMessage(), new Object[] { newValue.toString() })); + } + fireApplyEditorValue(); + deactivate(); + } + }); + + return text; + } + + @Override + protected void updateContents(Object value) + { + text.setText(value == null ? "" : value.toString()); //$NON-NLS-1$ + } + + @Override + public void setFocus() + { + text.setFocus(); + } + +} |