Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Davis2015-05-01 21:09:27 +0000
committerGerrit Code Review @ Eclipse.org2015-05-08 22:48:04 +0000
commit205f1647ae9890189f910d640a201eca548cb2a3 (patch)
tree36b07ddf6571487a7f8e703dbf35d1a3de7c8c3d
parent6edf650671f7b35b5abc0533fc23d5b3bb9a5e67 (diff)
downloadorg.eclipse.mylyn.tasks-205f1647ae9890189f910d640a201eca548cb2a3.tar.gz
org.eclipse.mylyn.tasks-205f1647ae9890189f910d640a201eca548cb2a3.tar.xz
org.eclipse.mylyn.tasks-205f1647ae9890189f910d640a201eca548cb2a3.zip
452674: don't call dirtyStateChanged when form is dirty
Change-Id: Ie7d2176235557b34590ab254b361c87c2450628d Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=452674
-rw-r--r--org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/tasks/ui/editors/AbstractTaskEditorPageTest.java95
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractTaskEditorPage.java2
2 files changed, 96 insertions, 1 deletions
diff --git a/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/tasks/ui/editors/AbstractTaskEditorPageTest.java b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/tasks/ui/editors/AbstractTaskEditorPageTest.java
new file mode 100644
index 000000000..355ff55be
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/tasks/ui/editors/AbstractTaskEditorPageTest.java
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Tasktop Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.tasks.ui.editors;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.mylyn.tasks.core.ITask;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.core.data.ITaskDataWorkingCopy;
+import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
+import org.eclipse.mylyn.tasks.core.data.TaskData;
+import org.eclipse.mylyn.tasks.core.data.TaskDataModel;
+import org.eclipse.mylyn.tasks.tests.TaskTestUtil;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.handlers.IHandlerService;
+import org.junit.Before;
+import org.junit.Test;
+
+public class AbstractTaskEditorPageTest {
+ public class TestAbstractTaskEditorPage extends AbstractTaskEditorPage {
+ private TestAbstractTaskEditorPage(TaskEditor editor, String connectorKind) {
+ super(editor, connectorKind);
+ }
+
+ @Override
+ protected TaskDataModel createModel(final TaskEditorInput input) throws CoreException {
+ TaskDataModel model = spy(new TaskDataModel(input.getTaskRepository(), input.getTask(),
+ mock(ITaskDataWorkingCopy.class)));
+ when(model.getTaskData()).thenReturn(taskData);
+ return model;
+ }
+ }
+
+ private TaskRepository repository;
+
+ private ITask task;
+
+ private TaskData taskData;
+
+ private AbstractTaskEditorPage page;
+
+ private IManagedForm form;
+
+ private TaskAttribute attribute;
+
+ @SuppressWarnings("restriction")
+ @Before
+ public void setUp() {
+ repository = TaskTestUtil.createMockRepository();
+ task = TaskTestUtil.createMockTask("1");
+ taskData = TaskTestUtil.createMockTaskData("1");
+ attribute = taskData.getRoot().createAttribute("test");
+ page = spy(new TestAbstractTaskEditorPage(mock(TaskEditor.class), task.getConnectorKind()));
+ form = mock(IManagedForm.class);
+ when(page.getManagedForm()).thenReturn(form);
+ page.init(createSite(), new TaskEditorInput(repository, task));
+ }
+
+ private IEditorSite createSite() {
+ IEditorSite site = mock(IEditorSite.class);
+ IHandlerService service = mock(IHandlerService.class);
+ when(site.getService(any(Class.class))).thenReturn(service);
+ return site;
+ }
+
+ @Test
+ public void testInitModelListener() {
+ page.getModel().attributeChanged(attribute);
+ verify(form).dirtyStateChanged();
+ }
+
+ @Test
+ public void testInitModelListenerDirtyForm() {
+ when(form.isDirty()).thenReturn(true);
+ page.getModel().attributeChanged(attribute);
+ verify(form, never()).dirtyStateChanged();
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractTaskEditorPage.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractTaskEditorPage.java
index 5adee388a..fff321ab3 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractTaskEditorPage.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractTaskEditorPage.java
@@ -1304,7 +1304,7 @@ public abstract class AbstractTaskEditorPage extends TaskFormPage implements ISe
@Override
public void attributeChanged(TaskDataModelEvent event) {
IManagedForm form = getManagedForm();
- if (form != null) {
+ if (form != null && !form.isDirty()) {
form.dirtyStateChanged();
}
}

Back to the top