From e16cf822385950aded05130261f6e32018724361 Mon Sep 17 00:00:00 2001 From: Michael Valenta Date: Fri, 1 Oct 2004 14:16:32 +0000 Subject: *** empty log message *** --- .../ui/subscriber/CVSChangeSetActionGroup.java | 40 +++ .../ccvs/ui/subscriber/ChangeLogModelProvider.java | 1 + .../ccvs/ui/subscriber/OpenChangeSetAction.java | 61 ++-- .../WorkspaceSynchronizeParticipant.java | 8 +- .../ui/synchronize/ChangeSetActionGroup.java | 368 -------------------- .../internal/ui/synchronize/ChangeSetDiffNode.java | 10 + .../ui/synchronize/ChangeSetModelProvider.java | 1 + .../synchronize/actions/ChangeSetActionGroup.java | 375 +++++++++++++++++++++ .../team/ui/synchronize/ChangeSetCapability.java | 73 +++- 9 files changed, 527 insertions(+), 410 deletions(-) create mode 100644 bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/CVSChangeSetActionGroup.java delete mode 100644 bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ChangeSetActionGroup.java create mode 100644 bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/ChangeSetActionGroup.java diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/CVSChangeSetActionGroup.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/CVSChangeSetActionGroup.java new file mode 100644 index 000000000..9203f79b8 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/CVSChangeSetActionGroup.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 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.internal.ccvs.ui.subscriber; + +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; +import org.eclipse.team.ui.synchronize.SynchronizePageActionGroup; + +/** + * Action group that is used by CVS Change Set Capabilities + */ +public class CVSChangeSetActionGroup extends SynchronizePageActionGroup { + + private OpenChangeSetAction openCommitSet; + + public void initialize(ISynchronizePageConfiguration configuration) { + super.initialize(configuration); + openCommitSet = new OpenChangeSetAction(configuration); + } + + /* (non-Javadoc) + * @see org.eclipse.team.ui.synchronize.SynchronizePageActionGroup#fillContextMenu(org.eclipse.jface.action.IMenuManager) + */ + public void fillContextMenu(IMenuManager menu) { + if (getConfiguration().getMode() == ISynchronizePageConfiguration.OUTGOING_MODE) { + appendToGroup( + menu, + ISynchronizePageConfiguration.FILE_GROUP, + openCommitSet); + } + } +} diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/ChangeLogModelProvider.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/ChangeLogModelProvider.java index 840a6239b..d063b7d16 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/ChangeLogModelProvider.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/ChangeLogModelProvider.java @@ -45,6 +45,7 @@ import org.eclipse.team.internal.core.Assert; import org.eclipse.team.internal.ui.TeamUIPlugin; import org.eclipse.team.internal.ui.Utils; import org.eclipse.team.internal.ui.synchronize.*; +import org.eclipse.team.internal.ui.synchronize.actions.ChangeSetActionGroup; import org.eclipse.team.ui.synchronize.*; import org.eclipse.ui.progress.UIJob; diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/OpenChangeSetAction.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/OpenChangeSetAction.java index 31b84f3fe..34dded90b 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/OpenChangeSetAction.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/OpenChangeSetAction.java @@ -11,12 +11,16 @@ package org.eclipse.team.internal.ccvs.ui.subscriber; import java.lang.reflect.InvocationTargetException; +import java.text.DateFormat; import org.eclipse.compare.structuremergeviewer.IDiffElement; import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.team.core.TeamException; +import org.eclipse.team.core.subscribers.ChangeSet; +import org.eclipse.team.core.subscribers.CheckedInChangeSet; import org.eclipse.team.core.synchronize.*; import org.eclipse.team.core.synchronize.FastSyncInfoFilter.*; import org.eclipse.team.core.variants.IResourceVariant; @@ -28,11 +32,8 @@ import org.eclipse.team.ui.synchronize.*; class OpenChangeSetAction extends SynchronizeModelAction { - private final ChangeLogModelProvider provider; - - protected OpenChangeSetAction(ChangeLogModelProvider provider, ISynchronizePageConfiguration configuration) { + protected OpenChangeSetAction(ISynchronizePageConfiguration configuration) { super(Policy.bind("OpenCommitSetAction.20"), configuration); //$NON-NLS-1$ - this.provider = provider; } /* (non-Javadoc) @@ -55,25 +56,36 @@ class OpenChangeSetAction extends SynchronizeModelAction { }) }); } - + + private ChangeSet getChangeSet(IStructuredSelection selection) { + // First, check to see if a change set is selected directly + if (selection.size() == 1) { + Object o = selection.getFirstElement(); + if (o instanceof IAdaptable) { + ChangeSet set = (ChangeSet)((IAdaptable)o).getAdapter(ChangeSet.class); + if (set != null) + return set; + } + } + // Failing that, check to see if all the selected elements and their childen are in the same change set + return getChangeSet(selection.toArray()); + } + + private ChangeSet getChangeSet(Object[] elements) { + // TODO Auto-generated method stub + return null; + } + /* (non-Javadoc) * @see org.eclipse.team.ui.synchronize.SynchronizeModelAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection) */ protected boolean updateSelection(IStructuredSelection selection) { boolean enabled = super.updateSelection(selection); if (enabled) { - // The selection only contains appropriate files - // only enable if there is only one item selected and - // it is a file or a commit set - if (selection.size() == 1) { - Object o = selection.getFirstElement(); - if (o instanceof ChangeSetDiffNode) return true; - if (o instanceof ISynchronizeModelElement) { - ISynchronizeModelElement element = (ISynchronizeModelElement)o; - IResource resource = element.getResource(); - return (resource != null && resource.getType() == IResource.FILE); - } - } + // The selection only contains appropriate files so + // only enable if the selection is contained within a single change set + ChangeSet set = getChangeSet(selection); + return set != null; } return false; } @@ -121,16 +133,13 @@ class OpenChangeSetAction extends SynchronizeModelAction { private String getCompareTitle() { IDiffElement[] elements = getSelectedDiffElements(); - for (int i = 0; i < elements.length; i++) { - IDiffElement element = elements[i]; - while (element != null) { - if (element instanceof ChangeSetDiffNode) { - return ((ChangeSetDiffNode)element).getShortName(); - } - element = element.getParent(); - } + ChangeSet set = getChangeSet(elements); + if (set instanceof CheckedInChangeSet) { + CheckedInChangeSet cics = (CheckedInChangeSet)set; + String date = DateFormat.getDateTimeInstance().format(cics.getDate()); + return "[" + cics.getAuthor() + "] (" + date + ")"; } - return null; + return "CVS Change"; } private ICVSRepositoryLocation getLocation(SyncInfo info) { diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/WorkspaceSynchronizeParticipant.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/WorkspaceSynchronizeParticipant.java index 64ae79696..8c0012981 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/WorkspaceSynchronizeParticipant.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/WorkspaceSynchronizeParticipant.java @@ -186,7 +186,13 @@ public class WorkspaceSynchronizeParticipant extends ScopableSubscriberParticipa public SubscriberChangeSetCollector getActiveChangeSetManager() { return CVSUIPlugin.getPlugin().getChangeSetManager(); } - + + /* (non-Javadoc) + * @see org.eclipse.team.ui.synchronize.ChangeSetCapability#getActionGroup() + */ + public SynchronizePageActionGroup getActionGroup() { + return new CVSChangeSetActionGroup(); + } } /** diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ChangeSetActionGroup.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ChangeSetActionGroup.java deleted file mode 100644 index 1966ccff4..000000000 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ChangeSetActionGroup.java +++ /dev/null @@ -1,368 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 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.internal.ui.synchronize; - -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.compare.structuremergeviewer.IDiffElement; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.action.*; -import org.eclipse.jface.dialogs.IDialogSettings; -import org.eclipse.jface.viewers.*; -import org.eclipse.swt.widgets.Control; -import org.eclipse.team.core.subscribers.*; -import org.eclipse.team.core.synchronize.FastSyncInfoFilter; -import org.eclipse.team.core.synchronize.SyncInfo; -import org.eclipse.team.core.synchronize.FastSyncInfoFilter.SyncInfoDirectionFilter; -import org.eclipse.team.internal.ui.Policy; -import org.eclipse.team.internal.ui.TeamUIPlugin; -import org.eclipse.team.internal.ui.actions.TeamAction; -import org.eclipse.team.ui.synchronize.*; -import org.eclipse.ui.actions.BaseSelectionListenerAction; - -/** - * This action group contributes actions that support the management - * of Change sets to a synchronize page. - */ -public final class ChangeSetActionGroup extends SynchronizePageActionGroup { - - /** - * Menu group that can be added to the context menu - */ - public final static String CHANGE_SET_GROUP = "change_set_group"; //$NON-NLS-1$ - - // Constants for persisting sorting options - private static final String P_LAST_COMMENTSORT = TeamUIPlugin.ID + ".P_LAST_COMMENT_SORT"; //$NON-NLS-1$ - - public static final FastSyncInfoFilter OUTGOING_RESOURCE_FILTER = new SyncInfoDirectionFilter( - new int[] { SyncInfo.OUTGOING, SyncInfo.CONFLICTING }); - - private class CreateChangeSetAction extends SynchronizeModelAction { - - public CreateChangeSetAction(ISynchronizePageConfiguration configuration) { - super(Policy.bind("ChangeLogModelProvider.0"), configuration); //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.SynchronizeModelAction#needsToSaveDirtyEditors() - */ - protected boolean needsToSaveDirtyEditors() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.SynchronizeModelAction#getSyncInfoFilter() - */ - protected FastSyncInfoFilter getSyncInfoFilter() { - return OUTGOING_RESOURCE_FILTER; - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.SynchronizeModelAction#getSubscriberOperation(org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration, org.eclipse.compare.structuremergeviewer.IDiffElement[]) - */ - protected SynchronizeModelOperation getSubscriberOperation(ISynchronizePageConfiguration configuration, IDiffElement[] elements) { - return new SynchronizeModelOperation(configuration, elements) { - public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - syncExec(new Runnable() { - public void run() { - SyncInfo[] infos = getSyncInfoSet().getSyncInfos(); - ActiveChangeSet set = createChangeSet(infos); - getActiveChangeSetManager().add(set); - } - }); - } - }; - } - } - - private abstract class ChangeSetAction extends BaseSelectionListenerAction { - - public ChangeSetAction(String title, ISynchronizePageConfiguration configuration) { - super(title); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.actions.BaseSelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection) - */ - protected boolean updateSelection(IStructuredSelection selection) { - return getSelectedSet() != null; - } - - protected ActiveChangeSet getSelectedSet() { - IStructuredSelection selection = getStructuredSelection(); - if (selection.size() == 1) { - Object first = selection.getFirstElement(); - return (ActiveChangeSet)TeamAction.getAdapter(first, ActiveChangeSet.class); - } - return null; - } - } - - private class EditChangeSetAction extends ChangeSetAction { - - public EditChangeSetAction(ISynchronizePageConfiguration configuration) { - super(Policy.bind("ChangeLogModelProvider.6"), configuration); //$NON-NLS-1$ - } - - public void run() { - ActiveChangeSet set = getSelectedSet(); - if (set == null) return; - editChangeSet(set); - } - } - - private class MakeDefaultChangeSetAction extends ChangeSetAction { - - public MakeDefaultChangeSetAction(ISynchronizePageConfiguration configuration) { - super(Policy.bind("ChangeLogModelProvider.9"), configuration); //$NON-NLS-1$ - } - - public void run() { - ActiveChangeSet set = getSelectedSet(); - if (set == null) return; - getActiveChangeSetManager().makeDefault(set); - } - - } - - private class AddToChangeSetAction extends SynchronizeModelAction { - - private final ActiveChangeSet set; - - public AddToChangeSetAction(ISynchronizePageConfiguration configuration, ActiveChangeSet set, ISelection selection) { - super(set.getTitle(), configuration); - this.set = set; - selectionChanged(selection); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.SynchronizeModelAction#getSyncInfoFilter() - */ - protected FastSyncInfoFilter getSyncInfoFilter() { - return OUTGOING_RESOURCE_FILTER; - } - - protected boolean needsToSaveDirtyEditors() { - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.SynchronizeModelAction#getSubscriberOperation(org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration, org.eclipse.compare.structuremergeviewer.IDiffElement[]) - */ - protected SynchronizeModelOperation getSubscriberOperation(ISynchronizePageConfiguration configuration, IDiffElement[] elements) { - return new SynchronizeModelOperation(configuration, elements) { - public void run(IProgressMonitor monitor) - throws InvocationTargetException, InterruptedException { - set.add(getSyncInfoSet().getSyncInfos()); - } - }; - } - } - - /* ***************************************************************************** - * Action that allows changing the model providers sort order. - */ - private class ToggleSortOrderAction extends Action { - private int criteria; - protected ToggleSortOrderAction(String name, int criteria) { - super(name, Action.AS_RADIO_BUTTON); - this.criteria = criteria; - update(); - } - - public void run() { - if (isChecked() && sortCriteria != criteria) { - sortCriteria = criteria; - String key = getSettingsKey(); - IDialogSettings pageSettings = getConfiguration().getSite().getPageSettings(); - if(pageSettings != null) { - pageSettings.put(key, criteria); - } - update(); - provider.setViewerSorter(getViewerSorter()); - } - } - - public void update() { - setChecked(criteria == sortCriteria); - } - - protected String getSettingsKey() { - return P_LAST_COMMENTSORT; - } - } - - /* - * The model provider for this action group - */ - private ChangeSetModelProvider provider; - - /* - * The actions created by this group - */ - private MenuManager sortByComment; - private CreateChangeSetAction createChangeSet; - private MenuManager addToChangeSet; - private EditChangeSetAction editChangeSet; - private MakeDefaultChangeSetAction makeDefault; - - /* - * The currently chosen sort criteria - */ - private int sortCriteria = ChangeSetModelSorter.DATE; - - public ChangeSetActionGroup(ChangeSetModelProvider provider) { - this.provider = provider; - } - - public void initialize(ISynchronizePageConfiguration configuration) { - super.initialize(configuration); - - if (getChangeSetCapability().supportsCheckedInChangeSets()) { - sortByComment = new MenuManager(Policy.bind("ChangeLogModelProvider.0a")); //$NON-NLS-1$ - appendToGroup( - ISynchronizePageConfiguration.P_CONTEXT_MENU, - ISynchronizePageConfiguration.SORT_GROUP, - sortByComment); - initializeSortCriteria(configuration); - - sortByComment.add(new ToggleSortOrderAction(Policy.bind("ChangeLogModelProvider.1a"), ChangeSetModelSorter.COMMENT)); //$NON-NLS-1$ - sortByComment.add(new ToggleSortOrderAction(Policy.bind("ChangeLogModelProvider.2a"), ChangeSetModelSorter.DATE)); //$NON-NLS-1$ - sortByComment.add(new ToggleSortOrderAction(Policy.bind("ChangeLogModelProvider.3a"), ChangeSetModelSorter.USER)); //$NON-NLS-1$ - } - - if (getChangeSetCapability().supportsActiveChangeSets()) { - addToChangeSet = new MenuManager(Policy.bind("ChangeLogModelProvider.12")); //$NON-NLS-1$ - addToChangeSet.setRemoveAllWhenShown(true); - addToChangeSet.addMenuListener(new IMenuListener() { - public void menuAboutToShow(IMenuManager manager) { - addChangeSets(manager); - } - }); - createChangeSet = new CreateChangeSetAction(configuration); - addToChangeSet.add(createChangeSet); - addToChangeSet.add(new Separator()); - editChangeSet = new EditChangeSetAction(configuration); - makeDefault = new MakeDefaultChangeSetAction(configuration); - - appendToGroup( - ISynchronizePageConfiguration.P_CONTEXT_MENU, - CHANGE_SET_GROUP, - addToChangeSet); - appendToGroup( - ISynchronizePageConfiguration.P_CONTEXT_MENU, - CHANGE_SET_GROUP, - editChangeSet); - appendToGroup( - ISynchronizePageConfiguration.P_CONTEXT_MENU, - CHANGE_SET_GROUP, - makeDefault); - } - } - - private void initializeSortCriteria(ISynchronizePageConfiguration configuration) { - try { - IDialogSettings pageSettings = getConfiguration().getSite().getPageSettings(); - if(pageSettings != null) { - sortCriteria = pageSettings.getInt(P_LAST_COMMENTSORT); - } - } catch(NumberFormatException e) { - // ignore and use the defaults. - } - switch (sortCriteria) { - case ChangeSetModelSorter.COMMENT: - case ChangeSetModelSorter.DATE: - case ChangeSetModelSorter.USER: - break; - default: - sortCriteria = ChangeSetModelSorter.DATE; - break; - } - } - - protected void addChangeSets(IMenuManager manager) { - ChangeSet[] sets = getActiveChangeSetManager().getSets(); - ISelection selection = getContext().getSelection(); - createChangeSet.selectionChanged(selection); - addToChangeSet.add(createChangeSet); - addToChangeSet.add(new Separator()); - for (int i = 0; i < sets.length; i++) { - ActiveChangeSet set = (ActiveChangeSet)sets[i]; - AddToChangeSetAction action = new AddToChangeSetAction(getConfiguration(), set, selection); - manager.add(action); - } - } - - /** - * Return the change set manager for the current page. - * @return the change set manager for the current page - */ - protected SubscriberChangeSetCollector getActiveChangeSetManager() { - return getChangeSetCapability().getActiveChangeSetManager(); - } - - /* (non-Javadoc) - * @see org.eclipse.team.ui.synchronize.SynchronizePageActionGroup#dispose() - */ - public void dispose() { - if (addToChangeSet != null) { - addToChangeSet.dispose(); - addToChangeSet.removeAll(); - } - if (sortByComment != null) { - sortByComment.dispose(); - sortByComment.removeAll(); - } - super.dispose(); - } - - - public void updateActionBars() { - if (editChangeSet != null) - editChangeSet.selectionChanged((IStructuredSelection)getContext().getSelection()); - if (makeDefault != null) - makeDefault.selectionChanged((IStructuredSelection)getContext().getSelection()); - super.updateActionBars(); - } - - private void syncExec(final Runnable runnable) { - final Control ctrl = getConfiguration().getPage().getViewer().getControl(); - if (ctrl != null && !ctrl.isDisposed()) { - ctrl.getDisplay().syncExec(new Runnable() { - public void run() { - if (!ctrl.isDisposed()) { - runnable.run(); - } - } - }); - } - } - - /** - * Return a viewer sorter that utilizes the sort criteria - * selected by the user. - */ - public ViewerSorter getViewerSorter() { - return new ChangeSetModelSorter(provider, sortCriteria); - } - - private ActiveChangeSet createChangeSet(SyncInfo[] infos) { - return getChangeSetCapability().createChangeSet(null, infos); - } - - private void editChangeSet(ActiveChangeSet set) { - getChangeSetCapability().editChangeSet(null, set); - } - - private ChangeSetCapability getChangeSetCapability() { - return provider.getChangeSetCapability(); - } -} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ChangeSetDiffNode.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ChangeSetDiffNode.java index 8c39fb40e..f1774965e 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ChangeSetDiffNode.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ChangeSetDiffNode.java @@ -77,4 +77,14 @@ public class ChangeSetDiffNode extends SynchronizeModelElement { } return super.equals(object); } + + /* (non-Javadoc) + * @see org.eclipse.team.internal.ui.synchronize.SynchronizeModelElement#getAdapter(java.lang.Class) + */ + public Object getAdapter(Class adapter) { + if (adapter.equals(ChangeSet.class)) { + return set; + } + return super.getAdapter(adapter); + } } diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ChangeSetModelProvider.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ChangeSetModelProvider.java index b05c1958d..bfea748c1 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ChangeSetModelProvider.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ChangeSetModelProvider.java @@ -25,6 +25,7 @@ import org.eclipse.team.core.subscribers.ChangeSet; import org.eclipse.team.core.subscribers.IChangeSetChangeListener; import org.eclipse.team.core.synchronize.*; import org.eclipse.team.internal.ui.*; +import org.eclipse.team.internal.ui.synchronize.actions.ChangeSetActionGroup; import org.eclipse.team.ui.synchronize.*; /** diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/ChangeSetActionGroup.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/ChangeSetActionGroup.java new file mode 100644 index 000000000..ed6c2242f --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/ChangeSetActionGroup.java @@ -0,0 +1,375 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 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.internal.ui.synchronize.actions; + +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.compare.structuremergeviewer.IDiffElement; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.action.*; +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.viewers.*; +import org.eclipse.swt.widgets.Control; +import org.eclipse.team.core.subscribers.*; +import org.eclipse.team.core.synchronize.FastSyncInfoFilter; +import org.eclipse.team.core.synchronize.SyncInfo; +import org.eclipse.team.core.synchronize.FastSyncInfoFilter.SyncInfoDirectionFilter; +import org.eclipse.team.internal.ui.Policy; +import org.eclipse.team.internal.ui.TeamUIPlugin; +import org.eclipse.team.internal.ui.actions.TeamAction; +import org.eclipse.team.internal.ui.synchronize.ChangeSetModelProvider; +import org.eclipse.team.internal.ui.synchronize.ChangeSetModelSorter; +import org.eclipse.team.ui.synchronize.*; +import org.eclipse.ui.actions.BaseSelectionListenerAction; + +/** + * This action group contributes actions that support the management + * of Change sets to a synchronize page. + */ +public final class ChangeSetActionGroup extends SynchronizePageActionGroup { + + /** + * Menu group that can be added to the context menu + */ + public final static String CHANGE_SET_GROUP = "change_set_group"; //$NON-NLS-1$ + + // Constants for persisting sorting options + private static final String P_LAST_COMMENTSORT = TeamUIPlugin.ID + ".P_LAST_COMMENT_SORT"; //$NON-NLS-1$ + + public static final FastSyncInfoFilter OUTGOING_RESOURCE_FILTER = new SyncInfoDirectionFilter( + new int[] { SyncInfo.OUTGOING, SyncInfo.CONFLICTING }); + + private class CreateChangeSetAction extends SynchronizeModelAction { + + public CreateChangeSetAction(ISynchronizePageConfiguration configuration) { + super(Policy.bind("ChangeLogModelProvider.0"), configuration); //$NON-NLS-1$ + } + + /* (non-Javadoc) + * @see org.eclipse.team.ui.synchronize.SynchronizeModelAction#needsToSaveDirtyEditors() + */ + protected boolean needsToSaveDirtyEditors() { + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.team.ui.synchronize.SynchronizeModelAction#getSyncInfoFilter() + */ + protected FastSyncInfoFilter getSyncInfoFilter() { + return OUTGOING_RESOURCE_FILTER; + } + + /* (non-Javadoc) + * @see org.eclipse.team.ui.synchronize.SynchronizeModelAction#getSubscriberOperation(org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration, org.eclipse.compare.structuremergeviewer.IDiffElement[]) + */ + protected SynchronizeModelOperation getSubscriberOperation(ISynchronizePageConfiguration configuration, IDiffElement[] elements) { + return new SynchronizeModelOperation(configuration, elements) { + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + syncExec(new Runnable() { + public void run() { + SyncInfo[] infos = getSyncInfoSet().getSyncInfos(); + ActiveChangeSet set = createChangeSet(infos); + getActiveChangeSetManager().add(set); + } + }); + } + }; + } + } + + private abstract class ChangeSetAction extends BaseSelectionListenerAction { + + public ChangeSetAction(String title, ISynchronizePageConfiguration configuration) { + super(title); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.actions.BaseSelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection) + */ + protected boolean updateSelection(IStructuredSelection selection) { + return getSelectedSet() != null; + } + + protected ActiveChangeSet getSelectedSet() { + IStructuredSelection selection = getStructuredSelection(); + if (selection.size() == 1) { + Object first = selection.getFirstElement(); + return (ActiveChangeSet)TeamAction.getAdapter(first, ActiveChangeSet.class); + } + return null; + } + } + + private class EditChangeSetAction extends ChangeSetAction { + + public EditChangeSetAction(ISynchronizePageConfiguration configuration) { + super(Policy.bind("ChangeLogModelProvider.6"), configuration); //$NON-NLS-1$ + } + + public void run() { + ActiveChangeSet set = getSelectedSet(); + if (set == null) return; + editChangeSet(set); + } + } + + private class MakeDefaultChangeSetAction extends ChangeSetAction { + + public MakeDefaultChangeSetAction(ISynchronizePageConfiguration configuration) { + super(Policy.bind("ChangeLogModelProvider.9"), configuration); //$NON-NLS-1$ + } + + public void run() { + ActiveChangeSet set = getSelectedSet(); + if (set == null) return; + getActiveChangeSetManager().makeDefault(set); + } + + } + + private class AddToChangeSetAction extends SynchronizeModelAction { + + private final ActiveChangeSet set; + + public AddToChangeSetAction(ISynchronizePageConfiguration configuration, ActiveChangeSet set, ISelection selection) { + super(set.getTitle(), configuration); + this.set = set; + selectionChanged(selection); + } + + /* (non-Javadoc) + * @see org.eclipse.team.ui.synchronize.SynchronizeModelAction#getSyncInfoFilter() + */ + protected FastSyncInfoFilter getSyncInfoFilter() { + return OUTGOING_RESOURCE_FILTER; + } + + protected boolean needsToSaveDirtyEditors() { + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.team.ui.synchronize.SynchronizeModelAction#getSubscriberOperation(org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration, org.eclipse.compare.structuremergeviewer.IDiffElement[]) + */ + protected SynchronizeModelOperation getSubscriberOperation(ISynchronizePageConfiguration configuration, IDiffElement[] elements) { + return new SynchronizeModelOperation(configuration, elements) { + public void run(IProgressMonitor monitor) + throws InvocationTargetException, InterruptedException { + set.add(getSyncInfoSet().getSyncInfos()); + } + }; + } + } + + /* ***************************************************************************** + * Action that allows changing the model providers sort order. + */ + private class ToggleSortOrderAction extends Action { + private int criteria; + protected ToggleSortOrderAction(String name, int criteria) { + super(name, Action.AS_RADIO_BUTTON); + this.criteria = criteria; + update(); + } + + public void run() { + if (isChecked() && sortCriteria != criteria) { + sortCriteria = criteria; + String key = getSettingsKey(); + IDialogSettings pageSettings = getConfiguration().getSite().getPageSettings(); + if(pageSettings != null) { + pageSettings.put(key, criteria); + } + update(); + provider.setViewerSorter(getViewerSorter()); + } + } + + public void update() { + setChecked(criteria == sortCriteria); + } + + protected String getSettingsKey() { + return P_LAST_COMMENTSORT; + } + } + + /* + * The model provider for this action group + */ + private ChangeSetModelProvider provider; + + /* + * The actions created by this group + */ + private MenuManager sortByComment; + private CreateChangeSetAction createChangeSet; + private MenuManager addToChangeSet; + private EditChangeSetAction editChangeSet; + private MakeDefaultChangeSetAction makeDefault; + + /* + * The currently chosen sort criteria + */ + private int sortCriteria = ChangeSetModelSorter.DATE; + + public ChangeSetActionGroup(ChangeSetModelProvider provider) { + this.provider = provider; + } + + public void initialize(ISynchronizePageConfiguration configuration) { + super.initialize(configuration); + + if (getChangeSetCapability().supportsCheckedInChangeSets()) { + initializeSortCriteria(configuration); + sortByComment = new MenuManager(Policy.bind("ChangeLogModelProvider.0a")); //$NON-NLS-1$ + sortByComment.add(new ToggleSortOrderAction(Policy.bind("ChangeLogModelProvider.1a"), ChangeSetModelSorter.COMMENT)); //$NON-NLS-1$ + sortByComment.add(new ToggleSortOrderAction(Policy.bind("ChangeLogModelProvider.2a"), ChangeSetModelSorter.DATE)); //$NON-NLS-1$ + sortByComment.add(new ToggleSortOrderAction(Policy.bind("ChangeLogModelProvider.3a"), ChangeSetModelSorter.USER)); //$NON-NLS-1$ + } + + if (getChangeSetCapability().supportsActiveChangeSets()) { + addToChangeSet = new MenuManager(Policy.bind("ChangeLogModelProvider.12")); //$NON-NLS-1$ + addToChangeSet.setRemoveAllWhenShown(true); + addToChangeSet.addMenuListener(new IMenuListener() { + public void menuAboutToShow(IMenuManager manager) { + addChangeSets(manager); + } + }); + createChangeSet = new CreateChangeSetAction(configuration); + addToChangeSet.add(createChangeSet); + addToChangeSet.add(new Separator()); + editChangeSet = new EditChangeSetAction(configuration); + makeDefault = new MakeDefaultChangeSetAction(configuration); + } + } + + /* (non-Javadoc) + * @see org.eclipse.team.ui.synchronize.SynchronizePageActionGroup#fillContextMenu(org.eclipse.jface.action.IMenuManager) + */ + public void fillContextMenu(IMenuManager menu) { + if (getChangeSetCapability().supportsCheckedInChangeSets() && getConfiguration().getMode() == ISynchronizePageConfiguration.INCOMING_MODE) { + appendToGroup(menu, ISynchronizePageConfiguration.SORT_GROUP, sortByComment); + } + if (getChangeSetCapability().supportsActiveChangeSets() && getConfiguration().getMode() == ISynchronizePageConfiguration.OUTGOING_MODE) { + appendToGroup( + menu, + CHANGE_SET_GROUP, + addToChangeSet); + appendToGroup( + menu, + CHANGE_SET_GROUP, + editChangeSet); + appendToGroup( + menu, + CHANGE_SET_GROUP, + makeDefault); + } + } + + private void initializeSortCriteria(ISynchronizePageConfiguration configuration) { + try { + IDialogSettings pageSettings = getConfiguration().getSite().getPageSettings(); + if(pageSettings != null) { + sortCriteria = pageSettings.getInt(P_LAST_COMMENTSORT); + } + } catch(NumberFormatException e) { + // ignore and use the defaults. + } + switch (sortCriteria) { + case ChangeSetModelSorter.COMMENT: + case ChangeSetModelSorter.DATE: + case ChangeSetModelSorter.USER: + break; + default: + sortCriteria = ChangeSetModelSorter.DATE; + break; + } + } + + protected void addChangeSets(IMenuManager manager) { + ChangeSet[] sets = getActiveChangeSetManager().getSets(); + ISelection selection = getContext().getSelection(); + createChangeSet.selectionChanged(selection); + addToChangeSet.add(createChangeSet); + addToChangeSet.add(new Separator()); + for (int i = 0; i < sets.length; i++) { + ActiveChangeSet set = (ActiveChangeSet)sets[i]; + AddToChangeSetAction action = new AddToChangeSetAction(getConfiguration(), set, selection); + manager.add(action); + } + } + + /** + * Return the change set manager for the current page. + * @return the change set manager for the current page + */ + protected SubscriberChangeSetCollector getActiveChangeSetManager() { + return getChangeSetCapability().getActiveChangeSetManager(); + } + + /* (non-Javadoc) + * @see org.eclipse.team.ui.synchronize.SynchronizePageActionGroup#dispose() + */ + public void dispose() { + if (addToChangeSet != null) { + addToChangeSet.dispose(); + addToChangeSet.removeAll(); + } + if (sortByComment != null) { + sortByComment.dispose(); + sortByComment.removeAll(); + } + super.dispose(); + } + + + public void updateActionBars() { + if (editChangeSet != null) + editChangeSet.selectionChanged((IStructuredSelection)getContext().getSelection()); + if (makeDefault != null) + makeDefault.selectionChanged((IStructuredSelection)getContext().getSelection()); + super.updateActionBars(); + } + + private void syncExec(final Runnable runnable) { + final Control ctrl = getConfiguration().getPage().getViewer().getControl(); + if (ctrl != null && !ctrl.isDisposed()) { + ctrl.getDisplay().syncExec(new Runnable() { + public void run() { + if (!ctrl.isDisposed()) { + runnable.run(); + } + } + }); + } + } + + /** + * Return a viewer sorter that utilizes the sort criteria + * selected by the user. + */ + public ViewerSorter getViewerSorter() { + return new ChangeSetModelSorter(provider, sortCriteria); + } + + private ActiveChangeSet createChangeSet(SyncInfo[] infos) { + return getChangeSetCapability().createChangeSet(null, infos); + } + + private void editChangeSet(ActiveChangeSet set) { + getChangeSetCapability().editChangeSet(null, set); + } + + private ChangeSetCapability getChangeSetCapability() { + return provider.getChangeSetCapability(); + } +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/ChangeSetCapability.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/ChangeSetCapability.java index 62cdf1901..29ad078fb 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/ChangeSetCapability.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/ChangeSetCapability.java @@ -24,52 +24,95 @@ public abstract class ChangeSetCapability { /** * Return whether the associated participant supports - * the display of checked-in change sets. + * the display of checked-in change sets. The default is + * unsupported (false). If subclasses support + * checked-in change sets, they must override the + * createCheckedInChangeSetCollector + * method to return an appropriate values. * @return whether the associated participant supports * the display of checked-in change sets */ - public abstract boolean supportsCheckedInChangeSets(); + public boolean supportsCheckedInChangeSets() { + return false; + } /** * Return whether the associated participant supports - * the use of active change sets. + * the use of active change sets. The default is unsupported + * (false). If a subclass overrides this method in + * order to support active change sets, they must also override the methods + * getActiveChangeSetManager, + * createChangeSet and editChangeSet. * @return whether the associated participant supports * the use of active change sets */ - public abstract boolean supportsActiveChangeSets(); + public boolean supportsActiveChangeSets() { + return false; + } /** * Return the change set collector that manages the active change - * set for the particpant associated with this capability. + * set for the particpant associated with this capability. A null + * is returned if active change sets are not supported. The default is to + * return null. This method must be + * overridden by subclasses that support active change sets. * @return the change set collector that manages the active change - * set for the particpant associated with this capability + * set for the particpant associated with this capability or + * null if active change sets are not supported. */ - public abstract SubscriberChangeSetCollector getActiveChangeSetManager(); + public SubscriberChangeSetCollector getActiveChangeSetManager() { + return null; + } /** * Create a change set from the given manager that contains the given sync info. - * This method is invoked from the UI thread. - * @param configuration TODO + * This method is invoked from the UI thread. A null + * is returned if active change sets are not supported. The default is to + * return null. This method must be + * overridden by subclasses that support active change sets. + * @param configuration the configuration of the page displaying the change sets * @param infos the sync info to be added to the change set * @param manager a change set manager * @return the created set. */ - public abstract ActiveChangeSet createChangeSet(ISynchronizePageConfiguration configuration, SyncInfo[] infos); + public ActiveChangeSet createChangeSet(ISynchronizePageConfiguration configuration, SyncInfo[] infos) { + return null; + } /** - * Edit the title and comment of the given change set. + * Edit the title and comment of the given change set. This method must be + * overridden by subclasses that support active change sets. * This method is invoked from the UI thread. - * @param configuration TODO + * @param configuration the configuration of the page displaying the change sets * @param set the set to be edited */ - public abstract void editChangeSet(ISynchronizePageConfiguration configuration, ActiveChangeSet set); + public void editChangeSet(ISynchronizePageConfiguration configuration, ActiveChangeSet set) { + // Default is to do nothing + } /** * Return a collector that can be used to group a set of checked-in changes - * into a set of checked-in change sets. + * into a set of checked-in change sets. This method must be + * overridden by subclasses that support checked-in change sets. * @param configuration the configuration for the page that will be displaying the change sets * @return a change set collector */ - public abstract SyncInfoSetChangeSetCollector createCheckedInChangeSetCollector(ISynchronizePageConfiguration configuration); + public SyncInfoSetChangeSetCollector createCheckedInChangeSetCollector(ISynchronizePageConfiguration configuration) { + return null; + } + + /** + * Return an action group for contributing context menu items + * to the synchronize page while change sets are enabled. + * Return null if no custom actions are required. + * Note that only context menus can be contributed since the view menu + * and toolbar menu are fixed. This method can be overridden by subclasses + * who wish to support custom change set actions. + * @return an action group for contributing context menu items + * to the synchronize page while change sets are enabled or null + */ + public SynchronizePageActionGroup getActionGroup() { + return null; + } } -- cgit v1.2.3