Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 250869 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylyn/internal/context/ui/actions/ContextClearAction.java (-4 / +3 lines)
Lines 15-26 Link Here
15
import org.eclipse.jface.dialogs.MessageDialog;
15
import org.eclipse.jface.dialogs.MessageDialog;
16
import org.eclipse.mylyn.context.core.ContextCore;
16
import org.eclipse.mylyn.context.core.ContextCore;
17
import org.eclipse.mylyn.internal.context.ui.commands.ClearContextHandler;
17
import org.eclipse.mylyn.internal.context.ui.commands.ClearContextHandler;
18
import org.eclipse.mylyn.internal.provisional.commons.ui.WorkbenchUtil;
18
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
19
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
19
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
20
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
20
import org.eclipse.mylyn.tasks.core.ITask;
21
import org.eclipse.mylyn.tasks.core.ITask;
21
import org.eclipse.mylyn.tasks.ui.TasksUiImages;
22
import org.eclipse.mylyn.tasks.ui.TasksUiImages;
22
import org.eclipse.ui.IViewPart;
23
import org.eclipse.ui.IViewPart;
23
import org.eclipse.ui.PlatformUI;
24
24
25
/**
25
/**
26
 * @author Mik Kersten
26
 * @author Mik Kersten
Lines 58-66 Link Here
58
	}
58
	}
59
59
60
	public boolean run(ITask task) {
60
	public boolean run(ITask task) {
61
		boolean deleteConfirmed = MessageDialog.openQuestion(PlatformUI.getWorkbench()
61
		boolean deleteConfirmed = MessageDialog.openQuestion(WorkbenchUtil.getShell(),
62
				.getActiveWorkbenchWindow()
62
				Messages.ContextClearAction_Confirm_clear_context,
63
				.getShell(), Messages.ContextClearAction_Confirm_clear_context,
64
				Messages.ContextClearAction_Clear_the_context_for_the_selected_task);
63
				Messages.ContextClearAction_Clear_the_context_for_the_selected_task);
65
		if (!deleteConfirmed) {
64
		if (!deleteConfirmed) {
66
			return false;
65
			return false;
(-)src/org/eclipse/mylyn/internal/context/ui/actions/ContextRetrieveAction.java (-11 / +7 lines)
Lines 19-33 Link Here
19
import org.eclipse.mylyn.internal.context.ui.commands.RetrieveContextAttachmentHandler;
19
import org.eclipse.mylyn.internal.context.ui.commands.RetrieveContextAttachmentHandler;
20
import org.eclipse.mylyn.internal.context.ui.commands.RetrieveContextHandler;
20
import org.eclipse.mylyn.internal.context.ui.commands.RetrieveContextHandler;
21
import org.eclipse.mylyn.internal.context.ui.wizards.ContextRetrieveWizard;
21
import org.eclipse.mylyn.internal.context.ui.wizards.ContextRetrieveWizard;
22
import org.eclipse.mylyn.internal.provisional.commons.ui.WorkbenchUtil;
22
import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
23
import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
23
import org.eclipse.mylyn.internal.tasks.ui.util.AttachmentUtil;
24
import org.eclipse.mylyn.internal.tasks.ui.util.AttachmentUtil;
24
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
25
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
25
import org.eclipse.mylyn.tasks.core.ITask;
26
import org.eclipse.mylyn.tasks.core.ITask;
26
import org.eclipse.mylyn.tasks.ui.TasksUiImages;
27
import org.eclipse.mylyn.tasks.ui.TasksUiImages;
27
import org.eclipse.swt.widgets.Shell;
28
import org.eclipse.ui.IViewActionDelegate;
28
import org.eclipse.ui.IViewActionDelegate;
29
import org.eclipse.ui.IViewPart;
29
import org.eclipse.ui.IViewPart;
30
import org.eclipse.ui.PlatformUI;
31
30
32
/**
31
/**
33
 * @author Mik Kersten
32
 * @author Mik Kersten
Lines 67-81 Link Here
67
66
68
	public void run(ITask task) {
67
	public void run(ITask task) {
69
		ContextRetrieveWizard wizard = new ContextRetrieveWizard(task);
68
		ContextRetrieveWizard wizard = new ContextRetrieveWizard(task);
70
		Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
69
		WizardDialog dialog = new WizardDialog(WorkbenchUtil.getShell(), wizard);
71
		if (shell != null && !shell.isDisposed()) {
70
		dialog.create();
72
			WizardDialog dialog = new WizardDialog(shell, wizard);
71
		dialog.setBlockOnOpen(true);
73
			dialog.create();
72
		if (dialog.open() == Window.CANCEL) {
74
			dialog.setBlockOnOpen(true);
73
			dialog.close();
75
			if (dialog.open() == Window.CANCEL) {
74
			return;
76
				dialog.close();
77
				return;
78
			}
79
		}
75
		}
80
	}
76
	}
81
77
(-)src/org/eclipse/mylyn/internal/context/ui/actions/ContextAttachAction.java (-13 / +8 lines)
Lines 20-35 Link Here
20
import org.eclipse.mylyn.context.core.ContextCore;
20
import org.eclipse.mylyn.context.core.ContextCore;
21
import org.eclipse.mylyn.internal.context.ui.commands.AttachContextHandler;
21
import org.eclipse.mylyn.internal.context.ui.commands.AttachContextHandler;
22
import org.eclipse.mylyn.internal.context.ui.wizards.ContextAttachWizard;
22
import org.eclipse.mylyn.internal.context.ui.wizards.ContextAttachWizard;
23
import org.eclipse.mylyn.internal.provisional.commons.ui.WorkbenchUtil;
23
import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
24
import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
24
import org.eclipse.mylyn.internal.tasks.ui.util.AttachmentUtil;
25
import org.eclipse.mylyn.internal.tasks.ui.util.AttachmentUtil;
25
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
26
import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView;
26
import org.eclipse.mylyn.tasks.core.ITask;
27
import org.eclipse.mylyn.tasks.core.ITask;
27
import org.eclipse.mylyn.tasks.core.ITask.SynchronizationState;
28
import org.eclipse.mylyn.tasks.core.ITask.SynchronizationState;
28
import org.eclipse.mylyn.tasks.ui.TasksUiImages;
29
import org.eclipse.mylyn.tasks.ui.TasksUiImages;
29
import org.eclipse.swt.widgets.Shell;
30
import org.eclipse.ui.IViewActionDelegate;
30
import org.eclipse.ui.IViewActionDelegate;
31
import org.eclipse.ui.IViewPart;
31
import org.eclipse.ui.IViewPart;
32
import org.eclipse.ui.PlatformUI;
33
32
34
/**
33
/**
35
 * @author Mik Kersten
34
 * @author Mik Kersten
Lines 71-92 Link Here
71
70
72
	public void run(ITask task) {
71
	public void run(ITask task) {
73
		if (task.getSynchronizationState() != SynchronizationState.SYNCHRONIZED) {
72
		if (task.getSynchronizationState() != SynchronizationState.SYNCHRONIZED) {
74
			MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
73
			MessageDialog.openInformation(WorkbenchUtil.getShell(), Messages.ContextAttachAction_Context_Attachment,
75
					Messages.ContextAttachAction_Context_Attachment,
76
					Messages.ContextAttachAction_Task_must_be_synchronized_before_attaching_context);
74
					Messages.ContextAttachAction_Task_must_be_synchronized_before_attaching_context);
77
			return;
75
			return;
78
		}
76
		}
79
77
80
		ContextAttachWizard wizard = new ContextAttachWizard(task);
78
		ContextAttachWizard wizard = new ContextAttachWizard(task);
81
		Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
79
		WizardDialog dialog = new WizardDialog(WorkbenchUtil.getShell(), wizard);
82
		if (shell != null && !shell.isDisposed()) {
80
		dialog.create();
83
			WizardDialog dialog = new WizardDialog(shell, wizard);
81
		dialog.setBlockOnOpen(true);
84
			dialog.create();
82
		if (dialog.open() == Window.CANCEL) {
85
			dialog.setBlockOnOpen(true);
83
			dialog.close();
86
			if (dialog.open() == Window.CANCEL) {
84
			return;
87
				dialog.close();
88
				return;
89
			}
90
		}
85
		}
91
	}
86
	}
92
87
(-)src/org/eclipse/mylyn/internal/context/ui/ContextUiPlugin.java (-9 / +4 lines)
Lines 30-36 Link Here
30
import org.eclipse.core.runtime.IStatus;
30
import org.eclipse.core.runtime.IStatus;
31
import org.eclipse.core.runtime.Platform;
31
import org.eclipse.core.runtime.Platform;
32
import org.eclipse.core.runtime.Status;
32
import org.eclipse.core.runtime.Status;
33
import org.eclipse.jface.dialogs.MessageDialog;
34
import org.eclipse.jface.preference.IPreferenceStore;
33
import org.eclipse.jface.preference.IPreferenceStore;
35
import org.eclipse.jface.resource.ImageDescriptor;
34
import org.eclipse.jface.resource.ImageDescriptor;
36
import org.eclipse.jface.text.TextSelection;
35
import org.eclipse.jface.text.TextSelection;
Lines 47-53 Link Here
47
import org.eclipse.mylyn.context.core.IInteractionRelation;
46
import org.eclipse.mylyn.context.core.IInteractionRelation;
48
import org.eclipse.mylyn.context.ui.AbstractContextUiBridge;
47
import org.eclipse.mylyn.context.ui.AbstractContextUiBridge;
49
import org.eclipse.mylyn.context.ui.IContextUiStartup;
48
import org.eclipse.mylyn.context.ui.IContextUiStartup;
49
import org.eclipse.mylyn.internal.context.ui.wizards.RetrieveLatestContextDialog;
50
import org.eclipse.mylyn.internal.monitor.ui.MonitorUiPlugin;
50
import org.eclipse.mylyn.internal.monitor.ui.MonitorUiPlugin;
51
import org.eclipse.mylyn.internal.provisional.commons.ui.WorkbenchUtil;
51
import org.eclipse.mylyn.monitor.ui.MonitorUi;
52
import org.eclipse.mylyn.monitor.ui.MonitorUi;
52
import org.eclipse.mylyn.tasks.core.ITask;
53
import org.eclipse.mylyn.tasks.core.ITask;
53
import org.eclipse.mylyn.tasks.core.ITaskActivationListener;
54
import org.eclipse.mylyn.tasks.core.ITaskActivationListener;
Lines 185-191 Link Here
185
186
186
	private static final ITaskActivationListener TASK_ACTIVATION_LISTENER = new TaskActivationAdapter() {
187
	private static final ITaskActivationListener TASK_ACTIVATION_LISTENER = new TaskActivationAdapter() {
187
188
188
		@SuppressWarnings( { "deprecation", "restriction" })
189
		@SuppressWarnings( { "restriction" })
189
		@Override
190
		@Override
190
		public void taskActivated(ITask task) {
191
		public void taskActivated(ITask task) {
191
			if (CoreUtil.TEST_MODE) {
192
			if (CoreUtil.TEST_MODE) {
Lines 196-208 Link Here
196
			boolean hasLocalContext = ContextCore.getContextManager().hasContext(task.getHandleIdentifier());
197
			boolean hasLocalContext = ContextCore.getContextManager().hasContext(task.getHandleIdentifier());
197
			if (!hasLocalContext) {
198
			if (!hasLocalContext) {
198
				if (org.eclipse.mylyn.internal.tasks.ui.util.AttachmentUtil.hasContextAttachment(task)) {
199
				if (org.eclipse.mylyn.internal.tasks.ui.util.AttachmentUtil.hasContextAttachment(task)) {
199
					boolean getRemote = MessageDialog.openQuestion(PlatformUI.getWorkbench()
200
					RetrieveLatestContextDialog.openQuestion(WorkbenchUtil.getShell(), task);
200
							.getActiveWorkbenchWindow()
201
							.getShell(), Messages.ContextUiPlugin_Task_Activation,
202
							Messages.ContextUiPlugin_No_local_task_context_exists);
203
					if (getRemote) {
204
						new org.eclipse.mylyn.internal.context.ui.actions.ContextRetrieveAction().run(task);
205
					}
206
				}
201
				}
207
			}
202
			}
208
		}
203
		}
(-)src/org/eclipse/mylyn/internal/context/ui/wizards/RetrieveLatestContextDialog.java (+177 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Tasktop Technologies and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Tasktop Technologies - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylyn.internal.context.ui.wizards;
13
14
import java.util.Collections;
15
import java.util.Date;
16
import java.util.List;
17
import java.util.Map;
18
19
import org.eclipse.jface.dialogs.IDialogConstants;
20
import org.eclipse.jface.dialogs.MessageDialog;
21
import org.eclipse.jface.layout.GridDataFactory;
22
import org.eclipse.jface.layout.GridLayoutFactory;
23
import org.eclipse.jface.wizard.ProgressMonitorPart;
24
import org.eclipse.jface.wizard.WizardDialog;
25
import org.eclipse.mylyn.internal.provisional.commons.ui.WorkbenchUtil;
26
import org.eclipse.mylyn.internal.tasks.ui.util.AttachmentUtil;
27
import org.eclipse.mylyn.tasks.core.ITask;
28
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
29
import org.eclipse.mylyn.tasks.core.TaskRepository;
30
import org.eclipse.mylyn.tasks.ui.TasksUi;
31
import org.eclipse.osgi.util.NLS;
32
import org.eclipse.swt.SWT;
33
import org.eclipse.swt.events.SelectionAdapter;
34
import org.eclipse.swt.events.SelectionEvent;
35
import org.eclipse.swt.graphics.Image;
36
import org.eclipse.swt.widgets.Composite;
37
import org.eclipse.swt.widgets.Control;
38
import org.eclipse.swt.widgets.Link;
39
import org.eclipse.swt.widgets.Shell;
40
41
import com.ibm.icu.text.DateFormat;
42
43
/**
44
 * @author Steffen Pingel
45
 */
46
public class RetrieveLatestContextDialog extends MessageDialog {
47
48
	public static boolean openQuestion(Shell shell, ITask task) {
49
		String title = Messages.RetrieveLatestContextDialog_Task_Activation0;
50
		TaskRepository repository = TasksUi.getRepositoryManager().getRepository(task.getConnectorKind(),
51
				task.getRepositoryUrl());
52
		List<ITaskAttachment> contextAttachments = AttachmentUtil.getContextAttachments(repository, task);
53
		Collections.sort(contextAttachments, new TaskAttachmentComparator());
54
		if (contextAttachments.size() > 0) {
55
			ITaskAttachment attachment = contextAttachments.get(0);
56
			String author = null;
57
			if (attachment.getAuthor() != null) {
58
				author = (attachment.getAuthor().getName()) != null ? attachment.getAuthor().getName()
59
						: attachment.getAuthor().getPersonId();
60
			}
61
			if (author == null) {
62
				author = Messages.RetrieveLatestContextDialog_Task_ActivationUnknown;
63
			}
64
			Date date = attachment.getCreationDate();
65
			String dateString = null;
66
			if (date != null) {
67
				dateString = DateFormat.getDateInstance(DateFormat.LONG).format(date);
68
			}
69
			if (dateString == null) {
70
				dateString = Messages.RetrieveLatestContextDialog_Task_ActivationUnknown;
71
			}
72
			String message = NLS.bind(Messages.RetrieveLatestContextDialog_Task_ActivationNo_local_context, author,
73
					dateString);
74
			int kind = QUESTION;
75
			int style = SWT.NONE;
76
77
			RetrieveLatestContextDialog dialog = new RetrieveLatestContextDialog(shell, title, null, message, kind,
78
					new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 0, task, attachment);
79
			style &= SWT.SHEET;
80
			dialog.setShellStyle(dialog.getShellStyle() | style);
81
			return dialog.open() == 0;
82
		}
83
		return false;
84
	}
85
86
	private final ITaskAttachment attachment;
87
88
	private Link link;
89
90
	private ProgressContainer progressContainer;
91
92
	private ProgressMonitorPart progressMonitorPart;
93
94
	private final ITask task;
95
96
	public RetrieveLatestContextDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage,
97
			String dialogMessage, int dialogImageType, String[] dialogButtonLabels, int defaultIndex, ITask task,
98
			ITaskAttachment attachment) {
99
		super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, dialogImageType, dialogButtonLabels,
100
				defaultIndex);
101
		this.task = task;
102
		this.attachment = attachment;
103
	}
104
105
	@Override
106
	protected void buttonPressed(int buttonId) {
107
		if (progressContainer.isActive()) {
108
			return;
109
		}
110
		if (buttonId == 0) {
111
			if (!AttachmentUtil.downloadContext(task, attachment, progressContainer)) {
112
				// failed
113
				return;
114
			}
115
		}
116
		super.buttonPressed(buttonId);
117
	}
118
119
	@Override
120
	protected Control createButtonBar(Composite parent) {
121
		Composite composite = new Composite(parent, SWT.NONE);
122
		composite.setLayout(GridLayoutFactory.fillDefaults().numColumns(3).create());
123
		GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(composite);
124
		Control control = createLink(composite);
125
		GridDataFactory.fillDefaults().grab(true, false).applyTo(control);
126
		super.createButtonBar(composite);
127
		return composite;
128
	}
129
130
	@Override
131
	protected Control createContents(Composite parent) {
132
		Control control = super.createContents(parent);
133
		progressContainer.setCancelButton(getButton(1));
134
		getButton(0).setFocus();
135
		return control;
136
	}
137
138
	@Override
139
	protected Control createCustomArea(Composite parent) {
140
		progressMonitorPart = new ProgressMonitorPart(parent, null);
141
		GridDataFactory.fillDefaults().grab(true, false).applyTo(progressMonitorPart);
142
		progressContainer = new ProgressContainer(getShell(), progressMonitorPart) {
143
			@Override
144
			protected void restoreUiState(Map<Object, Object> state) {
145
				link.setEnabled(true);
146
				getButton(0).setEnabled(true);
147
				getButton(1).setEnabled(true);
148
			};
149
150
			@Override
151
			protected void saveUiState(Map<Object, Object> savedState) {
152
				link.setEnabled(false);
153
				getButton(0).setEnabled(false);
154
			};
155
		};
156
		return progressMonitorPart;
157
	}
158
159
	protected Control createLink(Composite parent) {
160
		link = new Link(parent, SWT.NONE);
161
		link.setText(Messages.RetrieveLatestContextDialog_Task_ActivationSelect_from_history);
162
		link.addSelectionListener(new SelectionAdapter() {
163
			@Override
164
			public void widgetSelected(SelectionEvent e) {
165
				close();
166
167
				ContextRetrieveWizard wizard = new ContextRetrieveWizard(task);
168
				WizardDialog dialog = new WizardDialog(WorkbenchUtil.getShell(), wizard);
169
				dialog.create();
170
				dialog.setBlockOnOpen(true);
171
				setReturnCode(dialog.open());
172
			}
173
		});
174
		return link;
175
	}
176
177
}
(-)src/org/eclipse/mylyn/internal/context/ui/wizards/TaskAttachmentComparator.java (+35 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Tasktop Technologies and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Tasktop Technologies - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylyn.internal.context.ui.wizards;
13
14
import java.util.Comparator;
15
import java.util.Date;
16
17
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
18
19
class TaskAttachmentComparator implements Comparator<ITaskAttachment> {
20
	public int compare(ITaskAttachment attachment1, ITaskAttachment attachment2) {
21
		Date created1 = null;
22
		Date created2 = null;
23
		created1 = attachment1.getCreationDate();
24
		created2 = attachment2.getCreationDate();
25
		if (created1 != null && created2 != null) {
26
			return (-1) * created1.compareTo(created2);
27
		} else if (created1 == null && created2 != null) {
28
			return 1;
29
		} else if (created1 != null && created2 == null) {
30
			return -1;
31
		} else {
32
			return 0;
33
		}
34
	}
35
}

Return to bug 250869