diff options
author | Eike Stepper | 2013-09-21 10:56:07 +0000 |
---|---|---|
committer | Eike Stepper | 2013-09-21 10:56:07 +0000 |
commit | 3a5aed9500d5fc42cbbc2b8764e41398c7ded662 (patch) | |
tree | d0cd8edb3e4d42f5b74074ae2d5bc66074ef3148 | |
parent | 7f95531eae2cbbedab4464f2b27f4c0e365ef2da (diff) | |
download | cdo-3a5aed9500d5fc42cbbc2b8764e41398c7ded662.tar.gz cdo-3a5aed9500d5fc42cbbc2b8764e41398c7ded662.tar.xz cdo-3a5aed9500d5fc42cbbc2b8764e41398c7ded662.zip |
[417747] [UI] Make the CDO Sessions view security-aware
https://bugs.eclipse.org/bugs/show_bug.cgi?id=417747
11 files changed, 463 insertions, 29 deletions
diff --git a/plugins/org.eclipse.emf.cdo.ui/.settings/org.eclipse.pde.prefs b/plugins/org.eclipse.emf.cdo.ui/.settings/org.eclipse.pde.prefs index fe01bb701d..494f76278b 100644 --- a/plugins/org.eclipse.emf.cdo.ui/.settings/org.eclipse.pde.prefs +++ b/plugins/org.eclipse.emf.cdo.ui/.settings/org.eclipse.pde.prefs @@ -1,9 +1,10 @@ -#Thu Feb 04 09:44:24 CET 2010 compilers.f.unresolved-features=1 compilers.f.unresolved-plugins=1 compilers.incompatible-environment=1 compilers.p.build=1 compilers.p.build.bin.includes=1 +compilers.p.build.encodings=2 +compilers.p.build.java.compiler=2 compilers.p.build.java.compliance=1 compilers.p.build.missing.output=2 compilers.p.build.output.library=1 @@ -20,7 +21,7 @@ compilers.p.no-required-att=0 compilers.p.not-externalized-att=2 compilers.p.unknown-attribute=1 compilers.p.unknown-class=1 -compilers.p.unknown-element=1 +compilers.p.unknown-element=2 compilers.p.unknown-identifier=1 compilers.p.unknown-resource=1 compilers.p.unresolved-ex-points=0 diff --git a/plugins/org.eclipse.emf.cdo.ui/plugin.xml b/plugins/org.eclipse.emf.cdo.ui/plugin.xml index 5018100999..497886714e 100644 --- a/plugins/org.eclipse.emf.cdo.ui/plugin.xml +++ b/plugins/org.eclipse.emf.cdo.ui/plugin.xml @@ -153,11 +153,19 @@ adaptableType="org.eclipse.emf.cdo.session.CDOSession" class="org.eclipse.emf.cdo.internal.ui.CDOPropertyAdapterFactory"> <adapter type="org.eclipse.ui.views.properties.IPropertySourceProvider"/> + <adapter type="org.eclipse.ui.IActionFilter"/> </factory> <factory adaptableType="org.eclipse.emf.cdo.view.CDOView" class="org.eclipse.emf.cdo.internal.ui.CDOPropertyAdapterFactory"> <adapter type="org.eclipse.ui.views.properties.IPropertySourceProvider"/> + <adapter type="org.eclipse.ui.IActionFilter"/> + </factory> + <factory + adaptableType="org.eclipse.emf.ecore.EObject" + class="org.eclipse.emf.cdo.internal.ui.CDOPropertyAdapterFactory"> + <adapter type="org.eclipse.ui.views.properties.IPropertySourceProvider"/> + <adapter type="org.eclipse.ui.IActionFilter"/> </factory> </extension> @@ -184,7 +192,7 @@ point="org.eclipse.ui.popupMenus"> <objectContribution adaptable="true" - id="org.eclipse.emf.cdo.ui.CDOResourceNodeContributions" + id="org.eclipse.emf.cdo.ui.CDOResourceNodeContributionsWritableContainer" objectClass="org.eclipse.emf.cdo.eresource.CDOResourceNode"> <action class="org.eclipse.emf.cdo.internal.ui.actions.RemoveResourceActionDelegate" @@ -193,25 +201,29 @@ label="%action.label.2" tooltip="%action.tooltip.1"> </action> + <enablement> + <test property="org.eclipse.emf.cdo.object.writableContainer" value="true"/> + </enablement> + </objectContribution> + <objectContribution + adaptable="true" + id="org.eclipse.emf.cdo.ui.CDOResourceNodeContributionsWritable" + objectClass="org.eclipse.emf.cdo.eresource.CDOResourceNode"> <action class="org.eclipse.emf.cdo.internal.ui.actions.RenameResourceActionDelegate" id="org.eclipse.emf.cdo.ui.RenameResource" label="%action.label.13" tooltip="%action.tooltip.11"> </action> + <enablement> + <test property="org.eclipse.emf.cdo.object.writable" value="true"/> + </enablement> </objectContribution> <objectContribution adaptable="true" - id="org.eclipse.emf.cdo.ui.CDOResourceFolderContributions" + id="org.eclipse.emf.cdo.ui.CDOResourceFolderContributionsWritable" objectClass="org.eclipse.emf.cdo.eresource.CDOResourceFolder"> <action - class="org.eclipse.emf.cdo.internal.ui.actions.ImportResourceActionDelegate" - icon="icons/full/elcl16/import_wiz.gif" - id="org.eclipse.emf.cdo.ui.ImportResource" - label="%action.label.9" - tooltip="%action.tooltip.8"> - </action> - <action class="org.eclipse.emf.cdo.internal.ui.actions.NewBinaryResourceActionDelegate" icon="icons/full/elcl16/NewCDOBinaryResource.gif" id="org.eclipse.emf.cdo.ui.NewBinaryResource" @@ -239,10 +251,13 @@ label="%action.label.4" tooltip="%action.tooltip.3"> </action> + <enablement> + <test property="org.eclipse.emf.cdo.object.writable" value="true"/> + </enablement> </objectContribution> <objectContribution adaptable="false" - id="org.eclipse.emf.cdo.ui.CDOResourceActionContribution" + id="org.eclipse.emf.cdo.ui.CDOResourceActionContributionReadable" objectClass="org.eclipse.emf.cdo.eresource.CDOResource"> <action class="org.eclipse.emf.cdo.internal.ui.actions.ExportResourceActionDelegate" @@ -251,6 +266,9 @@ label="%action.label.10" tooltip="%action.tooltip.14"> </action> + <enablement> + <test property="org.eclipse.emf.cdo.object.readable" value="true"/> + </enablement> </objectContribution> </extension> diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/CDOPropertyAdapterFactory.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/CDOPropertyAdapterFactory.java index 58ca34141f..dd89c0b05e 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/CDOPropertyAdapterFactory.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/CDOPropertyAdapterFactory.java @@ -13,12 +13,17 @@ package org.eclipse.emf.cdo.internal.ui; import org.eclipse.emf.cdo.session.CDOSession; import org.eclipse.emf.cdo.view.CDOView; +import org.eclipse.emf.internal.cdo.object.ObjectProperties; import org.eclipse.emf.internal.cdo.session.SessionProperties; import org.eclipse.emf.internal.cdo.view.ViewProperties; import org.eclipse.net4j.util.ui.AbstractPropertyAdapterFactory; +import org.eclipse.net4j.util.ui.DefaultActionFilter; import org.eclipse.net4j.util.ui.DefaultPropertySource; +import org.eclipse.emf.ecore.EObject; + +import org.eclipse.ui.IActionFilter; import org.eclipse.ui.views.properties.IPropertySource; /** @@ -26,6 +31,13 @@ import org.eclipse.ui.views.properties.IPropertySource; */ public class CDOPropertyAdapterFactory extends AbstractPropertyAdapterFactory { + private static final IActionFilter SESSION_ACTION_FILTER = new DefaultActionFilter<CDOSession>( + SessionProperties.INSTANCE); + + private static final IActionFilter VIEW_ACTION_FILTER = new DefaultActionFilter<CDOView>(ViewProperties.INSTANCE); + + private static final IActionFilter OBJECT_ACTION_FILTER = new DefaultActionFilter<EObject>(ObjectProperties.INSTANCE); + public CDOPropertyAdapterFactory() { } @@ -43,6 +55,32 @@ public class CDOPropertyAdapterFactory extends AbstractPropertyAdapterFactory return new DefaultPropertySource<CDOView>((CDOView)object, ViewProperties.INSTANCE); } + if (object instanceof EObject) + { + return new DefaultPropertySource<EObject>((EObject)object, ObjectProperties.INSTANCE); + } + return null; } + + @Override + protected IActionFilter createActionFilter(Object object) + { + if (object instanceof CDOSession) + { + return SESSION_ACTION_FILTER; + } + + if (object instanceof CDOView) + { + return VIEW_ACTION_FILTER; + } + + if (object instanceof EObject) + { + return OBJECT_ACTION_FILTER; + } + + return super.createActionFilter(object); + } } diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java index fbc9bc2f41..ab2456f94f 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOEditor.java @@ -1163,7 +1163,7 @@ public class CDOEditor extends MultiPageEditorPart implements IEditingDomainProv Composite composite = UIUtil.createGridComposite(getContainer(), 1); composite.setLayoutData(UIUtil.createGridData()); composite.setLayout(UIUtil.createGridLayout(1)); - Tree tree = new Tree(composite, SWT.MULTI | SWT.BORDER); + Tree tree = new Tree(composite, SWT.MULTI); tree.setLayoutData(UIUtil.createGridData()); final Set<CDOID> expandedIDs = new HashSet<CDOID>(); diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOSessionsView.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOSessionsView.java index e5568649e0..e6cad5dcb7 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOSessionsView.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOSessionsView.java @@ -95,6 +95,16 @@ public class CDOSessionsView extends ContainerView { IWorkbenchPage page = getSite().getPage(); + if (object instanceof CDOSession) + { + CDOSession session = (CDOSession)object; + if (session.getViews().length == 0) + { + session.openTransaction(); + return; + } + } + if (object instanceof CDOResourceLeaf) { CDOResourceLeaf resource = (CDOResourceLeaf)object; @@ -111,11 +121,11 @@ public class CDOSessionsView extends ContainerView { CDOEditorUtil.openEditor(page, resource); } + + return; } - else - { - super.doubleClicked(object); - } + + super.doubleClicked(object); } public static ResourceOpener registerResourceOpener(String resourceExtension, ResourceOpener opener) diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOItemProvider.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOItemProvider.java index 8b5d50d155..ed2f1e62f6 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOItemProvider.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOItemProvider.java @@ -17,6 +17,7 @@ import org.eclipse.emf.cdo.common.branch.CDOBranchManager; import org.eclipse.emf.cdo.common.model.CDOPackageRegistry; import org.eclipse.emf.cdo.common.model.CDOPackageTypeRegistry; import org.eclipse.emf.cdo.common.model.CDOPackageUnit.Type; +import org.eclipse.emf.cdo.common.security.CDOPermission; import org.eclipse.emf.cdo.eresource.CDOBinaryResource; import org.eclipse.emf.cdo.eresource.CDOResource; import org.eclipse.emf.cdo.eresource.CDOResourceFolder; @@ -58,7 +59,6 @@ import org.eclipse.net4j.util.event.IListener; import org.eclipse.net4j.util.ui.views.ContainerItemProvider; import org.eclipse.net4j.util.ui.views.IElementFilter; -import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EPackage; import org.eclipse.jface.action.IMenuManager; @@ -177,8 +177,7 @@ public class CDOItemProvider extends ContainerItemProvider<IContainer<Object>> if (element instanceof CDOResourceFolder) { - EList<CDOResourceNode> result = CDOUtil.filterReadables(((CDOResourceFolder)element).getNodes()); - return result.toArray(); + return ((CDOResourceFolder)element).getNodes().toArray(); } return super.getChildren(element); @@ -247,7 +246,13 @@ public class CDOItemProvider extends ContainerItemProvider<IContainer<Object>> if (element instanceof CDOResourceFolder) { - return !((CDOResourceFolder)element).getNodes().isEmpty(); + CDOResourceFolder folder = (CDOResourceFolder)element; + if (folder.cdoPermission() == CDOPermission.NONE) + { + return false; + } + + return !folder.getNodes().isEmpty(); } return super.hasChildren(element); @@ -552,10 +557,13 @@ public class CDOItemProvider extends ContainerItemProvider<IContainer<Object>> if (!view.isReadOnly()) { CDOResource rootResource = view.getRootResource(); - manager.add(new NewResourceNodeAction(this, page, view, rootResource, NewResourceNodeAction.Type.FOLDER)); - manager.add(new NewResourceNodeAction(this, page, view, rootResource, NewResourceNodeAction.Type.MODEL)); - manager.add(new NewResourceNodeAction(this, page, view, rootResource, NewResourceNodeAction.Type.TEXT)); - manager.add(new NewResourceNodeAction(this, page, view, rootResource, NewResourceNodeAction.Type.BINARY)); + if (rootResource.cdoPermission() == CDOPermission.WRITE) + { + manager.add(new NewResourceNodeAction(this, page, view, rootResource, NewResourceNodeAction.Type.FOLDER)); + manager.add(new NewResourceNodeAction(this, page, view, rootResource, NewResourceNodeAction.Type.MODEL)); + manager.add(new NewResourceNodeAction(this, page, view, rootResource, NewResourceNodeAction.Type.TEXT)); + manager.add(new NewResourceNodeAction(this, page, view, rootResource, NewResourceNodeAction.Type.BINARY)); + } } manager.add(new Separator()); diff --git a/plugins/org.eclipse.emf.cdo/plugin.xml b/plugins/org.eclipse.emf.cdo/plugin.xml index dbccda65b2..ac0e800fd1 100644 --- a/plugins/org.eclipse.emf.cdo/plugin.xml +++ b/plugins/org.eclipse.emf.cdo/plugin.xml @@ -50,6 +50,12 @@ namespace="org.eclipse.emf.cdo.view" properties="open,viewID,branchName,branch,timeStamp,lastUpdateTime,readOnly,dirty,durable,sessionID,userID" class="org.eclipse.emf.internal.cdo.view.ViewProperties$Tester"/> + <propertyTester + id="org.eclipse.emf.cdo.object.properties" + type="org.eclipse.emf.ecore.EObject" + namespace="org.eclipse.emf.cdo.object" + properties="id,state,transactional,readable,writable,writableContainer,permission,permissionContainer,readLocks,writeLock,writeOption" + class="org.eclipse.emf.internal.cdo.object.ObjectProperties$Tester"/> </extension> </plugin> diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/ObjectProperties.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/ObjectProperties.java new file mode 100644 index 0000000000..49ac4fc3db --- /dev/null +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/object/ObjectProperties.java @@ -0,0 +1,282 @@ +/* + * Copyright (c) 2011, 2012 Eike Stepper (Berlin, Germany) 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: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.emf.internal.cdo.object; + +import org.eclipse.emf.cdo.CDOObject; +import org.eclipse.emf.cdo.common.lock.CDOLockState; +import org.eclipse.emf.cdo.common.security.CDOPermission; +import org.eclipse.emf.cdo.util.CDOUtil; +import org.eclipse.emf.cdo.view.CDOView; + +import org.eclipse.net4j.util.properties.DefaultPropertyTester; +import org.eclipse.net4j.util.properties.IProperties; +import org.eclipse.net4j.util.properties.Properties; +import org.eclipse.net4j.util.properties.Property; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; + +/** + * @author Eike Stepper + */ +public class ObjectProperties extends Properties<EObject> +{ + public static final IProperties<EObject> INSTANCE = new ObjectProperties(); + + private static final String CATEGORY_CDO = "CDO"; //$NON-NLS-1$ + + private ObjectProperties() + { + super(EObject.class); + + add(new Property<EObject>("id", //$NON-NLS-1$ + "ID", "The technical CDOID of this object.", CATEGORY_CDO) + { + @Override + protected Object eval(EObject object) + { + CDOObject cdoObject = CDOUtil.getCDOObject(object); + if (cdoObject == null) + { + return null; + } + + return cdoObject.cdoID(); + } + }); + + add(new Property<EObject>("state", //$NON-NLS-1$ + "State", "The current state of this object.", CATEGORY_CDO) + { + @Override + protected Object eval(EObject object) + { + CDOObject cdoObject = CDOUtil.getCDOObject(object); + if (cdoObject == null) + { + return null; + } + + return cdoObject.cdoState(); + } + }); + + add(new Property<EObject>("transactional") //$NON-NLS-1$ + { + @Override + protected Object eval(EObject object) + { + CDOObject cdoObject = CDOUtil.getCDOObject(object); + if (cdoObject == null) + { + return false; + } + + CDOView view = cdoObject.cdoView(); + if (view == null) + { + return false; + } + + return !view.isReadOnly(); + } + }); + + add(new Property<EObject>("readable") //$NON-NLS-1$ + { + @Override + protected Object eval(EObject object) + { + CDOObject cdoObject = CDOUtil.getCDOObject(object); + if (cdoObject == null) + { + return true; + } + + return cdoObject.cdoPermission() != CDOPermission.NONE; + } + }); + + add(new Property<EObject>("writable") //$NON-NLS-1$ + { + @Override + protected Object eval(EObject object) + { + CDOObject cdoObject = CDOUtil.getCDOObject(object); + if (cdoObject == null) + { + return true; + } + + CDOView view = cdoObject.cdoView(); + if (view == null) + { + return true; + } + + return !view.isReadOnly() && cdoObject.cdoPermission() == CDOPermission.WRITE; + } + }); + + add(new Property<EObject>("writableContainer") //$NON-NLS-1$ + { + @Override + protected Object eval(EObject object) + { + CDOObject cdoObject = null; + + EObject eContainer = object.eContainer(); + if (eContainer != null) + { + cdoObject = CDOUtil.getCDOObject(eContainer); + } + + if (cdoObject == null) + { + Resource resource = object.eResource(); + if (resource instanceof CDOObject) + { + cdoObject = (CDOObject)resource; + } + } + + if (cdoObject == null) + { + return true; + } + + CDOView view = cdoObject.cdoView(); + if (view == null) + { + return true; + } + + return !view.isReadOnly() && cdoObject.cdoPermission() == CDOPermission.WRITE; + } + }); + + add(new Property<EObject>("permission", //$NON-NLS-1$ + "Permission", "The permission the current user has for this object.", CATEGORY_CDO) + { + @Override + protected Object eval(EObject object) + { + CDOObject cdoObject = CDOUtil.getCDOObject(object); + if (cdoObject == null) + { + return null; + } + + return cdoObject.cdoPermission(); + } + }); + + add(new Property<EObject>("permissionContainer") //$NON-NLS-1$ + { + @Override + protected Object eval(EObject object) + { + CDOObject cdoObject = CDOUtil.getCDOObject(object.eContainer()); + if (cdoObject == null) + { + return null; + } + + return cdoObject.cdoPermission(); + } + }); + + add(new Property<EObject>("readLocks", //$NON-NLS-1$ + "Read Locks", "The owner of read locks on this object.", CATEGORY_CDO) + { + @Override + protected Object eval(EObject object) + { + CDOObject cdoObject = CDOUtil.getCDOObject(object); + if (cdoObject == null) + { + return null; + } + + CDOLockState lockState = cdoObject.cdoLockState(); + if (lockState == null) + { + return null; + } + + return lockState.getReadLockOwners(); + } + }); + + add(new Property<EObject>("writeLock", //$NON-NLS-1$ + "Write Lock", "The owner of a write lock on this object.", CATEGORY_CDO) + { + @Override + protected Object eval(EObject object) + { + CDOObject cdoObject = CDOUtil.getCDOObject(object); + if (cdoObject == null) + { + return null; + } + + CDOLockState lockState = cdoObject.cdoLockState(); + if (lockState == null) + { + return null; + } + + return lockState.getWriteLockOwner(); + } + }); + + add(new Property<EObject>("writeOption", //$NON-NLS-1$ + "Write Option", "The owner of a write option on this object.", CATEGORY_CDO) + { + @Override + protected Object eval(EObject object) + { + CDOObject cdoObject = CDOUtil.getCDOObject(object); + if (cdoObject == null) + { + return null; + } + + CDOLockState lockState = cdoObject.cdoLockState(); + if (lockState == null) + { + return null; + } + + return lockState.getWriteOptionOwner(); + } + }); + + } + + public static void main(String[] args) + { + new Tester().dumpContributionMarkup(); + } + + /** + * @author Eike Stepper + */ + public static final class Tester extends DefaultPropertyTester<EObject> + { + public static final String NAMESPACE = "org.eclipse.emf.cdo.object"; + + public Tester() + { + super(NAMESPACE, INSTANCE); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/ViewProperties.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/ViewProperties.java index 3b1ef9325e..96b90b5ff5 100644 --- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/ViewProperties.java +++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/ViewProperties.java @@ -92,6 +92,18 @@ public class ViewProperties extends Properties<CDOView> } }); + add(new Property<CDOView>( + "rootResourcePermission", //$NON-NLS-1$ + "Root Resource Permission", "The permission the current user has for the root resource of this view.", + CATEGORY_VIEW) + { + @Override + protected Object eval(CDOView view) + { + return view.getRootResource().cdoPermission(); + } + }); + add(new Property<CDOView>("readOnly", //$NON-NLS-1$ "Read-Only", "Whether this view is read-only or not.", CATEGORY_VIEW) { @@ -143,9 +155,6 @@ public class ViewProperties extends Properties<CDOView> }); } - /** - * - */ public static void main(String[] args) { new Tester().dumpContributionMarkup(); diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/AbstractPropertyAdapterFactory.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/AbstractPropertyAdapterFactory.java index 4c78d2326f..c8f2ea8cfe 100644 --- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/AbstractPropertyAdapterFactory.java +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/AbstractPropertyAdapterFactory.java @@ -11,6 +11,7 @@ package org.eclipse.net4j.util.ui; import org.eclipse.core.runtime.IAdapterFactory; +import org.eclipse.ui.IActionFilter; import org.eclipse.ui.views.properties.IPropertySource; import org.eclipse.ui.views.properties.IPropertySourceProvider; @@ -21,7 +22,7 @@ import org.eclipse.ui.views.properties.IPropertySourceProvider; @SuppressWarnings("rawtypes") public abstract class AbstractPropertyAdapterFactory implements IAdapterFactory { - private static final Class[] CLASSES = { IPropertySourceProvider.class }; + private static final Class[] CLASSES = { IPropertySourceProvider.class, IActionFilter.class }; public AbstractPropertyAdapterFactory() { @@ -49,8 +50,21 @@ public abstract class AbstractPropertyAdapterFactory implements IAdapterFactory } } + if (adapterType == CLASSES[1]) + { + return createActionFilter(adaptableObject); + } + return null; } protected abstract IPropertySource createPropertySource(Object object); + + /** + * @since 3.4 + */ + protected IActionFilter createActionFilter(Object object) + { + return null; + } } diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/DefaultActionFilter.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/DefaultActionFilter.java new file mode 100644 index 0000000000..73cf14efd1 --- /dev/null +++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/DefaultActionFilter.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2011, 2012 Eike Stepper (Berlin, Germany) 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: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.util.ui; + +import org.eclipse.net4j.util.ObjectUtil; +import org.eclipse.net4j.util.properties.IPropertyProvider; +import org.eclipse.net4j.util.properties.Property; + +import org.eclipse.ui.IActionFilter; + +/** + * @author Eike Stepper + * @since 3.4 + */ +public class DefaultActionFilter<RECEIVER> implements IActionFilter +{ + private IPropertyProvider<RECEIVER> provider; + + public DefaultActionFilter(IPropertyProvider<RECEIVER> provider) + { + this.provider = provider; + } + + public boolean testAttribute(Object target, String name, String value) + { + for (Property<RECEIVER> property : provider.getProperties()) + { + if (property.getName().equals(name)) + { + @SuppressWarnings("unchecked") + RECEIVER receiver = (RECEIVER)target; + + Object actualValue = property.getValue(receiver); + return ObjectUtil.equals(value, actualValue); + } + } + + return false; + } +} |