Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ReplaceWithEditionAction.java')
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ReplaceWithEditionAction.java90
1 files changed, 90 insertions, 0 deletions
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ReplaceWithEditionAction.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ReplaceWithEditionAction.java
new file mode 100644
index 000000000..e62dee7c4
--- /dev/null
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ReplaceWithEditionAction.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed Materials - Property of IBM,
+ * WebSphere Studio Workbench
+ * (c) Copyright IBM Corp 2001
+ */
+package org.eclipse.compare.internal;
+
+import java.io.InputStream;
+import java.util.ResourceBundle;
+
+import org.eclipse.swt.widgets.Shell;
+
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+
+import org.eclipse.core.resources.*;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.ui.IActionDelegate;
+import org.eclipse.compare.*;
+
+
+public class ReplaceWithEditionAction implements IActionDelegate {
+
+ private static final String ACTION_LABEL= "Replace with Edition";
+ private ISelection fSelection;
+
+
+ public void run(IAction action) {
+
+ Object[] s= Utilities.toArray(fSelection);
+
+ for (int i= 0; i < s.length; i++) {
+ Object o= s[i];
+ if (o instanceof IFile) {
+ replaceFromHistory((IFile)o);
+ continue;
+ }
+ if (o instanceof IAdaptable) {
+ IAdaptable a= (IAdaptable) o;
+ Object adapter= a.getAdapter(IResource.class);
+ if (adapter instanceof IFile)
+ replaceFromHistory((IFile)adapter);
+ continue;
+ }
+ }
+ }
+
+ public void selectionChanged(IAction a, ISelection s) {
+ fSelection= s;
+ }
+
+ void replaceFromHistory(IFile file) {
+
+ Shell parent= CompareUIPlugin.getShell();
+
+ IFileState states[]= null;
+ try {
+ states= file.getHistory(null);
+ } catch (CoreException ex) {
+ MessageDialog.openError(parent, ACTION_LABEL, ex.getMessage());
+ return;
+ }
+
+ if (states != null && states.length > 0) {
+
+ ITypedElement base= new ResourceNode(file);
+
+ ITypedElement[] editions= new ITypedElement[states.length];
+ for (int i= 0; i < states.length; i++)
+ editions[i]= new HistoryItem(base, states[i]);
+
+ ResourceBundle bundle= ResourceBundle.getBundle("org.eclipse.compare.internal.ReplaceWithEditionAction");
+ EditionSelectionDialog d= new EditionSelectionDialog(parent, bundle);
+
+ ITypedElement ti= d.selectEdition(base, editions, null);
+ if (ti instanceof IStreamContentAccessor) {
+ try {
+ InputStream is= ((IStreamContentAccessor)ti).getContents();
+ file.setContents(is, false, true, null);
+ } catch (CoreException ex) {
+ MessageDialog.openError(parent, ACTION_LABEL, ex.getMessage());
+ }
+ }
+ } else
+ MessageDialog.openInformation(parent, ACTION_LABEL, "No local editions available for selected resource.");
+ }
+}
+

Back to the top