Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaxsun McCarthy Huggan2016-10-03 17:23:41 -0400
committerGerrit Code Review @ Eclipse.org2017-01-26 19:09:41 -0500
commit6691e7f132193ac291940f274344c649ac5cfc5f (patch)
tree9e0cbdff06b75642be51ee0705ee334f182deb3d
parent0924348790cef34199b4e15638d5932a0eec0da7 (diff)
downloadorg.eclipse.mylyn.tasks-6691e7f132193ac291940f274344c649ac5cfc5f.tar.gz
org.eclipse.mylyn.tasks-6691e7f132193ac291940f274344c649ac5cfc5f.tar.xz
org.eclipse.mylyn.tasks-6691e7f132193ac291940f274344c649ac5cfc5f.zip
326005: Task Editor asks to save or delete newly created tasks on close
* The Task Editor is marked as dirty initially when editing newly created tasks ** In this state when the editor is closed it asks if the user wants to save or delete the new task ** If the editor is saved or the task is submitted this state is cleared * Introduced TasksUiUtil API for task deletion from relevant stores * Removed remaining uses of WorkbenchUtil.SHOW_IN_TASKBAR_ICON_PROPERTY * Fixed workspace warnings and did code cleanup in altered classes Change-Id: Icb06522aac407cbc877b1643d58c4ff4bb9dcd64 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=326005 Signed-off-by: Jaxsun McCarthy Huggan <jaxsun.mccarthy@tasktop.com>
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/ITasksCoreConstants.java6
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListExternalizationTest.java24
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/DeleteAction.java27
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/NewSubTaskAction.java8
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AbstractTaskEditorAttributeSection.java41
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/Messages.java10
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskMigrator.java15
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/messages.properties5
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TasksUiInternal.java30
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/UpdateRepositoryConfigurationAction.java4
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUiUtil.java8
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractTaskEditorPage.java136
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/TaskEditor.java194
13 files changed, 184 insertions, 324 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/ITasksCoreConstants.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/ITasksCoreConstants.java
index 1682e2cd4..7a045a591 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/ITasksCoreConstants.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/ITasksCoreConstants.java
@@ -13,6 +13,7 @@ package org.eclipse.mylyn.internal.tasks.core;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.mylyn.tasks.core.ITask;
/**
* @author Rob Elves
@@ -161,4 +162,9 @@ public interface ITasksCoreConstants {
public static final Object JOB_FAMILY_SYNCHRONIZATION = new Object();
+ /**
+ * A property to mark an {@link ITask} as having been newly created and not yet saved or submitted.
+ */
+ public static final String PROPERTY_NEW_UNSAVED_TASK = "org.eclipse.mylyn.tasks.ui.new.unsaved.task"; //$NON-NLS-1$
+
}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListExternalizationTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListExternalizationTest.java
index ff139112e..d64b1b076 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListExternalizationTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListExternalizationTest.java
@@ -19,8 +19,6 @@ import java.util.Iterator;
import java.util.Set;
import java.util.TimeZone;
-import junit.framework.TestCase;
-
import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
import org.eclipse.mylyn.internal.tasks.core.AbstractTaskCategory;
import org.eclipse.mylyn.internal.tasks.core.AbstractTaskContainer;
@@ -42,6 +40,8 @@ import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnector;
import org.eclipse.mylyn.tasks.ui.TasksUi;
+import junit.framework.TestCase;
+
/**
* @author Robert Elves
* @author Steffen Pingel
@@ -75,29 +75,31 @@ public class TaskListExternalizationTest extends TestCase {
public void testTaskAttributes() throws Exception {
AbstractTask task1 = TasksUiInternal.createNewLocalTask("task 1");
+ int initialAttributeCount = task1.getAttributes().size();
task1.setAttribute("key", "value");
- assertEquals(1, task1.getAttributes().size());
+ assertEquals(initialAttributeCount + 1, task1.getAttributes().size());
TaskTestUtil.saveAndReadTasklist();
task1 = taskList.getTask(task1.getHandleIdentifier());
assertNotNull(task1);
- assertEquals(1, task1.getAttributes().size());
+ assertEquals(initialAttributeCount + 1, task1.getAttributes().size());
assertEquals("value", task1.getAttribute("key"));
}
public void testTaskAttributeDelete() throws Exception {
AbstractTask task1 = TasksUiInternal.createNewLocalTask("task 1");
+ int initialAttributeCount = task1.getAttributes().size();
task1.setAttribute("key", "value");
task1.setAttribute("key", null);
- assertEquals(0, task1.getAttributes().size());
+ assertEquals(initialAttributeCount, task1.getAttributes().size());
assertEquals(null, task1.getAttribute("key"));
TaskTestUtil.saveAndReadTasklist();
task1 = taskList.getTask(task1.getHandleIdentifier());
assertNotNull(task1);
- assertEquals(0, task1.getAttributes().size());
+ assertEquals(initialAttributeCount, task1.getAttributes().size());
assertEquals(null, task1.getAttribute("key"));
}
@@ -354,7 +356,7 @@ public class TaskListExternalizationTest extends TestCase {
/**
* If a task exists in a category and is a query hit it should not be removed from the category
- *
+ *
* @throws Exception
*/
public void testQueryRemovedTaskInCategory() throws Exception {
@@ -648,8 +650,8 @@ public class TaskListExternalizationTest extends TestCase {
assertEquals(1, TasksUiPlugin.getTaskList().getAllTasks().size());
// removed/disable externalizers
- AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager().removeRepositoryConnector(
- MockRepositoryConnector.CONNECTOR_KIND);
+ AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager()
+ .removeRepositoryConnector(MockRepositoryConnector.CONNECTOR_KIND);
// reload tasklist ensure task didn't load
TaskTestUtil.saveAndReadTasklist();
@@ -682,8 +684,8 @@ public class TaskListExternalizationTest extends TestCase {
assertEquals(1, TasksUiPlugin.getTaskList().getQueries().size());
// removed/disable externalizers
- AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager().removeRepositoryConnector(
- MockRepositoryConnector.CONNECTOR_KIND);
+ AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager()
+ .removeRepositoryConnector(MockRepositoryConnector.CONNECTOR_KIND);
// reload tasklist ensure query didn't load
TaskTestUtil.saveAndReadTasklist();
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/DeleteAction.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/DeleteAction.java
index 74cfccf21..098abcc59 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/DeleteAction.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/DeleteAction.java
@@ -86,7 +86,8 @@ public class DeleteAction extends BaseSelectionListenerAction {
for (Object object : toDelete) {
if (object instanceof ITask) {
ITask task = (ITask) object;
- AbstractRepositoryConnector repositoryConnector = TasksUi.getRepositoryConnector(task.getConnectorKind());
+ AbstractRepositoryConnector repositoryConnector = TasksUi
+ .getRepositoryConnector(task.getConnectorKind());
TaskRepository repository = TasksUi.getRepositoryManager().getRepository(task.getConnectorKind(),
task.getRepositoryUrl());
if (repository != null && repositoryConnector != null) {
@@ -113,9 +114,9 @@ public class DeleteAction extends BaseSelectionListenerAction {
final boolean allTasksDeletable = allSupportRepositoryDeletion;
if (allLocalTasks || !allElementsAreTasks) {
- deleteConfirmed = MessageDialog.openQuestion(PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow()
- .getShell(), Messages.DeleteAction_Delete_Tasks, message);
+ deleteConfirmed = MessageDialog.openQuestion(
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+ Messages.DeleteAction_Delete_Tasks, message);
} else {
String toggleMessage = Messages.DeleteAction_Also_delete_from_repository_X;
if (allTasksDeletable) {
@@ -124,8 +125,9 @@ public class DeleteAction extends BaseSelectionListenerAction {
toggleMessage = NLS.bind(toggleMessage, Messages.DeleteAction_Not_supported);
}
final MessageDialogWithToggle dialog = new MessageDialogWithToggle(WorkbenchUtil.getShell(),
- Messages.DeleteAction_Delete_Tasks, null, message, MessageDialog.QUESTION, new String[] {
- IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0, toggleMessage, false) {
+ Messages.DeleteAction_Delete_Tasks, null, message, MessageDialog.QUESTION,
+ new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0, toggleMessage,
+ false) {
@Override
protected Control createContents(Composite parent) {
Control createdControl = super.createContents(parent);
@@ -167,8 +169,8 @@ public class DeleteAction extends BaseSelectionListenerAction {
try {
WorkbenchUtil.runInUi(op, null);
} catch (CoreException e) {
- Status status = new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, NLS.bind(
- "Problems encountered deleting task list elements: {0}", e.getMessage()), e); //$NON-NLS-1$
+ Status status = new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN,
+ NLS.bind("Problems encountered deleting task list elements: {0}", e.getMessage()), e); //$NON-NLS-1$
TasksUiInternal.logAndDisplayStatus(Messages.DeleteTaskRepositoryAction_Delete_Task_Repository_Failed,
status);
} catch (OperationCanceledException e) {
@@ -251,14 +253,7 @@ public class DeleteAction extends BaseSelectionListenerAction {
for (Object selectedObject : toDelete) {
if (selectedObject instanceof AbstractTask) {
AbstractTask task = (AbstractTask) selectedObject;
- TasksUiInternal.getTaskList().deleteTask(task);
- try {
- TasksUiPlugin.getTaskDataManager().deleteTaskData(task);
- } catch (CoreException e) {
- StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Failed to delete task data", //$NON-NLS-1$
- e));
- }
- TasksUiPlugin.getContextStore().deleteContext(task);
+ TasksUiInternal.deleteTask(task);
} else if (selectedObject instanceof IRepositoryQuery) {
TasksUiInternal.getTaskList().deleteQuery((RepositoryQuery) selectedObject);
} else if (selectedObject instanceof TaskCategory) {
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/NewSubTaskAction.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/NewSubTaskAction.java
index 9a79613c7..af61efbe7 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/NewSubTaskAction.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/actions/NewSubTaskAction.java
@@ -29,14 +29,12 @@ import org.eclipse.mylyn.commons.core.StatusHandler;
import org.eclipse.mylyn.commons.ui.CommonUiUtil;
import org.eclipse.mylyn.commons.workbench.WorkbenchUtil;
import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
-import org.eclipse.mylyn.internal.tasks.core.LocalRepositoryConnector;
import org.eclipse.mylyn.internal.tasks.core.LocalTask;
import org.eclipse.mylyn.internal.tasks.core.TaskList;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
import org.eclipse.mylyn.tasks.core.ITask;
-import org.eclipse.mylyn.tasks.core.ITask.PriorityLevel;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler;
import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
@@ -74,12 +72,8 @@ public class NewSubTaskAction extends BaseSelectionListenerAction implements IVi
}
if (selectedTask instanceof LocalTask) {
- // XXX code copied from NewLocalTaskWizard.performFinish() and TaskListManager.createNewLocalTask()
TaskList taskList = TasksUiPlugin.getTaskList();
- LocalTask newTask = new LocalTask("" + taskList.getNextLocalTaskId(), //$NON-NLS-1$
- LocalRepositoryConnector.DEFAULT_SUMMARY);
- newTask.setPriority(PriorityLevel.P3.toString());
- TasksUiInternal.scheduleNewTask(newTask);
+ LocalTask newTask = TasksUiInternal.createNewLocalTask(null);
taskList.addTask(newTask, selectedTask);
TasksUiUtil.openTask(newTask);
return;
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AbstractTaskEditorAttributeSection.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AbstractTaskEditorAttributeSection.java
index fbc492003..ce80eff84 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AbstractTaskEditorAttributeSection.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AbstractTaskEditorAttributeSection.java
@@ -25,7 +25,6 @@ import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.mylyn.commons.workbench.WorkbenchUtil;
import org.eclipse.mylyn.commons.workbench.forms.CommonFormUtil;
import org.eclipse.mylyn.internal.tasks.ui.notifications.TaskDiffUtil;
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
@@ -48,10 +47,11 @@ import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.progress.IProgressConstants2;
/**
* Editor part that shows {@link TaskAttribute}s in a two column layout.
- *
+ *
* @author Steffen Pingel
* @author Kevin Sawicki
*/
@@ -207,7 +207,7 @@ public abstract class AbstractTaskEditorAttributeSection extends AbstractTaskEdi
/**
* Create a comparator by which attribute editors will be sorted. By default attribute editors are sorted by layout
* hint priority. Subclasses may override this method to sort attribute editors in a custom way.
- *
+ *
* @return comparator for {@link AbstractAttributeEditor} objects
*/
protected Comparator<AbstractAttributeEditor> createAttributeEditorSorter() {
@@ -264,10 +264,9 @@ public abstract class AbstractTaskEditorAttributeSection extends AbstractTaskEdi
public void run() {
getTaskEditorPage().showEditorBusy(false);
if (job.getStatus() != null) {
- getTaskEditorPage().getTaskEditor()
- .setStatus(
- Messages.TaskEditorAttributePart_Updating_of_repository_configuration_failed,
- Messages.TaskEditorAttributePart_Update_Failed, job.getStatus());
+ getTaskEditorPage().getTaskEditor().setStatus(
+ Messages.TaskEditorAttributePart_Updating_of_repository_configuration_failed,
+ Messages.TaskEditorAttributePart_Update_Failed, job.getStatus());
} else {
getTaskEditorPage().refresh();
}
@@ -277,34 +276,10 @@ public abstract class AbstractTaskEditorAttributeSection extends AbstractTaskEdi
});
job.setUser(true);
// show the progress in the system task bar if this is a user job (i.e. forced)
- job.setProperty(WorkbenchUtil.SHOW_IN_TASKBAR_ICON_PROPERTY, Boolean.TRUE);
+ job.setProperty(IProgressConstants2.SHOW_IN_TASKBAR_ICON_PROPERTY, Boolean.TRUE);
job.setPriority(Job.INTERACTIVE);
job.schedule();
};
-
-// @Override
-// public void performUpdate(TaskRepository repository, AbstractRepositoryConnector connector,
-// IProgressMonitor monitor) {
-// PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
-// public void run() {
-// getTaskEditorPage().showEditorBusy(true);
-// }
-// });
-// try {
-// super.performUpdate(repository, connector, monitor);
-// AbstractTask task = getTaskEditorPage().getTask();
-// Job job = TasksUi.synchronizeTask(connector, task, true, null);
-// job.join();
-// } catch (InterruptedException e) {
-// // ignore
-// } finally {
-// PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
-// public void run() {
-// getTaskEditorPage().refreshFormContent();
-// }
-// });
-// }
-// }
};
repositoryConfigRefresh.setImageDescriptor(TasksUiImages.REPOSITORY_SYNCHRONIZE_SMALL);
repositoryConfigRefresh.selectionChanged(new StructuredSelection(getTaskEditorPage().getTaskRepository()));
@@ -343,7 +318,7 @@ public abstract class AbstractTaskEditorAttributeSection extends AbstractTaskEdi
/**
* Returns the attributes that are shown in the overlay text.
- *
+ *
* @see #getInfoOverlayText()
*/
protected abstract List<TaskAttribute> getOverlayAttributes();
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/Messages.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/Messages.java
index db64beafa..08c31ade8 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/Messages.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/Messages.java
@@ -275,8 +275,18 @@ public class Messages extends NLS {
public static String SummaryPart_Section_Title;
+ public static String TaskEditor_Delete;
+
public static String TaskEditor_Edit_Task_Repository_ToolTip;
+ public static String TaskEditor_Save;
+
+ public static String TaskEditor_SaveNewLocalTaskDescription;
+
+ public static String TaskEditor_SaveNewTask;
+
+ public static String TaskEditor_SaveNewRemoteTaskDescription;
+
public static String TaskEditor_Task;
public static String TaskEditor_Task_added_to_the_Uncategorized_container;
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskMigrator.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskMigrator.java
index d4cdd5ee7..121359a74 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskMigrator.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskMigrator.java
@@ -13,7 +13,6 @@ package org.eclipse.mylyn.internal.tasks.ui.editors;
import java.util.Date;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.SafeRunner;
@@ -83,7 +82,7 @@ public class TaskMigrator {
* <li>Reactivate new task
* <li>Open new task
* </ul>
- *
+ *
* @param newTask
* the task to migrate properties to
*/
@@ -96,8 +95,8 @@ public class TaskMigrator {
final TaskMigrationEvent event = new TaskMigrationEvent(oldTask, newTask);
SafeRunner.run(new ISafeRunnable() {
public void handleException(Throwable e) {
- StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN,
- "Unexpected error in task migrator: " //$NON-NLS-1$
+ StatusHandler.log(
+ new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Unexpected error in task migrator: " //$NON-NLS-1$
+ connector.getClass(), e));
}
@@ -164,13 +163,7 @@ public class TaskMigrator {
private void deleteOldTask() {
// delete old task details
if (delete()) {
- TasksUiInternal.getTaskList().deleteTask(oldTask);
- TasksUiPlugin.getContextStore().deleteContext(oldTask);
- try {
- TasksUiPlugin.getTaskDataManager().deleteTaskData(oldTask);
- } catch (CoreException e) {
- StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Failed to delete task data", e)); //$NON-NLS-1$
- }
+ TasksUiInternal.deleteTask(oldTask);
}
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/messages.properties b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/messages.properties
index 4a973a490..e0db6f77b 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/messages.properties
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/messages.properties
@@ -152,7 +152,12 @@ AttributePart_Category_=Category:
DoubleAttributeEditor_this_field_requires_double_value=This field requires a double value.
IntegerAttributeEditor_this_field_requires_integer_value=This field requires an integer value.
SummaryPart_Section_Title=Summary
+TaskEditor_Delete=Delete
TaskEditor_Edit_Task_Repository_ToolTip=Edit Task Repository
+TaskEditor_Save=Save
+TaskEditor_SaveNewLocalTaskDescription=This new task has not been saved. Do you wish to save or delete this task?
+TaskEditor_SaveNewTask=Save New Task
+TaskEditor_SaveNewRemoteTaskDescription=This new task has not been saved or submitted. Do you wish to save or delete this task?
TaskEditor_Task=Task
TaskEditor_Task_added_to_the_Uncategorized_container=Task added to the Uncategorized container
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TasksUiInternal.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TasksUiInternal.java
index 1b6c107b0..73ecfe177 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TasksUiInternal.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TasksUiInternal.java
@@ -142,11 +142,14 @@ import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.handlers.IHandlerService;
+import org.eclipse.ui.progress.IProgressConstants2;
import org.eclipse.ui.services.IServiceLocator;
import org.eclipse.ui.statushandlers.IStatusAdapterConstants;
import org.eclipse.ui.statushandlers.StatusAdapter;
import org.eclipse.ui.statushandlers.StatusManager;
+import com.google.common.base.Strings;
+
/**
* @author Steffen Pingel
*/
@@ -395,7 +398,7 @@ public class TasksUiInternal {
job.setUser(force);
if (force) {
// show the progress in the system task bar if this is a user job (i.e. forced)
- job.setProperty(WorkbenchUtil.SHOW_IN_TASKBAR_ICON_PROPERTY, Boolean.TRUE);
+ job.setProperty(IProgressConstants2.SHOW_IN_TASKBAR_ICON_PROPERTY, Boolean.TRUE);
}
if (listener != null) {
job.addJobChangeListener(listener);
@@ -433,7 +436,7 @@ public class TasksUiInternal {
job.setUser(force);
if (force) {
// show the progress in the system task bar if this is a user job (i.e. forced)
- job.setProperty(WorkbenchUtil.SHOW_IN_TASKBAR_ICON_PROPERTY, Boolean.TRUE);
+ job.setProperty(IProgressConstants2.SHOW_IN_TASKBAR_ICON_PROPERTY, Boolean.TRUE);
}
job.schedule();
joinIfInTestMode(job);
@@ -464,7 +467,7 @@ public class TasksUiInternal {
job.setUser(force);
if (force) {
// show the progress in the system task bar if this is a user job (i.e. forced)
- job.setProperty(WorkbenchUtil.SHOW_IN_TASKBAR_ICON_PROPERTY, Boolean.TRUE);
+ job.setProperty(IProgressConstants2.SHOW_IN_TASKBAR_ICON_PROPERTY, Boolean.TRUE);
}
job.setFullSynchronization(false);
return job;
@@ -658,6 +661,7 @@ public class TasksUiInternal {
MessageFormat.format(Messages.TasksUiInternal_The_new_task_will_be_added_to_the_X_container,
UncategorizedTaskContainer.LABEL));
}
+ newTask.setAttribute(ITasksCoreConstants.PROPERTY_NEW_UNSAVED_TASK, Boolean.TRUE.toString());
taskList.addTask(newTask, category);
return newTask;
}
@@ -885,11 +889,11 @@ public class TasksUiInternal {
.getRepositoryConnector(taskData.getConnectorKind());
ITaskMapping mapping = connector.getTaskMapping(taskData);
String summary = mapping.getSummary();
- if (summary != null && summary.length() > 0) {
+ if (!Strings.isNullOrEmpty(summary)) {
task.setSummary(summary);
}
String taskKind = mapping.getTaskKind();
- if (taskKind != null && taskKind.length() > 0) {
+ if (!Strings.isNullOrEmpty(taskKind)) {
task.setTaskKind(taskKind);
}
UnsubmittedTaskContainer unsubmitted = TasksUiPlugin.getTaskList()
@@ -1568,4 +1572,20 @@ public class TasksUiInternal {
return undoContext;
}
+ /**
+ * Deletes the given task from the Task List, the Task Context Store, and the Task Data Manager.
+ *
+ * @param task
+ * the task to delete
+ */
+ public static void deleteTask(ITask task) {
+ TasksUiInternal.getTaskList().deleteTask(task);
+ TasksUiPlugin.getContextStore().deleteContext(task);
+ try {
+ TasksUiPlugin.getTaskDataManager().deleteTaskData(task);
+ } catch (CoreException e) {
+ StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Failed to delete task data", e)); //$NON-NLS-1$
+ }
+ }
+
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/UpdateRepositoryConfigurationAction.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/UpdateRepositoryConfigurationAction.java
index 9f9ed5f80..32cc87ca2 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/UpdateRepositoryConfigurationAction.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/UpdateRepositoryConfigurationAction.java
@@ -14,11 +14,11 @@ package org.eclipse.mylyn.internal.tasks.ui.views;
import java.util.Iterator;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.mylyn.commons.workbench.WorkbenchUtil;
import org.eclipse.mylyn.internal.tasks.ui.actions.AbstractTaskRepositoryAction;
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.core.sync.TaskJob;
+import org.eclipse.ui.progress.IProgressConstants2;
/**
* @author Mik Kersten
@@ -42,7 +42,7 @@ public class UpdateRepositoryConfigurationAction extends AbstractTaskRepositoryA
if (repository != null) {
TaskJob job = TasksUiInternal.updateRepositoryConfiguration(repository);
// show the progress in the system task bar if this is a user job (i.e. forced)
- job.setProperty(WorkbenchUtil.SHOW_IN_TASKBAR_ICON_PROPERTY, Boolean.TRUE);
+ job.setProperty(IProgressConstants2.SHOW_IN_TASKBAR_ICON_PROPERTY, Boolean.TRUE);
}
}
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUiUtil.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUiUtil.java
index 43575ca43..672640c8c 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUiUtil.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUiUtil.java
@@ -242,13 +242,7 @@ public class TasksUiUtil {
* @since 3.0
*/
public static boolean openNewTaskEditor(Shell shell, ITaskMapping taskSelection, TaskRepository taskRepository) {
- final IWizard wizard;
-// List<TaskRepository> repositories = TasksUi.getRepositoryManager().getAllRepositories();
-// if (taskRepository == null && repositories.size() == 1) {
-// // only the Local repository connector is available
-// taskRepository = repositories.get(0);
-// }
-
+ IWizard wizard;
if (taskRepository != null) {
AbstractRepositoryConnectorUi connectorUi = TasksUiPlugin.getConnectorUi(taskRepository.getConnectorKind());
wizard = connectorUi.getNewTaskWizard(taskRepository, taskSelection);
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 f1e2558b2..8b7e6b9ce 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
@@ -259,44 +259,6 @@ public abstract class AbstractTaskEditorPage extends TaskFormPage
}
-// private class TaskListChangeListener extends TaskListChangeAdapter {
-// @Override
-// public void containersChanged(Set<TaskContainerDelta> containers) {
-// if (refreshDisabled) {
-// return;
-// }
-// ITask taskToRefresh = null;
-// for (TaskContainerDelta taskContainerDelta : containers) {
-// if (task.equals(taskContainerDelta.getElement())) {
-// if (taskContainerDelta.getKind().equals(TaskContainerDelta.Kind.CONTENT)
-// && !taskContainerDelta.isTransient()) {
-// taskToRefresh = (ITask) taskContainerDelta.getElement();
-// break;
-// }
-// }
-// }
-// if (taskToRefresh != null) {
-// PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
-// public void run() {
-// if (!isDirty() && task.getSynchronizationState() == SynchronizationState.SYNCHRONIZED) {
-// // automatically refresh if the user has not made any changes and there is no chance of missing incomings
-// refreshFormContent();
-// } else {
-// getTaskEditor().setMessage("Task has incoming changes", IMessageProvider.WARNING,
-// new HyperlinkAdapter() {
-// @Override
-// public void linkActivated(HyperlinkEvent e) {
-// refreshFormContent();
-// }
-// });
-// setSubmitEnabled(false);
-// }
-// }
-// });
-// }
-// }
-// }
-
private final ITaskDataManagerListener TASK_DATA_LISTENER = new ITaskDataManagerListener() {
public void taskDataUpdated(final TaskDataManagerEvent event) {
@@ -319,11 +281,11 @@ public abstract class AbstractTaskEditorPage extends TaskFormPage
} else {
getTaskEditor().setMessage(Messages.AbstractTaskEditorPage_Task_has_incoming_changes,
IMessageProvider.WARNING, new HyperlinkAdapter() {
- @Override
- public void linkActivated(HyperlinkEvent e) {
- AbstractTaskEditorPage.this.refresh();
- }
- });
+ @Override
+ public void linkActivated(HyperlinkEvent e) {
+ AbstractTaskEditorPage.this.refresh();
+ }
+ });
setSubmitEnabled(false);
}
}
@@ -446,8 +408,6 @@ public abstract class AbstractTaskEditorPage extends TaskFormPage
public static final String PATH_PLANNING = "planning"; //$NON-NLS-1$
-// private static final String ID_POPUP_MENU = "org.eclipse.mylyn.tasks.ui.editor.menu.page";
-
private AttributeEditorFactory attributeEditorFactory;
private AttributeEditorToolkit attributeEditorToolkit;
@@ -482,8 +442,6 @@ public abstract class AbstractTaskEditorPage extends TaskFormPage
private TaskData taskData;
-// private ITaskListChangeListener taskListChangeListener;
-
private FormToolkit toolkit;
private TaskEditorOutlinePage outlinePage;
@@ -648,13 +606,6 @@ public abstract class AbstractTaskEditorPage extends TaskFormPage
GridLayout editorLayout = new GridLayout();
editorLayout.verticalSpacing = 0;
editorComposite.setLayout(editorLayout);
-
- //form.setData("focusScrolling", Boolean.FALSE);
-
-// menuManager = new MenuManager();
-// menuManager.setRemoveAllWhenShown(true);
-// getEditorSite().registerContextMenu(ID_POPUP_MENU, menuManager, this, true);
-// editorComposite.setMenu(menuManager.createContextMenu(editorComposite));
editorComposite.setMenu(getTaskEditor().getMenu());
AbstractRepositoryConnectorUi connectorUi = TasksUiPlugin.getConnectorUi(getConnectorKind());
@@ -664,11 +615,11 @@ public abstract class AbstractTaskEditorPage extends TaskFormPage
getTaskEditor().setMessage(
Messages.AbstractTaskEditorPage_Synchronize_to_update_editor_contents,
IMessageProvider.INFORMATION, new HyperlinkAdapter() {
- @Override
- public void linkActivated(HyperlinkEvent e) {
- AbstractTaskEditorPage.this.refresh();
- }
- });
+ @Override
+ public void linkActivated(HyperlinkEvent e) {
+ AbstractTaskEditorPage.this.refresh();
+ }
+ });
}
});
}
@@ -733,10 +684,6 @@ public abstract class AbstractTaskEditorPage extends TaskFormPage
focusTracker = new FocusTracker();
focusTracker.track(editorComposite);
-// AbstractTaskEditorPart summaryPart = getPart(ID_PART_SUMMARY);
-// if (summaryPart != null) {
-// lastFocusControl = summaryPart.getControl();
-// }
}
protected TaskDataModel createModel(TaskEditorInput input) throws CoreException {
@@ -948,7 +895,7 @@ public abstract class AbstractTaskEditorPage extends TaskFormPage
}
// update the summary of unsubmitted repository tasks
if (getTask().getSynchronizationState() == SynchronizationState.OUTGOING_NEW) {
- final String summary = connector.getTaskMapping(model.getTaskData()).getSummary();
+ String summary = connector.getTaskMapping(model.getTaskData()).getSummary();
try {
TasksUiPlugin.getTaskList().run(new ITaskListRunnable() {
public void execute(IProgressMonitor monitor) throws CoreException {
@@ -1112,7 +1059,7 @@ public abstract class AbstractTaskEditorPage extends TaskFormPage
}
}
- @SuppressWarnings("rawtypes")
+ @SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Object getAdapter(Class adapter) {
if (adapter == IContentOutlinePage.class) {
@@ -1369,7 +1316,17 @@ public abstract class AbstractTaskEditorPage extends TaskFormPage
@Override
public boolean isDirty() {
- return (getModel() != null && getModel().isDirty()) || (getManagedForm() != null && getManagedForm().isDirty());
+ return isModelDirty() || isFormDirty();
+ }
+
+ private boolean isFormDirty() {
+ IManagedForm form = getManagedForm();
+ return form != null && form.isDirty();
+ }
+
+ private boolean isModelDirty() {
+ TaskDataModel model = getModel();
+ return model != null && model.isDirty();
}
@Override
@@ -1671,18 +1628,6 @@ public abstract class AbstractTaskEditorPage extends TaskFormPage
private void createFooterContent(Composite parent) {
parent.setLayout(new GridLayout());
-
-// submitButton = toolkit.createButton(parent, Messages.TaskEditorActionPart_Submit, SWT.NONE);
-// GridData submitButtonData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
-// submitButtonData.widthHint = 100;
-// submitButton.setBackground(null);
-// submitButton.setImage(CommonImages.getImage(TasksUiImages.REPOSITORY_SUBMIT));
-// submitButton.setLayoutData(submitButtonData);
-// submitButton.addListener(SWT.Selection, new Listener() {
-// public void handleEvent(Event e) {
-// doSubmit();
-// }
-// });
}
/**
@@ -1746,41 +1691,6 @@ public abstract class AbstractTaskEditorPage extends TaskFormPage
this.needsPrivateSection = needsPrivateSection;
}
-// private void fillLeftHeaderToolBar(IToolBarManager toolBarManager) {
-// if (needsSubmit()) {
-// ControlContribution submitButtonContribution = new ControlContribution(
-// "org.eclipse.mylyn.tasks.toolbars.submit") { //$NON-NLS-1$
-// @Override
-// protected int computeWidth(Control control) {
-// return super.computeWidth(control) + 5;
-// }
-//
-// @Override
-// protected Control createControl(Composite parent) {
-// Composite composite = new Composite(parent, SWT.NONE);
-// composite.setBackground(null);
-// GridLayout layout = new GridLayout();
-// layout.marginWidth = 0;
-// layout.marginHeight = 0;
-// layout.marginLeft = 10;
-// composite.setLayout(layout);
-//
-// submitButton = toolkit.createButton(composite, Messages.TaskEditorActionPart_Submit + " ", SWT.NONE); //$NON-NLS-1$
-// submitButton.setImage(CommonImages.getImage(TasksUiImages.REPOSITORY_SUBMIT));
-// submitButton.setBackground(null);
-// submitButton.addListener(SWT.Selection, new Listener() {
-// public void handleEvent(Event e) {
-// doSubmit();
-// }
-// });
-// GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.BOTTOM).applyTo(submitButton);
-// return composite;
-// }
-// };
-// toolBarManager.add(submitButtonContribution);
-// }
-// }
-
@Override
public boolean selectReveal(Object object) {
if (object instanceof TaskEditorOutlineNode) {
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/TaskEditor.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/TaskEditor.java
index 8f01cd634..b356c09be 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/TaskEditor.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/TaskEditor.java
@@ -34,7 +34,9 @@ import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.action.ToolBarManager;
+import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IMessageProvider;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.resource.CompositeImageDescriptor;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.JFaceResources;
@@ -53,6 +55,7 @@ import org.eclipse.mylyn.commons.workbench.BusyAnimator;
import org.eclipse.mylyn.commons.workbench.BusyAnimator.IBusyClient;
import org.eclipse.mylyn.commons.workbench.WorkbenchUtil;
import org.eclipse.mylyn.commons.workbench.editors.CommonTextSupport;
+import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants;
import org.eclipse.mylyn.internal.tasks.core.LocalRepositoryConnector;
import org.eclipse.mylyn.internal.tasks.core.TaskList;
import org.eclipse.mylyn.internal.tasks.ui.TaskEditorBloatMonitor;
@@ -95,6 +98,7 @@ import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.ISaveablePart2;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.contexts.IContextService;
@@ -125,7 +129,7 @@ import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
* @author Thomas Ehrnhoefer
* @since 2.0
*/
-public class TaskEditor extends SharedHeaderFormEditor {
+public class TaskEditor extends SharedHeaderFormEditor implements ISaveablePart2 {
/**
* @since 2.0
@@ -170,12 +174,8 @@ public class TaskEditor extends SharedHeaderFormEditor {
private Image headerImage;
-// private int initialLeftToolbarSize;
-
private boolean noExtraPadding;
-// private boolean headerLabelInitialized;
-
private BusyIndicator busyLabel;
private StyledText titleLabel;
@@ -526,6 +526,8 @@ public class TaskEditor extends SharedHeaderFormEditor {
@Override
public void doSave(IProgressMonitor monitor) {
+ task.setAttribute(ITasksCoreConstants.PROPERTY_NEW_UNSAVED_TASK, null);
+
for (IFormPage page : getPages()) {
if (page.isDirty()) {
page.doSave(monitor);
@@ -544,7 +546,7 @@ public class TaskEditor extends SharedHeaderFormEditor {
return (TaskEditorActionContributor) getEditorSite().getActionBarContributor();
}
- @SuppressWarnings("rawtypes")
+ @SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Object getAdapter(Class adapter) {
if (contentOutlineProvider != null) {
@@ -659,6 +661,10 @@ public class TaskEditor extends SharedHeaderFormEditor {
@Override
public boolean isDirty() {
+ return arePagesDirty() || isTaskNewAndUnsaved();
+ }
+
+ private boolean arePagesDirty() {
for (IFormPage page : getPages()) {
if (page.isDirty()) {
return true;
@@ -667,6 +673,10 @@ public class TaskEditor extends SharedHeaderFormEditor {
return false;
}
+ private boolean isTaskNewAndUnsaved() {
+ return task != null && Boolean.valueOf(task.getAttribute(ITasksCoreConstants.PROPERTY_NEW_UNSAVED_TASK));
+ }
+
@Override
public boolean isSaveAsAllowed() {
return false;
@@ -674,7 +684,7 @@ public class TaskEditor extends SharedHeaderFormEditor {
@Deprecated
public void markDirty() {
- firePropertyChange(PROP_DIRTY);
+ editorDirtyStateChanged();
}
/**
@@ -807,7 +817,6 @@ public class TaskEditor extends SharedHeaderFormEditor {
// avoid extra padding due to large title font
// TODO reset font in case tool bar is empty
- //leftToolBar.getParent().setFont(JFaceResources.getDefaultFont());
getHeaderForm().getForm().reflow(true);
}
@@ -933,9 +942,8 @@ public class TaskEditor extends SharedHeaderFormEditor {
toolBarManager = form.getToolBarManager();
toolBarManager.removeAll();
-// toolBarManager.update(true);
- TaskRepository outgoingNewRepository = TasksUiUtil.getOutgoingNewTaskRepository(task);
+ TaskRepository outgoingNewRepository = getOutgoingRepository();
final TaskRepository taskRepository = (outgoingNewRepository != null)
? outgoingNewRepository
: taskEditorInput.getTaskRepository();
@@ -982,11 +990,7 @@ public class TaskEditor extends SharedHeaderFormEditor {
openWithBrowserAction = new OpenWithBrowserAction();
openWithBrowserAction.selectionChanged(new StructuredSelection(task));
if (openWithBrowserAction.isEnabled()) {
-// ImageDescriptor overlay = TasksUiPlugin.getDefault().getOverlayIcon(taskRepository.getConnectorKind());
-// ImageDescriptor compositeDescriptor = new TaskListImageDescriptor(TasksUiImages.REPOSITORY_SMALL_TOP,
-// overlay, false, true);
openWithBrowserAction.setImageDescriptor(CommonImages.WEB);
- //openWithBrowserAction.setImageDescriptor(CommonImages.BROWSER_OPEN_TASK);
openWithBrowserAction.setToolTipText(Messages.AbstractTaskEditorPage_Open_with_Web_Browser);
toolBarManager.appendToGroup("open", openWithBrowserAction); //$NON-NLS-1$
} else {
@@ -1025,39 +1029,6 @@ public class TaskEditor extends SharedHeaderFormEditor {
toolBarManager.add(new Separator("activation")); //$NON-NLS-1$
-// ContributionItem spacer = new ContributionItem() {
-// @Override
-// public void fill(ToolBar toolbar, int index) {
-// ToolItem item = new ToolItem(toolbar, SWT.NONE);
-// int scaleHeight = 42;
-// if (PlatformUtil.needsCarbonToolBarFix()) {
-// scaleHeight = 32;
-// }
-// final Image image = new Image(toolbar.getDisplay(), CommonImages.getImage(CommonImages.BLANK)
-// .getImageData()
-// .scaledTo(1, scaleHeight));
-// item.setImage(image);
-// item.addDisposeListener(new DisposeListener() {
-// public void widgetDisposed(DisposeEvent e) {
-// image.dispose();
-// }
-// });
-// item.setWidth(5);
-// item.setEnabled(false);
-// }
-// };
-// toolBarManager.add(spacer);
-
-// for (IFormPage page : getPages()) {
-// if (page instanceof AbstractTaskEditorPage) {
-// AbstractTaskEditorPage taskEditorPage = (AbstractTaskEditorPage) page;
-// taskEditorPage.fillLeftHeaderToolBar(toolBarManager);
-// } else if (page instanceof TaskPlanningEditor) {
-// TaskPlanningEditor taskEditorPage = (TaskPlanningEditor) page;
-// taskEditorPage.fillLeftHeaderToolBar(toolBarManager);
-// }
-// }
-
// add external contributions
menuService = (IMenuService) getSite().getService(IMenuService.class);
if (menuService != null && toolBarManager instanceof ContributionManager) {
@@ -1087,26 +1058,14 @@ public class TaskEditor extends SharedHeaderFormEditor {
leftToolBarManager.add(new Separator("activation")); //$NON-NLS-1$
leftToolBarManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
-// initialLeftToolbarSize = leftToolBarManager.getSize();
-
if (needsContext) {
leftToolBarManager.add(activateAction);
}
-// for (IFormPage page : getPages()) {
-// if (page instanceof AbstractTaskEditorPage) {
-// AbstractTaskEditorPage taskEditorPage = (AbstractTaskEditorPage) page;
-// taskEditorPage.fillLeftHeaderToolBar(leftToolBarManager);
-// } else if (page instanceof TaskPlanningEditor) {
-// TaskPlanningEditor taskEditorPage = (TaskPlanningEditor) page;
-// taskEditorPage.fillLeftHeaderToolBar(leftToolBarManager);
-// }
-// }
-
// add external contributions
menuService = (IMenuService) getSite().getService(IMenuService.class);
if (menuService != null && leftToolBarManager instanceof ContributionManager) {
- TaskRepository outgoingNewRepository = TasksUiUtil.getOutgoingNewTaskRepository(task);
+ TaskRepository outgoingNewRepository = getOutgoingRepository();
TaskRepository taskRepository = (outgoingNewRepository != null)
? outgoingNewRepository
: taskEditorInput.getTaskRepository();
@@ -1117,49 +1076,6 @@ public class TaskEditor extends SharedHeaderFormEditor {
leftToolBarManager.update(true);
if (hasLeftToolBar()) {
- // XXX work around a bug in Gtk that causes the toolbar size to be incorrect if no
- // tool bar buttons are contributed
-// if (leftToolBar != null) {
-// Point size = leftToolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT, false);
-// boolean changed = false;
-// for (Control control : leftToolBar.getChildren()) {
-// final Point childSize = control.computeSize(SWT.DEFAULT, SWT.DEFAULT, false);
-// if (childSize.y > size.y) {
-// size.y = childSize.y;
-// changed = true;
-// }
-// }
-// if (changed) {
-// leftToolBar.setSize(size);
-// }
-// }
-//
-// if (PlatformUtil.isToolBarHeightBroken(leftToolBar)) {
-// ToolItem item = new ToolItem(leftToolBar, SWT.NONE);
-// item.setEnabled(false);
-// item.setImage(CommonImages.getImage(CommonImages.BLANK));
-// item.setWidth(1);
-// noExtraPadding = true;
-// } else if (PlatformUtil.needsToolItemToForceToolBarHeight()) {
-// ToolItem item = new ToolItem(leftToolBar, SWT.NONE);
-// item.setEnabled(false);
-// int scaleHeight = 22;
-// if (PlatformUtil.needsCarbonToolBarFix()) {
-// scaleHeight = 32;
-// }
-// final Image image = new Image(item.getDisplay(), CommonImages.getImage(CommonImages.BLANK)
-// .getImageData()
-// .scaledTo(1, scaleHeight));
-// item.setImage(image);
-// item.addDisposeListener(new DisposeListener() {
-// public void widgetDisposed(DisposeEvent e) {
-// image.dispose();
-// }
-// });
-// item.setWidth(1);
-// noExtraPadding = true;
-// }
-
// fix size of toolbar on Gtk with Eclipse 3.3
Point size = leftToolBar.getSize();
if (size.x == 0 && size.y == 0) {
@@ -1178,17 +1094,11 @@ public class TaskEditor extends SharedHeaderFormEditor {
}
private Image getBrandingImage() {
- String connectorKind;
- TaskRepository outgoingNewRepository = TasksUiUtil.getOutgoingNewTaskRepository(task);
- if (outgoingNewRepository != null) {
- connectorKind = outgoingNewRepository.getConnectorKind();
- } else {
- connectorKind = task.getConnectorKind();
- }
-
+ String connectorKind = getOutgoingConnectorKind();
if (LocalRepositoryConnector.CONNECTOR_KIND.equals(connectorKind)) {
return CommonImages.getImage(TasksUiImages.TASK);
} else {
+ TaskRepository outgoingNewRepository = getOutgoingRepository();
ImageDescriptor overlay;
if (outgoingNewRepository != null) {
overlay = TasksUiPlugin.getDefault().getBrandManager().getOverlayIcon(outgoingNewRepository);
@@ -1200,20 +1110,33 @@ public class TaskEditor extends SharedHeaderFormEditor {
}
}
+ private String getOutgoingConnectorKind() {
+ TaskRepository repository = getOutgoingRepository();
+ if (repository != null) {
+ return repository.getConnectorKind();
+ } else if (task != null) {
+ return task.getConnectorKind();
+ }
+ return null;
+ }
+
+ private TaskRepository getOutgoingRepository() {
+ if (task != null) {
+ return TasksUiUtil.getOutgoingNewTaskRepository(task);
+ }
+ return null;
+ }
+
private boolean hasLeftToolBar() {
return leftToolBar != null && leftToolBarManager != null;
-// && leftToolBarManager.getSize() > initialLeftToolbarSize;
}
private void updateHeaderLabel() {
- TaskRepository outgoingNewRepository = TasksUiUtil.getOutgoingNewTaskRepository(task);
- final TaskRepository taskRepository = (outgoingNewRepository != null)
+ TaskRepository outgoingNewRepository = getOutgoingRepository();
+ TaskRepository taskRepository = (outgoingNewRepository != null)
? outgoingNewRepository
: taskEditorInput.getTaskRepository();
-// if (taskRepository.getConnectorKind().equals(LocalRepositoryConnector.CONNECTOR_KIND)) {
-// getHeaderForm().getForm().setText(Messages.TaskEditor_Task_ + task.getSummary());
-// } else {
AbstractRepositoryConnectorUi connectorUi = TasksUiPlugin.getConnectorUi(taskRepository.getConnectorKind());
String kindLabel = Messages.TaskEditor_Task;
if (connectorUi != null) {
@@ -1253,11 +1176,44 @@ public class TaskEditor extends SharedHeaderFormEditor {
} else {
setTitleImage(CommonImages.getImage(TasksUiImages.TASK));
}
-// } else if (getEditorInput() instanceof AbstractRepositoryTaskEditorInput) {
-// setTitleImage(CommonImages.getImage(TasksUiImages.TASK_REMOTE));
} else {
setTitleImage(CommonImages.getImage(TasksUiImages.TASK));
}
}
+ /**
+ * @since 3.22
+ */
+ @Override
+ public int promptToSaveOnClose() {
+ if (isTaskNewAndUnsaved()) {
+ int result = openSaveOnCloseConfirmation(Messages.TaskEditor_Save, Messages.TaskEditor_Delete,
+ IDialogConstants.CANCEL_LABEL);
+ if (result == 0) {
+ return ISaveablePart2.YES;
+ } else if (result == 1) {
+ TasksUiInternal.deleteTask(task);
+ return ISaveablePart2.NO;
+ } else {
+ return ISaveablePart2.CANCEL;
+ }
+ }
+ // prompt to save as normal
+ return ISaveablePart2.DEFAULT;
+ }
+
+ private int openSaveOnCloseConfirmation(String... buttons) {
+ return new MessageDialog(getEditorSite().getShell(), Messages.TaskEditor_SaveNewTask, null,
+ getSaveOnCloseMessage(), MessageDialog.QUESTION, buttons, 0).open();
+ }
+
+ private String getSaveOnCloseMessage() {
+ String kind = getOutgoingConnectorKind();
+ if (LocalRepositoryConnector.CONNECTOR_KIND.equals(kind)) {
+ return Messages.TaskEditor_SaveNewLocalTaskDescription;
+ } else {
+ return Messages.TaskEditor_SaveNewRemoteTaskDescription;
+ }
+ }
+
}

Back to the top