1 package com.proalpha.pds.ui.wizards.wizardpages;
4 import java.util.Collections;
5 import java.util.HashMap;
6 import java.util.LinkedHashMap;
10 import org.eclipse.core.resources.IFolder;
11 import org.eclipse.core.resources.IResource;
12 import org.eclipse.core.resources.ResourcesPlugin;
13 import org.eclipse.core.runtime.FileLocator;
14 import org.eclipse.core.runtime.Path;
15 import org.eclipse.core.runtime.Platform;
16 import org.eclipse.jface.dialogs.IDialogPage;
17 import org.eclipse.jface.layout.GridDataFactory;
18 import org.eclipse.jface.resource.ImageDescriptor;
19 import org.eclipse.jface.wizard.WizardPage;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.custom.CCombo;
22 import org.eclipse.swt.events.FocusAdapter;
23 import org.eclipse.swt.events.FocusEvent;
24 import org.eclipse.swt.events.ModifyEvent;
25 import org.eclipse.swt.events.ModifyListener;
26 import org.eclipse.swt.events.SelectionAdapter;
27 import org.eclipse.swt.events.SelectionEvent;
28 import org.eclipse.swt.layout.GridData;
29 import org.eclipse.swt.layout.GridLayout;
30 import org.eclipse.swt.widgets.Button;
31 import org.eclipse.swt.widgets.Combo;
32 import org.eclipse.swt.widgets.Composite;
33 import org.eclipse.swt.widgets.Label;
34 import org.eclipse.swt.widgets.Text;
35 import org.eclipse.ui.dialogs.ContainerSelectionDialog;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
39 import com.proalpha.pds.paconnector.PaProject;
40 import com.proalpha.pds.paconnector.parameter.StartparameterReader;
41 import com.proalpha.pds.paconnector.repository.Instance;
42 import com.proalpha.pds.paconnector.repository.RepositoryDelegate;
43 import com.proalpha.pds.paconnector.repository.RepositoryInformations;
44 import com.proalpha.pds.templates.data.GeneratorSettingsConstans;
45 import com.proalpha.pds.ui.Activator;
56 private static final Logger logger = LoggerFactory.getLogger(
WizardMainPage.class);
62 private CCombo programVariant;
63 private Text containerText;
64 private Text fileText;
65 private Text relativePathText;
66 private String currConfig;
67 private Map<String, WizardMainPageConfiguration> configList;
68 private boolean checkRepository;
69 private boolean supportRepositoryCreateButton;
70 private boolean checkFileNameLength;
71 private boolean checkLowerCase;
72 private Combo parentClassCombo;
73 private String rootClass;
74 private Text shortDescriptionText;
75 private Text descriptionText;
76 private Button buttonCreateObject;
77 private Text productText;
78 private Text versionText;
79 private Text authorText;
80 private List<String> extensionList;
81 private Text productDescriptionText;
82 private Text moduleDescriptionText;
83 private Text moduleText;
84 private String thirdDigit;
85 private HashMap<String, String> classGroupCode;
86 private Boolean isFileExisting =
false;
88 private static final String OO_ABL =
"OOABL";
102 super(
"WizardMainPage");
104 URL url = FileLocator.find(Platform.getBundle(
Activator.PLUGIN_ID),
new Path(
"icons/pA-logox72.png"),
105 Collections.emptyMap());
107 setImageDescriptor(ImageDescriptor.createFromURL(url));
109 this.paProject = paProject;
110 this.configList = configs;
111 currConfig = configs.entrySet().iterator().next().getKey();
112 this.repositoryDelegate = repositoryDelegate;
113 this.repositoryInformations = repositoryInformations;
114 this.startparameterReader = startparameterReader;
120 private class CreateInRepositorySelectionAdapter
extends SelectionAdapter {
122 public void widgetSelected(SelectionEvent event) {
123 String fileName = getFileName();
124 String description = getFileDescription();
125 String shortDescription = getShortDescription();
126 String parentClass = parentClassCombo.getText();
135 checkFileExisting(getFileName());
141 private String getFileDescription() {
142 return descriptionText.getText();
147 private class BrowseButtonSelectionAdapter
extends SelectionAdapter {
154 public void widgetSelected(SelectionEvent event) {
155 ContainerSelectionDialog dialog =
new ContainerSelectionDialog(getShell(),
156 ResourcesPlugin.getWorkspace().getRoot(),
false,
"Select new file container");
158 if (dialog.open() == ContainerSelectionDialog.OK) {
159 Object[] result = dialog.getResult();
160 if (result.length == 1) {
161 containerText.setText(((Path) result[0]).toString());
167 private class FileNameFocusAdapter
extends FocusAdapter {
169 public void focusLost(FocusEvent event) {
176 private class ValidateModifyListener
implements ModifyListener {
177 public void modifyText(ModifyEvent e) {
178 if (programVariant.isVisible())
189 container =
new Composite(parent, SWT.NULL);
191 GridLayout glContainer =
new GridLayout(3,
false);
192 container.setLayout(glContainer);
194 ValidateModifyListener modifyListener =
new ValidateModifyListener();
196 createLabel(container,
"Program &Variant:", SWT.NULL);
197 programVariant =
new CCombo(container, SWT.SINGLE | SWT.BORDER);
198 programVariant.setEditable(
false);
199 GridData gdProgramVariant =
new GridData(GridData.FILL, GridData.FILL,
true,
false, 1, 1);
200 gdProgramVariant.widthHint = convertWidthInCharsToPixels(10);
201 programVariant.setLayoutData(gdProgramVariant);
202 programVariant.addSelectionListener(
new SelectionAdapter() {
204 public void widgetSelected(SelectionEvent e) {
205 if (!currConfig.equals(programVariant.getText())) {
206 currConfig = programVariant.getText();
211 createEmptyLabel(container, SWT.NONE);
213 createLabel(container,
"&File name:", SWT.NULL);
214 fileText = createTextField(container,
"Physical File Name");
215 fileText.addModifyListener(modifyListener);
216 fileText.addFocusListener(
new FileNameFocusAdapter());
217 createEmptyLabel(container, SWT.NONE);
219 createLabel(container,
"&Parent Class:", SWT.NONE);
220 parentClassCombo =
new Combo(container, SWT.NONE);
221 GridData gdParentClass =
new GridData(GridData.FILL, GridData.FILL,
true,
false, 1, 1);
222 gdParentClass.widthHint = convertWidthInCharsToPixels(10);
223 parentClassCombo.setLayoutData(gdParentClass);
224 parentClassCombo.addModifyListener(modifyListener);
226 buttonCreateObject = createButton(container,
"Create in Repository");
227 buttonCreateObject.addSelectionListener(
new CreateInRepositorySelectionAdapter());
229 createLabel(container,
"&Container:", SWT.NONE);
230 containerText = createTextField(container,
"Parent Directory");
231 containerText.addModifyListener(modifyListener);
233 Button buttonBrowseForContainer = createButton(container,
"Browse...");
234 buttonBrowseForContainer.setToolTipText(
"Browse Directories in current Project");
235 buttonBrowseForContainer.addSelectionListener(
new BrowseButtonSelectionAdapter());
237 createLabel(container,
"Author:", SWT.NONE);
238 authorText = createTextField(container,
"Author");
239 createEmptyLabel(container, SWT.NONE);
241 createLabel(container,
"Version:", SWT.NONE);
242 versionText = createTextField(container,
"Current proALPHA Version");
243 createEmptyLabel(container, SWT.NONE);
245 createLabel(container,
"Product:", SWT.NONE);
246 productText = createReadOnlyTextField(container,
"proALPHA Product Key");
247 productDescriptionText = createReadOnlyTextField(container,
"proALPHA Product Description");
249 createLabel(container,
"Module:", SWT.NONE);
250 moduleText = createReadOnlyTextField(container,
"proALPHA Sub Module Key");
251 moduleDescriptionText = createReadOnlyTextField(container,
"proALPHA Sub Module Description");
253 createLabel(container,
"Relative Path:", SWT.NONE);
254 relativePathText = createReadOnlyTextField(container,
"Relative Path of File");
256 GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(
true,
false).span(2, 1)
257 .applyTo(relativePathText);
259 createLabel(container,
"Short Description:", SWT.NONE);
260 shortDescriptionText = createTextField(container,
"Short Description");
261 GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(
true,
false).span(2, 1)
262 .applyTo(shortDescriptionText);
263 shortDescriptionText.addModifyListener(modifyListener);
264 shortDescriptionText.setTextLimit(80);
266 Label descriptionLabel = createLabel(container,
"Description:", SWT.NONE);
267 GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).applyTo(descriptionLabel);
268 descriptionText = createTextField(container,
"Description", SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
269 GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(
true,
true).span(2, 1).applyTo(descriptionText);
270 descriptionText.addModifyListener(modifyListener);
271 descriptionText.setTextLimit(800);
273 setControl(container);
274 new Label(container, SWT.NONE);
275 new Label(container, SWT.NONE);
280 public void setVisible(
boolean visible) {
281 programVariant.setItems(getConfigKeys((LinkedHashMap<String, WizardMainPageConfiguration>) this.configList));
282 programVariant.setText(currConfig);
284 super.setVisible(visible);
287 private Button createButton(Composite composite, String text) {
288 Button newButton =
new Button(composite, SWT.PUSH);
289 newButton.setText(text);
293 private Text createReadOnlyTextField(Composite composite, String tooltip) {
294 return createTextField(composite, tooltip, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
297 private Text createTextField(Composite composite, String tooltip) {
298 return createTextField(composite, tooltip, SWT.BORDER | SWT.SINGLE);
301 private Text createTextField(Composite composite, String tooltip,
int style) {
302 Text newText =
new Text(composite, style);
303 newText.setToolTipText(tooltip);
305 GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(
true,
false).applyTo(newText);
310 private Label createEmptyLabel(Composite composite,
int style) {
311 return createLabel(composite,
"", style);
314 private Label createLabel(Composite composite, String text,
int style) {
315 Label newLabel =
new Label(composite, style);
316 newLabel.setText(text);
325 private void initialize() {
327 authorText.setText(System.getProperty(
"user.name"));
328 versionText.setText(this.paProject.getVersion());
330 WizardMainPageConfiguration configuration = configList.get(currConfig);
332 setTitle(configuration.getWizardTitle());
333 setDescription(configuration.getWizardDescription());
334 this.checkRepository = configuration.isCheckRepository();
335 this.extensionList = configuration.getExtensionList();
336 this.thirdDigit = configuration.getThirdDigit();
337 this.rootClass = configuration.getRootClass();
338 this.extensionList = configuration.getExtensionList();
339 this.checkFileNameLength = configuration.isCheckFileNameLength();
340 this.checkLowerCase = configuration.isCheckLowerCase();
341 this.supportRepositoryCreateButton = configuration.isSupportRepositoryCreateButton();
345 containerText.setText(workingDirectory.getFullPath().toString());
347 buttonCreateObject.setEnabled(
false);
352 if (!checkRepository) {
353 parentClassCombo.setEnabled(
false);
356 String subClasses = repositoryInformations.getListOFSubClasses(this.rootClass);
358 if (subClasses !=
null && !subClasses.isEmpty()) {
359 String[] subClassesArray = subClasses.split(
",");
361 parentClassCombo.setItems(subClassesArray);
362 parentClassCombo.setText(rootClass);
366 classGroupCode =
new HashMap<>();
368 if (rootClass.equals(OO_ABL)) {
369 for (String className : subClassesArray) {
370 String objectClassCode = repositoryInformations.getClassGroupOf(className);
371 classGroupCode.put(className, objectClassCode);
377 setPageComplete(
false);
383 private void validateInput() {
387 if (!this.paProject.isAvailable()) {
391 String fileName = getFileName();
393 buttonCreateObject.setEnabled((checkRepository) && (supportRepositoryCreateButton)
394 && (!shortDescriptionText.getText().equals(
"")) && (!isFileExisting)
396 && (!
this.paProject.getCustomLevel().equals(
"")));
399 .setEnabled((checkRepository) && (parentClassCombo.getItemCount() != 1) && (!isFileExisting));
401 shortDescriptionText.setEnabled(!((checkRepository) && (isFileExisting)));
403 IResource container = ResourcesPlugin.getWorkspace().getRoot().findMember(
new Path(getContainerName()));
405 int dotLoc = fileName.lastIndexOf(
'.');
407 updateStatus(
"File extension must be specified");
408 buttonCreateObject.setEnabled(Boolean.FALSE);
411 String ext = fileName.substring(dotLoc + 1);
412 if (!(this.extensionList.contains(ext))) {
413 updateStatus(
"Invalid File Extension \"" + ext +
"\"");
414 buttonCreateObject.setEnabled(Boolean.FALSE);
419 if (getContainerName().length() == 0) {
420 updateStatus(
"File container must be specified");
423 if (container ==
null || (container.getType() & (IResource.PROJECT | IResource.FOLDER)) == 0) {
424 updateStatus(
"File container must exist");
427 if (!container.isAccessible()) {
428 updateStatus(
"Project must be writable");
431 if (fileName.length() == 0) {
432 updateStatus(
"File name must be specified");
435 if (fileName.replace(
'\\',
'/').indexOf(
'/', 1) > 0) {
436 updateStatus(
"File name must be valid");
439 if ((this.checkLowerCase) && !fileName.toLowerCase().equals(fileName)) {
440 updateStatus(
"File name must be lower case");
444 String fileBody = fileName.substring(0, dotLoc);
445 if ((this.checkFileNameLength) && (fileBody.length() != 8)) {
446 updateStatus(
"File name must have a length of 8 digits");
450 if (this.thirdDigit.length() > 0 && !fileName.substring(2, 3).equals(
this.thirdDigit)) {
451 updateStatus(
"Thirdt Digit of File name must be \"" + this.thirdDigit +
"\"");
457 if (!fileName.startsWith(
"_") && moduleText.getText().equals(
"")) {
458 updateStatus(
"The file must be assigned to a module.");
462 if (shortDescriptionText.getText().length() == 0) {
463 updateStatus(
"Short description must be specified");
472 if (fileName.endsWith(
".cls")) {
473 String parentClass = parentClassCombo.getText();
474 String objectClassCode = this.classGroupCode.get(parentClass);
476 for (
int i = 0; i < 2; i++) {
478 if (Character.isLowerCase(fileName.charAt(i))) {
479 updateStatus(
"The first three characters must be uppercase.");
487 if (objectClassCode ==
null || objectClassCode.contains(
"?")) {
488 objectClassCode =
"";
491 if ((!fileName.contains(objectClassCode +
".cls") && (!parentClassCombo.getText().equals(OO_ABL)))) {
493 updateStatus(
"You selected the following parent Class: " + parentClass
494 +
"Your Classname does not contain the dedicated Class Group Code: *" + objectClassCode
496 buttonCreateObject.setEnabled(
false);
499 if ((!fileName.contains(objectClassCode +
".cls") && (parentClassCombo.getText().equals(OO_ABL)))) {
500 fileText.setText(fileName.replace(objectClassCode,
""));
505 if (this.checkRepository && parentClassCombo.getText().equals(
"") && (!isFileExisting)) {
506 updateStatus(
"Object should be member of Class \"" + this.rootClass +
"\"");
510 if (checkRepository && (!isFileExisting)) {
513 if (this.paProject.getCustomLevel().equals(
"")) {
514 updateStatus(
"File unknown to Repository Manager. Please create manually in a seperate pA Session");
517 updateStatus(
"File unknown to Repository Manager.");
523 }
catch (Exception e) {
524 logger.error(e.getMessage(), e);
528 private void updateStatus(String message) {
529 setErrorMessage(message);
530 setPageComplete(message ==
null);
533 public String getContainerName() {
534 return containerText.getText();
537 public String getFileName() {
538 return fileText.getText();
541 public void setFileName(String fileName) {
542 this.fileText.setText(fileName);
546 public String getAuthor() {
547 return authorText.getText();
550 public String getShortDescription() {
551 return shortDescriptionText.getText();
554 public String getProduct() {
555 return productText.getText();
558 public String getProductDescription() {
559 return productDescriptionText.getText();
562 public String getRelativePath() {
563 return relativePathText.getText();
566 public String getVersion() {
567 return versionText.getText();
570 public String getModule() {
571 return moduleText.getText();
574 public String getModuleDescription() {
575 return moduleDescriptionText.getText();
578 public Map<String, Object> getSettings() {
579 HashMap<String, Object> wizardSettings =
new HashMap<>();
580 wizardSettings.put(GeneratorSettingsConstans.AUTHOR,
this.getAuthor());
581 wizardSettings.put(GeneratorSettingsConstans.CONTAINER_NAME,
this.getContainerName());
582 wizardSettings.put(GeneratorSettingsConstans.DESCRIPTION,
this.getShortDescription());
583 wizardSettings.put(
"FileName", this.getFileName());
584 wizardSettings.put(
"Product", this.getProduct());
585 wizardSettings.put(
"ProductDescription", this.getProductDescription());
586 wizardSettings.put(
"RelativePath", this.getRelativePath());
587 wizardSettings.put(
"Module", this.getModule());
588 wizardSettings.put(
"ModuleDescription", this.getModuleDescription());
589 wizardSettings.put(
"Version", this.getVersion());
590 wizardSettings.put(
"ParentObject", this.getParentClass());
591 wizardSettings.put(GeneratorSettingsConstans.TEMPLATE_NAME,
this.configList.get(currConfig).getTemplateName());
592 return wizardSettings;
595 private Object getParentClass() {
597 return parentClassCombo.getText();
600 public void setFileDescriptionText(String description) {
601 if (shortDescriptionText !=
null) {
602 shortDescriptionText.setText(description);
610 return checkFileNameLength;
617 this.checkFileNameLength = checkFileNameLength;
624 return checkLowerCase;
631 this.checkLowerCase = checkLowerCase;
634 private void checkFileExisting(String fileName) {
635 if (checkRepository) {
638 isFileExisting =
false;
642 private void validateFileName() {
643 if (!this.paProject.isAvailable())
646 String fileName = getFileName();
648 checkFileExisting(fileName);
653 if (fileName.length() > 0) {
655 productText.setText(repositoryInformations.getProductName(fileName));
656 productDescriptionText.setText(repositoryInformations.getProductDescription(fileName));
658 moduleText.setText(repositoryInformations.getModule(fileName));
659 moduleDescriptionText.setText(repositoryInformations.getModuleDescription(fileName));
661 relativePathText.setText(repositoryInformations.getRelativePath(fileName));
664 productText.setText(
"");
665 productDescriptionText.setText(
"");
666 moduleText.setText(
"");
667 moduleDescriptionText.setText(
"");
668 relativePathText.setText(
"");
674 if (isFileExisting) {
676 shortDescriptionText.setText(repositoryInformations.getProgramShortDesc(fileName));
680 if (checkRepository) {
682 String parentClass =
"";
683 if (isFileExisting) {
684 parentClass = repositoryInformations.
getClassName(repositoryInformations.getClassOBJ(fileName));
686 }
else if (fileName.contains(
".cls")) {
687 parentClass = retrieveParentClass();
690 if (!parentClass.isEmpty()) {
691 parentClassCombo.setText(parentClass);
699 private String retrieveParentClass() {
701 String fileName = getFileName();
703 for (Map.Entry<String, String> entry : classGroupCode.entrySet()) {
705 String classCode = entry.getValue();
707 if ((classCode !=
null) && (!classCode.isEmpty()) && (classCode.length() == 3)) {
708 classCode = classCode +
".cls";
709 if (fileName.contains(classCode)) {
710 return entry.getKey();
724 private String[] getConfigKeys(LinkedHashMap<String, WizardMainPageConfiguration> configList) {
725 return configList.keySet().stream().toArray(String[]::
new);
void createControl(Composite parent)
boolean isCheckLowerCase()
boolean isCheckFileNameLength()
void setCheckLowerCase(boolean checkLowerCase)
WizardMainPage(PaProject paProject, Map< String, WizardMainPageConfiguration > configs, RepositoryDelegate repositoryDelegate, RepositoryInformations repositoryInformations, StartparameterReader startparameterReader)
void setCheckFileNameLength(boolean checkFileNameLength)
IFolder getWorkingDirectory()
void setDescription(String description)
void setParentClass(String parentClass)
void setShortDescription(String shortDescription)
void setName(String name)
boolean createRepositoryEntryforInstance(Instance instance)
Instance getEmptyInstance()