diff options
Diffstat (limited to 'examples/org.eclipse.team.examples.filesystem/src/org')
55 files changed, 0 insertions, 6150 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 5e0821b2d..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileModificationValidator.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-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.IFileModificationValidator; -import org.eclipse.core.resources.IResource; -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 clas for illustration purposes. It may have been more apporpriate - * to have FileSystemProvider implement IFileModificationValidator itself since the interface - * only has two methods and their implementation is straight forward. - */ -public final class FileModificationValidator implements IFileModificationValidator { - - private FileSystemOperations operations; - - /** - * Constructor for FileModificationValidator. - */ - public FileModificationValidator(RepositoryProvider provider) { - operations = ((FileSystemProvider)provider).getOperations(); - } - - /** - * This method will convert any exceptions thrown by the SimpleAccessOperations.chechout() 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. - * @see org.eclipse.team.internal.core.simpleAccess.SimpleAccessOperations#chechout(IResource[] resources, int depth, IProgressMonitor progress) - */ - 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, Object 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 recieve 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 }); - } else { - 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 32133b3ec..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemOperations.java +++ /dev/null @@ -1,383 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -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.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(); - } - } - - /** - * Checkout the given resources to the given depth by setting any files - * to writtable (i.e set read-only to <coce>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(); - } - } - - /** - * Checkin 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(); - } - } - - /** - * 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) - || (synchronizer.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); - } catch (CoreException e) { - throw TeamException.asTeamException(e); - } - } - if (!synchronizer.isLocallyModified(localFile) && comparator.compare(base, remote)) { - // The base and remote are the same and there's no local changes - // so nothing needs to be done - } - 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(); - } - - /* - * Get the file if it is out-of-sync. - */ - private void 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; - } 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; - } - } else if (base != null && remote != null) { - boolean same = comparator.compare(base, remote); - if (!synchronizer.isLocallyModified(localFile) && same) { - // The base and remote are the same and there's no local changes - // so nothing needs to be done - return; - } - if (!same && !overrideIncoming) { - // The remote has changed. Only override if specified - return; - } - } - - // 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); - } - } - } - - /* - * 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 9be45c067..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemPlugin.java +++ /dev/null @@ -1,115 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.examples.filesystem; - -import java.io.IOException; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPluginDescriptor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.examples.pessimistic.PessimisticFilesystemProviderPlugin; -import org.eclipse.ui.plugin.AbstractUIPlugin; - -/** - * 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 pessimisticPlugin; - - /** - * Override the standard plugin constructor. - * - * @param descriptor the plugin descriptor - */ - public FileSystemPlugin(IPluginDescriptor descriptor) { - super(descriptor); - // record this instance as the singleton - plugin = this; - pessimisticPlugin = new PessimisticFilesystemProviderPlugin(descriptor); - } - - /** - * This method will get invoked when the plugin is started. - * Note that this is not necessarily at workbench startup. - * - * @see org.eclipse.core.runtime.Plugin#startup() - */ - public void startup() throws CoreException { - // localize the string bindings used by the plugins (in order to provide NLS support) - Policy.localize("org.eclipse.team.examples.filesystem.messages"); //$NON-NLS-1$ - } - - /** - * 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); - } -} - 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 4d80d9fb7..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileSystemProvider.java +++ /dev/null @@ -1,207 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-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.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.variants.IResourceVariant; -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 repsitory provider's - * ID. - * - * <p> - * This example provider illustrates the following: - * <ol> - * <li>simple working implementation of <code>RepositoyProvider</code> - * <li>storage of a persistant 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/Validat 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 { - - // 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 accross workspace as a persistant property on a resource - private static QualifiedName FILESYSTEM_REPO_LOC = new QualifiedName(FileSystemPlugin.ID, "disk_location"); //$NON-NLS-1$ - - /** - * 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() throws CoreException { - 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.getStatus()); - 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); - } - /** - * @see org.eclipse.team.core.RepositoryProvider#getFileModificationValidator() - */ - public IFileModificationValidator getFileModificationValidator() { - return new 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) 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; - } - -} 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 97a9aff37..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, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-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 cfb2db53a..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/Policy.java +++ /dev/null @@ -1,93 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-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 Polciy classes many Eclipse plugin suse to - * provide NLSing of strings and aid in proper progress monitoring. - */ -public class Policy { - - protected static ResourceBundle bundle = null; - - /** - * Creates a NLS catalog for the given locale. - */ - public static void localize(String bundleName) { - 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 bundle.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 f39f21743..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, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-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/messages.properties b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/messages.properties deleted file mode 100644 index ccb68c1c3..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, 2003 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Common Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/cpl-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/FileSystemRemoteTree.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemRemoteTree.java deleted file mode 100644 index 891046ad3..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemRemoteTree.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-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.TeamException; -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 sytem three-way remote resource varant tree taht provides - * the ability to traverse the file system for the creation of resource variants. - */ -public class FileSystemRemoteTree extends ThreeWayRemoteTree { - - /** - * Create the file syetm 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) throws TeamException { - 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) throws TeamException { - 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 365846239..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemResourceVariant.java +++ /dev/null @@ -1,150 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-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; - } else { - 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$ - } - } -} 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 d8b94976e..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemSubscriber.java +++ /dev/null @@ -1,126 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-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.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.QualifiedName; -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.IResourceVariant; -import org.eclipse.team.core.variants.ThreeWayRemoteTree; -import org.eclipse.team.core.variants.ThreeWaySubscriber; -import org.eclipse.team.core.variants.ThreeWaySynchronizer; -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) throws TeamException { - 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; - } - -} 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 6f9f52d69..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, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-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/ConfigurationWizard.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/ConfigurationWizard.java deleted file mode 100644 index bab78242b..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/ConfigurationWizard.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-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.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.FileSystemPlugin; -import org.eclipse.team.examples.filesystem.FileSystemProvider; -import org.eclipse.team.examples.filesystem.Policy; -import org.eclipse.team.ui.IConfigurationWizard; -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 locaton on disk. - */ -public class ConfigurationWizard extends Wizard implements IConfigurationWizard { - - IProject project; - - 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) { - this.project = 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 { - // Map the provider and set the location - RepositoryProvider.map(project, FileSystemPlugin.PROVIDER_ID); - FileSystemProvider provider = (FileSystemProvider) RepositoryProvider.getProvider(project); - provider.setTargetLocation(mainPage.getLocation()); - } 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; - } - -} 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 6fc051cdd..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/DisconnectAction.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-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 { - - /** - * @see org.eclipse.ui.IActionDelegate#run(IAction) - */ - public void run(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() - */ - protected 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 f129ab5d4..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemAction.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-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.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 multipe actions. - */ -public abstract class FileSystemAction extends TeamAction { - - /** - * @see org.eclipse.team.internal.ui.actions.TeamAction#isEnabled() - */ - protected boolean isEnabled() { - IResource[] resources = getSelectedResources(); - if (resources.length == 0) - return false; - for (int i = 0; i < resources.length; i++) { - IResource resource = resources[i]; - // we only want to work on resources mapped to a file system provider - RepositoryProvider provider = RepositoryProvider.getProvider(resource.getProject(), FileSystemPlugin.PROVIDER_ID); - if (provider == null) - return false; - } - return true; - } - - /** - * 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; - } - -} 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 219ac80fc..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemMainPage.java +++ /dev/null @@ -1,301 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-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. - */ - private void validateFields() { - String location = locationCombo.getText(); - if (location.length() == 0) { - setErrorMessage(null); - setPageComplete(false); - return; - } else { - 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/FileSystemPropertiesPage.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemPropertiesPage.java deleted file mode 100644 index 5db059449..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, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-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/FileSystemSynchronizeOperation.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemSynchronizeOperation.java deleted file mode 100644 index 2795419df..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemSynchronizeOperation.java +++ /dev/null @@ -1,103 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-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.compare.structuremergeviewer.IDiffElement; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.team.core.RepositoryProvider; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.core.synchronize.SyncInfo; -import org.eclipse.team.core.synchronize.SyncInfoSet; -import org.eclipse.team.examples.filesystem.FileSystemPlugin; -import org.eclipse.team.examples.filesystem.FileSystemProvider; -import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; -import org.eclipse.team.ui.synchronize.SynchronizeModelOperation; - -/** - * Override SynchronizeModelOperation in order to delegate the operation to each file system - * provider instance (i.e. each project). Also, prompt to prune conflicts from the set of - * selected resources. - */ -public abstract class FileSystemSynchronizeOperation extends SynchronizeModelOperation { - - protected FileSystemSynchronizeOperation(ISynchronizePageConfiguration configuration, IDiffElement[] elements) { - super(configuration, elements); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor) - */ - public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - // First, ask the user if they want to include conflicts - SyncInfoSet syncSet = getSyncInfoSet(); - if (!promptForConflictHandling(getShell(), syncSet)) return; - // Divide the sync info by project - final Map projectSyncInfos = getProjectSyncInfoSetMap(syncSet); - monitor.beginTask(null, projectSyncInfos.size() * 100); - for (Iterator iter = projectSyncInfos.keySet().iterator(); iter.hasNext(); ) { - final IProject project = (IProject) iter.next(); - try { - // Pass the scheduling rule to the synchronizer so that sync change events - // and cache commits to disk are batched - FileSystemProvider provider = (FileSystemProvider)RepositoryProvider.getProvider(project, FileSystemPlugin.PROVIDER_ID); - if (provider != null) { - run(provider, (SyncInfoSet)projectSyncInfos.get(project), monitor); - } - } catch (TeamException e) { - throw new InvocationTargetException(e); - } - } - monitor.done(); - } - - /** - * Prompt the user to include conflicts. If the user choses not to include - * conflicts, they will be removed from the passed set. If the user cancels, - * <code>false</code> is returned. - * @param shell a shell - * @param syncSet the set of selected resources - * @return whether the operation should proceed. - */ - protected abstract boolean promptForConflictHandling(Shell shell, SyncInfoSet syncSet); - - /* - * Divide the sync info for the operation by project - */ - private Map getProjectSyncInfoSetMap(SyncInfoSet syncSet) { - Map map = new HashMap(); - SyncInfo[] infos = syncSet.getSyncInfos(); - for (int i = 0; i < infos.length; i++) { - SyncInfo info = infos[i]; - IProject project = info.getLocal().getProject(); - SyncInfoSet set = (SyncInfoSet)map.get(project); - if (set == null) { - set = new SyncInfoSet(); - map.put(project, set); - } - set.add(info); - } - return map; - } - - /** - * Run the operation on the sync info in the given set. The sync info will be all - * from the same project. - * @param provider - * @param set the sync info set - * @param monitor a progress monitor - */ - protected abstract void run(FileSystemProvider provider, SyncInfoSet set, IProgressMonitor monitor) throws TeamException; -} 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 7ff7f3891..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemSynchronizeParticipant.java +++ /dev/null @@ -1,139 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-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.CoreException; -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.subscribers.Subscriber; -import org.eclipse.team.core.synchronize.SyncInfo; -import org.eclipse.team.core.variants.IResourceVariant; -import org.eclipse.team.examples.filesystem.subscriber.FileSystemSubscriber; -import org.eclipse.team.ui.TeamUI; -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 SubscriberParticipant { - - /** - * The particpant ID as defined in the plugin manifest - */ - public static final String ID = "org.eclipse.team.examples.filesystem.participant"; //$NON-NLS-1$ - - /** - * Contxt menu action group for synchronize view actions - */ - public static final String CONTEXT_MENU_CONTRIBUTION_GROUP_1 = "context_group_1"; //$NON-NLS-1$ - - /** - * A custom label decorator that will show the remote mapped path for each - * file. - */ - private 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 null; - } - /* (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) { - } - return null; - } - } - - /** - * Action group that contributes the get an put menus to the context menu - * in the synchronize view - */ - private class FileSystemParticipantActionGroup extends SynchronizePageActionGroup { - /* (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_CONTRIBUTION_GROUP_1, - new GetSynchronizeAction("Get", configuration)); - appendToGroup( - ISynchronizePageConfiguration.P_CONTEXT_MENU, - CONTEXT_MENU_CONTRIBUTION_GROUP_1, - new PutSynchronizeAction("Put", configuration)); - } - - } - - public FileSystemSynchronizeParticipant(ISynchronizeScope scope) { - super(scope); - setSubscriber(FileSystemSubscriber.getInstance()); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.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 - } - } - - /* (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); - - ILabelDecorator labelDecorator = new FileSystemParticipantLabelDecorator(); - configuration.addLabelDecorator(labelDecorator); - - // Add support for showing mode buttons - configuration.setSupportedModes(ISynchronizePageConfiguration.ALL_MODES); - configuration.setMode(ISynchronizePageConfiguration.BOTH_MODE); - - // Create the action group that contributes the get and put actions - configuration.addActionContribution(new FileSystemParticipantActionGroup()); - // Add the get and put group to the context menu - configuration.addMenuGroup( - ISynchronizePageConfiguration.P_CONTEXT_MENU, - CONTEXT_MENU_CONTRIBUTION_GROUP_1); - } -} 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 06dc044d3..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetAction.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.examples.filesystem.ui; - -import java.lang.reflect.InvocationTargetException; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.jface.action.IAction; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.examples.filesystem.FileSystemProvider; -import org.eclipse.team.examples.filesystem.Policy; -import org.eclipse.ui.actions.WorkspaceModifyOperation; - -/** - * Action for getting the contents of the selected resources - */ -public class GetAction extends FileSystemAction { - - public void run(IAction action) { - run(new WorkspaceModifyOperation(null) { - public void execute(IProgressMonitor monitor) throws InterruptedException, InvocationTargetException { - try { - Map table = getRepositoryProviderMapping(); - monitor.beginTask(null, table.size() * 1000); - monitor.setTaskName(Policy.bind("GetAction.working")); //$NON-NLS-1$ - for (Iterator iter = table.keySet().iterator(); iter.hasNext();) { - IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1000); - FileSystemProvider provider = (FileSystemProvider) iter.next(); - List list = (List) table.get(provider); - IResource[] providerResources = (IResource[]) list.toArray(new IResource[list.size()]); - provider.getOperations().get(providerResources, IResource.DEPTH_INFINITE, isOverwriteOutgoing(), subMonitor); - } - } catch (TeamException e) { - throw new InvocationTargetException(e); - } finally { - monitor.done(); - } - } - }, Policy.bind("GetAction.problemMessage"), PROGRESS_DIALOG); //$NON-NLS-1$ - } - - /** - * 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/GetSynchronizeAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetSynchronizeAction.java deleted file mode 100644 index 307598713..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetSynchronizeAction.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.examples.filesystem.ui; - -import org.eclipse.compare.structuremergeviewer.IDiffElement; -import org.eclipse.team.core.synchronize.FastSyncInfoFilter; -import org.eclipse.team.core.synchronize.SyncInfo; -import org.eclipse.team.core.synchronize.FastSyncInfoFilter.SyncInfoDirectionFilter; -import org.eclipse.team.ui.synchronize.*; - -/** - * Get action that appears in the synchronize view. It's main purpose is - * to filter the selection and delegate its execution to the get operation. - */ -public class GetSynchronizeAction extends SynchronizeModelAction { - - protected GetSynchronizeAction(String text, ISynchronizePageConfiguration configuration) { - super(text, configuration); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.SynchronizeModelAction#getSubscriberOperation(org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration, org.eclipse.compare.structuremergeviewer.IDiffElement[]) - */ - protected SynchronizeModelOperation getSubscriberOperation(ISynchronizePageConfiguration configuration, IDiffElement[] elements) { - return new GetSynchronizeOperation(configuration, elements); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.sync.SubscriberAction#getSyncInfoFilter() - */ - protected FastSyncInfoFilter getSyncInfoFilter() { - return new SyncInfoDirectionFilter(new int[] {SyncInfo.INCOMING, SyncInfo.CONFLICTING}); - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetSynchronizeOperation.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetSynchronizeOperation.java deleted file mode 100644 index 067861739..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/GetSynchronizeOperation.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.examples.filesystem.ui; - -import org.eclipse.compare.structuremergeviewer.IDiffElement; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.core.synchronize.SyncInfoSet; -import org.eclipse.team.examples.filesystem.FileSystemProvider; -import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; - -/** - * Sync view operation for getting file system resources - */ -public class GetSynchronizeOperation extends FileSystemSynchronizeOperation { - - protected GetSynchronizeOperation(ISynchronizePageConfiguration configuration, IDiffElement[] elements) { - super(configuration, elements); - } - - /* (non-Javadoc) - * @see org.eclipse.team.examples.filesystem.ui.FileSystemSynchronizeOperation#promptForConflictHandling(org.eclipse.swt.widgets.Shell, org.eclipse.team.core.synchronize.SyncInfoSet) - */ - protected boolean promptForConflictHandling(Shell shell, SyncInfoSet syncSet) { - // If there is a conflict in the syncSet, we need to prompt the user before proceeding. - if (syncSet.hasConflicts() || syncSet.hasOutgoingChanges()) { - switch (promptForConflicts(shell, syncSet)) { - case 0: - // Yes, synchronize conflicts as well - break; - case 1: - // No, remove outgoing - syncSet.removeConflictingNodes(); - syncSet.removeOutgoingNodes(); - break; - case 2: - default: - // Cancel - return false; - } - } - return true; - } - - /** - * Prompts the user to determine how conflicting changes should be handled. - * Note: This method is designed to be overridden by test cases. - * @return 0 to sync conflicts, 1 to sync all non-conflicts, 2 to cancel - */ - private int promptForConflicts(Shell shell, SyncInfoSet syncSet) { - String[] buttons = new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL}; - String title = "Confirm Overwrite"; //$NON-NLS-1$ - String question = "You have changes that conflict with the server. Overwrite those changes?"; //$NON-NLS-1$ - final MessageDialog dialog = new MessageDialog(shell, title, null, question, MessageDialog.QUESTION, buttons, 0); - shell.getDisplay().syncExec(new Runnable() { - public void run() { - dialog.open(); - } - }); - return dialog.getReturnCode(); - } - - /* (non-Javadoc) - * @see org.eclipse.team.examples.filesystem.ui.FileSystemSynchronizeOperation#run(org.eclipse.team.examples.filesystem.FileSystemProvider, org.eclipse.team.core.synchronize.SyncInfoSet, org.eclipse.core.runtime.IProgressMonitor) - */ - protected void run(FileSystemProvider provider, SyncInfoSet set, IProgressMonitor monitor) throws TeamException { - provider.getOperations().get(set.getResources(), IResource.DEPTH_INFINITE, true, monitor); - } - -} 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 4d0316af8..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/ProjectSetSerializer.java +++ /dev/null @@ -1,123 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-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.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.team.core.IProjectSetSerializer; -import org.eclipse.team.core.RepositoryProvider; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.examples.filesystem.FileSystemPlugin; -import org.eclipse.team.examples.filesystem.FileSystemProvider; -import org.eclipse.team.examples.filesystem.Policy; -import org.eclipse.team.internal.core.Assert; - -/** - * 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) throws TeamException { - 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) throws TeamException { - 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 585391d8c..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutAction.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.examples.filesystem.ui; - -import java.lang.reflect.InvocationTargetException; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.jface.action.IAction; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.examples.filesystem.FileSystemProvider; -import org.eclipse.team.examples.filesystem.Policy; -import org.eclipse.ui.actions.WorkspaceModifyOperation; - -/** - * Action for checking in the selected resources - */ -public class PutAction extends FileSystemAction { - - /* - * Method declared on IActionDelegate. - */ - public void run(IAction action) { - run(new WorkspaceModifyOperation(null) { - public void execute(IProgressMonitor monitor) throws InterruptedException, InvocationTargetException { - try { - Map table = getRepositoryProviderMapping(); - monitor.beginTask(null, table.size() * 1000); - monitor.setTaskName(Policy.bind("PutAction.working")); //$NON-NLS-1$ - for (Iterator iter = table.keySet().iterator(); iter.hasNext();) { - IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1000); - FileSystemProvider provider = (FileSystemProvider) iter.next(); - List list = (List) table.get(provider); - IResource[] providerResources = (IResource[]) list.toArray(new IResource[list.size()]); - provider.getOperations().checkin(providerResources, IResource.DEPTH_INFINITE, isOverrideIncoming(), subMonitor); - } - } catch (TeamException e) { - throw new InvocationTargetException(e); - } finally { - monitor.done(); - } - } - }, Policy.bind("PutAction.problemMessage"), PROGRESS_DIALOG); //$NON-NLS-1$ - } - - /** - * 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/PutSynchronizeAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutSynchronizeAction.java deleted file mode 100644 index d6234c606..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutSynchronizeAction.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.examples.filesystem.ui; - -import org.eclipse.compare.structuremergeviewer.IDiffElement; -import org.eclipse.team.core.synchronize.FastSyncInfoFilter; -import org.eclipse.team.core.synchronize.SyncInfo; -import org.eclipse.team.core.synchronize.FastSyncInfoFilter.SyncInfoDirectionFilter; -import org.eclipse.team.ui.synchronize.*; - -/** - * Put action that appears in the synchronize view. It's main purpose is - * to filter the selection and delegate its execution to the put operation. - */ -public class PutSynchronizeAction extends SynchronizeModelAction { - - public PutSynchronizeAction(String text, ISynchronizePageConfiguration configuration) { - super(text, configuration); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.SynchronizeModelAction#getSyncInfoFilter() - */ - protected FastSyncInfoFilter getSyncInfoFilter() { - return new SyncInfoDirectionFilter(new int[] {SyncInfo.OUTGOING, SyncInfo.CONFLICTING}); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.SynchronizeModelAction#getSubscriberOperation(org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration, org.eclipse.compare.structuremergeviewer.IDiffElement[]) - */ - protected SynchronizeModelOperation getSubscriberOperation(ISynchronizePageConfiguration configuration, IDiffElement[] elements) { - return new PutSynchronizeOperation(configuration, elements); - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutSynchronizeOperation.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutSynchronizeOperation.java deleted file mode 100644 index 91fdf4db1..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/PutSynchronizeOperation.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.examples.filesystem.ui; - -import org.eclipse.compare.structuremergeviewer.IDiffElement; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.core.synchronize.SyncInfoSet; -import org.eclipse.team.examples.filesystem.FileSystemProvider; -import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; - -/** - * Sync view operation for putting file system resources - */ -public class PutSynchronizeOperation extends FileSystemSynchronizeOperation { - - protected PutSynchronizeOperation(ISynchronizePageConfiguration configuration, IDiffElement[] elements) { - super(configuration, elements); - } - - /* (non-Javadoc) - * @see org.eclipse.team.examples.filesystem.ui.FileSystemSynchronizeOperation#promptForConflictHandling(org.eclipse.swt.widgets.Shell, org.eclipse.team.core.synchronize.SyncInfoSet) - */ - protected boolean promptForConflictHandling(Shell shell, SyncInfoSet syncSet) { - // If there is a conflict in the syncSet, we need to prompt the user before proceeding. - if (syncSet.hasConflicts() || syncSet.hasIncomingChanges()) { - switch (promptForConflicts(shell, syncSet)) { - case 0: - // Yes, synchronize conflicts as well - break; - case 1: - // No, stop here - syncSet.removeConflictingNodes(); - syncSet.removeIncomingNodes(); - break; - case 2: - default: - // Cancel - return false; - } - } - return true; - } - - /** - * Prompts the user to determine how conflicting changes should be handled. - * Note: This method is designed to be overridden by test cases. - * @return 0 to sync conflicts, 1 to sync all non-conflicts, 2 to cancel - */ - private int promptForConflicts(Shell shell, SyncInfoSet syncSet) { - String[] buttons = new String[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL}; - String title = "Confirm Overwrite"; //$NON-NLS-1$ - String question = "You have changes that conflict with the server. Release those changes?"; //$NON-NLS-1$ - final MessageDialog dialog = new MessageDialog(shell, title, null, question, MessageDialog.QUESTION, buttons, 0); - shell.getDisplay().syncExec(new Runnable() { - public void run() { - dialog.open(); - } - }); - return dialog.getReturnCode(); - } - - /* (non-Javadoc) - * @see org.eclipse.team.examples.filesystem.ui.FileSystemSynchronizeOperation#run(org.eclipse.team.examples.filesystem.FileSystemProvider, org.eclipse.team.core.synchronize.SyncInfoSet, org.eclipse.core.runtime.IProgressMonitor) - */ - protected void run(FileSystemProvider provider, SyncInfoSet set, IProgressMonitor monitor) throws TeamException { - provider.getOperations().checkin(set.getResources(), IResource.DEPTH_INFINITE, true, monitor); - } - -} 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 7c22b7ccb..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, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-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/SynchronizeAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/SynchronizeAction.java deleted file mode 100644 index d60ffc021..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/SynchronizeAction.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-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.jface.action.IAction; -import org.eclipse.team.ui.TeamUI; -import org.eclipse.team.ui.synchronize.*; - -/** - * Action to synchronize the selected resources. This results - * in a file-system participant being added to the synchronize view. - */ -public class SynchronizeAction extends FileSystemAction { - - /* (non-Javadoc) - * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) - */ - public void run(IAction action) { - IResource[] resources = getSelectedResources(); - // First check if there is an existing matching participant - FileSystemSynchronizeParticipant participant = (FileSystemSynchronizeParticipant)SubscriberParticipant.getMatchingParticipant(FileSystemSynchronizeParticipant.ID, resources); - // If there isn't, create one and add to the manager - if (participant == null) { - participant = new FileSystemSynchronizeParticipant(new ResourceScope(resources)); - TeamUI.getSynchronizeManager().addSynchronizeParticipants(new ISynchronizeParticipant[] {participant}); - } - participant.refresh(resources, null, null, getTargetPart().getSite()); - - } - -} 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 b79f651c9..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, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-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.jface.wizard.IWizard; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.team.examples.filesystem.subscriber.FileSystemSubscriber; -import org.eclipse.team.internal.ui.ITeamUIImages; -import org.eclipse.team.internal.ui.Policy; -import org.eclipse.team.internal.ui.synchronize.GlobalRefreshResourceSelectionPage; -import org.eclipse.team.ui.TeamImages; -import org.eclipse.team.ui.TeamUI; -import org.eclipse.team.ui.synchronize.ISynchronizeParticipant; -import org.eclipse.team.ui.synchronize.SubscriberParticipant; - -public class SynchronizeWizard extends Wizard { - private GlobalRefreshResourceSelectionPage selectionPage; - private IWizard importWizard; - - public SynchronizeWizard() { - setDefaultPageImageDescriptor(TeamImages.getImageDescriptor(ITeamUIImages.IMG_WIZBAN_SHARE)); - setNeedsProgressMonitor(false); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.wizard.Wizard#getWindowTitle() - */ - public String getWindowTitle() { - return Policy.bind("GlobalRefreshSubscriberPage.0"); //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.jface.wizard.Wizard#addPages() - */ - public void addPages() { - selectionPage = new GlobalRefreshResourceSelectionPage(FileSystemSubscriber.getInstance().roots()); - selectionPage.setTitle("Synchronize File System Example"); - selectionPage.setMessage("Synchronize File System Example"); - addPage(selectionPage); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.wizard.IWizard#performFinish() - */ - public boolean performFinish() { - if (importWizard != null) { - return importWizard.performFinish(); - } else { - IResource[] resources = selectionPage.getRootResources(); - if (resources != null && resources.length > 0) { - SubscriberParticipant participant = new FileSystemSynchronizeParticipant(selectionPage.getSynchronizeScope()); - TeamUI.getSynchronizeManager().addSynchronizeParticipants(new ISynchronizeParticipant[]{participant}); - // We don't know in which site to show progress because a participant could actually be shown in multiple sites. - participant.run(null /* no site */); - } - return true; - } - } -} diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/LocalHistoryPartipant.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/LocalHistoryPartipant.java deleted file mode 100644 index 12658fd09..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/LocalHistoryPartipant.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.examples.localhistory; - -import org.eclipse.compare.structuremergeviewer.IDiffElement; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.jface.viewers.ILabelDecorator; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.swt.graphics.Image; -import org.eclipse.team.core.subscribers.Subscriber; -import org.eclipse.team.core.synchronize.SyncInfo; -import org.eclipse.team.ui.TeamUI; -import org.eclipse.team.ui.synchronize.*; - -public class LocalHistoryPartipant 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 LocalHistoryPartipant() { - 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) { - } - } - - 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()); - } -} 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 49a6b4c14..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/LocalHistorySubscriber.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.examples.localhistory; - -import java.util.*; - -import org.eclipse.core.resources.*; -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$ - } - - public boolean isSupervised(IResource resource) throws TeamException { - // 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; - } - - public void refresh(IResource[] resources, int depth, IProgressMonitor monitor) throws TeamException { - } -} 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 fd0c38fdc..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/LocalHistorySyncInfo.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-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; - else - return super.calculateKind(); - } -}
\ No newline at end of file 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 ebbfb0d3f..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, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-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() { - LocalHistoryPartipant participant = new LocalHistoryPartipant(); - 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 fcee62b20..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, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-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.TeamException; -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) throws TeamException { - 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 ead29974d..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, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-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 93913befc..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, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-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/pessimistic/IPessimisticFilesystemConstants.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/IPessimisticFilesystemConstants.java deleted file mode 100644 index 7f8748631..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/IPessimisticFilesystemConstants.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ -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 d8dc6be75..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/IResourceStateListener.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ -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 57b9463ab..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/PessimisticFilesystemProvider.java +++ /dev/null @@ -1,710 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ -package org.eclipse.team.examples.pessimistic; - -import java.io.*; -import java.util.*; -import org.eclipse.core.resources.*; -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 IFileModificationValidator validator; - /** - * The cache of resources that are currently controlled. - * The cache is a map of parent resource -> set of controlled children. - */ - private 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); - - Set keys= byParent.keySet(); - 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; - } else { - 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. - */ - private Set readControlFile(IFile controlFile) { - Set controlledResources= new HashSet(1); - if (controlFile.exists()) { - InputStream in= null; - try { - try { - in= ((IFile)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 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) throws CoreException { - 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) throws CoreException { - 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) throws CoreException { - 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) throws CoreException { - 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) { - } - } 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) throws CoreException { - } - }, - 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) throws CoreException { - 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 df787013f..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/PessimisticFilesystemProviderPlugin.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ -package org.eclipse.team.examples.pessimistic; - -import java.util.*; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.*; -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"; - - /** - * Contstructor 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) { - 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= getDescriptor().getUniqueIdentifier(); - 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(); - 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 3701951b4..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/PessimisticModificationValidator.java +++ /dev/null @@ -1,331 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ -package org.eclipse.team.examples.pessimistic; - -import java.util.*; -import org.eclipse.core.resources.*; -import org.eclipse.core.runtime.*; -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.*; -import org.eclipse.ui.dialogs.CheckedTreeSelectionDialog; -import org.eclipse.ui.model.WorkbenchLabelProvider; -import org.eclipse.ui.views.navigator.ResourceSorter; - -/** - * The <code>PessimisticModificationValidator</code> is an - * implementation of the <code>IFileModificationValidator</code> for the - * <code>PessimisticFilesystemProvider</code>. - * - * @see PessimiticFilesystemProvider - * @see IFileModificationValidator - */ -public class PessimisticModificationValidator - implements IFileModificationValidator { - /* - * The provider for this validator - */ - private PessimisticFilesystemProvider fProvider; - - public PessimisticModificationValidator(PessimisticFilesystemProvider provider) { - fProvider= provider; - } - - /** - * @see IFileModificationValidator#validateEdit(IFile[], Object) - */ - public IStatus validateEdit(IFile[] files, Object 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 cancelled 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, "NOTOK", 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, "NOTOK", null); - } - } - return new MultiStatus( getUid(), IStatus.OK, children, "MULTISTATUS", 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.setSorter(new ResourceSorter(ResourceSorter.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 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 2a206beaa..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ResourceChangeListener.java +++ /dev/null @@ -1,294 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ -package org.eclipse.team.examples.pessimistic; - -import java.util.*; - -import org.eclipse.core.resources.*; -import org.eclipse.core.runtime.*; -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.*; -import org.eclipse.ui.dialogs.CheckedTreeSelectionDialog; -import org.eclipse.ui.model.WorkbenchLabelProvider; -import org.eclipse.ui.views.navigator.ResourceSorter; - -/** - * 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) throws CoreException { - 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) throws CoreException { - 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.setSorter(new ResourceSorter(ResourceSorter.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 0d3248b7c..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ResourceSetContentProvider.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ -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 d7178d0f8..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/AddToControlAction.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ -package org.eclipse.team.examples.pessimistic.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.runtime.IProgressMonitor; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.team.examples.pessimistic.PessimisticFilesystemProvider; - -/** - * 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) - throws InvocationTargetException, InterruptedException { - 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 e7be75fc7..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/BlankPage.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ -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 fa4dd3759..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/CheckInAction.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ -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 37e54dc45..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/CheckOutAction.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ -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 4f9525da8..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/ConfigurationWizard.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ -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 74757fd3f..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/DisconnectAction.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ -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.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; - -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) - throws InvocationTargetException, InterruptedException { - 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 8e4e64843..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/PessimisticDecorator.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ -package org.eclipse.team.examples.pessimistic.ui; - -import java.util.HashSet; -import java.util.Set; - -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 { - - private Set fDecoratedProjects; - - /** - * Constructor needed for extension - */ - public PessimisticDecorator() { - fDecoratedProjects= new HashSet(1); - 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; - } else { - return text; - } - } else { - if (provider.isIgnored(resource)) { - return "[ignored] " + text; - } else { - 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 4bc37d635..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/PessimisticPreferencesPage.java +++ /dev/null @@ -1,366 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ -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 values for the files are edited without a context preference. - */ - private static final int[] EDIT_NO_PROMPT_OPTION_KEYS= - new int[] { - IPessimisticFilesystemConstants.OPTION_AUTOMATIC, - IPessimisticFilesystemConstants.OPTION_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) { - } - - /* - * @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 ec035b7ea..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/PessimisticProviderAction.java +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ -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; - } else { - 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 9a03edb10..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/RemoveFromControlAction.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ -package org.eclipse.team.examples.pessimistic.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.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) - throws InvocationTargetException, InterruptedException { - 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 a5df14347..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/SourceManagementAction.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ -package org.eclipse.team.examples.pessimistic.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.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) - throws InvocationTargetException, InterruptedException { - 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 69a768213..000000000 --- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/ui/UncheckOutAction.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2002 IBM Corp. All rights reserved. - * This file is made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - */ -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); - } - -} |