Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0a83446abd199a9fa253fa7ddc1104122a11e6aa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*******************************************************************************
 * Copyright (c) 2014, 2018 Frank Becker and others.
 * 
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     Frank Becker - initial API and implementation
 *     Red Hat Inc. - modified for use with OpenShift.io
 *******************************************************************************/

package org.eclipse.linuxtools.internal.mylyn.osio.rest.ui;

import java.util.ArrayList;
import java.util.Set;

import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.IOSIORestConstants;
import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestCore;
import org.eclipse.linuxtools.internal.mylyn.osio.rest.core.OSIORestTaskSchema;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor;
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage;
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPart;
import org.eclipse.mylyn.tasks.ui.editors.AttributeEditorFactory;
import org.eclipse.mylyn.tasks.ui.editors.LayoutHint;
import org.eclipse.mylyn.tasks.ui.editors.LayoutHint.ColumnSpan;
import org.eclipse.mylyn.tasks.ui.editors.LayoutHint.RowSpan;
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
import org.eclipse.mylyn.tasks.ui.editors.TaskEditorPartDescriptor;

public class OSIORestTaskEditorPage extends AbstractTaskEditorPage {

	public OSIORestTaskEditorPage(TaskEditor editor) {
		this(editor, OSIORestCore.CONNECTOR_KIND);
	}

	public OSIORestTaskEditorPage(TaskEditor editor, String connectorKind) {
		super(editor, connectorKind);
		setNeedsPrivateSection(true);
		setNeedsSubmitButton(true);
	}

	@Override
	protected AttributeEditorFactory createAttributeEditorFactory() {
		AttributeEditorFactory factory = new AttributeEditorFactory(getModel(), getTaskRepository(), getEditorSite()) {

			@Override
			public AbstractAttributeEditor createEditor(String type, TaskAttribute taskAttribute) {
				AbstractAttributeEditor editor;
				if (IOSIORestConstants.EDITOR_TYPE_ASSIGNEES.equals(type)) {
					editor = new OSIOAssigneeAttributeEditor(getModel(), taskAttribute);
				} else if (IOSIORestConstants.EDITOR_TYPE_LABELS.equals(type)) {
					editor = new OSIOLabelAttributeEditor(getModel(), taskAttribute);
				} else if (IOSIORestConstants.EDITOR_TYPE_LINKS.equals(type)) {
					editor = new OSIOLinksAttributeEditor(getModel(), taskAttribute);
				} else if (IOSIORestConstants.EDITOR_TYPE_ADD_LINKS.equals(type)) {
					editor = new OSIOAddLinksAttributeEditor(getModel(), getConnector(), taskAttribute);
				} else if (IOSIORestConstants.EDITOR_TYPE_ADD_LABELS.equals(type)) {
					editor = new OSIOLabelsAttributeEditor(getModel(), taskAttribute);
				} else if (IOSIORestConstants.EDITOR_TYPE_KEYWORD.equals(type)) {
					editor = new OSIOKeywordAttributeEditor(getModel(), taskAttribute);
				} else {
					editor = super.createEditor(type, taskAttribute);
				}
				if (editor != null
						&& OSIORestTaskSchema.getDefault().ADD_ASSIGNEE.getKey().equals(taskAttribute.getId())) {
					editor.setLayoutHint(new LayoutHint(RowSpan.SINGLE, ColumnSpan.SINGLE));
				}
				if (editor != null
						&& OSIORestTaskSchema.getDefault().ADD_LABEL.getKey().equals(taskAttribute.getId())) {
					editor.setLayoutHint(new LayoutHint(RowSpan.SINGLE, ColumnSpan.SINGLE));
				}
				if (editor != null
						&& OSIORestTaskSchema.getDefault().ADD_LINK.getKey().equals(taskAttribute.getId())) {
					editor.setLayoutHint(new LayoutHint(RowSpan.SINGLE, ColumnSpan.SINGLE));
				}

				return editor;
			}
		};
		return factory;
	}

	@Override
	protected Set<TaskEditorPartDescriptor> createPartDescriptors() {
		Set<TaskEditorPartDescriptor> descriptors = super.createPartDescriptors();
		// remove unnecessary default editor parts
		ArrayList<TaskEditorPartDescriptor> descriptorsToRemove = new ArrayList<TaskEditorPartDescriptor>(2);
		for (TaskEditorPartDescriptor taskEditorPartDescriptor : descriptors) {
			if (taskEditorPartDescriptor.getId().equals(ID_PART_PEOPLE) ||
					taskEditorPartDescriptor.getId().equals("org.eclipse.mylyn.tasks.activity.ui.viewer.ActivityPart") || //$NON-NLS-1$
					taskEditorPartDescriptor.getId().equals(ID_PART_ATTRIBUTES)) {
				descriptorsToRemove.add(taskEditorPartDescriptor);
				continue;
			}
		}
		descriptors.removeAll(descriptorsToRemove);

		// Add the updated OSIO attributes part
		descriptors.add(new TaskEditorPartDescriptor(ID_PART_ATTRIBUTES) {
			@Override
			public AbstractTaskEditorPart createPart() {
				return new OSIORestTaskEditorAttributePart();
			}
	
		}.setPath(PATH_ATTRIBUTES));
		
		// Add the updated OSIO people part
		descriptors.add(new TaskEditorPartDescriptor(ID_PART_PEOPLE) {
			@Override
			public AbstractTaskEditorPart createPart() {
				return new OSIORestTaskEditorPeoplePart();
			}
		}.setPath(PATH_PEOPLE));

		return descriptors;
	}

}

Back to the top