Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 10586 Details for
Bug 9109
[CVS UI] replace with needs to support multiselect
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
This patch adds multiselect to the "replace from local history" action
9109_org.eclipse.compare_patch.txt (text/plain), 13.18 KB, created by
Stefan Xenos
on 2004-05-13 02:05:36 EDT
(
hide
)
Description:
This patch adds multiselect to the "replace from local history" action
Filename:
MIME Type:
Creator:
Stefan Xenos
Created:
2004-05-13 02:05:36 EDT
Size:
13.18 KB
patch
obsolete
>Index: plugin.xml >=================================================================== >RCS file: /home/eclipse/org.eclipse.compare/plugin.xml,v >retrieving revision 1.47 >diff -u -r1.47 plugin.xml >--- plugin.xml 20 Apr 2004 09:23:45 -0000 1.47 >+++ plugin.xml 13 May 2004 05:23:56 -0000 >@@ -255,14 +255,16 @@ > name="replaceWithGroup"> > </separator> > </menu> >+ <!-- > <action >+ enablesFor="+" > label="%ReplaceFromHistoryAction.label" >- tooltip="%ReplaceFromHistoryAction.tooltip" > class="org.eclipse.compare.internal.ReplaceWithEditionAction" >+ tooltip="%ReplaceFromHistoryAction.tooltip" > menubarPath="replaceWithMenu/replaceWithGroup" >- enablesFor="1" > id="replaceFromHistory"> > </action> >+ --> > <action > label="%ReplaceWithPreviousFromHistoryAction.label" > tooltip="%ReplaceWithPreviousFromHistoryAction.tooltip" >@@ -271,6 +273,20 @@ > enablesFor="1" > id="replaceWithPreviousFromHistory"> > </action> >+ </objectContribution> >+ <objectContribution >+ objectClass="org.eclipse.core.resources.IResource" >+ adaptable="true" >+ id="org.eclipse.compare.ReplaceWithEditionAction2"> >+ <action >+ enablesFor="+" >+ label="%ReplaceFromHistoryAction.label" >+ class="org.eclipse.compare.internal.ReplaceWithEditionAction" >+ tooltip="%ReplaceFromHistoryAction.tooltip" >+ menubarPath="replaceWithMenu/replaceWithGroup" >+ id="replaceFromHistory"> >+ </action> >+ > </objectContribution> > <objectContribution > objectClass="org.eclipse.core.resources.IFile" >Index: compare/org/eclipse/compare/internal/EditionAction.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.compare/compare/org/eclipse/compare/internal/EditionAction.java,v >retrieving revision 1.19 >diff -u -r1.19 EditionAction.java >--- compare/org/eclipse/compare/internal/EditionAction.java 10 Feb 2004 09:55:33 -0000 1.19 >+++ compare/org/eclipse/compare/internal/EditionAction.java 13 May 2004 05:23:57 -0000 >@@ -85,6 +85,10 @@ > fBundleName= bundleName; > } > >+ protected String getBundleName() { >+ return fBundleName; >+ } >+ > protected boolean isEnabled(ISelection selection) { > return Utilities.getFiles(selection).length == 1; // we don't support multiple selection for now > } >Index: compare/org/eclipse/compare/internal/ListDialog.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.compare/compare/org/eclipse/compare/internal/ListDialog.java,v >retrieving revision 1.5 >diff -u -r1.5 ListDialog.java >--- compare/org/eclipse/compare/internal/ListDialog.java 18 Mar 2003 19:47:43 -0000 1.5 >+++ compare/org/eclipse/compare/internal/ListDialog.java 13 May 2004 05:23:57 -0000 >@@ -32,6 +32,14 @@ > fAddCancelButton= false; > } > >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.dialogs.Dialog#okPressed() >+ */ >+ protected void okPressed() { >+ setResult(((IStructuredSelection)fTableViewer.getSelection()).toList()); >+ >+ super.okPressed(); >+ } > public void setInput(Object input) { > fInput= input; > } >Index: compare/org/eclipse/compare/internal/ReplaceWithEditionAction.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.compare/compare/org/eclipse/compare/internal/ReplaceWithEditionAction.java,v >retrieving revision 1.10 >diff -u -r1.10 ReplaceWithEditionAction.java >--- compare/org/eclipse/compare/internal/ReplaceWithEditionAction.java 10 Mar 2003 21:25:35 -0000 1.10 >+++ compare/org/eclipse/compare/internal/ReplaceWithEditionAction.java 13 May 2004 05:23:57 -0000 >@@ -10,11 +10,268 @@ > *******************************************************************************/ > package org.eclipse.compare.internal; > >+import java.text.DateFormat; >+import java.text.MessageFormat; >+import java.util.ArrayList; >+import java.util.Arrays; >+import java.util.Comparator; >+import java.util.Date; >+import java.util.HashSet; >+import java.util.List; >+import java.util.ResourceBundle; >+import java.util.Set; >+ >+import org.eclipse.core.resources.IContainer; >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IFileState; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.resources.IWorkspace; >+import org.eclipse.core.resources.IWorkspaceRoot; >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.resources.WorkspaceJob; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Status; >+import org.eclipse.core.runtime.SubProgressMonitor; >+import org.eclipse.jface.dialogs.MessageDialog; >+import org.eclipse.jface.viewers.ISelection; >+import org.eclipse.jface.viewers.LabelProvider; >+import org.eclipse.swt.widgets.Shell; >+ > > public class ReplaceWithEditionAction extends EditionAction { >+ >+ private static class FileStateWrapper { >+ >+ long timestamp; >+ IFile file; > >+ public FileStateWrapper(IFile file, long timestamp) { >+ this.file = file; >+ this.timestamp = timestamp; >+ } >+ } >+ > public ReplaceWithEditionAction() { > super(true, "org.eclipse.compare.internal.ReplaceWithEditionAction"); //$NON-NLS-1$ > fHelpContextId= ICompareContextIds.REPLACE_WITH_EDITION_DIALOG; >+ } >+ >+ protected boolean isEnabled(ISelection selection) { >+ return true; >+ } >+ >+ protected void run(ISelection selection) { >+ final ResourceBundle bundle= ResourceBundle.getBundle(getBundleName()); >+ >+ Shell shell = CompareUIPlugin.getShell(); >+ >+ try { >+ >+ // Determine what files are directly or indirectly in the current selection >+ IFile[] selectedFiles = getFilesRecursive(selection); >+ >+ if (selectedFiles.length == 1) { >+ super.run(selection); >+ return; >+ } >+ >+ // Collect every known timestamp at which any file in the selection was modified. >+ // Include the current timestamp plus everything in the resource history. >+ // Sort them in chronological order with the most recent changes first >+ List fileStates = getAllFileStates(selectedFiles); >+ >+ Object[] states = fileStates.toArray(); >+ Comparator comparator = new Comparator() { >+ >+ public int compare(Object arg0, Object arg1) { >+ FileStateWrapper state0 = (FileStateWrapper)arg0; >+ FileStateWrapper state1 = (FileStateWrapper)arg1; >+ >+ long t0 = state0.timestamp; >+ long t1 = state1.timestamp; >+ return t0 > t1 ? -1 : t0 == t1 ? 0 : 1; >+ } >+ }; >+ >+ Arrays.sort(states, comparator); >+ >+ fileStates = Arrays.asList(states); >+ >+ // Create a dialog to let the user pick where they want to roll back to >+ ListDialog listDialog = new ListDialog(shell); >+ >+ listDialog.setContentProvider(new ListContentProvider()); >+ listDialog.setInput(fileStates); >+ listDialog.setLabelProvider(new LabelProvider() { >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object) >+ */ >+ public String getText(Object element) { >+ FileStateWrapper state = ((FileStateWrapper)element); >+ String date = DateFormat.getDateTimeInstance().format(new Date(state.timestamp)); >+ >+ return MessageFormat.format( bundle.getString("historyFormat"), new String[]{date, state.file.getName()}); >+ } >+ >+ }); >+ >+ listDialog.setTitle(bundle.getString("selectEarliest")); >+ >+ listDialog.setAddCancelButton(true); >+ listDialog.open(); >+ >+ Object[] selections = listDialog.getResult(); >+ >+ // Just exit if the user cancelled or didn't pick anything >+ if (selections != null && selections.length == 1) { >+ final FileStateWrapper earliestChange = (FileStateWrapper)selections[0]; >+ >+ IWorkspace workspace = ResourcesPlugin.getWorkspace(); >+ final IWorkspaceRoot root = workspace.getRoot(); >+ >+ final List finalFileStates = fileStates; >+ final Object[] finalStates = states; >+ >+ final String restoringFromHistoryName = bundle.getString("restoringFromHistory"); >+ >+ WorkspaceJob workspaceJob = new WorkspaceJob(restoringFromHistoryName) { >+ public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { >+ monitor.beginTask(restoringFromHistoryName, finalStates.length * 100); >+ >+ Set alreadyProcessed = new HashSet(); >+ >+ for (int idx = finalFileStates.indexOf(earliestChange); idx >= 0; idx--) { >+ FileStateWrapper next = (FileStateWrapper)finalStates[idx]; >+ IPath path = next.file.getFullPath(); >+ >+ if (!alreadyProcessed.contains(path)) { >+ IFile file = next.file; >+ >+ SubProgressMonitor subMon = new SubProgressMonitor(monitor, 100); >+ >+ rollback(file, earliestChange.timestamp, subMon); >+ >+ alreadyProcessed.add(path); >+ } else { >+ monitor.worked(100); >+ } >+ } >+ >+ monitor.done(); >+ >+ return Status.OK_STATUS; >+ } >+ >+ }; >+ >+ workspaceJob.setRule(root); >+ workspaceJob.setUser(true); >+ workspaceJob.schedule(); >+ }; >+ >+ } catch (CoreException e) { >+ MessageDialog.openError(shell, bundle.getString("error"), e.toString()); >+ } >+ } >+ >+ /** >+ * Rolls back the given file to the given time (if possible). >+ * >+ * @param file >+ * @param timestamp >+ * @param mon >+ * @throws CoreException >+ */ >+ public static void rollback(IFile file, long timestamp, IProgressMonitor mon) throws CoreException { >+ if (file.getLocalTimeStamp() >= timestamp) { >+ >+ IFileState[] states = file.getHistory(null); >+ >+ IFileState mostRecent = null; >+ long mostRecentTimestamp = 0; >+ >+ for (int stateIdx = 0; stateIdx < states.length; stateIdx++) { >+ IFileState state = states[stateIdx]; >+ >+ if (state.exists()) { >+ long modTime = state.getModificationTime(); >+ if (modTime > mostRecentTimestamp && modTime < timestamp) { >+ mostRecent = state; >+ mostRecentTimestamp = modTime; >+ } >+ } >+ } >+ >+ if (mostRecent != null) { >+ file.setContents(mostRecent, true, true, mon); >+ } >+ >+ } >+ } >+ >+ /** >+ * >+ * >+ * @param files >+ * @return a List of FileStateWrappers representing all known times when the files in the given >+ * list were modified. This includes the current file timestamp plus everything found in the >+ * resource history. >+ */ >+ protected static List getAllFileStates(IFile[] files) throws CoreException { >+ List result = new ArrayList(files.length); >+ >+ for (int idx = 0; idx < files.length; idx++) { >+ IFile file = files[idx]; >+ if (!file.isAccessible()) { >+ continue; >+ } >+ >+ result.add(new FileStateWrapper(file, file.getLocalTimeStamp())); >+ >+ IFileState[] states = files[idx].getHistory(null); >+ for (int stateIdx = 0; stateIdx < states.length; stateIdx++) { >+ IFileState state = states[stateIdx]; >+ >+ if (state.exists()) { >+ result.add(new FileStateWrapper(file, state.getModificationTime())); >+ } >+ } >+ } >+ >+ return result; >+ } >+ >+ protected static IFile[] getFilesRecursive(ISelection selection) throws CoreException { >+ List result = getFilesRecursive(Utilities.getResources(selection)); >+ return (IFile[]) result.toArray(new IFile[result.size()]); >+ } >+ >+ private static List getFilesRecursive(IResource[] input) throws CoreException { >+ List result = new ArrayList(input.length); >+ >+ for (int idx = 0; idx < input.length; idx++) { >+ >+ IResource resource = input[idx]; >+ >+ if (!resource.isAccessible()) { >+ continue; >+ } >+ >+ if (resource instanceof IContainer) { >+ IContainer container = (IContainer)resource; >+ >+ result.addAll(getFilesRecursive(container.members())); >+ } >+ >+ if (resource instanceof IFile) { >+ result.add(resource); >+ } >+ } >+ >+ return result; > } > } >Index: compare/org/eclipse/compare/internal/ReplaceWithEditionAction.properties >=================================================================== >RCS file: /home/eclipse/org.eclipse.compare/compare/org/eclipse/compare/internal/ReplaceWithEditionAction.properties,v >retrieving revision 1.22 >diff -u -r1.22 ReplaceWithEditionAction.properties >--- compare/org/eclipse/compare/internal/ReplaceWithEditionAction.properties 28 Apr 2004 10:47:12 -0000 1.22 >+++ compare/org/eclipse/compare/internal/ReplaceWithEditionAction.properties 13 May 2004 05:23:57 -0000 >@@ -37,4 +37,10 @@ > noLocalHistoryError= No local history available for selected resource. > replaceError=Cannot replace resource (reason: {0}). > >-taskName=Replacing >\ No newline at end of file >+taskName=Replacing >+ >+ >+historyFormat={0} : {1} >+selectEarliest=Select earliest change to undo >+restoringFromHistory=Restoring from history >+error=Error
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 9109
: 10586