diff options
Diffstat (limited to 'examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team')
102 files changed, 0 insertions, 12137 deletions
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileModificationValidator.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileModificationValidator.java deleted file mode 100644 index 79f48a032..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileModificationValidator.java +++ /dev/null @@ -1,85 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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.filesystem; - -import java.util.ArrayList; -import java.util.Collection; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.team.FileModificationValidationContext; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.team.core.RepositoryProvider; -import org.eclipse.team.core.TeamException; - -/** - * This class models a sentry that verifies whether resources are available for editing or overwriting. - * This has been made a separate class for illustration purposes. It may have been more appropriate - * to have FileSystemProvider implement IFileModificationValidator itself since the interface - * only has two methods and their implementation is straight forward. - */ -public final class FileModificationValidator extends org.eclipse.core.resources.team.FileModificationValidator { - - private FileSystemOperations operations; - - /** - * Constructor for FileModificationValidator. - */ - public FileModificationValidator(RepositoryProvider provider) { - operations = ((FileSystemProvider)provider).getOperations(); - } - - /** - * This method will convert any exceptions thrown by the SimpleAccessOperations.checkout() to a Status. - * @param resources the resources that are to be checked out - * @return IStatus a status indicator that reports whether the operation went smoothly or not. - */ - private IStatus checkout(IResource[] resources) { - try { - operations.checkout(resources, IResource.DEPTH_INFINITE, null); - } catch (TeamException e) { - return new Status(IStatus.ERROR, FileSystemPlugin.ID, 0, e.getLocalizedMessage(), e); - } - return Status.OK_STATUS; - } - - /** - * This method will be called by the workbench/editor before it tries to edit one or more files. - * The idea is to prevent anyone from accidentally working on a file that they won't be able to check in changes to. - * @see org.eclipse.core.resources.IFileModificationValidator#validateEdit(IFile[], Object) - */ - public IStatus validateEdit(IFile[] files, FileModificationValidationContext context) { - Collection toBeCheckedOut = new ArrayList(); - - //Make a list of all the files that need to be checked out: - for (int i = 0; i < files.length; i++) { - if (!operations.isCheckedOut(files[i])) { - toBeCheckedOut.add(files[i]); - } - } - - return checkout((IResource[]) toBeCheckedOut.toArray(new IResource[toBeCheckedOut.size()])); - } - - /** - * This method will be called by the workbench before it tries to save a file. - * It should not attempt to save any files that don't receive an OK status here. - * @see org.eclipse.core.resources.IFileModificationValidator#validateSave(IFile) - */ - public IStatus validateSave(IFile file) { - if (file.isReadOnly()) { - return checkout(new IResource[] { file }); - } - return Status.OK_STATUS; - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemOperations.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemOperations.java deleted file mode 100644 index d7b419a22..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemOperations.java +++ /dev/null @@ -1,450 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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 - * Andreas Voss <av@tonbeller.com> - Bug 181141 [Examples] Team: filesystem provider example can not handle deletions - *******************************************************************************/ -package org.eclipse.team.examples.filesystem; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceVisitor; -import org.eclipse.core.resources.mapping.ResourceTraversal; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.core.variants.IResourceVariant; -import org.eclipse.team.core.variants.IResourceVariantComparator; -import org.eclipse.team.core.variants.ThreeWaySynchronizer; -import org.eclipse.team.examples.filesystem.subscriber.FileSystemResourceVariant; -import org.eclipse.team.examples.filesystem.subscriber.FileSystemSubscriber; - -/** - * The get and put operations for the file system provider. - */ -public class FileSystemOperations { - - // A reference to the provider - private FileSystemProvider provider; - - FileSystemOperations(FileSystemProvider provider) { - this.provider = provider; - } - - /** - * Make the local state of the project match the remote state by getting any out-of-sync - * resources. The overrideOutgoing flag is used to indicate whether locally modified - * files should also be replaced or left alone. - * @param resources the resources to get - * @param depth the depth of the operation - * @param overrideOutgoing whether locally modified resources should be replaced - * @param progress a progress monitor - * @throws TeamException - */ - public void get(IResource[] resources, int depth, boolean overrideOutgoing, IProgressMonitor progress) throws TeamException { - try { - // ensure the progress monitor is not null - progress = Policy.monitorFor(progress); - progress.beginTask(Policy.bind("GetAction.working"), 100); //$NON-NLS-1$ - // Refresh the subscriber so we have the latest remote state - FileSystemSubscriber.getInstance().refresh(resources, depth, new SubProgressMonitor(progress, 30)); - internalGet(resources, depth, overrideOutgoing, new SubProgressMonitor(progress, 70)); - } finally { - progress.done(); - } - } - - /** - * Make the local state of the traversals match the remote state by getting any out-of-sync - * resources. The overrideOutgoing flag is used to indicate whether locally modified - * files should also be replaced or left alone. - * @param traversals the traversals that cover the resources to get - * @param overrideOutgoing whether locally modified resources should be replaced - * @param progress a progress monitor - * @throws TeamException - */ - public void get(ResourceTraversal[] traversals, boolean overrideOutgoing, IProgressMonitor monitor) throws TeamException { - try { - // ensure the progress monitor is not null - monitor = Policy.monitorFor(monitor); - monitor.beginTask(null, 100* traversals.length); - for (int i = 0; i < traversals.length; i++) { - ResourceTraversal traversal = traversals[i]; - get(traversal.getResources(), traversal.getDepth(), overrideOutgoing, new SubProgressMonitor(monitor, 100)); - } - } finally { - monitor.done(); - } - } - - /** - * Checkout the given resources to the given depth by setting any files - * to writable (i.e set read-only to <code>false</code>. - * @param resources the resources to be checked out - * @param depth the depth of the checkout - * @param progress a progress monitor - * @throws TeamException - */ - public void checkout(IResource[] resources, int depth, IProgressMonitor progress) throws TeamException { - try { - progress = Policy.monitorFor(progress); - progress.beginTask(Policy.bind("FileSystemSimpleAccessOperations.1"), resources.length); //$NON-NLS-1$ - for (int i = 0; i < resources.length; i++) { - Policy.checkCanceled(progress); - resources[i].accept(new IResourceVisitor() { - public boolean visit(IResource resource) throws CoreException { - if (resource.getType() == IResource.FILE) { - //TODO: lock the file on the 'server'. - resource.setReadOnly(false); - } - return true; - } - }, depth, false /* include phantoms */); - progress.worked(1); - } - } catch (CoreException e) { - throw TeamException.asTeamException(e); - } finally { - progress.done(); - } - } - - /** - * Check-in the given resources to the given depth by replacing the remote (i.e. file system) - * contents with the local workspace contents. - * @param resources the resources - * @param depth the depth of the operation - * @param overrideIncoming indicate whether incoming remote changes should be replaced - * @param progress a progress monitor - * @throws TeamException - */ - public void checkin(IResource[] resources, int depth, boolean overrideIncoming, IProgressMonitor progress) throws TeamException { - try { - // ensure the progress monitor is not null - progress = Policy.monitorFor(progress); - progress.beginTask(Policy.bind("PutAction.working"), 100); //$NON-NLS-1$ - // Refresh the subscriber so we have the latest remote state - FileSystemSubscriber.getInstance().refresh(resources, depth, new SubProgressMonitor(progress, 30)); - internalPut(resources, depth, overrideIncoming, new SubProgressMonitor(progress, 70)); - } finally { - progress.done(); - } - } - - /** - * Check-in the given resources to the given depth by replacing the remote (i.e. file system) - * contents with the local workspace contents. - * @param traversals the traversals that cover the resources to check in - * @param overrideIncoming indicate whether incoming remote changes should be replaced - * @param progress a progress monitor - * @throws TeamException - */ - public void checkin(ResourceTraversal[] traversals, boolean overrideIncoming, IProgressMonitor monitor) throws TeamException { - try { - // ensure the progress monitor is not null - monitor = Policy.monitorFor(monitor); - monitor.beginTask(null, 100* traversals.length); - for (int i = 0; i < traversals.length; i++) { - ResourceTraversal traversal = traversals[i]; - checkin(traversal.getResources(), traversal.getDepth(), overrideIncoming, new SubProgressMonitor(monitor, 100)); - } - } finally { - monitor.done(); - } - } - - /** - * Return whether the local resource is checked out. A resource - * is checked out if it is a file that is not read-only. Folders - * are always checked out. - * @param resource the resource - * @return whether the resource is checked out and can be modified - */ - public boolean isCheckedOut(IResource resource) { - if (resource.getType() != IResource.FILE) return true; - return !resource.isReadOnly(); - } - - /* - * Get the resource variant for the given resource. - */ - private FileSystemResourceVariant getResourceVariant(IResource resource) { - return (FileSystemResourceVariant)provider.getResourceVariant(resource); - } - - private void internalGet(IResource[] resources, int depth, boolean overrideOutgoing, IProgressMonitor progress) throws TeamException { - // Traverse the resources and get any that are out-of-sync - progress.beginTask(Policy.bind("GetAction.working"), IProgressMonitor.UNKNOWN); //$NON-NLS-1$ - for (int i = 0; i < resources.length; i++) { - Policy.checkCanceled(progress); - if (resources[i].getType() == IResource.FILE) { - internalGet((IFile) resources[i], overrideOutgoing, progress); - } else if (depth != IResource.DEPTH_ZERO) { - internalGet((IContainer)resources[i], depth, overrideOutgoing, progress); - } - progress.worked(1); - } - } - - /* - * Get the folder and its children to the depth specified. - */ - private void internalGet(IContainer container, int depth, boolean overrideOutgoing, IProgressMonitor progress) throws TeamException { - try { - ThreeWaySynchronizer synchronizer = FileSystemSubscriber.getInstance().getSynchronizer(); - // Make the local folder state match the remote folder state - List toDelete = new ArrayList(); - if (container.getType() == IResource.FOLDER) { - IFolder folder = (IFolder)container; - FileSystemResourceVariant remote = getResourceVariant(container); - if (!folder.exists() && remote != null) { - // Create the local folder - folder.create(false, true, progress); - synchronizer.setBaseBytes(folder, remote.asBytes()); - } else if (folder.exists() && remote == null) { - // Schedule the folder for removal but delay in - // case the folder contains outgoing changes - toDelete.add(folder); - } - } - - // Get the children - IResource[] children = synchronizer.members(container); - if (children.length > 0) { - internalGet(children, depth == IResource.DEPTH_INFINITE ? IResource.DEPTH_INFINITE : IResource.DEPTH_ZERO, overrideOutgoing, progress); - } - - // Remove any empty folders - for (Iterator iter = toDelete.iterator(); iter.hasNext(); ) { - IFolder folder = (IFolder) iter.next(); - if (folder.members().length == 0) { - folder.delete(false, true, progress); - synchronizer.flush(folder, IResource.DEPTH_INFINITE); - } - } - } catch (CoreException e) { - throw TeamException.asTeamException(e); - } - } - - /* - * Get the file if it is out-of-sync. - */ - private void internalGet(IFile localFile, boolean overrideOutgoing, IProgressMonitor progress) throws TeamException { - ThreeWaySynchronizer synchronizer = FileSystemSubscriber.getInstance().getSynchronizer(); - IResourceVariantComparator comparator = FileSystemSubscriber.getInstance().getResourceComparator(); - FileSystemResourceVariant remote = getResourceVariant(localFile); - byte[] baseBytes = synchronizer.getBaseBytes(localFile); - IResourceVariant base = provider.getResourceVariant(localFile, baseBytes); - if (!synchronizer.hasSyncBytes(localFile) - || (isLocallyModified(localFile) && !overrideOutgoing)) { - // Do not overwrite the local modification - return; - } - if (base != null && remote == null) { - // The remote no longer exists so remove the local - try { - localFile.delete(false, true, progress); - synchronizer.flush(localFile, IResource.DEPTH_ZERO); - return; - } catch (CoreException e) { - throw TeamException.asTeamException(e); - } - } - if (!synchronizer.isLocallyModified(localFile) - && base != null - && remote != null - && comparator.compare(base, remote)) { - // The base and remote are the same and there's no local changes - // so nothing needs to be done - return; - } - try { - //Copy from the local file to the remote file: - InputStream source = null; - try { - // Get the remote file content. - source = remote.getContents(); - // Set the local file content to be the same as the remote file. - if (localFile.exists()) - localFile.setContents(source, false, false, progress); - else - localFile.create(source, false, progress); - } finally { - if (source != null) - source.close(); - } - // Mark as read-only to force a checkout before editing - localFile.setReadOnly(true); - synchronizer.setBaseBytes(localFile, remote.asBytes()); - } catch (IOException e) { - throw FileSystemPlugin.wrapException(e); - } catch (CoreException e) { - throw FileSystemPlugin.wrapException(e); - } - } - - private void internalPut(IResource[] resources, int depth, boolean overrideIncoming, IProgressMonitor progress) throws TeamException { - // ensure the progress monitor is not null - progress = Policy.monitorFor(progress); - progress.beginTask(Policy.bind("PutAction.working"), IProgressMonitor.UNKNOWN); //$NON-NLS-1$ - for (int i = 0; i < resources.length; i++) { - Policy.checkCanceled(progress); - if (resources[i].getType() == IResource.FILE) { - internalPut((IFile)resources[i], overrideIncoming, progress); - } else if (depth > 0) { //Assume that resources are either files or containers. - internalPut((IContainer)resources[i], depth, overrideIncoming, progress); - } - progress.worked(1); - } - progress.done(); - } - - /** - * Put the file if the sync state allows it. - * @param localFile the local file - * @param overrideIncoming whether incoming changes should be overwritten - * @param progress a progress monitor - * @return whether the put succeeded (i.e. the local matches the remote) - * @throws TeamException - */ - private boolean internalPut(IFile localFile, boolean overrideIncoming, IProgressMonitor progress) throws TeamException { - ThreeWaySynchronizer synchronizer = FileSystemSubscriber.getInstance().getSynchronizer(); - IResourceVariantComparator comparator = FileSystemSubscriber.getInstance().getResourceComparator(); - FileSystemResourceVariant remote = getResourceVariant(localFile); - byte[] baseBytes = synchronizer.getBaseBytes(localFile); - IResourceVariant base = provider.getResourceVariant(localFile, baseBytes); - - // Check whether we are overriding a remote change - if (base == null && remote != null && !overrideIncoming) { - // The remote is an incoming (or conflicting) addition. - // Do not replace unless we are overriding - return false; - } else if (base != null && remote == null) { - // The remote is an incoming deletion - if (!localFile.exists()) { - // Conflicting deletion. Clear the synchronizer. - synchronizer.flush(localFile, IResource.DEPTH_ZERO); - } else if (!overrideIncoming) { - // Do not override the incoming deletion - return false; - } - } else if (base != null && remote != null) { - boolean same = comparator.compare(base, remote); - if (!isLocallyModified(localFile) && same) { - // The base and remote are the same and there's no local changes - // so nothing needs to be done - return true; - } - if (!same && !overrideIncoming) { - // The remote has changed. Only override if specified - return false; - } - } - - // Handle an outgoing deletion - File diskFile = provider.getFile(localFile); - if (!localFile.exists()) { - diskFile.delete(); - synchronizer.flush(localFile, IResource.DEPTH_ZERO); - } else { - // Otherwise, upload the contents - try { - //Copy from the local file to the remote file: - InputStream in = null; - FileOutputStream out = null; - try { - if(! diskFile.getParentFile().exists()) { - diskFile.getParentFile().mkdirs(); - } - in = localFile.getContents(); - out = new FileOutputStream(diskFile); - //Copy the contents of the local file to the remote file: - StreamUtil.pipe(in, out, diskFile.length(), progress, diskFile.getName()); - // Mark the file as read-only to require another checkout - localFile.setReadOnly(true); - } finally { - if (in != null) - in.close(); - if (out != null) - out.close(); - } - // Update the synchronizer base bytes - remote = getResourceVariant(localFile); - synchronizer.setBaseBytes(localFile, remote.asBytes()); - } catch (IOException e) { - throw FileSystemPlugin.wrapException(e); - } catch (CoreException e) { - throw FileSystemPlugin.wrapException(e); - } - } - return true; - } - - private boolean isLocallyModified(IFile localFile) throws TeamException { - ThreeWaySynchronizer synchronizer = FileSystemSubscriber.getInstance().getSynchronizer(); - if (!localFile.exists()) { - // Extra check for bug 141415 - return synchronizer.getBaseBytes(localFile) != null; - } - return synchronizer.isLocallyModified(localFile); - } - - /* - * Get the folder and its children to the depth specified. - */ - private void internalPut(IContainer container, int depth, boolean overrideIncoming, IProgressMonitor progress) throws TeamException { - try { - ThreeWaySynchronizer synchronizer = FileSystemSubscriber.getInstance().getSynchronizer(); - // Make the local folder state match the remote folder state - List toDelete = new ArrayList(); - if (container.getType() == IResource.FOLDER) { - IFolder folder = (IFolder)container; - File diskFile = provider.getFile(container); - FileSystemResourceVariant remote = getResourceVariant(container); - if (!folder.exists() && remote != null) { - // Schedule the folder for removal but delay in - // case the folder contains incoming changes - toDelete.add(diskFile); - } else if (folder.exists() && remote == null) { - // Create the remote directory and sync up the local - diskFile.mkdir(); - synchronizer.setBaseBytes(folder, provider.getResourceVariant(folder).asBytes()); - } - } - - // Get the children - IResource[] children = synchronizer.members(container); - if (children.length > 0) { - internalPut(children, depth == IResource.DEPTH_INFINITE ? IResource.DEPTH_INFINITE : IResource.DEPTH_ZERO, overrideIncoming, progress); - } - - // Remove any empty folders - for (Iterator iter = toDelete.iterator(); iter.hasNext(); ) { - File diskFile = (File) iter.next(); - if (diskFile.listFiles().length == 0) { - diskFile.delete(); - synchronizer.flush(container, IResource.DEPTH_INFINITE); - } - } - } catch (CoreException e) { - throw TeamException.asTeamException(e); - } - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemPlugin.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemPlugin.java deleted file mode 100644 index 53b3c39a0..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemPlugin.java +++ /dev/null @@ -1,143 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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.filesystem; - -import java.io.IOException; - -import org.eclipse.core.runtime.*; -import org.eclipse.swt.widgets.Display; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.examples.model.PluginManifestChangeTracker; -import org.eclipse.team.examples.pessimistic.PessimisticFilesystemProviderPlugin; -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.osgi.framework.BundleContext; - -/** - * This is the plugin class for the file system examples. It provides the following: - * - * <ol> - * <li>public fields for the plugin and provider IDs as defined in the plugin.xml - * <li>initialization on startup of Policy class that provides internationalization of strings - * <li>helper methods for outputing IStatus objects to the log - * <li>helper methods for converting CoreExceptions and IOExceptions to TeamExceptions - * </ol> - */ -public class FileSystemPlugin extends AbstractUIPlugin { - - /** - * This is the ID of the plugin as defined in the plugin.xml - */ - public static final String ID = "org.eclipse.team.examples.filesystem"; //$NON-NLS-1$ - - /** - * This is the provider ID of the plugin as defined in the plugin.xml - */ - public static final String PROVIDER_ID = ID + ".FileSystemProvider"; //$NON-NLS-1$ - - // This static field will hold the singleton instance of the plugin class - private static FileSystemPlugin plugin; - - private PessimisticFilesystemProviderPlugin pessPlugin; - - private PluginManifestChangeTracker tracker; - - /** - * Override the standard plugin constructor. - * - * @param descriptor the plugin descriptor - */ - public FileSystemPlugin(IPluginDescriptor descriptor) { - super(descriptor); - // record this instance as the singleton - plugin = this; - // Instanctiate pessimistic provider - pessPlugin = new PessimisticFilesystemProviderPlugin(descriptor); - } - - /** - * Return the singlton instance of the plugin class to allow other - * classes in the plugin access to plugin instance methods such as - * those for logging errors, etc. - */ - public static FileSystemPlugin getPlugin() { - return plugin; - } - - /** - * Helper method to convert a CoreException into a TeamException. - * We do this to maintain the core status and code. This type of - * mapping may not be appropriate in more complicated exception - * handling situations. - * - * @param e the CoreException - */ - public static TeamException wrapException(CoreException e) { - return new TeamException(e.getStatus()); - } - - /** - * Helper method to convert an IOException into a TeamException. - * This type of mapping may not be appropriate in more complicated - * exception handling situations. - * - * @param e the CoreException - */ - public static TeamException wrapException(IOException e) { - return new TeamException(new Status(IStatus.ERROR, FileSystemPlugin.ID, - TeamException.IO_FAILED, e.getMessage(), e)); - } - - /** - * Helper method to log an exception status. - * - * @param status the status to be logged - */ - public static void log(IStatus status) { - plugin.getLog().log(status); - } - - /** - * Returns the standard display to be used. The method first checks, if - * the thread calling this method has an associated display. If so, this - * display is returned. Otherwise the method returns the default display. - */ - public static Display getStandardDisplay() { - Display display= Display.getCurrent(); - if (display == null) { - display= Display.getDefault(); - } - return display; - } - - public void start(BundleContext context) throws Exception { - super.start(context); - //Call startup on the Pessimistic Plugin - pessPlugin.startup(); - tracker = new PluginManifestChangeTracker(); - tracker.start(); - } - - public void stop(BundleContext context) throws Exception { - try { - if (pessPlugin != null) - pessPlugin.shutdown(); - } finally { - super.stop(context); - } - tracker.dispose(); - tracker = null; - } - - public static void log(CoreException e) { - log (new Status(e.getStatus().getSeverity(), FileSystemPlugin.ID, 0, e.getMessage(), e)); - } -} - diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemProvider.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemProvider.java deleted file mode 100644 index e951bebc5..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemProvider.java +++ /dev/null @@ -1,243 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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.filesystem; - -import java.io.File; - -import org.eclipse.core.resources.IFileModificationValidator; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceRuleFactory; -import org.eclipse.core.resources.team.FileModificationValidator; -import org.eclipse.core.resources.team.ResourceRuleFactory; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.team.core.RepositoryProvider; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.core.history.IFileHistoryProvider; -import org.eclipse.team.core.variants.IResourceVariant; -import org.eclipse.team.examples.filesystem.history.FileSystemHistoryProvider; -import org.eclipse.team.examples.filesystem.subscriber.FileSystemResourceVariant; -import org.eclipse.team.examples.filesystem.subscriber.FileSystemSubscriber; - -/** - * This example illustrates how to create a concrete implementation of a <code>RepositoryProvider</code> - * that uses the file system to act as the repository. See the plugin.xml file for the xml required - * to register this provider with the Team extension point <code>org.eclipse.team.core.repository</code>. - * The plugin.xml file also contains examples of how to filter menu items using a repository provider's - * ID. - * - * <p> - * This example provider illustrates the following: - * <ol> - * <li>simple working implementation of <code>RepositoyProvider</code> - * <li>storage of a persistent property with the project (which provides the target location for the provider) - * <li>access to an instance of <code>SimpleAccessOperations</code> for performing simple file operations - * </ol> - * - * <p> - * Additional functionality that will be illustrated in the future include: - * <ol> - * <li>Validate Save/Validate Edit - * <li>Move/Delete Hook - * <li>Project Sets - * <li>Use of the workspace synchronizer (ISynchronizer) - * <li>Use of decorators - * <li>combining streams and progress monitors to get responsive UI - * </ol> - * - */ -public class FileSystemProvider extends RepositoryProvider { - - /* - * Create a custom rule factory to allow more optimistic concurrency - */ - private static final ResourceRuleFactory RESOURCE_RULE_FACTORY = new ResourceRuleFactory() { - // Just need a subclass to instantiate - }; - - // The location of the folder on file system where the repository is stored. - private IPath root; - - // The QualifiedName that is used to persist the location across workspace as a persistent property on a resource - private static QualifiedName FILESYSTEM_REPO_LOC = new QualifiedName(FileSystemPlugin.ID, "disk_location"); //$NON-NLS-1$ - - private static FileSystemHistoryProvider fileHistoryProvider; - - /** - * Create a new FileSystemProvider. - */ - public FileSystemProvider() { - super(); - } - - /** - * This method is invoked when the provider is mapped to a project. - * Although we have access to the project at this point (using - * <code>getProject()</code>, we don't know the root location so - * there is nothing we can do yet. - * - * @see org.eclipse.team.core.RepositoryProvider#configureProject() - */ - public void configureProject() { - FileSystemSubscriber.getInstance().handleRootChanged(getProject(), true /* added */); - } - - /** - * This method is invoked when the provider is unmapped from its - * project. - * - * @see org.eclipse.core.resources.IProjectNature#deconfigure() - */ - public void deconfigure() throws CoreException { - // Clear the persistant property containing the location - getProject().setPersistentProperty(FILESYSTEM_REPO_LOC, null); - FileSystemSubscriber.getInstance().handleRootChanged(getProject(), false /* removed */); - } - - /** - * Return the provider ID as specified in the plugin.xml - * - * @see RepositoryProvider#getID() - */ - public String getID() { - return FileSystemPlugin.PROVIDER_ID; - } - - /** - * Set the file system location for the provider. This mist be invoked after - * the provider is mapped and configured but before the provider is used to - * perform any operations. - * - * @param location the path representing the location where the project contents will be stored. - * @throws TeamException - */ - public void setTargetLocation(String location) throws TeamException { - - // set the instance variable to the provided path - root = new Path(location); - - // ensure that the location is a folder (if it exists) - File file = new File(location); - if (file.exists() && !file.isDirectory()) { - throw new TeamException(Policy.bind("FileSystemProvider.mustBeFolder", location)); //$NON-NLS-1$ - } - - // record the location as a persistant property so it will be remembered across platform invokations - try { - getProject().setPersistentProperty(FILESYSTEM_REPO_LOC, location); - } catch (CoreException e) { - throw FileSystemPlugin.wrapException(e); - } - } - - /** - * Returns the folder in the file system to which the provider is connected. - * Return <code>null</code> if there is no location or there was a problem - * determining it. - * - * @return IPath The path to the root of the repository. - */ - public IPath getRoot() { - if (root == null) { - try { - String location = getProject().getPersistentProperty(FILESYSTEM_REPO_LOC); - if (location == null) { - return null; - } - root = new Path(location); - } catch (CoreException e) { - // log the problem and carry on - FileSystemPlugin.log(e); - return null; - } - } - return root; - } - - /** - * Return an object that provides the operations for transfering data - * to and from the provider's location. - */ - public FileSystemOperations getOperations() { - return new FileSystemOperations(this); - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.RepositoryProvider#getFileModificationValidator() - */ - public IFileModificationValidator getFileModificationValidator() { - return getFileModificationValidator2(); - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.RepositoryProvider#getFileModificationValidator2() - */ - public FileModificationValidator getFileModificationValidator2() { - return new org.eclipse.team.examples.filesystem.FileModificationValidator(this); - } - - /** - * Return the resource variant for the local resource using the bytes to - * identify the variant. - * @param resource the resource - * @param bytes the bytes that identify the resource variant - * @return the resource variant handle - */ - public IResourceVariant getResourceVariant(IResource resource, byte[] bytes) { - if (bytes == null) return null; - File file = getFile(resource); - if (file == null) return null; - return new FileSystemResourceVariant(file, bytes); - } - - /** - * Return the resource variant for the local resource. - * @param resource the resource - * @return the resource variant - */ - public IResourceVariant getResourceVariant(IResource resource) { - File file = getFile(resource); - if (file == null || !file.exists()) return null; - return new FileSystemResourceVariant(file); - } - - /** - * Return the <code>java.io.File</code> that the given resource maps to. - * Return <code>null</code> if the resource is not a child of this provider's - * project. - * @param resource the resource - * @return the file that the resource maps to. - */ - public java.io.File getFile(IResource resource) { - if (resource.getProject().equals(getProject())) { - IPath rootdir = getRoot(); - return new File(rootdir.append(resource.getProjectRelativePath()).toOSString()); - } - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.RepositoryProvider#getRuleFactory() - */ - public IResourceRuleFactory getRuleFactory() { - return RESOURCE_RULE_FACTORY; - } - - public IFileHistoryProvider getFileHistoryProvider() { - if (FileSystemProvider.fileHistoryProvider == null) { - FileSystemProvider.fileHistoryProvider = new FileSystemHistoryProvider(); - } - return FileSystemProvider.fileHistoryProvider; - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemProviderType.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemProviderType.java deleted file mode 100644 index 2b5c5cc9e..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemProviderType.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.filesystem; - -import org.eclipse.team.core.ProjectSetCapability; -import org.eclipse.team.core.RepositoryProviderType; - -/** - * The file system repository provider types - */ -public class FileSystemProviderType extends RepositoryProviderType { - - /* (non-Javadoc) - * @see org.eclipse.team.core.RepositoryProviderType#getProjectSetCapability() - */ - public ProjectSetCapability getProjectSetCapability() { - // Create an empty project set capability to test backwards compatibility - return new ProjectSetCapability() {}; - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/Policy.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/Policy.java deleted file mode 100644 index 1ee036a46..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/Policy.java +++ /dev/null @@ -1,100 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 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.filesystem; - -import java.text.MessageFormat; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; - -/** - * This class is a clone of the Policy classes many Eclipse plugin use to - * provide NLSing of strings and aid in proper progress monitoring. - */ -public class Policy { - - private static ResourceBundle bundle = null; - private static final String bundleName = "org.eclipse.team.examples.filesystem.messages"; //$NON-NLS-1$ - - /* - * Returns a resource bundle, creating one if it none is available. - */ - private static ResourceBundle getResourceBundle() { - // thread safety - ResourceBundle tmpBundle = bundle; - if (tmpBundle != null) - return tmpBundle; - // always create a new classloader to be passed in - // in order to prevent ResourceBundle caching - return bundle = ResourceBundle.getBundle(bundleName); - } - - /** - * Lookup the message with the given ID in this catalog and bind its - * substitution locations with the given string. - */ - public static String bind(String id, String binding) { - return bind(id, new String[] { binding }); - } - - /** - * Lookup the message with the given ID in this catalog and bind its - * substitution locations with the given strings. - */ - public static String bind(String id, String binding1, String binding2) { - return bind(id, new String[] { binding1, binding2 }); - } - - /** - * Gets a string from the resource bundle. We don't want to crash because of a missing String. - * Returns the key if not found. - */ - public static String bind(String key) { - try { - return getResourceBundle().getString(key); - } catch (MissingResourceException e) { - return key; - } catch (NullPointerException e) { - return "!" + key + "!"; //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - /** - * Gets a string from the resource bundle and binds it with the given arguments. If the key is - * not found, return the key. - */ - public static String bind(String key, Object[] args) { - try { - return MessageFormat.format(bind(key), args); - } catch (MissingResourceException e) { - return key; - } catch (NullPointerException e) { - return "!" + key + "!"; //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - /** - * Progress monitor helpers - */ - public static void checkCanceled(IProgressMonitor monitor) { - if (monitor.isCanceled()) - throw new OperationCanceledException(); - } - - public static IProgressMonitor monitorFor(IProgressMonitor monitor) { - if (monitor == null) - return new NullProgressMonitor(); - return monitor; - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/StreamUtil.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/StreamUtil.java deleted file mode 100644 index bf9620d3f..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/StreamUtil.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.filesystem; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import org.eclipse.core.runtime.IProgressMonitor; - -public class StreamUtil { - - protected final static byte[] COPY_BUFFER = new byte[4096]; - - public static void pipe( - InputStream in, - OutputStream out, - long sizeEstimate, - IProgressMonitor progress, - String title) - throws IOException { - - // Only show progress for files larger than 25Kb. - Long kilobytesEstimate = new Long(sizeEstimate / 1024); - boolean showProgress = (progress != null) && (sizeEstimate > 25000); - long bytesCopied = 0; - - synchronized (COPY_BUFFER) { - // Read the initial chunk. - int read = in.read(COPY_BUFFER, 0, COPY_BUFFER.length); - - while (read != -1) { - out.write(COPY_BUFFER, 0, read); - - // Report progress - if (showProgress) { - bytesCopied = bytesCopied + read; - progress.subTask( - Policy.bind( - "filetransfer.monitor", //$NON-NLS-1$ - new Object[] { title, new Long(bytesCopied / 1024), kilobytesEstimate })); - } - - // Read the next chunk. - read = in.read(COPY_BUFFER, 0, COPY_BUFFER.length); - } // end while - } // end synchronized - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/history/FileSystemFileRevision.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/history/FileSystemFileRevision.java deleted file mode 100644 index 0b248c205..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/history/FileSystemFileRevision.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 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.filesystem.history; - -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.InputStream; - -import org.eclipse.core.resources.IStorage; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.team.core.history.IFileRevision; -import org.eclipse.team.core.history.provider.FileRevision; - -public class FileSystemFileRevision extends FileRevision { - - java.io.File remoteFile; - - public FileSystemFileRevision(java.io.File file) { - this.remoteFile = file; - } - - public String getName() { - return remoteFile.getName(); - } - - public long getTimestamp() { - return remoteFile.lastModified(); - } - - public IStorage getStorage(IProgressMonitor monitor) { - return new IStorage() { - - public InputStream getContents() { - try { - return new FileInputStream(remoteFile); - } catch (FileNotFoundException e) { - // ignore - } - - return null; - } - - public IPath getFullPath() { - return new Path(remoteFile.getAbsolutePath()); - } - - public String getName() { - return remoteFile.getName(); - } - - public boolean isReadOnly() { - return true; - } - - public Object getAdapter(Class adapter) { - return null; - } - - }; - } - - public boolean isPropertyMissing() { - return false; - } - - public IFileRevision withAllProperties(IProgressMonitor monitor) { - return null; - } - - public String getContentIdentifier() { - return "[File System Revision]"; //$NON-NLS-1$ - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/history/FileSystemHistory.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/history/FileSystemHistory.java deleted file mode 100644 index 5e91b1219..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/history/FileSystemHistory.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 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.filesystem.history; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFileState; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.core.RepositoryProvider; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.core.history.IFileRevision; -import org.eclipse.team.core.history.provider.FileHistory; -import org.eclipse.team.core.variants.IResourceVariant; -import org.eclipse.team.examples.filesystem.FileSystemProvider; -import org.eclipse.team.examples.filesystem.subscriber.FileSystemResourceVariant; -import org.eclipse.team.internal.core.history.LocalFileRevision; - -public class FileSystemHistory extends FileHistory { - - private IFile file; - protected IFileRevision[] revisions; - - public FileSystemHistory(IFile file) { - this.file = file; - } - - public IFileRevision[] getContributors(IFileRevision revision) { - return null; - } - - public IFileRevision getFileRevision(String id) { - return null; - } - - public IFileRevision[] getFileRevisions() { - return revisions; - } - - public IFileRevision[] getTargets(IFileRevision revision) { - return null; - } - - public void refresh(IProgressMonitor monitor) { - try { - RepositoryProvider provider = RepositoryProvider.getProvider(file.getProject()); - if (provider != null && provider instanceof FileSystemProvider) { - FileSystemProvider fileProvider = (FileSystemProvider) provider; - IResourceVariant resVar = fileProvider.getResourceVariant(file); - if (resVar instanceof FileSystemResourceVariant) { - FileSystemResourceVariant resVarF = (FileSystemResourceVariant) resVar; - java.io.File javaFile = resVarF.getFile(); - //Get local history items - IFileState[] states = file.getHistory(monitor); - revisions = new IFileRevision[states.length + 1]; - int i = 0; - for (; i < states.length; i++) { - revisions[i] = new LocalFileRevision(states[i]); - } - revisions[i] = new FileSystemFileRevision(javaFile); - } - } - } catch (TeamException e) { - // ignore - } catch (CoreException e) { - // ignore - } - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/history/FileSystemHistoryProvider.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/history/FileSystemHistoryProvider.java deleted file mode 100644 index b9335c15a..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/history/FileSystemHistoryProvider.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * 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.filesystem.history; - -import org.eclipse.core.filesystem.IFileStore; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.core.history.IFileHistory; -import org.eclipse.team.core.history.IFileRevision; -import org.eclipse.team.core.history.provider.FileHistoryProvider; - -public class FileSystemHistoryProvider extends FileHistoryProvider { - - public IFileHistory getFileHistoryFor(IResource resource, int flags, IProgressMonitor monitor) { - return null; - } - - public IFileHistory getFileHistoryFor(IFileStore store, int flags, IProgressMonitor monitor) { - return null; - } - - public IFileRevision getWorkspaceFileRevision(IResource resource) { - return null; - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/messages.properties b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/messages.properties deleted file mode 100644 index 5911b1297..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/messages.properties +++ /dev/null @@ -1,41 +0,0 @@ -############################################################################### -# Copyright (c) 2000, 2005 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 -############################################################################### -fileSystem.propertyLocation=Location: - -FileSystemMainPage.location=Location: -FileSystemMainPage.browseDir=&Browse... -FileSystemMainPage.notValidLocation=Location must be an existing directory - -fsMainPage.name=Select a file system location -fsMainPage.description=This location will be used to share resources with a team - -ConfigurationWizard.errorTitle=Error configuring the provider. -ConfigurationWizard.error=File System provider could not be created - -ConfigurationWizard.name=File System Repository -ConfigurationWizard.description=File System Repository Properties - -DisconnectAction.errorTitle=Error Disconnecting - -PutAction.working=Putting resources... -PutAction.problemMessage=A problem occured putting the resources. - -GetAction.working=Getting resources... -GetAction.problemMessage=A problem occured getting the resources. - -ReplaceAction.working=Replacing resources... -ReplaceAction.problemMessage=A problem occured replacing the resources. - -FileSystemProvider.mustBeFolder=Target location ''{0}'' is a file and must be a folder. -RemoteResource.mustBeFolder=Resource ''{0}'' is a file so it cannot have entries -FileSystemRemoteResource.0=This resource is a container so it cannot have data. -FileSystemSimpleAccessOperations.1=Checking resources out... -FileSystemSimpleAccessOperations.3=Re-locking resources... diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemMergeContext.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemMergeContext.java deleted file mode 100644 index 1c72e3acc..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemMergeContext.java +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* - * 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.filesystem.subscriber; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.*; -import org.eclipse.core.runtime.jobs.ISchedulingRule; -import org.eclipse.team.core.diff.IDiff; -import org.eclipse.team.core.diff.IThreeWayDiff; -import org.eclipse.team.core.mapping.ISynchronizationScopeManager; -import org.eclipse.team.core.mapping.provider.MergeStatus; -import org.eclipse.team.core.mapping.provider.ResourceDiffTree; -import org.eclipse.team.core.subscribers.SubscriberMergeContext; -import org.eclipse.team.examples.filesystem.FileSystemPlugin; - -/** - * A merge context for merging file system changes. - */ -public class FileSystemMergeContext extends SubscriberMergeContext { - - /** - * Create the file system merge context for the given scope manager. - * @param manager the scope manager - */ - public FileSystemMergeContext(ISynchronizationScopeManager manager) { - super(FileSystemSubscriber.getInstance(), manager); - initialize(); - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.mapping.provider.MergeContext#makeInSync(org.eclipse.team.core.diff.IDiff, org.eclipse.core.runtime.IProgressMonitor) - */ - protected void makeInSync(IDiff diff, IProgressMonitor monitor) - throws CoreException { - IResource resource = ResourceDiffTree.getResourceFor(diff); - FileSystemSubscriber.getInstance().makeInSync(resource); - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.mapping.IMergeContext#markAsMerged(org.eclipse.team.core.diff.IDiff, boolean, org.eclipse.core.runtime.IProgressMonitor) - */ - public void markAsMerged(IDiff diff, boolean inSyncHint, - IProgressMonitor monitor) throws CoreException { - // TODO if inSyncHint is true, we should test to see if the contents match - IResource resource = ResourceDiffTree.getResourceFor(diff); - FileSystemSubscriber.getInstance().markAsMerged(resource, monitor); - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.mapping.IMergeContext#reject(org.eclipse.team.core.diff.IDiff, org.eclipse.core.runtime.IProgressMonitor) - */ - public void reject(IDiff diff, IProgressMonitor monitor) - throws CoreException { - markAsMerged(diff, false, monitor); - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.mapping.provider.MergeContext#getMergeRule(org.eclipse.team.core.diff.IDiff) - */ - public ISchedulingRule getMergeRule(IDiff node) { - return ResourceDiffTree.getResourceFor(node).getProject(); - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.mapping.provider.MergeContext#merge(org.eclipse.team.core.diff.IDiff, boolean, org.eclipse.core.runtime.IProgressMonitor) - */ - public IStatus merge(IDiff diff, boolean ignoreLocalChanges, IProgressMonitor monitor) throws CoreException { - // Only attempt the merge for non-conflicts. The reason we do this - // is because the file system provider doesn't really have the proper base - // so merging conflicts doesn't work properly - if (!ignoreLocalChanges) { - IResource resource = ResourceDiffTree.getResourceFor(diff); - if (diff instanceof IThreeWayDiff && resource instanceof IFile) { - IThreeWayDiff twd = (IThreeWayDiff) diff; - if (twd.getDirection() == IThreeWayDiff.CONFLICTING) { - return new MergeStatus(FileSystemPlugin.ID, "Cannot merge conflicting files", new IFile[] { (IFile)resource }); - } - } - } - return super.merge(diff, ignoreLocalChanges, monitor); - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemRemoteTree.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemRemoteTree.java deleted file mode 100644 index b3975785f..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemRemoteTree.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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.filesystem.subscriber; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.core.RepositoryProvider; -import org.eclipse.team.core.variants.IResourceVariant; -import org.eclipse.team.core.variants.ThreeWayRemoteTree; -import org.eclipse.team.examples.filesystem.FileSystemPlugin; -import org.eclipse.team.examples.filesystem.FileSystemProvider; - -/** - * The file system three-way remote resource variant tree that provides - * the ability to traverse the file system for the creation of resource variants. - */ -public class FileSystemRemoteTree extends ThreeWayRemoteTree { - - /** - * Create the file system remote resource variant tree - * @param subscriber the file system subscriber - */ - public FileSystemRemoteTree(FileSystemSubscriber subscriber) { - super(subscriber); - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.variants.AbstractResourceVariantTree#fetchMembers(org.eclipse.team.core.variants.IResourceVariant, org.eclipse.core.runtime.IProgressMonitor) - */ - protected IResourceVariant[] fetchMembers(IResourceVariant variant, IProgressMonitor progress) { - return ((FileSystemResourceVariant)variant).members(); - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.variants.AbstractResourceVariantTree#fetchVariant(org.eclipse.core.resources.IResource, int, org.eclipse.core.runtime.IProgressMonitor) - */ - protected IResourceVariant fetchVariant(IResource resource, int depth, IProgressMonitor monitor) { - RepositoryProvider provider = RepositoryProvider.getProvider(resource.getProject(), FileSystemPlugin.PROVIDER_ID); - if (provider != null) { - return ((FileSystemProvider)provider).getResourceVariant(resource); - } - return null; - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemResourceVariant.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemResourceVariant.java deleted file mode 100644 index 722935e8b..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemResourceVariant.java +++ /dev/null @@ -1,153 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 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.filesystem.subscriber; - -import java.io.BufferedInputStream; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.util.Date; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.core.variants.CachedResourceVariant; -import org.eclipse.team.examples.filesystem.FileSystemPlugin; - -/** - * A file system resource variant. Although not strictly necessary, this - * class extends <code>CachedResourceVariant</code> which will - * cache the contents of the resource variant. - */ -public class FileSystemResourceVariant extends CachedResourceVariant { - - private java.io.File ioFile; - private byte[] bytes; - - /** - * Create a resource variant for the given file. The bytes will - * be calculated when they are accessed. - * @param file the file - */ - public FileSystemResourceVariant(java.io.File file) { - this.ioFile = file; - } - - /** - * Create a resource variant for the given file and sync bytes. - * @param file the file - * @param bytes the timestamp bytes - */ - public FileSystemResourceVariant(java.io.File file, byte[] bytes) { - this.ioFile = file; - this.bytes = bytes; - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.variants.CachedResourceVariant#fetchContents(org.eclipse.core.runtime.IProgressMonitor) - */ - protected void fetchContents(IProgressMonitor monitor) throws TeamException { - setContents(getContents(), monitor); - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.variants.CachedResourceVariant#getCachePath() - */ - protected String getCachePath() { - // append the timestamp to the file path to give each variant a unique path - return getFilePath() + " " + ioFile.lastModified(); //$NON-NLS-1$ - } - - private String getFilePath() { - try { - return ioFile.getCanonicalPath(); - } catch (IOException e) { - // Failed for some reason. Try the absolute path. - FileSystemPlugin.log(new Status(IStatus.ERROR, FileSystemPlugin.ID, 0, - "Failed to obtain canonical path for " + ioFile.getAbsolutePath(), e)); //$NON-NLS-1$ - return ioFile.getAbsolutePath(); - } - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.variants.CachedResourceVariant#getCacheId() - */ - protected String getCacheId() { - return FileSystemPlugin.ID; - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.variants.IResourceVariant#getName() - */ - public String getName() { - return ioFile.getName(); - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.variants.IResourceVariant#isContainer() - */ - public boolean isContainer() { - return ioFile.isDirectory(); - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.variants.IResourceVariant#getContentIdentifier() - */ - public String getContentIdentifier() { - // Use the modification timestamp as the content identifier - return new Date(ioFile.lastModified()).toString(); - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.variants.IResourceVariant#asBytes() - */ - public byte[] asBytes() { - if (bytes == null) { - // For simplicity, convert the timestamp to it's string representation. - // A more optimal storage format would be the 8 bytes that make up the long. - bytes = Long.toString(ioFile.lastModified()).getBytes(); - } - return bytes; - } - - /** - * Return the files contained by the file of this resource variant. - * @return the files contained by the file of this resource variant. - */ - public FileSystemResourceVariant[] members() { - if (isContainer()) { - java.io.File[] members = ioFile.listFiles(); - FileSystemResourceVariant[] result = new FileSystemResourceVariant[members.length]; - for (int i = 0; i < members.length; i++) { - result[i] = new FileSystemResourceVariant(members[i]); - } - return result; - } - return new FileSystemResourceVariant[0]; - } - - /** - * @return - */ - public InputStream getContents() throws TeamException { - try { - return new BufferedInputStream(new FileInputStream(ioFile)); - } catch (FileNotFoundException e) { - throw new TeamException("Failed to fetch contents for " + getFilePath(), e); //$NON-NLS-1$ - } - } - - public java.io.File getFile(){ - return ioFile; - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemSubscriber.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemSubscriber.java deleted file mode 100644 index 9d96af05d..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemSubscriber.java +++ /dev/null @@ -1,151 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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.filesystem.subscriber; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.*; -import org.eclipse.core.runtime.*; -import org.eclipse.team.core.RepositoryProvider; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.core.synchronize.SyncInfo; -import org.eclipse.team.core.variants.*; -import org.eclipse.team.examples.filesystem.FileSystemPlugin; -import org.eclipse.team.examples.filesystem.FileSystemProvider; - -/** - * This is an example file system subscriber that overrides - * ThreeWaySubscriber. It uses a repository - * provider (<code>FileSystemProvider</code>) to determine and - * manage the roots and to create resource variants. It also makes - * use of a file system specific remote tree (<code>FileSystemRemoteTree</code>) - * for provided the remote tree access and refresh. - * - * @see ThreeWaySubscriber - * @see ThreeWaySynchronizer - * @see FileSystemProvider - * @see FileSystemRemoteTree - */ -public class FileSystemSubscriber extends ThreeWaySubscriber { - - private static FileSystemSubscriber instance; - - /** - * Return the file system subscriber singleton. - * @return the file system subscriber singleton. - */ - public static synchronized FileSystemSubscriber getInstance() { - if (instance == null) { - instance = new FileSystemSubscriber(); - } - return instance; - } - - /** - * Create the file system subscriber. - */ - private FileSystemSubscriber() { - super(new ThreeWaySynchronizer(new QualifiedName(FileSystemPlugin.ID, "workpsace-sync"))); //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.variants.ThreeWaySubscriber#getResourceVariant(org.eclipse.core.resources.IResource, byte[]) - */ - public IResourceVariant getResourceVariant(IResource resource, byte[] bytes) { - RepositoryProvider provider = RepositoryProvider.getProvider(resource.getProject(), FileSystemPlugin.PROVIDER_ID); - if (provider != null) { - return ((FileSystemProvider)provider).getResourceVariant(resource, bytes); - } - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.variants.ThreeWaySubscriber#createRemoteTree() - */ - protected ThreeWayRemoteTree createRemoteTree() { - return new FileSystemRemoteTree(this); - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.subscribers.Subscriber#getName() - */ - public String getName() { - return "File System Example"; //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.subscribers.Subscriber#roots() - */ - public IResource[] roots() { - List result = new ArrayList(); - IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); - for (int i = 0; i < projects.length; i++) { - IProject project = projects[i]; - if(project.isAccessible()) { - RepositoryProvider provider = RepositoryProvider.getProvider(project, FileSystemPlugin.PROVIDER_ID); - if(provider != null) { - result.add(project); - } - } - } - return (IProject[]) result.toArray(new IProject[result.size()]); - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.variants.ThreeWaySubscriber#handleRootChanged(org.eclipse.core.resources.IResource, boolean) - */ - public void handleRootChanged(IResource resource, boolean added) { - // Override to allow FileSystemProvider to signal the addition and removal of roots - super.handleRootChanged(resource, added); - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.variants.ResourceVariantTreeSubscriber#getSyncInfo(org.eclipse.core.resources.IResource, org.eclipse.team.core.variants.IResourceVariant, org.eclipse.team.core.variants.IResourceVariant) - */ - protected SyncInfo getSyncInfo(IResource local, IResourceVariant base, IResourceVariant remote) throws TeamException { - // Override to use a custom sync info - FileSystemSyncInfo info = new FileSystemSyncInfo(local, base, remote, this.getResourceComparator()); - info.init(); - return info; - } - - /** - * Make the resource in-sync. - * @param resource the resource - * @throws TeamException - */ - public void makeInSync(IResource resource) throws TeamException { - ThreeWaySynchronizer synchronizer = getSynchronizer(); - byte[] remoteBytes = synchronizer.getRemoteBytes(resource); - if (remoteBytes == null) { - if (!resource.exists()) - synchronizer.flush(resource, IResource.DEPTH_ZERO); - } else { - synchronizer.setBaseBytes(resource, remoteBytes); - } - } - - /** - * Make the change an outgoing change - * @param resource - * @throws TeamException - */ - public void markAsMerged(IResource resource, IProgressMonitor monitor) throws TeamException { - makeInSync(resource); - try { - resource.touch(monitor); - } catch (CoreException e) { - throw TeamException.asTeamException(e); - } - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemSyncInfo.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemSyncInfo.java deleted file mode 100644 index 58d0e7e28..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemSyncInfo.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 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.filesystem.subscriber; - -import org.eclipse.core.resources.IResource; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.core.synchronize.SyncInfo; -import org.eclipse.team.core.variants.IResourceVariant; -import org.eclipse.team.core.variants.IResourceVariantComparator; - -/** - * Provide a custom sync info that will report files that exist both - * locally and remotely as in-sync and will return a null base if there - * is an incoming change. - */ -public class FileSystemSyncInfo extends SyncInfo { - - public FileSystemSyncInfo(IResource local, IResourceVariant base, IResourceVariant remote, IResourceVariantComparator comparator) { - super(local, base, remote, comparator); - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.subscribers.SyncInfo#calculateKind(org.eclipse.core.runtime.IProgressMonitor) - */ - protected int calculateKind() throws TeamException { - if (getLocal().getType() != IResource.FILE) { - if (getLocal().exists() && getRemote() != null) { - return IN_SYNC; - } - } - return super.calculateKind(); - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.synchronize.SyncInfo#getBase() - */ - public IResourceVariant getBase() { - // If the kind has been set and there is an incoming change - // return null as the base since the server does not keep the - // base contents -// if ((getKind() & INCOMING) > 0) { -// return null; -// } - return super.getBase(); - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/CompoundResourceTraversal.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/CompoundResourceTraversal.java deleted file mode 100644 index 8fbb36d2f..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/CompoundResourceTraversal.java +++ /dev/null @@ -1,289 +0,0 @@ -/******************************************************************************* - * 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.filesystem.ui; - -import java.util.*; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.mapping.ResourceTraversal; -import org.eclipse.core.runtime.IPath; - -/** - * Helper class that accumulates several traversals in order - * to generate a final set of traversals and to perform certain - * queries on a set of traversals. - * - * TODO: This class was copied from the Team Core plugin since it was an internal - * class. It should probably be made API at some point. - */ -public class CompoundResourceTraversal { - - private Set deepFolders = new HashSet(); - private Set shallowFolders = new HashSet(); - private Set zeroFolders = new HashSet(); - private Set files = new HashSet(); - - public void addTraversals(ResourceTraversal[] traversals) { - for (int i = 0; i < traversals.length; i++) { - ResourceTraversal traversal = traversals[i]; - addTraversal(traversal); - } - } - - public void addTraversal(ResourceTraversal traversal) { - IResource[] resources = traversal.getResources(); - for (int i = 0; i < resources.length; i++) { - IResource resource = resources[i]; - addResource(resource, traversal.getDepth()); - } - } - - public void addResource(IResource resource, int depth) { - if (resource.getType() == IResource.FILE) { - if (!isCovered(resource, IResource.DEPTH_ZERO)) - files.add(resource); - } - switch (depth) { - case IResource.DEPTH_INFINITE: - addDeepFolder(resource); - break; - case IResource.DEPTH_ONE: - addShallowFolder(resource); - break; - case IResource.DEPTH_ZERO: - addZeroFolder(resource); - break; - } - } - - private void addShallowFolder(IResource resource) { - if (!isCovered(resource, IResource.DEPTH_ONE)) { - shallowFolders.add(resource); - removeDescendants(resource, IResource.DEPTH_ONE); - } - } - - public boolean isCovered(IResource resource, int depth) { - IPath fullPath = resource.getFullPath(); - // Regardless of the depth, look for a deep folder that covers the resource - for (Iterator iter = deepFolders.iterator(); iter.hasNext();) { - IResource deepFolder = (IResource) iter.next(); - if (deepFolder.getFullPath().isPrefixOf(fullPath)) { - return true; - } - } - // For files, look in the shallow folders and files - if (resource.getType() == IResource.FILE) { - return (shallowFolders.contains(resource.getParent()) || files.contains(resource)); - } - // For folders, look in appropriate sets - switch (depth) { - case IResource.DEPTH_ONE: - return (shallowFolders.contains(resource)); - case IResource.DEPTH_ZERO: - return (shallowFolders.contains(resource.getParent()) || zeroFolders.contains(resource)); - } - return false; - } - - private void addZeroFolder(IResource resource) { - if (!isCovered(resource, IResource.DEPTH_ZERO)) - zeroFolders.add(resource); - } - - private void addDeepFolder(IResource resource) { - if (!isCovered(resource, IResource.DEPTH_INFINITE)) { - deepFolders.add(resource); - removeDescendants(resource, IResource.DEPTH_INFINITE); - } - } - - private void removeDescendants(IResource resource, int depth) { - IPath fullPath = resource.getFullPath(); - // First, remove any files that are now covered - for (Iterator iter = files.iterator(); iter.hasNext();) { - IResource child = (IResource) iter.next(); - switch (depth) { - case IResource.DEPTH_INFINITE: - if (fullPath.isPrefixOf(child.getFullPath())) { - iter.remove(); - } - break; - case IResource.DEPTH_ONE: - if (fullPath.equals(child.getFullPath().removeLastSegments(1))) { - iter.remove(); - } - break; - } - } - // Now, remove any shallow folders - if (depth == IResource.DEPTH_INFINITE) { - for (Iterator iter = shallowFolders.iterator(); iter.hasNext();) { - IResource child = (IResource) iter.next(); - if (fullPath.isPrefixOf(child.getFullPath())) { - iter.remove(); - } - } - } - // Finally, remove any zero folders - for (Iterator iter = zeroFolders.iterator(); iter.hasNext();) { - IResource child = (IResource) iter.next(); - switch (depth) { - case IResource.DEPTH_INFINITE: - if (fullPath.isPrefixOf(child.getFullPath())) { - iter.remove(); - } - break; - case IResource.DEPTH_ONE: - // TODO: Is a zero folder covered by a shallow folder? - if (fullPath.equals(child.getFullPath().removeLastSegments(1))) { - iter.remove(); - } - break; - } - } - } - - public void add(CompoundResourceTraversal compoundTraversal) { - addResources( - (IResource[]) compoundTraversal.deepFolders.toArray(new IResource[compoundTraversal.deepFolders.size()]), - IResource.DEPTH_INFINITE); - addResources( - (IResource[]) compoundTraversal.shallowFolders.toArray(new IResource[compoundTraversal.shallowFolders.size()]), - IResource.DEPTH_ONE); - addResources( - (IResource[]) compoundTraversal.zeroFolders.toArray(new IResource[compoundTraversal.zeroFolders.size()]), - IResource.DEPTH_ZERO); - addResources( - (IResource[]) compoundTraversal.files.toArray(new IResource[compoundTraversal.files.size()]), - IResource.DEPTH_ZERO); - } - - public void addResources(IResource[] resources, int depth) { - for (int i = 0; i < resources.length; i++) { - IResource resource = resources[i]; - addResource(resource, depth); - } - - } - - /** - * Return the resources contained in the given traversals that are not covered by this traversal - * @param traversals the traversals being testes - * @return the resources contained in the given traversals that are not covered by this traversal - */ - public IResource[] getUncoveredResources(ResourceTraversal[] traversals) { - CompoundResourceTraversal newTraversals = new CompoundResourceTraversal(); - newTraversals.addTraversals(traversals); - return getUncoveredResources(newTraversals); - } - - /* - * Return any resources in the other traversal that are not covered by this traversal - */ - private IResource[] getUncoveredResources(CompoundResourceTraversal otherTraversal) { - Set result = new HashSet(); - for (Iterator iter = otherTraversal.files.iterator(); iter.hasNext();) { - IResource resource = (IResource) iter.next(); - if (!isCovered(resource, IResource.DEPTH_ZERO)) { - result.add(resource); - } - } - for (Iterator iter = otherTraversal.zeroFolders.iterator(); iter.hasNext();) { - IResource resource = (IResource) iter.next(); - if (!isCovered(resource, IResource.DEPTH_ZERO)) { - result.add(resource); - } - } - for (Iterator iter = otherTraversal.shallowFolders.iterator(); iter.hasNext();) { - IResource resource = (IResource) iter.next(); - if (!isCovered(resource, IResource.DEPTH_ONE)) { - result.add(resource); - } - } - for (Iterator iter = otherTraversal.deepFolders.iterator(); iter.hasNext();) { - IResource resource = (IResource) iter.next(); - if (!isCovered(resource, IResource.DEPTH_INFINITE)) { - result.add(resource); - } - } - return (IResource[]) result.toArray(new IResource[result.size()]); - } - - public ResourceTraversal[] asTraversals() { - List result = new ArrayList(); - if (!files.isEmpty() || ! zeroFolders.isEmpty()) { - Set combined = new HashSet(); - combined.addAll(files); - combined.addAll(zeroFolders); - result.add(new ResourceTraversal((IResource[]) combined.toArray(new IResource[combined.size()]), IResource.DEPTH_ZERO, IResource.NONE)); - } - if (!shallowFolders.isEmpty()) { - result.add(new ResourceTraversal((IResource[]) shallowFolders.toArray(new IResource[shallowFolders.size()]), IResource.DEPTH_ONE, IResource.NONE)); - } - if (!deepFolders.isEmpty()) { - result.add(new ResourceTraversal((IResource[]) deepFolders.toArray(new IResource[deepFolders.size()]), IResource.DEPTH_INFINITE, IResource.NONE)); - } - return (ResourceTraversal[]) result.toArray(new ResourceTraversal[result.size()]); - } - - public IResource[] getRoots() { - List result = new ArrayList(); - result.addAll(files); - result.addAll(zeroFolders); - result.addAll(shallowFolders); - result.addAll(deepFolders); - return (IResource[]) result.toArray(new IResource[result.size()]); - } - - public ResourceTraversal[] getUncoveredTraversals(ResourceTraversal[] traversals) { - CompoundResourceTraversal other = new CompoundResourceTraversal(); - other.addTraversals(traversals); - return getUncoveredTraversals(other); - } - - public ResourceTraversal[] getUncoveredTraversals(CompoundResourceTraversal otherTraversal) { - CompoundResourceTraversal uncovered = new CompoundResourceTraversal(); - for (Iterator iter = otherTraversal.files.iterator(); iter.hasNext();) { - IResource resource = (IResource) iter.next(); - if (!isCovered(resource, IResource.DEPTH_ZERO)) { - uncovered.addResource(resource, IResource.DEPTH_ZERO); - } - } - for (Iterator iter = otherTraversal.zeroFolders.iterator(); iter.hasNext();) { - IResource resource = (IResource) iter.next(); - if (!isCovered(resource, IResource.DEPTH_ZERO)) { - uncovered.addResource(resource, IResource.DEPTH_ZERO); - } - } - for (Iterator iter = otherTraversal.shallowFolders.iterator(); iter.hasNext();) { - IResource resource = (IResource) iter.next(); - if (!isCovered(resource, IResource.DEPTH_ONE)) { - uncovered.addResource(resource, IResource.DEPTH_ONE); - } - } - for (Iterator iter = otherTraversal.deepFolders.iterator(); iter.hasNext();) { - IResource resource = (IResource) iter.next(); - if (!isCovered(resource, IResource.DEPTH_INFINITE)) { - uncovered.addResource(resource, IResource.DEPTH_INFINITE); - } - } - return uncovered.asTraversals(); - } - - public void clear() { - deepFolders.clear(); - shallowFolders.clear(); - zeroFolders.clear(); - files.clear(); - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/ConfigurationWizard.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/ConfigurationWizard.java deleted file mode 100644 index 742f862b5..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/ConfigurationWizard.java +++ /dev/null @@ -1,113 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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.filesystem.ui; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.Path; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.jface.dialogs.IDialogSettings; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.team.core.RepositoryProvider; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.examples.filesystem.*; -import org.eclipse.team.ui.IConfigurationWizard; -import org.eclipse.team.ui.IConfigurationWizardExtension; -import org.eclipse.ui.IWorkbench; - -/** - * The file system configuration wizard used when associating a project - * the the file system provider. It is registered as a Team configuration wizard - * in the plugin.xml and is invoked when a user chooses to create a File System - * Repository Provider. One invoked, this wizard makes use of the <code>FileSystemMainPage</code> - * in order to obtain a target location on disk. - */ -public class ConfigurationWizard extends Wizard implements IConfigurationWizard, IAdaptable { - - IProject[] projects; - - FileSystemMainPage mainPage; - - public ConfigurationWizard() { - // retrieve the remembered dialog settings - IDialogSettings workbenchSettings = FileSystemPlugin.getPlugin().getDialogSettings(); - IDialogSettings section = workbenchSettings.getSection("ProviderExamplesWizard"); //$NON-NLS-1$ - if (section == null) { - section = workbenchSettings.addNewSection("ProviderExamplesWizard"); //$NON-NLS-1$ - } - setDialogSettings(section); - } - - /** - * Remember the project so we can map it on finish - * - * @see org.eclipse.team.ui.IConfigurationWizard#init(IWorkbench, IProject) - */ - public void init(IWorkbench workbench, IProject project) { - setProjects(new IProject[] { project } ); - } - - public void addPages() { - mainPage = new FileSystemMainPage( - "FileSystemMainPage", //$NON-NLS-1$ - Policy.bind("ConfigurationWizard.name"), //$NON-NLS-1$ - Policy.bind("ConfigurationWizard.description"), //$NON-NLS-1$ - null); - addPage(mainPage); - } - - /* - * Using the information entered in the main page set the provider for - * the given project. - */ - public boolean performFinish() { - mainPage.finish(null); - try { - if (projects.length == 1) { - // Map the provider and set the location - RepositoryProvider.map(projects[0], FileSystemPlugin.PROVIDER_ID); - FileSystemProvider provider = (FileSystemProvider) RepositoryProvider.getProvider(projects[0]); - provider.setTargetLocation(mainPage.getLocation()); - } else { - for (int i = 0; i < projects.length; i++) { - IProject project = projects[i]; - RepositoryProvider.map(project, FileSystemPlugin.PROVIDER_ID); - FileSystemProvider provider = (FileSystemProvider) RepositoryProvider.getProvider(project); - String path = new Path(mainPage.getLocation()).append(project.getName()).toOSString(); - provider.setTargetLocation(path); - } - } - } catch (TeamException e) { - ErrorDialog.openError( - getShell(), - Policy.bind("ConfigurationWizard.errorMapping"), //$NON-NLS-1$ - Policy.bind("ConfigurationWizard.error"), //$NON-NLS-1$ - e.getStatus()); - return false; - } - return true; - } - - public Object getAdapter(Class adapter) { - if (adapter == IConfigurationWizardExtension.class) { - return new IConfigurationWizardExtension(){ - public void init(IWorkbench workbench, IProject[] projects) { - setProjects(projects); - } - }; - } - return null; - } - - /* package */ void setProjects(IProject[] projects) { - this.projects = projects; - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/DisconnectAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/DisconnectAction.java deleted file mode 100644 index 71c0496bf..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/DisconnectAction.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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.filesystem.ui; - -import org.eclipse.core.resources.IProject; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.team.core.RepositoryProvider; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.examples.filesystem.Policy; -import org.eclipse.team.internal.ui.actions.TeamAction; - -/** - * Action for getting the contents of the selected resources - */ -public class DisconnectAction extends TeamAction { - - protected void execute(IAction action) { - IProject projects[] = getSelectedProjects(); - try { - for (int i = 0; i < projects.length; i++) { - RepositoryProvider.unmap(projects[i]); - } - } catch (TeamException e) { - ErrorDialog.openError(getShell(), Policy.bind("DisconnectAction.errorTitle"), null, e.getStatus()); //$NON-NLS-1$ - } - } - - /** - * @see TeamAction#isEnabled() - */ - public boolean isEnabled() { - return true; - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemAction.java deleted file mode 100644 index 95e3783fe..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemAction.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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.filesystem.ui; - -import java.util.*; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.mapping.ResourceMapping; -import org.eclipse.team.core.RepositoryProvider; -import org.eclipse.team.examples.filesystem.FileSystemPlugin; -import org.eclipse.team.internal.ui.actions.TeamAction; - -/** - * An abstract class that acts as a super class for FileSystemProvider actions. - * It provides some general methods applicable to multiple actions. - */ -public abstract class FileSystemAction extends TeamAction { - - /** - * @see org.eclipse.team.internal.ui.actions.TeamAction#isEnabled() - */ - public boolean isEnabled() { - return getSelectedMappings().length > 0; - } - - /** - * Split the resources into sets associated with their project/provider - */ - protected Map getRepositoryProviderMapping() { - HashMap result = new HashMap(); - IResource[] resources = getSelectedResources(); - for (int i = 0; i < resources.length; i++) { - RepositoryProvider provider = RepositoryProvider.getProvider(resources[i].getProject()); - List list = (List) result.get(provider); - if (list == null) { - list = new ArrayList(); - result.put(provider, list); - } - list.add(resources[i]); - } - return result; - } - - /** - * Return the selected resource mappings that are associated with the - * file system provider. - * @return the selected resource mappings that are associated with the - * file system provider. - */ - protected ResourceMapping[] getSelectedMappings() { - return getSelectedResourceMappings(FileSystemPlugin.PROVIDER_ID); - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemHistoryPage.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemHistoryPage.java deleted file mode 100644 index 9d0a744ae..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemHistoryPage.java +++ /dev/null @@ -1,246 +0,0 @@ -/******************************************************************************* - * 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.filesystem.ui; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.jface.action.IMenuListener; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.team.core.RepositoryProvider; -import org.eclipse.team.core.history.IFileHistory; -import org.eclipse.team.core.history.IFileRevision; -import org.eclipse.team.examples.filesystem.FileSystemProvider; -import org.eclipse.team.examples.filesystem.history.FileSystemHistory; -import org.eclipse.team.internal.ui.Utils; -import org.eclipse.team.ui.history.HistoryPage; -import org.eclipse.team.ui.history.IHistoryPageSite; -import org.eclipse.ui.IWorkbenchActionConstants; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchPartSite; - -public class FileSystemHistoryPage extends HistoryPage { - - /* private */IFile file; - /* private */FileSystemHistory fileSystemHistory; - /* private */IFileRevision[] entries; - /* private */IFileRevision currentSelection; - - private FileSystemTableProvider fileSystemTableProvider; - /* private */TableViewer tableViewer; - private Composite localComposite; - - /* private */OpenFileSystemRevisionAction openAction; - - boolean shutdown = false; - - private RefreshFileHistory refreshFileHistoryJob; - - private class RefreshFileHistory extends Job { - /* private */FileSystemHistory fileHistory; - - public RefreshFileHistory() { - super("Fetching FileSystem revisions..."); //$NON-NLS-1$ - } - - public void setFileHistory(FileSystemHistory fileHistory) { - this.fileHistory = fileHistory; - } - - public IStatus run(IProgressMonitor monitor) { - - IStatus status = Status.OK_STATUS; - - if (fileHistory != null && !shutdown) { - fileHistory.refresh(monitor); - //Internal code used for convenience - you can use - //your own here - Utils.asyncExec(new Runnable() { - public void run() { - tableViewer.setInput(fileHistory); - } - }, tableViewer); - } - - return status; - } - } - - public boolean inputSet() { - IFile tempFile = getFile(); - this.file = tempFile; - if (tempFile == null) - return false; - - //blank current input only after we're sure that we have a file - //to fetch history for - this.tableViewer.setInput(null); - - fileSystemHistory = new FileSystemHistory(file); - - refreshHistory(); - return true; - } - - private IWorkbenchPartSite getWorkbenchSite(IHistoryPageSite parentSite) { - IWorkbenchPart part = parentSite.getPart(); - if (part != null) - return part.getSite(); - return null; - } - - private IFile getFile() { - Object obj = getInput(); - if (obj instanceof IFile) - return (IFile) obj; - - return null; - } - - public void createControl(Composite parent) { - - localComposite = new Composite(parent, SWT.NONE); - GridLayout layout = new GridLayout(); - layout.marginHeight = 0; - layout.marginWidth = 0; - localComposite.setLayout(layout); - GridData data = new GridData(GridData.FILL_BOTH); - data.grabExcessVerticalSpace = true; - localComposite.setLayoutData(data); - - tableViewer = createTable(localComposite); - - contributeActions(); - - } - - private void contributeActions() { - openAction = new OpenFileSystemRevisionAction("Open"); //$NON-NLS-1$ - tableViewer.getTable().addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - openAction.selectionChanged((IStructuredSelection) tableViewer.getSelection()); - } - }); - openAction.setPage(this); - //Contribute actions to popup menu - MenuManager menuMgr = new MenuManager(); - Menu menu = menuMgr.createContextMenu(tableViewer.getTable()); - menuMgr.addMenuListener(new IMenuListener() { - public void menuAboutToShow(IMenuManager menuMgr) { - menuMgr.add(new Separator(IWorkbenchActionConstants.GROUP_FILE)); - menuMgr.add(openAction); - } - }); - menuMgr.setRemoveAllWhenShown(true); - tableViewer.getTable().setMenu(menu); - } - - private TableViewer createTable(Composite parent) { - fileSystemTableProvider = new FileSystemTableProvider(); - TableViewer viewer = fileSystemTableProvider.createTable(parent); - viewer.setContentProvider(new IStructuredContentProvider() { - - public Object[] getElements(Object inputElement) { - // The entries of already been fetch so return them - if (entries != null) - return entries; - - final IFileHistory fileHistory = (IFileHistory) inputElement; - entries = fileHistory.getFileRevisions(); - - return entries; - } - - public void dispose() { - // TODO Auto-generated method stub - - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - entries = null; - } - - }); - return viewer; - } - - public Control getControl() { - return localComposite; - } - - public void setFocus() { - localComposite.setFocus(); - } - - public String getDescription() { - if (file != null) - return file.getFullPath().toString(); - - return null; - } - - public String getName() { - if (file != null) - return file.getName(); - - return ""; //$NON-NLS-1$ - } - - public boolean isValidInput(Object object) { - - if (object instanceof IResource && ((IResource) object).getType() == IResource.FILE) { - RepositoryProvider provider = RepositoryProvider.getProvider(((IFile) object).getProject()); - if (provider != null && provider instanceof FileSystemProvider) - return true; - } - - return false; - } - - public void refresh() { - refreshHistory(); - } - - private void refreshHistory() { - if (refreshFileHistoryJob == null) - refreshFileHistoryJob = new RefreshFileHistory(); - - if (refreshFileHistoryJob.getState() != Job.NONE) { - refreshFileHistoryJob.cancel(); - } - refreshFileHistoryJob.setFileHistory(fileSystemHistory); - IHistoryPageSite parentSite = getHistoryPageSite(); - //Internal code used for convenience - you can use your own here - Utils.schedule(refreshFileHistoryJob, getWorkbenchSite(parentSite)); - } - - public Object getAdapter(Class adapter) { - return null; - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemHistoryPageSource.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemHistoryPageSource.java deleted file mode 100644 index 379fa931d..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemHistoryPageSource.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * 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.filesystem.ui; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.team.core.RepositoryProvider; -import org.eclipse.team.examples.filesystem.FileSystemProvider; -import org.eclipse.team.ui.history.HistoryPageSource; -import org.eclipse.ui.part.Page; - -public class FileSystemHistoryPageSource extends HistoryPageSource { - - public boolean canShowHistoryFor(Object object) { - if (object instanceof IResource && ((IResource) object).getType() == IResource.FILE) { - RepositoryProvider provider = RepositoryProvider.getProvider(((IFile) object).getProject()); - if (provider instanceof FileSystemProvider) - return true; - } - - return false; - } - - public Page createPage(Object object) { - FileSystemHistoryPage page = new FileSystemHistoryPage(); - return page; - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemMainPage.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemMainPage.java deleted file mode 100644 index 0efeae81e..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemMainPage.java +++ /dev/null @@ -1,300 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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.filesystem.ui; - -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.IDialogSettings; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.DirectoryDialog; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Text; -import org.eclipse.team.examples.filesystem.Policy; - -/** - * This class provides the main page of the file system repository configuration wizard. - * It allows the user to select a location on disk. Once the page is finished, the - * location can be accessed using the <code>getLocation()</code> method. - */ -public class FileSystemMainPage extends WizardPage { - - private static final int COMBO_HISTORY_LENGTH = 5; - - String location; - Combo locationCombo; - - /* - * WizardPage constructor comment. - * @param pageName the name of the page - * @param title the title of the page - * @param description the description of the page - * @param titleImage the image for the page - */ - - public FileSystemMainPage(String pageName, String title, String description, ImageDescriptor titleImage) { - super(pageName, title, titleImage); - setDescription(description); - setTitle(title); - } - - /* - * Creates a new checkbox instance and sets the default layout data. - * - * @param group the composite in which to create the checkbox - * @param label the string to set into the checkbox - * @return the new checkbox - */ - protected Button createCheckBox(Composite group, String label) { - Button button = new Button(group, SWT.CHECK | SWT.LEFT); - button.setText(label); - GridData data = new GridData(); - data.horizontalSpan = 2; - button.setLayoutData(data); - return button; - } - - /* - * Utility method that creates a combo box - * - * @param parent the parent for the new label - * @return the new widget - */ - protected Combo createCombo(Composite parent) { - Combo combo = new Combo(parent, SWT.READ_ONLY); - GridData data = new GridData(GridData.FILL_HORIZONTAL); - data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH; - combo.setLayoutData(data); - return combo; - } - - /* - * Creates composite control and sets the default layout data. - * - * @param parent the parent of the new composite - * @param numColumns the number of columns for the new composite - * @return the newly-created coposite - */ - protected Composite createComposite(Composite parent, int numColumns) { - Composite composite = new Composite(parent, SWT.NULL); - - // GridLayout - GridLayout layout = new GridLayout(); - layout.numColumns = numColumns; - composite.setLayout(layout); - - // GridData - GridData data = new GridData(); - data.verticalAlignment = GridData.FILL; - data.horizontalAlignment = GridData.FILL; - composite.setLayoutData(data); - return composite; - } - - /* - * Utility method that creates a label instance - * and sets the default layout data. - * - * @param parent the parent for the new label - * @param text the text for the new label - * @return the new label - */ - protected Label createLabel(Composite parent, String text) { - Label label = new Label(parent, SWT.LEFT); - label.setText(text); - GridData data = new GridData(); - data.horizontalSpan = 1; - data.horizontalAlignment = GridData.FILL; - label.setLayoutData(data); - return label; - } - - /* - * Create a text field specific for this application - * - * @param parent the parent of the new text field - * @return the new text field - */ - protected Text createTextField(Composite parent) { - Text text = new Text(parent, SWT.SINGLE | SWT.BORDER); - GridData data = new GridData(GridData.FILL_HORIZONTAL); - data.verticalAlignment = GridData.CENTER; - data.grabExcessVerticalSpace = false; - data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH; - text.setLayoutData(data); - return text; - } - - /* - * Adds an entry to a history, while taking care of duplicate history items - * and excessively long histories. The assumption is made that all histories - * should be of length <code>ConfigurationWizardMainPage.COMBO_HISTORY_LENGTH</code>. - * - * @param history the current history - * @param newEntry the entry to add to the history - * @return the history with the new entry appended - */ - protected String[] addToHistory(String[] history, String newEntry) { - ArrayList l = new ArrayList(Arrays.asList(history)); - addToHistory(l, newEntry); - String[] r = new String[l.size()]; - l.toArray(r); - return r; - } - - /* - * Adds an entry to a history, while taking care of duplicate history items - * and excessively long histories. The assumption is made that all histories - * should be of length <code>ConfigurationWizardMainPage.COMBO_HISTORY_LENGTH</code>. - * - * @param history the current history - * @param newEntry the entry to add to the history - */ - protected void addToHistory(List history, String newEntry) { - history.remove(newEntry); - history.add(0,newEntry); - - // since only one new item was added, we can be over the limit - // by at most one item - if (history.size() > COMBO_HISTORY_LENGTH) - history.remove(COMBO_HISTORY_LENGTH); - } - - /* - * Utility method to create an editable combo box - * - * @param parent the parent of the combo box - * @return the created combo - */ - protected Combo createEditableCombo(Composite parent) { - Combo combo = new Combo(parent, SWT.NULL); - GridData data = new GridData(GridData.FILL_HORIZONTAL); - data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH; - combo.setLayoutData(data); - return combo; - } - - // Dialog store id constants - private static final String STORE_LOCATION = - "ExamplesFSWizardMainPage.STORE_LOCATION";//$NON-NLS-1$ - - public void createControl(Composite parent) { - Composite composite = new Composite(parent, SWT.NULL); - composite.setLayoutData(new GridData(GridData.FILL_BOTH)); - GridLayout layout = new GridLayout(); - layout.numColumns = 2; - composite.setLayout(layout); - setControl(composite); - - Label label = new Label(composite, SWT.NULL); - label.setText(Policy.bind("FileSystemMainPage.location")); //$NON-NLS-1$ - label.setLayoutData(new GridData()); - - locationCombo = createEditableCombo(composite); - locationCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - locationCombo.addListener(SWT.Modify, new Listener() { - public void handleEvent(Event e) { - location = ((Combo)e.widget).getText(); - FileSystemMainPage.this.validateFields(); - } - }); - - locationCombo.setFocus(); - - new Label(composite, SWT.NULL); - Button browse = new Button(composite, SWT.NULL); - browse.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END)); - browse.setText(Policy.bind("FileSystemMainPage.browseDir")); //$NON-NLS-1$ - browse.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event event) { - DirectoryDialog d = new DirectoryDialog(getShell()); - String directory = d.open(); - if(directory!=null) { - locationCombo.setText(directory); - } - } - }); - - initializeValues(); - validateFields(); - } - - public String getLocation() { - return location; - } - - public boolean finish(IProgressMonitor monitor) { - saveWidgetValues(); - return true; - } - /** - * Initializes states of the controls. - */ - private void initializeValues() { - IDialogSettings settings = getDialogSettings(); - if (settings != null) { - String[] locations = settings.getArray(STORE_LOCATION); - if (locations != null) { - for (int i = 0; i < locations.length; i++) { - locationCombo.add(locations[i]); - } - locationCombo.select(0); - } - } - } - /** - * Saves the widget values - */ - private void saveWidgetValues() { - // Update history - IDialogSettings settings = getDialogSettings(); - if (settings != null) { - String[] locations = settings.getArray(STORE_LOCATION); - if (locations == null) locations = new String[0]; - locations = addToHistory(locations, locationCombo.getText()); - settings.put(STORE_LOCATION, locations); - } - } - - /* - * Validates the contents of the editable fields and set page completion - * and error messages appropriately. - */ - void validateFields() { - String location = locationCombo.getText(); - if (location.length() == 0) { - setErrorMessage(null); - setPageComplete(false); - return; - } - File file = new File(location); - if(!file.exists() || !file.isDirectory()) { - setErrorMessage(Policy.bind("FileSystemMainPage.notValidLocation")); //$NON-NLS-1$ - setPageComplete(false); - return; - } - setErrorMessage(null); - setPageComplete(true); - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemOperation.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemOperation.java deleted file mode 100644 index 2991cf679..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemOperation.java +++ /dev/null @@ -1,152 +0,0 @@ -/******************************************************************************* - * 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.filesystem.ui; - -import java.lang.reflect.InvocationTargetException; -import java.util.*; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.mapping.ResourceMapping; -import org.eclipse.core.resources.mapping.ResourceTraversal; -import org.eclipse.core.runtime.*; -import org.eclipse.team.core.RepositoryProvider; -import org.eclipse.team.core.mapping.ISynchronizationScope; -import org.eclipse.team.core.subscribers.SubscriberScopeManager; -import org.eclipse.team.examples.filesystem.FileSystemPlugin; -import org.eclipse.team.examples.filesystem.FileSystemProvider; -import org.eclipse.team.examples.filesystem.subscriber.FileSystemSubscriber; -import org.eclipse.team.ui.synchronize.ModelOperation; -import org.eclipse.ui.IWorkbenchPart; - -public abstract class FileSystemOperation extends ModelOperation { - - /** - * Create a scope manager for the file system example. - * @param name the name of the manager - * @param inputMappings the input mappings - * @return a scope manager - */ - public static SubscriberScopeManager createScopeManager(String name, ResourceMapping[] inputMappings) { - return new SubscriberScopeManager(name, inputMappings, FileSystemSubscriber.getInstance(), true); - } - - /** - * Create a file system operation. - * @param part the part from which the operation was launched - * @param manager the scope manager that provides the input to the operation - */ - protected FileSystemOperation(IWorkbenchPart part, SubscriberScopeManager manager) { - super(part, manager); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.ModelOperation#execute(org.eclipse.core.runtime.IProgressMonitor) - */ - protected void execute(IProgressMonitor monitor) throws InvocationTargetException { - try { - Map providerToTraversals = getProviderToTraversalsMap(); - monitor.beginTask(getTaskName(), providerToTraversals.size() * 100); - monitor.setTaskName(getTaskName()); - for (Iterator iter = providerToTraversals.keySet().iterator(); iter.hasNext();) { - FileSystemProvider provider = (FileSystemProvider) iter.next(); - ResourceTraversal[] traversals = getTraversals(providerToTraversals, provider); - execute(provider, - traversals, - new SubProgressMonitor(monitor, 100)); - } - } catch (CoreException e) { - throw new InvocationTargetException(e); - } finally { - monitor.done(); - } - } - - /** - * Return a map of FileSystemProvider to ResourceTraversals. - * @return a map of FileSystemProvider to ResourceTraversals - */ - private Map getProviderToTraversalsMap() { - HashMap result = new HashMap(); - ISynchronizationScope scope = getScope(); - ResourceMapping[] mappings = scope.getMappings(); - for (int i = 0; i < mappings.length; i++) { - ResourceMapping mapping = mappings[i]; - ResourceTraversal[] traversals = scope.getTraversals(mapping); - for (int j = 0; j < traversals.length; j++) { - ResourceTraversal traversal = traversals[j]; - IResource[] resources = traversal.getResources(); - for (int k = 0; k < resources.length; k++) { - IResource resource = resources[k]; - recordResourceAndDepth(result, resource, traversal.getDepth()); - } - } - } - return result; - } - - /** - * Return the file system provider associated with the given project or <code>null</code> - * if the project is not mapped to the file system provider. - * @param project the project - * @return the file system provider associated with the given project - */ - protected FileSystemProvider getProviderFor(IProject project) { - return (FileSystemProvider)RepositoryProvider.getProvider(project, FileSystemPlugin.PROVIDER_ID); - } - - private void recordResourceAndDepth(HashMap providerToTraversals, IResource resource, int depth) { - FileSystemProvider provider = getProviderFor(resource.getProject()); - if (provider != null) { - CompoundResourceTraversal traversal = (CompoundResourceTraversal)providerToTraversals.get(provider); - if (traversal == null) { - traversal = new CompoundResourceTraversal(); - providerToTraversals.put(provider, traversal); - } - traversal.addResource(resource, depth); - } - } - - /** - * Return the traversals that were accumulated for the given provider by the - * {@link #getProviderToTraversalsMap()} method. - * @param providerToTraversals the provider to traversals map - * @param provider the provider - * @return the traversals for the given provider - */ - private ResourceTraversal[] getTraversals(Map providerToTraversals, FileSystemProvider provider) { - CompoundResourceTraversal traversal = (CompoundResourceTraversal)providerToTraversals.get(provider); - return traversal.asTraversals(); - } - - /** - * Execute the operation for the given provider and traversals. - * @param provider the provider - * @param traversals the traversals to be operated on - * @param monitor a progress monitor - * @throws CoreException - */ - protected abstract void execute(FileSystemProvider provider, ResourceTraversal[] traversals, IProgressMonitor monitor) throws CoreException; - - /** - * Return the task name for this operation. - * @return the task name for this operation - */ - protected abstract String getTaskName(); - - /* (non-Javadoc) - * @see org.eclipse.team.ui.TeamOperation#canRunAsJob() - */ - protected boolean canRunAsJob() { - return true; - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemPropertiesPage.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemPropertiesPage.java deleted file mode 100644 index 9c892fb04..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemPropertiesPage.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.filesystem.ui; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.*; -import org.eclipse.ui.dialogs.PropertyPage; -/* - * A property page which displays the file system specific properties - * for the selected resource. - */ -public class FileSystemPropertiesPage extends PropertyPage { - // The resource to show properties for - protected IResource resource; - - /* - * Creates a key-value property pair in the given parent. - * - * @param parent the parent for the labels - * @param left the string for the left label - * @param right the string for the right label - */ - protected void createPair(Composite parent, String left, String right) { - Label label = new Label(parent, SWT.NONE); - label.setText(left); - - label = new Label(parent, SWT.NONE); - label.setText(right); - label.setToolTipText(right); - label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - } - - /* - * Returns the element selected when the properties was run - * @return the selected element - */ - protected IResource getSelectedElement() { - // get the resource that is the source of this property page - IResource resource = null; - IAdaptable element = getElement(); - if (element instanceof IResource) { - resource = (IResource)element; - } else { - Object adapter = element.getAdapter(IResource.class); - if (adapter instanceof IResource) { - resource = (IResource)adapter; - } - } - return resource; - } - - /* - * @see PreferencePage#createContents(Composite) - */ - protected Control createContents(Composite parent) { - Composite composite = new Composite(parent, SWT.NONE); - GridLayout layout = new GridLayout(); - layout.numColumns = 2; - layout.marginHeight = layout.marginWidth = 0; - composite.setLayout(layout); - composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - return composite; - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemRevisionEditorInput.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemRevisionEditorInput.java deleted file mode 100644 index 41757a4d6..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemRevisionEditorInput.java +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 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.filesystem.ui; - -import java.text.DateFormat; -import java.util.Date; - -import org.eclipse.core.resources.IFileState; -import org.eclipse.core.resources.IStorage; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.PlatformObject; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.team.core.history.IFileRevision; -import org.eclipse.ui.IPersistableElement; -import org.eclipse.ui.IStorageEditorInput; -import org.eclipse.ui.model.IWorkbenchAdapter; - -public class FileSystemRevisionEditorInput extends PlatformObject implements IWorkbenchAdapter, IStorageEditorInput { - - private IFileRevision fileRevision; - private IStorage storage; - - public FileSystemRevisionEditorInput(IFileRevision revision) { - this.fileRevision = revision; - try { - this.storage = revision.getStorage(new NullProgressMonitor()); - } catch (CoreException e) { - // ignore - } - } - - public Object[] getChildren(Object o) { - return new Object[0]; - } - - public ImageDescriptor getImageDescriptor(Object object) { - return null; - } - - public String getLabel(Object o) { - if (storage != null) { - return storage.getName(); - } - return ""; //$NON-NLS-1$ - } - - public Object getParent(Object o) { - return null; - } - - public IStorage getStorage() { - return storage; - } - - public boolean exists() { - return true; - } - - public ImageDescriptor getImageDescriptor() { - return null; - } - - public String getName() { - if (fileRevision != null) - return fileRevision.getName() + " " + fileRevision.getContentIdentifier(); //$NON-NLS-1$ - - if (storage != null) { - return storage.getName() + " " + DateFormat.getInstance().format(new Date(((IFileState) storage).getModificationTime())); //$NON-NLS-1$ - } - return ""; //$NON-NLS-1$ - } - - public IPersistableElement getPersistable() { - return null; - } - - public String getToolTipText() { - if (fileRevision != null) - return getStorage().getFullPath().toString(); - - if (storage != null) - return storage.getFullPath().toString(); - - return ""; //$NON-NLS-1$ - } - - public Object getAdapter(Class adapter) { - if (adapter == IWorkbenchAdapter.class) { - return this; - } - if (adapter == IFileRevision.class) - return fileRevision; - else if (adapter == IFileState.class){ - if (storage != null && storage instanceof IFileState) - return storage; - } - return super.getAdapter(adapter); - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemSynchronizeParticipant.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemSynchronizeParticipant.java deleted file mode 100644 index 6b31a91cc..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemSynchronizeParticipant.java +++ /dev/null @@ -1,208 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 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.filesystem.ui; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.mapping.ResourceMapping; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jface.action.*; -import org.eclipse.jface.viewers.ILabelDecorator; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.swt.graphics.Image; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.core.mapping.ISynchronizationScopeManager; -import org.eclipse.team.core.mapping.provider.MergeContext; -import org.eclipse.team.core.mapping.provider.SynchronizationContext; -import org.eclipse.team.core.synchronize.SyncInfo; -import org.eclipse.team.core.variants.IResourceVariant; -import org.eclipse.team.examples.filesystem.FileSystemPlugin; -import org.eclipse.team.examples.filesystem.subscriber.FileSystemMergeContext; -import org.eclipse.team.examples.filesystem.subscriber.FileSystemSubscriber; -import org.eclipse.team.internal.ui.TeamUIPlugin; -import org.eclipse.team.ui.TeamUI; -import org.eclipse.team.ui.mapping.SynchronizationActionProvider; -import org.eclipse.team.ui.synchronize.*; - - -/** - * This is an example synchronize participant for the file system provider. It will allow - * showing synchronization state for local resources mapped to a remote file system - * location. - * - * @since 3.0 - */ -public class FileSystemSynchronizeParticipant extends ModelSynchronizeParticipant { - - /** - * The participant id for the org.eclipse.team.ui.synchronizeParticipant extension point. - */ - public static final String ID = "org.eclipse.team.examples.filesystem.participant"; //$NON-NLS-1$ - - /** - * The viewer id for the org.eclipse.ui.navigator.viewer extension point. - */ - public static final String VIEWER_ID = "org.eclipse.team.examples.filesystem.syncViewer"; //$NON-NLS-1$ - - /** - * Custom menu groups included in the viewer definition in the plugin.xml. - */ - public static final String CONTEXT_MENU_PUT_GROUP_1 = "put"; //$NON-NLS-1$ - public static final String CONTEXT_MENU_OVERWRITE_GROUP_1 = "overwrite"; //$NON-NLS-1$ - - /** - * A custom label decorator that will show the remote mapped path for each - * file. - */ - public class FileSystemParticipantLabelDecorator extends LabelProvider implements ILabelDecorator { - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.ILabelDecorator#decorateImage(org.eclipse.swt.graphics.Image, java.lang.Object) - */ - public Image decorateImage(Image image, Object element) { - return image; - } - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.ILabelDecorator#decorateText(java.lang.String, java.lang.Object) - */ - public String decorateText(String text, Object element) { - try { - if (element instanceof ISynchronizeModelElement) { - IResource resource = ((ISynchronizeModelElement) element).getResource(); - if (resource != null && resource.getType() == IResource.FILE) { - SyncInfo info = FileSystemSubscriber.getInstance().getSyncInfo(resource); - IResourceVariant variant = info.getRemote(); - if (variant != null) { - return text + " (" + variant.getContentIdentifier() + ")"; - } - } - } - } catch (TeamException e) { - FileSystemPlugin.log(e); - } - return null; - } - } - - /** - * Action group that contributes the get an put menus to the context menu - * in the synchronize view - */ - public class FileSystemParticipantActionGroup extends ModelSynchronizeParticipantActionGroup { - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.SynchronizePageActionGroup#initialize(org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration) - */ - public void initialize(ISynchronizePageConfiguration configuration) { - super.initialize(configuration); - appendToGroup( - ISynchronizePageConfiguration.P_CONTEXT_MENU, - CONTEXT_MENU_PUT_GROUP_1, - new ModelPutAction("Put", configuration)); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.operations.MergeActionGroup#configureMergeAction(java.lang.String, org.eclipse.jface.action.Action) - */ - protected void configureMergeAction(String mergeActionId, Action action) { - if (mergeActionId == SynchronizationActionProvider.MERGE_ACTION_ID) { - // Custom label for overwrite - action.setText("Get"); - } else if (mergeActionId == SynchronizationActionProvider.MARK_AS_MERGE_ACTION_ID) { - // Custom label for mark-as-merged - action.setText("Ignore Remote"); - } else { - super.configureMergeAction(mergeActionId, action); - } - } - - protected void addToContextMenu(String mergeActionId, Action action, IMenuManager manager) { - IContributionItem group = null; - if (mergeActionId == SynchronizationActionProvider.MERGE_ACTION_ID) { - // This could be left out since this is the default group but it is here for illustration - group = manager.find(MERGE_ACTION_GROUP); - } else if (mergeActionId == SynchronizationActionProvider.OVERWRITE_ACTION_ID) { - // This is a custom group for the overwrite command - group = manager.find(CONTEXT_MENU_OVERWRITE_GROUP_1); - } else if (mergeActionId == SynchronizationActionProvider.MARK_AS_MERGE_ACTION_ID) { - // This could be left out since this is the default group but it is here for illustration - group = manager.find(OTHER_ACTION_GROUP); - } else { - super.addToContextMenu(mergeActionId, action, manager); - return; - } - if (group != null) { - manager.appendToGroup(group.getId(), action); - } else { - manager.add(action); - } - } - - } - - /** - * Create a file system participant. This method is invoked by the - * Synchronize view when a persisted participant is being restored. - * Participants that are persisted must override the - * {@link #restoreContext(ISynchronizationScopeManager)} method to recreate - * the context and may also need to override the - * {@link #createScopeManager(ResourceMapping[])} method if they require a - * custom scope manager. - */ - public FileSystemSynchronizeParticipant() { - super(); - } - - /** - * Create the participant for the given context. This method is used - * by the file system plugin to create a participant and then add it to - * the sync view (or show it is some other container). - * @param context the synchronization context - */ - public FileSystemSynchronizeParticipant(SynchronizationContext context) { - super(context); - try { - setInitializationData(TeamUI.getSynchronizeManager().getParticipantDescriptor(ID)); - } catch (CoreException e) { - TeamUIPlugin.log(e); - } - setSecondaryId(Long.toString(System.currentTimeMillis())); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.subscribers.SubscriberParticipant#initializeConfiguration(org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration) - */ - protected void initializeConfiguration(ISynchronizePageConfiguration configuration) { - super.initializeConfiguration(configuration); - configuration.setProperty(ISynchronizePageConfiguration.P_VIEWER_ID, VIEWER_ID); - - // Add the label decorator - configuration.addLabelDecorator(new FileSystemParticipantLabelDecorator()); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.ModelSynchronizeParticipant#createMergeActionGroup() - */ - protected ModelSynchronizeParticipantActionGroup createMergeActionGroup() { - return new FileSystemParticipantActionGroup(); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.ModelSynchronizeParticipant#restoreContext(org.eclipse.team.core.mapping.ISynchronizationScopeManager) - */ - protected MergeContext restoreContext(ISynchronizationScopeManager manager) { - return new FileSystemMergeContext(manager); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.ModelSynchronizeParticipant#createScopeManager(org.eclipse.core.resources.mapping.ResourceMapping[]) - */ - protected ISynchronizationScopeManager createScopeManager(ResourceMapping[] mappings) { - return FileSystemOperation.createScopeManager(getName(), mappings); - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemTableProvider.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemTableProvider.java deleted file mode 100644 index 85004fda1..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemTableProvider.java +++ /dev/null @@ -1,264 +0,0 @@ -/******************************************************************************* - * 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.filesystem.ui; - -import java.text.DateFormat; -import java.util.Date; - -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.jface.viewers.ColumnWeightData; -import org.eclipse.jface.viewers.IColorProvider; -import org.eclipse.jface.viewers.IFontProvider; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.TableLayout; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerSorter; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.team.core.history.IFileRevision; -import org.eclipse.team.examples.filesystem.history.FileSystemFileRevision; - -public class FileSystemTableProvider { - - //column constants - private static final int COL_TYPE = 0; - private static final int COL_DATE = 1; - - public TableViewer createTable(Composite parent) { - Table table = new Table(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION); - table.setHeaderVisible(true); - table.setLinesVisible(true); - GridData data = new GridData(GridData.FILL_BOTH); - table.setLayoutData(data); - - TableLayout layout = new TableLayout(); - table.setLayout(layout); - - TableViewer viewer = new TableViewer(table); - - createColumns(table, layout, viewer); - - viewer.setLabelProvider(new HistoryLabelProvider()); - - // By default, reverse sort by revision. - HistorySorter sorter = new HistorySorter(COL_DATE); - sorter.setReversed(true); - viewer.setSorter(sorter); - - return viewer; - } - - /** - * Creates the columns for the history table. - */ - private void createColumns(Table table, TableLayout layout, TableViewer viewer) { - SelectionListener headerListener = getColumnListener(viewer); - // revision - TableColumn col = new TableColumn(table, SWT.NONE); - col.setResizable(true); - col.setText("Revision"); //$NON-NLS-1$ - col.addSelectionListener(headerListener); - layout.addColumnData(new ColumnWeightData(20, true)); - - // creation date - col = new TableColumn(table, SWT.NONE); - col.setResizable(true); - col.setText("Date"); //$NON-NLS-1$ - col.addSelectionListener(headerListener); - layout.addColumnData(new ColumnWeightData(20, true)); - - } - - class HistoryLabelProvider extends LabelProvider implements ITableLabelProvider, IColorProvider, IFontProvider { - - public Image getColumnImage(Object element, int columnIndex) { - return null; - } - - public String getColumnText(Object element, int columnIndex) { - IFileRevision entry = adaptToFileRevision(element); - if (entry == null) - return ""; //$NON-NLS-1$ - switch (columnIndex) { - case COL_TYPE : - if (entry instanceof FileSystemFileRevision) - return "FileSystem revision"; //$NON-NLS-1$ - - return "Local history revision"; //$NON-NLS-1$ - case COL_DATE : - long date = entry.getTimestamp(); - Date dateFromLong = new Date(date); - return DateFormat.getInstance().format(dateFromLong); - } - return ""; //$NON-NLS-1$ - } - - public Color getBackground(Object element) { - return null; - } - - public Color getForeground(Object element) { - return null; - } - - public Font getFont(Object element) { - return null; - } - - } - - /** - * The history sorter - */ - class HistorySorter extends ViewerSorter { - private boolean reversed = false; - private int columnNumber; - - // column headings: "Type" "Date" - private int[][] SORT_ORDERS_BY_COLUMN = { {COL_DATE, COL_TYPE} /* date */, {COL_TYPE, COL_DATE} /* type */ - }; - - /** - * The constructor. - * @param columnNumber - */ - public HistorySorter(int columnNumber) { - this.columnNumber = columnNumber; - } - - /** - * Compares two log entries, sorting first by the main column of this sorter, - * then by subsequent columns, depending on the column sort order. - */ - public int compare(Viewer compareViewer, Object o1, Object o2) { - /*if (o1 instanceof AbstractCVSHistoryCategory || o2 instanceof AbstractCVSHistoryCategory) - return 0;*/ - - IFileRevision e1 = adaptToFileRevision(o1); - IFileRevision e2 = adaptToFileRevision(o2); - int result = 0; - if (e1 == null || e2 == null) { - result = super.compare(compareViewer, o1, o2); - } else { - int[] columnSortOrder = SORT_ORDERS_BY_COLUMN[columnNumber]; - for (int i = 0; i < columnSortOrder.length; ++i) { - result = compareColumnValue(columnSortOrder[i], e1, e2); - if (result != 0) - break; - } - } - if (reversed) - result = -result; - return result; - } - - /** - * Compares two markers, based only on the value of the specified column. - */ - int compareColumnValue(int columnNumber, IFileRevision e1, IFileRevision e2) { - switch (columnNumber) { - case 0 : /* date */ - long date1 = e1.getTimestamp(); - long date2 = e2.getTimestamp(); - if (date1 == date2) - return 0; - - return date1 > date2 ? -1 : 1; - - default : - return 0; - } - } - - /** - * Returns the number of the column by which this is sorting. - * @return the column number - */ - public int getColumnNumber() { - return columnNumber; - } - - /** - * Returns true for descending, or false - * for ascending sorting order. - * @return returns true if reversed - */ - public boolean isReversed() { - return reversed; - } - - /** - * Sets the sorting order. - * @param newReversed - */ - public void setReversed(boolean newReversed) { - reversed = newReversed; - } - } - - protected IFileRevision adaptToFileRevision(Object element) { - // Get the log entry for the provided object - IFileRevision entry = null; - if (element instanceof IFileRevision) { - entry = (IFileRevision) element; - } else if (element instanceof IAdaptable) { - entry = (IFileRevision) ((IAdaptable) element).getAdapter(IFileRevision.class); - } - return entry; - } - - /** - * Adds the listener that sets the sorter. - */ - private SelectionListener getColumnListener(final TableViewer tableViewer) { - /** - * This class handles selections of the column headers. - * Selection of the column header will cause resorting - * of the shown tasks using that column's sorter. - * Repeated selection of the header will toggle - * sorting order (ascending versus descending). - */ - return new SelectionAdapter() { - /** - * Handles the case of user selecting the - * header area. - * <p>If the column has not been selected previously, - * it will set the sorter of that column to be - * the current tasklist sorter. Repeated - * presses on the same column header will - * toggle sorting order (ascending/descending). - */ - public void widgetSelected(SelectionEvent e) { - // column selected - need to sort - int column = tableViewer.getTable().indexOf((TableColumn) e.widget); - HistorySorter oldSorter = (HistorySorter) tableViewer.getSorter(); - if (oldSorter != null && column == oldSorter.getColumnNumber()) { - oldSorter.setReversed(!oldSorter.isReversed()); - tableViewer.refresh(); - } else { - tableViewer.setSorter(new HistorySorter(column)); - } - } - }; - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetAction.java deleted file mode 100644 index 9cfe613ff..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetAction.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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.filesystem.ui; - -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.jface.action.IAction; -import org.eclipse.team.examples.filesystem.Policy; - -/** - * Action for getting the contents of the selected resources - */ -public class GetAction extends FileSystemAction { - - protected void execute(IAction action) { - try { - GetOperation operation = new GetOperation(getTargetPart(), - FileSystemOperation.createScopeManager(Policy.bind("GetAction.working"), getSelectedMappings())); //$NON-NLS-1$ - operation.setOverwriteOutgoing(isOverwriteOutgoing()); - operation.run(); - } catch (InvocationTargetException e) { - handle(e, null, Policy.bind("GetAction.problemMessage")); //$NON-NLS-1$ - } catch (InterruptedException e) { - // Ignore - } - } - - /** - * Indicate whether the action should overwrite outgoing changes. - * By default, the get action does not override local modifications. - * @return whether the action should overwrite outgoing changes. - */ - protected boolean isOverwriteOutgoing() { - return false; - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetOperation.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetOperation.java deleted file mode 100644 index 9f7404cd4..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetOperation.java +++ /dev/null @@ -1,94 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 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.filesystem.ui; - -import org.eclipse.core.resources.mapping.ResourceTraversal; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.core.diff.*; -import org.eclipse.team.core.subscribers.SubscriberScopeManager; -import org.eclipse.team.examples.filesystem.FileSystemProvider; -import org.eclipse.team.examples.filesystem.Policy; -import org.eclipse.team.examples.filesystem.subscriber.FileSystemSubscriber; -import org.eclipse.ui.IWorkbenchPart; - -/** - * Operation for getting the contents of the selected resources - */ -public class GetOperation extends FileSystemOperation { - - private boolean overwriteOutgoing; - - public GetOperation(IWorkbenchPart part, SubscriberScopeManager manager) { - super(part, manager); - } - - /* (non-Javadoc) - * @see org.eclipse.team.examples.filesystem.ui.FileSystemOperation#execute(org.eclipse.team.examples.filesystem.FileSystemProvider, org.eclipse.core.resources.mapping.ResourceTraversal[], org.eclipse.core.runtime.SubProgressMonitor) - */ - protected void execute(FileSystemProvider provider, - ResourceTraversal[] traversals, IProgressMonitor monitor) - throws CoreException { - provider.getOperations().get(traversals, isOverwriteOutgoing(), monitor); - if (!isOverwriteOutgoing() && hasIncomingChanges(traversals)) { - throw new TeamException("Could not get all changes due to conflicts."); - } - - } - - private boolean hasIncomingChanges(ResourceTraversal[] traversals) throws CoreException { - final RuntimeException found = new RuntimeException(); - try { - FileSystemSubscriber.getInstance().accept(traversals, new IDiffVisitor() { - public boolean visit(IDiff diff) { - if (diff instanceof IThreeWayDiff) { - IThreeWayDiff twd = (IThreeWayDiff) diff; - if (twd.getDirection() == IThreeWayDiff.INCOMING || twd.getDirection() == IThreeWayDiff.CONFLICTING) { - throw found; - } - } - return false; - } - }); - } catch (RuntimeException e) { - if (e == found) - return true; - throw e; - } - return false; - } - - /** - * Indicate whether the operation should overwrite outgoing changes. - * By default, the get operation does not override local modifications. - * @return whether the operation should overwrite outgoing changes. - */ - protected boolean isOverwriteOutgoing() { - return overwriteOutgoing; - } - - /** - * Set whether the operation should overwrite outgoing changes. - * @param overwriteOutgoing whether the operation should overwrite outgoing changes - */ - public void setOverwriteOutgoing(boolean overwriteOutgoing) { - this.overwriteOutgoing = overwriteOutgoing; - } - - /* (non-Javadoc) - * @see org.eclipse.team.examples.filesystem.ui.FileSystemOperation#getTaskName() - */ - protected String getTaskName() { - return Policy.bind("GetAction.working"); //$NON-NLS-1$ - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/MergeAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/MergeAction.java deleted file mode 100644 index 6300832a0..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/MergeAction.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 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.filesystem.ui; - -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.jface.action.IAction; -import org.eclipse.team.ui.synchronize.ModelMergeOperation; - -/** - * This merge action is contributed as a a popupmenu objectContribution in - * the plugin.xml. You can change the value return from {@link #isUseSyncFramework()} - * to try out different dialogs. - * - * @since 3.2 - */ -public class MergeAction extends FileSystemAction { - - protected void execute(IAction action) { - try { - ModelMergeOperation operation; - if (isUseSyncFramework()) { - operation = new SyncDialogModelMergeOperation(getTargetPart(), - FileSystemOperation.createScopeManager("Merging", getSelectedMappings())); - } else { - operation = new NonSyncModelMergeOperation(getTargetPart(), - FileSystemOperation.createScopeManager("Merging", getSelectedMappings())); - } - operation.run(); - } catch (InvocationTargetException e) { - handle(e, null, "Errors occurred while merging"); - } catch (InterruptedException e) { - // Ignore - } - } - - private boolean isUseSyncFramework() { - return true; - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/ModelPutAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/ModelPutAction.java deleted file mode 100644 index 2eddf4662..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/ModelPutAction.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * 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.filesystem.ui; - -import java.lang.reflect.InvocationTargetException; -import java.util.*; - -import org.eclipse.core.resources.mapping.ResourceMapping; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.team.core.subscribers.SubscriberScopeManager; -import org.eclipse.team.examples.filesystem.FileSystemPlugin; -import org.eclipse.team.internal.ui.Utils; -import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; -import org.eclipse.team.ui.synchronize.ModelParticipantAction; - -/** - * A put action for use in the file system synchronize participant. - */ -public class ModelPutAction extends ModelParticipantAction { - - public ModelPutAction(String text, ISynchronizePageConfiguration configuration) { - super(text, configuration); - } - - protected boolean isEnabledForSelection(IStructuredSelection selection) { - // Only enable the put in outgoing or both modes - int mode = getConfiguration().getMode(); - if (mode == ISynchronizePageConfiguration.OUTGOING_MODE || mode == ISynchronizePageConfiguration.BOTH_MODE) { - return getResourceMappings(selection).length > 0; - } - return false; - } - - private ResourceMapping[] getResourceMappings(IStructuredSelection selection) { - List mappings = new ArrayList(); - for (Iterator iter = selection.iterator(); iter.hasNext();) { - Object element = iter.next(); - ResourceMapping mapping = Utils.getResourceMapping(element); - if (mapping != null) - mappings.add(mapping); - } - return (ResourceMapping[]) mappings.toArray(new ResourceMapping[mappings.size()]); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.action.Action#run() - */ - public void run() { - ResourceMapping[] resourceMappings = getResourceMappings(getStructuredSelection()); - SubscriberScopeManager manager = FileSystemOperation.createScopeManager("Put", resourceMappings); - try { - new PutOperation(getConfiguration().getSite().getPart(), manager).run(); - } catch (InvocationTargetException e) { - IStatus status = getStatus(e); - ErrorDialog.openError(getConfiguration().getSite().getShell(), null, null, status); - } catch (InterruptedException e) { - // Ignore - } - } - - private IStatus getStatus(Throwable throwable) { - if (throwable instanceof InvocationTargetException) { - return getStatus(((InvocationTargetException) throwable).getCause()); - } - return new Status(IStatus.ERROR, FileSystemPlugin.ID, 0, "An error occurred during the put.", throwable); - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/NonSyncMergeDialog.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/NonSyncMergeDialog.java deleted file mode 100644 index 9a4792ee5..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/NonSyncMergeDialog.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * 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.filesystem.ui; - -import org.eclipse.compare.CompareConfiguration; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.team.core.diff.*; -import org.eclipse.team.core.mapping.IMergeContext; -import org.eclipse.team.ui.ISaveableWorkbenchPart; -import org.eclipse.team.ui.SaveablePartDialog; - -/** - * A dialog that can be used to merge conflicting model elements without - * using the Synchronization framework. This is experimental. - * See {@link NonSyncModelMergeOperation} - * for a description of this work flow and its shortcomings. - */ -public class NonSyncMergeDialog extends SaveablePartDialog { - - public static void openFor(NonSyncModelMergeOperation operation) { - NonSyncModelMergePage page = new NonSyncModelMergePage((IMergeContext) operation.getContext()); - NonSyncMergePart part = new NonSyncMergePart(operation.getShell(), new CompareConfiguration(), page); - NonSyncMergeDialog dialog = new NonSyncMergeDialog(operation.getShell(), part); - dialog.open(); - } - - public NonSyncMergeDialog(Shell shell, ISaveableWorkbenchPart input) { - super(shell, input); - } - - protected void buttonPressed(int buttonId) { - if (buttonId == OK) { - NonSyncMergePart part = (NonSyncMergePart)getInput(); - IMergeContext context = part.getContext(); - if (hasUnmergedChanges(context)) { - if (!MessageDialog.openQuestion(getShell(), "Unmerged Changes", "There are still unmerged changes. Are you sure you want to close the dialog?")) - return; - } - } - super.buttonPressed(buttonId); - } - - private boolean hasUnmergedChanges(IMergeContext context) { - return context.getDiffTree().hasMatchingDiffs( - ResourcesPlugin.getWorkspace().getRoot().getFullPath(), - new FastDiffFilter() { - public boolean select(IDiff diff) { - if (diff instanceof IThreeWayDiff) { - IThreeWayDiff twd = (IThreeWayDiff) diff; - return twd.getDirection() == IThreeWayDiff.INCOMING || twd.getDirection() == IThreeWayDiff.CONFLICTING; - } - return false; - } - }); - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/NonSyncMergePart.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/NonSyncMergePart.java deleted file mode 100644 index aa6fa1e80..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/NonSyncMergePart.java +++ /dev/null @@ -1,138 +0,0 @@ -/******************************************************************************* - * 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.filesystem.ui; - -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.compare.CompareConfiguration; -import org.eclipse.compare.IContentChangeNotifier; -import org.eclipse.compare.structuremergeviewer.ICompareInput; -import org.eclipse.core.resources.mapping.ModelProvider; -import org.eclipse.core.resources.mapping.ResourceMapping; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.action.ToolBarManager; -import org.eclipse.jface.viewers.*; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.*; -import org.eclipse.team.core.mapping.IMergeContext; -import org.eclipse.team.internal.ui.Policy; -import org.eclipse.team.internal.ui.Utils; -import org.eclipse.team.ui.PageSaveablePart; -import org.eclipse.team.ui.mapping.ISynchronizationCompareAdapter; -import org.eclipse.team.ui.mapping.ISynchronizationCompareInput; - - -/** - * This class is the compare container used by the {@link NonSyncModelMergeOperation} - * to show a manual merge. - */ -public class NonSyncMergePart extends PageSaveablePart { - - private final NonSyncModelMergePage page; - - protected NonSyncMergePart(Shell shell, CompareConfiguration compareConfiguration, NonSyncModelMergePage page) { - super(shell, compareConfiguration); - this.page = page; - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.PageSaveablePart#createPage(org.eclipse.swt.widgets.Composite, org.eclipse.jface.action.ToolBarManager) - */ - protected Control createPage(Composite parent, ToolBarManager toolBarManager) { - page.createControl(parent); - return page.getControl(); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.PageSaveablePart#getSelectionProvider() - */ - protected ISelectionProvider getSelectionProvider() { - return page.getViewer(); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.PageSaveablePart#getCompareInput(org.eclipse.jface.viewers.ISelection) - */ - protected ICompareInput getCompareInput(ISelection selection) { - ICompareInput compareInput = super.getCompareInput(selection); - if (compareInput != null) - return compareInput; - Object element = ((IStructuredSelection)selection).getFirstElement(); - ISynchronizationCompareAdapter compareAdapter = getCompareAdapter(element); - if (element instanceof ResourceMapping) { - element = ((ResourceMapping) element).getModelObject(); - } - if (compareAdapter != null){ - return compareAdapter.asCompareInput(page.getContext(), element); - } - return null; - } - - protected static ISynchronizationCompareAdapter getCompareAdapter(Object element) { - if (element instanceof ResourceMapping) { - ResourceMapping mapping = (ResourceMapping) element; - ModelProvider provider = mapping.getModelProvider(); - Object adapter = provider.getAdapter(ISynchronizationCompareAdapter.class); - if (adapter instanceof ISynchronizationCompareAdapter) { - return (ISynchronizationCompareAdapter) adapter; - } - } - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.PageSaveablePart#prepareInput(org.eclipse.compare.structuremergeviewer.ICompareInput, org.eclipse.compare.CompareConfiguration, org.eclipse.core.runtime.IProgressMonitor) - */ - protected void prepareInput(ICompareInput input, - CompareConfiguration configuration, IProgressMonitor monitor) - throws InvocationTargetException { - try { - ISynchronizationCompareInput adapter = asSynchronizationCompareInput(input); - if (adapter != null) { - adapter.prepareInput(configuration, Policy.subMonitorFor(monitor, 90)); - } - } catch (CoreException e) { - throw new InvocationTargetException(e); - } - } - - /* - * Convert the compare input to a synchronize compare input. - */ - private ISynchronizationCompareInput asSynchronizationCompareInput(ICompareInput input) { - return (ISynchronizationCompareInput)Utils.getAdapter(input, ISynchronizationCompareInput.class); - } - - public void contentChanged(IContentChangeNotifier source) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IWorkbenchPart#getTitle() - */ - public String getTitle() { - return "File System Provider Merge"; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IWorkbenchPart#getTitleImage() - */ - public Image getTitleImage() { - return null; - } - - public IMergeContext getContext() { - return page.getContext(); - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/NonSyncModelMergeOperation.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/NonSyncModelMergeOperation.java deleted file mode 100644 index e736d5c11..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/NonSyncModelMergeOperation.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 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.filesystem.ui; - -import org.eclipse.core.resources.mapping.RemoteResourceMappingContext; -import org.eclipse.core.runtime.*; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.team.core.mapping.ISynchronizationContext; -import org.eclipse.team.core.mapping.ISynchronizationScopeManager; -import org.eclipse.team.examples.filesystem.subscriber.FileSystemMergeContext; -import org.eclipse.team.ui.synchronize.ModelMergeOperation; -import org.eclipse.ui.IWorkbenchPart; - -/** - * This operation shows an example of how a repository tool could - * perform the Preview (manual merge) phase of the merge operation - * without using the Synchronize view. It will do so by showing the - * user a flat list of all model elements that require a manual merge. - * <p> - * There are a couple of open issues here: - * <ol> - * <li>All the model provider UI is Common Navigator based so there is no model - * provider contributed actions available to overwrite and mark-as-merged. This will - * be a problem for models that have multiple resource mappings within a single file. - * <li>The order in which model elements are merged may matter. There is currently - * no Team API to determine this order.</li> - * <li>This operation assumes that a compare input will be available for the - * model objects that are obtained from the model provider. Although this - * is a reasonable assumption, it is not enforced by the API specification.</li> - * </ol> - */ -public class NonSyncModelMergeOperation extends ModelMergeOperation { - - private FileSystemMergeContext context; - - /** - * Create the operation - * @param part the part from which the operation was launched - * @param manager the scope of the operation - */ - protected NonSyncModelMergeOperation(IWorkbenchPart part, ISynchronizationScopeManager manager) { - super(part, manager); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.ModelMergeOperation#initializeContext(org.eclipse.core.runtime.IProgressMonitor) - */ - protected void initializeContext(IProgressMonitor monitor) throws CoreException { - try { - monitor.beginTask(null, 100); - // Create the context - context = new FileSystemMergeContext(getScopeManager()); - // Refresh the context to get the latest remote state - context.refresh(getScope().getTraversals(), - RemoteResourceMappingContext.FILE_CONTENTS_REQUIRED, new SubProgressMonitor(monitor, 75)); - // What for the context to asynchronously update the diff tree - try { - Job.getJobManager().join(context, new SubProgressMonitor(monitor, 25)); - } catch (InterruptedException e) { - // Ignore - } - } finally { - monitor.done(); - } - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.ModelOperation#getContext() - */ - protected ISynchronizationContext getContext() { - return context; - } - - /** - * Handle the preview request by opening a dialog that allows the user to manually merge - * any changes. - * @see org.eclipse.team.ui.synchronize.ModelMergeOperation#handlePreviewRequest() - */ - protected void handlePreviewRequest() { - // We perform a syncExec so that the job will dispose of the scope manager - // after the dialog closes - Display.getDefault().syncExec(new Runnable() { - public void run() { - NonSyncMergeDialog.openFor(NonSyncModelMergeOperation.this); - } - }); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.TeamOperation#getShell() - */ - public Shell getShell() { - // Change method to public - return super.getShell(); - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/NonSyncModelMergePage.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/NonSyncModelMergePage.java deleted file mode 100644 index 1ec6e3b52..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/NonSyncModelMergePage.java +++ /dev/null @@ -1,311 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 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.filesystem.ui; - -import java.lang.reflect.InvocationTargetException; -import java.util.*; -import java.util.List; - -import org.eclipse.compare.structuremergeviewer.ICompareInput; -import org.eclipse.core.resources.*; -import org.eclipse.core.resources.mapping.*; -import org.eclipse.core.runtime.*; -import org.eclipse.jface.action.*; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.viewers.*; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.*; -import org.eclipse.team.core.diff.IDiff; -import org.eclipse.team.core.mapping.IMergeContext; -import org.eclipse.team.core.mapping.provider.ResourceDiffTree; -import org.eclipse.team.examples.filesystem.FileSystemPlugin; -import org.eclipse.team.internal.ui.mapping.SynchronizationResourceMappingContext; -import org.eclipse.team.ui.mapping.ISynchronizationCompareAdapter; -import org.eclipse.team.ui.synchronize.ModelMergeOperation; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.part.Page; - -/** - * This class provides the page for the {@link NonSyncMergePart}. - */ -public class NonSyncModelMergePage extends Page { - - IMergeContext context; - TreeViewer viewer; - List mappings; - - /* - * Content provider that returns the list of conflicting mappings - */ - class PageContentProvider implements ITreeContentProvider { - public Object[] getChildren(Object parentElement) { - if (parentElement instanceof IMergeContext) { - if (mappings == null) - // TODO: should be using a real progress monitor - computeMappings(new NullProgressMonitor()); - return mappings.toArray(); - } - return new Object[0]; - } - public Object getParent(Object element) { - if (element instanceof ResourceMapping) { - return context; - } - return null; - } - public boolean hasChildren(Object element) { - if (element instanceof IMergeContext) { - return true; - } - return false; - } - public Object[] getElements(Object inputElement) { - return getChildren(inputElement); - } - public void dispose() { - // Nothing to do - } - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - // Nothing to do - } - } - - /* - * Label provider that provides a label and image for conflicting resource mappings - */ - class PageLabelProvider extends LabelProvider { - public String getText(Object element) { - if (element instanceof ResourceMapping) { - ResourceMapping mapping = (ResourceMapping) element; - ISynchronizationCompareAdapter adapter = NonSyncMergePart.getCompareAdapter(mapping); - if (adapter != null) - return adapter.getPathString(mapping) + "(" + mapping.getModelProvider().getDescriptor().getLabel() + ")"; - } - if (element instanceof ICompareInput) { - ICompareInput ci = (ICompareInput) element; - ci.getName(); - } - return super.getText(element); - } - public Image getImage(Object element) { - if (element instanceof ICompareInput) { - ICompareInput ci = (ICompareInput) element; - ci.getImage(); - } - if (element instanceof ResourceMapping) { - ResourceMapping mapping = (ResourceMapping) element; - ISynchronizationCompareAdapter adapter = NonSyncMergePart.getCompareAdapter(mapping); - ICompareInput input = adapter.asCompareInput(context, mapping.getModelObject()); - if (input != null) - return input.getImage(); - } - return super.getImage(element); - } - } - - /* - * Sorter that sorts mappings by model and then name - */ - class PageSorter extends ViewerSorter { - public int compare(Viewer viewer, Object e1, Object e2) { - if (e1 instanceof ResourceMapping && e2 instanceof ResourceMapping) { - ResourceMapping m1 = (ResourceMapping) e1; - ResourceMapping m2 = (ResourceMapping) e2; - if (m1.getModelProvider() == m2.getModelProvider()) { - return getLabel(m1).compareTo(getLabel(m2)); - } - return compare(m1, m2); - } - return super.compare(viewer, e1, e2); - } - private int compare(ResourceMapping m1, ResourceMapping m2) { - ModelProvider[] sorted = ModelMergeOperation.sortByExtension(new ModelProvider[] { m1.getModelProvider(), m2.getModelProvider() }); - return sorted[0] == m1.getModelProvider() ? -1 : 1; - } - private String getLabel(ResourceMapping mapping) { - ISynchronizationCompareAdapter adapter = NonSyncMergePart.getCompareAdapter(mapping); - if (adapter != null) - return adapter.getPathString(mapping); - return ""; - } - } - - public NonSyncModelMergePage(IMergeContext context) { - super(); - this.context = context; - } - - /** - * Create the list of all mappings that overlap with the out-of-sync files. - */ - public void computeMappings(IProgressMonitor monitor) { - IModelProviderDescriptor[] descriptors = ModelProvider.getModelProviderDescriptors(); - mappings = new ArrayList(); - for (int i = 0; i < descriptors.length; i++) { - IModelProviderDescriptor descriptor = descriptors[i]; - // Get the subset of files that this model provider cares about - try { - IResource[] resources = descriptor.getMatchingResources(getOutOfSyncFiles()); - if (resources.length > 0) { - ModelProvider provider = descriptor.getModelProvider(); - // Get the mappings for those resources - ResourceMapping[] mappings = provider.getMappings(resources, new SynchronizationResourceMappingContext(context), monitor); - this.mappings.addAll(Arrays.asList(mappings )); - } - } catch (CoreException e) { - FileSystemPlugin.log(e); - } - } - } - - private IResource[] getOutOfSyncFiles() { - IDiff[] diffs = getContext().getDiffTree().getDiffs(ResourcesPlugin.getWorkspace().getRoot(), IResource.DEPTH_INFINITE); - List result = new ArrayList(); - for (int i = 0; i < diffs.length; i++) { - IDiff diff = diffs[i]; - IResource resource = ResourceDiffTree.getResourceFor(diff); - if (resource.getType() == IResource.FILE) - result.add(resource); - } - return (IResource[]) result.toArray(new IResource[result.size()]); - } - - /** - * Return the merge context. - * @return the merge context - */ - public IMergeContext getContext() { - return context; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.part.Page#createControl(org.eclipse.swt.widgets.Composite) - */ - public void createControl(Composite parent) { - viewer = new TreeViewer(parent); - viewer.setContentProvider(new PageContentProvider()); - viewer.setLabelProvider(new PageLabelProvider()); - viewer.setSorter(new PageSorter()); - hookContextMenu(viewer); - viewer.setInput(context); - } - - /* - * Hook the context menu to display the Overwrite and Mark-as-merged actions - */ - private void hookContextMenu(final TreeViewer viewer) { - final MenuManager menuMgr = new MenuManager(); - menuMgr.setRemoveAllWhenShown(true); - menuMgr.addMenuListener(new IMenuListener() { - public void menuAboutToShow(IMenuManager manager) { - fillContextMenu(manager); - } - }); - Menu menu = menuMgr.createContextMenu(viewer.getControl()); - viewer.getControl().setMenu(menu); - } - - /** - * Fill the context menu. - * @param manager the context menu manager - */ - protected void fillContextMenu(IMenuManager manager) { - /* - * Add a mark as merged action. Because we are not using the - * Synchronization framework and, more specifically, the - * Common Navigator content provider for the model providers, - * we do not have access to the merge handlers of the model. - * Therefore, we are writing are action to detect whether there - * are files that overlap between the selected model elements and - * unselected model elements. - */ - Action markAsMerged = new Action("Mark as Merged") { - public void run() { - try { - final IStructuredSelection selection = (IStructuredSelection)viewer.getSelection(); - PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() { - public void run(IProgressMonitor monitor) throws InvocationTargetException { - IDiff[] diffs = getSelectedDiffs(selection, monitor); - if (!checkForModelOverlap(diffs, monitor)) { - return; - } - try { - context.markAsMerged(diffs, false, monitor); - } catch (CoreException e) { - throw new InvocationTargetException(e); - } - } - }); - } catch (InvocationTargetException e) { - FileSystemPlugin.log(new Status(IStatus.ERROR, FileSystemPlugin.ID, 0, e.getTargetException().getMessage(), e.getTargetException())); - } catch (InterruptedException e) { - // Ignore - } - } - }; - manager.add(markAsMerged); - } - - protected IDiff[] getSelectedDiffs(IStructuredSelection selection, IProgressMonitor monitor) { - Object[] elements = selection.toArray(); - return getDiffs(elements, monitor); - } - - private IDiff[] getDiffs(Object[] elements, IProgressMonitor monitor) { - Set result = new HashSet(); - for (int i = 0; i < elements.length; i++) { - Object element = elements[i]; - try { - if (element instanceof ResourceMapping) { - ResourceMapping mapping = (ResourceMapping) element; - ResourceTraversal[] traversals = mapping.getTraversals(new SynchronizationResourceMappingContext(context), monitor); - result.addAll(Arrays.asList(context.getDiffTree().getDiffs(traversals))); - } - } catch (CoreException e) { - FileSystemPlugin.log(e); - } - } - return (IDiff[]) result.toArray(new IDiff[result.size()]); - } - - /** - * Check whether any of the diffs overlap with mappings that are not selected - * @param diffs - * @return - */ - protected boolean checkForModelOverlap(IDiff[] diffs, IProgressMonitor monitor) { - // TODO: This check should see if the diffs are also part of mappings - // that are not included in the selection. - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.part.Page#getControl() - */ - public Control getControl() { - if (viewer != null) - return viewer.getControl(); - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.part.Page#setFocus() - */ - public void setFocus() { - if (viewer != null) - viewer.getControl().setFocus(); - } - - public ISelectionProvider getViewer() { - return viewer; - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/OpenFileSystemRevisionAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/OpenFileSystemRevisionAction.java deleted file mode 100644 index 2220a4032..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/OpenFileSystemRevisionAction.java +++ /dev/null @@ -1,164 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 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.filesystem.ui; - -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IStorage; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.team.core.history.IFileRevision; -import org.eclipse.team.examples.filesystem.FileSystemPlugin; -import org.eclipse.team.ui.history.HistoryPage; -import org.eclipse.ui.IEditorDescriptor; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IEditorReference; -import org.eclipse.ui.IEditorRegistry; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.actions.BaseSelectionListenerAction; -import org.eclipse.ui.ide.IDE; -import org.eclipse.ui.progress.IProgressService; - -public class OpenFileSystemRevisionAction extends BaseSelectionListenerAction { - - private IStructuredSelection selection; - HistoryPage page; - - public OpenFileSystemRevisionAction(String text) { - super(text); - } - - public void run() { - IStructuredSelection structSel = selection; - - Object[] objArray = structSel.toArray(); - - for (int i = 0; i < objArray.length; i++) { - Object tempRevision = objArray[i]; - - final IFileRevision revision = (IFileRevision) tempRevision; - if (revision == null || !revision.exists()) { - MessageDialog.openError(page.getSite().getShell(), "Deleted Revision", "Can't open a deleted revision"); - } else { - IRunnableWithProgress runnable = new IRunnableWithProgress() { - public void run(IProgressMonitor monitor) throws InvocationTargetException { - IStorage file; - try { - file = revision.getStorage(monitor); - String id = getEditorID(file.getName(), file.getContents()); - - if (file instanceof IFile) { - //if this is the current workspace file, open it - IDE.openEditor(page.getSite().getPage(), (IFile) file); - } else { - FileSystemRevisionEditorInput fileRevEditorInput = new FileSystemRevisionEditorInput(revision); - if (!editorAlreadyOpenOnContents(fileRevEditorInput)) - page.getSite().getPage().openEditor(fileRevEditorInput, id); - } - } catch (CoreException e) { - throw new InvocationTargetException(e); - } - - } - }; - - IProgressService progressService = PlatformUI.getWorkbench().getProgressService(); - try { - progressService.run(false, false, runnable); - } catch (InvocationTargetException e) { - // ignore - } catch (InterruptedException e) { - // ignore - } - } - - } - } - - /* private */String getEditorID(String fileName, InputStream contents) { - IWorkbench workbench = FileSystemPlugin.getPlugin().getWorkbench(); - IEditorRegistry registry = workbench.getEditorRegistry(); - IContentType type = null; - if (contents != null) { - try { - type = Platform.getContentTypeManager().findContentTypeFor(contents, fileName); - } catch (IOException e) { - // ignore - } - } - if (type == null) { - type = Platform.getContentTypeManager().findContentTypeFor(fileName); - } - IEditorDescriptor descriptor = registry.getDefaultEditor(fileName, type); - String id; - if (descriptor == null || descriptor.isOpenExternal()) { - id = "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$ - } else { - id = descriptor.getId(); - } - - return id; - } - - protected boolean updateSelection(IStructuredSelection selection) { - this.selection = selection; - return shouldShow(); - } - - public void setPage(HistoryPage page) { - this.page = page; - } - - private boolean shouldShow() { - IStructuredSelection structSel = selection; - Object[] objArray = structSel.toArray(); - - if (objArray.length == 0) - return false; - - for (int i = 0; i < objArray.length; i++) { - IFileRevision revision = (IFileRevision) objArray[i]; - //check to see if any of the selected revisions are deleted revisions - if (revision != null && !revision.exists()) - return false; - } - - return true; - } - - boolean editorAlreadyOpenOnContents(FileSystemRevisionEditorInput input) { - IEditorReference[] editorRefs = page.getSite().getPage().getEditorReferences(); - for (int i = 0; i < editorRefs.length; i++) { - IEditorPart part = editorRefs[i].getEditor(false); - if (part != null && part.getEditorInput() instanceof FileSystemRevisionEditorInput) { - IFileRevision inputRevision = (IFileRevision) input.getAdapter(IFileRevision.class); - IFileRevision editorRevision = (IFileRevision) part.getEditorInput().getAdapter(IFileRevision.class); - - if (inputRevision.equals(editorRevision)) { - //make the editor that already contains the revision current - page.getSite().getPage().activate(part); - return true; - } - } - } - return false; - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/ProjectSetSerializer.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/ProjectSetSerializer.java deleted file mode 100644 index c0d0a62c0..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/ProjectSetSerializer.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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.filesystem.ui; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.*; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.team.core.*; -import org.eclipse.team.examples.filesystem.*; - -/** - * This is an old-style (pre-3.0) project set serializer used to test backwards compatibility - */ -public class ProjectSetSerializer implements IProjectSetSerializer { - - /* (non-Javadoc) - * @see org.eclipse.team.core.IProjectSetSerializer#asReference(org.eclipse.core.resources.IProject[], java.lang.Object, org.eclipse.core.runtime.IProgressMonitor) - */ - public String[] asReference(IProject[] providerProjects, Object context, IProgressMonitor monitor) { - Assert.isTrue(context instanceof Shell); - List refs = new ArrayList(); - for (int i = 0; i < providerProjects.length; i++) { - IProject project = providerProjects[i]; - FileSystemProvider provider = (FileSystemProvider)RepositoryProvider.getProvider(project, FileSystemPlugin.PROVIDER_ID); - if (provider != null) { - refs.add(asReference(provider)); - } - } - return (String[]) refs.toArray(new String[refs.size()]); - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.IProjectSetSerializer#addToWorkspace(java.lang.String[], java.lang.String, java.lang.Object, org.eclipse.core.runtime.IProgressMonitor) - */ - public IProject[] addToWorkspace(String[] referenceStrings, String filename, Object context, IProgressMonitor monitor) { - Assert.isTrue(context instanceof Shell); - List projects = new ArrayList(); - for (int i = 0; i < referenceStrings.length; i++) { - String string = referenceStrings[i]; - String projectName = getProjectName(string); - String path = getPath(string); - if (projectName != null && path != null) { - try { - IProject project = createProject(projectName, monitor); - RepositoryProvider.map(project, FileSystemPlugin.PROVIDER_ID); - FileSystemProvider provider = (FileSystemProvider) RepositoryProvider.getProvider(project); - provider.setTargetLocation(path); - projects.add(project); - } catch (CoreException e) { - ErrorDialog.openError( - (Shell)context, - Policy.bind("ConfigurationWizard.errorMapping"), //$NON-NLS-1$ - Policy.bind("ConfigurationWizard.error"), //$NON-NLS-1$ - e.getStatus()); - } - } - } - return (IProject[]) projects.toArray(new IProject[projects.size()]); - } - - /** - * @param provider - * @return - */ - private String asReference(FileSystemProvider provider) { - return provider.getProject().getName() + "," + provider.getRoot().toString(); //$NON-NLS-1$ - } - - /** - * @param string - * @return - */ - private String getProjectName(String string) { - int i = string.indexOf(','); - if (i == -1) return null; - return string.substring(0, i); - } - - /** - * @param string - * @return - */ - private String getPath(String string) { - int i = string.indexOf(','); - if (i == -1) return null; - return string.substring(i + 1); - } - - /** - * @param projectName - * @return - * @throws CoreException - */ - private IProject createProject(String projectName, IProgressMonitor monitor) throws CoreException { - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); - if (!project.exists()) { - project.create(monitor); - } - if (!project.isOpen()) { - project.open(monitor); - } - return project; - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutAction.java deleted file mode 100644 index 185bf4cb0..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutAction.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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.filesystem.ui; - -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.jface.action.IAction; -import org.eclipse.team.examples.filesystem.Policy; - -/** - * Action for checking in the selected resources - */ -public class PutAction extends FileSystemAction { - - protected void execute(IAction action) { - try { - PutOperation operation = new PutOperation(getTargetPart(), - FileSystemOperation.createScopeManager(Policy.bind("PutAction.working"), getSelectedMappings())); //$NON-NLS-1$ - operation.setOverwriteIncoming(isOverrideIncoming()); - operation.run(); - } catch (InvocationTargetException e) { - handle(e, null, Policy.bind("PutAction.problemMessage")); //$NON-NLS-1$ - } catch (InterruptedException e) { - // Ignore - } - } - - /** - * Indicate whether the put should override incoming changes. - * @return whether the put should override incoming changes. - */ - protected boolean isOverrideIncoming() { - return false; - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutOperation.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutOperation.java deleted file mode 100644 index eb67fc9b3..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutOperation.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 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.filesystem.ui; - -import org.eclipse.core.resources.mapping.ResourceTraversal; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.core.diff.*; -import org.eclipse.team.core.subscribers.SubscriberScopeManager; -import org.eclipse.team.examples.filesystem.FileSystemProvider; -import org.eclipse.team.examples.filesystem.Policy; -import org.eclipse.team.examples.filesystem.subscriber.FileSystemSubscriber; -import org.eclipse.ui.IWorkbenchPart; - -/** - * Operation for copying the selected resources to the file system location - */ -public class PutOperation extends FileSystemOperation { - - private boolean overwriteIncoming; - - /** - * Create the put operation - * @param part the originating part - * @param manager the scope manager - */ - protected PutOperation(IWorkbenchPart part, SubscriberScopeManager manager) { - super(part, manager); - } - - /* (non-Javadoc) - * @see org.eclipse.team.examples.filesystem.ui.FileSystemOperation#execute(org.eclipse.team.examples.filesystem.FileSystemProvider, org.eclipse.core.resources.mapping.ResourceTraversal[], org.eclipse.core.runtime.SubProgressMonitor) - */ - protected void execute(FileSystemProvider provider, - ResourceTraversal[] traversals, IProgressMonitor monitor) - throws CoreException { - provider.getOperations().checkin(traversals, isOverwriteIncoming(), monitor); - if (!isOverwriteIncoming() && hasOutgoingChanges(traversals)) { - throw new TeamException("Could not put all changes due to conflicts."); - } - - } - - private boolean hasOutgoingChanges(ResourceTraversal[] traversals) throws CoreException { - final RuntimeException found = new RuntimeException(); - try { - FileSystemSubscriber.getInstance().accept(traversals, new IDiffVisitor() { - public boolean visit(IDiff diff) { - if (diff instanceof IThreeWayDiff) { - IThreeWayDiff twd = (IThreeWayDiff) diff; - if (twd.getDirection() == IThreeWayDiff.OUTGOING || twd.getDirection() == IThreeWayDiff.CONFLICTING) { - throw found; - } - } - return false; - } - }); - } catch (RuntimeException e) { - if (e == found) - return true; - throw e; - } - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.team.examples.filesystem.ui.FileSystemOperation#getTaskName() - */ - protected String getTaskName() { - return Policy.bind("PutAction.working"); //$NON-NLS-1$ - } - - /** - * Return whether incoming changes should be overwritten. - * @return whether incoming changes should be overwritten - */ - public boolean isOverwriteIncoming() { - return overwriteIncoming; - } - - /** - * Set whether incoming changes should be overwritten. - * @param overwriteIncoming whether incoming changes should be overwritten - */ - public void setOverwriteIncoming(boolean overwriteIncoming) { - this.overwriteIncoming = overwriteIncoming; - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/ReplaceAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/ReplaceAction.java deleted file mode 100644 index 5bf23e60b..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/ReplaceAction.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.filesystem.ui; - - -/** - * A replace is simply a get that overwrite local changes - */ -public class ReplaceAction extends GetAction { - - /* (non-Javadoc) - * @see org.eclipse.team.examples.filesystem.ui.GetAction#isOverwriteOutgoing() - */ - protected boolean isOverwriteOutgoing() { - return true; - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/ShowHistoryAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/ShowHistoryAction.java deleted file mode 100644 index 762d3ee8e..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/ShowHistoryAction.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 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.filesystem.ui; - -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.ProgressMonitorDialog; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.team.examples.filesystem.FileSystemPlugin; -import org.eclipse.team.internal.ui.TeamUIPlugin; -import org.eclipse.team.ui.TeamUI; -import org.eclipse.ui.IObjectActionDelegate; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.actions.ActionDelegate; - -public class ShowHistoryAction extends ActionDelegate implements IObjectActionDelegate { - - IStructuredSelection fSelection; - - public void run(IAction action) { - final Shell shell = Display.getDefault().getActiveShell(); - try { - new ProgressMonitorDialog(shell).run(true, true, new IRunnableWithProgress() { - public void run(IProgressMonitor monitor) { - final IResource resource = (IResource) fSelection.getFirstElement(); - Runnable r = new Runnable() { - public void run() { - TeamUI.showHistoryFor(TeamUIPlugin.getActivePage(), resource, null); - } - }; - - FileSystemPlugin.getStandardDisplay().asyncExec(r); - } - }); - } catch (InvocationTargetException exception) { - // ignore - } catch (InterruptedException exception) { - // ignore - } - } - - public void selectionChanged(IAction action, ISelection sel) { - if (sel instanceof IStructuredSelection) { - fSelection = (IStructuredSelection) sel; - } - } - - public void setActivePart(IAction action, IWorkbenchPart targetPart) { - // do nothing - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/SyncDialogModelMergeOperation.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/SyncDialogModelMergeOperation.java deleted file mode 100644 index e820c5471..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/SyncDialogModelMergeOperation.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * 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.filesystem.ui; - -import org.eclipse.team.core.mapping.ISynchronizationScopeManager; -import org.eclipse.team.core.mapping.provider.SynchronizationContext; -import org.eclipse.team.examples.filesystem.subscriber.FileSystemMergeContext; -import org.eclipse.team.ui.synchronize.ModelParticipantMergeOperation; -import org.eclipse.ui.IWorkbenchPart; - -/** - * This merge operation will attempt a headless merge and then prompt - * the user with a dialog if conflicts exist. - */ -public class SyncDialogModelMergeOperation extends - ModelParticipantMergeOperation { - - public SyncDialogModelMergeOperation(IWorkbenchPart part, ISynchronizationScopeManager manager) { - super(part, manager); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.ModelParticipantMergeOperation#createMergeContext() - */ - protected SynchronizationContext createMergeContext() { - return new FileSystemMergeContext(getScopeManager()); - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/SynchronizeAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/SynchronizeAction.java deleted file mode 100644 index b1064ac48..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/SynchronizeAction.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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.filesystem.ui; - -import org.eclipse.core.resources.mapping.ResourceMapping; -import org.eclipse.jface.action.IAction; -import org.eclipse.team.core.subscribers.SubscriberScopeManager; -import org.eclipse.team.examples.filesystem.subscriber.FileSystemMergeContext; -import org.eclipse.team.examples.filesystem.subscriber.FileSystemSubscriber; -import org.eclipse.team.ui.TeamUI; -import org.eclipse.team.ui.synchronize.ISynchronizeParticipant; - -/** - * Action to synchronize the selected resources. This results - * in a file-system participant being added to the synchronize view. - */ -public class SynchronizeAction extends FileSystemAction { - - protected void execute(IAction action) { - ResourceMapping[] mappings = getSelectedMappings(); - if (mappings.length == 0) - return; - SubscriberScopeManager manager = FileSystemOperation.createScopeManager(FileSystemSubscriber.getInstance().getName(), mappings); - FileSystemMergeContext context = new FileSystemMergeContext(manager); - FileSystemSynchronizeParticipant participant = new FileSystemSynchronizeParticipant(context); - TeamUI.getSynchronizeManager().addSynchronizeParticipants(new ISynchronizeParticipant[] {participant}); - participant.run(getTargetPart()); - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/SynchronizeWizard.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/SynchronizeWizard.java deleted file mode 100644 index f87cb20db..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/SynchronizeWizard.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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.filesystem.ui; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.mapping.ResourceMapping; -import org.eclipse.jface.wizard.IWizard; -import org.eclipse.team.core.subscribers.SubscriberScopeManager; -import org.eclipse.team.examples.filesystem.subscriber.FileSystemMergeContext; -import org.eclipse.team.examples.filesystem.subscriber.FileSystemSubscriber; -import org.eclipse.team.ui.synchronize.ISynchronizeParticipant; -import org.eclipse.team.ui.synchronize.ModelParticipantWizard; - -/** - * This class is registered as the file system synchronization wizard. - */ -public class SynchronizeWizard extends ModelParticipantWizard { - private IWizard importWizard; - - /* - * Default no-arg constructor - */ - public SynchronizeWizard() { - super(); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.ModelParticipantWizard#createParticipant(org.eclipse.core.resources.mapping.ResourceMapping[]) - */ - protected ISynchronizeParticipant createParticipant(ResourceMapping[] selectedMappings) { - SubscriberScopeManager manager = FileSystemOperation.createScopeManager(FileSystemSubscriber.getInstance().getName(), selectedMappings); - FileSystemMergeContext context = new FileSystemMergeContext(manager); - FileSystemSynchronizeParticipant participant = new FileSystemSynchronizeParticipant(context); - return participant; - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.ParticipantSynchronizeWizard#getImportWizard() - */ - protected IWizard getImportWizard() { - // We don't have an import wizard for the file system example but - // if we did, we could return it here and it would be used if the - // getRoots method returned an empty array. - return importWizard; - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.ParticipantSynchronizeWizard#getPageTitle() - */ - protected String getPageTitle() { - return "Synchronize File System Example"; - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.ParticipantSynchronizeWizard#getRootResources() - */ - protected IResource[] getRootResources() { - return FileSystemSubscriber.getInstance().roots(); - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/LocalHistoryParticipant.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/LocalHistoryParticipant.java deleted file mode 100644 index 86af167ac..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/LocalHistoryParticipant.java +++ /dev/null @@ -1,121 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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.localhistory; - -import org.eclipse.compare.CompareConfiguration; -import org.eclipse.compare.structuremergeviewer.IDiffElement; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.viewers.ILabelDecorator; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.graphics.Image; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.core.subscribers.Subscriber; -import org.eclipse.team.core.synchronize.SyncInfo; -import org.eclipse.team.core.variants.IResourceVariant; -import org.eclipse.team.ui.TeamUI; -import org.eclipse.team.ui.synchronize.ISynchronizeModelElement; -import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; -import org.eclipse.team.ui.synchronize.ISynchronizeParticipantDescriptor; -import org.eclipse.team.ui.synchronize.SubscriberParticipant; -import org.eclipse.team.ui.synchronize.SynchronizeModelAction; -import org.eclipse.team.ui.synchronize.SynchronizeModelOperation; -import org.eclipse.team.ui.synchronize.SynchronizePageActionGroup; - -public class LocalHistoryParticipant extends SubscriberParticipant { - - public static final String ID = "org.eclipse.team.synchronize.example"; //$NON-NLS-1$ - public static final String CONTEXT_MENU_CONTRIBUTION_GROUP = "context_group_1"; //$NON-NLS-1$ - - private class LocalHistoryActionContribution extends SynchronizePageActionGroup { - public void initialize(ISynchronizePageConfiguration configuration) { - super.initialize(configuration); - appendToGroup( - ISynchronizePageConfiguration.P_CONTEXT_MENU, CONTEXT_MENU_CONTRIBUTION_GROUP, - new SynchronizeModelAction("Revert to latest in local history", configuration) { //$NON-NLS-1$ - protected SynchronizeModelOperation getSubscriberOperation(ISynchronizePageConfiguration configuration, IDiffElement[] elements) { - return new RevertAllOperation(configuration, elements); - } - }); - } - } - - private class LocalHistoryDecorator extends LabelProvider implements ILabelDecorator { - public String decorateText(String text, Object element) { - if(element instanceof ISynchronizeModelElement) { - ISynchronizeModelElement node = (ISynchronizeModelElement)element; - if(node instanceof IAdaptable) { - SyncInfo info = (SyncInfo)((IAdaptable)node).getAdapter(SyncInfo.class); - if(info != null) { - LocalHistoryVariant state = (LocalHistoryVariant)info.getRemote(); - return text+ " ("+ state.getContentIdentifier() + ")"; - } - } - } - return text; - } - - public Image decorateImage(Image image, Object element) { - return null; - } - } - - public LocalHistoryParticipant() { - setSubscriber(new LocalHistorySubscriber()); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.subscriber.SubscriberParticipant#setSubscriber(org.eclipse.team.core.subscribers.Subscriber) - */ - protected void setSubscriber(Subscriber subscriber) { - super.setSubscriber(subscriber); - try { - ISynchronizeParticipantDescriptor descriptor = TeamUI.getSynchronizeManager().getParticipantDescriptor(ID); - setInitializationData(descriptor); - setSecondaryId(Long.toString(System.currentTimeMillis())); - } catch (CoreException e) { - // ignore - } - } - - protected void initializeConfiguration(ISynchronizePageConfiguration configuration) { - super.initializeConfiguration(configuration); - configuration.addMenuGroup( - ISynchronizePageConfiguration.P_CONTEXT_MENU, - CONTEXT_MENU_CONTRIBUTION_GROUP); - configuration.addActionContribution(new LocalHistoryActionContribution()); - configuration.addLabelDecorator(new LocalHistoryDecorator()); - } - - protected static SyncInfo getSyncInfo(ISynchronizeModelElement element) { - if (element instanceof IAdaptable) { - return (SyncInfo)((IAdaptable)element).getAdapter(SyncInfo.class); - } - return null; - } - - public void prepareCompareInput(ISynchronizeModelElement element, - CompareConfiguration config, IProgressMonitor monitor) - throws TeamException { - super.prepareCompareInput(element, config, monitor); - - SyncInfo sync = getSyncInfo(element); - final IResourceVariant remote = sync.getRemote(); - if (remote != null) { - config.setRightLabel(NLS.bind("Local History ({0})", - new String[] { remote.getContentIdentifier() })); - } else { - config.setRightLabel("Local History"); - } - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/LocalHistorySubscriber.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/LocalHistorySubscriber.java deleted file mode 100644 index b6d79736e..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/LocalHistorySubscriber.java +++ /dev/null @@ -1,102 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2010 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.localhistory; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFileState; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.core.subscribers.Subscriber; -import org.eclipse.team.core.synchronize.SyncInfo; -import org.eclipse.team.core.variants.IResourceVariant; -import org.eclipse.team.core.variants.IResourceVariantComparator; - -public class LocalHistorySubscriber extends Subscriber { - - private LocalHistoryVariantComparator comparator; - - public LocalHistorySubscriber() { - this.comparator = new LocalHistoryVariantComparator(); - } - - public String getName() { - return "Local History Subscriber"; //$NON-NLS-1$ - } - - /** - * @param resource the resource being tested - */ - public boolean isSupervised(IResource resource) { - // all resources in the workspace can potentially have resource history - return true; - } - - public IResource[] members(IResource resource) throws TeamException { - try { - if(resource.getType() == IResource.FILE) - return new IResource[0]; - IContainer container = (IContainer)resource; - List existingChildren = new ArrayList(Arrays.asList(container.members())); - existingChildren.addAll(Arrays.asList(container.findDeletedMembersWithHistory(IResource.DEPTH_INFINITE, null))); - return (IResource[]) existingChildren.toArray(new IResource[existingChildren.size()]); - } catch (CoreException e) { - throw TeamException.asTeamException(e); - } - } - - public IResource[] roots() { - return ResourcesPlugin.getWorkspace().getRoot().getProjects(); - } - - public SyncInfo getSyncInfo(IResource resource) throws TeamException { - try { - IResourceVariant variant = null; - if(resource.getType() == IResource.FILE) { - IFile file = (IFile)resource; - IFileState[] states = file.getHistory(null); - if(states.length > 0) { - // last state only - variant = new LocalHistoryVariant(states[0]); - } - } - SyncInfo info = new LocalHistorySyncInfo(resource, variant, comparator); - info.init(); - return info; - } catch (CoreException e) { - throw TeamException.asTeamException(e); - } - } - - public IResourceVariantComparator getResourceComparator() { - return comparator; - } - - /** - * @param resources - * the resources to refresh - * @param depth - * the depth - * @param monitor - * progress monitor, or <code>null</code> if progress reporting - * and cancellation are not desired - */ - public void refresh(IResource[] resources, int depth, IProgressMonitor monitor) { - // do nothing - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/LocalHistorySyncInfo.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/LocalHistorySyncInfo.java deleted file mode 100644 index 22b3cceee..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/LocalHistorySyncInfo.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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.localhistory; - -import org.eclipse.core.resources.IResource; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.core.synchronize.SyncInfo; -import org.eclipse.team.core.variants.IResourceVariant; -import org.eclipse.team.core.variants.IResourceVariantComparator; - -public class LocalHistorySyncInfo extends SyncInfo { - - public LocalHistorySyncInfo(IResource local, IResourceVariant remote, IResourceVariantComparator comparator) { - super(local, null, remote, comparator); - } - - protected int calculateKind() throws TeamException { - if (getRemote() == null) - return IN_SYNC; - return super.calculateKind(); - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/LocalHistorySynchronizeWizard.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/LocalHistorySynchronizeWizard.java deleted file mode 100644 index c72c2f095..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/LocalHistorySynchronizeWizard.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.localhistory; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.team.internal.ui.ITeamUIImages; -import org.eclipse.team.ui.TeamImages; -import org.eclipse.team.ui.TeamUI; -import org.eclipse.team.ui.synchronize.*; -import org.eclipse.team.ui.synchronize.ISynchronizeManager; -import org.eclipse.team.ui.synchronize.ISynchronizeParticipant; - - -public class LocalHistorySynchronizeWizard extends Wizard { - - private class MessagePage extends WizardPage { - protected MessagePage(String pageName, String title, ImageDescriptor titleImage) { - super(pageName, title, titleImage); - } - - public void createControl(Composite parent) { - Composite top = new Composite(parent, SWT.NONE); - top.setLayout(new GridLayout()); - top.setLayoutData(new GridData(GridData.FILL_BOTH)); - Label label = new Label(top, SWT.WRAP); - label.setText("This will create a synchronization against the latest file state in local history."); //$NON-NLS-1$ - label.setLayoutData(new GridData(GridData.FILL_BOTH)); - setControl(top); - } - } - - public LocalHistorySynchronizeWizard() { - super(); - } - - public void addPages() { - addPage(new MessagePage("Local History", "Create a local history synchronization", TeamImages.getImageDescriptor(ITeamUIImages.IMG_WIZBAN_SHARE))); //$NON-NLS-1$//$NON-NLS-2$ - } - - public boolean performFinish() { - LocalHistoryParticipant participant = new LocalHistoryParticipant(); - ISynchronizeManager manager = TeamUI.getSynchronizeManager(); - manager.addSynchronizeParticipants(new ISynchronizeParticipant[] {participant}); - ISynchronizeView view = manager.showSynchronizeViewInActivePage(); - view.display(participant); - return true; - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/LocalHistoryVariant.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/LocalHistoryVariant.java deleted file mode 100644 index 76eea57c7..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/LocalHistoryVariant.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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.localhistory; - -import java.text.DateFormat; -import java.util.Date; - -import org.eclipse.core.resources.IFileState; -import org.eclipse.core.resources.IStorage; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.core.variants.IResourceVariant; - -public class LocalHistoryVariant implements IResourceVariant { - - private final IFileState state; - - public LocalHistoryVariant(IFileState state) { - this.state = state; - } - - public String getName() { - return state.getName(); - } - - public boolean isContainer() { - return false; - } - - public IStorage getStorage(IProgressMonitor monitor) { - return state; - } - - public String getContentIdentifier() { - return DateFormat.getDateTimeInstance().format(new Date(state.getModificationTime())); - } - - public byte[] asBytes() { - return null; - } - - public IFileState getFileState() { - return state; - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/LocalHistoryVariantComparator.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/LocalHistoryVariantComparator.java deleted file mode 100644 index 7b7d89b4c..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/LocalHistoryVariantComparator.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.localhistory; - -import org.eclipse.core.resources.IResource; -import org.eclipse.team.core.variants.IResourceVariant; -import org.eclipse.team.core.variants.IResourceVariantComparator; - -public class LocalHistoryVariantComparator implements IResourceVariantComparator { - public boolean compare(IResource local, IResourceVariant remote) { - return false; - } - - public boolean compare(IResourceVariant base, IResourceVariant remote) { - return false; - } - - public boolean isThreeWay() { - return false; - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/RevertAllOperation.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/RevertAllOperation.java deleted file mode 100644 index 87dba234e..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/RevertAllOperation.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.localhistory; - -import java.lang.reflect.InvocationTargetException; -import org.eclipse.compare.structuremergeviewer.IDiffElement; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.*; -import org.eclipse.team.core.synchronize.SyncInfo; -import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; -import org.eclipse.team.ui.synchronize.SynchronizeModelOperation; -import org.eclipse.ui.actions.WorkspaceModifyOperation; - -public class RevertAllOperation extends SynchronizeModelOperation { - - protected RevertAllOperation(ISynchronizePageConfiguration configuration, IDiffElement[] elements) { - super(configuration, elements); - } - - protected boolean canRunAsJob() { - return true; - } - - public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - final SyncInfo infos[] = getSyncInfoSet().getSyncInfos(); - if(infos.length == 0) return; - - WorkspaceModifyOperation operation= new WorkspaceModifyOperation() { - public void execute(IProgressMonitor pm) throws InvocationTargetException { - try { - pm.beginTask("Reverting from local history", 100 * infos.length); //$NON-NLS-1$ - for (int i = 0; i < infos.length; i++) { - SyncInfo info = infos[i]; - LocalHistoryVariant state = (LocalHistoryVariant)info.getRemote(); - IFile file = (IFile)info.getLocal(); - if(file.exists()) { - file.setContents(state.getFileState(), false, true, new SubProgressMonitor(pm, 100)); - } else { - // TODO: have to pre-create parents if they dont exist - file.create(state.getFileState().getContents(), false, new SubProgressMonitor(pm, 100)); - } - } - } catch (CoreException e) { - throw new InvocationTargetException(e); - } finally { - pm.done(); - } - } - }; - operation.run(monitor); - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelContainer.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelContainer.java deleted file mode 100644 index c7e7808a0..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelContainer.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * 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; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.*; -import org.eclipse.core.runtime.CoreException; - -public abstract class ModelContainer extends ModelResource { - - protected ModelContainer(IContainer container) { - super(container); - } - - protected IContainer getContainer() { - return (IContainer)getResource(); - } - - public ModelObject[] getChildren() throws CoreException { - IResource[] members = getContainer().members(); - List result = new ArrayList(); - for (int i = 0; i < members.length; i++) { - IResource resource = members[i]; - if (resource instanceof IFolder) { - result.add(new ModelFolder((IFolder) resource)); - } else if (ModelObjectDefinitionFile.isModFile(resource)) { - result.add(new ModelObjectDefinitionFile((IFile)resource)); - } else if (resource instanceof IProject && ModelProject.isModProject((IProject) resource)) { - result.add(new ModelProject((IProject) resource)); - } - } - return (ModelObject[]) result.toArray(new ModelObject[result.size()]); - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelFile.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelFile.java deleted file mode 100644 index f334c0e40..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelFile.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * 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; - -import org.eclipse.core.resources.IFile; - -public abstract class ModelFile extends ModelResource { - - protected ModelFile(IFile file) { - super(file); - } - - public String getName() { - String name = super.getName(); - int index = name.lastIndexOf("."); - return name.substring(0, index); - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelFolder.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelFolder.java deleted file mode 100644 index 76447385d..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelFolder.java +++ /dev/null @@ -1,21 +0,0 @@ -/******************************************************************************* - * 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; - -import org.eclipse.core.resources.IFolder; - -public class ModelFolder extends ModelContainer { - - public ModelFolder(IFolder folder) { - super(folder); - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelNature.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelNature.java deleted file mode 100644 index d4dbb8ca1..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelNature.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * 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; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectNature; - -/** - * Nature used to identify a model project - */ -public class ModelNature implements IProjectNature { - - public static final String NATURE_ID = "org.eclipse.team.examples.filesystem.modelNature"; - - private IProject project; - - /* (non-Javadoc) - * @see org.eclipse.core.resources.IProjectNature#configure() - */ - public void configure() { - // Nothing to do - } - - /* (non-Javadoc) - * @see org.eclipse.core.resources.IProjectNature#deconfigure() - */ - public void deconfigure() { - // Nothing to do - } - - /* (non-Javadoc) - * @see org.eclipse.core.resources.IProjectNature#getProject() - */ - public IProject getProject() { - return project; - } - - /* (non-Javadoc) - * @see org.eclipse.core.resources.IProjectNature#setProject(org.eclipse.core.resources.IProject) - */ - public void setProject(IProject project) { - this.project = project; - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelObject.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelObject.java deleted file mode 100644 index adbcd4e8f..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelObject.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * 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; - -import org.eclipse.core.resources.*; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.PlatformObject; - -public abstract class ModelObject extends PlatformObject { - - public static ModelObject create(IResource resource) { - switch (resource.getType()) { - case IResource.ROOT: - return new ModelWorkspace(); - case IResource.PROJECT: - return new ModelProject((IProject)resource); - case IResource.FOLDER: - return new ModelFolder((IFolder)resource); - case IResource.FILE: - if (ModelObjectDefinitionFile.isModFile(resource)) { - return new ModelObjectDefinitionFile((IFile)resource); - } - } - return null; - } - - /** - * Return the name of the model object. - * @return the name of the model object - */ - public abstract String getName(); - - /** - * Return the path of this object in the model namespace. - * @return the path of this object in the model namespace - */ - public abstract String getPath(); - - /** - * Return the children of this object. - * @return the children of this object - */ - public abstract ModelObject[] getChildren() throws CoreException; - - /** - * Return the parent of this object. - * @return the parent of this object - */ - public abstract ModelObject getParent(); - - /** - * Delete the model object - */ - public abstract void delete() throws CoreException; - - /** - * Return the project that contains this model object. - * @return the project that contains this model object - */ - public abstract ModelProject getProject(); -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelObjectDefinitionFile.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelObjectDefinitionFile.java deleted file mode 100644 index a30378070..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelObjectDefinitionFile.java +++ /dev/null @@ -1,173 +0,0 @@ -/******************************************************************************* - * 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; - -import java.io.*; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.*; -import org.eclipse.core.runtime.*; -import org.eclipse.osgi.util.NLS; -import org.eclipse.team.examples.filesystem.FileSystemPlugin; - -public class ModelObjectDefinitionFile extends ModelFile { - - public static final String MODEL_OBJECT_DEFINITION_FILE_EXTENSION = "mod"; - - public static boolean isModFile(IResource resource) { - if (resource instanceof IFile) { - String fileExtension = resource.getFileExtension(); - if (fileExtension != null) - return fileExtension.equals(MODEL_OBJECT_DEFINITION_FILE_EXTENSION); - } - return false; - } - - public static IResource[] getReferencedResources(String projectName, IStorage storage) throws CoreException { - if (storage == null) - return new IResource[0]; - List result = new ArrayList(); - String[] filePaths = readLines(storage); - for (int i = 0; i < filePaths.length; i++) { - String path = filePaths[i]; - IFile file = getFile(projectName, path); - if (file != null - && file.getFileExtension() != null - && file.getFileExtension().equals(ModelObjectElementFile.MODEL_OBJECT_ELEMENTFILE_EXTENSION)) { - result.add(file); - } - } - return (IResource[]) result.toArray(new IResource[result.size()]); - } - - public ModelObjectDefinitionFile(IFile file) { - super(file); - } - - /* (non-Javadoc) - * @see org.eclipse.team.examples.model.ModelObject#getChildren() - */ - public ModelObject[] getChildren() throws CoreException { - return getModelObjectElementFiles(); - } - - public ModelObjectElementFile[] getModelObjectElementFiles() throws CoreException { - List result = new ArrayList(); - String[] filePaths = readLines((IFile)getResource()); - for (int i = 0; i < filePaths.length; i++) { - String path = filePaths[i]; - IFile file = getFile(getResource().getProject().getName(), path); - if (file != null) { - ModelObjectElementFile moeFile = getMoeFile(file); - if (moeFile != null) - result.add(moeFile); - } - } - return (ModelObjectElementFile[]) result.toArray(new ModelObjectElementFile[result.size()]); - } - - private static String[] readLines(IStorage file) throws CoreException { - BufferedReader reader = new BufferedReader(new InputStreamReader(file.getContents())); - String line = null; - List result = new ArrayList(); - try { - while ((line = reader.readLine()) != null) { - result.add(line.trim()); - } - } catch (IOException e) { - throw new CoreException(new Status(IStatus.ERROR, FileSystemPlugin.ID, 0, - NLS.bind("Error reading from file {0}", file.getFullPath()), e)); - } finally { - try { - reader.close(); - } catch (IOException e) { - // Ignore - } - } - return (String[]) result.toArray(new String[result.size()]); - } - - private void writeLines(String[] strings) throws CoreException { - StringBuffer buffer = new StringBuffer(); - for (int i = 0; i < strings.length; i++) { - String string = strings[i]; - buffer.append(string); - buffer.append("\n"); - } - ((IFile)getResource()).setContents(new ByteArrayInputStream(buffer.toString().getBytes()), false, true, null); - } - - private ModelObjectElementFile getMoeFile(IFile file) { - if (ModelObjectElementFile.isMoeFile(file)) { - return new ModelObjectElementFile(this, file); - } - return null; - } - - private static IFile getFile(String projectName, String path) { - if (path.length() == 0) - return null; - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - IStatus status = workspace.validatePath("/" + projectName + "/" + path, IResource.FILE); - if (status.isOK()) { - IProject project = workspace.getRoot().getProject(projectName); - return project.getFile(new Path(path)); - } - FileSystemPlugin.log(status); - return null; - } - - public void addMoe(IFile file) throws CoreException { - ((IFile)getResource()).appendContents(new ByteArrayInputStream(("\n" + file.getProjectRelativePath()).getBytes()), false, true, null); - } - - public void remove(ModelObjectElementFile file) throws CoreException { - ModelObjectElementFile[] files = getModelObjectElementFiles(); - List paths = new ArrayList(); - for (int i = 0; i < files.length; i++) { - ModelObjectElementFile child = files[i]; - if (!child.equals(file)) { - paths.add(child.getResource().getProjectRelativePath().toString()); - } - } - writeLines((String[]) paths.toArray(new String[paths.size()])); - } - - public void delete() throws CoreException { - ModelObjectElementFile[] files = getModelObjectElementFiles(); - super.delete(); - for (int i = 0; i < files.length; i++) { - ModelObjectElementFile file = files[i]; - file.getResource().delete(false, null); - } - } - - public void setElements(IResource[] resources) throws CoreException { - List paths = new ArrayList(); - for (int i = 0; i < resources.length; i++) { - IResource resource = resources[i]; - paths.add(resource.getProjectRelativePath().toString()); - } - writeLines((String[]) paths.toArray(new String[paths.size()])); - } - - public boolean hasMoe(IFile file) throws CoreException { - ModelObjectElementFile[] files = getModelObjectElementFiles(); - for (int i = 0; i < files.length; i++) { - ModelObjectElementFile child = files[i]; - if (child.getResource().equals(file)) - return true; - } - return false; - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelObjectElementFile.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelObjectElementFile.java deleted file mode 100644 index 84ec39268..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelObjectElementFile.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * 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; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; - -public class ModelObjectElementFile extends ModelFile { - - public static final String MODEL_OBJECT_ELEMENTFILE_EXTENSION = "moe"; - - private final ModelObjectDefinitionFile parent; - - public static boolean isMoeFile(IResource resource) { - return resource instanceof IFile - && resource.getFileExtension().equals(MODEL_OBJECT_ELEMENTFILE_EXTENSION); - } - - public ModelObjectElementFile(ModelObjectDefinitionFile parent, IFile file) { - super(file); - this.parent = parent; - } - - public ModelObject[] getChildren() { - return new ModelObject[0]; - } - - public ModelObject getParent() { - return parent; - } - - public void delete() throws CoreException { - parent.remove(this); - super.delete(); - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelProject.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelProject.java deleted file mode 100644 index 20b1241fb..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelProject.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 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; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; - -public class ModelProject extends ModelContainer { - - public static boolean isModProject(IProject project) throws CoreException { - if (! project.isOpen()) - return false; - IProjectDescription description = project.getDescription(); - return description.hasNature(ModelNature.NATURE_ID); - } - - public static void makeModProject(IProject project, IProgressMonitor monitor) throws CoreException { - IProjectDescription description = project.getDescription(); - String[] natureIds = description.getNatureIds(); - List result = new ArrayList(); - for (int i = 0; i < natureIds.length; i++) { - result.add(natureIds[i]); - } - result.add(ModelNature.NATURE_ID); - description.setNatureIds((String[]) result.toArray(new String[result.size()])); - project.setDescription(description, monitor); - } - - public ModelProject(IProject project) { - super(project); - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelResource.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelResource.java deleted file mode 100644 index c5e4a54e8..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelResource.java +++ /dev/null @@ -1,89 +0,0 @@ -/******************************************************************************* - * 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; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; - -/** - * A model object that has a corresponding resource. - * This does not indicate that the model object only - * consists of a single resource. It only means that at least - * the resource of this model element makes up the model - * element. There may be other resources included as well. - * <p> - * The model consists of the following: - * <ol> - * <li>Model object definition files (*.mod). A MOD file consists - * of a pointer to one of more model object element (*.moe) files.</li> - * <li>Model object element file (*.moe) contain one or more elements</li> - * <li>Model object projects correspond to workspace projects but only show child - * folders and MOD files when expanded.</li> - * <li>Model object folders correspond to workspace folders but only show child - * folders and MOD files when expanded.</li> - * </ol> - * - */ -public abstract class ModelResource extends ModelObject{ - private final IResource resource; - - protected ModelResource(IResource resource) { - this.resource = resource; - } - - public IResource getResource() { - return resource; - } - - public String getName() { - return getResource().getName(); - } - - public String getPath() { - return getResource().getFullPath().makeRelative().toString(); - } - - public ModelObject getParent() { - return ModelObject.create(getResource().getParent()); - } - - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals(Object obj) { - if (obj instanceof ModelResource) { - ModelResource mr = (ModelResource) obj; - return getResource().equals(mr.getResource()); - } - return super.equals(obj); - } - - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - public int hashCode() { - return getResource().hashCode(); - } - - /* (non-Javadoc) - * @see org.eclipse.team.examples.model.ModelObject#delete() - */ - public void delete() throws CoreException { - getResource().delete(false, null); - } - - /* (non-Javadoc) - * @see org.eclipse.team.examples.model.ModelObject#getProject() - */ - public ModelProject getProject() { - return (ModelProject)ModelObject.create(getResource().getProject()); - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelWorkspace.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelWorkspace.java deleted file mode 100644 index bbd26ad64..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ModelWorkspace.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * 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; - -import org.eclipse.core.resources.ResourcesPlugin; - -public class ModelWorkspace extends ModelContainer { - - protected ModelWorkspace() { - super(ResourcesPlugin.getWorkspace().getRoot()); - } - - public String getName() { - return "Model Root"; - } - - public ModelObject getParent() { - return null; - } - - public static Object getRoot() { - return new ModelWorkspace(); - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/PluginManifestChangeTracker.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/PluginManifestChangeTracker.java deleted file mode 100644 index fb9f6837c..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/PluginManifestChangeTracker.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 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; - -import java.util.*; - -import org.eclipse.core.resources.*; -import org.eclipse.core.runtime.*; -import org.eclipse.osgi.util.NLS; -import org.eclipse.team.core.mapping.ChangeTracker; -import org.eclipse.team.examples.filesystem.FileSystemPlugin; - -public class PluginManifestChangeTracker extends ChangeTracker { - - Set manifestFilePaths; - - public PluginManifestChangeTracker() { - manifestFilePaths = new HashSet(); - manifestFilePaths.add(new Path(null, "plugin.xml")); - manifestFilePaths.add(new Path(null, "plugin.properties")); - manifestFilePaths.add(new Path(null, "build.properties")); - manifestFilePaths.add(new Path(null, "META-INF/MANIFEST.MF")); - } - - protected boolean isProjectOfInterest(IProject project) { - return super.isProjectOfInterest(project) && hasPDENature(project); - } - - private boolean hasPDENature(IProject project) { - try { - return project.getDescription().hasNature("org.eclipse.pde.PluginNature"); - } catch (CoreException e) { - FileSystemPlugin.log(new Status(e.getStatus().getSeverity(), FileSystemPlugin.ID, 0, - NLS.bind("Could not obtain project description for {0}", project.getName()), e)); - } - return false; - } - - protected void handleChanges(IProject project, IResource[] resources) { - handleProjectChange(project); - } - - protected void handleProjectChange(IProject project) { - List changes = new ArrayList(); - for (Iterator iter = manifestFilePaths.iterator(); iter.hasNext();) { - IPath path = (IPath) iter.next(); - IFile file = project.getFile(path); - try { - if (isModified(file)) { - changes.add(file); - } - } catch (CoreException e) { - FileSystemPlugin.log(new Status(e.getStatus().getSeverity(), FileSystemPlugin.ID, 0, - NLS.bind("Could not obtain diff for {0}", file.getFullPath().toString()), e)); - } - } - if (changes.size() > 1) { - groupInSet(project, (IFile[]) changes.toArray(new IFile[changes.size()])); - } - } - - private void groupInSet(IProject project, IFile[] files) { - String name = getSetName(project); - try { - ensureGrouped(project, name, files); - } catch (CoreException e) { - FileSystemPlugin.log(new Status(e.getStatus().getSeverity(), FileSystemPlugin.ID, 0, - NLS.bind("Could not create change set {0}", name), e)); - } - } - - private String getSetName(IProject project) { - return "Plugin manifest files for " + project.getName(); - } - - protected boolean isResourceOfInterest(IResource resource) { - return manifestFilePaths.contains(resource.getProjectRelativePath()); - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/mapping/ExampleModelProvider.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/mapping/ExampleModelProvider.java deleted file mode 100644 index df597d58b..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/mapping/ExampleModelProvider.java +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 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.mapping; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.*; -import org.eclipse.core.resources.mapping.*; -import org.eclipse.core.runtime.*; -import org.eclipse.osgi.util.NLS; -import org.eclipse.team.examples.filesystem.FileSystemPlugin; -import org.eclipse.team.examples.model.*; - -/** - * The model provider for our example - */ -public class ExampleModelProvider extends - org.eclipse.core.resources.mapping.ModelProvider { - - public static final String ID = "org.eclipse.team.examples.filesystem.modelProvider"; - - public ExampleModelProvider() { - super(); - } - - /* (non-Javadoc) - * @see org.eclipse.core.resources.mapping.ModelProvider#validateChange(org.eclipse.core.resources.IResourceDelta, org.eclipse.core.runtime.IProgressMonitor) - */ - public IStatus validateChange(IResourceDelta delta, IProgressMonitor monitor) { - // Visit the changes in the delta to look for changes we care about - final List problems = new ArrayList(); - try { - delta.accept(new IResourceDeltaVisitor() { - public boolean visit(IResourceDelta delta) throws CoreException { - IResource resource = delta.getResource(); - if (ModelObjectElementFile.isMoeFile(resource)) { - // Removal may leave a stale reference in a MOD file - if (delta.getKind() == IResourceDelta.REMOVED) { - IStatus status = new ModelStatus(IStatus.ERROR, FileSystemPlugin.ID, getDescriptor().getId(), - NLS.bind("Deleting file {0} may corrupt any model definition that references it.", resource.getFullPath())); - problems.add(status); - } - } - if (ModelObjectDefinitionFile.isModFile(resource)) { - // Removal may leave unreferenced MOE files around - if (delta.getKind() == IResourceDelta.REMOVED) { - IStatus status = new ModelStatus(IStatus.WARNING, FileSystemPlugin.ID, getDescriptor().getId(), - NLS.bind("Deleting file {0} may result in unreferenced element files.", resource.getFullPath())); - problems.add(status); - } - if (delta.getKind() == IResourceDelta.ADDED - && ((delta.getFlags() & IResourceDelta.COPIED_FROM) > 0)) { - // Copying will result in two MOD files that reference the same elements - IStatus status = new ModelStatus(IStatus.ERROR, FileSystemPlugin.ID, getDescriptor().getId(), - NLS.bind("Copying file {0} may corrupt the model defintion.", delta.getMovedFromPath())); - problems.add(status); - } - } - return delta.getResource().getType() == IResource.ROOT - || ModelProject.isModProject(delta.getResource().getProject()); - } - }); - } catch (CoreException e) { - FileSystemPlugin.log(e); - } - if (problems.size() == 1) - return (IStatus)problems.get(0); - else if (problems.size() > 1) { - return new MultiStatus(FileSystemPlugin.ID, 0, (IStatus[]) problems.toArray(new IStatus[problems.size()]), "Multiple potential side effects have been found.", null); - } - return super.validateChange(delta, monitor); - } - - public ResourceMapping[] getMappings(IResource resource, ResourceMappingContext context, IProgressMonitor monitor) throws CoreException { - if (ModelProject.isModProject(resource.getProject())) { - ModelObject object = ModelObject.create(resource); - if (object != null) - return new ResourceMapping[] { (ResourceMapping)object.getAdapter(ResourceMapping.class) }; - } - return super.getMappings(resource, context, monitor); - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/mapping/ModResourceMapping.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/mapping/ModResourceMapping.java deleted file mode 100644 index 02f49fb1e..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/mapping/ModResourceMapping.java +++ /dev/null @@ -1,101 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 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.mapping; - -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.mapping.*; -import org.eclipse.core.runtime.*; -import org.eclipse.team.examples.filesystem.FileSystemPlugin; -import org.eclipse.team.examples.model.*; - -public class ModResourceMapping extends ModelResourceMapping { - - public ModResourceMapping(ModelObjectDefinitionFile file) { - super(file); - } - - /* (non-Javadoc) - * @see org.eclipse.core.resources.mapping.ResourceMapping#getTraversals(org.eclipse.core.resources.mapping.ResourceMappingContext, org.eclipse.core.runtime.IProgressMonitor) - */ - public ResourceTraversal[] getTraversals(ResourceMappingContext context, - IProgressMonitor monitor) throws CoreException { - Set resources = getLocalResources(); - if (context instanceof RemoteResourceMappingContext) { - monitor.beginTask(null, IProgressMonitor.UNKNOWN); - RemoteResourceMappingContext remoteContext = (RemoteResourceMappingContext) context; - if (remoteContext.hasRemoteChange(getResource(), new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN))) { - IResource[] remoteResources = ModelObjectDefinitionFile.getReferencedResources( - getResource().getProject().getName(), - remoteContext.fetchRemoteContents((IFile)getResource(), - new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN))); - for (int i = 0; i < remoteResources.length; i++) { - IResource resource = remoteResources[i]; - resources.add(resource); - } - } - if (remoteContext.isThreeWay() - && remoteContext.hasLocalChange(getResource(), new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN))) { - IResource[] remoteResources = ModelObjectDefinitionFile.getReferencedResources( - getResource().getProject().getName(), - remoteContext.fetchBaseContents((IFile)getResource(), - new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN))); - for (int i = 0; i < remoteResources.length; i++) { - IResource resource = remoteResources[i]; - resources.add(resource); - } - } - monitor.done(); - } - return new ResourceTraversal[] { - new ResourceTraversal((IResource[]) resources.toArray(new IResource[resources.size()]), - IResource.DEPTH_ZERO, IResource.NONE) - }; - } - - private IResource getResource() { - return ((ModelResource)getModelObject()).getResource(); - } - - private Set getLocalResources() throws CoreException { - ModelObjectDefinitionFile mdf = (ModelObjectDefinitionFile)getModelObject(); - Set resources = new HashSet(); - resources.add(mdf.getResource()); - ModelObjectElementFile[] files = mdf.getModelObjectElementFiles(); - for (int i = 0; i < files.length; i++) { - ModelObjectElementFile file = files[i]; - resources.add(file.getResource()); - } - return resources; - } - - /* (non-Javadoc) - * @see org.eclipse.core.resources.mapping.ResourceMapping#contains(org.eclipse.core.resources.mapping.ResourceMapping) - */ - public boolean contains(ResourceMapping mapping) { - if (mapping instanceof ModelResourceMapping) { - ModelObject object = (ModelObject)mapping.getModelObject(); - if (object instanceof ModelResource) { - IResource resource = ((ModelResource) object).getResource(); - try { - return getLocalResources().contains(resource); - } catch (CoreException e) { - FileSystemPlugin.log(e); - } - } - } - return false; - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/mapping/ModelContainerResourceMapping.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/mapping/ModelContainerResourceMapping.java deleted file mode 100644 index d6dd9c066..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/mapping/ModelContainerResourceMapping.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 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.mapping; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.mapping.ResourceMapping; -import org.eclipse.core.resources.mapping.ResourceMappingContext; -import org.eclipse.core.resources.mapping.ResourceTraversal; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.examples.model.ModelContainer; -import org.eclipse.team.examples.model.ModelObject; -import org.eclipse.team.examples.model.ModelResource; - -public class ModelContainerResourceMapping extends ModelResourceMapping { - - public ModelContainerResourceMapping(ModelContainer container) { - super(container); - } - - /* (non-Javadoc) - * @see org.eclipse.core.resources.mapping.ResourceMapping#getTraversals(org.eclipse.core.resources.mapping.ResourceMappingContext, org.eclipse.core.runtime.IProgressMonitor) - */ - public ResourceTraversal[] getTraversals(ResourceMappingContext context, - IProgressMonitor monitor) { - return new ResourceTraversal[] { - new ResourceTraversal(new IResource[] { - getResource() - }, IResource.DEPTH_INFINITE, IResource.NONE) - }; - } - - private IResource getResource() { - return ((ModelContainer)getModelObject()).getResource(); - } - - /* (non-Javadoc) - * @see org.eclipse.core.resources.mapping.ResourceMapping#contains(org.eclipse.core.resources.mapping.ResourceMapping) - */ - public boolean contains(ResourceMapping mapping) { - if (mapping instanceof ModelResourceMapping) { - ModelObject object = (ModelObject)mapping.getModelObject(); - if (object instanceof ModelResource) { - IResource resource = ((ModelResource) object).getResource(); - return getResource().getFullPath().isPrefixOf(resource.getFullPath()); - } - } - return false; - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/mapping/ModelMerger.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/mapping/ModelMerger.java deleted file mode 100644 index e69a53c72..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/mapping/ModelMerger.java +++ /dev/null @@ -1,299 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 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.mapping; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.mapping.ResourceMapping; -import org.eclipse.core.resources.mapping.ResourceTraversal; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.team.core.diff.FastDiffFilter; -import org.eclipse.team.core.diff.IDiff; -import org.eclipse.team.core.diff.IDiffVisitor; -import org.eclipse.team.core.diff.IThreeWayDiff; -import org.eclipse.team.core.history.IFileRevision; -import org.eclipse.team.core.mapping.IMergeContext; -import org.eclipse.team.core.mapping.IResourceDiff; -import org.eclipse.team.core.mapping.ResourceMappingMerger; -import org.eclipse.team.core.mapping.provider.MergeStatus; -import org.eclipse.team.core.mapping.provider.ResourceDiffTree; -import org.eclipse.team.core.mapping.provider.SynchronizationContext; -import org.eclipse.team.examples.filesystem.FileSystemPlugin; -import org.eclipse.team.examples.model.ModelObject; -import org.eclipse.team.examples.model.ModelObjectDefinitionFile; -import org.eclipse.team.examples.model.ModelProject; - -/** - * A resource mapping merger for our example model - */ -public class ModelMerger extends ResourceMappingMerger { - - private final org.eclipse.team.examples.model.mapping.ExampleModelProvider provider; - - public ModelMerger(org.eclipse.team.examples.model.mapping.ExampleModelProvider provider) { - this.provider = provider; - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.mapping.ResourceMappingMerger#getModelProvider() - */ - protected org.eclipse.core.resources.mapping.ModelProvider getModelProvider() { - return provider; - } - - /* (non-Javadoc) - * @see org.eclipse.team.core.mapping.ResourceMappingMerger#merge(org.eclipse.team.core.mapping.IMergeContext, org.eclipse.core.runtime.IProgressMonitor) - */ - public IStatus merge(IMergeContext mergeContext, IProgressMonitor monitor) throws CoreException { - try { - IStatus status; - // Only override the merge for three-way synchronizations - if (mergeContext.getType() == SynchronizationContext.THREE_WAY) { - monitor.beginTask("Merging model elements", 100); - status = mergeModelElements(mergeContext, new SubProgressMonitor(monitor, 50)); - // Stop the merge if there was a failure - if (!status.isOK()) - return status; - // We need to wait for any background processing to complete for the context - // so the diff tree will be up-to-date when we delegate the rest of the merge - // to the superclass - try { - Job.getJobManager().join(mergeContext, new SubProgressMonitor(monitor, 50)); - } catch (InterruptedException e) { - // Ignore - } - // Delegate the rest of the merge to the superclass - status = super.merge(mergeContext, monitor); - } else { - status = super.merge(mergeContext, monitor); - } - return status; - } finally { - monitor.done(); - } - } - - /* - * Merge all the model element changes in the context - */ - private IStatus mergeModelElements(IMergeContext mergeContext, IProgressMonitor monitor) throws CoreException { - try { - IDiff[] modeDiffs = getModDiffs(mergeContext); - List failures = new ArrayList(); - monitor.beginTask(null, 100 * modeDiffs.length); - for (int i = 0; i < modeDiffs.length; i++) { - IDiff diff = modeDiffs[i]; - if (!mergeModelElement(mergeContext, diff, new SubProgressMonitor(monitor, 100))) { - failures.add(diff); - } - } - if (failures.size() > 0) { - return new MergeStatus(FileSystemPlugin.ID, "Several objects could not be merged", getMappings(failures)); - } - return Status.OK_STATUS; - } finally { - monitor.done(); - } - } - - private ResourceMapping[] getMappings(List failures) { - List mappings = new ArrayList(); - for (Iterator iter = failures.iterator(); iter.hasNext();) { - IDiff diff = (IDiff) iter.next(); - IResource resource = ResourceDiffTree.getResourceFor(diff); - ModelObjectDefinitionFile file = (ModelObjectDefinitionFile)ModelObject.create(resource); - mappings.add(file.getAdapter(ResourceMapping.class)); - } - return (ResourceMapping[]) mappings.toArray(new ResourceMapping[mappings.size()]); - } - - /* - * Return all the diffs for MOD files. - */ - private IDiff[] getModDiffs(IMergeContext mergeContext) { - final List result = new ArrayList(); - mergeContext.getDiffTree().accept(getModelProjectTraversals(mergeContext), new IDiffVisitor() { - public boolean visit(IDiff diff) { - IResource resource = ResourceDiffTree.getResourceFor(diff); - if (ModelObjectDefinitionFile.isModFile(resource)) { - result.add(diff); - } - return true; - } - - }); - return (IDiff[]) result.toArray(new IDiff[result.size()]); - } - - /* - * Return a traversal that covers all the model projects in the scope of the merge. - */ - private ResourceTraversal[] getModelProjectTraversals(IMergeContext mergeContext) { - IProject[] scopeProjects = mergeContext.getScope().getProjects(); - List modelProjects = new ArrayList(); - for (int i = 0; i < scopeProjects.length; i++) { - IProject project = scopeProjects[i]; - try { - if (ModelProject.isModProject(project)) { - modelProjects.add(project); - } - } catch (CoreException e) { - FileSystemPlugin.log(e); - } - } - if (modelProjects.isEmpty()) - return new ResourceTraversal[0]; - return new ResourceTraversal[] { - new ResourceTraversal((IResource[]) modelProjects.toArray(new IResource[modelProjects.size()]), - IResource.DEPTH_INFINITE, IResource.NONE) - }; - } - - /* - * Merge the model definition file and all the element files it contains. - */ - private boolean mergeModelElement(IMergeContext mergeContext, IDiff diff, IProgressMonitor monitor) throws CoreException { - if (diff instanceof IThreeWayDiff) { - IThreeWayDiff twd = (IThreeWayDiff) diff; - if (twd.getDirection() == IThreeWayDiff.INCOMING - || twd.getDirection() == IThreeWayDiff.CONFLICTING) { - IResource resource = ResourceDiffTree.getResourceFor(diff); - - // First, check if a change conflicts with a deletion - if (twd.getDirection() == IThreeWayDiff.CONFLICTING) { - if (!resource.exists()) - return false; - if (((IResourceDiff)twd.getRemoteChange()).getAfterState() == null) - return false; - } - - // First determine the element files and element file changes - IResourceDiff remoteChange = (IResourceDiff)twd.getRemoteChange(); - IResource[] localElements = getReferencedResources(resource); - IResource[] baseElements = getReferencedResources(resource.getProject().getName(), remoteChange.getBeforeState(), monitor); - IResource[] remoteElements = getReferencedResources(resource.getProject().getName(), remoteChange.getAfterState(), monitor); - IResource[] addedElements = getAddedElements(baseElements, remoteElements); - // Trick: The removed elements can be obtained by reversing the base and remote and looking for added - IResource[] removedElements = getAddedElements(remoteElements, baseElements); - - // Check to see if any removed elements have changed locally - if (hasOutgoingChanges(mergeContext, removedElements)) { - return false; - } - - // Now try to merge all the element files involved - Set elementFiles = new HashSet(); - elementFiles.addAll(Arrays.asList(baseElements)); - elementFiles.addAll(Arrays.asList(localElements)); - elementFiles.addAll(Arrays.asList(remoteElements)); - if (!mergeElementFiles(mergeContext, (IResource[]) elementFiles.toArray(new IResource[elementFiles.size()]), monitor)) { - return false; - } - - // Finally, merge the model definition - if (!resource.exists()) { - // This is a new model definition so just merge it - IStatus status = mergeContext.merge(diff, false, monitor); - if (!status.isOK()) - return false; - } else { - // Update the contents of the model definition file - ModelObjectDefinitionFile file = (ModelObjectDefinitionFile)ModelObject.create(resource); - elementFiles = new HashSet(); - elementFiles.addAll(Arrays.asList(localElements)); - elementFiles.addAll(Arrays.asList(addedElements)); - elementFiles.removeAll(Arrays.asList(removedElements)); - file.setElements((IResource[]) elementFiles.toArray(new IResource[elementFiles.size()])); - // Let the merge context know we handled the file - mergeContext.markAsMerged(diff, false, monitor); - } - } - } - return true; - } - - private boolean mergeElementFiles(IMergeContext mergeContext, IResource[] resources, IProgressMonitor monitor) throws CoreException { - IDiff[] diffs = getDiffs(mergeContext, resources); - IStatus status = mergeContext.merge(diffs, false, monitor); - return status.isOK(); - } - - private IDiff[] getDiffs(IMergeContext mergeContext, IResource[] resources) { - Set diffSet = new HashSet(); - for (int i = 0; i < resources.length; i++) { - IResource resource = resources[i]; - IDiff[] diffs = mergeContext.getDiffTree().getDiffs(resource, IResource.DEPTH_ZERO); - diffSet.addAll(Arrays.asList(diffs)); - } - return (IDiff[]) diffSet.toArray(new IDiff[diffSet.size()]); - } - - private boolean hasOutgoingChanges(IMergeContext mergeContext, IResource[] removedElements) { - FastDiffFilter fastDiffFilter = new FastDiffFilter() { - public boolean select(IDiff diff) { - if (diff instanceof IThreeWayDiff) { - IThreeWayDiff twd = (IThreeWayDiff) diff; - return twd.getDirection() == IThreeWayDiff.OUTGOING || twd.getDirection() == IThreeWayDiff.CONFLICTING; - } - return false; - } - }; - for (int i = 0; i < removedElements.length; i++) { - IResource resource = removedElements[i]; - if (mergeContext.getDiffTree().hasMatchingDiffs(resource.getFullPath(), fastDiffFilter)) - return true; - } - return false; - } - - private IResource[] getAddedElements(IResource[] baseElements, IResource[] remoteElements) { - List result = new ArrayList(); - Set base = new HashSet(); - for (int i = 0; i < baseElements.length; i++) { - IResource resource = baseElements[i]; - base.add(resource); - } - for (int i = 0; i < remoteElements.length; i++) { - IResource resource = remoteElements[i]; - if (!base.contains(resource)) - result.add(resource); - } - return (IResource[]) result.toArray(new IResource[result.size()]); - } - - private IResource[] getReferencedResources(IResource resource) throws CoreException { - if (resource instanceof IFile && resource.exists()) { - return ModelObjectDefinitionFile.getReferencedResources(resource.getProject().getName(), (IFile) resource); - } - return new IResource[0]; - } - - private IResource[] getReferencedResources(String projectName, IFileRevision revision, IProgressMonitor monitor) throws CoreException { - if (revision != null) { - return ModelObjectDefinitionFile.getReferencedResources(projectName, revision.getStorage(monitor)); - } - return new IResource[0]; - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/mapping/ModelResourceMapping.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/mapping/ModelResourceMapping.java deleted file mode 100644 index e936a94fa..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/mapping/ModelResourceMapping.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * 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.mapping; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.mapping.ResourceMapping; -import org.eclipse.team.examples.model.*; - -public abstract class ModelResourceMapping extends ResourceMapping { - - private final ModelObject object; - - public static ResourceMapping create(ModelObject object) { - if (object instanceof ModelContainer) { - return new ModelContainerResourceMapping((ModelContainer) object); - } - if (object instanceof ModelObjectDefinitionFile) { - return new ModResourceMapping((ModelObjectDefinitionFile) object); - } - if (object instanceof ModelObjectElementFile) { - return new MoeResourceMapping((ModelObjectElementFile) object); - } - return null; - } - - protected ModelResourceMapping(ModelObject object) { - this.object = object; - } - - /* (non-Javadoc) - * @see org.eclipse.core.resources.mapping.ResourceMapping#getModelObject() - */ - public Object getModelObject() { - return object; - } - - /* (non-Javadoc) - * @see org.eclipse.core.resources.mapping.ResourceMapping#getModelProviderId() - */ - public String getModelProviderId() { - return ExampleModelProvider.ID; - } - - /* (non-Javadoc) - * @see org.eclipse.core.resources.mapping.ResourceMapping#getProjects() - */ - public IProject[] getProjects() { - return new IProject[] { (IProject)object.getProject().getResource() }; - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/mapping/MoeResourceMapping.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/mapping/MoeResourceMapping.java deleted file mode 100644 index 0cf5e5ae7..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/mapping/MoeResourceMapping.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 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.mapping; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.mapping.ResourceMapping; -import org.eclipse.core.resources.mapping.ResourceMappingContext; -import org.eclipse.core.resources.mapping.ResourceTraversal; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.examples.model.ModelObjectElementFile; -import org.eclipse.team.examples.model.ModelResource; - -public class MoeResourceMapping extends ModelResourceMapping { - - public MoeResourceMapping(ModelObjectElementFile file) { - super(file); - } - - /* (non-Javadoc) - * @see org.eclipse.core.resources.mapping.ResourceMapping#getTraversals(org.eclipse.core.resources.mapping.ResourceMappingContext, org.eclipse.core.runtime.IProgressMonitor) - */ - public ResourceTraversal[] getTraversals(ResourceMappingContext context, - IProgressMonitor monitor) { - return new ResourceTraversal[] { - new ResourceTraversal(new IResource[] { - getResource() - }, IResource.DEPTH_ZERO, IResource.NONE) - }; - } - - private IResource getResource() { - return ((ModelResource)getModelObject()).getResource(); - } - - /* (non-Javadoc) - * @see org.eclipse.core.resources.mapping.ResourceMapping#contains(org.eclipse.core.resources.mapping.ResourceMapping) - */ - public boolean contains(ResourceMapping mapping) { - if (mapping.equals(this)) - return true; - return false; - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/AdapterFactory.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/AdapterFactory.java deleted file mode 100644 index ce0ce565c..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/AdapterFactory.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * 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; - -import org.eclipse.core.resources.mapping.ResourceMapping; -import org.eclipse.core.runtime.IAdapterFactory; -import org.eclipse.team.core.mapping.IResourceMappingMerger; -import org.eclipse.team.examples.filesystem.ui.FileSystemHistoryPageSource; -import org.eclipse.team.examples.model.ModelObject; -import org.eclipse.team.examples.model.mapping.ExampleModelProvider; -import org.eclipse.team.examples.model.mapping.ModelMerger; -import org.eclipse.team.examples.model.mapping.ModelResourceMapping; -import org.eclipse.team.examples.model.ui.mapping.CompareAdapter; -import org.eclipse.team.ui.history.IHistoryPageSource; -import org.eclipse.team.ui.mapping.ISynchronizationCompareAdapter; -import org.eclipse.ui.model.IWorkbenchAdapter; - -public class AdapterFactory implements IAdapterFactory { - - private IWorkbenchAdapter modelAdapter = new ModelWorkbenchAdapter(); - private ModelMerger modelMerger; - private CompareAdapter compareAdapter; - private static Object historyPageSource = new FileSystemHistoryPageSource(); - - public Object getAdapter(Object adaptableObject, Class adapterType) { - if (adapterType == IWorkbenchAdapter.class && adaptableObject instanceof ModelObject) - return modelAdapter; - if (adapterType == ResourceMapping.class && adaptableObject instanceof ModelObject) - return ModelResourceMapping.create((ModelObject)adaptableObject); - if (adapterType == IResourceMappingMerger.class && adaptableObject instanceof ExampleModelProvider) { - if (modelMerger == null) { - modelMerger = new ModelMerger((ExampleModelProvider)adaptableObject); - } - return modelMerger; - } - if (adapterType == ISynchronizationCompareAdapter.class && adaptableObject instanceof ExampleModelProvider) { - if (compareAdapter == null) { - compareAdapter = new CompareAdapter((ExampleModelProvider)adaptableObject); - } - return compareAdapter; - } - - if (adapterType == IHistoryPageSource.class){ - return historyPageSource; - } - - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList() - */ - public Class[] getAdapterList() { - return new Class[] { IWorkbenchAdapter.class, ResourceMapping.class, IResourceMappingMerger.class, ISynchronizationCompareAdapter.class }; - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/ModelNavigatorActionProvider.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/ModelNavigatorActionProvider.java deleted file mode 100644 index bddb2a1bf..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/ModelNavigatorActionProvider.java +++ /dev/null @@ -1,214 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 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; - -import java.io.ByteArrayInputStream; -import java.util.Iterator; - -import org.eclipse.core.resources.*; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.Path; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.jface.dialogs.InputDialog; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.team.examples.model.*; -import org.eclipse.team.internal.ui.Utils; -import org.eclipse.ui.navigator.*; - -/** - * Model action provider for use with the Common Navigator framework. The - * purpose of this example is to illustrate logical model integration support in - * Eclipse and, more specifically, Team. It should not be taken as an - * illustration of other features (e.g. UI responsiveness, etc). - */ -public class ModelNavigatorActionProvider extends CommonActionProvider { - - private Action newModAction; - private Action newFolderAction; - private Action newMoeAction; - private Action deleteAction; - private Action makeDirty; - - public ModelNavigatorActionProvider() { - super(); - } - - public void init(ICommonActionExtensionSite aSite) { - super.init(aSite); - createActions(); - } - - private void createActions() { - deleteAction = new Action("Delete") { - public void run() { - IStructuredSelection selection = (IStructuredSelection)getContext().getSelection(); - try { - for (Iterator iter = selection.iterator(); iter.hasNext();) { - Object element = iter.next(); - if (element instanceof ModelObject) { - ModelObject mo = (ModelObject) element; - mo.delete(); - } - } - } catch (CoreException e) { - ErrorDialog.openError(getShell(), null, null, e.getStatus()); - } - } - }; - newFolderAction = new Action("Create Folder") { - public void run() { - IContainer container = getSelectedContainer(); - if (container != null) { - String name = promptForName(); - if (name == null) - return; - IFolder folder = container.getFolder(new Path(name)); - try { - folder.create(false, true, null); - } catch (CoreException e) { - ErrorDialog.openError(getShell(), null, null, e.getStatus()); - } - } - } - - private String promptForName() { - InputDialog dialog = new InputDialog(getShell(), "Enter Name", "Enter the name of the new folder", "New Folder", null); - int result = dialog.open(); - if (result == Window.OK) { - return dialog.getValue(); - } - return null; - } - }; - newModAction = new Action("Create MOD File") { - public void run() { - IContainer container = getSelectedContainer(); - if (container != null) { - String name = promptForName(); - if (name == null) - return; - if (!name.endsWith(".mod")) - name += ".mod"; - IFile file = container.getFile(new Path(name)); - try { - file.create(new ByteArrayInputStream("".getBytes()), false, null); - } catch (CoreException e) { - ErrorDialog.openError(getShell(), null, null, e.getStatus()); - } - } - } - - private String promptForName() { - InputDialog dialog = new InputDialog(getShell(), "Enter Name", "Enter the name of the new model object", "New Object", null); - int result = dialog.open(); - if (result == Window.OK) { - return dialog.getValue(); - } - return null; - } - }; - newMoeAction = new Action("Create MOE File") { - public void run() { - ModelObjectDefinitionFile modFile = getSelectedModFile(); - if (modFile != null) { - String path = promptForPath((ModelContainer)modFile.getParent()); - if (path == null) - return; - if (!path.endsWith(".moe")) - path += ".moe"; - ModelContainer parent = (ModelContainer)modFile.getParent(); - IFile file = ((IContainer)parent.getResource()).getFile(new Path(path)); - try { - file.create(new ByteArrayInputStream("".getBytes()), false, null); - modFile.addMoe(file); - } catch (CoreException e) { - ErrorDialog.openError(getShell(), null, null, e.getStatus()); - } - } - } - - private String promptForPath(ModelContainer parent) { - InputDialog dialog = new InputDialog(getShell(), "Enter Path", "Enter the path of the new model element relative to " + parent.getPath(), "New Element", null); - int result = dialog.open(); - if (result == Window.OK) { - return dialog.getValue(); - } - return null; - } - }; - makeDirty = new Action("Make Dirty") { - public void run() { - IStructuredSelection selection = (IStructuredSelection)getContext().getSelection(); - for (Iterator iter = selection.iterator(); iter.hasNext();) { - Object element = iter.next(); - if (element instanceof ModelObjectDefinitionFile) { - ModelObjectDefinitionFile mo = (ModelObjectDefinitionFile) element; - ModelSaveablesProvider provider = getSaveablesProvider(); - provider.makeDirty(mo); - } - } - } - - private ModelSaveablesProvider getSaveablesProvider() { - ITreeContentProvider provider = getActionSite().getContentService().getContentExtensionById("org.eclipse.team.examples.model.navigator").getContentProvider(); - return (ModelSaveablesProvider)Utils.getAdapter(provider, SaveablesProvider.class); - } - }; - } - - protected Shell getShell() { - return getActionSite().getViewSite().getShell(); - } - - public void fillContextMenu(IMenuManager menu) { - super.fillContextMenu(menu); - menu.add(deleteAction); - IContainer container = getSelectedContainer(); - if (container != null) { - menu.add(newFolderAction); - menu.add(newModAction); - } - ModelObjectDefinitionFile modFile = getSelectedModFile(); - if (modFile != null) { - menu.add(newMoeAction); - menu.add(makeDirty); - } - } - - IContainer getSelectedContainer() { - IStructuredSelection selection = (IStructuredSelection)getContext().getSelection(); - if (selection.size() == 1) { - Object o = selection.getFirstElement(); - if (o instanceof ModelContainer) { - ModelContainer mc = (ModelContainer) o; - return (IContainer)mc.getResource(); - } - } - return null; - } - - ModelObjectDefinitionFile getSelectedModFile() { - IStructuredSelection selection = (IStructuredSelection)getContext().getSelection(); - if (selection.size() == 1) { - Object o = selection.getFirstElement(); - if (o instanceof ModelObjectDefinitionFile) { - return (ModelObjectDefinitionFile) o; - } - } - return null; - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/ModelNavigatorContentProvider.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/ModelNavigatorContentProvider.java deleted file mode 100644 index 2e1d35c46..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/ModelNavigatorContentProvider.java +++ /dev/null @@ -1,330 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 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; - -import java.util.*; - -import org.eclipse.core.resources.*; -import org.eclipse.core.runtime.*; -import org.eclipse.jface.viewers.AbstractTreeViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.widgets.Display; -import org.eclipse.team.examples.filesystem.FileSystemPlugin; -import org.eclipse.team.examples.model.*; -import org.eclipse.team.ui.mapping.*; -import org.eclipse.ui.IMemento; -import org.eclipse.ui.model.BaseWorkbenchContentProvider; -import org.eclipse.ui.navigator.*; - -/** - * Model content provider for use with the Common Navigator framework. - * It makes use of an IWorkbenchAdapter to get the children and parent - * of model objects. It also makes use of the Common Navigator pipeline - * to override the resource content extension so that model projects will - * replace the corresponding resource project in the Project Explorer. - */ -public class ModelNavigatorContentProvider extends BaseWorkbenchContentProvider - implements ICommonContentProvider, IResourceChangeListener, IPipelinedTreeContentProvider, ITeamStateChangeListener, IAdaptable { - - private ICommonContentExtensionSite extensionSite; - private boolean isWorkspaceRoot; - private Viewer viewer; - private final boolean updateViewer; - private SynchronizationStateTester syncStateTester; - private Object saveablesProvider = new ModelSaveablesProvider(); - - public ModelNavigatorContentProvider() { - super(); - updateViewer = true; - } - - /** - * Create a contentProvider - * @param updateViewer whether this content provider is reponsible for updating the viewer - */ - public ModelNavigatorContentProvider(boolean updateViewer) { - this.updateViewer = updateViewer; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.navigator.ICommonContentProvider#init(org.eclipse.ui.navigator.ICommonContentExtensionSite) - */ - public void init(ICommonContentExtensionSite aConfig) { - extensionSite = aConfig; - if (updateViewer) { - ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE); - // Use a synchronization state tester to listen for team state changes - syncStateTester = new SynchronizationStateTester(); - syncStateTester.getTeamStateProvider().addDecoratedStateChangeListener(this); - } - } - - /* (non-Javadoc) - * @see org.eclipse.ui.model.BaseWorkbenchContentProvider#dispose() - */ - public void dispose() { - super.dispose(); - ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); - if (syncStateTester != null) - syncStateTester.getTeamStateProvider().removeDecoratedStateChangeListener(this); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.navigator.IMementoAware#restoreState(org.eclipse.ui.IMemento) - */ - public void restoreState(IMemento aMemento) { - // Nothing to do - } - - /* (non-Javadoc) - * @see org.eclipse.ui.navigator.IMementoAware#saveState(org.eclipse.ui.IMemento) - */ - public void saveState(IMemento aMemento) { - // Nothing to do - } - - /** - * Return the extension site for this label provider. - * @return the extension site for this label provider - */ - public ICommonContentExtensionSite getExtensionSite() { - return extensionSite; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.model.BaseWorkbenchContentProvider#getElements(java.lang.Object) - */ - public Object[] getElements(Object element) { - // Since we are used in the project explorer, the root may be - // an IWorkspaceRoot. We need to change it to the ModelWorkspace - if (element instanceof IWorkspaceRoot) { - isWorkspaceRoot = true; - return super.getElements(ModelObject.create((IWorkspaceRoot)element)); - - } - return super.getElements(element); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.model.BaseWorkbenchContentProvider#getParent(java.lang.Object) - */ - public Object getParent(Object element) { - Object parent = super.getParent(element); - if (isWorkspaceRoot && parent instanceof ModelWorkspace) { - return ((ModelWorkspace)parent).getResource(); - } - return parent; - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - this.viewer = viewer; - super.inputChanged(viewer, oldInput, newInput); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.mapping.ITeamStateChangeListener#teamStateChanged(org.eclipse.team.ui.mapping.ITeamStateChangeEvent) - */ - public void teamStateChanged(ITeamStateChangeEvent event) { - // We need to listen to team state changes in order to determine when we need - // to perform label updates on model elements. - // We actually just refresh all projects that contain changes. - // This is inefficient but will do for an example - Set refreshProjects = new HashSet(); - IResource[] addedRoots = event.getAddedRoots(); - for (int i = 0; i < addedRoots.length; i++) { - IResource resource = addedRoots[i]; - if (isModelProject(resource.getProject())) { - refreshProjects.add(ModelObject.create(resource.getProject())); - } - } - IResource[] removedRoots = event.getRemovedRoots(); - for (int i = 0; i < removedRoots.length; i++) { - IResource resource = removedRoots[i]; - if (isModelProject(resource.getProject())) { - refreshProjects.add(ModelObject.create(resource.getProject())); - } - } - IResource[] changed = event.getChangedResources(); - for (int i = 0; i < changed.length; i++) { - IResource resource = changed[i]; - if (isModelProject(resource.getProject())) { - refreshProjects.add(ModelObject.create(resource.getProject())); - } - } - - refreshProjects((ModelProject[]) refreshProjects.toArray(new ModelProject[refreshProjects.size()])); - } - - /* (non-Javadoc) - * @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent) - */ - public void resourceChanged(IResourceChangeEvent event) { - if (viewer == null) return; - IResourceDelta delta = event.getDelta(); - IResourceDelta[] children = delta.getAffectedChildren(); - boolean refreshAll = false; - List refreshProjects = new ArrayList(); - for (int i = 0; i < children.length; i++) { - IResourceDelta childDelta = children[i]; - if (isModelProject(childDelta.getResource())) { - if (isProjectChange(childDelta)) { - refreshAll = true; - break; - } - refreshProjects.add(ModelObject.create(childDelta.getResource())); - } - } - if (refreshAll || !refreshProjects.isEmpty()) { - if (refreshAll) - refreshViewer(); - else - refreshProjects((ModelProject[]) refreshProjects.toArray(new ModelProject[refreshProjects.size()])); - } - } - - private void refreshProjects(final ModelProject[] projects) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (!getViewer().getControl().isDisposed()) { - for (int i = 0; i < projects.length; i++) { - ModelProject project = projects[i]; - ((AbstractTreeViewer)getViewer()).refresh(project, true); - } - } - } - - }); - } - - private void refreshViewer() { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - if (!getViewer().getControl().isDisposed()) { - getViewer().refresh(); - } - } - - }); - } - - private boolean isProjectChange(IResourceDelta childDelta) { - if ((childDelta.getFlags() & (IResourceDelta.DESCRIPTION | IResourceDelta.OPEN)) > 0) - return true; - return false; - } - - private boolean isModelProject(IResource resource) { - try { - return ModelProject.isModProject(resource.getProject()); - } catch (CoreException e) { - FileSystemPlugin.log(e); - return false; - } - } - - Viewer getViewer() { - return viewer; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#getPipelinedChildren(java.lang.Object, java.util.Set) - */ - public void getPipelinedChildren(Object aParent, Set theCurrentChildren) { - // Nothing to do - } - - /* (non-Javadoc) - * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#getPipelinedElements(java.lang.Object, java.util.Set) - */ - public void getPipelinedElements(Object anInput, Set theCurrentElements) { - // Replace any model projects with a ModelProject - if (anInput instanceof IWorkspaceRoot) { - List newProjects = new ArrayList(); - for (Iterator iter = theCurrentElements.iterator(); iter.hasNext();) { - Object element = iter.next(); - if (element instanceof IProject) { - IProject project = (IProject) element; - try { - if (ModelProject.isModProject(project)) { - iter.remove(); - newProjects.add(ModelObject.create(project)); - } - } catch (CoreException e) { - FileSystemPlugin.log(e); - } - } - } - theCurrentElements.addAll(newProjects); - } - } - - /* (non-Javadoc) - * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#getPipelinedParent(java.lang.Object, java.lang.Object) - */ - public Object getPipelinedParent(Object anObject, Object aSuggestedParent) { - // We're not changing the parenting of any resources - return aSuggestedParent; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#interceptAdd(org.eclipse.ui.navigator.PipelinedShapeModification) - */ - public PipelinedShapeModification interceptAdd(PipelinedShapeModification anAddModification) { - if (anAddModification.getParent() instanceof IWorkspaceRoot) { - for (Iterator iter = anAddModification.getChildren().iterator(); iter.hasNext();) { - Object element = iter.next(); - if (element instanceof IProject) { - IProject project = (IProject) element; - try { - if (ModelProject.isModProject(project)) { - iter.remove(); - } - } catch (CoreException e) { - FileSystemPlugin.log(e); - } - } - } - } - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#interceptRefresh(org.eclipse.ui.navigator.PipelinedViewerUpdate) - */ - public boolean interceptRefresh(PipelinedViewerUpdate aRefreshSynchronization) { - // No need to intercept the refresh - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#interceptRemove(org.eclipse.ui.navigator.PipelinedShapeModification) - */ - public PipelinedShapeModification interceptRemove(PipelinedShapeModification aRemoveModification) { - // No need to intercept the remove - return aRemoveModification; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#interceptUpdate(org.eclipse.ui.navigator.PipelinedViewerUpdate) - */ - public boolean interceptUpdate(PipelinedViewerUpdate anUpdateSynchronization) { - // No need to intercept the update - return false; - } - - public Object getAdapter(Class adapter) { - if (adapter == SaveablesProvider.class) { - return saveablesProvider; - } - return Platform.getAdapterManager().getAdapter(this, adapter); - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/ModelNavigatorLabelProvider.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/ModelNavigatorLabelProvider.java deleted file mode 100644 index 23812e2b9..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/ModelNavigatorLabelProvider.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 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; - -import org.eclipse.team.examples.model.ModelObject; -import org.eclipse.ui.IMemento; -import org.eclipse.ui.model.WorkbenchLabelProvider; -import org.eclipse.ui.navigator.ICommonContentExtensionSite; -import org.eclipse.ui.navigator.ICommonLabelProvider; - -/** - * Model content provider for use with the Common Navigator framework. - * It makes use of an <code>IWorkbenchAdapter</code> to get the label and image - * of model objects. - */ -public class ModelNavigatorLabelProvider extends WorkbenchLabelProvider implements - ICommonLabelProvider { - - private ICommonContentExtensionSite extensionSite; - - /* (non-Javadoc) - * @see org.eclipse.ui.navigator.ICommonLabelProvider#init(org.eclipse.ui.navigator.ICommonContentExtensionSite) - */ - public void init(ICommonContentExtensionSite aConfig) { - extensionSite = aConfig; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.navigator.IMementoAware#restoreState(org.eclipse.ui.IMemento) - */ - public void restoreState(IMemento aMemento) { - // Nothing to do - } - - /* (non-Javadoc) - * @see org.eclipse.ui.navigator.IMementoAware#saveState(org.eclipse.ui.IMemento) - */ - public void saveState(IMemento aMemento) { - // Nothing to do - } - - /* (non-Javadoc) - * @see org.eclipse.ui.navigator.IDescriptionProvider#getDescription(java.lang.Object) - */ - public String getDescription(Object anElement) { - if (anElement instanceof ModelObject) { - return ((ModelObject) anElement).getPath(); - } - return null; - } - - /** - * Return the extension site for this label provider. - * @return the extension site for this label provider - */ - public ICommonContentExtensionSite getExtensionSite() { - return extensionSite; - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/ModelSaveable.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/ModelSaveable.java deleted file mode 100644 index 6131153a5..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/ModelSaveable.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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; - -import org.eclipse.core.resources.mapping.ResourceMapping; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.team.examples.model.ModelObject; -import org.eclipse.team.examples.model.ModelObjectDefinitionFile; -import org.eclipse.team.internal.ui.Utils; -import org.eclipse.ui.Saveable; - -/** - * A Saveable that represents a modified model object definition file. - */ -public class ModelSaveable extends Saveable { - - private ModelObject modelObject; - private boolean dirty; - private final ModelSaveablesProvider modelSaveablesProvider; - - public ModelSaveable(ModelSaveablesProvider modelSaveablesProvider, ModelObjectDefinitionFile mo) { - this.modelSaveablesProvider = modelSaveablesProvider; - modelObject = mo; - } - - public boolean equals(Object object) { - if (object instanceof ModelSaveable) { - ModelSaveable other = (ModelSaveable) object; - return (other.getModelObject().equals(getModelObject())); - } - return false; - } - - public ModelObject getModelObject() { - return modelObject; - } - - public ImageDescriptor getImageDescriptor() { - return ModelWorkbenchAdapter.createImageDescriptor("obj/mod_obj.gif"); - } - - public String getName() { - return modelObject.getName(); - } - - public String getToolTipText() { - return "Saveable for " + getName(); - } - - public int hashCode() { - return modelObject.hashCode(); - } - - public boolean isDirty() { - return dirty; - } - - public void doSave(IProgressMonitor monitor) { - dirty = false; - modelSaveablesProvider.saved(this); - } - - public void makeDirty() { - dirty = true; - } - - public Object getAdapter(Class adapter) { - if (adapter == ResourceMapping.class) { - return Utils.getAdapter(getModelObject(), ResourceMapping.class); - } - return super.getAdapter(adapter); - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/ModelSaveablesProvider.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/ModelSaveablesProvider.java deleted file mode 100644 index 442c4e425..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/ModelSaveablesProvider.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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; - -import java.util.*; - -import org.eclipse.team.examples.model.ModelObjectDefinitionFile; -import org.eclipse.ui.Saveable; -import org.eclipse.ui.navigator.SaveablesProvider; - -/** - * Provider used by the Common Navigator framework to link saveables to - * model elements. - */ -public class ModelSaveablesProvider extends SaveablesProvider { - - private List saveables = new ArrayList(); - - public Object[] getElements(Saveable saveable) { - if (saveable instanceof ModelSaveable) { - ModelSaveable ms = (ModelSaveable) saveable; - return new Object[] { ms.getModelObject() }; - } - return new Object[0]; - } - - public Saveable getSaveable(Object element) { - for (Iterator iterator = saveables.iterator(); iterator.hasNext();) { - ModelSaveable saveable = (ModelSaveable) iterator.next(); - if (saveable.getModelObject().equals(element)) - return saveable; - } - return null; - } - - public Saveable[] getSaveables() { - return (Saveable[]) saveables.toArray(new Saveable[saveables.size()]); - } - - public void makeDirty(ModelObjectDefinitionFile mo) { - Saveable saveable = getSaveable(mo); - if (saveable == null) { - saveable = new ModelSaveable(this, mo); - saveables.add(saveable); - fireSaveablesOpened(new Saveable[] { saveable }); - } - ((ModelSaveable)saveable).makeDirty(); - fireSaveablesDirtyChanged(new Saveable[] { saveable }); - } - - public void saved(ModelSaveable saveable) { - fireSaveablesDirtyChanged(new Saveable[] { saveable }); - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/ModelWorkbenchAdapter.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/ModelWorkbenchAdapter.java deleted file mode 100644 index 88bab8a85..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/ModelWorkbenchAdapter.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 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; - -import java.net.URL; - -import org.eclipse.core.runtime.*; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.team.examples.filesystem.FileSystemPlugin; -import org.eclipse.team.examples.model.*; -import org.eclipse.ui.model.IWorkbenchAdapter; - -/** - * The workbench adapter for ModelObjects. - */ -public class ModelWorkbenchAdapter implements IWorkbenchAdapter { - - // image path - private static final String ICON_PATH = "$nl$/icons/full/"; //$NON-NLS-1$ - - /* (non-Javadoc) - * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object) - */ - public Object[] getChildren(Object o) { - if (o instanceof ModelObject) { - ModelObject mo = (ModelObject) o; - try { - return mo.getChildren(); - } catch (CoreException e) { - FileSystemPlugin.log(e); - } - } - return new Object[0]; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.model.IWorkbenchAdapter#getImageDescriptor(java.lang.Object) - */ - public ImageDescriptor getImageDescriptor(Object object) { - if (object instanceof ModelProject) { - return createImageDescriptor("obj/prj_obj.gif"); - } - if (object instanceof ModelWorkspace) { - return createImageDescriptor("obj/root_obj.gif"); - } - if (object instanceof ModelFolder) { - return createImageDescriptor("obj/fldr_obj.gif"); - } - if (object instanceof ModelObjectDefinitionFile) { - return createImageDescriptor("obj/mod_obj.gif"); - } - if (object instanceof ModelObjectElementFile) { - return createImageDescriptor("obj/moe_obj.gif"); - } - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.model.IWorkbenchAdapter#getLabel(java.lang.Object) - */ - public String getLabel(Object o) { - if (o instanceof ModelObject) { - ModelObject mo = (ModelObject) o; - return mo.getName(); - } - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(java.lang.Object) - */ - public Object getParent(Object o) { - if (o instanceof ModelObject) { - ModelObject mo = (ModelObject) o; - return mo.getParent(); - } - return null; - } - - /** - * Creates an image descriptor. - */ - public static ImageDescriptor createImageDescriptor(String id) { - URL url = FileLocator.find(FileSystemPlugin.getPlugin().getBundle(), new Path(ICON_PATH + id), null); - return ImageDescriptor.createFromURL(url); - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/NewModelProjectWizard.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/NewModelProjectWizard.java deleted file mode 100644 index b3420deed..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/NewModelProjectWizard.java +++ /dev/null @@ -1,132 +0,0 @@ -/******************************************************************************* - * 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; - -import java.lang.reflect.InvocationTargetException; -import java.net.URI; - -import org.eclipse.core.resources.*; -import org.eclipse.core.runtime.*; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.team.examples.model.ModelNature; -import org.eclipse.ui.INewWizard; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.actions.WorkspaceModifyOperation; -import org.eclipse.ui.dialogs.WizardNewProjectCreationPage; -import org.eclipse.ui.internal.wizards.newresource.ResourceMessages; - -public class NewModelProjectWizard extends Wizard implements INewWizard { - - private WizardNewProjectCreationPage mainPage; - - public NewModelProjectWizard() { - super(); - } - - public void addPages() { - super.addPages(); - - mainPage = new WizardNewProjectCreationPage("basicNewProjectPage");//$NON-NLS-1$ - mainPage.setTitle(ResourceMessages.NewProject_title); - mainPage.setDescription(ResourceMessages.NewProject_description); - this.addPage(mainPage); - } - - public boolean performFinish() { - // get a project handle - final IProject newProjectHandle = mainPage.getProjectHandle(); - - // get a project descriptor - URI location = null; - if (!mainPage.useDefaults()) { - location = mainPage.getLocationURI(); - } - - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - final IProjectDescription description = workspace - .newProjectDescription(newProjectHandle.getName()); - description.setLocationURI(location); - description.setNatureIds(new String[] {ModelNature.NATURE_ID}); - - // create the new project operation - WorkspaceModifyOperation op = new WorkspaceModifyOperation() { - protected void execute(IProgressMonitor monitor) - throws CoreException { - createProject(description, newProjectHandle, monitor); - } - }; - - // run the new project creation operation - try { - getContainer().run(true, true, op); - } catch (InterruptedException e) { - return false; - } catch (InvocationTargetException e) { - // ie.- one of the steps resulted in a core exception - Throwable t = e.getTargetException(); - if (t instanceof CoreException) { - ErrorDialog.openError(getShell(), null, null, - ((CoreException) t).getStatus()); - } else { - MessageDialog - .openError( - getShell(), - "Error occurred", - t.getMessage()); - } - return false; - } - return true; - } - - /** - * Creates a project resource given the project handle and description. - * - * @param description - * the project description to create a project resource for - * @param projectHandle - * the project handle to create a project resource for - * @param monitor - * the progress monitor to show visual progress with - * - * @exception CoreException - * if the operation fails - * @exception OperationCanceledException - * if the operation is canceled - */ - void createProject(IProjectDescription description, IProject projectHandle, - IProgressMonitor monitor) throws CoreException, - OperationCanceledException { - try { - monitor.beginTask("", 2000);//$NON-NLS-1$ - - projectHandle.create(description, new SubProgressMonitor(monitor, - 1000)); - - if (monitor.isCanceled()) { - throw new OperationCanceledException(); - } - - projectHandle.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(monitor, 1000)); - - } finally { - monitor.done(); - } - } - - public void init(IWorkbench workbench, IStructuredSelection selection) { - // Nothing to do - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/mapping/CompareAdapter.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/mapping/CompareAdapter.java deleted file mode 100644 index 00ce39099..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/mapping/CompareAdapter.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* - * 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.compare.structuremergeviewer.ICompareInput; -import org.eclipse.core.resources.*; -import org.eclipse.core.resources.mapping.ModelProvider; -import org.eclipse.core.resources.mapping.ResourceMapping; -import org.eclipse.core.runtime.Path; -import org.eclipse.team.core.mapping.ISynchronizationContext; -import org.eclipse.team.examples.model.*; -import org.eclipse.team.examples.model.mapping.ExampleModelProvider; -import org.eclipse.team.ui.mapping.SynchronizationCompareAdapter; -import org.eclipse.ui.IMemento; - -/** - * Compare adapter for use with our example model. - */ -public class CompareAdapter extends SynchronizationCompareAdapter { - - private static final String CTX_MODEL_MAPPINGS = "org.eclipse.team.examples.filesystem.modelMappings"; - - private final ExampleModelProvider provider; - - public CompareAdapter(ExampleModelProvider provider) { - this.provider = provider; - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.mapping.SynchronizationCompareAdapter#getName(org.eclipse.core.resources.mapping.ResourceMapping) - */ - public String getName(ResourceMapping mapping) { - Object o = mapping.getModelObject(); - if (o instanceof ModelObject) { - return ((ModelObject) o).getName(); - } - return super.getName(mapping); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.mapping.SynchronizationCompareAdapter#getPathString(org.eclipse.core.resources.mapping.ResourceMapping) - */ - public String getPathString(ResourceMapping mapping) { - Object o = mapping.getModelObject(); - if (o instanceof ModelObject) { - return ((ModelObject) o).getPath(); - } - return super.getPathString(mapping); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.mapping.SynchronizationCompareAdapter#asCompareInput(org.eclipse.team.core.mapping.ISynchronizationContext, java.lang.Object) - */ - public ICompareInput asCompareInput(ISynchronizationContext context, Object o) { - if (o instanceof ModelObjectElementFile) { - ModelObjectElementFile moeFile = (ModelObjectElementFile) o; - // Use a file compare input for the model element file - return super.asCompareInput(context, moeFile.getResource()); - } - return super.asCompareInput(context, o); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.mapping.ISynchronizationCompareAdapter#restore(org.eclipse.ui.IMemento) - */ - public ResourceMapping[] restore(IMemento memento) { - List result = new ArrayList(); - IMemento[] children = memento.getChildren(CTX_MODEL_MAPPINGS); - for (int i = 0; i < children.length; i++) { - IMemento child = children[i]; - ResourceMapping mapping = restoreMapping(child); - if (mapping != null) - result.add(mapping); - } - return (ResourceMapping[]) result.toArray(new ResourceMapping[result.size()]); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.mapping.ISynchronizationCompareAdapter#save(org.eclipse.core.resources.mapping.ResourceMapping[], org.eclipse.ui.IMemento) - */ - public void save(ResourceMapping[] mappings, IMemento memento) { - for (int i = 0; i < mappings.length; i++) { - ResourceMapping mapping = mappings[i]; - Object o = mapping.getModelObject(); - if (o instanceof ModelObject) { - ModelObject mo = (ModelObject) o; - save(mo, memento.createChild(CTX_MODEL_MAPPINGS)); - } - } - - } - - private ResourceMapping restoreMapping(IMemento child) { - String parent = child.getString("definition"); - String path = child.getString("resource"); - if (parent != null) { - ModelObjectDefinitionFile modFile = (ModelObjectDefinitionFile)ModelObject.create(getResource(parent)); - if (modFile != null) - return (ResourceMapping)new ModelObjectElementFile(modFile, (IFile)getResource(path)).getAdapter(ResourceMapping.class); - } else { - ModelObject object = ModelObject.create(getResource(path)); - if (object != null) - return (ResourceMapping)object.getAdapter(ResourceMapping.class); - } - return null; - } - - private IResource getResource(String path) { - Path resourcePath = new Path(path); - if (path.endsWith(ModelObjectDefinitionFile.MODEL_OBJECT_DEFINITION_FILE_EXTENSION) - || path.endsWith(ModelObjectElementFile.MODEL_OBJECT_ELEMENTFILE_EXTENSION)) - return ResourcesPlugin.getWorkspace().getRoot().getFile(resourcePath); - if (resourcePath.segmentCount() == 1) - return ResourcesPlugin.getWorkspace().getRoot().getProject(resourcePath.lastSegment()); - return ResourcesPlugin.getWorkspace().getRoot().getFolder(resourcePath); - } - - private void save(ModelObject mo, IMemento memento) { - if (mo instanceof ModelResource) { - ModelResource resource = (ModelResource) mo; - memento.putString("resource", resource.getResource().getFullPath().toString()); - if (mo instanceof ModelObjectElementFile) { - ModelObjectElementFile moeFile = (ModelObjectElementFile) mo; - ModelObjectDefinitionFile parent = (ModelObjectDefinitionFile)moeFile.getParent(); - memento.putString("definition", parent.getResource().getFullPath().toString()); - } - } - } - - public ModelProvider getProvider() { - return provider; - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/mapping/ModelMergeActionHandler.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/mapping/ModelMergeActionHandler.java deleted file mode 100644 index 0a6f05026..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/mapping/ModelMergeActionHandler.java +++ /dev/null @@ -1,121 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 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.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.*; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.team.core.diff.*; -import org.eclipse.team.core.mapping.IMergeContext; -import org.eclipse.team.examples.model.ModelObjectDefinitionFile; -import org.eclipse.team.examples.model.ModelObjectElementFile; -import org.eclipse.team.internal.ui.mapping.ResourceModelProviderOperation; -import org.eclipse.team.ui.mapping.MergeActionHandler; -import org.eclipse.team.ui.mapping.SynchronizationOperation; -import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; - -public class ModelMergeActionHandler extends MergeActionHandler { - - /* - * Operation to merge model elements. We're using an internal superclass to save on copying - * code. - */ - private final class ModelSynchronizeOperation extends ResourceModelProviderOperation { - public ModelSynchronizeOperation(ISynchronizePageConfiguration configuration, IStructuredSelection selection) { - super(configuration, selection); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.mapping.SynchronizationOperation#execute(org.eclipse.core.runtime.IProgressMonitor) - */ - protected void execute(IProgressMonitor monitor) throws InvocationTargetException { - // We need to perform special handling for any MOE file whose parent MOD is not included in the merge - try { - IMergeContext context = (IMergeContext)getContext(); - IDiff[] diffs = getTargetDiffs(); - ModelObjectElementFile[] moeMerges = getMoeOnlyMerges(); - IStatus status = context.merge(diffs, overwrite, monitor); - if (!status.isOK()) - throw new CoreException(status); - // For now, just cycle through each lonely MOE and update the parent - for (int i = 0; i < moeMerges.length; i++) { - ModelObjectElementFile file = moeMerges[i]; - ModelObjectDefinitionFile modFile = (ModelObjectDefinitionFile)file.getParent(); - if (file.getResource().exists() && !modFile.hasMoe((IFile)file.getResource())) - modFile.addMoe((IFile)file.getResource()); - else - modFile.remove(file); - } - } catch (CoreException e) { - throw new InvocationTargetException(e); - } - } - - private ModelObjectElementFile[] getMoeOnlyMerges() { - List result = new ArrayList(); - Object[] elements = getElements(); - for (int i = 0; i < elements.length; i++) { - Object object = elements[i]; - if (object instanceof ModelObjectElementFile) { - ModelObjectElementFile moeFile = (ModelObjectElementFile) object; - result.add(moeFile); - } - } - return (ModelObjectElementFile[]) result.toArray(new ModelObjectElementFile[result.size()]); - } - - /* (non-Javadoc) - * @see org.eclipse.team.internal.ui.mapping.ResourceModelProviderOperation#getDiffFilter() - */ - protected FastDiffFilter getDiffFilter() { - return new FastDiffFilter() { - public boolean select(IDiff node) { - if (node instanceof IThreeWayDiff) { - IThreeWayDiff twd = (IThreeWayDiff) node; - if ((twd.getDirection() == IThreeWayDiff.OUTGOING && overwrite) || twd.getDirection() == IThreeWayDiff.CONFLICTING || twd.getDirection() == IThreeWayDiff.INCOMING) { - return true; - } - return false; - } - // Overwrite should always be available for two-way diffs - return overwrite; - } - }; - } - } - - final boolean overwrite; - private SynchronizationOperation operation; - - public ModelMergeActionHandler(ISynchronizePageConfiguration configuration, boolean overwrite) { - super(configuration); - this.overwrite = overwrite; - } - - protected SynchronizationOperation getOperation() { - if (operation == null) { - operation = new ModelSynchronizeOperation(getConfiguration(), getStructuredSelection()); - } - return operation; - } - - protected void updateEnablement(IStructuredSelection selection) { - synchronized (this) { - operation = null; - } - super.updateEnablement(selection); - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/mapping/ModelSyncActionProvider.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/mapping/ModelSyncActionProvider.java deleted file mode 100644 index 1ab2e2991..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/mapping/ModelSyncActionProvider.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * 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 org.eclipse.team.ui.mapping.SynchronizationActionProvider; -import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; - -/** - * The action provider that is used for synchronizations. - */ -public class ModelSyncActionProvider extends SynchronizationActionProvider { - - public ModelSyncActionProvider() { - super(); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.mapping.SynchronizationActionProvider#initialize() - */ - protected void initialize() { - super.initialize(); - final ISynchronizePageConfiguration configuration= getSynchronizePageConfiguration(); - // We provide custom handlers that ensure that the MOD files get updated properly - // when MOE files are merged. - registerHandler(MERGE_ACTION_ID, new ModelMergeActionHandler(configuration, false)); - registerHandler(OVERWRITE_ACTION_ID, new ModelMergeActionHandler(configuration, true)); - // We can just use the default mark as merged handler - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/mapping/ModelSyncContentProvider.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/mapping/ModelSyncContentProvider.java deleted file mode 100644 index 48052377d..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/mapping/ModelSyncContentProvider.java +++ /dev/null @@ -1,392 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 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.*; - -import org.eclipse.core.resources.*; -import org.eclipse.core.resources.mapping.*; -import org.eclipse.core.runtime.*; -import org.eclipse.jface.viewers.*; -import org.eclipse.swt.widgets.Tree; -import org.eclipse.swt.widgets.TreeItem; -import org.eclipse.team.core.diff.*; -import org.eclipse.team.core.mapping.ISynchronizationContext; -import org.eclipse.team.core.mapping.ISynchronizationScope; -import org.eclipse.team.core.mapping.provider.ResourceDiffTree; -import org.eclipse.team.examples.filesystem.FileSystemPlugin; -import org.eclipse.team.examples.model.*; -import org.eclipse.team.examples.model.mapping.ExampleModelProvider; -import org.eclipse.team.examples.model.ui.ModelNavigatorContentProvider; -import org.eclipse.team.internal.ui.Utils; -import org.eclipse.team.internal.ui.mapping.SynchronizationResourceMappingContext; -import org.eclipse.team.ui.mapping.SynchronizationContentProvider; -import org.eclipse.ui.navigator.*; - -/** - * The content provider that is used for synchronizations. - * It also makes use of the Common Navigator pipeline - * to override the resource content extension so that model projects will - * replace the corresponding resource project in the Synchronize view. - */ -public class ModelSyncContentProvider extends SynchronizationContentProvider implements IPipelinedTreeContentProvider { - - private ModelNavigatorContentProvider delegate; - - public ModelSyncContentProvider() { - super(); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.mapping.SynchronizationContentProvider#init(org.eclipse.ui.navigator.ICommonContentExtensionSite) - */ - public void init(ICommonContentExtensionSite site) { - super.init(site); - delegate = new ModelNavigatorContentProvider(getContext() != null); - delegate.init(site); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.mapping.SynchronizationContentProvider#dispose() - */ - public void dispose() { - super.dispose(); - if (delegate != null) - delegate.dispose(); - } - - protected ITreeContentProvider getDelegateContentProvider() { - return delegate; - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.mapping.SynchronizationContentProvider#getModelProviderId() - */ - protected String getModelProviderId() { - return ExampleModelProvider.ID; - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.mapping.SynchronizationContentProvider#getModelRoot() - */ - protected Object getModelRoot() { - return ModelWorkspace.getRoot(); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.mapping.SynchronizationContentProvider#getTraversals(org.eclipse.team.core.mapping.ISynchronizationContext, java.lang.Object) - */ - protected ResourceTraversal[] getTraversals( - ISynchronizationContext context, Object object) { - if (object instanceof ModelObject) { - ModelObject mo = (ModelObject) object; - ResourceMapping mapping = (ResourceMapping)mo.getAdapter(ResourceMapping.class); - ResourceMappingContext rmc = new SynchronizationResourceMappingContext(context); - try { - // Technically speaking, this may end up being too long running for this - // (i.e. we may end up hitting the server) but it will do for illustration purposes - return mapping.getTraversals(rmc, new NullProgressMonitor()); - } catch (CoreException e) { - FileSystemPlugin.log(e); - } - } - return new ResourceTraversal[0]; - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.mapping.SynchronizationContentProvider#getChildrenInContext(org.eclipse.team.core.mapping.ISynchronizationContext, java.lang.Object, java.lang.Object[]) - */ - protected Object[] getChildrenInContext(ISynchronizationContext context, Object parent, Object[] children) { - Set allChildren = new HashSet(); - allChildren.addAll(Arrays.asList(super.getChildrenInContext(context, parent, children))); - // We need to override this method in order to ensure that any elements - // that exist in the context but do not exist locally are included - if (parent instanceof ModelContainer) { - ModelContainer mc = (ModelContainer) parent; - IDiff[] diffs = context.getDiffTree().getDiffs(mc.getResource(), IResource.DEPTH_ONE); - for (int i = 0; i < diffs.length; i++) { - IDiff diff = diffs[i]; - IResource resource = ResourceDiffTree.getResourceFor(diff); - if (!resource.exists() && ModelObjectDefinitionFile.isModFile(resource)) { - ModelObject o = ModelObject.create(resource); - if (o != null) - allChildren.add(o); - } - } - } - if (parent instanceof ModelObjectDefinitionFile) { - ResourceTraversal[] traversals = getTraversals(context, parent); - IDiff[] diffs = context.getDiffTree().getDiffs(traversals); - for (int i = 0; i < diffs.length; i++) { - IDiff diff = diffs[i]; - IResource resource = ResourceDiffTree.getResourceFor(diff); - if (!resource.exists() && ModelObjectElementFile.isMoeFile(resource)) { - ModelObject o = new ModelObjectElementFile((ModelObjectDefinitionFile)parent, (IFile)resource); - if (o != null) - allChildren.add(o); - } - } - } - return allChildren.toArray(new Object[allChildren.size()]); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#getPipelinedChildren(java.lang.Object, java.util.Set) - */ - public void getPipelinedChildren(Object aParent, Set theCurrentChildren) { - // Nothing to do - } - - /* (non-Javadoc) - * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#getPipelinedElements(java.lang.Object, java.util.Set) - */ - public void getPipelinedElements(Object anInput, Set theCurrentElements) { - // Replace any model projects with a ModelProject if the input - // is a synchronization context - if (anInput instanceof ISynchronizationContext) { - List newProjects = new ArrayList(); - for (Iterator iter = theCurrentElements.iterator(); iter.hasNext();) { - Object element = iter.next(); - if (element instanceof IProject) { - IProject project = (IProject) element; - try { - if (ModelProject.isModProject(project)) { - iter.remove(); - newProjects.add(ModelObject.create(project)); - } - } catch (CoreException e) { - FileSystemPlugin.log(e); - } - } - } - theCurrentElements.addAll(newProjects); - } else if (anInput instanceof ISynchronizationScope) { - // When the root is a scope, we should return - // our model provider so all model providers appear - // at the root of the viewer. - theCurrentElements.add(getModelProvider()); - } - } - - /* (non-Javadoc) - * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#getPipelinedParent(java.lang.Object, java.lang.Object) - */ - public Object getPipelinedParent(Object anObject, Object aSuggestedParent) { - // We're not changing the parenting of any resources - return aSuggestedParent; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#interceptAdd(org.eclipse.ui.navigator.PipelinedShapeModification) - */ - public PipelinedShapeModification interceptAdd(PipelinedShapeModification anAddModification) { - if (anAddModification.getParent() instanceof ISynchronizationContext) { - for (Iterator iter = anAddModification.getChildren().iterator(); iter.hasNext();) { - Object element = iter.next(); - if (element instanceof IProject) { - IProject project = (IProject) element; - try { - if (ModelProject.isModProject(project)) { - iter.remove(); - } - } catch (CoreException e) { - FileSystemPlugin.log(e); - } - } - } - } - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#interceptRefresh(org.eclipse.ui.navigator.PipelinedViewerUpdate) - */ - public boolean interceptRefresh(PipelinedViewerUpdate aRefreshSynchronization) { - // No need to intercept the refresh - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#interceptRemove(org.eclipse.ui.navigator.PipelinedShapeModification) - */ - public PipelinedShapeModification interceptRemove(PipelinedShapeModification aRemoveModification) { - // No need to intercept the remove - return aRemoveModification; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.navigator.IPipelinedTreeContentProvider#interceptUpdate(org.eclipse.ui.navigator.PipelinedViewerUpdate) - */ - public boolean interceptUpdate(PipelinedViewerUpdate anUpdateSynchronization) { - // No need to intercept the update - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.mapping.SynchronizationContentProvider#diffsChanged(org.eclipse.team.core.diff.IDiffChangeEvent, org.eclipse.core.runtime.IProgressMonitor) - */ - public void diffsChanged(final IDiffChangeEvent event, IProgressMonitor monitor) { - // Override in order to perform custom viewer updates when the diff tree changes - Utils.syncExec(new Runnable() { - public void run() { - handleChange(event); - } - }, (StructuredViewer)getViewer()); - } - - void handleChange(IDiffChangeEvent event) { - Set existingProjects = getVisibleModelProjects(); - IProject[] changedProjects = getChangedModelProjects(event); - List refreshes = new ArrayList(changedProjects.length); - List additions = new ArrayList(changedProjects.length); - List removals = new ArrayList(changedProjects.length); - for (int i = 0; i < changedProjects.length; i++) { - IProject project = changedProjects[i]; - if (hasVisibleChanges(event.getTree(), project)) { - if (existingProjects.contains(project)) { - refreshes.add(ModelObject.create(project)); - } else { - additions.add(ModelObject.create(project)); - } - } else if (existingProjects.contains(project)) { - removals.add(ModelObject.create(project)); - - } - } - if (!removals.isEmpty() || !additions.isEmpty() || !refreshes.isEmpty()) { - TreeViewer viewer = (TreeViewer)getViewer(); - Tree tree = viewer.getTree(); - try { - tree.setRedraw(false); - if (!additions.isEmpty()) - viewer.add(viewer.getInput(), additions.toArray()); - if (!removals.isEmpty()) - viewer.remove(viewer.getInput(), removals.toArray()); - if (!refreshes.isEmpty()) { - for (Iterator iter = refreshes.iterator(); iter.hasNext();) { - Object element = iter.next(); - viewer.refresh(element); - } - } - } finally { - tree.setRedraw(true); - } - } - } - - private boolean hasVisibleChanges(IDiffTree tree, IProject project) { - return tree.hasMatchingDiffs(project.getFullPath(), new FastDiffFilter() { - public boolean select(IDiff diff) { - return isVisible(diff); - } - }); - } - - /* - * Return the list of all projects that are model projects - */ - private IProject[] getChangedModelProjects(IDiffChangeEvent event) { - Set result = new HashSet(); - IDiff[] changes = event.getChanges(); - for (int i = 0; i < changes.length; i++) { - IDiff diff = changes[i]; - IResource resource = ResourceDiffTree.getResourceFor(diff); - if (resource != null && isModProject(resource.getProject())) { - result.add(resource.getProject()); - } - } - IDiff[] additions = event.getAdditions(); - for (int i = 0; i < additions.length; i++) { - IDiff diff = additions[i]; - IResource resource = ResourceDiffTree.getResourceFor(diff); - if (resource != null && isModProject(resource.getProject())) { - result.add(resource.getProject()); - } - } - IPath[] removals = event.getRemovals(); - for (int i = 0; i < removals.length; i++) { - IPath path = removals[i]; - if (path.segmentCount() > 0) { - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(path.segment(0)); - if (isModProject(project)) - result.add(project); - } - } - return (IProject[]) result.toArray(new IProject[result.size()]); - } - - private boolean isModProject(IProject project) { - try { - return ModelProject.isModProject(project); - } catch (CoreException e) { - FileSystemPlugin.log(e); - } - return false; - } - - /* - * Return the set of visible model projects - */ - private Set getVisibleModelProjects() { - TreeViewer viewer = (TreeViewer)getViewer(); - Tree tree = viewer.getTree(); - TreeItem[] children = tree.getItems(); - Set result = new HashSet(); - for (int i = 0; i < children.length; i++) { - TreeItem control = children[i]; - Object data = control.getData(); - if (data instanceof ModelProject) { - result.add(((ModelProject) data).getProject()); - } - } - return result; - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.mapping.SynchronizationContentProvider#propertyChanged(org.eclipse.team.core.diff.IDiffTree, int, org.eclipse.core.runtime.IPath[]) - */ - public void propertyChanged(IDiffTree tree, int property, IPath[] paths) { - // We're overriding this message so that label updates occur for any elements - // whose labels may have changed - if (getContext() == null) - return; - final Set updates = new HashSet(); - boolean refresh = false; - for (int i = 0; i < paths.length; i++) { - IPath path = paths[i]; - IDiff diff = tree.getDiff(path); - if (diff != null) { - IResource resource = ResourceDiffTree.getResourceFor(diff); - ModelObject object = ModelObject.create(resource); - if (object != null) { - updates.add(object); - } else { - // If the resource is a MOE file, we need to update both the MOE and the MOD file - // Unfortunately, there's no good way to find the parent file so we'll just refresh everything - refresh = true; - } - } - } - if (!updates.isEmpty() || refresh) { - final boolean refreshAll = refresh; - final StructuredViewer viewer = (StructuredViewer)getViewer(); - Utils.syncExec(new Runnable() { - public void run() { - if (refreshAll) - viewer.refresh(true); - else - viewer.update(updates.toArray(new Object[updates.size()]), null); - } - }, viewer); - } - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/mapping/ModelSyncLabelProvider.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/mapping/ModelSyncLabelProvider.java deleted file mode 100644 index d70f01456..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/mapping/ModelSyncLabelProvider.java +++ /dev/null @@ -1,130 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2009 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 org.eclipse.core.runtime.CoreException; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.team.core.diff.IDiff; -import org.eclipse.team.core.diff.IDiffTree; -import org.eclipse.team.examples.filesystem.FileSystemPlugin; -import org.eclipse.team.examples.model.ModelObjectDefinitionFile; -import org.eclipse.team.examples.model.ModelObjectElementFile; -import org.eclipse.team.examples.model.ModelResource; -import org.eclipse.team.examples.model.ui.ModelNavigatorLabelProvider; -import org.eclipse.team.ui.mapping.SynchronizationLabelProvider; -import org.eclipse.ui.navigator.ICommonContentExtensionSite; - -/** - * The label provider that is used for synchronizations. - * It provides a diff for each model element and also provides - * overlay hints for isBusy, conflict propagation and markers. - */ -public class ModelSyncLabelProvider extends SynchronizationLabelProvider { - - private ModelNavigatorLabelProvider delegate; - - public ModelSyncLabelProvider() { - super(); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.mapping.SynchronizationLabelProvider#init(org.eclipse.ui.navigator.ICommonContentExtensionSite) - */ - public void init(ICommonContentExtensionSite site) { - super.init(site); - delegate = new ModelNavigatorLabelProvider(); - delegate.init(site); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.AbstractSynchronizeLabelProvider#dispose() - */ - public void dispose() { - super.dispose(); - if (delegate != null) - delegate.dispose(); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.AbstractSynchronizeLabelProvider#getDelegateLabelProvider() - */ - protected ILabelProvider getDelegateLabelProvider() { - return delegate; - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.AbstractSynchronizeLabelProvider#getDiff(java.lang.Object) - */ - protected IDiff getDiff(Object element) { - if (element instanceof ModelResource) { - ModelResource mr = (ModelResource) element; - return getContext().getDiffTree().getDiff(mr.getResource()); - } - return super.getDiff(element); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.AbstractSynchronizeLabelProvider#isIncludeOverlays() - */ - protected boolean isIncludeOverlays() { - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.AbstractSynchronizeLabelProvider#isBusy(java.lang.Object) - */ - protected boolean isBusy(Object element) { - if (element instanceof ModelResource) { - ModelResource mr = (ModelResource) element; - boolean busy = getContext().getDiffTree().getProperty(mr.getResource().getFullPath(), IDiffTree.P_BUSY_HINT); - if (!busy && mr instanceof ModelObjectDefinitionFile) { - ModelObjectDefinitionFile modFile = (ModelObjectDefinitionFile) mr; - try { - ModelObjectElementFile[] children = modFile.getModelObjectElementFiles(); - for (int i = 0; i < children.length; i++) { - ModelObjectElementFile file = children[i]; - busy = getContext().getDiffTree().getProperty(file.getResource().getFullPath(), IDiffTree.P_BUSY_HINT); - if (busy) - break; - } - } catch (CoreException e) { - FileSystemPlugin.log(e); - } - } - return busy; - } - return super.isBusy(element); - } - - protected boolean hasDecendantConflicts(Object element) { - if (element instanceof ModelResource) { - ModelResource mr = (ModelResource) element; - boolean conflict = getContext().getDiffTree().getProperty(mr.getResource().getFullPath(), IDiffTree.P_HAS_DESCENDANT_CONFLICTS); - if (!conflict && mr instanceof ModelObjectDefinitionFile) { - ModelObjectDefinitionFile modFile = (ModelObjectDefinitionFile) mr; - try { - ModelObjectElementFile[] children = modFile.getModelObjectElementFiles(); - for (int i = 0; i < children.length; i++) { - ModelObjectElementFile file = children[i]; - conflict = getContext().getDiffTree().getProperty(file.getResource().getFullPath(), IDiffTree.P_HAS_DESCENDANT_CONFLICTS); - if (conflict) - break; - } - } catch (CoreException e) { - FileSystemPlugin.log(e); - } - } - return conflict; - } - return super.hasDecendantConflicts(element); - } - -} 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 deleted file mode 100644 index bcaed1ce2..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/mapping/ThirdPartyActionProvider.java +++ /dev/null @@ -1,147 +0,0 @@ -/******************************************************************************* - * 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; - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/IPessimisticFilesystemConstants.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/IPessimisticFilesystemConstants.java deleted file mode 100644 index a20b8b3b5..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/IPessimisticFilesystemConstants.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.pessimistic; - -/** - * Preference constants for the <code>PessimisticFilesystemProvider</code>. - */ -public interface IPessimisticFilesystemConstants { - /** - * Preference name's prefix - */ - String PREFIX = "org.eclipse.team.examples.pessimistic."; - - /** - * Preference name for when checked in files are saved. - */ - String PREF_CHECKED_IN_FILES_SAVED = PREFIX + "WhenCheckedInFilesAreSaved"; - /** - * Preference name for when checked in files are edited with a UI context. - */ - String PREF_CHECKED_IN_FILES_EDITED = PREFIX + "WhenCheckedInFilesAreEdited"; - /** - * Preference name for when checked in files are edited without a UI context. - */ - String PREF_CHECKED_IN_FILES_EDITED_NOPROMPT = PREFIX + "WhenCheckedInFilesAreEditedNoPrompt"; - /** - * Preference name for the option to always fail validate edit. - */ - String PREF_FAIL_VALIDATE_EDIT= PREFIX + "FailValidateEdit"; - /** - * Preference name for the option to touch files during validate edit calls - */ - String PREF_TOUCH_DURING_VALIDATE_EDIT= PREFIX + "ChangeFileContents"; - /** - * Preference name for the option to add files to the repository provider. - */ - String PREF_ADD_TO_CONTROL= PREFIX + "AddToControl"; - - /** - * Preference option indicating that the user should be prompted. - */ - int OPTION_PROMPT = 1; - /** - * Preference option indicating that the action should happen automatically. - */ - int OPTION_AUTOMATIC = 2; - /** - * Preference option indicating that the action should not occur. - */ - int OPTION_DO_NOTHING = 4; - - /** - * Status flag indicating that resources are ready to be edited. - */ - int STATUS_OK_TO_EDIT = 1; - /** - * Status flag indicating that resources need to be reloaded. - */ - int STATUS_PROMPT_FOR_RELOAD = 2; -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/IResourceStateListener.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/IResourceStateListener.java deleted file mode 100644 index e3368621a..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/IResourceStateListener.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.pessimistic; - -import org.eclipse.core.resources.IResource; - -/** - * An <code>IResourceStateListener</code> recieves callbacks - * when the repository state of resources change, i.e. a file gets checked - * in, a folder gets checked out, a project is no longer shared, etc. - */ -public interface IResourceStateListener { - /** - * Notifies this listener that the state of the resources has changed. - * @param resources An array of resources with changed states or an empty array. - */ - void stateChanged(IResource[] resources); -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/PessimisticFilesystemProvider.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/PessimisticFilesystemProvider.java deleted file mode 100644 index 494755c43..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/PessimisticFilesystemProvider.java +++ /dev/null @@ -1,719 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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.pessimistic; - -import java.io.*; -import java.util.*; - -import org.eclipse.core.resources.*; -import org.eclipse.core.resources.team.FileModificationValidator; -import org.eclipse.core.runtime.*; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.team.core.RepositoryProvider; - -/** - * The <code>PessimisticFilesystemProvider</code> is a repository provider. - * - * The provider manages a file named ".pessimistic" in each container it - * controls. This is where it stores metadata on which files it controls - * in that container. This file is considered to be controlled by the - * provider and may be deleted. - * - * The provider provides very simple checkin/checkout facilities by marking - * files read-only to check them in and read-write to check them out. It - * also supports ignoring derived files. - */ -public class PessimisticFilesystemProvider extends RepositoryProvider { - /** - * The name of the file used to store metadata on which - * files are controlled by this provider. - */ - private static final String CONTROL_FILE_NAME= ".pessimistic"; - /** - * The file modification validator for this provider. - */ - private FileModificationValidator validator; - /** - * The cache of resources that are currently controlled. - * The cache is a map of parent resource -> set of controlled children. - */ - Map fControlledResources; - - /** - * Creates a new provider, required for team repository extension. - */ - public PessimisticFilesystemProvider() { - validator = new PessimisticModificationValidator(this); - fControlledResources= new HashMap(1); - } - - /** - * Adds the resources to the control of this provider. - */ - public void addToControl(final IResource[] resources, IProgressMonitor monitor) { - if (PessimisticFilesystemProviderPlugin.getInstance().isDebugging()) { - System.out.println("Add to control:"); - if (resources != null) { - for (int i= 0; i < resources.length; i++) { - System.out.println("\t" + resources[i]); - } - } else { - System.out.println("null resources"); - } - } - if (resources == null || resources.length == 0) { - return; - } - final Set toAdd= new HashSet(resources.length); - IWorkspaceRunnable runnable= new IWorkspaceRunnable() { - public void run(IProgressMonitor monitor) throws CoreException { - for (int i = 0; i < resources.length; i++) { - IResource resource= resources[i]; - if (!isControlled(resource)) { - toAdd.add(resource); - } - } - Map byParent= sortByParent(toAdd); - - monitor.beginTask("Adding to control", 1000); - for (Iterator i= byParent.keySet().iterator(); i.hasNext();) { - IContainer parent= (IContainer) i.next(); - Set controlledResources= (Set)fControlledResources.get(parent); - if (controlledResources == null) { - controlledResources= new HashSet(1); - fControlledResources.put(parent, controlledResources); - } - controlledResources.addAll((Set)byParent.get(parent)); - writeControlFile(parent, monitor); - } - monitor.done(); - } - }; - run(runnable, monitor); - fireStateChanged(toAdd, false); - } - - /** - * Removes the resources from the control of this provider. - */ - public void removeFromControl(final IResource[] resources, IProgressMonitor monitor) { - if (PessimisticFilesystemProviderPlugin.getInstance().isDebugging()) { - System.out.println("Remove from control:"); - if (resources != null) { - for (int i= 0; i < resources.length; i++) { - System.out.println("\t" + resources[i]); - } - } else { - System.out.println("null resources"); - } - } - if (resources == null || resources.length == 0) { - return; - } - final Set toRemove= new HashSet(resources.length); - IWorkspaceRunnable runnable= new IWorkspaceRunnable() { - public void run(IProgressMonitor monitor) throws CoreException { - for (int i = 0; i < resources.length; i++) { - IResource resource= resources[i]; - if (isControlled(resource)) { - toRemove.add(resource); - } - } - Map byParent= sortByParent(toRemove); - - monitor.beginTask("Removing from control", 1000); - for (Iterator i= byParent.keySet().iterator(); i.hasNext();) { - IContainer parent= (IContainer) i.next(); - Set controlledResources= (Set)fControlledResources.get(parent); - if (controlledResources == null) { - deleteControlFile(parent, monitor); - } else { - Set toRemove= (Set)byParent.get(parent); - controlledResources.removeAll(toRemove); - if (controlledResources.isEmpty()) { - fControlledResources.remove(parent); - deleteControlFile(parent, monitor); - } else { - writeControlFile(parent, monitor); - } - for (Iterator j= controlledResources.iterator(); j.hasNext();) { - IResource resource= (IResource) j.next(); - if (!resource.exists()) { - j.remove(); - } - } - } - } - monitor.done(); - } - }; - run(runnable, monitor); - fireStateChanged(toRemove, false); - } - - /* - * Returns a map of IContainer -> Set of IResource. - */ - private Map sortByParent(Set resources) { - Map byParent= new HashMap(1); - for (Iterator i = resources.iterator(); i.hasNext();) { - IResource resource= (IResource) i.next(); - IContainer parent= resource.getParent(); - Set set= (Set)byParent.get(parent); - if (set == null) { - set= new HashSet(1); - byParent.put(parent, set); - } - set.add(resource); - } - return byParent; - } - - /* - * Deletes the control file for the given container. - */ - private void deleteControlFile(final IContainer container, IProgressMonitor monitor) { - IWorkspaceRunnable runnable= new IWorkspaceRunnable() { - public void run(IProgressMonitor monitor) throws CoreException { - IFile controlFile= getControlFile(container, monitor); - monitor.beginTask("Deleting control file " + controlFile, 1); - if (controlFile.exists()) { - controlFile.delete(true, false, monitor); - } - monitor.done(); - } - }; - run(runnable, monitor); - } - - /* - * Answers the control file for the given container. If the control - * file exists, but is a directory, it will be deleted! - */ - private IFile getControlFile(IContainer container, IProgressMonitor monitor) throws CoreException { - IResource child= container.findMember(CONTROL_FILE_NAME); - if (child != null) { - if (child.getType() == IResource.FILE) { - return (IFile)child; - } - child.delete(true, monitor); - } - IFile controlFile= container.getFile(new Path(CONTROL_FILE_NAME)); - monitor.beginTask("Creating control file " + controlFile, 2); - controlFile.create(new ByteArrayInputStream(new byte[0]), true, monitor); - controlFile.setDerived(true); - controlFile.setTeamPrivateMember(true); - monitor.done(); - return controlFile; - } - - /* - * Reads the contents of a control file, answering the set of - * resources that was specified in the file. - */ - Set readControlFile(IFile controlFile) { - Set controlledResources= new HashSet(1); - if (controlFile.exists()) { - InputStream in= null; - try { - try { - in= controlFile.getContents(true); - } catch (CoreException e) { - PessimisticFilesystemProviderPlugin.getInstance().logError(e, "Could not open stream on control file: " + controlFile); - } - DataInputStream dIn= new DataInputStream(in); - int count= 0; - try { - count= dIn.readInt(); - } catch (IOException e) { - // could be empty - } - if (count > 0) { - try { - for(int i= 0; i < count; i++) { - String name= dIn.readUTF(); - IResource resource= getProject().findMember(new Path(name)); - if (resource != null) { - controlledResources.add(resource); - } - } - } catch (IOException e) { - // corrupt control file - try { - controlFile.delete(true, null); - } catch (CoreException ce) { - PessimisticFilesystemProviderPlugin.getInstance().logError(ce, "Could not delete corrupt control file: " + controlFile); - } - } - } - } finally { - if (in != null) { - try { - in.close(); - } catch (IOException e) { - PessimisticFilesystemProviderPlugin.getInstance().logError(e, "Problems closing input stream on control file: " + controlFile); - } - } - } - } - return controlledResources; - } - - /* - * Writes the currently controled resources to the control file for the container. - */ - private void writeControlFile(IContainer container, IProgressMonitor monitor) throws CoreException { - IFile controlFile= getControlFile(container, monitor); - Set controlledResources= (Set)fControlledResources.get(container); - InputStream contents= generateControlFileContents(controlledResources); - monitor.beginTask("Writing control file " + controlFile, 1000); - if (contents == null) { - controlFile.delete(true, false, monitor); - } else { - controlFile.setContents(contents, true, false, monitor); - } - monitor.done(); - } - - /* - * Generates an InputStream on a byte array which specifies - * the resources given in controlledResources. - */ - private InputStream generateControlFileContents(Set controlledResources) { - if (controlledResources == null || controlledResources.isEmpty()) { - return null; - } - ByteArrayOutputStream byteOut= new ByteArrayOutputStream(); - DataOutputStream out= new DataOutputStream(byteOut); - try { - out.writeInt(controlledResources.size()); - for (Iterator i= controlledResources.iterator(); i.hasNext();) { - IResource resource= (IResource) i.next(); - out.writeUTF(resource.getProjectRelativePath().toString()); - } - out.flush(); - } catch (IOException e) { - PessimisticFilesystemProviderPlugin.getInstance().logError(e, "Unexpected problems during content generation"); - } - return new ByteArrayInputStream(byteOut.toByteArray()); - } - - /* - * @see IProjectNature#setProject(IProject) - */ - public void setProject(IProject project) { - if (PessimisticFilesystemProviderPlugin.getInstance().isDebugging()) { - System.out.println("Set project to " + project); - } - super.setProject(project); - configureProject(); - } - - /* - * @see IRepositoryProvider#getID() - */ - public String getID() { - return PessimisticFilesystemProviderPlugin.NATURE_ID; - } - - /* - * @see IRepositoryProvider#getFileModificationValidator() - */ - public IFileModificationValidator getFileModificationValidator() { - return getFileModificationValidator(); - } - - public FileModificationValidator getFileModificationValidator2() { - return validator; - } - - /* - * @see IRepositoryProvider#deconfigure() - */ - public void deconfigure() { - if (PessimisticFilesystemProviderPlugin.getInstance().isDebugging()) { - System.out.println("Deconfigure " + getProject()); - } - - fControlledResources.clear(); - fireStateChanged(getSubtreeMembers(getProject()), true); - } - - /* - * @see IRepositoryProvider#configure() - */ - public void configureProject() { - if (PessimisticFilesystemProviderPlugin.getInstance().isDebugging()) { - System.out.println("Configure " + getProject()); - } - - readControlFiles(); - fireStateChanged(getSubtreeMembers(getProject()), true); - } - - /* - * Reads the control files located in the project - */ - private void readControlFiles() { - IProject project= getProject(); - Set set= new HashSet(1); - set.add(project); - fControlledResources.put(project.getParent(), set); - try { - getProject().accept(new IResourceVisitor() { - public boolean visit(IResource resource) { - if (resource.getType() == IResource.FILE) { - if (CONTROL_FILE_NAME.equals(resource.getName())) { - Set controlledResources= readControlFile((IFile)resource); - fControlledResources.put(resource.getParent(), controlledResources); - } - return false; - } - return true; - } - }); - } catch (CoreException e) { - PessimisticFilesystemProviderPlugin.getInstance().logError(e, "Problems traversing resource tree"); - } - } - - /** - * Checks the resources in by marking them read-only. - */ - public void checkin(final IResource[] resources, IProgressMonitor monitor) { - if (PessimisticFilesystemProviderPlugin.getInstance().isDebugging()) { - System.out.println("Check in:"); - if (resources != null) { - for (int i= 0; i < resources.length; i++) { - System.out.println("\t" + resources[i]); - } - } else { - System.out.println("null resources"); - } - } - if (resources == null || resources.length == 0) { - return; - } - final Set modified= new HashSet(1); - IWorkspaceRunnable runnable= new IWorkspaceRunnable() { - public void run(IProgressMonitor monitor) { - monitor.beginTask("Checking in resources", 1000); - for(int i= 0; i < resources.length; i++) { - IResource resource= resources[i]; - if (isControlled(resource)) { - if (resource.exists()) { - resource.setReadOnly(true); - modified.add(resource); - } - } - } - monitor.done(); - } - }; - run(runnable, monitor); - fireStateChanged(modified, false); - } - - /** - * Unchecks the resources out. In this provider this operation is - * equivalent to checkin. - * - * @see PessimisticFilesystemProvider#checkin(IResource[], IProgressMonitor) - */ - public void uncheckout(final IResource[] resources, IProgressMonitor monitor) { - if (PessimisticFilesystemProviderPlugin.getInstance().isDebugging()) { - System.out.println("Uncheckout:"); - if (resources != null) { - for (int i= 0; i < resources.length; i++) { - System.out.println("\t" + resources[i]); - } - } else { - System.out.println("null resources"); - } - } - if (resources == null || resources.length == 0) { - return; - } - final Set modified= new HashSet(1); - IWorkspaceRunnable runnable= new IWorkspaceRunnable() { - public void run(IProgressMonitor monitor) { - monitor.beginTask("Unchecking in resources", 1000); - for(int i= 0; i < resources.length; i++) { - IResource resource= resources[i]; - if (isControlled(resource)) { - if (resource.exists()) { - resource.setReadOnly(true); - modified.add(resource); - } - } - } - monitor.done(); - } - }; - run(runnable, monitor); - fireStateChanged(modified, false); - } - - /** - * Checks the resources out by marking the resources read-write. - */ - public void checkout(final IResource[] resources, IProgressMonitor monitor) { - if (PessimisticFilesystemProviderPlugin.getInstance().isDebugging()) { - System.out.println("Check out:"); - if (resources != null) { - for (int i= 0; i < resources.length; i++) { - System.out.println("\t" + resources[i]); - } - } else { - System.out.println("null resources"); - } - } - if (resources == null || resources.length == 0) { - return; - } - final Set modified= new HashSet(1); - IWorkspaceRunnable runnable= new IWorkspaceRunnable() { - public void run(IProgressMonitor monitor) { - monitor.beginTask("Checking out resources", 1000); - for(int i= 0; i < resources.length; i++) { - IResource resource= resources[i]; - if (isControlled(resource)) { - if(resource.exists()) { - resource.setReadOnly(false); - modified.add(resource); - } - } - } - monitor.done(); - } - }; - run(runnable, monitor); - fireStateChanged(modified, false); - } - - /** - * Answers <code>true</code> if and only if the resource is - * not <code>null</code>, controlled, not ignored, and checked out. - * Otherwise this method answers <code>false</code>. - */ - public boolean isCheckedout(IResource resource) { - if (PessimisticFilesystemProviderPlugin.getInstance().isDebugging()) { - System.out.println("Is checked out: " + resource); - } - if (resource == null) { - return false; - } - if (!isControlled(resource)) { - return false; - } - if (isIgnored(resource)) { - return false; - } - return !resource.isReadOnly(); - } - - /** - * Answers <code>true</code> if the resource is not <code>null</code>, - * and is controlled, <code>false</code> otherwise. - */ - public boolean isControlled(IResource resource) { - if (PessimisticFilesystemProviderPlugin.getInstance().isDebugging()) { - System.out.println("Is controlled: " + resource); - } - if (resource == null) { - return false; - } - IProject project= getProject(); - if (!project.equals(resource.getProject())) { - return false; - } - Set controlled= (Set)fControlledResources.get(resource.getParent()); - if (controlled == null) { - return false; - } - return controlled.contains(resource); - } - - /** - * Answers <code>true</code> if the resource is ignored. - * Resources are ignored if they are derived. - * Will return <code>false</code> when a resource is derived, but - * has explicitly been added to the control of this provider. - */ - public boolean isIgnored (IResource resource) { - if (PessimisticFilesystemProviderPlugin.getInstance().isDebugging()) { - System.out.println("Is ignored: " + resource); - } - if (resource.isDerived()) { - if (isControlled(resource)) { - return false; - } - return true; - } - return false; - } - - /** - * Answers <code>true</code> if the preference to change the content - * of the file has been set to <code>true</code>, <code>false</code> - * otherwise. - */ - public boolean hasContentChanged(IResource resource) { - if (PessimisticFilesystemProviderPlugin.getInstance().isDebugging()) { - System.out.println("Has content change: " + resource); - } - - IPreferenceStore preferences= PessimisticFilesystemProviderPlugin.getInstance().getPreferenceStore(); - boolean change= preferences.getBoolean(IPessimisticFilesystemConstants.PREF_TOUCH_DURING_VALIDATE_EDIT); - if (change) { - try { - if(resource.getType() == IResource.FILE) { - try { - appendText((IFile)resource, getRandomSnippet(), false); - } catch (IOException e1) { - // ignore - } - } else { - resource.touch(null); - } - } catch (CoreException e) { - PessimisticFilesystemProviderPlugin.getInstance().logError(e, "Problems touching resource: " + resource); - } - } - return change; - } - - public void appendText(IFile file, String text, boolean prepend) throws CoreException, IOException { - String contents = getFileContents(file); - StringBuffer buffer = new StringBuffer(); - if (prepend) { - buffer.append(text); - } - buffer.append(contents); - if (!prepend) { - buffer.append(System.getProperty("line.separator") + text); - } - file.setContents(new ByteArrayInputStream(buffer.toString().getBytes()), false, false, null); - } - - public static String getFileContents(IFile file) throws IOException, CoreException { - StringBuffer buf = new StringBuffer(); - Reader reader = new InputStreamReader(new BufferedInputStream(file.getContents())); - try { - int c; - while ((c = reader.read()) != -1) buf.append((char)c); - } finally { - reader.close(); - } - return buf.toString(); - } - - public static String getRandomSnippet() { - switch ((int) Math.round(Math.random() * 10)) { - case 0 : - return "este e' o meu conteudo (portuguese)"; - case 1 : - return "Dann brauchen wir aber auch einen deutschen Satz!"; - case 2 : - return "I'll be back"; - case 3 : - return "don't worry, be happy"; - case 4 : - return "there is no imagination for more sentences"; - case 5 : - return "customize yours"; - case 6 : - return "foo"; - case 7 : - return "bar"; - case 8 : - return "foobar"; - case 9 : - return "case 9"; - default : - return "these are my contents"; - } - } - - /* - * Notifies listeners that the state of the resources has changed. - * - * @param resources A collection of resources whose state has changed. - * @param queueAfterWorkspaceOperation If <code>true</code>, indicates that the - * notification should occur after the current workspace runnable - * has completed. - */ - private void fireStateChanged(final Collection resources, boolean queueAfterWorkspaceOperation) { - if (resources == null || resources.isEmpty()) { - return; - } - - if (queueAfterWorkspaceOperation) { - Thread t= new Thread(new Runnable() { - public void run() { - try { - ResourcesPlugin.getWorkspace().run( - new IWorkspaceRunnable() { - public void run(IProgressMonitor monitor) { - } - }, - null); - } catch (CoreException e) { - PessimisticFilesystemProviderPlugin.getInstance().logError(e, "Problem during empty runnable"); - } - fireStateChanged(resources, false); - } - }); - t.start(); - } else { - PessimisticFilesystemProviderPlugin.getInstance().fireResourcesChanged( - (IResource[])resources.toArray(new IResource[resources.size()])); - } - } - - /* - * Answers a collection of all of the resources contained below - * the given resource and the resource itself. - */ - private Collection getSubtreeMembers(IResource resource) { - final Set resources= new HashSet(1); - IResourceVisitor visitor= new IResourceVisitor() { - public boolean visit(IResource resource) { - switch (resource.getType()) { - case IResource.PROJECT: - case IResource.FOLDER: - case IResource.FILE: - resources.add(resource); - return true; - } - return true; - } - }; - try { - resource.accept(visitor); - } catch (CoreException e) { - PessimisticFilesystemProviderPlugin.getInstance().logError(e, "Problem during resource visiting"); - } - return resources; - } - - /* - * Runs a workspace operation reporting errors to the PessimisticFilesystemProviderPlugin. - */ - private void run(IWorkspaceRunnable runnable, IProgressMonitor monitor) { - try { - ResourcesPlugin.getWorkspace().run(runnable, monitor); - } catch (CoreException e) { - PessimisticFilesystemProviderPlugin.getInstance().logError(e, "Problems during workspace operation."); - } - } -} - diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/PessimisticFilesystemProviderPlugin.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/PessimisticFilesystemProviderPlugin.java deleted file mode 100644 index 407729815..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/PessimisticFilesystemProviderPlugin.java +++ /dev/null @@ -1,164 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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.pessimistic; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPluginDescriptor; -import org.eclipse.core.runtime.Plugin; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.ui.plugin.AbstractUIPlugin; - -/** - * The plugin for the <code>PessimisticFilesystemProvider</code>. - */ -public class PessimisticFilesystemProviderPlugin extends AbstractUIPlugin { - /* - * Singleton instance. - */ - private static PessimisticFilesystemProviderPlugin instance; - /* - * The resource change listener which notifies the provider of - * added and deleted files. - */ - private ResourceChangeListener fListener; - /* - * The provider listeners - */ - private List fListeners; - - /** - * The plugin identifier - */ - public static final String PLUGIN_ID = "org.eclipse.team.examples.pessimistic"; - /** - * The nature identifier. - */ - public static final String NATURE_ID = PLUGIN_ID + ".pessimisticnature"; - - /** - * Constructor required by plugin lifecycle. - */ - public PessimisticFilesystemProviderPlugin(IPluginDescriptor pluginDescriptor) { - super(pluginDescriptor); - instance = this; - fListeners= new ArrayList(1); - //setDebugging(true); - } - - /** - * Answers the singleton instance of this plugin. - */ - public static PessimisticFilesystemProviderPlugin getInstance() { - return instance; - } - - /** - * Initializes the default preferences for this plugin. - */ - protected void initializeDefaultPreferences() { - IPreferenceStore store = getPreferenceStore(); - - store.setDefault( - IPessimisticFilesystemConstants.PREF_CHECKED_IN_FILES_EDITED, - IPessimisticFilesystemConstants.OPTION_PROMPT); - store.setDefault( - IPessimisticFilesystemConstants.PREF_CHECKED_IN_FILES_EDITED_NOPROMPT, - IPessimisticFilesystemConstants.OPTION_AUTOMATIC); - store.setDefault( - IPessimisticFilesystemConstants.PREF_CHECKED_IN_FILES_SAVED, - IPessimisticFilesystemConstants.OPTION_DO_NOTHING); - store.setDefault( - IPessimisticFilesystemConstants.PREF_ADD_TO_CONTROL, - IPessimisticFilesystemConstants.OPTION_PROMPT); - store.setDefault(IPessimisticFilesystemConstants.PREF_FAIL_VALIDATE_EDIT, false); - store.setDefault(IPessimisticFilesystemConstants.PREF_TOUCH_DURING_VALIDATE_EDIT, true); - } - - /** - * Convenience method for logging errors. - */ - public void logError(Throwable exception, String message) { - String pluginId= getBundle().getSymbolicName(); - Status status= new Status(Status.ERROR, pluginId, Status.OK, message, exception); - getLog().log(status); - if (isDebugging()) { - System.out.println(message); - exception.printStackTrace(); - } - } - - /** - * Starts the resource listener. - * - * @see Plugin#startup() - */ - public void startup() throws CoreException { - fListener= new ResourceChangeListener(); - fListener.startup(); - initializeDefaultPreferences(); - super.startup(); - } - - /** - * Stops the resource listener. - * - * @see Plugin#startup() - */ - public void shutdown() throws CoreException { - fListener.shutdown(); - fListener= null; - super.shutdown(); - } - - /** - * Notifies the registered <code>IResourceStateListener</code> objects - * that the repository state for the resources has changed. - * - * @param resources Collection of resources that have changed. - */ - public void fireResourcesChanged(IResource[] resources) { - if (resources == null || resources.length == 0 || fListeners.isEmpty()) - return; - for (Iterator i= fListeners.iterator(); i.hasNext();) { - IResourceStateListener listener= (IResourceStateListener) i.next(); - listener.stateChanged(resources); - } - } - - /** - * Adds the listener to the list of listeners that are notified when - * the repository state of resources change. - * - * @param listener - */ - public void addProviderListener(IResourceStateListener listener) { - if (fListeners.contains(listener)) - return; - fListeners.add(listener); - } - - - /** - * Removes the listener from the list of listeners that are notified when - * the repository state of resources change. - * - * @param listener - */ - public void removeProviderListener(IResourceStateListener listener) { - fListeners.remove(listener); - } -}
\ No newline at end of file diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/PessimisticModificationValidator.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/PessimisticModificationValidator.java deleted file mode 100644 index 41fc1cabc..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/PessimisticModificationValidator.java +++ /dev/null @@ -1,354 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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.pessimistic; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFileModificationValidator; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.resources.team.FileModificationValidationContext; -import org.eclipse.core.resources.team.FileModificationValidator; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Widget; -import org.eclipse.ui.dialogs.CheckedTreeSelectionDialog; -import org.eclipse.ui.model.WorkbenchLabelProvider; -import org.eclipse.ui.views.navigator.ResourceComparator; - -/** - * The <code>PessimisticModificationValidator</code> is an - * implementation of the <code>IFileModificationValidator</code> for the - * <code>PessimisticFilesystemProvider</code>. - * - * @see PessimiticFilesystemProvider - * @see IFileModificationValidator - */ -public class PessimisticModificationValidator - extends FileModificationValidator { - /* - * The provider for this validator - */ - private PessimisticFilesystemProvider fProvider; - - public PessimisticModificationValidator(PessimisticFilesystemProvider provider) { - fProvider= provider; - } - - /** - * @see IFileModificationValidator#validateEdit(IFile[], Object) - */ - public IStatus validateEdit(IFile[] files, FileModificationValidationContext context) { - if (files.length == 0) { - return new Status( IStatus.OK, getUid(), IStatus.OK, "OK", null); - } - - Set checkOut = new HashSet(); - int reloadCount = 0; - int checkoutFailCount = 0; - - Map validateEditStatusMap= new HashMap(files.length); - - for ( int i = 0 ; i < files.length; i++ ) { - IFile file= files[i]; - - if (fProvider.isControlled(file) ) { - if (fProvider.isCheckedout(file)) { - setValidateEditStatus(validateEditStatusMap, file, - IPessimisticFilesystemConstants.STATUS_OK_TO_EDIT ); - } else { - checkOut.add(file); - } - } else { - setValidateEditStatus(validateEditStatusMap, file, - IPessimisticFilesystemConstants.STATUS_OK_TO_EDIT); - } - } - - if (!checkOut.isEmpty()) { - if (context != null) { - boolean shouldFail= shouldFailValidateEdit(); - int statusCode = checkout(checkOut, IPessimisticFilesystemConstants.PREF_CHECKED_IN_FILES_EDITED, shouldFail, context); - if (shouldFail) { - return new Status( IStatus.ERROR, getUid(), IStatus.ERROR, "Fail Validate Edit Preference true", null); - } - if(statusCode == IStatus.CANCEL) { - return new Status( IStatus.CANCEL, getUid(), IStatus.ERROR, "Checkout canceled by user", null); - } - } else { - if (isAutomaticCheckout()) { - if (shouldFailValidateEdit()) { - return new Status( IStatus.ERROR, getUid(), IStatus.ERROR, "Fail Validate Edit Preference true", null); - } - - checkout(checkOut); - } - } - - for (Iterator i= checkOut.iterator(); i.hasNext(); ) { - IFile file = (IFile) i.next(); - - if ( fProvider.isCheckedout(file) ) { - if ( !fProvider.hasContentChanged(file) ) { - setValidateEditStatus(validateEditStatusMap, file, - IPessimisticFilesystemConstants.STATUS_OK_TO_EDIT ); - } else { - reloadCount++; - setValidateEditStatus(validateEditStatusMap, file, - IPessimisticFilesystemConstants.STATUS_PROMPT_FOR_RELOAD ); - } - } else { - checkoutFailCount++; - } - } - } - - if (reloadCount + checkoutFailCount == 0) { - return new Status( IStatus.OK, getUid(), IStatus.OK, "OK", null); - } - - if (checkoutFailCount == files.length) { - return new Status( IStatus.ERROR, getUid(), IStatus.ERROR, "No files were checked out.", null); - } - - IStatus children[] = new Status[ files.length ]; - - int mask = IPessimisticFilesystemConstants.STATUS_OK_TO_EDIT | - IPessimisticFilesystemConstants.STATUS_PROMPT_FOR_RELOAD; - - for (int i = 0; i < files.length; i++) { - int result = getValidateEditStatus(validateEditStatusMap, files[i]); - if ((result & mask) != 0) { - children[i] = new Status( IStatus.OK, getUid(), IStatus.OK, "OK", null); - } else { - children[i] = new Status( IStatus.ERROR, getUid(), IStatus.ERROR, "File " + files[i].getName() + " could not be checked out.", null); - } - } - return new MultiStatus( getUid(), IStatus.OK, children, "Some files were not successfully checked out", null); - } - - /** - * @see IFileModificationValidator#validateSave(IFile) - */ - public IStatus validateSave(IFile file) { - int checkedInFilesSaved = getPreferences().getInt(IPessimisticFilesystemConstants.PREF_CHECKED_IN_FILES_SAVED); - if (checkedInFilesSaved == IPessimisticFilesystemConstants.OPTION_DO_NOTHING) { - return new Status( IStatus.OK, getUid(), IStatus.OK, "", null); - } - - - IStatus status = new Status( IStatus.OK, getUid(), IStatus.OK, - "File is writable", null); - - if (!fProvider.isControlled(file)) { - return status; - } - - if (fProvider.isIgnored(file)) { - return status; - } - - if (fProvider.isCheckedout(file)) { - return status; - } - Set files= new HashSet(1); - files.add(file); - - checkout(files, IPessimisticFilesystemConstants.PREF_CHECKED_IN_FILES_SAVED, false, null); - - if (fProvider.isCheckedout(file)) { - return status; - } - return new Status( - IStatus.ERROR, - getUid(), - IStatus.ERROR, - file.getProjectRelativePath() + " could not be checked out", - null); - } - - /* - * Convenience method to get the plugin id - */ - private String getUid() { - return PessimisticFilesystemProviderPlugin.PLUGIN_ID; - } - - /* - * Convenience method to answer if the fail validate edit preference - * has been set. - */ - private boolean shouldFailValidateEdit() { - return getPreferences().getBoolean(IPessimisticFilesystemConstants.PREF_FAIL_VALIDATE_EDIT); - } - - /* - * Convenience method to answer if the check out preference is set to automatic. - */ - private boolean isAutomaticCheckout() { - return getPreferences().getInt(IPessimisticFilesystemConstants.PREF_CHECKED_IN_FILES_EDITED_NOPROMPT) == IPessimisticFilesystemConstants.OPTION_AUTOMATIC; - } - - /* - * Optionally prompts the user to select which resources should be - * checked out, and then checks the selected resources. - */ - private int promptAndCheckout(Set resources, boolean beQuiet, boolean shouldFail, Object context) { - if (resources.isEmpty()) { - return IStatus.OK; - } - - Set temp= new HashSet(resources.size()); - for(Iterator i= resources.iterator(); i.hasNext(); ) { - IFile resource= (IFile)i.next(); - if (fProvider.isControlled(resource) && !fProvider.isCheckedout(resource)) - temp.add(resource); - } - resources= temp; - final int[] statusCode = new int[] {IStatus.OK}; - if (!beQuiet && !resources.isEmpty()) { - final Shell shell= getShell(context); - if (shell != null && !shell.isDisposed()) { - Display display = shell.getDisplay(); - final Set[] result = {resources}; - display.syncExec(new Runnable() { - public void run() { - ILabelProvider labelProvider= new WorkbenchLabelProvider(); - Object[] resourceArray= result[0].toArray(); - ITreeContentProvider contentProvider= new ResourceSetContentProvider(result[0]); - CheckedTreeSelectionDialog dialog= new CheckedTreeSelectionDialog(shell, labelProvider, contentProvider); - dialog.setMessage("Select resources to be checked out."); - dialog.setTitle("Check out resources"); - dialog.setContainerMode(true); - dialog.setBlockOnOpen(true); - dialog.setComparator(new ResourceComparator(ResourceComparator.NAME)); - dialog.setExpandedElements(resourceArray); - dialog.setInitialSelections(resourceArray); - dialog.setInput(ResourcesPlugin.getWorkspace().getRoot()); - int status= dialog.open(); - result[0]= null; - if (status == Window.OK) { - Object[] results= dialog.getResult(); - result[0] = new HashSet(results.length); - for (int i= 0; i < results.length; i++) { - result[0].add(results[i]); - } - } else if(status == Window.CANCEL) { - statusCode[0] = IStatus.CANCEL; - } - } - }); - resources= result[0]; - } else { - resources= null; - PessimisticFilesystemProviderPlugin.getInstance().logError(new RuntimeException(), "Context is invalid: " + context); - } - } - - if (resources != null && !resources.isEmpty() && !shouldFail) { - checkout(resources); - } - return statusCode[0]; - } - - /* - * Checks out the files contained in the resources set - */ - private void checkout(Set resources) { - if (resources.isEmpty()) - return; - IFile[] checkOut= new IFile[resources.size()]; - resources.toArray(checkOut); - fProvider.checkout(checkOut, null); - } - - /* - * Convenience method to get the plugin preferences. - */ - private IPreferenceStore getPreferences() { - return PessimisticFilesystemProviderPlugin.getInstance().getPreferenceStore(); - } - - /* - * Checks out the files if necessary and if the preferences allow. - */ - private int checkout(Set resources, String itemId, boolean shouldFail, Object context) { - if (resources.isEmpty()) { - return IStatus.OK; - } - - int preference= getPreferences().getInt(itemId); - - if (preference == IPessimisticFilesystemConstants.OPTION_DO_NOTHING) - return IStatus.OK; - - boolean beQuiet= false; - if (preference == IPessimisticFilesystemConstants.OPTION_AUTOMATIC) { - beQuiet= true; - } - return promptAndCheckout(resources, beQuiet, shouldFail, context); - } - - /* - * Convenience method to set the validate edit status for the given resource. - */ - private static void setValidateEditStatus(Map map, IFile resource, int status) { - map.put(resource, new Integer(status)); - } - - /* - * Convenience method to get the validate edit status for the given resource. - */ - private static int getValidateEditStatus(Map map, IFile resource) { - Integer i= (Integer)map.get(resource); - if (i == null) - return 0; - return i.intValue(); - } - - /* - * Convenience method to get a shell from an object. - */ - private Shell getShell(Object context) { - if (context instanceof FileModificationValidationContext) { - FileModificationValidationContext fmvc = (FileModificationValidationContext) context; - return (Shell)fmvc.getShell(); - } - - if (context instanceof Shell) { - return (Shell)context; - } - - if (context instanceof Control) { - Control control= (Control)context; - return control.getShell(); - } - - if (context instanceof Widget) { - Widget widget= (Widget)context; - return widget.getDisplay().getActiveShell(); - } - - return null; - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ResourceChangeListener.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ResourceChangeListener.java deleted file mode 100644 index 6c6887d1a..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ResourceChangeListener.java +++ /dev/null @@ -1,315 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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.pessimistic; - -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceChangeEvent; -import org.eclipse.core.resources.IResourceChangeListener; -import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.IResourceDeltaVisitor; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Preferences; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.team.core.RepositoryProvider; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.CheckedTreeSelectionDialog; -import org.eclipse.ui.model.WorkbenchLabelProvider; -import org.eclipse.ui.views.navigator.ResourceComparator; - -/** - * The <code>ResourceChangeListener</code> listens for resource changes - * and (optionally) prompts the user to add the new resources to the - * control of the repository provider. - */ -public class ResourceChangeListener implements IResourceDeltaVisitor, IResourceChangeListener { - /* - * Set of added resources - */ - private Set fAdded; - /* - * Set of removed resources - */ - private Set fRemoved; - - public ResourceChangeListener() { - fAdded= new HashSet(1); - fRemoved= new HashSet(1); - } - - /** - * Looks for the following changes: - * <ul> - * <li>Resources that are controlled and are removed</li> - * <li>Resources that are added under a managed project</li> - * </ul> - * @see org.eclipse.core.resources.IResourceDeltaVisitor#visit(IResourceDelta) - */ - public boolean visit(IResourceDelta delta) { - IResource resource= delta.getResource(); - if (resource != null) { - IProject project= resource.getProject(); - if (project != null) { - PessimisticFilesystemProvider provider= (PessimisticFilesystemProvider)RepositoryProvider.getProvider(project, PessimisticFilesystemProviderPlugin.NATURE_ID); - if (provider == null) - return false; - if (provider.isControlled(resource)) { - switch (delta.getKind()) { - case IResourceDelta.CHANGED: - case IResourceDelta.ADDED: - return true; - case IResourceDelta.REMOVED: - fRemoved.add(resource); - return false; - } - } else { - switch (delta.getKind()) { - case IResourceDelta.CHANGED: - case IResourceDelta.REMOVED: - return true; - case IResourceDelta.ADDED: - // don't prompt for ignored resources - if (!provider.isIgnored(resource)) { - fAdded.add(resource); - } - return true; - } - } - } else { - return true; - } - } - return false; - } - - /* - * Convenience method to return a resource array from a collection - */ - private IResource[] toResourceArray(Collection collection) { - if (collection.isEmpty()) { - return new IResource[0]; - } - IResource[] resources= new IResource[collection.size()]; - collection.toArray(resources); - return resources; - } - - /** - * @see IResourceChangeListener#resourceChanged(IResourceChangeEvent) - */ - public void resourceChanged (IResourceChangeEvent event) { - try { - event.getDelta().accept(this); - } catch (CoreException e) { - e.printStackTrace(); - PessimisticFilesystemProviderPlugin.getInstance().logError(e, "Exceptions during resource callback"); - } - - if (!fRemoved.isEmpty() || !fAdded.isEmpty()) { - final IWorkspaceRunnable workspaceRunnable= new IWorkspaceRunnable() { - public void run(final IProgressMonitor monitor) { - if (!fRemoved.isEmpty()) { - remove(monitor); - } - - if (!fAdded.isEmpty()) { - add(monitor); - } - } - }; - // must fork since we are in resource callback. - Runnable run= new Runnable() { - public void run() { - try { - IWorkspace workspace= ResourcesPlugin.getWorkspace(); - if (workspace != null) { - workspace.run(workspaceRunnable, null); - } - } catch (CoreException e) { - PessimisticFilesystemProviderPlugin.getInstance().logError(e, "Problems encountered during attempt to add/remove control."); - } - } - }; - new Thread(run).start(); - } - } - - /* - * Convenience method to get the preference for what to do - * when new resource have been detected. - */ - private int getAddToControlPreference() { - Preferences preferences= PessimisticFilesystemProviderPlugin.getInstance().getPluginPreferences(); - return preferences.getInt(IPessimisticFilesystemConstants.PREF_ADD_TO_CONTROL); - } - - /* - * Adds the resources to the control of the provider. - * If the add to control preference is: - * do nothing - does not add - * automatic - adds all resources - * prompt - brings up a prompt which requests that the user - * select which resources to add - */ - private void add(final IProgressMonitor monitor) { - switch (getAddToControlPreference()) { - case IPessimisticFilesystemConstants.OPTION_DO_NOTHING: - break; - case IPessimisticFilesystemConstants.OPTION_AUTOMATIC: - addToControl(fAdded, monitor); - break; - case IPessimisticFilesystemConstants.OPTION_PROMPT: - final Shell shell= getShell(); - if (shell != null && !shell.isDisposed()) { - final Set resources= new HashSet(fAdded); - Runnable run= new Runnable() { - public void run() { - CheckedTreeSelectionDialog dialog= new CheckedTreeSelectionDialog(shell, new WorkbenchLabelProvider(), new ResourceSetContentProvider(resources)); - dialog.setMessage("Select the resources to be added to the control of the repository."); - dialog.setTitle("Add resources to control"); - dialog.setContainerMode(true); - dialog.setBlockOnOpen(true); - dialog.setComparator(new ResourceComparator(ResourceComparator.NAME)); - Object[] resourceArray= resources.toArray(); - dialog.setExpandedElements(resourceArray); - dialog.setInitialSelections(resourceArray); - dialog.setInput(ResourcesPlugin.getWorkspace().getRoot()); - int status= dialog.open(); - - if (status == Window.OK) { - Object[] results= dialog.getResult(); - if (results != null) { - Set resources= new HashSet(results.length); - for (int i= 0; i < results.length; i++) { - resources.add(results[i]); - } - addToControl(resources, monitor); - } - } - } - }; - - Display display= shell.getDisplay(); - display.asyncExec(run); - } else { - PessimisticFilesystemProviderPlugin.getInstance().logError(null, "Could not aquire a shell"); - } - break; - } - fAdded.clear(); - } - - /* - * Adds the resources to the control of the provider. - */ - private void addToControl(Collection resources, final IProgressMonitor monitor) { - Map byProject= sortByProject(resources); - for (Iterator i= byProject.keySet().iterator(); i.hasNext();) { - IProject project= (IProject) i.next(); - PessimisticFilesystemProvider provider= (PessimisticFilesystemProvider)RepositoryProvider.getProvider(project, PessimisticFilesystemProviderPlugin.NATURE_ID); - if (provider != null) { - provider.addToControl(toResourceArray((Collection)byProject.get(project)), monitor); - } - - } - } - - /* - * Removes the resources from the control of the provider. - */ - private void remove(IProgressMonitor monitor) { - Map byProject= sortByProject(fRemoved); - for (Iterator i= byProject.keySet().iterator(); i.hasNext();) { - IProject project= (IProject) i.next(); - PessimisticFilesystemProvider provider= (PessimisticFilesystemProvider)RepositoryProvider.getProvider(project, PessimisticFilesystemProviderPlugin.NATURE_ID); - if (provider != null) { - provider.removeFromControl(toResourceArray((Collection)byProject.get(project)), monitor); - } - } - fRemoved.clear(); - } - - /* - * Convenience method to sort the resources by project - */ - private Map sortByProject(Collection resources) { - Map byProject= new HashMap(); - for (Iterator i= resources.iterator(); i.hasNext();) { - IResource resource= (IResource) i.next(); - IProject project= resource.getProject(); - Set set= (Set)byProject.get(project); - if (set == null) { - set= new HashSet(1); - byProject.put(project, set); - } - set.add(resource); - } - return byProject; - } - - /* - * Convenience method which answers a shell with which to prompt. - */ - private Shell getShell() { - IWorkbench workbench= PlatformUI.getWorkbench(); - if (workbench != null) { - IWorkbenchWindow window= workbench.getActiveWorkbenchWindow(); - if (window == null) { - IWorkbenchWindow[] windows= workbench.getWorkbenchWindows(); - if (windows != null && windows.length > 0) { - window= windows[0]; - } - } - if (window != null) { - Shell shell= window.getShell(); - if (shell == null) - return null; - if (shell.isDisposed()) - return null; - return shell; - } - } - return null; - } - - /** - * Starts listening for changes. - */ - public void startup() { - ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE); - if (PessimisticFilesystemProviderPlugin.getInstance().isDebugging()) - System.out.println ("Resource callback registered"); - } - - /** - * Stops listening for changes. - */ - public void shutdown() { - ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); - if (PessimisticFilesystemProviderPlugin.getInstance().isDebugging()) - System.out.println ("Resource callback unregistered"); - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ResourceSetContentProvider.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ResourceSetContentProvider.java deleted file mode 100644 index 40cbd2b49..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ResourceSetContentProvider.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.pessimistic; - -import java.util.*; - -import org.eclipse.core.resources.IResource; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.Viewer; - -public class ResourceSetContentProvider implements ITreeContentProvider { - private static final Object[] EMPTY_ARRAY= new Object[0]; - private Map fResourceTree; - private IResource[] fRoots; - - public ResourceSetContentProvider(Set resources) { - fResourceTree= new HashMap(1); - Set roots= new HashSet(resources); - for(Iterator i= resources.iterator(); i.hasNext(); ) { - IResource resource= (IResource)i.next(); - if(resource.getType() == IResource.ROOT) { - continue; // root cannot be displayed - } - IResource parent= resource.getParent(); - if (roots.contains(parent)) { - roots.remove(resource); - Set set= (Set)fResourceTree.get(parent); - if (set == null) { - set= new HashSet(1); - fResourceTree.put(parent, set); - } - set.add(resource); - } - } - fRoots= (IResource[])roots.toArray(new IResource[roots.size()]); - } - - public Object[] getChildren(Object parentElement) { - Set set= (Set) fResourceTree.get(parentElement); - if (set != null) { - return set.toArray(); - } - return EMPTY_ARRAY; - } - - public Object getParent(Object element) { - if (element instanceof IResource) { - return ((IResource)element).getParent(); - } - return null; - } - - public boolean hasChildren(Object element) { - return fResourceTree.get(element) != null; - } - - public Object[] getElements(Object inputElement) { - return fRoots; - } - - public void dispose() { - fResourceTree= null; - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/AddToControlAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/AddToControlAction.java deleted file mode 100644 index e3709d906..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/AddToControlAction.java +++ /dev/null @@ -1,89 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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.pessimistic.ui; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.team.examples.pessimistic.PessimisticFilesystemProvider; -import org.eclipse.ui.IActionDelegate; - -/** - * Adds the selected resources and their parent resources to - * the control of the provider. - */ -public class AddToControlAction extends PessimisticProviderAction { - - /** - * Collects the selected resources, sorts them by project - * and adds them to their respective repository providers. - * - * @see IActionDelegate#run(IAction) - */ - public void run(IAction action) { - IResource[] resources= getSelectedResources(); - if (resources == null || resources.length == 0) - return; - Set resourceSet= new HashSet(resources.length); - for(int i= 0; i < resources.length; i++) { - IResource resource= resources[i]; - while (resource.getType() != IResource.PROJECT && !isControlled(resource)) { - resourceSet.add(resource); - resource= resource.getParent(); - } - } - if (!resourceSet.isEmpty()) { - final Map byProject= sortByProject(resourceSet); - IRunnableWithProgress runnable= new IRunnableWithProgress() { - public void run(IProgressMonitor monitor) { - for (Iterator i= byProject.keySet().iterator(); i.hasNext();) { - IProject project= (IProject) i.next(); - PessimisticFilesystemProvider provider= getProvider(project); - if (provider != null) { - Set set= (Set)byProject.get(project); - IResource[] resources= new IResource[set.size()]; - set.toArray(resources); - provider.addToControl(resources, monitor); - } - } - } - }; - runWithProgressDialog(runnable); - } - } - - /** - * Answers <code>true</code> if the selected resource is not - * a project (or the workspace root) and is not controlled. - * - * @see PessimisticProviderAction#shouldEnableFor(IResource) - */ - protected boolean shouldEnableFor(IResource resource) { - if (resource == null) { - return false; - } - if ((resource.getType() & (IResource.ROOT | IResource.PROJECT)) != 0) { - return false; - } - PessimisticFilesystemProvider provider= getProvider(resource); - if (provider == null) - return false; - return !provider.isControlled(resource); - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/BlankPage.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/BlankPage.java deleted file mode 100644 index f01aac3ac..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/BlankPage.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.pessimistic.ui; - -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; - -/** - * A wizard page that is empty to workaround a bug. - */ -public class BlankPage extends WizardPage { - - /** - * Creates a blank page telling the user what is about to happen. - */ - public BlankPage() { - super("AddPessimisticFilesystemSupport"); - setTitle("Pessimistic filesystem provider"); - setDescription("Add pessimistic filesystem provider support to this project"); - setPageComplete(true); - } - - /** - * Creates an empty control. - */ - public void createControl(Composite parent) { - Composite client = new Composite(parent, SWT.NULL); - GridLayout layout = new GridLayout(); - client.setLayout(layout); - setControl(client); - } -}
\ No newline at end of file diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/CheckInAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/CheckInAction.java deleted file mode 100644 index 6414f7e57..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/CheckInAction.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.pessimistic.ui; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.examples.pessimistic.PessimisticFilesystemProvider; - -/** - * Performs a check in on the selected resources. If a folder is - * selected all of its children are recursively checked in. - */ -public class CheckInAction extends SourceManagementAction { - - /** - * Answers <code>true</code> if and only if the resource is - * not null, controlled, not ignored, and is checked out. - * - * @see PessimisticProviderAction#shouldEnableFor(IResource) - */ - protected boolean shouldEnableFor(IResource resource) { - if (resource == null) - return false; - PessimisticFilesystemProvider provider= getProvider(resource); - if (provider == null) - return false; - if (!provider.isControlled(resource)) - return false; - if (provider.isIgnored(resource)) - return false; - return provider.isCheckedout(resource); - } - - /* - * @see SourceControlAction#manageResources(PessimisticFilesystemProvider, IResource[], IProgressMonitor) - */ - protected void manageResources(PessimisticFilesystemProvider provider, IResource[] resources, IProgressMonitor monitor) { - provider.checkin(resources, monitor); - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/CheckOutAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/CheckOutAction.java deleted file mode 100644 index ba08f6290..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/CheckOutAction.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.pessimistic.ui; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.examples.pessimistic.PessimisticFilesystemProvider; - -/** - * Performs a check out on the selected resources. If a folder is - * selected all of its children are recursively checked out. - */ -public class CheckOutAction extends SourceManagementAction { - /** - * Answers <code>true</code> if and only if the <code>resource</code> - * is not <code>null</code>, controlled, not ignored and not checked out. - * - * @see PessimisticProviderAction#shouldEnableFor(IResource) - */ - protected boolean shouldEnableFor(IResource resource) { - if (resource == null) - return false; - PessimisticFilesystemProvider provider= getProvider(resource); - if (provider == null) - return false; - if (!provider.isControlled(resource)) - return false; - if (provider.isIgnored(resource)) - return false; - return !provider.isCheckedout(resource); - } - - /* - * @see SourceControlAction#manageResources(PessimisticFilesystemProvider, IResource[], IProgressMonitor) - */ - protected void manageResources(PessimisticFilesystemProvider provider, IResource[] resources, IProgressMonitor monitor) { - provider.checkout(resources, monitor); - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/ConfigurationWizard.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/ConfigurationWizard.java deleted file mode 100644 index 06f0a6437..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/ConfigurationWizard.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.pessimistic.ui; - -import org.eclipse.core.resources.IProject; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.team.core.RepositoryProvider; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.examples.pessimistic.PessimisticFilesystemProviderPlugin; -import org.eclipse.team.ui.IConfigurationWizard; -import org.eclipse.ui.IWorkbench; - -/** - * A wizard which adds the <code>PessimisticFilesystemProvider</code> nature - * to a given project. - */ -public class ConfigurationWizard extends Wizard implements IConfigurationWizard { - /* - * The project in question. - */ - private IProject project; - - /* - * @see Wizard#addPages() - */ - public void addPages() { - // workaround the wizard problem - addPage(new BlankPage()); - } - - /* - * @see Wizard#performFinish() - */ - public boolean performFinish() { - try { - RepositoryProvider.map(project, PessimisticFilesystemProviderPlugin.NATURE_ID); - } catch (TeamException e) { - PessimisticFilesystemProviderPlugin.getInstance().logError(e, "Could not set sharing on " + project); - return false; - } - return true; - } - - /* - * @see IConfigurationWizard#init(IWorkbench, IProject) - */ - public void init(IWorkbench workbench, IProject project) { - this.project = project; - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/DisconnectAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/DisconnectAction.java deleted file mode 100644 index 6b61c0871..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/DisconnectAction.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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.pessimistic.ui; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.team.core.RepositoryProvider; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.examples.pessimistic.PessimisticFilesystemProvider; -import org.eclipse.team.examples.pessimistic.PessimisticFilesystemProviderPlugin; -import org.eclipse.ui.IActionDelegate; - -public class DisconnectAction extends PessimisticProviderAction { - /** - * Collects the selected resources, extracts the projects selected - * and disconnects the projects from their respective providers. - * - * @see IActionDelegate#run(IAction) - */ - public void run(IAction action) { - if (PessimisticFilesystemProviderPlugin.getInstance().isDebugging()) - System.out.println("Disconnect"); - - IResource[] resources= getSelectedResources(); - if (resources == null || resources.length == 0) - return; - final Set projects= new HashSet(resources.length); - for(int i= 0; i < resources.length; i++) { - IResource resource= resources[i]; - if (resource.getType() == IResource.PROJECT) { - projects.add(resource.getProject()); - } - } - if (!projects.isEmpty()) { - IRunnableWithProgress runnable= new IRunnableWithProgress() { - public void run(IProgressMonitor monitor) { - IWorkspaceRunnable runnable= new IWorkspaceRunnable() { - public void run(IProgressMonitor monitor) - throws CoreException { - for (Iterator i= projects.iterator(); i.hasNext();) { - IProject project= (IProject) i.next(); - PessimisticFilesystemProvider provider= getProvider(project); - if (provider != null) { - try { - RepositoryProvider.unmap(project); - } catch (TeamException e) { - PessimisticFilesystemProviderPlugin.getInstance().logError(e, "Could not unmap " + project); - } - } - } - } - }; - try { - ResourcesPlugin.getWorkspace().run(runnable, monitor); - } catch (CoreException e) { - PessimisticFilesystemProviderPlugin.getInstance().logError(e, "Problem during unmap runnable"); - } - - } - }; - runWithProgressDialog(runnable); - } - } - - /** - * Answers <code>true</code> if and only if the resource is a - * project and is controlled by the pessimistic filesystem provider. - * - * @see PessimisticProviderAction#shouldEnableFor(IResource) - */ - protected boolean shouldEnableFor(IResource resource) { - if (resource.getType() == IResource.PROJECT) { - PessimisticFilesystemProvider provider= getProvider(resource); - if (provider == null) - return false; - return true; - } - return false; - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/PessimisticDecorator.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/PessimisticDecorator.java deleted file mode 100644 index beb656d5a..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/PessimisticDecorator.java +++ /dev/null @@ -1,125 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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.pessimistic.ui; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.jface.viewers.*; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; -import org.eclipse.team.core.RepositoryProvider; -import org.eclipse.team.examples.pessimistic.*; - -/** - * The <code>PessimisticDecorator</code> is a label provider - * that decorates resources controlled by a <code>PessimisticFilesystemProvider</code>. - */ -public class PessimisticDecorator extends LabelProvider implements ILabelDecorator, IResourceStateListener { - - /** - * Constructor needed for extension - */ - public PessimisticDecorator() { - PessimisticFilesystemProviderPlugin.getInstance().addProviderListener(this); - } - - /* - * @see org.eclipse.jface.viewers.ILabelDecorator#decorateText(String, Object) - */ - public String decorateText(String text, Object element) { - IResource resource= getResource(element); - if (resource == null) - return text; - PessimisticFilesystemProvider provider= getProvider(resource); - if (provider == null) { - return text; - } - if (provider.isControlled(resource)) { - if (provider.isCheckedout(resource)) { - return ">" + text; - } - return text; - } - if (provider.isIgnored(resource)) { - return "[ignored] " + text; - } - return "(not controlled) " + text; - } - - /* - * @see org.eclipse.jface.viewers.ILabelDecorator#decorateImage(Image, Object) - */ - public Image decorateImage(Image image, Object element) { - return image; - } - - /* - * Convenience method to get the provider of a resource - */ - private PessimisticFilesystemProvider getProvider(IResource resource) { - IProject project= resource.getProject(); - if (project != null) { - return (PessimisticFilesystemProvider) RepositoryProvider.getProvider(project, PessimisticFilesystemProviderPlugin.NATURE_ID); - } - return null; - } - - /* - * Convenience method to get a resource from an object - */ - private IResource getResource(Object object) { - if (object instanceof IResource) { - return (IResource) object; - } - if (object instanceof IAdaptable) { - return (IResource) ((IAdaptable) object).getAdapter(IResource.class); - } - return null; - } - - /* - * Fires label events - */ - private void postLabelEvents(final LabelProviderChangedEvent[] events) { - if (events != null && events.length > 0) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - for (int i= 0; i < events.length; i++) { - fireLabelProviderChanged(events[i]); - } - } - }); - } - } - - /* - * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose() - */ - public void dispose() { - PessimisticFilesystemProviderPlugin.getInstance().removeProviderListener(this); - super.dispose(); - } - - /* - * @see org.eclipse.team.examples.pessimistic.IResourceStateListener#resourcesChanged(IResource[]) - */ - public void stateChanged(IResource[] resources) { - if (resources.length > 0) { - LabelProviderChangedEvent[] events= new LabelProviderChangedEvent[resources.length]; - for (int i= 0; i < resources.length; i++) { - events[i]= new LabelProviderChangedEvent(this, resources[i]); - } - postLabelEvents(events); - } - } - -}
\ No newline at end of file diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/PessimisticPreferencesPage.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/PessimisticPreferencesPage.java deleted file mode 100644 index 6afbadb01..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/PessimisticPreferencesPage.java +++ /dev/null @@ -1,364 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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.pessimistic.ui; - -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.preference.PreferencePage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.*; -import org.eclipse.team.examples.pessimistic.IPessimisticFilesystemConstants; -import org.eclipse.team.examples.pessimistic.PessimisticFilesystemProviderPlugin; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPreferencePage; - -/** - * A preference page for the <code>PessimisticFilesystemProviderPlugin</code>. - */ -public class PessimisticPreferencesPage - extends PreferencePage - implements IWorkbenchPreferencePage { - - /* - * Widget for the files are edited preference - */ - private Combo filesAreEditedCombo; - /* - * Widget for the files are edited without a context preference - */ - private Combo filesAreEditedNoPromptCombo; - /* - * Widget for the files are saved preference - */ - private Combo filesAreSavedCombo; - /* - * Widget for the files are edited preference - */ - private Combo addToControlCombo; - /* - * Widget for the change file contents preference - */ - private Button changeFileContents; - /* - * Widget for the fail validate edit preference - */ - private Button failValidateEdit; - - /* - * Option strings for the files are edited preference. - */ - private static final String[] EDIT_OPTION_STRINGS= - new String[] { - "Prompt to checkout", - "Checkout", - "Do nothing", }; - /* - * Option values for the files are edited preference. - */ - private static final int[] EDIT_OPTION_KEYS= - new int[] { - IPessimisticFilesystemConstants.OPTION_PROMPT, - IPessimisticFilesystemConstants.OPTION_AUTOMATIC, - IPessimisticFilesystemConstants.OPTION_DO_NOTHING, }; - - /* - * Option strings for the files are edited without a context preference. - */ - private static final String[] EDIT_NO_PROMPT_OPTION_STRINGS= - new String[] { - "Checkout", - "Do nothing", }; - - /* - * Option strings for the files are saved preference. - */ - private static final String[] SAVE_OPTION_STRINGS= - new String[] { - "Checkout", - "Do nothing", }; - /* - * Option values for the files are saved preference. - */ - private static final int[] SAVE_OPTION_KEYS= - new int[] { - IPessimisticFilesystemConstants.OPTION_AUTOMATIC, - IPessimisticFilesystemConstants.OPTION_DO_NOTHING, }; - - /* - * Option strings for the add to control preference. - */ - private static final String[] ADD_TO_CONTROL_OPTION_STRINGS= - new String[] { - "Prompt to add to control", - "Add to control", - "Do nothing", }; - /* - * Option values for the add to control preference. - */ - private static final int[] ADD_TO_CONTROL_OPTION_KEYS= - new int[] { - IPessimisticFilesystemConstants.OPTION_PROMPT, - IPessimisticFilesystemConstants.OPTION_AUTOMATIC, - IPessimisticFilesystemConstants.OPTION_DO_NOTHING, }; - - - /* - * @see org.eclipse.jface.preference.PreferencePage#doGetPreferenceStore() - */ - protected IPreferenceStore doGetPreferenceStore() { - return PessimisticFilesystemProviderPlugin.getInstance().getPreferenceStore(); - } - - - /* - * Sets the layout to be a grid layout with the given number of columns. - */ - protected void setDefaultLayout(Composite group, int columns) { - GridLayout layout = new GridLayout(); - group.setLayout(layout); - - GridData data = - new GridData( - GridData.VERTICAL_ALIGN_FILL - | GridData.HORIZONTAL_ALIGN_FILL - | GridData.GRAB_HORIZONTAL); - - layout.numColumns = columns; - group.setLayoutData(data); - } - - /* - * @see org.eclipse.jface.preference.PreferencePage#createContents(Composite) - */ - protected Control createContents(Composite parent) { - Composite composite = new Composite(parent, SWT.NULL); - setDefaultLayout(composite, 1); - - Composite options = new Composite(composite, SWT.NULL); - setDefaultLayout(options, 2); - - Label label = new Label(options, SWT.NONE); - label.setText("File handling:"); - GridData gridData = new GridData(); - gridData.horizontalSpan = 2; - gridData.horizontalAlignment = GridData.FILL; - label.setLayoutData(gridData); - - label = new Label(options, SWT.NONE); - label.setText("When checked in files are edited:"); - gridData = new GridData(); - gridData.horizontalSpan = 1; - gridData.horizontalAlignment = GridData.FILL; - label.setLayoutData(gridData); - - filesAreEditedCombo= new Combo(options, SWT.BORDER | SWT.READ_ONLY); - gridData = new GridData(); - gridData.horizontalSpan= 1; - gridData.horizontalAlignment = GridData.FILL; - filesAreEditedCombo.setLayoutData(gridData); - filesAreEditedCombo.setItems(EDIT_OPTION_STRINGS); - - label = new Label(options, SWT.NONE); - label.setText("When checked in files are edited programmatically:"); - gridData = new GridData(); - gridData.horizontalSpan = 1; - gridData.horizontalAlignment = GridData.FILL; - label.setLayoutData(gridData); - - filesAreEditedNoPromptCombo= new Combo(options, SWT.BORDER | SWT.READ_ONLY); - gridData = new GridData(); - gridData.horizontalSpan= 1; - gridData.horizontalAlignment = GridData.FILL; - filesAreEditedNoPromptCombo.setLayoutData(gridData); - filesAreEditedNoPromptCombo.setItems(EDIT_NO_PROMPT_OPTION_STRINGS); - - label = new Label(options, SWT.NONE); - label.setText("When checked in files are saved:"); - gridData = new GridData(); - gridData.horizontalSpan = 1; - gridData.horizontalAlignment = GridData.FILL; - label.setLayoutData(gridData); - - filesAreSavedCombo= new Combo(options, SWT.BORDER | SWT.READ_ONLY); - gridData = new GridData(); - gridData.horizontalSpan = 1; - gridData.horizontalAlignment = GridData.FILL; - filesAreSavedCombo.setLayoutData(gridData); - filesAreSavedCombo.setItems(SAVE_OPTION_STRINGS); - - label = new Label(options, SWT.NONE); - label.setText("When files are created:"); - gridData = new GridData(); - gridData.horizontalSpan = 1; - gridData.horizontalAlignment = GridData.FILL; - label.setLayoutData(gridData); - - addToControlCombo= new Combo(options, SWT.BORDER | SWT.READ_ONLY); - gridData = new GridData(); - gridData.horizontalSpan = 1; - gridData.horizontalAlignment = GridData.FILL; - addToControlCombo.setLayoutData(gridData); - addToControlCombo.setItems(ADD_TO_CONTROL_OPTION_STRINGS); - - options = new Composite(composite, SWT.NULL); - setDefaultLayout(options, 1); - - label = new Label(options, SWT.NONE); - label.setText("Error cases:"); - gridData = new GridData(); - gridData.horizontalSpan = 1; - gridData.horizontalAlignment = GridData.FILL; - label.setLayoutData(gridData); - - failValidateEdit= new Button(options, SWT.CHECK | SWT.LEFT); - failValidateEdit.setText("Fail validate edit"); - gridData = new GridData(); - failValidateEdit.setLayoutData(gridData); - - changeFileContents= new Button(options, SWT.CHECK | SWT.LEFT); - changeFileContents.setText("Touch files during validate edit"); - gridData = new GridData(); - changeFileContents.setLayoutData(gridData); - - updatePreferencePage(); - - return composite; - } - - /* - * @see org.eclipse.ui.IWorkbenchPreferencePage#init(IWorkbench) - */ - public void init(IWorkbench workbench) { - // do nothing - } - - /* - * @see org.eclipse.jface.preference.PreferencePage#performDefaults() - */ - protected void performDefaults() { - IPreferenceStore store = getPreferenceStore(); - - filesAreEditedCombo.select( - getEditOptionIndex(store.getDefaultInt(IPessimisticFilesystemConstants.PREF_CHECKED_IN_FILES_EDITED))); - filesAreEditedNoPromptCombo.select( - getEditNoPromptOptionIndex(store.getDefaultInt(IPessimisticFilesystemConstants.PREF_CHECKED_IN_FILES_EDITED_NOPROMPT))); - filesAreSavedCombo.select( - getSaveOptionIndex(store.getDefaultInt(IPessimisticFilesystemConstants.PREF_CHECKED_IN_FILES_SAVED))); - addToControlCombo.select( - getAddToControlOptionIndex(store.getDefaultInt(IPessimisticFilesystemConstants.PREF_ADD_TO_CONTROL))); - failValidateEdit.setSelection( - store.getDefaultBoolean(IPessimisticFilesystemConstants.PREF_FAIL_VALIDATE_EDIT)); - changeFileContents.setSelection( - store.getDefaultBoolean(IPessimisticFilesystemConstants.PREF_TOUCH_DURING_VALIDATE_EDIT)); - super.performDefaults(); - } - - /* - * @see org.eclipse.jface.preference.IPreferencePage#performOk() - */ - public boolean performOk() { - IPreferenceStore store = getPreferenceStore(); - - int selectionIndex = filesAreEditedCombo.getSelectionIndex(); - if (selectionIndex != -1) - store.setValue( - IPessimisticFilesystemConstants.PREF_CHECKED_IN_FILES_EDITED, - EDIT_OPTION_KEYS[selectionIndex]); - selectionIndex = filesAreEditedNoPromptCombo.getSelectionIndex(); - if (selectionIndex != -1) - store.setValue( - IPessimisticFilesystemConstants.PREF_CHECKED_IN_FILES_EDITED_NOPROMPT, - SAVE_OPTION_KEYS[selectionIndex]); - selectionIndex = filesAreSavedCombo.getSelectionIndex(); - if (selectionIndex != -1) - store.setValue( - IPessimisticFilesystemConstants.PREF_CHECKED_IN_FILES_SAVED, - SAVE_OPTION_KEYS[selectionIndex]); - selectionIndex = addToControlCombo.getSelectionIndex(); - if (selectionIndex != -1) - store.setValue( - IPessimisticFilesystemConstants.PREF_ADD_TO_CONTROL, - ADD_TO_CONTROL_OPTION_KEYS[selectionIndex]); - store.setValue( - IPessimisticFilesystemConstants.PREF_FAIL_VALIDATE_EDIT, - failValidateEdit.getSelection()); - store.setValue( - IPessimisticFilesystemConstants.PREF_TOUCH_DURING_VALIDATE_EDIT, - changeFileContents.getSelection()); - return true; - } - - /* - * Sets the widgets to have the state stored in the preferences. - */ - protected void updatePreferencePage() { - IPreferenceStore store = getPreferenceStore(); - - filesAreEditedCombo.select( - getEditOptionIndex(store.getInt(IPessimisticFilesystemConstants.PREF_CHECKED_IN_FILES_EDITED))); - filesAreEditedNoPromptCombo.select( - getEditNoPromptOptionIndex(store.getInt(IPessimisticFilesystemConstants.PREF_CHECKED_IN_FILES_EDITED_NOPROMPT))); - filesAreSavedCombo.select( - getSaveOptionIndex(store.getInt(IPessimisticFilesystemConstants.PREF_CHECKED_IN_FILES_SAVED))); - addToControlCombo.select( - getAddToControlOptionIndex(store.getInt(IPessimisticFilesystemConstants.PREF_ADD_TO_CONTROL))); - failValidateEdit.setSelection( - store.getBoolean(IPessimisticFilesystemConstants.PREF_FAIL_VALIDATE_EDIT)); - changeFileContents.setSelection( - store.getBoolean(IPessimisticFilesystemConstants.PREF_TOUCH_DURING_VALIDATE_EDIT)); - } - - /* - * Answers the index of the given key. - */ - protected int getEditOptionIndex(int key) { - for(int i= 0; i < EDIT_OPTION_KEYS.length; i++) { - if (EDIT_OPTION_KEYS[i] == key) - return i; - } - return -1; - } - - /* - * Answers the index of the given key. - */ - protected int getSaveOptionIndex(int key) { - for(int i= 0; i < SAVE_OPTION_KEYS.length; i++) { - if (SAVE_OPTION_KEYS[i] == key) - return i; - } - return -1; - } - - /* - * Answers the index of the given key. - */ - protected int getEditNoPromptOptionIndex(int key) { - for(int i= 0; i < SAVE_OPTION_KEYS.length; i++) { - if (SAVE_OPTION_KEYS[i] == key) - return i; - } - return -1; - } - - /* - * Answers the index of the given key. - */ - protected int getAddToControlOptionIndex(int key) { - for(int i= 0; i < ADD_TO_CONTROL_OPTION_KEYS.length; i++) { - if (ADD_TO_CONTROL_OPTION_KEYS[i] == key) - return i; - } - return -1; - } - -}
\ No newline at end of file diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/PessimisticProviderAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/PessimisticProviderAction.java deleted file mode 100644 index f2fdf61a2..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/PessimisticProviderAction.java +++ /dev/null @@ -1,234 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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.pessimistic.ui; - -import java.lang.reflect.InvocationTargetException; -import java.util.*; - -import org.eclipse.core.resources.*; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.ProgressMonitorDialog; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.team.core.RepositoryProvider; -import org.eclipse.team.examples.pessimistic.PessimisticFilesystemProvider; -import org.eclipse.team.examples.pessimistic.PessimisticFilesystemProviderPlugin; -import org.eclipse.ui.IObjectActionDelegate; -import org.eclipse.ui.IWorkbenchPart; - - -/** - * Abstract base action implementation for all pessimistic provider actions. - * Provides convenience methods an abstractions. - */ -public abstract class PessimisticProviderAction - implements IObjectActionDelegate { - - /* - * The current selection. - */ - protected ISelection fSelection; - /* - * The current shell. - */ - protected Shell fShell; - - /* - * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection) - */ - public void selectionChanged(IAction action, ISelection selection) { - fSelection = selection; - - boolean enabled= action.isEnabled(); - if (enabled != checkEnablement()) { - action.setEnabled(!enabled); - } - } - - /* - * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart) - */ - public void setActivePart(IAction action, IWorkbenchPart part) { - fShell= part.getSite().getShell(); - } - - /** - * Answers <code>true</code> if this action should be enabled - * for the given <code>resource</code>. - */ - protected abstract boolean shouldEnableFor(IResource resource); - - /* - * Checks to see if this action should be enabled. - */ - protected boolean checkEnablement() { - IResource[] resources= getSelectedResources(); - if (resources == null || resources.length == 0) { - return false; - } - boolean enabled= false; - for(int i= 0; !enabled && i < resources.length; i++) { - if (shouldEnableFor(resources[i])) { - enabled= true; - } - } - return enabled; - } - - /** - * Convenience method to get an array of resources from the selection. - */ - protected IResource[] getSelectedResources() { - ArrayList resources = null; - if (!fSelection.isEmpty()) { - resources = new ArrayList(); - Iterator elements = ((IStructuredSelection) fSelection).iterator(); - while (elements.hasNext()) { - Object next = elements.next(); - if (next instanceof IResource) { - resources.add(next); - continue; - } - if (next instanceof IAdaptable) { - IAdaptable a = (IAdaptable) next; - Object adapter = a.getAdapter(IResource.class); - if (adapter instanceof IResource) { - resources.add(adapter); - continue; - } - } - } - } - if (resources != null && !resources.isEmpty()) { - IResource[] result = new IResource[resources.size()]; - resources.toArray(result); - return result; - } - return new IResource[0]; - } - - /** - * Convenience method which answers <code>true</code> if the - * resource is controlled by a <code>PessimisticFilesystemProvider</code>. - */ - protected boolean isControlled(IResource resource) { - PessimisticFilesystemProvider provider= getProvider(resource); - if (provider == null) - return false; - return provider.isControlled(resource); - } - - /** - * Convenience method which answers <code>true</code> if and only if the - * resource is controlled by a <code>PessimisticFilesystemProvider</code> - * and is checked out. - */ - protected boolean isCheckedOut(IResource resource) { - PessimisticFilesystemProvider provider= getProvider(resource); - if (provider == null) - return false; - return provider.isCheckedout(resource); - } - - /** - * Convenience method which answers <code>true</code> if and only if the - * resource is controlled by a <code>PessimisticFilesystemProvider</code> - * and the resource is ignored. - */ - protected boolean isIgnored(IResource resource) { - PessimisticFilesystemProvider provider= getProvider(resource); - if (provider == null) - return false; - return provider.isIgnored(resource); - } - - /** - * Convenience method which answers the <code>PessimisticFilesystemProvider</code> - * for the given <code>resource</code> or <code>null</code> if the - * <code>resource</code> is not associated with a <code>PessimisticFilesystemProvider</code>. - */ - protected PessimisticFilesystemProvider getProvider(IResource resource) { - if (resource == null) { - return null; - } - IProject project= resource.getProject(); - if (project == null) { - return null; - } - return (PessimisticFilesystemProvider)RepositoryProvider.getProvider(project, PessimisticFilesystemProviderPlugin.NATURE_ID); - } - - /** - * Convenience method which walks a resource tree and collects the - * resources that this action would enable for. - */ - protected void recursivelyAdd(IResource resource, Set resources) { - if (isControlled(resource) && !isIgnored(resource)) { - if (shouldEnableFor(resource)) { - resources.add(resource); - } - - if (resource instanceof IContainer) { - IContainer container = (IContainer) resource; - IResource[] members= null; - try { - members = container.members(); - } catch (CoreException e) { - PessimisticFilesystemProviderPlugin.getInstance().logError(e, "Exception traversing members"); - } - if (members != null) { - for (int i = 0; i < members.length; i++) { - recursivelyAdd(members[i], resources); - } - } - } - } - } - - /** - * Convenience method which sorts the given <code>resources</code> - * into a map of IProject -> Set of IResource objects. - */ - protected Map sortByProject(Set resources) { - Map byProject= new HashMap(); - if (resources != null) { - for (Iterator i= resources.iterator(); i.hasNext();) { - IResource resource= (IResource) i.next(); - IProject project= resource.getProject(); - Set set= (Set)byProject.get(project); - if (set == null) { - set= new HashSet(1); - byProject.put(project, set); - } - set.add(resource); - } - } - return byProject; - } - - /** - * Convenience method for displaying runnable progress - * with a <code>ProgressMonitorDialog</code>. - */ - protected void runWithProgressDialog(IRunnableWithProgress runnable) { - try { - new ProgressMonitorDialog(fShell).run(true, false, runnable); - } catch (InvocationTargetException e) { - PessimisticFilesystemProviderPlugin.getInstance().logError(e, "Problems running action " + this); - } catch (InterruptedException e) { - PessimisticFilesystemProviderPlugin.getInstance().logError(e, "Problems running action " + this); - } - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/RemoveFromControlAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/RemoveFromControlAction.java deleted file mode 100644 index 61d1c8ab3..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/RemoveFromControlAction.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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.pessimistic.ui; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.team.examples.pessimistic.PessimisticFilesystemProvider; - -/** - * Removes the selected resources and their children resources from - * the control of the provider. - */ -public class RemoveFromControlAction extends PessimisticProviderAction { - - /** - * Collects the selected resources into sets by project, - * then removes the resources from the provider associated - * with their containing project. - * - * @see org.eclipse.ui.IActionDelegate#run(IAction) - */ - public void run(IAction action) { - IResource[] resources= getSelectedResources(); - if (resources == null || resources.length == 0) - return; - Set resourceSet= new HashSet(resources.length); - for(int i= 0; i < resources.length; i++) { - IResource resource= resources[i]; - recursivelyAdd(resource, resourceSet); - } - if (!resourceSet.isEmpty()) { - final Map byProject= sortByProject(resourceSet); - IRunnableWithProgress runnable= new IRunnableWithProgress() { - public void run(IProgressMonitor monitor) { - for (Iterator i= byProject.keySet().iterator(); i.hasNext();) { - IProject project= (IProject) i.next(); - PessimisticFilesystemProvider provider= getProvider(project); - if (provider != null) { - Set set= (Set)byProject.get(project); - IResource[] resources= new IResource[set.size()]; - set.toArray(resources); - provider.removeFromControl(resources, monitor); - } - } - } - }; - runWithProgressDialog(runnable); - } - } - - /** - * Answers <code>true</code> if and only if the resource is not <code>null</code>, - * not a project or the workspace root, and is controlled by the provider. - * - * @see org.eclipse.team.examples.pessimistic.ui.PessimisticProviderAction#shouldEnableFor(IResource) - */ - protected boolean shouldEnableFor(IResource resource) { - if (resource == null) { - return false; - } - if ((resource.getType() & (IResource.ROOT | IResource.PROJECT)) != 0) { - return false; - } - PessimisticFilesystemProvider provider= getProvider(resource); - if (provider == null) - return false; - return provider.isControlled(resource); - } - -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/SourceManagementAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/SourceManagementAction.java deleted file mode 100644 index 3ad66fa41..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/SourceManagementAction.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 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.pessimistic.ui; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.team.examples.pessimistic.PessimisticFilesystemProvider; - -/** - * An abstract action used to centralize the implementation of - * source management actions. - */ -public abstract class SourceManagementAction extends PessimisticProviderAction { - - /** - * Collects the selected resources by project, then iterates - * over the projects finding the associated provider. If a - * provider is found it requests that this action manage the resources - * using the found provider. - * - * @see org.eclipse.ui.IActionDelegate#run(IAction) - */ - public void run(IAction action) { - IResource[] resources= getSelectedResources(); - if (resources == null || resources.length == 0) - return; - Set resourceSet= new HashSet(resources.length); - for(int i= 0; i < resources.length; i++) { - IResource resource= resources[i]; - recursivelyAdd(resource, resourceSet); - } - if (!resourceSet.isEmpty()) { - final Map byProject= sortByProject(resourceSet); - IRunnableWithProgress runnable= new IRunnableWithProgress() { - public void run(IProgressMonitor monitor) { - for (Iterator i= byProject.keySet().iterator(); i.hasNext();) { - IProject project= (IProject) i.next(); - PessimisticFilesystemProvider provider= getProvider(project); - if (provider != null) { - Set set= (Set)byProject.get(project); - IResource[] resources= new IResource[set.size()]; - set.toArray(resources); - manageResources(provider, resources, monitor); - } - } - } - }; - runWithProgressDialog(runnable); - } - } - - /** - * Manages the <code>resources</code> using the given <code>provider</code>. - * - * @param provider The provider associated with the resources. - * @param resources The resources to be managed. - * @param monitor A progress monitor to give feedback. - */ - protected abstract void manageResources(PessimisticFilesystemProvider provider, IResource[] resources, IProgressMonitor monitor); -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/UncheckOutAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/UncheckOutAction.java deleted file mode 100644 index d31ff3c96..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/UncheckOutAction.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 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.pessimistic.ui; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.examples.pessimistic.PessimisticFilesystemProvider; - -/** - * Performs an uncheck out on the selected resources. If a folder is - * selected all of its children are recursively unchecked out. - */ -public class UncheckOutAction extends CheckInAction { - /** - * @see org.eclipse.team.examples.pessimistic.ui.SourceManagementAction#manageResources(PessimisticFilesystemProvider, IResource[], IProgressMonitor) - */ - protected void manageResources(PessimisticFilesystemProvider provider, IResource[] resources, IProgressMonitor monitor) { - provider.uncheckout(resources, monitor); - } - -} |