Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean Michel-Lemieux2003-10-15 18:26:39 +0000
committerJean Michel-Lemieux2003-10-15 18:26:39 +0000
commitc68655c12f6b3508a7dcd08ab77d39179a70b1b4 (patch)
treee4b562fded2606a45c25406d79ee5893e84a3095
parentee2ae506fcecf711e08f887d451159dbd4e26958 (diff)
downloadeclipse.platform.team-c68655c12f6b3508a7dcd08ab77d39179a70b1b4.tar.gz
eclipse.platform.team-c68655c12f6b3508a7dcd08ab77d39179a70b1b4.tar.xz
eclipse.platform.team-c68655c12f6b3508a7dcd08ab77d39179a70b1b4.zip
*** empty log message ***
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java1
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/TeamUIPlugin.java22
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/pages/SubscriberSynchronizeViewPage.java200
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/SubscriberPage.java11
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/actions/OpenInCompareAction.java201
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/actions/OpenWithActionGroup.java104
6 files changed, 439 insertions, 100 deletions
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java
index c39d4a31a..6e6f099c7 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java
@@ -48,7 +48,6 @@ import org.eclipse.team.internal.ccvs.ui.repo.RepositoryManager;
import org.eclipse.team.internal.ccvs.ui.repo.RepositoryRoot;
import org.eclipse.team.internal.ui.TeamUIPlugin;
import org.eclipse.team.internal.ui.Utils;
-import org.eclipse.team.internal.ui.sync.pages.SubscriberSynchronizeViewPage;
import org.eclipse.team.ui.TeamUI;
import org.eclipse.team.ui.sync.ISynchronizeViewPage;
import org.eclipse.team.ui.sync.SubscriberPage;
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/TeamUIPlugin.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/TeamUIPlugin.java
index da33f7341..5deb4e0e3 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/TeamUIPlugin.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/TeamUIPlugin.java
@@ -11,6 +11,7 @@
package org.eclipse.team.internal.ui;
+import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
@@ -18,7 +19,13 @@ import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
-import org.eclipse.core.runtime.*;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IPluginDescriptor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.util.IPropertyChangeListener;
@@ -33,6 +40,7 @@ import org.eclipse.team.ui.ISharedImages;
import org.eclipse.team.ui.sync.ISynchronizeView;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.plugin.AbstractUIPlugin;
/**
@@ -383,6 +391,16 @@ public class TeamUIPlugin extends AbstractUIPlugin implements IPropertyChangeLis
return display;
}
+ public static void run(IRunnableWithProgress runnable) {
+ try {
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().run(true, true, runnable);
+ } catch (InvocationTargetException e) {
+ Utils.handleError(getStandardDisplay().getActiveShell(), e, null, null);
+ } catch (InterruptedException e2) {
+ // Nothing to be done
+ }
+ }
+
public void propertyChange(PropertyChangeEvent event) {
// update the background sync delay
if(event.getProperty().equals(IPreferenceIds.SYNCVIEW_DELAY)) {
@@ -406,4 +424,4 @@ public class TeamUIPlugin extends AbstractUIPlugin implements IPropertyChangeLis
}
}
}
-}
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/pages/SubscriberSynchronizeViewPage.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/pages/SubscriberSynchronizeViewPage.java
index d3b218180..c7f97b2c8 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/pages/SubscriberSynchronizeViewPage.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/pages/SubscriberSynchronizeViewPage.java
@@ -1,22 +1,39 @@
package org.eclipse.team.internal.ui.sync.pages;
-import java.lang.reflect.InvocationTargetException;
-
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.jface.operation.IRunnableWithProgress;
+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.preference.IPreferenceStore;
-import org.eclipse.jface.viewers.*;
+import org.eclipse.jface.viewers.AbstractTreeViewer;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.IOpenListener;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.OpenEvent;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.jface.viewers.TableLayout;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.*;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.core.subscribers.TeamSubscriber;
-import org.eclipse.team.internal.core.Assert;
import org.eclipse.team.internal.ui.IPreferenceIds;
import org.eclipse.team.internal.ui.Policy;
import org.eclipse.team.internal.ui.TeamUIPlugin;
@@ -27,10 +44,29 @@ import org.eclipse.team.internal.ui.jobs.RefreshSubscriberInputJob;
import org.eclipse.team.internal.ui.sync.sets.ISyncSetChangedListener;
import org.eclipse.team.internal.ui.sync.sets.SubscriberInput;
import org.eclipse.team.internal.ui.sync.sets.SyncSetChangedEvent;
-import org.eclipse.team.internal.ui.sync.views.*;
+import org.eclipse.team.internal.ui.sync.views.INavigableControl;
+import org.eclipse.team.internal.ui.sync.views.StatisticsPanel;
+import org.eclipse.team.internal.ui.sync.views.SyncSetContentProvider;
+import org.eclipse.team.internal.ui.sync.views.SyncSetTableContentProvider;
+import org.eclipse.team.internal.ui.sync.views.SyncTableViewer;
+import org.eclipse.team.internal.ui.sync.views.SyncTreeViewer;
+import org.eclipse.team.internal.ui.sync.views.SyncViewerLabelProvider;
+import org.eclipse.team.internal.ui.sync.views.SyncViewerSorter;
+import org.eclipse.team.internal.ui.sync.views.SyncViewerTableSorter;
+import org.eclipse.team.internal.ui.sync.views.SynchronizeView;
+import org.eclipse.team.internal.ui.sync.views.ViewStatusInformation;
import org.eclipse.team.ui.sync.INewSynchronizeView;
-import org.eclipse.team.ui.sync.actions.*;
-import org.eclipse.ui.*;
+import org.eclipse.team.ui.sync.actions.AndSyncInfoFilter;
+import org.eclipse.team.ui.sync.actions.OpenWithActionGroup;
+import org.eclipse.team.ui.sync.actions.PseudoConflictFilter;
+import org.eclipse.team.ui.sync.actions.SubscriberAction;
+import org.eclipse.team.ui.sync.actions.SyncInfoChangeTypeFilter;
+import org.eclipse.team.ui.sync.actions.SyncInfoDirectionFilter;
+import org.eclipse.team.ui.sync.actions.SyncInfoFilter;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.PartInitException;
import org.eclipse.ui.actions.ActionContext;
import org.eclipse.ui.part.IPageBookViewPage;
import org.eclipse.ui.part.IPageSite;
@@ -40,10 +76,6 @@ import org.eclipse.ui.views.navigator.ResourceSorter;
public class SubscriberSynchronizeViewPage implements IPageBookViewPage, ISyncSetChangedListener {
- private IPageSite site;
- private TeamSubscriber subscriber;
- private INewSynchronizeView view;
-
public static final int PROP_VIEWTYPE = 1;
/**
@@ -58,9 +90,6 @@ public class SubscriberSynchronizeViewPage implements IPageBookViewPage, ISyncSe
*/
public static final int TABLE_VIEW = 1;
- //This view's id. The same value as in the plugin.xml.
- public static final String VIEW_ID = "org.eclipse.team.sync.views.SynchronizeView"; //$NON-NLS-1$
-
// The viewer that is shown in the view. Currently this can be either a table or tree viewer.
private StructuredViewer viewer;
@@ -80,13 +109,15 @@ public class SubscriberSynchronizeViewPage implements IPageBookViewPage, ISyncSe
// private SyncViewerActions actions;
private JobBusyCursor busyCursor;
+ private INewSynchronizeView view;
+ private IPageSite site;
+ OpenWithActionGroup openWithActions;
/**
* Constructs a new SynchronizeView.
*/
public SubscriberSynchronizeViewPage(TeamSubscriber subscriber, INewSynchronizeView view) {
this.view = view;
- this.subscriber = subscriber;
this.input = new SubscriberInput(subscriber);
currentViewType = getStore().getInt(IPreferenceIds.SYNCVIEW_VIEW_TYPE);
if (currentViewType != TREE_VIEW) {
@@ -110,15 +141,16 @@ public class SubscriberSynchronizeViewPage implements IPageBookViewPage, ISyncSe
createViewer(composite);
updateStatusPanel();
updateTooltip();
+
+ openWithActions = new OpenWithActionGroup(getSite());
initializeSubscriberInput(input);
- //actions = new SyncViewerActions(this);
- //actions.setContext(null);
}
/* (non-Javadoc)
* @see org.eclipse.ui.IViewPart#init(org.eclipse.ui.IViewSite, org.eclipse.ui.IMemento)
*/
public void init(IPageSite site) throws PartInitException {
+ this.site = site;
RefreshSubscriberInputJob refreshJob = TeamUIPlugin.getPlugin().getRefreshJob();
if(getStore().getBoolean(IPreferenceIds.SYNCVIEW_SCHEDULED_SYNC) && refreshJob.getState() == Job.NONE) {
refreshJob.setReschedule(true);
@@ -130,38 +162,32 @@ public class SubscriberSynchronizeViewPage implements IPageBookViewPage, ISyncSe
/*
* This method is synchronized to ensure that all internal state is not corrupted
*/
- public synchronized void initializeSubscriberInput(final SubscriberInput input) {
- Assert.isNotNull(input);
-
+ public void initializeSubscriberInput(final SubscriberInput input) {
// listen to sync set changes in order to update state relating to the
// size of the sync sets and update the title
- disconnectSubscriberInput();
input.registerListeners(this);
-
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- // create the viewer is it doesn't exist yet.
- if(viewer == null) {
- switchViewerType(currentViewType);
- }
- ActionContext context = new ActionContext(null);
- context.setInput(input);
- //actions.setContext(context);
- viewer.setInput(input);
-
- RefreshSubscriberInputJob refreshJob = TeamUIPlugin.getPlugin().getRefreshJob();
- refreshJob.setSubscriberInput(input);
- updateStatusPanel();
- }
- });
+ RefreshSubscriberInputJob refreshJob = TeamUIPlugin.getPlugin().getRefreshJob();
+ refreshJob.setSubscriberInput(input);
+ updateStatusPanel();
}
- private void disconnectSubscriberInput() {
- if(input != null) {
- input.deregisterListeners(this);
- input = null;
+ protected void hookContextMenu() {
+ if(getViewer() != null) {
+ MenuManager menuMgr = new MenuManager("#PopupMenu2"); //$NON-NLS-1$
+ menuMgr.setRemoveAllWhenShown(true);
+ menuMgr.addMenuListener(new IMenuListener() {
+ public void menuAboutToShow(IMenuManager manager) {
+ openWithActions.setContext(new ActionContext(viewer.getSelection()));
+ openWithActions.fillContextMenu(manager);
+ manager.add(new Separator("Additions"));
+ }
+ });
+ Menu menu = menuMgr.createContextMenu(viewer.getControl());
+ viewer.getControl().setMenu(menu);
+ getSite().registerContextMenu("#PopupMenu3", menuMgr, viewer);
}
- }
+ }
+
/**
* Toggles between label/tree/table viewers.
*/
@@ -192,7 +218,7 @@ public class SubscriberSynchronizeViewPage implements IPageBookViewPage, ISyncSe
protected void initializeListeners() {
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
- handleSelectionChanged(event);
+ ;
}
});
viewer.addDoubleClickListener(new IDoubleClickListener() {
@@ -220,6 +246,8 @@ public class SubscriberSynchronizeViewPage implements IPageBookViewPage, ISyncSe
viewer.setInput(input);
viewer.getControl().setFocus();
initializeListeners();
+ hookContextMenu();
+ getSite().setSelectionProvider(getViewer());
busyCursor.setControl(viewer.getControl());
}
@@ -327,7 +355,7 @@ public class SubscriberSynchronizeViewPage implements IPageBookViewPage, ISyncSe
Display.getDefault().asyncExec(new Runnable() {
public void run() {
SubscriberInput input = getInput();
- if(input != null && statsPanel != null) {
+ if(statsPanel != null) {
statsPanel.update(new ViewStatusInformation(input));
}
}
@@ -361,10 +389,6 @@ public class SubscriberSynchronizeViewPage implements IPageBookViewPage, ISyncSe
return viewer;
}
- private static void handle(Shell shell, Exception exception, String title, String message) {
- Utils.handleError(shell, exception, title, message);
- }
-
/* (non-Javadoc)
* @see org.eclipse.ui.IWorkbenchPart#dispose()
*/
@@ -381,20 +405,11 @@ public class SubscriberSynchronizeViewPage implements IPageBookViewPage, ISyncSe
job.setSubscriberInput(null);
// Cleanup the subscriber inputs
+ input.deregisterListeners(this);
input.dispose();
busyCursor.dispose();
}
- public void run(IRunnableWithProgress runnable) {
- try {
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().run(true, true, runnable);
- } catch (InvocationTargetException e) {
- handle(getSite().getShell(), e, null, null);
- } catch (InterruptedException e) {
- // Nothing to be done
- }
- }
-
public int getViewerType() {
return currentViewType;
}
@@ -436,11 +451,7 @@ public class SubscriberSynchronizeViewPage implements IPageBookViewPage, ISyncSe
((AbstractTreeViewer)viewer).collapseToLevel(viewer.getInput(), TreeViewer.ALL_LEVELS);
viewer.getControl().setRedraw(true);
}
-
- public ISelection getSelection() {
- return getViewer().getSelection();
- }
-
+
/**
* This method enables "Show In" support for this view
*
@@ -519,27 +530,28 @@ public class SubscriberSynchronizeViewPage implements IPageBookViewPage, ISyncSe
* Makes this view visible in the active page.
*/
public static SynchronizeView showInActivePage(IWorkbenchPage activePage, boolean allowSwitchingPerspectives) {
- IWorkbench workbench= TeamUIPlugin.getPlugin().getWorkbench();
- IWorkbenchWindow window= workbench.getActiveWorkbenchWindow();
-
- if(allowSwitchingPerspectives && ! TeamUIPlugin.getPlugin().getPreferenceStore().getString(IPreferenceIds.SYNCVIEW_DEFAULT_PERSPECTIVE).equals(IPreferenceIds.SYNCVIEW_DEFAULT_PERSPECTIVE_NONE)) {
- try {
- String pId = TeamUIPlugin.getPlugin().getPreferenceStore().getString(IPreferenceIds.SYNCVIEW_DEFAULT_PERSPECTIVE);
- activePage = workbench.showPerspective(pId, window);
- } catch (WorkbenchException e) {
- Utils.handleError(window.getShell(), e, Policy.bind("SynchronizeView.14"), e.getMessage()); //$NON-NLS-1$
- }
- }
- try {
- if (activePage == null) {
- activePage = TeamUIPlugin.getActivePage();
- if (activePage == null) return null;
- }
- return (SynchronizeView)activePage.showView(VIEW_ID);
- } catch (PartInitException pe) {
- Utils.handleError(window.getShell(), pe, Policy.bind("SynchronizeView.16"), pe.getMessage()); //$NON-NLS-1$
- return null;
- }
+// IWorkbench workbench= TeamUIPlugin.getPlugin().getWorkbench();
+// IWorkbenchWindow window= workbench.getActiveWorkbenchWindow();
+//
+// if(allowSwitchingPerspectives && ! TeamUIPlugin.getPlugin().getPreferenceStore().getString(IPreferenceIds.SYNCVIEW_DEFAULT_PERSPECTIVE).equals(IPreferenceIds.SYNCVIEW_DEFAULT_PERSPECTIVE_NONE)) {
+// try {
+// String pId = TeamUIPlugin.getPlugin().getPreferenceStore().getString(IPreferenceIds.SYNCVIEW_DEFAULT_PERSPECTIVE);
+// activePage = workbench.showPerspective(pId, window);
+// } catch (WorkbenchException e) {
+// Utils.handleError(window.getShell(), e, Policy.bind("SynchronizeView.14"), e.getMessage()); //$NON-NLS-1$
+// }
+// }
+// try {
+// if (activePage == null) {
+// activePage = TeamUIPlugin.getActivePage();
+// if (activePage == null) return null;
+// }
+// //return (SynchronizeView)activePage.showView(VIEW_ID);
+// } catch (PartInitException pe) {
+// Utils.handleError(window.getShell(), pe, Policy.bind("SynchronizeView.16"), pe.getMessage()); //$NON-NLS-1$
+// return null;
+// }
+ return null;
}
/**
@@ -651,13 +663,6 @@ public class SubscriberSynchronizeViewPage implements IPageBookViewPage, ISyncSe
}
/* (non-Javadoc)
- * @see org.eclipse.ui.part.IPageBookViewPage#getSite()
- */
- public IPageSite getSite() {
- return site;
- }
-
- /* (non-Javadoc)
* @see org.eclipse.ui.part.IPage#createControl(org.eclipse.swt.widgets.Composite)
*/
public void createControl(Composite parent) {
@@ -678,4 +683,11 @@ public class SubscriberSynchronizeViewPage implements IPageBookViewPage, ISyncSe
// TODO Auto-generated method stub
//actions.fillActionBars(actionBars);
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.IPageBookViewPage#getSite()
+ */
+ public IPageSite getSite() {
+ return this.site;
+ }
}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/SubscriberPage.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/SubscriberPage.java
index c8fb245b2..0ce77b72c 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/SubscriberPage.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/SubscriberPage.java
@@ -3,23 +3,28 @@ package org.eclipse.team.ui.sync;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.team.core.subscribers.TeamSubscriber;
import org.eclipse.team.internal.ui.sync.pages.*;
+import org.eclipse.team.internal.ui.sync.sets.SubscriberInput;
import org.eclipse.ui.part.IPageBookViewPage;
public class SubscriberPage extends AbstractSynchronizeViewPage {
private TeamSubscriber subscriber;
+ private SubscriberSynchronizeViewPage page;
public SubscriberPage(TeamSubscriber subscriber, String name, ImageDescriptor imageDescriptor) {
super(name, imageDescriptor);
this.subscriber = subscriber;
- // TODO Auto-generated constructor stub
}
/* (non-Javadoc)
* @see org.eclipse.team.ui.sync.ISynchronizeViewPage#createPage(org.eclipse.team.ui.sync.ISynchronizeView)
*/
public IPageBookViewPage createPage(INewSynchronizeView view) {
- // TODO Auto-generated method stub
- return new SubscriberSynchronizeViewPage(subscriber, view);
+ this.page = new SubscriberSynchronizeViewPage(subscriber, view);
+ return page;
+ }
+
+ public SubscriberInput getInput() {
+ return page.getInput();
}
}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/actions/OpenInCompareAction.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/actions/OpenInCompareAction.java
new file mode 100644
index 000000000..2105d9d2b
--- /dev/null
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/actions/OpenInCompareAction.java
@@ -0,0 +1,201 @@
+/*******************************************************************************
+ * 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.ui.sync.actions;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.compare.CompareUI;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.core.subscribers.SyncInfo;
+import org.eclipse.team.core.sync.IRemoteResource;
+import org.eclipse.team.internal.ui.Policy;
+import org.eclipse.team.internal.ui.TeamUIPlugin;
+import org.eclipse.team.internal.ui.Utils;
+import org.eclipse.team.internal.ui.actions.TeamAction;
+import org.eclipse.team.internal.ui.sync.compare.SyncInfoCompareInput;
+import org.eclipse.team.internal.ui.sync.views.SynchronizeView;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IReusableEditor;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPartSite;
+
+/**
+ * Action to open a compare editor from a SyncInfo object.
+ *
+ * @see SyncInfoCompareInput
+ * @since 3.0
+ */
+public class OpenInCompareAction extends Action {
+
+ private IWorkbenchPage page;
+
+ public OpenInCompareAction(IWorkbenchPage page) {
+ this.page = page;
+ Utils.initAction(this, "action.openInCompareEditor."); //$NON-NLS-1$
+ }
+
+ public void run() {
+ ISelection selection = page.getSelection();
+ Object obj = ((IStructuredSelection)selection).getFirstElement();
+ SyncInfo info = getSyncInfo(obj);
+ if(info != null) {
+ openCompareEditor(page, info, true /* keep focus */);
+ }
+ }
+
+ public static SyncInfoCompareInput openCompareEditor(IWorkbenchPage page, SyncInfo info, boolean keepFocus) {
+ SyncInfoCompareInput input = getCompareInput(info);
+ if(input != null) {
+ IEditorPart editor = findReusableCompareEditor(page);
+
+ if(editor != null) {
+ IEditorInput otherInput = editor.getEditorInput();
+ if(otherInput instanceof SyncInfoCompareInput && otherInput.equals(input)) {
+ // simply provide focus to editor
+ page.activate(editor);
+ } else {
+ // if editor is currently not open on that input either re-use existing
+ if (!prefetchFileContents(info)) return null;
+ if(editor != null && editor instanceof IReusableEditor) {
+ CompareUI.reuseCompareEditor(input, (IReusableEditor)editor);
+ page.activate(editor);
+ }
+ }
+ } else {
+ CompareUI.openCompareEditor(input);
+ }
+
+ if(keepFocus) {
+ SynchronizeView.showInActivePage(page, false /* don't switch perspectives */);
+ }
+ return input;
+ }
+ return null;
+ }
+
+ /**
+ * Prefetching the file contents will cache them for use by the compare editor
+ * so that the compare editor doesn't have to perform file transfers. This will
+ * make the transfer cancellable.
+ */
+ private static boolean prefetchFileContents(SyncInfo info) {
+ final IRemoteResource remote = info.getRemote();
+ final IRemoteResource base = info.getBase();
+ if (remote != null || base != null) {
+ final boolean[] ok = new boolean[] { true };
+ TeamUIPlugin.run(new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ try {
+ monitor.beginTask(null, (remote == null ? 0 : 100) + (base == null ? 0 : 100));
+ if (remote != null)
+ remote.getContents(Policy.subMonitorFor(monitor, 100));
+ if (base != null)
+ base.getContents(Policy.subMonitorFor(monitor, 100));
+ } catch (TeamException e) {
+ ok[0] = false;
+ // The sync viewer will show the error to the user so we need only abort the action
+ throw new InvocationTargetException(e);
+ } finally {
+ // return false if the operation was cancelled
+ ok[0] = ! monitor.isCanceled();
+ monitor.done();
+ }
+ }
+ });
+ return ok[0];
+ }
+ return true;
+ }
+
+ /**
+ * Returns a SyncInfoCompareInput instance for the current selection.
+ */
+ private static SyncInfoCompareInput getCompareInput(SyncInfo info) {
+ if (info != null && info.getLocal() instanceof IFile) {
+ return SyncInfoCompareInput.createInput(info);
+ }
+ return null;
+ }
+
+ /**
+ * Returns an editor that can be re-used. An open compare editor that
+ * has un-saved changes cannot be re-used.
+ */
+ public static IEditorPart findReusableCompareEditor(IWorkbenchPage page) {
+ IEditorReference[] editorRefs = page.getEditorReferences();
+
+ for (int i = 0; i < editorRefs.length; i++) {
+ IEditorPart part = editorRefs[i].getEditor(true);
+ if(part != null && part.getEditorInput() instanceof SyncInfoCompareInput) {
+ if(! part.isDirty()) {
+ return part;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Close a compare editor that is opened on the given IResource.
+ *
+ * @param site the view site in which to close the editors
+ * @param resource the resource to use to find the compare editor
+ */
+ public static void closeCompareEditorFor(final IWorkbenchPartSite site, final IResource resource) {
+ site.getShell().getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ IEditorPart editor = findOpenCompareEditor(site, resource);
+ if(editor != null) {
+ site.getPage().closeEditor(editor, true /*save changes if required */);
+ }
+ }
+ });
+ }
+
+ /**
+ * Returns an editor handle if a SyncInfoCompareInput compare editor is opened on
+ * the given IResource.
+ *
+ * @param site the view site in which to search for editors
+ * @param resource the resource to use to find the compare editor
+ * @return an editor handle if found and <code>null</code> otherwise
+ */
+ public static IEditorPart findOpenCompareEditor(IWorkbenchPartSite site, IResource resource) {
+ IWorkbenchPage page = site.getPage();
+ IEditorReference[] editorRefs = page.getEditorReferences();
+ for (int i = 0; i < editorRefs.length; i++) {
+ final IEditorPart part = editorRefs[i].getEditor(false /* don't restore editor */);
+ if(part != null) {
+ IEditorInput input = part.getEditorInput();
+ if(part != null && input instanceof SyncInfoCompareInput) {
+ SyncInfo inputInfo = ((SyncInfoCompareInput)input).getSyncInfo();
+ if(inputInfo.getLocal().equals(resource)) {
+ return part;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ public static SyncInfo getSyncInfo(Object obj) {
+ return (SyncInfo)TeamAction.getAdapter(obj, SyncInfo.class);
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/actions/OpenWithActionGroup.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/actions/OpenWithActionGroup.java
new file mode 100644
index 000000000..9db72be8d
--- /dev/null
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/actions/OpenWithActionGroup.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * 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.ui.sync.actions;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.team.internal.ui.actions.TeamAction;
+import org.eclipse.ui.IWorkbenchSite;
+import org.eclipse.ui.actions.ActionContext;
+import org.eclipse.ui.actions.ActionGroup;
+import org.eclipse.ui.actions.OpenFileAction;
+import org.eclipse.ui.actions.OpenWithMenu;
+import org.eclipse.ui.views.navigator.ResourceNavigatorMessages;
+
+/**
+ * This is the action group for the open actions.
+ */
+public class OpenWithActionGroup extends ActionGroup {
+
+ private OpenFileAction openFileAction;
+ private OpenInCompareAction openInCompareAction;
+ private IWorkbenchSite site;
+
+ public OpenWithActionGroup(IWorkbenchSite site) {
+ this.site = site;
+ makeActions();
+ }
+
+ protected void makeActions() {
+ openFileAction = new OpenFileAction(site.getPage());
+ openInCompareAction = new OpenInCompareAction(site.getPage());
+ }
+
+ public void fillContextMenu(IMenuManager menu) {
+ ActionContext context = getContext();
+ IStructuredSelection selection = null;
+ if (context != null) {
+ selection = (IStructuredSelection) context.getSelection();
+ }
+ fillOpenWithMenu(menu, selection);
+ }
+
+ /**
+ * Adds the OpenWith submenu to the context menu.
+ *
+ * @param menu the context menu
+ * @param selection the current selection
+ */
+ private void fillOpenWithMenu(IMenuManager menu, IStructuredSelection selection) {
+
+ // Only supported if exactly one file is selected.
+ if (selection == null || selection.size() != 1)
+ return;
+ Object element = selection.getFirstElement();
+ IResource resource = getResource(element);
+ if (!(resource instanceof IFile)) {
+ return;
+ }
+
+ menu.add(openInCompareAction);
+
+ if(!((resource.exists()))) {
+ return;
+ }
+
+ openFileAction.selectionChanged(selection);
+ menu.add(openFileAction);
+
+ MenuManager submenu =
+ new MenuManager(ResourceNavigatorMessages.getString("ResourceNavigator.openWith")); //$NON-NLS-1$
+ submenu.add(new OpenWithMenu(site.getPage(), (IFile) resource));
+ menu.add(submenu);
+ }
+
+ /**
+ * Runs the default action (open file).
+ */
+ public void runDefaultAction(IStructuredSelection selection) {
+ Object element = selection.getFirstElement();
+ if (element instanceof IFile) {
+ openFileAction.selectionChanged(selection);
+ openFileAction.run();
+ }
+ }
+
+ private IResource getResource(Object obj) {
+ return (IResource)TeamAction.getAdapter(obj, IResource.class);
+ }
+
+ public void openInCompareEditor() {
+ openInCompareAction.run();
+ }
+} \ No newline at end of file

Back to the top