blob: a3b3955eee4464fd09df74e0509895f8c249a137 (
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) 2013 Ericsson and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Tasktop Technologies - initial API and implementation
*******************************************************************************/
package org.eclipse.mylyn.reviews.ui.spi.factories;
import org.eclipse.mylyn.reviews.core.spi.remote.AbstractRemoteFactoryProvider;
import org.eclipse.mylyn.reviews.ui.spi.editor.AbstractReviewSection;
import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.core.data.TaskData;
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage;
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.forms.widgets.FormToolkit;
/**
* Support UI context and implementation neutral creation of controls for a single component that modifies the state of
* a model object and it's related remote objects. (For convenience, the factory delegates back to the supplied UI
* context.)
*
* @author Miles Parker
*/
public abstract class AbstractUiFactory<EObjectType> implements IUiContext {
String name;
private final EObjectType object;
private final IUiContext context;
public AbstractUiFactory(String name, IUiContext context, EObjectType object) {
this.context = context;
this.name = name;
this.object = object;
}
/**
* Creates a control.
*
* @param context
* @param parent
* @param toolkit
* @return the created control; may be null in the case where the factory isn't executable.
*/
public Control createControl(IUiContext context, Composite parent, FormToolkit toolkit) {
if (isExecutable()) {
Button button = toolkit.createButton(parent, name, SWT.PUSH);
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
execute();
}
});
return button;
}
return null;
}
public abstract boolean isExecutable();
public abstract void execute();
public EObjectType getModelObject() {
return object;
}
public Shell getShell() {
return context.getShell();
}
public ITask getTask() {
return context.getTask();
}
public TaskData getTaskData() {
return context.getTaskData();
}
public TaskEditor getEditor() {
return context.getEditor();
}
public TaskRepository getTaskRepository() {
return context.getTaskRepository();
}
public AbstractRemoteFactoryProvider getRemoteFactoryProvider() {
return context.getRemoteFactoryProvider();
}
public IUiContext getContext() {
return context;
}
/**
* May return null, e.g. in the case where a factory was used outside of an editor context.
*
* @return
*/
public AbstractTaskEditorPage getTaskEditorPage() {
if (getContext() instanceof AbstractTaskEditorPage) {
return (AbstractTaskEditorPage) getContext();
} else if (getContext() instanceof AbstractReviewSection) {
return ((AbstractReviewSection) getContext()).getReviewEditorPage();
}
return null;
}
}
|