diff options
author | Jean Michel-Lemieux | 2003-07-09 17:08:13 +0000 |
---|---|---|
committer | Jean Michel-Lemieux | 2003-07-09 17:08:13 +0000 |
commit | 6085ad26f7f913a386aa696ab0e498ca3091706d (patch) | |
tree | d85b58695544a9d728d99773337440634030a4f1 /bundles/org.eclipse.team.ui | |
parent | adcfcbbd7f9c65bcb3d4ad4cb903cb2d0653cfd1 (diff) | |
download | eclipse.platform.team-6085ad26f7f913a386aa696ab0e498ca3091706d.tar.gz eclipse.platform.team-6085ad26f7f913a386aa696ab0e498ca3091706d.tar.xz eclipse.platform.team-6085ad26f7f913a386aa696ab0e498ca3091706d.zip |
*** empty log message ***
Diffstat (limited to 'bundles/org.eclipse.team.ui')
13 files changed, 519 insertions, 145 deletions
diff --git a/bundles/org.eclipse.team.ui/plugin.properties b/bundles/org.eclipse.team.ui/plugin.properties index eed75caa9..3b7b65aa9 100644 --- a/bundles/org.eclipse.team.ui/plugin.properties +++ b/bundles/org.eclipse.team.ui/plugin.properties @@ -11,6 +11,7 @@ providerName=Eclipse.org pluginName=Team Support UI +Team=Team configurationWizards=Configuration Wizards targetWizards=Target Site Addition Wizards subscriberMenus=Team Subscriber Menu Contributions @@ -49,4 +50,9 @@ SiteExplorerGetAs.tooltip=Download the selected remote folder with a user specif SiteExplorerGetAsProject.label=&Download As Project SiteExplorerGetAsProject.tooltip=Download the selected remote folder and create a project with the same name. SiteExplorerDiscardSite.label=D&iscard Site -SiteExplorerDiscardSite.tooltip=Discard the site
\ No newline at end of file +SiteExplorerDiscardSite.tooltip=Discard the site + +TeamActionSet.categoryName=Team +TeamActionSet.description=Actions that apply when working with a Team +TeamActionSet.syncLabel=Synchronize +TeamActionSet.syncTooltip=Synchronize
\ No newline at end of file diff --git a/bundles/org.eclipse.team.ui/plugin.xml b/bundles/org.eclipse.team.ui/plugin.xml index 9b99c4fb0..f00fd3919 100644 --- a/bundles/org.eclipse.team.ui/plugin.xml +++ b/bundles/org.eclipse.team.ui/plugin.xml @@ -190,13 +190,13 @@ category="org.eclipse.team.ui" class="org.eclipse.team.internal.ui.sync.views.SyncViewer"> </view> -<!-- <view + <view id="org.eclipse.team.sync.views.JobsView" name="Jobs" fastViewWidthRatio="0.25" category="org.eclipse.team.ui" class="org.eclipse.team.internal.ui.jobs.JobsView"> - </view> --> + </view> </extension> <!-- ****************** Import Wizards ********************* --> @@ -261,4 +261,45 @@ relationship="stack"/> </perspectiveExtension> </extension> + +<!-- ***************** Actions ********************** --> + <extension point="org.eclipse.ui.commands"> + <category + name="%TeamActionSet.categoryName" + description="%TeamActionSet.description" + id="org.eclipse.team.ui.actionSet"> + </category> + <command + category="org.eclipse.team.ui.actionSet" + name="%TeamActionSet.syncLabel" + description="%TeamActionSet.syncTooltip" + id="org.eclipse.team.ui.sync.all"> + </command> + <command + category="org.eclipse.team.ui.actionSet" + name="%TeamActionSet.syncLabel" + description="%TeamActionSet.syncTooltip" + id="org.eclipse.team.ui.sync.all"> + </command> + </extension> + + <extension point="org.eclipse.ui.actionSets"> + <actionSet + label="%Team" + visible="true" + id="org.eclipse.team.ui.actionSet" + description="%ActionSet.description"> + <action + toolbarPath="Normal/CVS" + style="pulldown" + label="%TeamActionSet.syncLabel" + tooltip="%TeamActionSet.syncTooltip" + icon="icons/full/cview16/synch_synch.gif" + class="org.eclipse.team.internal.ui.sync.actions.SyncAllAction" + id="org.eclipse.team.internal.ui.sync.actions.SyncAllAction" + definitionId="org.eclipse.team.ui.sync.all"> + </action> + </actionSet> + </extension> + </plugin> 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 dc4b92aaf..2082340fd 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 @@ -30,6 +30,7 @@ import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.swt.custom.BusyIndicator; import org.eclipse.swt.graphics.Image; +import org.eclipse.team.internal.ui.jobs.RefreshSubscriberInputJob; import org.eclipse.team.internal.ui.jobs.RefreshSubscriberJob; import org.eclipse.team.ui.ISharedImages; import org.eclipse.ui.IWorkbenchPage; @@ -60,12 +61,12 @@ public class TeamUIPlugin extends AbstractUIPlugin implements IPropertyChangeLis private static Hashtable imageDescriptors = new Hashtable(20); private static List disposeOnShutdownImages= new ArrayList(); - private RefreshSubscriberJob refreshJob; + private RefreshSubscriberInputJob refreshJob; /** * Returns the job that refreshes the active subscribers in the background. */ - public RefreshSubscriberJob getRefreshJob() { + public RefreshSubscriberInputJob getRefreshJob() { return refreshJob; } @@ -182,7 +183,7 @@ public class TeamUIPlugin extends AbstractUIPlugin implements IPropertyChangeLis getPreferenceStore().addPropertyChangeListener(this); // startup auto-refresh job if necessary - refreshJob = new RefreshSubscriberJob(Policy.bind("ScheduledSyncViewRefresh.taskName")); + refreshJob = new RefreshSubscriberInputJob(Policy.bind("ScheduledSyncViewRefresh.taskName")); refreshJob.setReschedule(true); refreshJob.setRefreshInterval(getPreferenceStore().getInt(IPreferenceIds.SYNCVIEW_DELAY) * 60); if(getPreferenceStore().getBoolean(IPreferenceIds.SYNCVIEW_SCHEDULED_SYNC)) { @@ -364,7 +365,8 @@ public class TeamUIPlugin extends AbstractUIPlugin implements IPropertyChangeLis refreshJob.setRefreshInterval(getPreferenceStore().getInt(IPreferenceIds.SYNCVIEW_DELAY) * 60); if(((Boolean)event.getNewValue()).booleanValue()) { refreshJob.schedule(); - } else { + } else { + refreshJob.setRestartOnCancel(false /* don't restart the job */); refreshJob.cancel(); } } diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/jobs/RefreshSubscriberInputJob.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/jobs/RefreshSubscriberInputJob.java new file mode 100644 index 000000000..407afae68 --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/jobs/RefreshSubscriberInputJob.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * 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.internal.ui.jobs; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.team.core.subscribers.ITeamResourceChangeListener; +import org.eclipse.team.core.subscribers.TeamDelta; +import org.eclipse.team.core.subscribers.TeamSubscriber; +import org.eclipse.team.internal.ui.sync.views.SubscriberInput; + +/** + * Job to refresh a subscriber with its remote state. + * + * There can be several refresh jobs created but they will be serialized. + */ +public class RefreshSubscriberInputJob extends RefreshSubscriberJob implements ITeamResourceChangeListener { + + /** + * The subscribers and roots to refresh. If these are changed when the job + * is running the job is cancelled. + */ + private SubscriberInput input; + + public RefreshSubscriberInputJob(String name) { + super(name, null, null); + } + + public void teamResourceChanged(TeamDelta[] deltas) { + for (int i = 0; i < deltas.length; i++) { + TeamDelta delta = deltas[i]; + if(delta.getFlags() == TeamDelta.SUBSCRIBER_DELETED) { + // cancel current refresh just to make sure that the subscriber being deleted can + // be properly shutdown + cancel(); + setSubscriberInput(null); + } + } + } + + public void setSubscriberInput(SubscriberInput input) { + int state = getState(); + if(state == Job.RUNNING) { + cancel(); + } + this.input = input; + + if(state == Job.NONE && input != null) { + if(shouldReschedule()) { + schedule(getScheduleDelay()); + } + } + } + + protected IResource[] getResources() { + if(input != null) { + return input.roots(); + } + return null; + } + + protected TeamSubscriber getSubscriber() { + if(input != null) { + return input.getSubscriber(); + } + return null; + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/jobs/RefreshSubscriberJob.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/jobs/RefreshSubscriberJob.java index 58e103bc4..fd8b9eed7 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/jobs/RefreshSubscriberJob.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/jobs/RefreshSubscriberJob.java @@ -21,19 +21,16 @@ import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.JobChangeAdapter; import org.eclipse.team.core.TeamException; -import org.eclipse.team.core.subscribers.ITeamResourceChangeListener; -import org.eclipse.team.core.subscribers.TeamDelta; import org.eclipse.team.core.subscribers.TeamSubscriber; import org.eclipse.team.internal.core.Policy; import org.eclipse.team.internal.core.TeamPlugin; -import org.eclipse.team.internal.ui.sync.views.SubscriberInput; /** * Job to refresh a subscriber with its remote state. * * There can be several refresh jobs created but they will be serialized. */ -public class RefreshSubscriberJob extends Job implements ITeamResourceChangeListener { +public class RefreshSubscriberJob extends Job { protected final static boolean DEBUG = Policy.DEBUG_REFRESH_JOB; @@ -50,7 +47,7 @@ public class RefreshSubscriberJob extends Job implements ITeamResourceChangeList /** * If true a rescheduled refresh job should be retarted when cancelled */ - private boolean restartOnCancel = false; + private boolean restartOnCancel = true; /** * The schedule delay used when rescheduling a completed job @@ -61,7 +58,8 @@ public class RefreshSubscriberJob extends Job implements ITeamResourceChangeList * The subscribers and roots to refresh. If these are changed when the job * is running the job is cancelled. */ - private SubscriberInput input; + private IResource[] resources; + private TeamSubscriber subscriber; private class BatchSimilarSchedulingRule implements ISchedulingRule { public String id; @@ -76,25 +74,29 @@ public class RefreshSubscriberJob extends Job implements ITeamResourceChangeList } } - public RefreshSubscriberJob(String name) { + public RefreshSubscriberJob(String name, IResource[] resources, TeamSubscriber subscriber) { super(name); + + this.resources = resources; + this.subscriber = subscriber; + setPriority(Job.DECORATE); setRule(new BatchSimilarSchedulingRule("org.eclipse.team.core.refreshsubscribers")); addJobChangeListener(new JobChangeAdapter() { public void done(IJobChangeEvent event) { if(shouldReschedule()) { - if(event.getResult().getSeverity() != IStatus.CANCEL || restartOnCancel) { + if(restartOnCancel && shouldReschedule()) { RefreshSubscriberJob.this.schedule(scheduleDelay); - restartOnCancel = false; } + restartOnCancel = true; } } }); } public boolean shouldRun() { - return input != null; + return getSubscriber() != null && getResources() != null; } public boolean belongsTo(Object family) { @@ -111,8 +113,8 @@ public class RefreshSubscriberJob extends Job implements ITeamResourceChangeList */ public IStatus run(IProgressMonitor monitor) { MultiStatus status = new MultiStatus(TeamPlugin.ID, TeamException.UNABLE, Policy.bind("Team.errorRefreshingSubscribers"), null); - TeamSubscriber subscriber = input.getSubscriber(); - IResource[] roots = input.roots(); + TeamSubscriber subscriber = getSubscriber(); + IResource[] roots = getResources(); monitor.beginTask(Policy.bind("RefreshSubscriber.runTitle", subscriber.getName()), 100); try { TeamSubscriber[] subscribers = new TeamSubscriber[] {subscriber}; @@ -136,35 +138,18 @@ public class RefreshSubscriberJob extends Job implements ITeamResourceChangeList return status.isOK() ? Status.OK_STATUS : (IStatus) status; } - public void teamResourceChanged(TeamDelta[] deltas) { - for (int i = 0; i < deltas.length; i++) { - TeamDelta delta = deltas[i]; - if(delta.getFlags() == TeamDelta.SUBSCRIBER_DELETED) { - // cancel current refresh just to make sure that the subscriber being deleted can - // be properly shutdown - cancel(); - setSubscriberInput(null); - } - } + protected IResource[] getResources() { + return resources; + } + + protected TeamSubscriber getSubscriber() { + return subscriber; } - public void setSubscriberInput(SubscriberInput input) { - int state = getState(); - if(state == Job.RUNNING) { - if(shouldReschedule()) { - setRestartOnCancel(true); - } - cancel(); - } - this.input = input; - - if(state == Job.NONE && input != null) { - if(reschedule) { - schedule(scheduleDelay); - } - } + protected long getScheduleDelay() { + return scheduleDelay; } - + /** * Specify the interval in seconds at which this job is scheduled. * @param seconds delay specified in seconds @@ -191,5 +176,5 @@ public class RefreshSubscriberJob extends Job implements ITeamResourceChangeList public boolean shouldReschedule() { return reschedule; - } + } }
\ No newline at end of file diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/OpenInCompareAction.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/OpenInCompareAction.java index 6258a3f75..b8e27bf7d 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/OpenInCompareAction.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/OpenInCompareAction.java @@ -55,6 +55,7 @@ public class OpenInCompareAction extends Action { } else { CompareUI.openCompareEditor(input); } + SyncViewer.showInActivePage(viewer.getSite().getPage()); } } diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/RefreshAction.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/RefreshAction.java index 8f9b901c6..0a3b34fce 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/RefreshAction.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/RefreshAction.java @@ -30,7 +30,7 @@ import org.eclipse.team.internal.ui.sync.views.SyncViewer; import org.eclipse.team.ui.ISharedImages; import org.eclipse.ui.actions.ActionContext; -class RefreshAction extends Action { +public class RefreshAction extends Action { private final SyncViewerActions actions; private boolean refreshAll; @@ -55,17 +55,7 @@ class RefreshAction extends Action { // If no resources are selected, refresh all the subscriber roots resources = input.roots(); } - if(TeamUIPlugin.getPlugin().getPreferenceStore().getBoolean(IPreferenceIds.SYNCVIEW_BACKGROUND_SYNC)) { - // Cancel the scheduled background refresh but ensure it gets rescheduled - // to run later. - TeamUIPlugin.getPlugin().getRefreshJob().setRestartOnCancel(true); - Platform.getJobManager().cancel(RefreshSubscriberJob.getFamily()); - RefreshSubscriberJob job = new RefreshSubscriberJob(Policy.bind("SyncViewRefresh.taskName", new Integer(resources.length).toString())); - job.setSubscriberInput(input); - job.schedule(); - } else { - runBlocking(input.getSubscriber(), resources); - } + run(view, resources, input.getSubscriber()); } } @@ -76,8 +66,22 @@ class RefreshAction extends Action { return (IResource[])TeamAction.getSelectedAdaptables(selection, IResource.class); } - private void runBlocking(final TeamSubscriber s, final IResource[] resources) { - actions.getSyncView().run(new IRunnableWithProgress() { + public static void run(SyncViewer viewer, IResource[] resources, TeamSubscriber subscriber) { + if(TeamUIPlugin.getPlugin().getPreferenceStore().getBoolean(IPreferenceIds.SYNCVIEW_BACKGROUND_SYNC)) { + // Cancel the scheduled background refresh but ensure it gets rescheduled + // to run later. + Platform.getJobManager().cancel(RefreshSubscriberJob.getFamily()); + RefreshSubscriberJob job = new RefreshSubscriberJob(Policy.bind("SyncViewRefresh.taskName", new Integer(resources.length).toString()), resources, subscriber); + if(TeamUIPlugin.getPlugin().getPreferenceStore().getBoolean(IPreferenceIds.SYNCVIEW_SCHEDULED_SYNC)) { + job.schedule(); + } + } else { + runBlocking(viewer, subscriber, resources); + } + } + + private static void runBlocking(SyncViewer viewer, final TeamSubscriber s, final IResource[] resources) { + viewer.run(new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { monitor.beginTask(null, 100); diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/SyncAllAction.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/SyncAllAction.java new file mode 100644 index 000000000..e808d05ad --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/SyncAllAction.java @@ -0,0 +1,135 @@ +/******************************************************************************* + * 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.internal.ui.sync.actions; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.ActionContributionItem; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.events.MenuAdapter; +import org.eclipse.swt.events.MenuEvent; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.team.core.subscribers.TeamProvider; +import org.eclipse.team.core.subscribers.TeamSubscriber; +import org.eclipse.team.ui.TeamUI; +import org.eclipse.team.ui.sync.ISyncViewer; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.IWorkbenchWindowPulldownDelegate2; + +public class SyncAllAction implements IWorkbenchWindowPulldownDelegate2 { + + private IWorkbenchWindow window; + private Menu createdMenu; + + class SubscriberAction extends Action { + TeamSubscriber subscriber; + SubscriberAction(TeamSubscriber s) { + this.subscriber = s; + setText(s.getName()); + } + public void run() { + ISyncViewer view = TeamUI.showSyncViewInActivePage(window.getActivePage()); + if(view != null) { + view.refreshWithRemote(subscriber); + } + } + } + + public void run(IAction action) { + ISyncViewer view = TeamUI.showSyncViewInActivePage(window.getActivePage()); + if(view != null) { + view.refreshWithRemote(); + } + } + + public void dispose() { + if(getCreatedMenu() != null) { + getCreatedMenu().dispose(); + } + } + + public void init(IWorkbenchWindow window) { + this.window = window; + } + + private void createAction(Menu parent, IAction action, int count) { + StringBuffer label= new StringBuffer(); + //add the numerical accelerator + if (count != -1) { + label.append('&'); + label.append(count); + label.append(' '); + } + label.append(action.getText()); + action.setText(label.toString()); + ActionContributionItem item= new ActionContributionItem(action); + item.fill(parent, -1); + } + + public Menu getMenu(Menu parent) { + dispose(); + setCreatedMenu(new Menu(parent)); + fillMenu(); + initMenu(); + return getCreatedMenu(); + } + + private Menu getCreatedMenu() { + return createdMenu; + } + + private void setCreatedMenu(Menu menu) { + createdMenu = menu; + } + + private void fillMenu() { + TeamSubscriber[] subscribers = TeamProvider.getSubscribers(); + for (int i = 0; i < subscribers.length; i++) { + TeamSubscriber subscriber = subscribers[i]; + createAction(getCreatedMenu(), new SubscriberAction(subscriber), i + 1); + } + new Separator().fill(getCreatedMenu(), -1); + createAction(getCreatedMenu(), new SyncViewerShowPreferencesAction(window.getShell()), -1); + + } + + /** + * Creates the menu for the action + */ + private void initMenu() { + // Add listener to repopulate the menu each time + // it is shown to reflect changes in selection or active perspective + getCreatedMenu().addMenuListener(new MenuAdapter() { + public void menuShown(MenuEvent e) { + Menu m = (Menu)e.widget; + MenuItem[] items = m.getItems(); + for (int i=0; i < items.length; i++) { + items[i].dispose(); + } + fillMenu(); + } + }); + } + + public Menu getMenu(Control parent) { + dispose(); + setCreatedMenu(new Menu(parent)); + fillMenu(); + initMenu(); + return getCreatedMenu(); + } + + public void selectionChanged(IAction action, ISelection selection) { + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/SyncViewerActions.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/SyncViewerActions.java index b41ece17e..18b4f5c42 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/SyncViewerActions.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/SyncViewerActions.java @@ -33,6 +33,7 @@ import org.eclipse.team.ui.sync.SyncInfoDirectionFilter; import org.eclipse.team.ui.sync.SyncInfoFilter; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IMemento; +import org.eclipse.ui.IPropertyListener; import org.eclipse.ui.IWorkingSet; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.actions.ActionContext; @@ -78,14 +79,17 @@ public class SyncViewerActions extends SyncViewerActionGroup { } } - class ToggleViewAction extends Action { - public ToggleViewAction(int initialState) { + class ToggleViewAction extends Action implements IPropertyListener { + private SyncViewer viewer; + public ToggleViewAction(SyncViewer viewer, int initialState) { + this.viewer = viewer; setText("Toggle Tree/Table"); setToolTipText("Toggle Tree/Table"); setImageDescriptor(PlatformUI.getWorkbench().getSharedImages(). getImageDescriptor(org.eclipse.ui.ISharedImages.IMG_TOOL_COPY)); setChecked(initialState == SyncViewer.TREE_VIEW); collapseAll.setEnabled(false); + viewer.addPropertyListener(this); } public void run() { int viewerType; @@ -98,6 +102,11 @@ public class SyncViewerActions extends SyncViewerActionGroup { } getSyncView().switchViewerType(viewerType); } + public void propertyChanged(Object source, int propId) { + if(propId == SyncViewer.PROP_VIEWTYPE) { + setChecked(viewer.getCurrentViewType() == SyncViewer.TREE_VIEW); + } + } } class SelectAllAction extends Action { @@ -188,7 +197,7 @@ public class SyncViewerActions extends SyncViewerActionGroup { expandAll = new ExpandAllAction(this); cancelSubscription = new CancelSubscription(this); - toggleViewerType = new ToggleViewAction(getSyncView().getViewerType()); + toggleViewerType = new ToggleViewAction(getSyncView(), getSyncView().getCurrentViewType()); open = new OpenInCompareAction(syncView); IPropertyChangeListener workingSetUpdater = new IPropertyChangeListener() { @@ -232,7 +241,7 @@ public class SyncViewerActions extends SyncViewerActionGroup { IMenuManager dropDownMenu = actionBars.getMenuManager(); workingSetGroup.fillActionBars(actionBars); - dropDownMenu.add(new SyncViewerShowPreferencesAction(this)); + dropDownMenu.add(new SyncViewerShowPreferencesAction(getSyncView().getSite().getShell())); dropDownMenu.add(cancelSubscription); } diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/SyncViewerShowPreferencesAction.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/SyncViewerShowPreferencesAction.java index 98c53d812..59f2e6a13 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/SyncViewerShowPreferencesAction.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/actions/SyncViewerShowPreferencesAction.java @@ -13,23 +13,22 @@ package org.eclipse.team.internal.ui.sync.actions; import org.eclipse.jface.action.Action; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.swt.widgets.Shell; import org.eclipse.team.internal.ui.dialogs.PreferencePageContainerDialog; import org.eclipse.team.internal.ui.preferences.SyncViewerPreferencePage; public class SyncViewerShowPreferencesAction extends Action { - private final SyncViewerActions actions; + private final Shell shell; - public SyncViewerShowPreferencesAction(SyncViewerActions actions) { - this.actions = actions; + public SyncViewerShowPreferencesAction(Shell shell) { + this.shell = shell; setText("Preferences..."); setToolTipText("Configure the view's preferences"); } public void run() { PreferencePage page = new SyncViewerPreferencePage(); - Dialog dialog = new PreferencePageContainerDialog( - actions.getSyncView().getSite().getShell(), - page); + Dialog dialog = new PreferencePageContainerDialog(shell, page); dialog.setBlockOnOpen(true); dialog.open(); } diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/views/SyncViewer.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/views/SyncViewer.java index 252271721..e43f3da84 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/views/SyncViewer.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/sync/views/SyncViewer.java @@ -16,6 +16,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Set; @@ -23,10 +24,11 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.QualifiedName; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.IJobChangeEvent; -import org.eclipse.core.runtime.jobs.IJobChangeListener; import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.core.runtime.jobs.JobChangeAdapter; import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.MenuManager; @@ -70,12 +72,14 @@ 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.jobs.RefreshSubscriberInputJob; import org.eclipse.team.internal.ui.jobs.RefreshSubscriberJob; +import org.eclipse.team.internal.ui.sync.actions.RefreshAction; import org.eclipse.team.internal.ui.sync.actions.SyncViewerActions; import org.eclipse.team.ui.ISharedImages; +import org.eclipse.team.ui.sync.ISyncViewer; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IMemento; -import org.eclipse.ui.IViewPart; import org.eclipse.ui.IViewSite; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPart; @@ -87,12 +91,14 @@ import org.eclipse.ui.part.IShowInSource; import org.eclipse.ui.part.ShowInContext; import org.eclipse.ui.part.ViewPart; -public class SyncViewer extends ViewPart implements ITeamResourceChangeListener, ISyncSetChangedListener, IJobChangeListener { +public class SyncViewer extends ViewPart implements ITeamResourceChangeListener, ISyncSetChangedListener, ISyncViewer { + public static int PROP_VIEWTYPE = 0x10; + /* * This view's id. The same value as in the plugin.xml. */ - public static final String VIEW_ID = "org.eclipse.team.sync.views.SyncViewer"; + public static final String VIEW_ID = "org.eclipse.team.sync.views.SyncViewer"; /* * The viewer thst is shown in the view. Currently this can be @@ -110,8 +116,7 @@ public class SyncViewer extends ViewPart implements ITeamResourceChangeListener, /* * viewer type constants */ - public static final int TREE_VIEW = 0; - public static final int TABLE_VIEW = 1; + private int currentViewType = TABLE_VIEW; /* * Array of SubscriberInput objects. There is one of these for each subscriber @@ -133,16 +138,12 @@ public class SyncViewer extends ViewPart implements ITeamResourceChangeListener, private Image refreshingImg; private Image initialImg; private Image viewImage; - - // the currently choosen viewer type (TREE_VIEW or TABLE_VIEW) - private int viewerType = TABLE_VIEW; private static final String VIEWER_TYPE_MEMENTO_KEY = "viewerType"; // $NON-NLS-1$ - + /** - * Subclass of TreeViewer which handles decorator events properly. - * - * TODO: We should not need to create a subclass just for this! + * Subclass of TreeViewer which handles decorator events properly. We should not need to create + * a subclass just for this! */ public class SyncTreeViewer extends TreeViewer { public SyncTreeViewer(Composite parent, int style) { @@ -167,7 +168,7 @@ public class SyncViewer extends ViewPart implements ITeamResourceChangeListener, super.handleLabelProviderChanged(event); } } - + public SyncViewer() { } @@ -181,9 +182,23 @@ public class SyncViewer extends ViewPart implements ITeamResourceChangeListener, */ public void createPartControl(Composite parent) { TeamProvider.addListener(this); - Platform.getJobManager().addJobChangeListener(this); + + Platform.getJobManager().addJobChangeListener(new JobChangeAdapter() { + public void done(IJobChangeEvent event) { + if(event.getJob().belongsTo(RefreshSubscriberJob.getFamily())) { + setViewImage(initialImg); + } + } + + public void running(IJobChangeEvent event) { + if(event.getJob().belongsTo(RefreshSubscriberJob.getFamily())) { + setViewImage(refreshingImg); + } + } + }); + initializeActions(); - createViewer(parent, getViewerType()); + createViewer(parent); contributeToActionBars(); this.composite = parent; @@ -198,25 +213,29 @@ public class SyncViewer extends ViewPart implements ITeamResourceChangeListener, refreshingImg = TeamUIPlugin.getImageDescriptor(ISharedImages.IMG_SYNC_MODE_CATCHUP).createImage(); TeamUIPlugin.disposeOnShutdown(initialImg); TeamUIPlugin.disposeOnShutdown(refreshingImg); - viewImage= initialImg; + setViewImage(initialImg); updateTitle(); } - public int getViewerType() { - return viewerType; + private void setViewImage(Image image) { + viewImage = image; + fireSafePropertyChange(IWorkbenchPart.PROP_TITLE); } - + public void switchViewerType(int viewerType) { - if (composite == null || composite.isDisposed()) return; - disposeChildren(composite); - createViewer(composite, viewerType); - composite.layout(); + if(viewerType != currentViewType) { + if (composite == null || composite.isDisposed()) return; + currentViewType = viewerType; + disposeChildren(composite); + createViewer(composite); + composite.layout(); + fireSafePropertyChange(PROP_VIEWTYPE); + } } - private void createViewer(Composite parent, int viewerType) { - this.viewerType = viewerType; - switch(viewerType) { + private void createViewer(Composite parent) { + switch(currentViewType) { case TREE_VIEW: createTreeViewerPartControl(parent); break; @@ -397,6 +416,7 @@ public class SyncViewer extends ViewPart implements ITeamResourceChangeListener, actions = new SyncViewerActions(this); actions.restore(memento); } + public void activateSubscriber(TeamSubscriber subscriber) { SubscriberInput input = (SubscriberInput)subscriberInputs.get(subscriber.getId()); @@ -457,7 +477,7 @@ public class SyncViewer extends ViewPart implements ITeamResourceChangeListener, Display.getDefault().asyncExec(new Runnable() { public void run() { viewer.setInput(input.getFilteredSyncSet()); - RefreshSubscriberJob refreshJob = TeamUIPlugin.getPlugin().getRefreshJob(); + RefreshSubscriberInputJob refreshJob = TeamUIPlugin.getPlugin().getRefreshJob(); refreshJob.setSubscriberInput(input); } }); @@ -521,6 +541,7 @@ public class SyncViewer extends ViewPart implements ITeamResourceChangeListener, SubscriberInput input = (SubscriberInput) it.next(); input.dispose(); } + TeamUIPlugin.getPlugin().getRefreshJob().setSubscriberInput(null); } public void run(IRunnableWithProgress runnable) { @@ -554,7 +575,7 @@ public class SyncViewer extends ViewPart implements ITeamResourceChangeListener, if (memento != null) { Integer i = memento.getInteger(VIEWER_TYPE_MEMENTO_KEY); if (i != null) { - viewerType = i.intValue(); + currentViewType = i.intValue(); } } } @@ -568,6 +589,10 @@ public class SyncViewer extends ViewPart implements ITeamResourceChangeListener, actions.save(memento); } + public int getViewerType() { + return currentViewType; + } + /* * Return the current input for the view. */ @@ -602,6 +627,7 @@ public class SyncViewer extends ViewPart implements ITeamResourceChangeListener, ActionContext context = new ActionContext(null); context.setInput(si); actions.addContext(context); + initializeSubscriberInput(si); } private void removeSubscriber(TeamSubscriber s) { @@ -615,8 +641,8 @@ public class SyncViewer extends ViewPart implements ITeamResourceChangeListener, subscriberInputs.remove(s.getId()); if (si == input && lastInput != null) { - // show last input - initializeSubscriberInput(lastInput); + // show last input + initializeSubscriberInput(lastInput); } } @@ -673,8 +699,10 @@ public class SyncViewer extends ViewPart implements ITeamResourceChangeListener, protected void updateActionBars(IStructuredSelection selection) { if (actions != null) { ActionContext actionContext = actions.getContext(); - actionContext.setSelection(selection); - actions.updateActionBars(); + if(actionContext != null) { + actionContext.setSelection(selection); + actions.updateActionBars(); + } } } @@ -721,27 +749,19 @@ public class SyncViewer extends ViewPart implements ITeamResourceChangeListener, /** * Makes this view visible in the active page. */ - public static void showInActivePage(IWorkbenchPage activePage) { - showInActivePage(activePage, null); - } - - /** - * Makes this view visible in the active page. - */ - public static void showInActivePage(IWorkbenchPage activePage, TeamSubscriber subscriber) { + public static SyncViewer showInActivePage(IWorkbenchPage activePage) { try { if (activePage == null) { activePage = TeamUIPlugin.getActivePage(); - if (activePage == null) return; - } - IViewPart view = activePage.showView(VIEW_ID); - if (subscriber != null && view instanceof SyncViewer) { - ((SyncViewer)view).activateSubscriber(subscriber); + if (activePage == null) return null; } + return (SyncViewer)activePage.showView(VIEW_ID); } catch (PartInitException pe) { TeamUIPlugin.log(new TeamException("error showing view", pe)); + return null; } } + /** * Update the title when either the subscriber or filter sync set changes. */ @@ -749,44 +769,69 @@ public class SyncViewer extends ViewPart implements ITeamResourceChangeListener, updateTitle(); } - /** - * IJobChangeListener overrides. The only one of interest is done so that we can - * change the icon of the view when the refresh jobis running. - */ - public void done(IJobChangeEvent event) { - if(event.getJob().belongsTo(RefreshSubscriberJob.getFamily())) { - viewImage = initialImg; - fireSavePropertyChange(IWorkbenchPart.PROP_TITLE); - } + private void fireSafePropertyChange(final int property) { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + firePropertyChange(property); + } + }); } - - public void running(IJobChangeEvent event) { - if(event.getJob().belongsTo(RefreshSubscriberJob.getFamily())) { - viewImage = refreshingImg; - fireSavePropertyChange(IWorkbenchPart.PROP_TITLE); + + public void setSelection(TeamSubscriber subscriber, IResource[] resources, int viewType) { + switchViewerType(viewType); + List syncResource = new ArrayList(resources.length); + for (int i = 0; i < resources.length; i++) { + syncResource.add(new SyncResource((SyncSet)viewer.getInput(), resources[i])); + } + if(! syncResource.isEmpty()) { + viewer.setSelection(new StructuredSelection(syncResource), true /* reveal */); + if(viewer instanceof AbstractTreeViewer) { + ((AbstractTreeViewer)viewer).expandToLevel(2); + } + } + if(subscriber != null) { + activateSubscriber(subscriber); } } - - public void scheduled(IJobChangeEvent event) { - } - - public void sleeping(IJobChangeEvent event) { + + /** + * 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.getSubscriber().getId().equals(id)) { + initializeSubscriberInput((SubscriberInput)subscriberInputs.get(id)); + } + RefreshAction.run(this, resources, subscriber); + } } - public void aboutToRun(IJobChangeEvent event) { + /** + * Refreshes the resources in the current input for the given subscriber. + */ + public void refreshWithRemote(TeamSubscriber subscriber) { + QualifiedName id = subscriber.getId(); + if(subscriberInputs.containsKey(id)) { + if(! input.getSubscriber().getId().equals(id)) { + initializeSubscriberInput((SubscriberInput)subscriberInputs.get(id)); + } + RefreshAction.run(this, input.roots(), subscriber); + } } - - public void awake(IJobChangeEvent event) { + + /** + * Refreshes the resources in the current input for the given subscriber. + */ + public void refreshWithRemote() { + RefreshAction.run(this, input.roots(), input.getSubscriber()); } - private void fireSavePropertyChange(final int property) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - firePropertyChange(property); - } - }); + public int getCurrentViewType() { + return currentViewType; } - +} public void selectAll() { if (getViewerType() == TABLE_VIEW) { TableViewer table = (TableViewer)getViewer(); diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/TeamUI.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/TeamUI.java index d9f1669cc..20d58102d 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/TeamUI.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/TeamUI.java @@ -12,6 +12,9 @@ package org.eclipse.team.ui; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.team.internal.ui.TeamUIPlugin; +import org.eclipse.team.internal.ui.sync.views.SyncViewer; +import org.eclipse.team.ui.sync.ISyncViewer; +import org.eclipse.ui.IWorkbenchPage; /** * TeamUI contains public API for generic UI-based Team functionality @@ -19,6 +22,14 @@ import org.eclipse.team.internal.ui.TeamUIPlugin; public class TeamUI { // property change types public static String GLOBAL_IGNORES_CHANGED = "global_ignores_changed"; //$NON-NLS-1$ + + /** + * Makes the synchronize view visible in the active page and returns a handle + * to the view. + */ + public static ISyncViewer showSyncViewInActivePage(IWorkbenchPage activePage) { + return SyncViewer.showInActivePage(activePage); + } /** * Register for changes made to Team properties. diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/ISyncViewer.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/ISyncViewer.java new file mode 100644 index 000000000..ef4d0288f --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/sync/ISyncViewer.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * 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; + +import org.eclipse.core.resources.IResource; +import org.eclipse.team.core.subscribers.TeamSubscriber; + +public interface ISyncViewer { + + /** + * View type constant (value 0) indicating that the synchronize view will be shown + * as a tree. + */ + public static final int TREE_VIEW = 0; + + /** + * View type constant (value 1) indicating that the synchronize view will be shown + * as a table. + */ + public static final int TABLE_VIEW = 1; + + /** + * Called to set the current selection in the sync viewer for the given subscriber. The viewType + * parameter determines in which configuration of the view the selection should be made in. If + * there are no resources passed in the given subscriber is activate. + * + * @param resources the resources to select + * @param viewType the view configuration in which to select the resources + */ + public void setSelection(TeamSubscriber subscriber, IResource[] resources, int viewType); + + /** + * Refreshes the resources from the specified subscriber. The working set or filters applied + * to the synchronize view are ignored. + */ + public void refreshWithRemote(TeamSubscriber subscriber, IResource[] resources); + + /** + * Refreshes the resources in the current input for the given subscriber. + */ + public void refreshWithRemote(TeamSubscriber subscriber); + + /** + * Refreshes the active subscriber. + */ + public void refreshWithRemote(); + + /** + * Returns the current view configuration. + */ + public int getCurrentViewType(); +} |