diff options
author | Sam Davis | 2014-05-08 21:56:05 +0000 |
---|---|---|
committer | Sam Davis | 2014-05-08 23:06:41 +0000 |
commit | ed61e11bd571655a445acd1e662f79f144cbd7cb (patch) | |
tree | a07173e0a006ac878918c354fb4d6240dbb99d01 | |
parent | 4b93b2859c0aa609592c03bcf5d2d17e4456ca8b (diff) | |
download | org.eclipse.mylyn.tasks-ed61e11bd571655a445acd1e662f79f144cbd7cb.tar.gz org.eclipse.mylyn.tasks-ed61e11bd571655a445acd1e662f79f144cbd7cb.tar.xz org.eclipse.mylyn.tasks-ed61e11bd571655a445acd1e662f79f144cbd7cb.zip |
432764: create reusable CommentEditor
Change-Id: I4e9f1ed7bc3e9d4ae92884e6df6e04ba26206fb5
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=432764
2 files changed, 102 insertions, 47 deletions
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/CommentEditor.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/CommentEditor.java new file mode 100644 index 000000000..a09c4d0a0 --- /dev/null +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/CommentEditor.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (c) 2014 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.internal.tasks.ui.editors; + +import org.eclipse.mylyn.commons.workbench.editors.CommonTextSupport; +import org.eclipse.mylyn.tasks.core.ITask; +import org.eclipse.mylyn.tasks.core.TaskRepository; +import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorExtension; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.ActiveShellExpression; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.contexts.IContextActivation; +import org.eclipse.ui.contexts.IContextService; +import org.eclipse.ui.handlers.IHandlerService; + +public abstract class CommentEditor { + private RichTextEditor textEditor; + + private IContextService contextService; + + private IContextActivation commentContext; + + private CommonTextSupport textSupport; + + private final ITask task; + + private final TaskRepository taskRepository; + + public CommentEditor(ITask task, TaskRepository taskRepository) { + this.task = task; + this.taskRepository = taskRepository; + } + + public void createControl(Composite composite) { + AbstractTaskEditorExtension extension = TaskEditorExtensions.getTaskEditorExtension(taskRepository); + if (extension != null) { + String contextId = extension.getEditorContextId(); + if (contextId != null) { + contextService = (IContextService) PlatformUI.getWorkbench().getService(IContextService.class); + if (contextService != null) { + commentContext = contextService.activateContext(contextId, + new ActiveShellExpression(composite.getShell())); + } + } + } + + textEditor = new RichTextEditor(taskRepository, SWT.V_SCROLL | SWT.BORDER | SWT.WRAP, contextService, + extension, task) { + @Override + protected void valueChanged(String value) { + CommentEditor.this.valueChanged(value); + }; + }; + textEditor.createControl(composite, null); + textEditor.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); + + IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class); + if (handlerService != null) { + textSupport = new CommonTextSupport(handlerService); + textSupport.install(textEditor.getViewer(), true); + } + } + + protected abstract void valueChanged(String value); + + public RichTextEditor getTextEditor() { + return textEditor; + } + + public String getText() { + return textEditor.getText(); + } + + public void dispose() { + if (contextService != null && commentContext != null) { + contextService.deactivateContext(commentContext); + commentContext = null; + } + if (textSupport != null) { + textSupport.dispose(); + } + } +} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/TaskAttachmentPage.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/TaskAttachmentPage.java index 27d30eac2..0e577142b 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/TaskAttachmentPage.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/TaskAttachmentPage.java @@ -16,16 +16,13 @@ package org.eclipse.mylyn.tasks.ui.wizards; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.mylyn.commons.ui.CommonImages; -import org.eclipse.mylyn.commons.workbench.editors.CommonTextSupport; import org.eclipse.mylyn.internal.tasks.core.data.FileTaskAttachmentSource; import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; -import org.eclipse.mylyn.internal.tasks.ui.editors.RichTextEditor; -import org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorExtensions; +import org.eclipse.mylyn.internal.tasks.ui.editors.CommentEditor; import org.eclipse.mylyn.internal.tasks.ui.wizards.Messages; import org.eclipse.mylyn.tasks.core.data.TaskAttachmentMapper; import org.eclipse.mylyn.tasks.core.data.TaskAttachmentModel; import org.eclipse.mylyn.tasks.ui.TasksUiImages; -import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorExtension; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; @@ -39,11 +36,6 @@ import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.ActiveShellExpression; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.contexts.IContextActivation; -import org.eclipse.ui.contexts.IContextService; -import org.eclipse.ui.handlers.IHandlerService; /** * A wizard page to enter details of a new attachment. @@ -57,7 +49,7 @@ public class TaskAttachmentPage extends WizardPage { private Button attachContextButton; - private RichTextEditor commentEditor; + private CommentEditor commentEditor; private Text descriptionText; @@ -75,12 +67,6 @@ public class TaskAttachmentPage extends WizardPage { private boolean first = true; - private IContextService contextService; - - private IContextActivation commentContext; - - private CommonTextSupport textSupport; - private boolean needsReplaceExisting; private Button replaceExistingButton; @@ -137,32 +123,13 @@ public class TaskAttachmentPage extends WizardPage { label.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false)); label.setText(Messages.TaskAttachmentPage_Comment); - AbstractTaskEditorExtension extension = TaskEditorExtensions.getTaskEditorExtension(model.getTaskRepository()); - if (extension != null) { - String contextId = extension.getEditorContextId(); - if (contextId != null) { - contextService = (IContextService) PlatformUI.getWorkbench().getService(IContextService.class); - if (contextService != null) { - commentContext = contextService.activateContext(contextId, new ActiveShellExpression(getShell())); - } - } - } - - commentEditor = new RichTextEditor(getModel().getTaskRepository(), SWT.V_SCROLL | SWT.BORDER | SWT.WRAP, - contextService, extension, getModel().getTask()) { + commentEditor = new CommentEditor(getModel().getTask(), getModel().getTaskRepository()) { @Override protected void valueChanged(String value) { apply(); - }; + } }; - commentEditor.createControl(composite, null); - commentEditor.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); - - IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class); - if (handlerService != null) { - textSupport = new CommonTextSupport(handlerService); - textSupport.install(commentEditor.getViewer(), true); - } + commentEditor.createControl(composite); new Label(composite, SWT.NONE).setText(Messages.TaskAttachmentPage_Content_Type);// .setBackground(parent.getBackground()); @@ -255,7 +222,7 @@ public class TaskAttachmentPage extends WizardPage { if (descriptionText != null) { descriptionText.setFocus(); } else { - commentEditor.getControl().setFocus(); + commentEditor.getTextEditor().getControl().setFocus(); } Dialog.applyDialogFont(composite); @@ -353,7 +320,7 @@ public class TaskAttachmentPage extends WizardPage { if (descriptionText != null) { descriptionText.setFocus(); } else { - commentEditor.getControl().setFocus(); + commentEditor.getTextEditor().getControl().setFocus(); } first = false; } @@ -362,13 +329,7 @@ public class TaskAttachmentPage extends WizardPage { @Override public void dispose() { super.dispose(); - if (contextService != null && commentContext != null) { - contextService.deactivateContext(commentContext); - commentContext = null; - } - if (textSupport != null) { - textSupport.dispose(); - } + commentEditor.dispose(); } /** |