diff options
author | Michael Valenta | 2006-06-22 18:27:23 +0000 |
---|---|---|
committer | Michael Valenta | 2006-06-22 18:27:23 +0000 |
commit | 0d3bff80537b3d90e4375fbf03e3d9a36a1a63c0 (patch) | |
tree | 40b95139ac9902c96b8680371f0dada8d8be380e /examples/org.eclipse.team.examples.filesystem | |
parent | 4de8cd623dde46b4005d6bc5a1aa9df76fac61cc (diff) | |
download | eclipse.platform.team-0d3bff80537b3d90e4375fbf03e3d9a36a1a63c0.tar.gz eclipse.platform.team-0d3bff80537b3d90e4375fbf03e3d9a36a1a63c0.tar.xz eclipse.platform.team-0d3bff80537b3d90e4375fbf03e3d9a36a1a63c0.zip |
Bug 124882 [Model Sync] Support third party action contributions to a model sync
Diffstat (limited to 'examples/org.eclipse.team.examples.filesystem')
2 files changed, 162 insertions, 0 deletions
diff --git a/examples/org.eclipse.team.examples.filesystem/plugin.xml b/examples/org.eclipse.team.examples.filesystem/plugin.xml index 694a38930..e28cd42df 100644 --- a/examples/org.eclipse.team.examples.filesystem/plugin.xml +++ b/examples/org.eclipse.team.examples.filesystem/plugin.xml @@ -546,6 +546,21 @@ </or> </possibleChildren> </navigatorContent> + <actionProvider + class="org.eclipse.team.examples.model.ui.mapping.ThirdPartyActionProvider" + id="org.eclipse.team.examples.model.ThirdPartyActionProvider"> + <enablement> + <adapt type="org.eclipse.core.resources.mapping.ResourceMapping"/> + </enablement> + </actionProvider> + </extension> + <extension + point="org.eclipse.ui.navigator.viewer"> + <viewerActionBinding viewerId="org.eclipse.team.cvs.ui.workspaceSynchronization"> + <includes> + <actionExtension pattern="org.eclipse.team.examples.model.ThirdPartyActionProvider"/> + </includes> + </viewerActionBinding> </extension> diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/mapping/ThirdPartyActionProvider.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/mapping/ThirdPartyActionProvider.java new file mode 100644 index 000000000..bcaed1ce2 --- /dev/null +++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/mapping/ThirdPartyActionProvider.java @@ -0,0 +1,147 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.team.examples.model.ui.mapping; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.resources.mapping.ModelProvider; +import org.eclipse.core.resources.mapping.ResourceMapping; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.team.core.mapping.ISynchronizationContext; +import org.eclipse.team.ui.mapping.ISynchronizationCompareAdapter; +import org.eclipse.team.ui.mapping.ITeamContentProviderManager; +import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; +import org.eclipse.ui.IContributorResourceAdapter; +import org.eclipse.ui.ide.IContributorResourceAdapter2; +import org.eclipse.ui.navigator.*; + +public class ThirdPartyActionProvider extends CommonActionProvider { + + private Action exampleAction; + + public ThirdPartyActionProvider() { + // Nothing to do + } + + /** + * Return the configuration from the synchronize page that contains + * the common viewer. + * @return the configuration from the synchronize page that contains + * the common viewer + */ + protected final ISynchronizePageConfiguration getSynchronizePageConfiguration() { + return (ISynchronizePageConfiguration)getExtensionStateModel().getProperty(ITeamContentProviderManager.P_SYNCHRONIZATION_PAGE_CONFIGURATION); + } + + /** + * Return the extension state model for the content provider associated with + * action provider. + * @return the extension state model for the content provider associated with + * action provider + */ + protected final IExtensionStateModel getExtensionStateModel() { + return getActionSite().getExtensionStateModel(); + } + + /** + * Return the synchronization context to which the actions of this provider + * apply. + * @return the synchronization context to which the actions of this provider + * apply + */ + protected final ISynchronizationContext getSynchronizationContext() { + return (ISynchronizationContext)getExtensionStateModel().getProperty(ITeamContentProviderManager.P_SYNCHRONIZATION_CONTEXT); + } + + public void init(ICommonActionExtensionSite aSite) { + super.init(aSite); + exampleAction = new Action("3rd Party Action") { + public void run() { + StringBuffer buffer = new StringBuffer(); + boolean addComma = false; + IStructuredSelection selection = (IStructuredSelection)getContext().getSelection(); + ResourceMapping[] mappings = getResourceMappings(selection.toArray()); + for (int i = 0; i < mappings.length; i++) { + ResourceMapping mapping = mappings[i]; + ISynchronizationCompareAdapter adapter = getCompareAdpater(mapping); + if (adapter != null) { + String name = adapter.getName(mapping); + if (addComma) { + buffer.append(", "); + } + buffer.append(name); + addComma = true; + } + } + MessageDialog.openInformation(getActionSite().getViewSite().getShell(), "Example Action", "You have executed a third party action on the selected elements: " + buffer.toString()); + } + }; + } + + protected ISynchronizationCompareAdapter getCompareAdpater(ResourceMapping mapping) { + if (mapping != null) { + ModelProvider provider = mapping.getModelProvider(); + if (provider != null) { + Object o = provider.getAdapter(ISynchronizationCompareAdapter.class); + if (o instanceof ISynchronizationCompareAdapter) { + return (ISynchronizationCompareAdapter) o; + } + } + } + return null; + } + + public void fillContextMenu(IMenuManager menu) { + super.fillContextMenu(menu); + menu.add(exampleAction); + } + + private ResourceMapping[] getResourceMappings(Object[] objects) { + List result = new ArrayList(); + for (int i = 0; i < objects.length; i++) { + Object object = objects[i]; + ResourceMapping mapping = getResourceMapping(object); + if (mapping != null) + result.add(mapping); + } + return (ResourceMapping[]) result.toArray(new ResourceMapping[result.size()]); + } + + private ResourceMapping getResourceMapping(Object o) { + if (o instanceof ResourceMapping) { + return (ResourceMapping) o; + } + if (o instanceof IAdaptable) { + IAdaptable adaptable = (IAdaptable) o; + Object adapted = adaptable.getAdapter(ResourceMapping.class); + if (adapted instanceof ResourceMapping) { + return(ResourceMapping) adapted; + } + adapted = adaptable.getAdapter(IContributorResourceAdapter.class); + if (adapted instanceof IContributorResourceAdapter2) { + IContributorResourceAdapter2 cra = (IContributorResourceAdapter2) adapted; + return cra.getAdaptedResourceMapping(adaptable); + } + } else { + Object adapted = Platform.getAdapterManager().getAdapter(o, ResourceMapping.class); + if (adapted instanceof ResourceMapping) { + return(ResourceMapping) adapted; + } + } + return null; + } +} |