diff options
10 files changed, 571 insertions, 172 deletions
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/messages.properties b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/messages.properties index 704f9684c..3c98c4b4b 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/messages.properties +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/messages.properties @@ -368,10 +368,10 @@ action.directionFilterBoth.tooltip=Incoming/Outgoing mode action.directionFilterBoth.description=Incoming/Outgoing mode (shows outgoing changes, incoming changes, and conflicts) action.directionFilterBoth.image=catchuprelease_rls.gif -action.refreshSubscriber.label=Refresh with Remote +action.refreshSubscriber.label=Registered Synchronize Partners action.refreshSubscriber.tooltip=Refresh the current synchronization target with Remote action.refreshSubscriber.description=Refresh the current synchronization target with Remote -action.refreshSubscriber.image=refresh_remote.gif +action.refreshSubscriber.image=contents.gif action.navigateNext.label=Go to Next Difference action.navigateNext.tooltip=Go to Next Difference 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 e3eb057d4..412a148b6 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 @@ -2,86 +2,31 @@ package org.eclipse.team.internal.ui.sync.pages; 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.action.Action; -import org.eclipse.jface.action.IMenuListener; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; +import org.eclipse.jface.action.*; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; -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.jface.viewers.*; 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.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.swt.widgets.*; import org.eclipse.team.core.TeamException; import org.eclipse.team.core.subscribers.SyncInfo; -import org.eclipse.team.core.subscribers.TeamSubscriber; -import org.eclipse.team.internal.ui.IPreferenceIds; -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.*; import org.eclipse.team.internal.ui.actions.TeamAction; import org.eclipse.team.internal.ui.jobs.JobBusyCursor; 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.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.ViewStatusInformation; +import org.eclipse.team.internal.ui.sync.sets.*; +import org.eclipse.team.internal.ui.sync.views.*; import org.eclipse.team.ui.sync.INewSynchronizeView; import org.eclipse.team.ui.sync.SubscriberPage; -import org.eclipse.team.ui.sync.actions.AndSyncInfoFilter; -import org.eclipse.team.ui.sync.actions.DirectionFilterActionGroup; -import org.eclipse.team.ui.sync.actions.INavigableControl; -import org.eclipse.team.ui.sync.actions.NavigateAction; -import org.eclipse.team.ui.sync.actions.OpenWithActionGroup; -import org.eclipse.team.ui.sync.actions.PseudoConflictFilter; -import org.eclipse.team.ui.sync.actions.RefactorActionGroup; -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.team.ui.sync.actions.SyncViewerShowPreferencesAction; -import org.eclipse.team.ui.sync.actions.ToggleViewLayoutAction; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IWorkbenchActionConstants; -import org.eclipse.ui.IWorkingSet; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.actions.WorkingSetFilterActionGroup; -import org.eclipse.ui.part.IPageBookViewPage; -import org.eclipse.ui.part.IPageSite; -import org.eclipse.ui.part.IShowInSource; -import org.eclipse.ui.part.ShowInContext; +import org.eclipse.team.ui.sync.actions.*; +import org.eclipse.team.ui.sync.actions.workingsets.WorkingSetFilterActionGroup; +import org.eclipse.ui.*; +import org.eclipse.ui.part.*; import org.eclipse.ui.views.navigator.ResourceSorter; public class SubscriberSynchronizeViewPage implements IPageBookViewPage, ISyncSetChangedListener, IPropertyChangeListener { @@ -123,6 +68,7 @@ public class SubscriberSynchronizeViewPage implements IPageBookViewPage, ISyncSe private SyncViewerShowPreferencesAction showPreferences; private DirectionFilterActionGroup modesGroup; private WorkingSetFilterActionGroup workingSetGroup; + private RefreshAction refreshAction; /** * Constructs a new SynchronizeView. @@ -165,7 +111,9 @@ public class SubscriberSynchronizeViewPage implements IPageBookViewPage, ISyncSe toggleLayoutTree = new ToggleViewLayoutAction(page, SubscriberPage.TREE_LAYOUT); showPreferences = new SyncViewerShowPreferencesAction(view.getSite().getShell()); - workingSetGroup = new WorkingSetFilterActionGroup(getSite().getShell(), this); + workingSetGroup = new WorkingSetFilterActionGroup(getSite().getShell(), this, view, page); + + refreshAction = new RefreshAction(getSite().getPage(), input, true /* refresh all */); initializeSubscriberInput(input); } @@ -192,8 +140,9 @@ public class SubscriberSynchronizeViewPage implements IPageBookViewPage, ISyncSe // size of the sync sets and update the title input.registerListeners(this); RefreshSubscriberInputJob refreshJob = TeamUIPlugin.getPlugin().getRefreshJob(); - refreshJob.setSubscriberInput(input); + refreshJob.addSubscriberInput(input); updateStatusPanel(); + page.setMode(TeamUIPlugin.getPlugin().getPreferenceStore().getInt(IPreferenceIds.SYNCVIEW_SELECTED_MODE)); } private void hookContextMenu() { @@ -362,7 +311,6 @@ public class SubscriberSynchronizeViewPage implements IPageBookViewPage, ISyncSe protected void handleSelectionChanged(SelectionChangedEvent event) { final IStructuredSelection sel = (IStructuredSelection) event.getSelection(); updateStatusLine(sel); - updateActionBars(sel); } protected void handleOpen(OpenEvent event) { @@ -415,8 +363,8 @@ public class SubscriberSynchronizeViewPage implements IPageBookViewPage, ISyncSe } }); } - /** - * Passing the focus request to the viewer's control. + /* (non-Javadoc) + * @see org.eclipse.ui.part.IPage#setFocus() */ public void setFocus() { if (viewer == null) return; @@ -433,14 +381,7 @@ public class SubscriberSynchronizeViewPage implements IPageBookViewPage, ISyncSe public void dispose() { // cancel and wait RefreshSubscriberInputJob job = TeamUIPlugin.getPlugin().getRefreshJob(); - job.setRestartOnCancel(false); - job.cancel(); - try { - job.join(); - } catch (InterruptedException e) { - // continue with shutdown - } - job.setSubscriberInput(null); + job.removeSubscriberInput(input); // Cleanup the subscriber inputs input.deregisterListeners(this); @@ -481,22 +422,6 @@ public class SubscriberSynchronizeViewPage implements IPageBookViewPage, ISyncSe } /** - * Updates the action bar actions. - * - * @param selection the current selection - * @since 2.0 - */ - protected void updateActionBars(IStructuredSelection selection) { - //if (actions != null) { - //ActionContext actionContext = actions.getContext(); - //if(actionContext != null) { - //actionContext.setSelection(selection); - //actions.updateActionBars(); - //} - //} - } - - /** * Updates the message shown in the status line. * * @param selection the current selection @@ -542,47 +467,7 @@ public class SubscriberSynchronizeViewPage implements IPageBookViewPage, ISyncSe public void syncSetChanged(SyncSetChangedEvent event) { updateStatusPanel(); } - - public void selectSubscriber(TeamSubscriber subscriber) { - //activateSubscriber(subscriber); - } - - /** - * Refreshes the resources from the specified subscriber. The working set or filters applied - * to the sync view do not affect the sync. - */ - public void refreshWithRemote(TeamSubscriber subscriber, IResource[] resources) { - QualifiedName id = subscriber.getId(); - // if(subscriberInputs.containsKey(id)) { - // if(input != null && ! input.getSubscriber().getId().equals(id)) { - // initializeSubscriberInput((SubscriberInput)subscriberInputs.get(id)); - // } - // RefreshAction.run(this, resources, subscriber); - // } - } - - /** - * Refreshes the resources in the current input for the given subscriber. - */ - public void refreshWithRemote(TeamSubscriber subscriber) { - QualifiedName id = subscriber.getId(); - // if(input != null && subscriberInputs.containsKey(id)) { - // if(! input.getSubscriber().getId().equals(id)) { - // initializeSubscriberInput((SubscriberInput)subscriberInputs.get(id)); - // } - // RefreshAction.run(this, input.workingSetRoots(), subscriber); - // } - } - - /** - * Refreshes the resources in the current input for the given subscriber. - */ - public void refreshWithRemote() { - if(input != null) { - //RefreshAction.run(this, input.workingSetRoots(), input.getSubscriber()); - } - } - + public void selectAll() { if (getLayout() == SubscriberPage.TABLE_LAYOUT) { TableViewer table = (TableViewer)getViewer(); @@ -596,42 +481,10 @@ public class SubscriberSynchronizeViewPage implements IPageBookViewPage, ISyncSe return TeamUIPlugin.getPlugin().getPreferenceStore(); } - public SyncSetContentProvider getContentProvider() { - return (SyncSetContentProvider)getViewer().getContentProvider(); - } - - public void setWorkingSet(IWorkingSet workingSet) { - //actions.setWorkingSet(workingSet); - } - public void workingSetChanged(IWorkingSet set) { input.setWorkingSet(set); updateTooltip(); } - /** - * Updates the filter applied to the active subscriber input and ensures that selection and expansions - * is preserved when the filtered contents are shown. - * @param filter - */ - public void updateInputFilter(int[] directions, int[] changeTypes) { - try { - if(viewer instanceof INavigableControl) { - ((INavigableControl)viewer).preserveState(1); - } - input.setFilter( - new AndSyncInfoFilter( - new SyncInfoFilter[] { - new SyncInfoDirectionFilter(directions), - new SyncInfoChangeTypeFilter(changeTypes), - new PseudoConflictFilter() - }), new NullProgressMonitor()); - if(viewer instanceof INavigableControl) { - ((INavigableControl)viewer).restoreState(1); - } - } catch (TeamException e) { - Utils.handleError(getSite().getShell(), e, Policy.bind("SynchronizeView.16"), e.getMessage()); //$NON-NLS-1$ - } - } /* (non-Javadoc) * @see org.eclipse.ui.part.IPage#getControl() @@ -643,8 +496,9 @@ public class SubscriberSynchronizeViewPage implements IPageBookViewPage, ISyncSe /* (non-Javadoc) * @see org.eclipse.ui.part.IPage#setActionBars(org.eclipse.ui.IActionBars) */ - public void setActionBars(IActionBars actionBars) { + public void setActionBars(final IActionBars actionBars) { IToolBarManager manager = actionBars.getToolBarManager(); + manager.add(refreshAction); manager.add(gotoNext); manager.add(gotoPrevious); modesGroup.fillActionBars(actionBars); 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 6d168f504..1b91cf9be 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 @@ -61,7 +61,6 @@ public class SubscriberPage extends AbstractSynchronizeViewPage { */ public IPageBookViewPage createPage(INewSynchronizeView view) { this.page = new SubscriberSynchronizeViewPage(this, view); - setMode(TeamUIPlugin.getPlugin().getPreferenceStore().getInt(IPreferenceIds.SYNCVIEW_SELECTED_MODE)); return page; } diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/actions/DirectionFilterActionGroup.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/actions/DirectionFilterActionGroup.java index 5dc724c30..73fc81634 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/actions/DirectionFilterActionGroup.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/actions/DirectionFilterActionGroup.java @@ -122,8 +122,12 @@ public class DirectionFilterActionGroup extends ActionGroup implements IProperty * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) */ public void propertyChange(PropertyChangeEvent event) { - page.removePropertyChangeListener(this); + if(event.getProperty().equals(SubscriberPage.P_SYNCVIEWPAGE_MODE)) { + Integer mode = (Integer)event.getNewValue(); + checkMode(mode.intValue()); + } } + /* (non-Javadoc) * @see org.eclipse.ui.actions.ActionGroup#dispose() */ diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/actions/RefreshAction.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/actions/RefreshAction.java new file mode 100644 index 000000000..eb01db8db --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/actions/RefreshAction.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * 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.core.resources.IResource; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Platform; +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.TeamSubscriber; +import org.eclipse.team.internal.ui.*; +import org.eclipse.team.internal.ui.actions.TeamAction; +import org.eclipse.team.internal.ui.jobs.JobStatusHandler; +import org.eclipse.team.internal.ui.jobs.RefreshSubscriberJob; +import org.eclipse.team.internal.ui.sync.sets.SubscriberInput; +import org.eclipse.ui.IWorkbenchPage; + +public class RefreshAction extends Action { + private boolean refreshAll; + private SubscriberInput input; + private IWorkbenchPage page; + + public RefreshAction(IWorkbenchPage page, SubscriberInput input, boolean refreshAll) { + this.page = page; + this.input = input; + this.refreshAll = refreshAll; + Utils.initAction(this, "action.refreshWithRemote."); //$NON-NLS-1$ + } + + public void run() { + ISelection selection = page.getSelection(); + if(selection instanceof IStructuredSelection) { + IResource[] resources = getResources((IStructuredSelection)selection); + if (refreshAll || resources.length == 0) { + // If no resources are selected, refresh all the subscriber roots + resources = input.workingSetRoots(); + } + run(resources, input.getSubscriber()); + } + } + + private IResource[] getResources(ISelection selection) { + if(selection == null) { + return new IResource[0]; + } + return (IResource[])TeamAction.getSelectedAdaptables(selection, IResource.class); + } + + public static void run(IResource[] resources, TeamSubscriber subscriber) { + // Cancel the scheduled background refresh or any other refresh that is happening. + // The scheduled background refresh will restart automatically. + Platform.getJobManager().cancel(RefreshSubscriberJob.getFamily()); + if(TeamUIPlugin.getPlugin().getPreferenceStore().getBoolean(IPreferenceIds.SYNCVIEW_BACKGROUND_SYNC)) { + RefreshSubscriberJob job = new RefreshSubscriberJob(Policy.bind("SyncViewRefresh.taskName", new Integer(resources.length).toString(), subscriber.getName()), resources, subscriber); //$NON-NLS-1$ + JobStatusHandler.schedule(job, SubscriberAction.SUBSCRIBER_JOB_TYPE); + } else { + runBlocking(subscriber, resources); + } + } + + private static void runBlocking(final TeamSubscriber s, final IResource[] resources) { + TeamUIPlugin.run(new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + try { + monitor.beginTask(null, 100); + s.refresh(resources, IResource.DEPTH_INFINITE, Policy.subMonitorFor(monitor, 100)); + } catch (TeamException e) { + throw new InvocationTargetException(e); + } finally { + monitor.done(); + } + } + }); + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/actions/workingsets/ClearWorkingSetAction.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/actions/workingsets/ClearWorkingSetAction.java new file mode 100644 index 000000000..7ff4c6158 --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/actions/workingsets/ClearWorkingSetAction.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * 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.workingsets; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.util.Assert; +import org.eclipse.ui.help.WorkbenchHelp; +import org.eclipse.ui.internal.IHelpContextIds; +import org.eclipse.ui.internal.WorkbenchMessages; + +/** + * Clears the selected working set in the working set action group. + * + * @since 2.1 + */ +public class ClearWorkingSetAction extends Action { + private WorkingSetFilterActionGroup actionGroup; + + /** + * Creates a new instance of the receiver. + * + * @param actionGroup the action group this action is created in + */ + public ClearWorkingSetAction(WorkingSetFilterActionGroup actionGroup) { + super(WorkbenchMessages.getString("ClearWorkingSetAction.text")); //$NON-NLS-1$ + Assert.isNotNull(actionGroup); + setToolTipText(WorkbenchMessages.getString("ClearWorkingSetAction.toolTip")); //$NON-NLS-1$ + setEnabled(actionGroup.getWorkingSet() != null); + WorkbenchHelp.setHelp(this, IHelpContextIds.CLEAR_WORKING_SET_ACTION); + this.actionGroup = actionGroup; + } + /** + * Overrides method from Action + * + * @see org.eclipse.jface.Action#run + */ + public void run() { + actionGroup.setWorkingSet(null); + } +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/actions/workingsets/EditWorkingSetAction.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/actions/workingsets/EditWorkingSetAction.java new file mode 100644 index 000000000..1184acd85 --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/actions/workingsets/EditWorkingSetAction.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * 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.workingsets; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.util.Assert; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IWorkingSet; +import org.eclipse.ui.IWorkingSetManager; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.dialogs.IWorkingSetEditWizard; +import org.eclipse.ui.help.WorkbenchHelp; +import org.eclipse.ui.internal.IHelpContextIds; +import org.eclipse.ui.internal.WorkbenchMessages; + +/** + * Displays an IWorkingSetEditWizard for editing a working set. + * + * @since 2.1 + */ +public class EditWorkingSetAction extends Action { + private Shell shell; + private WorkingSetFilterActionGroup actionGroup; + + /** + * Creates a new instance of the receiver. + * + * @param actionGroup the action group this action is created in + */ + public EditWorkingSetAction(WorkingSetFilterActionGroup actionGroup, Shell shell) { + super(WorkbenchMessages.getString("EditWorkingSetAction.text")); //$NON-NLS-1$ + Assert.isNotNull(actionGroup); + setToolTipText(WorkbenchMessages.getString("EditWorkingSetAction.toolTip")); //$NON-NLS-1$ + + this.shell = shell; + this.actionGroup = actionGroup; + WorkbenchHelp.setHelp(this, IHelpContextIds.EDIT_WORKING_SET_ACTION); + } + /** + * Overrides method from Action + * + * @see org.eclipse.jface.Action#run + */ + public void run() { + IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager(); + IWorkingSet workingSet = actionGroup.getWorkingSet(); + + if (workingSet == null) { + setEnabled(false); + return; + } + IWorkingSetEditWizard wizard = manager.createWorkingSetEditWizard(workingSet); + if (wizard == null) { + String title = WorkbenchMessages.getString("EditWorkingSetAction.error.nowizard.title"); //$NON-NLS-1$ + String message = WorkbenchMessages.getString("EditWorkingSetAction.error.nowizard.message"); //$NON-NLS-1$ + MessageDialog.openError(shell, title, message); + return; + } + WizardDialog dialog = new WizardDialog(shell, wizard); + dialog.create(); + if (dialog.open() == WizardDialog.OK) + actionGroup.setWorkingSet(wizard.getSelection()); + } +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/actions/workingsets/SelectWorkingSetAction.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/actions/workingsets/SelectWorkingSetAction.java new file mode 100644 index 000000000..8beb2fff9 --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/actions/workingsets/SelectWorkingSetAction.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * 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.workingsets; + + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.util.Assert; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.*; +import org.eclipse.ui.dialogs.IWorkingSetSelectionDialog; +import org.eclipse.ui.help.WorkbenchHelp; +import org.eclipse.ui.internal.IHelpContextIds; +import org.eclipse.ui.internal.WorkbenchMessages; + +/** + * Displays an IWorkingSetSelectionDialog and sets the selected + * working set in the action group. + * + * @since 2.1 + */ +public class SelectWorkingSetAction extends Action { + private Shell shell; + private WorkingSetFilterActionGroup actionGroup; + + /** + * Creates a new instance of the receiver. + * + * @param actionGroup the action group this action is created in + * @param shell shell to use for opening working set selection dialog. + */ + public SelectWorkingSetAction(WorkingSetFilterActionGroup actionGroup, Shell shell) { + super(WorkbenchMessages.getString("SelectWorkingSetAction.text")); //$NON-NLS-1$ + Assert.isNotNull(actionGroup); + setToolTipText(WorkbenchMessages.getString("SelectWorkingSetAction.toolTip")); //$NON-NLS-1$ + + this.shell = shell; + this.actionGroup = actionGroup; + WorkbenchHelp.setHelp(this, IHelpContextIds.SELECT_WORKING_SET_ACTION); + } + /** + * Overrides method from Action + * + * @see org.eclipse.jface.Action#run + */ + public void run() { + IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager(); + IWorkingSetSelectionDialog dialog = manager.createWorkingSetSelectionDialog(shell, false); + IWorkingSet workingSet = actionGroup.getWorkingSet(); + + if (workingSet != null) + dialog.setSelection(new IWorkingSet[]{workingSet}); + + if (dialog.open() == Window.OK) { + IWorkingSet[] result = dialog.getSelection(); + if (result != null && result.length > 0) { + actionGroup.setWorkingSet(result[0]); + manager.addRecentWorkingSet(result[0]); + } + else { + actionGroup.setWorkingSet(null); + } + } + else + actionGroup.setWorkingSet(workingSet); + } +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/actions/workingsets/WorkingSetFilterActionGroup.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/actions/workingsets/WorkingSetFilterActionGroup.java new file mode 100644 index 000000000..992cfa232 --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/actions/workingsets/WorkingSetFilterActionGroup.java @@ -0,0 +1,174 @@ +/******************************************************************************* + * 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.workingsets; + +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.jface.action.IContributionItem; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.util.Assert; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.team.ui.sync.INewSynchronizeView; +import org.eclipse.team.ui.sync.ISynchronizeViewPage; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IWorkingSet; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.actions.ActionGroup; +import org.eclipse.ui.internal.WorkingSetComparator; + +/** + * Adds working set filter actions (set / clear / edit) + * + * @since 2.1 + */ +public class WorkingSetFilterActionGroup extends ActionGroup { + public static final String CHANGE_WORKING_SET = "changeWorkingSet"; //$NON-NLS-1$ + + private static final String SEPARATOR_ID = "workingSetGroupSeparator"; //$NON-NLS-1$ + + private IWorkingSet workingSet = null; + + private ClearWorkingSetAction clearWorkingSetAction; + private SelectWorkingSetAction selectWorkingSetAction; + private EditWorkingSetAction editWorkingSetAction; + + private IPropertyChangeListener workingSetUpdater; + + private int mruMenuCount; + private IMenuManager menuManager; + private IMenuListener menuListener; + + private ISynchronizeViewPage page; + + private INewSynchronizeView view; + + /** + * Creates a new instance of the receiver + * + * @param shell shell to open dialogs and wizards on + * @param workingSetUpdater property change listener notified when a + * working set is set + */ + public WorkingSetFilterActionGroup(Shell shell, IPropertyChangeListener workingSetUpdater, INewSynchronizeView view, ISynchronizeViewPage page) { + this.view = view; + this.page = page; + Assert.isNotNull(shell); + + this.workingSetUpdater = workingSetUpdater; + clearWorkingSetAction = new ClearWorkingSetAction(this); + selectWorkingSetAction = new SelectWorkingSetAction(this, shell); + editWorkingSetAction = new EditWorkingSetAction(this, shell); + } + /** + * Adds actions for the most recently used working sets to the + * specified menu manager. + * + * @param menuManager menu manager to add actions to + */ + private void addMruWorkingSetActions(IMenuManager menuManager) { + IWorkingSet[] workingSets = PlatformUI.getWorkbench().getWorkingSetManager().getRecentWorkingSets(); + List sortedWorkingSets = Arrays.asList(workingSets); + Collections.sort(sortedWorkingSets, new WorkingSetComparator()); + + Iterator iter = sortedWorkingSets.iterator(); + mruMenuCount = 0; + while (iter.hasNext()) { + IWorkingSet workingSet = (IWorkingSet)iter.next(); + if (workingSet != null) { + IContributionItem item = new WorkingSetMenuContributionItem(++mruMenuCount, this, workingSet); + menuManager.insertBefore(SEPARATOR_ID, item); + } + } + } + /** + * Removes the menu listener + * + * @see ActionGroup#dispose() + */ + public void dispose() { + if (menuManager != null) + menuManager.removeMenuListener(menuListener); + super.dispose(); + } + /** + * Adds working set actions to the specified action bar. + * + * @param actionBars action bar to add working set actions to. + * @see ActionGroup#fillActionBars(IActionBars) + */ + public void fillActionBars(IActionBars actionBars) { + menuManager = actionBars.getMenuManager(); + menuManager.add(selectWorkingSetAction); + menuManager.add(clearWorkingSetAction); + menuManager.add(editWorkingSetAction); + menuManager.add(new Separator()); + menuManager.add(new Separator(SEPARATOR_ID)); + + menuListener = new IMenuListener() { + public void menuAboutToShow(IMenuManager manager) { + removePreviousMruWorkingSetActions(manager); + addMruWorkingSetActions(manager); + } + }; + menuManager.addMenuListener(menuListener); + }; + /** + * Returns the working set which is currently selected. + * + * @return the working set which is currently selected. + */ + public IWorkingSet getWorkingSet() { + return workingSet; + } + /** + * Removes the most recently used working set actions that were + * added to the specified menu. + * + * @param menuManager menu manager to remove actions from + */ + private void removePreviousMruWorkingSetActions(IMenuManager menuManager) { + for (int i = 1; i <= mruMenuCount; i++) + menuManager.remove(WorkingSetMenuContributionItem.getId(i)); + } + /** + * Sets the current working set. + * + * @param newWorkingSet the new working set + */ + public void setWorkingSet(IWorkingSet newWorkingSet) { + IWorkingSet oldWorkingSet = workingSet; + + workingSet = newWorkingSet; + // Update action + clearWorkingSetAction.setEnabled(newWorkingSet != null); + editWorkingSetAction.setEnabled(newWorkingSet != null); + + // Update viewer + if (workingSetUpdater != null) { + workingSetUpdater.propertyChange( + new PropertyChangeEvent( + this, + WorkingSetFilterActionGroup.CHANGE_WORKING_SET, + oldWorkingSet, + newWorkingSet)); + } + } + + +} + diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/actions/workingsets/WorkingSetMenuContributionItem.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/actions/workingsets/WorkingSetMenuContributionItem.java new file mode 100644 index 000000000..31b33331f --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/actions/workingsets/WorkingSetMenuContributionItem.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * 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.workingsets; + +import org.eclipse.jface.action.ContributionItem; +import org.eclipse.jface.util.Assert; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.ui.IWorkingSet; +import org.eclipse.ui.IWorkingSetManager; +import org.eclipse.ui.PlatformUI; + +/** + * Menu contribution item which shows a working set. + * + * @since 2.1 + */ +public class WorkingSetMenuContributionItem extends ContributionItem { + private int id; + private IWorkingSet workingSet; + private WorkingSetFilterActionGroup actionGroup; + + /** + * Returns the id of this menu contribution item + * + * @param id numerical id + * @return String string id + */ + public static String getId(int id) { + return WorkingSetMenuContributionItem.class.getName() + "." + id; //$NON-NLS-1$ + } + /** + * Creates a new instance of the receiver. + * + * @param id sequential id of the new instance + * @param actionGroup the action group this contribution item is created in + */ + public WorkingSetMenuContributionItem(int id, WorkingSetFilterActionGroup actionGroup, IWorkingSet workingSet) { + super(getId(id)); + Assert.isNotNull(actionGroup); + Assert.isNotNull(workingSet); + this.id = id; + this.actionGroup = actionGroup; + this.workingSet = workingSet; + } + /** + * Adds a menu item for the working set. + * Overrides method from ContributionItem. + * + * @see org.eclipse.jface.action.ContributionItem#fill(Menu,int) + */ + public void fill(Menu menu, int index) { + MenuItem mi = new MenuItem(menu, SWT.RADIO, index); + mi.setText("&" + id + " " + workingSet.getName()); //$NON-NLS-1$ //$NON-NLS-2$ + mi.setSelection(workingSet.equals(actionGroup.getWorkingSet())); + mi.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager(); + actionGroup.setWorkingSet(workingSet); + manager.addRecentWorkingSet(workingSet); + } + }); + } + /** + * Overridden to always return true and force dynamic menu building. + */ + public boolean isDynamic() { + return true; + } + +} + |