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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
/*******************************************************************************
* Copyright (c) 2010 BestSolution.at 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:
* Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
* Steven Spungin <steven@spungin.tv> - Ongoing maintenance
******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component.virtual;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.value.WritableValue;
import org.eclipse.e4.tools.emf.ui.common.component.AbstractComponentEditor;
import org.eclipse.e4.tools.emf.ui.internal.ResourceProvider;
import org.eclipse.e4.tools.emf.ui.internal.common.AbstractPickList;
import org.eclipse.e4.tools.emf.ui.internal.common.AbstractPickList.PickListFeatures;
import org.eclipse.e4.tools.emf.ui.internal.common.E4PickList;
import org.eclipse.e4.tools.emf.ui.internal.common.VirtualEntry;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.commands.MBindingTable;
import org.eclipse.e4.ui.model.application.commands.MCommandsFactory;
import org.eclipse.e4.ui.model.application.commands.impl.CommandsPackageImpl;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.databinding.EMFDataBindingContext;
import org.eclipse.emf.edit.command.AddCommand;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
public class VBindingTableEditor extends AbstractComponentEditor {
private Composite composite;
private EMFDataBindingContext context;
private TableViewer viewer;
private List<Action> actions = new ArrayList<Action>();
@Inject
public VBindingTableEditor() {
super();
}
@PostConstruct
void init() {
actions.add(new Action(Messages.VBindingTableEditor_AddBindingTable, createImageDescriptor(ResourceProvider.IMG_BindingTable)) {
@Override
public void run() {
handleAdd();
}
});
}
@Override
public Image getImage(Object element, Display display) {
return null;
}
@Override
public String getLabel(Object element) {
return Messages.VBindingTableEditor_Label;
}
@Override
public String getDetailLabel(Object element) {
return null;
}
@Override
public String getDescription(Object element) {
return Messages.VBindingTableEditor_Description;
}
@Override
public Composite doGetEditor(Composite parent, Object object) {
if (composite == null) {
context = new EMFDataBindingContext();
composite = createForm(parent, context, getMaster());
}
VirtualEntry<?> o = (VirtualEntry<?>) object;
viewer.setInput(o.getList());
getMaster().setValue(o.getOriginalParent());
return composite;
}
private Composite createForm(Composite parent, EMFDataBindingContext context, WritableValue master) {
CTabFolder folder = new CTabFolder(parent, SWT.BOTTOM);
CTabItem item = new CTabItem(folder, SWT.NONE);
item.setText(Messages.ModelTooling_Common_TabDefault);
parent = createScrollableContainer(folder);
item.setControl(parent.getParent());
{
AbstractPickList pickList = new E4PickList(parent, SWT.NONE, Arrays.asList(PickListFeatures.NO_PICKER), Messages, this, CommandsPackageImpl.Literals.BINDING_TABLE_CONTAINER__BINDING_TABLES) {
@Override
protected void addPressed() {
handleAdd();
}
@Override
protected List<?> getContainerChildren(Object container) {
return ((MApplication) container).getBindingTables();
}
};
pickList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
viewer = pickList.getList();
}
folder.setSelection(0);
return folder;
}
protected void handleAdd() {
MBindingTable command = MCommandsFactory.INSTANCE.createBindingTable();
setElementId(command);
Command cmd = AddCommand.create(getEditingDomain(), getMaster().getValue(), CommandsPackageImpl.Literals.BINDING_TABLE_CONTAINER__BINDING_TABLES, command);
if (cmd.canExecute()) {
getEditingDomain().getCommandStack().execute(cmd);
getEditor().setSelection(command);
}
}
@Override
public IObservableList getChildList(Object element) {
return null;
}
@Override
public List<Action> getActions(Object element) {
ArrayList<Action> l = new ArrayList<Action>(super.getActions(element));
l.addAll(actions);
return l;
}
}
|