diff options
Diffstat (limited to 'examples')
8 files changed, 405 insertions, 0 deletions
diff --git a/examples/org.eclipse.team.examples.filesystem/icons/full/wizards/synced.gif b/examples/org.eclipse.team.examples.filesystem/icons/full/wizards/synced.gif Binary files differnew file mode 100644 index 000000000..870934b69 --- /dev/null +++ b/examples/org.eclipse.team.examples.filesystem/icons/full/wizards/synced.gif diff --git a/examples/org.eclipse.team.examples.filesystem/plugin.xml b/examples/org.eclipse.team.examples.filesystem/plugin.xml index 39007b74a..b8f080ec5 100644 --- a/examples/org.eclipse.team.examples.filesystem/plugin.xml +++ b/examples/org.eclipse.team.examples.filesystem/plugin.xml @@ -80,6 +80,26 @@ name="Synchronize File System Provider" id="org.eclipse.team.examples.filesystem.synchronizeWizard"/> </extension> + + <extension + point="org.eclipse.team.ui.synchronizeParticipants"> + <participant + persistent="false" + icon="icons/full/wizards/synced.gif" + class="org.eclipse.team.examples.localhistory.LocalHistoryParticipant" + name="Latest From Local History" + id="org.eclipse.team.synchronize.example"/> + </extension> + + <extension + point="org.eclipse.team.ui.synchronizeWizards"> + <wizard + class="org.eclipse.team.examples.localhistory.LocalHistorySynchronizeWizard" + icon="icons/full/wizards/synced.gif" + description="ExampleSynchronizeSupport.wizard1" + name="Latest From Local History Synchronize" + id="ExampleSynchronizeSupport.wizard1"/> + </extension> <!-- =================================================================================== --> <!-- Menus for File System Example --> 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 new file mode 100644 index 000000000..fde5878c2 --- /dev/null +++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/LocalHistoryPartipant.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * 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.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 new file mode 100644 index 000000000..12e5be628 --- /dev/null +++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/LocalHistorySubscriber.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * 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.localhistory; + +import java.util.*; +import org.eclipse.core.resources.*; +import org.eclipse.core.runtime.*; +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.IResourceVariantComparator; +import org.eclipse.team.examples.filesystem.FileSystemPlugin; + +public class LocalHistorySubscriber extends Subscriber { + + private long timestamp; + private static final long LAST_FILESTATE = 0L; + private LocalHistoryVariantComparator comparator; + + public LocalHistorySubscriber() { + this(LAST_FILESTATE); + } + + public LocalHistorySubscriber(long timestamp) { + this.timestamp = timestamp; + 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, new NullProgressMonitor()))); + return (IResource[]) existingChildren.toArray(new IResource[existingChildren.size()]); + } catch (CoreException e) { + FileSystemPlugin.getPlugin().getLog().log(e.getStatus()); + return new IResource[0]; + } + } + + public IResource[] roots() { + return ResourcesPlugin.getWorkspace().getRoot().getProjects(); + } + + public SyncInfo getSyncInfo(IResource resource) throws TeamException { + try { + if(resource.getType() == IResource.FILE) { + IFile file = (IFile)resource; + IFileState[] states = file.getHistory(new NullProgressMonitor()); + if(states.length > 0) { + // last state only + SyncInfo info = new SyncInfo(file,null, new LocalHistoryVariant(states[0]), comparator); + info.init(); + return info; + } + } + } catch (CoreException e) { + FileSystemPlugin.getPlugin().getLog().log(e.getStatus()); + } + return new SyncInfo(resource, null, null, comparator) { + protected int calculateKind() throws TeamException { + return IN_SYNC; + } + }; + } + + 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/LocalHistorySynchronizeWizard.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/LocalHistorySynchronizeWizard.java new file mode 100644 index 000000000..a617fabd9 --- /dev/null +++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/LocalHistorySynchronizeWizard.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * 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.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 new file mode 100644 index 000000000..f99f35b75 --- /dev/null +++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/LocalHistoryVariant.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * 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.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 new file mode 100644 index 000000000..a359564d7 --- /dev/null +++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/LocalHistoryVariantComparator.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * 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.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 new file mode 100644 index 000000000..256f6abae --- /dev/null +++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/localhistory/RevertAllOperation.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * 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.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); + } +} |