diff options
Diffstat (limited to 'bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/SyncInfoDiffViewerSyncViewConfiguration.java')
-rw-r--r-- | bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/SyncInfoDiffViewerSyncViewConfiguration.java | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/SyncInfoDiffViewerSyncViewConfiguration.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/SyncInfoDiffViewerSyncViewConfiguration.java new file mode 100644 index 000000000..a508cd950 --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/SyncInfoDiffViewerSyncViewConfiguration.java @@ -0,0 +1,144 @@ +/******************************************************************************* + * 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.synchronize; + +import org.eclipse.compare.structuremergeviewer.DiffNode; +import org.eclipse.core.resources.IResource; +import org.eclipse.jface.action.*; +import org.eclipse.jface.viewers.*; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.team.core.subscribers.SyncInfo; +import org.eclipse.team.internal.ui.Policy; +import org.eclipse.team.internal.ui.Utils; +import org.eclipse.team.internal.ui.synchronize.actions.*; +import org.eclipse.ui.IWorkbenchActionConstants; + +/** + * Overrides the SyncInfoDiffViewerConfiguration to configure the diff viewer for the synchroniza view + */ +public class SyncInfoDiffViewerSyncViewConfiguration extends SyncInfoDiffViewerConfiguration { + + private ISynchronizeView view; + private TeamSubscriberParticipant participant; + + private OpenWithActionGroup openWithActions; + private RefactorActionGroup refactorActions; + private RefreshAction refreshSelectionAction; + private Action expandAll; + + public SyncInfoDiffViewerSyncViewConfiguration(ISynchronizeView view, TeamSubscriberParticipant participant) { + super(participant.getId(), participant.getSyncInfoSetCollector().getSyncInfoSet()); + this.view = view; + this.participant = participant; + } + /* (non-Javadoc) + * @see org.eclipse.team.ui.synchronize.SyncInfoDiffViewerConfiguration#createDiffTreeViewer(org.eclipse.swt.widgets.Composite) + */ + public SyncInfoDiffTreeViewer createDiffTreeViewer(Composite parent) { + SyncInfoDiffTreeViewer treeViewer = super.createDiffTreeViewer(parent); + + openWithActions = new OpenWithActionGroup(view, participant); + refactorActions = new RefactorActionGroup(view.getSite().getPage().getActivePart()); + refreshSelectionAction = new RefreshAction(view.getSite().getPage(), participant, false /*refresh*/); + expandAll = new Action() { + public void run() { + expandAllFromSelection(); + } + }; + Utils.initAction(expandAll, "action.expandAll."); //$NON-NLS-1$ + setAcceptParticipantMenuContributions(true); + return treeViewer; + } + + protected void fillContextMenu(IMenuManager manager) { + openWithActions.fillContextMenu(manager); + refactorActions.fillContextMenu(manager); + manager.add(refreshSelectionAction); + manager.add(new Separator()); + manager.add(expandAll); + manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.team.ui.synchronize.SyncInfoDiffTreeViewer#handleDoubleClick(org.eclipse.jface.viewers.DoubleClickEvent) + */ + protected void handleDoubleClick(DoubleClickEvent event) { + IStructuredSelection selection = (IStructuredSelection) event.getSelection(); + DiffNode node = (DiffNode) selection.getFirstElement(); + if (node != null && node instanceof SyncInfoDiffNode) { + SyncInfoDiffNode syncNode = (SyncInfoDiffNode)node; + SyncInfo info = syncNode.getSyncInfo(); + if (syncNode != null && syncNode.getResource().getType() == IResource.FILE) { + openWithActions.openInCompareEditor(); + return; + } + } + // Double-clicking should expand/collapse containers + super.handleDoubleClick(event); + } + + protected void initializeListeners() { + getViewer().addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + updateStatusLine((IStructuredSelection) event.getSelection()); + } + }); + getViewer().addOpenListener(new IOpenListener() { + public void open(OpenEvent event) { + handleOpen(); + } + }); + super.initializeListeners(); + } + + protected void handleOpen() { + openWithActions.openInCompareEditor(); + } + + /** + * Updates the message shown in the status line. + * + * @param selection + * the current selection + */ + private void updateStatusLine(IStructuredSelection selection) { + String msg = getStatusLineMessage(selection); + view.getViewSite().getActionBars().getStatusLineManager().setMessage(msg); + } + + /** + * Returns the message to show in the status line. + * + * @param selection + * the current selection + * @return the status line message + * @since 2.0 + */ + private String getStatusLineMessage(IStructuredSelection selection) { + if (selection.size() == 1) { + Object first = selection.getFirstElement(); + if (first instanceof SyncInfoDiffNode) { + SyncInfo info = ((SyncInfoDiffNode) first).getSyncInfo(); + if (info == null) { + return Policy.bind("SynchronizeView.12"); //$NON-NLS-1$ + } else { + return info.getLocal().getFullPath().makeRelative().toString(); + } + } + } + if (selection.size() > 1) { + return selection.size() + Policy.bind("SynchronizeView.13"); //$NON-NLS-1$ + } + return ""; //$NON-NLS-1$ + } +} |