diff --git a/plugins/de.cognicrypt.codegenerator/src/main/java/de/cognicrypt/codegenerator/wizard/LocatorPage.java b/plugins/de.cognicrypt.codegenerator/src/main/java/de/cognicrypt/codegenerator/wizard/LocatorPage.java index 20cb2936a..1bb6b2364 100644 --- a/plugins/de.cognicrypt.codegenerator/src/main/java/de/cognicrypt/codegenerator/wizard/LocatorPage.java +++ b/plugins/de.cognicrypt.codegenerator/src/main/java/de/cognicrypt/codegenerator/wizard/LocatorPage.java @@ -35,6 +35,8 @@ import org.eclipse.ui.model.WorkbenchLabelProvider; import org.eclipse.ui.part.DrillDownComposite; +import de.cognicrypt.core.Activator; +import de.cognicrypt.core.Constants; import de.cognicrypt.utils.DeveloperProject; import de.cognicrypt.utils.Utils; @@ -45,6 +47,8 @@ public class LocatorPage extends WizardPage { protected LocatorPage(final String pageName) { super(pageName); setPageComplete(false); + this.setTitle("Select a file CogniCrypt should generate code into"); + this.setDescription("You may also select a package or project. In this case, CogniCrypt will generate a new Java source file within the selected resource."); } @Override @@ -54,11 +58,6 @@ public void createControl(final Composite parent) { new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1); - final Label label = new Label(composite, SWT.WRAP); - label.setText( - "Please select the file CogniCrypt should generate code into. You may also select a package or \nproject. In this case, CogniCrypt will generate a new Java source file within the selected resource."); - label.setFont(getFont()); - final DrillDownComposite drillDown = new DrillDownComposite(composite, SWT.BORDER); final GridData spec = new GridData(SWT.FILL, SWT.FILL, true, true); spec.widthHint = 320; @@ -139,6 +138,7 @@ private boolean isProperTarget(Object target) { String systemTargetPath = targetFolder.getFullPath().removeFirstSegments(1).toOSString(); return systemTargetPath.startsWith(new DeveloperProject(targetFolder.getProject()).getSourcePath()); } catch (CoreException e) { + Activator.getDefault().logError(e, Constants.CodeGenerationErrorMessage); return false; } } diff --git a/plugins/de.cognicrypt.codegenerator/src/main/java/de/cognicrypt/codegenerator/wizard/beginner/BeginnerTaskQuestionPage.java b/plugins/de.cognicrypt.codegenerator/src/main/java/de/cognicrypt/codegenerator/wizard/beginner/BeginnerTaskQuestionPage.java index 42d599fb7..8fb08d0c5 100644 --- a/plugins/de.cognicrypt.codegenerator/src/main/java/de/cognicrypt/codegenerator/wizard/beginner/BeginnerTaskQuestionPage.java +++ b/plugins/de.cognicrypt.codegenerator/src/main/java/de/cognicrypt/codegenerator/wizard/beginner/BeginnerTaskQuestionPage.java @@ -24,6 +24,7 @@ import org.eclipse.jface.fieldassist.ControlDecoration; import org.eclipse.jface.fieldassist.FieldDecoration; import org.eclipse.jface.fieldassist.FieldDecorationRegistry; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.ComboViewer; import org.eclipse.jface.viewers.IStructuredSelection; @@ -33,13 +34,19 @@ import org.eclipse.swt.custom.ScrolledComposite; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.FormData; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.layout.RowData; +import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; @@ -158,16 +165,14 @@ public boolean isPageComplete() { @Override public void createControl(final Composite parent) { - final ScrolledComposite sc = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL); + final ScrolledComposite sc = new ScrolledComposite(parent, SWT.V_SCROLL); sc.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); this.container = new Composite(sc, SWT.NONE); - // this.container.setBounds(10, 10, 450, 200); - // Updated the number of columns to order the questions vertically. final GridLayout layout = new GridLayout(1, false); - - // To display the Help view after clicking the help icon this.container.setLayout(layout); + this.container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + // If legacy JSON files are in effect. if (this.page == null) { createQuestionControl(this.container, this.quest); @@ -180,29 +185,33 @@ public void createControl(final Composite parent) { //setting focus to the first field on the page this.container.getChildren()[0].setFocus(); } + sc.setContent(this.container); sc.setExpandHorizontal(true); sc.setExpandVertical(true); - sc.setMinSize(sc.computeSize(SWT.DEFAULT, SWT.DEFAULT)); + sc.setSize(sc.computeSize(SWT.DEFAULT, SWT.DEFAULT)); setControl(sc); } private void createQuestionControl(final Composite parent, final Question question) { final List answers = question.getAnswers(); - final Composite container = getPanel(parent); - final Label label = new Label(container, SWT.TOP | SWT.FILL | SWT.WRAP); - final GridData gd_question = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1); - gd_question.widthHint = 750; - label.setLayoutData(gd_question); - label.setText(question.getQuestionText()); - - final Composite answerPanel = new Composite(parent, SWT.NONE); - final GridLayout answerLayout = new GridLayout(); - answerLayout.numColumns = 4; - answerLayout.verticalSpacing = 15; - answerLayout.horizontalSpacing = 15; - answerPanel.setLayout(answerLayout); + + // create group + final Group container = new Group(parent, SWT.NONE); + container.setLayout(new GridLayout(1, false)); + container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + + // add questions title to the group + final Label label = createHeadline(container, question.getQuestionText()); + + // add answer panel to the group + final Composite answerPanel = new Composite(container, SWT.NONE); + final GridLayout rl = new GridLayout(1, false); + rl.marginLeft = 0; + answerPanel.setLayout(rl); + answerPanel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); + int noOfAnswers = answers.size(); switch (question.getElement()) { @@ -216,10 +225,9 @@ private void createQuestionControl(final Composite parent, final Question questi BeginnerTaskQuestionPage.this.selectionMap.put(question, (Answer) selection.getFirstElement()); question.setEnteredAnswer((Answer) selection.getFirstElement()); }); - new Label(parent, SWT.NONE); //added description for questions if (!question.getNote().isEmpty()) { - createNote(parent, question, true); + createNote(answerPanel, question, true); } this.finish = true; BeginnerTaskQuestionPage.this.setPageComplete(this.finish); @@ -231,19 +239,14 @@ private void createQuestionControl(final Composite parent, final Question questi break; case radio: final String radioNote = question.getNote(); - Group radioNoteControl = null; + Composite radioNoteControl = null; if (!radioNote.isEmpty()) { - radioNoteControl = createNote(container, question, !(radioNote.contains("$$$"))); + radioNoteControl = createNote(answerPanel, question, !(radioNote.contains("$$$"))); } final Button[] radioButtons = new Button[noOfAnswers]; - boolean shouldBreak = noOfAnswers % 4 == 1; for (int i = 0; i < noOfAnswers; i++) { - final int count = i; - if (shouldBreak && i + 2 == noOfAnswers) { - new Label(answerPanel, SWT.NULL); - } - - final Group finalRadioNote = radioNoteControl; + + final Composite finalRadioNote = radioNoteControl; final String ans = answers.get(i).getValue(); radioButtons[i] = new Button(answerPanel, SWT.RADIO); radioButtons[i].setText(ans); @@ -279,18 +282,18 @@ public void widgetSelected(final SelectionEvent e) { BeginnerTaskQuestionPage.this.setPageComplete(this.finish = true); break; case checkbox: - Group checkboxNoteControl = null; + Composite checkboxNoteControl = null; final String checkboxNoteText = question.getNote(); //added description for questions if (!checkboxNoteText.isEmpty()) { - checkboxNoteControl = createNote(container, question, !checkboxNoteText.contains("$$$")); + checkboxNoteControl = createNote(answerPanel, question, !checkboxNoteText.contains("$$$")); } final List