Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBogdan Gheorghe2006-06-01 03:43:39 +0000
committerBogdan Gheorghe2006-06-01 03:43:39 +0000
commit2c0b8784be0075c26149c882a53a86b3ba94d5f3 (patch)
treec45ec94cd28c646dda69b5cdbd98f48ea8f8bc37
parent576d5d521f1695eb5a18d5288506d955cedc1c2d (diff)
downloadeclipse.platform.team-2c0b8784be0075c26149c882a53a86b3ba94d5f3.tar.gz
eclipse.platform.team-2c0b8784be0075c26149c882a53a86b3ba94d5f3.tar.xz
eclipse.platform.team-2c0b8784be0075c26149c882a53a86b3ba94d5f3.zip
FileSystem History ExampleI200605311150
-rw-r--r--examples/org.eclipse.team.examples.filesystem/doc-html/team_filesystem_ex.html6
-rw-r--r--examples/org.eclipse.team.examples.filesystem/plugin.xml22
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/history/FileSystemFileRevision.java74
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/history/FileSystemHistory.java65
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/history/FileSystemHistoryProvider.java24
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemRemoteTree.java4
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemResourceVariant.java4
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemHistoryPage.java233
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemHistoryPageSource.java27
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemRevisionEditorInput.java97
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemTableProvider.java254
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/OpenFileSystemRevisionAction.java158
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/ShowHistoryAction.java68
-rw-r--r--examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/AdapterFactory.java12
14 files changed, 1043 insertions, 5 deletions
diff --git a/examples/org.eclipse.team.examples.filesystem/doc-html/team_filesystem_ex.html b/examples/org.eclipse.team.examples.filesystem/doc-html/team_filesystem_ex.html
index e37ab1471..d5167a143 100644
--- a/examples/org.eclipse.team.examples.filesystem/doc-html/team_filesystem_ex.html
+++ b/examples/org.eclipse.team.examples.filesystem/doc-html/team_filesystem_ex.html
@@ -20,9 +20,11 @@ this example shows how to:
<li>Implement synchronization support that shows up the Synchronize View.
<li>Use decorators to show the repository state of the local resources.
<li>How to implement a file modification validator.
-<li>Adding a repository provider to a capability.
+<li>Add a repository provider to a capability.
+<li>Add a History page for the basic file system which will display both the local history revisions and the file system revisions in the
+History view.</li>
</ul>
-The example includes two separate repository providers, the basic file system and the pessimistic file system. The basic provider illustrates
+The example includes two separate repository providers: the basic file system and the pessimistic file system. The basic provider illustrates
the synchronization support whereas the pessimistic provider is more focused to allowing you to test the workbench behavior with pessimistic
repository providers. There is a preference page for the pessimistic provider that allows configuring the behavior of the file modification
validator.
diff --git a/examples/org.eclipse.team.examples.filesystem/plugin.xml b/examples/org.eclipse.team.examples.filesystem/plugin.xml
index 6256087e2..5175365b5 100644
--- a/examples/org.eclipse.team.examples.filesystem/plugin.xml
+++ b/examples/org.eclipse.team.examples.filesystem/plugin.xml
@@ -204,6 +204,23 @@
id="org.eclipse.team.examples.filesystem.unmanage">
</action>
</objectContribution>
+ <objectContribution
+ adaptable="false"
+ id="org.eclipse.team.examples.filesystem.fileContribution"
+ objectClass="org.eclipse.core.resources.IFile">
+ <enablement>
+ <adapt type="org.eclipse.core.resources.mapping.ResourceMapping">
+ <test property="org.eclipse.core.resources.projectPersistentProperty"
+ args="org.eclipse.team.core.repository,org.eclipse.team.examples.filesystem.FileSystemProvider"/>
+ </adapt>
+ </enablement>
+ <action
+ class="org.eclipse.team.examples.filesystem.ui.ShowHistoryAction"
+ id="org.eclipse.team.examples.filesystem.showHistory"
+ label="Show History Dude"
+ menubarPath="team.main/group4">
+ </action>
+ </objectContribution>
</extension>
<!-- =================================================================================== -->
@@ -481,6 +498,11 @@
<adapter type="org.eclipse.team.core.mapping.IResourceMappingMerger"/>
<adapter type="org.eclipse.team.ui.mapping.ISynchronizationCompareAdapter"/>
</factory>
+ <factory
+ adaptableType="org.eclipse.team.core.history.provider.FileHistoryProvider"
+ class="org.eclipse.team.examples.model.ui.AdapterFactory">
+ <adapter type="org.eclipse.team.ui.history.IHistoryPageSource"/>
+ </factory>
</extension>
<extension
point="org.eclipse.team.ui.teamContentProviders">
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/history/FileSystemFileRevision.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/history/FileSystemFileRevision.java
new file mode 100644
index 000000000..0ace47653
--- /dev/null
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/history/FileSystemFileRevision.java
@@ -0,0 +1,74 @@
+package org.eclipse.team.examples.filesystem.history;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+
+import org.eclipse.core.resources.IStorage;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.team.core.history.IFileRevision;
+import org.eclipse.team.core.history.provider.FileRevision;
+
+public class FileSystemFileRevision extends FileRevision {
+
+ java.io.File remoteFile;
+
+ public FileSystemFileRevision(java.io.File file) {
+ this.remoteFile = file;
+ }
+
+ public String getName() {
+ return remoteFile.getName();
+ }
+
+ public long getTimestamp() {
+ return remoteFile.lastModified();
+ }
+
+ public IStorage getStorage(IProgressMonitor monitor) throws CoreException {
+ return new IStorage() {
+
+ public InputStream getContents() throws CoreException {
+ try {
+ return new FileInputStream(remoteFile);
+ } catch (FileNotFoundException e) {
+ }
+
+ return null;
+ }
+
+ public IPath getFullPath() {
+ return new Path(remoteFile.getAbsolutePath());
+ }
+
+ public String getName() {
+ return remoteFile.getName();
+ }
+
+ public boolean isReadOnly() {
+ return true;
+ }
+
+ public Object getAdapter(Class adapter) {
+ return null;
+ }
+
+ };
+ }
+
+ public boolean isPropertyMissing() {
+ return false;
+ }
+
+ public IFileRevision withAllProperties(IProgressMonitor monitor) throws CoreException {
+ return null;
+ }
+
+ public String getContentIdentifier() {
+ return "[File System Revision]"; //$NON-NLS-1$
+ }
+
+}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/history/FileSystemHistory.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/history/FileSystemHistory.java
new file mode 100644
index 000000000..918b9602e
--- /dev/null
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/history/FileSystemHistory.java
@@ -0,0 +1,65 @@
+package org.eclipse.team.examples.filesystem.history;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFileState;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.core.RepositoryProvider;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.core.history.IFileRevision;
+import org.eclipse.team.core.history.provider.FileHistory;
+import org.eclipse.team.core.variants.IResourceVariant;
+import org.eclipse.team.examples.filesystem.FileSystemProvider;
+import org.eclipse.team.examples.filesystem.subscriber.FileSystemResourceVariant;
+import org.eclipse.team.internal.core.history.LocalFileRevision;
+
+public class FileSystemHistory extends FileHistory {
+
+ private IFile file;
+ protected IFileRevision[] revisions;
+
+ public FileSystemHistory(IFile file) {
+ this.file = file;
+ }
+
+ public IFileRevision[] getContributors(IFileRevision revision) {
+ return null;
+ }
+
+ public IFileRevision getFileRevision(String id) {
+ return null;
+ }
+
+ public IFileRevision[] getFileRevisions() {
+ return revisions;
+ }
+
+ public IFileRevision[] getTargets(IFileRevision revision) {
+ return null;
+ }
+
+ public void refresh(IProgressMonitor monitor) {
+ try {
+ RepositoryProvider provider = RepositoryProvider.getProvider(file.getProject());
+ if (provider != null && provider instanceof FileSystemProvider) {
+ FileSystemProvider fileProvider = (FileSystemProvider) provider;
+ IResourceVariant resVar = fileProvider.getResourceVariant(file);
+ if (resVar instanceof FileSystemResourceVariant) {
+ FileSystemResourceVariant resVarF = (FileSystemResourceVariant) resVar;
+ java.io.File javaFile = resVarF.getFile();
+ //Get local history items
+ IFileState[] states = file.getHistory(monitor);
+ revisions = new IFileRevision[states.length + 1];
+ int i = 0;
+ for (; i < states.length; i++) {
+ revisions[i] = new LocalFileRevision(states[i]);
+ }
+ revisions[i] = new FileSystemFileRevision(javaFile);
+ }
+ }
+ } catch (TeamException e) {
+ } catch (CoreException e) {
+ }
+ }
+
+}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/history/FileSystemHistoryProvider.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/history/FileSystemHistoryProvider.java
new file mode 100644
index 000000000..f1e8a9845
--- /dev/null
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/history/FileSystemHistoryProvider.java
@@ -0,0 +1,24 @@
+package org.eclipse.team.examples.filesystem.history;
+
+import org.eclipse.core.filesystem.IFileStore;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.core.history.IFileHistory;
+import org.eclipse.team.core.history.IFileRevision;
+import org.eclipse.team.core.history.provider.FileHistoryProvider;
+
+public class FileSystemHistoryProvider extends FileHistoryProvider {
+
+ public IFileHistory getFileHistoryFor(IResource resource, int flags, IProgressMonitor monitor) {
+ return null;
+ }
+
+ public IFileHistory getFileHistoryFor(IFileStore store, int flags, IProgressMonitor monitor) {
+ return null;
+ }
+
+ public IFileRevision getWorkspaceFileRevision(IResource resource) {
+ return null;
+ }
+
+}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemRemoteTree.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/subscriber/FileSystemRemoteTree.java
index 2e03301be..c8aed4922 100644
--- 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
@@ -20,13 +20,13 @@ 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 file system three-way remote resource variant tree that provides
* the ability to traverse the file system for the creation of resource variants.
*/
public class FileSystemRemoteTree extends ThreeWayRemoteTree {
/**
- * Create the file syetm remote resource variant tree
+ * Create the file system remote resource variant tree
* @param subscriber the file system subscriber
*/
public FileSystemRemoteTree(FileSystemSubscriber subscriber) {
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
index 632f937e6..8a06ae485 100644
--- 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
@@ -146,4 +146,8 @@ public class FileSystemResourceVariant extends CachedResourceVariant {
throw new TeamException("Failed to fetch contents for " + getFilePath(), e); //$NON-NLS-1$
}
}
+
+ public java.io.File getFile(){
+ return ioFile;
+ }
}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemHistoryPage.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemHistoryPage.java
new file mode 100644
index 000000000..9cf2e8323
--- /dev/null
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemHistoryPage.java
@@ -0,0 +1,233 @@
+package org.eclipse.team.examples.filesystem.ui;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.team.core.RepositoryProvider;
+import org.eclipse.team.core.history.IFileHistory;
+import org.eclipse.team.core.history.IFileRevision;
+import org.eclipse.team.examples.filesystem.FileSystemProvider;
+import org.eclipse.team.examples.filesystem.history.FileSystemHistory;
+import org.eclipse.team.internal.ui.Utils;
+import org.eclipse.team.ui.history.HistoryPage;
+import org.eclipse.team.ui.history.IHistoryPageSite;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchPartSite;
+
+public class FileSystemHistoryPage extends HistoryPage {
+
+ /* private */IFile file;
+ /* private */FileSystemHistory fileSystemHistory;
+ /* private */IFileRevision[] entries;
+ /* private */IFileRevision currentSelection;
+
+ private FileSystemTableProvider fileSystemTableProvider;
+ /* private */TableViewer tableViewer;
+ private Composite localComposite;
+
+ /* private */OpenFileSystemRevisionAction openAction;
+
+ boolean shutdown = false;
+
+ private RefreshFileHistory refreshFileHistoryJob;
+
+ private class RefreshFileHistory extends Job {
+ /* private */FileSystemHistory fileHistory;
+
+ public RefreshFileHistory() {
+ super("Fetching FileSystem revisions..."); //$NON-NLS-1$
+ }
+
+ public void setFileHistory(FileSystemHistory fileHistory) {
+ this.fileHistory = fileHistory;
+ }
+
+ public IStatus run(IProgressMonitor monitor) {
+
+ IStatus status = Status.OK_STATUS;
+
+ if (fileHistory != null && !shutdown) {
+ fileHistory.refresh(monitor);
+ Utils.asyncExec(new Runnable() {
+ public void run() {
+ tableViewer.setInput(fileHistory);
+ }
+ }, tableViewer);
+ }
+
+ return status;
+ }
+ }
+
+ public boolean inputSet() {
+ IFile tempFile = getFile();
+ this.file = tempFile;
+ if (tempFile == null)
+ return false;
+
+ //blank current input only after we're sure that we have a file
+ //to fetch history for
+ this.tableViewer.setInput(null);
+
+ fileSystemHistory = new FileSystemHistory(file);
+
+ refreshHistory();
+ return true;
+ }
+
+ private IWorkbenchPartSite getWorkbenchSite(IHistoryPageSite parentSite) {
+ IWorkbenchPart part = parentSite.getPart();
+ if (part != null)
+ return part.getSite();
+ return null;
+ }
+
+ private IFile getFile() {
+ Object obj = getInput();
+ if (obj instanceof IFile)
+ return (IFile) obj;
+
+ return null;
+ }
+
+ public void createControl(Composite parent) {
+
+ localComposite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ localComposite.setLayout(layout);
+ GridData data = new GridData(GridData.FILL_BOTH);
+ data.grabExcessVerticalSpace = true;
+ localComposite.setLayoutData(data);
+
+ tableViewer = createTable(localComposite);
+
+ contributeActions();
+
+ }
+
+ private void contributeActions() {
+ openAction = new OpenFileSystemRevisionAction("Open"); //$NON-NLS-1$
+ tableViewer.getTable().addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ openAction.selectionChanged((IStructuredSelection) tableViewer.getSelection());
+ }
+ });
+ openAction.setPage(this);
+ //Contribute actions to popup menu
+ MenuManager menuMgr = new MenuManager();
+ Menu menu = menuMgr.createContextMenu(tableViewer.getTable());
+ menuMgr.addMenuListener(new IMenuListener() {
+ public void menuAboutToShow(IMenuManager menuMgr) {
+ menuMgr.add(new Separator(IWorkbenchActionConstants.GROUP_FILE));
+ menuMgr.add(openAction);
+ }
+ });
+ menuMgr.setRemoveAllWhenShown(true);
+ tableViewer.getTable().setMenu(menu);
+ }
+
+ private TableViewer createTable(Composite parent) {
+ fileSystemTableProvider = new FileSystemTableProvider();
+ TableViewer viewer = fileSystemTableProvider.createTable(parent);
+ viewer.setContentProvider(new IStructuredContentProvider() {
+
+ public Object[] getElements(Object inputElement) {
+ // The entries of already been fetch so return them
+ if (entries != null)
+ return entries;
+
+ final IFileHistory fileHistory = (IFileHistory) inputElement;
+ entries = fileHistory.getFileRevisions();
+
+ return entries;
+ }
+
+ public void dispose() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ entries = null;
+ }
+
+ });
+ return viewer;
+ }
+
+ public Control getControl() {
+ return localComposite;
+ }
+
+ public void setFocus() {
+ localComposite.setFocus();
+ }
+
+ public String getDescription() {
+ if (file != null)
+ return file.getFullPath().toString();
+
+ return null;
+ }
+
+ public String getName() {
+ if (file != null)
+ return file.getName();
+
+ return ""; //$NON-NLS-1$
+ }
+
+ public boolean isValidInput(Object object) {
+
+ if (object instanceof IResource && ((IResource) object).getType() == IResource.FILE) {
+ RepositoryProvider provider = RepositoryProvider.getProvider(((IFile) object).getProject());
+ if (provider != null && provider instanceof FileSystemProvider)
+ return true;
+ }
+
+ return false;
+ }
+
+ public void refresh() {
+ refreshHistory();
+ }
+
+ private void refreshHistory() {
+ if (refreshFileHistoryJob == null)
+ refreshFileHistoryJob = new RefreshFileHistory();
+
+ if (refreshFileHistoryJob.getState() != Job.NONE) {
+ refreshFileHistoryJob.cancel();
+ }
+ refreshFileHistoryJob.setFileHistory(fileSystemHistory);
+ IHistoryPageSite parentSite = getHistoryPageSite();
+ Utils.schedule(refreshFileHistoryJob, getWorkbenchSite(parentSite));
+ }
+
+ public Object getAdapter(Class adapter) {
+ return null;
+ }
+
+}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemHistoryPageSource.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemHistoryPageSource.java
new file mode 100644
index 000000000..54b19f5a0
--- /dev/null
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemHistoryPageSource.java
@@ -0,0 +1,27 @@
+package org.eclipse.team.examples.filesystem.ui;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.team.core.RepositoryProvider;
+import org.eclipse.team.examples.filesystem.FileSystemProvider;
+import org.eclipse.team.ui.history.HistoryPageSource;
+import org.eclipse.ui.part.Page;
+
+public class FileSystemHistoryPageSource extends HistoryPageSource {
+
+ public boolean canShowHistoryFor(Object object) {
+ if (object instanceof IResource && ((IResource) object).getType() == IResource.FILE) {
+ RepositoryProvider provider = RepositoryProvider.getProvider(((IFile) object).getProject());
+ if (provider instanceof FileSystemProvider)
+ return true;
+ }
+
+ return false;
+ }
+
+ public Page createPage(Object object) {
+ FileSystemHistoryPage page = new FileSystemHistoryPage();
+ return page;
+ }
+
+}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemRevisionEditorInput.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemRevisionEditorInput.java
new file mode 100644
index 000000000..19b4b716c
--- /dev/null
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemRevisionEditorInput.java
@@ -0,0 +1,97 @@
+package org.eclipse.team.examples.filesystem.ui;
+
+import java.text.DateFormat;
+import java.util.Date;
+
+import org.eclipse.core.resources.IFileState;
+import org.eclipse.core.resources.IStorage;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.team.core.history.IFileRevision;
+import org.eclipse.ui.IPersistableElement;
+import org.eclipse.ui.IStorageEditorInput;
+import org.eclipse.ui.model.IWorkbenchAdapter;
+
+public class FileSystemRevisionEditorInput extends PlatformObject implements IWorkbenchAdapter, IStorageEditorInput {
+
+ private IFileRevision fileRevision;
+ private IStorage storage;
+
+ public FileSystemRevisionEditorInput(IFileRevision revision) {
+ this.fileRevision = revision;
+ try {
+ this.storage = revision.getStorage(new NullProgressMonitor());
+ } catch (CoreException e) {
+ }
+ }
+
+ public Object[] getChildren(Object o) {
+ return new Object[0];
+ }
+
+ public ImageDescriptor getImageDescriptor(Object object) {
+ return null;
+ }
+
+ public String getLabel(Object o) {
+ if (storage != null) {
+ return storage.getName();
+ }
+ return ""; //$NON-NLS-1$
+ }
+
+ public Object getParent(Object o) {
+ return null;
+ }
+
+ public IStorage getStorage() throws CoreException {
+ return storage;
+ }
+
+ public boolean exists() {
+ return true;
+ }
+
+ public ImageDescriptor getImageDescriptor() {
+ return null;
+ }
+
+ public String getName() {
+ if (fileRevision != null)
+ return fileRevision.getName() + " " + fileRevision.getContentIdentifier(); //$NON-NLS-1$
+
+ if (storage != null) {
+ return storage.getName() + " " + DateFormat.getInstance().format(new Date(((IFileState) storage).getModificationTime())); //$NON-NLS-1$
+ }
+ return ""; //$NON-NLS-1$
+ }
+
+ public IPersistableElement getPersistable() {
+ return null;
+ }
+
+ public String getToolTipText() {
+ if (fileRevision != null)
+ try {
+ return getStorage().getFullPath().toString();
+ } catch (CoreException e) {
+ }
+
+ if (storage != null)
+ return storage.getFullPath().toString();
+
+ return ""; //$NON-NLS-1$
+ }
+
+ public Object getAdapter(Class adapter) {
+ if (adapter == IWorkbenchAdapter.class) {
+ return this;
+ }
+ if (adapter == IFileRevision.class)
+ return fileRevision;
+ return super.getAdapter(adapter);
+ }
+
+}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemTableProvider.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemTableProvider.java
new file mode 100644
index 000000000..e9fb5ecd0
--- /dev/null
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/FileSystemTableProvider.java
@@ -0,0 +1,254 @@
+package org.eclipse.team.examples.filesystem.ui;
+
+import java.text.DateFormat;
+import java.util.Date;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.IColorProvider;
+import org.eclipse.jface.viewers.IFontProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TableLayout;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.team.core.history.IFileRevision;
+import org.eclipse.team.examples.filesystem.history.FileSystemFileRevision;
+
+public class FileSystemTableProvider {
+
+ //column constants
+ private static final int COL_TYPE = 0;
+ private static final int COL_DATE = 1;
+
+ public TableViewer createTable(Composite parent) {
+ Table table = new Table(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
+ table.setHeaderVisible(true);
+ table.setLinesVisible(true);
+ GridData data = new GridData(GridData.FILL_BOTH);
+ table.setLayoutData(data);
+
+ TableLayout layout = new TableLayout();
+ table.setLayout(layout);
+
+ TableViewer viewer = new TableViewer(table);
+
+ createColumns(table, layout, viewer);
+
+ viewer.setLabelProvider(new HistoryLabelProvider());
+
+ // By default, reverse sort by revision.
+ HistorySorter sorter = new HistorySorter(COL_DATE);
+ sorter.setReversed(true);
+ viewer.setSorter(sorter);
+
+ return viewer;
+ }
+
+ /**
+ * Creates the columns for the history table.
+ */
+ private void createColumns(Table table, TableLayout layout, TableViewer viewer) {
+ SelectionListener headerListener = getColumnListener(viewer);
+ // revision
+ TableColumn col = new TableColumn(table, SWT.NONE);
+ col.setResizable(true);
+ col.setText("Revision"); //$NON-NLS-1$
+ col.addSelectionListener(headerListener);
+ layout.addColumnData(new ColumnWeightData(20, true));
+
+ // creation date
+ col = new TableColumn(table, SWT.NONE);
+ col.setResizable(true);
+ col.setText("Date"); //$NON-NLS-1$
+ col.addSelectionListener(headerListener);
+ layout.addColumnData(new ColumnWeightData(20, true));
+
+ }
+
+ class HistoryLabelProvider extends LabelProvider implements ITableLabelProvider, IColorProvider, IFontProvider {
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ IFileRevision entry = adaptToFileRevision(element);
+ if (entry == null)
+ return ""; //$NON-NLS-1$
+ switch (columnIndex) {
+ case COL_TYPE :
+ if (entry instanceof FileSystemFileRevision)
+ return "FileSystem revision"; //$NON-NLS-1$
+
+ return "Local history revision"; //$NON-NLS-1$
+ case COL_DATE :
+ long date = entry.getTimestamp();
+ Date dateFromLong = new Date(date);
+ return DateFormat.getInstance().format(dateFromLong);
+ }
+ return ""; //$NON-NLS-1$
+ }
+
+ public Color getBackground(Object element) {
+ return null;
+ }
+
+ public Color getForeground(Object element) {
+ return null;
+ }
+
+ public Font getFont(Object element) {
+ return null;
+ }
+
+ }
+
+ /**
+ * The history sorter
+ */
+ class HistorySorter extends ViewerSorter {
+ private boolean reversed = false;
+ private int columnNumber;
+
+ // column headings: "Type" "Date"
+ private int[][] SORT_ORDERS_BY_COLUMN = { {COL_DATE, COL_TYPE} /* date */, {COL_TYPE, COL_DATE} /* type */
+ };
+
+ /**
+ * The constructor.
+ * @param columnNumber
+ */
+ public HistorySorter(int columnNumber) {
+ this.columnNumber = columnNumber;
+ }
+
+ /**
+ * Compares two log entries, sorting first by the main column of this sorter,
+ * then by subsequent columns, depending on the column sort order.
+ */
+ public int compare(Viewer compareViewer, Object o1, Object o2) {
+ /*if (o1 instanceof AbstractCVSHistoryCategory || o2 instanceof AbstractCVSHistoryCategory)
+ return 0;*/
+
+ IFileRevision e1 = adaptToFileRevision(o1);
+ IFileRevision e2 = adaptToFileRevision(o2);
+ int result = 0;
+ if (e1 == null || e2 == null) {
+ result = super.compare(compareViewer, o1, o2);
+ } else {
+ int[] columnSortOrder = SORT_ORDERS_BY_COLUMN[columnNumber];
+ for (int i = 0; i < columnSortOrder.length; ++i) {
+ result = compareColumnValue(columnSortOrder[i], e1, e2);
+ if (result != 0)
+ break;
+ }
+ }
+ if (reversed)
+ result = -result;
+ return result;
+ }
+
+ /**
+ * Compares two markers, based only on the value of the specified column.
+ */
+ int compareColumnValue(int columnNumber, IFileRevision e1, IFileRevision e2) {
+ switch (columnNumber) {
+ case 0 : /* date */
+ long date1 = e1.getTimestamp();
+ long date2 = e2.getTimestamp();
+ if (date1 == date2)
+ return 0;
+
+ return date1 > date2 ? -1 : 1;
+
+ default :
+ return 0;
+ }
+ }
+
+ /**
+ * Returns the number of the column by which this is sorting.
+ * @return the column number
+ */
+ public int getColumnNumber() {
+ return columnNumber;
+ }
+
+ /**
+ * Returns true for descending, or false
+ * for ascending sorting order.
+ * @return returns true if reversed
+ */
+ public boolean isReversed() {
+ return reversed;
+ }
+
+ /**
+ * Sets the sorting order.
+ * @param newReversed
+ */
+ public void setReversed(boolean newReversed) {
+ reversed = newReversed;
+ }
+ }
+
+ protected IFileRevision adaptToFileRevision(Object element) {
+ // Get the log entry for the provided object
+ IFileRevision entry = null;
+ if (element instanceof IFileRevision) {
+ entry = (IFileRevision) element;
+ } else if (element instanceof IAdaptable) {
+ entry = (IFileRevision) ((IAdaptable) element).getAdapter(IFileRevision.class);
+ }
+ return entry;
+ }
+
+ /**
+ * Adds the listener that sets the sorter.
+ */
+ private SelectionListener getColumnListener(final TableViewer tableViewer) {
+ /**
+ * This class handles selections of the column headers.
+ * Selection of the column header will cause resorting
+ * of the shown tasks using that column's sorter.
+ * Repeated selection of the header will toggle
+ * sorting order (ascending versus descending).
+ */
+ return new SelectionAdapter() {
+ /**
+ * Handles the case of user selecting the
+ * header area.
+ * <p>If the column has not been selected previously,
+ * it will set the sorter of that column to be
+ * the current tasklist sorter. Repeated
+ * presses on the same column header will
+ * toggle sorting order (ascending/descending).
+ */
+ public void widgetSelected(SelectionEvent e) {
+ // column selected - need to sort
+ int column = tableViewer.getTable().indexOf((TableColumn) e.widget);
+ HistorySorter oldSorter = (HistorySorter) tableViewer.getSorter();
+ if (oldSorter != null && column == oldSorter.getColumnNumber()) {
+ oldSorter.setReversed(!oldSorter.isReversed());
+ tableViewer.refresh();
+ } else {
+ tableViewer.setSorter(new HistorySorter(column));
+ }
+ }
+ };
+ }
+
+}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/OpenFileSystemRevisionAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/OpenFileSystemRevisionAction.java
new file mode 100644
index 000000000..c16e665fa
--- /dev/null
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/OpenFileSystemRevisionAction.java
@@ -0,0 +1,158 @@
+package org.eclipse.team.examples.filesystem.ui;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IStorage;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.team.core.history.IFileRevision;
+import org.eclipse.team.examples.filesystem.FileSystemPlugin;
+import org.eclipse.team.internal.ui.history.AbstractHistoryCategory;
+import org.eclipse.team.internal.ui.history.FileRevisionEditorInput;
+import org.eclipse.team.ui.history.HistoryPage;
+import org.eclipse.ui.IEditorDescriptor;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IEditorRegistry;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.BaseSelectionListenerAction;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.progress.IProgressService;
+
+public class OpenFileSystemRevisionAction extends BaseSelectionListenerAction {
+
+ private IStructuredSelection selection;
+ private HistoryPage page;
+
+ public OpenFileSystemRevisionAction(String text) {
+ super(text);
+ }
+
+ public void run() {
+ IStructuredSelection structSel = selection;
+
+ Object[] objArray = structSel.toArray();
+
+ for (int i = 0; i < objArray.length; i++) {
+ Object tempRevision = objArray[i];
+
+ final IFileRevision revision = (IFileRevision) tempRevision;
+ if (revision == null || !revision.exists()) {
+ MessageDialog.openError(page.getSite().getShell(), "Deleted Revision", "Can't open a deleted revision");
+ } else {
+ IRunnableWithProgress runnable = new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ IStorage file;
+ try {
+ file = revision.getStorage(monitor);
+ String id = getEditorID(file.getName(), file.getContents());
+
+ if (file instanceof IFile) {
+ //if this is the current workspace file, open it
+ IDE.openEditor(page.getSite().getPage(), (IFile) file);
+ } else {
+ FileSystemRevisionEditorInput fileRevEditorInput = new FileSystemRevisionEditorInput(revision);
+ if (!editorAlreadyOpenOnContents(fileRevEditorInput))
+ page.getSite().getPage().openEditor(fileRevEditorInput, id);
+ }
+ } catch (CoreException e) {
+ throw new InvocationTargetException(e);
+ }
+
+ }
+ };
+
+ IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
+ try {
+ progressService.run(false, false, runnable);
+ } catch (InvocationTargetException e) {
+ } catch (InterruptedException e) {
+ }
+ }
+
+ }
+ }
+
+ /* private */String getEditorID(String fileName, InputStream contents) {
+ IWorkbench workbench = FileSystemPlugin.getPlugin().getWorkbench();
+ IEditorRegistry registry = workbench.getEditorRegistry();
+ IContentType type = null;
+ if (contents != null) {
+ try {
+ type = Platform.getContentTypeManager().findContentTypeFor(contents, fileName);
+ } catch (IOException e) {
+
+ }
+ }
+ if (type == null) {
+ type = Platform.getContentTypeManager().findContentTypeFor(fileName);
+ }
+ IEditorDescriptor descriptor = registry.getDefaultEditor(fileName, type);
+ String id;
+ if (descriptor == null || descriptor.isOpenExternal()) {
+ id = "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$
+ } else {
+ id = descriptor.getId();
+ }
+
+ return id;
+ }
+
+ protected boolean updateSelection(IStructuredSelection selection) {
+ this.selection = selection;
+ return shouldShow();
+ }
+
+ public void setPage(HistoryPage page) {
+ this.page = page;
+ }
+
+ private boolean shouldShow() {
+ IStructuredSelection structSel = selection;
+ Object[] objArray = structSel.toArray();
+
+ if (objArray.length == 0)
+ return false;
+
+ for (int i = 0; i < objArray.length; i++) {
+ //Don't bother showing if this a category
+ if (objArray[i] instanceof AbstractHistoryCategory)
+ return false;
+
+ IFileRevision revision = (IFileRevision) objArray[i];
+ //check to see if any of the selected revisions are deleted revisions
+ if (revision != null && !revision.exists())
+ return false;
+ }
+
+ return true;
+ }
+
+ private boolean editorAlreadyOpenOnContents(FileSystemRevisionEditorInput input) {
+ IEditorReference[] editorRefs = page.getSite().getPage().getEditorReferences();
+ for (int i = 0; i < editorRefs.length; i++) {
+ IEditorPart part = editorRefs[i].getEditor(false);
+ if (part != null && part.getEditorInput() instanceof FileRevisionEditorInput) {
+ IFileRevision inputRevision = (IFileRevision) input.getAdapter(IFileRevision.class);
+ IFileRevision editorRevision = (IFileRevision) part.getEditorInput().getAdapter(IFileRevision.class);
+
+ if (inputRevision.equals(editorRevision)) {
+ //make the editor that already contains the revision current
+ page.getSite().getPage().activate(part);
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/ShowHistoryAction.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/ShowHistoryAction.java
new file mode 100644
index 000000000..87045f20b
--- /dev/null
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/ui/ShowHistoryAction.java
@@ -0,0 +1,68 @@
+package org.eclipse.team.examples.filesystem.ui;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.team.internal.ui.TeamUIMessages;
+import org.eclipse.team.internal.ui.TeamUIPlugin;
+import org.eclipse.team.internal.ui.history.GenericHistoryView;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.actions.ActionDelegate;
+
+public class ShowHistoryAction extends ActionDelegate implements IObjectActionDelegate {
+
+ private IStructuredSelection fSelection;
+ private IWorkbenchPart targetPart;
+
+ public void run(IAction action) {
+ final Shell shell = Display.getDefault().getActiveShell();
+ try {
+ new ProgressMonitorDialog(shell).run(true, true, new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ final IResource resource = (IResource) fSelection.getFirstElement();
+ Runnable r = new Runnable() {
+ public void run() {
+ try {
+ IViewPart view = targetPart.getSite().getPage().showView("org.eclipse.team.ui.GenericHistoryView"); //$NON-NLS-1$
+ if (view instanceof GenericHistoryView) {
+ GenericHistoryView historyView = (GenericHistoryView) view;
+ historyView.itemDropped(resource, true);
+ }
+ } catch (PartInitException e) {
+ }
+ }
+ };
+
+ TeamUIPlugin.getStandardDisplay().asyncExec(r);
+ }
+ });
+ } catch (InvocationTargetException exception) {
+ ErrorDialog.openError(shell, null, null, new Status(IStatus.ERROR, TeamUIPlugin.PLUGIN_ID, IStatus.ERROR, TeamUIMessages.ShowLocalHistory_1, exception.getTargetException()));
+ } catch (InterruptedException exception) {
+ }
+ }
+
+ public void selectionChanged(IAction action, ISelection sel) {
+ if (sel instanceof IStructuredSelection) {
+ fSelection = (IStructuredSelection) sel;
+ }
+ }
+
+ public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+ this.targetPart = targetPart;
+ }
+}
diff --git a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/AdapterFactory.java b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/AdapterFactory.java
index 814e6cdac..ce0ce565c 100644
--- a/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/AdapterFactory.java
+++ b/examples/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/model/ui/AdapterFactory.java
@@ -13,9 +13,13 @@ package org.eclipse.team.examples.model.ui;
import org.eclipse.core.resources.mapping.ResourceMapping;
import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.team.core.mapping.IResourceMappingMerger;
+import org.eclipse.team.examples.filesystem.ui.FileSystemHistoryPageSource;
import org.eclipse.team.examples.model.ModelObject;
-import org.eclipse.team.examples.model.mapping.*;
+import org.eclipse.team.examples.model.mapping.ExampleModelProvider;
+import org.eclipse.team.examples.model.mapping.ModelMerger;
+import org.eclipse.team.examples.model.mapping.ModelResourceMapping;
import org.eclipse.team.examples.model.ui.mapping.CompareAdapter;
+import org.eclipse.team.ui.history.IHistoryPageSource;
import org.eclipse.team.ui.mapping.ISynchronizationCompareAdapter;
import org.eclipse.ui.model.IWorkbenchAdapter;
@@ -24,6 +28,7 @@ public class AdapterFactory implements IAdapterFactory {
private IWorkbenchAdapter modelAdapter = new ModelWorkbenchAdapter();
private ModelMerger modelMerger;
private CompareAdapter compareAdapter;
+ private static Object historyPageSource = new FileSystemHistoryPageSource();
public Object getAdapter(Object adaptableObject, Class adapterType) {
if (adapterType == IWorkbenchAdapter.class && adaptableObject instanceof ModelObject)
@@ -42,6 +47,11 @@ public class AdapterFactory implements IAdapterFactory {
}
return compareAdapter;
}
+
+ if (adapterType == IHistoryPageSource.class){
+ return historyPageSource;
+ }
+
return null;
}

Back to the top