|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2004 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Common Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/cpl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.compare.internal; |
| 12 |
|
| 13 |
import java.util.List; |
| 14 |
import java.util.Set; |
| 15 |
|
| 16 |
import org.eclipse.core.resources.Checkpoint; |
| 17 |
import org.eclipse.core.resources.CheckpointBridge; |
| 18 |
import org.eclipse.jface.action.IAction; |
| 19 |
import org.eclipse.jface.viewers.ILabelProvider; |
| 20 |
import org.eclipse.jface.viewers.ILabelProviderListener; |
| 21 |
import org.eclipse.jface.viewers.ISelection; |
| 22 |
import org.eclipse.jface.viewers.IStructuredContentProvider; |
| 23 |
import org.eclipse.jface.viewers.Viewer; |
| 24 |
import org.eclipse.swt.graphics.Image; |
| 25 |
import org.eclipse.ui.IWorkbenchPart; |
| 26 |
import org.eclipse.ui.IWorkbenchWindow; |
| 27 |
import org.eclipse.ui.IWorkbenchWindowActionDelegate; |
| 28 |
import org.eclipse.ui.dialogs.ListDialog; |
| 29 |
|
| 30 |
|
| 31 |
/* |
| 32 |
* The "Rollback to Checkpoint" action |
| 33 |
*/ |
| 34 |
public class ShowCheckpointsAction implements IWorkbenchWindowActionDelegate, IStructuredContentProvider, ILabelProvider { |
| 35 |
|
| 36 |
private ISelection fSelection; |
| 37 |
private List fCheckpoints; |
| 38 |
private RollbackDialog dialog = null; |
| 39 |
|
| 40 |
private class RollbackDialog extends ListDialog { |
| 41 |
public RollbackDialog() { |
| 42 |
super(CompareUIPlugin.getShell()); |
| 43 |
} |
| 44 |
public void okPressed() { |
| 45 |
super.okPressed(); |
| 46 |
Object[] results = dialog.getResult(); |
| 47 |
if (results.length > 0) { |
| 48 |
Checkpoint cp = (Checkpoint)results[0]; |
| 49 |
Set[] states = CheckpointBridge.getRestoreAndDeleteFallbackStates(cp.getLastModified()); |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
public void run(ISelection selection) { |
| 55 |
fCheckpoints = CheckpointBridge.getCheckpoints(); |
| 56 |
dialog = new RollbackDialog(); |
| 57 |
dialog.setTitle("Show Checkpoint"); |
| 58 |
dialog.setContentProvider(this); |
| 59 |
dialog.setLabelProvider(this); |
| 60 |
dialog.setInput(fCheckpoints); |
| 61 |
dialog.setAddCancelButton(true); |
| 62 |
dialog.setMessage("Select Checkpoint"); |
| 63 |
dialog.open(); |
| 64 |
} |
| 65 |
|
| 66 |
/* (non-Javadoc) |
| 67 |
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) |
| 68 |
*/ |
| 69 |
final public void run(IAction action) { |
| 70 |
run(fSelection); |
| 71 |
} |
| 72 |
|
| 73 |
/* (non-Javadoc) |
| 74 |
* @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) |
| 75 |
*/ |
| 76 |
final public void selectionChanged(IAction action, ISelection selection) { |
| 77 |
if (action != null) |
| 78 |
action.setEnabled(true); |
| 79 |
} |
| 80 |
|
| 81 |
protected boolean isEnabled(ISelection selection) { |
| 82 |
return true; |
| 83 |
} |
| 84 |
|
| 85 |
public void setActivePart(IAction action, IWorkbenchPart targetPart) { |
| 86 |
} |
| 87 |
|
| 88 |
// IStructuredContentProvider Interface |
| 89 |
|
| 90 |
/* (non-Javadoc) |
| 91 |
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) |
| 92 |
*/ |
| 93 |
public Object[] getElements(Object inputElement) { |
| 94 |
return fCheckpoints.toArray(); |
| 95 |
} |
| 96 |
|
| 97 |
/* (non-Javadoc) |
| 98 |
* @see org.eclipse.jface.viewers.IContentProvider#dispose() |
| 99 |
*/ |
| 100 |
public void dispose() { |
| 101 |
} |
| 102 |
|
| 103 |
/* (non-Javadoc) |
| 104 |
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) |
| 105 |
*/ |
| 106 |
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
| 107 |
} |
| 108 |
|
| 109 |
/* (non-Javadoc) |
| 110 |
* @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object) |
| 111 |
*/ |
| 112 |
public Image getImage(Object element) { |
| 113 |
return null; |
| 114 |
} |
| 115 |
|
| 116 |
/* (non-Javadoc) |
| 117 |
* @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object) |
| 118 |
*/ |
| 119 |
public String getText(Object element) { |
| 120 |
Checkpoint cp = (Checkpoint) element; |
| 121 |
//Date date = new Date(cp.getLastModified()); |
| 122 |
//String dateString = date.toString(); |
| 123 |
//String label = dateString.equals(cp.getLabel()) ? "" : " -- " + cp.getLabel(); |
| 124 |
//return dateString + label; |
| 125 |
return cp.getLabel(); |
| 126 |
} |
| 127 |
|
| 128 |
/* (non-Javadoc) |
| 129 |
* @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener) |
| 130 |
*/ |
| 131 |
public void addListener(ILabelProviderListener listener) { |
| 132 |
|
| 133 |
} |
| 134 |
|
| 135 |
/* (non-Javadoc) |
| 136 |
* @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String) |
| 137 |
*/ |
| 138 |
public boolean isLabelProperty(Object element, String property) { |
| 139 |
return false; |
| 140 |
} |
| 141 |
|
| 142 |
/* (non-Javadoc) |
| 143 |
* @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener) |
| 144 |
*/ |
| 145 |
public void removeListener(ILabelProviderListener listener) { |
| 146 |
|
| 147 |
} |
| 148 |
|
| 149 |
/* (non-Javadoc) |
| 150 |
* @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow) |
| 151 |
*/ |
| 152 |
public void init(IWorkbenchWindow window) { |
| 153 |
// TODO Auto-generated method stub |
| 154 |
|
| 155 |
} |
| 156 |
} |