From 94848b90454157b7ddec0439c0e78fdeacec134e Mon Sep 17 00:00:00 2001 From: Jean Michel-Lemieux Date: Tue, 27 Apr 2004 19:45:10 +0000 Subject: Improving progress support --- .../eclipse/team/internal/ui/messages.properties | 4 +- .../synchronize/RefreshUserNotificationPolicy.java | 68 ++++++++++------------ ...RefreshUserNotificationPolicyInModalDialog.java | 23 ++++---- .../internal/ui/synchronize/WorkbenchAction.java | 28 +++++++++ .../subscribers/IRefreshSubscriberListener.java | 3 +- .../subscribers/RefreshSubscriberJob.java | 10 +--- .../subscribers/SubscriberParticipant.java | 34 ++++++++--- .../subscribers/SubscriberRefreshSchedule.java | 3 +- 8 files changed, 102 insertions(+), 71 deletions(-) create mode 100644 bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/WorkbenchAction.java 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 4cfb8f931..b0b610f1b 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 @@ -322,8 +322,8 @@ Utils.25=Conflicting Utils.26=unknown mode RefreshCompleteDialog.4=Synchronize Complete - {0} RefreshCompleteDialog.4a=Scheduled Synchronize Complete - {0} -RefreshCompleteDialog.5=Changes found. {0} currently has {1} outgoing, {2} incoming, and {3} conflicting changes. -RefreshCompleteDialog.5a={0} new changes found. {1} currently has {2} outgoing, {3} incoming, and {4} conflicting changes. +RefreshCompleteDialog.5={0} changes. +RefreshCompleteDialog.5a={0} new changes found. RefreshCompleteDialog.6=No changes found. RefreshCompleteDialog.17=Details >> RefreshCompleteDialog.18=<< Details diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/RefreshUserNotificationPolicy.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/RefreshUserNotificationPolicy.java index aef5e03a1..4c0b2da56 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/RefreshUserNotificationPolicy.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/RefreshUserNotificationPolicy.java @@ -6,13 +6,12 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.Status; import org.eclipse.swt.widgets.Shell; import org.eclipse.team.core.synchronize.SyncInfo; -import org.eclipse.team.internal.ui.IPreferenceIds; import org.eclipse.team.internal.ui.TeamUIPlugin; import org.eclipse.team.ui.TeamUI; import org.eclipse.team.ui.synchronize.ISynchronizeView; import org.eclipse.team.ui.synchronize.SyncInfoCompareInput; import org.eclipse.team.ui.synchronize.subscribers.*; -import org.eclipse.ui.internal.WorkbenchPlugin; +import org.eclipse.ui.actions.ActionFactory; /** * This class manages the notification and setup that occurs after a refresh is completed. @@ -46,50 +45,47 @@ public class RefreshUserNotificationPolicy implements IRefreshSubscriberListener * (non-Javadoc) * @see org.eclipse.team.internal.ui.jobs.IRefreshSubscriberListener#refreshDone(org.eclipse.team.internal.ui.jobs.IRefreshEvent) */ - public Runnable refreshDone(final IRefreshEvent event) { + public ActionFactory.IWorkbenchAction refreshDone(final IRefreshEvent event) { // Ensure that this event was generated for this participant if (event.getSubscriber() != participant.getSubscriberSyncInfoCollector().getSubscriber()) return null; // If the event is for a cancelled operation, there's nothing to do int severity = event.getStatus().getSeverity(); if(severity == Status.CANCEL || severity == Status.ERROR) return null; // Decide on what action to take after the refresh is completed - return new Runnable() { + return new WorkbenchAction() { public void run() { - boolean prompt = true; - if(WorkbenchPlugin.getDefault().getPreferenceStore().getBoolean("USE_NEW_PROGRESS")) { - prompt = event.getStatus().getCode() == IRefreshEvent.STATUS_NO_CHANGES; - } else { - if(event.getRefreshType() == IRefreshEvent.USER_REFRESH) { - prompt = TeamUIPlugin.getPlugin().getPreferenceStore().getBoolean(IPreferenceIds.SYNCHRONIZING_COMPLETE_SHOW_DIALOG); - } else { - prompt = TeamUIPlugin.getPlugin().getPreferenceStore().getBoolean(IPreferenceIds.SYNCHRONIZING_SCHEDULED_COMPLETE_SHOW_DIALOG); - } - } + boolean prompt = (event.getStatus().getCode() == IRefreshEvent.STATUS_NO_CHANGES); - SyncInfo[] infos = event.getChanges(); - List selectedResources = new ArrayList(); - selectedResources.addAll(Arrays.asList(event.getResources())); - for (int i = 0; i < infos.length; i++) { - selectedResources.add(infos[i].getLocal()); - } - IResource[] resources = (IResource[]) selectedResources.toArray(new IResource[selectedResources.size()]); - - // If it's a file, simply show the compare editor - if (resources.length == 1 && resources[0].getType() == IResource.FILE) { - IResource file = resources[0]; - SyncInfo info = participant.getSubscriberSyncInfoCollector().getSubscriberSyncInfoSet().getSyncInfo(file); - if(info != null) { - SyncInfoCompareInput input = new SyncInfoCompareInput(participant.getName(), info); - CompareUI.openCompareEditor(input); - prompt = false; - } + SyncInfo[] infos = event.getChanges(); + List selectedResources = new ArrayList(); + selectedResources.addAll(Arrays.asList(event.getResources())); + for (int i = 0; i < infos.length; i++) { + selectedResources.add(infos[i].getLocal()); + } + IResource[] resources = (IResource[]) selectedResources.toArray(new IResource[selectedResources.size()]); + + // If it's a file, simply show the compare editor + if (resources.length == 1 && resources[0].getType() == IResource.FILE) { + IResource file = resources[0]; + SyncInfo info = participant.getSubscriberSyncInfoCollector().getSubscriberSyncInfoSet().getSyncInfo(file); + if(info != null) { + SyncInfoCompareInput input = new SyncInfoCompareInput(participant.getName(), info); + CompareUI.openCompareEditor(input); + prompt = false; } - - // Prompt user if preferences are set for this type of refresh. - if (prompt) { - notifyIfNeededModal(event); + } + + // Prompt user if preferences are set for this type of refresh. + if (prompt) { + notifyIfNeededModal(event); + } else { + // Else simply show the synchronize view + ISynchronizeView view = TeamUI.getSynchronizeManager().showSynchronizeViewInActivePage(); + if(view != null) { + view.display(participant); } - } + } + } }; } diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/RefreshUserNotificationPolicyInModalDialog.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/RefreshUserNotificationPolicyInModalDialog.java index d085902cf..646dc07d8 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/RefreshUserNotificationPolicyInModalDialog.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/RefreshUserNotificationPolicyInModalDialog.java @@ -25,6 +25,7 @@ import org.eclipse.team.internal.ui.Utils; import org.eclipse.team.ui.TeamUI; import org.eclipse.team.ui.synchronize.*; import org.eclipse.team.ui.synchronize.subscribers.*; +import org.eclipse.ui.actions.ActionFactory; public class RefreshUserNotificationPolicyInModalDialog implements IRefreshSubscriberListener { @@ -44,7 +45,7 @@ public class RefreshUserNotificationPolicyInModalDialog implements IRefreshSubsc public void refreshStarted(IRefreshEvent event) { } - public Runnable refreshDone(final IRefreshEvent event) { + public ActionFactory.IWorkbenchAction refreshDone(final IRefreshEvent event) { // Ensure that this event was generated for this participant if (event.getSubscriber() != participant.getSubscriberSyncInfoCollector().getSubscriber()) return null; @@ -53,23 +54,19 @@ public class RefreshUserNotificationPolicyInModalDialog implements IRefreshSubsc if(severity == Status.CANCEL || severity == Status.ERROR) return null; - return new Runnable() { - public void run() { - try { + return new WorkbenchAction() { + public void run() { // If there are no changes if (!areChanges()) { MessageDialog.openInformation(shell, Policy.bind("OpenComparedDialog.noChangeTitle"), Policy.bind("OpenComparedDialog.noChangesMessage")); //$NON-NLS-1$ //$NON-NLS-2$ return; } - //if (isSingleFileCompare(event.getResources())) { - // compareAndOpenEditors(event, participant); - //} else { - compareAndOpenDialog(event, participant); - //} - } finally { - if (TeamUI.getSynchronizeManager().get(participant.getId(), participant.getSecondaryId()) == null) { - participant.dispose(); - } + compareAndOpenDialog(event, participant); + setEnabled(false); + } + public void dispose() { + if (TeamUI.getSynchronizeManager().get(participant.getId(), participant.getSecondaryId()) == null) { + participant.dispose(); } } }; diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/WorkbenchAction.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/WorkbenchAction.java new file mode 100644 index 000000000..fc1f5f500 --- /dev/null +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/WorkbenchAction.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * 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.synchronize; + +import org.eclipse.jface.action.Action; +import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction; + +/** + * Class used as goto actions for synchronize jobs. + * + * @since 3.0 + */ +public class WorkbenchAction extends Action implements IWorkbenchAction { + + /* (non-Javadoc) + * @see org.eclipse.ui.actions.ActionFactory.IWorkbenchAction#dispose() + */ + public void dispose() { + } +} diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/subscribers/IRefreshSubscriberListener.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/subscribers/IRefreshSubscriberListener.java index 617bbe322..d8c3123d6 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/subscribers/IRefreshSubscriberListener.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/subscribers/IRefreshSubscriberListener.java @@ -13,6 +13,7 @@ package org.eclipse.team.ui.synchronize.subscribers; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.team.core.subscribers.Subscriber; +import org.eclipse.ui.actions.ActionFactory; /** * Callback interface for clients interested in being notified about the lifecycle of @@ -39,5 +40,5 @@ public interface IRefreshSubscriberListener { * * @param event the event describing the result of the refresh. */ - public Runnable refreshDone(IRefreshEvent event); + public ActionFactory.IWorkbenchAction refreshDone(IRefreshEvent event); } \ No newline at end of file diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/subscribers/RefreshSubscriberJob.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/subscribers/RefreshSubscriberJob.java index a70e1f0de..4b2a7baa3 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/subscribers/RefreshSubscriberJob.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/subscribers/RefreshSubscriberJob.java @@ -62,7 +62,6 @@ public final class RefreshSubscriberJob extends WorkspaceJob { */ private IResource[] resources; private Subscriber subscriber; - //private SubscriberSyncInfoCollector collector; /** * Refresh started/completed listener for every refresh @@ -134,14 +133,7 @@ public final class RefreshSubscriberJob extends WorkspaceJob { */ public boolean shouldRun() { // Ensure that any progress shown as a result of this refresh occurs hidden in a progress group. - boolean shouldRun = getSubscriber() != null; - if(shouldRun && getCollector() != null) { - IProgressMonitor group = Platform.getJobManager().createProgressGroup(); - group.beginTask(getName(), 100); //$NON-NLS-1$ - setProgressGroup(group, 80); - collector.setProgressGroup(group, 20); - } - return shouldRun; + return getSubscriber() != null; } public boolean belongsTo(Object family) { diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/subscribers/SubscriberParticipant.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/subscribers/SubscriberParticipant.java index 2d434c042..73773e935 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/subscribers/SubscriberParticipant.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/subscribers/SubscriberParticipant.java @@ -14,6 +14,7 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.*; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.jface.viewers.StructuredSelection; @@ -27,7 +28,7 @@ import org.eclipse.team.internal.ui.synchronize.*; import org.eclipse.team.ui.TeamUI; import org.eclipse.team.ui.synchronize.*; import org.eclipse.ui.*; -import org.eclipse.ui.internal.WorkbenchPlugin; +import org.eclipse.ui.actions.ActionFactory; import org.eclipse.ui.internal.progress.ProgressManager; import org.eclipse.ui.part.IPageBookViewPage; import org.eclipse.ui.progress.UIJob; @@ -167,19 +168,26 @@ public abstract class SubscriberParticipant extends AbstractSynchronizeParticipa } private void internalRefresh(IResource[] resources, final IRefreshSubscriberListener listener, String taskName, IWorkbenchSite site) { - final Runnable[] gotoAction = new Runnable[] {null}; + final IAction[] gotoAction = new IAction[] {null}; final RefreshSubscriberJob job = new RefreshSubscriberJob(taskName, resources, collector.getSubscriber()); + IProgressMonitor group = Platform.getJobManager().createProgressGroup(); + group.beginTask(taskName + " " + getName(), 100); + job.setProgressGroup(group, 80); + collector.setProgressGroup(group, 20); job.setUser(true); job.setSubscriberCollector(collector); job.setProperty(new QualifiedName("org.eclipse.ui.workbench.progress", "icon"), getImageDescriptor()); - job.setProperty(new QualifiedName("org.eclipse.ui.workbench.progress", "goto"), new Action() { + job.setProperty(new QualifiedName("org.eclipse.ui.workbench.progress", "goto"), new WorkbenchAction() { public void run() { if(gotoAction[0] != null) { gotoAction[0].run(); } } public boolean isEnabled() { - return gotoAction[0] != null; + if(gotoAction[0] != null) { + return gotoAction[0].isEnabled(); + } + return false; } }); // Listener delagate @@ -189,7 +197,7 @@ public abstract class SubscriberParticipant extends AbstractSynchronizeParticipa listener.refreshStarted(event); } } - public Runnable refreshDone(IRefreshEvent event) { + public ActionFactory.IWorkbenchAction refreshDone(IRefreshEvent event) { if(listener != null) { // Update the progress properties. Only keep the synchronize if the operation is non-modal. Boolean modelProperty = (Boolean)job.getProperty(ProgressManager.PROPERTY_IN_DIALOG); @@ -198,12 +206,11 @@ public abstract class SubscriberParticipant extends AbstractSynchronizeParticipa isModal = modelProperty.booleanValue(); } - Runnable runnable = listener.refreshDone(event); + ActionFactory.IWorkbenchAction runnable = listener.refreshDone(event); // If the job is being run modally then simply prompt the user immediatly - boolean newProgressSupport = WorkbenchPlugin.getDefault().getPreferenceStore().getBoolean("USE_NEW_PROGRESS"); - if(isModal || ! newProgressSupport) { + if(isModal) { if(runnable != null) { - final Runnable[] r = new Runnable[] {runnable}; + final IAction[] r = new IAction[] {runnable}; Job update = new UIJob("") { public IStatus runInUIThread(IProgressMonitor monitor) { r[0].run(); @@ -217,6 +224,15 @@ public abstract class SubscriberParticipant extends AbstractSynchronizeParticipa // to perform the results. } else { gotoAction[0] = runnable; + gotoAction[0].setEnabled(runnable.isEnabled()); + runnable.addPropertyChangeListener(new IPropertyChangeListener() { + public void propertyChange(PropertyChangeEvent event) { + if(event.getProperty().equals(IAction.ENABLED)) { + Boolean bool = (Boolean) event.getNewValue(); + gotoAction[0].setEnabled(bool.booleanValue()); + } + } + }); } RefreshSubscriberJob.removeRefreshListener(this); } diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/subscribers/SubscriberRefreshSchedule.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/subscribers/SubscriberRefreshSchedule.java index 48f397dfd..32a540199 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/subscribers/SubscriberRefreshSchedule.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/subscribers/SubscriberRefreshSchedule.java @@ -10,6 +10,7 @@ import org.eclipse.team.internal.ui.Policy; import org.eclipse.team.internal.ui.TeamUIPlugin; import org.eclipse.team.internal.ui.synchronize.RefreshUserNotificationPolicy; import org.eclipse.ui.IMemento; +import org.eclipse.ui.actions.ActionFactory; /** * Schedule to refresh a subscriber at a specified interval. The schedule can be disabled or enabled @@ -41,7 +42,7 @@ public class SubscriberRefreshSchedule { private IRefreshSubscriberListener refreshSubscriberListener = new IRefreshSubscriberListener() { public void refreshStarted(IRefreshEvent event) { } - public Runnable refreshDone(final IRefreshEvent event) { + public ActionFactory.IWorkbenchAction refreshDone(final IRefreshEvent event) { if (event.getSubscriber() == participant.getSubscriber()) { lastRefreshEvent = event; if(enabled && event.getRefreshType() == IRefreshEvent.SCHEDULED_REFRESH) { -- cgit v1.2.3