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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*******************************************************************************
* Copyright (c) 2014 Elphel, Inc.
* Copyright (c) 2006 Elphel, Inc and Excelsior, LLC.
* This file is a part of VDT plug-in.
* VDT plug-in is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VDT plug-in is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional permission under GNU GPL version 3 section 7:
* If you modify this Program, or any covered work, by linking or combining it
* with Eclipse or Eclipse plugins (or a modified version of those libraries),
* containing parts covered by the terms of EPL/CPL, the licensors of this
* Program grant you additional permission to convey the resulting work.
* {Corresponding Source for a non-source form of such a combination shall
* include the source code for the parts of Eclipse or Eclipse plugins used
* as well as that of the covered work.}
*******************************************************************************/
package com.elphel.vdt.ui.wizards.module;
import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
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.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import com.elphel.vdt.Txt;
//import com.elphel.vdt.core.verilog.VerilogUtils;
class NewModuleTemplatePage extends AbstractModulePage {
private Text textModuleName;
private ModulePortListViewer portListViewer;
private Button addButton;
private Button removeButton;
private Button upButton;
private Button downButton;
private SelectionListener buttonListener = new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
ModulePort port = (ModulePort) portListViewer.getSelection().getFirstElement();
Object source= e.getSource();
if (source == addButton) {
// Add a port to the PortList and refresh the view
portListViewer.getPortList().addPort();
} else if (source == removeButton) {
// Remove the selection and refresh the view
if (port != null) {
portListViewer.getPortList().removePort(port);
}
} else if (source == upButton) {
if (port != null) {
portListViewer.getPortList().moveUpPort(port);
}
} else if (source == downButton) {
if (port != null) {
portListViewer.getPortList().moveDownPort(port);
}
}
} // widgetSelected()
};
private final String getModuleName() { return textModuleName.getText().trim(); }
public NewModuleTemplatePage(ModuleData data) {
super("newModuleTemplatePage", data);
setTitle(Txt.s("WizardPage.NewModuleTemplate.caption"));
setDescription(Txt.s("WizardPage.NewModuleTemplate.description"));
}
private void createModuleName(Composite parent) {
createLabel(parent, Txt.s("WizardPage.NewModuleTemplate.Module.name"));
textModuleName = createText(parent, fieldsListener);
}
private Button createButton(Composite parent, String caption) {
Button button = new Button(parent, SWT.PUSH);
button.setText(caption);
GridData gridData = new GridData( GridData.HORIZONTAL_ALIGN_FILL);
button.setLayoutData(gridData);
button.addSelectionListener(buttonListener);
return button;
}
private void createModuleInterface(Composite parent) {
Composite panel = new Composite(parent, SWT.NULL);
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 2;
panel.setLayoutData(gridData);
GridLayout layout = new GridLayout(2, false);
panel.setLayout(layout);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 2;
Label label = new Label(panel, SWT.NULL);
label.setText(Txt.s("WizardPage.NewModuleTemplate.ModuleInterface.prompt"));
label.setLayoutData(gridData);
// Create the table of ports
gridData = new GridData( GridData.FILL_BOTH
| GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
gridData.verticalSpan = 4;
portListViewer = new ModulePortListViewer(panel);
portListViewer.setLayoutData(gridData);
addButton = createButton(panel, Txt.s("WizardPage.NewModuleTemplate.AddPort"));
removeButton = createButton(panel, Txt.s("WizardPage.NewModuleTemplate.RemovePort"));
upButton = createButton(panel, Txt.s("WizardPage.NewModuleTemplate.MoveUpPort"));
downButton = createButton(panel, Txt.s("WizardPage.NewModuleTemplate.MoveDownPort"));
} // createModuleInterface()
public void createControl(Composite parent) {
Composite panel = new Composite(parent, SWT.NULL);
GridLayout layout = new GridLayout();
panel.setLayout(layout);
layout.numColumns = 2;
layout.verticalSpacing = 9;
createModuleName(panel);
createModuleInterface(panel);
setControl(panel);
} // createControl()
private boolean validateModuleName() {
String moduleName = getModuleName();
if ((moduleName == null) || (moduleName.length() == 0)) {
updateStatus(Txt.s("WizardPage.NewModuleTemplate.Error.NoModuleName"));
return false;
}
try {
IFile file = data.getFile();
// if (file.exists() && VerilogUtils.existsModule(file, moduleName)) {
if (file.exists()) {
updateStatus("Specified module already exists");
return false;
}
} catch (CoreException e) {
}
return true;
}
protected void validatePage() {
if (validateModuleName())
updateStatus(null);
} // validatePage()
public void updateData() {
data.setModuleName(getModuleName());
List<ModulePort> ports = portListViewer.getPortList().getPorts();
data.setPorts((ModulePort[])ports.toArray(new ModulePort[ports.size()]));
} // updateData()
// @see org.eclipse.jface.dialogs.IDialogPage#setVisible(boolean)
public void setVisible(boolean visible) {
if (visible) {
textModuleName.setText(data.getPureFileName());
}
super.setVisible(visible);
}
} // class NewModuleTemplatePage