diff options
Diffstat (limited to 'org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks')
31 files changed, 0 insertions, 7028 deletions
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/AbstractRepositoryConnectorUi.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/AbstractRepositoryConnectorUi.java deleted file mode 100644 index 05127bd2b..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/AbstractRepositoryConnectorUi.java +++ /dev/null @@ -1,245 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Mylyn project committers 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.ui; - -import java.util.Collections; -import java.util.List; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.text.hyperlink.IHyperlink; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.wizard.IWizard; -import org.eclipse.jface.wizard.IWizardPage; -import org.eclipse.mylyn.internal.tasks.ui.wizards.CommonAddExistingTaskWizard; -import org.eclipse.mylyn.tasks.core.IRepositoryElement; -import org.eclipse.mylyn.tasks.core.IRepositoryQuery; -import org.eclipse.mylyn.tasks.core.ITask; -import org.eclipse.mylyn.tasks.core.ITaskComment; -import org.eclipse.mylyn.tasks.core.ITaskMapping; -import org.eclipse.mylyn.tasks.core.TaskRepository; -import org.eclipse.mylyn.tasks.core.ITask.PriorityLevel; -import org.eclipse.mylyn.tasks.core.data.TaskAttachmentModel; -import org.eclipse.mylyn.tasks.ui.editors.TaskEditor; -import org.eclipse.mylyn.tasks.ui.wizards.ITaskRepositoryPage; -import org.eclipse.mylyn.tasks.ui.wizards.ITaskSearchPage; -import org.eclipse.mylyn.tasks.ui.wizards.TaskAttachmentPage; - -/** - * Extend to provide connector-specific UI extensions. - * - * TODO: consider refactoring into extension points - * - * @author Mik Kersten - * @author Eugene Kuleshov - * @since 2.0 - */ -public abstract class AbstractRepositoryConnectorUi { - - private static final String LABEL_TASK_DEFAULT = "Task"; - - private boolean customNotificationHandling = false; - - /** - * @return the unique type of the repository, e.g. "bugzilla" - */ - public abstract String getConnectorKind(); - - /** - * @since 3.0 - */ - public abstract ITaskRepositoryPage getSettingsPage(TaskRepository taskRepository); - - /** - * @param repository - * @param queryToEdit - * can be null - * @since 3.0 - */ - public abstract IWizard getQueryWizard(TaskRepository repository, IRepositoryQuery queryToEdit); - - /** - * @since 3.0 - */ - public abstract IWizard getNewTaskWizard(TaskRepository taskRepository, ITaskMapping selection); - - /** - * Override to return a custom task editor ID. If overriding this method the connector becomes responsible for - * showing the additional pages handled by the default task editor. As of Mylyn 2.0M2 these are the Planning and - * Context pages. - * - * @since 3.0 - */ - public String getTaskEditorId(ITask repositoryTask) { - return TaskEditor.ID_EDITOR; - } - - public abstract boolean hasSearchPage(); - - /** - * Contributions to the UI legend. - * - * @deprecated use {@link #getLegendElements()} instead - */ - @Deprecated - public List<ITask> getLegendItems() { - return Collections.emptyList(); - } - - /** - * Contributions to the UI legend. - * - * @since 3.0 - */ - public List<LegendElement> getLegendElements() { - return Collections.emptyList(); - } - - /** - * @param repositoryTask - * can be null - * @since 3.0 - */ - public String getTaskKindLabel(ITask task) { - return LABEL_TASK_DEFAULT; - } - - /** - * Connector-specific task icons. Not recommended to override unless providing custom icons and kind overlays. - * - * For connectors that have a decorator that they want to reuse, the connector can maintain a reference to the label - * provider and get the descriptor from the images it returns. - * - * @since 3.0 - */ - public ImageDescriptor getImageDescriptor(IRepositoryElement element) { - if (element instanceof IRepositoryQuery) { - return TasksUiImages.QUERY; - } else if (element instanceof ITask) { - return TasksUiImages.TASK; - } else { - return null; - } - } - - /** - * Task kind overlay, recommended to override with connector-specific overlay. - * - * @since 3.0 - */ - public ImageDescriptor getTaskKindOverlay(ITask task) { - return null; - } - - /** - * Connector-specific priority icons. Not recommended to override since priority icons are used elsewhere in the - * Task List UI (e.g. filter selection in view menu). - * - * @since 3.0 - */ - public ImageDescriptor getTaskPriorityOverlay(ITask task) { - return TasksUiImages.getImageDescriptorForPriority(PriorityLevel.fromString(task.getPriority())); - } - - public IWizard getAddExistingTaskWizard(TaskRepository repository) { - return new CommonAddExistingTaskWizard(repository); - } - - /** - * @since 3.0 - */ - public ITaskSearchPage getSearchPage(TaskRepository repository, IStructuredSelection selection) { - return null; - } - - /** - * Override to return a URL that provides the user with an account creation page for the repository - * - * @param taskRepository - * TODO - */ - public String getAccountCreationUrl(TaskRepository taskRepository) { - return null; - } - - /** - * Override to return a URL that provides the user with an account management page for the repository - * - * @param taskRepository - * TODO - */ - public String getAccountManagementUrl(TaskRepository taskRepository) { - return null; - } - - /** - * Override to return a URL that provides the user with a history page for the task. - * - * @return a url of a page for the history of the task; null, if no history url is available - * @since 3.0 - */ - public String getTaskHistoryUrl(TaskRepository taskRepository, ITask task) { - return null; - } - - /** - * Override to return a textual reference to a comment, e.g. for Bugzilla this method returns <code>#12</code> for - * comment 12. This reference is used when generating replies to comments - * - * @return a reference to <code>comment</code>; null, if no reference is available - * @since 3.0 - */ - public String getReplyText(TaskRepository taskRepository, ITask task, ITaskComment taskComment, boolean includeTask) { - return null; - } - - /** - * Returns an array of hyperlinks that link to tasks within <code>text</code>. - * - * @param repository - * the task repository, never <code>null</code> - * @param text - * the line of text - * @param textOffset - * the offset within <code>text</code> - * @param lineOffset - * the offset of <code>text</code> - * @return an array of hyperlinks - * @since 2.0 - */ - public IHyperlink[] findHyperlinks(TaskRepository repository, String text, int textOffset, int lineOffset) { - return null; - } - - @Deprecated - public void setCustomNotificationHandling(boolean customNotifications) { - this.customNotificationHandling = customNotifications; - } - - /** - * @since 3.0 - */ - public boolean hasCustomNotifications() { - return customNotificationHandling; - } - - /** - * @since 3.0 - * @return true if connector doesn't support non-grouping (flattening) of subtasks - */ - public boolean hasStrictSubtaskHierarchy() { - return false; - } - - /** - * @since 3.0 - */ - public IWizardPage getTaskAttachmentPage(TaskAttachmentModel model) { - return new TaskAttachmentPage(model); - } -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/AbstractTaskRepositoryLinkProvider.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/AbstractTaskRepositoryLinkProvider.java deleted file mode 100644 index 41af44d98..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/AbstractTaskRepositoryLinkProvider.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Mylyn project committers 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.ui; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExecutableExtension; -import org.eclipse.mylyn.tasks.core.IRepositoryManager; -import org.eclipse.mylyn.tasks.core.TaskRepository; - -/** - * Extend to provide linking between repositories and tasks. - * - * @author Eugene Kuleshov - * @since 2.0 - */ -public abstract class AbstractTaskRepositoryLinkProvider implements IExecutableExtension { - - private static final int DEFAULT_ORDER = 1000; - - private String id; - - private String name; - - private int order; - - public void setInitializationData(IConfigurationElement config, String propertyName, Object data) { - id = config.getAttribute("id"); - name = config.getAttribute("name"); - try { - order = Integer.parseInt(config.getAttribute("order")); - } catch (NumberFormatException ex) { - order = DEFAULT_ORDER; - } - } - - /** - * This operation is invoked frequently by hyperlink detectors and needs to be fast (i.e. cannot do network access - * or invoke long-running refreshes). Return null if the repository cannot be resolved without excessive file I/O.@since 3.0 - * @since 3.0 - */ - public abstract TaskRepository getTaskRepository(IResource resource, IRepositoryManager repositoryManager); - - public boolean canSetTaskRepository(IResource resource) { - return false; - } - - public boolean setTaskRepository(IResource resource, TaskRepository repository) { - return false; - } - - public String getId() { - return id; - } - - public String getName() { - return name; - } - - public int getOrder() { - return order; - } -}
\ No newline at end of file diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/ITasksUiConstants.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/ITasksUiConstants.java deleted file mode 100644 index 3ae92adf3..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/ITasksUiConstants.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Mylyn project committers 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.ui; - -/** - * @author Mik Kersten - * @since 3.0 - * @noimplement This interface is not intended to be implemented by clients. - */ -public interface ITasksUiConstants { - - public static final String ID_COMMAND_MARK_TASK_UNREAD = "org.eclipse.mylyn.tasks.ui.command.markTaskUnread"; - - public static final String ID_COMMAND_MARK_TASK_READ = "org.eclipse.mylyn.tasks.ui.command.markTaskRead"; - - public static final String ID_PAGE_PLANNING = "org.eclipse.mylyn.tasks.ui.pageFactory.Planning"; - - public static final String ID_PERSPECTIVE_PLANNING = "org.eclipse.mylyn.tasks.ui.perspectives.planning"; - - public static final String ID_PREFERENCES_COLORS_AND_FONTS = "org.eclipse.ui.preferencePages.ColorsAndFonts"; - -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/LegendElement.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/LegendElement.java deleted file mode 100644 index 500748a7e..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/LegendElement.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Mylyn project committers 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.ui; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages; -import org.eclipse.swt.graphics.Image; - -/** - * @author Steffen Pingel - * @since 3.0 - */ -public class LegendElement { - - public static LegendElement createTask(String label, ImageDescriptor overlay) { - return new LegendElement(label, CommonImages.getCompositeTaskImage(TasksUiImages.TASK, overlay, false)); - } - - private final Image image; - - private final String label; - - private LegendElement(String label, Image image) { - this.label = label; - this.image = image; - } - - public void dispose() { - } - - public Image getImage() { - return image; - } - - public String getLabel() { - return label; - } - -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TaskElementLabelProvider.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TaskElementLabelProvider.java deleted file mode 100644 index a27c31687..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TaskElementLabelProvider.java +++ /dev/null @@ -1,299 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Mylyn project committers 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.ui; - -import java.util.HashSet; -import java.util.Set; -import java.util.regex.Pattern; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.IColorProvider; -import org.eclipse.jface.viewers.IFontProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.mylyn.internal.provisional.commons.ui.CommonColors; -import org.eclipse.mylyn.internal.provisional.commons.ui.CommonFonts; -import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages; -import org.eclipse.mylyn.internal.provisional.commons.ui.CommonThemes; -import org.eclipse.mylyn.internal.tasks.core.AbstractTask; -import org.eclipse.mylyn.internal.tasks.core.Person; -import org.eclipse.mylyn.internal.tasks.core.RepositoryQuery; -import org.eclipse.mylyn.internal.tasks.core.ScheduledTaskContainer; -import org.eclipse.mylyn.internal.tasks.core.TaskCategory; -import org.eclipse.mylyn.internal.tasks.core.TaskGroup; -import org.eclipse.mylyn.internal.tasks.core.UncategorizedTaskContainer; -import org.eclipse.mylyn.internal.tasks.core.UnmatchedTaskContainer; -import org.eclipse.mylyn.internal.tasks.ui.ITaskHighlighter; -import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; -import org.eclipse.mylyn.tasks.core.IRepositoryElement; -import org.eclipse.mylyn.tasks.core.IRepositoryQuery; -import org.eclipse.mylyn.tasks.core.ITask; -import org.eclipse.mylyn.tasks.core.ITaskContainer; -import org.eclipse.mylyn.tasks.core.TaskRepository; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.Image; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.themes.IThemeManager; - -/** - * @author Mik Kersten - * @since 3.0 - */ -public class TaskElementLabelProvider extends LabelProvider implements IColorProvider, IFontProvider { - - private static final String NO_SUMMARY_AVAILABLE = ": <no summary available>"; - - private final IThemeManager themeManager = PlatformUI.getWorkbench().getThemeManager(); - - private static final Pattern pattern = Pattern.compile("\\d*: .*"); - - private boolean wideImages = false; - - private class CompositeImageDescriptor { - - ImageDescriptor icon; - - ImageDescriptor overlayKind; - - }; - - public TaskElementLabelProvider() { - this(false); - } - - public TaskElementLabelProvider(boolean wideImages) { - super(); - this.wideImages = wideImages; - } - - @Override - public Image getImage(Object element) { - CompositeImageDescriptor compositeDescriptor = getImageDescriptor(element); - if (element instanceof ITask) { - if (compositeDescriptor.overlayKind == null) { - compositeDescriptor.overlayKind = CommonImages.OVERLAY_CLEAR; - } - return CommonImages.getCompositeTaskImage(compositeDescriptor.icon, compositeDescriptor.overlayKind, - wideImages); - } else if (element instanceof ITaskContainer) { - return CommonImages.getCompositeTaskImage(compositeDescriptor.icon, CommonImages.OVERLAY_CLEAR, wideImages); - } else { - return CommonImages.getCompositeTaskImage(compositeDescriptor.icon, null, wideImages); - } - } - - private CompositeImageDescriptor getImageDescriptor(Object object) { - CompositeImageDescriptor compositeDescriptor = new CompositeImageDescriptor(); - if (object instanceof UncategorizedTaskContainer) { - compositeDescriptor.icon = TasksUiImages.CATEGORY_UNCATEGORIZED; - return compositeDescriptor; - } else if (object instanceof TaskCategory) { - compositeDescriptor.icon = TasksUiImages.CATEGORY; - } else if (object instanceof TaskGroup) { - compositeDescriptor.icon = CommonImages.GROUPING; - } - - if (object instanceof ITaskContainer) { - IRepositoryElement element = (IRepositoryElement) object; - - AbstractRepositoryConnectorUi connectorUi = null; - if (element instanceof ITask) { - ITask repositoryTask = (ITask) element; - connectorUi = TasksUiPlugin.getConnectorUi(((ITask) element).getConnectorKind()); - if (connectorUi != null) { - compositeDescriptor.overlayKind = connectorUi.getTaskKindOverlay(repositoryTask); - } - } else if (element instanceof IRepositoryQuery) { - connectorUi = TasksUiPlugin.getConnectorUi(((IRepositoryQuery) element).getConnectorKind()); - } - - if (connectorUi != null) { - compositeDescriptor.icon = connectorUi.getImageDescriptor(element); - return compositeDescriptor; - } else { - if (element instanceof UnmatchedTaskContainer) { - compositeDescriptor.icon = TasksUiImages.QUERY_UNMATCHED; - } else if (element instanceof IRepositoryQuery || object instanceof UnmatchedTaskContainer) { - compositeDescriptor.icon = TasksUiImages.QUERY; - } else if (element instanceof ITask) { - compositeDescriptor.icon = TasksUiImages.TASK; - } else if (element instanceof ScheduledTaskContainer) { - compositeDescriptor.icon = CommonImages.CALENDAR; - } else if (element instanceof Person) { - compositeDescriptor.icon = CommonImages.PERSON; - Person person = (Person) element; - TaskRepository repository = TasksUi.getRepositoryManager().getRepository(person.getConnectorKind(), - person.getRepositoryUrl()); - - if (repository != null - && !repository.isAnonymous() - && (repository.getUserName() != null && repository.getUserName().equalsIgnoreCase( - element.getHandleIdentifier()))) { - compositeDescriptor.icon = CommonImages.PERSON_ME; - } - } - return compositeDescriptor; - } - } - return compositeDescriptor; - } - - @Override - public String getText(Object object) { - if (object instanceof ITask) { - ITask task = (ITask) object; - if (task.getSummary() == null) { - if (task.getTaskKey() != null) { - return task.getTaskKey() + NO_SUMMARY_AVAILABLE; - } else { - return task.getTaskId() + NO_SUMMARY_AVAILABLE; - } - } else if (!pattern.matcher(task.getSummary()).matches()) { - if (task.getTaskKey() != null) { - return task.getTaskKey() + ": " + task.getSummary(); - } else { - return task.getSummary(); - } - } else { - return task.getSummary(); - } - } else if (object instanceof TaskGroup) { - TaskGroup element = (TaskGroup) object; - return element.getSummary();// + " / " + element.getChildren().size(); - } else if (object instanceof UnmatchedTaskContainer) { - - UnmatchedTaskContainer container = (UnmatchedTaskContainer) object; - - String result = container.getSummary(); - TaskRepository repository = TasksUi.getRepositoryManager().getRepository(container.getConnectorKind(), - container.getRepositoryUrl()); - if (repository != null) { - result = "Unmatched [" + repository.getRepositoryLabel() + "]"; - } - - return result; - - } else if (object instanceof ITaskContainer) { - IRepositoryElement element = (IRepositoryElement) object; - return element.getSummary(); - } else { - return super.getText(object); - } - } - - public Color getForeground(Object object) { - if (object instanceof AbstractTask) { - AbstractTask task = (AbstractTask) object; - if (task != null) { - if (TasksUiPlugin.getTaskActivityManager().isCompletedToday(task)) { - return themeManager.getCurrentTheme().getColorRegistry().get(CommonThemes.COLOR_COMPLETED_TODAY); - } else if (task.isCompleted()) { - return themeManager.getCurrentTheme().getColorRegistry().get(CommonThemes.COLOR_COMPLETED); - } else if (TasksUi.getTaskActivityManager().isActive(task)) { - return CommonColors.CONTEXT_ACTIVE; - } else if (TasksUiPlugin.getTaskActivityManager().isOverdue(task)) { - return themeManager.getCurrentTheme().getColorRegistry().get(CommonThemes.COLOR_OVERDUE); - } else if (TasksUiPlugin.getTaskActivityManager().isDueToday(task)) { - return themeManager.getCurrentTheme().getColorRegistry().get(CommonThemes.COLOR_SCHEDULED_TODAY); - } else if (task.getScheduledForDate() != null && task.getScheduledForDate().isDay() - && TasksUiPlugin.getTaskActivityManager().isPastReminder(task)) { - return themeManager.getCurrentTheme().getColorRegistry().get(CommonThemes.COLOR_SCHEDULED_PAST); - } else if (TasksUiPlugin.getTaskActivityManager().isScheduledForToday(task)) { - return themeManager.getCurrentTheme().getColorRegistry().get(CommonThemes.COLOR_SCHEDULED_TODAY); - } else if (TasksUiPlugin.getTaskActivityManager().isScheduledForThisWeek(task)) { - return themeManager.getCurrentTheme() - .getColorRegistry() - .get(CommonThemes.COLOR_SCHEDULED_THIS_WEEK); - } - } - } else if (object instanceof ITaskContainer) { - for (ITask child : ((ITaskContainer) object).getChildren()) { - if (child.isActive() || (child instanceof ITaskContainer && showHasActiveChild((ITaskContainer) child))) { - return CommonColors.CONTEXT_ACTIVE; - } else if (TasksUiPlugin.getTaskActivityManager().isOverdue(child)) { -// } else if ((child.isPastReminder() && !child.isCompleted()) || showHasChildrenPastDue(child)) { - return themeManager.getCurrentTheme().getColorRegistry().get(CommonThemes.COLOR_OVERDUE); - } - } - } - return null; - } - - public Color getBackground(Object element) { - if (element instanceof ITask) { - ITask task = (ITask) element; - ITaskHighlighter highlighter = TasksUiPlugin.getDefault().getHighlighter(); - if (highlighter != null) { - return highlighter.getHighlightColor(task); - } - } - return null; - } - - public Font getFont(Object element) { - if (element instanceof AbstractTask) { - if (((AbstractTask) element).isSynchronizing()) { - return CommonFonts.ITALIC; - } - } - - if (element instanceof IRepositoryQuery) { - if (((RepositoryQuery) element).isSynchronizing()) { - return CommonFonts.ITALIC; - } - } - - if (element instanceof ITaskContainer) { - for (ITask child : ((ITaskContainer) element).getChildren()) { - if (child.isActive() || (child instanceof ITaskContainer && showHasActiveChild((ITaskContainer) child))) { - return CommonFonts.BOLD; - } - } - } - - if (element instanceof AbstractTask) { - if (((AbstractTask) element).isActive()) { - return CommonFonts.BOLD; - } else if (((AbstractTask) element).isCompleted()) { - return CommonFonts.STRIKETHROUGH; - } - for (ITask child : ((ITaskContainer) element).getChildren()) { - if (child.isActive() || (child instanceof ITaskContainer && showHasActiveChild((ITaskContainer) child))) { - return CommonFonts.BOLD; - } - } - } - return null; - } - - private boolean showHasActiveChild(ITaskContainer container) { - if (!TasksUiPlugin.getDefault().groupSubtasks(container)) { - return false; - } - - return showHasActiveChildHelper(container, new HashSet<IRepositoryElement>()); - } - - private boolean showHasActiveChildHelper(ITaskContainer container, Set<IRepositoryElement> visitedContainers) { - for (IRepositoryElement child : container.getChildren()) { - if (visitedContainers.contains(child)) { - continue; - } - visitedContainers.add(child); - if (child instanceof ITask && ((AbstractTask) child).isActive()) { - return true; - } else if (child instanceof ITaskContainer) { - if (showHasActiveChildHelper((ITaskContainer) child, visitedContainers)) { - return true; - } - } - } - return false; - } -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TaskHyperlink.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TaskHyperlink.java deleted file mode 100644 index 00914ba09..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TaskHyperlink.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Mylyn project committers 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 - *******************************************************************************/ -package org.eclipse.mylyn.tasks.ui; - -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.hyperlink.IHyperlink; -import org.eclipse.mylyn.tasks.core.TaskRepository; - -/** - * Immutable. Encapsulates information for linking to tasks from text. - * - * @author Eugene Kuleshov - * @author Steffen Pingel - */ -public final class TaskHyperlink implements IHyperlink { - - private final IRegion region; - - private final TaskRepository repository; - - private final String taskId; - - public TaskHyperlink(IRegion region, TaskRepository repository, String taskId) { - this.region = region; - this.repository = repository; - this.taskId = taskId; - } - - public IRegion getHyperlinkRegion() { - return region; - } - - public String getTaskId() { - return taskId; - } - - public String getTypeLabel() { - return null; - } - - /** - * @Since 2.1 - * @return - */ - public TaskRepository getRepository() { - return repository; - } - - public String getHyperlinkText() { - return "Open Task " + taskId; - } - - public void open() { - if (repository != null) { - TasksUiUtil.openTask(repository, taskId); - } else { - MessageDialog.openError(null, "Mylyn", "Could not determine repository for report"); - } - } - -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TaskRepositoryLocationUiFactory.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TaskRepositoryLocationUiFactory.java deleted file mode 100644 index d48c541b5..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TaskRepositoryLocationUiFactory.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Mylyn project committers 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.ui; - -import org.eclipse.mylyn.commons.net.AbstractWebLocation; -import org.eclipse.mylyn.internal.tasks.ui.TaskRepositoryLocationUi; -import org.eclipse.mylyn.tasks.core.TaskRepository; -import org.eclipse.mylyn.tasks.core.TaskRepositoryLocationFactory; - -/** - * @since 2.2 - * @author Steffen Pingel - */ -public class TaskRepositoryLocationUiFactory extends TaskRepositoryLocationFactory { - - /** - * @since 3.0 - */ - @Override - public AbstractWebLocation createWebLocation(TaskRepository taskRepository) { - return new TaskRepositoryLocationUi(taskRepository); - } - -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUi.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUi.java deleted file mode 100644 index 9382c3918..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUi.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Mylyn project committers 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.ui; - -import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; -import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector; -import org.eclipse.mylyn.tasks.core.IRepositoryManager; -import org.eclipse.mylyn.tasks.core.IRepositoryModel; -import org.eclipse.mylyn.tasks.core.ITaskActivityManager; -import org.eclipse.mylyn.tasks.core.data.ITaskDataManager; - -/** - * @author Steffen Pingel - * @author Mik Kersten - * @since 3.0 - */ -public class TasksUi { - - public static AbstractRepositoryConnector getRepositoryConnector(String kind) { - return getRepositoryManager().getRepositoryConnector(kind); - } - - public static AbstractRepositoryConnectorUi getRepositoryConnectorUi(String kind) { - return TasksUiPlugin.getConnectorUi(kind); - } - - public static IRepositoryManager getRepositoryManager() { - return TasksUiPlugin.getRepositoryManager(); - } - - public static ITaskActivityManager getTaskActivityManager() { - return TasksUiPlugin.getTaskActivityManager(); - } - - public static ITaskDataManager getTaskDataManager() { - return TasksUiPlugin.getTaskDataManager(); - } - - public static IRepositoryModel getRepositoryModel() { - return TasksUiPlugin.getRepositoryModel(); - } - -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUiImages.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUiImages.java deleted file mode 100644 index 12ef15056..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUiImages.java +++ /dev/null @@ -1,207 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Mylyn project committers 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.ui; - -import java.net.MalformedURLException; -import java.net.URL; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages; -import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; -import org.eclipse.mylyn.tasks.core.ITask.PriorityLevel; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Image; - -/** - * API-3.0: consider removing images not used by clients - * - * @author Mik Kersten - * @since 3.0 - */ -public class TasksUiImages { - - private static final URL baseURL = TasksUiPlugin.getDefault().getBundle().getEntry("/icons/"); - - private static final String VIEW = "eview16"; - - private static final String TOOL = "etool16"; - - private static final String OBJ = "obj16"; - - private static final String WIZBAN = "wizban"; - - // Tasks and Task List elements - - public static final ImageDescriptor TASK = create(TOOL, "task.gif"); - - public static final ImageDescriptor TASK_COMPLETE = create(TOOL, "task-complete.gif"); - - public static final ImageDescriptor TASK_INCOMPLETE = create(TOOL, "task-incomplete.gif"); - - public static final ImageDescriptor TASK_COMPLETED = create(TOOL, "task-completed.gif"); - - public static final ImageDescriptor TASK_NOTES = create(TOOL, "task-notes.gif"); - - public static final ImageDescriptor TASK_NEW = create(TOOL, "task-new.gif"); - - public static final ImageDescriptor TASK_NEW_SUB = create(TOOL, "sub-task-new.gif"); - - public static final ImageDescriptor TASK_REPOSITORY_HISTORY = create(TOOL, "task-repository-history.gif"); - - public static final ImageDescriptor TASK_REMOTE = create(TOOL, "task-remote.gif"); - - public static final ImageDescriptor TASK_WORKING_SET = create(TOOL, "open-task.gif"); - - public static final ImageDescriptor TASKS_VIEW = create("eview16", "task-list.gif"); - - public static final ImageDescriptor TASK_ATTACHMENT_PATCH = create(OBJ, "attachment-patch.gif"); - - public static final ImageDescriptor TASK_RETRIEVE = create(TOOL, "task-retrieve.gif"); - - public static final ImageDescriptor TASK_REPOSITORY = create(TOOL, "task-repository.gif"); - - public static final ImageDescriptor TASK_REPOSITORY_NEW = create(TOOL, "task-repository-new.gif"); - - public static final ImageDescriptor CATEGORY = create(TOOL, "category.gif"); - - public static final ImageDescriptor CATEGORY_NEW = create(TOOL, "category-new.gif"); - - public static final ImageDescriptor CATEGORY_UNCATEGORIZED = create(TOOL, "category-archive.gif"); - - public static final ImageDescriptor QUERY = create(TOOL, "query.gif"); - - public static final ImageDescriptor QUERY_NEW = create(TOOL, "query-new.gif"); - - public static final ImageDescriptor QUERY_UNMATCHED = create(TOOL, "query-unmatched.png"); - - public static final ImageDescriptor REPOSITORY = create("eview16", "repository.gif"); - - public static final ImageDescriptor REPOSITORY_OFFLINE = ImageDescriptor.createWithFlags(TasksUiImages.REPOSITORY, - SWT.IMAGE_GRAY); - - public static final ImageDescriptor REPOSITORY_SYNCHRONIZE = create(TOOL, "repository-synchronize.gif"); - - public static final ImageDescriptor REPOSITORY_SUBMIT = create(TOOL, "repository-submit.gif"); - - public static final ImageDescriptor REPOSITORY_SMALL = create(OBJ, "repository-small.gif"); - - public static final ImageDescriptor REPOSITORY_NEW = create("etool16", "repository-new.gif"); - - public static final ImageDescriptor REPOSITORIES_VIEW = create("eview16", "repositories.gif"); - - // Context and activation - - public static final ImageDescriptor CONTEXT_ACTIVE = create(TOOL, "task-active.gif"); - - public static final ImageDescriptor CONTEXT_ACTIVE_CENTERED = create(TOOL, "task-active-centered.gif"); - - public static final ImageDescriptor CONTEXT_INACTIVE_EMPTY = create(TOOL, "task-inactive.gif"); - - public static final ImageDescriptor CONTEXT_INACTIVE = create(TOOL, "task-context.gif"); - - public static final ImageDescriptor CONTEXT_FOCUS = create(VIEW, "focus.gif"); - - public static final ImageDescriptor CONTEXT_ATTACH = create(TOOL, "context-attach.gif"); - - public static final ImageDescriptor CONTEXT_RETRIEVE = create(TOOL, "context-retrieve.gif"); - - public static final ImageDescriptor CONTEXT_TRANSFER = create(TOOL, "context-transfer.gif"); - - public static final ImageDescriptor CONTEXT_CLEAR = create(TOOL, "context-clear.gif"); - - public static final ImageDescriptor CONTEXT_HISTORY_PREVIOUS = create(TOOL, "navigate-previous.gif"); - - public static final ImageDescriptor CONTEXT_HISTORY_PREVIOUS_PAUSE = create(TOOL, "navigate-previous-pause.gif"); - - public static final ImageDescriptor CONTEXT_HISTORY_PREVIOUS_ACTIVE = create(TOOL, "navigate-previous-active.gif"); - - public static final ImageDescriptor CONTEXT_HISTORY_NEXT = create(TOOL, "navigate-next.gif"); - - public static final ImageDescriptor CONTEXT_CAPTURE_PAUSE = create(TOOL, "capture-pause.gif"); - - public static final ImageDescriptor CONTEXT_ADD = create(TOOL, "context-add.gif"); - - public static final ImageDescriptor CONTEXT_COPY = create(TOOL, "context-transfer.gif"); - - // Comments and collaboration - - public static final ImageDescriptor COMMENT = create(TOOL, "comment.gif"); - - public static final ImageDescriptor COMMENT_SORT_DOWN = create(TOOL, "sort-down.gif"); - - public static final ImageDescriptor COMMENT_SORT_UP = create(TOOL, "sort-up.gif"); - - public static final ImageDescriptor COMMENT_SORT_DOWN_GRAY = create(TOOL, "sort-down-gray.gif"); - - public static final ImageDescriptor COMMENT_SORT_UP_GRAY = create(TOOL, "sort-up-gray.gif"); - - public static final ImageDescriptor COMMENT_REPLY = create(TOOL, "reply.gif"); - - // Wizard banners - - public static final ImageDescriptor BANNER_REPOSITORY = create(WIZBAN, "banner-repository.gif"); - - public static final ImageDescriptor BANNER_REPOSITORY_SETTINGS = create(WIZBAN, "banner-repository-settings.gif"); - - public static final ImageDescriptor BANNER_REPOSITORY_CONTEXT = create(WIZBAN, "banner-repository-context.gif"); - - public static final ImageDescriptor BANNER_WORKING_SET = create(WIZBAN, "workset_wiz.png"); - - public static Image getImageForPriority(PriorityLevel priorityLevel) { - if (priorityLevel == null) { - return null; - } else { - ImageDescriptor imageDescriptor = getImageDescriptorForPriority(priorityLevel); - if (imageDescriptor != null) { - return CommonImages.getImage(imageDescriptor); - } - } - return null; - } - - public static ImageDescriptor getImageDescriptorForPriority(PriorityLevel priorityLevel) { - if (priorityLevel == null) { - return null; - } - switch (priorityLevel) { - case P1: - return CommonImages.PRIORITY_1; - case P2: - return CommonImages.PRIORITY_2; - case P3: - return CommonImages.PRIORITY_3; - case P4: - return CommonImages.PRIORITY_4; - case P5: - return CommonImages.PRIORITY_5; - default: - return null; - } - } - - public static ImageDescriptor create(String prefix, String name) { - try { - return ImageDescriptor.createFromURL(makeIconFileURL(prefix, name)); - } catch (MalformedURLException e) { - return ImageDescriptor.getMissingImageDescriptor(); - } - } - - private static URL makeIconFileURL(String prefix, String name) throws MalformedURLException { - if (baseURL == null) { - throw new MalformedURLException(); - } - - StringBuffer buffer = new StringBuffer(prefix); - buffer.append('/'); - buffer.append(name); - return new URL(baseURL, buffer.toString()); - } - -} 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 deleted file mode 100644 index 0e2996461..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/TasksUiUtil.java +++ /dev/null @@ -1,506 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Mylyn project committers 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.ui; - -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Calendar; -import java.util.Collection; -import java.util.List; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredViewer; -import org.eclipse.jface.window.Window; -import org.eclipse.jface.wizard.IWizard; -import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.mylyn.commons.core.StatusHandler; -import org.eclipse.mylyn.internal.tasks.core.AbstractTask; -import org.eclipse.mylyn.internal.tasks.core.LocalTask; -import org.eclipse.mylyn.internal.tasks.ui.ITasksUiPreferenceConstants; -import org.eclipse.mylyn.internal.tasks.ui.TasksUiMessages; -import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; -import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal; -import org.eclipse.mylyn.internal.tasks.ui.views.TaskListView; -import org.eclipse.mylyn.internal.tasks.ui.views.TaskRepositoriesView; -import org.eclipse.mylyn.internal.tasks.ui.wizards.EditRepositoryWizard; -import org.eclipse.mylyn.internal.tasks.ui.wizards.MultiRepositoryAwareWizard; -import org.eclipse.mylyn.internal.tasks.ui.wizards.NewLocalTaskWizard; -import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector; -import org.eclipse.mylyn.tasks.core.IRepositoryQuery; -import org.eclipse.mylyn.tasks.core.ITask; -import org.eclipse.mylyn.tasks.core.ITaskMapping; -import org.eclipse.mylyn.tasks.core.TaskRepository; -import org.eclipse.mylyn.tasks.core.ITask.SynchronizationState; -import org.eclipse.mylyn.tasks.ui.editors.TaskEditor; -import org.eclipse.mylyn.tasks.ui.editors.TaskEditorInput; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.browser.IWebBrowser; -import org.eclipse.ui.browser.IWorkbenchBrowserSupport; -import org.eclipse.ui.internal.browser.WebBrowserPreference; -import org.eclipse.ui.internal.browser.WorkbenchBrowserSupport; - -/** - * @since 2.0 - * @author Mik Kersten - * @author Steffen Pingel - * @author Shawn Minto - */ -public class TasksUiUtil { - - /** - * Flag that is passed along to the workbench browser support when a task is opened in a browser because no rich - * editor was available. - * - * @see #openTask(String) - */ - public static final int FLAG_NO_RICH_EDITOR = 1 << 17; - - private static final String ATTRIBUTE_OUTGOING_NEW_CONNECTOR_KIND = "outgoingNewConnectorKind"; - - /** - * @since 3.0 - */ - public static ITask createOutgoingNewTask(String connectorKind) { - Assert.isNotNull(connectorKind); - LocalTask task = TasksUiInternal.createNewLocalTask(null); - task.setAttribute(ATTRIBUTE_OUTGOING_NEW_CONNECTOR_KIND, connectorKind); - task.setSynchronizationState(SynchronizationState.OUTGOING_NEW); - return task; - } - - /** - * @since 3.0 - */ - public static boolean isOutgoingNewTask(ITask task, String connectorKind) { - Assert.isNotNull(task); - Assert.isNotNull(connectorKind); - return connectorKind.equals(task.getAttribute(ATTRIBUTE_OUTGOING_NEW_CONNECTOR_KIND)); - } - - public static TaskRepository getSelectedRepository() { - return getSelectedRepository(null); - } - - /** - * Will use the workbench window's selection if viewer's selection is null - */ - public static TaskRepository getSelectedRepository(StructuredViewer viewer) { - IStructuredSelection selection = null; - if (viewer != null) { - selection = (IStructuredSelection) viewer.getSelection(); - } - if (selection == null || selection.isEmpty()) { - IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - ISelection windowSelection = window.getSelectionService().getSelection(); - if (windowSelection instanceof IStructuredSelection) { - selection = (IStructuredSelection) windowSelection; - } - } - - if (selection == null) { - return null; - } - - Object element = selection.getFirstElement(); - if (element instanceof TaskRepository) { - return (TaskRepository) selection.getFirstElement(); - } else if (element instanceof IRepositoryQuery) { - IRepositoryQuery query = (IRepositoryQuery) element; - return TasksUi.getRepositoryManager().getRepository(query.getConnectorKind(), query.getRepositoryUrl()); - } else if (element instanceof ITask) { - ITask task = (ITask) element; - return TasksUi.getRepositoryManager().getRepository(task.getConnectorKind(), task.getRepositoryUrl()); - } else if (element instanceof IResource) { - IResource resource = (IResource) element; - return TasksUiPlugin.getDefault().getRepositoryForResource(resource); - } else if (element instanceof IAdaptable) { - IAdaptable adaptable = (IAdaptable) element; - IResource resource = (IResource) adaptable.getAdapter(IResource.class); - if (resource != null) { - return TasksUiPlugin.getDefault().getRepositoryForResource(resource); - } else { - ITask task = (ITask) adaptable.getAdapter(AbstractTask.class); - if (task != null) { - ITask rtask = task; - return TasksUi.getRepositoryManager().getRepository(rtask.getConnectorKind(), - rtask.getRepositoryUrl()); - } - } - } - - // TODO mapping between LogEntry.pliginId and repositories - // TODO handle other selection types - return null; - } - - private static String getTaskEditorId(final ITask task) { - String taskEditorId = TaskEditor.ID_EDITOR; - if (task != null) { - ITask repositoryTask = task; - AbstractRepositoryConnectorUi repositoryUi = TasksUiPlugin.getConnectorUi(repositoryTask.getConnectorKind()); - String customTaskEditorId = repositoryUi.getTaskEditorId(repositoryTask); - if (customTaskEditorId != null) { - taskEditorId = customTaskEditorId; - } - } - return taskEditorId; - } - - public static IEditorPart openEditor(IEditorInput input, String editorId, IWorkbenchPage page) { - try { - return page.openEditor(input, editorId); - } catch (PartInitException e) { - StatusHandler.fail(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Open for editor failed: " + input - + ", taskId: " + editorId, e)); - } - return null; - } - - public static int openEditRepositoryWizard(TaskRepository repository) { - try { - EditRepositoryWizard wizard = new EditRepositoryWizard(repository); - Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); - if (shell != null && !shell.isDisposed()) { - WizardDialog dialog = new WizardDialog(shell, wizard); - dialog.create(); - dialog.setBlockOnOpen(true); - if (dialog.open() == Window.CANCEL) { - dialog.close(); - return Window.CANCEL; - } - } - - if (TaskRepositoriesView.getFromActivePerspective() != null) { - TaskRepositoriesView.getFromActivePerspective().getViewer().refresh(); - } - } catch (Exception e) { - StatusHandler.fail(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, e.getMessage(), e)); - } - return Window.OK; - } - - /** - * @since 3.0 - */ - public static boolean openNewLocalTaskEditor(Shell shell, ITaskMapping taskSelection) { - return openNewTaskEditor(shell, new NewLocalTaskWizard(taskSelection), taskSelection); - } - - private static boolean openNewTaskEditor(Shell shell, IWizard wizard, ITaskMapping taskSelection) { - WizardDialog dialog = new WizardDialog(shell, wizard); - dialog.setBlockOnOpen(true); - - // make sure the wizard has created its pages - dialog.create(); - if (!(wizard instanceof MultiRepositoryAwareWizard) && wizard.canFinish()) { - wizard.performFinish(); - return true; - } - - int result = dialog.open(); - return result == Window.OK; - } - - /** - * @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); - } - - if (taskRepository != null) { - AbstractRepositoryConnectorUi connectorUi = TasksUiPlugin.getConnectorUi(taskRepository.getConnectorKind()); - wizard = connectorUi.getNewTaskWizard(taskRepository, taskSelection); - } else { - wizard = TasksUiInternal.createNewTaskWizard(taskSelection); - } - - return openNewTaskEditor(shell, wizard, taskSelection); - } - - /** - * Either pass in a repository and taskId, or fullUrl, or all of them - * - * @deprecated Use {@link #openTask(String,String,String)} instead - */ - @Deprecated - public static boolean openRepositoryTask(String repositoryUrl, String taskId, String fullUrl) { - return openTask(repositoryUrl, taskId, fullUrl); - } - - /** - * @deprecated Use {@link #openTask(TaskRepository,String)} instead - */ - @Deprecated - public static boolean openRepositoryTask(TaskRepository repository, String taskId) { - return openTask(repository, taskId); - } - - /** - * @since 3.0 - */ - public static boolean openTask(ITask task) { - Assert.isNotNull(task); - IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - if (window != null) { - boolean openWithBrowser = !TasksUiPlugin.getDefault().getPreferenceStore().getBoolean( - ITasksUiPreferenceConstants.EDITOR_TASKS_RICH); - if (openWithBrowser) { - openUrl(task.getUrl()); - return true; - } else { - TaskRepository taskRepository = TasksUi.getRepositoryManager().getRepository(task.getConnectorKind(), - task.getRepositoryUrl()); - IEditorInput editorInput = new TaskEditorInput(taskRepository, task); - boolean wasOpen = refreshEditorContentsIfOpen(task, editorInput); - if (wasOpen) { - synchronizeTask(task); - return true; - } else { - IWorkbenchPage page = window.getActivePage(); - IEditorPart editor = openEditor(editorInput, getTaskEditorId(task), page); - if (editor != null) { - synchronizeTask(task); - return true; - } - } - } - } else { - StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Unable to open editor for \"" - + task.getSummary() + "\": no active workbench window")); - } - return false; - } - - private static void synchronizeTask(ITask task) { - if (task instanceof LocalTask) { - return; - } - - AbstractRepositoryConnector connector = TasksUi.getRepositoryManager().getRepositoryConnector( - task.getConnectorKind()); - TasksUiInternal.synchronizeTask(connector, task, false, null); - } - - /** - * Resolves a rich editor for the task if available. - * - * @since 3.0 - */ - public static void openTask(String url) { - AbstractTask task = TasksUiUtil.getTaskByUrl(url); - if (task != null && !(task instanceof LocalTask)) { - openTask(task); - } else { - boolean opened = false; - AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager() - .getConnectorForRepositoryTaskUrl(url); - if (connector != null) { - String repositoryUrl = connector.getRepositoryUrlFromTaskUrl(url); - String id = connector.getTaskIdFromTaskUrl(url); - TaskRepository repository = TasksUi.getRepositoryManager().getRepository(connector.getConnectorKind(), - repositoryUrl); - opened = openTask(repository, id); - } - if (!opened) { - openUrl(url, 0); - } - } - } - - /** - * Either pass in a repository and taskId, or fullUrl, or all of them - * - * @since 3.0 - */ - public static boolean openTask(String repositoryUrl, String taskId, String fullUrl) { - AbstractTask task = null; - if (repositoryUrl != null && taskId != null) { - task = (AbstractTask) TasksUiInternal.getTaskList().getTask(repositoryUrl, taskId); - } - if (task == null && fullUrl != null) { - task = TasksUiUtil.getTaskByUrl(fullUrl); - } - if (task == null && repositoryUrl != null && taskId != null) { - task = TasksUiPlugin.getTaskList().getTaskByKey(repositoryUrl, taskId); - } - - if (task != null) { - return TasksUiUtil.openTask(task); - } - - boolean opened = false; - - AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager().getConnectorForRepositoryTaskUrl( - fullUrl); - if (connector != null) { - AbstractRepositoryConnectorUi connectorUi = TasksUiPlugin.getConnectorUi(connector.getConnectorKind()); - if (repositoryUrl != null && taskId != null) { - opened = TasksUiInternal.openRepositoryTask(connectorUi.getConnectorKind(), repositoryUrl, taskId); - } else { - repositoryUrl = connector.getRepositoryUrlFromTaskUrl(fullUrl); - taskId = connector.getTaskIdFromTaskUrl(fullUrl); - if (repositoryUrl != null && taskId != null) { - opened = TasksUiInternal.openRepositoryTask(connectorUi.getConnectorKind(), repositoryUrl, taskId); - } - } - } - - if (!opened) { - TasksUiUtil.openUrl(fullUrl); - } - - return true; - } - - /** - * Searches for a task whose URL matches - * - * @return first task with a matching URL. - * @since 2.0 - */ - private static AbstractTask getTaskByUrl(String taskUrl) { - Collection<AbstractTask> tasks = TasksUiPlugin.getTaskList().getAllTasks(); - for (AbstractTask task : tasks) { - String currUrl = task.getUrl(); - if (currUrl != null && !currUrl.equals("") && currUrl.equals(taskUrl)) { - return task; - } - } - return null; - } - - /** - * @since 3.0 - */ - public static boolean openTask(TaskRepository repository, String taskId) { - Assert.isNotNull(repository); - Assert.isNotNull(taskId); - - AbstractTask task = (AbstractTask) TasksUiInternal.getTaskList().getTask(repository.getRepositoryUrl(), taskId); - if (task == null) { - task = TasksUiPlugin.getTaskList().getTaskByKey(repository.getRepositoryUrl(), taskId); - } - if (task != null) { - return TasksUiUtil.openTask(task); - } else { - AbstractRepositoryConnectorUi connectorUi = TasksUiPlugin.getConnectorUi(repository.getConnectorKind()); - if (connectorUi != null) { - try { - return TasksUiInternal.openRepositoryTask(connectorUi.getConnectorKind(), - repository.getRepositoryUrl(), taskId); - } catch (Exception e) { - StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, - "Internal error while opening repository task", e)); - } - } - } - return false; - } - - /** - * @since 3.0 - */ - public static void openUrl(String location) { - openUrl(location, FLAG_NO_RICH_EDITOR); - } - - private static void openUrl(String location, int customFlags) { - try { - URL url = null; - - if (location != null) { - url = new URL(location); - } - if (WebBrowserPreference.getBrowserChoice() == WebBrowserPreference.EXTERNAL) { - try { - IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport(); - support.getExternalBrowser().openURL(url); - } catch (Exception e) { - StatusHandler.fail(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Could not open task url", e)); - } - } else { - IWebBrowser browser = null; - int flags = 0; - if (WorkbenchBrowserSupport.getInstance().isInternalWebBrowserAvailable()) { - flags = IWorkbenchBrowserSupport.AS_EDITOR | IWorkbenchBrowserSupport.LOCATION_BAR - | IWorkbenchBrowserSupport.NAVIGATION_BAR; - } else { - flags = IWorkbenchBrowserSupport.AS_EXTERNAL | IWorkbenchBrowserSupport.LOCATION_BAR - | IWorkbenchBrowserSupport.NAVIGATION_BAR; - } - - String generatedId = "org.eclipse.mylyn.web.browser-" + Calendar.getInstance().getTimeInMillis(); - browser = WorkbenchBrowserSupport.getInstance().createBrowser(flags, generatedId, null, null); - browser.openURL(url); - } - } catch (PartInitException e) { - MessageDialog.openError(Display.getDefault().getActiveShell(), "Browser init error", - "Browser could not be initiated"); - } catch (MalformedURLException e) { - if (location != null && location.trim().equals("")) { - MessageDialog.openInformation(Display.getDefault().getActiveShell(), TasksUiMessages.DIALOG_EDITOR, - "No URL to open." + location); - } else { - MessageDialog.openInformation(Display.getDefault().getActiveShell(), TasksUiMessages.DIALOG_EDITOR, - "Could not open URL: " + location); - } - } - } - - /** - * If task is already open and has incoming, must force refresh in place - */ - private static boolean refreshEditorContentsIfOpen(ITask task, IEditorInput editorInput) { - if (task != null) { - if (task.getSynchronizationState() == SynchronizationState.INCOMING - || task.getSynchronizationState() == SynchronizationState.CONFLICT) { - for (TaskEditor editor : TasksUiInternal.getActiveRepositoryTaskEditors()) { - if (editor.getEditorInput().equals(editorInput)) { - editor.refreshEditorContents(); - editor.getEditorSite().getPage().activate(editor); - return true; - } - } - } - } - return false; - } - - /** - * @since 3.0 - */ - public static IViewPart openTasksViewInActivePerspective() { - try { - return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(TaskListView.ID); - } catch (Exception e) { - StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Could not show Task List view", e)); - return null; - } - } -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractAttributeEditor.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractAttributeEditor.java deleted file mode 100644 index 4a034a440..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractAttributeEditor.java +++ /dev/null @@ -1,155 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Mylyn project committers 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.ui.editors; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.mylyn.tasks.core.data.TaskAttribute; -import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper; -import org.eclipse.mylyn.tasks.core.data.TaskDataModel; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.ui.forms.IFormColors; -import org.eclipse.ui.forms.widgets.FormToolkit; - -/** - * @author Steffen Pingel - * @since 3.0 - */ -public abstract class AbstractAttributeEditor { - - public static final int MAXIMUM_HEIGHT = 140; - - public static final int MAXIMUM_WIDTH = 500; - - // XXX why is this required? - protected static final Font TEXT_FONT = JFaceResources.getDefaultFont(); - - private Control control; - - private boolean decorationEnabled; - - private Label labelControl; - - private LayoutHint layoutHint; - - private final TaskDataModel manager; - - private final TaskAttribute taskAttribute; - - private boolean readOnly; - - public AbstractAttributeEditor(TaskDataModel manager, TaskAttribute taskAttribute) { - Assert.isNotNull(manager); - Assert.isNotNull(taskAttribute); - this.manager = manager; - this.taskAttribute = taskAttribute; - setDecorationEnabled(true); - setReadOnly(taskAttribute.getMetaData().isReadOnly()); - } - - protected void attributeChanged() { - getModel().attributeChanged(getTaskAttribute()); - } - - public abstract void createControl(Composite parent, FormToolkit toolkit); - - public void createLabelControl(Composite composite, FormToolkit toolkit) { - labelControl = toolkit.createLabel(composite, getLabel()); - labelControl.setForeground(toolkit.getColors().getColor(IFormColors.TITLE)); - } - - public void dispose() { - } - - public TaskDataModel getModel() { - return manager; - } - - protected TaskAttributeMapper getAttributeMapper() { - return getModel().getTaskData().getAttributeMapper(); - } - - public Control getControl() { - return control; - } - - public String getLabel() { - String label = getAttributeMapper().getLabel(getTaskAttribute()); - return (label != null) ? label.replace("&", "&&") : null; // mask & from SWT - } - - public Label getLabelControl() { - return labelControl; - } - - public LayoutHint getLayoutHint() { - return layoutHint; - } - - public TaskAttribute getTaskAttribute() { - return taskAttribute; - } - - public boolean hasLabel() { - // TODO EDITOR - return true; - } - - public boolean isDecorationEnabled() { - return decorationEnabled; - } - - protected void setControl(Control control) { - this.control = control; - } - - public void setDecorationEnabled(boolean decorationEnabled) { - this.decorationEnabled = decorationEnabled; - } - - protected void setLayoutHint(LayoutHint layoutHint) { - this.layoutHint = layoutHint; - } - - public void decorate(Color color) { - if (isDecorationEnabled()) { - if (manager.hasBeenRead() && manager.hasIncomingChanges(getTaskAttribute())) { - decorateIncoming(color); - } - if (manager.hasOutgoingChanges(getTaskAttribute())) { - decorateOutgoing(color); - } - } - } - - protected void decorateOutgoing(Color color) { - if (labelControl != null) { - labelControl.setText("*" + labelControl.getText()); - } - } - - protected void decorateIncoming(Color color) { - if (getControl() != null) { - getControl().setBackground(color); - } - } - - public boolean isReadOnly() { - return readOnly; - } - - public void setReadOnly(boolean readOnly) { - this.readOnly = readOnly; - } - -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractRenderingEngine.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractRenderingEngine.java deleted file mode 100644 index 581176074..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractRenderingEngine.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2007 Mylyn project committers 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.ui.editors; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.mylyn.tasks.core.TaskRepository; - -/** - * Extend to provide HTML preview for ticket description and comments - * - * @author Xiaoyang Guan - * @since 2.1 - */ -// API 3.0 move to core? -public abstract class AbstractRenderingEngine { - - /** - * generate HTML preview page for <code>text</code> - */ - public abstract String renderAsHtml(TaskRepository repository, String text, IProgressMonitor monitor) - throws CoreException; -} 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 deleted file mode 100644 index 701a20fda..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractTaskEditorPage.java +++ /dev/null @@ -1,1165 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Mylyn project committers 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.ui.editors; - -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.ISafeRunnable; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.ListenerList; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.SafeRunner; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.ControlContribution; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.dialogs.IMessageProvider; -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jface.text.TextSelection; -import org.eclipse.jface.util.SafeRunnable; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.window.Window; -import org.eclipse.mylyn.commons.core.StatusHandler; -import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages; -import org.eclipse.mylyn.internal.tasks.core.AbstractTaskContainer; -import org.eclipse.mylyn.internal.tasks.core.ITaskListChangeListener; -import org.eclipse.mylyn.internal.tasks.core.TaskContainerDelta; -import org.eclipse.mylyn.internal.tasks.ui.AttachmentUtil; -import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; -import org.eclipse.mylyn.internal.tasks.ui.actions.ClearOutgoingAction; -import org.eclipse.mylyn.internal.tasks.ui.actions.NewSubTaskAction; -import org.eclipse.mylyn.internal.tasks.ui.actions.SynchronizeEditorAction; -import org.eclipse.mylyn.internal.tasks.ui.editors.EditorUtil; -import org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorActionContributor; -import org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorActionPart; -import org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorAttachmentPart; -import org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorAttributePart; -import org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorCommentPart; -import org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorDescriptionPart; -import org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorNewCommentPart; -import org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorOutlineNode; -import org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorOutlinePage; -import org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorPeoplePart; -import org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorPlanningPart; -import org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorRichTextPart; -import org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorSummaryPart; -import org.eclipse.mylyn.internal.tasks.ui.editors.TaskListChangeAdapter; -import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal; -import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector; -import org.eclipse.mylyn.tasks.core.IRepositoryElement; -import org.eclipse.mylyn.tasks.core.ITask; -import org.eclipse.mylyn.tasks.core.RepositoryStatus; -import org.eclipse.mylyn.tasks.core.TaskRepository; -import org.eclipse.mylyn.tasks.core.ITask.SynchronizationState; -import org.eclipse.mylyn.tasks.core.data.ITaskDataWorkingCopy; -import org.eclipse.mylyn.tasks.core.data.TaskAttribute; -import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper; -import org.eclipse.mylyn.tasks.core.data.TaskData; -import org.eclipse.mylyn.tasks.core.data.TaskDataModel; -import org.eclipse.mylyn.tasks.core.data.TaskDataModelEvent; -import org.eclipse.mylyn.tasks.core.data.TaskDataModelListener; -import org.eclipse.mylyn.tasks.core.sync.SubmitJob; -import org.eclipse.mylyn.tasks.core.sync.SubmitJobEvent; -import org.eclipse.mylyn.tasks.core.sync.SubmitJobListener; -import org.eclipse.mylyn.tasks.ui.AbstractRepositoryConnectorUi; -import org.eclipse.mylyn.tasks.ui.TasksUi; -import org.eclipse.mylyn.tasks.ui.TasksUiImages; -import org.eclipse.mylyn.tasks.ui.TasksUiUtil; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.custom.CTabFolder; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.dnd.DND; -import org.eclipse.swt.dnd.DropTarget; -import org.eclipse.swt.dnd.FileTransfer; -import org.eclipse.swt.dnd.TextTransfer; -import org.eclipse.swt.dnd.Transfer; -import org.eclipse.swt.events.FocusAdapter; -import org.eclipse.swt.events.FocusEvent; -import org.eclipse.swt.events.FocusListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.layout.RowLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Link; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.Spinner; -import org.eclipse.swt.widgets.TabFolder; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.Text; -import org.eclipse.swt.widgets.Tree; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IEditorSite; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.FilteredTree; -import org.eclipse.ui.forms.IFormColors; -import org.eclipse.ui.forms.IFormPart; -import org.eclipse.ui.forms.IManagedForm; -import org.eclipse.ui.forms.editor.FormPage; -import org.eclipse.ui.forms.events.HyperlinkAdapter; -import org.eclipse.ui.forms.events.HyperlinkEvent; -import org.eclipse.ui.forms.widgets.ExpandableComposite; -import org.eclipse.ui.forms.widgets.FormToolkit; -import org.eclipse.ui.forms.widgets.Hyperlink; -import org.eclipse.ui.forms.widgets.ScrolledForm; -import org.eclipse.ui.handlers.IHandlerService; -import org.eclipse.ui.views.contentoutline.IContentOutlinePage; - -/** - * Extend to provide a task editor page. - * - * @author Mik Kersten - * @author Rob Elves - * @author Steffen Pingel - * @since 3.0 - */ -public abstract class AbstractTaskEditorPage extends FormPage implements ISelectionProvider, ISelectionChangedListener { - - private class SubmitTaskJobListener extends SubmitJobListener { - - private final boolean attachContext; - - public SubmitTaskJobListener(boolean attachContext) { - this.attachContext = attachContext; - } - - @Override - public void done(SubmitJobEvent event) { - final SubmitJob job = event.getJob(); - PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { - - private void openNewTask(ITask newTask) { - AbstractTaskContainer parent = null; - AbstractTaskEditorPart actionPart = getPart(ID_PART_ACTIONS); - if (actionPart instanceof TaskEditorAttributePart) { - parent = ((TaskEditorActionPart) actionPart).getCategory(); - } - // TODO copy context and scheduling - TasksUiInternal.getTaskList().addTask(newTask, parent); - close(); - TasksUiInternal.getTaskList().deleteTask(getTask()); - TasksUiInternal.openTaskInBackground(newTask, false); - } - - public void run() { - if (job.getStatus() == null) { - if (job.getTask().equals(getTask())) { - refreshFormContent(); - } else { - openNewTask(job.getTask()); - } - } else { - handleSubmitError(job); - } - - showEditorBusy(false); - } - }); - } - - @Override - public void taskSubmitted(SubmitJobEvent event, IProgressMonitor monitor) throws CoreException { - // attach context if required - if (attachContext) { - // TODO: review - TaskAttributeMapper mapper = getModel().getTaskData().getAttributeMapper(); - TaskAttribute attribute = mapper.createTaskAttachment(getModel().getTaskData()); - AttachmentUtil.postContext(connector, getModel().getTaskRepository(), task, "", attribute, monitor); - } - } - - @Override - public void taskSynchronized(SubmitJobEvent event, IProgressMonitor monitor) { - } - - } - - 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.INCOMING) { - // automatically refresh if the user has not made any changes - refreshFormContent(); - } else { - getTaskEditor().setMessage("Task has incoming changes", IMessageProvider.WARNING, - new HyperlinkAdapter() { - @Override - public void linkActivated(HyperlinkEvent e) { - refreshFormContent(); - } - }); - setSubmitEnabled(false); - } - } - }); - } - } - } - - private static final String ERROR_NOCONNECTIVITY = "Unable to submit at this time. Check connectivity and retry."; - - public static final String ID_PART_ACTIONS = "org.eclipse.mylyn.tasks.ui.editors.parts.actions"; - - public static final String ID_PART_ATTACHMENTS = "org.eclipse.mylyn.tasks.ui.editors.parts.attachments"; - - public static final String ID_PART_ATTRIBUTES = "org.eclipse.mylyn.tasks.ui.editors.parts.attributes"; - - public static final String ID_PART_COMMENTS = "org.eclipse.mylyn.tasks.ui.editors.parts.comments"; - - public static final String ID_PART_DESCRIPTION = "org.eclipse.mylyn.tasks.ui.editors.part.descriptions"; - - public static final String ID_PART_NEW_COMMENT = "org.eclipse.mylyn.tasks.ui.editors.part.newComment"; - - public static final String ID_PART_PEOPLE = "org.eclipse.mylyn.tasks.ui.editors.part.people"; - - public static final String ID_PART_PLANNING = "org.eclipse.mylyn.tasks.ui.editors.part.planning"; - - public static final String ID_PART_SUMMARY = "org.eclipse.mylyn.tasks.ui.editors.part.summary"; - - public static final String PATH_ACTIONS = "actions"; - - public static final String PATH_ATTACHMENTS = "attachments"; - - public static final String PATH_ATTRIBUTES = "attributes"; - - public static final String PATH_COMMENTS = "comments"; - - public static final String PATH_HEADER = "header"; - - public static final String PATH_PEOPLE = "people"; - - public static final String PATH_PLANNING = "planning"; - -// private static final String ID_POPUP_MENU = "org.eclipse.mylyn.tasks.ui.editor.menu.page"; - - private AttributeEditorFactory attributeEditorFactory; - - private AttributeEditorToolkit attributeEditorToolkit; - - private Action clearOutgoingAction; - - private AbstractRepositoryConnector connector; - - private final String connectorKind; - - private StructuredSelection defaultSelection; - - private Composite editorComposite; - - private boolean expandAttributesSection; - - private ScrolledForm form; - - private boolean formBusy; - - private Action historyAction; - - protected Control lastFocusControl; - - private ISelection lastSelection; - - private TaskDataModel model; - - private boolean needsAddToCategory; - - private NewSubTaskAction newSubTaskAction; - - private Action openBrowserAction; - - private boolean reflow; - - private volatile boolean refreshDisabled; - - private final ListenerList selectionChangedListeners; - - private SynchronizeEditorAction synchronizeEditorAction; - - private ITask task; - - private TaskData taskData; - - private ITaskListChangeListener taskListChangeListener; - - private FormToolkit toolkit; - - private TaskEditorOutlinePage outlinePage; - - public AbstractTaskEditorPage(TaskEditor editor, String connectorKind) { - super(editor, "id", "label"); - Assert.isNotNull(connectorKind); - this.connectorKind = connectorKind; - this.reflow = true; - this.selectionChangedListeners = new ListenerList(); - } - - private void addFocusListener(Composite composite, FocusListener listener) { - Control[] children = composite.getChildren(); - for (Control control : children) { - if ((control instanceof Text) || (control instanceof Button) || (control instanceof Combo) - || (control instanceof CCombo) || (control instanceof Tree) || (control instanceof Table) - || (control instanceof Spinner) || (control instanceof Link) || (control instanceof List) - || (control instanceof TabFolder) || (control instanceof CTabFolder) - || (control instanceof Hyperlink) || (control instanceof FilteredTree) - || (control instanceof StyledText)) { - control.addFocusListener(listener); - } - if (control instanceof Composite) { - addFocusListener((Composite) control, listener); - } - } - } - - public void addSelectionChangedListener(ISelectionChangedListener listener) { - selectionChangedListeners.add(listener); - } - - public void appendTextToNewComment(String text) { - AbstractTaskEditorPart newCommentPart = getPart(ID_PART_NEW_COMMENT); - if (newCommentPart instanceof TaskEditorRichTextPart) { - ((TaskEditorRichTextPart) newCommentPart).appendText(text); - newCommentPart.setFocus(); - } - } - - public boolean canPerformAction(String actionId) { - return EditorUtil.canPerformAction(actionId, EditorUtil.getFocusControl(this)); - } - - public void close() { - Display activeDisplay = getSite().getShell().getDisplay(); - activeDisplay.asyncExec(new Runnable() { - public void run() { - if (getSite() != null && getSite().getPage() != null && !getManagedForm().getForm().isDisposed()) { - if (getTaskEditor() != null) { - getSite().getPage().closeEditor(getTaskEditor(), false); - } else { - getSite().getPage().closeEditor(AbstractTaskEditorPage.this, false); - } - } - } - }); - } - - protected AttributeEditorFactory createAttributeEditorFactory() { - return new AttributeEditorFactory(getModel(), getTaskRepository()); - } - - AttributeEditorToolkit createAttributeEditorToolkit() { - IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class); - return new AttributeEditorToolkit(handlerService); - } - - @Override - protected void createFormContent(final IManagedForm managedForm) { - form = managedForm.getForm(); - toolkit = managedForm.getToolkit(); - registerDropListener(form); - - try { - setReflow(false); - - editorComposite = form.getBody(); - GridLayout editorLayout = new GridLayout(); - editorComposite.setLayout(editorLayout); - editorComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); - -// 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()); - if (connectorUi == null) { - getTaskEditor().setMessage("The editor may not be fully loaded", IMessageProvider.INFORMATION, - new HyperlinkAdapter() { - @Override - public void linkActivated(HyperlinkEvent e) { - refreshFormContent(); - } - }); - } - - if (taskData != null) { - createFormContentInternal(); - } - updateHeaderMessage(); - } finally { - setReflow(true); - } - } - - private void createFormContentInternal() { - // end life-cycle of previous editor controls - if (attributeEditorToolkit != null) { - attributeEditorToolkit.dispose(); - } - - // start life-cycle of previous editor controls - if (attributeEditorFactory == null) { - attributeEditorFactory = createAttributeEditorFactory(); - Assert.isNotNull(attributeEditorFactory); - } - attributeEditorToolkit = createAttributeEditorToolkit(); - Assert.isNotNull(attributeEditorToolkit); - attributeEditorToolkit.setMenu(editorComposite.getMenu()); - attributeEditorToolkit.setSelectionChangedListener(this); - - createParts(); - - FocusListener listener = new FocusAdapter() { - @Override - public void focusGained(FocusEvent e) { - lastFocusControl = (Control) e.widget; - } - }; - addFocusListener(editorComposite, listener); - AbstractTaskEditorPart summaryPart = getPart(ID_PART_SUMMARY); - if (summaryPart != null) { - lastFocusControl = summaryPart.getControl(); - } - } - - protected TaskDataModel createModel(TaskEditorInput input) throws CoreException { - ITaskDataWorkingCopy taskDataState = TasksUi.getTaskDataManager().getWorkingCopy(task); - TaskRepository taskRepository = TasksUi.getRepositoryManager().getRepository(getConnectorKind(), - taskDataState.getRepositoryUrl()); - return new TaskDataModel(taskRepository, input.getTask(), taskDataState); - } - - protected Set<TaskEditorPartDescriptor> createPartDescriptors() { - Set<TaskEditorPartDescriptor> descriptors = new LinkedHashSet<TaskEditorPartDescriptor>(); - descriptors.add(new TaskEditorPartDescriptor(ID_PART_SUMMARY) { - @Override - public AbstractTaskEditorPart createPart() { - return new TaskEditorSummaryPart(); - } - }.setPath(PATH_HEADER)); - descriptors.add(new TaskEditorPartDescriptor(ID_PART_ATTRIBUTES) { - @Override - public AbstractTaskEditorPart createPart() { - return new TaskEditorAttributePart(); - } - }.setPath(PATH_ATTRIBUTES)); - if (!taskData.isNew()) { - descriptors.add(new TaskEditorPartDescriptor(ID_PART_ATTACHMENTS) { - @Override - public AbstractTaskEditorPart createPart() { - return new TaskEditorAttachmentPart(); - } - }.setPath(PATH_ATTACHMENTS)); - } - descriptors.add(new TaskEditorPartDescriptor(ID_PART_DESCRIPTION) { - @Override - public AbstractTaskEditorPart createPart() { - TaskEditorDescriptionPart part = new TaskEditorDescriptionPart(); - if (getModel().getTaskData().isNew()) { - part.setExpandVertically(true); - part.setSectionStyle(ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED); - } - return part; - } - }.setPath(PATH_COMMENTS)); - if (!taskData.isNew()) { - descriptors.add(new TaskEditorPartDescriptor(ID_PART_COMMENTS) { - @Override - public AbstractTaskEditorPart createPart() { - return new TaskEditorCommentPart(); - } - }.setPath(PATH_COMMENTS)); - } - descriptors.add(new TaskEditorPartDescriptor(ID_PART_NEW_COMMENT) { - @Override - public AbstractTaskEditorPart createPart() { - return new TaskEditorNewCommentPart(); - } - }.setPath(PATH_COMMENTS)); - if (taskData.isNew()) { - descriptors.add(new TaskEditorPartDescriptor(ID_PART_PLANNING) { - @Override - public AbstractTaskEditorPart createPart() { - return new TaskEditorPlanningPart(); - } - }.setPath(PATH_PLANNING)); - } - descriptors.add(new TaskEditorPartDescriptor(ID_PART_ACTIONS) { - @Override - public AbstractTaskEditorPart createPart() { - return new TaskEditorActionPart(); - } - }.setPath(PATH_ACTIONS)); - descriptors.add(new TaskEditorPartDescriptor(ID_PART_PEOPLE) { - @Override - public AbstractTaskEditorPart createPart() { - return new TaskEditorPeoplePart(); - } - }.setPath(PATH_PEOPLE)); - return descriptors; - } - - private void createParts() { - List<TaskEditorPartDescriptor> descriptors = new LinkedList<TaskEditorPartDescriptor>(createPartDescriptors()); - // single column - createParts(PATH_HEADER, editorComposite, descriptors); - createParts(PATH_ATTRIBUTES, editorComposite, descriptors); - createParts(PATH_ATTACHMENTS, editorComposite, descriptors); - createParts(PATH_COMMENTS, editorComposite, descriptors); - createParts(PATH_PLANNING, editorComposite, descriptors); - // two column - Composite bottomComposite = toolkit.createComposite(editorComposite); - bottomComposite.setLayout(new GridLayout(2, false)); - GridDataFactory.fillDefaults().grab(true, false).applyTo(bottomComposite); - createParts(PATH_ACTIONS, bottomComposite, descriptors); - createParts(PATH_PEOPLE, bottomComposite, descriptors); - bottomComposite.pack(true); - } - - private void createParts(String path, final Composite parent, Collection<TaskEditorPartDescriptor> descriptors) { - for (Iterator<TaskEditorPartDescriptor> it = descriptors.iterator(); it.hasNext();) { - final TaskEditorPartDescriptor descriptor = it.next(); - if (path == null || path.equals(descriptor.getPath())) { - SafeRunner.run(new ISafeRunnable() { - public void handleException(Throwable e) { - StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, - "Error creating task editor part: \"" + descriptor.getId() + "\"", e)); - } - - public void run() throws Exception { - AbstractTaskEditorPart part = descriptor.createPart(); - part.setPartId(descriptor.getId()); - initializePart(parent, part); - } - }); - it.remove(); - } - } - } - - @Override - public void dispose() { - if (attributeEditorToolkit != null) { - attributeEditorToolkit.dispose(); - } - TasksUiInternal.getTaskList().removeChangeListener(taskListChangeListener); - super.dispose(); - } - - public void doAction(String actionId) { - EditorUtil.doAction(actionId, EditorUtil.getFocusControl(this)); - } - - @Override - public void doSave(IProgressMonitor monitor) { - if (!isDirty()) { - return; - } - - getManagedForm().commit(true); - - try { - model.save(monitor); - } catch (final CoreException e) { - StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Error saving task", e)); - getTaskEditor().setMessage("Could not save task", IMessageProvider.ERROR, new HyperlinkAdapter() { - @Override - public void linkActivated(HyperlinkEvent event) { - TasksUiInternal.displayStatus("Save failed", e.getStatus()); - } - }); - } - - updateHeaderMessage(); - getManagedForm().dirtyStateChanged(); - getTaskEditor().updateHeaderToolBar(); - } - - @Override - public void doSaveAs() { - throw new UnsupportedOperationException(); - } - - public void doSubmit() { - showEditorBusy(true); - - doSave(new NullProgressMonitor()); - - SubmitJob submitJob = TasksUiInternal.getJobFactory().createSubmitTaskJob(connector, - getModel().getTaskRepository(), task, getModel().getTaskData(), getModel().getChangedOldAttributes()); - submitJob.addSubmitJobListener(new SubmitTaskJobListener(getAttachContext())); - submitJob.schedule(); - } - - /** - * Override for customizing the tool bar. - */ - public void fillToolBar(IToolBarManager toolBarManager) { - final TaskRepository taskRepository = (model != null) ? getModel().getTaskRepository() : null; - if (taskRepository != null) { - ControlContribution repositoryLabelControl = new ControlContribution("Title") { - @Override - protected Control createControl(Composite parent) { - FormToolkit toolkit = getTaskEditor().getHeaderForm().getToolkit(); - Composite composite = toolkit.createComposite(parent); - composite.setLayout(new RowLayout()); - composite.setBackground(null); - String label = taskRepository.getRepositoryLabel(); - if (label.indexOf("//") != -1) { - label = label.substring((taskRepository.getRepositoryUrl().indexOf("//") + 2)); - } - - Hyperlink link = new Hyperlink(composite, SWT.NONE); - link.setText(label); - link.setFont(JFaceResources.getBannerFont()); - link.setForeground(toolkit.getColors().getColor(IFormColors.TITLE)); - link.addHyperlinkListener(new HyperlinkAdapter() { - - @Override - public void linkActivated(HyperlinkEvent e) { - TasksUiUtil.openEditRepositoryWizard(taskRepository); - } - }); - - return composite; - } - }; - toolBarManager.add(repositoryLabelControl); - } - - if (taskRepository != null && !taskData.isNew()) { - synchronizeEditorAction = new SynchronizeEditorAction(); - synchronizeEditorAction.selectionChanged(new StructuredSelection(getTaskEditor())); - toolBarManager.add(synchronizeEditorAction); - - clearOutgoingAction = new ClearOutgoingAction(Collections.singletonList((IRepositoryElement) task)); - if (clearOutgoingAction.isEnabled()) { - toolBarManager.add(clearOutgoingAction); - } - - newSubTaskAction = new NewSubTaskAction(); - newSubTaskAction.selectionChanged(newSubTaskAction, new StructuredSelection(task)); - if (newSubTaskAction.isEnabled()) { - toolBarManager.add(newSubTaskAction); - } - - AbstractRepositoryConnectorUi connectorUi = TasksUiPlugin.getConnectorUi(taskData.getConnectorKind()); - if (connectorUi != null) { - final String historyUrl = connectorUi.getTaskHistoryUrl(taskRepository, task); - if (historyUrl != null) { - historyAction = new Action() { - @Override - public void run() { - TasksUiUtil.openUrl(historyUrl); - } - }; - - historyAction.setImageDescriptor(TasksUiImages.TASK_REPOSITORY_HISTORY); - historyAction.setToolTipText("History"); - toolBarManager.add(historyAction); - } - } - - final String taskUrlToOpen = task.getUrl(); - if (taskUrlToOpen != null) { - openBrowserAction = new Action() { - @Override - public void run() { - TasksUiUtil.openUrl(taskUrlToOpen); - } - }; - - openBrowserAction.setImageDescriptor(CommonImages.BROWSER_OPEN_TASK); - openBrowserAction.setToolTipText("Open with Web Browser"); - toolBarManager.add(openBrowserAction); - } - } - } - - protected void fireSelectionChanged(ISelection selection) { - // create an event - final SelectionChangedEvent event = new SelectionChangedEvent(this, selection); - - // fire the event - Object[] listeners = selectionChangedListeners.getListeners(); - for (int i = 0; i < listeners.length; ++i) { - final ISelectionChangedListener l = (ISelectionChangedListener) listeners[i]; - SafeRunner.run(new SafeRunnable() { - public void run() { - l.selectionChanged(event); - } - }); - } - } - - @SuppressWarnings("unchecked") - @Override - public Object getAdapter(Class adapter) { - if (adapter == IContentOutlinePage.class) { - updateOutlinePage(); - return outlinePage; - } - return super.getAdapter(adapter); - } - - private void updateOutlinePage() { - if (outlinePage == null) { - outlinePage = new TaskEditorOutlinePage(); - outlinePage.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - ISelection selection = event.getSelection(); - if (selection instanceof StructuredSelection) { - Object select = ((StructuredSelection) selection).getFirstElement(); - if (select instanceof TaskEditorOutlineNode) { - TaskEditorOutlineNode node = (TaskEditorOutlineNode) select; - if (node.getData() != null) { - EditorUtil.reveal(form, node.getData().getId()); - } else { - EditorUtil.reveal(form, node.getLabel()); - } - } - } - } - }); - } - if (getModel() != null) { - TaskEditorOutlineNode node = TaskEditorOutlineNode.parse(getModel().getTaskData()); - outlinePage.setInput(getTaskRepository(), node); - } else { - outlinePage.setInput(null, null); - } - } - - private boolean getAttachContext() { - AbstractTaskEditorPart actionPart = getPart(ID_PART_ACTIONS); - if (actionPart instanceof TaskEditorAttributePart) { - return ((TaskEditorActionPart) actionPart).getAttachContext(); - } - return false; - } - - public AttributeEditorFactory getAttributeEditorFactory() { - return attributeEditorFactory; - } - - public AttributeEditorToolkit getAttributeEditorToolkit() { - return attributeEditorToolkit; - } - - public AbstractRepositoryConnector getConnector() { - return connector; - } - - public String getConnectorKind() { - return connectorKind; - } - - /** - * @return The composite for the whole editor. - */ - public Composite getEditorComposite() { - return editorComposite; - } - - public TaskDataModel getModel() { - return model; - } - - public AbstractTaskEditorPart getPart(String partId) { - Assert.isNotNull(partId); - for (IFormPart part : getManagedForm().getParts()) { - if (part instanceof AbstractTaskEditorPart) { - AbstractTaskEditorPart taskEditorPart = (AbstractTaskEditorPart) part; - if (partId.equals(taskEditorPart.getPartId())) { - return taskEditorPart; - } - } - } - return null; - } - - public ISelection getSelection() { - return lastSelection; - } - - public ITask getTask() { - return task; - } - - public TaskEditor getTaskEditor() { - return (TaskEditor) getEditor(); - } - - public TaskRepository getTaskRepository() { - return getModel().getTaskRepository(); - } - - private void handleSubmitError(SubmitJob job) { - if (form != null && !form.isDisposed()) { - final IStatus status = job.getStatus(); - if (status.getCode() == RepositoryStatus.REPOSITORY_COMMENT_REQUIRED) { - TasksUiInternal.displayStatus("Comment required", status); - AbstractTaskEditorPart newCommentPart = getPart(ID_PART_NEW_COMMENT); - if (newCommentPart != null) { - newCommentPart.setFocus(); - } - } else if (status.getCode() == RepositoryStatus.ERROR_REPOSITORY_LOGIN) { - if (TasksUiUtil.openEditRepositoryWizard(getTaskRepository()) == Window.OK) { - doSubmit(); - } - } else { - String message; - if (status.getCode() == RepositoryStatus.ERROR_IO) { - message = ERROR_NOCONNECTIVITY; - } else if (status.getMessage().length() > 0) { - message = "Submit failed: " + status.getMessage(); - } else { - message = "Submit failed"; - } - getTaskEditor().setMessage(message, IMessageProvider.ERROR, new HyperlinkAdapter() { - @Override - public void linkActivated(HyperlinkEvent e) { - TasksUiInternal.displayStatus("Submit failed", status); - } - }); - } - } - } - - @Override - public void init(IEditorSite site, IEditorInput input) { - super.init(site, input); - - site.setSelectionProvider(this); - - TaskEditorInput taskEditorInput = (TaskEditorInput) input; - this.task = taskEditorInput.getTask(); - this.defaultSelection = new StructuredSelection(task); - this.lastSelection = defaultSelection; - try { - setModel(createModel(taskEditorInput)); - } catch (final CoreException e) { - StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Error opening task", e)); - getTaskEditor().setStatus("Error opening task", "Open failed", e.getStatus()); - } - - taskListChangeListener = new TaskListChangeListener(); - TasksUiInternal.getTaskList().addChangeListener(taskListChangeListener); - } - - private void initializePart(Composite parent, AbstractTaskEditorPart part) { - getManagedForm().addPart(part); - part.initialize(this); - part.createControl(parent, toolkit); - if (part.getControl() != null) { - if (part.getExpandVertically()) { - GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(part.getControl()); - } else { - GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).grab(true, false).applyTo(part.getControl()); - } - // for outline - if (ID_PART_COMMENTS.equals(part.getPartId())) { - EditorUtil.setMarker(part.getControl(), TaskEditorOutlineNode.LABEL_COMMENTS); - } - } - } - - @Override - public boolean isDirty() { - return (getModel() != null && getModel().isDirty()) || (getManagedForm() != null && getManagedForm().isDirty()); - } - - public boolean isExpandAttributesSection() { - return expandAttributesSection; - } - - @Override - public boolean isSaveAsAllowed() { - return false; - } - - public boolean needsAddToCategory() { - return needsAddToCategory; - } - - /** - * Force a re-layout of entire form. - */ - public void reflow() { - if (reflow) { - form.layout(true, true); - form.reflow(true); - } - } - - /** - * Updates the editor contents in place. - */ - public void refreshFormContent() { - if (getManagedForm().getForm().isDisposed()) { - // editor possibly closed as part of submit - return; - } - - try { - showEditorBusy(true); - - doSave(new NullProgressMonitor()); - refreshInput(); - - if (taskData != null) { - try { - setReflow(false); - // save menu - Menu menu = editorComposite.getMenu(); - setMenu(editorComposite, null); - - // clear old controls - for (Control control : editorComposite.getChildren()) { - control.dispose(); - } - lastFocusControl = null; - lastSelection = null; - - // restore menu - editorComposite.setMenu(menu); - - createFormContentInternal(); - - getTaskEditor().setMessage(null, 0); - getTaskEditor().setActivePage(getId()); - - setSubmitEnabled(true); - } finally { - setReflow(true); - } - } - - updateOutlinePage(); - updateHeaderMessage(); - getManagedForm().dirtyStateChanged(); - getTaskEditor().updateHeaderToolBar(); - } finally { - showEditorBusy(false); - } - reflow(); - } - - private void refreshInput() { - try { - refreshDisabled = true; - model.refresh(null); - } catch (CoreException e) { - getTaskEditor().setMessage("Failed to read task data: " + e.getMessage(), IMessageProvider.ERROR); - taskData = null; - return; - } finally { - refreshDisabled = false; - } - - setTaskData(model.getTaskData()); - } - - private void registerDropListener(final Control control) { - DropTarget target = new DropTarget(control, DND.DROP_COPY | DND.DROP_DEFAULT); - final TextTransfer textTransfer = TextTransfer.getInstance(); - final FileTransfer fileTransfer = FileTransfer.getInstance(); - Transfer[] types = new Transfer[] { textTransfer, fileTransfer }; - target.setTransfer(types); - - // Adapted from eclipse.org DND Article by Veronika Irvine, IBM OTI Labs - // http://www.eclipse.org/articles/Article-SWT-DND/DND-in-SWT.html#_dt10D - // TODO EDITOR - //target.addDropListener(new RepositoryTaskEditorDropListener(this, fileTransfer, textTransfer, control)); - } - - public void removeSelectionChangedListener(ISelectionChangedListener listener) { - selectionChangedListeners.remove(listener); - } - - public void selectionChanged(Object element) { - selectionChanged(new SelectionChangedEvent(this, new StructuredSelection(element))); - } - - public void selectionChanged(SelectionChangedEvent event) { - ISelection selection = event.getSelection(); - if (selection instanceof TextSelection) { - // only update global actions - ((TaskEditorActionContributor) getEditorSite().getActionBarContributor()).updateSelectableActions(event.getSelection()); - return; - } - if (selection.isEmpty()) { - // something was unselected, reset to default selection - selection = defaultSelection; - } - if (!selection.equals(lastSelection)) { - this.lastSelection = selection; - fireSelectionChanged(lastSelection); - } - } - - public void setExpandAttributeSection(boolean expandAttributeSection) { - this.expandAttributesSection = expandAttributeSection; - } - - @Override - public void setFocus() { - if (lastFocusControl != null && !lastFocusControl.isDisposed()) { - lastFocusControl.setFocus(); - } - } - - /** - * Used to prevent form menu from being disposed when disposing elements on the form during refresh - */ - private void setMenu(Composite comp, Menu menu) { - if (!comp.isDisposed()) { - comp.setMenu(null); - for (Control child : comp.getChildren()) { - child.setMenu(null); - if (child instanceof Composite) { - setMenu((Composite) child, menu); - } - } - } - } - - private void setModel(TaskDataModel model) { - Assert.isNotNull(model); - this.model = model; - this.connector = TasksUi.getRepositoryManager().getRepositoryConnector(getConnectorKind()); - setTaskData(model.getTaskData()); - model.addModelListener(new TaskDataModelListener() { - @Override - public void attributeChanged(TaskDataModelEvent event) { - getManagedForm().dirtyStateChanged(); - } - }); - } - - public void setNeedsAddToCategory(boolean needsAddToCategory) { - this.needsAddToCategory = needsAddToCategory; - } - - public void setReflow(boolean reflow) { - this.reflow = reflow; - form.setRedraw(reflow); - } - - public void setSelection(ISelection selection) { - IFormPart[] parts = getManagedForm().getParts(); - for (IFormPart formPart : parts) { - if (formPart instanceof AbstractTaskEditorPart) { - if (((AbstractTaskEditorPart) formPart).setSelection(selection)) { - lastSelection = selection; - return; - } - } - } - } - - // TODO EDITOR this needs to be tracked somewhere else - private void setSubmitEnabled(boolean enabled) { - AbstractTaskEditorPart actionPart = getPart(ID_PART_ACTIONS); - if (actionPart instanceof TaskEditorAttributePart) { - ((TaskEditorActionPart) actionPart).setSubmitEnabled(enabled); - } - } - - private void setTaskData(TaskData taskData) { - this.taskData = taskData; - } - - @Override - public void showBusy(boolean busy) { - if (!getManagedForm().getForm().isDisposed() && busy != formBusy) { - // parentEditor.showBusy(busy); -// if (synchronizeEditorAction != null) { -// synchronizeEditorAction.setEnabled(!busy); -// } -// -// if (openBrowserAction != null) { -// openBrowserAction.setEnabled(!busy); -// } -// -// if (historyAction != null) { -// historyAction.setEnabled(!busy); -// } -// -// if (actionPart != null) { -// actionPart.setSubmitEnabled(!busy); -// } -// -// if (newSubTaskAction != null) { -// newSubTaskAction.setEnabled(!busy); -// } -// -// if (clearOutgoingAction != null) { -// clearOutgoingAction.setEnabled(!busy); -// } - - EditorUtil.setEnabledState(editorComposite, !busy); - - formBusy = busy; - } - } - - public void showEditorBusy(boolean busy) { - getTaskEditor().showBusy(busy); - refreshDisabled = busy; - } - - private void updateHeaderMessage() { - if (taskData == null) { - getTaskEditor().setMessage( - "Task data not available. Press synchronize button (right) to retrieve latest data.", - IMessageProvider.WARNING, new HyperlinkAdapter() { - @Override - public void linkActivated(HyperlinkEvent e) { - if (synchronizeEditorAction != null) { - synchronizeEditorAction.run(); - } - } - }); - } - } - -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractTaskEditorPageFactory.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractTaskEditorPageFactory.java deleted file mode 100644 index d4faf347b..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractTaskEditorPageFactory.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Mylyn project committers 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.ui.editors; - -import org.eclipse.swt.graphics.Image; -import org.eclipse.ui.forms.editor.FormPage; - -/** - * @since 3.0 - * @author Steffen Pingel - */ -public abstract class AbstractTaskEditorPageFactory { - - public static final int PRIORITY_ADDITIONS = 100; - - public static final int PRIORITY_CONTEXT = 20; - - public static final int PRIORITY_PLANNING = 10; - - public static final int PRIORITY_TASK = 30; - - private String id; - - public abstract boolean canCreatePageFor(TaskEditorInput input); - - public abstract FormPage createPage(TaskEditor parentEditor); - - public String[] getConflictingIds(TaskEditorInput input) { - return null; - } - - public String getId() { - return id; - } - - // TODO EDITOR life cycle of image? - public abstract Image getPageImage(); - - public abstract String getPageText(); - - public int getPriority() { - return PRIORITY_ADDITIONS; - } - - public void setId(String id) { - this.id = id; - } - -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractTaskEditorPart.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractTaskEditorPart.java deleted file mode 100644 index e4e9037f6..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AbstractTaskEditorPart.java +++ /dev/null @@ -1,161 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Mylyn project committers 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.ui.editors; - -import org.eclipse.jface.action.ToolBarManager; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.mylyn.internal.tasks.ui.editors.RichTextAttributeEditor; -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.swt.SWT; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.layout.RowLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.ui.forms.AbstractFormPart; -import org.eclipse.ui.forms.widgets.ExpandableComposite; -import org.eclipse.ui.forms.widgets.FormToolkit; -import org.eclipse.ui.forms.widgets.Section; - -/** - * @author Steffen Pingel - * @since 3.0 - */ -public abstract class AbstractTaskEditorPart extends AbstractFormPart { - - // the default font of some controls, e.g. radio buttons, is too big; set this font explicitly on the control - protected static final Font TEXT_FONT = JFaceResources.getDefaultFont(); - - private Control control; - - private String partName; - - private String partId; - - private AbstractTaskEditorPage taskEditorPage; - - private boolean expandVertically; - - public AbstractTaskEditorPart() { - } - - protected AbstractAttributeEditor createAttributeEditor(TaskAttribute attribute) { - if (attribute == null) { - return null; - } - - String type = attribute.getMetaData().getType(); - if (type != null) { - AttributeEditorFactory attributeEditorFactory = getTaskEditorPage().getAttributeEditorFactory(); - AbstractAttributeEditor editor = attributeEditorFactory.createEditor(type, attribute); - if (editor instanceof RichTextAttributeEditor) { - boolean spellChecking = getTaskEditorPage().getAttributeEditorToolkit().hasSpellChecking(attribute); - ((RichTextAttributeEditor) editor).setSpellCheckingEnabled(spellChecking); - } - return editor; - } - return null; - } - - public abstract void createControl(Composite parent, FormToolkit toolkit); - - protected Section createSection(Composite parent, FormToolkit toolkit, int style) { - Section section = toolkit.createSection(parent, style); - section.setText(getPartName()); - return section; - } - - protected Section createSection(Composite parent, FormToolkit toolkit, boolean expandedState) { - int style = ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE; - if (expandedState) { - style |= ExpandableComposite.EXPANDED; - } - return createSection(parent, toolkit, style); - } - - protected void fillToolBar(ToolBarManager toolBarManager) { - } - - public Control getControl() { - return control; - } - - public TaskDataModel getModel() { - return getTaskEditorPage().getModel(); - } - - public String getPartId() { - return partId; - } - - public String getPartName() { - return partName; - } - - public TaskData getTaskData() { - return getTaskEditorPage().getModel().getTaskData(); - } - - public AbstractTaskEditorPage getTaskEditorPage() { - return taskEditorPage; - } - - public void initialize(AbstractTaskEditorPage taskEditorPage) { - this.taskEditorPage = taskEditorPage; - } - - public void setControl(Control control) { - this.control = control; - } - - void setPartId(String partId) { - this.partId = partId; - } - - protected void setPartName(String partName) { - this.partName = partName; - } - - protected void setSection(FormToolkit toolkit, Section section) { - if (section.getTextClient() == null) { - ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT); - fillToolBar(toolBarManager); - - // TODO toolBarManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); - - if (toolBarManager.getSize() > 0) { - Composite toolbarComposite = toolkit.createComposite(section); - toolbarComposite.setBackground(null); - RowLayout rowLayout = new RowLayout(); - rowLayout.marginTop = 0; - rowLayout.marginBottom = 0; - toolbarComposite.setLayout(rowLayout); - - toolBarManager.createControl(toolbarComposite); - section.setTextClient(toolbarComposite); - } - } - setControl(section); - } - - protected boolean setSelection(ISelection selection) { - return false; - } - - public boolean getExpandVertically() { - return expandVertically; - } - - public void setExpandVertically(boolean expandVertically) { - this.expandVertically = expandVertically; - } - -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AttributeEditorFactory.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AttributeEditorFactory.java deleted file mode 100644 index 9ce683fbd..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AttributeEditorFactory.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Mylyn project committers 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.ui.editors; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.mylyn.internal.tasks.ui.editors.BooleanAttributeEditor; -import org.eclipse.mylyn.internal.tasks.ui.editors.DateAttributeEditor; -import org.eclipse.mylyn.internal.tasks.ui.editors.LongTextAttributeEditor; -import org.eclipse.mylyn.internal.tasks.ui.editors.MultiSelectionAttributeEditor; -import org.eclipse.mylyn.internal.tasks.ui.editors.PersonAttributeEditor; -import org.eclipse.mylyn.internal.tasks.ui.editors.RichTextAttributeEditor; -import org.eclipse.mylyn.internal.tasks.ui.editors.SingleSelectionAttributeEditor; -import org.eclipse.mylyn.internal.tasks.ui.editors.TextAttributeEditor; -import org.eclipse.mylyn.internal.tasks.ui.editors.RepositoryTextViewerConfiguration.Mode; -import org.eclipse.mylyn.tasks.core.TaskRepository; -import org.eclipse.mylyn.tasks.core.data.TaskAttribute; -import org.eclipse.mylyn.tasks.core.data.TaskDataModel; -import org.eclipse.swt.SWT; - -/** - * @since 3.0 - * @author Steffen Pingel - */ -public class AttributeEditorFactory { - - private final TaskDataModel model; - - private final TaskRepository taskRepository; - - public AttributeEditorFactory(TaskDataModel model, TaskRepository taskRepository) { - this.model = model; - this.taskRepository = taskRepository; - } - - public AbstractAttributeEditor createEditor(String type, TaskAttribute taskAttribute) { - Assert.isNotNull(type); - - if (TaskAttribute.TYPE_BOOLEAN.equals(type)) { - return new BooleanAttributeEditor(model, taskAttribute); - } else if (TaskAttribute.TYPE_DATE.equals(type)) { - return new DateAttributeEditor(model, taskAttribute); - } else if (TaskAttribute.TYPE_PERSON.equals(type)) { - return new PersonAttributeEditor(model, taskAttribute); - } else if (TaskAttribute.TYPE_LONG_RICH_TEXT.equals(type)) { - return new RichTextAttributeEditor(model, taskRepository, taskAttribute); - } else if (TaskAttribute.TYPE_LONG_TEXT.equals(type)) { - return new LongTextAttributeEditor(model, taskAttribute); - } else if (TaskAttribute.TYPE_MULTI_SELECT.equals(type)) { - return new MultiSelectionAttributeEditor(model, taskAttribute); - } else if (TaskAttribute.TYPE_SHORT_RICH_TEXT.equals(type)) { - return new RichTextAttributeEditor(model, taskRepository, taskAttribute, SWT.SINGLE); - } else if (TaskAttribute.TYPE_SHORT_TEXT.equals(type)) { - return new TextAttributeEditor(model, taskAttribute); - } else if (TaskAttribute.TYPE_SINGLE_SELECT.equals(type)) { - return new SingleSelectionAttributeEditor(model, taskAttribute); - } else if (TaskAttribute.TYPE_TASK_DEPENDENCY.equals(type)) { - RichTextAttributeEditor editor = new RichTextAttributeEditor(model, taskRepository, taskAttribute, - SWT.SINGLE); - editor.setMode(Mode.TASK_RELATION); - return editor; - } else if (TaskAttribute.TYPE_URL.equals(type)) { - RichTextAttributeEditor editor = new RichTextAttributeEditor(model, taskRepository, taskAttribute, - SWT.SINGLE); - editor.setMode(Mode.URL); - return editor; - } - - throw new IllegalArgumentException("Unsupported editor type: \"" + type + "\""); - } - -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AttributeEditorToolkit.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AttributeEditorToolkit.java deleted file mode 100644 index 89fbe1562..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/AttributeEditorToolkit.java +++ /dev/null @@ -1,297 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Mylyn project committers 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 - *******************************************************************************/ -package org.eclipse.mylyn.tasks.ui.editors; - -import org.eclipse.core.commands.IHandler; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.commands.ActionHandler; -import org.eclipse.jface.fieldassist.ContentProposalAdapter; -import org.eclipse.jface.fieldassist.ControlDecoration; -import org.eclipse.jface.fieldassist.FieldDecoration; -import org.eclipse.jface.fieldassist.FieldDecorationRegistry; -import org.eclipse.jface.fieldassist.IContentProposalProvider; -import org.eclipse.jface.fieldassist.TextContentAdapter; -import org.eclipse.jface.text.ITextListener; -import org.eclipse.jface.text.TextEvent; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.jface.text.source.SourceViewer; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.mylyn.internal.provisional.commons.ui.CommonThemes; -import org.eclipse.mylyn.internal.tasks.ui.PersonProposalLabelProvider; -import org.eclipse.mylyn.internal.tasks.ui.PersonProposalProvider; -import org.eclipse.mylyn.internal.tasks.ui.editors.EditorUtil; -import org.eclipse.mylyn.internal.tasks.ui.editors.RichTextAttributeEditor; -import org.eclipse.mylyn.internal.tasks.ui.editors.RepositoryTextViewerConfiguration.Mode; -import org.eclipse.mylyn.tasks.core.data.TaskAttribute; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.events.FocusEvent; -import org.eclipse.swt.events.FocusListener; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.ActiveShellExpression; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter; -import org.eclipse.ui.handlers.IHandlerActivation; -import org.eclipse.ui.handlers.IHandlerService; -import org.eclipse.ui.keys.IBindingService; -import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; -import org.eclipse.ui.themes.IThemeManager; - -/** - * @author Steffen Pingel - * @since 3.0 - */ -// TODO EDITOR rename to AttributeUiToolkit? -public class AttributeEditorToolkit { - - private class StyledTextFocusListener implements FocusListener { - - private final boolean spellCheck; - - private final SourceViewer viewer; - - public StyledTextFocusListener(SourceViewer viewer, boolean spellCheck) { - this.viewer = viewer; - this.spellCheck = spellCheck; - } - - public void focusGained(FocusEvent e) { - if (selectionChangedListener != null) { - selectionChangedListener.selectionChanged(new SelectionChangedEvent(viewer, viewer.getSelection())); - } - activateHandlers(viewer, spellCheck); - } - - public void focusLost(FocusEvent e) { - deactivateHandlers(); - if (selectionChangedListener != null) { - // make sure selection no text is selected when control looses focus - StyledText st = (StyledText) e.widget; - st.setSelectionRange(st.getCaretOffset(), 0); - // update action enablement - selectionChangedListener.selectionChanged(new SelectionChangedEvent(viewer, StructuredSelection.EMPTY)); - } - } - - } - - private final Color colorIncoming; - - public IHandlerActivation contentAssistHandlerActivation; - - private final IHandlerService handlerService; - - private Menu menu; - - private IHandlerActivation quickAssistHandlerActivation; - - private ISelectionChangedListener selectionChangedListener; - - AttributeEditorToolkit(IHandlerService handlerService) { - this.handlerService = handlerService; - IThemeManager themeManager = PlatformUI.getWorkbench().getThemeManager(); - colorIncoming = themeManager.getCurrentTheme().getColorRegistry().get(CommonThemes.COLOR_INCOMING_BACKGROUND); - } - - private IHandlerActivation activateHandler(SourceViewer viewer, int operation, String actionDefinitionId) { - IHandler handler = createActionHandler(viewer, operation, actionDefinitionId); - return handlerService.activateHandler(actionDefinitionId, handler, // - new ActiveShellExpression(viewer.getTextWidget().getShell())); - } - - private void activateHandlers(SourceViewer viewer, boolean spellCheck) { - deactivateHandlers(); - if (spellCheck) { - quickAssistHandlerActivation = activateHandler(viewer, ISourceViewer.QUICK_ASSIST, - ITextEditorActionDefinitionIds.QUICK_ASSIST); - } - contentAssistHandlerActivation = activateHandler(viewer, ISourceViewer.CONTENTASSIST_PROPOSALS, - ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); - - } - - public void adapt(AbstractAttributeEditor editor) { - if (editor.getControl() instanceof Text && hasContentAssist(editor.getTaskAttribute())) { - Text text = (Text) editor.getControl(); - - IContentProposalProvider contentProposalProvider = createContentProposalProvider(editor.getTaskAttribute()); - ILabelProvider labelPropsalProvider = createLabelProposalProvider(editor.getTaskAttribute()); - - if (contentProposalProvider != null && labelPropsalProvider != null) { - ContentAssistCommandAdapter adapter = applyContentAssist(text, contentProposalProvider); - adapter.setLabelProvider(labelPropsalProvider); - adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE); - } - } else if (editor instanceof RichTextAttributeEditor) { - RichTextAttributeEditor richTextEditor = (RichTextAttributeEditor) editor; - boolean spellCheck = hasSpellChecking(editor.getTaskAttribute()); - final SourceViewer viewer = richTextEditor.getViewer(); - viewer.getControl().addFocusListener(new StyledTextFocusListener(viewer, spellCheck)); - if (selectionChangedListener != null) { - viewer.addSelectionChangedListener(selectionChangedListener); - viewer.addTextListener(new ITextListener() { - public void textChanged(TextEvent event) { - if (selectionChangedListener != null) { - selectionChangedListener.selectionChanged(new SelectionChangedEvent(viewer, - viewer.getSelection())); - } - } - }); - } - if (richTextEditor.getMode() == Mode.TASK_RELATION) { - applyContentAssist(viewer.getControl(), null); - } - if (menu != null) { - viewer.getControl().setMenu(menu); - } - EditorUtil.setTextViewer(editor.getControl(), viewer); - } - - // for outline - EditorUtil.setMarker(editor.getControl(), editor.getTaskAttribute().getId()); - - editor.decorate(getColorIncoming()); - } - - /** - * Adds content assist to the given text field. - * - * @param text - * text field to decorate. - * @param proposalProvider - * instance providing content proposals - * @return the ContentAssistCommandAdapter for the field. - */ - private ContentAssistCommandAdapter applyContentAssist(Control control, IContentProposalProvider proposalProvider) { - ControlDecoration controlDecoration = new ControlDecoration(control, (SWT.TOP | SWT.LEFT)); - controlDecoration.setMarginWidth(0); - controlDecoration.setShowHover(true); - controlDecoration.setShowOnlyOnFocus(true); - FieldDecoration contentProposalImage = FieldDecorationRegistry.getDefault().getFieldDecoration( - FieldDecorationRegistry.DEC_CONTENT_PROPOSAL); - controlDecoration.setImage(contentProposalImage.getImage()); - IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class); - controlDecoration.setDescriptionText(NLS.bind("Content Assist Available ({0})", - bindingService.getBestActiveBindingFormattedFor(ContentAssistCommandAdapter.CONTENT_PROPOSAL_COMMAND))); - - if (proposalProvider != null) { - TextContentAdapter textContentAdapter = new TextContentAdapter(); - ContentAssistCommandAdapter adapter = new ContentAssistCommandAdapter(control, textContentAdapter, - proposalProvider, ContentAssistCommandAdapter.CONTENT_PROPOSAL_COMMAND, new char[0]); - return adapter; - } - return null; - } - - private IHandler createActionHandler(final SourceViewer viewer, final int operation, String actionDefinitionId) { - Action quickFixAction = new Action() { - @Override - public void run() { - if (viewer.canDoOperation(operation)) { - viewer.doOperation(operation); - } - } - }; - quickFixAction.setActionDefinitionId(actionDefinitionId); - return new ActionHandler(quickFixAction); - } - - /** - * Creates an IContentProposalProvider to provide content assist proposals for the given attribute. - * - * @param attribute - * attribute for which to provide content assist. - * @return the IContentProposalProvider. - */ - private IContentProposalProvider createContentProposalProvider(TaskAttribute attribute) { - return new PersonProposalProvider(null, attribute.getTaskData()); - } - - private ILabelProvider createLabelProposalProvider(TaskAttribute attribute) { - return new PersonProposalLabelProvider(); - } - - private void deactivateHandlers() { - if (quickAssistHandlerActivation != null) { - handlerService.deactivateHandler(quickAssistHandlerActivation); - quickAssistHandlerActivation = null; - } - if (contentAssistHandlerActivation != null) { - handlerService.deactivateHandler(contentAssistHandlerActivation); - contentAssistHandlerActivation = null; - } - } - - void dispose() { - deactivateHandlers(); - } - - public Color getColorIncoming() { - return colorIncoming; - } - - Menu getMenu() { - return menu; - } - - /** - * Subclasses that support HTML preview of ticket description and comments override this method to return an - * instance of AbstractRenderingEngine - * - * @return <code>null</code> if HTML preview is not supported for the repository (default) - * @since 2.1 - */ - public AbstractRenderingEngine getRenderingEngine(TaskAttribute attribute) { - return null; - } - - ISelectionChangedListener getSelectionChangedListener() { - return selectionChangedListener; - } - - /** - * Called to check if there's content assist available for the given attribute. - * - * @param attribute - * the attribute - * @return true if content assist is available for the specified attribute. - */ - private boolean hasContentAssist(TaskAttribute taskAttribute) { - String type = taskAttribute.getMetaData().getType(); - if (TaskAttribute.TYPE_PERSON.equals(type)) { - return true; - } else if (TaskAttribute.TYPE_TASK_DEPENDENCY.equals(type)) { - return true; - } - return false; - } - - boolean hasSpellChecking(TaskAttribute taskAttribute) { - String type = taskAttribute.getMetaData().getType(); - if (TaskAttribute.TYPE_LONG_RICH_TEXT.equals(type) || TaskAttribute.TYPE_SHORT_RICH_TEXT.equals(type)) { - return true; - } - return false; - } - - void setMenu(Menu menu) { - this.menu = menu; - } - - void setSelectionChangedListener(ISelectionChangedListener selectionListener) { - this.selectionChangedListener = selectionListener; - } - -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/BrowserFormPage.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/BrowserFormPage.java deleted file mode 100644 index 84bce7b2b..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/BrowserFormPage.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Mylyn project committers 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.ui.editors; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.mylyn.commons.core.StatusHandler; -import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; -import org.eclipse.swt.SWT; -import org.eclipse.swt.SWTError; -import org.eclipse.swt.browser.Browser; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.forms.IManagedForm; -import org.eclipse.ui.forms.editor.FormEditor; -import org.eclipse.ui.forms.editor.FormPage; -import org.eclipse.ui.forms.widgets.ScrolledForm; - -/** - * A form page that contains a browser control. - * - * @since 3.0 - * @author Mik Kersten - * @author Steffen Pingel - */ -public class BrowserFormPage extends FormPage { - - public static final String ID_EDITOR = "org.eclipse.mylyn.tasks.ui.editor.browser"; - - private Browser browser; - - public BrowserFormPage(FormEditor editor, String title) { - super(editor, ID_EDITOR, title); - } - - @Override - protected void createFormContent(IManagedForm managedForm) { - super.createFormContent(managedForm); - try { - ScrolledForm form = managedForm.getForm(); - form.getBody().setLayout(new FillLayout()); - browser = new Browser(form.getBody(), SWT.NONE); - managedForm.getForm().setContent(browser); - String url = getUrl(); - if (url != null) { - browser.setUrl(url); - } - } catch (SWTError e) { - // TODO review error handling - StatusHandler.fail(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Could not create browser page: " - + e.getMessage(), e)); - } catch (RuntimeException e) { - // TODO review error handling - StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Could not create browser page", e)); - } - } - - /** - * Returns a reference to the browser control. - */ - public Browser getBrowser() { - return browser; - } - - /** - * Returns the initial URL that is displayed in the browser control. The default implementation tries to determine - * the URL from the editor input. - * <p> - * Subclasses should override this method to display a specific URL. - * - * @return the URL to load when the page is created; null, if no URL should be loaded - */ - protected String getUrl() { - IEditorInput input = getEditorInput(); - if (input instanceof TaskEditorInput) { - return ((TaskEditorInput) input).getTask().getUrl(); - } - return null; - } - -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/LayoutHint.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/LayoutHint.java deleted file mode 100644 index cf149505a..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/LayoutHint.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Mylyn project committers 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.ui.editors; - -/** - * @author Steffen Pingel - * @since 3.0 - */ -public class LayoutHint { - - public final static int DEFAULT_PRIORITY = 10; - - public enum ColumnSpan { - MULTIPLE, SINGLE - }; - - public enum RowSpan { - MULTIPLE, SINGLE - }; - - public RowSpan rowSpan; - - public ColumnSpan columnSpan; - - public LayoutHint(RowSpan rowHint, ColumnSpan columnHint) { - this.rowSpan = rowHint; - this.columnSpan = columnHint; - } - - public int getPriority() { - if (columnSpan == null || columnSpan == ColumnSpan.SINGLE) { - if (rowSpan == null || rowSpan == RowSpan.SINGLE) { - return DEFAULT_PRIORITY; - } else { - return DEFAULT_PRIORITY * 2; - } - } else { - if (rowSpan == null || rowSpan == RowSpan.SINGLE) { - return DEFAULT_PRIORITY * 3; - } else { - return DEFAULT_PRIORITY * 4; - } - } - } - -} 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 deleted file mode 100644 index 7bfc4d2da..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/TaskEditor.java +++ /dev/null @@ -1,648 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Mylyn project committers 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.ui.editors; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.action.IMenuListener; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.dialogs.IMessageProvider; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionProvider; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.mylyn.commons.core.StatusHandler; -import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages; -import org.eclipse.mylyn.internal.tasks.core.LocalRepositoryConnector; -import org.eclipse.mylyn.internal.tasks.core.LocalTask; -import org.eclipse.mylyn.internal.tasks.core.deprecated.RepositoryTaskData; -import org.eclipse.mylyn.internal.tasks.ui.TaskTransfer; -import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; -import org.eclipse.mylyn.internal.tasks.ui.actions.ToggleTaskActivationAction; -import org.eclipse.mylyn.internal.tasks.ui.deprecated.AbstractRepositoryTaskEditor; -import org.eclipse.mylyn.internal.tasks.ui.deprecated.AbstractRepositoryTaskEditorInput; -import org.eclipse.mylyn.internal.tasks.ui.deprecated.AbstractTaskEditorFactory; -import org.eclipse.mylyn.internal.tasks.ui.deprecated.NewTaskEditorInput; -import org.eclipse.mylyn.internal.tasks.ui.deprecated.RepositoryTaskEditorInput; -import org.eclipse.mylyn.internal.tasks.ui.editors.EditorBusyIndicator; -import org.eclipse.mylyn.internal.tasks.ui.editors.EditorUtil; -import org.eclipse.mylyn.internal.tasks.ui.editors.IBusyEditor; -import org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorActionContributor; -import org.eclipse.mylyn.internal.tasks.ui.util.SelectionProviderAdapter; -import org.eclipse.mylyn.internal.tasks.ui.util.TaskDragSourceListener; -import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal; -import org.eclipse.mylyn.tasks.core.ITask; -import org.eclipse.mylyn.tasks.ui.AbstractRepositoryConnectorUi; -import org.eclipse.mylyn.tasks.ui.TasksUiImages; -import org.eclipse.swt.dnd.DND; -import org.eclipse.swt.dnd.FileTransfer; -import org.eclipse.swt.dnd.TextTransfer; -import org.eclipse.swt.dnd.Transfer; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IEditorSite; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.forms.IManagedForm; -import org.eclipse.ui.forms.editor.FormPage; -import org.eclipse.ui.forms.editor.IFormPage; -import org.eclipse.ui.forms.editor.SharedHeaderFormEditor; -import org.eclipse.ui.forms.events.HyperlinkAdapter; -import org.eclipse.ui.forms.events.HyperlinkEvent; -import org.eclipse.ui.forms.events.IHyperlinkListener; -import org.eclipse.ui.forms.widgets.Form; -import org.eclipse.ui.part.WorkbenchPart; -import org.eclipse.ui.progress.IWorkbenchSiteProgressService; -import org.eclipse.ui.views.contentoutline.IContentOutlinePage; - -/** - * @author Mik Kersten - * @author Eric Booth (initial prototype) - * @author Rob Elves - */ -@SuppressWarnings( { "deprecation", "restriction" }) -public class TaskEditor extends SharedHeaderFormEditor { - - public static final String ID_EDITOR = "org.eclipse.mylyn.tasks.ui.editors.task"; - - private ToggleTaskActivationAction activateAction; - - @Deprecated - private IEditorPart contentOutlineProvider = null; - - private EditorBusyIndicator editorBusyIndicator; - - private MenuManager menuManager; - - private IHyperlinkListener messageHyperLinkListener; - - private ITask task; - - private TaskEditorInput taskEditorInput; - - private TaskDragSourceListener titleDragSourceListener; - - public TaskEditor() { - } - - @Deprecated - private void addPage(AbstractTaskEditorFactory factory) { - IEditorInput editorInput; - if (taskEditorInput != null && taskEditorInput.getTask() == null) { - editorInput = new RepositoryTaskEditorInput(taskEditorInput.getTaskRepository(), taskEditorInput.getTask() - .getTaskId(), ""); - } else { - editorInput = getEditorInput(); - } - if (factory.canCreateEditorFor(task) || factory.canCreateEditorFor(editorInput)) { - try { - IEditorPart editor = factory.createEditor(this, editorInput); - IEditorInput input = task != null ? factory.createEditorInput(task) : editorInput; - if (editor != null && input != null) { - FormPage taskEditor = (FormPage) editor; - editor.init(getEditorSite(), input); - int index = addPage(taskEditor); - if (input.getImageDescriptor() != null) { - setPageImage(index, CommonImages.getImage(input.getImageDescriptor())); - } - if (editor instanceof AbstractRepositoryTaskEditor) { - ((AbstractRepositoryTaskEditor) editor).setParentEditor(this); - - if (editorInput instanceof RepositoryTaskEditorInput) { - RepositoryTaskEditorInput existingInput = (RepositoryTaskEditorInput) editorInput; - setPartName(existingInput.getName()); - } else if (editorInput instanceof NewTaskEditorInput) { - String label = ((NewTaskEditorInput) editorInput).getName(); - setPartName(label); - } - setPageText(index, factory.getTitle()); - - // TODO review - setActivePage(index); - } - } - - // HACK: overwrites if multiple present - if (factory.providesOutline()) { - contentOutlineProvider = editor; - } - } catch (Exception e) { - StatusHandler.fail(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, - "Could not create editor via factory: " + factory, e)); - } - } - - } - - @Override - protected void addPages() { - initialize(); - - // API REVIEW remove check - if (taskEditorInput != null) { - // determine factories - Set<String> conflictingIds = new HashSet<String>(); - ArrayList<AbstractTaskEditorPageFactory> pageFactories = new ArrayList<AbstractTaskEditorPageFactory>(); - for (AbstractTaskEditorPageFactory pageFactory : TasksUiPlugin.getDefault().getTaskEditorPageFactories()) { - if (pageFactory.canCreatePageFor(getTaskEditorInput())) { - pageFactories.add(pageFactory); - String[] ids = pageFactory.getConflictingIds(getTaskEditorInput()); - if (ids != null) { - conflictingIds.addAll(Arrays.asList(ids)); - } - } - } - for (Iterator<AbstractTaskEditorPageFactory> it = pageFactories.iterator(); it.hasNext();) { - if (conflictingIds.contains(it.next().getId())) { - it.remove(); - } - } - - // sort by priority - Collections.sort(pageFactories, new Comparator<AbstractTaskEditorPageFactory>() { - public int compare(AbstractTaskEditorPageFactory o1, AbstractTaskEditorPageFactory o2) { - return o1.getPriority() - o2.getPriority(); - } - }); - - // create pages - for (AbstractTaskEditorPageFactory factory : pageFactories) { - try { - FormPage page = factory.createPage(this); - int index = addPage(page); - setPageImage(index, factory.getPageImage()); - setPageText(index, factory.getPageText()); - if (factory.getPriority() == AbstractTaskEditorPageFactory.PRIORITY_TASK) { - setActivePage(index); - } - if (page instanceof ISelectionProvider) { - ((ISelectionProvider) page).addSelectionChangedListener(getActionBarContributor()); - } - } catch (Exception e) { - StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, - "Could not create editor via factory: " + factory, e)); - } - } - } - - // API REVIEW remove code - List<AbstractTaskEditorFactory> factories = new ArrayList<AbstractTaskEditorFactory>(TasksUiPlugin.getDefault() - .getTaskEditorFactories()); - Collections.sort(factories, new Comparator<AbstractTaskEditorFactory>() { - public int compare(AbstractTaskEditorFactory o1, AbstractTaskEditorFactory o2) { - return o1.getTabOrderPriority() - o2.getTabOrderPriority(); - } - }); - for (AbstractTaskEditorFactory factory : factories) { - addPage(factory); - } - - updateTitleImage(); - updateHeaderToolBar(); - } - - private void initialize() { - editorBusyIndicator = new EditorBusyIndicator(new IBusyEditor() { - public Image getTitleImage() { - return TaskEditor.this.getTitleImage(); - } - - public void setTitleImage(Image image) { - TaskEditor.this.setTitleImage(image); - } - }); - - menuManager = new MenuManager(); - configureContextMenuManager(menuManager); - Menu menu = menuManager.createContextMenu(getContainer()); - getContainer().setMenu(menu); - getEditorSite().registerContextMenu(menuManager, getEditorSite().getSelectionProvider(), false); - } - - /** - * @since 3.0 - */ - @Deprecated - public void configureContextMenuManager(MenuManager manager) { - if (manager == null) { - return; - } - IMenuListener listener = new IMenuListener() { - public void menuAboutToShow(IMenuManager manager) { - contextMenuAboutToShow(manager); - } - }; - manager.setRemoveAllWhenShown(true); - manager.addMenuListener(listener); - } - - @Deprecated - protected void contextMenuAboutToShow(IMenuManager manager) { - TaskEditorActionContributor contributor = getActionBarContributor(); - if (contributor != null) { - contributor.contextMenuAboutToShow(manager); - } - } - - @Override - protected void createHeaderContents(IManagedForm headerForm) { - getToolkit().decorateFormHeading(headerForm.getForm().getForm()); - updateHeader(); - installTitleDrag(getHeaderForm().getForm().getForm()); - } - - @Override - public void dispose() { - if (editorBusyIndicator != null) { - editorBusyIndicator.stop(); - } - if (activateAction != null) { - activateAction.dispose(); - } - super.dispose(); - } - - @Override - public void doSave(IProgressMonitor monitor) { - for (IFormPage page : getPages()) { - if (page.isDirty()) { - page.doSave(monitor); - } - } - - editorDirtyStateChanged(); - } - - @Override - public void doSaveAs() { - throw new UnsupportedOperationException(); - } - - private TaskEditorActionContributor getActionBarContributor() { - return (TaskEditorActionContributor) getEditorSite().getActionBarContributor(); - } - - @SuppressWarnings("unchecked") - @Override - public Object getAdapter(Class adapter) { - if (contentOutlineProvider != null) { - return contentOutlineProvider.getAdapter(adapter); - } else if (IContentOutlinePage.class.equals(adapter)) { - IFormPage[] pages = getPages(); - for (IFormPage page : pages) { - Object outlinePage = page.getAdapter(adapter); - if (outlinePage != null) { - return outlinePage; - } - } - } - return super.getAdapter(adapter); - } - - /** - * @since 3.0 - */ - public Menu getMenu() { - return getContainer().getMenu(); - } - - @SuppressWarnings("unchecked") - IFormPage[] getPages() { - ArrayList formPages = new ArrayList(); - if (pages != null) { - for (int i = 0; i < pages.size(); i++) { - Object page = pages.get(i); - if (page instanceof IFormPage) { - formPages.add(page); - } - } - } - return (IFormPage[]) formPages.toArray(new IFormPage[formPages.size()]); - } - - @Deprecated - protected IWorkbenchSiteProgressService getProgressService() { - Object siteService = getEditorSite().getAdapter(IWorkbenchSiteProgressService.class); - if (siteService != null) { - return (IWorkbenchSiteProgressService) siteService; - } - return null; - } - - @Deprecated - public ISelection getSelection() { - if (getSite() != null && getSite().getSelectionProvider() != null) { - return getSite().getSelectionProvider().getSelection(); - } else { - return StructuredSelection.EMPTY; - } - } - - public TaskEditorInput getTaskEditorInput() { - return taskEditorInput; - } - - @Deprecated - public Form getTopForm() { - return this.getHeaderForm().getForm().getForm(); - } - - @Override - public void init(IEditorSite site, IEditorInput input) throws PartInitException { - // API REVIEW remove the commented parts - // if (!(input instanceof TaskEditorInput)) { -// throw new PartInitException("Invalid editor input \"" + input.getClass() + "\""); -// } - - super.init(site, input); - - // API REVIEW remove the instanceof check - if (input instanceof TaskEditorInput) { - this.taskEditorInput = (TaskEditorInput) input; - this.task = taskEditorInput.getTask(); - } - - setPartName(input.getName()); - } - - private void installTitleDrag(Form form) { - // API 3.0 remove - if (task == null) { - return; - } - - if (titleDragSourceListener == null) { - Transfer[] transferTypes; - if (null == task) { - transferTypes = new Transfer[] { TextTransfer.getInstance() }; - } else { - transferTypes = new Transfer[] { TaskTransfer.getInstance(), TextTransfer.getInstance(), - FileTransfer.getInstance() }; - } - titleDragSourceListener = new TaskDragSourceListener(new SelectionProviderAdapter() { - @Override - public ISelection getSelection() { - return new StructuredSelection(task); - } - }); - form.addTitleDragSupport(DND.DROP_MOVE | DND.DROP_LINK, transferTypes, titleDragSourceListener); - } - } - - @Override - public boolean isDirty() { - for (IFormPage page : getPages()) { - if (page.isDirty()) { - return true; - } - } - return false; - } - - @Override - public boolean isSaveAsAllowed() { - return false; - } - - @Deprecated - public void markDirty() { - firePropertyChange(PROP_DIRTY); - } - - /** - * Refresh editor with new contents (if any) - */ - @Deprecated - public void refreshEditorContents() { - for (IFormPage page : getPages()) { - if (page instanceof AbstractRepositoryTaskEditor) { - AbstractRepositoryTaskEditor editor = (AbstractRepositoryTaskEditor) page; - editor.refreshEditor(); - } - } - } - - @Override - public void setFocus() { - IFormPage page = getActivePageInstance(); - if (page != null) { - page.setFocus(); - } else { - super.setFocus(); - } - } - - @Deprecated - public void setFocusOfActivePage() { - if (this.getActivePage() > -1) { - IFormPage page = this.getPages()[this.getActivePage()]; - if (page != null) { - page.setFocus(); - } - } - } - - public void setMessage(String message, int type) { - setMessage(message, type, null); - } - - /** - * @since 2.3 - */ - public void setMessage(String message, int type, IHyperlinkListener listener) { - if (getHeaderForm() != null && getHeaderForm().getForm() != null) { - if (!getHeaderForm().getForm().isDisposed()) { - Form form = getHeaderForm().getForm().getForm(); - form.setMessage(message, type); - if (messageHyperLinkListener != null) { - form.removeMessageHyperlinkListener(messageHyperLinkListener); - } - if (listener != null) { - form.addMessageHyperlinkListener(listener); - } - messageHyperLinkListener = listener; - } - } - } - - /** - * @since 3.0 - */ - public void setStatus(String message, final String title, final IStatus status) { - setMessage(message, IMessageProvider.ERROR, new HyperlinkAdapter() { - @Override - public void linkActivated(HyperlinkEvent event) { - TasksUiInternal.displayStatus(title, status); - } - }); - } - - @Override - public void showBusy(boolean busy) { - if (busy) { - if (TasksUiInternal.isAnimationsEnabled()) { - editorBusyIndicator.start(); - } - } else { - editorBusyIndicator.stop(); - } - Form form = getHeaderForm().getForm().getForm(); - EditorUtil.setEnabledState(form.getBody(), !busy); - for (IFormPage page : getPages()) { - if (page instanceof WorkbenchPart) { - WorkbenchPart part = (WorkbenchPart) page; - part.showBusy(busy); - } - } - } - - private void updateHeader() { - IEditorInput input = getEditorInput(); - if (input instanceof TaskEditorInput) { - updateHeaderImage(task.getConnectorKind()); - updateHeaderLabel(task); - } else if (input instanceof RepositoryTaskEditorInput) { - RepositoryTaskData taskData = ((RepositoryTaskEditorInput) input).getTaskData(); - if (task != null) { - updateHeaderImage(task.getConnectorKind()); - updateHeaderLabel(task); - } else if (taskData != null) { - updateHeaderImage(taskData.getConnectorKind()); - updateHeaderLabel(taskData); - } - } - installTitleDrag(getHeaderForm().getForm().getForm()); - } - - /** - * @since 3.0 - */ - public void updateHeaderToolBar() { - Form form = getHeaderForm().getForm().getForm(); - IToolBarManager toolBarManager = form.getToolBarManager(); - - toolBarManager.removeAll(); - toolBarManager.update(true); - - for (IFormPage page : getPages()) { - if (page instanceof AbstractTaskEditorPage) { - AbstractTaskEditorPage taskEditorPage = (AbstractTaskEditorPage) page; - taskEditorPage.fillToolBar(toolBarManager); - } else if (page instanceof AbstractRepositoryTaskEditor) { - AbstractRepositoryTaskEditor taskEditorPage = (AbstractRepositoryTaskEditor) page; - taskEditorPage.fillToolBar(toolBarManager); - } - } - - // TODO EDITOR remove check - if (task != null) { - if (activateAction == null) { - activateAction = new ToggleTaskActivationAction(task, toolBarManager); - } - toolBarManager.add(new Separator("activation")); - toolBarManager.add(activateAction); - } - - toolBarManager.update(true); - } - - private void updateHeaderImage(String connectorKind) { - if (LocalRepositoryConnector.CONNECTOR_KIND.equals(connectorKind)) { - getHeaderForm().getForm().setImage(CommonImages.getImage(TasksUiImages.TASK)); - } else { - ImageDescriptor overlay = TasksUiPlugin.getDefault().getOverlayIcon(connectorKind); - Image image = CommonImages.getImageWithOverlay(TasksUiImages.REPOSITORY, overlay, false, false); - getHeaderForm().getForm().setImage(image); - } - } - - private void updateHeaderLabel(ITask task) { - if (task instanceof LocalTask) { - getHeaderForm().getForm().setText("Task: " + task.getSummary()); - } else { - AbstractRepositoryConnectorUi connectorUi = TasksUiPlugin.getConnectorUi(task.getConnectorKind()); - String kindLabel = ""; - if (connectorUi != null) { - kindLabel = connectorUi.getTaskKindLabel(task); - } - - String idLabel = task.getTaskKey(); - if (idLabel != null) { - getHeaderForm().getForm().setText(kindLabel + " " + idLabel); - } else { - getHeaderForm().getForm().setText(kindLabel); - } - } - } - - @Deprecated - private void updateHeaderLabel(RepositoryTaskData taskData) { - String kindLabel = taskData.getTaskKind(); - String idLabel = taskData.getTaskKey(); - - AbstractRepositoryConnectorUi connectorUi = TasksUiPlugin.getConnectorUi(taskData.getConnectorKind()); - if (connectorUi != null && task != null) { - kindLabel = connectorUi.getTaskKindLabel(task); - } - if (taskData.isNew()) { - kindLabel = "New " + kindLabel; - idLabel = ""; - } - - if (getHeaderForm().getForm() != null) { - if (idLabel != null) { - getHeaderForm().getForm().setText(kindLabel + " " + idLabel); - } else { - getHeaderForm().getForm().setText(kindLabel); - } - } - } - - /** - * Update the title of the editor - */ - @Deprecated - public void updateTitle(String name) { - // setContentDescription(name); - setPartName(name); - setTitleToolTip(name); - updateHeader(); - } - - private void updateTitleImage() { - if (task != null) { - AbstractRepositoryConnectorUi connectorUi = TasksUiPlugin.getConnectorUi(task.getConnectorKind()); - if (connectorUi != null) { - ImageDescriptor overlayDescriptor = connectorUi.getTaskKindOverlay(task); - setTitleImage(CommonImages.getCompositeTaskImage(TasksUiImages.TASK, overlayDescriptor, false)); - } else { - setTitleImage(CommonImages.getImage(TasksUiImages.TASK)); - } - } else if (getEditorInput() instanceof AbstractRepositoryTaskEditorInput) { - setTitleImage(CommonImages.getImage(TasksUiImages.TASK_REMOTE)); - } else { - setTitleImage(CommonImages.getImage(TasksUiImages.TASK)); - } - } - -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/TaskEditorInput.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/TaskEditorInput.java deleted file mode 100644 index ed94a4636..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/TaskEditorInput.java +++ /dev/null @@ -1,212 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Mylyn project committers 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 - *******************************************************************************/ -/* - * Created on 19-Jan-2005 - */ -package org.eclipse.mylyn.tasks.ui.editors; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorInputFactory; -import org.eclipse.mylyn.tasks.core.ITask; -import org.eclipse.mylyn.tasks.core.TaskRepository; -import org.eclipse.mylyn.tasks.ui.TasksUi; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IMemento; -import org.eclipse.ui.IPersistableElement; - -/** - * Input for task editors. - * - * @author Eric Booth - * @author Rob Elves - * @author Mik Kersten - * @author Steffen Pingel - * @since 2.0 - */ -public class TaskEditorInput implements IEditorInput, IPersistableElement { - - private static final int MAX_LABEL_LENGTH = 60; - - private final ITask task; - - private final TaskRepository taskRepository; - - private Object data; - - /** - * @since 3.0 - */ - @Deprecated - public TaskEditorInput(ITask task, boolean newTask) { - this(TasksUi.getRepositoryManager().getRepository(task.getConnectorKind(), task.getRepositoryUrl()), task); - } - - /** - * @since 3.0 - */ - public TaskEditorInput(TaskRepository taskRepository, ITask task) { - Assert.isNotNull(taskRepository); - Assert.isNotNull(task); - this.taskRepository = taskRepository; - this.task = task; - } - - /** - * @since 2.0 - */ - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - TaskEditorInput other = (TaskEditorInput) obj; - return task.equals(other.task); - } - - /** - * @since 2.0 - */ - public boolean exists() { - return task != null; - } - - /** - * @since 2.0 - */ - @SuppressWarnings("unchecked") - public Object getAdapter(Class adapter) { - if (adapter == IEditorInput.class) { - return this; - } - return null; - } - - /** - * @since 2.0 - */ - public String getFactoryId() { - return TaskEditorInputFactory.ID_FACTORY; - } - - /** - * @since 2.0 - */ - public ImageDescriptor getImageDescriptor() { - return null; - } - - /** - * @deprecated use {@link #getName()} - * @since 2.0 - */ - @Deprecated - public String getLabel() { - return getName(); - } - - /** - * @since 2.0 - */ - public String getName() { - String toolTipText = getToolTipText(); - if (toolTipText == null) { - return null; - } - - if (task != null) { - String taskKey = task.getTaskKey(); - if (taskKey != null) { - return truncate(taskKey + ": " + toolTipText); - } - } - return truncate(toolTipText); - } - - /** - * @since 2.0 - */ - public IPersistableElement getPersistable() { - return this; - } - - /** - * Returns the task if the task is in the task list; returns <code>null</code> otherwise. - * - * @since 3.0 - */ - public ITask getTask() { - return task; - } - - /** - * @since 3.0 - */ - public TaskRepository getTaskRepository() { - return taskRepository; - } - - /** - * @since 2.0 - */ - public String getToolTipText() { - return task.getSummary(); - } - - /** - * @since 2.0 - */ - @Override - public int hashCode() { - return task.getTaskId().hashCode(); - } - - /** - * @since 2.0 - */ - @Deprecated - public boolean isNewTask() { - return false; - } - - /** - * @since 2.0 - */ - public void saveState(IMemento memento) { - TaskEditorInputFactory.saveState(memento, this); - } - - private String truncate(String description) { - if (description == null || description.length() <= MAX_LABEL_LENGTH) { - return description; - } else { - return description.substring(0, MAX_LABEL_LENGTH) + "..."; - } - } - - /** - * @since 3.0 - */ - public Object getData() { - return data; - } - - /** - * @since 3.0 - */ - public void setData(Object data) { - this.data = data; - } - -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/TaskEditorPartDescriptor.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/TaskEditorPartDescriptor.java deleted file mode 100644 index d692f8e52..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/editors/TaskEditorPartDescriptor.java +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Mylyn project committers 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.ui.editors; - -import org.eclipse.core.runtime.Assert; - -/** - * @author Steffen Pingel - * @since 3.0 - */ -public abstract class TaskEditorPartDescriptor { - - private final String id; - - private String path; - -// public AbstractTaskEditorPart createPart() { -// final AbstractTaskEditorPart[] result = new AbstractTaskEditorPart[1]; -// SafeRunnable.run(new ISafeRunnable() { -// -// public void handleException(Throwable exception) { -// StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, -// "Unable to create instance of class \"" + getClassName() + "\" for task editor part \"" -// + getId() + "\"")); -// } -// -// public void run() throws Exception { -// Class<?> clazz = Class.forName(getClassName()); -// result[0] = (AbstractTaskEditorPart) clazz.newInstance(); -// } -// -// }); -// return result[0]; -// } - - public TaskEditorPartDescriptor(String id) { - Assert.isNotNull(id); - this.id = id; - } - - public abstract AbstractTaskEditorPart createPart(); - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - TaskEditorPartDescriptor other = (TaskEditorPartDescriptor) obj; - if (id == null) { - if (other.id != null) { - return false; - } - } else if (!id.equals(other.id)) { - return false; - } - return true; - } - - public String getId() { - return id; - } - - public String getPath() { - return path; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((id == null) ? 0 : id.hashCode()); - return result; - } - - public TaskEditorPartDescriptor setPath(String path) { - this.path = path; - return this; - } - -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/AbstractRepositoryQueryPage.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/AbstractRepositoryQueryPage.java deleted file mode 100644 index e2032b256..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/AbstractRepositoryQueryPage.java +++ /dev/null @@ -1,170 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Mylyn project committers 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.ui.wizards; - -import java.util.Set; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.mylyn.internal.tasks.core.AbstractTaskCategory; -import org.eclipse.mylyn.internal.tasks.core.RepositoryQuery; -import org.eclipse.mylyn.internal.tasks.ui.deprecated.AbstractRepositoryQueryWizard; -import org.eclipse.mylyn.internal.tasks.ui.search.SearchHitCollector; -import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal; -import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector; -import org.eclipse.mylyn.tasks.core.IRepositoryQuery; -import org.eclipse.mylyn.tasks.core.TaskRepository; -import org.eclipse.mylyn.tasks.ui.TasksUi; -import org.eclipse.mylyn.tasks.ui.TasksUiImages; -import org.eclipse.search.ui.NewSearchUI; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; - -/** - * Extend to provide repository-specific query page to the Workbench search dialog. - * - * @author Rob Elves - * @author Steffen Pingel - * @since 3.0 - */ -public abstract class AbstractRepositoryQueryPage extends WizardPage implements ITaskSearchPage { - - private static final String TITLE = "Enter query parameters"; - - private static final String DESCRIPTION = "If attributes are blank or stale press the Update button."; - - private ITaskSearchPageContainer searchContainer; - - private final TaskRepository taskRepository; - - private final IRepositoryQuery query; - - public AbstractRepositoryQueryPage(String title, TaskRepository taskRepository, IRepositoryQuery query) { - super(title); - Assert.isNotNull(taskRepository); - this.taskRepository = taskRepository; - this.query = query; - setTitle(TITLE); - setDescription(DESCRIPTION); - setImageDescriptor(TasksUiImages.BANNER_REPOSITORY); - setPageComplete(false); - } - - public AbstractRepositoryQueryPage(String title, TaskRepository taskRepository) { - this(title, taskRepository, null); - } - - public IRepositoryQuery getQuery() { - return query; - } - - public abstract String getQueryTitle(); - - @Override - public boolean isPageComplete() { - String queryTitle = getQueryTitle(); - if (queryTitle == null || queryTitle.equals("")) { - setErrorMessage("Please specify a title for the query."); - return false; - } else { - Set<RepositoryQuery> queries = TasksUiInternal.getTaskList().getQueries(); - Set<AbstractTaskCategory> categories = TasksUiInternal.getTaskList().getCategories(); - String oldSummary = null; - if (query != null) { - oldSummary = query.getSummary(); - } else if (getWizard() instanceof AbstractRepositoryQueryWizard) { - oldSummary = ((AbstractRepositoryQueryWizard) getWizard()).getQuerySummary(); - } - if (oldSummary != null && queryTitle.equals(oldSummary)) { - setErrorMessage(null); - return true; - } - - for (AbstractTaskCategory category : categories) { - if (queryTitle.equals(category.getSummary())) { - setErrorMessage("A category with this name already exists, please choose another name."); - return false; - } - } - for (RepositoryQuery repositoryQuery : queries) { - if (queryTitle.equals(repositoryQuery.getSummary()) && !query.equals(repositoryQuery)) { - setErrorMessage("A query with this name already exists, please choose another name."); - return false; - } - } - } - setErrorMessage(null); - return true; - } - - public IRepositoryQuery createQuery() { - IRepositoryQuery query = TasksUi.getRepositoryModel().createQuery(getTaskRepository()); - applyTo(query); - return query; - } - - public abstract void applyTo(IRepositoryQuery query); - - public void saveState() { - // empty - } - - public void setContainer(ITaskSearchPageContainer container) { - searchContainer = container; - } - - public boolean inSearchContainer() { - return searchContainer != null; - } - - public boolean performSearch() { - NewSearchUI.activateSearchResultView(); - AbstractRepositoryConnector connector = TasksUi.getRepositoryManager().getRepositoryConnector( - taskRepository.getConnectorKind()); - if (connector != null) { - try { - SearchHitCollector collector = new SearchHitCollector(TasksUiInternal.getTaskList(), taskRepository, - createQuery()); - NewSearchUI.runQueryInBackground(collector); - } catch (UnsupportedOperationException e) { - SearchHitCollector collector = new SearchHitCollector(TasksUiInternal.getTaskList(), taskRepository, - getQuery()); - NewSearchUI.runQueryInBackground(collector); - } - } - return true; - } - - /** - * @since 2.1 - */ - public void setControlsEnabled(boolean enabled) { - setControlsEnabled(getControl(), enabled); - } - - // TODO: make reusable or find better API, task editor has similar functionality - private void setControlsEnabled(Control control, boolean enabled) { - if (control instanceof Composite) { - for (Control childControl : ((Composite) control).getChildren()) { - childControl.setEnabled(enabled); - setControlsEnabled(childControl, enabled); - } - } - setPageComplete(isPageComplete()); - } - - public ITaskSearchPageContainer getSearchContainer() { - return searchContainer; - } - - public TaskRepository getTaskRepository() { - return taskRepository; - } - -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/AbstractRepositorySettingsPage.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/AbstractRepositorySettingsPage.java deleted file mode 100644 index c78a9697c..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/AbstractRepositorySettingsPage.java +++ /dev/null @@ -1,1489 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Mylyn project committers 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.ui.wizards; - -import java.lang.reflect.InvocationTargetException; -import java.nio.charset.Charset; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.dialogs.IMessageProvider; -import org.eclipse.jface.layout.GridDataFactory; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.preference.PreferenceDialog; -import org.eclipse.jface.preference.StringFieldEditor; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.mylyn.commons.core.StatusHandler; -import org.eclipse.mylyn.commons.net.AuthenticationCredentials; -import org.eclipse.mylyn.commons.net.AuthenticationType; -import org.eclipse.mylyn.internal.tasks.core.IRepositoryConstants; -import org.eclipse.mylyn.internal.tasks.core.RepositoryTemplateManager; -import org.eclipse.mylyn.internal.tasks.core.TaskRepositoryManager; -import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; -import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector; -import org.eclipse.mylyn.tasks.core.RepositoryTemplate; -import org.eclipse.mylyn.tasks.core.TaskRepository; -import org.eclipse.mylyn.tasks.ui.TasksUi; -import org.eclipse.mylyn.tasks.ui.TasksUiUtil; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.FocusAdapter; -import org.eclipse.swt.events.FocusEvent; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.dialogs.PreferencesUtil; -import org.eclipse.ui.forms.events.ExpansionAdapter; -import org.eclipse.ui.forms.events.ExpansionEvent; -import org.eclipse.ui.forms.events.HyperlinkAdapter; -import org.eclipse.ui.forms.events.HyperlinkEvent; -import org.eclipse.ui.forms.events.IHyperlinkListener; -import org.eclipse.ui.forms.widgets.ExpandableComposite; -import org.eclipse.ui.forms.widgets.FormToolkit; -import org.eclipse.ui.forms.widgets.Hyperlink; - -/** - * Extend to provide custom repository settings. This page is typically invoked by the user requesting properties via - * the Task Repositories view. - * - * @author Mik Kersten - * @author Rob Elves - * @author Steffen Pingel - * @author Frank Becker - */ -public abstract class AbstractRepositorySettingsPage extends WizardPage implements ITaskRepositoryPage { - - protected static final String PREFS_PAGE_ID_NET_PROXY = "org.eclipse.ui.net.NetPreferences"; - - protected static final String LABEL_REPOSITORY_LABEL = "Label: "; - - protected static final String LABEL_SERVER = "Server: "; - - protected static final String LABEL_USER = "User ID: "; - - protected static final String LABEL_PASSWORD = "Password: "; - - protected static final String URL_PREFIX_HTTPS = "https://"; - - protected static final String URL_PREFIX_HTTP = "http://"; - - protected static final String INVALID_REPOSITORY_URL = "Repository url is invalid."; - - protected static final String INVALID_LOGIN = "Unable to authenticate with repository. Login credentials invalid."; - - protected AbstractRepositoryConnector connector; - - protected StringFieldEditor repositoryLabelEditor; - - protected Combo serverUrlCombo; - - private String serverVersion = TaskRepository.NO_VERSION_SPECIFIED; - - protected StringFieldEditor repositoryUserNameEditor; - - protected StringFieldEditor repositoryPasswordEditor; - - protected StringFieldEditor httpAuthUserNameEditor; - - protected StringFieldEditor httpAuthPasswordEditor; - - protected StringFieldEditor proxyHostnameEditor; - - protected StringFieldEditor proxyPortEditor; - - protected StringFieldEditor proxyUserNameEditor; - - protected StringFieldEditor proxyPasswordEditor; - - protected TaskRepository repository; - - private Button validateServerButton; - - private Combo otherEncodingCombo; - - private Button defaultEncoding; - - // private Combo timeZonesCombo; - - protected Button anonymousButton; - - private String oldUsername; - - private String oldPassword; - - private String oldHttpAuthUserId; - - private String oldHttpAuthPassword; - - private boolean needsAnonymousLogin; - - private boolean needsTimeZone; - - private boolean needsEncoding; - - private boolean needsHttpAuth; - - private boolean needsValidation; - - private boolean needsAdvanced; - - protected Composite compositeContainer; - - private Composite advancedComp; - - private Composite httpAuthComp; - - private Composite proxyAuthComp; - - private ExpandableComposite advancedExpComposite; - - private ExpandableComposite httpAuthExpComposite; - - private ExpandableComposite proxyExpComposite; - - private Set<String> repositoryUrls; - - private String originalUrl; - - private Button otherEncoding; - - private Button httpAuthButton; - - private boolean needsProxy; - - private Button systemProxyButton; - - private String oldProxyUsername = ""; - - private String oldProxyPassword = ""; - - // private Button proxyAuthButton; - - private String oldProxyHostname = ""; - - private String oldProxyPort = ""; - - private Button proxyAuthButton; - - private final FormToolkit toolkit = new FormToolkit(Display.getCurrent()); - - private Hyperlink createAccountHyperlink; - - private Hyperlink manageAccountHyperlink; - - private Button savePasswordButton; - - private Button saveHttpPasswordButton; - - private Button saveProxyPasswordButton; - - private Button disconnectedButton; - - /** - * @since 3.0 - */ - public AbstractRepositorySettingsPage(String title, String description, TaskRepository taskRepository) { - super(title); - this.repository = taskRepository; - this.connector = TasksUi.getRepositoryManager().getRepositoryConnector(getConnectorKind()); - setTitle(title); - setDescription(description); - setNeedsAnonymousLogin(false); - setNeedsEncoding(true); - setNeedsTimeZone(true); - setNeedsProxy(true); - setNeedsValidation(true); - setNeedsAdvanced(true); - } - - /** - * @since 3.0 - */ - public abstract String getConnectorKind(); - - @Override - public void dispose() { - super.dispose(); - if (toolkit != null) { - if (toolkit.getColors() != null) { - toolkit.dispose(); - } - } - } - - public void createControl(Composite parent) { - - if (repository != null) { - originalUrl = repository.getRepositoryUrl(); - oldUsername = repository.getUserName(); - oldPassword = repository.getPassword(); - - if (repository.getHttpUser() != null && repository.getHttpPassword() != null) { - oldHttpAuthUserId = repository.getHttpUser(); - oldHttpAuthPassword = repository.getHttpPassword(); - } else { - oldHttpAuthPassword = ""; - oldHttpAuthUserId = ""; - } - - oldProxyHostname = repository.getProperty(TaskRepository.PROXY_HOSTNAME); - oldProxyPort = repository.getProperty(TaskRepository.PROXY_PORT); - if (oldProxyHostname == null) { - oldProxyHostname = ""; - } - if (oldProxyPort == null) { - oldProxyPort = ""; - } - - oldProxyUsername = repository.getProxyUsername(); - oldProxyPassword = repository.getProxyPassword(); - if (oldProxyUsername == null) { - oldProxyUsername = ""; - } - if (oldProxyPassword == null) { - oldProxyPassword = ""; - } - - } else { - oldUsername = ""; - oldPassword = ""; - oldHttpAuthPassword = ""; - oldHttpAuthUserId = ""; - } - - compositeContainer = new Composite(parent, SWT.NULL); - FillLayout layout = new FillLayout(); - compositeContainer.setLayout(layout); - - new Label(compositeContainer, SWT.NONE).setText(LABEL_SERVER); - serverUrlCombo = new Combo(compositeContainer, SWT.DROP_DOWN); - serverUrlCombo.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - isValidUrl(serverUrlCombo.getText()); - if (getWizard() != null) { - getWizard().getContainer().updateButtons(); - } - } - }); - - serverUrlCombo.addFocusListener(new FocusAdapter() { - - @Override - public void focusLost(FocusEvent e) { - updateHyperlinks(); - } - }); - - serverUrlCombo.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - isValidUrl(serverUrlCombo.getText()); - if (getWizard() != null) { - getWizard().getContainer().updateButtons(); - } - } - }); - - GridDataFactory.fillDefaults().hint(300, SWT.DEFAULT).grab(true, false).applyTo(serverUrlCombo); - - repositoryLabelEditor = new StringFieldEditor("", LABEL_REPOSITORY_LABEL, StringFieldEditor.UNLIMITED, - compositeContainer) { - - @Override - protected boolean doCheckState() { - return true; - // return isValidUrl(getStringValue()); - } - - @Override - protected void valueChanged() { - super.valueChanged(); - if (getWizard() != null) { - getWizard().getContainer().updateButtons(); - } - } - }; - // repositoryLabelEditor.setErrorMessage("error"); - - if (needsAnonymousLogin()) { - anonymousButton = new Button(compositeContainer, SWT.CHECK); - GridDataFactory.fillDefaults().span(2, SWT.DEFAULT).applyTo(anonymousButton); - - anonymousButton.setText("Anonymous Access"); - anonymousButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - setAnonymous(anonymousButton.getSelection()); - isPageComplete(); - } - }); - } - - repositoryUserNameEditor = new StringFieldEditor("", LABEL_USER, StringFieldEditor.UNLIMITED, - compositeContainer) { - - @Override - protected boolean doCheckState() { - return true; - } - - @Override - protected void valueChanged() { - super.valueChanged(); - isPageComplete(); - if (getWizard() != null) { - getWizard().getContainer().updateButtons(); - } - } - }; - - repositoryPasswordEditor = new RepositoryStringFieldEditor("", LABEL_PASSWORD, StringFieldEditor.UNLIMITED, - compositeContainer) { - - @Override - protected boolean doCheckState() { - return true; - } - - @Override - protected void valueChanged() { - super.valueChanged(); - isPageComplete(); - if (getWizard() != null) { - getWizard().getContainer().updateButtons(); - } - } - }; - - savePasswordButton = new Button(compositeContainer, SWT.CHECK); - GridDataFactory.fillDefaults().span(2, SWT.DEFAULT).applyTo(savePasswordButton); - savePasswordButton.setText("Save Password"); - - if (repository != null) { - try { - String repositoryLabel = repository.getProperty(IRepositoryConstants.PROPERTY_LABEL); - if (repositoryLabel != null && repositoryLabel.length() > 0) { - // repositoryLabelCombo.add(repositoryLabel); - // repositoryLabelCombo.select(0); - repositoryLabelEditor.setStringValue(repositoryLabel); - } - serverUrlCombo.setText(repository.getRepositoryUrl()); - repositoryUserNameEditor.setStringValue(repository.getUserName()); - repositoryPasswordEditor.setStringValue(repository.getPassword()); - } catch (Throwable t) { - StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Could not set field value", t)); - } - } - - if (needsAnonymousLogin()) { - if (repository != null) { - setAnonymous(repository.isAnonymous()); - } else { - setAnonymous(true); - } - } - - if (repository != null) { - savePasswordButton.setSelection(repository.getSavePassword(AuthenticationType.REPOSITORY)); - } else { - savePasswordButton.setSelection(false); - } - - // TODO: put this back if we can't get the info from all connectors - // if (needsTimeZone()) { - // Label timeZoneLabel = new Label(container, SWT.NONE); - // timeZoneLabel.setText("Repository time zone: "); - // timeZonesCombo = new Combo(container, SWT.READ_ONLY); - // String[] timeZoneIds = TimeZone.getAvailableIDs(); - // Arrays.sort(timeZoneIds); - // for (String zone : timeZoneIds) { - // timeZonesCombo.add(zone); - // } - // boolean setZone = false; - // if (repository != null) { - // if (timeZonesCombo.indexOf(repository.getTimeZoneId()) > -1) { - // timeZonesCombo.select(timeZonesCombo.indexOf(repository.getTimeZoneId())); - // setZone = true; - // } - // } - // if (!setZone) { - // timeZonesCombo.select(timeZonesCombo.indexOf(TimeZone.getDefault().getID())); - // } - // } - - if (needsAdvanced() || needsEncoding()) { - - advancedExpComposite = toolkit.createExpandableComposite(compositeContainer, ExpandableComposite.COMPACT - | ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR); - advancedExpComposite.clientVerticalSpacing = 0; - GridData gridData_2 = new GridData(SWT.FILL, SWT.FILL, true, false); - gridData_2.horizontalIndent = -5; - advancedExpComposite.setLayoutData(gridData_2); - advancedExpComposite.setFont(compositeContainer.getFont()); - advancedExpComposite.setBackground(compositeContainer.getBackground()); - advancedExpComposite.setText("Additional Settings"); - advancedExpComposite.addExpansionListener(new ExpansionAdapter() { - @Override - public void expansionStateChanged(ExpansionEvent e) { - getControl().getShell().pack(); - } - }); - - GridDataFactory.fillDefaults().span(2, SWT.DEFAULT).applyTo(advancedExpComposite); - - advancedComp = toolkit.createComposite(advancedExpComposite, SWT.NONE); - GridLayout gridLayout2 = new GridLayout(); - gridLayout2.numColumns = 2; - gridLayout2.verticalSpacing = 5; - advancedComp.setLayout(gridLayout2); - advancedComp.setBackground(compositeContainer.getBackground()); - advancedExpComposite.setClient(advancedComp); - - createAdditionalControls(advancedComp); - - if (needsEncoding()) { - Label encodingLabel = new Label(advancedComp, SWT.HORIZONTAL); - encodingLabel.setText("Character encoding:"); - GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.TOP).applyTo(encodingLabel); - - Composite encodingContainer = new Composite(advancedComp, SWT.NONE); - GridLayout gridLayout = new GridLayout(2, false); - gridLayout.marginWidth = 0; - gridLayout.marginHeight = 0; - encodingContainer.setLayout(gridLayout); - - defaultEncoding = new Button(encodingContainer, SWT.RADIO); - defaultEncoding.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1)); - defaultEncoding.setText("Default (" + TaskRepository.DEFAULT_CHARACTER_ENCODING + ")"); - defaultEncoding.setSelection(true); - - otherEncoding = new Button(encodingContainer, SWT.RADIO); - otherEncoding.setText("Other:"); - otherEncodingCombo = new Combo(encodingContainer, SWT.READ_ONLY); - for (String encoding : Charset.availableCharsets().keySet()) { - if (!encoding.equals(TaskRepository.DEFAULT_CHARACTER_ENCODING)) { - otherEncodingCombo.add(encoding); - } - } - - setDefaultEncoding(); - - otherEncoding.addSelectionListener(new SelectionAdapter() { - - @Override - public void widgetSelected(SelectionEvent e) { - if (otherEncoding.getSelection()) { - defaultEncoding.setSelection(false); - otherEncodingCombo.setEnabled(true); - } else { - defaultEncoding.setSelection(true); - otherEncodingCombo.setEnabled(false); - } - } - }); - - if (repository != null) { - try { - String repositoryEncoding = repository.getCharacterEncoding(); - if (repositoryEncoding != null) {// && - // !repositoryEncoding.equals(defaultEncoding)) - // { - if (otherEncodingCombo.getItemCount() > 0 - && otherEncodingCombo.indexOf(repositoryEncoding) > -1) { - otherEncodingCombo.setEnabled(true); - otherEncoding.setSelection(true); - defaultEncoding.setSelection(false); - otherEncodingCombo.select(otherEncodingCombo.indexOf(repositoryEncoding)); - } else { - setDefaultEncoding(); - } - } - } catch (Throwable t) { - StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, - "Could not set field value", t)); - } - } - } - } - - if (needsHttpAuth()) { - httpAuthExpComposite = toolkit.createExpandableComposite(compositeContainer, ExpandableComposite.COMPACT - | ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR); - httpAuthExpComposite.clientVerticalSpacing = 0; - GridData gridData_2 = new GridData(SWT.FILL, SWT.FILL, true, false); - gridData_2.horizontalIndent = -5; - httpAuthExpComposite.setLayoutData(gridData_2); - httpAuthExpComposite.setFont(compositeContainer.getFont()); - httpAuthExpComposite.setBackground(compositeContainer.getBackground()); - httpAuthExpComposite.setText("Http Authentication"); - httpAuthExpComposite.addExpansionListener(new ExpansionAdapter() { - @Override - public void expansionStateChanged(ExpansionEvent e) { - getControl().getShell().pack(); - } - }); - - GridDataFactory.fillDefaults().span(2, SWT.DEFAULT).applyTo(httpAuthExpComposite); - - httpAuthComp = toolkit.createComposite(httpAuthExpComposite, SWT.NONE); - GridLayout gridLayout2 = new GridLayout(); - gridLayout2.numColumns = 2; - gridLayout2.verticalSpacing = 0; - httpAuthComp.setLayout(gridLayout2); - httpAuthComp.setBackground(compositeContainer.getBackground()); - httpAuthExpComposite.setClient(httpAuthComp); - - httpAuthButton = new Button(httpAuthComp, SWT.CHECK); - GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.TOP).span(2, SWT.DEFAULT).applyTo(httpAuthButton); - - httpAuthButton.setText("Enabled"); - - httpAuthButton.addSelectionListener(new SelectionListener() { - public void widgetSelected(SelectionEvent e) { - setHttpAuth(httpAuthButton.getSelection()); - } - - public void widgetDefaultSelected(SelectionEvent e) { - // ignore - } - }); - - httpAuthUserNameEditor = new StringFieldEditor("", "User ID: ", StringFieldEditor.UNLIMITED, httpAuthComp) { - - @Override - protected boolean doCheckState() { - return true; - } - - @Override - protected void valueChanged() { - super.valueChanged(); - if (getWizard() != null) { - getWizard().getContainer().updateButtons(); - } - } - }; - httpAuthPasswordEditor = new RepositoryStringFieldEditor("", "Password: ", StringFieldEditor.UNLIMITED, - httpAuthComp); - ((RepositoryStringFieldEditor) httpAuthPasswordEditor).getTextControl().setEchoChar('*'); - - saveHttpPasswordButton = new Button(httpAuthComp, SWT.CHECK); - GridDataFactory.fillDefaults().span(2, SWT.DEFAULT).applyTo(saveHttpPasswordButton); - saveHttpPasswordButton.setText("Save Http Password"); - - httpAuthUserNameEditor.setEnabled(httpAuthButton.getSelection(), httpAuthComp); - httpAuthPasswordEditor.setEnabled(httpAuthButton.getSelection(), httpAuthComp); - saveHttpPasswordButton.setEnabled(httpAuthButton.getSelection()); - - if (repository != null) { - saveHttpPasswordButton.setSelection(repository.getSavePassword(AuthenticationType.HTTP)); - } else { - saveHttpPasswordButton.setSelection(false); - } - setHttpAuth(oldHttpAuthPassword != null && oldHttpAuthUserId != null && !oldHttpAuthUserId.equals("")); - - httpAuthExpComposite.setExpanded(httpAuthButton.getSelection()); - } - - if (needsProxy()) { - addProxySection(); - } - - addStatusSection(); - - Composite managementComposite = new Composite(compositeContainer, SWT.NULL); - GridLayout managementLayout = new GridLayout(4, false); - managementLayout.marginHeight = 0; - managementLayout.marginWidth = 0; - managementLayout.horizontalSpacing = 10; - managementComposite.setLayout(managementLayout); - managementComposite.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 2, 1)); - - if (needsValidation()) { - validateServerButton = new Button(managementComposite, SWT.PUSH); - GridDataFactory.swtDefaults().span(2, SWT.DEFAULT).grab(false, false).applyTo(validateServerButton); - validateServerButton.setText("Validate Settings"); - validateServerButton.addSelectionListener(new SelectionAdapter() { - - @Override - public void widgetSelected(SelectionEvent e) { - validateSettings(); - } - }); - } - - createAccountHyperlink = toolkit.createHyperlink(managementComposite, "Create new account", SWT.NONE); - createAccountHyperlink.setBackground(managementComposite.getBackground()); - createAccountHyperlink.addHyperlinkListener(new HyperlinkAdapter() { - @Override - public void linkActivated(HyperlinkEvent e) { -// TaskRepository repository = getRepository(); - TaskRepository repository = createTaskRepository(); -// if (repository == null && getServerUrl() != null && getServerUrl().length() > 0) { -// repository = createTaskRepository(); -// } - if (repository != null) { - String accountCreationUrl = TasksUiPlugin.getConnectorUi(connector.getConnectorKind()) - .getAccountCreationUrl(repository); - if (accountCreationUrl != null) { - TasksUiUtil.openUrl(accountCreationUrl); - } - } - } - }); - - manageAccountHyperlink = toolkit.createHyperlink(managementComposite, "Change account settings", SWT.NONE); - manageAccountHyperlink.setBackground(managementComposite.getBackground()); - manageAccountHyperlink.addHyperlinkListener(new HyperlinkAdapter() { - @Override - public void linkActivated(HyperlinkEvent e) { - TaskRepository repository = getRepository(); - if (repository == null && getRepositoryUrl() != null && getRepositoryUrl().length() > 0) { - repository = createTaskRepository(); - } - if (repository != null) { - String accountManagementUrl = TasksUiPlugin.getConnectorUi(connector.getConnectorKind()) - .getAccountManagementUrl(repository); - if (accountManagementUrl != null) { - TasksUiUtil.openUrl(accountManagementUrl); - } - } - } - }); - - // bug 131656: must set echo char after setting value on Mac - ((RepositoryStringFieldEditor) repositoryPasswordEditor).getTextControl().setEchoChar('*'); - - if (needsAnonymousLogin()) { - // do this after username and password widgets have been intialized - if (repository != null) { - setAnonymous(isAnonymousAccess()); - } - } - - updateHyperlinks(); - - setControl(compositeContainer); - } - - private void addProxySection() { - - proxyExpComposite = toolkit.createExpandableComposite(compositeContainer, ExpandableComposite.COMPACT - | ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR); - proxyExpComposite.clientVerticalSpacing = 0; - GridData gridData_2 = new GridData(SWT.FILL, SWT.FILL, true, false); - gridData_2.horizontalIndent = -5; - proxyExpComposite.setLayoutData(gridData_2); - proxyExpComposite.setFont(compositeContainer.getFont()); - proxyExpComposite.setBackground(compositeContainer.getBackground()); - proxyExpComposite.setText("Proxy Server Configuration"); - proxyExpComposite.addExpansionListener(new ExpansionAdapter() { - @Override - public void expansionStateChanged(ExpansionEvent e) { - getControl().getShell().pack(); - } - }); - - GridDataFactory.fillDefaults().span(2, SWT.DEFAULT).applyTo(proxyExpComposite); - - proxyAuthComp = toolkit.createComposite(proxyExpComposite, SWT.NONE); - GridLayout gridLayout2 = new GridLayout(); - gridLayout2.numColumns = 2; - gridLayout2.verticalSpacing = 0; - proxyAuthComp.setLayout(gridLayout2); - proxyAuthComp.setBackground(compositeContainer.getBackground()); - proxyExpComposite.setClient(proxyAuthComp); - - Composite settingsComposite = new Composite(proxyAuthComp, SWT.NULL); - GridLayout gridLayout3 = new GridLayout(); - gridLayout3.numColumns = 2; - gridLayout3.verticalSpacing = 0; - settingsComposite.setLayout(gridLayout3); - - systemProxyButton = new Button(settingsComposite, SWT.CHECK); - GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.TOP).span(2, SWT.DEFAULT).applyTo(settingsComposite); - - systemProxyButton.setText("Use global Network Connections preferences"); - Hyperlink changeProxySettingsLink = toolkit.createHyperlink(settingsComposite, "Change Settings", SWT.NULL); - changeProxySettingsLink.setBackground(compositeContainer.getBackground()); - changeProxySettingsLink.addHyperlinkListener(new IHyperlinkListener() { - - public void linkActivated(HyperlinkEvent e) { - PreferenceDialog dlg = PreferencesUtil.createPreferenceDialogOn(getShell(), PREFS_PAGE_ID_NET_PROXY, - new String[] { PREFS_PAGE_ID_NET_PROXY }, null); - dlg.open(); - } - - public void linkEntered(HyperlinkEvent e) { - // ignore - } - - public void linkExited(HyperlinkEvent e) { - // ignore - } - }); - - systemProxyButton.addSelectionListener(new SelectionListener() { - public void widgetSelected(SelectionEvent e) { - setUseDefaultProxy(systemProxyButton.getSelection()); - } - - public void widgetDefaultSelected(SelectionEvent e) { - // ignore - } - }); - - proxyHostnameEditor = new StringFieldEditor("", "Proxy host address: ", StringFieldEditor.UNLIMITED, - proxyAuthComp) { - - @Override - protected boolean doCheckState() { - return true; - } - - @Override - protected void valueChanged() { - super.valueChanged(); - if (getWizard() != null) { - getWizard().getContainer().updateButtons(); - } - } - }; - proxyHostnameEditor.setStringValue(oldProxyHostname); - - proxyPortEditor = new RepositoryStringFieldEditor("", "Proxy host port: ", StringFieldEditor.UNLIMITED, - proxyAuthComp); - - proxyPortEditor.setStringValue(oldProxyPort); - - proxyHostnameEditor.setEnabled(systemProxyButton.getSelection(), proxyAuthComp); - proxyPortEditor.setEnabled(systemProxyButton.getSelection(), proxyAuthComp); - - // ************* PROXY AUTHENTICATION ************** - - proxyAuthButton = new Button(proxyAuthComp, SWT.CHECK); - GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.TOP).span(2, SWT.DEFAULT).applyTo(proxyAuthButton); - - proxyAuthButton.setText("Enable proxy authentication"); - proxyAuthButton.addSelectionListener(new SelectionListener() { - public void widgetSelected(SelectionEvent e) { - setProxyAuth(proxyAuthButton.getSelection()); - } - - public void widgetDefaultSelected(SelectionEvent e) { - // ignore - } - }); - - proxyUserNameEditor = new StringFieldEditor("", "User ID: ", StringFieldEditor.UNLIMITED, proxyAuthComp) { - - @Override - protected boolean doCheckState() { - return true; - } - - @Override - protected void valueChanged() { - super.valueChanged(); - if (getWizard() != null) { - getWizard().getContainer().updateButtons(); - } - } - }; - proxyPasswordEditor = new RepositoryStringFieldEditor("", "Password: ", StringFieldEditor.UNLIMITED, - proxyAuthComp); - ((RepositoryStringFieldEditor) proxyPasswordEditor).getTextControl().setEchoChar('*'); - - // proxyPasswordEditor.setEnabled(httpAuthButton.getSelection(), - // advancedComp); - // ((StringFieldEditor) - // httpAuthPasswordEditor).setEnabled(httpAuthButton.getSelection(), - // advancedComp); - - saveProxyPasswordButton = new Button(proxyAuthComp, SWT.CHECK); - GridDataFactory.fillDefaults().span(2, SWT.DEFAULT).applyTo(saveProxyPasswordButton); - saveProxyPasswordButton.setText("Save Proxy Password"); - saveProxyPasswordButton.setEnabled(proxyAuthButton.getSelection()); - - if (repository != null) { - saveProxyPasswordButton.setSelection(repository.getSavePassword(AuthenticationType.PROXY)); - } else { - saveProxyPasswordButton.setSelection(false); - } - - setProxyAuth(oldProxyUsername != null && oldProxyPassword != null && !oldProxyUsername.equals("")); - - setUseDefaultProxy(repository != null ? repository.isDefaultProxyEnabled() : true); - proxyExpComposite.setExpanded(!systemProxyButton.getSelection()); - } - - private void addStatusSection() { - ExpandableComposite statusComposite = toolkit.createExpandableComposite(compositeContainer, - ExpandableComposite.COMPACT | ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR); - statusComposite.clientVerticalSpacing = 0; - GridData gd = new GridData(SWT.FILL, SWT.FILL, true, false); - gd.horizontalIndent = -5; - statusComposite.setLayoutData(gd); - statusComposite.setFont(compositeContainer.getFont()); - statusComposite.setBackground(compositeContainer.getBackground()); - statusComposite.setText("Status"); - statusComposite.addExpansionListener(new ExpansionAdapter() { - @Override - public void expansionStateChanged(ExpansionEvent e) { - getControl().getShell().pack(); - } - }); - GridDataFactory.fillDefaults().span(2, SWT.DEFAULT).applyTo(statusComposite); - - Composite composite = toolkit.createComposite(statusComposite, SWT.NONE); - GridLayout layout = new GridLayout(); - layout.numColumns = 2; - layout.verticalSpacing = 0; - composite.setLayout(layout); - composite.setBackground(compositeContainer.getBackground()); - statusComposite.setClient(composite); - - disconnectedButton = new Button(composite, SWT.CHECK); - disconnectedButton.setText("Disconnected"); - GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.TOP).span(2, SWT.DEFAULT).applyTo(disconnectedButton); - disconnectedButton.setSelection(repository != null ? repository.isOffline() : false); - statusComposite.setExpanded(disconnectedButton.getSelection()); - } - - protected void setEncoding(String encoding) { - if (encoding.equals(TaskRepository.DEFAULT_CHARACTER_ENCODING)) { - setDefaultEncoding(); - } else { - if (otherEncodingCombo.indexOf(encoding) != -1) { - defaultEncoding.setSelection(false); - otherEncodingCombo.setEnabled(true); - otherEncoding.setSelection(true); - otherEncodingCombo.select(otherEncodingCombo.indexOf(encoding)); - } else { - setDefaultEncoding(); - } - } - } - - private void setDefaultEncoding() { - defaultEncoding.setSelection(true); - otherEncoding.setSelection(false); - otherEncodingCombo.setEnabled(false); - if (otherEncodingCombo.getItemCount() > 0) { - otherEncodingCombo.select(0); - } - } - - public void setAnonymous(boolean selected) { - if (!needsAnonymousLogin) { - return; - } - - anonymousButton.setSelection(selected); - - if (selected) { - oldUsername = repositoryUserNameEditor.getStringValue(); - oldPassword = (repositoryPasswordEditor).getStringValue(); - repositoryUserNameEditor.setStringValue(""); - repositoryPasswordEditor.setStringValue(""); - } else { - repositoryUserNameEditor.setStringValue(oldUsername); - repositoryPasswordEditor.setStringValue(oldPassword); - } - - repositoryUserNameEditor.setEnabled(!selected, compositeContainer); - repositoryPasswordEditor.setEnabled(!selected, compositeContainer); - savePasswordButton.setEnabled(!selected); - if (getWizard() != null) { - getWizard().getContainer().updateButtons(); - } - } - - public void setHttpAuth(boolean selected) { - if (!needsHttpAuth) { - return; - } - httpAuthButton.setSelection(selected); - if (!selected) { - oldHttpAuthUserId = httpAuthUserNameEditor.getStringValue(); - oldHttpAuthPassword = httpAuthPasswordEditor.getStringValue(); - httpAuthUserNameEditor.setStringValue(null); - httpAuthPasswordEditor.setStringValue(null); - } else { - httpAuthUserNameEditor.setStringValue(oldHttpAuthUserId); - httpAuthPasswordEditor.setStringValue(oldHttpAuthPassword); - } - httpAuthUserNameEditor.setEnabled(selected, httpAuthComp); - httpAuthPasswordEditor.setEnabled(selected, httpAuthComp); - saveHttpPasswordButton.setEnabled(selected); - } - - /** - * @since 2.2 - */ - public boolean getHttpAuth() { - return httpAuthButton.getSelection(); - } - - public void setUseDefaultProxy(boolean selected) { - if (!needsProxy) { - return; - } - - systemProxyButton.setSelection(selected); - - if (selected) { - oldProxyHostname = proxyHostnameEditor.getStringValue(); - oldProxyPort = proxyPortEditor.getStringValue(); - // proxyHostnameEditor.setStringValue(null); - // proxyPortEditor.setStringValue(null); - } else { - proxyHostnameEditor.setStringValue(oldProxyHostname); - proxyPortEditor.setStringValue(oldProxyPort); - } - proxyHostnameEditor.setEnabled(!selected, proxyAuthComp); - proxyPortEditor.setEnabled(!selected, proxyAuthComp); - proxyAuthButton.setEnabled(!selected); - setProxyAuth(proxyAuthButton.getSelection()); - } - - public void setProxyAuth(boolean selected) { - - proxyAuthButton.setSelection(selected); - proxyAuthButton.setEnabled(!systemProxyButton.getSelection()); - if (!selected) { - oldProxyUsername = proxyUserNameEditor.getStringValue(); - oldProxyPassword = proxyPasswordEditor.getStringValue(); - proxyUserNameEditor.setStringValue(null); - proxyPasswordEditor.setStringValue(null); - } else { - proxyUserNameEditor.setStringValue(oldProxyUsername); - proxyPasswordEditor.setStringValue(oldProxyPassword); - } - - proxyUserNameEditor.setEnabled(selected && !systemProxyButton.getSelection(), proxyAuthComp); - proxyPasswordEditor.setEnabled(selected && !systemProxyButton.getSelection(), proxyAuthComp); - saveProxyPasswordButton.setEnabled(selected && !systemProxyButton.getSelection()); - } - - /** - * @since 2.2 - */ - public boolean getProxyAuth() { - return proxyAuthButton.getSelection(); - } - - /** - * @since 3.0 - */ - protected void addRepositoryTemplatesToServerUrlCombo() { - final RepositoryTemplateManager templateManager = TasksUiPlugin.getRepositoryTemplateManager(); - for (RepositoryTemplate template : templateManager.getTemplates(connector.getConnectorKind())) { - serverUrlCombo.add(template.label); - } - serverUrlCombo.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - String text = serverUrlCombo.getText(); - RepositoryTemplate template = templateManager.getTemplate(connector.getConnectorKind(), text); - if (template != null) { - repositoryTemplateSelected(template); - return; - } - } - - }); - } - - /** - * @since 3.0 - */ - protected void repositoryTemplateSelected(RepositoryTemplate template) { - } - - protected abstract void createAdditionalControls(Composite parent); - - protected abstract boolean isValidUrl(String name); - - void updateHyperlinks() { - if (getRepositoryUrl() != null && getRepositoryUrl().length() > 0) { - TaskRepository repository = createTaskRepository(); - String accountCreationUrl = TasksUiPlugin.getConnectorUi(connector.getConnectorKind()) - .getAccountCreationUrl(repository); - createAccountHyperlink.setEnabled(accountCreationUrl != null); - createAccountHyperlink.setVisible(accountCreationUrl != null); - - String accountManagementUrl = TasksUiPlugin.getConnectorUi(connector.getConnectorKind()) - .getAccountManagementUrl(repository); - manageAccountHyperlink.setEnabled(accountManagementUrl != null); - manageAccountHyperlink.setVisible(accountManagementUrl != null); - } else { - createAccountHyperlink.setEnabled(false); - createAccountHyperlink.setVisible(false); - manageAccountHyperlink.setEnabled(false); - manageAccountHyperlink.setVisible(false); - } - } - - public String getRepositoryLabel() { - return repositoryLabelEditor.getStringValue(); - } - - /** - * @since 3.0 - */ - public String getRepositoryUrl() { - return TaskRepositoryManager.stripSlashes(serverUrlCombo.getText()); - } - - public String getUserName() { - return repositoryUserNameEditor.getStringValue(); - } - - public String getPassword() { - return repositoryPasswordEditor.getStringValue(); - } - - public String getHttpAuthUserId() { - if (needsHttpAuth()) { - return httpAuthUserNameEditor.getStringValue(); - } else { - return ""; - } - } - - public String getHttpAuthPassword() { - if (needsHttpAuth()) { - return httpAuthPasswordEditor.getStringValue(); - } else { - return ""; - } - } - - public String getProxyHostname() { - if (needsProxy()) { - return proxyHostnameEditor.getStringValue(); - } else { - return ""; - } - } - - public String getProxyPort() { - if (needsProxy()) { - return proxyPortEditor.getStringValue(); - } else { - return ""; - } - } - - public Boolean getUseDefaultProxy() { - if (needsProxy()) { - return systemProxyButton.getSelection(); - } else { - return true; - } - } - - public String getProxyUserName() { - if (needsProxy()) { - return proxyUserNameEditor.getStringValue(); - } else { - return ""; - } - } - - public String getProxyPassword() { - if (needsProxy()) { - return proxyPasswordEditor.getStringValue(); - } else { - return ""; - } - } - - public void init(IWorkbench workbench) { - // ignore - } - - public boolean isAnonymousAccess() { - if (anonymousButton != null) { - return anonymousButton.getSelection(); - } else { - return false; - } - } - - /** - * Exposes StringFieldEditor.refreshValidState() - * - * TODO: is there a better way? - */ - private static class RepositoryStringFieldEditor extends StringFieldEditor { - public RepositoryStringFieldEditor(String name, String labelText, int style, Composite parent) { - super(name, labelText, style, parent); - } - - @Override - public void refreshValidState() { - try { - super.refreshValidState(); - } catch (Exception e) { - StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, - "Problem refreshing password field", e)); - } - } - - @Override - public Text getTextControl() { - return super.getTextControl(); - } - - } - - @Override - public boolean isPageComplete() { - String errorMessage = null; - String url = getRepositoryUrl(); - errorMessage = isUniqueUrl(url); - if (errorMessage == null && !isValidUrl(url)) { - errorMessage = "Enter a valid server url"; - } - if (errorMessage == null) { - errorMessage = credentialsComplete(); - } - - setErrorMessage(errorMessage); - return errorMessage == null; - } - - private String credentialsComplete() { - if ((needsAnonymousLogin() && !anonymousButton.getSelection()) - && (repositoryUserNameEditor.getStringValue().trim().equals("") || (repositoryPasswordEditor.getStringValue() - .trim().equals("")))) { - return "Repository user name and password must not be blank"; - } - return null; - - } - - protected String isUniqueUrl(String urlString) { - if (!urlString.equals(originalUrl)) { - if (repositoryUrls == null) { - List<TaskRepository> repositories = TasksUi.getRepositoryManager().getAllRepositories(); - repositoryUrls = new HashSet<String>(repositories.size()); - for (TaskRepository repository : repositories) { - repositoryUrls.add(repository.getRepositoryUrl()); - } - } - - if (repositoryUrls.contains(urlString)) { - return "Repository already exists."; - } - } - return null; - } - - @Deprecated - public void setRepository(TaskRepository repository) { - this.repository = repository; - } - - @Deprecated - public void setVersion(String previousVersion) { - if (previousVersion == null) { - serverVersion = TaskRepository.NO_VERSION_SPECIFIED; - } else { - serverVersion = previousVersion; - } - } - - public String getVersion() { - return serverVersion; - } - - public TaskRepository getRepository() { - return repository; - } - - public String getCharacterEncoding() { - if (defaultEncoding == null) { - return null; - } - - if (defaultEncoding.getSelection()) { - return TaskRepository.DEFAULT_CHARACTER_ENCODING; - } else { - if (otherEncodingCombo.getSelectionIndex() > -1) { - return otherEncodingCombo.getItem(otherEncodingCombo.getSelectionIndex()); - } else { - return TaskRepository.DEFAULT_CHARACTER_ENCODING; - } - } - } - - public TaskRepository createTaskRepository() { - TaskRepository repository = new TaskRepository(connector.getConnectorKind(), getRepositoryUrl()); - applyTo(repository); - return repository; - } - - /** - * @since 2.2 - */ - public void applyTo(TaskRepository repository) { - repository.setVersion(getVersion()); - if (needsEncoding()) { - repository.setCharacterEncoding(getCharacterEncoding()); - } - - if (isAnonymousAccess()) { - repository.setCredentials(AuthenticationType.REPOSITORY, null, getSavePassword()); - } else { - AuthenticationCredentials credentials = new AuthenticationCredentials(getUserName(), getPassword()); - repository.setCredentials(AuthenticationType.REPOSITORY, credentials, getSavePassword()); - } - repository.setRepositoryLabel(getRepositoryLabel()); - repository.setAnonymous(isAnonymousAccess()); - - if (needsHttpAuth()) { - if (getHttpAuth()) { - AuthenticationCredentials webCredentials = new AuthenticationCredentials(getHttpAuthUserId(), - getHttpAuthPassword()); - repository.setCredentials(AuthenticationType.HTTP, webCredentials, getSaveHttpPassword()); - } else { - repository.setCredentials(AuthenticationType.HTTP, null, getSaveHttpPassword()); - } - } - - if (needsProxy()) { - repository.setProperty(TaskRepository.PROXY_USEDEFAULT, String.valueOf(getUseDefaultProxy())); - repository.setProperty(TaskRepository.PROXY_HOSTNAME, getProxyHostname()); - repository.setProperty(TaskRepository.PROXY_PORT, getProxyPort()); - if (getProxyAuth()) { - AuthenticationCredentials webCredentials = new AuthenticationCredentials(getProxyUserName(), - getProxyPassword()); - repository.setCredentials(AuthenticationType.PROXY, webCredentials, getSaveProxyPassword()); - } else { - repository.setCredentials(AuthenticationType.PROXY, null, getSaveProxyPassword()); - } - } - - repository.setOffline(disconnectedButton.getSelection()); - } - - public AbstractRepositoryConnector getConnector() { - return connector; - } - - public boolean needsEncoding() { - return needsEncoding; - } - - public boolean needsTimeZone() { - return needsTimeZone; - } - - public boolean needsAnonymousLogin() { - return needsAnonymousLogin; - } - - public boolean needsAdvanced() { - return needsAdvanced; - } - - public void setNeedsEncoding(boolean needsEncoding) { - this.needsEncoding = needsEncoding; - } - - public void setNeedsTimeZone(boolean needsTimeZone) { - this.needsTimeZone = needsTimeZone; - } - - public void setNeedsAdvanced(boolean needsAdvanced) { - this.needsAdvanced = needsAdvanced; - } - - public boolean needsHttpAuth() { - return this.needsHttpAuth; - } - - public void setNeedsHttpAuth(boolean needsHttpAuth) { - this.needsHttpAuth = needsHttpAuth; - } - - public void setNeedsProxy(boolean needsProxy) { - this.needsProxy = needsProxy; - } - - public boolean needsProxy() { - return this.needsProxy; - } - - public void setNeedsAnonymousLogin(boolean needsAnonymousLogin) { - this.needsAnonymousLogin = needsAnonymousLogin; - } - - public void setNeedsValidation(boolean needsValidation) { - this.needsValidation = needsValidation; - } - - public boolean needsValidation() { - return needsValidation; - } - - /** for testing */ - public void setUrl(String url) { - serverUrlCombo.setText(url); - } - - /** for testing */ - public void setUserId(String id) { - repositoryUserNameEditor.setStringValue(id); - } - - /** for testing */ - public void setPassword(String pass) { - repositoryPasswordEditor.setStringValue(pass); - } - - /** - * @since 2.2 - */ - public Boolean getSavePassword() { - return savePasswordButton.getSelection(); - } - - /** - * @since 2.2 - */ - public Boolean getSaveProxyPassword() { - if (needsProxy()) { - return saveProxyPasswordButton.getSelection(); - } else { - return false; - } - } - - /** - * @since 2.2 - */ - public Boolean getSaveHttpPassword() { - if (needsHttpAuth()) { - return saveHttpPasswordButton.getSelection(); - } else { - return false; - } - } - - protected void validateSettings() { - final Validator validator = getValidator(createTaskRepository()); - if (validator == null) { - return; - } - - try { - getWizard().getContainer().run(true, true, new IRunnableWithProgress() { - public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - monitor.beginTask("Validating server settings", IProgressMonitor.UNKNOWN); - try { - validator.run(monitor); - if (validator.getStatus() == null) { - validator.setStatus(Status.OK_STATUS); - } - } catch (CoreException e) { - validator.setStatus(e.getStatus()); - } catch (OperationCanceledException e) { - validator.setStatus(Status.CANCEL_STATUS); - throw new InterruptedException(); - } catch (Exception e) { - throw new InvocationTargetException(e); - } finally { - monitor.done(); - } - } - }); - } catch (InvocationTargetException e) { - StatusHandler.fail(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, - "Internal error validating repository", e.getCause())); - return; - } catch (InterruptedException e) { - // canceled - return; - } - - applyValidatorResult(validator); - getWizard().getContainer().updateButtons(); - } - - protected void applyValidatorResult(Validator validator) { - IStatus status = validator.getStatus(); - String message = status.getMessage(); - if (message == null || message.length() == 0) { - message = null; - } - switch (status.getSeverity()) { - case IStatus.OK: - if (status == Status.OK_STATUS) { - if (getUserName().length() > 0) { - message = "Authentication credentials are valid."; - } else { - message = "Repository is valid."; - } - } - setMessage(message, IMessageProvider.INFORMATION); - break; - case IStatus.INFO: - setMessage(message, IMessageProvider.INFORMATION); - break; - case IStatus.WARNING: - setMessage(message, IMessageProvider.WARNING); - break; - default: - setMessage(message, IMessageProvider.ERROR); - break; - } - setErrorMessage(null); - } - - protected abstract Validator getValidator(TaskRepository repository); - - // public for testing - public abstract class Validator { - - private IStatus status; - - public abstract void run(IProgressMonitor monitor) throws CoreException; - - public IStatus getStatus() { - return status; - } - - public void setStatus(IStatus status) { - this.status = status; - } - - } - -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/ITaskRepositoryPage.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/ITaskRepositoryPage.java deleted file mode 100644 index 772a7a30f..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/ITaskRepositoryPage.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Mylyn project committers 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.ui.wizards; - -import org.eclipse.jface.wizard.IWizardPage; -import org.eclipse.mylyn.tasks.core.TaskRepository; - -/** - * @author Steffen Pingel - * @since 3.0 - */ -public interface ITaskRepositoryPage extends IWizardPage { - - public abstract TaskRepository createTaskRepository(); - - public abstract void applyTo(TaskRepository repository); - - public abstract String getRepositoryUrl(); - -}
\ No newline at end of file diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/ITaskSearchPage.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/ITaskSearchPage.java deleted file mode 100644 index 70b434e57..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/ITaskSearchPage.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Mylyn project committers 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.ui.wizards; - -import org.eclipse.jface.dialogs.IDialogPage; - -/** - * @author Steffen Pingel - * @since 3.0 - */ -public interface ITaskSearchPage extends IDialogPage { - - public abstract void setContainer(ITaskSearchPageContainer container); - - public abstract boolean performSearch(); - -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/ITaskSearchPageContainer.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/ITaskSearchPageContainer.java deleted file mode 100644 index c86b9eef6..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/ITaskSearchPageContainer.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Mylyn project committers 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.ui.wizards; - -import org.eclipse.jface.operation.IRunnableContext; - -/** - * @author Steffen Pingel - * @since 3.0 - */ -public interface ITaskSearchPageContainer { - - public abstract IRunnableContext getRunnableContext(); - - public abstract void setPerformActionEnabled(boolean enabled); - -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/NewTaskWizard.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/NewTaskWizard.java deleted file mode 100644 index f32a24f05..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/NewTaskWizard.java +++ /dev/null @@ -1,208 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Mylyn project committers 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.ui.wizards; - -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.mylyn.commons.core.StatusHandler; -import org.eclipse.mylyn.internal.tasks.core.AbstractTask; -import org.eclipse.mylyn.internal.tasks.core.deprecated.AbstractAttributeFactory; -import org.eclipse.mylyn.internal.tasks.core.deprecated.AbstractLegacyRepositoryConnector; -import org.eclipse.mylyn.internal.tasks.core.deprecated.RepositoryTaskData; -import org.eclipse.mylyn.internal.tasks.core.deprecated.TaskSelection; -import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; -import org.eclipse.mylyn.internal.tasks.ui.deprecated.NewTaskEditorInput; -import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal; -import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector; -import org.eclipse.mylyn.tasks.core.ITaskMapping; -import org.eclipse.mylyn.tasks.core.RepositoryStatus; -import org.eclipse.mylyn.tasks.core.TaskRepository; -import org.eclipse.mylyn.tasks.core.data.TaskData; -import org.eclipse.mylyn.tasks.ui.TasksUi; -import org.eclipse.mylyn.tasks.ui.TasksUiImages; -import org.eclipse.mylyn.tasks.ui.TasksUiUtil; -import org.eclipse.mylyn.tasks.ui.editors.TaskEditor; -import org.eclipse.ui.INewWizard; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.PlatformUI; - -/** - * Extend for customizing how new tasks editors are created. - * - * @author Steffen Pingel - * @since 2.0 - */ -public class NewTaskWizard extends Wizard implements INewWizard { - - private final TaskRepository taskRepository; - - private ITaskMapping taskSelection; - - /** - * @since 3.0 - */ - public NewTaskWizard(TaskRepository taskRepository, ITaskMapping taskSelection) { - Assert.isNotNull(taskRepository); - this.taskRepository = taskRepository; - this.taskSelection = taskSelection; - setDefaultPageImageDescriptor(TasksUiImages.BANNER_REPOSITORY); - setNeedsProgressMonitor(true); - } - - public NewTaskWizard(TaskRepository taskRepository) { - this.taskRepository = taskRepository; - } - - public void init(IWorkbench workbench, IStructuredSelection selection) { - } - - @Override - public void addPages() { - } - - @Override - public boolean canFinish() { - return true; - } - - /** - * @since 3.0 - */ - protected ITaskMapping getInitializationData() { - return null; - } - - /** - * @since 3.0 - */ - public TaskRepository getTaskRepository() { - return taskRepository; - } - - /** - * @since 3.0 - */ - public ITaskMapping getTaskSelection() { - return taskSelection; - } - - @SuppressWarnings( { "deprecation", "restriction" }) - @Override - public boolean performFinish() { - AbstractRepositoryConnector connector = TasksUi.getRepositoryManager().getRepositoryConnector( - taskRepository.getConnectorKind()); - if (connector instanceof AbstractLegacyRepositoryConnector) { - return createLegacyTask((AbstractLegacyRepositoryConnector) connector); - } - - final TaskData[] taskData = new TaskData[1]; - final ITaskMapping initializationData = getInitializationData(); - final ITaskMapping selectionData = getTaskSelection(); - try { - IRunnableWithProgress runnable = new IRunnableWithProgress() { - public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - try { - taskData[0] = TasksUiInternal.createTaskData(taskRepository, initializationData, selectionData, - monitor); - } catch (OperationCanceledException e) { - throw new InterruptedException(); - } catch (CoreException e) { - throw new InvocationTargetException(e); - } - } - }; - getContainer().run(true, true, runnable); - } catch (InvocationTargetException e) { - if (e.getCause() instanceof CoreException) { - TasksUiInternal.displayStatus("Error creating new task", ((CoreException) e.getCause()).getStatus()); - } else { - StatusHandler.fail(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Error creating new task", - e.getCause())); - } - return false; - } catch (InterruptedException e) { - return false; - } - - try { - TasksUiInternal.createAndOpenNewTask(taskData[0]); - return true; - } catch (CoreException e) { - StatusHandler.log(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Failed to open new task", e)); - TasksUiInternal.displayStatus("Create Task", new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, - "Failed to create new task: " + e.getMessage())); - return false; - } - } - - @SuppressWarnings( { "deprecation", "restriction" }) - private boolean createLegacyTask(AbstractLegacyRepositoryConnector legacyConnector) { - final org.eclipse.mylyn.internal.tasks.core.deprecated.AbstractTaskDataHandler taskDataHandler = legacyConnector.getLegacyTaskDataHandler(); - if (taskDataHandler == null) { - TasksUiInternal.displayStatus("Error creating new task", new RepositoryStatus(IStatus.ERROR, - TasksUiPlugin.ID_PLUGIN, RepositoryStatus.ERROR_REPOSITORY, - "The selected repository does not support creating new tasks.")); - return false; - } - - AbstractAttributeFactory attributeFactory = taskDataHandler.getAttributeFactory( - taskRepository.getRepositoryUrl(), taskRepository.getConnectorKind(), AbstractTask.DEFAULT_TASK_KIND); - - final RepositoryTaskData taskData = new RepositoryTaskData(attributeFactory, taskRepository.getConnectorKind(), - taskRepository.getRepositoryUrl(), TasksUiPlugin.getDefault().getNextNewRepositoryTaskId()); - taskData.setNew(true); - - try { - IRunnableWithProgress runnable = new IRunnableWithProgress() { - public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - try { - if (!taskDataHandler.initializeTaskData(taskRepository, taskData, monitor)) { - throw new CoreException(new RepositoryStatus(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, - RepositoryStatus.ERROR_REPOSITORY, - "The selected repository does not support creating new tasks.")); - } - } catch (CoreException e) { - throw new InvocationTargetException(e); - } - } - }; - - getContainer().run(true, true, runnable); - } catch (InvocationTargetException e) { - if (e.getCause() instanceof CoreException) { - TasksUiInternal.displayStatus("Error creating new task", ((CoreException) e.getCause()).getStatus()); - } else { - StatusHandler.fail(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Error creating new task", - e.getCause())); - } - return false; - } catch (InterruptedException e) { - return false; - } - - if (taskSelection instanceof TaskSelection) { - taskDataHandler.cloneTaskData(((TaskSelection) taskSelection).getLegacyTaskData(), taskData); - } - - NewTaskEditorInput editorInput = new NewTaskEditorInput(taskRepository, taskData); - IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - TasksUiUtil.openEditor(editorInput, TaskEditor.ID_EDITOR, page); - return true; - } -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/NewWebTaskWizard.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/NewWebTaskWizard.java deleted file mode 100644 index 1fd16b7e4..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/NewWebTaskWizard.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Mylyn project committers 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.ui.wizards; - -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.mylyn.internal.tasks.core.deprecated.RepositoryTaskData; -import org.eclipse.mylyn.internal.tasks.core.deprecated.TaskSelection; -import org.eclipse.mylyn.internal.tasks.ui.wizards.NewWebTaskPage; -import org.eclipse.mylyn.tasks.core.ITaskMapping; -import org.eclipse.mylyn.tasks.core.TaskRepository; -import org.eclipse.mylyn.tasks.ui.TasksUiImages; -import org.eclipse.mylyn.tasks.ui.TasksUiUtil; -import org.eclipse.swt.dnd.Clipboard; -import org.eclipse.swt.dnd.TextTransfer; -import org.eclipse.swt.dnd.Transfer; -import org.eclipse.ui.INewWizard; -import org.eclipse.ui.IWorkbench; - -/** - * Wizard for creating new tickets through a web browser. - * - * @author Eugene Kuleshov - * @author Mik Kersten - * @author Steffen Pingel - * @since 2.0 - */ -public class NewWebTaskWizard extends Wizard implements INewWizard { - - protected TaskRepository taskRepository; - - protected String newTaskUrl; - - private final ITaskMapping taskSelection; - - /** - * @since 3.0 - */ - public NewWebTaskWizard(TaskRepository taskRepository, String newTaskUrl, ITaskMapping taskSelection) { - this.taskRepository = taskRepository; - this.newTaskUrl = newTaskUrl; - this.taskSelection = taskSelection; - - setWindowTitle("New Task"); - setDefaultPageImageDescriptor(TasksUiImages.BANNER_REPOSITORY); - } - - public void init(IWorkbench workbench, IStructuredSelection selection) { - } - - @Override - public void addPages() { - addPage(new NewWebTaskPage(taskSelection)); - } - - @Override - public boolean canFinish() { - return true; - } - - @Override - public boolean performFinish() { - handleSelection(taskSelection); - TasksUiUtil.openUrl(newTaskUrl); - return true; - } - - private void handleSelection(final ITaskMapping taskSelection) { - if (taskSelection == null) { - return; - } - - if (taskSelection instanceof TaskSelection) { - RepositoryTaskData taskData = ((TaskSelection) taskSelection).getLegacyTaskData(); - String summary = taskData.getSummary(); - String description = taskData.getDescription(); - - Clipboard clipboard = new Clipboard(getShell().getDisplay()); - clipboard.setContents(new Object[] { summary + "\n" + description }, - new Transfer[] { TextTransfer.getInstance() }); - } - // FIXME 3.0 implement TaskData support - - MessageDialog.openInformation( - getShell(), - "New Task", - "This connector does not provide a rich task editor for creating tasks.\n\n" - + "The error contents have been placed in the clipboard so that you can paste them into the entry form."); - } - -} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/RepositoryQueryWizard.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/RepositoryQueryWizard.java deleted file mode 100644 index e6be135ba..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/RepositoryQueryWizard.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Mylyn project committers 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.ui.wizards; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.wizard.IWizardPage; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.mylyn.commons.core.StatusHandler; -import org.eclipse.mylyn.internal.tasks.core.RepositoryQuery; -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.IRepositoryQuery; -import org.eclipse.mylyn.tasks.core.TaskRepository; -import org.eclipse.mylyn.tasks.ui.TasksUi; -import org.eclipse.mylyn.tasks.ui.TasksUiImages; - -/** - * Extend to provide a custom edit query dialog, typically invoked by the user requesting properties on a query node in - * the Task List. - * - * @author Mik Kersten - * @author Steffen Pingel - * @since 3.0 - */ -public class RepositoryQueryWizard extends Wizard { - - private static final String TITLE = "Edit Repository Query"; - - private final TaskRepository repository; - - /** - * @since 3.0 - */ - public RepositoryQueryWizard(TaskRepository repository) { - Assert.isNotNull(repository); - this.repository = repository; - setNeedsProgressMonitor(true); - setWindowTitle(TITLE); - setDefaultPageImageDescriptor(TasksUiImages.BANNER_REPOSITORY); - } - - @Override - public boolean canFinish() { - IWizardPage currentPage = getContainer().getCurrentPage(); - if (currentPage instanceof AbstractRepositoryQueryPage) { - return currentPage.isPageComplete(); - } - return false; - } - - @Override - public boolean performFinish() { - IWizardPage currentPage = getContainer().getCurrentPage(); - if (!(currentPage instanceof AbstractRepositoryQueryPage)) { - StatusHandler.fail(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, - "Current wizard page does not extends AbstractRepositoryQueryPage")); - return false; - } - - AbstractRepositoryQueryPage page = (AbstractRepositoryQueryPage) currentPage; - IRepositoryQuery query = page.getQuery(); - if (query != null) { - page.applyTo(query); - if (query instanceof RepositoryQuery) { - TasksUiPlugin.getTaskList().notifyElementChanged((RepositoryQuery) query); - } - } else { - query = page.createQuery(); - TasksUiInternal.getTaskList().addQuery((RepositoryQuery) query); - } - AbstractRepositoryConnector connector = TasksUi.getRepositoryManager().getRepositoryConnector( - getTaskRepository().getConnectorKind()); - TasksUiInternal.synchronizeQuery(connector, (RepositoryQuery) query, null, true); - return true; - } - - public TaskRepository getTaskRepository() { - return repository; - } - -}
\ No newline at end of file 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 deleted file mode 100644 index ddf26edfc..000000000 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/TaskAttachmentPage.java +++ /dev/null @@ -1,326 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Mylyn project committers 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 - *******************************************************************************/ - -package org.eclipse.mylyn.tasks.ui.wizards; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -import org.eclipse.jface.wizard.IWizardPage; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.mylyn.context.core.ContextCore; -import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages; -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.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; - -/** - * A wizard page to enter details of a new attachment. - * - * @author Jeff Pound - * @author Mik Kersten - * @author Steffen Pingel - * @since 3.0 - */ -public class TaskAttachmentPage extends WizardPage { - - private static List<String> contentTypes; - - private static Map<String, String> extensions2Types; - - static { - /* For UI */ - contentTypes = new LinkedList<String>(); - contentTypes.add("text/plain"); - contentTypes.add("text/html"); - contentTypes.add("application/xml"); - contentTypes.add("image/gif"); - contentTypes.add("image/jpeg"); - contentTypes.add("image/png"); - contentTypes.add("application/octet-stream"); - - /* For auto-detect */ - extensions2Types = new HashMap<String, String>(); - extensions2Types.put("txt", "text/plain"); - extensions2Types.put("html", "text/html"); - extensions2Types.put("htm", "text/html"); - extensions2Types.put("jpg", "image/jpeg"); - extensions2Types.put("jpeg", "image/jpeg"); - extensions2Types.put("gif", "image/gif"); - extensions2Types.put("png", "image/png"); - extensions2Types.put("xml", "application/xml"); - extensions2Types.put("zip", "application/octet-stream"); - extensions2Types.put("tar", "application/octet-stream"); - extensions2Types.put("gz", "application/octet-stream"); - } - - private Button attachContextButton; - - private Text commentText; - - private Text descriptionText; - - private Combo contentTypeList; - - private Text fileNameText; - - private Button isPatchButton; - - private final TaskAttachmentModel model; - - private boolean needsDescription; - - private final TaskAttachmentMapper taskAttachment; - - private boolean first = true; - - public TaskAttachmentPage(TaskAttachmentModel model) { - super("AttachmentDetails"); - this.model = model; - this.taskAttachment = TaskAttachmentMapper.createFrom(model.getAttribute()); - setTitle("Attachment Details"); - setNeedsDescription(true); - } - - public void createControl(Composite parent) { - Composite composite = new Composite(parent, SWT.NONE); - GridLayout gridLayout = new GridLayout(); - gridLayout.numColumns = 3; - composite.setLayout(gridLayout); - setControl(composite); - - composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - composite.setLayout(new GridLayout(3, false)); - - new Label(composite, SWT.NONE).setText("File"); - fileNameText = new Text(composite, SWT.BORDER); - fileNameText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1)); - - if (needsDescription) { - new Label(composite, SWT.NONE).setText("Description"); - descriptionText = new Text(composite, SWT.BORDER); - descriptionText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1)); - - descriptionText.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - if ("".equals(descriptionText.getText().trim())) { - setErrorMessage("Description required"); - } else { - taskAttachment.setDescription(descriptionText.getText().trim()); - if (!"".equals(fileNameText.getText())) { - setPageComplete(true); - setErrorMessage(null); - } - } - } - - }); - } - - Label label = new Label(composite, SWT.NONE); - label.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false)); - label.setText("Comment"); - commentText = new Text(composite, SWT.V_SCROLL | SWT.BORDER | SWT.WRAP); - commentText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1)); - - new Label(composite, SWT.NONE).setText("Content Type");// .setBackground(parent.getBackground()); - - contentTypeList = new Combo(composite, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY); - contentTypeList.setLayoutData(new GridData(SWT.DEFAULT, SWT.DEFAULT, false, false, 2, 1)); - final HashMap<String, Integer> contentTypeIndices = new HashMap<String, Integer>(); - Iterator<String> iter = contentTypes.iterator(); - int i = 0; - while (iter.hasNext()) { - String next = iter.next(); - contentTypeList.add(next); - contentTypeIndices.put(next, new Integer(i)); - i++; - } - - /* Update attachment on select content type */ - contentTypeList.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - // ignore - } - - public void widgetSelected(SelectionEvent e) { - taskAttachment.setContentType(contentTypeList.getItem(contentTypeList.getSelectionIndex())); - } - }); - contentTypeList.select(0); - taskAttachment.setContentType(contentTypeList.getItem(0)); - - // TODO: is there a better way to pad? - new Label(composite, SWT.NONE); - - isPatchButton = new Button(composite, SWT.CHECK); - isPatchButton.setLayoutData(new GridData(SWT.DEFAULT, SWT.DEFAULT, false, false, 2, 1)); - isPatchButton.setText("Patch"); - - // TODO: is there a better way to pad? - new Label(composite, SWT.NONE); - - attachContextButton = new Button(composite, SWT.CHECK); - attachContextButton.setLayoutData(new GridData(SWT.DEFAULT, SWT.DEFAULT, false, false, 2, 1)); - attachContextButton.setText("Attach Context"); - attachContextButton.setImage(CommonImages.getImage(TasksUiImages.CONTEXT_ATTACH)); - attachContextButton.setEnabled(ContextCore.getContextManager() - .hasContext(model.getTask().getHandleIdentifier())); - - /* - * Attachment file name listener, update the local attachment - * accordingly - */ - fileNameText.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - // Determine type by extension - int index = fileNameText.getText().lastIndexOf("."); - if (index > 0 && index < fileNameText.getText().length()) { - String ext = fileNameText.getText().substring(index + 1); - String type = extensions2Types.get(ext.toLowerCase(Locale.ENGLISH)); - if (type != null) { - contentTypeList.select(contentTypeIndices.get(type)); - taskAttachment.setContentType(type); - } - } - - // check page completenes - if (descriptionText != null && "".equals(descriptionText.getText())) { - setErrorMessage("Description required"); - } else { - if (!"".equals(fileNameText.getText())) { - setPageComplete(true); - setErrorMessage(null); - } - } - } - }); - - fileNameText.setText(taskAttachment.getFileName() == null ? "" : taskAttachment.getFileName()); //$NON-NLS-1$ - - /* Listener for isPatch */ - isPatchButton.addSelectionListener(new SelectionListener() { - private int lastSelected; - - public void widgetDefaultSelected(SelectionEvent e) { - // ignore - } - - public void widgetSelected(SelectionEvent e) { - taskAttachment.setPatch(isPatchButton.getSelection()); - if (isPatchButton.getSelection()) { - lastSelected = contentTypeList.getSelectionIndex(); - contentTypeList.select(0); - contentTypeList.setEnabled(false); - if (attachContextButton.isEnabled()) { - attachContextButton.setSelection(true); - } - } else { - contentTypeList.setEnabled(true); - contentTypeList.select(lastSelected); - } - } - }); - - setErrorMessage(null); - - if (descriptionText != null) { - descriptionText.setFocus(); - } else { - commentText.setFocus(); - } - } - - public TaskAttachmentModel getModel() { - return model; - } - - @Override - public IWizardPage getNextPage() { - taskAttachment.applyTo(model.getAttribute()); - model.setComment(commentText.getText()); - model.setAttachContext(attachContextButton.getSelection()); - model.setContentType(taskAttachment.getContentType()); - return super.getNextPage(); - } - - @Override - public boolean isPageComplete() { - return !"".equals(fileNameText.getText().trim()) - && (descriptionText == null || !"".equals(descriptionText.getText().trim())); - } - - private void setContentType(String contentType) { - String[] typeList = contentTypeList.getItems(); - for (int i = 0; i < typeList.length; i++) { - if (typeList[i].equals(contentType)) { - contentTypeList.select(i); - break; - } - } - } - - private void setFilePath(String path) { - fileNameText.setText(path); - if (path.endsWith(".patch")) { - isPatchButton.setSelection(true); - if (attachContextButton.isEnabled()) { - attachContextButton.setSelection(true); - } - } - } - - public void setNeedsDescription(boolean supportsDescription) { - this.needsDescription = supportsDescription; - if (supportsDescription) { - setMessage("Enter a description and verify the content type of the attachment"); - } else { - setMessage("Verify the content type of the attachment"); - } - } - - public boolean supportsDescription() { - return needsDescription; - } - - @Override - public void setVisible(boolean visible) { - if (visible) { - if (fileNameText.getText().length() == 0) { - setFilePath(getModel().getSource().getName()); - } - setContentType(getModel().getSource().getContentType()); - } - super.setVisible(visible); - if (first) { - if (descriptionText != null) { - descriptionText.setFocus(); - } else { - commentText.setFocus(); - } - first = false; - } - } - -} |